aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-07-02 18:26:36 -0400
committerMark Brown <broonie@linaro.org>2013-07-15 06:20:32 -0400
commit6692e432a9d59b55edbfdb4ed388e03c7f17e43c (patch)
treefe661e68b572dd4ecf9c63f5d293d8b9696b121d
parent94d33c02c7186b69849c292e1216a08ad1c0d99d (diff)
regulator: wm8400: Use linear ranges
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/regulator/wm8400-regulator.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index a09f03ee5506..2ac7e1aceb05 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -19,47 +19,21 @@
19#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
20#include <linux/mfd/wm8400-private.h> 20#include <linux/mfd/wm8400-private.h>
21 21
22static int wm8400_ldo_list_voltage(struct regulator_dev *dev, 22static const struct regulator_linear_range wm8400_ldo_ranges[] = {
23 unsigned selector) 23 { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14,
24{ 24 .uV_step = 50000 },
25 if (selector > WM8400_LDO1_VSEL_MASK) 25 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31,
26 return -EINVAL; 26 .uV_step = 100000 },
27 27};
28 if (selector < 15)
29 return 900000 + (selector * 50000);
30 else
31 return 1700000 + ((selector - 15) * 100000);
32}
33
34static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
35 int min_uV, int max_uV)
36{
37 u16 val;
38 int volt;
39
40 if (min_uV < 900000 || min_uV > 3300000)
41 return -EINVAL;
42
43 if (min_uV < 1700000) /* Steps of 50mV from 900mV; */
44 val = DIV_ROUND_UP(min_uV - 900000, 50000);
45 else /* Steps of 100mV from 1700mV */
46 val = DIV_ROUND_UP(min_uV - 1700000, 100000) + 15;
47
48 volt = wm8400_ldo_list_voltage(dev, val);
49 if (volt < min_uV || volt > max_uV)
50 return -EINVAL;
51
52 return val;
53}
54 28
55static struct regulator_ops wm8400_ldo_ops = { 29static struct regulator_ops wm8400_ldo_ops = {
56 .is_enabled = regulator_is_enabled_regmap, 30 .is_enabled = regulator_is_enabled_regmap,
57 .enable = regulator_enable_regmap, 31 .enable = regulator_enable_regmap,
58 .disable = regulator_disable_regmap, 32 .disable = regulator_disable_regmap,
59 .list_voltage = wm8400_ldo_list_voltage, 33 .list_voltage = regulator_list_voltage_linear_range,
60 .get_voltage_sel = regulator_get_voltage_sel_regmap, 34 .get_voltage_sel = regulator_get_voltage_sel_regmap,
61 .set_voltage_sel = regulator_set_voltage_sel_regmap, 35 .set_voltage_sel = regulator_set_voltage_sel_regmap,
62 .map_voltage = wm8400_ldo_map_voltage, 36 .map_voltage = regulator_map_voltage_linear_range,
63}; 37};
64 38
65static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) 39static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
@@ -155,6 +129,8 @@ static struct regulator_desc regulators[] = {
155 .enable_reg = WM8400_LDO1_CONTROL, 129 .enable_reg = WM8400_LDO1_CONTROL,
156 .enable_mask = WM8400_LDO1_ENA, 130 .enable_mask = WM8400_LDO1_ENA,
157 .n_voltages = WM8400_LDO1_VSEL_MASK + 1, 131 .n_voltages = WM8400_LDO1_VSEL_MASK + 1,
132 .linear_ranges = wm8400_ldo_ranges,
133 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
158 .vsel_reg = WM8400_LDO1_CONTROL, 134 .vsel_reg = WM8400_LDO1_CONTROL,
159 .vsel_mask = WM8400_LDO1_VSEL_MASK, 135 .vsel_mask = WM8400_LDO1_VSEL_MASK,
160 .type = REGULATOR_VOLTAGE, 136 .type = REGULATOR_VOLTAGE,
@@ -167,6 +143,8 @@ static struct regulator_desc regulators[] = {
167 .enable_reg = WM8400_LDO2_CONTROL, 143 .enable_reg = WM8400_LDO2_CONTROL,
168 .enable_mask = WM8400_LDO2_ENA, 144 .enable_mask = WM8400_LDO2_ENA,
169 .n_voltages = WM8400_LDO2_VSEL_MASK + 1, 145 .n_voltages = WM8400_LDO2_VSEL_MASK + 1,
146 .linear_ranges = wm8400_ldo_ranges,
147 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
170 .type = REGULATOR_VOLTAGE, 148 .type = REGULATOR_VOLTAGE,
171 .vsel_reg = WM8400_LDO2_CONTROL, 149 .vsel_reg = WM8400_LDO2_CONTROL,
172 .vsel_mask = WM8400_LDO2_VSEL_MASK, 150 .vsel_mask = WM8400_LDO2_VSEL_MASK,
@@ -179,6 +157,8 @@ static struct regulator_desc regulators[] = {
179 .enable_reg = WM8400_LDO3_CONTROL, 157 .enable_reg = WM8400_LDO3_CONTROL,
180 .enable_mask = WM8400_LDO3_ENA, 158 .enable_mask = WM8400_LDO3_ENA,
181 .n_voltages = WM8400_LDO3_VSEL_MASK + 1, 159 .n_voltages = WM8400_LDO3_VSEL_MASK + 1,
160 .linear_ranges = wm8400_ldo_ranges,
161 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
182 .vsel_reg = WM8400_LDO3_CONTROL, 162 .vsel_reg = WM8400_LDO3_CONTROL,
183 .vsel_mask = WM8400_LDO3_VSEL_MASK, 163 .vsel_mask = WM8400_LDO3_VSEL_MASK,
184 .type = REGULATOR_VOLTAGE, 164 .type = REGULATOR_VOLTAGE,
@@ -191,6 +171,8 @@ static struct regulator_desc regulators[] = {
191 .enable_reg = WM8400_LDO4_CONTROL, 171 .enable_reg = WM8400_LDO4_CONTROL,
192 .enable_mask = WM8400_LDO4_ENA, 172 .enable_mask = WM8400_LDO4_ENA,
193 .n_voltages = WM8400_LDO4_VSEL_MASK + 1, 173 .n_voltages = WM8400_LDO4_VSEL_MASK + 1,
174 .linear_ranges = wm8400_ldo_ranges,
175 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
194 .vsel_reg = WM8400_LDO4_CONTROL, 176 .vsel_reg = WM8400_LDO4_CONTROL,
195 .vsel_mask = WM8400_LDO4_VSEL_MASK, 177 .vsel_mask = WM8400_LDO4_VSEL_MASK,
196 .type = REGULATOR_VOLTAGE, 178 .type = REGULATOR_VOLTAGE,