drivers: use DT_INST_ENUM_IDX(_OR) macros

Replace `DT_ENUM_IDX(_OR)(DT_DRV_INST(...),` pattern with
`DT_INST_ENUM_IDX(_OR)(...,`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-11-17 14:01:42 +01:00 committed by Anas Nashif
commit c759a35d08
17 changed files with 28 additions and 30 deletions

View file

@ -95,7 +95,7 @@ static const struct dac_driver_api api_sam0_driver_api = {
#define SAM0_DAC_REFSEL(n) \ #define SAM0_DAC_REFSEL(n) \
COND_CODE_1(DT_INST_NODE_HAS_PROP(n, reference), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(n, reference), \
(DT_ENUM_IDX(DT_DRV_INST(n), reference)), (0)) (DT_INST_ENUM_IDX(n, reference)), (0))
#define SAM0_DAC_INIT(n) \ #define SAM0_DAC_INIT(n) \
static const struct dac_sam0_cfg dac_sam0_cfg_##n = { \ static const struct dac_sam0_cfg dac_sam0_cfg_##n = { \

View file

@ -1107,7 +1107,7 @@ static int gmac_init(Gmac *gmac, uint32_t gmac_ncfgr_val)
/* Setup Network Configuration Register */ /* Setup Network Configuration Register */
gmac->GMAC_NCFGR = gmac_ncfgr_val | mck_divisor; gmac->GMAC_NCFGR = gmac_ncfgr_val | mck_divisor;
gmac->GMAC_UR = DT_ENUM_IDX(DT_DRV_INST(0), phy_connection_type); gmac->GMAC_UR = DT_INST_ENUM_IDX(0, phy_connection_type);
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC) #if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
/* Initialize PTP Clock Registers */ /* Initialize PTP Clock Registers */

View file

@ -403,7 +403,7 @@ static const struct ethphy_driver_api phy_mii_driver_api = {
static const struct phy_mii_dev_config phy_mii_dev_config_##n = { \ static const struct phy_mii_dev_config phy_mii_dev_config_##n = { \
.phy_addr = DT_PROP(DT_DRV_INST(n), address), \ .phy_addr = DT_PROP(DT_DRV_INST(n), address), \
.fixed = IS_FIXED_LINK(n), \ .fixed = IS_FIXED_LINK(n), \
.fixed_speed = DT_ENUM_IDX_OR(DT_DRV_INST(n), fixed_link, 0), \ .fixed_speed = DT_INST_ENUM_IDX_OR(n, fixed_link, 0), \
.mdio = UTIL_AND(UTIL_NOT(IS_FIXED_LINK(n)), \ .mdio = UTIL_AND(UTIL_NOT(IS_FIXED_LINK(n)), \
DEVICE_DT_GET(DT_PHANDLE(DT_DRV_INST(n), mdio)))\ DEVICE_DT_GET(DT_PHANDLE(DT_DRV_INST(n), mdio)))\
}; };

View file

@ -593,8 +593,6 @@ static const struct i2c_driver_api i2c_sam_twim_driver_api = {
.transfer = i2c_sam_twim_transfer, .transfer = i2c_sam_twim_transfer,
}; };
#define DT_INST_ENUM_IDX(inst, prop) DT_ENUM_IDX(DT_DRV_INST(inst), prop)
#define I2C_TWIM_SAM_SLEW_REGS(n) \ #define I2C_TWIM_SAM_SLEW_REGS(n) \
.std_clk_slew_lim = DT_INST_ENUM_IDX(n, std_clk_slew_lim), \ .std_clk_slew_lim = DT_INST_ENUM_IDX(n, std_clk_slew_lim), \
.std_clk_strength_low = DT_INST_ENUM_IDX(n, std_clk_strength_low),\ .std_clk_strength_low = DT_INST_ENUM_IDX(n, std_clk_strength_low),\

View file

