sensor: voltage_divider: fix power-gpio
`CONFIG_PM_DEVICE` being disabled does not mean that the `power-gpio` does not need to be controlled. Additionally, not having a `power-gpio` property does not mean that power management is not supported, just that is has no work to do. Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
parent
97bd924f59
commit
7ddbe9d4bd
1 changed files with 3 additions and 13 deletions
|
@ -17,9 +17,7 @@ LOG_MODULE_REGISTER(voltage, CONFIG_SENSOR_LOG_LEVEL);
|
|||
|
||||
struct voltage_config {
|
||||
struct voltage_divider_dt_spec voltage;
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
struct gpio_dt_spec gpio_power;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct voltage_data {
|
||||
|
@ -90,8 +88,8 @@ static int pm_action(const struct device *dev, enum pm_device_action action)
|
|||
int ret;
|
||||
|
||||
if (config->gpio_power.port == NULL) {
|
||||
LOG_ERR("PM not supported");
|
||||
return -ENOTSUP;
|
||||
/* No work to do */
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
|
@ -126,7 +124,6 @@ static int voltage_init(const struct device *dev)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
if (config->gpio_power.port != NULL) {
|
||||
if (!gpio_is_ready_dt(&config->gpio_power)) {
|
||||
LOG_ERR("Power GPIO is not ready");
|
||||
|
@ -138,7 +135,6 @@ static int voltage_init(const struct device *dev)
|
|||
LOG_ERR("failed to initialize GPIO for reset");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = adc_channel_setup_dt(&config->voltage.port);
|
||||
if (ret != 0) {
|
||||
|
@ -158,18 +154,12 @@ static int voltage_init(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
#define POWER_GPIOS(inst) .gpio_power = GPIO_DT_SPEC_INST_GET_OR(inst, power_gpios, {0}),
|
||||
#else
|
||||
#define POWER_GPIOS(inst)
|
||||
#endif
|
||||
|
||||
#define VOLTAGE_INIT(inst) \
|
||||
static struct voltage_data voltage_##inst##_data; \
|
||||
\
|
||||
static const struct voltage_config voltage_##inst##_config = { \
|
||||
.voltage = VOLTAGE_DIVIDER_DT_SPEC_GET(DT_DRV_INST(inst)), \
|
||||
POWER_GPIOS(inst) \
|
||||
.gpio_power = GPIO_DT_SPEC_INST_GET_OR(inst, power_gpios, {0}), \
|
||||
}; \
|
||||
\
|
||||
PM_DEVICE_DT_INST_DEFINE(inst, pm_action); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue