diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-10-20 08:37:27 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-10-20 10:43:53 -0400 |
commit | a204f41e2d670c07c4dbd382d5bd8f6db8347ac2 (patch) | |
tree | 9f3ea6b39c92184c7c098ce43ff04c0597eb95f5 | |
parent | a9f226bcd9bb1941e581806e83d2c03d4043c367 (diff) |
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: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/core.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 5d161e11d5e6..f15b04548715 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -2606,6 +2606,23 @@ int regulator_is_supported_voltage(struct regulator *regulator, | |||
2606 | } | 2606 | } |
2607 | EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); | 2607 | EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); |
2608 | 2608 | ||
2609 | static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV, | ||
2610 | int max_uV) | ||
2611 | { | ||
2612 | const struct regulator_desc *desc = rdev->desc; | ||
2613 | |||
2614 | if (desc->ops->map_voltage) | ||
2615 | return desc->ops->map_voltage(rdev, min_uV, max_uV); | ||
2616 | |||
2617 | if (desc->ops->list_voltage == regulator_list_voltage_linear) | ||
2618 | return regulator_map_voltage_linear(rdev, min_uV, max_uV); | ||
2619 | |||
2620 | if (desc->ops->list_voltage == regulator_list_voltage_linear_range) | ||
2621 | return regulator_map_voltage_linear_range(rdev, min_uV, max_uV); | ||
2622 | |||
2623 | return regulator_map_voltage_iterate(rdev, min_uV, max_uV); | ||
2624 | } | ||
2625 | |||
2609 | static int _regulator_call_set_voltage(struct regulator_dev *rdev, | 2626 | static int _regulator_call_set_voltage(struct regulator_dev *rdev, |
2610 | int min_uV, int max_uV, | 2627 | int min_uV, int max_uV, |
2611 | unsigned *selector) | 2628 | unsigned *selector) |
@@ -2694,23 +2711,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, | |||
2694 | } | 2711 | } |
2695 | 2712 | ||
2696 | } else if (rdev->desc->ops->set_voltage_sel) { | 2713 | } else if (rdev->desc->ops->set_voltage_sel) { |
2697 | if (rdev->desc->ops->map_voltage) { | 2714 | ret = regulator_map_voltage(rdev, min_uV, max_uV); |
2698 | ret = rdev->desc->ops->map_voltage(rdev, min_uV, | ||
2699 | max_uV); | ||
2700 | } else { | ||
2701 | if (rdev->desc->ops->list_voltage == | ||
2702 | regulator_list_voltage_linear) | ||
2703 | ret = regulator_map_voltage_linear(rdev, | ||
2704 | min_uV, max_uV); | ||
2705 | else if (rdev->desc->ops->list_voltage == | ||
2706 | regulator_list_voltage_linear_range) | ||
2707 | ret = regulator_map_voltage_linear_range(rdev, | ||
2708 | min_uV, max_uV); | ||
2709 | else | ||
2710 | ret = regulator_map_voltage_iterate(rdev, | ||
2711 | min_uV, max_uV); | ||
2712 | } | ||
2713 | |||
2714 | if (ret >= 0) { | 2715 | if (ret >= 0) { |
2715 | best_val = rdev->desc->ops->list_voltage(rdev, ret); | 2716 | best_val = rdev->desc->ops->list_voltage(rdev, ret); |
2716 | if (min_uV <= best_val && max_uV >= best_val) { | 2717 | if (min_uV <= best_val && max_uV >= best_val) { |