@@ -750,10 +750,10 @@ static const struct video_reg8 default_mipi_csi_regs[] = {
750750
751751struct gc2145_config {
752752 struct i2c_dt_spec i2c ;
753- #if DT_INST_NODE_HAS_PROP ( 0 , pwdn_gpios )
753+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY ( pwdn_gpios )
754754 struct gpio_dt_spec pwdn_gpio ;
755755#endif
756- #if DT_INST_NODE_HAS_PROP ( 0 , reset_gpios )
756+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY ( reset_gpios )
757757 struct gpio_dt_spec reset_gpio ;
758758#endif
759759 int bus_type ;
@@ -1221,23 +1221,40 @@ static int gc2145_init(const struct device *dev)
12211221 const struct gc2145_config * cfg = dev -> config ;
12221222 (void ) cfg ;
12231223
1224- #if DT_INST_NODE_HAS_PROP (0 , pwdn_gpios )
1225- ret = gpio_pin_configure_dt (& cfg -> pwdn_gpio , GPIO_OUTPUT_INACTIVE );
1226- if (ret ) {
1227- return ret ;
1224+ if (!i2c_is_ready_dt (& cfg -> i2c )) {
1225+ LOG_ERR ("Bus device is not ready" );
1226+ return - ENODEV ;
12281227 }
12291228
1229+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (pwdn_gpios )
1230+ if (cfg -> pwdn_gpio .port != NULL ) {
1231+ if (!gpio_is_ready_dt (& cfg -> pwdn_gpio )) {
1232+ LOG_ERR ("%s: device %s is not ready" , dev -> name , cfg -> pwdn_gpio .port -> name );
1233+ return - ENODEV ;
1234+ }
1235+ ret = gpio_pin_configure_dt (& cfg -> pwdn_gpio , GPIO_OUTPUT_INACTIVE );
1236+ if (ret ) {
1237+ return ret ;
1238+ }
1239+ }
12301240 k_sleep (K_MSEC (10 ));
12311241#endif
1232- #if DT_INST_NODE_HAS_PROP (0 , reset_gpios )
1233- ret = gpio_pin_configure_dt (& cfg -> reset_gpio , GPIO_OUTPUT_ACTIVE );
1234- if (ret ) {
1235- return ret ;
1236- }
1242+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (reset_gpios )
1243+ if (cfg -> reset_gpio .port != NULL ) {
1244+ if (!gpio_is_ready_dt (& cfg -> reset_gpio )) {
1245+ LOG_ERR ("%s: device %s is not ready" , dev -> name ,
1246+ cfg -> reset_gpio .port -> name );
1247+ return - ENODEV ;
1248+ }
1249+ ret = gpio_pin_configure_dt (& cfg -> reset_gpio , GPIO_OUTPUT_ACTIVE );
1250+ if (ret ) {
1251+ return ret ;
1252+ }
12371253
1238- k_sleep (K_MSEC (1 ));
1239- gpio_pin_set_dt (& cfg -> reset_gpio , 0 );
1240- k_sleep (K_MSEC (1 ));
1254+ k_sleep (K_MSEC (1 ));
1255+ gpio_pin_set_dt (& cfg -> reset_gpio , 0 );
1256+ k_sleep (K_MSEC (1 ));
1257+ }
12411258#endif
12421259
12431260 ret = gc2145_check_connection (dev );
@@ -1265,46 +1282,30 @@ static int gc2145_init(const struct device *dev)
12651282 return gc2145_init_controls (dev );
12661283}
12671284
1268- /* Unique Instance */
1269- static const struct gc2145_config gc2145_cfg_0 = {
1270- .i2c = I2C_DT_SPEC_INST_GET (0 ),
1271- #if DT_INST_NODE_HAS_PROP (0 , pwdn_gpios )
1272- .pwdn_gpio = GPIO_DT_SPEC_INST_GET (0 , pwdn_gpios ),
1285+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (reset_gpios )
1286+ #define GC2145_GET_RESET_GPIO (n ) .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {0}),
1287+ #else
1288+ #define GC2145_GET_RESET_GPIO (n )
12731289#endif
1274- #if DT_INST_NODE_HAS_PROP (0 , reset_gpios )
1275- .reset_gpio = GPIO_DT_SPEC_INST_GET (0 , reset_gpios ),
1290+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (pwdn_gpios )
1291+ #define GC2145_GET_PWDN_GPIO (n ) .pwdn_gpio = GPIO_DT_SPEC_INST_GET_OR(n, pwdn_gpios, {0}),
1292+ #else
1293+ #define GC2145_GET_PWDN_GPIO (n )
12761294#endif
1277- .bus_type = DT_PROP_OR (DT_INST_ENDPOINT_BY_ID (0 , 0 , 0 ), bus_type ,
1278- VIDEO_BUS_TYPE_PARALLEL ),
1279- };
1280- static struct gc2145_data gc2145_data_0 ;
1281-
1282- static int gc2145_init_0 (const struct device * dev )
1283- {
1284- const struct gc2145_config * cfg = dev -> config ;
1285-
1286- if (!i2c_is_ready_dt (& cfg -> i2c )) {
1287- LOG_ERR ("Bus device is not ready" );
1288- return - ENODEV ;
1289- }
1290-
1291- #if DT_INST_NODE_HAS_PROP (0 , pwdn_gpios )
1292- if (!gpio_is_ready_dt (& cfg -> pwdn_gpio )) {
1293- LOG_ERR ("%s: device %s is not ready" , dev -> name , cfg -> pwdn_gpio .port -> name );
1294- return - ENODEV ;
1295- }
1296- #endif
1297- #if DT_INST_NODE_HAS_PROP (0 , reset_gpios )
1298- if (!gpio_is_ready_dt (& cfg -> reset_gpio )) {
1299- LOG_ERR ("%s: device %s is not ready" , dev -> name , cfg -> reset_gpio .port -> name );
1300- return - ENODEV ;
1301- }
1302- #endif
1303-
1304- return gc2145_init (dev );
1305- }
1306-
1307- DEVICE_DT_INST_DEFINE (0 , & gc2145_init_0 , NULL , & gc2145_data_0 , & gc2145_cfg_0 , POST_KERNEL ,
1308- CONFIG_VIDEO_INIT_PRIORITY , & gc2145_driver_api );
13091295
1310- VIDEO_DEVICE_DEFINE (gc2145 , DEVICE_DT_INST_GET (0 ), NULL );
1296+ #define GC2145_INIT (n ) \
1297+ static struct gc2145_data gc2145_data_##n; \
1298+ static const struct gc2145_config gc2145_cfg_##n = { \
1299+ .i2c = I2C_DT_SPEC_INST_GET(n), \
1300+ GC2145_GET_PWDN_GPIO(n) \
1301+ GC2145_GET_RESET_GPIO(n) \
1302+ .bus_type = DT_PROP_OR(DT_INST_ENDPOINT_BY_ID(n, 0, 0), bus_type, \
1303+ VIDEO_BUS_TYPE_PARALLEL), \
1304+ }; \
1305+ \
1306+ DEVICE_DT_INST_DEFINE(n, &gc2145_init, NULL, &gc2145_data_##n, &gc2145_cfg_##n, \
1307+ POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &gc2145_driver_api); \
1308+ \
1309+ VIDEO_DEVICE_DEFINE(gc2145_##n, DEVICE_DT_INST_GET(n), NULL);
1310+
1311+ DT_INST_FOREACH_STATUS_OKAY (GC2145_INIT )
0 commit comments