Skip to content

Commit 77c643a

Browse files
varun-shaandrewboie
authored andcommitted
drivers: Modify drivers to use DEVICE_AND_API_INIT()
Modified drivers to use DEVICE_AND_API_INIT() instead of DEVICE_INIT() This will make sure driver_api,is populated at build time and is exposed to user space Signed-off-by: Varun Sharma <[email protected]>
1 parent 052121e commit 77c643a

File tree

19 files changed

+74
-95
lines changed

19 files changed

+74
-95
lines changed

drivers/display/grove_lcd_rgb.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,6 @@ int glcd_initialize(struct device *port)
267267
return -EPERM;
268268
}
269269

270-
/* Since device_get_binding() will not return any
271-
* reference to a driver instance if port->driver_api
272-
* is NULL and grove_lcd does not have any API struct,
273-
* just populate it with some magic number
274-
* so grove_lcd can be referenced.
275-
*
276-
* Since dev is probably still in registers.
277-
* use that to minimize code addition.
278-
*/
279-
port->driver_api = (void *)dev;
280270

281271
/*
282272
* Initialization sequence from the data sheet:
@@ -344,6 +334,14 @@ static struct glcd_data grove_lcd_driver = {
344334
.function = 0,
345335
};
346336

347-
DEVICE_INIT(grove_lcd, GROVE_LCD_NAME, glcd_initialize,
337+
/* Since device_get_binding() will not return any
338+
* reference to a driver instance if driver_api
339+
* is NULL and grove_lcd does not have any API struct,
340+
* just populate it with some magic number
341+
* so grove_lcd can be referenced.
342+
* since grove_lcd_driver struct is available, populating with it
343+
*/
344+
DEVICE_AND_API_INIT(grove_lcd, GROVE_LCD_NAME, glcd_initialize,
348345
&grove_lcd_driver, &grove_lcd_config,
349-
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);
346+
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY,
347+
(void *)&grove_lcd_driver);

