Skip to content

Commit 7cd0d4b

Browse files
committed
drivers: fpga: allow multiple instances of an ICE40 on the same bus
This gets rid of the instantation of the parent pinctrl config, which was used to reapply the default pin state for the parent SPI bus. It uses instead the newly introduced SPI API to do so. This enables multiple instances of an ICE40 on the same SPI bus with CONFIG_PINCTRL=y. Signed-off-by: Benedikt Schmidt <[email protected]>
1 parent 946a0af commit 7cd0d4b

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

drivers/fpga/fpga_ice40.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ struct fpga_ice40_config {
9999
uint8_t leading_clocks;
100100
uint8_t trailing_clocks;
101101
fpga_api_load load;
102-
#ifdef CONFIG_PINCTRL
103-
const struct pinctrl_dev_config *pincfg;
104-
#endif
105102
};
106103

107104
static void fpga_ice40_crc_to_str(uint32_t crc, char *s)
@@ -299,9 +296,7 @@ static int fpga_ice40_load_gpio(const struct device *dev, uint32_t *image_ptr, u
299296
(void)gpio_pin_configure_dt(&config->bus.config.cs.gpio, GPIO_OUTPUT_HIGH);
300297
(void)gpio_pin_configure_dt(&config->clk, GPIO_DISCONNECTED);
301298
(void)gpio_pin_configure_dt(&config->pico, GPIO_DISCONNECTED);
302-
#ifdef CONFIG_PINCTRL
303-
(void)pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
304-
#endif
299+
spi_apply_default_pin_state_dt(&config->bus);
305300

306301
k_spin_unlock(&data->lock, key);
307302

@@ -438,9 +433,7 @@ static int fpga_ice40_load_spi(const struct device *dev, uint32_t *image_ptr, ui
438433
unlock:
439434
(void)gpio_pin_configure_dt(&config->creset, GPIO_OUTPUT_HIGH);
440435
(void)gpio_pin_configure_dt(&config->bus.config.cs.gpio, GPIO_OUTPUT_HIGH);
441-
#ifdef CONFIG_PINCTRL
442-
(void)pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
443-
#endif
436+
spi_apply_default_pin_state_dt(&config->bus);
444437

445438
k_spin_unlock(&data->lock, key);
446439

@@ -553,14 +546,6 @@ static int fpga_ice40_init(const struct device *dev)
553546
: (FPGA_ICE40_LOAD_MODE(inst) == FPGA_ICE40_LOAD_MODE_GPIO ? fpga_ice40_load_gpio \
554547
: NULL))
555548

556-
#ifdef CONFIG_PINCTRL
557-
#define FPGA_ICE40_PINCTRL_CONFIG(inst) .pincfg = PINCTRL_DT_DEV_CONFIG_GET(DT_INST_PARENT(inst)),
558-
#define FPGA_ICE40_PINCTRL_DEFINE(inst) PINCTRL_DT_DEFINE(DT_INST_PARENT(inst))
559-
#else
560-
#define FPGA_ICE40_PINCTRL_CONFIG(inst)
561-
#define FPGA_ICE40_PINCTRL_DEFINE(inst)
562-
#endif
563-
564549
#define FPGA_ICE40_DEFINE(inst) \
565550
BUILD_ASSERT(FPGA_ICE40_LOAD_MODE(inst) == FPGA_ICE40_LOAD_MODE_SPI || \
566551
FPGA_ICE40_LOAD_MODE(inst) == FPGA_ICE40_LOAD_MODE_GPIO); \
@@ -576,7 +561,6 @@ static int fpga_ice40_init(const struct device *dev)
576561
BUILD_ASSERT(FPGA_ICE40_TRAILING_CLOCKS(inst) <= UINT8_MAX); \
577562
BUILD_ASSERT(FPGA_ICE40_MHZ_DELAY_COUNT(inst) >= 0); \
578563
\
579-
FPGA_ICE40_PINCTRL_DEFINE(inst); \
580564
static struct fpga_ice40_data fpga_ice40_data_##inst; \
581565
\
582566
static const struct fpga_ice40_config fpga_ice40_config_##inst = { \
@@ -593,7 +577,7 @@ static int fpga_ice40_init(const struct device *dev)
593577
.leading_clocks = FPGA_ICE40_LEADING_CLOCKS(inst), \
594578
.trailing_clocks = FPGA_ICE40_TRAILING_CLOCKS(inst), \
595579
.load = FPGA_ICE40_LOAD_FUNC(inst), \
596-
FPGA_ICE40_PINCTRL_CONFIG(inst)}; \
580+
}; \
597581
\
598582
DEVICE_DT_INST_DEFINE(inst, fpga_ice40_init, NULL, &fpga_ice40_data_##inst, \
599583
&fpga_ice40_config_##inst, POST_KERNEL, CONFIG_FPGA_INIT_PRIORITY, \

tests/drivers/build_all/fpga/prj.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
55
CONFIG_GPIO=y
66
CONFIG_SPI=y
77
CONFIG_FPGA=y
8-
# Must disable pinctrl here because otherwise there is an error in
9-
# fpga_ice40.c here about the two nodes both declaring the same pinctrl data
10-
# of the common spi-bus parent. That effectively limits the number of
11-
# iCE40 FPGAs on a single bus to 1.
12-
CONFIG_PINCTRL=n
138
CONFIG_ICE40_FPGA=y
149
CONFIG_ALTERA_AGILEX_BRIDGE_FPGA=y
1510
CONFIG_ARM_SIP_SVC_DRIVER=y

tests/drivers/build_all/fpga/testcase.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ common:
55
platform_allow:
66
- native_posix
77
- native_sim
8+
- nucleo_f746zg
89
build_only: true
910
tests:
1011
drivers.fpga.build:

0 commit comments

Comments
 (0)