Skip to content

Commit 33ff1f6

Browse files
0xFarahFlkartben
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 46bf6b5 commit 33ff1f6

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
@@ -526,10 +526,16 @@ static int mt9m114_init_controls(const struct device *dev)
526526

527527
static int mt9m114_init(const struct device *dev)
528528
{
529+
const struct mt9m114_config *cfg = dev->config;
529530
struct video_format fmt;
530531
uint16_t val;
531532
int ret;
532533

534+
if (!device_is_ready(cfg->i2c.bus)) {
535+
LOG_ERR("Bus device is not ready");
536+
return -ENODEV;
537+
}
538+
533539
/* no power control, wait for camera ready */
534540
k_sleep(K_MSEC(100));
535541

@@ -573,29 +579,16 @@ static int mt9m114_init(const struct device *dev)
573579
return mt9m114_init_controls(dev);
574580
}
575581

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

0 commit comments

Comments
 (0)