From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 8/9] regulator: pwm-regulator: Simplify voltage to duty-cycle call
Date: Tue, 7 Jul 2015 16:06:52 +0100 [thread overview]
Message-ID: <1436281613-899-9-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1436281613-899-1-git-send-email-lee.jones@linaro.org>
If we reverse some of the logic and change the formula used,
we can simplify the function greatly.
It is intentional that this function is supplied and then re-worked
within the same patch-set. The submission in the previous patch is
the tried and tested (i.e. in real releases) method written by ST.
This patch contains a simplification provided later. It looks and
performs better, but doesn't have the same time-under-test that the
original method does. The idea is that we keep some history in
order to provide an easy way back i.e. revert.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/regulator/pwm-regulator.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index dac145d..d5cb267 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -93,26 +93,13 @@ static int pwm_regulator_list_voltage(struct regulator_dev *rdev,
/**
* Continuous voltage call-backs
*/
-static int pwm_voltage_to_duty_cycle(struct regulator_dev *rdev,
- int volt_mV)
+static int pwm_voltage_to_duty_cycle(struct regulator_dev *rdev, int req_uV)
{
- struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
- int min_mV = rdev->constraints->min_uV / 1000;
- int max_mV = rdev->constraints->max_uV / 1000;
- int max_duty_cycle = drvdata->max_duty_cycle;
- int vdiff = min_mV - max_mV;
- int pwm_code;
- int tmp;
-
- tmp = ((max_duty_cycle - min_mV) * max_duty_cycle) / vdiff;
- pwm_code = ((tmp + max_duty_cycle) * volt_mV) / vdiff;
-
- if (pwm_code < 0)
- pwm_code = 0;
- if (pwm_code > max_duty_cycle)
- pwm_code = max_duty_cycle;
-
- return pwm_code * 100 / max_duty_cycle;
+ int min_uV = rdev->constraints->min_uV;
+ int max_uV = rdev->constraints->max_uV;
+ int diff = max_uV - min_uV;
+
+ return 100 - ((((req_uV * 100) - (min_uV * 100)) / diff));
}
static int pwm_regulator_get_voltage(struct regulator_dev *rdev)
@@ -131,7 +118,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
int duty_cycle;
int ret;
- duty_cycle = pwm_voltage_to_duty_cycle(rdev, min_uV / 1000);
+ duty_cycle = pwm_voltage_to_duty_cycle(rdev, min_uV);
ret = pwm_config(drvdata->pwm,
(drvdata->pwm->period / 100) * duty_cycle,
--
1.9.1
next prev parent reply other threads:[~2015-07-07 15:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 15:06 [PATCH v2 0/9] regulator: pwm-regulator: Introduce continuous-mode Lee Jones
2015-07-07 15:06 ` [PATCH v2 1/9] ARM: multi_v7_defconfig: Enable ST's PWM driver Lee Jones
2015-07-07 15:06 ` [PATCH v2 2/9] ARM: multi_v7_defconfig: Enable ST's Power Reset driver Lee Jones
2015-07-07 15:06 ` [PATCH v2 3/9] ARM: multi_v7_defconfig: Enable support for PWM Regulators Lee Jones
2015-07-07 15:06 ` [PATCH v2 4/9] ARM: STi: STiH407: Move PWM nodes STiH407 => STiH407-family Lee Jones
2015-07-07 15:06 ` [PATCH v2 5/9] ARM: STi: STiH407: Add PWM Regulator node Lee Jones
2015-07-07 15:06 ` [PATCH v2 6/9] regulator: pwm-regulator: Re-write bindings Lee Jones
2015-07-09 8:01 ` Boris Brezillon
2015-07-07 15:06 ` [PATCH v2 7/9] regulator: pwm-regulator: Add support for continuous-voltage Lee Jones
2015-07-07 15:06 ` Lee Jones [this message]
2015-07-07 15:06 ` [PATCH v2 9/9] regulator: pwm-regulator: Don't assign structure attributes right away Lee Jones
2015-07-09 6:30 ` [PATCH v2 0/9] regulator: pwm-regulator: Introduce continuous-mode Boris Brezillon
2015-07-09 11:51 ` Lee Jones
2015-07-09 13:14 ` Boris Brezillon
2015-07-09 15:44 ` Lee Jones
2015-07-09 16:25 ` Doug Anderson
2015-07-09 17:20 ` Lee Jones
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=1436281613-899-9-git-send-email-lee.jones@linaro.org \
--to=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).