Skip to content

Commit

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

Signed-off-by: Pieter De Gendt <[email protected]>
  • Loading branch information
pdgendt committed Nov 28, 2024
1 parent bbca807 commit f7e694a
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 22 deletions.
10 changes: 10 additions & 0 deletions drivers/can/can_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ int z_impl_can_send(const struct device *dev, const struct can_frame *frame,
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
uint32_t id_mask;

__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

CHECKIF(frame == NULL) {
return -EINVAL;
}
Expand Down Expand Up @@ -81,6 +83,8 @@ int can_add_rx_filter(const struct device *dev, can_rx_callback_t callback,
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
uint32_t id_mask;

__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

CHECKIF(callback == NULL || filter == NULL) {
return -EINVAL;
}
Expand Down Expand Up @@ -123,6 +127,8 @@ int z_impl_can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq,
{
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);
}

Expand Down Expand Up @@ -388,6 +394,8 @@ int z_impl_can_set_timing(const struct device *dev,
const struct can_timing *max = can_get_timing_max(dev);
int err;

__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

err = check_timing_in_range(timing, min, max);
if (err != 0) {
return err;
Expand Down Expand Up @@ -430,6 +438,8 @@ int z_impl_can_set_timing_data(const struct device *dev,
const struct can_timing *max = can_get_timing_data_max(dev);
int err;

__ASSERT_NO_MSG(DEVICE_API_IS(can, dev));

if (api->set_timing_data == NULL) {
return -ENOSYS;
}
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 = {
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 = {
static DEVICE_API(can, mcux_flexcan_driver_api) __maybe_unused = {
.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

0 comments on commit f7e694a

Please sign in to comment.