Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: adc: Place API into iterable section #72292

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/kernel/drivers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ High-level calls accessed through device-specific APIs, such as
:file:`i2c.h` or :file:`spi.h`, are usually intended as synchronous. Thus,
these calls should be blocking.

.. _device_driver_api:

Driver APIs
***********

Expand Down
7 changes: 7 additions & 0 deletions doc/releases/migration-guide-4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ LVGL
Device Drivers and Devicetree
*****************************

* Device driver APIs are placed into iterable sections (:github:`71773`) to allow for runtime
checking. See :ref:`device_driver_api` for more details.
The :c:macro:`DEVICE_API()` macro should be used by out-of-tree driver implementations for
the following driver classes:

* :c:struct:`adc_driver_api`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to do this in a separate PR for all modified driver classes after the corresponding PRs are merged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was going to do it in a follow-up to add the other entries.


Controller Area Network (CAN)
=============================

Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ad559x.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static int adc_ad559x_init(const struct device *dev)
#endif

#define ADC_AD559X_DRIVER_API(inst) \
static const struct adc_driver_api adc_ad559x_api##inst = { \
static DEVICE_API(adc, adc_ad559x_api##inst) = { \
.channel_setup = adc_ad559x_channel_setup, \
.read = adc_ad559x_read, \
.ref_internal = AD559X_ADC_VREF_MV * (1 + DT_INST_PROP(inst, double_input_range)), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ads1112.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ static int ads1112_init(const struct device *dev)
return rc;
}

