Skip to content

Commit c016fdf

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 014e87e commit c016fdf

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

drivers/video/mt9m114.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,16 @@ static int mt9m114_init_controls(const struct device *dev)
529529

530530
static int mt9m114_init(const struct device *dev)
531531
{
532+
const struct mt9m114_config *cfg = dev->config;
532533
struct video_format fmt;
533534
uint16_t val;
534535
int ret;
535536

537+
if (!device_is_ready(cfg->i2c.bus)) {
538+
LOG_ERR("Bus device is not ready");
539+
return -ENODEV;
540+
}
541+
536542
/* no power control, wait for camera ready */
537543
k_sleep(K_MSEC(100));
538544

@@ -576,29 +582,16 @@ static int mt9m114_init(const struct device *dev)
576582
return mt9m114_init_controls(dev);
577583
}
578584

579-
#if 1 /* Unique Instance */
580-
581-
static const struct mt9m114_config mt9m114_cfg_0 = {
582-
.i2c = I2C_DT_SPEC_INST_GET(0),
583-
};
584-
585-
static struct mt9m114_data mt9m114_data_0;
586-
587-
static int mt9m114_init_0(const struct device *dev)
588-
{
589-
const struct mt9m114_config *cfg = dev->config;
590-
591-
if (!device_is_ready(cfg->i2c.bus)) {
592-
LOG_ERR("Bus device is not ready");
593-
return -ENODEV;
594-
}
595-
596-
return mt9m114_init(dev);
597-
}
598-
599-
DEVICE_DT_INST_DEFINE(0, &mt9m114_init_0, NULL, &mt9m114_data_0, &mt9m114_cfg_0, POST_KERNEL,
600-
CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);
601-
602-
VIDEO_DEVICE_DEFINE(mt9m114, DEVICE_DT_INST_GET(0), NULL);
603-
604-
#endif
585+
#define MT9M114_INIT(n) \
586+
static struct mt9m114_data mt9m114_data_##n; \
587+
\
588+
static const struct mt9m114_config mt9m114_cfg_##n = { \
589+
.i2c = I2C_DT_SPEC_INST_GET(n), \
590+
}; \
591+
\
592+
DEVICE_DT_INST_DEFINE(n, &mt9m114_init, NULL, &mt9m114_data_##n, &mt9m114_cfg_##n, \
593+
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api); \
594+
\
595+
VIDEO_DEVICE_DEFINE(mt9m114_##n, DEVICE_DT_INST_GET(n), NULL);
596+
597+
DT_INST_FOREACH_STATUS_OKAY(MT9M114_INIT)

0 commit comments

Comments
 (0)