Skip to content

Commit

Permalink
drivers: i3c: Place API into iterable section
Browse files Browse the repository at this point in the history
Add wrapper DEVICE_API macro to all i3c_driver_api instances.

Signed-off-by: Pieter De Gendt <[email protected]>
  • Loading branch information
pdgendt committed Nov 28, 2024
1 parent 8780d91 commit 8f080a4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 55 deletions.
2 changes: 1 addition & 1 deletion drivers/i3c/i3c_cdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
10 changes: 10 additions & 0 deletions drivers/i3c/i3c_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/i3c/i3c_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/i3c/i3c_npcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion drivers/i3c/i3c_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
68 changes: 29 additions & 39 deletions include/zephyr/drivers/i3c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/** @} */
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
21 changes: 9 additions & 12 deletions include/zephyr/drivers/i3c/target_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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
Expand Down

0 comments on commit 8f080a4

Please sign in to comment.