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>
This commit is contained in:
Tomasz Gorochowik 2024-04-15 14:04:31 +02:00 committed by Alberto Escolar
parent bf637bf623
commit 59bd6b84f2
1 changed files with 21 additions and 0 deletions

View File

@ -58,6 +58,13 @@ static inline enum FPGA_status fpga_get_status(const struct device *dev)
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 @@ static inline int fpga_reset(const struct device *dev)
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 @@ static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
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 @@ static inline int fpga_on(const struct device *dev)
return api->on(dev);
}
#define FPGA_GET_INFO_DEFAULT "n/a"
/**
* @brief Returns information about the FPGA.
*
@ -128,6 +145,10 @@ static inline const char *fpga_get_info(const struct device *dev)
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);
}