drivers: regulator: provide generic regulator_is_supported_voltage

The function can be implemented by using regulator_count_voltages() +
regulator_list_voltage(), so there's no need to defer the job to each
driver.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-12-01 12:05:22 +01:00 committed by Carles Cufí
commit 4e8795a8ce
3 changed files with 23 additions and 39 deletions

View file

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