提交 a204f41e 编写于 作者: S Sascha Hauer 提交者: Mark Brown

regulator: core: Factor out regulator_map_voltage

_regulator_call_set_voltage has code to translate a minimum/maximum
voltage pair into a selector. This code is useful for others aswell,
so create a regulator_map_voltage function.
Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 a9f226bc
...@@ -2606,6 +2606,23 @@ int regulator_is_supported_voltage(struct regulator *regulator, ...@@ -2606,6 +2606,23 @@ int regulator_is_supported_voltage(struct regulator *regulator,
} }
EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); EXPORT_SYMBOL_GPL(regulator_is_supported_voltage);
static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV,
int max_uV)
{
const struct regulator_desc *desc = rdev->desc;
if (desc->ops->map_voltage)
return desc->ops->map_voltage(rdev, min_uV, max_uV);
if (desc->ops->list_voltage == regulator_list_voltage_linear)
return regulator_map_voltage_linear(rdev, min_uV, max_uV);
if (desc->ops->list_voltage == regulator_list_voltage_linear_range)
return regulator_map_voltage_linear_range(rdev, min_uV, max_uV);
return regulator_map_voltage_iterate(rdev, min_uV, max_uV);
}
static int _regulator_call_set_voltage(struct regulator_dev *rdev, static int _regulator_call_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV, int min_uV, int max_uV,
unsigned *selector) unsigned *selector)
...@@ -2694,23 +2711,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, ...@@ -2694,23 +2711,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
} }
} else if (rdev->desc->ops->set_voltage_sel) { } else if (rdev->desc->ops->set_voltage_sel) {
if (rdev->desc->ops->map_voltage) { ret = regulator_map_voltage(rdev, min_uV, max_uV);
ret = rdev->desc->ops->map_voltage(rdev, min_uV,
max_uV);
} else {
if (rdev->desc->ops->list_voltage ==
regulator_list_voltage_linear)
ret = regulator_map_voltage_linear(rdev,
min_uV, max_uV);
else if (rdev->desc->ops->list_voltage ==
regulator_list_voltage_linear_range)
ret = regulator_map_voltage_linear_range(rdev,
min_uV, max_uV);
else
ret = regulator_map_voltage_iterate(rdev,
min_uV, max_uV);
}
if (ret >= 0) { if (ret >= 0) {
best_val = rdev->desc->ops->list_voltage(rdev, ret); best_val = rdev->desc->ops->list_voltage(rdev, ret);
if (min_uV <= best_val && max_uV >= best_val) { if (min_uV <= best_val && max_uV >= best_val) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册