From patchwork Tue Jun 28 04:53:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9201835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C94296075F for ; Tue, 28 Jun 2016 04:54:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBE1A285D0 for ; Tue, 28 Jun 2016 04:54:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0BBC285E6; Tue, 28 Jun 2016 04:54:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5556C285D0 for ; Tue, 28 Jun 2016 04:54:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bHl2A-0007YC-RQ; Tue, 28 Jun 2016 04:54:02 +0000 Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bHl27-00078J-S1 for linux-rockchip@lists.infradead.org; Tue, 28 Jun 2016 04:54:00 +0000 Received: by mail-pf0-x22f.google.com with SMTP id h14so2609009pfe.1 for ; Mon, 27 Jun 2016 21:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=dUllnSWUU1lfCah6ougeDQBoY7iOF2hMjQPDSCQlgkk=; b=ZHJh/cVluDJOvtkJ2yO90Qn59/bp43QWvwv7bx/pBepiRqtLYlUBEJzdMz6bx6bPkE 36gpG9X4CDcVnLRlGfegaMdOVZOsRH3WgcDElvaE8AuE+X2pxkQflB1ejYY9h/Zk4a9y rM2dOgG0FSXiOMswugFA3LD4IplbrcjX43+ig= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dUllnSWUU1lfCah6ougeDQBoY7iOF2hMjQPDSCQlgkk=; b=lklKxq0eszIT6QvXTw4IF5bvLh3q0erEP9Oao1dWzJ41QWhZtnuyAUeWmqh/N3ahjA SYt0aBE90Zohk7jN3Xw72nsdMgCqBXpFxSfkIFpobFh8Xms4rMXQqGztm61/ghKwaC8F PqEECopKsZKLNGH2SaGrxKnV4YTwXNQLxwvH5OG6V7oU+gNWtY3BI0gREdHpFT3bbtF/ lqw1jCVlQuLthfqYRKnJ7FMZmapajqI747JIKg6LA5jfL8aRkYi7Z9V8kX8mqpW2PFb3 JcZXn+1hmeP40NuPHL8Weo2wR8PRp9PKEY1EgSvnCQyNAcTgVoynsOFT8zhIwPD+KKVo /pMQ== X-Gm-Message-State: ALyK8tLChnEi0eEK6IWdCc/fMyICdd6ofOzhqL6zAuhXgozrDJ2uJXm2Fgv2aEz0TPb+V3yz X-Received: by 10.98.82.68 with SMTP id g65mr1516591pfb.157.1467089618045; Mon, 27 Jun 2016 21:53:38 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id p187sm2950363pfg.67.2016.06.27.21.53.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Jun 2016 21:53:37 -0700 (PDT) From: Douglas Anderson To: Mark Brown Subject: [PATCH] regulator: pwm: Fix regulator ramp delay for continuous mode Date: Mon, 27 Jun 2016 21:53:11 -0700 Message-Id: <1467089591-7631-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160627_215359_996068_9B421AE1 X-CRM114-Status: GOOD ( 13.85 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@free-electrons.com, Heiko Stuebner , linux-kernel@vger.kernel.org, briannorris@chromium.org, Douglas Anderson , lgirdwood@gmail.com, linux-rockchip@lists.infradead.org, lee.jones@linaro.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Caesar Wang Reviewed-by: Brian Norris --- 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; }