diff --git a/drivers/i3c/i3c_cdns.c b/drivers/i3c/i3c_cdns.c index 1690b33f9a43be6..e44ec1919ec0c50 100644 --- a/drivers/i3c/i3c_cdns.c +++ b/drivers/i3c/i3c_cdns.c @@ -3281,7 +3281,7 @@ static int cdns_i3c_bus_init(const struct device *dev) return 0; } -static struct i3c_driver_api api = { +static DEVICE_API(i3c, api) = { .i2c_api.configure = cdns_i3c_i2c_api_configure, .i2c_api.transfer = cdns_i3c_i2c_api_transfer, diff --git a/drivers/i3c/i3c_common.c b/drivers/i3c/i3c_common.c index 9e3783876b848da..75dc8be50338b90 100644 --- a/drivers/i3c/i3c_common.c +++ b/drivers/i3c/i3c_common.c @@ -242,6 +242,8 @@ int i3c_attach_i3c_device(struct i3c_device_desc *target) int status = 0; struct i3c_device_desc *i3c_desc; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); + /* check to see if the device has already been attached */ I3C_BUS_FOR_EACH_I3CDEV(target->bus, i3c_desc) { if (i3c_desc == target) { @@ -279,6 +281,8 @@ int i3c_reattach_i3c_device(struct i3c_device_desc *target, uint8_t old_dyn_addr const struct i3c_driver_api *api = (const struct i3c_driver_api *)target->bus->api; int status = 0; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); + if (!i3c_addr_slots_is_free(&data->attached_dev.addr_slots, target->dynamic_addr)) { return -EINVAL; } @@ -303,6 +307,8 @@ int i3c_detach_i3c_device(struct i3c_device_desc *target) const struct i3c_driver_api *api = (const struct i3c_driver_api *)target->bus->api; int status = 0; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); + if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) { if (!sys_slist_find_and_remove(&data->attached_dev.devices.i3c, &target->node)) { return -EINVAL; @@ -328,6 +334,8 @@ int i3c_attach_i2c_device(struct i3c_i2c_device_desc *target) int status = 0; struct i3c_i2c_device_desc *i3c_i2c_desc; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); + /* check to see if the device has already been attached */ I3C_BUS_FOR_EACH_I2CDEV(target->bus, i3c_i2c_desc) { if (i3c_i2c_desc == target) { @@ -356,6 +364,8 @@ int i3c_detach_i2c_device(struct i3c_i2c_device_desc *target) const struct i3c_driver_api *api = (const struct i3c_driver_api *)target->bus->api; int status = 0; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); + if (!sys_slist_is_empty(&data->attached_dev.devices.i2c)) { if (!sys_slist_find_and_remove(&data->attached_dev.devices.i2c, &target->node)) { return -EINVAL; diff --git a/drivers/i3c/i3c_mcux.c b/drivers/i3c/i3c_mcux.c index 3c81dd0d2249691..48c952cb816dc69 100644 --- a/drivers/i3c/i3c_mcux.c +++ b/drivers/i3c/i3c_mcux.c @@ -2090,7 +2090,7 @@ static int mcux_i3c_i2c_api_transfer(const struct device *dev, return ret; } -static const struct i3c_driver_api mcux_i3c_driver_api = { +static DEVICE_API(i3c, mcux_i3c_driver_api) = { .i2c_api.configure = mcux_i3c_i2c_api_configure, .i2c_api.transfer = mcux_i3c_i2c_api_transfer, .i2c_api.recover_bus = mcux_i3c_recover_bus, diff --git a/drivers/i3c/i3c_npcx.c b/drivers/i3c/i3c_npcx.c index 11b4c1efe9e0893..bde34aee040de43 100644 --- a/drivers/i3c/i3c_npcx.c +++ b/drivers/i3c/i3c_npcx.c @@ -2963,7 +2963,7 @@ static int npcx_i3c_init(const struct device *dev) return 0; } -static const struct i3c_driver_api npcx_i3c_driver_api = { +static DEVICE_API(i3c, npcx_i3c_driver_api) = { .configure = npcx_i3c_configure, .config_get = npcx_i3c_config_get, diff --git a/drivers/i3c/i3c_test.c b/drivers/i3c/i3c_test.c index 165449747d859bc..09586433ec954a0 100644 --- a/drivers/i3c/i3c_test.c +++ b/drivers/i3c/i3c_test.c @@ -32,7 +32,7 @@ static int vnd_i3c_recover_bus(const struct device *dev) return -ENOTSUP; } -static const struct i3c_driver_api vnd_i3c_api = { +static DEVICE_API(i3c, vnd_i3c_api) = { .configure = vnd_i3c_configure, .config_get = vnd_i3c_config_get, .recover_bus = vnd_i3c_recover_bus, diff --git a/include/zephyr/drivers/i3c.h b/include/zephyr/drivers/i3c.h index f3581663bfe44e4..6be6a5b034b45b5 100644 --- a/include/zephyr/drivers/i3c.h +++ b/include/zephyr/drivers/i3c.h @@ -1345,14 +1345,13 @@ int i3c_dev_list_daa_addr_helper(struct i3c_addr_slots *addr_slots, static inline int i3c_configure(const struct device *dev, enum i3c_config_type type, void *config) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->configure == NULL) { + if (DEVICE_API_GET(i3c, dev)->configure == NULL) { return -ENOSYS; } - return api->configure(dev, type, config); + return DEVICE_API_GET(i3c, dev)->configure(dev, type, config); } /** @@ -1378,14 +1377,13 @@ static inline int i3c_configure(const struct device *dev, static inline int i3c_config_get(const struct device *dev, enum i3c_config_type type, void *config) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->config_get == NULL) { + if (DEVICE_API_GET(i3c, dev)->config_get == NULL) { return -ENOSYS; } - return api->config_get(dev, type, config); + return DEVICE_API_GET(i3c, dev)->config_get(dev, type, config); } /** @@ -1400,14 +1398,13 @@ static inline int i3c_config_get(const struct device *dev, */ static inline int i3c_recover_bus(const struct device *dev) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->recover_bus == NULL) { + if (DEVICE_API_GET(i3c, dev)->recover_bus == NULL) { return -ENOSYS; } - return api->recover_bus(dev); + return DEVICE_API_GET(i3c, dev)->recover_bus(dev); } /** @@ -1542,14 +1539,13 @@ int i3c_detach_i2c_device(struct i3c_i2c_device_desc *target); */ static inline int i3c_do_daa(const struct device *dev) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->do_daa == NULL) { + if (DEVICE_API_GET(i3c, dev)->do_daa == NULL) { return -ENOSYS; } - return api->do_daa(dev); + return DEVICE_API_GET(i3c, dev)->do_daa(dev); } /** @@ -1571,14 +1567,13 @@ __syscall int i3c_do_ccc(const struct device *dev, static inline int z_impl_i3c_do_ccc(const struct device *dev, struct i3c_ccc_payload *payload) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->do_ccc == NULL) { + if (DEVICE_API_GET(i3c, dev)->do_ccc == NULL) { return -ENOSYS; } - return api->do_ccc(dev, payload); + return DEVICE_API_GET(i3c, dev)->do_ccc(dev, payload); } /** @@ -1618,10 +1613,9 @@ __syscall int i3c_transfer(struct i3c_device_desc *target, static inline int z_impl_i3c_transfer(struct i3c_device_desc *target, struct i3c_msg *msgs, uint8_t num_msgs) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)target->bus->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); - return api->i3c_xfers(target->bus, target, msgs, num_msgs); + return DEVICE_API_GET(i3c, target->bus)->i3c_xfers(target->bus, target, msgs, num_msgs); } /** @} */ @@ -1644,14 +1638,13 @@ static inline struct i3c_device_desc *i3c_device_find(const struct device *dev, const struct i3c_device_id *id) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->i3c_device_find == NULL) { + if (DEVICE_API_GET(i3c, dev)->i3c_device_find == NULL) { return NULL; } - return api->i3c_device_find(dev, id); + return DEVICE_API_GET(i3c, dev)->i3c_device_find(dev, id); } /** @@ -1673,14 +1666,13 @@ struct i3c_device_desc *i3c_device_find(const struct device *dev, static inline int i3c_ibi_raise(const struct device *dev, struct i3c_ibi *request) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->ibi_raise == NULL) { + if (DEVICE_API_GET(i3c, dev)->ibi_raise == NULL) { return -ENOSYS; } - return api->ibi_raise(dev, request); + return DEVICE_API_GET(i3c, dev)->ibi_raise(dev, request); } /** @@ -1699,14 +1691,13 @@ static inline int i3c_ibi_raise(const struct device *dev, */ static inline int i3c_ibi_enable(struct i3c_device_desc *target) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)target->bus->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); - if (api->ibi_enable == NULL) { + if (DEVICE_API_GET(i3c, target->bus)->ibi_enable == NULL) { return -ENOSYS; } - return api->ibi_enable(target->bus, target); + return DEVICE_API_GET(i3c, target->bus)->ibi_enable(target->bus, target); } /** @@ -1723,14 +1714,13 @@ static inline int i3c_ibi_enable(struct i3c_device_desc *target) */ static inline int i3c_ibi_disable(struct i3c_device_desc *target) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)target->bus->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, target->bus)); - if (api->ibi_disable == NULL) { + if (DEVICE_API_GET(i3c, target->bus)->ibi_disable == NULL) { return -ENOSYS; } - return api->ibi_disable(target->bus, target); + return DEVICE_API_GET(i3c, target->bus)->ibi_disable(target->bus, target); } /** diff --git a/include/zephyr/drivers/i3c/target_device.h b/include/zephyr/drivers/i3c/target_device.h index 7d85e03b001e639..6966bd4f69c20cc 100644 --- a/include/zephyr/drivers/i3c/target_device.h +++ b/include/zephyr/drivers/i3c/target_device.h @@ -295,14 +295,13 @@ __subsystem struct i3c_target_driver_api { static inline int i3c_target_tx_write(const struct device *dev, uint8_t *buf, uint16_t len, uint8_t hdr_mode) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->target_tx_write == NULL) { + if (DEVICE_API_GET(i3c, dev)->target_tx_write == NULL) { return -ENOSYS; } - return api->target_tx_write(dev, buf, len, hdr_mode); + return DEVICE_API_GET(i3c, dev)->target_tx_write(dev, buf, len, hdr_mode); } /** @@ -331,14 +330,13 @@ static inline int i3c_target_tx_write(const struct device *dev, static inline int i3c_target_register(const struct device *dev, struct i3c_target_config *cfg) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->target_register == NULL) { + if (DEVICE_API_GET(i3c, dev)->target_register == NULL) { return -ENOSYS; } - return api->target_register(dev, cfg); + return DEVICE_API_GET(i3c, dev)->target_register(dev, cfg); } /** @@ -360,14 +358,13 @@ static inline int i3c_target_register(const struct device *dev, static inline int i3c_target_unregister(const struct device *dev, struct i3c_target_config *cfg) { - const struct i3c_driver_api *api = - (const struct i3c_driver_api *)dev->api; + __ASSERT_NO_MSG(DEVICE_API_IS(i3c, dev)); - if (api->target_unregister == NULL) { + if (DEVICE_API_GET(i3c, dev)->target_unregister == NULL) { return -ENOSYS; } - return api->target_unregister(dev, cfg); + return DEVICE_API_GET(i3c, dev)->target_unregister(dev, cfg); } #ifdef __cplusplus