drivers/flash/soc_flash_nrf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ static const struct flash_driver_api flash_nrf_api = {
254254

255255
static int nrf_flash_init(struct device *dev)
256256
{
257-
dev->driver_api = &flash_nrf_api;
258-
259257
SYNC_INIT();
260258

261259
#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
@@ -270,8 +268,9 @@ static int nrf_flash_init(struct device *dev)
270268
return 0;
271269
}
272270

273-
DEVICE_INIT(nrf_flash, DT_FLASH_DEV_NAME, nrf_flash_init,
274-
NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
271+
DEVICE_AND_API_INIT(nrf_flash, DT_FLASH_DEV_NAME, nrf_flash_init,
272+
NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
273+
&flash_nrf_api);
275274

276275
#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
277276

drivers/flash/spi_flash_w25qxxdv.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ static int spi_flash_init(struct device *dev)
431431
SYNC_INIT();
432432

433433
ret = spi_flash_wb_configure(dev);
434-
if (!ret) {
435-
dev->driver_api = &spi_flash_api;
436-
}
437434

438435
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
439436
/*
@@ -450,6 +447,6 @@ static int spi_flash_init(struct device *dev)
450447

451448
static struct spi_flash_data spi_flash_memory_data;
452449

453-
DEVICE_INIT(spi_flash_memory, CONFIG_SPI_FLASH_W25QXXDV_DRV_NAME,
450+
DEVICE_AND_API_INIT(spi_flash_memory, CONFIG_SPI_FLASH_W25QXXDV_DRV_NAME,
454451
spi_flash_init, &spi_flash_memory_data, NULL, POST_KERNEL,
455-
CONFIG_SPI_FLASH_W25QXXDV_INIT_PRIORITY);
452+
CONFIG_SPI_FLASH_W25QXXDV_INIT_PRIORITY, &spi_flash_api);

drivers/gpio/gpio_pcal9535a.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,6 @@ static int gpio_pcal9535a_init(struct device *dev)
549549
}
550550
drv_data->i2c_master = i2c_master;
551551

552-
dev->driver_api = &gpio_pcal9535a_drv_api_funcs;
553-
554552
return 0;
555553
}
556554

@@ -571,10 +569,11 @@ static struct gpio_pcal9535a_drv_data gpio_pcal9535a_0_drvdata = {
571569
};
572570

573571
/* This has to init after I2C master */
574-
DEVICE_INIT(gpio_pcal9535a_0, CONFIG_GPIO_PCAL9535A_0_DEV_NAME,
572+
DEVICE_AND_API_INIT(gpio_pcal9535a_0, CONFIG_GPIO_PCAL9535A_0_DEV_NAME,
575573
gpio_pcal9535a_init,
576574
&gpio_pcal9535a_0_drvdata, &gpio_pcal9535a_0_cfg,
577-
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY);
575+
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY,
576+
&gpio_pcal9535a_drv_api_funcs);
578577

579578
#endif /* CONFIG_GPIO_PCAL9535A_0 */
580579

@@ -595,10 +594,11 @@ static struct gpio_pcal9535a_drv_data gpio_pcal9535a_1_drvdata = {
595594
};
596595

597596
/* This has to init after I2C master */
598-
DEVICE_INIT(gpio_pcal9535a_1, CONFIG_GPIO_PCAL9535A_1_DEV_NAME,
597+
DEVICE_AND_API_INIT(gpio_pcal9535a_1, CONFIG_GPIO_PCAL9535A_1_DEV_NAME,
599598
gpio_pcal9535a_init,
600599
&gpio_pcal9535a_1_drvdata, &gpio_pcal9535a_1_cfg,
601-
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY);
600+
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY,
601+
&gpio_pcal9535a_drv_api_funcs);
602602

603603
#endif /* CONFIG_GPIO_PCAL9535A_1 */
604604

@@ -619,10 +619,11 @@ static struct gpio_pcal9535a_drv_data gpio_pcal9535a_2_drvdata = {
619619
};
620620

621621
/* This has to init after I2C master */
622-
DEVICE_INIT(gpio_pcal9535a_2, CONFIG_GPIO_PCAL9535A_2_DEV_NAME,
622+
DEVICE_AND_API_INIT(gpio_pcal9535a_2, CONFIG_GPIO_PCAL9535A_2_DEV_NAME,
623623
gpio_pcal9535a_init,
624624
&gpio_pcal9535a_2_drvdata, &gpio_pcal9535a_2_cfg,
625-
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY);
625+
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY,
626+
&gpio_pcal9535a_drv_api_funcs);
626627

627628
#endif /* CONFIG_GPIO_PCAL9535A_2 */
628629

@@ -643,9 +644,10 @@ static struct gpio_pcal9535a_drv_data gpio_pcal9535a_3_drvdata = {
643644
};
644645

645646
/* This has to init after I2C master */
646-
DEVICE_INIT(gpio_pcal9535a_3, CONFIG_GPIO_PCAL9535A_3_DEV_NAME,
647+
DEVICE_AND_API_INIT(gpio_pcal9535a_3, CONFIG_GPIO_PCAL9535A_3_DEV_NAME,
647648
gpio_pcal9535a_init,
648649
&gpio_pcal9535a_3_drvdata, &gpio_pcal9535a_3_cfg,
649-
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY);
650+
POST_KERNEL, CONFIG_GPIO_PCAL9535A_INIT_PRIORITY,
651+
&gpio_pcal9535a_drv_api_funcs);
650652

651653
#endif /* CONFIG_GPIO_PCAL9535A_3 */

drivers/gpio/gpio_sch.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ static int gpio_sch_init(struct device *dev)
311311
{
312312
struct gpio_sch_data *gpio = dev->driver_data;
313313

314-
dev->driver_api = &gpio_sch_api;
315-
316314
k_timer_init(&gpio->poll_timer, NULL, NULL);
317315

318316
LOG_DBG("SCH GPIO Intel Driver initialized on device: %p", dev);
@@ -329,9 +327,9 @@ static const struct gpio_sch_config gpio_sch_0_config = {
329327

330328
static struct gpio_sch_data gpio_data_0;
331329

332-
DEVICE_INIT(gpio_0, CONFIG_GPIO_SCH_0_DEV_NAME, gpio_sch_init,
330+
DEVICE_AND_API_INIT(gpio_0, CONFIG_GPIO_SCH_0_DEV_NAME, gpio_sch_init,
333331
&gpio_data_0, &gpio_sch_0_config,
334-
POST_KERNEL, CONFIG_GPIO_SCH_INIT_PRIORITY);
332+
POST_KERNEL, CONFIG_GPIO_SCH_INIT_PRIORITY, &gpio_sch_api);
335333

336334
#endif /* CONFIG_GPIO_SCH_0 */
337335
#if CONFIG_GPIO_SCH_1
@@ -343,8 +341,8 @@ static const struct gpio_sch_config gpio_sch_1_config = {
343341

344342
static struct gpio_sch_data gpio_data_1;
345343

346-
DEVICE_INIT(gpio_1, CONFIG_GPIO_SCH_1_DEV_NAME, gpio_sch_init,
344+
DEVICE_AND_API_INIT(gpio_1, CONFIG_GPIO_SCH_1_DEV_NAME, gpio_sch_init,
347345
&gpio_data_1, &gpio_sch_1_config,
348-
POST_KERNEL, CONFIG_GPIO_SCH_INIT_PRIORITY);
346+
POST_KERNEL, CONFIG_GPIO_SCH_INIT_PRIORITY, &gpio_sch_api);
349347

350348
#endif /* CONFIG_GPIO_SCH_1 */

drivers/i2c/i2c_gpio.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ static int i2c_gpio_init(struct device *dev)
105105

106106
i2c_bitbang_init(&context->bitbang, &io_fns, context);
107107

108-
dev->driver_api = &api;
109-
110108
return 0;
111109
}
112110

@@ -120,11 +118,11 @@ static const struct i2c_gpio_config i2c_gpio_dev_cfg_##_num = { \
120118
.sda_pin = CONFIG_I2C_GPIO_##_num##_SDA_PIN, \
121119
}; \
122120
\
123-
DEVICE_INIT(i2c_gpio_##_num, CONFIG_I2C_GPIO_##_num##_NAME, \
121+
DEVICE_AND_API_INIT(i2c_gpio_##_num, CONFIG_I2C_GPIO_##_num##_NAME, \
124122
i2c_gpio_init, \
125123
&i2c_gpio_dev_data_##_num, \
126124
&i2c_gpio_dev_cfg_##_num, \
127-
PRE_KERNEL_2, CONFIG_I2C_INIT_PRIORITY)
125+
PRE_KERNEL_2, CONFIG_I2C_INIT_PRIORITY, &api)
128126

129127
#ifdef CONFIG_I2C_GPIO_0
130128
DEFINE_I2C_GPIO(0);

drivers/i2c/i2c_sbcon.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ static int i2c_sbcon_init(struct device *dev)
103103

104104
i2c_bitbang_init(&context->bitbang, &io_fns, config->sbcon);
105105

106-
dev->driver_api = &api;
107-
108106
return 0;
109107
}
110108

@@ -116,11 +114,11 @@ static const struct i2c_sbcon_config i2c_sbcon_dev_cfg_##_num = { \
116114
.sbcon = (void *)DT_I2C_SBCON_##_num##_BASE_ADDR, \
117115
}; \
118116
\
119-
DEVICE_INIT(i2c_sbcon_##_num, CONFIG_I2C_SBCON_##_num##_NAME, \
117+
DEVICE_AND_API_INIT(i2c_sbcon_##_num, CONFIG_I2C_SBCON_##_num##_NAME, \
120118
i2c_sbcon_init, \
121119
&i2c_sbcon_dev_data_##_num, \
122120
&i2c_sbcon_dev_cfg_##_num, \
123-
PRE_KERNEL_2, CONFIG_I2C_INIT_PRIORITY)
121+
PRE_KERNEL_2, CONFIG_I2C_INIT_PRIORITY, &api)
124122

125123
#ifdef CONFIG_I2C_SBCON_0
126124
DEFINE_I2C_SBCON(0);

drivers/interrupt_controller/shared_irq.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ static const struct shared_irq_driver_api api_funcs = {
117117
int shared_irq_initialize(struct device *dev)
118118
{
119119
const struct shared_irq_config *config = dev->config->config_info;
120-
121-
dev->driver_api = &api_funcs;
122120
config->config();
123-
124121
return 0;
125122
}
126123

@@ -135,9 +132,10 @@ const struct shared_irq_config shared_irq_config_0 = {
135132

136133
struct shared_irq_runtime shared_irq_0_runtime;
137134

138-
DEVICE_INIT(shared_irq_0, CONFIG_SHARED_IRQ_0_NAME, shared_irq_initialize,
139-
&shared_irq_0_runtime, &shared_irq_config_0,
140-
POST_KERNEL, CONFIG_SHARED_IRQ_INIT_PRIORITY);
135+
DEVICE_AND_API_INIT(shared_irq_0, CONFIG_SHARED_IRQ_0_NAME,
136+
shared_irq_initialize, &shared_irq_0_runtime,
137+
&shared_irq_config_0, POST_KERNEL,
138+
CONFIG_SHARED_IRQ_INIT_PRIORITY, &api_funcs);
141139

142140
#if defined(CONFIG_IOAPIC)
143141
#if defined(CONFIG_SHARED_IRQ_0_FALLING_EDGE)
@@ -173,9 +171,10 @@ const struct shared_irq_config shared_irq_config_1 = {
173171

174172
struct shared_irq_runtime shared_irq_1_runtime;
175173

176-
DEVICE_INIT(shared_irq_1, CONFIG_SHARED_IRQ_1_NAME, shared_irq_initialize,
177-
&shared_irq_1_runtime, &shared_irq_config_1,
178-
POST_KERNEL, CONFIG_SHARED_IRQ_INIT_PRIORITY);
174+
DEVICE_AND_API_INIT(shared_irq_1, CONFIG_SHARED_IRQ_1_NAME,
175+
shared_irq_initialize, &shared_irq_1_runtime,
176+
&shared_irq_config_1, POST_KERNEL,
177+
CONFIG_SHARED_IRQ_INIT_PRIORITY, &api_funcs);
179178

180179
#if defined(CONFIG_IOAPIC)
181180
#if defined(CONFIG_SHARED_IRQ_1_FALLING_EDGE)

drivers/pwm/pwm_pca9685.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ int pwm_pca9685_init(struct device *dev)
145145
return -EPERM;
146146
}
147147

148-
dev->driver_api = &pwm_pca9685_drv_api_funcs;
149-
150148
return 0;
151149
}
152150

@@ -163,9 +161,10 @@ static const struct pwm_pca9685_config pwm_pca9685_0_cfg = {
163161
static struct pwm_pca9685_drv_data pwm_pca9685_0_drvdata;
164162

165163
/* This has to init after I2C master */
166-
DEVICE_INIT(pwm_pca9685_0, CONFIG_PWM_PCA9685_0_DEV_NAME,
164+
DEVICE_AND_API_INIT(pwm_pca9685_0, CONFIG_PWM_PCA9685_0_DEV_NAME,
167165
pwm_pca9685_init,
168166
&pwm_pca9685_0_drvdata, &pwm_pca9685_0_cfg,
169-
POST_KERNEL, CONFIG_PWM_PCA9685_INIT_PRIORITY);
167+
POST_KERNEL, CONFIG_PWM_PCA9685_INIT_PRIORITY,
168+
&pwm_pca9685_drv_api_funcs);
170169

171170
#endif /* CONFIG_PWM_PCA9685_0 */

drivers/sensor/bmi160/bmi160.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,6 @@ int bmi160_init(struct device *dev)
895895
}
896896
#endif
897897

898-
dev->driver_api = &bmi160_api;
899-
900898
return 0;
901899
}
902900

@@ -909,5 +907,6 @@ const struct bmi160_device_config bmi160_config = {
909907

910908

911909

912-
DEVICE_INIT(bmi160, DT_BMI160_NAME, bmi160_init, &bmi160_data,
913-
&bmi160_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY);
910+
DEVICE_AND_API_INIT(bmi160, DT_BMI160_NAME, bmi160_init, &bmi160_data,
911+
&bmi160_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
912+
&bmi160_api);

0 commit comments

Comments
 (0)