Commit graph

19 commits

Author SHA1 Message Date
Benedikt Schmidt
760210f39d drivers: fpga: separate drivers of iCE40 for SPI and GPIO bitbang
Separate the current driver for the FPGA iCE40 into two different ones.
One implements only the SPI load mode, the other one only the GPIO
bitbang mode.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-28 15:39:33 +00:00
Benedikt Schmidt
b4893c46ce drivers: fpga: use defaults in iCE40 binding
Replace the DT_INST_PROP_OR statements with defaults
in the devicetree binding of the iCE40.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-22 08:25:44 -05:00
Benedikt Schmidt
b0a1dddde3 drivers: fpga: fix waveform for iCE40 configuration in SPI mode
The datasheet of the iCE40 specifies that there should be a leading and
trailing clocks phase during its configuration with SPI. Due to the
limitations of the SPI interface, and probably also due to a lock of
support for such a feature for instance in the STM32 SPI peripheral,
this is achieved with additional SPI transfers before and after the
actual image. Unfortunately, this by default also affects the slave
select GPIO, which has to stay high during these phases.
This fixes this behaviour via not passing the slave select GPIO
to the SPI driver and manipulating this GPIO manually.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-21 19:22:20 -05:00
Benedikt Schmidt
53ae195f0d drivers: fpga: replace runtime checks with buildtime asserts in iCE40
Replace NULL checks for the set and clear registers with BUILD_ASSERTs
in the iCE40 device instantiation.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-21 20:11:47 +01:00
Fin Maaß
d18f4256ee drivers: fpga: fix log level
Use CONFIG_FPGA_LOG_LEVEL for the fpga
log modules.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-11-21 11:02:23 +00:00
Benedikt Schmidt
5aa835c66b drivers: fpga: simplify load mode selection of iCE40
Replace the enum for load modes for the iCE40 with a boolean flag,
as there are only two options:
- SPI: default, which should be used whenever possible
- GPIO bitbang: workarorund, in case a low-end microcontroller is used

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-16 14:57:36 -05:00
Benedikt Schmidt
7918c921d5 drivers: fpga: always check state of CDONE during configuration of iCE40
Turn the assert into an if-statement to ensure that CDONE is always
checked during the configuration of an iCE40.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-16 13:37:16 -05:00
Benedikt Schmidt
035b139f64 drivers: fpga: add checks for optional properties of iCE40
Add checks in the GPIO bitbang mode to avoid a fault for missing
configuration in the devicetree.
Fixes #80850

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-11-07 08:32:42 -06:00
Chris Friedt
f4e07d15d6 sys: util: define bits per byte, nibble, and nibbles per byte
Collect some common bit-widths redefined in various locations
and put them under sys/util.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-15 19:05:06 +01:00
Benedikt Schmidt
f54a97c117 drivers: fpga: configure CDONE for ICE40 as input
Configure the GPIO CDONE of the ICE40 as GPIO_INPUT.
Fixes #78934.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-09-28 08:18:49 -05:00
Fabio Baltieri
f45e7eddaa drivers: fpga: add an init priority config option
Add a Kconfig option for FPGA device initialization priority.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-24 15:35:37 +02:00
Christopher Friedt
64e6c90fc0 drivers: fpga: ice40: remove unnecessary include
The `<zephyr/posix/time.h>` header was unused in `fpga_ice40.c`
so remove it.

This fixes an error about `pthread_attr_t` not being defined.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-23 10:06:00 +02:00
Gerard Marull-Paretas
3f2c2d4130 drivers: spi: make SPI dt-spec macros compatible with C++
As of today it is not possible to use SPI dt-spec macros in C++,
something known and documented. The main reason is because `cs` property
is initialized using a compound literal, something not supported in C++.
This PR takes another approach, that is to not make `cs` a pointer but a
struct member. This way, we can perform a regular initialization, at the
cost of using extra memory for unused delay/pin/flags if `cs` is not
used.

Fixes #56572

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-24 21:29:55 +02:00
Gerard Marull-Paretas
0ebe14beb4 sys: util: migrate all files to DIV_ROUND_UP
ceiling_fraction is deprecated, use DIV_ROUND_UP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Armin Brauns
a6e5135381 drivers: fpga: ice40: fix busy delay loop
This was being optimized out entirely by certain compiler configurations.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-14 11:17:35 +01:00
Armin Brauns
d0762e5439 drivers/fpga: ice40: use microsecond resolution for reset time
The 200ns reset time specified in the datasheet are a minimum time; and the
nanoseconds were being rounded to whole microseconds anyway.

Also make it the same type as `config_delay_us` (`uint16_t`).

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-14 11:17:35 +01:00
Armin Brauns
2f6dff59c5 drivers/fpga: ice40: use k_usleep instead of busy loop in SPI mode
The 200ns reset time are a minimum value, there is no need to enforce
precise timing (and thus manual per-device calibration) here.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-14 11:17:35 +01:00
Armin Brauns
8aec9dd552 drivers/fpga: ice40: fix minimum config delay
From FPGA-TN-02001-3.3 "iCE40 Programming and Configuration":

> After driving CRESET_B High or allowing it to float High, the AP must
> wait a minimum of 1200 µs, allowing the iCE40 FPGA to clear its internal
> configuration memory.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-14 11:17:35 +01:00
Chris Friedt
22fe674a9c drivers: fpga: ice40: add support for the Lattice iCE40 series
Add support for the Lattice iCE40 series FPGAs.

Fixes zephyrproject-rtos#48317

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-17 09:17:44 -05:00