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:
parent
c77c3ac7d6
commit
4e8795a8ce
3 changed files with 23 additions and 39 deletions
|
@ -63,3 +63,21 @@ int regulator_disable(const struct device *dev)
|
||||||
|
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -188,10 +188,6 @@ static const struct regulator_pca9420_desc ldo2_desc = {
|
||||||
.num_ranges = ARRAY_SIZE(ldo2_ranges),
|
.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,
|
static bool regulator_pca9420_is_mode_allowed(const struct device *dev,
|
||||||
uint8_t mode)
|
uint8_t mode)
|
||||||
{
|
{
|
||||||
|
@ -281,22 +277,6 @@ static int regulator_pca9420_list_voltage(const struct device *dev,
|
||||||
volt_uv);
|
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
|
* Part of the extended regulator consumer API
|
||||||
* Sets the output voltage to the closest supported voltage value
|
* 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,
|
.disable = regulator_pca9420_disable,
|
||||||
.count_voltages = regulator_pca9420_count_voltages,
|
.count_voltages = regulator_pca9420_count_voltages,
|
||||||
.list_voltage = regulator_pca9420_list_voltage,
|
.list_voltage = regulator_pca9420_list_voltage,
|
||||||
.is_supported_voltage = regulator_pca9420_is_supported_voltage,
|
|
||||||
.set_voltage = regulator_pca9420_set_voltage,
|
.set_voltage = regulator_pca9420_set_voltage,
|
||||||
.get_voltage = regulator_pca9420_get_voltage,
|
.get_voltage = regulator_pca9420_get_voltage,
|
||||||
.get_current_limit = regulator_pca9420_get_current_limit,
|
.get_current_limit = regulator_pca9420_get_current_limit,
|
||||||
|
|
|
@ -34,8 +34,6 @@ __subsystem struct regulator_driver_api {
|
||||||
unsigned int (*count_voltages)(const struct device *dev);
|
unsigned int (*count_voltages)(const struct device *dev);
|
||||||
int (*list_voltage)(const struct device *dev, unsigned int idx,
|
int (*list_voltage)(const struct device *dev, unsigned int idx,
|
||||||
int32_t *volt_uv);
|
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,
|
int (*set_voltage)(const struct device *dev, int32_t min_uv,
|
||||||
int32_t max_uv);
|
int32_t max_uv);
|
||||||
int32_t (*get_voltage)(const struct device *dev);
|
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 dev Regulator device instance.
|
||||||
* @param min_uv Minimum voltage in microvolts.
|
* @param min_uv Minimum voltage in microvolts.
|
||||||
* @param max_uv maximum voltage in microvolts.
|
* @param max_uv maximum voltage in microvolts.
|
||||||
*
|
*
|
||||||
* @retval 0 If successful.
|
* @retval true If voltage is supported.
|
||||||
* @retval -ENOSYS If function is not implemented.
|
* @retval false If voltage is not supported.
|
||||||
* @retval -errno In case of any other error.
|
|
||||||
*/
|
*/
|
||||||
static inline int regulator_is_supported_voltage(const struct device *dev,
|
bool regulator_is_supported_voltage(const struct device *dev, int32_t min_uv,
|
||||||
int32_t min_uv, int32_t max_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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set output voltage.
|
* @brief Set output voltage.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue