public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthias Kaehlcke <mka@chromium.org>
To: Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Javier Martinez Canillas <javier@dowhile0.org>
Cc: Doug Anderson <dianders@chromium.org>, linux-kernel@vger.kernel.org
Subject: [PATCH v2] pwm-regulator: Add support for a fixed delay after duty cycle changes
Date: Fri, 26 Aug 2016 17:20:14 -0700	[thread overview]
Message-ID: <20160827002014.GB92391@google.com> (raw)

A change of the duty cycle doesn't necessarily cause an inmediate switch
to the target voltage. The voltage change may be gradual and complete
with a certain delay. This change introduces the device tree properties
"settle-time-up-us" and "settle-time-down-us", which allow to specify a
fixed delay after a voltage increase or decrease. Often it is not
strictly necessary for a voltage decrease to complete, therefore the
delays may be asymmetric. For regulators with a ramp delay the
corresponding settle time is added to the ramp delay.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 .../bindings/regulator/pwm-regulator.txt           | 10 +++++++++
 drivers/regulator/pwm-regulator.c                  | 25 ++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/pwm-regulator.txt b/Documentation/devicetree/bindings/regulator/pwm-regulator.txt
index 3aeba9f..42b6819 100644
--- a/Documentation/devicetree/bindings/regulator/pwm-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/pwm-regulator.txt
@@ -29,6 +29,16 @@ Required properties:
 
 - pwms:			PWM specification (See: ../pwm/pwm.txt)
 
+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.
+
+- settle-time-down-us:	Time to settle down after a voltage decrease
+			(unit: us). For regulators with a ramp delay
+			the two values are added.
+
 Only required for Voltage Table Mode:
 - voltage-table: 	Voltage and Duty-Cycle table consisting of 2 cells
 			    First cell is voltage in microvolts (uV)
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index c245242..51fe4da 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -46,6 +46,9 @@ struct pwm_regulator_data {
 
 	int state;
 
+	u32 settle_time_up_us;
+	u32 settle_time_down_us;
+
 	/* Enable GPIO */
 	struct gpio_desc *enb_gpio;
 };
@@ -195,6 +198,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;
 	int min_uV = rdev->constraints->min_uV;
 	int max_uV = rdev->constraints->max_uV;
 	int diff_uV = max_uV - min_uV;
@@ -233,12 +237,20 @@ 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;
+	else
+		delay = drvdata->settle_time_down_us;
+
+	if (!pwm_regulator_is_enabled(rdev) ||
+		((delay == 0) && (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));
+	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);
+
+	usleep_range(delay, delay + DIV_ROUND_UP(delay, 10));
 
 	return 0;
 }
@@ -368,6 +380,11 @@ 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);
+	of_property_read_u32(np, "settle-time-down-us",
+			&drvdata->settle_time_down_us);
+
 	config.of_node = np;
 	config.dev = &pdev->dev;
 	config.driver_data = drvdata;
-- 
2.6.6

             reply	other threads:[~2016-08-27  0:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-27  0:20 Matthias Kaehlcke [this message]
2016-08-30  2:57 ` [PATCH v2] pwm-regulator: Add support for a fixed delay after duty cycle changes Doug Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160827002014.GB92391@google.com \
    --to=mka@chromium.org \
    --cc=broonie@kernel.org \
    --cc=dianders@chromium.org \
    --cc=javier@dowhile0.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox