drivers: regulator-fixed: extend api of driver (list/count voltages)

Allow properties 'regulator-min-microvolt' and 'regulator-max-microvolt'
for fixed regulators: Note: they should be equal.

Add simple functions for getting list of allowed and count of voltages.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
This commit is contained in:
Mykola Kvach 2023-08-10 11:56:21 +03:00 committed by Fabio Baltieri
commit d9fe261f8e
3 changed files with 65 additions and 13 deletions

View file

@ -59,9 +59,33 @@ static int regulator_fixed_disable(const struct device *dev)
return gpio_pin_set_dt(&cfg->enable, 0);
}
static unsigned int regulator_fixed_count_voltages(const struct device *dev)
{
int32_t min_uv;
return (regulator_common_get_min_voltage(dev, &min_uv) < 0) ? 0U : 1U;
}
static int regulator_fixed_list_voltage(const struct device *dev,
unsigned int idx,
int32_t *volt_uv)
{
if (idx != 0) {
return -EINVAL;
}
if (regulator_common_get_min_voltage(dev, volt_uv) < 0) {
return -EINVAL;
}
return 0;
}
static const struct regulator_driver_api regulator_fixed_api = {
.enable = regulator_fixed_enable,
.disable = regulator_fixed_disable,
.count_voltages = regulator_fixed_count_voltages,
.list_voltage = regulator_fixed_list_voltage,
};
static int regulator_fixed_init(const struct device *dev)
@ -98,19 +122,22 @@ static int regulator_fixed_init(const struct device *dev)
return regulator_common_init(dev, init_enabled);
}
#define REGULATOR_FIXED_DEFINE(inst) \
static struct regulator_fixed_data data##inst; \
\
static const struct regulator_fixed_config config##inst = { \
.common = REGULATOR_DT_INST_COMMON_CONFIG_INIT(inst), \
.startup_delay_us = DT_INST_PROP(inst, startup_delay_us), \
.off_on_delay_us = DT_INST_PROP(inst, off_on_delay_us), \
.enable = GPIO_DT_SPEC_INST_GET_OR(inst, enable_gpios, {0}), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, regulator_fixed_init, NULL, &data##inst, \
&config##inst, POST_KERNEL, \
CONFIG_REGULATOR_FIXED_INIT_PRIORITY, \
#define REGULATOR_FIXED_DEFINE(inst) \
BUILD_ASSERT(DT_INST_PROP_OR(inst, regulator_min_microvolt, 0) == \
DT_INST_PROP_OR(inst, regulator_max_microvolt, 0), \
"Regulator requires fixed voltages"); \
static struct regulator_fixed_data data##inst; \
\
static const struct regulator_fixed_config config##inst = { \
.common = REGULATOR_DT_INST_COMMON_CONFIG_INIT(inst), \
.startup_delay_us = DT_INST_PROP(inst, startup_delay_us), \
.off_on_delay_us = DT_INST_PROP(inst, off_on_delay_us), \
.enable = GPIO_DT_SPEC_INST_GET_OR(inst, enable_gpios, {0}), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, regulator_fixed_init, NULL, &data##inst, \
&config##inst, POST_KERNEL, \
CONFIG_REGULATOR_FIXED_INIT_PRIORITY, \
&regulator_fixed_api);
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_FIXED_DEFINE)