All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: pwm: Fix regulator ramp delay for continuous mode
@ 2016-06-28  4:53 Douglas Anderson
  2016-06-28 10:32 ` Caesar Wang
                   ` (5 more replies)
  0 siblings, 6 replies; 34+ messages in thread
From: Douglas Anderson @ 2016-06-28  4:53 UTC (permalink / raw)
  To: Mark Brown
  Cc: boris.brezillon, lee.jones, briannorris, linux-rockchip,
	Heiko Stuebner, Douglas Anderson, lgirdwood, linux-kernel

The original commit adding support for continuous voltage mode didn't
handle the regulator ramp delay properly.  It treated the delay as a
fixed delay in uS despite the property being defined as uV / uS.  Let's
adjust it.  Luckily there appear to be no users of this ramp delay for
PWM regulators (as per grepping through device trees in linuxnext).

Note also that the upper bound of usleep_range probably shouldn't be a
full 1 ms longer than the lower bound since I've seen plenty of hardware
with a ramp rate of ~5000 uS / uV and for small jumps the total delays
are in the tens of uS.  1000 is way too much.  We'll try to be dynamic
and use 10%

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
Note that this patch is atop Boris's recent PWM regulator fixes.  If
desired it wouldn't be too hard to write it atop the old code, though
quite honestly anyone using a PWM regulator should probably be using his
new code.

 drivers/regulator/pwm-regulator.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index fa1c74c77bb0..de94d19f6e1f 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -188,6 +188,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
 	struct pwm_state pstate;
 	unsigned int diff_duty;
 	unsigned int dutycycle;
+	int old_uV = pwm_regulator_get_voltage(rdev);
 	int ret;
 
 	pwm_init_state(drvdata->pwm, &pstate);
@@ -219,8 +220,12 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
 		return ret;
 	}
 
-	/* Delay required by PWM regulator to settle to the new voltage */
-	usleep_range(ramp_delay, ramp_delay + 1000);
+	if (ramp_delay == 0)
+		return 0;
+
+	/* Ramp delay is in uV/uS. Adjust to uS and delay */
+	ramp_delay = DIV_ROUND_UP(abs(req_min_uV - old_uV), ramp_delay);
+	usleep_range(ramp_delay, ramp_delay + DIV_ROUND_UP(ramp_delay, 10));
 
 	return 0;
 }
-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2016-07-08 16:42 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-28  4:53 [PATCH] regulator: pwm: Fix regulator ramp delay for continuous mode Douglas Anderson
2016-06-28 10:32 ` Caesar Wang
2016-06-28 16:07 ` Brian Norris
2016-06-28 16:07   ` Brian Norris
2016-06-28 18:52 ` Mark Brown
2016-06-28 19:31   ` Doug Anderson
2016-06-28 19:31     ` Doug Anderson
2016-06-28 19:53     ` Mark Brown
2016-06-28 19:53       ` Mark Brown
2016-06-28 18:56 ` Mark Brown
2016-06-28 18:56   ` Mark Brown
2016-06-28 19:35   ` Doug Anderson
2016-06-28 19:35     ` Doug Anderson
2016-07-01  8:06 ` Mark Brown
2016-07-01 20:17   ` Doug Anderson
2016-07-01 20:17     ` Doug Anderson
2016-07-02  7:59     ` Mark Brown
2016-07-02  7:59       ` Mark Brown
2016-07-06 18:30       ` Doug Anderson
2016-07-07  8:17         ` Mark Brown
2016-07-02 15:47     ` Boris Brezillon
2016-07-02 15:47       ` Boris Brezillon
2016-07-04  8:53       ` Mark Brown
2016-07-04  8:53         ` Mark Brown
2016-07-04  9:05         ` Boris Brezillon
2016-07-04  9:05           ` Boris Brezillon
2016-07-04  9:13           ` Mark Brown
2016-07-04  9:13             ` Mark Brown
2016-07-08 16:41             ` Thierry Reding
2016-07-06 12:27 ` Boris Brezillon
2016-07-06 18:31   ` Doug Anderson
2016-07-07  8:16     ` Mark Brown
2016-07-07  8:03   ` Mark Brown
2016-07-07  8:03     ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.