@ -135,7 +135,7 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(semtech_sx1272) +
#define SX127X_PA_OUTPUT(power) SX127X_PA_BOOST #define SX127X_PA_OUTPUT(power) SX127X_PA_BOOST
#elif DT_INST_NODE_HAS_PROP(0, power_amplifier_output) #elif DT_INST_NODE_HAS_PROP(0, power_amplifier_output)
#define SX127X_PA_OUTPUT(power) \ #define SX127X_PA_OUTPUT(power) \
DT_ENUM_IDX(DT_DRV_INST(0), power_amplifier_output) DT_INST_ENUM_IDX(0, power_amplifier_output)
#else #else
BUILD_ASSERT(0, "None of rfo-enable-gpios, pa-boost-enable-gpios and " BUILD_ASSERT(0, "None of rfo-enable-gpios, pa-boost-enable-gpios and "
"power-amplifier-output has been specified. " "power-amplifier-output has been specified. "

View file

@ -131,7 +131,7 @@ static const struct mdio_driver_api mdio_sam_driver_api = {
#define MDIO_SAM_CONFIG(n) \ #define MDIO_SAM_CONFIG(n) \
static const struct mdio_sam_dev_config mdio_sam_dev_config_##n = { \ static const struct mdio_sam_dev_config mdio_sam_dev_config_##n = { \
.regs = (Gmac *)DT_REG_ADDR(DT_PARENT(DT_DRV_INST(n))), \ .regs = (Gmac *)DT_REG_ADDR(DT_PARENT(DT_DRV_INST(n))), \
.protocol = DT_ENUM_IDX(DT_DRV_INST(n), protocol), \ .protocol = DT_INST_ENUM_IDX(n, protocol), \
}; };
#define MDIO_SAM_DEVICE(n) \ #define MDIO_SAM_DEVICE(n) \

View file

@ -710,15 +710,15 @@ static int bmp388_init(const struct device *dev)
#define BMP388_INST(inst) \ #define BMP388_INST(inst) \
static struct bmp388_data bmp388_data_##inst = { \ static struct bmp388_data bmp388_data_##inst = { \
.odr = DT_ENUM_IDX(DT_DRV_INST(inst), odr), \ .odr = DT_INST_ENUM_IDX(inst, odr), \
.osr_pressure = DT_ENUM_IDX(DT_DRV_INST(inst), osr_press), \ .osr_pressure = DT_INST_ENUM_IDX(inst, osr_press), \
.osr_temp = DT_ENUM_IDX(DT_DRV_INST(inst), osr_temp), \ .osr_temp = DT_INST_ENUM_IDX(inst, osr_temp), \
}; \ }; \
static const struct bmp388_config bmp388_config_##inst = { \ static const struct bmp388_config bmp388_config_##inst = { \
.bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \ .bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \
BMP388_BUS_CFG(inst), \ BMP388_BUS_CFG(inst), \
BMP388_INT_CFG(inst) \ BMP388_INT_CFG(inst) \
.iir_filter = DT_ENUM_IDX(DT_DRV_INST(inst), iir_filter), \ .iir_filter = DT_INST_ENUM_IDX(inst, iir_filter), \
}; \ }; \
DEVICE_DT_INST_DEFINE( \ DEVICE_DT_INST_DEFINE( \
inst, \ inst, \

View file

@ -1014,9 +1014,9 @@ static int fdc2x1x_init(const struct device *dev)
.active_channel = DT_INST_PROP(n, active_channel), \ .active_channel = DT_INST_PROP(n, active_channel), \
.deglitch = DT_INST_PROP(n, deglitch), \ .deglitch = DT_INST_PROP(n, deglitch), \
.sensor_activate_sel = \ .sensor_activate_sel = \
DT_ENUM_IDX(DT_DRV_INST(n), sensor_activate_sel), \ DT_INST_ENUM_IDX(n, sensor_activate_sel), \
.clk_src = DT_ENUM_IDX(DT_DRV_INST(n), ref_clk_src), \ .clk_src = DT_INST_ENUM_IDX(n, ref_clk_src), \
.current_drv = DT_ENUM_IDX(DT_DRV_INST(n), current_drive), \ .current_drv = DT_INST_ENUM_IDX(n, current_drive), \
.output_gain = DT_INST_PROP(n, output_gain), \ .output_gain = DT_INST_PROP(n, output_gain), \
.ch_cfg = ch_cfg_##n, \ .ch_cfg = ch_cfg_##n, \
.num_channels = ARRAY_SIZE(fdc2x1x_sample_buf_##n), \ .num_channels = ARRAY_SIZE(fdc2x1x_sample_buf_##n), \

View file

@ -457,8 +457,8 @@ static const struct sensor_driver_api icm42605_driver_api = {
.gpio_dt_flags = DT_INST_SPI_DEV_CS_GPIOS_FLAGS(index), \ .gpio_dt_flags = DT_INST_SPI_DEV_CS_GPIOS_FLAGS(index), \
.accel_hz = DT_INST_PROP(index, accel_hz), \ .accel_hz = DT_INST_PROP(index, accel_hz), \
.gyro_hz = DT_INST_PROP(index, gyro_hz), \ .gyro_hz = DT_INST_PROP(index, gyro_hz), \
.accel_fs = DT_ENUM_IDX(DT_DRV_INST(index), accel_fs), \ .accel_fs = DT_INST_ENUM_IDX(index, accel_fs), \
.gyro_fs = DT_ENUM_IDX(DT_DRV_INST(index), gyro_fs), \ .gyro_fs = DT_INST_ENUM_IDX(index, gyro_fs), \
} }
#define ICM42605_INIT(index) \ #define ICM42605_INIT(index) \

View file

@ -242,8 +242,8 @@ static int shtcx_init(const struct device *dev)
{ \ { \
.bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \ .bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \
.base_address = DT_INST_REG_ADDR(inst), \ .base_address = DT_INST_REG_ADDR(inst), \
.chip = DT_ENUM_IDX(DT_DRV_INST(inst), chip), \ .chip = DT_INST_ENUM_IDX(inst, chip), \
.measure_mode = DT_ENUM_IDX(DT_DRV_INST(inst), measure_mode), \ .measure_mode = DT_INST_ENUM_IDX(inst, measure_mode), \
.clock_stretching = DT_INST_PROP(inst, clock_stretching) \ .clock_stretching = DT_INST_PROP(inst, clock_stretching) \
} }

View file

@ -354,11 +354,11 @@ static const struct vcnl4040_config vcnl4040_config = {
.gpio_flags = 0, .gpio_flags = 0,
#endif #endif
#endif #endif
.led_i = DT_ENUM_IDX(DT_DRV_INST(0), led_current), .led_i = DT_INST_ENUM_IDX(0, led_current),
.led_dc = DT_ENUM_IDX(DT_DRV_INST(0), led_duty_cycle), .led_dc = DT_INST_ENUM_IDX(0, led_duty_cycle),
.als_it = DT_ENUM_IDX(DT_DRV_INST(0), als_it), .als_it = DT_INST_ENUM_IDX(0, als_it),
.proxy_it = DT_ENUM_IDX(DT_DRV_INST(0), proximity_it), .proxy_it = DT_INST_ENUM_IDX(0, proximity_it),
.proxy_type = DT_ENUM_IDX(DT_DRV_INST(0), proximity_trigger), .proxy_type = DT_INST_ENUM_IDX(0, proximity_trigger),
}; };
static struct vcnl4040_data vcnl4040_data; static struct vcnl4040_data vcnl4040_data;

View file

@ -397,8 +397,8 @@ static const struct itds_device_config itds_config_##idx = { \
.gpio_port = DT_INST_GPIO_LABEL(idx, int_gpios), \ .gpio_port = DT_INST_GPIO_LABEL(idx, int_gpios), \
.int_pin = DT_INST_GPIO_PIN(idx, int_gpios), \ .int_pin = DT_INST_GPIO_PIN(idx, int_gpios), \
.int_flags = DT_INST_GPIO_FLAGS(idx, int_gpios), \ .int_flags = DT_INST_GPIO_FLAGS(idx, int_gpios), \
.def_odr = DT_ENUM_IDX(DT_DRV_INST(idx), odr), \ .def_odr = DT_INST_ENUM_IDX(idx, odr), \
.def_op_mode = DT_ENUM_IDX(DT_DRV_INST(idx), op_mode), \ .def_op_mode = DT_INST_ENUM_IDX(idx, op_mode), \
}; \ }; \
\ \
DEVICE_DT_INST_DEFINE(idx, itds_init, NULL, \ DEVICE_DT_INST_DEFINE(idx, itds_init, NULL, \

View file

@ -332,7 +332,7 @@ static const struct mcux_flexcomm_config mcux_flexcomm_##n##_config = { \
.clock_subsys = \ .clock_subsys = \
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\ (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
.baud_rate = DT_INST_PROP(n, current_speed), \ .baud_rate = DT_INST_PROP(n, current_speed), \
.parity = DT_ENUM_IDX_OR(DT_DRV_INST(n), parity, UART_CFG_PARITY_NONE), \ .parity = DT_INST_ENUM_IDX_OR(n, parity, UART_CFG_PARITY_NONE), \
IRQ_FUNC_INIT \ IRQ_FUNC_INIT \
} }

View file

@ -1603,7 +1603,7 @@ static const struct uart_stm32_config uart_stm32_cfg_##index = { \
.enr = DT_INST_CLOCKS_CELL(index, bits) \ .enr = DT_INST_CLOCKS_CELL(index, bits) \
}, \ }, \
.hw_flow_control = DT_INST_PROP(index, hw_flow_control), \ .hw_flow_control = DT_INST_PROP(index, hw_flow_control), \
.parity = DT_ENUM_IDX_OR(DT_DRV_INST(index), parity, UART_CFG_PARITY_NONE), \ .parity = DT_INST_ENUM_IDX_OR(index, parity, UART_CFG_PARITY_NONE), \
STM32_UART_POLL_IRQ_HANDLER_FUNC(index) \ STM32_UART_POLL_IRQ_HANDLER_FUNC(index) \
.pinctrl_list = uart_pins_##index, \ .pinctrl_list = uart_pins_##index, \
.pinctrl_list_size = ARRAY_SIZE(uart_pins_##index), \ .pinctrl_list_size = ARRAY_SIZE(uart_pins_##index), \

View file

@ -463,7 +463,7 @@ static struct spi_driver_api spi_b91_api = {
}; \ }; \
\ \
static struct spi_b91_cfg spi_b91_cfg_##inst = { \ static struct spi_b91_cfg spi_b91_cfg_##inst = { \
.peripheral_id = DT_ENUM_IDX(DT_DRV_INST(inst), peripheral_id), \ .peripheral_id = DT_INST_ENUM_IDX(inst, peripheral_id), \
.cs_pin[0] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs0_pin), \ .cs_pin[0] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs0_pin), \
.cs_pin[1] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs1_pin), \ .cs_pin[1] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs1_pin), \
.cs_pin[2] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs2_pin), \ .cs_pin[2] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs2_pin), \

