Path: csiph.com!news.freedyn.net!aioe.org!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Brian Norris Newsgroups: linux.kernel Subject: Re: [PATCH] regulator: pwm: Fix regulator ramp delay for continuous mode Date: Tue, 28 Jun 2016 18:10:01 +0200 Message-ID: References: Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=M0qHstUlckJkEb12ZpZ1d+4zDIiASNPMtWA+fq1sjOs=; b=eu3c/DRr8xL5KZYhQQZwKtIkmHS28UVNmHP9bOOhjeJ2k3STseDfiO2VHapQgCxu5b ER+mHoJtLpWo7uliBlGH/OLoDCXSScOcH4bqxrYiuecnoPowhJyDOsI6fYy1dVycEn0J tLUsqHlrd9fncJtTwo34rVcWOhxlk6AjDj3wY= X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=M0qHstUlckJkEb12ZpZ1d+4zDIiASNPMtWA+fq1sjOs=; b=GMdpOSOwV7dSRyUV8omnXOZ3S0/CWryTqtjKRO6RjNRlqI9TN9Xqe60MKXvaaEWBO7 gBC7CBSnjIoSdZseKRZLG7ID4I9ta3NqpVAsA4ljAaCQbqdcdzQgkP5G1BZdz6RleiQt /rXMY2cnhsECVJb5v5S+AHH7eu3Pqn0MEED/cLAke5noWYeCb6EatD9VeUeI5iBXJVaF 0pjXWfp3pieidsMVP+viERBjuborN1/Uc97winyh9+zT3sIJIzq4DH1/0f9qe9LRD54p T/QHEC4NNqYxeX/nZKfPlS45hTemE0aj0Rzpf/b2hqHJUkExyFwVL3H8SL01YnrBwhXn wlWA== X-Gm-Message-State: ALyK8tLvWR5xriR3Ya9LT+i3u8gPy3y1K1WFlzQA1Lx2WXS8biMI9utjN/Ny6XZ1VJnMh77b X-Received: by 10.36.158.197 with SMTP id p188mr4643732itd.97.1467130045533; Tue, 28 Jun 2016 09:07:25 -0700 (PDT) X-Received: by 10.107.25.7 with SMTP id 7mr4471482ioz.104.1467130044228; Tue, 28 Jun 2016 09:07:24 -0700 (PDT) MIME-Version: 1.0 X-Gmail-Original-Message-ID: Content-Type: text/plain; charset=UTF-8 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 64 Organization: linux.* mail to news gateway X-Original-Cc: Mark Brown , Boris Brezillon , lee.jones@linaro.org, "open list:ARM/Rockchip SoC..." , Heiko Stuebner , lgirdwood@gmail.com, linux-kernel@vger.kernel.org X-Original-Date: Tue, 28 Jun 2016 09:07:23 -0700 X-Original-Message-ID: X-Original-References: <1467089591-7631-1-git-send-email-dianders@chromium.org> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1433086 On Mon, Jun 27, 2016 at 9:53 PM, Douglas Anderson wrote: > 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). My grepping agrees, though I'm sure I didn't do a very thorough job. > 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 > --- > 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); I was curious about the side effects of the unconditional usleep_range(ramp_delay, ...), even when ramp_delay is 0 (e.g., would we ever sleep here for up to 1ms?), but apparently the implementation optimizes the '0' case to be an unconditional, immediate wake-up. So refactoring this shouldn't have any accidental effects. > + 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)); Math checks out to me. > > return 0; > } Reviewed-by: Brian Norris