From: Laxman Dewangan Date: Tue, 8 Mar 2016 10:53:21 +0000 (+0530) Subject: UPSTREAM: regulator: pwm: Fix calculation of voltage-to-duty cycle X-Git-Tag: firefly_0821_release~479 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4df4795120da3cf2ddb2388faf1e0d247e862bb5;p=firefly-linux-kernel-4.4.55.git UPSTREAM: regulator: pwm: Fix calculation of voltage-to-duty cycle With following equation for calculating voltage_to_duty_cycle_percentage 100 - (((req_uV * 100) - (min_uV * 100)) / diff); we get 0% for max_uV and 100% for min_uV. Correcting this to ((req_uV * 100) - (min_uV * 100)) / diff; to get proper duty cycle. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown (cherry picked from commit 1aaab34878ac14efede3f0e737b99447745699d1) Change-Id: I61d88577ece2d7bec3e9ea6c863c101c65892271 Signed-off-by: David Wu --- diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index 3aca067b9901..4d8eb3506dc8 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c @@ -115,7 +115,7 @@ static int pwm_voltage_to_duty_cycle_percentage(struct regulator_dev *rdev, int int max_uV = rdev->constraints->max_uV; int diff = max_uV - min_uV; - return 100 - (((req_uV * 100) - (min_uV * 100)) / diff); + return ((req_uV * 100) - (min_uV * 100)) / diff; } static int pwm_regulator_get_voltage(struct regulator_dev *rdev)