mirror of https://gitee.com/openkylin/linux.git
regulator: add regulator_desc_list_voltage_linear_range
Add regulator_desc_list_voltage_linear_range which can be used by drivers for getting the voltages before regulator is registered. This may be useful for drivers which need to fetch the voltage selectors at device-tree parsing callback. Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Acked-by: Mark Brown <broonie@kernel.org> Tested-by: Angus Ainslie <angus@akkea.ca> Reviewed-by: Angus Ainslie <angus@akkea.ca> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
f43d1b388f
commit
6a47b4da55
|
@ -593,6 +593,45 @@ int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(regulator_list_voltage_pickable_linear_range);
|
EXPORT_SYMBOL_GPL(regulator_list_voltage_pickable_linear_range);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* regulator_desc_list_voltage_linear_range - List voltages for linear ranges
|
||||||
|
*
|
||||||
|
* @desc: Regulator desc for regulator which volatges are to be listed
|
||||||
|
* @selector: Selector to convert into a voltage
|
||||||
|
*
|
||||||
|
* Regulators with a series of simple linear mappings between voltages
|
||||||
|
* and selectors who have set linear_ranges in the regulator descriptor
|
||||||
|
* can use this function prior regulator registration to list voltages.
|
||||||
|
* This is useful when voltages need to be listed during device-tree
|
||||||
|
* parsing.
|
||||||
|
*/
|
||||||
|
int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
|
||||||
|
unsigned int selector)
|
||||||
|
{
|
||||||
|
const struct regulator_linear_range *range;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!desc->n_linear_ranges) {
|
||||||
|
BUG_ON(!desc->n_linear_ranges);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < desc->n_linear_ranges; i++) {
|
||||||
|
range = &desc->linear_ranges[i];
|
||||||
|
|
||||||
|
if (!(selector >= range->min_sel &&
|
||||||
|
selector <= range->max_sel))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
selector -= range->min_sel;
|
||||||
|
|
||||||
|
return range->min_uV + (range->uV_step * selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(regulator_desc_list_voltage_linear_range);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* regulator_list_voltage_linear_range - List voltages for linear ranges
|
* regulator_list_voltage_linear_range - List voltages for linear ranges
|
||||||
*
|
*
|
||||||
|
@ -606,27 +645,7 @@ EXPORT_SYMBOL_GPL(regulator_list_voltage_pickable_linear_range);
|
||||||
int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
|
int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
|
||||||
unsigned int selector)
|
unsigned int selector)
|
||||||
{
|
{
|
||||||
const struct regulator_linear_range *range;
|
return regulator_desc_list_voltage_linear_range(rdev->desc, selector);
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!rdev->desc->n_linear_ranges) {
|
|
||||||
BUG_ON(!rdev->desc->n_linear_ranges);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
|
|
||||||
range = &rdev->desc->linear_ranges[i];
|
|
||||||
|
|
||||||
if (!(selector >= range->min_sel &&
|
|
||||||
selector <= range->max_sel))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
selector -= range->min_sel;
|
|
||||||
|
|
||||||
return range->min_uV + (range->uV_step * selector);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range);
|
EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range);
|
||||||
|
|
||||||
|
|
|
@ -539,4 +539,10 @@ void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
|
||||||
void regulator_lock(struct regulator_dev *rdev);
|
void regulator_lock(struct regulator_dev *rdev);
|
||||||
void regulator_unlock(struct regulator_dev *rdev);
|
void regulator_unlock(struct regulator_dev *rdev);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper functions intended to be used by regulator drivers prior registering
|
||||||
|
* their regulators.
|
||||||
|
*/
|
||||||
|
int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
|
||||||
|
unsigned int selector);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue