From patchwork Wed Jul 6 18:42:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Anderson X-Patchwork-Id: 9216859 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 8D6D460467 for ; Wed, 6 Jul 2016 18:42:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81D9828395 for ; Wed, 6 Jul 2016 18:42:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 760BE283A6; Wed, 6 Jul 2016 18:42:38 +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=unavailable 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 1E3262839B for ; Wed, 6 Jul 2016 18:42:38 +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 1bKrmN-00008S-Ge; Wed, 06 Jul 2016 18:42:35 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bKrmM-00007C-76 for linux-rockchip@lists.infradead.org; Wed, 06 Jul 2016 18:42:34 +0000 Received: by mail-pf0-x230.google.com with SMTP id i123so81968770pfg.0 for ; Wed, 06 Jul 2016 11:42:13 -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=6fWJvbCNIp1XtIt16LDdve0BAvsEo8VLZkjMG5OvO6Y=; b=VH/f/lAfC+wlyB844v8OXJKKu4o+Gf8lLouRzU5HEBnF333jbymHJ3RBi+hDQxwhrL uOGMb/qmAlDgcS+X0b66nM4UGoMoTum2GDKD7srd8trUYYtgEqIxNzqsTqj0eyO9A0lh VqzRXdRzwi4vAqKWG919FBVsf89j8VI1i2S3o= 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=6fWJvbCNIp1XtIt16LDdve0BAvsEo8VLZkjMG5OvO6Y=; b=Tu6QmvFqmoaUlG4r+6svjf9U8C4EUUjezdVLOBcnaNuyJBVT8gw/fE329nEgDuE80Y JfTX6GHJmUHPam1chtJ0/MXw1wty1gTWRcn6dpS0DqZL9j3MMJqbQE4hMA19oXnOJGRh gMCjcw3MkMPhzD0R2qpgZ7QpnbxUbj5SCWf2/zln67T+fj5Zu6VY3hXqRhwBYyiyjvnp 3mKAD0atQcGOfVsx+UgZP9at9E1nDYxE1ss2yGdaE5dAermhBaTmUmlML+sY/z9Xv+pi YnNARpWlw+8l3cGtRy2VqekDHX/73zLNhU9veUpFNUqMxDaD1NfbMigRa8VfPUishZER dIHg== X-Gm-Message-State: ALyK8tLL3abt25zIpHMARzL7ZIGdpOPjIMpBDTcnj5Z5XnzEPTuRtxwbYK5GAGSMT04ub9/m X-Received: by 10.98.32.148 with SMTP id m20mr44265784pfj.77.1467830532938; Wed, 06 Jul 2016 11:42:12 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id o68sm6296963pfb.18.2016.07.06.11.42.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jul 2016 11:42:11 -0700 (PDT) From: Douglas Anderson To: Mark Brown Subject: [PATCH v2] regulator: pwm: Fix regulator ramp delay for continuous mode Date: Wed, 6 Jul 2016 11:42:01 -0700 Message-Id: <1467830521-15300-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-20160706_114234_300695_1B5B61C8 X-CRM114-Status: GOOD ( 15.97 ) 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, thierry.reding@gmail.com, ldewangan@nvidia.com, 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%. 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 Acked-by: Laxman Dewangan --- 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; }