diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-09 19:12:09 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-12 06:11:48 -0400 |
commit | c54a155d4d20e35d41bb2922ed4a6c615d177c4f (patch) | |
tree | 9ce33dce0e694e270fb0a8666557474462f3fb4d | |
parent | d31e954e07c838f44183addeecc7115d25e83266 (diff) |
regulator: wm8400: Modernise driver
Update the driver to use all the regmap based helpers, saving a nice chunk
of code (especially for the DCDCs).
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | drivers/regulator/wm8400-regulator.c | 169 |
1 files changed, 44 insertions, 125 deletions
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 4408b7802e75..69a2b7ce5e4a 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c | |||
@@ -19,31 +19,6 @@ | |||
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 | ||
22 | static int wm8400_ldo_is_enabled(struct regulator_dev *dev) | ||
23 | { | ||
24 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
25 | u16 val; | ||
26 | |||
27 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | ||
28 | return (val & WM8400_LDO1_ENA) != 0; | ||
29 | } | ||
30 | |||
31 | static int wm8400_ldo_enable(struct regulator_dev *dev) | ||
32 | { | ||
33 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
34 | |||
35 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
36 | WM8400_LDO1_ENA, WM8400_LDO1_ENA); | ||
37 | } | ||
38 | |||
39 | static int wm8400_ldo_disable(struct regulator_dev *dev) | ||
40 | { | ||
41 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
42 | |||
43 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
44 | WM8400_LDO1_ENA, 0); | ||
45 | } | ||
46 | |||
47 | static int wm8400_ldo_list_voltage(struct regulator_dev *dev, | 22 | static int wm8400_ldo_list_voltage(struct regulator_dev *dev, |
48 | unsigned selector) | 23 | unsigned selector) |
49 | { | 24 | { |
@@ -56,21 +31,9 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev, | |||
56 | return 1600000 + ((selector - 14) * 100000); | 31 | return 1600000 + ((selector - 14) * 100000); |
57 | } | 32 | } |
58 | 33 | ||
59 | static int wm8400_ldo_get_voltage_sel(struct regulator_dev *dev) | 34 | static int wm8400_ldo_map_voltage(struct regulator_dev *dev, |
35 | int min_uV, int max_uV) | ||
60 | { | 36 | { |
61 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
62 | u16 val; | ||
63 | |||
64 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | ||
65 | val &= WM8400_LDO1_VSEL_MASK; | ||
66 | |||
67 | return val; | ||
68 | } | ||
69 | |||
70 | static int wm8400_ldo_set_voltage(struct regulator_dev *dev, | ||
71 | int min_uV, int max_uV, unsigned *selector) | ||
72 | { | ||
73 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
74 | u16 val; | 37 | u16 val; |
75 | 38 | ||
76 | if (min_uV < 900000 || min_uV > 3300000) | 39 | if (min_uV < 900000 || min_uV > 3300000) |
@@ -94,92 +57,19 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev, | |||
94 | val += 0xf; | 57 | val += 0xf; |
95 | } | 58 | } |
96 | 59 | ||
97 | *selector = val; | 60 | return val; |
98 | |||
99 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
100 | WM8400_LDO1_VSEL_MASK, val); | ||
101 | } | 61 | } |
102 | 62 | ||
103 | static struct regulator_ops wm8400_ldo_ops = { | 63 | static struct regulator_ops wm8400_ldo_ops = { |
104 | .is_enabled = wm8400_ldo_is_enabled, | 64 | .is_enabled = regulator_is_enabled_regmap, |
105 | .enable = wm8400_ldo_enable, | 65 | .enable = regulator_enable_regmap, |
106 | .disable = wm8400_ldo_disable, | 66 | .disable = regulator_disable_regmap, |
107 | .list_voltage = wm8400_ldo_list_voltage, | 67 | .list_voltage = wm8400_ldo_list_voltage, |
108 | .get_voltage_sel = wm8400_ldo_get_voltage_sel, | 68 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
109 | .set_voltage = wm8400_ldo_set_voltage, | 69 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
70 | .map_voltage = wm8400_ldo_map_voltage, | ||
110 | }; | 71 | }; |
111 | 72 | ||
112 | static int wm8400_dcdc_is_enabled(struct regulator_dev *dev) | ||
113 | { | ||
114 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
115 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
116 | u16 val; | ||
117 | |||
118 | val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset); | ||
119 | return (val & WM8400_DC1_ENA) != 0; | ||
120 | } | ||
121 | |||
122 | static int wm8400_dcdc_enable(struct regulator_dev *dev) | ||
123 | { | ||
124 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
125 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
126 | |||
127 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
128 | WM8400_DC1_ENA, WM8400_DC1_ENA); | ||
129 | } | ||
130 | |||
131 | static int wm8400_dcdc_disable(struct regulator_dev *dev) | ||
132 | { | ||
133 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
134 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
135 | |||
136 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
137 | WM8400_DC1_ENA, 0); | ||
138 | } | ||
139 | |||
140 | static int wm8400_dcdc_list_voltage(struct regulator_dev *dev, | ||
141 | unsigned selector) | ||
142 | { | ||
143 | if (selector > WM8400_DC1_VSEL_MASK) | ||
144 | return -EINVAL; | ||
145 | |||
146 | return 850000 + (selector * 25000); | ||
147 | } | ||
148 | |||
149 | static int wm8400_dcdc_get_voltage_sel(struct regulator_dev *dev) | ||
150 | { | ||
151 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
152 | u16 val; | ||
153 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
154 | |||
155 | val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset); | ||
156 | val &= WM8400_DC1_VSEL_MASK; | ||
157 | |||
158 | return val; | ||
159 | } | ||
160 | |||
161 | static int wm8400_dcdc_set_voltage(struct regulator_dev *dev, | ||
162 | int min_uV, int max_uV, unsigned *selector) | ||
163 | { | ||
164 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
165 | u16 val; | ||
166 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
167 | |||
168 | if (min_uV < 850000) | ||
169 | return -EINVAL; | ||
170 | |||
171 | val = DIV_ROUND_UP(min_uV - 850000, 25000); | ||
172 | |||
173 | if (850000 + (25000 * val) > max_uV) | ||
174 | return -EINVAL; | ||
175 | BUG_ON(850000 + (25000 * val) < min_uV); | ||
176 | |||
177 | *selector = val; | ||
178 | |||
179 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
180 | WM8400_DC1_VSEL_MASK, val); | ||
181 | } | ||
182 | |||
183 | static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) | 73 | static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) |
184 | { | 74 | { |
185 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | 75 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); |
@@ -258,12 +148,12 @@ static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev, | |||
258 | } | 148 | } |
259 | 149 | ||
260 | static struct regulator_ops wm8400_dcdc_ops = { | 150 | static struct regulator_ops wm8400_dcdc_ops = { |
261 | .is_enabled = wm8400_dcdc_is_enabled, | 151 | .is_enabled = regulator_is_enabled_regmap, |
262 | .enable = wm8400_dcdc_enable, | 152 | .enable = regulator_enable_regmap, |
263 | .disable = wm8400_dcdc_disable, | 153 | .disable = regulator_disable_regmap, |
264 | .list_voltage = wm8400_dcdc_list_voltage, | 154 | .list_voltage = regulator_list_voltage_linear, |
265 | .get_voltage_sel = wm8400_dcdc_get_voltage_sel, | 155 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
266 | .set_voltage = wm8400_dcdc_set_voltage, | 156 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
267 | .get_mode = wm8400_dcdc_get_mode, | 157 | .get_mode = wm8400_dcdc_get_mode, |
268 | .set_mode = wm8400_dcdc_set_mode, | 158 | .set_mode = wm8400_dcdc_set_mode, |
269 | .get_optimum_mode = wm8400_dcdc_get_optimum_mode, | 159 | .get_optimum_mode = wm8400_dcdc_get_optimum_mode, |
@@ -274,7 +164,11 @@ static struct regulator_desc regulators[] = { | |||
274 | .name = "LDO1", | 164 | .name = "LDO1", |
275 | .id = WM8400_LDO1, | 165 | .id = WM8400_LDO1, |
276 | .ops = &wm8400_ldo_ops, | 166 | .ops = &wm8400_ldo_ops, |
167 | .enable_reg = WM8400_LDO1_CONTROL, | ||
168 | .enable_mask = WM8400_LDO1_ENA, | ||
277 | .n_voltages = WM8400_LDO1_VSEL_MASK + 1, | 169 | .n_voltages = WM8400_LDO1_VSEL_MASK + 1, |
170 | .vsel_reg = WM8400_LDO1_CONTROL, | ||
171 | .vsel_mask = WM8400_LDO1_VSEL_MASK, | ||
278 | .type = REGULATOR_VOLTAGE, | 172 | .type = REGULATOR_VOLTAGE, |
279 | .owner = THIS_MODULE, | 173 | .owner = THIS_MODULE, |
280 | }, | 174 | }, |
@@ -282,15 +176,23 @@ static struct regulator_desc regulators[] = { | |||
282 | .name = "LDO2", | 176 | .name = "LDO2", |
283 | .id = WM8400_LDO2, | 177 | .id = WM8400_LDO2, |
284 | .ops = &wm8400_ldo_ops, | 178 | .ops = &wm8400_ldo_ops, |
179 | .enable_reg = WM8400_LDO2_CONTROL, | ||
180 | .enable_mask = WM8400_LDO2_ENA, | ||
285 | .n_voltages = WM8400_LDO2_VSEL_MASK + 1, | 181 | .n_voltages = WM8400_LDO2_VSEL_MASK + 1, |
286 | .type = REGULATOR_VOLTAGE, | 182 | .type = REGULATOR_VOLTAGE, |
183 | .vsel_reg = WM8400_LDO2_CONTROL, | ||
184 | .vsel_mask = WM8400_LDO2_VSEL_MASK, | ||
287 | .owner = THIS_MODULE, | 185 | .owner = THIS_MODULE, |
288 | }, | 186 | }, |
289 | { | 187 | { |
290 | .name = "LDO3", | 188 | .name = "LDO3", |
291 | .id = WM8400_LDO3, | 189 | .id = WM8400_LDO3, |
292 | .ops = &wm8400_ldo_ops, | 190 | .ops = &wm8400_ldo_ops, |
191 | .enable_reg = WM8400_LDO3_CONTROL, | ||
192 | .enable_mask = WM8400_LDO3_ENA, | ||
293 | .n_voltages = WM8400_LDO3_VSEL_MASK + 1, | 193 | .n_voltages = WM8400_LDO3_VSEL_MASK + 1, |
194 | .vsel_reg = WM8400_LDO3_CONTROL, | ||
195 | .vsel_mask = WM8400_LDO3_VSEL_MASK, | ||
294 | .type = REGULATOR_VOLTAGE, | 196 | .type = REGULATOR_VOLTAGE, |
295 | .owner = THIS_MODULE, | 197 | .owner = THIS_MODULE, |
296 | }, | 198 | }, |
@@ -298,7 +200,11 @@ static struct regulator_desc regulators[] = { | |||
298 | .name = "LDO4", | 200 | .name = "LDO4", |
299 | .id = WM8400_LDO4, | 201 | .id = WM8400_LDO4, |
300 | .ops = &wm8400_ldo_ops, | 202 | .ops = &wm8400_ldo_ops, |
203 | .enable_reg = WM8400_LDO4_CONTROL, | ||
204 | .enable_mask = WM8400_LDO4_ENA, | ||
301 | .n_voltages = WM8400_LDO4_VSEL_MASK + 1, | 205 | .n_voltages = WM8400_LDO4_VSEL_MASK + 1, |
206 | .vsel_reg = WM8400_LDO4_CONTROL, | ||
207 | .vsel_mask = WM8400_LDO4_VSEL_MASK, | ||
302 | .type = REGULATOR_VOLTAGE, | 208 | .type = REGULATOR_VOLTAGE, |
303 | .owner = THIS_MODULE, | 209 | .owner = THIS_MODULE, |
304 | }, | 210 | }, |
@@ -306,7 +212,13 @@ static struct regulator_desc regulators[] = { | |||
306 | .name = "DCDC1", | 212 | .name = "DCDC1", |
307 | .id = WM8400_DCDC1, | 213 | .id = WM8400_DCDC1, |
308 | .ops = &wm8400_dcdc_ops, | 214 | .ops = &wm8400_dcdc_ops, |
215 | .enable_reg = WM8400_DCDC1_CONTROL_1, | ||
216 | .enable_mask = WM8400_DC1_ENA_MASK, | ||
309 | .n_voltages = WM8400_DC1_VSEL_MASK + 1, | 217 | .n_voltages = WM8400_DC1_VSEL_MASK + 1, |
218 | .vsel_reg = WM8400_DCDC1_CONTROL_1, | ||
219 | .vsel_mask = WM8400_DC1_VSEL_MASK, | ||
220 | .min_uV = 850000, | ||
221 | .uV_step = 25000, | ||
310 | .type = REGULATOR_VOLTAGE, | 222 | .type = REGULATOR_VOLTAGE, |
311 | .owner = THIS_MODULE, | 223 | .owner = THIS_MODULE, |
312 | }, | 224 | }, |
@@ -314,7 +226,13 @@ static struct regulator_desc regulators[] = { | |||
314 | .name = "DCDC2", | 226 | .name = "DCDC2", |
315 | .id = WM8400_DCDC2, | 227 | .id = WM8400_DCDC2, |
316 | .ops = &wm8400_dcdc_ops, | 228 | .ops = &wm8400_dcdc_ops, |
229 | .enable_reg = WM8400_DCDC2_CONTROL_1, | ||
230 | .enable_mask = WM8400_DC1_ENA_MASK, | ||
317 | .n_voltages = WM8400_DC2_VSEL_MASK + 1, | 231 | .n_voltages = WM8400_DC2_VSEL_MASK + 1, |
232 | .vsel_reg = WM8400_DCDC2_CONTROL_1, | ||
233 | .vsel_mask = WM8400_DC2_VSEL_MASK, | ||
234 | .min_uV = 850000, | ||
235 | .uV_step = 25000, | ||
318 | .type = REGULATOR_VOLTAGE, | 236 | .type = REGULATOR_VOLTAGE, |
319 | .owner = THIS_MODULE, | 237 | .owner = THIS_MODULE, |
320 | }, | 238 | }, |
@@ -329,6 +247,7 @@ static int __devinit wm8400_regulator_probe(struct platform_device *pdev) | |||
329 | config.dev = &pdev->dev; | 247 | config.dev = &pdev->dev; |
330 | config.init_data = pdev->dev.platform_data; | 248 | config.init_data = pdev->dev.platform_data; |
331 | config.driver_data = wm8400; | 249 | config.driver_data = wm8400; |
250 | config.regmap = wm8400->regmap; | ||
332 | 251 | ||
333 | rdev = regulator_register(®ulators[pdev->id], &config); | 252 | rdev = regulator_register(®ulators[pdev->id], &config); |
334 | if (IS_ERR(rdev)) | 253 | if (IS_ERR(rdev)) |