| From da34517710552131881039400947fec6ec621ee7 Mon Sep 17 00:00:00 2001 |
| From: Bjorn Andersson <bjorn@kryo.se> |
| Date: Wed, 5 Feb 2014 12:30:26 -0800 |
| Subject: regulator: core: Allow regulator_set_voltage for fixed regulators |
| |
| Make it okay to call regulator_set_voltage on regulators with fixed |
| voltage if the requested range overlaps the current/configured voltage. |
| |
| Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com> |
| Signed-off-by: Mark Brown <broonie@linaro.org> |
| (cherry picked from commit c00dc359e5e0b10de993651d8e73e60c41bf29cd) |
| Signed-off-by: Simon Horman <horms+renesas@verge.net.au> |
| (cherry picked from commit d5c3595331d512c6af6b636cef687421c2ba11e3) |
| Signed-off-by: Simon Horman <horms+renesas@verge.net.au> |
| --- |
| drivers/regulator/core.c | 14 ++++++++++++++ |
| 1 file changed, 14 insertions(+) |
| |
| diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c |
| index afca1bc24f26..bac485acc7f3 100644 |
| --- a/drivers/regulator/core.c |
| +++ b/drivers/regulator/core.c |
| @@ -2399,6 +2399,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) |
| struct regulator_dev *rdev = regulator->rdev; |
| int ret = 0; |
| int old_min_uV, old_max_uV; |
| + int current_uV; |
| |
| mutex_lock(&rdev->mutex); |
| |
| @@ -2409,6 +2410,19 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) |
| if (regulator->min_uV == min_uV && regulator->max_uV == max_uV) |
| goto out; |
| |
| + /* If we're trying to set a range that overlaps the current voltage, |
| + * return succesfully even though the regulator does not support |
| + * changing the voltage. |
| + */ |
| + if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
| + current_uV = _regulator_get_voltage(rdev); |
| + if (min_uV <= current_uV && current_uV <= max_uV) { |
| + regulator->min_uV = min_uV; |
| + regulator->max_uV = max_uV; |
| + goto out; |
| + } |
| + } |
| + |
| /* sanity check */ |
| if (!rdev->desc->ops->set_voltage && |
| !rdev->desc->ops->set_voltage_sel) { |
| -- |
| 2.1.2 |
| |