Skip to content

Commit dc9ceed

Browse files
committed
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>
1 parent ad81f05 commit dc9ceed

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎include/linux/regulator/consumer.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,11 @@ static inline int regulator_count_voltages(struct regulator *regulator)
369369
static inline int regulator_set_voltage_tol(struct regulator *regulator,
370370
int new_uV, int tol_uV)
371371
{
372-
return regulator_set_voltage(regulator,
373-
new_uV - tol_uV, new_uV + tol_uV);
372+
if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
373+
return 0;
374+
else
375+
return regulator_set_voltage(regulator,
376+
new_uV - tol_uV, new_uV + tol_uV);
374377
}
375378

376379
static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,

0 commit comments

Comments
 (0)