View file

@ -699,7 +699,7 @@ int usb_dc_attach(void)
/* Select the speed with pads detached */ /* Select the speed with pads detached */
regval = USBC_UDCON_DETACH; regval = USBC_UDCON_DETACH;
switch (DT_ENUM_IDX(DT_DRV_INST(0), maximum_speed)) { switch (DT_INST_ENUM_IDX(0, maximum_speed)) {
case 1: case 1:
WRITE_BIT(regval, USBC_UDCON_LS_Pos, 0); WRITE_BIT(regval, USBC_UDCON_LS_Pos, 0);
break; break;

View file

@ -47,7 +47,7 @@ LOG_MODULE_REGISTER(usb_dc_sam_usbhs);
#define NUM_OF_EP_MAX DT_INST_PROP(0, num_bidir_endpoints) #define NUM_OF_EP_MAX DT_INST_PROP(0, num_bidir_endpoints)
#if DT_INST_NODE_HAS_PROP(0, maximum_speed) #if DT_INST_NODE_HAS_PROP(0, maximum_speed)
#define USB_MAXIMUM_SPEED DT_ENUM_IDX(DT_DRV_INST(0), maximum_speed) #define USB_MAXIMUM_SPEED DT_INST_ENUM_IDX(0, maximum_speed)
#else #else
#define USB_MAXIMUM_SPEED 2 /* Default to high-speed */ #define USB_MAXIMUM_SPEED 2 /* Default to high-speed */
#endif #endif