drivers: fpga: better support for incomplete drivers
Add more checks and error handling for drivers which do not implement
the whole API.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
diff --git a/include/zephyr/drivers/fpga.h b/include/zephyr/drivers/fpga.h
index 27dcb69..61e9c1c 100644
--- a/include/zephyr/drivers/fpga.h
+++ b/include/zephyr/drivers/fpga.h
@@ -58,6 +58,13 @@
const struct fpga_driver_api *api =
(const struct fpga_driver_api *)dev->api;
+ if (api->get_status == NULL) {
+ /* assume it can never be reprogrammed if it
+ * doesn't support the get_status callback
+ */
+ return FPGA_STATUS_INACTIVE;
+ }
+
return api->get_status(dev);
}
@@ -74,6 +81,10 @@
const struct fpga_driver_api *api =
(const struct fpga_driver_api *)dev->api;
+ if (api->reset == NULL) {
+ return -ENOTSUP;
+ }
+
return api->reset(dev);
}
@@ -93,6 +104,10 @@
const struct fpga_driver_api *api =
(const struct fpga_driver_api *)dev->api;
+ if (api->load == NULL) {
+ return -ENOTSUP;
+ }
+
return api->load(dev, image_ptr, img_size);
}
@@ -116,6 +131,8 @@
return api->on(dev);
}
+#define FPGA_GET_INFO_DEFAULT "n/a"
+
/**
* @brief Returns information about the FPGA.
*
@@ -128,6 +145,10 @@
const struct fpga_driver_api *api =
(const struct fpga_driver_api *)dev->api;
+ if (api->get_info == NULL) {
+ return FPGA_GET_INFO_DEFAULT;
+ }
+
return api->get_info(dev);
}