Skip to content

Commit

Permalink
drivers: can: update API to use DEIVCE_API macros
Browse files Browse the repository at this point in the history
Update can API and device drivers to use DEVICE_API macros.

Signed-off-by: Yishai Jaffe <[email protected]>
  • Loading branch information
yishai1999 committed Nov 28, 2024
1 parent 8780d91 commit e8f5c55
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 64 deletions.
28 changes: 16 additions & 12 deletions drivers/can/can_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ int z_impl_can_send(const struct device *dev, const struct can_frame *frame,
k_timeout_t timeout, can_tx_callback_t callback,
void *user_data)
{
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

uint32_t id_mask;

CHECKIF(frame == NULL) {
Expand All @@ -62,7 +63,7 @@ int z_impl_can_send(const struct device *dev, const struct can_frame *frame,

k_sem_init(&ctx.done, 0, 1);

err = api->send(dev, frame, timeout, can_tx_default_cb, &ctx);
err = DEVICE_API_GET(can, dev)->send(dev, frame, timeout, can_tx_default_cb, &ctx);
if (err != 0) {
return err;
}
Expand All @@ -72,13 +73,14 @@ int z_impl_can_send(const struct device *dev, const struct can_frame *frame,
return ctx.status;
}

return api->send(dev, frame, timeout, callback, user_data);
return DEVICE_API_GET(can, dev)->send(dev, frame, timeout, callback, user_data);
}

int can_add_rx_filter(const struct device *dev, can_rx_callback_t callback,
void *user_data, const struct can_filter *filter)
{
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

uint32_t id_mask;

CHECKIF(callback == NULL || filter == NULL) {
Expand All @@ -100,7 +102,7 @@ int can_add_rx_filter(const struct device *dev, can_rx_callback_t callback,
return -EINVAL;
}

return api->add_rx_filter(dev, callback, user_data, filter);
return DEVICE_API_GET(can, dev)->add_rx_filter(dev, callback, user_data, filter);
}

static void can_msgq_put(const struct device *dev, struct can_frame *frame, void *user_data)
Expand All @@ -121,9 +123,9 @@ static void can_msgq_put(const struct device *dev, struct can_frame *frame, void
int z_impl_can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq,
const struct can_filter *filter)
{
const struct can_driver_api *api = dev->api;
__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

return api->add_rx_filter(dev, can_msgq_put, msgq, filter);
return DEVICE_API_GET(can, dev)->add_rx_filter(dev, can_msgq_put, msgq, filter);
}

/**
Expand Down Expand Up @@ -383,7 +385,8 @@ static int check_timing_in_range(const struct can_timing *timing,
int z_impl_can_set_timing(const struct device *dev,
const struct can_timing *timing)
{
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

const struct can_timing *min = can_get_timing_min(dev);
const struct can_timing *max = can_get_timing_max(dev);
int err;
Expand All @@ -393,7 +396,7 @@ int z_impl_can_set_timing(const struct device *dev,
return err;
}

return api->set_timing(dev, timing);
return DEVICE_API_GET(can, dev)->set_timing(dev, timing);
}

int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate)
Expand Down Expand Up @@ -425,12 +428,13 @@ int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate)
int z_impl_can_set_timing_data(const struct device *dev,
const struct can_timing *timing_data)
{
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

const struct can_timing *min = can_get_timing_data_min(dev);
const struct can_timing *max = can_get_timing_data_max(dev);
int err;

if (api->set_timing_data == NULL) {
if (DEVICE_API_GET(can, dev)->set_timing_data == NULL) {
return -ENOSYS;
}

Expand All @@ -439,7 +443,7 @@ int z_impl_can_set_timing_data(const struct device *dev,
return err;
}

return api->set_timing_data(dev, timing_data);
return DEVICE_API_GET(can, dev)->set_timing_data(dev, timing_data);
}

int z_impl_can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data)
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_esp32_twai.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static int can_esp32_twai_init(const struct device *dev)
return err;
}

const struct can_driver_api can_esp32_twai_driver_api = {
static DEVICE_API(can, can_esp32_twai_driver_api) = {
.get_capabilities = can_sja1000_get_capabilities,
.start = can_sja1000_start,
.stop = can_sja1000_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_fake.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int fake_can_init(const struct device *dev)
return 0;
}

static const struct can_driver_api fake_can_driver_api = {
static DEVICE_API(can, fake_can_driver_api) = {
.start = fake_can_start,
.stop = fake_can_stop,
.get_capabilities = fake_can_get_capabilities,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_kvaser_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static int can_kvaser_pci_init(const struct device *dev)
return 0;
}

const struct can_driver_api can_kvaser_pci_driver_api = {
DEVICE_API(can, can_kvaser_pci_driver_api) = {
.get_capabilities = can_sja1000_get_capabilities,
.start = can_sja1000_start,
.stop = can_sja1000_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ static int can_loopback_get_max_filters(const struct device *dev, bool ide)
return CONFIG_CAN_MAX_FILTER;
}

static const struct can_driver_api can_loopback_driver_api = {
static DEVICE_API(can, can_loopback_driver_api) = {
.get_capabilities = can_loopback_get_capabilities,
.start = can_loopback_start,
.stop = can_loopback_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcp2515.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ static void mcp2515_int_gpio_callback(const struct device *dev,
k_sem_give(&dev_data->int_sem);
}

static const struct can_driver_api can_api_funcs = {
static DEVICE_API(can, can_api_funcs) = {
.get_capabilities = mcp2515_get_capabilities,
.set_timing = mcp2515_set_timing,
.start = mcp2515_start,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcp251xfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ static int mcp251xfd_init(const struct device *dev)
return ret;
}

static const struct can_driver_api mcp251xfd_api_funcs = {
static DEVICE_API(can, mcp251xfd_api_funcs) = {
.get_capabilities = mcp251xfd_get_capabilities,
.set_mode = mcp251xfd_set_mode,
.set_timing = mcp251xfd_set_timing,
Expand Down
4 changes: 2 additions & 2 deletions drivers/can/can_mcux_flexcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ static int mcux_flexcan_init(const struct device *dev)
return 0;
}

__maybe_unused static const struct can_driver_api mcux_flexcan_driver_api = {
__maybe_unused static DEVICE_API(can, mcux_flexcan_driver_api) = {
.get_capabilities = mcux_flexcan_get_capabilities,
.start = mcux_flexcan_start,
.stop = mcux_flexcan_stop,
Expand Down Expand Up @@ -1299,7 +1299,7 @@ __maybe_unused static const struct can_driver_api mcux_flexcan_driver_api = {
};

#ifdef CONFIG_CAN_MCUX_FLEXCAN_FD
static const struct can_driver_api mcux_flexcan_fd_driver_api = {
static DEVICE_API(can, mcux_flexcan_fd_driver_api) = {
.get_capabilities = mcux_flexcan_get_capabilities,
.start = mcux_flexcan_start,
.stop = mcux_flexcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcux_mcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static int mcux_mcan_init(const struct device *dev)
return 0;
}

static const struct can_driver_api mcux_mcan_driver_api = {
static DEVICE_API(can, mcux_mcan_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_native_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static int can_native_linux_get_max_filters(const struct device *dev, bool ide)
return CONFIG_CAN_MAX_FILTER;
}

static const struct can_driver_api can_native_linux_driver_api = {
static DEVICE_API(can, can_native_linux_driver_api) = {
.start = can_native_linux_start,
.stop = can_native_linux_stop,
.get_capabilities = can_native_linux_get_capabilities,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int can_nrf_get_core_clock(const struct device *dev, uint32_t *rate)
return clock_control_get_rate(config->clock, NULL, rate);
}

static const struct can_driver_api can_nrf_api = {
static DEVICE_API(can, can_nrf_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int can_numaker_init(const struct device *dev)
return rc;
}

static const struct can_driver_api can_numaker_driver_api = {
static DEVICE_API(can, can_numaker_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_nxp_s32_canxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ static void can_nxp_s32_isr_error(const struct device *dev)
Canexcel_Ip_ErrIRQHandler(config->instance);
}

static const struct can_driver_api can_nxp_s32_driver_api = {
static DEVICE_API(can, can_nxp_s32_driver_api) = {
.get_capabilities = can_nxp_s32_get_capabilities,
.start = can_nxp_s32_start,
.stop = can_nxp_s32_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_rcar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ static int can_rcar_get_max_filters(const struct device *dev, bool ide)
return CONFIG_CAN_RCAR_MAX_FILTER;
}

static const struct can_driver_api can_rcar_driver_api = {
static DEVICE_API(can, can_rcar_driver_api) = {
.get_capabilities = can_rcar_get_capabilities,
.start = can_rcar_start,
.stop = can_rcar_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_renesas_ra.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ static int can_renesas_ra_init(const struct device *dev)
return 0;
}

static const struct can_driver_api can_renesas_ra_driver_api = {
static DEVICE_API(can, can_renesas_ra_driver_api) = {
.get_capabilities = can_renesas_ra_get_capabilities,
.start = can_renesas_ra_start,
.stop = can_renesas_ra_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int can_sam_init(const struct device *dev)
return ret;
}

static const struct can_driver_api can_sam_driver_api = {
static DEVICE_API(can, can_sam_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_sam0.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static int can_sam0_init(const struct device *dev)
return ret;
}

static const struct can_driver_api can_sam0_driver_api = {
static DEVICE_API(can, can_sam0_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_stm32_bxcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ static void can_stm32_remove_rx_filter(const struct device *dev, int filter_id)
k_mutex_unlock(&filter_mutex);
}

static const struct can_driver_api can_api_funcs = {
static DEVICE_API(can, can_api_funcs) = {
.get_capabilities = can_stm32_get_capabilities,
.start = can_stm32_start,
.stop = can_stm32_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_stm32_fdcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static int can_stm32fd_init(const struct device *dev)
return ret;
}

static const struct can_driver_api can_stm32fd_driver_api = {
static DEVICE_API(can, can_stm32fd_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_stm32h7_fdcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static int can_stm32h7_init(const struct device *dev)
return 0;
}

static const struct can_driver_api can_stm32h7_driver_api = {
static DEVICE_API(can, can_stm32h7_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_tcan4x5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ static int tcan4x5x_init(const struct device *dev)
return 0;
}

static const struct can_driver_api tcan4x5x_driver_api = {
static DEVICE_API(can, tcan4x5x_driver_api) = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_xmc4xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ static int can_xmc4xxx_init(const struct device *dev)
return can_set_timing(dev, &timing);
}

static const struct can_driver_api can_xmc4xxx_api_funcs = {
static DEVICE_API(can, can_xmc4xxx_api_funcs) = {
.get_capabilities = can_xmc4xxx_get_capabilities,
.set_mode = can_xmc4xxx_set_mode,
.set_timing = can_xmc4xxx_set_timing,
Expand Down
Loading

0 comments on commit e8f5c55

Please sign in to comment.