diff --git a/drivers/regulator/regulator_pca9420.c b/drivers/regulator/regulator_pca9420.c index 063cdd90602..f2c1b35e1bf 100644 --- a/drivers/regulator/regulator_pca9420.c +++ b/drivers/regulator/regulator_pca9420.c @@ -271,23 +271,14 @@ static unsigned int regulator_pca9420_count_voltages(const struct device *dev) config->desc->num_ranges); } -/** - * Part of the extended regulator consumer API - * Returns the supported voltage in uV for a given selector value - */ -static int32_t regulator_pca9420_list_voltages(const struct device *dev, - unsigned int selector) +static int regulator_pca9420_list_voltage(const struct device *dev, + unsigned int idx, int32_t *volt_uv) { const struct regulator_pca9420_config *config = dev->config; - int32_t value; - if (linear_range_group_get_value(config->desc->ranges, - config->desc->num_ranges, selector, - &value) < 0) { - return 0; - } - - return value; + return linear_range_group_get_value(config->desc->ranges, + config->desc->num_ranges, idx, + volt_uv); } /** @@ -536,7 +527,7 @@ static const struct regulator_driver_api api = { .enable = regulator_pca9420_enable, .disable = regulator_pca9420_disable, .count_voltages = regulator_pca9420_count_voltages, - .list_voltages = regulator_pca9420_list_voltages, + .list_voltage = regulator_pca9420_list_voltage, .is_supported_voltage = regulator_pca9420_is_supported_voltage, .set_voltage = regulator_pca9420_set_voltage, .get_voltage = regulator_pca9420_get_voltage, diff --git a/include/zephyr/drivers/regulator.h b/include/zephyr/drivers/regulator.h index 7892337286e..b3628de51a1 100644 --- a/include/zephyr/drivers/regulator.h +++ b/include/zephyr/drivers/regulator.h @@ -32,8 +32,8 @@ __subsystem struct regulator_driver_api { int (*enable)(const struct device *dev); int (*disable)(const struct device *dev); unsigned int (*count_voltages)(const struct device *dev); - int32_t (*list_voltages)(const struct device *dev, - unsigned int selector); + int (*list_voltage)(const struct device *dev, unsigned int idx, + int32_t *volt_uv); int (*is_supported_voltage)(const struct device *dev, int32_t min_uv, int32_t max_uv); int (*set_voltage)(const struct device *dev, int32_t min_uv, @@ -110,7 +110,7 @@ int regulator_disable(const struct device *dev); * * Each voltage level supported by a regulator gets an index, starting from * zero. The total number of supported voltage levels can be used together with - * regulator_list_voltages() to list all supported voltage levels. + * regulator_list_voltage() to list all supported voltage levels. * * @param dev Regulator device instance. * @@ -129,25 +129,31 @@ static inline unsigned int regulator_count_voltages(const struct device *dev) } /** - * @brief Obtain supported voltages. + * @brief Obtain the value of a voltage given an index. + * + * Each voltage level supported by a regulator gets an index, starting from + * zero. Together with regulator_count_voltages(), this function can be used + * to iterate over all supported voltages. * * @param dev Regulator device instance. - * @param selector Voltage selector. + * @param idx Voltage index. + * @param[out] volt_uv Where voltage for the given @p index will be stored, in + * microvolts. * - * @return voltage Voltage level in microvolts. - * @retval 0 If selector code can't be used. + * @retval 0 If @p index corresponds to a supported voltage. + * @retval -EINVAL If @p index does not correspond to a supported voltage. */ -static inline int32_t regulator_list_voltages(const struct device *dev, - unsigned int selector) +static inline int regulator_list_voltage(const struct device *dev, + unsigned int idx, int32_t *volt_uv) { const struct regulator_driver_api *api = (const struct regulator_driver_api *)dev->api; - if (api->list_voltages == NULL) { - return 0; + if (api->list_voltage == NULL) { + return -EINVAL; } - return api->list_voltages(dev, selector); + return api->list_voltage(dev, idx, volt_uv); } /**