From: Douglas Anderson <dianders@chromium.org> To: Mark Brown <broonie@kernel.org>, lgirdwood@gmail.com Cc: mka@chromium.org, briannorris@chromium.org, javier@dowhile0.org, linux-rockchip@lists.infradead.org, Douglas Anderson <dianders@chromium.org>, robh+dt@kernel.org, mark.rutland@arm.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org 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 [thread overview] Message-ID: <1472617277-30814-1-git-send-email-dianders@chromium.org> (raw) From: Matthias Kaehlcke <mka@chromium.org> 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 <mka@chromium.org> Signed-off-by: Douglas Anderson <dianders@chromium.org> --- 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; -- 2.8.0.rc3.226.g39d4020
WARNING: multiple messages have this Message-ID (diff)
From: Douglas Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, lgirdwood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Cc: mka-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org, briannorris-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org, javier-0uQlZySMnqxg9hUCZPvPmw@public.gmane.org, linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Douglas Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>, robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, mark.rutland-5wv7dgnIgG8@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org 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 [thread overview] Message-ID: <1472617277-30814-1-git-send-email-dianders@chromium.org> (raw) From: Matthias Kaehlcke <mka-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> 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 <mka-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> Signed-off-by: Douglas Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> --- 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; -- 2.8.0.rc3.226.g39d4020 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2016-08-31 4:21 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-08-31 4:21 Douglas Anderson [this message] 2016-08-31 4:21 ` [PATCH v3 1/2] regulator: pwm: Add support for a fixed delay after duty cycle changes Douglas Anderson 2016-08-31 4:21 ` [PATCH v3 2/2] regulator: pwm: Prevent falling too fast Douglas Anderson 2016-09-01 19:51 ` Mark Brown 2016-09-01 19:51 ` Mark Brown 2016-09-01 19:24 ` [PATCH v3 1/2] regulator: pwm: Add support for a fixed delay after duty cycle changes Mark Brown 2016-09-01 19:24 ` Mark Brown 2016-09-02 15:11 ` Rob Herring 2016-09-02 15:11 ` Rob Herring 2016-09-02 15:13 ` Rob Herring 2016-09-02 15:13 ` Rob Herring
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=1472617277-30814-1-git-send-email-dianders@chromium.org \ --to=dianders@chromium.org \ --cc=briannorris@chromium.org \ --cc=broonie@kernel.org \ --cc=devicetree@vger.kernel.org \ --cc=javier@dowhile0.org \ --cc=lgirdwood@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=mark.rutland@arm.com \ --cc=mka@chromium.org \ --cc=robh+dt@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.