static const struct adc_driver_api api = {
static DEVICE_API(adc, api) = {
.channel_setup = ads1112_channel_setup,
.read = ads1112_read,
.ref_internal = ADS1112_REF_INTERNAL,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ads1119.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ static int ads1119_init(const struct device *dev)
return rc;
}

static const struct adc_driver_api api = {
static DEVICE_API(adc, api) = {
.channel_setup = ads1119_channel_setup,
.read = ads1119_read,
.ref_internal = ADS1119_REF_INTERNAL,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ads114s0x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ static int ads114s0x_init(const struct device *dev)
return result;
}

static const struct adc_driver_api api = {
static DEVICE_API(adc, api) = {
.channel_setup = ads114s0x_channel_setup,
.read = ads114s0x_read,
.ref_internal = ADS114S0X_REF_INTERNAL,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ads1x1x.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ static int ads1x1x_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api ads1x1x_api = {
static DEVICE_API(adc, ads1x1x_api) = {
.channel_setup = ads1x1x_channel_setup,
.read = ads1x1x_read,
.ref_internal = 2048,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ads7052.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static int adc_ads7052_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api ads7052_api = {
static DEVICE_API(adc, ads7052_api) = {
.channel_setup = adc_ads7052_channel_setup,
.read = adc_ads7052_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
4 changes: 2 additions & 2 deletions drivers/adc/adc_ambiq.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,15 @@ static int adc_ambiq_pm_action(const struct device *dev, enum pm_device_action a

#ifdef CONFIG_ADC_ASYNC
#define ADC_AMBIQ_DRIVER_API(n) \
static const struct adc_driver_api adc_ambiq_driver_api_##n = { \
static DEVICE_API(adc, adc_ambiq_driver_api_##n) = { \
.channel_setup = adc_ambiq_channel_setup, \
.read = adc_ambiq_read, \
.read_async = adc_ambiq_read_async, \
.ref_internal = DT_INST_PROP(n, internal_vref_mv), \
};
#else
#define ADC_AMBIQ_DRIVER_API(n) \
static const struct adc_driver_api adc_ambiq_driver_api_##n = { \
static DEVICE_API(adc, adc_ambiq_driver_api_##n) = { \
.channel_setup = adc_ambiq_channel_setup, \
.read = adc_ambiq_read, \
.ref_internal = DT_INST_PROP(n, internal_vref_mv), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_b91.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static const struct b91_adc_cfg cfg_0 = {
.vref_internal_mv = DT_INST_PROP(0, vref_internal_mv),
};

static const struct adc_driver_api adc_b91_driver_api = {
static DEVICE_API(adc, adc_b91_driver_api) = {
.channel_setup = adc_b91_channel_setup,
.read = adc_b91_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void adc_cc13xx_cc26xx_isr(const struct device *dev)
adc_context_on_sampling_done(&data->ctx, dev);
}

static const struct adc_driver_api cc13xx_cc26xx_driver_api = {
static DEVICE_API(adc, cc13xx_cc26xx_driver_api) = {
.channel_setup = adc_cc13xx_cc26xx_channel_setup,
.read = adc_cc13xx_cc26xx_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_cc32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void adc_cc32xx_isr_ch3(const struct device *dev)
adc_cc32xx_isr(dev, 3);
}

static const struct adc_driver_api cc32xx_driver_api = {
static DEVICE_API(adc, cc32xx_driver_api) = {
.channel_setup = adc_cc32xx_channel_setup,
.read = adc_cc32xx_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
4 changes: 1 addition & 3 deletions drivers/adc/adc_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ int adc_emul_value_func_set(const struct device *dev, unsigned int chan,
int adc_emul_ref_voltage_set(const struct device *dev, enum adc_reference ref,
uint16_t value)
{
struct adc_driver_api *api = (struct adc_driver_api *)dev->api;
struct adc_emul_data *data = dev->data;
int err = 0;

Expand All @@ -167,7 +166,6 @@ int adc_emul_ref_voltage_set(const struct device *dev, enum adc_reference ref,
break;
case ADC_REF_INTERNAL:
data->ref_int = value;
api->ref_internal = value;
break;
case ADC_REF_EXTERNAL0:
data->ref_ext0 = value;
Expand Down Expand Up @@ -548,7 +546,7 @@ static int adc_emul_init(const struct device *dev)
}

#define ADC_EMUL_INIT(_num) \
static struct adc_driver_api adc_emul_api_##_num = { \
static DEVICE_API(adc, adc_emul_api_##_num) = { \
.channel_setup = adc_emul_channel_setup, \
.read = adc_emul_read, \
.ref_internal = DT_INST_PROP(_num, ref_internal_mv), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ene_kb1200.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx, bool repe
}
}

struct adc_driver_api adc_kb1200_api = {
static DEVICE_API(adc, adc_kb1200_api) = {
.channel_setup = adc_kb1200_channel_setup,
.read = adc_kb1200_read,
.ref_internal = ADC_VREF_ANALOG,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ static int adc_esp32_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api api_esp32_driver_api = {
static DEVICE_API(adc, api_esp32_driver_api) = {
.channel_setup = adc_esp32_channel_setup,
.read = adc_esp32_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_gd32.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static int adc_gd32_read_async(const struct device *dev,
}
#endif /* CONFIG_ADC_ASYNC */

static struct adc_driver_api adc_gd32_driver_api = {
static DEVICE_API(adc, adc_gd32_driver_api) = {
.channel_setup = adc_gd32_channel_setup,
.read = adc_gd32_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_gecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static int adc_gecko_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api api_gecko_adc_driver_api = {
static DEVICE_API(adc, api_gecko_adc_driver_api) = {
.channel_setup = adc_gecko_channel_setup,
.read = adc_gecko_read,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ifx_cat1.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static int ifx_cat1_adc_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api adc_cat1_driver_api = {
static DEVICE_API(adc, adc_cat1_driver_api) = {
.channel_setup = ifx_cat1_adc_channel_setup,
.read = ifx_cat1_adc_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ite_it8xxx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static void adc_it8xxx2_isr(const struct device *dev)
k_sem_give(&data->sem);
}

static const struct adc_driver_api api_it8xxx2_driver_api = {
static DEVICE_API(adc, api_it8xxx2_driver_api) = {
.channel_setup = adc_it8xxx2_channel_setup,
.read = adc_it8xxx2_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_lmp90xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ static int lmp90xxx_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api lmp90xxx_adc_api = {
static DEVICE_API(adc, lmp90xxx_adc_api) = {
.channel_setup = lmp90xxx_adc_channel_setup,
.read = lmp90xxx_adc_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_ltc2451.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static int ltc2451_init(const struct device *dev)
return ltc2451_set_conversion_speed(dev, config->conversion_speed);
}

static const struct adc_driver_api ltc2451_api = {
static DEVICE_API(adc, ltc2451_api) = {
.channel_setup = ltc2451_channel_setup,
.read = ltc2451_read_latest_conversion,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_max11102_17.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static int max11102_17_init(const struct device *dev)
return result;
}

static const struct adc_driver_api api = {
static DEVICE_API(adc, api) = {
.channel_setup = max11102_17_channel_setup,
.read = max11102_17_read,
.ref_internal = 0,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_max1125x.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ static int max1125x_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api max1125x_api = {
static DEVICE_API(adc, max1125x_api) = {
.channel_setup = max1125x_channel_setup,
.read = max1125x_read,
.ref_internal = 2048,
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_max32.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static void adc_max32_isr(const struct device *dev)
}
}

static const struct adc_driver_api adc_max32_driver_api = {
static DEVICE_API(adc, adc_max32_driver_api) = {
.channel_setup = adc_max32_channel_setup,
.read = adc_max32_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mchp_xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static int adc_xec_pm_action(const struct device *dev, enum pm_device_action act
}
#endif /* CONFIG_PM_DEVICE */

struct adc_driver_api adc_xec_api = {
static DEVICE_API(adc, adc_xec_api) = {
.channel_setup = adc_xec_channel_setup,
.read = adc_xec_read,
#if defined(CONFIG_ADC_ASYNC)
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mcp320x.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static int mcp320x_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api mcp320x_adc_api = {
static DEVICE_API(adc, mcp320x_adc_api) = {
.channel_setup = mcp320x_channel_setup,
.read = mcp320x_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mcux_12b1msps_sar.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static int mcux_12b1msps_sar_adc_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api mcux_12b1msps_sar_adc_driver_api = {
static DEVICE_API(adc, mcux_12b1msps_sar_adc_driver_api) = {
.channel_setup = mcux_12b1msps_sar_adc_channel_setup,
.read = mcux_12b1msps_sar_adc_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mcux_adc12.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static int mcux_adc12_init(const struct device *dev)
(kADC12_ReferenceVoltageSourceVref))

#define ADC12_MCUX_DRIVER_API(n) \
static const struct adc_driver_api mcux_adc12_driver_api_##n = { \
static DEVICE_API(adc, mcux_adc12_driver_api_##n) = { \
.channel_setup = mcux_adc12_channel_setup, \
.read = mcux_adc12_read, \
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = mcux_adc12_read_async,)) \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mcux_adc16.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static int mcux_adc16_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api mcux_adc16_driver_api = {
static DEVICE_API(adc, mcux_adc16_driver_api) = {
.channel_setup = mcux_adc16_channel_setup,
.read = mcux_adc16_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mcux_gau_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static int mcux_gau_adc_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api mcux_gau_adc_driver_api = {
static DEVICE_API(adc, mcux_gau_adc_driver_api) = {
.channel_setup = mcux_gau_adc_channel_setup,
.read = mcux_gau_adc_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_mcux_lpadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ static int mcux_lpadc_init(const struct device *dev)
return 0;
}

static const struct adc_driver_api mcux_lpadc_driver_api = {
static DEVICE_API(adc, mcux_lpadc_driver_api) = {
.channel_setup = mcux_lpadc_channel_setup,
.read = mcux_lpadc_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_npcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ static int adc_npcx_init(const struct device *dev)
irq_enable(DT_INST_IRQN(n)); \
} \
\
static const struct adc_driver_api adc_npcx_driver_api_##n = { \
static DEVICE_API(adc, adc_npcx_driver_api_##n) = { \
.channel_setup = adc_npcx_channel_setup, \
.read = adc_npcx_read, \
.ref_internal = DT_INST_PROP(n, vref_mv), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_nrfx_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static int init_adc(const struct device *dev)
return 0;
}

static const struct adc_driver_api adc_nrfx_driver_api = {
static DEVICE_API(adc, adc_nrfx_driver_api) = {
.channel_setup = adc_nrfx_channel_setup,
.read = adc_nrfx_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_nrfx_saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ static int init_saadc(const struct device *dev)
return 0;
}

static const struct adc_driver_api adc_nrfx_driver_api = {
static DEVICE_API(adc, adc_nrfx_driver_api) = {
.channel_setup = adc_nrfx_channel_setup,
.read = adc_nrfx_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int adc_numaker_read_async(const struct device *dev,
}
#endif

static const struct adc_driver_api adc_numaker_driver_api = {
static DEVICE_API(adc, adc_numaker_driver_api) = {
.channel_setup = adc_numaker_channel_setup,
.read = adc_numaker_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_nxp_s32_adc_sar.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static void adc_nxp_s32_isr(const struct device *dev)
}

#define ADC_NXP_S32_DRIVER_API(n) \
static const struct adc_driver_api adc_nxp_s32_driver_api_##n = { \
static DEVICE_API(adc, adc_nxp_s32_driver_api_##n) = { \
.channel_setup = adc_nxp_s32_channel_setup, \
.read = adc_nxp_s32_read, \
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_nxp_s32_read_async,))\
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_renesas_ra.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const adc_extended_cfg_t g_adc_cfg_extend = {
#define ADC_RA_INIT(idx) \
IRQ_CONFIGURE_FUNC(idx) \
PINCTRL_DT_INST_DEFINE(idx); \
static struct adc_driver_api adc_ra_api_##idx = { \
static DEVICE_API(adc, adc_ra_api_##idx) = { \
.channel_setup = adc_ra_channel_setup, \
.read = adc_ra_read, \
.ref_internal = DT_INST_PROP(idx, vref_mv), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_rpi_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static int adc_rpi_init(const struct device *dev)
#define ADC_RPI_INIT(idx) \
IRQ_CONFIGURE_FUNC(idx) \
PINCTRL_DT_INST_DEFINE(idx); \
static struct adc_driver_api adc_rpi_api_##idx = { \
static DEVICE_API(adc, adc_rpi_api_##idx) = { \
.channel_setup = adc_rpi_channel_setup, \
.read = adc_rpi_read, \
.ref_internal = DT_INST_PROP(idx, vref_mv), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ static int adc_sam_read_async(const struct device *dev,
}
#endif

static const struct adc_driver_api adc_sam_api = {
static DEVICE_API(adc, adc_sam_api) = {
.channel_setup = adc_sam_channel_setup,
.read = adc_sam_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_sam0.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ static int adc_sam0_read_async(const struct device *dev,
}
#endif

static const struct adc_driver_api adc_sam0_api = {
static DEVICE_API(adc, adc_sam0_api) = {
.channel_setup = adc_sam0_channel_setup,
.read = adc_sam0_read,
.ref_internal = 1000U, /* Fixed 1.0 V reference */
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_sam_afec.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static int adc_sam_read_async(const struct device *dev,
}
#endif

static const struct adc_driver_api adc_sam_api = {
static DEVICE_API(adc, adc_sam_api) = {
.channel_setup = adc_sam_channel_setup,
.read = adc_sam_read,
#ifdef CONFIG_ADC_ASYNC
Expand Down
Loading
Loading