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:
parent
ed9ca0f6d3
commit
d9fe261f8e
3 changed files with 65 additions and 13 deletions
|
@ -59,9 +59,33 @@ static int regulator_fixed_disable(const struct device *dev)
|
||||||
return gpio_pin_set_dt(&cfg->enable, 0);
|
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 = {
|
static const struct regulator_driver_api regulator_fixed_api = {
|
||||||
.enable = regulator_fixed_enable,
|
.enable = regulator_fixed_enable,
|
||||||
.disable = regulator_fixed_disable,
|
.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)
|
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);
|
return regulator_common_init(dev, init_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REGULATOR_FIXED_DEFINE(inst) \
|
#define REGULATOR_FIXED_DEFINE(inst) \
|
||||||
static struct regulator_fixed_data data##inst; \
|
BUILD_ASSERT(DT_INST_PROP_OR(inst, regulator_min_microvolt, 0) == \
|
||||||
\
|
DT_INST_PROP_OR(inst, regulator_max_microvolt, 0), \
|
||||||
static const struct regulator_fixed_config config##inst = { \
|
"Regulator requires fixed voltages"); \
|
||||||
.common = REGULATOR_DT_INST_COMMON_CONFIG_INIT(inst), \
|
static struct regulator_fixed_data data##inst; \
|
||||||
.startup_delay_us = DT_INST_PROP(inst, startup_delay_us), \
|
\
|
||||||
.off_on_delay_us = DT_INST_PROP(inst, off_on_delay_us), \
|
static const struct regulator_fixed_config config##inst = { \
|
||||||
.enable = GPIO_DT_SPEC_INST_GET_OR(inst, enable_gpios, {0}), \
|
.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), \
|
||||||
DEVICE_DT_INST_DEFINE(inst, regulator_fixed_init, NULL, &data##inst, \
|
.enable = GPIO_DT_SPEC_INST_GET_OR(inst, enable_gpios, {0}), \
|
||||||
&config##inst, POST_KERNEL, \
|
}; \
|
||||||
CONFIG_REGULATOR_FIXED_INIT_PRIORITY, \
|
\
|
||||||
|
DEVICE_DT_INST_DEFINE(inst, regulator_fixed_init, NULL, &data##inst, \
|
||||||
|
&config##inst, POST_KERNEL, \
|
||||||
|
CONFIG_REGULATOR_FIXED_INIT_PRIORITY, \
|
||||||
®ulator_fixed_api);
|
®ulator_fixed_api);
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_FIXED_DEFINE)
|
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_FIXED_DEFINE)
|
||||||
|
|
|
@ -11,6 +11,8 @@ include:
|
||||||
- regulator-name
|
- regulator-name
|
||||||
- regulator-boot-on
|
- regulator-boot-on
|
||||||
- regulator-always-on
|
- regulator-always-on
|
||||||
|
- regulator-min-microvolt
|
||||||
|
- regulator-max-microvolt
|
||||||
|
|
||||||
compatible: "regulator-fixed"
|
compatible: "regulator-fixed"
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Copyright (c) 2019-2020 Peter Bigot Consulting, LLC
|
* Copyright (c) 2019-2020 Peter Bigot Consulting, LLC
|
||||||
* Copyright (c) 2021 NXP
|
* Copyright (c) 2021 NXP
|
||||||
* Copyright (c) 2022 Nordic Semiconductor ASA
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
* Copyright (c) 2023 EPAM Systems
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -242,6 +243,28 @@ static inline bool regulator_common_is_init_enabled(const struct device *dev)
|
||||||
return (config->flags & REGULATOR_INIT_ENABLED) != 0U;
|
return (config->flags & REGULATOR_INIT_ENABLED) != 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get minimum supported voltage.
|
||||||
|
*
|
||||||
|
* @param dev Regulator device instance.
|
||||||
|
* @param min_uv Where minimum voltage will be stored, in microvolts.
|
||||||
|
*
|
||||||
|
* @retval 0 If successful
|
||||||
|
* @retval -ENOENT If minimum voltage is not specified.
|
||||||
|
*/
|
||||||
|
static inline int regulator_common_get_min_voltage(const struct device *dev, int32_t *min_uv)
|
||||||
|
{
|
||||||
|
const struct regulator_common_config *config =
|
||||||
|
(const struct regulator_common_config *)dev->config;
|
||||||
|
|
||||||
|
if (config->min_uv == INT32_MIN) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
*min_uv = config->min_uv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** @endcond */
|
/** @endcond */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue