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); 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)
@ -99,6 +123,9 @@ static int regulator_fixed_init(const struct device *dev)
} }
#define REGULATOR_FIXED_DEFINE(inst) \ #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 struct regulator_fixed_data data##inst; \
\ \
static const struct regulator_fixed_config config##inst = { \ static const struct regulator_fixed_config config##inst = { \

View file

@ -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"

View file

@ -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 */
/** /**