From patchwork Wed Aug 31 04:21:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9306303 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 92E6F60487 for ; Wed, 31 Aug 2016 04:22:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E9BC28E28 for ; Wed, 31 Aug 2016 04:22:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73A4728E36; Wed, 31 Aug 2016 04:22:27 +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 B726F28E28 for ; Wed, 31 Aug 2016 04:22:19 +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 1bex2W-0000VD-Bp; Wed, 31 Aug 2016 04:22:16 +0000 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bex2U-0000RU-1R for linux-rockchip@lists.infradead.org; Wed, 31 Aug 2016 04:22:14 +0000 Received: by mail-pf0-x235.google.com with SMTP id h186so14890721pfg.3 for ; Tue, 30 Aug 2016 21:21:53 -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=sMzwC2NXlFKvtoMFSml+aYrnzGJL8Dq+rm5T6bT954Y=; b=WSDLslkfjcciOhQUzC4arEzFREi930BS3zt6QpR0EpfytG88umiL0lak4ruIeYj54N 6+mnEquEYyb5dhfL7GEVze0SfMYgndevMHhajN01mSj/8nQCYXSKN2C/BqF0oTakA5Sj 9RC5eLdNR0jzfcs7CGz81Mlgcb90zs3SC61Rs= 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=sMzwC2NXlFKvtoMFSml+aYrnzGJL8Dq+rm5T6bT954Y=; b=TEnQgpAsu9Fecw5FZKqlojzZ4iO6h0advOCQzqmAsb3uddZueN6D/ac3fC5q7ecKOn vGNVQgCwqifUmLpzu3QrfKZRIYHN/+ArExv/Y49urpQgJsFGyvw58kKcTJA69WA+NBGo gus7tr2JU7QPZB3jWzol8WFU4z5KtAkOLajIWCtNm7dKyd2yD8RpZkAkTQgThn6HNwNS 7A+3segKiDbFWZwdJNStjjcJsz7iDd55u9g14TVebB4D72ExP8gaN2bH2XAVCxphu2Ok Y3QGJvF5558qh8A0/U+kjr/wlDwm+qCYhV5MiXpSVeZmnfBfMfB5CtrJDcwRMYWfNJ95 nugQ== X-Gm-Message-State: AE9vXwMlidvbEk67IWpwfmEXNywmaOZv5MhRdbXIZTORd7+jFF1eoOmR3NyL/4THPZFcpuea X-Received: by 10.98.207.6 with SMTP id b6mr13189164pfg.25.1472617312918; Tue, 30 Aug 2016 21:21:52 -0700 (PDT) Received: from chromelab4.mtv.corp.google.com ([100.98.62.8]) by smtp.gmail.com with ESMTPSA id zk7sm60800533pac.41.2016.08.30.21.21.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Aug 2016 21:21:51 -0700 (PDT) From: Douglas Anderson To: Mark Brown , lgirdwood@gmail.com Subject: [PATCH v3 1/2] regulator: pwm: Add support for a fixed delay after duty cycle changes Date: Tue, 30 Aug 2016 21:21:15 -0700 Message-Id: <1472617277-30814-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-20160830_212214_167366_203FD129 X-CRM114-Status: GOOD ( 14.75 ) 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: mark.rutland@arm.com, devicetree@vger.kernel.org, briannorris@chromium.org, Douglas Anderson , robh+dt@kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, javier@dowhile0.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 From: Matthias Kaehlcke A change of the duty cycle doesn't necessarily cause an immediate switch to the target voltage. On many PWM regulators there is a fixed "settle time" (irrespective of the jump size) that we need to wait after an upward jump. This change introduces the device tree property "settle-time-up-us" which allows us to specify a fixed delay after a voltage increase. We don't add an option of a fixed delay on the way down for now because the way down is probably modelled best with a ramp rate, not a fixed delay. Signed-off-by: Matthias Kaehlcke Signed-off-by: Douglas Anderson Acked-by: Rob Herring --- Changes in v3: - Took out fixed delay for falling transitions - Updated description .../devicetree/bindings/regulator/pwm-regulator.txt | 6 ++++++ drivers/regulator/pwm-regulator.c | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/regulator/pwm-regulator.txt b/Documentation/devicetree/bindings/regulator/pwm-regulator.txt index 3aeba9f86ed8..9dc15d18e787 100644 --- a/Documentation/devicetree/bindings/regulator/pwm-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/pwm-regulator.txt @@ -34,6 +34,12 @@ Only required for Voltage Table Mode: First cell is voltage in microvolts (uV) Second cell is duty-cycle in percent (%) +Optional properties: +-------------------- +- settle-time-up-us: Time to settle down after a voltage increase + (unit: us). For regulators with a ramp delay + the two values are added. + Optional properties for Continuous mode: - pwm-dutycycle-unit: Integer value encoding the duty cycle unit. If not defined, <100> is assumed, meaning that diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index c24524242da2..94f1ca3b793d 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c @@ -48,6 +48,8 @@ struct pwm_regulator_data { /* Enable GPIO */ struct gpio_desc *enb_gpio; + + u32 settle_time_up_us; }; struct pwm_voltages { @@ -195,6 +197,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev, unsigned int max_uV_duty = drvdata->continuous.max_uV_dutycycle; unsigned int duty_unit = drvdata->continuous.dutycycle_unit; unsigned int ramp_delay = rdev->constraints->ramp_delay; + unsigned int delay = 0; int min_uV = rdev->constraints->min_uV; int max_uV = rdev->constraints->max_uV; int diff_uV = max_uV - min_uV; @@ -233,12 +236,17 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev, return ret; } - if ((ramp_delay == 0) || !pwm_regulator_is_enabled(rdev)) + if (req_min_uV > old_uV) + delay = drvdata->settle_time_up_us; + + if (ramp_delay != 0) + /* Adjust ramp delay to uS and add to settle time. */ + delay += DIV_ROUND_UP(abs(req_min_uV - old_uV), ramp_delay); + + if ((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(req_min_uV - old_uV), ramp_delay); - usleep_range(ramp_delay, ramp_delay + DIV_ROUND_UP(ramp_delay, 10)); + usleep_range(delay, delay + DIV_ROUND_UP(delay, 10)); return 0; } @@ -368,6 +376,9 @@ static int pwm_regulator_probe(struct platform_device *pdev) if (!init_data) return -ENOMEM; + of_property_read_u32(np, "settle-time-up-us", + &drvdata->settle_time_up_us); + config.of_node = np; config.dev = &pdev->dev; config.driver_data = drvdata;