public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] regulator: pwm: Fix regulator ramp delay for continuous mode
@ 2016-07-06 18:42 Douglas Anderson
  2016-07-07  8:36 ` Laxman Dewangan
  2016-07-07 10:01 ` Applied "regulator: pwm: Fix regulator ramp delay for continuous mode" to the regulator tree Mark Brown
  0 siblings, 2 replies; 8+ messages in thread
From: Douglas Anderson @ 2016-07-06 18:42 UTC (permalink / raw)
  To: Mark Brown
  Cc: boris.brezillon, lee.jones, briannorris, linux-rockchip,
	Heiko Stuebner, thierry.reding, ldewangan, 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%.

NOTE: This commit doesn't add support for regulator-enable-ramp-delay.
That could be done in a future patch when someone has a user of that
featre.

Though this patch is shows as "fixing" a bug, there are no actual known
users of continuous mode PWM regulator w/ ramp delay in mainline and so
this likely won't have any effect on anyone unless they are working
out-of-tree with private patches.  For anyone in this state, it is
highly encouraged to also pick Boris Brezillon's WIP patches to get
yourself a reliable and glitch-free regulator.

Fixes: 4773be185a0f ("regulator: pwm-regulator: Add support for continuous-voltage")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
Note: I don't have a board that works against mainline and can use the
PWM regulator in continuous mode without Boris's patches.  That means
that this patch has only been compile tested.  The previous version of
the patches (atop Boris's changes) was tested more thoroughly.  YMMV.

Changes in v2:
- No longer atop Boris PWM regulator fixes (Mark).
- Don't delay if the regulator is not enabled (Boris).

 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 ab3cc0235843..75d9f9b1ad62 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -132,6 +132,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
 	unsigned int duty_pulse;
 	u64 req_period;
 	u32 rem;
+	int old_uV = pwm_regulator_get_voltage(rdev);
 	int ret;
 
 	pwm_get_args(drvdata->pwm, &pargs);
@@ -161,8 +162,12 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
 
 	drvdata->volt_uV = min_uV;
 
-	/* Delay required by PWM regulator to settle to the new voltage */
-	usleep_range(ramp_delay, ramp_delay + 1000);
+	if ((ramp_delay == 0) || !pwm_regulator_is_enabled(rdev))
+		return 0;
+
+	/* Ramp delay is in uV/uS. Adjust to uS and delay */
+	ramp_delay = DIV_ROUND_UP(abs(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] 8+ messages in thread

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-06 18:42 [PATCH v2] regulator: pwm: Fix regulator ramp delay for continuous mode Douglas Anderson
2016-07-07  8:36 ` Laxman Dewangan
2016-07-07 16:30   ` Doug Anderson
2016-07-07 18:23     ` Aleksandr Frid
2016-07-07 18:31       ` Doug Anderson
2016-07-07 18:43         ` Aleksandr Frid
2016-07-08  8:53           ` Mark Brown
2016-07-07 10:01 ` Applied "regulator: pwm: Fix regulator ramp delay for continuous mode" to the regulator tree Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox