Skip to content

Commit deed71e

Browse files
0xFarahFlngphibang
authored andcommitted
drivers: video: mt9m114: Make the driver multi-instance
The mt9m114 camera driver used to be single-instance. Improve it to multi-instance. Signed-off-by: Farah Fliss <farah.fliss@nxp.com> Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent 9445c0e commit deed71e

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

drivers/video/mt9m114.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,16 @@ static DEVICE_API(video, mt9m114_driver_api) = {
501501

502502
static int mt9m114_init(const struct device *dev)
503503
{
504+
const struct mt9m114_config *cfg = dev->config;
504505
struct video_format fmt;
505506
uint16_t val;
506507
int ret;
507508

509+
if (!device_is_ready(cfg->i2c.bus)) {
510+
LOG_ERR("Bus device is not ready");
511+
return -ENODEV;
512+
}
513+
508514
/* no power control, wait for camera ready */
509515
k_sleep(K_MSEC(100));
510516

@@ -547,26 +553,14 @@ static int mt9m114_init(const struct device *dev)
547553
return 0;
548554
}
549555

550-
#if 1 /* Unique Instance */
551-
552-
static const struct mt9m114_config mt9m114_cfg_0 = {
553-
.i2c = I2C_DT_SPEC_INST_GET(0),
554-
};
555-
556-
static struct mt9m114_data mt9m114_data_0;
557-
558-
static int mt9m114_init_0(const struct device *dev)
559-
{
560-
const struct mt9m114_config *cfg = dev->config;
561-
562-
if (!device_is_ready(cfg->i2c.bus)) {
563-
LOG_ERR("Bus device is not ready");
564-
return -ENODEV;
565-
}
566-
567-
return mt9m114_init(dev);
568-
}
569-
570-
DEVICE_DT_INST_DEFINE(0, &mt9m114_init_0, NULL, &mt9m114_data_0, &mt9m114_cfg_0, POST_KERNEL,
571-
CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);
572-
#endif
556+
#define MT9M114_INIT(n) \
557+
static struct mt9m114_data mt9m114_data_##n; \
558+
\
559+
static const struct mt9m114_config mt9m114_cfg_##n = { \
560+
.i2c = I2C_DT_SPEC_INST_GET(n), \
561+
}; \
562+
\
563+
DEVICE_DT_INST_DEFINE(n, &mt9m114_init, NULL, &mt9m114_data_##n, &mt9m114_cfg_##n, \
564+
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);
565+
566+
DT_INST_FOREACH_STATUS_OKAY(MT9M114_INIT)

0 commit comments

Comments
 (0)