diff --git a/drivers/regulator/regulator_common.c b/drivers/regulator/regulator_common.c index be733456b89..d256f6e6012 100644 --- a/drivers/regulator/regulator_common.c +++ b/drivers/regulator/regulator_common.c @@ -63,3 +63,21 @@ int regulator_disable(const struct device *dev) return ret; } + +bool regulator_is_supported_voltage(const struct device *dev, int32_t min_uv, + int32_t max_uv) +{ + unsigned int volt_cnt = regulator_count_voltages(dev); + + for (unsigned int idx = 0U; idx < volt_cnt; idx++) { + int32_t volt_uv; + + (void)regulator_list_voltage(dev, idx, &volt_uv); + + if ((volt_uv > min_uv) && (volt_uv < max_uv)) { + return true; + } + } + + return false; +} diff --git a/drivers/regulator/regulator_pca9420.c b/drivers/regulator/regulator_pca9420.c index f2c1b35e1bf..0ea697cf7cf 100644 --- a/drivers/regulator/regulator_pca9420.c +++ b/drivers/regulator/regulator_pca9420.c @@ -188,10 +188,6 @@ static const struct regulator_pca9420_desc ldo2_desc = { .num_ranges = ARRAY_SIZE(ldo2_ranges), }; -static int regulator_pca9420_is_supported_voltage(const struct device *dev, - int32_t min_uv, - int32_t max_uv); - static bool regulator_pca9420_is_mode_allowed(const struct device *dev, uint8_t mode) { @@ -281,22 +277,6 @@ static int regulator_pca9420_list_voltage(const struct device *dev, volt_uv); } -/** - * Part of the extended regulator consumer API - * Returns true if the regulator supports a voltage in the given range. - */ -static int regulator_pca9420_is_supported_voltage(const struct device *dev, - int32_t min_uv, - int32_t max_uv) -{ - const struct regulator_pca9420_config *config = dev->config; - uint16_t idx; - - return linear_range_group_get_win_index(config->desc->ranges, - config->desc->num_ranges, - min_uv, max_uv, &idx); -} - /** * Part of the extended regulator consumer API * Sets the output voltage to the closest supported voltage value @@ -528,7 +508,6 @@ static const struct regulator_driver_api api = { .disable = regulator_pca9420_disable, .count_voltages = regulator_pca9420_count_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, .get_current_limit = regulator_pca9420_get_current_limit, diff --git a/include/zephyr/drivers/regulator.h b/include/zephyr/drivers/regulator.h index b3628de51a1..9131ad0fe60 100644 --- a/include/zephyr/drivers/regulator.h +++ b/include/zephyr/drivers/regulator.h @@ -34,8 +34,6 @@ __subsystem struct regulator_driver_api { unsigned int (*count_voltages)(const struct device *dev); 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, int32_t max_uv); int32_t (*get_voltage)(const struct device *dev); @@ -157,28 +155,17 @@ static inline int regulator_list_voltage(const struct device *dev, } /** - * @brief Check if a voltage range is supported. + * @brief Check if a voltage within a window is supported. * * @param dev Regulator device instance. * @param min_uv Minimum voltage in microvolts. * @param max_uv maximum voltage in microvolts. * - * @retval 0 If successful. - * @retval -ENOSYS If function is not implemented. - * @retval -errno In case of any other error. + * @retval true If voltage is supported. + * @retval false If voltage is not supported. */ -static inline int regulator_is_supported_voltage(const struct device *dev, - int32_t min_uv, int32_t max_uv) -{ - const struct regulator_driver_api *api = - (const struct regulator_driver_api *)dev->api; - - if (api->is_supported_voltage == NULL) { - return -ENOSYS; - } - - return api->is_supported_voltage(dev, min_uv, max_uv); -} +bool regulator_is_supported_voltage(const struct device *dev, int32_t min_uv, + int32_t max_uv); /** * @brief Set output voltage.