Skip to content

Commit 035b139

Browse files
benediktibkmmahadevan108
authored andcommitted
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 <[email protected]>
1 parent c6cc7a1 commit 035b139

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/fpga/fpga_ice40.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,26 @@ static int fpga_ice40_load_gpio(const struct device *dev, uint32_t *image_ptr, u
207207
struct fpga_ice40_data *data = dev->data;
208208
const struct fpga_ice40_config *config = dev->config;
209209

210+
if (!device_is_ready(config->clk.port)) {
211+
LOG_ERR("%s: GPIO for clk is not ready", dev->name);
212+
return -ENODEV;
213+
}
214+
215+
if (!device_is_ready(config->pico.port)) {
216+
LOG_ERR("%s: GPIO for pico is not ready", dev->name);
217+
return -ENODEV;
218+
}
219+
220+
if (config->set == NULL) {
221+
LOG_ERR("%s: set register was not specified", dev->name);
222+
return -EFAULT;
223+
}
224+
225+
if (config->clear == NULL) {
226+
LOG_ERR("%s: clear register was not specified", dev->name);
227+
return -EFAULT;
228+
}
229+
210230
/* prepare masks */
211231
cs = BIT(config->bus.config.cs.gpio.pin);
212232
clk = BIT(config->clk.pin);
@@ -502,6 +522,16 @@ static int fpga_ice40_init(const struct device *dev)
502522
int ret;
503523
const struct fpga_ice40_config *config = dev->config;
504524

525+
if (!device_is_ready(config->creset.port)) {
526+
LOG_ERR("%s: GPIO for creset is not ready", dev->name);
527+
return -ENODEV;
528+
}
529+
530+
if (!device_is_ready(config->cdone.port)) {
531+
LOG_ERR("%s: GPIO for cdone is not ready", dev->name);
532+
return -ENODEV;
533+
}
534+
505535
ret = gpio_pin_configure_dt(&config->creset, GPIO_OUTPUT_HIGH);
506536
if (ret < 0) {
507537
LOG_ERR("failed to configure CRESET: %d", ret);

0 commit comments

Comments
 (0)