aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/pwm-regulator.c
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2015-07-07 11:06:52 -0400
committerMark Brown <broonie@kernel.org>2015-07-07 13:58:28 -0400
commitcae897dec26a9d81dcb5182b13b08450f38d6bde (patch)
tree2b60310636df499b0380f1aeb1004e3323d4670f /drivers/regulator/pwm-regulator.c
parent4773be185a0f7c1c09d8966e100c76f4fa9a3227 (diff)
regulator: pwm-regulator: Simplify voltage to duty-cycle call
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> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/pwm-regulator.c')
-rw-r--r--drivers/regulator/pwm-regulator.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index dac145db305c..d5cb267fa192 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,
93/** 93/**
94 * Continuous voltage call-backs 94 * Continuous voltage call-backs
95 */ 95 */
96static int pwm_voltage_to_duty_cycle(struct regulator_dev *rdev, 96static int pwm_voltage_to_duty_cycle(struct regulator_dev *rdev, int req_uV)
97 int volt_mV)
98{ 97{
99 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); 98 int min_uV = rdev->constraints->min_uV;
100 int min_mV = rdev->constraints->min_uV / 1000; 99 int max_uV = rdev->constraints->max_uV;
101 int max_mV = rdev->constraints->max_uV / 1000; 100 int diff = max_uV - min_uV;
102 int max_duty_cycle = drvdata->max_duty_cycle; 101
103 int vdiff = min_mV - max_mV; 102 return 100 - ((((req_uV * 100) - (min_uV * 100)) / diff));
104 int pwm_code;
105 int tmp;
106
107 tmp = ((max_duty_cycle - min_mV) * max_duty_cycle) / vdiff;
108 pwm_code = ((tmp + max_duty_cycle) * volt_mV) / vdiff;
109
110 if (pwm_code < 0)
111 pwm_code = 0;
112 if (pwm_code > max_duty_cycle)
113 pwm_code = max_duty_cycle;
114
115 return pwm_code * 100 / max_duty_cycle;
116} 103}
117 104
118static int pwm_regulator_get_voltage(struct regulator_dev *rdev) 105static int pwm_regulator_get_voltage(struct regulator_dev *rdev)
@@ -131,7 +118,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
131 int duty_cycle; 118 int duty_cycle;
132 int ret; 119 int ret;
133 120
134 duty_cycle = pwm_voltage_to_duty_cycle(rdev, min_uV / 1000); 121 duty_cycle = pwm_voltage_to_duty_cycle(rdev, min_uV);
135 122
136 ret = pwm_config(drvdata->pwm, 123 ret = pwm_config(drvdata->pwm,
137 (drvdata->pwm->period / 100) * duty_cycle, 124 (drvdata->pwm->period / 100) * duty_cycle,