Skip to content

Commit 25bae8d

Browse files
author
Alain Volmat
committed
video: imx335: only include gpio code if needed
Rely on DT_ANY_INST_HAS_PROP_STATUS_OKAY to only build the gpio handling code for reset pin if this is being used by one or more instance of the device. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1 parent 59144b0 commit 25bae8d

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

drivers/video/imx335.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ LOG_MODULE_REGISTER(video_imx335, CONFIG_VIDEO_LOG_LEVEL);
2828

2929
struct imx335_config {
3030
struct i2c_dt_spec i2c;
31+
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
3132
struct gpio_dt_spec reset_gpio;
33+
#endif
3234
uint32_t input_clk;
3335
};
3436

@@ -445,26 +447,27 @@ static int imx335_init(const struct device *dev)
445447
return -ENODEV;
446448
}
447449

448-
if (!gpio_is_ready_dt(&cfg->reset_gpio)) {
449-
LOG_ERR("%s: device %s is not ready", dev->name, cfg->reset_gpio.port->name);
450-
return -ENODEV;
451-
}
450+
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
451+
if (cfg->reset_gpio.port != NULL) {
452+
if (!gpio_is_ready_dt(&cfg->reset_gpio)) {
453+
LOG_ERR("%s: device %s is not ready", dev->name,
454+
cfg->reset_gpio.port->name);
455+
return -ENODEV;
456+
}
452457

453-
/* Power up sequence */
454-
if (cfg->reset_gpio.port) {
458+
/* Power up sequence */
455459
ret = gpio_pin_configure_dt(&cfg->reset_gpio, GPIO_OUTPUT_ACTIVE);
456460
if (ret) {
457461
return ret;
458462
}
459-
}
460463

461-
k_sleep(K_NSEC(500)); /* Tlow */
464+
k_sleep(K_NSEC(500)); /* Tlow */
462465

463-
if (cfg->reset_gpio.port) {
464466
gpio_pin_set_dt(&cfg->reset_gpio, 0);
465-
}
466467

467-
k_sleep(K_USEC(600)); /* T4 */
468+
k_sleep(K_USEC(600)); /* T4 */
469+
}
470+
#endif
468471

469472
/* Initialize register values */
470473
ret = video_write_cci_multiregs(&cfg->i2c, imx335_init_params,
@@ -499,6 +502,12 @@ static int imx335_init(const struct device *dev)
499502
return imx335_init_controls(dev);
500503
}
501504

505+
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
506+
#define IMX335_GET_RESET_GPIO(n) .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {0}),
507+
#else
508+
#define IMX335_GET_RESET_GPIO(n)
509+
#endif
510+
502511
#define IMX335_INIT(n) \
503512
static struct imx335_data imx335_data_##n = { \
504513
.fmt = { \
@@ -509,7 +518,7 @@ static int imx335_init(const struct device *dev)
509518
}; \
510519
static const struct imx335_config imx335_cfg_##n = { \
511520
.i2c = I2C_DT_SPEC_INST_GET(n), \
512-
.reset_gpio = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {0}), \
521+
IMX335_GET_RESET_GPIO(n) \
513522
.input_clk = DT_INST_PROP_BY_PHANDLE(n, clocks, clock_frequency), \
514523
}; \
515524
\

0 commit comments

Comments
 (0)