aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/88pm8607.c547
-rw-r--r--drivers/regulator/Kconfig50
-rw-r--r--drivers/regulator/Makefile10
-rw-r--r--drivers/regulator/ab3100.c39
-rw-r--r--drivers/regulator/core.c331
-rw-r--r--drivers/regulator/da903x.c2
-rw-r--r--drivers/regulator/dummy.c66
-rw-r--r--drivers/regulator/dummy.h31
-rw-r--r--drivers/regulator/fixed.c31
-rw-r--r--drivers/regulator/lp3971.c87
-rw-r--r--drivers/regulator/max1586.c12
-rw-r--r--drivers/regulator/max8649.c410
-rw-r--r--drivers/regulator/max8660.c512
-rw-r--r--drivers/regulator/max8925-regulator.c308
-rw-r--r--drivers/regulator/mc13783-regulator.c654
-rw-r--r--drivers/regulator/mc13783.c410
-rw-r--r--drivers/regulator/pcap-regulator.c8
-rw-r--r--drivers/regulator/pcf50633-regulator.c5
-rw-r--r--drivers/regulator/tps65023-regulator.c36
-rw-r--r--drivers/regulator/tps6507x-regulator.c35
-rw-r--r--drivers/regulator/twl-regulator.c (renamed from drivers/regulator/twl4030-regulator.c)346
-rw-r--r--drivers/regulator/userspace-consumer.c1
-rw-r--r--drivers/regulator/virtual.c65
-rw-r--r--drivers/regulator/wm831x-dcdc.c220
-rw-r--r--drivers/regulator/wm831x-isink.c4
-rw-r--r--drivers/regulator/wm831x-ldo.c8
-rw-r--r--drivers/regulator/wm8350-regulator.c62
-rw-r--r--drivers/regulator/wm8400-regulator.c7
-rw-r--r--drivers/regulator/wm8994-regulator.c308
29 files changed, 3782 insertions, 823 deletions
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
new file mode 100644
index 000000000000..5fb83e2ced25
--- /dev/null
+++ b/drivers/regulator/88pm8607.c
@@ -0,0 +1,547 @@
1/*
2 * Regulators driver for Marvell 88PM8607
3 *
4 * Copyright (C) 2009 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18#include <linux/mfd/88pm860x.h>
19
20struct pm8607_regulator_info {
21 struct regulator_desc desc;
22 struct pm860x_chip *chip;
23 struct regulator_dev *regulator;
24 struct i2c_client *i2c;
25
26 int min_uV;
27 int max_uV;
28 int step_uV;
29 int vol_reg;
30 int vol_shift;
31 int vol_nbits;
32 int update_reg;
33 int update_bit;
34 int enable_reg;
35 int enable_bit;
36 int slope_double;
37};
38
39static inline int check_range(struct pm8607_regulator_info *info,
40 int min_uV, int max_uV)
41{
42 if (max_uV < info->min_uV || min_uV > info->max_uV || min_uV > max_uV)
43 return -EINVAL;
44
45 return 0;
46}
47
48static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
49{
50 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
51 int ret = -EINVAL;
52
53 switch (info->desc.id) {
54 case PM8607_ID_BUCK1:
55 ret = (index < 0x1d) ? (index * 25000 + 800000) :
56 ((index < 0x20) ? 1500000 :
57 ((index < 0x40) ? ((index - 0x20) * 25000) :
58 -EINVAL));
59 break;
60 case PM8607_ID_BUCK3:
61 ret = (index < 0x3d) ? (index * 25000) :
62 ((index < 0x40) ? 1500000 : -EINVAL);
63 if (ret < 0)
64 break;
65 if (info->slope_double)
66 ret <<= 1;
67 break;
68 case PM8607_ID_LDO1:
69 ret = (index == 0) ? 1800000 :
70 ((index == 1) ? 1200000 :
71 ((index == 2) ? 2800000 : -EINVAL));
72 break;
73 case PM8607_ID_LDO5:
74 ret = (index == 0) ? 2900000 :
75 ((index == 1) ? 3000000 :
76 ((index == 2) ? 3100000 : 3300000));
77 break;
78 case PM8607_ID_LDO7:
79 case PM8607_ID_LDO8:
80 ret = (index < 3) ? (index * 50000 + 1800000) :
81 ((index < 8) ? (index * 50000 + 2550000) :
82 -EINVAL);
83 break;
84 case PM8607_ID_LDO12:
85 ret = (index < 2) ? (index * 100000 + 1800000) :
86 ((index < 7) ? (index * 100000 + 2500000) :
87 ((index == 7) ? 3300000 : 1200000));
88 break;
89 case PM8607_ID_LDO2:
90 case PM8607_ID_LDO3:
91 case PM8607_ID_LDO9:
92 ret = (index < 3) ? (index * 50000 + 1800000) :
93 ((index < 7) ? (index * 50000 + 2550000) :
94 3300000);
95 break;
96 case PM8607_ID_LDO4:
97 ret = (index < 3) ? (index * 50000 + 1800000) :
98 ((index < 6) ? (index * 50000 + 2550000) :
99 ((index == 6) ? 2900000 : 3300000));
100 break;
101 case PM8607_ID_LDO6:
102 ret = (index < 2) ? (index * 50000 + 1800000) :
103 ((index < 7) ? (index * 50000 + 2500000) :
104 3300000);
105 break;
106 case PM8607_ID_LDO10:
107 ret = (index < 3) ? (index * 50000 + 1800000) :
108 ((index < 7) ? (index * 50000 + 2550000) :
109 ((index == 7) ? 3300000 : 1200000));
110 break;
111 case PM8607_ID_LDO14:
112 ret = (index < 2) ? (index * 50000 + 1800000) :
113 ((index < 7) ? (index * 50000 + 2600000) :
114 3300000);
115 break;
116 }
117 return ret;
118}
119
120static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
121{
122 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
123 int val = -ENOENT;
124 int ret;
125
126 switch (info->desc.id) {
127 case PM8607_ID_BUCK1:
128 if (min_uV >= 800000) /* 800mV ~ 1500mV / 25mV */
129 val = (min_uV - 775001) / 25000;
130 else { /* 25mV ~ 775mV / 25mV */
131 val = (min_uV + 249999) / 25000;
132 val += 32;
133 }
134 break;
135 case PM8607_ID_BUCK3:
136 if (info->slope_double)
137 min_uV = min_uV >> 1;
138 val = (min_uV + 249999) / 25000; /* 0mV ~ 1500mV / 25mV */
139
140 break;
141 case PM8607_ID_LDO1:
142 if (min_uV > 1800000)
143 val = 2;
144 else if (min_uV > 1200000)
145 val = 0;
146 else
147 val = 1;
148 break;
149 case PM8607_ID_LDO5:
150 if (min_uV > 3100000)
151 val = 3;
152 else /* 2900mV ~ 3100mV / 100mV */
153 val = (min_uV - 2800001) / 100000;
154 break;
155 case PM8607_ID_LDO7:
156 case PM8607_ID_LDO8:
157 if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */
158 if (min_uV <= 1800000)
159 val = 0; /* 1800mv */
160 else if (min_uV <= 1900000)
161 val = (min_uV - 1750001) / 50000;
162 else
163 val = 3; /* 2700mV */
164 } else { /* 2700mV ~ 2900mV / 50mV */
165 if (min_uV <= 2900000) {
166 val = (min_uV - 2650001) / 50000;
167 val += 3;
168 } else
169 val = -EINVAL;
170 }
171 break;
172 case PM8607_ID_LDO10:
173 if (min_uV > 2850000)
174 val = 7;
175 else if (min_uV <= 1200000)
176 val = 8;
177 else if (min_uV < 2700000) /* 1800mV ~ 1900mV / 50mV */
178 val = (min_uV - 1750001) / 50000;
179 else { /* 2700mV ~ 2850mV / 50mV */
180 val = (min_uV - 2650001) / 50000;
181 val += 3;
182 }
183 break;
184 case PM8607_ID_LDO12:
185 if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 100mV */
186 if (min_uV <= 1200000)
187 val = 8; /* 1200mV */
188 else if (min_uV <= 1800000)
189 val = 0; /* 1800mV */
190 else if (min_uV <= 1900000)
191 val = (min_uV - 1700001) / 100000;
192 else
193 val = 2; /* 2700mV */
194 } else { /* 2700mV ~ 3100mV / 100mV */
195 if (min_uV <= 3100000) {
196 val = (min_uV - 2600001) / 100000;
197 val += 2;
198 } else if (min_uV <= 3300000)
199 val = 7;
200 else
201 val = -EINVAL;
202 }
203 break;
204 case PM8607_ID_LDO2:
205 case PM8607_ID_LDO3:
206 case PM8607_ID_LDO9:
207 if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */
208 if (min_uV <= 1800000)
209 val = 0;
210 else if (min_uV <= 1900000)
211 val = (min_uV - 1750001) / 50000;
212 else
213 val = 3; /* 2700mV */
214 } else { /* 2700mV ~ 2850mV / 50mV */
215 if (min_uV <= 2850000) {
216 val = (min_uV - 2650001) / 50000;
217 val += 3;
218 } else if (min_uV <= 3300000)
219 val = 7;
220 else
221 val = -EINVAL;
222 }
223 break;
224 case PM8607_ID_LDO4:
225 if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */
226 if (min_uV <= 1800000)
227 val = 0;
228 else if (min_uV <= 1900000)
229 val = (min_uV - 1750001) / 50000;
230 else
231 val = 3; /* 2700mV */
232 } else { /* 2700mV ~ 2800mV / 50mV */
233 if (min_uV <= 2850000) {
234 val = (min_uV - 2650001) / 50000;
235 val += 3;
236 } else if (min_uV <= 2900000)
237 val = 6;
238 else if (min_uV <= 3300000)
239 val = 7;
240 else
241 val = -EINVAL;
242 }
243 break;
244 case PM8607_ID_LDO6:
245 if (min_uV < 2600000) { /* 1800mV ~ 1850mV / 50mV */
246 if (min_uV <= 1800000)
247 val = 0;
248 else if (min_uV <= 1850000)
249 val = (min_uV - 1750001) / 50000;
250 else
251 val = 2; /* 2600mV */
252 } else { /* 2600mV ~ 2800mV / 50mV */
253 if (min_uV <= 2800000) {
254 val = (min_uV - 2550001) / 50000;
255 val += 2;
256 } else if (min_uV <= 3300000)
257 val = 7;
258 else
259 val = -EINVAL;
260 }
261 break;
262 case PM8607_ID_LDO14:
263 if (min_uV < 2700000) { /* 1800mV ~ 1850mV / 50mV */
264 if (min_uV <= 1800000)
265 val = 0;
266 else if (min_uV <= 1850000)
267 val = (min_uV - 1750001) / 50000;
268 else
269 val = 2; /* 2700mV */
270 } else { /* 2700mV ~ 2900mV / 50mV */
271 if (min_uV <= 2900000) {
272 val = (min_uV - 2650001) / 50000;
273 val += 2;
274 } else if (min_uV <= 3300000)
275 val = 7;
276 else
277 val = -EINVAL;
278 }
279 break;
280 }
281 if (val >= 0) {
282 ret = pm8607_list_voltage(rdev, val);
283 if (ret > max_uV) {
284 pr_err("exceed voltage range (%d %d) uV",
285 min_uV, max_uV);
286 return -EINVAL;
287 }
288 } else
289 pr_err("invalid voltage range (%d %d) uV", min_uV, max_uV);
290 return val;
291}
292
293static int pm8607_set_voltage(struct regulator_dev *rdev,
294 int min_uV, int max_uV)
295{
296 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
297 uint8_t val, mask;
298 int ret;
299
300 if (check_range(info, min_uV, max_uV)) {
301 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
302 return -EINVAL;
303 }
304
305 ret = choose_voltage(rdev, min_uV, max_uV);
306 if (ret < 0)
307 return -EINVAL;
308 val = (uint8_t)(ret << info->vol_shift);
309 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
310
311 ret = pm860x_set_bits(info->i2c, info->vol_reg, mask, val);
312 if (ret)
313 return ret;
314 switch (info->desc.id) {
315 case PM8607_ID_BUCK1:
316 case PM8607_ID_BUCK3:
317 ret = pm860x_set_bits(info->i2c, info->update_reg,
318 1 << info->update_bit,
319 1 << info->update_bit);
320 break;
321 }
322 return ret;
323}
324
325static int pm8607_get_voltage(struct regulator_dev *rdev)
326{
327 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
328 uint8_t val, mask;
329 int ret;
330
331 ret = pm860x_reg_read(info->i2c, info->vol_reg);
332 if (ret < 0)
333 return ret;
334
335 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
336 val = ((unsigned char)ret & mask) >> info->vol_shift;
337
338 return pm8607_list_voltage(rdev, val);
339}
340
341static int pm8607_enable(struct regulator_dev *rdev)
342{
343 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
344
345 return pm860x_set_bits(info->i2c, info->enable_reg,
346 1 << info->enable_bit,
347 1 << info->enable_bit);
348}
349
350static int pm8607_disable(struct regulator_dev *rdev)
351{
352 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
353
354 return pm860x_set_bits(info->i2c, info->enable_reg,
355 1 << info->enable_bit, 0);
356}
357
358static int pm8607_is_enabled(struct regulator_dev *rdev)
359{
360 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
361 int ret;
362
363 ret = pm860x_reg_read(info->i2c, info->enable_reg);
364 if (ret < 0)
365 return ret;
366
367 return !!((unsigned char)ret & (1 << info->enable_bit));
368}
369
370static struct regulator_ops pm8607_regulator_ops = {
371 .set_voltage = pm8607_set_voltage,
372 .get_voltage = pm8607_get_voltage,
373 .enable = pm8607_enable,
374 .disable = pm8607_disable,
375 .is_enabled = pm8607_is_enabled,
376};
377
378#define PM8607_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
379{ \
380 .desc = { \
381 .name = "BUCK" #_id, \
382 .ops = &pm8607_regulator_ops, \
383 .type = REGULATOR_VOLTAGE, \
384 .id = PM8607_ID_BUCK##_id, \
385 .owner = THIS_MODULE, \
386 }, \
387 .min_uV = (min) * 1000, \
388 .max_uV = (max) * 1000, \
389 .step_uV = (step) * 1000, \
390 .vol_reg = PM8607_##vreg, \
391 .vol_shift = (0), \
392 .vol_nbits = (nbits), \
393 .update_reg = PM8607_##ureg, \
394 .update_bit = (ubit), \
395 .enable_reg = PM8607_##ereg, \
396 .enable_bit = (ebit), \
397 .slope_double = (0), \
398}
399
400#define PM8607_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
401{ \
402 .desc = { \
403 .name = "LDO" #_id, \
404 .ops = &pm8607_regulator_ops, \
405 .type = REGULATOR_VOLTAGE, \
406 .id = PM8607_ID_LDO##_id, \
407 .owner = THIS_MODULE, \
408 }, \
409 .min_uV = (min) * 1000, \
410 .max_uV = (max) * 1000, \
411 .step_uV = (step) * 1000, \
412 .vol_reg = PM8607_##vreg, \
413 .vol_shift = (shift), \
414 .vol_nbits = (nbits), \
415 .enable_reg = PM8607_##ereg, \
416 .enable_bit = (ebit), \
417 .slope_double = (0), \
418}
419
420static struct pm8607_regulator_info pm8607_regulator_info[] = {
421 PM8607_DVC(1, 0, 1500, 25, BUCK1, 6, GO, 0, SUPPLIES_EN11, 0),
422 PM8607_DVC(3, 0, 1500, 25, BUCK3, 6, GO, 2, SUPPLIES_EN11, 2),
423
424 PM8607_LDO(1 , 1200, 2800, 0, LDO1 , 0, 2, SUPPLIES_EN11, 3),
425 PM8607_LDO(2 , 1800, 3300, 0, LDO2 , 0, 3, SUPPLIES_EN11, 4),
426 PM8607_LDO(3 , 1800, 3300, 0, LDO3 , 0, 3, SUPPLIES_EN11, 5),
427 PM8607_LDO(4 , 1800, 3300, 0, LDO4 , 0, 3, SUPPLIES_EN11, 6),
428 PM8607_LDO(5 , 2900, 3300, 0, LDO5 , 0, 2, SUPPLIES_EN11, 7),
429 PM8607_LDO(6 , 1800, 3300, 0, LDO6 , 0, 3, SUPPLIES_EN12, 0),
430 PM8607_LDO(7 , 1800, 2900, 0, LDO7 , 0, 3, SUPPLIES_EN12, 1),
431 PM8607_LDO(8 , 1800, 2900, 0, LDO8 , 0, 3, SUPPLIES_EN12, 2),
432 PM8607_LDO(9 , 1800, 3300, 0, LDO9 , 0, 3, SUPPLIES_EN12, 3),
433 PM8607_LDO(10, 1200, 3300, 0, LDO10, 0, 4, SUPPLIES_EN11, 4),
434 PM8607_LDO(12, 1200, 3300, 0, LDO12, 0, 4, SUPPLIES_EN11, 5),
435 PM8607_LDO(14, 1800, 3300, 0, LDO14, 0, 3, SUPPLIES_EN11, 6),
436};
437
438static inline struct pm8607_regulator_info *find_regulator_info(int id)
439{
440 struct pm8607_regulator_info *info;
441 int i;
442
443 for (i = 0; i < ARRAY_SIZE(pm8607_regulator_info); i++) {
444 info = &pm8607_regulator_info[i];
445 if (info->desc.id == id)
446 return info;
447 }
448 return NULL;
449}
450
451static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
452{
453 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
454 struct pm860x_platform_data *pdata = chip->dev->platform_data;
455 struct pm8607_regulator_info *info = NULL;
456
457 info = find_regulator_info(pdev->id);
458 if (info == NULL) {
459 dev_err(&pdev->dev, "invalid regulator ID specified\n");
460 return -EINVAL;
461 }
462
463 info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
464 info->chip = chip;
465
466 info->regulator = regulator_register(&info->desc, &pdev->dev,
467 pdata->regulator[pdev->id], info);
468 if (IS_ERR(info->regulator)) {
469 dev_err(&pdev->dev, "failed to register regulator %s\n",
470 info->desc.name);
471 return PTR_ERR(info->regulator);
472 }
473
474 /* check DVC ramp slope double */
475 if (info->desc.id == PM8607_ID_BUCK3)
476 if (info->chip->buck3_double)
477 info->slope_double = 1;
478
479 platform_set_drvdata(pdev, info);
480 return 0;
481}
482
483static int __devexit pm8607_regulator_remove(struct platform_device *pdev)
484{
485 struct pm8607_regulator_info *info = platform_get_drvdata(pdev);
486
487 regulator_unregister(info->regulator);
488 return 0;
489}
490
491#define PM8607_REGULATOR_DRIVER(_name) \
492{ \
493 .driver = { \
494 .name = "88pm8607-" #_name, \
495 .owner = THIS_MODULE, \
496 }, \
497 .probe = pm8607_regulator_probe, \
498 .remove = __devexit_p(pm8607_regulator_remove), \
499}
500
501static struct platform_driver pm8607_regulator_driver[] = {
502 PM8607_REGULATOR_DRIVER(buck1),
503 PM8607_REGULATOR_DRIVER(buck2),
504 PM8607_REGULATOR_DRIVER(buck3),
505 PM8607_REGULATOR_DRIVER(ldo1),
506 PM8607_REGULATOR_DRIVER(ldo2),
507 PM8607_REGULATOR_DRIVER(ldo3),
508 PM8607_REGULATOR_DRIVER(ldo4),
509 PM8607_REGULATOR_DRIVER(ldo5),
510 PM8607_REGULATOR_DRIVER(ldo6),
511 PM8607_REGULATOR_DRIVER(ldo7),
512 PM8607_REGULATOR_DRIVER(ldo8),
513 PM8607_REGULATOR_DRIVER(ldo9),
514 PM8607_REGULATOR_DRIVER(ldo10),
515 PM8607_REGULATOR_DRIVER(ldo12),
516 PM8607_REGULATOR_DRIVER(ldo14),
517};
518
519static int __init pm8607_regulator_init(void)
520{
521 int i, count, ret;
522
523 count = ARRAY_SIZE(pm8607_regulator_driver);
524 for (i = 0; i < count; i++) {
525 ret = platform_driver_register(&pm8607_regulator_driver[i]);
526 if (ret != 0)
527 pr_err("Failed to register regulator driver: %d\n",
528 ret);
529 }
530 return 0;
531}
532subsys_initcall(pm8607_regulator_init);
533
534static void __exit pm8607_regulator_exit(void)
535{
536 int i, count;
537
538 count = ARRAY_SIZE(pm8607_regulator_driver);
539 for (i = 0; i < count; i++)
540 platform_driver_unregister(&pm8607_regulator_driver[i]);
541}
542module_exit(pm8607_regulator_exit);
543
544MODULE_LICENSE("GPL");
545MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
546MODULE_DESCRIPTION("Regulator Driver for Marvell 88PM8607 PMIC");
547MODULE_ALIAS("platform:88pm8607-regulator");
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index bcbb161bde0b..04f2e085116a 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -27,6 +27,17 @@ config REGULATOR_DEBUG
27 help 27 help
28 Say yes here to enable debugging support. 28 Say yes here to enable debugging support.
29 29
30config REGULATOR_DUMMY
31 bool "Provide a dummy regulator if regulator lookups fail"
32 help
33 If this option is enabled then when a regulator lookup fails
34 and the board has not specified that it has provided full
35 constraints then the regulator core will provide an always
36 enabled dummy regulator will be provided, allowing consumer
37 drivers to continue.
38
39 A warning will be generated when this substitution is done.
40
30config REGULATOR_FIXED_VOLTAGE 41config REGULATOR_FIXED_VOLTAGE
31 tristate "Fixed voltage regulator support" 42 tristate "Fixed voltage regulator support"
32 help 43 help
@@ -69,8 +80,28 @@ config REGULATOR_MAX1586
69 regulator via I2C bus. The provided regulator is suitable 80 regulator via I2C bus. The provided regulator is suitable
70 for PXA27x chips to control VCC_CORE and VCC_USIM voltages. 81 for PXA27x chips to control VCC_CORE and VCC_USIM voltages.
71 82
83config REGULATOR_MAX8649
84 tristate "Maxim 8649 voltage regulator"
85 depends on I2C
86 help
87 This driver controls a Maxim 8649 voltage output regulator via
88 I2C bus.
89
90config REGULATOR_MAX8660
91 tristate "Maxim 8660/8661 voltage regulator"
92 depends on I2C
93 help
94 This driver controls a Maxim 8660/8661 voltage output
95 regulator via I2C bus.
96
97config REGULATOR_MAX8925
98 tristate "Maxim MAX8925 Power Management IC"
99 depends on MFD_MAX8925
100 help
101 Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC.
102
72config REGULATOR_TWL4030 103config REGULATOR_TWL4030
73 bool "TI TWL4030/TWL5030/TPS695x0 PMIC" 104 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC"
74 depends on TWL4030_CORE 105 depends on TWL4030_CORE
75 help 106 help
76 This driver supports the voltage regulators provided by 107 This driver supports the voltage regulators provided by
@@ -84,19 +115,26 @@ config REGULATOR_WM831X
84 of PMIC devices. 115 of PMIC devices.
85 116
86config REGULATOR_WM8350 117config REGULATOR_WM8350
87 tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC" 118 tristate "Wolfson Microelectronics WM8350 AudioPlus PMIC"
88 depends on MFD_WM8350 119 depends on MFD_WM8350
89 help 120 help
90 This driver provides support for the voltage and current regulators 121 This driver provides support for the voltage and current regulators
91 of the WM8350 AudioPlus PMIC. 122 of the WM8350 AudioPlus PMIC.
92 123
93config REGULATOR_WM8400 124config REGULATOR_WM8400
94 tristate "Wolfson Microelectroncis WM8400 AudioPlus PMIC" 125 tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC"
95 depends on MFD_WM8400 126 depends on MFD_WM8400
96 help 127 help
97 This driver provides support for the voltage regulators of the 128 This driver provides support for the voltage regulators of the
98 WM8400 AudioPlus PMIC. 129 WM8400 AudioPlus PMIC.
99 130
131config REGULATOR_WM8994
132 tristate "Wolfson Microelectronics WM8994 CODEC"
133 depends on MFD_WM8994
134 help
135 This driver provides support for the voltage regulators on the
136 WM8994 CODEC.
137
100config REGULATOR_DA903X 138config REGULATOR_DA903X
101 tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC" 139 tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC"
102 depends on PMIC_DA903X 140 depends on PMIC_DA903X
@@ -157,5 +195,11 @@ config REGULATOR_TPS6507X
157 three step-down converters and two general-purpose LDO voltage regulators. 195 three step-down converters and two general-purpose LDO voltage regulators.
158 It supports TI's software based Class-2 SmartReflex implementation. 196 It supports TI's software based Class-2 SmartReflex implementation.
159 197
198config REGULATOR_88PM8607
199 bool "Marvell 88PM8607 Power regulators"
200 depends on MFD_88PM860X=y
201 help
202 This driver supports 88PM8607 voltage regulator chips.
203
160endif 204endif
161 205
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 4257a8683778..4e7feece22d5 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -9,21 +9,27 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
9obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 9obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
10 10
11obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 11obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
12obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
12obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 13obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
13obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 14obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
14obj-$(CONFIG_REGULATOR_TWL4030) += twl4030-regulator.o 15obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
16obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
17obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
18obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o
15obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 19obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
16obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 20obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o
17obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o 21obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
18obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o 22obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
19obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o 23obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
24obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
20obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 25obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
21obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 26obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
22obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 27obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
23obj-$(CONFIG_REGULATOR_MC13783) += mc13783.o 28obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
24obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 29obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
25 30
26obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 31obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
27obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 32obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
33obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
28 34
29ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG 35ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 49aeee823a25..7de950959ed2 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -81,7 +81,7 @@ static const u8 ab3100_reg_init_order[AB3100_NUM_REGULATORS+2] = {
81#define LDO_C_VOLTAGE 2650000 81#define LDO_C_VOLTAGE 2650000
82#define LDO_D_VOLTAGE 2650000 82#define LDO_D_VOLTAGE 2650000
83 83
84static const int const ldo_e_buck_typ_voltages[] = { 84static const int ldo_e_buck_typ_voltages[] = {
85 1800000, 85 1800000,
86 1400000, 86 1400000,
87 1300000, 87 1300000,
@@ -91,7 +91,7 @@ static const int const ldo_e_buck_typ_voltages[] = {
91 900000, 91 900000,
92}; 92};
93 93
94static const int const ldo_f_typ_voltages[] = { 94static const int ldo_f_typ_voltages[] = {
95 1800000, 95 1800000,
96 1400000, 96 1400000,
97 1300000, 97 1300000,
@@ -102,21 +102,21 @@ static const int const ldo_f_typ_voltages[] = {
102 2650000, 102 2650000,
103}; 103};
104 104
105static const int const ldo_g_typ_voltages[] = { 105static const int ldo_g_typ_voltages[] = {
106 2850000, 106 2850000,
107 2750000, 107 2750000,
108 1800000, 108 1800000,
109 1500000, 109 1500000,
110}; 110};
111 111
112static const int const ldo_h_typ_voltages[] = { 112static const int ldo_h_typ_voltages[] = {
113 2750000, 113 2750000,
114 1800000, 114 1800000,
115 1500000, 115 1500000,
116 1200000, 116 1200000,
117}; 117};
118 118
119static const int const ldo_k_typ_voltages[] = { 119static const int ldo_k_typ_voltages[] = {
120 2750000, 120 2750000,
121 1800000, 121 1800000,
122}; 122};
@@ -241,24 +241,12 @@ static int ab3100_disable_regulator(struct regulator_dev *reg)
241 * LDO D is a special regulator. When it is disabled, the entire 241 * LDO D is a special regulator. When it is disabled, the entire
242 * system is shut down. So this is handled specially. 242 * system is shut down. So this is handled specially.
243 */ 243 */
244 pr_info("Called ab3100_disable_regulator\n");
244 if (abreg->regreg == AB3100_LDO_D) { 245 if (abreg->regreg == AB3100_LDO_D) {
245 int i;
246
247 dev_info(&reg->dev, "disabling LDO D - shut down system\n"); 246 dev_info(&reg->dev, "disabling LDO D - shut down system\n");
248 /*
249 * Set regulators to default values, ignore any errors,
250 * we're going DOWN
251 */
252 for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
253 (void) ab3100_set_register_interruptible(abreg->ab3100,
254 ab3100_reg_init_order[i],
255 abreg->plfdata->reg_initvals[i]);
256 }
257
258 /* Setting LDO D to 0x00 cuts the power to the SoC */ 247 /* Setting LDO D to 0x00 cuts the power to the SoC */
259 return ab3100_set_register_interruptible(abreg->ab3100, 248 return ab3100_set_register_interruptible(abreg->ab3100,
260 AB3100_LDO_D, 0x00U); 249 AB3100_LDO_D, 0x00U);
261
262 } 250 }
263 251
264 /* 252 /*
@@ -573,7 +561,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
573 * for all the different regulators. 561 * for all the different regulators.
574 */ 562 */
575 563
576static int __init ab3100_regulators_probe(struct platform_device *pdev) 564static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
577{ 565{
578 struct ab3100_platform_data *plfdata = pdev->dev.platform_data; 566 struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
579 struct ab3100 *ab3100 = platform_get_drvdata(pdev); 567 struct ab3100 *ab3100 = platform_get_drvdata(pdev);
@@ -607,13 +595,6 @@ static int __init ab3100_regulators_probe(struct platform_device *pdev)
607 } 595 }
608 } 596 }
609 597
610 if (err) {
611 dev_err(&pdev->dev,
612 "LDO D regulator initialization failed with error %d\n",
613 err);
614 return err;
615 }
616
617 /* Register the regulators */ 598 /* Register the regulators */
618 for (i = 0; i < AB3100_NUM_REGULATORS; i++) { 599 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
619 struct ab3100_regulator *reg = &ab3100_regulators[i]; 600 struct ab3100_regulator *reg = &ab3100_regulators[i];
@@ -660,7 +641,7 @@ static int __init ab3100_regulators_probe(struct platform_device *pdev)
660 return 0; 641 return 0;
661} 642}
662 643
663static int __exit ab3100_regulators_remove(struct platform_device *pdev) 644static int __devexit ab3100_regulators_remove(struct platform_device *pdev)
664{ 645{
665 int i; 646 int i;
666 647
@@ -678,7 +659,7 @@ static struct platform_driver ab3100_regulators_driver = {
678 .owner = THIS_MODULE, 659 .owner = THIS_MODULE,
679 }, 660 },
680 .probe = ab3100_regulators_probe, 661 .probe = ab3100_regulators_probe,
681 .remove = __exit_p(ab3100_regulators_remove), 662 .remove = __devexit_p(ab3100_regulators_remove),
682}; 663};
683 664
684static __init int ab3100_regulators_init(void) 665static __init int ab3100_regulators_init(void)
@@ -688,7 +669,7 @@ static __init int ab3100_regulators_init(void)
688 669
689static __exit void ab3100_regulators_exit(void) 670static __exit void ab3100_regulators_exit(void)
690{ 671{
691 platform_driver_register(&ab3100_regulators_driver); 672 platform_driver_unregister(&ab3100_regulators_driver);
692} 673}
693 674
694subsys_initcall(ab3100_regulators_init); 675subsys_initcall(ab3100_regulators_init);
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index efe568deda12..2b4e40d31190 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -16,13 +16,17 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/slab.h>
19#include <linux/err.h> 20#include <linux/err.h>
20#include <linux/mutex.h> 21#include <linux/mutex.h>
21#include <linux/suspend.h> 22#include <linux/suspend.h>
23#include <linux/delay.h>
22#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
23#include <linux/regulator/driver.h> 25#include <linux/regulator/driver.h>
24#include <linux/regulator/machine.h> 26#include <linux/regulator/machine.h>
25 27
28#include "dummy.h"
29
26#define REGULATOR_VERSION "0.5" 30#define REGULATOR_VERSION "0.5"
27 31
28static DEFINE_MUTEX(regulator_list_mutex); 32static DEFINE_MUTEX(regulator_list_mutex);
@@ -66,6 +70,16 @@ static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
66static void _notifier_call_chain(struct regulator_dev *rdev, 70static void _notifier_call_chain(struct regulator_dev *rdev,
67 unsigned long event, void *data); 71 unsigned long event, void *data);
68 72
73static const char *rdev_get_name(struct regulator_dev *rdev)
74{
75 if (rdev->constraints && rdev->constraints->name)
76 return rdev->constraints->name;
77 else if (rdev->desc->name)
78 return rdev->desc->name;
79 else
80 return "";
81}
82
69/* gets the regulator for a given consumer device */ 83/* gets the regulator for a given consumer device */
70static struct regulator *get_device_regulator(struct device *dev) 84static struct regulator *get_device_regulator(struct device *dev)
71{ 85{
@@ -96,12 +110,12 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
96 110
97 if (!rdev->constraints) { 111 if (!rdev->constraints) {
98 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 112 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
99 rdev->desc->name); 113 rdev_get_name(rdev));
100 return -ENODEV; 114 return -ENODEV;
101 } 115 }
102 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 116 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
103 printk(KERN_ERR "%s: operation not allowed for %s\n", 117 printk(KERN_ERR "%s: operation not allowed for %s\n",
104 __func__, rdev->desc->name); 118 __func__, rdev_get_name(rdev));
105 return -EPERM; 119 return -EPERM;
106 } 120 }
107 121
@@ -124,12 +138,12 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
124 138
125 if (!rdev->constraints) { 139 if (!rdev->constraints) {
126 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 140 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
127 rdev->desc->name); 141 rdev_get_name(rdev));
128 return -ENODEV; 142 return -ENODEV;
129 } 143 }
130 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { 144 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
131 printk(KERN_ERR "%s: operation not allowed for %s\n", 145 printk(KERN_ERR "%s: operation not allowed for %s\n",
132 __func__, rdev->desc->name); 146 __func__, rdev_get_name(rdev));
133 return -EPERM; 147 return -EPERM;
134 } 148 }
135 149
@@ -159,17 +173,17 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
159 173
160 if (!rdev->constraints) { 174 if (!rdev->constraints) {
161 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 175 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
162 rdev->desc->name); 176 rdev_get_name(rdev));
163 return -ENODEV; 177 return -ENODEV;
164 } 178 }
165 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { 179 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
166 printk(KERN_ERR "%s: operation not allowed for %s\n", 180 printk(KERN_ERR "%s: operation not allowed for %s\n",
167 __func__, rdev->desc->name); 181 __func__, rdev_get_name(rdev));
168 return -EPERM; 182 return -EPERM;
169 } 183 }
170 if (!(rdev->constraints->valid_modes_mask & mode)) { 184 if (!(rdev->constraints->valid_modes_mask & mode)) {
171 printk(KERN_ERR "%s: invalid mode %x for %s\n", 185 printk(KERN_ERR "%s: invalid mode %x for %s\n",
172 __func__, mode, rdev->desc->name); 186 __func__, mode, rdev_get_name(rdev));
173 return -EINVAL; 187 return -EINVAL;
174 } 188 }
175 return 0; 189 return 0;
@@ -180,12 +194,12 @@ static int regulator_check_drms(struct regulator_dev *rdev)
180{ 194{
181 if (!rdev->constraints) { 195 if (!rdev->constraints) {
182 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 196 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
183 rdev->desc->name); 197 rdev_get_name(rdev));
184 return -ENODEV; 198 return -ENODEV;
185 } 199 }
186 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { 200 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
187 printk(KERN_ERR "%s: operation not allowed for %s\n", 201 printk(KERN_ERR "%s: operation not allowed for %s\n",
188 __func__, rdev->desc->name); 202 __func__, rdev_get_name(rdev));
189 return -EPERM; 203 return -EPERM;
190 } 204 }
191 return 0; 205 return 0;
@@ -230,16 +244,8 @@ static ssize_t regulator_name_show(struct device *dev,
230 struct device_attribute *attr, char *buf) 244 struct device_attribute *attr, char *buf)
231{ 245{
232 struct regulator_dev *rdev = dev_get_drvdata(dev); 246 struct regulator_dev *rdev = dev_get_drvdata(dev);
233 const char *name;
234 247
235 if (rdev->constraints && rdev->constraints->name) 248 return sprintf(buf, "%s\n", rdev_get_name(rdev));
236 name = rdev->constraints->name;
237 else if (rdev->desc->name)
238 name = rdev->desc->name;
239 else
240 name = "";
241
242 return sprintf(buf, "%s\n", name);
243} 249}
244 250
245static ssize_t regulator_print_opmode(char *buf, int mode) 251static ssize_t regulator_print_opmode(char *buf, int mode)
@@ -388,7 +394,7 @@ static ssize_t regulator_total_uA_show(struct device *dev,
388 394
389 mutex_lock(&rdev->mutex); 395 mutex_lock(&rdev->mutex);
390 list_for_each_entry(regulator, &rdev->consumer_list, list) 396 list_for_each_entry(regulator, &rdev->consumer_list, list)
391 uA += regulator->uA_load; 397 uA += regulator->uA_load;
392 mutex_unlock(&rdev->mutex); 398 mutex_unlock(&rdev->mutex);
393 return sprintf(buf, "%d\n", uA); 399 return sprintf(buf, "%d\n", uA);
394} 400}
@@ -563,7 +569,7 @@ static void drms_uA_update(struct regulator_dev *rdev)
563 569
564 /* calc total requested load */ 570 /* calc total requested load */
565 list_for_each_entry(sibling, &rdev->consumer_list, list) 571 list_for_each_entry(sibling, &rdev->consumer_list, list)
566 current_uA += sibling->uA_load; 572 current_uA += sibling->uA_load;
567 573
568 /* now get the optimum mode for our new total regulator load */ 574 /* now get the optimum mode for our new total regulator load */
569 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, 575 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV,
@@ -579,10 +585,29 @@ static int suspend_set_state(struct regulator_dev *rdev,
579 struct regulator_state *rstate) 585 struct regulator_state *rstate)
580{ 586{
581 int ret = 0; 587 int ret = 0;
588 bool can_set_state;
589
590 can_set_state = rdev->desc->ops->set_suspend_enable &&
591 rdev->desc->ops->set_suspend_disable;
592
593 /* If we have no suspend mode configration don't set anything;
594 * only warn if the driver actually makes the suspend mode
595 * configurable.
596 */
597 if (!rstate->enabled && !rstate->disabled) {
598 if (can_set_state)
599 printk(KERN_WARNING "%s: No configuration for %s\n",
600 __func__, rdev_get_name(rdev));
601 return 0;
602 }
582 603
583 /* enable & disable are mandatory for suspend control */ 604 if (rstate->enabled && rstate->disabled) {
584 if (!rdev->desc->ops->set_suspend_enable || 605 printk(KERN_ERR "%s: invalid configuration for %s\n",
585 !rdev->desc->ops->set_suspend_disable) { 606 __func__, rdev_get_name(rdev));
607 return -EINVAL;
608 }
609
610 if (!can_set_state) {
586 printk(KERN_ERR "%s: no way to set suspend state\n", 611 printk(KERN_ERR "%s: no way to set suspend state\n",
587 __func__); 612 __func__);
588 return -EINVAL; 613 return -EINVAL;
@@ -640,26 +665,44 @@ static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
640static void print_constraints(struct regulator_dev *rdev) 665static void print_constraints(struct regulator_dev *rdev)
641{ 666{
642 struct regulation_constraints *constraints = rdev->constraints; 667 struct regulation_constraints *constraints = rdev->constraints;
643 char buf[80]; 668 char buf[80] = "";
644 int count; 669 int count = 0;
670 int ret;
645 671
646 if (rdev->desc->type == REGULATOR_VOLTAGE) { 672 if (constraints->min_uV && constraints->max_uV) {
647 if (constraints->min_uV == constraints->max_uV) 673 if (constraints->min_uV == constraints->max_uV)
648 count = sprintf(buf, "%d mV ", 674 count += sprintf(buf + count, "%d mV ",
649 constraints->min_uV / 1000); 675 constraints->min_uV / 1000);
650 else 676 else
651 count = sprintf(buf, "%d <--> %d mV ", 677 count += sprintf(buf + count, "%d <--> %d mV ",
652 constraints->min_uV / 1000, 678 constraints->min_uV / 1000,
653 constraints->max_uV / 1000); 679 constraints->max_uV / 1000);
654 } else { 680 }
681
682 if (!constraints->min_uV ||
683 constraints->min_uV != constraints->max_uV) {
684 ret = _regulator_get_voltage(rdev);
685 if (ret > 0)
686 count += sprintf(buf + count, "at %d mV ", ret / 1000);
687 }
688
689 if (constraints->min_uA && constraints->max_uA) {
655 if (constraints->min_uA == constraints->max_uA) 690 if (constraints->min_uA == constraints->max_uA)
656 count = sprintf(buf, "%d mA ", 691 count += sprintf(buf + count, "%d mA ",
657 constraints->min_uA / 1000); 692 constraints->min_uA / 1000);
658 else 693 else
659 count = sprintf(buf, "%d <--> %d mA ", 694 count += sprintf(buf + count, "%d <--> %d mA ",
660 constraints->min_uA / 1000, 695 constraints->min_uA / 1000,
661 constraints->max_uA / 1000); 696 constraints->max_uA / 1000);
662 } 697 }
698
699 if (!constraints->min_uA ||
700 constraints->min_uA != constraints->max_uA) {
701 ret = _regulator_get_current_limit(rdev);
702 if (ret > 0)
703 count += sprintf(buf + count, "at %d uA ", ret / 1000);
704 }
705
663 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) 706 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
664 count += sprintf(buf + count, "fast "); 707 count += sprintf(buf + count, "fast ");
665 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) 708 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL)
@@ -669,33 +712,30 @@ static void print_constraints(struct regulator_dev *rdev)
669 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 712 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
670 count += sprintf(buf + count, "standby"); 713 count += sprintf(buf + count, "standby");
671 714
672 printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); 715 printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf);
673} 716}
674 717
675/** 718static int machine_constraints_voltage(struct regulator_dev *rdev,
676 * set_machine_constraints - sets regulator constraints
677 * @rdev: regulator source
678 * @constraints: constraints to apply
679 *
680 * Allows platform initialisation code to define and constrain
681 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
682 * Constraints *must* be set by platform code in order for some
683 * regulator operations to proceed i.e. set_voltage, set_current_limit,
684 * set_mode.
685 */
686static int set_machine_constraints(struct regulator_dev *rdev,
687 struct regulation_constraints *constraints) 719 struct regulation_constraints *constraints)
688{ 720{
689 int ret = 0;
690 const char *name;
691 struct regulator_ops *ops = rdev->desc->ops; 721 struct regulator_ops *ops = rdev->desc->ops;
722 const char *name = rdev_get_name(rdev);
723 int ret;
692 724
693 if (constraints->name) 725 /* do we need to apply the constraint voltage */
694 name = constraints->name; 726 if (rdev->constraints->apply_uV &&
695 else if (rdev->desc->name) 727 rdev->constraints->min_uV == rdev->constraints->max_uV &&
696 name = rdev->desc->name; 728 ops->set_voltage) {
697 else 729 ret = ops->set_voltage(rdev,
698 name = "regulator"; 730 rdev->constraints->min_uV, rdev->constraints->max_uV);
731 if (ret < 0) {
732 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
733 __func__,
734 rdev->constraints->min_uV, name);
735 rdev->constraints = NULL;
736 return ret;
737 }
738 }
699 739
700 /* constrain machine-level voltage specs to fit 740 /* constrain machine-level voltage specs to fit
701 * the actual range supported by this regulator. 741 * the actual range supported by this regulator.
@@ -719,14 +759,13 @@ static int set_machine_constraints(struct regulator_dev *rdev,
719 759
720 /* voltage constraints are optional */ 760 /* voltage constraints are optional */
721 if ((cmin == 0) && (cmax == 0)) 761 if ((cmin == 0) && (cmax == 0))
722 goto out; 762 return 0;
723 763
724 /* else require explicit machine-level constraints */ 764 /* else require explicit machine-level constraints */
725 if (cmin <= 0 || cmax <= 0 || cmax < cmin) { 765 if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
726 pr_err("%s: %s '%s' voltage constraints\n", 766 pr_err("%s: %s '%s' voltage constraints\n",
727 __func__, "invalid", name); 767 __func__, "invalid", name);
728 ret = -EINVAL; 768 return -EINVAL;
729 goto out;
730 } 769 }
731 770
732 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ 771 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
@@ -748,8 +787,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
748 if (max_uV < min_uV) { 787 if (max_uV < min_uV) {
749 pr_err("%s: %s '%s' voltage constraints\n", 788 pr_err("%s: %s '%s' voltage constraints\n",
750 __func__, "unsupportable", name); 789 __func__, "unsupportable", name);
751 ret = -EINVAL; 790 return -EINVAL;
752 goto out;
753 } 791 }
754 792
755 /* use regulator's subset of machine constraints */ 793 /* use regulator's subset of machine constraints */
@@ -767,22 +805,34 @@ static int set_machine_constraints(struct regulator_dev *rdev,
767 } 805 }
768 } 806 }
769 807
808 return 0;
809}
810
811/**
812 * set_machine_constraints - sets regulator constraints
813 * @rdev: regulator source
814 * @constraints: constraints to apply
815 *
816 * Allows platform initialisation code to define and constrain
817 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
818 * Constraints *must* be set by platform code in order for some
819 * regulator operations to proceed i.e. set_voltage, set_current_limit,
820 * set_mode.
821 */
822static int set_machine_constraints(struct regulator_dev *rdev,
823 struct regulation_constraints *constraints)
824{
825 int ret = 0;
826 const char *name;
827 struct regulator_ops *ops = rdev->desc->ops;
828
770 rdev->constraints = constraints; 829 rdev->constraints = constraints;
771 830
772 /* do we need to apply the constraint voltage */ 831 name = rdev_get_name(rdev);
773 if (rdev->constraints->apply_uV && 832
774 rdev->constraints->min_uV == rdev->constraints->max_uV && 833 ret = machine_constraints_voltage(rdev, constraints);
775 ops->set_voltage) { 834 if (ret != 0)
776 ret = ops->set_voltage(rdev, 835 goto out;
777 rdev->constraints->min_uV, rdev->constraints->max_uV);
778 if (ret < 0) {
779 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
780 __func__,
781 rdev->constraints->min_uV, name);
782 rdev->constraints = NULL;
783 goto out;
784 }
785 }
786 836
787 /* do we need to setup our suspend state */ 837 /* do we need to setup our suspend state */
788 if (constraints->initial_state) { 838 if (constraints->initial_state) {
@@ -903,7 +953,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
903 dev_name(&node->regulator->dev), 953 dev_name(&node->regulator->dev),
904 node->regulator->desc->name, 954 node->regulator->desc->name,
905 supply, 955 supply,
906 dev_name(&rdev->dev), rdev->desc->name); 956 dev_name(&rdev->dev), rdev_get_name(rdev));
907 return -EBUSY; 957 return -EBUSY;
908 } 958 }
909 959
@@ -989,6 +1039,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
989 goto overflow_err; 1039 goto overflow_err;
990 1040
991 regulator->dev = dev; 1041 regulator->dev = dev;
1042 sysfs_attr_init(&regulator->dev_attr.attr);
992 regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL); 1043 regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL);
993 if (regulator->dev_attr.attr.name == NULL) 1044 if (regulator->dev_attr.attr.name == NULL)
994 goto attr_name_err; 1045 goto attr_name_err;
@@ -1038,6 +1089,13 @@ overflow_err:
1038 return NULL; 1089 return NULL;
1039} 1090}
1040 1091
1092static int _regulator_get_enable_time(struct regulator_dev *rdev)
1093{
1094 if (!rdev->desc->ops->enable_time)
1095 return 0;
1096 return rdev->desc->ops->enable_time(rdev);
1097}
1098
1041/* Internal regulator request function */ 1099/* Internal regulator request function */
1042static struct regulator *_regulator_get(struct device *dev, const char *id, 1100static struct regulator *_regulator_get(struct device *dev, const char *id,
1043 int exclusive) 1101 int exclusive)
@@ -1069,6 +1127,22 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1069 goto found; 1127 goto found;
1070 } 1128 }
1071 } 1129 }
1130
1131#ifdef CONFIG_REGULATOR_DUMMY
1132 if (!devname)
1133 devname = "deviceless";
1134
1135 /* If the board didn't flag that it was fully constrained then
1136 * substitute in a dummy regulator so consumers can continue.
1137 */
1138 if (!has_full_constraints) {
1139 pr_warning("%s supply %s not found, using dummy regulator\n",
1140 devname, id);
1141 rdev = dummy_regulator_rdev;
1142 goto found;
1143 }
1144#endif
1145
1072 mutex_unlock(&regulator_list_mutex); 1146 mutex_unlock(&regulator_list_mutex);
1073 return regulator; 1147 return regulator;
1074 1148
@@ -1205,14 +1279,14 @@ static int _regulator_can_change_status(struct regulator_dev *rdev)
1205/* locks held by regulator_enable() */ 1279/* locks held by regulator_enable() */
1206static int _regulator_enable(struct regulator_dev *rdev) 1280static int _regulator_enable(struct regulator_dev *rdev)
1207{ 1281{
1208 int ret; 1282 int ret, delay;
1209 1283
1210 /* do we need to enable the supply regulator first */ 1284 /* do we need to enable the supply regulator first */
1211 if (rdev->supply) { 1285 if (rdev->supply) {
1212 ret = _regulator_enable(rdev->supply); 1286 ret = _regulator_enable(rdev->supply);
1213 if (ret < 0) { 1287 if (ret < 0) {
1214 printk(KERN_ERR "%s: failed to enable %s: %d\n", 1288 printk(KERN_ERR "%s: failed to enable %s: %d\n",
1215 __func__, rdev->desc->name, ret); 1289 __func__, rdev_get_name(rdev), ret);
1216 return ret; 1290 return ret;
1217 } 1291 }
1218 } 1292 }
@@ -1229,16 +1303,37 @@ static int _regulator_enable(struct regulator_dev *rdev)
1229 if (!_regulator_can_change_status(rdev)) 1303 if (!_regulator_can_change_status(rdev))
1230 return -EPERM; 1304 return -EPERM;
1231 1305
1232 if (rdev->desc->ops->enable) { 1306 if (!rdev->desc->ops->enable)
1233 ret = rdev->desc->ops->enable(rdev);
1234 if (ret < 0)
1235 return ret;
1236 } else {
1237 return -EINVAL; 1307 return -EINVAL;
1308
1309 /* Query before enabling in case configuration
1310 * dependant. */
1311 ret = _regulator_get_enable_time(rdev);
1312 if (ret >= 0) {
1313 delay = ret;
1314 } else {
1315 printk(KERN_WARNING
1316 "%s: enable_time() failed for %s: %d\n",
1317 __func__, rdev_get_name(rdev),
1318 ret);
1319 delay = 0;
1238 } 1320 }
1321
1322 /* Allow the regulator to ramp; it would be useful
1323 * to extend this for bulk operations so that the
1324 * regulators can ramp together. */
1325 ret = rdev->desc->ops->enable(rdev);
1326 if (ret < 0)
1327 return ret;
1328
1329 if (delay >= 1000)
1330 mdelay(delay / 1000);
1331 else if (delay)
1332 udelay(delay);
1333
1239 } else if (ret < 0) { 1334 } else if (ret < 0) {
1240 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", 1335 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
1241 __func__, rdev->desc->name, ret); 1336 __func__, rdev_get_name(rdev), ret);
1242 return ret; 1337 return ret;
1243 } 1338 }
1244 /* Fallthrough on positive return values - already enabled */ 1339 /* Fallthrough on positive return values - already enabled */
@@ -1279,7 +1374,7 @@ static int _regulator_disable(struct regulator_dev *rdev)
1279 1374
1280 if (WARN(rdev->use_count <= 0, 1375 if (WARN(rdev->use_count <= 0,
1281 "unbalanced disables for %s\n", 1376 "unbalanced disables for %s\n",
1282 rdev->desc->name)) 1377 rdev_get_name(rdev)))
1283 return -EIO; 1378 return -EIO;
1284 1379
1285 /* are we the last user and permitted to disable ? */ 1380 /* are we the last user and permitted to disable ? */
@@ -1292,9 +1387,12 @@ static int _regulator_disable(struct regulator_dev *rdev)
1292 ret = rdev->desc->ops->disable(rdev); 1387 ret = rdev->desc->ops->disable(rdev);
1293 if (ret < 0) { 1388 if (ret < 0) {
1294 printk(KERN_ERR "%s: failed to disable %s\n", 1389 printk(KERN_ERR "%s: failed to disable %s\n",
1295 __func__, rdev->desc->name); 1390 __func__, rdev_get_name(rdev));
1296 return ret; 1391 return ret;
1297 } 1392 }
1393
1394 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1395 NULL);
1298 } 1396 }
1299 1397
1300 /* decrease our supplies ref count and disable if required */ 1398 /* decrease our supplies ref count and disable if required */
@@ -1349,12 +1447,12 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1349 ret = rdev->desc->ops->disable(rdev); 1447 ret = rdev->desc->ops->disable(rdev);
1350 if (ret < 0) { 1448 if (ret < 0) {
1351 printk(KERN_ERR "%s: failed to force disable %s\n", 1449 printk(KERN_ERR "%s: failed to force disable %s\n",
1352 __func__, rdev->desc->name); 1450 __func__, rdev_get_name(rdev));
1353 return ret; 1451 return ret;
1354 } 1452 }
1355 /* notify other consumers that power has been forced off */ 1453 /* notify other consumers that power has been forced off */
1356 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE, 1454 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
1357 NULL); 1455 REGULATOR_EVENT_DISABLE, NULL);
1358 } 1456 }
1359 1457
1360 /* decrease our supplies ref count and disable if required */ 1458 /* decrease our supplies ref count and disable if required */
@@ -1388,9 +1486,9 @@ EXPORT_SYMBOL_GPL(regulator_force_disable);
1388 1486
1389static int _regulator_is_enabled(struct regulator_dev *rdev) 1487static int _regulator_is_enabled(struct regulator_dev *rdev)
1390{ 1488{
1391 /* sanity check */ 1489 /* If we don't know then assume that the regulator is always on */
1392 if (!rdev->desc->ops->is_enabled) 1490 if (!rdev->desc->ops->is_enabled)
1393 return -EINVAL; 1491 return 1;
1394 1492
1395 return rdev->desc->ops->is_enabled(rdev); 1493 return rdev->desc->ops->is_enabled(rdev);
1396} 1494}
@@ -1766,7 +1864,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1766 output_uV = rdev->desc->ops->get_voltage(rdev); 1864 output_uV = rdev->desc->ops->get_voltage(rdev);
1767 if (output_uV <= 0) { 1865 if (output_uV <= 0) {
1768 printk(KERN_ERR "%s: invalid output voltage found for %s\n", 1866 printk(KERN_ERR "%s: invalid output voltage found for %s\n",
1769 __func__, rdev->desc->name); 1867 __func__, rdev_get_name(rdev));
1770 goto out; 1868 goto out;
1771 } 1869 }
1772 1870
@@ -1777,13 +1875,13 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1777 input_uV = rdev->constraints->input_uV; 1875 input_uV = rdev->constraints->input_uV;
1778 if (input_uV <= 0) { 1876 if (input_uV <= 0) {
1779 printk(KERN_ERR "%s: invalid input voltage found for %s\n", 1877 printk(KERN_ERR "%s: invalid input voltage found for %s\n",
1780 __func__, rdev->desc->name); 1878 __func__, rdev_get_name(rdev));
1781 goto out; 1879 goto out;
1782 } 1880 }
1783 1881
1784 /* calc total requested load for this regulator */ 1882 /* calc total requested load for this regulator */
1785 list_for_each_entry(consumer, &rdev->consumer_list, list) 1883 list_for_each_entry(consumer, &rdev->consumer_list, list)
1786 total_uA_load += consumer->uA_load; 1884 total_uA_load += consumer->uA_load;
1787 1885
1788 mode = rdev->desc->ops->get_optimum_mode(rdev, 1886 mode = rdev->desc->ops->get_optimum_mode(rdev,
1789 input_uV, output_uV, 1887 input_uV, output_uV,
@@ -1791,7 +1889,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1791 ret = regulator_check_mode(rdev, mode); 1889 ret = regulator_check_mode(rdev, mode);
1792 if (ret < 0) { 1890 if (ret < 0) {
1793 printk(KERN_ERR "%s: failed to get optimum mode for %s @" 1891 printk(KERN_ERR "%s: failed to get optimum mode for %s @"
1794 " %d uA %d -> %d uV\n", __func__, rdev->desc->name, 1892 " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev),
1795 total_uA_load, input_uV, output_uV); 1893 total_uA_load, input_uV, output_uV);
1796 goto out; 1894 goto out;
1797 } 1895 }
@@ -1799,7 +1897,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1799 ret = rdev->desc->ops->set_mode(rdev, mode); 1897 ret = rdev->desc->ops->set_mode(rdev, mode);
1800 if (ret < 0) { 1898 if (ret < 0) {
1801 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 1899 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
1802 __func__, mode, rdev->desc->name); 1900 __func__, mode, rdev_get_name(rdev));
1803 goto out; 1901 goto out;
1804 } 1902 }
1805 ret = mode; 1903 ret = mode;
@@ -1852,9 +1950,9 @@ static void _notifier_call_chain(struct regulator_dev *rdev,
1852 1950
1853 /* now notify regulator we supply */ 1951 /* now notify regulator we supply */
1854 list_for_each_entry(_rdev, &rdev->supply_list, slist) { 1952 list_for_each_entry(_rdev, &rdev->supply_list, slist) {
1855 mutex_lock(&_rdev->mutex); 1953 mutex_lock(&_rdev->mutex);
1856 _notifier_call_chain(_rdev, event, data); 1954 _notifier_call_chain(_rdev, event, data);
1857 mutex_unlock(&_rdev->mutex); 1955 mutex_unlock(&_rdev->mutex);
1858 } 1956 }
1859} 1957}
1860 1958
@@ -1885,9 +1983,9 @@ int regulator_bulk_get(struct device *dev, int num_consumers,
1885 consumers[i].consumer = regulator_get(dev, 1983 consumers[i].consumer = regulator_get(dev,
1886 consumers[i].supply); 1984 consumers[i].supply);
1887 if (IS_ERR(consumers[i].consumer)) { 1985 if (IS_ERR(consumers[i].consumer)) {
1888 dev_err(dev, "Failed to get supply '%s'\n",
1889 consumers[i].supply);
1890 ret = PTR_ERR(consumers[i].consumer); 1986 ret = PTR_ERR(consumers[i].consumer);
1987 dev_err(dev, "Failed to get supply '%s': %d\n",
1988 consumers[i].supply, ret);
1891 consumers[i].consumer = NULL; 1989 consumers[i].consumer = NULL;
1892 goto err; 1990 goto err;
1893 } 1991 }
@@ -1930,8 +2028,8 @@ int regulator_bulk_enable(int num_consumers,
1930 return 0; 2028 return 0;
1931 2029
1932err: 2030err:
1933 printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply); 2031 printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret);
1934 for (i = 0; i < num_consumers; i++) 2032 for (--i; i >= 0; --i)
1935 regulator_disable(consumers[i].consumer); 2033 regulator_disable(consumers[i].consumer);
1936 2034
1937 return ret; 2035 return ret;
@@ -1965,8 +2063,9 @@ int regulator_bulk_disable(int num_consumers,
1965 return 0; 2063 return 0;
1966 2064
1967err: 2065err:
1968 printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply); 2066 printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply,
1969 for (i = 0; i < num_consumers; i++) 2067 ret);
2068 for (--i; i >= 0; --i)
1970 regulator_enable(consumers[i].consumer); 2069 regulator_enable(consumers[i].consumer);
1971 2070
1972 return ret; 2071 return ret;
@@ -2316,7 +2415,7 @@ int regulator_suspend_prepare(suspend_state_t state)
2316 2415
2317 if (ret < 0) { 2416 if (ret < 0) {
2318 printk(KERN_ERR "%s: failed to prepare %s\n", 2417 printk(KERN_ERR "%s: failed to prepare %s\n",
2319 __func__, rdev->desc->name); 2418 __func__, rdev_get_name(rdev));
2320 goto out; 2419 goto out;
2321 } 2420 }
2322 } 2421 }
@@ -2404,8 +2503,15 @@ EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
2404 2503
2405static int __init regulator_init(void) 2504static int __init regulator_init(void)
2406{ 2505{
2506 int ret;
2507
2407 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); 2508 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
2408 return class_register(&regulator_class); 2509
2510 ret = class_register(&regulator_class);
2511
2512 regulator_dummy_init();
2513
2514 return ret;
2409} 2515}
2410 2516
2411/* init early to allow our consumers to complete system booting */ 2517/* init early to allow our consumers to complete system booting */
@@ -2429,12 +2535,7 @@ static int __init regulator_init_complete(void)
2429 ops = rdev->desc->ops; 2535 ops = rdev->desc->ops;
2430 c = rdev->constraints; 2536 c = rdev->constraints;
2431 2537
2432 if (c && c->name) 2538 name = rdev_get_name(rdev);
2433 name = c->name;
2434 else if (rdev->desc->name)
2435 name = rdev->desc->name;
2436 else
2437 name = "regulator";
2438 2539
2439 if (!ops->disable || (c && c->always_on)) 2540 if (!ops->disable || (c && c->always_on))
2440 continue; 2541 continue;
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index aa224d936e0d..f8c4661a7a81 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -331,7 +331,7 @@ static int da9034_get_ldo12_voltage(struct regulator_dev *rdev)
331static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, 331static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
332 unsigned selector) 332 unsigned selector)
333{ 333{
334 if (selector > ARRAY_SIZE(da9034_ldo12_data)) 334 if (selector >= ARRAY_SIZE(da9034_ldo12_data))
335 return -EINVAL; 335 return -EINVAL;
336 return da9034_ldo12_data[selector] * 1000; 336 return da9034_ldo12_data[selector] * 1000;
337} 337}
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c
new file mode 100644
index 000000000000..c7410bde7b5d
--- /dev/null
+++ b/drivers/regulator/dummy.c
@@ -0,0 +1,66 @@
1/*
2 * dummy.c
3 *
4 * Copyright 2010 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This is useful for systems with mixed controllable and
14 * non-controllable regulators, as well as for allowing testing on
15 * systems with no controllable regulators.
16 */
17
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22
23#include "dummy.h"
24
25struct regulator_dev *dummy_regulator_rdev;
26
27static struct regulator_init_data dummy_initdata;
28
29static struct regulator_ops dummy_ops;
30
31static struct regulator_desc dummy_desc = {
32 .name = "dummy",
33 .id = -1,
34 .type = REGULATOR_VOLTAGE,
35 .owner = THIS_MODULE,
36 .ops = &dummy_ops,
37};
38
39static struct platform_device *dummy_pdev;
40
41void __init regulator_dummy_init(void)
42{
43 int ret;
44
45 dummy_pdev = platform_device_alloc("reg-dummy", -1);
46 if (!dummy_pdev) {
47 pr_err("Failed to allocate dummy regulator device\n");
48 return;
49 }
50
51 ret = platform_device_add(dummy_pdev);
52 if (ret != 0) {
53 pr_err("Failed to register dummy regulator device: %d\n", ret);
54 platform_device_put(dummy_pdev);
55 return;
56 }
57
58 dummy_regulator_rdev = regulator_register(&dummy_desc, NULL,
59 &dummy_initdata, NULL);
60 if (IS_ERR(dummy_regulator_rdev)) {
61 ret = PTR_ERR(dummy_regulator_rdev);
62 pr_err("Failed to register regulator: %d\n", ret);
63 platform_device_unregister(dummy_pdev);
64 return;
65 }
66}
diff --git a/drivers/regulator/dummy.h b/drivers/regulator/dummy.h
new file mode 100644
index 000000000000..3921c0e24249
--- /dev/null
+++ b/drivers/regulator/dummy.h
@@ -0,0 +1,31 @@
1/*
2 * dummy.h
3 *
4 * Copyright 2010 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This is useful for systems with mixed controllable and
14 * non-controllable regulators, as well as for allowing testing on
15 * systems with no controllable regulators.
16 */
17
18#ifndef _DUMMY_H
19#define _DUMMY_H
20
21struct regulator_dev;
22
23extern struct regulator_dev *dummy_regulator_rdev;
24
25#ifdef CONFIG_REGULATOR_DUMMY
26void __init regulator_dummy_init(void);
27#else
28static inline void regulator_dummy_init(void) { }
29#endif
30
31#endif
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index f9f516a3028a..2fe9d99c9f23 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -24,14 +24,17 @@
24#include <linux/regulator/driver.h> 24#include <linux/regulator/driver.h>
25#include <linux/regulator/fixed.h> 25#include <linux/regulator/fixed.h>
26#include <linux/gpio.h> 26#include <linux/gpio.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
27 29
28struct fixed_voltage_data { 30struct fixed_voltage_data {
29 struct regulator_desc desc; 31 struct regulator_desc desc;
30 struct regulator_dev *dev; 32 struct regulator_dev *dev;
31 int microvolts; 33 int microvolts;
32 int gpio; 34 int gpio;
33 unsigned enable_high:1; 35 unsigned startup_delay;
34 unsigned is_enabled:1; 36 bool enable_high;
37 bool is_enabled;
35}; 38};
36 39
37static int fixed_voltage_is_enabled(struct regulator_dev *dev) 40static int fixed_voltage_is_enabled(struct regulator_dev *dev)
@@ -47,7 +50,7 @@ static int fixed_voltage_enable(struct regulator_dev *dev)
47 50
48 if (gpio_is_valid(data->gpio)) { 51 if (gpio_is_valid(data->gpio)) {
49 gpio_set_value_cansleep(data->gpio, data->enable_high); 52 gpio_set_value_cansleep(data->gpio, data->enable_high);
50 data->is_enabled = 1; 53 data->is_enabled = true;
51 } 54 }
52 55
53 return 0; 56 return 0;
@@ -59,12 +62,19 @@ static int fixed_voltage_disable(struct regulator_dev *dev)
59 62
60 if (gpio_is_valid(data->gpio)) { 63 if (gpio_is_valid(data->gpio)) {
61 gpio_set_value_cansleep(data->gpio, !data->enable_high); 64 gpio_set_value_cansleep(data->gpio, !data->enable_high);
62 data->is_enabled = 0; 65 data->is_enabled = false;
63 } 66 }
64 67
65 return 0; 68 return 0;
66} 69}
67 70
71static int fixed_voltage_enable_time(struct regulator_dev *dev)
72{
73 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
74
75 return data->startup_delay;
76}
77
68static int fixed_voltage_get_voltage(struct regulator_dev *dev) 78static int fixed_voltage_get_voltage(struct regulator_dev *dev)
69{ 79{
70 struct fixed_voltage_data *data = rdev_get_drvdata(dev); 80 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
@@ -87,11 +97,12 @@ static struct regulator_ops fixed_voltage_ops = {
87 .is_enabled = fixed_voltage_is_enabled, 97 .is_enabled = fixed_voltage_is_enabled,
88 .enable = fixed_voltage_enable, 98 .enable = fixed_voltage_enable,
89 .disable = fixed_voltage_disable, 99 .disable = fixed_voltage_disable,
100 .enable_time = fixed_voltage_enable_time,
90 .get_voltage = fixed_voltage_get_voltage, 101 .get_voltage = fixed_voltage_get_voltage,
91 .list_voltage = fixed_voltage_list_voltage, 102 .list_voltage = fixed_voltage_list_voltage,
92}; 103};
93 104
94static int regulator_fixed_voltage_probe(struct platform_device *pdev) 105static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
95{ 106{
96 struct fixed_voltage_config *config = pdev->dev.platform_data; 107 struct fixed_voltage_config *config = pdev->dev.platform_data;
97 struct fixed_voltage_data *drvdata; 108 struct fixed_voltage_data *drvdata;
@@ -117,6 +128,7 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev)
117 128
118 drvdata->microvolts = config->microvolts; 129 drvdata->microvolts = config->microvolts;
119 drvdata->gpio = config->gpio; 130 drvdata->gpio = config->gpio;
131 drvdata->startup_delay = config->startup_delay;
120 132
121 if (gpio_is_valid(config->gpio)) { 133 if (gpio_is_valid(config->gpio)) {
122 drvdata->enable_high = config->enable_high; 134 drvdata->enable_high = config->enable_high;
@@ -163,7 +175,7 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev)
163 /* Regulator without GPIO control is considered 175 /* Regulator without GPIO control is considered
164 * always enabled 176 * always enabled
165 */ 177 */
166 drvdata->is_enabled = 1; 178 drvdata->is_enabled = true;
167 } 179 }
168 180
169 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, 181 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
@@ -191,7 +203,7 @@ err:
191 return ret; 203 return ret;
192} 204}
193 205
194static int regulator_fixed_voltage_remove(struct platform_device *pdev) 206static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
195{ 207{
196 struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); 208 struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
197 209
@@ -205,10 +217,11 @@ static int regulator_fixed_voltage_remove(struct platform_device *pdev)
205} 217}
206 218
207static struct platform_driver regulator_fixed_voltage_driver = { 219static struct platform_driver regulator_fixed_voltage_driver = {
208 .probe = regulator_fixed_voltage_probe, 220 .probe = reg_fixed_voltage_probe,
209 .remove = regulator_fixed_voltage_remove, 221 .remove = __devexit_p(reg_fixed_voltage_remove),
210 .driver = { 222 .driver = {
211 .name = "reg-fixed-voltage", 223 .name = "reg-fixed-voltage",
224 .owner = THIS_MODULE,
212 }, 225 },
213}; 226};
214 227
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 7803a320543b..671a7d1f1f0e 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -18,6 +18,7 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
20#include <linux/regulator/lp3971.h> 20#include <linux/regulator/lp3971.h>
21#include <linux/slab.h>
21 22
22struct lp3971 { 23struct lp3971 {
23 struct device *dev; 24 struct device *dev;
@@ -45,7 +46,7 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val);
45 LP3971_BUCK2 -> 4 46 LP3971_BUCK2 -> 4
46 LP3971_BUCK3 -> 6 47 LP3971_BUCK3 -> 6
47*/ 48*/
48#define BUCK_VOL_CHANGE_SHIFT(x) (((1 << x) & ~0x01) << 1) 49#define BUCK_VOL_CHANGE_SHIFT(x) (((!!x) << 2) | (x & ~0x01))
49#define BUCK_VOL_CHANGE_FLAG_GO 0x01 50#define BUCK_VOL_CHANGE_FLAG_GO 0x01
50#define BUCK_VOL_CHANGE_FLAG_TARGET 0x02 51#define BUCK_VOL_CHANGE_FLAG_TARGET 0x02
51#define BUCK_VOL_CHANGE_FLAG_MASK 0x03 52#define BUCK_VOL_CHANGE_FLAG_MASK 0x03
@@ -54,7 +55,7 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val);
54#define LP3971_BUCK2_BASE 0x29 55#define LP3971_BUCK2_BASE 0x29
55#define LP3971_BUCK3_BASE 0x32 56#define LP3971_BUCK3_BASE 0x32
56 57
57const static int buck_base_addr[] = { 58static const int buck_base_addr[] = {
58 LP3971_BUCK1_BASE, 59 LP3971_BUCK1_BASE,
59 LP3971_BUCK2_BASE, 60 LP3971_BUCK2_BASE,
60 LP3971_BUCK3_BASE, 61 LP3971_BUCK3_BASE,
@@ -63,7 +64,7 @@ const static int buck_base_addr[] = {
63#define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x]) 64#define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x])
64#define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1) 65#define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1)
65 66
66const static int buck_voltage_map[] = { 67static const int buck_voltage_map[] = {
67 0, 800, 850, 900, 950, 1000, 1050, 1100, 68 0, 800, 850, 900, 950, 1000, 1050, 1100,
68 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 69 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500,
69 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, 70 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800,
@@ -96,17 +97,17 @@ const static int buck_voltage_map[] = {
96#define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2) 97#define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2)
97#define LDO_VOL_CONTR_MASK 0x0f 98#define LDO_VOL_CONTR_MASK 0x0f
98 99
99const static int ldo45_voltage_map[] = { 100static const int ldo45_voltage_map[] = {
100 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 101 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350,
101 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, 102 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300,
102}; 103};
103 104
104const static int ldo123_voltage_map[] = { 105static const int ldo123_voltage_map[] = {
105 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 106 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500,
106 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 107 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300,
107}; 108};
108 109
109const static int *ldo_voltage_map[] = { 110static const int *ldo_voltage_map[] = {
110 ldo123_voltage_map, /* LDO1 */ 111 ldo123_voltage_map, /* LDO1 */
111 ldo123_voltage_map, /* LDO2 */ 112 ldo123_voltage_map, /* LDO2 */
112 ldo123_voltage_map, /* LDO3 */ 113 ldo123_voltage_map, /* LDO3 */
@@ -183,11 +184,12 @@ static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
183 if (vol_map[val] >= min_vol) 184 if (vol_map[val] >= min_vol)
184 break; 185 break;
185 186
186 if (vol_map[val] > max_vol) 187 if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol)
187 return -EINVAL; 188 return -EINVAL;
188 189
189 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), 190 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo),
190 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), val); 191 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo),
192 val << LDO_VOL_CONTR_SHIFT(ldo));
191} 193}
192 194
193static struct regulator_ops lp3971_ldo_ops = { 195static struct regulator_ops lp3971_ldo_ops = {
@@ -272,7 +274,7 @@ static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
272 if (vol_map[val] >= min_vol) 274 if (vol_map[val] >= min_vol)
273 break; 275 break;
274 276
275 if (vol_map[val] > max_vol) 277 if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol)
276 return -EINVAL; 278 return -EINVAL;
277 279
278 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), 280 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck),
@@ -431,23 +433,27 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val)
431 return ret; 433 return ret;
432} 434}
433 435
434static int setup_regulators(struct lp3971 *lp3971, 436static int __devinit setup_regulators(struct lp3971 *lp3971,
435 struct lp3971_platform_data *pdata) 437 struct lp3971_platform_data *pdata)
436{ 438{
437 int i, err; 439 int i, err;
438 int num_regulators = pdata->num_regulators; 440
439 lp3971->num_regulators = num_regulators; 441 lp3971->num_regulators = pdata->num_regulators;
440 lp3971->rdev = kzalloc(sizeof(struct regulator_dev *) * num_regulators, 442 lp3971->rdev = kcalloc(pdata->num_regulators,
441 GFP_KERNEL); 443 sizeof(struct regulator_dev *), GFP_KERNEL);
444 if (!lp3971->rdev) {
445 err = -ENOMEM;
446 goto err_nomem;
447 }
442 448
443 /* Instantiate the regulators */ 449 /* Instantiate the regulators */
444 for (i = 0; i < num_regulators; i++) { 450 for (i = 0; i < pdata->num_regulators; i++) {
445 int id = pdata->regulators[i].id; 451 struct lp3971_regulator_subdev *reg = &pdata->regulators[i];
446 lp3971->rdev[i] = regulator_register(&regulators[id], 452 lp3971->rdev[i] = regulator_register(&regulators[reg->id],
447 lp3971->dev, pdata->regulators[i].initdata, lp3971); 453 lp3971->dev, reg->initdata, lp3971);
448 454
449 err = IS_ERR(lp3971->rdev[i]); 455 if (IS_ERR(lp3971->rdev[i])) {
450 if (err) { 456 err = PTR_ERR(lp3971->rdev[i]);
451 dev_err(lp3971->dev, "regulator init failed: %d\n", 457 dev_err(lp3971->dev, "regulator init failed: %d\n",
452 err); 458 err);
453 goto error; 459 goto error;
@@ -455,12 +461,13 @@ static int setup_regulators(struct lp3971 *lp3971,
455 } 461 }
456 462
457 return 0; 463 return 0;
464
458error: 465error:
459 for (i = 0; i < num_regulators; i++) 466 while (--i >= 0)
460 if (lp3971->rdev[i]) 467 regulator_unregister(lp3971->rdev[i]);
461 regulator_unregister(lp3971->rdev[i]);
462 kfree(lp3971->rdev); 468 kfree(lp3971->rdev);
463 lp3971->rdev = NULL; 469 lp3971->rdev = NULL;
470err_nomem:
464 return err; 471 return err;
465} 472}
466 473
@@ -472,15 +479,17 @@ static int __devinit lp3971_i2c_probe(struct i2c_client *i2c,
472 int ret; 479 int ret;
473 u16 val; 480 u16 val;
474 481
475 lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL); 482 if (!pdata) {
476 if (lp3971 == NULL) { 483 dev_dbg(&i2c->dev, "No platform init data supplied\n");
477 ret = -ENOMEM; 484 return -ENODEV;
478 goto err;
479 } 485 }
480 486
487 lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL);
488 if (lp3971 == NULL)
489 return -ENOMEM;
490
481 lp3971->i2c = i2c; 491 lp3971->i2c = i2c;
482 lp3971->dev = &i2c->dev; 492 lp3971->dev = &i2c->dev;
483 i2c_set_clientdata(i2c, lp3971);
484 493
485 mutex_init(&lp3971->io_lock); 494 mutex_init(&lp3971->io_lock);
486 495
@@ -493,19 +502,15 @@ static int __devinit lp3971_i2c_probe(struct i2c_client *i2c,
493 goto err_detect; 502 goto err_detect;
494 } 503 }
495 504
496 if (pdata) { 505 ret = setup_regulators(lp3971, pdata);
497 ret = setup_regulators(lp3971, pdata); 506 if (ret < 0)
498 if (ret < 0) 507 goto err_detect;
499 goto err_detect;
500 } else
501 dev_warn(lp3971->dev, "No platform init data supplied\n");
502 508
509 i2c_set_clientdata(i2c, lp3971);
503 return 0; 510 return 0;
504 511
505err_detect: 512err_detect:
506 i2c_set_clientdata(i2c, NULL);
507 kfree(lp3971); 513 kfree(lp3971);
508err:
509 return ret; 514 return ret;
510} 515}
511 516
@@ -513,11 +518,13 @@ static int __devexit lp3971_i2c_remove(struct i2c_client *i2c)
513{ 518{
514 struct lp3971 *lp3971 = i2c_get_clientdata(i2c); 519 struct lp3971 *lp3971 = i2c_get_clientdata(i2c);
515 int i; 520 int i;
521
522 i2c_set_clientdata(i2c, NULL);
523
516 for (i = 0; i < lp3971->num_regulators; i++) 524 for (i = 0; i < lp3971->num_regulators; i++)
517 if (lp3971->rdev[i]) 525 regulator_unregister(lp3971->rdev[i]);
518 regulator_unregister(lp3971->rdev[i]); 526
519 kfree(lp3971->rdev); 527 kfree(lp3971->rdev);
520 i2c_set_clientdata(i2c, NULL);
521 kfree(lp3971); 528 kfree(lp3971);
522 529
523 return 0; 530 return 0;
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 2c082d3ef484..b3c1afc16889 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -22,6 +22,7 @@
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/regulator/driver.h> 24#include <linux/regulator/driver.h>
25#include <linux/slab.h>
25#include <linux/regulator/max1586.h> 26#include <linux/regulator/max1586.h>
26 27
27#define MAX1586_V3_MAX_VSEL 31 28#define MAX1586_V3_MAX_VSEL 31
@@ -179,8 +180,8 @@ static struct regulator_desc max1586_reg[] = {
179 }, 180 },
180}; 181};
181 182
182static int max1586_pmic_probe(struct i2c_client *client, 183static int __devinit max1586_pmic_probe(struct i2c_client *client,
183 const struct i2c_device_id *i2c_id) 184 const struct i2c_device_id *i2c_id)
184{ 185{
185 struct regulator_dev **rdev; 186 struct regulator_dev **rdev;
186 struct max1586_platform_data *pdata = client->dev.platform_data; 187 struct max1586_platform_data *pdata = client->dev.platform_data;
@@ -235,7 +236,7 @@ out:
235 return ret; 236 return ret;
236} 237}
237 238
238static int max1586_pmic_remove(struct i2c_client *client) 239static int __devexit max1586_pmic_remove(struct i2c_client *client)
239{ 240{
240 struct regulator_dev **rdev = i2c_get_clientdata(client); 241 struct regulator_dev **rdev = i2c_get_clientdata(client);
241 int i; 242 int i;
@@ -243,8 +244,8 @@ static int max1586_pmic_remove(struct i2c_client *client)
243 for (i = 0; i <= MAX1586_V6; i++) 244 for (i = 0; i <= MAX1586_V6; i++)
244 if (rdev[i]) 245 if (rdev[i])
245 regulator_unregister(rdev[i]); 246 regulator_unregister(rdev[i]);
246 kfree(rdev);
247 i2c_set_clientdata(client, NULL); 247 i2c_set_clientdata(client, NULL);
248 kfree(rdev);
248 249
249 return 0; 250 return 0;
250} 251}
@@ -257,9 +258,10 @@ MODULE_DEVICE_TABLE(i2c, max1586_id);
257 258
258static struct i2c_driver max1586_pmic_driver = { 259static struct i2c_driver max1586_pmic_driver = {
259 .probe = max1586_pmic_probe, 260 .probe = max1586_pmic_probe,
260 .remove = max1586_pmic_remove, 261 .remove = __devexit_p(max1586_pmic_remove),
261 .driver = { 262 .driver = {
262 .name = "max1586", 263 .name = "max1586",
264 .owner = THIS_MODULE,
263 }, 265 },
264 .id_table = max1586_id, 266 .id_table = max1586_id,
265}; 267};
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
new file mode 100644
index 000000000000..bfc4c5ffdc96
--- /dev/null
+++ b/drivers/regulator/max8649.c
@@ -0,0 +1,410 @@
1/*
2 * Regulators driver for Maxim max8649
3 *
4 * Copyright (C) 2009-2010 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/slab.h>
18#include <linux/regulator/max8649.h>
19
20#define MAX8649_DCDC_VMIN 750000 /* uV */
21#define MAX8649_DCDC_VMAX 1380000 /* uV */
22#define MAX8649_DCDC_STEP 10000 /* uV */
23#define MAX8649_VOL_MASK 0x3f
24
25/* Registers */
26#define MAX8649_MODE0 0x00
27#define MAX8649_MODE1 0x01
28#define MAX8649_MODE2 0x02
29#define MAX8649_MODE3 0x03
30#define MAX8649_CONTROL 0x04
31#define MAX8649_SYNC 0x05
32#define MAX8649_RAMP 0x06
33#define MAX8649_CHIP_ID1 0x08
34#define MAX8649_CHIP_ID2 0x09
35
36/* Bits */
37#define MAX8649_EN_PD (1 << 7)
38#define MAX8649_VID0_PD (1 << 6)
39#define MAX8649_VID1_PD (1 << 5)
40#define MAX8649_VID_MASK (3 << 5)
41
42#define MAX8649_FORCE_PWM (1 << 7)
43#define MAX8649_SYNC_EXTCLK (1 << 6)
44
45#define MAX8649_EXT_MASK (3 << 6)
46
47#define MAX8649_RAMP_MASK (7 << 5)
48#define MAX8649_RAMP_DOWN (1 << 1)
49
50struct max8649_regulator_info {
51 struct regulator_dev *regulator;
52 struct i2c_client *i2c;
53 struct device *dev;
54 struct mutex io_lock;
55
56 int vol_reg;
57 unsigned mode:2; /* bit[1:0] = VID1, VID0 */
58 unsigned extclk_freq:2;
59 unsigned extclk:1;
60 unsigned ramp_timing:3;
61 unsigned ramp_down:1;
62};
63
64/* I2C operations */
65
66static inline int max8649_read_device(struct i2c_client *i2c,
67 int reg, int bytes, void *dest)
68{
69 unsigned char data;
70 int ret;
71
72 data = (unsigned char)reg;
73 ret = i2c_master_send(i2c, &data, 1);
74 if (ret < 0)
75 return ret;
76 ret = i2c_master_recv(i2c, dest, bytes);
77 if (ret < 0)
78 return ret;
79 return 0;
80}
81
82static inline int max8649_write_device(struct i2c_client *i2c,
83 int reg, int bytes, void *src)
84{
85 unsigned char buf[bytes + 1];
86 int ret;
87
88 buf[0] = (unsigned char)reg;
89 memcpy(&buf[1], src, bytes);
90
91 ret = i2c_master_send(i2c, buf, bytes + 1);
92 if (ret < 0)
93 return ret;
94 return 0;
95}
96
97static int max8649_reg_read(struct i2c_client *i2c, int reg)
98{
99 struct max8649_regulator_info *info = i2c_get_clientdata(i2c);
100 unsigned char data;
101 int ret;
102
103 mutex_lock(&info->io_lock);
104 ret = max8649_read_device(i2c, reg, 1, &data);
105 mutex_unlock(&info->io_lock);
106
107 if (ret < 0)
108 return ret;
109 return (int)data;
110}
111
112static int max8649_set_bits(struct i2c_client *i2c, int reg,
113 unsigned char mask, unsigned char data)
114{
115 struct max8649_regulator_info *info = i2c_get_clientdata(i2c);
116 unsigned char value;
117 int ret;
118
119 mutex_lock(&info->io_lock);
120 ret = max8649_read_device(i2c, reg, 1, &value);
121 if (ret < 0)
122 goto out;
123 value &= ~mask;
124 value |= data;
125 ret = max8649_write_device(i2c, reg, 1, &value);
126out:
127 mutex_unlock(&info->io_lock);
128 return ret;
129}
130
131static inline int check_range(int min_uV, int max_uV)
132{
133 if ((min_uV < MAX8649_DCDC_VMIN) || (max_uV > MAX8649_DCDC_VMAX)
134 || (min_uV > max_uV))
135 return -EINVAL;
136 return 0;
137}
138
139static int max8649_list_voltage(struct regulator_dev *rdev, unsigned index)
140{
141 return (MAX8649_DCDC_VMIN + index * MAX8649_DCDC_STEP);
142}
143
144static int max8649_get_voltage(struct regulator_dev *rdev)
145{
146 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
147 unsigned char data;
148 int ret;
149
150 ret = max8649_reg_read(info->i2c, info->vol_reg);
151 if (ret < 0)
152 return ret;
153 data = (unsigned char)ret & MAX8649_VOL_MASK;
154 return max8649_list_voltage(rdev, data);
155}
156
157static int max8649_set_voltage(struct regulator_dev *rdev,
158 int min_uV, int max_uV)
159{
160 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
161 unsigned char data, mask;
162
163 if (check_range(min_uV, max_uV)) {
164 dev_err(info->dev, "invalid voltage range (%d, %d) uV\n",
165 min_uV, max_uV);
166 return -EINVAL;
167 }
168 data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1)
169 / MAX8649_DCDC_STEP;
170 mask = MAX8649_VOL_MASK;
171
172 return max8649_set_bits(info->i2c, info->vol_reg, mask, data);
173}
174
175/* EN_PD means pulldown on EN input */
176static int max8649_enable(struct regulator_dev *rdev)
177{
178 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
179 return max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_EN_PD, 0);
180}
181
182/*
183 * Applied internal pulldown resistor on EN input pin.
184 * If pulldown EN pin outside, it would be better.
185 */
186static int max8649_disable(struct regulator_dev *rdev)
187{
188 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
189 return max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_EN_PD,
190 MAX8649_EN_PD);
191}
192
193static int max8649_is_enabled(struct regulator_dev *rdev)
194{
195 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
196 int ret;
197
198 ret = max8649_reg_read(info->i2c, MAX8649_CONTROL);
199 if (ret < 0)
200 return ret;
201 return !((unsigned char)ret & MAX8649_EN_PD);
202}
203
204static int max8649_enable_time(struct regulator_dev *rdev)
205{
206 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
207 int voltage, rate, ret;
208
209 /* get voltage */
210 ret = max8649_reg_read(info->i2c, info->vol_reg);
211 if (ret < 0)
212 return ret;
213 ret &= MAX8649_VOL_MASK;
214 voltage = max8649_list_voltage(rdev, (unsigned char)ret); /* uV */
215
216 /* get rate */
217 ret = max8649_reg_read(info->i2c, MAX8649_RAMP);
218 if (ret < 0)
219 return ret;
220 ret = (ret & MAX8649_RAMP_MASK) >> 5;
221 rate = (32 * 1000) >> ret; /* uV/uS */
222
223 return (voltage / rate);
224}
225
226static int max8649_set_mode(struct regulator_dev *rdev, unsigned int mode)
227{
228 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
229
230 switch (mode) {
231 case REGULATOR_MODE_FAST:
232 max8649_set_bits(info->i2c, info->vol_reg, MAX8649_FORCE_PWM,
233 MAX8649_FORCE_PWM);
234 break;
235 case REGULATOR_MODE_NORMAL:
236 max8649_set_bits(info->i2c, info->vol_reg,
237 MAX8649_FORCE_PWM, 0);
238 break;
239 default:
240 return -EINVAL;
241 }
242 return 0;
243}
244
245static unsigned int max8649_get_mode(struct regulator_dev *rdev)
246{
247 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
248 int ret;
249
250 ret = max8649_reg_read(info->i2c, info->vol_reg);
251 if (ret & MAX8649_FORCE_PWM)
252 return REGULATOR_MODE_FAST;
253 return REGULATOR_MODE_NORMAL;
254}
255
256static struct regulator_ops max8649_dcdc_ops = {
257 .set_voltage = max8649_set_voltage,
258 .get_voltage = max8649_get_voltage,
259 .list_voltage = max8649_list_voltage,
260 .enable = max8649_enable,
261 .disable = max8649_disable,
262 .is_enabled = max8649_is_enabled,
263 .enable_time = max8649_enable_time,
264 .set_mode = max8649_set_mode,
265 .get_mode = max8649_get_mode,
266
267};
268
269static struct regulator_desc dcdc_desc = {
270 .name = "max8649",
271 .ops = &max8649_dcdc_ops,
272 .type = REGULATOR_VOLTAGE,
273 .n_voltages = 1 << 6,
274 .owner = THIS_MODULE,
275};
276
277static int __devinit max8649_regulator_probe(struct i2c_client *client,
278 const struct i2c_device_id *id)
279{
280 struct max8649_platform_data *pdata = client->dev.platform_data;
281 struct max8649_regulator_info *info = NULL;
282 unsigned char data;
283 int ret;
284
285 info = kzalloc(sizeof(struct max8649_regulator_info), GFP_KERNEL);
286 if (!info) {
287 dev_err(&client->dev, "No enough memory\n");
288 return -ENOMEM;
289 }
290
291 info->i2c = client;
292 info->dev = &client->dev;
293 mutex_init(&info->io_lock);
294 i2c_set_clientdata(client, info);
295
296 info->mode = pdata->mode;
297 switch (info->mode) {
298 case 0:
299 info->vol_reg = MAX8649_MODE0;
300 break;
301 case 1:
302 info->vol_reg = MAX8649_MODE1;
303 break;
304 case 2:
305 info->vol_reg = MAX8649_MODE2;
306 break;
307 case 3:
308 info->vol_reg = MAX8649_MODE3;
309 break;
310 default:
311 break;
312 }
313
314 ret = max8649_reg_read(info->i2c, MAX8649_CHIP_ID1);
315 if (ret < 0) {
316 dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n",
317 ret);
318 goto out;
319 }
320 dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", ret);
321
322 /* enable VID0 & VID1 */
323 max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_VID_MASK, 0);
324
325 /* enable/disable external clock synchronization */
326 info->extclk = pdata->extclk;
327 data = (info->extclk) ? MAX8649_SYNC_EXTCLK : 0;
328 max8649_set_bits(info->i2c, info->vol_reg, MAX8649_SYNC_EXTCLK, data);
329 if (info->extclk) {
330 /* set external clock frequency */
331 info->extclk_freq = pdata->extclk_freq;
332 max8649_set_bits(info->i2c, MAX8649_SYNC, MAX8649_EXT_MASK,
333 info->extclk_freq);
334 }
335
336 if (pdata->ramp_timing) {
337 info->ramp_timing = pdata->ramp_timing;
338 max8649_set_bits(info->i2c, MAX8649_RAMP, MAX8649_RAMP_MASK,
339 info->ramp_timing << 5);
340 }
341
342 info->ramp_down = pdata->ramp_down;
343 if (info->ramp_down) {
344 max8649_set_bits(info->i2c, MAX8649_RAMP, MAX8649_RAMP_DOWN,
345 MAX8649_RAMP_DOWN);
346 }
347
348 info->regulator = regulator_register(&dcdc_desc, &client->dev,
349 pdata->regulator, info);
350 if (IS_ERR(info->regulator)) {
351 dev_err(info->dev, "failed to register regulator %s\n",
352 dcdc_desc.name);
353 ret = PTR_ERR(info->regulator);
354 goto out;
355 }
356
357 dev_info(info->dev, "Max8649 regulator device is detected.\n");
358 return 0;
359out:
360 i2c_set_clientdata(client, NULL);
361 kfree(info);
362 return ret;
363}
364
365static int __devexit max8649_regulator_remove(struct i2c_client *client)
366{
367 struct max8649_regulator_info *info = i2c_get_clientdata(client);
368
369 if (info) {
370 if (info->regulator)
371 regulator_unregister(info->regulator);
372 i2c_set_clientdata(client, NULL);
373 kfree(info);
374 }
375
376 return 0;
377}
378
379static const struct i2c_device_id max8649_id[] = {
380 { "max8649", 0 },
381 { }
382};
383MODULE_DEVICE_TABLE(i2c, max8649_id);
384
385static struct i2c_driver max8649_driver = {
386 .probe = max8649_regulator_probe,
387 .remove = __devexit_p(max8649_regulator_remove),
388 .driver = {
389 .name = "max8649",
390 },
391 .id_table = max8649_id,
392};
393
394static int __init max8649_init(void)
395{
396 return i2c_add_driver(&max8649_driver);
397}
398subsys_initcall(max8649_init);
399
400static void __exit max8649_exit(void)
401{
402 i2c_del_driver(&max8649_driver);
403}
404module_exit(max8649_exit);
405
406/* Module information */
407MODULE_DESCRIPTION("MAXIM 8649 voltage regulator driver");
408MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
409MODULE_LICENSE("GPL");
410
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
new file mode 100644
index 000000000000..3790b21879ff
--- /dev/null
+++ b/drivers/regulator/max8660.c
@@ -0,0 +1,512 @@
1/*
2 * max8660.c -- Voltage regulation for the Maxim 8660/8661
3 *
4 * based on max1586.c and wm8400-regulator.c
5 *
6 * Copyright (C) 2009 Wolfram Sang, Pengutronix e.K.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Some info:
22 *
23 * Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX8660-MAX8661.pdf
24 *
25 * This chip is a bit nasty because it is a write-only device. Thus, the driver
26 * uses shadow registers to keep track of its values. The main problem appears
27 * to be the initialization: When Linux boots up, we cannot know if the chip is
28 * in the default state or not, so we would have to pass such information in
29 * platform_data. As this adds a bit of complexity to the driver, this is left
30 * out for now until it is really needed.
31 *
32 * [A|S|M]DTV1 registers are currently not used, but [A|S|M]DTV2.
33 *
34 * If the driver is feature complete, it might be worth to check if one set of
35 * functions for V3-V7 is sufficient. For maximum flexibility during
36 * development, they are separated for now.
37 *
38 */
39
40#include <linux/module.h>
41#include <linux/err.h>
42#include <linux/i2c.h>
43#include <linux/platform_device.h>
44#include <linux/regulator/driver.h>
45#include <linux/slab.h>
46#include <linux/regulator/max8660.h>
47
48#define MAX8660_DCDC_MIN_UV 725000
49#define MAX8660_DCDC_MAX_UV 1800000
50#define MAX8660_DCDC_STEP 25000
51#define MAX8660_DCDC_MAX_SEL 0x2b
52
53#define MAX8660_LDO5_MIN_UV 1700000
54#define MAX8660_LDO5_MAX_UV 2000000
55#define MAX8660_LDO5_STEP 25000
56#define MAX8660_LDO5_MAX_SEL 0x0c
57
58#define MAX8660_LDO67_MIN_UV 1800000
59#define MAX8660_LDO67_MAX_UV 3300000
60#define MAX8660_LDO67_STEP 100000
61#define MAX8660_LDO67_MAX_SEL 0x0f
62
63enum {
64 MAX8660_OVER1,
65 MAX8660_OVER2,
66 MAX8660_VCC1,
67 MAX8660_ADTV1,
68 MAX8660_ADTV2,
69 MAX8660_SDTV1,
70 MAX8660_SDTV2,
71 MAX8660_MDTV1,
72 MAX8660_MDTV2,
73 MAX8660_L12VCR,
74 MAX8660_FPWM,
75 MAX8660_N_REGS, /* not a real register */
76};
77
78struct max8660 {
79 struct i2c_client *client;
80 u8 shadow_regs[MAX8660_N_REGS]; /* as chip is write only */
81 struct regulator_dev *rdev[];
82};
83
84static int max8660_write(struct max8660 *max8660, u8 reg, u8 mask, u8 val)
85{
86 static const u8 max8660_addresses[MAX8660_N_REGS] =
87 { 0x10, 0x12, 0x20, 0x23, 0x24, 0x29, 0x2a, 0x32, 0x33, 0x39, 0x80 };
88
89 int ret;
90 u8 reg_val = (max8660->shadow_regs[reg] & mask) | val;
91 dev_vdbg(&max8660->client->dev, "Writing reg %02x with %02x\n",
92 max8660_addresses[reg], reg_val);
93
94 ret = i2c_smbus_write_byte_data(max8660->client,
95 max8660_addresses[reg], reg_val);
96 if (ret == 0)
97 max8660->shadow_regs[reg] = reg_val;
98
99 return ret;
100}
101
102
103/*
104 * DCDC functions
105 */
106
107static int max8660_dcdc_is_enabled(struct regulator_dev *rdev)
108{
109 struct max8660 *max8660 = rdev_get_drvdata(rdev);
110 u8 val = max8660->shadow_regs[MAX8660_OVER1];
111 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4;
112 return !!(val & mask);
113}
114
115static int max8660_dcdc_enable(struct regulator_dev *rdev)
116{
117 struct max8660 *max8660 = rdev_get_drvdata(rdev);
118 u8 bit = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4;
119 return max8660_write(max8660, MAX8660_OVER1, 0xff, bit);
120}
121
122static int max8660_dcdc_disable(struct regulator_dev *rdev)
123{
124 struct max8660 *max8660 = rdev_get_drvdata(rdev);
125 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? ~1 : ~4;
126 return max8660_write(max8660, MAX8660_OVER1, mask, 0);
127}
128
129static int max8660_dcdc_list(struct regulator_dev *rdev, unsigned selector)
130{
131 if (selector > MAX8660_DCDC_MAX_SEL)
132 return -EINVAL;
133 return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP;
134}
135
136static int max8660_dcdc_get(struct regulator_dev *rdev)
137{
138 struct max8660 *max8660 = rdev_get_drvdata(rdev);
139 u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
140 u8 selector = max8660->shadow_regs[reg];
141 return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP;
142}
143
144static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV)
145{
146 struct max8660 *max8660 = rdev_get_drvdata(rdev);
147 u8 reg, selector, bits;
148 int ret;
149
150 if (min_uV < MAX8660_DCDC_MIN_UV || min_uV > MAX8660_DCDC_MAX_UV)
151 return -EINVAL;
152 if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV)
153 return -EINVAL;
154
155 selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1))
156 / MAX8660_DCDC_STEP;
157
158 ret = max8660_dcdc_list(rdev, selector);
159 if (ret < 0 || ret > max_uV)
160 return -EINVAL;
161
162 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
163 ret = max8660_write(max8660, reg, 0, selector);
164 if (ret)
165 return ret;
166
167 /* Select target voltage register and activate regulation */
168 bits = (rdev_get_id(rdev) == MAX8660_V3) ? 0x03 : 0x30;
169 return max8660_write(max8660, MAX8660_VCC1, 0xff, bits);
170}
171
172static struct regulator_ops max8660_dcdc_ops = {
173 .is_enabled = max8660_dcdc_is_enabled,
174 .list_voltage = max8660_dcdc_list,
175 .set_voltage = max8660_dcdc_set,
176 .get_voltage = max8660_dcdc_get,
177};
178
179
180/*
181 * LDO5 functions
182 */
183
184static int max8660_ldo5_list(struct regulator_dev *rdev, unsigned selector)
185{
186 if (selector > MAX8660_LDO5_MAX_SEL)
187 return -EINVAL;
188 return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP;
189}
190
191static int max8660_ldo5_get(struct regulator_dev *rdev)
192{
193 struct max8660 *max8660 = rdev_get_drvdata(rdev);
194 u8 selector = max8660->shadow_regs[MAX8660_MDTV2];
195
196 return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP;
197}
198
199static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV)
200{
201 struct max8660 *max8660 = rdev_get_drvdata(rdev);
202 u8 selector;
203 int ret;
204
205 if (min_uV < MAX8660_LDO5_MIN_UV || min_uV > MAX8660_LDO5_MAX_UV)
206 return -EINVAL;
207 if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV)
208 return -EINVAL;
209
210 selector = (min_uV - (MAX8660_LDO5_MIN_UV - MAX8660_LDO5_STEP + 1))
211 / MAX8660_LDO5_STEP;
212 ret = max8660_ldo5_list(rdev, selector);
213 if (ret < 0 || ret > max_uV)
214 return -EINVAL;
215
216 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector);
217 if (ret)
218 return ret;
219
220 /* Select target voltage register and activate regulation */
221 return max8660_write(max8660, MAX8660_VCC1, 0xff, 0xc0);
222}
223
224static struct regulator_ops max8660_ldo5_ops = {
225 .list_voltage = max8660_ldo5_list,
226 .set_voltage = max8660_ldo5_set,
227 .get_voltage = max8660_ldo5_get,
228};
229
230
231/*
232 * LDO67 functions
233 */
234
235static int max8660_ldo67_is_enabled(struct regulator_dev *rdev)
236{
237 struct max8660 *max8660 = rdev_get_drvdata(rdev);
238 u8 val = max8660->shadow_regs[MAX8660_OVER2];
239 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4;
240 return !!(val & mask);
241}
242
243static int max8660_ldo67_enable(struct regulator_dev *rdev)
244{
245 struct max8660 *max8660 = rdev_get_drvdata(rdev);
246 u8 bit = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4;
247 return max8660_write(max8660, MAX8660_OVER2, 0xff, bit);
248}
249
250static int max8660_ldo67_disable(struct regulator_dev *rdev)
251{
252 struct max8660 *max8660 = rdev_get_drvdata(rdev);
253 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? ~2 : ~4;
254 return max8660_write(max8660, MAX8660_OVER2, mask, 0);
255}
256
257static int max8660_ldo67_list(struct regulator_dev *rdev, unsigned selector)
258{
259 if (selector > MAX8660_LDO67_MAX_SEL)
260 return -EINVAL;
261 return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP;
262}
263
264static int max8660_ldo67_get(struct regulator_dev *rdev)
265{
266 struct max8660 *max8660 = rdev_get_drvdata(rdev);
267 u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4;
268 u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf;
269
270 return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP;
271}
272
273static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, int max_uV)
274{
275 struct max8660 *max8660 = rdev_get_drvdata(rdev);
276 u8 selector;
277 int ret;
278
279 if (min_uV < MAX8660_LDO67_MIN_UV || min_uV > MAX8660_LDO67_MAX_UV)
280 return -EINVAL;
281 if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV)
282 return -EINVAL;
283
284 selector = (min_uV - (MAX8660_LDO67_MIN_UV - MAX8660_LDO67_STEP + 1))
285 / MAX8660_LDO67_STEP;
286
287 ret = max8660_ldo67_list(rdev, selector);
288 if (ret < 0 || ret > max_uV)
289 return -EINVAL;
290
291 if (rdev_get_id(rdev) == MAX8660_V6)
292 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector);
293 else
294 return max8660_write(max8660, MAX8660_L12VCR, 0x0f, selector << 4);
295}
296
297static struct regulator_ops max8660_ldo67_ops = {
298 .is_enabled = max8660_ldo67_is_enabled,
299 .enable = max8660_ldo67_enable,
300 .disable = max8660_ldo67_disable,
301 .list_voltage = max8660_ldo67_list,
302 .get_voltage = max8660_ldo67_get,
303 .set_voltage = max8660_ldo67_set,
304};
305
306static struct regulator_desc max8660_reg[] = {
307 {
308 .name = "V3(DCDC)",
309 .id = MAX8660_V3,
310 .ops = &max8660_dcdc_ops,
311 .type = REGULATOR_VOLTAGE,
312 .n_voltages = MAX8660_DCDC_MAX_SEL + 1,
313 .owner = THIS_MODULE,
314 },
315 {
316 .name = "V4(DCDC)",
317 .id = MAX8660_V4,
318 .ops = &max8660_dcdc_ops,
319 .type = REGULATOR_VOLTAGE,
320 .n_voltages = MAX8660_DCDC_MAX_SEL + 1,
321 .owner = THIS_MODULE,
322 },
323 {
324 .name = "V5(LDO)",
325 .id = MAX8660_V5,
326 .ops = &max8660_ldo5_ops,
327 .type = REGULATOR_VOLTAGE,
328 .n_voltages = MAX8660_LDO5_MAX_SEL + 1,
329 .owner = THIS_MODULE,
330 },
331 {
332 .name = "V6(LDO)",
333 .id = MAX8660_V6,
334 .ops = &max8660_ldo67_ops,
335 .type = REGULATOR_VOLTAGE,
336 .n_voltages = MAX8660_LDO67_MAX_SEL + 1,
337 .owner = THIS_MODULE,
338 },
339 {
340 .name = "V7(LDO)",
341 .id = MAX8660_V7,
342 .ops = &max8660_ldo67_ops,
343 .type = REGULATOR_VOLTAGE,
344 .n_voltages = MAX8660_LDO67_MAX_SEL + 1,
345 .owner = THIS_MODULE,
346 },
347};
348
349static int __devinit max8660_probe(struct i2c_client *client,
350 const struct i2c_device_id *i2c_id)
351{
352 struct regulator_dev **rdev;
353 struct max8660_platform_data *pdata = client->dev.platform_data;
354 struct max8660 *max8660;
355 int boot_on, i, id, ret = -EINVAL;
356
357 if (pdata->num_subdevs > MAX8660_V_END) {
358 dev_err(&client->dev, "Too many regulators found!\n");
359 goto out;
360 }
361
362 max8660 = kzalloc(sizeof(struct max8660) +
363 sizeof(struct regulator_dev *) * MAX8660_V_END,
364 GFP_KERNEL);
365 if (!max8660) {
366 ret = -ENOMEM;
367 goto out;
368 }
369
370 max8660->client = client;
371 rdev = max8660->rdev;
372
373 if (pdata->en34_is_high) {
374 /* Simulate always on */
375 max8660->shadow_regs[MAX8660_OVER1] = 5;
376 } else {
377 /* Otherwise devices can be toggled via software */
378 max8660_dcdc_ops.enable = max8660_dcdc_enable;
379 max8660_dcdc_ops.disable = max8660_dcdc_disable;
380 }
381
382 /*
383 * First, set up shadow registers to prevent glitches. As some
384 * registers are shared between regulators, everything must be properly
385 * set up for all regulators in advance.
386 */
387 max8660->shadow_regs[MAX8660_ADTV1] =
388 max8660->shadow_regs[MAX8660_ADTV2] =
389 max8660->shadow_regs[MAX8660_SDTV1] =
390 max8660->shadow_regs[MAX8660_SDTV2] = 0x1b;
391 max8660->shadow_regs[MAX8660_MDTV1] =
392 max8660->shadow_regs[MAX8660_MDTV2] = 0x04;
393
394 for (i = 0; i < pdata->num_subdevs; i++) {
395
396 if (!pdata->subdevs[i].platform_data)
397 goto err_free;
398
399 boot_on = pdata->subdevs[i].platform_data->constraints.boot_on;
400
401 switch (pdata->subdevs[i].id) {
402 case MAX8660_V3:
403 if (boot_on)
404 max8660->shadow_regs[MAX8660_OVER1] |= 1;
405 break;
406
407 case MAX8660_V4:
408 if (boot_on)
409 max8660->shadow_regs[MAX8660_OVER1] |= 4;
410 break;
411
412 case MAX8660_V5:
413 break;
414
415 case MAX8660_V6:
416 if (boot_on)
417 max8660->shadow_regs[MAX8660_OVER2] |= 2;
418 break;
419
420 case MAX8660_V7:
421 if (!strcmp(i2c_id->name, "max8661")) {
422 dev_err(&client->dev, "Regulator not on this chip!\n");
423 goto err_free;
424 }
425
426 if (boot_on)
427 max8660->shadow_regs[MAX8660_OVER2] |= 4;
428 break;
429
430 default:
431 dev_err(&client->dev, "invalid regulator %s\n",
432 pdata->subdevs[i].name);
433 goto err_free;
434 }
435 }
436
437 /* Finally register devices */
438 for (i = 0; i < pdata->num_subdevs; i++) {
439
440 id = pdata->subdevs[i].id;
441
442 rdev[i] = regulator_register(&max8660_reg[id], &client->dev,
443 pdata->subdevs[i].platform_data,
444 max8660);
445 if (IS_ERR(rdev[i])) {
446 ret = PTR_ERR(rdev[i]);
447 dev_err(&client->dev, "failed to register %s\n",
448 max8660_reg[id].name);
449 goto err_unregister;
450 }
451 }
452
453 i2c_set_clientdata(client, rdev);
454 dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n");
455 return 0;
456
457err_unregister:
458 while (--i >= 0)
459 regulator_unregister(rdev[i]);
460err_free:
461 kfree(max8660);
462out:
463 return ret;
464}
465
466static int __devexit max8660_remove(struct i2c_client *client)
467{
468 struct regulator_dev **rdev = i2c_get_clientdata(client);
469 int i;
470
471 for (i = 0; i < MAX8660_V_END; i++)
472 if (rdev[i])
473 regulator_unregister(rdev[i]);
474 i2c_set_clientdata(client, NULL);
475 kfree(rdev);
476
477 return 0;
478}
479
480static const struct i2c_device_id max8660_id[] = {
481 { "max8660", 0 },
482 { "max8661", 0 },
483 { }
484};
485MODULE_DEVICE_TABLE(i2c, max8660_id);
486
487static struct i2c_driver max8660_driver = {
488 .probe = max8660_probe,
489 .remove = __devexit_p(max8660_remove),
490 .driver = {
491 .name = "max8660",
492 .owner = THIS_MODULE,
493 },
494 .id_table = max8660_id,
495};
496
497static int __init max8660_init(void)
498{
499 return i2c_add_driver(&max8660_driver);
500}
501subsys_initcall(max8660_init);
502
503static void __exit max8660_exit(void)
504{
505 i2c_del_driver(&max8660_driver);
506}
507module_exit(max8660_exit);
508
509/* Module information */
510MODULE_DESCRIPTION("MAXIM 8660/8661 voltage regulator driver");
511MODULE_AUTHOR("Wolfram Sang");
512MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
new file mode 100644
index 000000000000..552cad85ae5a
--- /dev/null
+++ b/drivers/regulator/max8925-regulator.c
@@ -0,0 +1,308 @@
1/*
2 * Regulators driver for Maxim max8925
3 *
4 * Copyright (C) 2009 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18#include <linux/mfd/max8925.h>
19
20#define SD1_DVM_VMIN 850000
21#define SD1_DVM_VMAX 1000000
22#define SD1_DVM_STEP 50000
23#define SD1_DVM_SHIFT 5 /* SDCTL1 bit5 */
24#define SD1_DVM_EN 6 /* SDV1 bit 6 */
25
26struct max8925_regulator_info {
27 struct regulator_desc desc;
28 struct regulator_dev *regulator;
29 struct i2c_client *i2c;
30 struct max8925_chip *chip;
31
32 int min_uV;
33 int max_uV;
34 int step_uV;
35 int vol_reg;
36 int vol_shift;
37 int vol_nbits;
38 int enable_bit;
39 int enable_reg;
40};
41
42static inline int check_range(struct max8925_regulator_info *info,
43 int min_uV, int max_uV)
44{
45 if (min_uV < info->min_uV || min_uV > info->max_uV)
46 return -EINVAL;
47
48 return 0;
49}
50
51static int max8925_list_voltage(struct regulator_dev *rdev, unsigned index)
52{
53 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
54 return info->min_uV + index * info->step_uV;
55}
56
57static int max8925_set_voltage(struct regulator_dev *rdev,
58 int min_uV, int max_uV)
59{
60 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
61 unsigned char data, mask;
62
63 if (check_range(info, min_uV, max_uV)) {
64 dev_err(info->chip->dev, "invalid voltage range (%d, %d) uV\n",
65 min_uV, max_uV);
66 return -EINVAL;
67 }
68 data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
69 data <<= info->vol_shift;
70 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
71
72 return max8925_set_bits(info->i2c, info->vol_reg, mask, data);
73}
74
75static int max8925_get_voltage(struct regulator_dev *rdev)
76{
77 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
78 unsigned char data, mask;
79 int ret;
80
81 ret = max8925_reg_read(info->i2c, info->vol_reg);
82 if (ret < 0)
83 return ret;
84 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
85 data = (ret & mask) >> info->vol_shift;
86
87 return max8925_list_voltage(rdev, data);
88}
89
90static int max8925_enable(struct regulator_dev *rdev)
91{
92 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
93
94 return max8925_set_bits(info->i2c, info->enable_reg,
95 1 << info->enable_bit,
96 1 << info->enable_bit);
97}
98
99static int max8925_disable(struct regulator_dev *rdev)
100{
101 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
102
103 return max8925_set_bits(info->i2c, info->enable_reg,
104 1 << info->enable_bit, 0);
105}
106
107static int max8925_is_enabled(struct regulator_dev *rdev)
108{
109 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
110 int ret;
111
112 ret = max8925_reg_read(info->i2c, info->enable_reg);
113 if (ret < 0)
114 return ret;
115
116 return ret & (1 << info->enable_bit);
117}
118
119static int max8925_set_dvm_voltage(struct regulator_dev *rdev, int uV)
120{
121 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
122 unsigned char data, mask;
123
124 if (uV < SD1_DVM_VMIN || uV > SD1_DVM_VMAX)
125 return -EINVAL;
126
127 data = (uV - SD1_DVM_VMIN + SD1_DVM_STEP - 1) / SD1_DVM_STEP;
128 data <<= SD1_DVM_SHIFT;
129 mask = 3 << SD1_DVM_SHIFT;
130
131 return max8925_set_bits(info->i2c, info->enable_reg, mask, data);
132}
133
134static int max8925_set_dvm_enable(struct regulator_dev *rdev)
135{
136 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
137
138 return max8925_set_bits(info->i2c, info->vol_reg, 1 << SD1_DVM_EN,
139 1 << SD1_DVM_EN);
140}
141
142static int max8925_set_dvm_disable(struct regulator_dev *rdev)
143{
144 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
145
146 return max8925_set_bits(info->i2c, info->vol_reg, 1 << SD1_DVM_EN, 0);
147}
148
149static struct regulator_ops max8925_regulator_sdv_ops = {
150 .set_voltage = max8925_set_voltage,
151 .get_voltage = max8925_get_voltage,
152 .enable = max8925_enable,
153 .disable = max8925_disable,
154 .is_enabled = max8925_is_enabled,
155 .set_suspend_voltage = max8925_set_dvm_voltage,
156 .set_suspend_enable = max8925_set_dvm_enable,
157 .set_suspend_disable = max8925_set_dvm_disable,
158};
159
160static struct regulator_ops max8925_regulator_ldo_ops = {
161 .set_voltage = max8925_set_voltage,
162 .get_voltage = max8925_get_voltage,
163 .enable = max8925_enable,
164 .disable = max8925_disable,
165 .is_enabled = max8925_is_enabled,
166};
167
168#define MAX8925_SDV(_id, min, max, step) \
169{ \
170 .desc = { \
171 .name = "SDV" #_id, \
172 .ops = &max8925_regulator_sdv_ops, \
173 .type = REGULATOR_VOLTAGE, \
174 .id = MAX8925_ID_SD##_id, \
175 .owner = THIS_MODULE, \
176 }, \
177 .min_uV = min * 1000, \
178 .max_uV = max * 1000, \
179 .step_uV = step * 1000, \
180 .vol_reg = MAX8925_SDV##_id, \
181 .vol_shift = 0, \
182 .vol_nbits = 6, \
183 .enable_reg = MAX8925_SDCTL##_id, \
184 .enable_bit = 0, \
185}
186
187#define MAX8925_LDO(_id, min, max, step) \
188{ \
189 .desc = { \
190 .name = "LDO" #_id, \
191 .ops = &max8925_regulator_ldo_ops, \
192 .type = REGULATOR_VOLTAGE, \
193 .id = MAX8925_ID_LDO##_id, \
194 .owner = THIS_MODULE, \
195 }, \
196 .min_uV = min * 1000, \
197 .max_uV = max * 1000, \
198 .step_uV = step * 1000, \
199 .vol_reg = MAX8925_LDOVOUT##_id, \
200 .vol_shift = 0, \
201 .vol_nbits = 6, \
202 .enable_reg = MAX8925_LDOCTL##_id, \
203 .enable_bit = 0, \
204}
205
206static struct max8925_regulator_info max8925_regulator_info[] = {
207 MAX8925_SDV(1, 637.5, 1425, 12.5),
208 MAX8925_SDV(2, 650, 2225, 25),
209 MAX8925_SDV(3, 750, 3900, 50),
210
211 MAX8925_LDO(1, 750, 3900, 50),
212 MAX8925_LDO(2, 650, 2250, 25),
213 MAX8925_LDO(3, 650, 2250, 25),
214 MAX8925_LDO(4, 750, 3900, 50),
215 MAX8925_LDO(5, 750, 3900, 50),
216 MAX8925_LDO(6, 750, 3900, 50),
217 MAX8925_LDO(7, 750, 3900, 50),
218 MAX8925_LDO(8, 750, 3900, 50),
219 MAX8925_LDO(9, 750, 3900, 50),
220 MAX8925_LDO(10, 750, 3900, 50),
221 MAX8925_LDO(11, 750, 3900, 50),
222 MAX8925_LDO(12, 750, 3900, 50),
223 MAX8925_LDO(13, 750, 3900, 50),
224 MAX8925_LDO(14, 750, 3900, 50),
225 MAX8925_LDO(15, 750, 3900, 50),
226 MAX8925_LDO(16, 750, 3900, 50),
227 MAX8925_LDO(17, 650, 2250, 25),
228 MAX8925_LDO(18, 650, 2250, 25),
229 MAX8925_LDO(19, 750, 3900, 50),
230 MAX8925_LDO(20, 750, 3900, 50),
231};
232
233static struct max8925_regulator_info * __devinit find_regulator_info(int id)
234{
235 struct max8925_regulator_info *ri;
236 int i;
237
238 for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
239 ri = &max8925_regulator_info[i];
240 if (ri->desc.id == id)
241 return ri;
242 }
243 return NULL;
244}
245
246static int __devinit max8925_regulator_probe(struct platform_device *pdev)
247{
248 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
249 struct max8925_platform_data *pdata = chip->dev->platform_data;
250 struct max8925_regulator_info *ri;
251 struct regulator_dev *rdev;
252
253 ri = find_regulator_info(pdev->id);
254 if (ri == NULL) {
255 dev_err(&pdev->dev, "invalid regulator ID specified\n");
256 return -EINVAL;
257 }
258 ri->i2c = chip->i2c;
259 ri->chip = chip;
260
261 rdev = regulator_register(&ri->desc, &pdev->dev,
262 pdata->regulator[pdev->id], ri);
263 if (IS_ERR(rdev)) {
264 dev_err(&pdev->dev, "failed to register regulator %s\n",
265 ri->desc.name);
266 return PTR_ERR(rdev);
267 }
268
269 platform_set_drvdata(pdev, rdev);
270 return 0;
271}
272
273static int __devexit max8925_regulator_remove(struct platform_device *pdev)
274{
275 struct regulator_dev *rdev = platform_get_drvdata(pdev);
276
277 platform_set_drvdata(pdev, NULL);
278 regulator_unregister(rdev);
279
280 return 0;
281}
282
283static struct platform_driver max8925_regulator_driver = {
284 .driver = {
285 .name = "max8925-regulator",
286 .owner = THIS_MODULE,
287 },
288 .probe = max8925_regulator_probe,
289 .remove = __devexit_p(max8925_regulator_remove),
290};
291
292static int __init max8925_regulator_init(void)
293{
294 return platform_driver_register(&max8925_regulator_driver);
295}
296subsys_initcall(max8925_regulator_init);
297
298static void __exit max8925_regulator_exit(void)
299{
300 platform_driver_unregister(&max8925_regulator_driver);
301}
302module_exit(max8925_regulator_exit);
303
304MODULE_LICENSE("GPL");
305MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
306MODULE_DESCRIPTION("Regulator Driver for Maxim 8925 PMIC");
307MODULE_ALIAS("platform:max8925-regulator");
308
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
new file mode 100644
index 000000000000..ad036dd8da13
--- /dev/null
+++ b/drivers/regulator/mc13783-regulator.c
@@ -0,0 +1,654 @@
1/*
2 * Regulator Driver for Freescale MC13783 PMIC
3 *
4 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
5 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/mfd/mc13783.h>
13#include <linux/regulator/machine.h>
14#include <linux/regulator/driver.h>
15#include <linux/platform_device.h>
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/init.h>
19#include <linux/err.h>
20
21#define MC13783_REG_SWITCHERS5 29
22#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20)
23#define MC13783_REG_SWITCHERS5_SW3VSEL 18
24#define MC13783_REG_SWITCHERS5_SW3VSEL_M (3 << 18)
25
26#define MC13783_REG_REGULATORSETTING0 30
27#define MC13783_REG_REGULATORSETTING0_VIOLOVSEL 2
28#define MC13783_REG_REGULATORSETTING0_VDIGVSEL 4
29#define MC13783_REG_REGULATORSETTING0_VGENVSEL 6
30#define MC13783_REG_REGULATORSETTING0_VRFDIGVSEL 9
31#define MC13783_REG_REGULATORSETTING0_VRFREFVSEL 11
32#define MC13783_REG_REGULATORSETTING0_VRFCPVSEL 13
33#define MC13783_REG_REGULATORSETTING0_VSIMVSEL 14
34#define MC13783_REG_REGULATORSETTING0_VESIMVSEL 15
35#define MC13783_REG_REGULATORSETTING0_VCAMVSEL 16
36
37#define MC13783_REG_REGULATORSETTING0_VIOLOVSEL_M (3 << 2)
38#define MC13783_REG_REGULATORSETTING0_VDIGVSEL_M (3 << 4)
39#define MC13783_REG_REGULATORSETTING0_VGENVSEL_M (7 << 6)
40#define MC13783_REG_REGULATORSETTING0_VRFDIGVSEL_M (3 << 9)
41#define MC13783_REG_REGULATORSETTING0_VRFREFVSEL_M (3 << 11)
42#define MC13783_REG_REGULATORSETTING0_VRFCPVSEL_M (1 << 13)
43#define MC13783_REG_REGULATORSETTING0_VSIMVSEL_M (1 << 14)
44#define MC13783_REG_REGULATORSETTING0_VESIMVSEL_M (1 << 15)
45#define MC13783_REG_REGULATORSETTING0_VCAMVSEL_M (7 << 16)
46
47#define MC13783_REG_REGULATORSETTING1 31
48#define MC13783_REG_REGULATORSETTING1_VVIBVSEL 0
49#define MC13783_REG_REGULATORSETTING1_VRF1VSEL 2
50#define MC13783_REG_REGULATORSETTING1_VRF2VSEL 4
51#define MC13783_REG_REGULATORSETTING1_VMMC1VSEL 6
52#define MC13783_REG_REGULATORSETTING1_VMMC2VSEL 9
53
54#define MC13783_REG_REGULATORSETTING1_VVIBVSEL_M (3 << 0)
55#define MC13783_REG_REGULATORSETTING1_VRF1VSEL_M (3 << 2)
56#define MC13783_REG_REGULATORSETTING1_VRF2VSEL_M (3 << 4)
57#define MC13783_REG_REGULATORSETTING1_VMMC1VSEL_M (7 << 6)
58#define MC13783_REG_REGULATORSETTING1_VMMC2VSEL_M (7 << 9)
59
60#define MC13783_REG_REGULATORMODE0 32
61#define MC13783_REG_REGULATORMODE0_VAUDIOEN (1 << 0)
62#define MC13783_REG_REGULATORMODE0_VIOHIEN (1 << 3)
63#define MC13783_REG_REGULATORMODE0_VIOLOEN (1 << 6)
64#define MC13783_REG_REGULATORMODE0_VDIGEN (1 << 9)
65#define MC13783_REG_REGULATORMODE0_VGENEN (1 << 12)
66#define MC13783_REG_REGULATORMODE0_VRFDIGEN (1 << 15)
67#define MC13783_REG_REGULATORMODE0_VRFREFEN (1 << 18)
68#define MC13783_REG_REGULATORMODE0_VRFCPEN (1 << 21)
69
70#define MC13783_REG_REGULATORMODE1 33
71#define MC13783_REG_REGULATORMODE1_VSIMEN (1 << 0)
72#define MC13783_REG_REGULATORMODE1_VESIMEN (1 << 3)
73#define MC13783_REG_REGULATORMODE1_VCAMEN (1 << 6)
74#define MC13783_REG_REGULATORMODE1_VRFBGEN (1 << 9)
75#define MC13783_REG_REGULATORMODE1_VVIBEN (1 << 11)
76#define MC13783_REG_REGULATORMODE1_VRF1EN (1 << 12)
77#define MC13783_REG_REGULATORMODE1_VRF2EN (1 << 15)
78#define MC13783_REG_REGULATORMODE1_VMMC1EN (1 << 18)
79#define MC13783_REG_REGULATORMODE1_VMMC2EN (1 << 21)
80
81#define MC13783_REG_POWERMISC 34
82#define MC13783_REG_POWERMISC_GPO1EN (1 << 6)
83#define MC13783_REG_POWERMISC_GPO2EN (1 << 8)
84#define MC13783_REG_POWERMISC_GPO3EN (1 << 10)
85#define MC13783_REG_POWERMISC_GPO4EN (1 << 12)
86#define MC13783_REG_POWERMISC_PWGT1SPIEN (1 << 15)
87#define MC13783_REG_POWERMISC_PWGT2SPIEN (1 << 16)
88
89#define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15)
90
91
92struct mc13783_regulator {
93 struct regulator_desc desc;
94 int reg;
95 int enable_bit;
96 int vsel_reg;
97 int vsel_shift;
98 int vsel_mask;
99 int const *voltages;
100};
101
102/* Voltage Values */
103static const int const mc13783_sw3_val[] = {
104 5000000, 5000000, 5000000, 5500000,
105};
106
107static const int const mc13783_vaudio_val[] = {
108 2775000,
109};
110
111static const int const mc13783_viohi_val[] = {
112 2775000,
113};
114
115static const int const mc13783_violo_val[] = {
116 1200000, 1300000, 1500000, 1800000,
117};
118
119static const int const mc13783_vdig_val[] = {
120 1200000, 1300000, 1500000, 1800000,
121};
122
123static const int const mc13783_vgen_val[] = {
124 1200000, 1300000, 1500000, 1800000,
125 1100000, 2000000, 2775000, 2400000,
126};
127
128static const int const mc13783_vrfdig_val[] = {
129 1200000, 1500000, 1800000, 1875000,
130};
131
132static const int const mc13783_vrfref_val[] = {
133 2475000, 2600000, 2700000, 2775000,
134};
135
136static const int const mc13783_vrfcp_val[] = {
137 2700000, 2775000,
138};
139
140static const int const mc13783_vsim_val[] = {
141 1800000, 2900000, 3000000,
142};
143
144static const int const mc13783_vesim_val[] = {
145 1800000, 2900000,
146};
147
148static const int const mc13783_vcam_val[] = {
149 1500000, 1800000, 2500000, 2550000,
150 2600000, 2750000, 2800000, 3000000,
151};
152
153static const int const mc13783_vrfbg_val[] = {
154 1250000,
155};
156
157static const int const mc13783_vvib_val[] = {
158 1300000, 1800000, 2000000, 3000000,
159};
160
161static const int const mc13783_vmmc_val[] = {
162 1600000, 1800000, 2000000, 2600000,
163 2700000, 2800000, 2900000, 3000000,
164};
165
166static const int const mc13783_vrf_val[] = {
167 1500000, 1875000, 2700000, 2775000,
168};
169
170static const int const mc13783_gpo_val[] = {
171 3100000,
172};
173
174static const int const mc13783_pwgtdrv_val[] = {
175 5500000,
176};
177
178static struct regulator_ops mc13783_regulator_ops;
179static struct regulator_ops mc13783_fixed_regulator_ops;
180static struct regulator_ops mc13783_gpo_regulator_ops;
181
182#define MC13783_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages) \
183 [MC13783_ ## prefix ## _ ## _name] = { \
184 .desc = { \
185 .name = #prefix "_" #_name, \
186 .n_voltages = ARRAY_SIZE(_voltages), \
187 .ops = &mc13783_regulator_ops, \
188 .type = REGULATOR_VOLTAGE, \
189 .id = MC13783_ ## prefix ## _ ## _name, \
190 .owner = THIS_MODULE, \
191 }, \
192 .reg = MC13783_REG_ ## _reg, \
193 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
194 .vsel_reg = MC13783_REG_ ## _vsel_reg, \
195 .vsel_shift = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL,\
196 .vsel_mask = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL_M,\
197 .voltages = _voltages, \
198 }
199
200#define MC13783_FIXED_DEFINE(prefix, _name, _reg, _voltages) \
201 [MC13783_ ## prefix ## _ ## _name] = { \
202 .desc = { \
203 .name = #prefix "_" #_name, \
204 .n_voltages = ARRAY_SIZE(_voltages), \
205 .ops = &mc13783_fixed_regulator_ops, \
206 .type = REGULATOR_VOLTAGE, \
207 .id = MC13783_ ## prefix ## _ ## _name, \
208 .owner = THIS_MODULE, \
209 }, \
210 .reg = MC13783_REG_ ## _reg, \
211 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
212 .voltages = _voltages, \
213 }
214
215#define MC13783_GPO_DEFINE(prefix, _name, _reg, _voltages) \
216 [MC13783_ ## prefix ## _ ## _name] = { \
217 .desc = { \
218 .name = #prefix "_" #_name, \
219 .n_voltages = ARRAY_SIZE(_voltages), \
220 .ops = &mc13783_gpo_regulator_ops, \
221 .type = REGULATOR_VOLTAGE, \
222 .id = MC13783_ ## prefix ## _ ## _name, \
223 .owner = THIS_MODULE, \
224 }, \
225 .reg = MC13783_REG_ ## _reg, \
226 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
227 .voltages = _voltages, \
228 }
229
230#define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \
231 MC13783_DEFINE(SW, _name, _reg, _vsel_reg, _voltages)
232#define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \
233 MC13783_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages)
234
235static struct mc13783_regulator mc13783_regulators[] = {
236 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val),
237
238 MC13783_FIXED_DEFINE(REGU, VAUDIO, REGULATORMODE0, mc13783_vaudio_val),
239 MC13783_FIXED_DEFINE(REGU, VIOHI, REGULATORMODE0, mc13783_viohi_val),
240 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \
241 mc13783_violo_val),
242 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \
243 mc13783_vdig_val),
244 MC13783_DEFINE_REGU(VGEN, REGULATORMODE0, REGULATORSETTING0, \
245 mc13783_vgen_val),
246 MC13783_DEFINE_REGU(VRFDIG, REGULATORMODE0, REGULATORSETTING0, \
247 mc13783_vrfdig_val),
248 MC13783_DEFINE_REGU(VRFREF, REGULATORMODE0, REGULATORSETTING0, \
249 mc13783_vrfref_val),
250 MC13783_DEFINE_REGU(VRFCP, REGULATORMODE0, REGULATORSETTING0, \
251 mc13783_vrfcp_val),
252 MC13783_DEFINE_REGU(VSIM, REGULATORMODE1, REGULATORSETTING0, \
253 mc13783_vsim_val),
254 MC13783_DEFINE_REGU(VESIM, REGULATORMODE1, REGULATORSETTING0, \
255 mc13783_vesim_val),
256 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \
257 mc13783_vcam_val),
258 MC13783_FIXED_DEFINE(REGU, VRFBG, REGULATORMODE1, mc13783_vrfbg_val),
259 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \
260 mc13783_vvib_val),
261 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \
262 mc13783_vrf_val),
263 MC13783_DEFINE_REGU(VRF2, REGULATORMODE1, REGULATORSETTING1, \
264 mc13783_vrf_val),
265 MC13783_DEFINE_REGU(VMMC1, REGULATORMODE1, REGULATORSETTING1, \
266 mc13783_vmmc_val),
267 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \
268 mc13783_vmmc_val),
269 MC13783_GPO_DEFINE(REGU, GPO1, POWERMISC, mc13783_gpo_val),
270 MC13783_GPO_DEFINE(REGU, GPO2, POWERMISC, mc13783_gpo_val),
271 MC13783_GPO_DEFINE(REGU, GPO3, POWERMISC, mc13783_gpo_val),
272 MC13783_GPO_DEFINE(REGU, GPO4, POWERMISC, mc13783_gpo_val),
273 MC13783_GPO_DEFINE(REGU, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val),
274 MC13783_GPO_DEFINE(REGU, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val),
275};
276
277struct mc13783_regulator_priv {
278 struct mc13783 *mc13783;
279 u32 powermisc_pwgt_state;
280 struct regulator_dev *regulators[];
281};
282
283static int mc13783_regulator_enable(struct regulator_dev *rdev)
284{
285 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
286 int id = rdev_get_id(rdev);
287 int ret;
288
289 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
290
291 mc13783_lock(priv->mc13783);
292 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg,
293 mc13783_regulators[id].enable_bit,
294 mc13783_regulators[id].enable_bit);
295 mc13783_unlock(priv->mc13783);
296
297 return ret;
298}
299
300static int mc13783_regulator_disable(struct regulator_dev *rdev)
301{
302 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
303 int id = rdev_get_id(rdev);
304 int ret;
305
306 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
307
308 mc13783_lock(priv->mc13783);
309 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg,
310 mc13783_regulators[id].enable_bit, 0);
311 mc13783_unlock(priv->mc13783);
312
313 return ret;
314}
315
316static int mc13783_regulator_is_enabled(struct regulator_dev *rdev)
317{
318 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
319 int ret, id = rdev_get_id(rdev);
320 unsigned int val;
321
322 mc13783_lock(priv->mc13783);
323 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val);
324 mc13783_unlock(priv->mc13783);
325
326 if (ret)
327 return ret;
328
329 return (val & mc13783_regulators[id].enable_bit) != 0;
330}
331
332static int mc13783_regulator_list_voltage(struct regulator_dev *rdev,
333 unsigned selector)
334{
335 int id = rdev_get_id(rdev);
336
337 if (selector >= mc13783_regulators[id].desc.n_voltages)
338 return -EINVAL;
339
340 return mc13783_regulators[id].voltages[selector];
341}
342
343static int mc13783_get_best_voltage_index(struct regulator_dev *rdev,
344 int min_uV, int max_uV)
345{
346 int reg_id = rdev_get_id(rdev);
347 int i;
348 int bestmatch;
349 int bestindex;
350
351 /*
352 * Locate the minimum voltage fitting the criteria on
353 * this regulator. The switchable voltages are not
354 * in strict falling order so we need to check them
355 * all for the best match.
356 */
357 bestmatch = INT_MAX;
358 bestindex = -1;
359 for (i = 0; i < mc13783_regulators[reg_id].desc.n_voltages; i++) {
360 if (mc13783_regulators[reg_id].voltages[i] >= min_uV &&
361 mc13783_regulators[reg_id].voltages[i] < bestmatch) {
362 bestmatch = mc13783_regulators[reg_id].voltages[i];
363 bestindex = i;
364 }
365 }
366
367 if (bestindex < 0 || bestmatch > max_uV) {
368 dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
369 min_uV, max_uV);
370 return -EINVAL;
371 }
372 return bestindex;
373}
374
375static int mc13783_regulator_set_voltage(struct regulator_dev *rdev,
376 int min_uV, int max_uV)
377{
378 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
379 int value, id = rdev_get_id(rdev);
380 int ret;
381
382 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
383 __func__, id, min_uV, max_uV);
384
385 /* Find the best index */
386 value = mc13783_get_best_voltage_index(rdev, min_uV, max_uV);
387 dev_dbg(rdev_get_dev(rdev), "%s best value: %d \n", __func__, value);
388 if (value < 0)
389 return value;
390
391 mc13783_lock(priv->mc13783);
392 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].vsel_reg,
393 mc13783_regulators[id].vsel_mask,
394 value << mc13783_regulators[id].vsel_shift);
395 mc13783_unlock(priv->mc13783);
396
397 return ret;
398}
399
400static int mc13783_regulator_get_voltage(struct regulator_dev *rdev)
401{
402 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
403 int ret, id = rdev_get_id(rdev);
404 unsigned int val;
405
406 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
407
408 mc13783_lock(priv->mc13783);
409 ret = mc13783_reg_read(priv->mc13783,
410 mc13783_regulators[id].vsel_reg, &val);
411 mc13783_unlock(priv->mc13783);
412
413 if (ret)
414 return ret;
415
416 val = (val & mc13783_regulators[id].vsel_mask)
417 >> mc13783_regulators[id].vsel_shift;
418
419 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
420
421 BUG_ON(val < 0 || val > mc13783_regulators[id].desc.n_voltages);
422
423 return mc13783_regulators[id].voltages[val];
424}
425
426static struct regulator_ops mc13783_regulator_ops = {
427 .enable = mc13783_regulator_enable,
428 .disable = mc13783_regulator_disable,
429 .is_enabled = mc13783_regulator_is_enabled,
430 .list_voltage = mc13783_regulator_list_voltage,
431 .set_voltage = mc13783_regulator_set_voltage,
432 .get_voltage = mc13783_regulator_get_voltage,
433};
434
435static int mc13783_fixed_regulator_set_voltage(struct regulator_dev *rdev,
436 int min_uV, int max_uV)
437{
438 int id = rdev_get_id(rdev);
439
440 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
441 __func__, id, min_uV, max_uV);
442
443 if (min_uV > mc13783_regulators[id].voltages[0] &&
444 max_uV < mc13783_regulators[id].voltages[0])
445 return 0;
446 else
447 return -EINVAL;
448}
449
450static int mc13783_fixed_regulator_get_voltage(struct regulator_dev *rdev)
451{
452 int id = rdev_get_id(rdev);
453
454 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
455
456 return mc13783_regulators[id].voltages[0];
457}
458
459static struct regulator_ops mc13783_fixed_regulator_ops = {
460 .enable = mc13783_regulator_enable,
461 .disable = mc13783_regulator_disable,
462 .is_enabled = mc13783_regulator_is_enabled,
463 .list_voltage = mc13783_regulator_list_voltage,
464 .set_voltage = mc13783_fixed_regulator_set_voltage,
465 .get_voltage = mc13783_fixed_regulator_get_voltage,
466};
467
468int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask,
469 u32 val)
470{
471 struct mc13783 *mc13783 = priv->mc13783;
472 int ret;
473 u32 valread;
474
475 BUG_ON(val & ~mask);
476
477 ret = mc13783_reg_read(mc13783, MC13783_REG_POWERMISC, &valread);
478 if (ret)
479 return ret;
480
481 /* Update the stored state for Power Gates. */
482 priv->powermisc_pwgt_state =
483 (priv->powermisc_pwgt_state & ~mask) | val;
484 priv->powermisc_pwgt_state &= MC13783_REG_POWERMISC_PWGTSPI_M;
485
486 /* Construct the new register value */
487 valread = (valread & ~mask) | val;
488 /* Overwrite the PWGTxEN with the stored version */
489 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
490 priv->powermisc_pwgt_state;
491
492 return mc13783_reg_write(mc13783, MC13783_REG_POWERMISC, valread);
493}
494
495static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev)
496{
497 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
498 int id = rdev_get_id(rdev);
499 int ret;
500 u32 en_val = mc13783_regulators[id].enable_bit;
501
502 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
503
504 /* Power Gate enable value is 0 */
505 if (id == MC13783_REGU_PWGT1SPI ||
506 id == MC13783_REGU_PWGT2SPI)
507 en_val = 0;
508
509 mc13783_lock(priv->mc13783);
510 ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit,
511 en_val);
512 mc13783_unlock(priv->mc13783);
513
514 return ret;
515}
516
517static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
518{
519 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
520 int id = rdev_get_id(rdev);
521 int ret;
522 u32 dis_val = 0;
523
524 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
525
526 /* Power Gate disable value is 1 */
527 if (id == MC13783_REGU_PWGT1SPI ||
528 id == MC13783_REGU_PWGT2SPI)
529 dis_val = mc13783_regulators[id].enable_bit;
530
531 mc13783_lock(priv->mc13783);
532 ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit,
533 dis_val);
534 mc13783_unlock(priv->mc13783);
535
536 return ret;
537}
538
539static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
540{
541 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
542 int ret, id = rdev_get_id(rdev);
543 unsigned int val;
544
545 mc13783_lock(priv->mc13783);
546 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val);
547 mc13783_unlock(priv->mc13783);
548
549 if (ret)
550 return ret;
551
552 /* Power Gates state is stored in powermisc_pwgt_state
553 * where the meaning of bits is negated */
554 val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
555 (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M);
556
557 return (val & mc13783_regulators[id].enable_bit) != 0;
558}
559
560static struct regulator_ops mc13783_gpo_regulator_ops = {
561 .enable = mc13783_gpo_regulator_enable,
562 .disable = mc13783_gpo_regulator_disable,
563 .is_enabled = mc13783_gpo_regulator_is_enabled,
564 .list_voltage = mc13783_regulator_list_voltage,
565 .set_voltage = mc13783_fixed_regulator_set_voltage,
566 .get_voltage = mc13783_fixed_regulator_get_voltage,
567};
568
569static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
570{
571 struct mc13783_regulator_priv *priv;
572 struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent);
573 struct mc13783_regulator_platform_data *pdata =
574 dev_get_platdata(&pdev->dev);
575 struct mc13783_regulator_init_data *init_data;
576 int i, ret;
577
578 dev_dbg(&pdev->dev, "mc13783_regulator_probe id %d\n", pdev->id);
579
580 priv = kzalloc(sizeof(*priv) +
581 pdata->num_regulators * sizeof(priv->regulators[0]),
582 GFP_KERNEL);
583 if (!priv)
584 return -ENOMEM;
585
586 priv->mc13783 = mc13783;
587
588 for (i = 0; i < pdata->num_regulators; i++) {
589 init_data = &pdata->regulators[i];
590 priv->regulators[i] = regulator_register(
591 &mc13783_regulators[init_data->id].desc,
592 &pdev->dev, init_data->init_data, priv);
593
594 if (IS_ERR(priv->regulators[i])) {
595 dev_err(&pdev->dev, "failed to register regulator %s\n",
596 mc13783_regulators[i].desc.name);
597 ret = PTR_ERR(priv->regulators[i]);
598 goto err;
599 }
600 }
601
602 platform_set_drvdata(pdev, priv);
603
604 return 0;
605err:
606 while (--i >= 0)
607 regulator_unregister(priv->regulators[i]);
608
609 kfree(priv);
610
611 return ret;
612}
613
614static int __devexit mc13783_regulator_remove(struct platform_device *pdev)
615{
616 struct mc13783_regulator_priv *priv = platform_get_drvdata(pdev);
617 struct mc13783_regulator_platform_data *pdata =
618 dev_get_platdata(&pdev->dev);
619 int i;
620
621 platform_set_drvdata(pdev, NULL);
622
623 for (i = 0; i < pdata->num_regulators; i++)
624 regulator_unregister(priv->regulators[i]);
625
626 kfree(priv);
627 return 0;
628}
629
630static struct platform_driver mc13783_regulator_driver = {
631 .driver = {
632 .name = "mc13783-regulator",
633 .owner = THIS_MODULE,
634 },
635 .remove = __devexit_p(mc13783_regulator_remove),
636 .probe = mc13783_regulator_probe,
637};
638
639static int __init mc13783_regulator_init(void)
640{
641 return platform_driver_register(&mc13783_regulator_driver);
642}
643subsys_initcall(mc13783_regulator_init);
644
645static void __exit mc13783_regulator_exit(void)
646{
647 platform_driver_unregister(&mc13783_regulator_driver);
648}
649module_exit(mc13783_regulator_exit);
650
651MODULE_LICENSE("GPL v2");
652MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
653MODULE_DESCRIPTION("Regulator Driver for Freescale MC13783 PMIC");
654MODULE_ALIAS("platform:mc13783-regulator");
diff --git a/drivers/regulator/mc13783.c b/drivers/regulator/mc13783.c
deleted file mode 100644
index 710211f67449..000000000000
--- a/drivers/regulator/mc13783.c
+++ /dev/null
@@ -1,410 +0,0 @@
1/*
2 * Regulator Driver for Freescale MC13783 PMIC
3 *
4 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/mfd/mc13783-private.h>
12#include <linux/regulator/machine.h>
13#include <linux/regulator/driver.h>
14#include <linux/platform_device.h>
15#include <linux/mfd/mc13783.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/err.h>
19
20struct mc13783_regulator {
21 struct regulator_desc desc;
22 int reg;
23 int enable_bit;
24};
25
26static struct regulator_ops mc13783_regulator_ops;
27
28static struct mc13783_regulator mc13783_regulators[] = {
29 [MC13783_SW_SW3] = {
30 .desc = {
31 .name = "SW_SW3",
32 .ops = &mc13783_regulator_ops,
33 .type = REGULATOR_VOLTAGE,
34 .id = MC13783_SW_SW3,
35 .owner = THIS_MODULE,
36 },
37 .reg = MC13783_REG_SWITCHERS_5,
38 .enable_bit = MC13783_SWCTRL_SW3_EN,
39 },
40 [MC13783_SW_PLL] = {
41 .desc = {
42 .name = "SW_PLL",
43 .ops = &mc13783_regulator_ops,
44 .type = REGULATOR_VOLTAGE,
45 .id = MC13783_SW_PLL,
46 .owner = THIS_MODULE,
47 },
48 .reg = MC13783_REG_SWITCHERS_4,
49 .enable_bit = MC13783_SWCTRL_PLL_EN,
50 },
51 [MC13783_REGU_VAUDIO] = {
52 .desc = {
53 .name = "REGU_VAUDIO",
54 .ops = &mc13783_regulator_ops,
55 .type = REGULATOR_VOLTAGE,
56 .id = MC13783_REGU_VAUDIO,
57 .owner = THIS_MODULE,
58 },
59 .reg = MC13783_REG_REGULATOR_MODE_0,
60 .enable_bit = MC13783_REGCTRL_VAUDIO_EN,
61 },
62 [MC13783_REGU_VIOHI] = {
63 .desc = {
64 .name = "REGU_VIOHI",
65 .ops = &mc13783_regulator_ops,
66 .type = REGULATOR_VOLTAGE,
67 .id = MC13783_REGU_VIOHI,
68 .owner = THIS_MODULE,
69 },
70 .reg = MC13783_REG_REGULATOR_MODE_0,
71 .enable_bit = MC13783_REGCTRL_VIOHI_EN,
72 },
73 [MC13783_REGU_VIOLO] = {
74 .desc = {
75 .name = "REGU_VIOLO",
76 .ops = &mc13783_regulator_ops,
77 .type = REGULATOR_VOLTAGE,
78 .id = MC13783_REGU_VIOLO,
79 .owner = THIS_MODULE,
80 },
81 .reg = MC13783_REG_REGULATOR_MODE_0,
82 .enable_bit = MC13783_REGCTRL_VIOLO_EN,
83 },
84 [MC13783_REGU_VDIG] = {
85 .desc = {
86 .name = "REGU_VDIG",
87 .ops = &mc13783_regulator_ops,
88 .type = REGULATOR_VOLTAGE,
89 .id = MC13783_REGU_VDIG,
90 .owner = THIS_MODULE,
91 },
92 .reg = MC13783_REG_REGULATOR_MODE_0,
93 .enable_bit = MC13783_REGCTRL_VDIG_EN,
94 },
95 [MC13783_REGU_VGEN] = {
96 .desc = {
97 .name = "REGU_VGEN",
98 .ops = &mc13783_regulator_ops,
99 .type = REGULATOR_VOLTAGE,
100 .id = MC13783_REGU_VGEN,
101 .owner = THIS_MODULE,
102 },
103 .reg = MC13783_REG_REGULATOR_MODE_0,
104 .enable_bit = MC13783_REGCTRL_VGEN_EN,
105 },
106 [MC13783_REGU_VRFDIG] = {
107 .desc = {
108 .name = "REGU_VRFDIG",
109 .ops = &mc13783_regulator_ops,
110 .type = REGULATOR_VOLTAGE,
111 .id = MC13783_REGU_VRFDIG,
112 .owner = THIS_MODULE,
113 },
114 .reg = MC13783_REG_REGULATOR_MODE_0,
115 .enable_bit = MC13783_REGCTRL_VRFDIG_EN,
116 },
117 [MC13783_REGU_VRFREF] = {
118 .desc = {
119 .name = "REGU_VRFREF",
120 .ops = &mc13783_regulator_ops,
121 .type = REGULATOR_VOLTAGE,
122 .id = MC13783_REGU_VRFREF,
123 .owner = THIS_MODULE,
124 },
125 .reg = MC13783_REG_REGULATOR_MODE_0,
126 .enable_bit = MC13783_REGCTRL_VRFREF_EN,
127 },
128 [MC13783_REGU_VRFCP] = {
129 .desc = {
130 .name = "REGU_VRFCP",
131 .ops = &mc13783_regulator_ops,
132 .type = REGULATOR_VOLTAGE,
133 .id = MC13783_REGU_VRFCP,
134 .owner = THIS_MODULE,
135 },
136 .reg = MC13783_REG_REGULATOR_MODE_0,
137 .enable_bit = MC13783_REGCTRL_VRFCP_EN,
138 },
139 [MC13783_REGU_VSIM] = {
140 .desc = {
141 .name = "REGU_VSIM",
142 .ops = &mc13783_regulator_ops,
143 .type = REGULATOR_VOLTAGE,
144 .id = MC13783_REGU_VSIM,
145 .owner = THIS_MODULE,
146 },
147 .reg = MC13783_REG_REGULATOR_MODE_1,
148 .enable_bit = MC13783_REGCTRL_VSIM_EN,
149 },
150 [MC13783_REGU_VESIM] = {
151 .desc = {
152 .name = "REGU_VESIM",
153 .ops = &mc13783_regulator_ops,
154 .type = REGULATOR_VOLTAGE,
155 .id = MC13783_REGU_VESIM,
156 .owner = THIS_MODULE,
157 },
158 .reg = MC13783_REG_REGULATOR_MODE_1,
159 .enable_bit = MC13783_REGCTRL_VESIM_EN,
160 },
161 [MC13783_REGU_VCAM] = {
162 .desc = {
163 .name = "REGU_VCAM",
164 .ops = &mc13783_regulator_ops,
165 .type = REGULATOR_VOLTAGE,
166 .id = MC13783_REGU_VCAM,
167 .owner = THIS_MODULE,
168 },
169 .reg = MC13783_REG_REGULATOR_MODE_1,
170 .enable_bit = MC13783_REGCTRL_VCAM_EN,
171 },
172 [MC13783_REGU_VRFBG] = {
173 .desc = {
174 .name = "REGU_VRFBG",
175 .ops = &mc13783_regulator_ops,
176 .type = REGULATOR_VOLTAGE,
177 .id = MC13783_REGU_VRFBG,
178 .owner = THIS_MODULE,
179 },
180 .reg = MC13783_REG_REGULATOR_MODE_1,
181 .enable_bit = MC13783_REGCTRL_VRFBG_EN,
182 },
183 [MC13783_REGU_VVIB] = {
184 .desc = {
185 .name = "REGU_VVIB",
186 .ops = &mc13783_regulator_ops,
187 .type = REGULATOR_VOLTAGE,
188 .id = MC13783_REGU_VVIB,
189 .owner = THIS_MODULE,
190 },
191 .reg = MC13783_REG_REGULATOR_MODE_1,
192 .enable_bit = MC13783_REGCTRL_VVIB_EN,
193 },
194 [MC13783_REGU_VRF1] = {
195 .desc = {
196 .name = "REGU_VRF1",
197 .ops = &mc13783_regulator_ops,
198 .type = REGULATOR_VOLTAGE,
199 .id = MC13783_REGU_VRF1,
200 .owner = THIS_MODULE,
201 },
202 .reg = MC13783_REG_REGULATOR_MODE_1,
203 .enable_bit = MC13783_REGCTRL_VRF1_EN,
204 },
205 [MC13783_REGU_VRF2] = {
206 .desc = {
207 .name = "REGU_VRF2",
208 .ops = &mc13783_regulator_ops,
209 .type = REGULATOR_VOLTAGE,
210 .id = MC13783_REGU_VRF2,
211 .owner = THIS_MODULE,
212 },
213 .reg = MC13783_REG_REGULATOR_MODE_1,
214 .enable_bit = MC13783_REGCTRL_VRF2_EN,
215 },
216 [MC13783_REGU_VMMC1] = {
217 .desc = {
218 .name = "REGU_VMMC1",
219 .ops = &mc13783_regulator_ops,
220 .type = REGULATOR_VOLTAGE,
221 .id = MC13783_REGU_VMMC1,
222 .owner = THIS_MODULE,
223 },
224 .reg = MC13783_REG_REGULATOR_MODE_1,
225 .enable_bit = MC13783_REGCTRL_VMMC1_EN,
226 },
227 [MC13783_REGU_VMMC2] = {
228 .desc = {
229 .name = "REGU_VMMC2",
230 .ops = &mc13783_regulator_ops,
231 .type = REGULATOR_VOLTAGE,
232 .id = MC13783_REGU_VMMC2,
233 .owner = THIS_MODULE,
234 },
235 .reg = MC13783_REG_REGULATOR_MODE_1,
236 .enable_bit = MC13783_REGCTRL_VMMC2_EN,
237 },
238 [MC13783_REGU_GPO1] = {
239 .desc = {
240 .name = "REGU_GPO1",
241 .ops = &mc13783_regulator_ops,
242 .type = REGULATOR_VOLTAGE,
243 .id = MC13783_REGU_GPO1,
244 .owner = THIS_MODULE,
245 },
246 .reg = MC13783_REG_POWER_MISCELLANEOUS,
247 .enable_bit = MC13783_REGCTRL_GPO1_EN,
248 },
249 [MC13783_REGU_GPO2] = {
250 .desc = {
251 .name = "REGU_GPO2",
252 .ops = &mc13783_regulator_ops,
253 .type = REGULATOR_VOLTAGE,
254 .id = MC13783_REGU_GPO2,
255 .owner = THIS_MODULE,
256 },
257 .reg = MC13783_REG_POWER_MISCELLANEOUS,
258 .enable_bit = MC13783_REGCTRL_GPO2_EN,
259 },
260 [MC13783_REGU_GPO3] = {
261 .desc = {
262 .name = "REGU_GPO3",
263 .ops = &mc13783_regulator_ops,
264 .type = REGULATOR_VOLTAGE,
265 .id = MC13783_REGU_GPO3,
266 .owner = THIS_MODULE,
267 },
268 .reg = MC13783_REG_POWER_MISCELLANEOUS,
269 .enable_bit = MC13783_REGCTRL_GPO3_EN,
270 },
271 [MC13783_REGU_GPO4] = {
272 .desc = {
273 .name = "REGU_GPO4",
274 .ops = &mc13783_regulator_ops,
275 .type = REGULATOR_VOLTAGE,
276 .id = MC13783_REGU_GPO4,
277 .owner = THIS_MODULE,
278 },
279 .reg = MC13783_REG_POWER_MISCELLANEOUS,
280 .enable_bit = MC13783_REGCTRL_GPO4_EN,
281 },
282};
283
284struct mc13783_priv {
285 struct regulator_desc desc[ARRAY_SIZE(mc13783_regulators)];
286 struct mc13783 *mc13783;
287 struct regulator_dev *regulators[0];
288};
289
290static int mc13783_enable(struct regulator_dev *rdev)
291{
292 struct mc13783_priv *priv = rdev_get_drvdata(rdev);
293 int id = rdev_get_id(rdev);
294
295 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
296
297 return mc13783_set_bits(priv->mc13783, mc13783_regulators[id].reg,
298 mc13783_regulators[id].enable_bit,
299 mc13783_regulators[id].enable_bit);
300}
301
302static int mc13783_disable(struct regulator_dev *rdev)
303{
304 struct mc13783_priv *priv = rdev_get_drvdata(rdev);
305 int id = rdev_get_id(rdev);
306
307 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
308
309 return mc13783_set_bits(priv->mc13783, mc13783_regulators[id].reg,
310 mc13783_regulators[id].enable_bit, 0);
311}
312
313static int mc13783_is_enabled(struct regulator_dev *rdev)
314{
315 struct mc13783_priv *priv = rdev_get_drvdata(rdev);
316 int ret, id = rdev_get_id(rdev);
317 unsigned int val;
318
319 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val);
320 if (ret)
321 return ret;
322
323 return (val & mc13783_regulators[id].enable_bit) != 0;
324}
325
326static struct regulator_ops mc13783_regulator_ops = {
327 .enable = mc13783_enable,
328 .disable = mc13783_disable,
329 .is_enabled = mc13783_is_enabled,
330};
331
332static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
333{
334 struct mc13783_priv *priv;
335 struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent);
336 struct mc13783_regulator_init_data *init_data;
337 int i, ret;
338
339 dev_dbg(&pdev->dev, "mc13783_regulator_probe id %d\n", pdev->id);
340
341 priv = kzalloc(sizeof(*priv) + mc13783->num_regulators * sizeof(void *),
342 GFP_KERNEL);
343 if (!priv)
344 return -ENOMEM;
345
346 priv->mc13783 = mc13783;
347
348 for (i = 0; i < mc13783->num_regulators; i++) {
349 init_data = &mc13783->regulators[i];
350 priv->regulators[i] = regulator_register(
351 &mc13783_regulators[init_data->id].desc,
352 &pdev->dev, init_data->init_data, priv);
353
354 if (IS_ERR(priv->regulators[i])) {
355 dev_err(&pdev->dev, "failed to register regulator %s\n",
356 mc13783_regulators[i].desc.name);
357 ret = PTR_ERR(priv->regulators[i]);
358 goto err;
359 }
360 }
361
362 platform_set_drvdata(pdev, priv);
363
364 return 0;
365err:
366 while (--i >= 0)
367 regulator_unregister(priv->regulators[i]);
368
369 kfree(priv);
370
371 return ret;
372}
373
374static int __devexit mc13783_regulator_remove(struct platform_device *pdev)
375{
376 struct mc13783_priv *priv = platform_get_drvdata(pdev);
377 struct mc13783 *mc13783 = priv->mc13783;
378 int i;
379
380 for (i = 0; i < mc13783->num_regulators; i++)
381 regulator_unregister(priv->regulators[i]);
382
383 return 0;
384}
385
386static struct platform_driver mc13783_regulator_driver = {
387 .driver = {
388 .name = "mc13783-regulator",
389 .owner = THIS_MODULE,
390 },
391 .remove = __devexit_p(mc13783_regulator_remove),
392};
393
394static int __init mc13783_regulator_init(void)
395{
396 return platform_driver_probe(&mc13783_regulator_driver,
397 mc13783_regulator_probe);
398}
399subsys_initcall(mc13783_regulator_init);
400
401static void __exit mc13783_regulator_exit(void)
402{
403 platform_driver_unregister(&mc13783_regulator_driver);
404}
405module_exit(mc13783_regulator_exit);
406
407MODULE_LICENSE("GPL");
408MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
409MODULE_DESCRIPTION("Regulator Driver for Freescale MC13783 PMIC");
410MODULE_ALIAS("platform:mc13783-regulator");
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c
index 33d7d899e030..29d0566379ae 100644
--- a/drivers/regulator/pcap-regulator.c
+++ b/drivers/regulator/pcap-regulator.c
@@ -288,16 +288,18 @@ static int __devexit pcap_regulator_remove(struct platform_device *pdev)
288 struct regulator_dev *rdev = platform_get_drvdata(pdev); 288 struct regulator_dev *rdev = platform_get_drvdata(pdev);
289 289
290 regulator_unregister(rdev); 290 regulator_unregister(rdev);
291 platform_set_drvdata(pdev, NULL);
291 292
292 return 0; 293 return 0;
293} 294}
294 295
295static struct platform_driver pcap_regulator_driver = { 296static struct platform_driver pcap_regulator_driver = {
296 .driver = { 297 .driver = {
297 .name = "pcap-regulator", 298 .name = "pcap-regulator",
299 .owner = THIS_MODULE,
298 }, 300 },
299 .probe = pcap_regulator_probe, 301 .probe = pcap_regulator_probe,
300 .remove = __devexit_p(pcap_regulator_remove), 302 .remove = __devexit_p(pcap_regulator_remove),
301}; 303};
302 304
303static int __init pcap_regulator_init(void) 305static int __init pcap_regulator_init(void)
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index 0803ffe6236d..c8f41dc05b76 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -314,13 +314,15 @@ static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
314 struct pcf50633 *pcf; 314 struct pcf50633 *pcf;
315 315
316 /* Already set by core driver */ 316 /* Already set by core driver */
317 pcf = platform_get_drvdata(pdev); 317 pcf = dev_to_pcf50633(pdev->dev.parent);
318 318
319 rdev = regulator_register(&regulators[pdev->id], &pdev->dev, 319 rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
320 pdev->dev.platform_data, pcf); 320 pdev->dev.platform_data, pcf);
321 if (IS_ERR(rdev)) 321 if (IS_ERR(rdev))
322 return PTR_ERR(rdev); 322 return PTR_ERR(rdev);
323 323
324 platform_set_drvdata(pdev, rdev);
325
324 if (pcf->pdata->regulator_registered) 326 if (pcf->pdata->regulator_registered)
325 pcf->pdata->regulator_registered(pcf, pdev->id); 327 pcf->pdata->regulator_registered(pcf, pdev->id);
326 328
@@ -331,6 +333,7 @@ static int __devexit pcf50633_regulator_remove(struct platform_device *pdev)
331{ 333{
332 struct regulator_dev *rdev = platform_get_drvdata(pdev); 334 struct regulator_dev *rdev = platform_get_drvdata(pdev);
333 335
336 platform_set_drvdata(pdev, NULL);
334 regulator_unregister(rdev); 337 regulator_unregister(rdev);
335 338
336 return 0; 339 return 0;
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index 07fda0a75adf..8e2f2098b005 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -24,6 +24,7 @@
24#include <linux/regulator/machine.h> 24#include <linux/regulator/machine.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h>
27 28
28/* Register definitions */ 29/* Register definitions */
29#define TPS65023_REG_VERSION 0 30#define TPS65023_REG_VERSION 0
@@ -457,8 +458,8 @@ static struct regulator_ops tps65023_ldo_ops = {
457 .list_voltage = tps65023_ldo_list_voltage, 458 .list_voltage = tps65023_ldo_list_voltage,
458}; 459};
459 460
460static 461static int __devinit tps_65023_probe(struct i2c_client *client,
461int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) 462 const struct i2c_device_id *id)
462{ 463{
463 static int desc_id; 464 static int desc_id;
464 const struct tps_info *info = (void *)id->driver_data; 465 const struct tps_info *info = (void *)id->driver_data;
@@ -466,6 +467,7 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id)
466 struct regulator_dev *rdev; 467 struct regulator_dev *rdev;
467 struct tps_pmic *tps; 468 struct tps_pmic *tps;
468 int i; 469 int i;
470 int error;
469 471
470 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 472 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
471 return -EIO; 473 return -EIO;
@@ -475,7 +477,6 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id)
475 * coming from the board-evm file. 477 * coming from the board-evm file.
476 */ 478 */
477 init_data = client->dev.platform_data; 479 init_data = client->dev.platform_data;
478
479 if (!init_data) 480 if (!init_data)
480 return -EIO; 481 return -EIO;
481 482
@@ -502,21 +503,12 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id)
502 503
503 /* Register the regulators */ 504 /* Register the regulators */
504 rdev = regulator_register(&tps->desc[i], &client->dev, 505 rdev = regulator_register(&tps->desc[i], &client->dev,
505 init_data, tps); 506 init_data, tps);
506 if (IS_ERR(rdev)) { 507 if (IS_ERR(rdev)) {
507 dev_err(&client->dev, "failed to register %s\n", 508 dev_err(&client->dev, "failed to register %s\n",
508 id->name); 509 id->name);
509 510 error = PTR_ERR(rdev);
510 /* Unregister */ 511 goto fail;
511 while (i)
512 regulator_unregister(tps->rdev[--i]);
513
514 tps->client = NULL;
515
516 /* clear the client data in i2c */
517 i2c_set_clientdata(client, NULL);
518 kfree(tps);
519 return PTR_ERR(rdev);
520 } 512 }
521 513
522 /* Save regulator for cleanup */ 514 /* Save regulator for cleanup */
@@ -526,6 +518,13 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id)
526 i2c_set_clientdata(client, tps); 518 i2c_set_clientdata(client, tps);
527 519
528 return 0; 520 return 0;
521
522 fail:
523 while (--i >= 0)
524 regulator_unregister(tps->rdev[i]);
525
526 kfree(tps);
527 return error;
529} 528}
530 529
531/** 530/**
@@ -539,13 +538,12 @@ static int __devexit tps_65023_remove(struct i2c_client *client)
539 struct tps_pmic *tps = i2c_get_clientdata(client); 538 struct tps_pmic *tps = i2c_get_clientdata(client);
540 int i; 539 int i;
541 540
541 /* clear the client data in i2c */
542 i2c_set_clientdata(client, NULL);
543
542 for (i = 0; i < TPS65023_NUM_REGULATOR; i++) 544 for (i = 0; i < TPS65023_NUM_REGULATOR; i++)
543 regulator_unregister(tps->rdev[i]); 545 regulator_unregister(tps->rdev[i]);
544 546
545 tps->client = NULL;
546
547 /* clear the client data in i2c */
548 i2c_set_clientdata(client, NULL);
549 kfree(tps); 547 kfree(tps);
550 548
551 return 0; 549 return 0;
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index f8a6dfbef751..74841abcc9cc 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -24,6 +24,7 @@
24#include <linux/regulator/machine.h> 24#include <linux/regulator/machine.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h>
27 28
28/* Register definitions */ 29/* Register definitions */
29#define TPS6507X_REG_PPATH1 0X01 30#define TPS6507X_REG_PPATH1 0X01
@@ -538,8 +539,8 @@ static struct regulator_ops tps6507x_ldo_ops = {
538 .list_voltage = tps6507x_ldo_list_voltage, 539 .list_voltage = tps6507x_ldo_list_voltage,
539}; 540};
540 541
541static 542static int __devinit tps_6507x_probe(struct i2c_client *client,
542int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) 543 const struct i2c_device_id *id)
543{ 544{
544 static int desc_id; 545 static int desc_id;
545 const struct tps_info *info = (void *)id->driver_data; 546 const struct tps_info *info = (void *)id->driver_data;
@@ -547,6 +548,7 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id)
547 struct regulator_dev *rdev; 548 struct regulator_dev *rdev;
548 struct tps_pmic *tps; 549 struct tps_pmic *tps;
549 int i; 550 int i;
551 int error;
550 552
551 if (!i2c_check_functionality(client->adapter, 553 if (!i2c_check_functionality(client->adapter,
552 I2C_FUNC_SMBUS_BYTE_DATA)) 554 I2C_FUNC_SMBUS_BYTE_DATA))
@@ -557,7 +559,6 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id)
557 * coming from the board-evm file. 559 * coming from the board-evm file.
558 */ 560 */
559 init_data = client->dev.platform_data; 561 init_data = client->dev.platform_data;
560
561 if (!init_data) 562 if (!init_data)
562 return -EIO; 563 return -EIO;
563 564
@@ -586,18 +587,8 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id)
586 if (IS_ERR(rdev)) { 587 if (IS_ERR(rdev)) {
587 dev_err(&client->dev, "failed to register %s\n", 588 dev_err(&client->dev, "failed to register %s\n",
588 id->name); 589 id->name);
589 590 error = PTR_ERR(rdev);
590 /* Unregister */ 591 goto fail;
591 while (i)
592 regulator_unregister(tps->rdev[--i]);
593
594 tps->client = NULL;
595
596 /* clear the client data in i2c */
597 i2c_set_clientdata(client, NULL);
598
599 kfree(tps);
600 return PTR_ERR(rdev);
601 } 592 }
602 593
603 /* Save regulator for cleanup */ 594 /* Save regulator for cleanup */
@@ -607,6 +598,13 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id)
607 i2c_set_clientdata(client, tps); 598 i2c_set_clientdata(client, tps);
608 599
609 return 0; 600 return 0;
601
602fail:
603 while (--i >= 0)
604 regulator_unregister(tps->rdev[i]);
605
606 kfree(tps);
607 return error;
610} 608}
611 609
612/** 610/**
@@ -620,13 +618,12 @@ static int __devexit tps_6507x_remove(struct i2c_client *client)
620 struct tps_pmic *tps = i2c_get_clientdata(client); 618 struct tps_pmic *tps = i2c_get_clientdata(client);
621 int i; 619 int i;
622 620
621 /* clear the client data in i2c */
622 i2c_set_clientdata(client, NULL);
623
623 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) 624 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
624 regulator_unregister(tps->rdev[i]); 625 regulator_unregister(tps->rdev[i]);
625 626
626 tps->client = NULL;
627
628 /* clear the client data in i2c */
629 i2c_set_clientdata(client, NULL);
630 kfree(tps); 627 kfree(tps);
631 628
632 return 0; 629 return 0;
diff --git a/drivers/regulator/twl4030-regulator.c b/drivers/regulator/twl-regulator.c
index e2032fb60b55..9729d760fb4d 100644
--- a/drivers/regulator/twl4030-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * twl4030-regulator.c -- support regulators in twl4030 family chips 2 * twl-regulator.c -- support regulators in twl4030/twl6030 family chips
3 * 3 *
4 * Copyright (C) 2008 David Brownell 4 * Copyright (C) 2008 David Brownell
5 * 5 *
@@ -12,14 +12,15 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/delay.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
16#include <linux/regulator/driver.h> 17#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h> 18#include <linux/regulator/machine.h>
18#include <linux/i2c/twl4030.h> 19#include <linux/i2c/twl.h>
19 20
20 21
21/* 22/*
22 * The TWL4030/TW5030/TPS659x0 family chips include power management, a 23 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
23 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions 24 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
24 * include an audio codec, battery charger, and more voltage regulators. 25 * include an audio codec, battery charger, and more voltage regulators.
25 * These chips are often used in OMAP-based systems. 26 * These chips are often used in OMAP-based systems.
@@ -33,13 +34,19 @@ struct twlreg_info {
33 /* start of regulator's PM_RECEIVER control register bank */ 34 /* start of regulator's PM_RECEIVER control register bank */
34 u8 base; 35 u8 base;
35 36
36 /* twl4030 resource ID, for resource control state machine */ 37 /* twl resource ID, for resource control state machine */
37 u8 id; 38 u8 id;
38 39
39 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ 40 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
40 u8 table_len; 41 u8 table_len;
41 const u16 *table; 42 const u16 *table;
42 43
44 /* regulator specific turn-on delay */
45 u16 delay;
46
47 /* State REMAP default configuration */
48 u8 remap;
49
43 /* chip constraints on regulator behavior */ 50 /* chip constraints on regulator behavior */
44 u16 min_mV; 51 u16 min_mV;
45 52
@@ -52,27 +59,38 @@ struct twlreg_info {
52 * The first three registers of all power resource banks help hardware to 59 * The first three registers of all power resource banks help hardware to
53 * manage the various resource groups. 60 * manage the various resource groups.
54 */ 61 */
62/* Common offset in TWL4030/6030 */
55#define VREG_GRP 0 63#define VREG_GRP 0
64/* TWL4030 register offsets */
56#define VREG_TYPE 1 65#define VREG_TYPE 1
57#define VREG_REMAP 2 66#define VREG_REMAP 2
58#define VREG_DEDICATED 3 /* LDO control */ 67#define VREG_DEDICATED 3 /* LDO control */
59 68/* TWL6030 register offsets */
69#define VREG_TRANS 1
70#define VREG_STATE 2
71#define VREG_VOLTAGE 3
72/* TWL6030 Misc register offsets */
73#define VREG_BC_ALL 1
74#define VREG_BC_REF 2
75#define VREG_BC_PROC 3
76#define VREG_BC_CLK_RST 4
60 77
61static inline int 78static inline int
62twl4030reg_read(struct twlreg_info *info, unsigned offset) 79twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
63{ 80{
64 u8 value; 81 u8 value;
65 int status; 82 int status;
66 83
67 status = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, 84 status = twl_i2c_read_u8(slave_subgp,
68 &value, info->base + offset); 85 &value, info->base + offset);
69 return (status < 0) ? status : value; 86 return (status < 0) ? status : value;
70} 87}
71 88
72static inline int 89static inline int
73twl4030reg_write(struct twlreg_info *info, unsigned offset, u8 value) 90twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
91 u8 value)
74{ 92{
75 return twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 93 return twl_i2c_write_u8(slave_subgp,
76 value, info->base + offset); 94 value, info->base + offset);
77} 95}
78 96
@@ -80,59 +98,84 @@ twl4030reg_write(struct twlreg_info *info, unsigned offset, u8 value)
80 98
81/* generic power resource operations, which work on all regulators */ 99/* generic power resource operations, which work on all regulators */
82 100
83static int twl4030reg_grp(struct regulator_dev *rdev) 101static int twlreg_grp(struct regulator_dev *rdev)
84{ 102{
85 return twl4030reg_read(rdev_get_drvdata(rdev), VREG_GRP); 103 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
104 VREG_GRP);
86} 105}
87 106
88/* 107/*
89 * Enable/disable regulators by joining/leaving the P1 (processor) group. 108 * Enable/disable regulators by joining/leaving the P1 (processor) group.
90 * We assume nobody else is updating the DEV_GRP registers. 109 * We assume nobody else is updating the DEV_GRP registers.
91 */ 110 */
92 111/* definition for 4030 family */
93#define P3_GRP BIT(7) /* "peripherals" */ 112#define P3_GRP_4030 BIT(7) /* "peripherals" */
94#define P2_GRP BIT(6) /* secondary processor, modem, etc */ 113#define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
95#define P1_GRP BIT(5) /* CPU/Linux */ 114#define P1_GRP_4030 BIT(5) /* CPU/Linux */
96 115/* definition for 6030 family */
97static int twl4030reg_is_enabled(struct regulator_dev *rdev) 116#define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
117#define P2_GRP_6030 BIT(1) /* "peripherals" */
118#define P1_GRP_6030 BIT(0) /* CPU/Linux */
119
120static int twlreg_is_enabled(struct regulator_dev *rdev)
98{ 121{
99 int state = twl4030reg_grp(rdev); 122 int state = twlreg_grp(rdev);
100 123
101 if (state < 0) 124 if (state < 0)
102 return state; 125 return state;
103 126
104 return (state & P1_GRP) != 0; 127 if (twl_class_is_4030())
128 state &= P1_GRP_4030;
129 else
130 state &= P1_GRP_6030;
131 return state;
105} 132}
106 133
107static int twl4030reg_enable(struct regulator_dev *rdev) 134static int twlreg_enable(struct regulator_dev *rdev)
108{ 135{
109 struct twlreg_info *info = rdev_get_drvdata(rdev); 136 struct twlreg_info *info = rdev_get_drvdata(rdev);
110 int grp; 137 int grp;
138 int ret;
111 139
112 grp = twl4030reg_read(info, VREG_GRP); 140 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
113 if (grp < 0) 141 if (grp < 0)
114 return grp; 142 return grp;
115 143
116 grp |= P1_GRP; 144 if (twl_class_is_4030())
117 return twl4030reg_write(info, VREG_GRP, grp); 145 grp |= P1_GRP_4030;
146 else
147 grp |= P1_GRP_6030;
148
149 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
150
151 udelay(info->delay);
152
153 return ret;
118} 154}
119 155
120static int twl4030reg_disable(struct regulator_dev *rdev) 156static int twlreg_disable(struct regulator_dev *rdev)
121{ 157{
122 struct twlreg_info *info = rdev_get_drvdata(rdev); 158 struct twlreg_info *info = rdev_get_drvdata(rdev);
123 int grp; 159 int grp;
124 160
125 grp = twl4030reg_read(info, VREG_GRP); 161 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
126 if (grp < 0) 162 if (grp < 0)
127 return grp; 163 return grp;
128 164
129 grp &= ~P1_GRP; 165 if (twl_class_is_4030())
130 return twl4030reg_write(info, VREG_GRP, grp); 166 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
167 else
168 grp &= ~(P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030);
169
170 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
131} 171}
132 172
133static int twl4030reg_get_status(struct regulator_dev *rdev) 173static int twlreg_get_status(struct regulator_dev *rdev)
134{ 174{
135 int state = twl4030reg_grp(rdev); 175 int state = twlreg_grp(rdev);
176
177 if (twl_class_is_6030())
178 return 0; /* FIXME return for 6030 regulator */
136 179
137 if (state < 0) 180 if (state < 0)
138 return state; 181 return state;
@@ -146,12 +189,15 @@ static int twl4030reg_get_status(struct regulator_dev *rdev)
146 : REGULATOR_STATUS_STANDBY; 189 : REGULATOR_STATUS_STANDBY;
147} 190}
148 191
149static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 192static int twlreg_set_mode(struct regulator_dev *rdev, unsigned mode)
150{ 193{
151 struct twlreg_info *info = rdev_get_drvdata(rdev); 194 struct twlreg_info *info = rdev_get_drvdata(rdev);
152 unsigned message; 195 unsigned message;
153 int status; 196 int status;
154 197
198 if (twl_class_is_6030())
199 return 0; /* FIXME return for 6030 regulator */
200
155 /* We can only set the mode through state machine commands... */ 201 /* We can only set the mode through state machine commands... */
156 switch (mode) { 202 switch (mode) {
157 case REGULATOR_MODE_NORMAL: 203 case REGULATOR_MODE_NORMAL:
@@ -165,18 +211,18 @@ static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
165 } 211 }
166 212
167 /* Ensure the resource is associated with some group */ 213 /* Ensure the resource is associated with some group */
168 status = twl4030reg_grp(rdev); 214 status = twlreg_grp(rdev);
169 if (status < 0) 215 if (status < 0)
170 return status; 216 return status;
171 if (!(status & (P3_GRP | P2_GRP | P1_GRP))) 217 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
172 return -EACCES; 218 return -EACCES;
173 219
174 status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 220 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
175 message >> 8, 0x15 /* PB_WORD_MSB */ ); 221 message >> 8, 0x15 /* PB_WORD_MSB */ );
176 if (status >= 0) 222 if (status >= 0)
177 return status; 223 return status;
178 224
179 return twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 225 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
180 message, 0x16 /* PB_WORD_LSB */ ); 226 message, 0x16 /* PB_WORD_LSB */ );
181} 227}
182 228
@@ -260,9 +306,43 @@ static const u16 VSIM_VSEL_table[] = {
260static const u16 VDAC_VSEL_table[] = { 306static const u16 VDAC_VSEL_table[] = {
261 1200, 1300, 1800, 1800, 307 1200, 1300, 1800, 1800,
262}; 308};
309static const u16 VDD1_VSEL_table[] = {
310 800, 1450,
311};
312static const u16 VDD2_VSEL_table[] = {
313 800, 1450, 1500,
314};
315static const u16 VIO_VSEL_table[] = {
316 1800, 1850,
317};
318static const u16 VINTANA2_VSEL_table[] = {
319 2500, 2750,
320};
321static const u16 VAUX1_6030_VSEL_table[] = {
322 1000, 1300, 1800, 2500,
323 2800, 2900, 3000, 3000,
324};
325static const u16 VAUX2_6030_VSEL_table[] = {
326 1200, 1800, 2500, 2750,
327 2800, 2800, 2800, 2800,
328};
329static const u16 VAUX3_6030_VSEL_table[] = {
330 1000, 1200, 1300, 1800,
331 2500, 2800, 3000, 3000,
332};
333static const u16 VMMC_VSEL_table[] = {
334 1200, 1800, 2800, 2900,
335 3000, 3000, 3000, 3000,
336};
337static const u16 VPP_VSEL_table[] = {
338 1800, 1900, 2000, 2100,
339 2200, 2300, 2400, 2500,
340};
341static const u16 VUSIM_VSEL_table[] = {
342 1200, 1800, 2500, 2900,
343};
263 344
264 345static int twlldo_list_voltage(struct regulator_dev *rdev, unsigned index)
265static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
266{ 346{
267 struct twlreg_info *info = rdev_get_drvdata(rdev); 347 struct twlreg_info *info = rdev_get_drvdata(rdev);
268 int mV = info->table[index]; 348 int mV = info->table[index];
@@ -271,7 +351,7 @@ static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
271} 351}
272 352
273static int 353static int
274twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 354twlldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
275{ 355{
276 struct twlreg_info *info = rdev_get_drvdata(rdev); 356 struct twlreg_info *info = rdev_get_drvdata(rdev);
277 int vsel; 357 int vsel;
@@ -288,16 +368,18 @@ twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
288 368
289 /* use the first in-range value */ 369 /* use the first in-range value */
290 if (min_uV <= uV && uV <= max_uV) 370 if (min_uV <= uV && uV <= max_uV)
291 return twl4030reg_write(info, VREG_DEDICATED, vsel); 371 return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
372 VREG_VOLTAGE, vsel);
292 } 373 }
293 374
294 return -EDOM; 375 return -EDOM;
295} 376}
296 377
297static int twl4030ldo_get_voltage(struct regulator_dev *rdev) 378static int twlldo_get_voltage(struct regulator_dev *rdev)
298{ 379{
299 struct twlreg_info *info = rdev_get_drvdata(rdev); 380 struct twlreg_info *info = rdev_get_drvdata(rdev);
300 int vsel = twl4030reg_read(info, VREG_DEDICATED); 381 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
382 VREG_VOLTAGE);
301 383
302 if (vsel < 0) 384 if (vsel < 0)
303 return vsel; 385 return vsel;
@@ -306,19 +388,19 @@ static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
306 return LDO_MV(info->table[vsel]) * 1000; 388 return LDO_MV(info->table[vsel]) * 1000;
307} 389}
308 390
309static struct regulator_ops twl4030ldo_ops = { 391static struct regulator_ops twlldo_ops = {
310 .list_voltage = twl4030ldo_list_voltage, 392 .list_voltage = twlldo_list_voltage,
311 393
312 .set_voltage = twl4030ldo_set_voltage, 394 .set_voltage = twlldo_set_voltage,
313 .get_voltage = twl4030ldo_get_voltage, 395 .get_voltage = twlldo_get_voltage,
314 396
315 .enable = twl4030reg_enable, 397 .enable = twlreg_enable,
316 .disable = twl4030reg_disable, 398 .disable = twlreg_disable,
317 .is_enabled = twl4030reg_is_enabled, 399 .is_enabled = twlreg_is_enabled,
318 400
319 .set_mode = twl4030reg_set_mode, 401 .set_mode = twlreg_set_mode,
320 402
321 .get_status = twl4030reg_get_status, 403 .get_status = twlreg_get_status,
322}; 404};
323 405
324/*----------------------------------------------------------------------*/ 406/*----------------------------------------------------------------------*/
@@ -326,60 +408,82 @@ static struct regulator_ops twl4030ldo_ops = {
326/* 408/*
327 * Fixed voltage LDOs don't have a VSEL field to update. 409 * Fixed voltage LDOs don't have a VSEL field to update.
328 */ 410 */
329static int twl4030fixed_list_voltage(struct regulator_dev *rdev, unsigned index) 411static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
330{ 412{
331 struct twlreg_info *info = rdev_get_drvdata(rdev); 413 struct twlreg_info *info = rdev_get_drvdata(rdev);
332 414
333 return info->min_mV * 1000; 415 return info->min_mV * 1000;
334} 416}
335 417
336static int twl4030fixed_get_voltage(struct regulator_dev *rdev) 418static int twlfixed_get_voltage(struct regulator_dev *rdev)
337{ 419{
338 struct twlreg_info *info = rdev_get_drvdata(rdev); 420 struct twlreg_info *info = rdev_get_drvdata(rdev);
339 421
340 return info->min_mV * 1000; 422 return info->min_mV * 1000;
341} 423}
342 424
343static struct regulator_ops twl4030fixed_ops = { 425static struct regulator_ops twlfixed_ops = {
344 .list_voltage = twl4030fixed_list_voltage, 426 .list_voltage = twlfixed_list_voltage,
345 427
346 .get_voltage = twl4030fixed_get_voltage, 428 .get_voltage = twlfixed_get_voltage,
347 429
348 .enable = twl4030reg_enable, 430 .enable = twlreg_enable,
349 .disable = twl4030reg_disable, 431 .disable = twlreg_disable,
350 .is_enabled = twl4030reg_is_enabled, 432 .is_enabled = twlreg_is_enabled,
351 433
352 .set_mode = twl4030reg_set_mode, 434 .set_mode = twlreg_set_mode,
353 435
354 .get_status = twl4030reg_get_status, 436 .get_status = twlreg_get_status,
355}; 437};
356 438
357/*----------------------------------------------------------------------*/ 439/*----------------------------------------------------------------------*/
358 440
359#define TWL_ADJUSTABLE_LDO(label, offset, num) { \ 441#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
442 TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \
443 remap_conf, TWL4030)
444#define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
445 remap_conf) \
446 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
447 remap_conf, TWL4030)
448#define TWL6030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \
449 remap_conf) \
450 TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \
451 remap_conf, TWL6030)
452#define TWL6030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
453 remap_conf) \
454 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
455 remap_conf, TWL6030)
456
457#define TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf, \
458 family) { \
360 .base = offset, \ 459 .base = offset, \
361 .id = num, \ 460 .id = num, \
362 .table_len = ARRAY_SIZE(label##_VSEL_table), \ 461 .table_len = ARRAY_SIZE(label##_VSEL_table), \
363 .table = label##_VSEL_table, \ 462 .table = label##_VSEL_table, \
463 .delay = turnon_delay, \
464 .remap = remap_conf, \
364 .desc = { \ 465 .desc = { \
365 .name = #label, \ 466 .name = #label, \
366 .id = TWL4030_REG_##label, \ 467 .id = family##_REG_##label, \
367 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ 468 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
368 .ops = &twl4030ldo_ops, \ 469 .ops = &twlldo_ops, \
369 .type = REGULATOR_VOLTAGE, \ 470 .type = REGULATOR_VOLTAGE, \
370 .owner = THIS_MODULE, \ 471 .owner = THIS_MODULE, \
371 }, \ 472 }, \
372 } 473 }
373 474
374#define TWL_FIXED_LDO(label, offset, mVolts, num) { \ 475#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
476 family) { \
375 .base = offset, \ 477 .base = offset, \
376 .id = num, \ 478 .id = num, \
377 .min_mV = mVolts, \ 479 .min_mV = mVolts, \
480 .delay = turnon_delay, \
481 .remap = remap_conf, \
378 .desc = { \ 482 .desc = { \
379 .name = #label, \ 483 .name = #label, \
380 .id = TWL4030_REG_##label, \ 484 .id = family##_REG_##label, \
381 .n_voltages = 1, \ 485 .n_voltages = 1, \
382 .ops = &twl4030fixed_ops, \ 486 .ops = &twlfixed_ops, \
383 .type = REGULATOR_VOLTAGE, \ 487 .type = REGULATOR_VOLTAGE, \
384 .owner = THIS_MODULE, \ 488 .owner = THIS_MODULE, \
385 }, \ 489 }, \
@@ -389,35 +493,45 @@ static struct regulator_ops twl4030fixed_ops = {
389 * We list regulators here if systems need some level of 493 * We list regulators here if systems need some level of
390 * software control over them after boot. 494 * software control over them after boot.
391 */ 495 */
392static struct twlreg_info twl4030_regs[] = { 496static struct twlreg_info twl_regs[] = {
393 TWL_ADJUSTABLE_LDO(VAUX1, 0x17, 1), 497 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
394 TWL_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2), 498 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
395 TWL_ADJUSTABLE_LDO(VAUX2, 0x1b, 2), 499 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
396 TWL_ADJUSTABLE_LDO(VAUX3, 0x1f, 3), 500 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
397 TWL_ADJUSTABLE_LDO(VAUX4, 0x23, 4), 501 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
398 TWL_ADJUSTABLE_LDO(VMMC1, 0x27, 5), 502 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
399 TWL_ADJUSTABLE_LDO(VMMC2, 0x2b, 6), 503 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
400 /* 504 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
401 TWL_ADJUSTABLE_LDO(VPLL1, 0x2f, 7), 505 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
402 */ 506 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
403 TWL_ADJUSTABLE_LDO(VPLL2, 0x33, 8), 507 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
404 TWL_ADJUSTABLE_LDO(VSIM, 0x37, 9), 508 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
405 TWL_ADJUSTABLE_LDO(VDAC, 0x3b, 10), 509 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
406 /* 510 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
407 TWL_ADJUSTABLE_LDO(VINTANA1, 0x3f, 11), 511 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
408 TWL_ADJUSTABLE_LDO(VINTANA2, 0x43, 12), 512 TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
409 TWL_ADJUSTABLE_LDO(VINTDIG, 0x47, 13), 513 TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
410 TWL_SMPS(VIO, 0x4b, 14), 514 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
411 TWL_SMPS(VDD1, 0x55, 15), 515 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
412 TWL_SMPS(VDD2, 0x63, 16), 516 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
413 */
414 TWL_FIXED_LDO(VUSB1V5, 0x71, 1500, 17),
415 TWL_FIXED_LDO(VUSB1V8, 0x74, 1800, 18),
416 TWL_FIXED_LDO(VUSB3V1, 0x77, 3100, 19),
417 /* VUSBCP is managed *only* by the USB subchip */ 517 /* VUSBCP is managed *only* by the USB subchip */
518
519 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
520 /* Turnon-delay and remap configuration values for 6030 are not
521 verified since the specification is not public */
522 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1, 0, 0x21),
523 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 2, 0, 0x21),
524 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 3, 0, 0x21),
525 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 4, 0, 0x21),
526 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 5, 0, 0x21),
527 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 7, 0, 0x21),
528 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0, 0x21),
529 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0, 0x21),
530 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0, 0x21),
531 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0, 0x21)
418}; 532};
419 533
420static int twl4030reg_probe(struct platform_device *pdev) 534static int __devinit twlreg_probe(struct platform_device *pdev)
421{ 535{
422 int i; 536 int i;
423 struct twlreg_info *info; 537 struct twlreg_info *info;
@@ -425,10 +539,10 @@ static int twl4030reg_probe(struct platform_device *pdev)
425 struct regulation_constraints *c; 539 struct regulation_constraints *c;
426 struct regulator_dev *rdev; 540 struct regulator_dev *rdev;
427 541
428 for (i = 0, info = NULL; i < ARRAY_SIZE(twl4030_regs); i++) { 542 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
429 if (twl4030_regs[i].desc.id != pdev->id) 543 if (twl_regs[i].desc.id != pdev->id)
430 continue; 544 continue;
431 info = twl4030_regs + i; 545 info = twl_regs + i;
432 break; 546 break;
433 } 547 }
434 if (!info) 548 if (!info)
@@ -446,6 +560,19 @@ static int twl4030reg_probe(struct platform_device *pdev)
446 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 560 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
447 | REGULATOR_CHANGE_MODE 561 | REGULATOR_CHANGE_MODE
448 | REGULATOR_CHANGE_STATUS; 562 | REGULATOR_CHANGE_STATUS;
563 switch (pdev->id) {
564 case TWL4030_REG_VIO:
565 case TWL4030_REG_VDD1:
566 case TWL4030_REG_VDD2:
567 case TWL4030_REG_VPLL1:
568 case TWL4030_REG_VINTANA1:
569 case TWL4030_REG_VINTANA2:
570 case TWL4030_REG_VINTDIG:
571 c->always_on = true;
572 break;
573 default:
574 break;
575 }
449 576
450 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info); 577 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
451 if (IS_ERR(rdev)) { 578 if (IS_ERR(rdev)) {
@@ -455,6 +582,9 @@ static int twl4030reg_probe(struct platform_device *pdev)
455 } 582 }
456 platform_set_drvdata(pdev, rdev); 583 platform_set_drvdata(pdev, rdev);
457 584
585 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
586 info->remap);
587
458 /* NOTE: many regulators support short-circuit IRQs (presentable 588 /* NOTE: many regulators support short-circuit IRQs (presentable
459 * as REGULATOR_OVER_CURRENT notifications?) configured via: 589 * as REGULATOR_OVER_CURRENT notifications?) configured via:
460 * - SC_CONFIG 590 * - SC_CONFIG
@@ -466,35 +596,35 @@ static int twl4030reg_probe(struct platform_device *pdev)
466 return 0; 596 return 0;
467} 597}
468 598
469static int __devexit twl4030reg_remove(struct platform_device *pdev) 599static int __devexit twlreg_remove(struct platform_device *pdev)
470{ 600{
471 regulator_unregister(platform_get_drvdata(pdev)); 601 regulator_unregister(platform_get_drvdata(pdev));
472 return 0; 602 return 0;
473} 603}
474 604
475MODULE_ALIAS("platform:twl4030_reg"); 605MODULE_ALIAS("platform:twl_reg");
476 606
477static struct platform_driver twl4030reg_driver = { 607static struct platform_driver twlreg_driver = {
478 .probe = twl4030reg_probe, 608 .probe = twlreg_probe,
479 .remove = __devexit_p(twl4030reg_remove), 609 .remove = __devexit_p(twlreg_remove),
480 /* NOTE: short name, to work around driver model truncation of 610 /* NOTE: short name, to work around driver model truncation of
481 * "twl4030_regulator.12" (and friends) to "twl4030_regulator.1". 611 * "twl_regulator.12" (and friends) to "twl_regulator.1".
482 */ 612 */
483 .driver.name = "twl4030_reg", 613 .driver.name = "twl_reg",
484 .driver.owner = THIS_MODULE, 614 .driver.owner = THIS_MODULE,
485}; 615};
486 616
487static int __init twl4030reg_init(void) 617static int __init twlreg_init(void)
488{ 618{
489 return platform_driver_register(&twl4030reg_driver); 619 return platform_driver_register(&twlreg_driver);
490} 620}
491subsys_initcall(twl4030reg_init); 621subsys_initcall(twlreg_init);
492 622
493static void __exit twl4030reg_exit(void) 623static void __exit twlreg_exit(void)
494{ 624{
495 platform_driver_unregister(&twl4030reg_driver); 625 platform_driver_unregister(&twlreg_driver);
496} 626}
497module_exit(twl4030reg_exit) 627module_exit(twlreg_exit)
498 628
499MODULE_DESCRIPTION("TWL4030 regulator driver"); 629MODULE_DESCRIPTION("TWL regulator driver");
500MODULE_LICENSE("GPL"); 630MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 44917da4ac97..9d5ba9357597 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -21,6 +21,7 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/regulator/consumer.h> 22#include <linux/regulator/consumer.h>
23#include <linux/regulator/userspace-consumer.h> 23#include <linux/regulator/userspace-consumer.h>
24#include <linux/slab.h>
24 25
25struct userspace_consumer_data { 26struct userspace_consumer_data {
26 const char *name; 27 const char *name;
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c
index addc032c84bf..69e550f57638 100644
--- a/drivers/regulator/virtual.c
+++ b/drivers/regulator/virtual.c
@@ -15,11 +15,12 @@
15#include <linux/mutex.h> 15#include <linux/mutex.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/slab.h>
18 19
19struct virtual_consumer_data { 20struct virtual_consumer_data {
20 struct mutex lock; 21 struct mutex lock;
21 struct regulator *regulator; 22 struct regulator *regulator;
22 int enabled; 23 bool enabled;
23 int min_uV; 24 int min_uV;
24 int max_uV; 25 int max_uV;
25 int min_uA; 26 int min_uA;
@@ -49,7 +50,7 @@ static void update_voltage_constraints(struct device *dev,
49 dev_dbg(dev, "Enabling regulator\n"); 50 dev_dbg(dev, "Enabling regulator\n");
50 ret = regulator_enable(data->regulator); 51 ret = regulator_enable(data->regulator);
51 if (ret == 0) 52 if (ret == 0)
52 data->enabled = 1; 53 data->enabled = true;
53 else 54 else
54 dev_err(dev, "regulator_enable() failed: %d\n", 55 dev_err(dev, "regulator_enable() failed: %d\n",
55 ret); 56 ret);
@@ -59,7 +60,7 @@ static void update_voltage_constraints(struct device *dev,
59 dev_dbg(dev, "Disabling regulator\n"); 60 dev_dbg(dev, "Disabling regulator\n");
60 ret = regulator_disable(data->regulator); 61 ret = regulator_disable(data->regulator);
61 if (ret == 0) 62 if (ret == 0)
62 data->enabled = 0; 63 data->enabled = false;
63 else 64 else
64 dev_err(dev, "regulator_disable() failed: %d\n", 65 dev_err(dev, "regulator_disable() failed: %d\n",
65 ret); 66 ret);
@@ -89,7 +90,7 @@ static void update_current_limit_constraints(struct device *dev,
89 dev_dbg(dev, "Enabling regulator\n"); 90 dev_dbg(dev, "Enabling regulator\n");
90 ret = regulator_enable(data->regulator); 91 ret = regulator_enable(data->regulator);
91 if (ret == 0) 92 if (ret == 0)
92 data->enabled = 1; 93 data->enabled = true;
93 else 94 else
94 dev_err(dev, "regulator_enable() failed: %d\n", 95 dev_err(dev, "regulator_enable() failed: %d\n",
95 ret); 96 ret);
@@ -99,7 +100,7 @@ static void update_current_limit_constraints(struct device *dev,
99 dev_dbg(dev, "Disabling regulator\n"); 100 dev_dbg(dev, "Disabling regulator\n");
100 ret = regulator_disable(data->regulator); 101 ret = regulator_disable(data->regulator);
101 if (ret == 0) 102 if (ret == 0)
102 data->enabled = 0; 103 data->enabled = false;
103 else 104 else
104 dev_err(dev, "regulator_disable() failed: %d\n", 105 dev_err(dev, "regulator_disable() failed: %d\n",
105 ret); 106 ret);
@@ -270,24 +271,28 @@ static DEVICE_ATTR(min_microamps, 0666, show_min_uA, set_min_uA);
270static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); 271static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA);
271static DEVICE_ATTR(mode, 0666, show_mode, set_mode); 272static DEVICE_ATTR(mode, 0666, show_mode, set_mode);
272 273
273static struct device_attribute *attributes[] = { 274static struct attribute *regulator_virtual_attributes[] = {
274 &dev_attr_min_microvolts, 275 &dev_attr_min_microvolts.attr,
275 &dev_attr_max_microvolts, 276 &dev_attr_max_microvolts.attr,
276 &dev_attr_min_microamps, 277 &dev_attr_min_microamps.attr,
277 &dev_attr_max_microamps, 278 &dev_attr_max_microamps.attr,
278 &dev_attr_mode, 279 &dev_attr_mode.attr,
280 NULL
279}; 281};
280 282
281static int regulator_virtual_consumer_probe(struct platform_device *pdev) 283static const struct attribute_group regulator_virtual_attr_group = {
284 .attrs = regulator_virtual_attributes,
285};
286
287static int __devinit regulator_virtual_probe(struct platform_device *pdev)
282{ 288{
283 char *reg_id = pdev->dev.platform_data; 289 char *reg_id = pdev->dev.platform_data;
284 struct virtual_consumer_data *drvdata; 290 struct virtual_consumer_data *drvdata;
285 int ret, i; 291 int ret;
286 292
287 drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); 293 drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL);
288 if (drvdata == NULL) { 294 if (drvdata == NULL)
289 return -ENOMEM; 295 return -ENOMEM;
290 }
291 296
292 mutex_init(&drvdata->lock); 297 mutex_init(&drvdata->lock);
293 298
@@ -299,13 +304,12 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev)
299 goto err; 304 goto err;
300 } 305 }
301 306
302 for (i = 0; i < ARRAY_SIZE(attributes); i++) { 307 ret = sysfs_create_group(&pdev->dev.kobj,
303 ret = device_create_file(&pdev->dev, attributes[i]); 308 &regulator_virtual_attr_group);
304 if (ret != 0) { 309 if (ret != 0) {
305 dev_err(&pdev->dev, "Failed to create attr %d: %d\n", 310 dev_err(&pdev->dev,
306 i, ret); 311 "Failed to create attribute group: %d\n", ret);
307 goto err_regulator; 312 goto err_regulator;
308 }
309 } 313 }
310 314
311 drvdata->mode = regulator_get_mode(drvdata->regulator); 315 drvdata->mode = regulator_get_mode(drvdata->regulator);
@@ -317,37 +321,36 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev)
317err_regulator: 321err_regulator:
318 regulator_put(drvdata->regulator); 322 regulator_put(drvdata->regulator);
319err: 323err:
320 for (i = 0; i < ARRAY_SIZE(attributes); i++)
321 device_remove_file(&pdev->dev, attributes[i]);
322 kfree(drvdata); 324 kfree(drvdata);
323 return ret; 325 return ret;
324} 326}
325 327
326static int regulator_virtual_consumer_remove(struct platform_device *pdev) 328static int __devexit regulator_virtual_remove(struct platform_device *pdev)
327{ 329{
328 struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev); 330 struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev);
329 int i;
330 331
331 for (i = 0; i < ARRAY_SIZE(attributes); i++) 332 sysfs_remove_group(&pdev->dev.kobj, &regulator_virtual_attr_group);
332 device_remove_file(&pdev->dev, attributes[i]); 333
333 if (drvdata->enabled) 334 if (drvdata->enabled)
334 regulator_disable(drvdata->regulator); 335 regulator_disable(drvdata->regulator);
335 regulator_put(drvdata->regulator); 336 regulator_put(drvdata->regulator);
336 337
337 kfree(drvdata); 338 kfree(drvdata);
338 339
340 platform_set_drvdata(pdev, NULL);
341
339 return 0; 342 return 0;
340} 343}
341 344
342static struct platform_driver regulator_virtual_consumer_driver = { 345static struct platform_driver regulator_virtual_consumer_driver = {
343 .probe = regulator_virtual_consumer_probe, 346 .probe = regulator_virtual_probe,
344 .remove = regulator_virtual_consumer_remove, 347 .remove = __devexit_p(regulator_virtual_remove),
345 .driver = { 348 .driver = {
346 .name = "reg-virt-consumer", 349 .name = "reg-virt-consumer",
350 .owner = THIS_MODULE,
347 }, 351 },
348}; 352};
349 353
350
351static int __init regulator_virtual_consumer_init(void) 354static int __init regulator_virtual_consumer_init(void)
352{ 355{
353 return platform_driver_register(&regulator_virtual_consumer_driver); 356 return platform_driver_register(&regulator_virtual_consumer_driver);
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 2eefc1a0cf08..dbfaf5945e48 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -19,6 +19,9 @@
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h> 21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/gpio.h>
24#include <linux/slab.h>
22 25
23#include <linux/mfd/wm831x/core.h> 26#include <linux/mfd/wm831x/core.h>
24#include <linux/mfd/wm831x/regulator.h> 27#include <linux/mfd/wm831x/regulator.h>
@@ -39,6 +42,7 @@
39#define WM831X_DCDC_CONTROL_2 1 42#define WM831X_DCDC_CONTROL_2 1
40#define WM831X_DCDC_ON_CONFIG 2 43#define WM831X_DCDC_ON_CONFIG 2
41#define WM831X_DCDC_SLEEP_CONTROL 3 44#define WM831X_DCDC_SLEEP_CONTROL 3
45#define WM831X_DCDC_DVS_CONTROL 4
42 46
43/* 47/*
44 * Shared 48 * Shared
@@ -50,6 +54,10 @@ struct wm831x_dcdc {
50 int base; 54 int base;
51 struct wm831x *wm831x; 55 struct wm831x *wm831x;
52 struct regulator_dev *regulator; 56 struct regulator_dev *regulator;
57 int dvs_gpio;
58 int dvs_gpio_state;
59 int on_vsel;
60 int dvs_vsel;
53}; 61};
54 62
55static int wm831x_dcdc_is_enabled(struct regulator_dev *rdev) 63static int wm831x_dcdc_is_enabled(struct regulator_dev *rdev)
@@ -240,11 +248,9 @@ static int wm831x_buckv_list_voltage(struct regulator_dev *rdev,
240 return -EINVAL; 248 return -EINVAL;
241} 249}
242 250
243static int wm831x_buckv_set_voltage_int(struct regulator_dev *rdev, int reg, 251static int wm831x_buckv_select_min_voltage(struct regulator_dev *rdev,
244 int min_uV, int max_uV) 252 int min_uV, int max_uV)
245{ 253{
246 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
247 struct wm831x *wm831x = dcdc->wm831x;
248 u16 vsel; 254 u16 vsel;
249 255
250 if (min_uV < 600000) 256 if (min_uV < 600000)
@@ -257,39 +263,126 @@ static int wm831x_buckv_set_voltage_int(struct regulator_dev *rdev, int reg,
257 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV) 263 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
258 return -EINVAL; 264 return -EINVAL;
259 265
260 return wm831x_set_bits(wm831x, reg, WM831X_DC1_ON_VSEL_MASK, vsel); 266 return vsel;
267}
268
269static int wm831x_buckv_select_max_voltage(struct regulator_dev *rdev,
270 int min_uV, int max_uV)
271{
272 u16 vsel;
273
274 if (max_uV < 600000 || max_uV > 1800000)
275 return -EINVAL;
276
277 vsel = ((max_uV - 600000) / 12500) + 8;
278
279 if (wm831x_buckv_list_voltage(rdev, vsel) < min_uV ||
280 wm831x_buckv_list_voltage(rdev, vsel) < max_uV)
281 return -EINVAL;
282
283 return vsel;
284}
285
286static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
287{
288 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
289
290 if (state == dcdc->dvs_gpio_state)
291 return 0;
292
293 dcdc->dvs_gpio_state = state;
294 gpio_set_value(dcdc->dvs_gpio, state);
295
296 /* Should wait for DVS state change to be asserted if we have
297 * a GPIO for it, for now assume the device is configured
298 * for the fastest possible transition.
299 */
300
301 return 0;
261} 302}
262 303
263static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, 304static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
264 int min_uV, int max_uV) 305 int min_uV, int max_uV)
265{ 306{
266 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 307 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
267 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 308 struct wm831x *wm831x = dcdc->wm831x;
309 int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
310 int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL;
311 int vsel, ret;
312
313 vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV);
314 if (vsel < 0)
315 return vsel;
316
317 /* If this value is already set then do a GPIO update if we can */
318 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel)
319 return wm831x_buckv_set_dvs(rdev, 0);
320
321 if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel)
322 return wm831x_buckv_set_dvs(rdev, 1);
323
324 /* Always set the ON status to the minimum voltage */
325 ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel);
326 if (ret < 0)
327 return ret;
328 dcdc->on_vsel = vsel;
329
330 if (!dcdc->dvs_gpio)
331 return ret;
332
333 /* Kick the voltage transition now */
334 ret = wm831x_buckv_set_dvs(rdev, 0);
335 if (ret < 0)
336 return ret;
337
338 /* Set the high voltage as the DVS voltage. This is optimised
339 * for CPUfreq usage, most processors will keep the maximum
340 * voltage constant and lower the minimum with the frequency. */
341 vsel = wm831x_buckv_select_max_voltage(rdev, min_uV, max_uV);
342 if (vsel < 0) {
343 /* This should never happen - at worst the same vsel
344 * should be chosen */
345 WARN_ON(vsel < 0);
346 return 0;
347 }
348
349 /* Don't bother if it's the same VSEL we're already using */
350 if (vsel == dcdc->on_vsel)
351 return 0;
352
353 ret = wm831x_set_bits(wm831x, dvs_reg, WM831X_DC1_DVS_VSEL_MASK, vsel);
354 if (ret == 0)
355 dcdc->dvs_vsel = vsel;
356 else
357 dev_warn(wm831x->dev, "Failed to set DCDC DVS VSEL: %d\n",
358 ret);
268 359
269 return wm831x_buckv_set_voltage_int(rdev, reg, min_uV, max_uV); 360 return 0;
270} 361}
271 362
272static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev, 363static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
273 int uV) 364 int uV)
274{ 365{
275 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 366 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
367 struct wm831x *wm831x = dcdc->wm831x;
276 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 368 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
369 int vsel;
277 370
278 return wm831x_buckv_set_voltage_int(rdev, reg, uV, uV); 371 vsel = wm831x_buckv_select_min_voltage(rdev, uV, uV);
372 if (vsel < 0)
373 return vsel;
374
375 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel);
279} 376}
280 377
281static int wm831x_buckv_get_voltage(struct regulator_dev *rdev) 378static int wm831x_buckv_get_voltage(struct regulator_dev *rdev)
282{ 379{
283 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 380 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
284 struct wm831x *wm831x = dcdc->wm831x;
285 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
286 int val;
287
288 val = wm831x_reg_read(wm831x, reg);
289 if (val < 0)
290 return val;
291 381
292 return wm831x_buckv_list_voltage(rdev, val & WM831X_DC1_ON_VSEL_MASK); 382 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state)
383 return wm831x_buckv_list_voltage(rdev, dcdc->dvs_vsel);
384 else
385 return wm831x_buckv_list_voltage(rdev, dcdc->on_vsel);
293} 386}
294 387
295/* Current limit options */ 388/* Current limit options */
@@ -346,6 +439,64 @@ static struct regulator_ops wm831x_buckv_ops = {
346 .set_suspend_mode = wm831x_dcdc_set_suspend_mode, 439 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
347}; 440};
348 441
442/*
443 * Set up DVS control. We just log errors since we can still run
444 * (with reduced performance) if we fail.
445 */
446static __devinit void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc,
447 struct wm831x_buckv_pdata *pdata)
448{
449 struct wm831x *wm831x = dcdc->wm831x;
450 int ret;
451 u16 ctrl;
452
453 if (!pdata || !pdata->dvs_gpio)
454 return;
455
456 switch (pdata->dvs_control_src) {
457 case 1:
458 ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT;
459 break;
460 case 2:
461 ctrl = 3 << WM831X_DC1_DVS_SRC_SHIFT;
462 break;
463 default:
464 dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n",
465 pdata->dvs_control_src, dcdc->name);
466 return;
467 }
468
469 ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL,
470 WM831X_DC1_DVS_SRC_MASK, ctrl);
471 if (ret < 0) {
472 dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n",
473 dcdc->name, ret);
474 return;
475 }
476
477 ret = gpio_request(pdata->dvs_gpio, "DCDC DVS");
478 if (ret < 0) {
479 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n",
480 dcdc->name, ret);
481 return;
482 }
483
484 /* gpiolib won't let us read the GPIO status so pick the higher
485 * of the two existing voltages so we take it as platform data.
486 */
487 dcdc->dvs_gpio_state = pdata->dvs_init_state;
488
489 ret = gpio_direction_output(pdata->dvs_gpio, dcdc->dvs_gpio_state);
490 if (ret < 0) {
491 dev_err(wm831x->dev, "Failed to enable %s DVS GPIO: %d\n",
492 dcdc->name, ret);
493 gpio_free(pdata->dvs_gpio);
494 return;
495 }
496
497 dcdc->dvs_gpio = pdata->dvs_gpio;
498}
499
349static __devinit int wm831x_buckv_probe(struct platform_device *pdev) 500static __devinit int wm831x_buckv_probe(struct platform_device *pdev)
350{ 501{
351 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 502 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
@@ -384,6 +535,23 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev)
384 dcdc->desc.ops = &wm831x_buckv_ops; 535 dcdc->desc.ops = &wm831x_buckv_ops;
385 dcdc->desc.owner = THIS_MODULE; 536 dcdc->desc.owner = THIS_MODULE;
386 537
538 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
539 if (ret < 0) {
540 dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret);
541 goto err;
542 }
543 dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK;
544
545 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
546 if (ret < 0) {
547 dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret);
548 goto err;
549 }
550 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
551
552 if (pdata->dcdc[id])
553 wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data);
554
387 dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev, 555 dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev,
388 pdata->dcdc[id], dcdc); 556 pdata->dcdc[id], dcdc);
389 if (IS_ERR(dcdc->regulator)) { 557 if (IS_ERR(dcdc->regulator)) {
@@ -422,6 +590,8 @@ err_uv:
422err_regulator: 590err_regulator:
423 regulator_unregister(dcdc->regulator); 591 regulator_unregister(dcdc->regulator);
424err: 592err:
593 if (dcdc->dvs_gpio)
594 gpio_free(dcdc->dvs_gpio);
425 kfree(dcdc); 595 kfree(dcdc);
426 return ret; 596 return ret;
427} 597}
@@ -431,9 +601,13 @@ static __devexit int wm831x_buckv_remove(struct platform_device *pdev)
431 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); 601 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
432 struct wm831x *wm831x = dcdc->wm831x; 602 struct wm831x *wm831x = dcdc->wm831x;
433 603
604 platform_set_drvdata(pdev, NULL);
605
434 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "HC"), dcdc); 606 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "HC"), dcdc);
435 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); 607 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc);
436 regulator_unregister(dcdc->regulator); 608 regulator_unregister(dcdc->regulator);
609 if (dcdc->dvs_gpio)
610 gpio_free(dcdc->dvs_gpio);
437 kfree(dcdc); 611 kfree(dcdc);
438 612
439 return 0; 613 return 0;
@@ -444,6 +618,7 @@ static struct platform_driver wm831x_buckv_driver = {
444 .remove = __devexit_p(wm831x_buckv_remove), 618 .remove = __devexit_p(wm831x_buckv_remove),
445 .driver = { 619 .driver = {
446 .name = "wm831x-buckv", 620 .name = "wm831x-buckv",
621 .owner = THIS_MODULE,
447 }, 622 },
448}; 623};
449 624
@@ -598,6 +773,8 @@ static __devexit int wm831x_buckp_remove(struct platform_device *pdev)
598 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); 773 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
599 struct wm831x *wm831x = dcdc->wm831x; 774 struct wm831x *wm831x = dcdc->wm831x;
600 775
776 platform_set_drvdata(pdev, NULL);
777
601 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); 778 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc);
602 regulator_unregister(dcdc->regulator); 779 regulator_unregister(dcdc->regulator);
603 kfree(dcdc); 780 kfree(dcdc);
@@ -610,6 +787,7 @@ static struct platform_driver wm831x_buckp_driver = {
610 .remove = __devexit_p(wm831x_buckp_remove), 787 .remove = __devexit_p(wm831x_buckp_remove),
611 .driver = { 788 .driver = {
612 .name = "wm831x-buckp", 789 .name = "wm831x-buckp",
790 .owner = THIS_MODULE,
613 }, 791 },
614}; 792};
615 793
@@ -724,6 +902,8 @@ static __devexit int wm831x_boostp_remove(struct platform_device *pdev)
724 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); 902 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
725 struct wm831x *wm831x = dcdc->wm831x; 903 struct wm831x *wm831x = dcdc->wm831x;
726 904
905 platform_set_drvdata(pdev, NULL);
906
727 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); 907 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc);
728 regulator_unregister(dcdc->regulator); 908 regulator_unregister(dcdc->regulator);
729 kfree(dcdc); 909 kfree(dcdc);
@@ -736,6 +916,7 @@ static struct platform_driver wm831x_boostp_driver = {
736 .remove = __devexit_p(wm831x_boostp_remove), 916 .remove = __devexit_p(wm831x_boostp_remove),
737 .driver = { 917 .driver = {
738 .name = "wm831x-boostp", 918 .name = "wm831x-boostp",
919 .owner = THIS_MODULE,
739 }, 920 },
740}; 921};
741 922
@@ -808,6 +989,8 @@ static __devexit int wm831x_epe_remove(struct platform_device *pdev)
808{ 989{
809 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); 990 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
810 991
992 platform_set_drvdata(pdev, NULL);
993
811 regulator_unregister(dcdc->regulator); 994 regulator_unregister(dcdc->regulator);
812 kfree(dcdc); 995 kfree(dcdc);
813 996
@@ -819,6 +1002,7 @@ static struct platform_driver wm831x_epe_driver = {
819 .remove = __devexit_p(wm831x_epe_remove), 1002 .remove = __devexit_p(wm831x_epe_remove),
820 .driver = { 1003 .driver = {
821 .name = "wm831x-epe", 1004 .name = "wm831x-epe",
1005 .owner = THIS_MODULE,
822 }, 1006 },
823}; 1007};
824 1008
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c
index 48857008758c..6c446cd6ad54 100644
--- a/drivers/regulator/wm831x-isink.c
+++ b/drivers/regulator/wm831x-isink.c
@@ -19,6 +19,7 @@
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h> 21#include <linux/regulator/driver.h>
22#include <linux/slab.h>
22 23
23#include <linux/mfd/wm831x/core.h> 24#include <linux/mfd/wm831x/core.h>
24#include <linux/mfd/wm831x/regulator.h> 25#include <linux/mfd/wm831x/regulator.h>
@@ -222,6 +223,8 @@ static __devexit int wm831x_isink_remove(struct platform_device *pdev)
222 struct wm831x_isink *isink = platform_get_drvdata(pdev); 223 struct wm831x_isink *isink = platform_get_drvdata(pdev);
223 struct wm831x *wm831x = isink->wm831x; 224 struct wm831x *wm831x = isink->wm831x;
224 225
226 platform_set_drvdata(pdev, NULL);
227
225 wm831x_free_irq(wm831x, platform_get_irq(pdev, 0), isink); 228 wm831x_free_irq(wm831x, platform_get_irq(pdev, 0), isink);
226 229
227 regulator_unregister(isink->regulator); 230 regulator_unregister(isink->regulator);
@@ -235,6 +238,7 @@ static struct platform_driver wm831x_isink_driver = {
235 .remove = __devexit_p(wm831x_isink_remove), 238 .remove = __devexit_p(wm831x_isink_remove),
236 .driver = { 239 .driver = {
237 .name = "wm831x-isink", 240 .name = "wm831x-isink",
241 .owner = THIS_MODULE,
238 }, 242 },
239}; 243};
240 244
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 902db56ce099..e686cdb61b97 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -19,6 +19,7 @@
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h> 21#include <linux/regulator/driver.h>
22#include <linux/slab.h>
22 23
23#include <linux/mfd/wm831x/core.h> 24#include <linux/mfd/wm831x/core.h>
24#include <linux/mfd/wm831x/regulator.h> 25#include <linux/mfd/wm831x/regulator.h>
@@ -371,6 +372,8 @@ static __devexit int wm831x_gp_ldo_remove(struct platform_device *pdev)
371 struct wm831x_ldo *ldo = platform_get_drvdata(pdev); 372 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
372 struct wm831x *wm831x = ldo->wm831x; 373 struct wm831x *wm831x = ldo->wm831x;
373 374
375 platform_set_drvdata(pdev, NULL);
376
374 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), ldo); 377 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), ldo);
375 regulator_unregister(ldo->regulator); 378 regulator_unregister(ldo->regulator);
376 kfree(ldo); 379 kfree(ldo);
@@ -383,6 +386,7 @@ static struct platform_driver wm831x_gp_ldo_driver = {
383 .remove = __devexit_p(wm831x_gp_ldo_remove), 386 .remove = __devexit_p(wm831x_gp_ldo_remove),
384 .driver = { 387 .driver = {
385 .name = "wm831x-ldo", 388 .name = "wm831x-ldo",
389 .owner = THIS_MODULE,
386 }, 390 },
387}; 391};
388 392
@@ -470,7 +474,7 @@ static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
470 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 474 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
471 struct wm831x *wm831x = ldo->wm831x; 475 struct wm831x *wm831x = ldo->wm831x;
472 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; 476 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
473 unsigned int ret; 477 int ret;
474 478
475 ret = wm831x_reg_read(wm831x, on_reg); 479 ret = wm831x_reg_read(wm831x, on_reg);
476 if (ret < 0) 480 if (ret < 0)
@@ -640,6 +644,7 @@ static struct platform_driver wm831x_aldo_driver = {
640 .remove = __devexit_p(wm831x_aldo_remove), 644 .remove = __devexit_p(wm831x_aldo_remove),
641 .driver = { 645 .driver = {
642 .name = "wm831x-aldo", 646 .name = "wm831x-aldo",
647 .owner = THIS_MODULE,
643 }, 648 },
644}; 649};
645 650
@@ -811,6 +816,7 @@ static struct platform_driver wm831x_alive_ldo_driver = {
811 .remove = __devexit_p(wm831x_alive_ldo_remove), 816 .remove = __devexit_p(wm831x_alive_ldo_remove),
812 .driver = { 817 .driver = {
813 .name = "wm831x-alive-ldo", 818 .name = "wm831x-alive-ldo",
819 .owner = THIS_MODULE,
814 }, 820 },
815}; 821};
816 822
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index 768bd0e5b48b..723cd1fb4867 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -290,6 +290,51 @@ static int wm8350_isink_is_enabled(struct regulator_dev *rdev)
290 return -EINVAL; 290 return -EINVAL;
291} 291}
292 292
293static int wm8350_isink_enable_time(struct regulator_dev *rdev)
294{
295 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
296 int isink = rdev_get_id(rdev);
297 int reg;
298
299 switch (isink) {
300 case WM8350_ISINK_A:
301 reg = wm8350_reg_read(wm8350, WM8350_CSA_FLASH_CONTROL);
302 break;
303 case WM8350_ISINK_B:
304 reg = wm8350_reg_read(wm8350, WM8350_CSB_FLASH_CONTROL);
305 break;
306 default:
307 return -EINVAL;
308 }
309
310 if (reg & WM8350_CS1_FLASH_MODE) {
311 switch (reg & WM8350_CS1_ON_RAMP_MASK) {
312 case 0:
313 return 0;
314 case 1:
315 return 1950;
316 case 2:
317 return 3910;
318 case 3:
319 return 7800;
320 }
321 } else {
322 switch (reg & WM8350_CS1_ON_RAMP_MASK) {
323 case 0:
324 return 0;
325 case 1:
326 return 250000;
327 case 2:
328 return 500000;
329 case 3:
330 return 1000000;
331 }
332 }
333
334 return -EINVAL;
335}
336
337
293int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, 338int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
294 u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp, 339 u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp,
295 u16 drive) 340 u16 drive)
@@ -1221,6 +1266,7 @@ static struct regulator_ops wm8350_isink_ops = {
1221 .enable = wm8350_isink_enable, 1266 .enable = wm8350_isink_enable,
1222 .disable = wm8350_isink_disable, 1267 .disable = wm8350_isink_disable,
1223 .is_enabled = wm8350_isink_is_enabled, 1268 .is_enabled = wm8350_isink_is_enabled,
1269 .enable_time = wm8350_isink_enable_time,
1224}; 1270};
1225 1271
1226static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { 1272static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
@@ -1330,9 +1376,10 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1330 }, 1376 },
1331}; 1377};
1332 1378
1333static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data) 1379static irqreturn_t pmic_uv_handler(int irq, void *data)
1334{ 1380{
1335 struct regulator_dev *rdev = (struct regulator_dev *)data; 1381 struct regulator_dev *rdev = (struct regulator_dev *)data;
1382 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1336 1383
1337 mutex_lock(&rdev->mutex); 1384 mutex_lock(&rdev->mutex);
1338 if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) 1385 if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2)
@@ -1344,6 +1391,8 @@ static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data)
1344 REGULATOR_EVENT_UNDER_VOLTAGE, 1391 REGULATOR_EVENT_UNDER_VOLTAGE,
1345 wm8350); 1392 wm8350);
1346 mutex_unlock(&rdev->mutex); 1393 mutex_unlock(&rdev->mutex);
1394
1395 return IRQ_HANDLED;
1347} 1396}
1348 1397
1349static int wm8350_regulator_probe(struct platform_device *pdev) 1398static int wm8350_regulator_probe(struct platform_device *pdev)
@@ -1388,7 +1437,7 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1388 1437
1389 /* register regulator IRQ */ 1438 /* register regulator IRQ */
1390 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq, 1439 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
1391 pmic_uv_handler, rdev); 1440 pmic_uv_handler, 0, "UV", rdev);
1392 if (ret < 0) { 1441 if (ret < 0) {
1393 regulator_unregister(rdev); 1442 regulator_unregister(rdev);
1394 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n", 1443 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
@@ -1396,8 +1445,6 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1396 return ret; 1445 return ret;
1397 } 1446 }
1398 1447
1399 wm8350_unmask_irq(wm8350, wm8350_reg[pdev->id].irq);
1400
1401 return 0; 1448 return 0;
1402} 1449}
1403 1450
@@ -1406,8 +1453,7 @@ static int wm8350_regulator_remove(struct platform_device *pdev)
1406 struct regulator_dev *rdev = platform_get_drvdata(pdev); 1453 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1407 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 1454 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1408 1455
1409 wm8350_mask_irq(wm8350, wm8350_reg[pdev->id].irq); 1456 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev);
1410 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq);
1411 1457
1412 regulator_unregister(rdev); 1458 regulator_unregister(rdev);
1413 1459
@@ -1504,7 +1550,8 @@ int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink,
1504 led->isink_init.consumer_supplies = &led->isink_consumer; 1550 led->isink_init.consumer_supplies = &led->isink_consumer;
1505 led->isink_init.constraints.min_uA = 0; 1551 led->isink_init.constraints.min_uA = 0;
1506 led->isink_init.constraints.max_uA = pdata->max_uA; 1552 led->isink_init.constraints.max_uA = pdata->max_uA;
1507 led->isink_init.constraints.valid_ops_mask = REGULATOR_CHANGE_CURRENT; 1553 led->isink_init.constraints.valid_ops_mask
1554 = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS;
1508 led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL; 1555 led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
1509 ret = wm8350_register_regulator(wm8350, isink, &led->isink_init); 1556 ret = wm8350_register_regulator(wm8350, isink, &led->isink_init);
1510 if (ret != 0) { 1557 if (ret != 0) {
@@ -1517,6 +1564,7 @@ int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink,
1517 led->dcdc_init.num_consumer_supplies = 1; 1564 led->dcdc_init.num_consumer_supplies = 1;
1518 led->dcdc_init.consumer_supplies = &led->dcdc_consumer; 1565 led->dcdc_init.consumer_supplies = &led->dcdc_consumer;
1519 led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL; 1566 led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
1567 led->dcdc_init.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
1520 ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init); 1568 ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init);
1521 if (ret != 0) { 1569 if (ret != 0) {
1522 platform_device_put(pdev); 1570 platform_device_put(pdev);
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index d9a2c988c6e7..924c7eb29ee9 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -317,14 +317,17 @@ static struct regulator_desc regulators[] = {
317 317
318static int __devinit wm8400_regulator_probe(struct platform_device *pdev) 318static int __devinit wm8400_regulator_probe(struct platform_device *pdev)
319{ 319{
320 struct wm8400 *wm8400 = container_of(pdev, struct wm8400, regulators[pdev->id]);
320 struct regulator_dev *rdev; 321 struct regulator_dev *rdev;
321 322
322 rdev = regulator_register(&regulators[pdev->id], &pdev->dev, 323 rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
323 pdev->dev.platform_data, dev_get_drvdata(&pdev->dev)); 324 pdev->dev.platform_data, wm8400);
324 325
325 if (IS_ERR(rdev)) 326 if (IS_ERR(rdev))
326 return PTR_ERR(rdev); 327 return PTR_ERR(rdev);
327 328
329 platform_set_drvdata(pdev, rdev);
330
328 return 0; 331 return 0;
329} 332}
330 333
@@ -332,6 +335,7 @@ static int __devexit wm8400_regulator_remove(struct platform_device *pdev)
332{ 335{
333 struct regulator_dev *rdev = platform_get_drvdata(pdev); 336 struct regulator_dev *rdev = platform_get_drvdata(pdev);
334 337
338 platform_set_drvdata(pdev, NULL);
335 regulator_unregister(rdev); 339 regulator_unregister(rdev);
336 340
337 return 0; 341 return 0;
@@ -370,7 +374,6 @@ int wm8400_register_regulator(struct device *dev, int reg,
370 wm8400->regulators[reg].id = reg; 374 wm8400->regulators[reg].id = reg;
371 wm8400->regulators[reg].dev.parent = dev; 375 wm8400->regulators[reg].dev.parent = dev;
372 wm8400->regulators[reg].dev.platform_data = initdata; 376 wm8400->regulators[reg].dev.platform_data = initdata;
373 dev_set_drvdata(&wm8400->regulators[reg].dev, wm8400);
374 377
375 return platform_device_register(&wm8400->regulators[reg]); 378 return platform_device_register(&wm8400->regulators[reg]);
376} 379}
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
new file mode 100644
index 000000000000..5a1dc8a24d35
--- /dev/null
+++ b/drivers/regulator/wm8994-regulator.c
@@ -0,0 +1,308 @@
1/*
2 * wm8994-regulator.c -- Regulator driver for the WM8994
3 *
4 * Copyright 2009 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/bitops.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/gpio.h>
22#include <linux/slab.h>
23
24#include <linux/mfd/wm8994/core.h>
25#include <linux/mfd/wm8994/registers.h>
26#include <linux/mfd/wm8994/pdata.h>
27
28struct wm8994_ldo {
29 int enable;
30 bool is_enabled;
31 struct regulator_dev *regulator;
32 struct wm8994 *wm8994;
33};
34
35#define WM8994_LDO1_MAX_SELECTOR 0x7
36#define WM8994_LDO2_MAX_SELECTOR 0x3
37
38static int wm8994_ldo_enable(struct regulator_dev *rdev)
39{
40 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
41
42 /* If we have no soft control assume that the LDO is always enabled. */
43 if (!ldo->enable)
44 return 0;
45
46 gpio_set_value(ldo->enable, 1);
47 ldo->is_enabled = true;
48
49 return 0;
50}
51
52static int wm8994_ldo_disable(struct regulator_dev *rdev)
53{
54 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
55
56 /* If we have no soft control assume that the LDO is always enabled. */
57 if (!ldo->enable)
58 return -EINVAL;
59
60 gpio_set_value(ldo->enable, 0);
61 ldo->is_enabled = false;
62
63 return 0;
64}
65
66static int wm8994_ldo_is_enabled(struct regulator_dev *rdev)
67{
68 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
69
70 return ldo->is_enabled;
71}
72
73static int wm8994_ldo_enable_time(struct regulator_dev *rdev)
74{
75 /* 3ms is fairly conservative but this shouldn't be too performance
76 * critical; can be tweaked per-system if required. */
77 return 3000;
78}
79
80static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev,
81 unsigned int selector)
82{
83 if (selector > WM8994_LDO1_MAX_SELECTOR)
84 return -EINVAL;
85
86 return (selector * 100000) + 2400000;
87}
88
89static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev)
90{
91 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
92 int val;
93
94 val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_1);
95 if (val < 0)
96 return val;
97
98 val = (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT;
99
100 return wm8994_ldo1_list_voltage(rdev, val);
101}
102
103static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
104 int min_uV, int max_uV)
105{
106 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
107 int selector, v;
108
109 selector = (min_uV - 2400000) / 100000;
110 v = wm8994_ldo1_list_voltage(rdev, selector);
111 if (v < 0 || v > max_uV)
112 return -EINVAL;
113
114 selector <<= WM8994_LDO1_VSEL_SHIFT;
115
116 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1,
117 WM8994_LDO1_VSEL_MASK, selector);
118}
119
120static struct regulator_ops wm8994_ldo1_ops = {
121 .enable = wm8994_ldo_enable,
122 .disable = wm8994_ldo_disable,
123 .is_enabled = wm8994_ldo_is_enabled,
124 .enable_time = wm8994_ldo_enable_time,
125
126 .list_voltage = wm8994_ldo1_list_voltage,
127 .get_voltage = wm8994_ldo1_get_voltage,
128 .set_voltage = wm8994_ldo1_set_voltage,
129};
130
131static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
132 unsigned int selector)
133{
134 if (selector > WM8994_LDO2_MAX_SELECTOR)
135 return -EINVAL;
136
137 return (selector * 100000) + 900000;
138}
139
140static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev)
141{
142 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
143 int val;
144
145 val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_2);
146 if (val < 0)
147 return val;
148
149 val = (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT;
150
151 return wm8994_ldo2_list_voltage(rdev, val);
152}
153
154static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev,
155 int min_uV, int max_uV)
156{
157 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
158 int selector, v;
159
160 selector = (min_uV - 900000) / 100000;
161 v = wm8994_ldo2_list_voltage(rdev, selector);
162 if (v < 0 || v > max_uV)
163 return -EINVAL;
164
165 selector <<= WM8994_LDO2_VSEL_SHIFT;
166
167 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2,
168 WM8994_LDO2_VSEL_MASK, selector);
169}
170
171static struct regulator_ops wm8994_ldo2_ops = {
172 .enable = wm8994_ldo_enable,
173 .disable = wm8994_ldo_disable,
174 .is_enabled = wm8994_ldo_is_enabled,
175 .enable_time = wm8994_ldo_enable_time,
176
177 .list_voltage = wm8994_ldo2_list_voltage,
178 .get_voltage = wm8994_ldo2_get_voltage,
179 .set_voltage = wm8994_ldo2_set_voltage,
180};
181
182static struct regulator_desc wm8994_ldo_desc[] = {
183 {
184 .name = "LDO1",
185 .id = 1,
186 .type = REGULATOR_VOLTAGE,
187 .n_voltages = WM8994_LDO1_MAX_SELECTOR + 1,
188 .ops = &wm8994_ldo1_ops,
189 .owner = THIS_MODULE,
190 },
191 {
192 .name = "LDO2",
193 .id = 2,
194 .type = REGULATOR_VOLTAGE,
195 .n_voltages = WM8994_LDO2_MAX_SELECTOR + 1,
196 .ops = &wm8994_ldo2_ops,
197 .owner = THIS_MODULE,
198 },
199};
200
201static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
202{
203 struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
204 struct wm8994_pdata *pdata = wm8994->dev->platform_data;
205 int id = pdev->id % ARRAY_SIZE(pdata->ldo);
206 struct wm8994_ldo *ldo;
207 int ret;
208
209 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
210
211 if (!pdata)
212 return -ENODEV;
213
214 ldo = kzalloc(sizeof(struct wm8994_ldo), GFP_KERNEL);
215 if (ldo == NULL) {
216 dev_err(&pdev->dev, "Unable to allocate private data\n");
217 return -ENOMEM;
218 }
219
220 ldo->wm8994 = wm8994;
221
222 ldo->is_enabled = true;
223
224 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) {
225 ldo->enable = pdata->ldo[id].enable;
226
227 ret = gpio_request(ldo->enable, "WM8994 LDO enable");
228 if (ret < 0) {
229 dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n",
230 ret);
231 goto err;
232 }
233
234 ret = gpio_direction_output(ldo->enable, ldo->is_enabled);
235 if (ret < 0) {
236 dev_err(&pdev->dev, "Failed to set GPIO up: %d\n",
237 ret);
238 goto err_gpio;
239 }
240 }
241
242 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev,
243 pdata->ldo[id].init_data, ldo);
244 if (IS_ERR(ldo->regulator)) {
245 ret = PTR_ERR(ldo->regulator);
246 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
247 id + 1, ret);
248 goto err_gpio;
249 }
250
251 platform_set_drvdata(pdev, ldo);
252
253 return 0;
254
255err_gpio:
256 if (gpio_is_valid(ldo->enable))
257 gpio_free(ldo->enable);
258err:
259 kfree(ldo);
260 return ret;
261}
262
263static __devexit int wm8994_ldo_remove(struct platform_device *pdev)
264{
265 struct wm8994_ldo *ldo = platform_get_drvdata(pdev);
266
267 platform_set_drvdata(pdev, NULL);
268
269 regulator_unregister(ldo->regulator);
270 if (gpio_is_valid(ldo->enable))
271 gpio_free(ldo->enable);
272 kfree(ldo);
273
274 return 0;
275}
276
277static struct platform_driver wm8994_ldo_driver = {
278 .probe = wm8994_ldo_probe,
279 .remove = __devexit_p(wm8994_ldo_remove),
280 .driver = {
281 .name = "wm8994-ldo",
282 .owner = THIS_MODULE,
283 },
284};
285
286static int __init wm8994_ldo_init(void)
287{
288 int ret;
289
290 ret = platform_driver_register(&wm8994_ldo_driver);
291 if (ret != 0)
292 pr_err("Failed to register Wm8994 GP LDO driver: %d\n", ret);
293
294 return ret;
295}
296subsys_initcall(wm8994_ldo_init);
297
298static void __exit wm8994_ldo_exit(void)
299{
300 platform_driver_unregister(&wm8994_ldo_driver);
301}
302module_exit(wm8994_ldo_exit);
303
304/* Module information */
305MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
306MODULE_DESCRIPTION("WM8994 LDO driver");
307MODULE_LICENSE("GPL");
308MODULE_ALIAS("platform:wm8994-ldo");