aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown2013-07-04 11:27:14 -0500
committerPraneeth Bajjuri2013-07-18 17:38:54 -0500
commit64a3bde7bb657cd286b2efdb682a632ec1c115e4 (patch)
treebaabe051eafa9759b7864cc0808e0c89f8ab448c
parent2f9562f0a900faaf5b1df46c511c332544391402 (diff)
downloadkernel-audio-64a3bde7bb657cd286b2efdb682a632ec1c115e4.tar.gz
kernel-audio-64a3bde7bb657cd286b2efdb682a632ec1c115e4.tar.xz
kernel-audio-64a3bde7bb657cd286b2efdb682a632ec1c115e4.zip
regulator: core: Make set_voltage_tol() try for mid-range first
The expected semantic for something expressed as a tolerance is that it should deliver the specified value with some deviation allowed but this is not what set_voltage_tol() currently does. Instead it just passes the maximum possible range to set_voltage() which will typically result in a voltage aimed at lower than the target voltage. Instead first try to set a voltage between the target voltage and the upper limit, then fall back on the full range. This will be much more robust against physical variation in systems and makes the API behave more like users would expect. Signed-off-by: Mark Brown <broonie@linaro.org> [cherry-pick from https://git.kernel.org/cgit/linux/kernel/git/broonie/regulator.git/commit/?h=topic/core&id=dc9ceed6a12aff627c81e01ada191e8a23fcbe3e ] Change-Id: I52e88a886e4277e5f7d9f97192931290b9775eab Signed-off-by: Praneeth Bajjuri <praneeth@ti.com>
-rw-r--r--include/linux/regulator/consumer.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 7bc732ce6e50..8f3063f458d9 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -368,8 +368,11 @@ static inline int regulator_count_voltages(struct regulator *regulator)
368static inline int regulator_set_voltage_tol(struct regulator *regulator, 368static inline int regulator_set_voltage_tol(struct regulator *regulator,
369 int new_uV, int tol_uV) 369 int new_uV, int tol_uV)
370{ 370{
371 return regulator_set_voltage(regulator, 371 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
372 new_uV - tol_uV, new_uV + tol_uV); 372 return 0;
373 else
374 return regulator_set_voltage(regulator,
375 new_uV - tol_uV, new_uV + tol_uV);
373} 376}
374 377
375static inline int regulator_is_supported_voltage_tol(struct regulator *regulator, 378static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,