Skip to content

Commit 53ae195

Browse files
benediktibkhenrikbrixandersen
authored andcommitted
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 <[email protected]>
1 parent 07b7802 commit 53ae195

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

drivers/fpga/fpga_ice40.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,6 @@ static int fpga_ice40_load_gpio(const struct device *dev, uint32_t *image_ptr, u
210210
return -ENODEV;
211211
}
212212

213-
if (config->set == NULL) {
214-
LOG_ERR("%s: set register was not specified", dev->name);
215-
return -EFAULT;
216-
}
217-
218-
if (config->clear == NULL) {
219-
LOG_ERR("%s: clear register was not specified", dev->name);
220-
return -EFAULT;
221-
}
222-
223213
/* prepare masks */
224214
cs = BIT(config->bus.config.cs.gpio.pin);
225215
clk = BIT(config->clk.pin);
@@ -589,6 +579,18 @@ static int fpga_ice40_init(const struct device *dev)
589579
BUILD_ASSERT(FPGA_ICE40_TRAILING_CLOCKS(inst) >= FPGA_ICE40_TRAILING_CLOCKS_MIN); \
590580
BUILD_ASSERT(FPGA_ICE40_TRAILING_CLOCKS(inst) <= UINT8_MAX); \
591581
BUILD_ASSERT(FPGA_ICE40_MHZ_DELAY_COUNT(inst) >= 0); \
582+
BUILD_ASSERT(!DT_INST_PROP(inst, load_mode_bitbang) || \
583+
DT_INST_NODE_HAS_PROP(inst, creset_gpios)); \
584+
BUILD_ASSERT(!DT_INST_PROP(inst, load_mode_bitbang) || \
585+
DT_INST_NODE_HAS_PROP(inst, cdone_gpios)); \
586+
BUILD_ASSERT(!DT_INST_PROP(inst, load_mode_bitbang) || \
587+
DT_INST_NODE_HAS_PROP(inst, clk_gpios)); \
588+
BUILD_ASSERT(!DT_INST_PROP(inst, load_mode_bitbang) || \
589+
DT_INST_NODE_HAS_PROP(inst, pico_gpios)); \
590+
BUILD_ASSERT(!DT_INST_PROP(inst, load_mode_bitbang) || \
591+
DT_INST_NODE_HAS_PROP(inst, gpios_set_reg)); \
592+
BUILD_ASSERT(!DT_INST_PROP(inst, load_mode_bitbang) || \
593+
DT_INST_NODE_HAS_PROP(inst, gpios_clear_reg)); \
592594
\
593595
FPGA_ICE40_PINCTRL_DEFINE(inst); \
594596
static struct fpga_ice40_data fpga_ice40_data_##inst; \

tests/drivers/build_all/fpga/spi.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ test_spi_fpga_ice40_gpio: ice40@0 {
1616
load-mode-bitbang;
1717
cdone-gpios = <&test_gpio 0 0>;
1818
creset-gpios = <&test_gpio 0 0>;
19+
clk-gpios = <&test_gpio 0 0>;
20+
pico-gpios = <&test_gpio 0 0>;
21+
gpios-set-reg = <0>;
22+
gpios-clear-reg = <0>;
1923
config-delay-us = <3900>;
2024
};
2125

@@ -28,9 +32,5 @@ test_spi_fpga_ice40_spi: ice40@1 {
2832

2933
cdone-gpios = <&test_gpio 0 0>;
3034
creset-gpios = <&test_gpio 0 0>;
31-
clk-gpios = <&test_gpio 0 0>;
32-
pico-gpios = <&test_gpio 0 0>;
33-
gpios-set-reg = <0>;
34-
gpios-clear-reg = <0>;
3535
config-delay-us = <3900>;
3636
};

0 commit comments

Comments
 (0)