From 40b002175491cae67878c8cccb7b831a988a5ff6 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 28 Nov 2024 08:35:43 +0100 Subject: [PATCH] drivers: i2c: Place API into iterable section Add wrapper DEVICE_API macro to all i2c_driver_api instances. Signed-off-by: Pieter De Gendt --- drivers/i2c/gpio_i2c_switch.c | 2 +- drivers/i2c/i2c_ambiq.c | 2 +- drivers/i2c/i2c_andes_atciic100.c | 2 +- drivers/i2c/i2c_b91.c | 2 +- drivers/i2c/i2c_bcm_iproc.c | 2 +- drivers/i2c/i2c_cc13xx_cc26xx.c | 2 +- drivers/i2c/i2c_cc32xx.c | 2 +- drivers/i2c/i2c_dw.c | 2 +- drivers/i2c/i2c_emul.c | 2 +- drivers/i2c/i2c_ene_kb1200.c | 2 +- drivers/i2c/i2c_esp32.c | 2 +- drivers/i2c/i2c_gd32.c | 2 +- drivers/i2c/i2c_gecko.c | 2 +- drivers/i2c/i2c_gpio.c | 2 +- drivers/i2c/i2c_ifx_cat1.c | 2 +- drivers/i2c/i2c_ifx_xmc4.c | 2 +- drivers/i2c/i2c_imx.c | 2 +- drivers/i2c/i2c_ite_enhance.c | 2 +- drivers/i2c/i2c_ite_it8xxx2.c | 2 +- drivers/i2c/i2c_litex.c | 2 +- drivers/i2c/i2c_ll_stm32.c | 2 +- drivers/i2c/i2c_lpc11u6x.c | 2 +- drivers/i2c/i2c_max32.c | 2 +- drivers/i2c/i2c_mchp_mss.c | 2 +- drivers/i2c/i2c_mchp_xec.c | 2 +- drivers/i2c/i2c_mchp_xec_v2.c | 2 +- drivers/i2c/i2c_mcux.c | 2 +- drivers/i2c/i2c_mcux_flexcomm.c | 2 +- drivers/i2c/i2c_mcux_lpi2c.c | 2 +- drivers/i2c/i2c_mcux_lpi2c_rtio.c | 2 +- drivers/i2c/i2c_nios2.c | 2 +- drivers/i2c/i2c_npcx_port.c | 2 +- drivers/i2c/i2c_nrfx_twi.c | 2 +- drivers/i2c/i2c_nrfx_twi_rtio.c | 2 +- drivers/i2c/i2c_nrfx_twim.c | 2 +- drivers/i2c/i2c_nrfx_twim_rtio.c | 2 +- drivers/i2c/i2c_numaker.c | 2 +- drivers/i2c/i2c_rcar.c | 2 +- drivers/i2c/i2c_renesas_ra_iic.c | 2 +- drivers/i2c/i2c_rv32m1_lpi2c.c | 2 +- drivers/i2c/i2c_sam0.c | 2 +- drivers/i2c/i2c_sam4l_twim.c | 2 +- drivers/i2c/i2c_sam_twi.c | 2 +- drivers/i2c/i2c_sam_twihs.c | 2 +- drivers/i2c/i2c_sam_twihs_rtio.c | 2 +- drivers/i2c/i2c_sbcon.c | 2 +- drivers/i2c/i2c_sc18im704.c | 2 +- drivers/i2c/i2c_sedi.c | 2 +- drivers/i2c/i2c_sifive.c | 2 +- drivers/i2c/i2c_smartbond.c | 2 +- drivers/i2c/i2c_tca954x.c | 2 +- drivers/i2c/i2c_test.c | 2 +- drivers/i2c/i2c_xilinx_axi.c | 2 +- include/zephyr/drivers/i2c.h | 56 ++++++------------- .../i2c/i2c_target_api/common/i2c_virtual.c | 2 +- 55 files changed, 71 insertions(+), 93 deletions(-) diff --git a/drivers/i2c/gpio_i2c_switch.c b/drivers/i2c/gpio_i2c_switch.c index 1564f37006679aa..a0b8166edbb72f1 100644 --- a/drivers/i2c/gpio_i2c_switch.c +++ b/drivers/i2c/gpio_i2c_switch.c @@ -64,7 +64,7 @@ static int gpio_i2c_switch_transfer(const struct device *dev, struct i2c_msg *ms return res; } -static const struct i2c_driver_api gpio_i2c_switch_api_funcs = { +static DEVICE_API(i2c, gpio_i2c_switch_api_funcs) = { .configure = gpio_i2c_switch_configure, .transfer = gpio_i2c_switch_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_ambiq.c b/drivers/i2c/i2c_ambiq.c index 69492b5a60861d0..50536a5dd531355 100644 --- a/drivers/i2c/i2c_ambiq.c +++ b/drivers/i2c/i2c_ambiq.c @@ -381,7 +381,7 @@ static int i2c_ambiq_init(const struct device *dev) return ret; } -static const struct i2c_driver_api i2c_ambiq_driver_api = { +static DEVICE_API(i2c, i2c_ambiq_driver_api) = { .configure = i2c_ambiq_configure, .transfer = i2c_ambiq_transfer, #if CONFIG_I2C_AMBIQ_BUS_RECOVERY diff --git a/drivers/i2c/i2c_andes_atciic100.c b/drivers/i2c/i2c_andes_atciic100.c index 3f1b4b9c3d28976..60e39c040c60da8 100644 --- a/drivers/i2c/i2c_andes_atciic100.c +++ b/drivers/i2c/i2c_andes_atciic100.c @@ -732,7 +732,7 @@ static void i2c_atciic100_irq_handler(void *arg) } } -static const struct i2c_driver_api i2c_atciic100_driver = { +static DEVICE_API(i2c, i2c_atciic100_driver) = { .configure = (i2c_api_configure_t)i2c_atciic100_configure, .transfer = (i2c_api_full_io_t)i2c_atciic100_transfer, #if defined(CONFIG_I2C_TARGET) diff --git a/drivers/i2c/i2c_b91.c b/drivers/i2c/i2c_b91.c index f7b25f54fd1e2c9..2681ef6e26fb467 100644 --- a/drivers/i2c/i2c_b91.c +++ b/drivers/i2c/i2c_b91.c @@ -147,7 +147,7 @@ static int i2c_b91_init(const struct device *dev) } /* I2C driver APIs structure */ -static const struct i2c_driver_api i2c_b91_api = { +static DEVICE_API(i2c, i2c_b91_api) = { .configure = i2c_b91_configure, .transfer = i2c_b91_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_bcm_iproc.c b/drivers/i2c/i2c_bcm_iproc.c index 18f6afb0ae68de7..f424ab97e648d62 100644 --- a/drivers/i2c/i2c_bcm_iproc.c +++ b/drivers/i2c/i2c_bcm_iproc.c @@ -916,7 +916,7 @@ static int iproc_i2c_init(const struct device *dev) return 0; } -static const struct i2c_driver_api iproc_i2c_driver_api = { +static DEVICE_API(i2c, iproc_i2c_driver_api) = { .configure = iproc_i2c_configure, .transfer = iproc_i2c_transfer_multi, #ifdef CONFIG_I2C_TARGET diff --git a/drivers/i2c/i2c_cc13xx_cc26xx.c b/drivers/i2c/i2c_cc13xx_cc26xx.c index d06ffe3c5cb6cd2..e475be674ca7e4d 100644 --- a/drivers/i2c/i2c_cc13xx_cc26xx.c +++ b/drivers/i2c/i2c_cc13xx_cc26xx.c @@ -419,7 +419,7 @@ static int i2c_cc13xx_cc26xx_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_cc13xx_cc26xx_driver_api = { +static DEVICE_API(i2c, i2c_cc13xx_cc26xx_driver_api) = { .configure = i2c_cc13xx_cc26xx_configure, .transfer = i2c_cc13xx_cc26xx_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_cc32xx.c b/drivers/i2c/i2c_cc32xx.c index 57fee7617990530..a5ce43b4a7aa437 100644 --- a/drivers/i2c/i2c_cc32xx.c +++ b/drivers/i2c/i2c_cc32xx.c @@ -379,7 +379,7 @@ static int i2c_cc32xx_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_cc32xx_driver_api = { +static DEVICE_API(i2c, i2c_cc32xx_driver_api) = { .configure = i2c_cc32xx_configure, .transfer = i2c_cc32xx_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_dw.c b/drivers/i2c/i2c_dw.c index 5d274dcf0adcd07..029fc1e58a1efdf 100644 --- a/drivers/i2c/i2c_dw.c +++ b/drivers/i2c/i2c_dw.c @@ -1023,7 +1023,7 @@ static void i2c_dw_slave_read_clear_intr_bits(const struct device *dev) } #endif /* CONFIG_I2C_TARGET */ -static const struct i2c_driver_api funcs = { +static DEVICE_API(i2c, funcs) = { .configure = i2c_dw_runtime_configure, .transfer = i2c_dw_transfer, #ifdef CONFIG_I2C_TARGET diff --git a/drivers/i2c/i2c_emul.c b/drivers/i2c/i2c_emul.c index 5554ce81b5c65d6..ee2ae8d3975b75c 100644 --- a/drivers/i2c/i2c_emul.c +++ b/drivers/i2c/i2c_emul.c @@ -292,7 +292,7 @@ static int i2c_emul_target_unregister(const struct device *dev, struct i2c_targe /* Device instantiation */ -static const struct i2c_driver_api i2c_emul_api = { +static DEVICE_API(i2c, i2c_emul_api) = { .configure = i2c_emul_configure, .get_config = i2c_emul_get_config, .transfer = i2c_emul_transfer, diff --git a/drivers/i2c/i2c_ene_kb1200.c b/drivers/i2c/i2c_ene_kb1200.c index 322efd2e30c51e1..359f99793e42e26 100644 --- a/drivers/i2c/i2c_ene_kb1200.c +++ b/drivers/i2c/i2c_ene_kb1200.c @@ -293,7 +293,7 @@ static int i2c_kb1200_transfer(const struct device *dev, struct i2c_msg *msgs, u } /* I2C Master driver registration */ -static const struct i2c_driver_api i2c_kb1200_api = { +static DEVICE_API(i2c, i2c_kb1200_api) = { .configure = i2c_kb1200_configure, .get_config = i2c_kb1200_get_config, .transfer = i2c_kb1200_transfer, diff --git a/drivers/i2c/i2c_esp32.c b/drivers/i2c/i2c_esp32.c index 07c8ea536caf65f..a46e76f31a77f1a 100644 --- a/drivers/i2c/i2c_esp32.c +++ b/drivers/i2c/i2c_esp32.c @@ -722,7 +722,7 @@ static void IRAM_ATTR i2c_esp32_isr(void *arg) k_sem_give(&data->cmd_sem); } -static const struct i2c_driver_api i2c_esp32_driver_api = { +static DEVICE_API(i2c, i2c_esp32_driver_api) = { .configure = i2c_esp32_configure, .get_config = i2c_esp32_get_config, .transfer = i2c_esp32_transfer, diff --git a/drivers/i2c/i2c_gd32.c b/drivers/i2c/i2c_gd32.c index 9b6d6f5e4e61660..381911fafb79c1f 100644 --- a/drivers/i2c/i2c_gd32.c +++ b/drivers/i2c/i2c_gd32.c @@ -641,7 +641,7 @@ static int i2c_gd32_configure(const struct device *dev, return err; } -static const struct i2c_driver_api i2c_gd32_driver_api = { +static DEVICE_API(i2c, i2c_gd32_driver_api) = { .configure = i2c_gd32_configure, .transfer = i2c_gd32_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_gecko.c b/drivers/i2c/i2c_gecko.c index e2d44f3989c40e1..373eb231f9ac49e 100644 --- a/drivers/i2c/i2c_gecko.c +++ b/drivers/i2c/i2c_gecko.c @@ -216,7 +216,7 @@ static int i2c_gecko_target_unregister(const struct device *dev, struct i2c_targ } #endif -static const struct i2c_driver_api i2c_gecko_driver_api = { +static DEVICE_API(i2c, i2c_gecko_driver_api) = { .configure = i2c_gecko_configure, .transfer = i2c_gecko_transfer, #if defined(CONFIG_I2C_TARGET) diff --git a/drivers/i2c/i2c_gpio.c b/drivers/i2c/i2c_gpio.c index 80a1a221490f355..406b10af8634f07 100644 --- a/drivers/i2c/i2c_gpio.c +++ b/drivers/i2c/i2c_gpio.c @@ -140,7 +140,7 @@ static int i2c_gpio_recover_bus(const struct device *dev) return rc; } -static const struct i2c_driver_api api = { +static DEVICE_API(i2c, api) = { .configure = i2c_gpio_configure, .get_config = i2c_gpio_get_config, .transfer = i2c_gpio_transfer, diff --git a/drivers/i2c/i2c_ifx_cat1.c b/drivers/i2c/i2c_ifx_cat1.c index 90bf9c1e68b45ee..3759be1d981f72c 100644 --- a/drivers/i2c/i2c_ifx_cat1.c +++ b/drivers/i2c/i2c_ifx_cat1.c @@ -492,7 +492,7 @@ static int ifx_cat1_i2c_target_unregister(const struct device *dev, struct i2c_t } /* I2C API structure */ -static const struct i2c_driver_api i2c_cat1_driver_api = { +static DEVICE_API(i2c, i2c_cat1_driver_api) = { .configure = ifx_cat1_i2c_configure, .transfer = ifx_cat1_i2c_transfer, .get_config = ifx_cat1_i2c_get_config, diff --git a/drivers/i2c/i2c_ifx_xmc4.c b/drivers/i2c/i2c_ifx_xmc4.c index 253445809c3834d..789f4f408f714e7 100644 --- a/drivers/i2c/i2c_ifx_xmc4.c +++ b/drivers/i2c/i2c_ifx_xmc4.c @@ -425,7 +425,7 @@ static void i2c_xmc4_isr(const struct device *dev) /* I2C API structure */ -static const struct i2c_driver_api i2c_xmc4_driver_api = { +static DEVICE_API(i2c, i2c_xmc4_driver_api) = { .configure = ifx_xmc4_i2c_configure, .transfer = ifx_xmc4_i2c_transfer, .get_config = ifx_xmc4_i2c_get_config, diff --git a/drivers/i2c/i2c_imx.c b/drivers/i2c/i2c_imx.c index eba04101693f8d0..d2c99ef9a8022ce 100644 --- a/drivers/i2c/i2c_imx.c +++ b/drivers/i2c/i2c_imx.c @@ -360,7 +360,7 @@ static int i2c_imx_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_imx_driver_api = { +static DEVICE_API(i2c, i2c_imx_driver_api) = { .configure = i2c_imx_configure, .transfer = i2c_imx_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_ite_enhance.c b/drivers/i2c/i2c_ite_enhance.c index 1264bcec844914e..e67083218ff7931 100644 --- a/drivers/i2c/i2c_ite_enhance.c +++ b/drivers/i2c/i2c_ite_enhance.c @@ -1452,7 +1452,7 @@ static int i2c_enhance_target_unregister(const struct device *dev, } #endif -static const struct i2c_driver_api i2c_enhance_driver_api = { +static DEVICE_API(i2c, i2c_enhance_driver_api) = { .configure = i2c_enhance_configure, .get_config = i2c_enhance_get_config, .transfer = i2c_enhance_transfer, diff --git a/drivers/i2c/i2c_ite_it8xxx2.c b/drivers/i2c/i2c_ite_it8xxx2.c index a9247734be3fc89..203eaaa3d339eac 100644 --- a/drivers/i2c/i2c_ite_it8xxx2.c +++ b/drivers/i2c/i2c_ite_it8xxx2.c @@ -1250,7 +1250,7 @@ static int i2c_it8xxx2_recover_bus(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_it8xxx2_driver_api = { +static DEVICE_API(i2c, i2c_it8xxx2_driver_api) = { .configure = i2c_it8xxx2_configure, .get_config = i2c_it8xxx2_get_config, .transfer = i2c_it8xxx2_transfer, diff --git a/drivers/i2c/i2c_litex.c b/drivers/i2c/i2c_litex.c index 38e0cfa8cfd7f2d..104829b6f7981db 100644 --- a/drivers/i2c/i2c_litex.c +++ b/drivers/i2c/i2c_litex.c @@ -136,7 +136,7 @@ static int i2c_litex_recover_bus(const struct device *dev) return i2c_bitbang_recover_bus(bitbang); } -static const struct i2c_driver_api i2c_litex_driver_api = { +static DEVICE_API(i2c, i2c_litex_driver_api) = { .configure = i2c_litex_configure, .get_config = i2c_litex_get_config, .transfer = i2c_litex_transfer, diff --git a/drivers/i2c/i2c_ll_stm32.c b/drivers/i2c/i2c_ll_stm32.c index 677d1f688e5a27b..36aa57482ff78cb 100644 --- a/drivers/i2c/i2c_ll_stm32.c +++ b/drivers/i2c/i2c_ll_stm32.c @@ -310,7 +310,7 @@ static int i2c_stm32_recover_bus(const struct device *dev) } #endif /* CONFIG_I2C_STM32_BUS_RECOVERY */ -static const struct i2c_driver_api api_funcs = { +static DEVICE_API(i2c, api_funcs) = { .configure = i2c_stm32_runtime_configure, .transfer = i2c_stm32_transfer, .get_config = i2c_stm32_get_config, diff --git a/drivers/i2c/i2c_lpc11u6x.c b/drivers/i2c/i2c_lpc11u6x.c index 2a32822be5c3cdb..a00ac10dd5c6f39 100644 --- a/drivers/i2c/i2c_lpc11u6x.c +++ b/drivers/i2c/i2c_lpc11u6x.c @@ -340,7 +340,7 @@ static int lpc11u6x_i2c_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_api = { +static DEVICE_API(i2c, i2c_api) = { .configure = lpc11u6x_i2c_configure, .transfer = lpc11u6x_i2c_transfer, .target_register = lpc11u6x_i2c_slave_register, diff --git a/drivers/i2c/i2c_max32.c b/drivers/i2c/i2c_max32.c index e08612114323b7b..c42f837bf3efe76 100644 --- a/drivers/i2c/i2c_max32.c +++ b/drivers/i2c/i2c_max32.c @@ -832,7 +832,7 @@ static void i2c_max32_isr(const struct device *dev) } #endif /* CONFIG_I2C_TARGET || CONFIG_I2C_MAX32_INTERRUPT */ -static const struct i2c_driver_api api = { +static DEVICE_API(i2c, api) = { .configure = api_configure, .transfer = api_transfer, #ifdef CONFIG_I2C_TARGET diff --git a/drivers/i2c/i2c_mchp_mss.c b/drivers/i2c/i2c_mchp_mss.c index ef132c6182cbf22..25e4e7c094a5f2e 100644 --- a/drivers/i2c/i2c_mchp_mss.c +++ b/drivers/i2c/i2c_mchp_mss.c @@ -232,7 +232,7 @@ static int mss_i2c_transfer(const struct device *dev, struct i2c_msg *msgs, uint return 0; } -static const struct i2c_driver_api mss_i2c_driver_api = { +static DEVICE_API(i2c, mss_i2c_driver_api) = { .configure = mss_i2c_configure, .transfer = mss_i2c_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_mchp_xec.c b/drivers/i2c/i2c_mchp_xec.c index 6f48e9404b15c38..e1376470ff405dc 100644 --- a/drivers/i2c/i2c_mchp_xec.c +++ b/drivers/i2c/i2c_mchp_xec.c @@ -829,7 +829,7 @@ static int i2c_xec_target_unregister(const struct device *dev, } #endif -static const struct i2c_driver_api i2c_xec_driver_api = { +static DEVICE_API(i2c, i2c_xec_driver_api) = { .configure = i2c_xec_configure, .transfer = i2c_xec_transfer, #ifdef CONFIG_I2C_TARGET diff --git a/drivers/i2c/i2c_mchp_xec_v2.c b/drivers/i2c/i2c_mchp_xec_v2.c index c0ab170ba03ef67..4feda66823ef693 100644 --- a/drivers/i2c/i2c_mchp_xec_v2.c +++ b/drivers/i2c/i2c_mchp_xec_v2.c @@ -1033,7 +1033,7 @@ static int i2c_xec_target_unregister(const struct device *dev, } #endif -static const struct i2c_driver_api i2c_xec_driver_api = { +static DEVICE_API(i2c, i2c_xec_driver_api) = { .configure = i2c_xec_configure, .transfer = i2c_xec_transfer, #ifdef CONFIG_I2C_TARGET diff --git a/drivers/i2c/i2c_mcux.c b/drivers/i2c/i2c_mcux.c index aaf6b0116a6de51..1ef10cc402060a5 100644 --- a/drivers/i2c/i2c_mcux.c +++ b/drivers/i2c/i2c_mcux.c @@ -342,7 +342,7 @@ static int i2c_mcux_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_mcux_driver_api = { +static DEVICE_API(i2c, i2c_mcux_driver_api) = { .configure = i2c_mcux_configure, .transfer = i2c_mcux_transfer, #ifdef CONFIG_I2C_CALLBACK diff --git a/drivers/i2c/i2c_mcux_flexcomm.c b/drivers/i2c/i2c_mcux_flexcomm.c index 158deacc6dedd75..51b8bfe1f0d1323 100644 --- a/drivers/i2c/i2c_mcux_flexcomm.c +++ b/drivers/i2c/i2c_mcux_flexcomm.c @@ -519,7 +519,7 @@ static int mcux_flexcomm_init(const struct device *dev) return 0; } -static const struct i2c_driver_api mcux_flexcomm_driver_api = { +static DEVICE_API(i2c, mcux_flexcomm_driver_api) = { .configure = mcux_flexcomm_configure, .transfer = mcux_flexcomm_transfer, #if defined(CONFIG_I2C_TARGET) diff --git a/drivers/i2c/i2c_mcux_lpi2c.c b/drivers/i2c/i2c_mcux_lpi2c.c index 0bb7e2d402f96d9..dbc11438b6e35c7 100644 --- a/drivers/i2c/i2c_mcux_lpi2c.c +++ b/drivers/i2c/i2c_mcux_lpi2c.c @@ -550,7 +550,7 @@ static int mcux_lpi2c_init(const struct device *dev) return 0; } -static const struct i2c_driver_api mcux_lpi2c_driver_api = { +static DEVICE_API(i2c, mcux_lpi2c_driver_api) = { .configure = mcux_lpi2c_configure, .transfer = mcux_lpi2c_transfer, #if CONFIG_I2C_MCUX_LPI2C_BUS_RECOVERY diff --git a/drivers/i2c/i2c_mcux_lpi2c_rtio.c b/drivers/i2c/i2c_mcux_lpi2c_rtio.c index 6b10994585deb7b..eae777e14c0bebb 100644 --- a/drivers/i2c/i2c_mcux_lpi2c_rtio.c +++ b/drivers/i2c/i2c_mcux_lpi2c_rtio.c @@ -332,7 +332,7 @@ static int mcux_lpi2c_init(const struct device *dev) return 0; } -static const struct i2c_driver_api mcux_lpi2c_driver_api = { +static DEVICE_API(i2c, mcux_lpi2c_driver_api) = { .configure = mcux_lpi2c_configure, .transfer = mcux_lpi2c_transfer, .iodev_submit = mcux_lpi2c_submit, diff --git a/drivers/i2c/i2c_nios2.c b/drivers/i2c/i2c_nios2.c index bbd1cf2223a5e6f..c146aa210c67464 100644 --- a/drivers/i2c/i2c_nios2.c +++ b/drivers/i2c/i2c_nios2.c @@ -152,7 +152,7 @@ static void i2c_nios2_isr(const struct device *dev) static int i2c_nios2_init(const struct device *dev); -static const struct i2c_driver_api i2c_nios2_driver_api = { +static DEVICE_API(i2c, i2c_nios2_driver_api) = { .configure = i2c_nios2_configure, .transfer = i2c_nios2_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_npcx_port.c b/drivers/i2c/i2c_npcx_port.c index 176389095617234..8a3d98c07e765b3 100644 --- a/drivers/i2c/i2c_npcx_port.c +++ b/drivers/i2c/i2c_npcx_port.c @@ -200,7 +200,7 @@ static int i2c_npcx_port_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_port_npcx_driver_api = { +static DEVICE_API(i2c, i2c_port_npcx_driver_api) = { .configure = i2c_npcx_port_configure, .get_config = i2c_npcx_port_get_config, .transfer = i2c_npcx_port_transfer, diff --git a/drivers/i2c/i2c_nrfx_twi.c b/drivers/i2c/i2c_nrfx_twi.c index 56d3727e125ef7f..c2c0a28d8756e57 100644 --- a/drivers/i2c/i2c_nrfx_twi.c +++ b/drivers/i2c/i2c_nrfx_twi.c @@ -125,7 +125,7 @@ static void event_handler(nrfx_twi_evt_t const *p_event, void *p_context) k_sem_give(&dev_data->completion_sync); } -static const struct i2c_driver_api i2c_nrfx_twi_driver_api = { +static DEVICE_API(i2c, i2c_nrfx_twi_driver_api) = { .configure = i2c_nrfx_twi_configure, .transfer = i2c_nrfx_twi_transfer, .recover_bus = i2c_nrfx_twi_recover_bus, diff --git a/drivers/i2c/i2c_nrfx_twi_rtio.c b/drivers/i2c/i2c_nrfx_twi_rtio.c index 1eb9b3762b297d6..9dc1b54914cd6ab 100644 --- a/drivers/i2c/i2c_nrfx_twi_rtio.c +++ b/drivers/i2c/i2c_nrfx_twi_rtio.c @@ -152,7 +152,7 @@ static void i2c_nrfx_twi_rtio_submit(const struct device *dev, struct rtio_iodev } } -static const struct i2c_driver_api i2c_nrfx_twi_rtio_driver_api = { +static DEVICE_API(i2c, i2c_nrfx_twi_rtio_driver_api) = { .configure = i2c_nrfx_twi_rtio_configure, .transfer = i2c_nrfx_twi_rtio_transfer, .recover_bus = i2c_nrfx_twi_rtio_recover_bus, diff --git a/drivers/i2c/i2c_nrfx_twim.c b/drivers/i2c/i2c_nrfx_twim.c index 9609709d8c354f4..f3d23521dd6eb90 100644 --- a/drivers/i2c/i2c_nrfx_twim.c +++ b/drivers/i2c/i2c_nrfx_twim.c @@ -204,7 +204,7 @@ static int i2c_nrfx_twim_init(const struct device *dev) return i2c_nrfx_twim_common_init(dev); } -static const struct i2c_driver_api i2c_nrfx_twim_driver_api = { +static DEVICE_API(i2c, i2c_nrfx_twim_driver_api) = { .configure = i2c_nrfx_twim_configure, .transfer = i2c_nrfx_twim_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_nrfx_twim_rtio.c b/drivers/i2c/i2c_nrfx_twim_rtio.c index ad4554332639b90..39c0380fb4cdb7d 100644 --- a/drivers/i2c/i2c_nrfx_twim_rtio.c +++ b/drivers/i2c/i2c_nrfx_twim_rtio.c @@ -148,7 +148,7 @@ static void event_handler(nrfx_twim_evt_t const *p_event, void *p_context) i2c_nrfx_twim_rtio_complete(dev, status); } -static const struct i2c_driver_api i2c_nrfx_twim_driver_api = { +static DEVICE_API(i2c, i2c_nrfx_twim_driver_api) = { .configure = i2c_nrfx_twim_rtio_configure, .transfer = i2c_nrfx_twim_rtio_transfer, .recover_bus = i2c_nrfx_twim_rtio_recover_bus, diff --git a/drivers/i2c/i2c_numaker.c b/drivers/i2c/i2c_numaker.c index 9441db55ca0e5bb..df2076becac35d6 100644 --- a/drivers/i2c/i2c_numaker.c +++ b/drivers/i2c/i2c_numaker.c @@ -732,7 +732,7 @@ static int i2c_numaker_init(const struct device *dev) return err; } -static const struct i2c_driver_api i2c_numaker_driver_api = { +static DEVICE_API(i2c, i2c_numaker_driver_api) = { .configure = i2c_numaker_configure, .get_config = i2c_numaker_get_config, .transfer = i2c_numaker_transfer, diff --git a/drivers/i2c/i2c_rcar.c b/drivers/i2c/i2c_rcar.c index 495579bb1e4315f..e8b7cd89505450f 100644 --- a/drivers/i2c/i2c_rcar.c +++ b/drivers/i2c/i2c_rcar.c @@ -344,7 +344,7 @@ static int i2c_rcar_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_rcar_driver_api = { +static DEVICE_API(i2c, i2c_rcar_driver_api) = { .configure = i2c_rcar_configure, .transfer = i2c_rcar_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_renesas_ra_iic.c b/drivers/i2c/i2c_renesas_ra_iic.c index 98eb46f625d59ee..8643b0c3d2e70a4 100644 --- a/drivers/i2c/i2c_renesas_ra_iic.c +++ b/drivers/i2c/i2c_renesas_ra_iic.c @@ -473,7 +473,7 @@ static void calc_iic_master_clock_setting(const struct device *dev, const uint32 clk_cfg->brl_value, clk_cfg->brh_value, clk_cfg->cks_value); } -static const struct i2c_driver_api i2c_ra_iic_driver_api = { +static DEVICE_API(i2c, i2c_ra_iic_driver_api) = { .configure = i2c_ra_iic_configure, .get_config = i2c_ra_iic_get_config, .transfer = i2c_ra_iic_transfer, diff --git a/drivers/i2c/i2c_rv32m1_lpi2c.c b/drivers/i2c/i2c_rv32m1_lpi2c.c index a7bffef4d4b4d46..db378f7f104e9ad 100644 --- a/drivers/i2c/i2c_rv32m1_lpi2c.c +++ b/drivers/i2c/i2c_rv32m1_lpi2c.c @@ -255,7 +255,7 @@ static int rv32m1_lpi2c_init(const struct device *dev) return 0; } -static const struct i2c_driver_api rv32m1_lpi2c_driver_api = { +static DEVICE_API(i2c, rv32m1_lpi2c_driver_api) = { .configure = rv32m1_lpi2c_configure, .transfer = rv32m1_lpi2c_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_sam0.c b/drivers/i2c/i2c_sam0.c index ff0b6c67fb652c4..0f66844840795d9 100644 --- a/drivers/i2c/i2c_sam0.c +++ b/drivers/i2c/i2c_sam0.c @@ -772,7 +772,7 @@ static int i2c_sam0_initialize(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sam0_driver_api = { +static DEVICE_API(i2c, i2c_sam0_driver_api) = { .configure = i2c_sam0_configure, .transfer = i2c_sam0_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_sam4l_twim.c b/drivers/i2c/i2c_sam4l_twim.c index 3f8551267f76a9c..3abd1b8c3fdf557 100644 --- a/drivers/i2c/i2c_sam4l_twim.c +++ b/drivers/i2c/i2c_sam4l_twim.c @@ -588,7 +588,7 @@ static int i2c_sam_twim_initialize(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sam_twim_driver_api = { +static DEVICE_API(i2c, i2c_sam_twim_driver_api) = { .configure = i2c_sam_twim_configure, .transfer = i2c_sam_twim_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_sam_twi.c b/drivers/i2c/i2c_sam_twi.c index ad6a32778598897..2ef99caa907817b 100644 --- a/drivers/i2c/i2c_sam_twi.c +++ b/drivers/i2c/i2c_sam_twi.c @@ -350,7 +350,7 @@ static int i2c_sam_twi_initialize(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sam_twi_driver_api = { +static DEVICE_API(i2c, i2c_sam_twi_driver_api) = { .configure = i2c_sam_twi_configure, .transfer = i2c_sam_twi_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_sam_twihs.c b/drivers/i2c/i2c_sam_twihs.c index 4b1fda4ce573c70..0a5f4e0ade9daa5 100644 --- a/drivers/i2c/i2c_sam_twihs.c +++ b/drivers/i2c/i2c_sam_twihs.c @@ -321,7 +321,7 @@ static int i2c_sam_twihs_initialize(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sam_twihs_driver_api = { +static DEVICE_API(i2c, i2c_sam_twihs_driver_api) = { .configure = i2c_sam_twihs_configure, .transfer = i2c_sam_twihs_transfer, }; diff --git a/drivers/i2c/i2c_sam_twihs_rtio.c b/drivers/i2c/i2c_sam_twihs_rtio.c index bbece9d50e5065a..0f8cf5730d0982f 100644 --- a/drivers/i2c/i2c_sam_twihs_rtio.c +++ b/drivers/i2c/i2c_sam_twihs_rtio.c @@ -327,7 +327,7 @@ static int i2c_sam_twihs_initialize(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sam_twihs_driver_api = { +static DEVICE_API(i2c, i2c_sam_twihs_driver_api) = { .configure = i2c_sam_twihs_configure, .transfer = i2c_sam_twihs_transfer, .iodev_submit = i2c_sam_twihs_submit, diff --git a/drivers/i2c/i2c_sbcon.c b/drivers/i2c/i2c_sbcon.c index 0212593ed3e5304..bf77fcdf352bcc6 100644 --- a/drivers/i2c/i2c_sbcon.c +++ b/drivers/i2c/i2c_sbcon.c @@ -113,7 +113,7 @@ static int i2c_sbcon_recover_bus(const struct device *dev) return i2c_bitbang_recover_bus(&context->bitbang); } -static const struct i2c_driver_api api = { +static DEVICE_API(i2c, api) = { .configure = i2c_sbcon_configure, .get_config = i2c_sbcon_get_config, .transfer = i2c_sbcon_transfer, diff --git a/drivers/i2c/i2c_sc18im704.c b/drivers/i2c/i2c_sc18im704.c index 64ea3482b28afea..722772931ba286c 100644 --- a/drivers/i2c/i2c_sc18im704.c +++ b/drivers/i2c/i2c_sc18im704.c @@ -320,7 +320,7 @@ static int i2c_sc18im_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sc18im_driver_api = { +static DEVICE_API(i2c, i2c_sc18im_driver_api) = { .configure = i2c_sc18im_configure, .get_config = i2c_sc18im_get_config, .transfer = i2c_sc18im_transfer, diff --git a/drivers/i2c/i2c_sedi.c b/drivers/i2c/i2c_sedi.c index 00ec5e06d4a0f6f..e2646dc6b2385e4 100644 --- a/drivers/i2c/i2c_sedi.c +++ b/drivers/i2c/i2c_sedi.c @@ -112,7 +112,7 @@ static int i2c_sedi_api_full_io(const struct device *dev, struct i2c_msg *msgs, return ret; } -static const struct i2c_driver_api i2c_sedi_apis = { +static DEVICE_API(i2c, i2c_sedi_apis) = { .configure = i2c_sedi_api_configure, .transfer = i2c_sedi_api_full_io, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_sifive.c b/drivers/i2c/i2c_sifive.c index 54ba5a779e462b1..2677e530c09612c 100644 --- a/drivers/i2c/i2c_sifive.c +++ b/drivers/i2c/i2c_sifive.c @@ -316,7 +316,7 @@ static int i2c_sifive_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_sifive_api = { +static DEVICE_API(i2c, i2c_sifive_api) = { .configure = i2c_sifive_configure, .transfer = i2c_sifive_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_smartbond.c b/drivers/i2c/i2c_smartbond.c index c402251e49b0e2d..f7f2a5a0f1a7ef1 100644 --- a/drivers/i2c/i2c_smartbond.c +++ b/drivers/i2c/i2c_smartbond.c @@ -548,7 +548,7 @@ static void i2c_smartbond_isr(const struct device *dev) #define I2C_SMARTBOND_CONFIGURE(id) #endif -static const struct i2c_driver_api i2c_smartbond_driver_api = { +static DEVICE_API(i2c, i2c_smartbond_driver_api) = { .configure = i2c_smartbond_configure, .get_config = i2c_smartbond_get_config, .transfer = i2c_smartbond_transfer, diff --git a/drivers/i2c/i2c_tca954x.c b/drivers/i2c/i2c_tca954x.c index 572b8daaf62e012..ab8c3f0101341e8 100644 --- a/drivers/i2c/i2c_tca954x.c +++ b/drivers/i2c/i2c_tca954x.c @@ -153,7 +153,7 @@ static int tca954x_channel_init(const struct device *dev) return 0; } -static const struct i2c_driver_api tca954x_api_funcs = { +static DEVICE_API(i2c, tca954x_api_funcs) = { .configure = tca954x_configure, .transfer = tca954x_transfer, #ifdef CONFIG_I2C_RTIO diff --git a/drivers/i2c/i2c_test.c b/drivers/i2c/i2c_test.c index 89001f617827e2c..dfe994deae6e70f 100644 --- a/drivers/i2c/i2c_test.c +++ b/drivers/i2c/i2c_test.c @@ -27,7 +27,7 @@ static int vnd_i2c_transfer(const struct device *dev, return -ENOTSUP; } -static const struct i2c_driver_api vnd_i2c_api = { +static DEVICE_API(i2c, vnd_i2c_api) = { .configure = vnd_i2c_configure, .transfer = vnd_i2c_transfer, }; diff --git a/drivers/i2c/i2c_xilinx_axi.c b/drivers/i2c/i2c_xilinx_axi.c index 715deaa6bb71dc3..61f9108b536071c 100644 --- a/drivers/i2c/i2c_xilinx_axi.c +++ b/drivers/i2c/i2c_xilinx_axi.c @@ -620,7 +620,7 @@ static int i2c_xilinx_axi_init(const struct device *dev) return 0; } -static const struct i2c_driver_api i2c_xilinx_axi_driver_api = { +static DEVICE_API(i2c, i2c_xilinx_axi_driver_api) = { .configure = i2c_xilinx_axi_configure, .transfer = i2c_xilinx_axi_transfer, #if defined(CONFIG_I2C_TARGET) diff --git a/include/zephyr/drivers/i2c.h b/include/zephyr/drivers/i2c.h index 5f1c3fbe8ae4d3e..605b306384212d0 100644 --- a/include/zephyr/drivers/i2c.h +++ b/include/zephyr/drivers/i2c.h @@ -716,10 +716,7 @@ __syscall int i2c_configure(const struct device *dev, uint32_t dev_config); static inline int z_impl_i2c_configure(const struct device *dev, uint32_t dev_config) { - const struct i2c_driver_api *api = - (const struct i2c_driver_api *)dev->api; - - return api->configure(dev, dev_config); + return DEVICE_API_GET(i2c, dev)->configure(dev, dev_config); } /** @@ -746,13 +743,11 @@ __syscall int i2c_get_config(const struct device *dev, uint32_t *dev_config); static inline int z_impl_i2c_get_config(const struct device *dev, uint32_t *dev_config) { - const struct i2c_driver_api *api = (const struct i2c_driver_api *)dev->api; - - if (api->get_config == NULL) { + if (DEVICE_API_GET(i2c, dev)->get_config == NULL) { return -ENOSYS; } - return api->get_config(dev, dev_config); + return DEVICE_API_GET(i2c, dev)->get_config(dev, dev_config); } /** @@ -794,9 +789,6 @@ static inline int z_impl_i2c_transfer(const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr) { - const struct i2c_driver_api *api = - (const struct i2c_driver_api *)dev->api; - if (!num_msgs) { return 0; } @@ -805,7 +797,7 @@ static inline int z_impl_i2c_transfer(const struct device *dev, msgs[num_msgs - 1].flags |= I2C_MSG_STOP; } - int res = api->transfer(dev, msgs, num_msgs, addr); + int res = DEVICE_API_GET(i2c, dev)->transfer(dev, msgs, num_msgs, addr); i2c_xfer_stats(dev, msgs, num_msgs); @@ -847,10 +839,7 @@ static inline int i2c_transfer_cb(const struct device *dev, i2c_callback_t cb, void *userdata) { - const struct i2c_driver_api *api = - (const struct i2c_driver_api *)dev->api; - - if (api->transfer_cb == NULL) { + if (DEVICE_API_GET(i2c, dev)->transfer_cb == NULL) { return -ENOSYS; } @@ -863,7 +852,7 @@ static inline int i2c_transfer_cb(const struct device *dev, msgs[num_msgs - 1].flags |= I2C_MSG_STOP; } - return api->transfer_cb(dev, msgs, num_msgs, addr, cb, userdata); + return DEVICE_API_GET(i2c, dev)->transfer_cb(dev, msgs, num_msgs, addr, cb, userdata); } /** @@ -996,13 +985,12 @@ static inline int i2c_transfer_signal(const struct device *dev, uint16_t addr, struct k_poll_signal *sig) { - const struct i2c_driver_api *api = (const struct i2c_driver_api *)dev->api; - - if (api->transfer_cb == NULL) { + if (DEVICE_API_GET(i2c, dev)->transfer_cb == NULL) { return -ENOSYS; } - return api->transfer_cb(dev, msgs, num_msgs, addr, z_i2c_transfer_signal_cb, sig); + return DEVICE_API_GET(i2c, dev)->transfer_cb(dev, msgs, num_msgs, addr, + z_i2c_transfer_signal_cb, sig); } #endif /* CONFIG_POLL */ @@ -1034,13 +1022,12 @@ static inline void i2c_iodev_submit(struct rtio_iodev_sqe *iodev_sqe) { const struct i2c_dt_spec *dt_spec = (const struct i2c_dt_spec *)iodev_sqe->sqe.iodev->data; const struct device *dev = dt_spec->bus; - const struct i2c_driver_api *api = (const struct i2c_driver_api *)dev->api; - if (api->iodev_submit == NULL) { + if (DEVICE_API_GET(i2c, dev)->iodev_submit == NULL) { rtio_iodev_sqe_err(iodev_sqe, -ENOSYS); return; } - api->iodev_submit(dt_spec->bus, iodev_sqe); + DEVICE_API_GET(i2c, dev)->iodev_submit(dt_spec->bus, iodev_sqe); } extern const struct rtio_iodev_api i2c_iodev_api; @@ -1129,14 +1116,11 @@ __syscall int i2c_recover_bus(const struct device *dev); static inline int z_impl_i2c_recover_bus(const struct device *dev) { - const struct i2c_driver_api *api = - (const struct i2c_driver_api *)dev->api; - - if (api->recover_bus == NULL) { + if (DEVICE_API_GET(i2c, dev)->recover_bus == NULL) { return -ENOSYS; } - return api->recover_bus(dev); + return DEVICE_API_GET(i2c, dev)->recover_bus(dev); } /** @@ -1166,14 +1150,11 @@ static inline int z_impl_i2c_recover_bus(const struct device *dev) static inline int i2c_target_register(const struct device *dev, struct i2c_target_config *cfg) { - const struct i2c_driver_api *api = - (const struct i2c_driver_api *)dev->api; - - if (api->target_register == NULL) { + if (DEVICE_API_GET(i2c, dev)->target_register == NULL) { return -ENOSYS; } - return api->target_register(dev, cfg); + return DEVICE_API_GET(i2c, dev)->target_register(dev, cfg); } /** @@ -1195,14 +1176,11 @@ static inline int i2c_target_register(const struct device *dev, static inline int i2c_target_unregister(const struct device *dev, struct i2c_target_config *cfg) { - const struct i2c_driver_api *api = - (const struct i2c_driver_api *)dev->api; - - if (api->target_unregister == NULL) { + if (DEVICE_API_GET(i2c, dev)->target_unregister == NULL) { return -ENOSYS; } - return api->target_unregister(dev, cfg); + return DEVICE_API_GET(i2c, dev)->target_unregister(dev, cfg); } /** diff --git a/tests/drivers/i2c/i2c_target_api/common/i2c_virtual.c b/tests/drivers/i2c/i2c_target_api/common/i2c_virtual.c index d8833b69c0a128d..d647061185c69c3 100644 --- a/tests/drivers/i2c/i2c_target_api/common/i2c_virtual.c +++ b/tests/drivers/i2c/i2c_target_api/common/i2c_virtual.c @@ -204,7 +204,7 @@ static int i2c_virtual_transfer(const struct device *dev, struct i2c_msg *msg, return ret; } -static const struct i2c_driver_api api_funcs = { +static DEVICE_API(i2c, api_funcs) = { .configure = i2c_virtual_runtime_configure, .transfer = i2c_virtual_transfer, .target_register = i2c_virtual_target_register,