Add linux-next specific files for 20110831
[linux-2.6/next.git] / drivers / regulator / tps65912-regulator.c
blob39d4a1749e71a78b3ad73907e407bb8d02435df3
1 /*
2 * tps65912.c -- TI tps65912
4 * Copyright 2011 Texas Instruments Inc.
6 * Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk>
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.
13 * This driver is based on wm8350 implementation.
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/err.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/gpio.h>
26 #include <linux/mfd/tps65912.h>
28 /* DCDC's */
29 #define TPS65912_REG_DCDC1 0
30 #define TPS65912_REG_DCDC2 1
31 #define TPS65912_REG_DCDC3 2
32 #define TPS65912_REG_DCDC4 3
34 /* LDOs */
35 #define TPS65912_REG_LDO1 4
36 #define TPS65912_REG_LDO2 5
37 #define TPS65912_REG_LDO3 6
38 #define TPS65912_REG_LDO4 7
39 #define TPS65912_REG_LDO5 8
40 #define TPS65912_REG_LDO6 9
41 #define TPS65912_REG_LDO7 10
42 #define TPS65912_REG_LDO8 11
43 #define TPS65912_REG_LDO9 12
44 #define TPS65912_REG_LDO10 13
46 /* Number of step-down converters available */
47 #define TPS65912_NUM_DCDC 4
49 /* Number of LDO voltage regulators available */
50 #define TPS65912_NUM_LDO 10
52 /* Number of total regulators available */
53 #define TPS65912_NUM_REGULATOR (TPS65912_NUM_DCDC + TPS65912_NUM_LDO)
55 #define TPS65912_REG_ENABLED 0x80
56 #define OP_SELREG_MASK 0x40
57 #define OP_SELREG_SHIFT 6
59 struct tps_info {
60 const char *name;
63 static struct tps_info tps65912_regs[] = {
65 .name = "DCDC1",
68 .name = "DCDC2",
71 .name = "DCDC3",
74 .name = "DCDC4",
77 .name = "LDO1",
80 .name = "LDO2",
83 .name = "LDO3",
86 .name = "LDO4",
89 .name = "LDO5",
92 .name = "LDO6",
95 .name = "LDO7",
98 .name = "LDO8",
101 .name = "LDO9",
104 .name = "LDO10",
108 struct tps65912_reg {
109 struct regulator_desc desc[TPS65912_NUM_REGULATOR];
110 struct tps65912 *mfd;
111 struct regulator_dev *rdev[TPS65912_NUM_REGULATOR];
112 struct tps_info *info[TPS65912_NUM_REGULATOR];
113 /* for read/write access */
114 struct mutex io_lock;
115 int mode;
116 int (*get_ctrl_reg)(int);
117 int dcdc1_range;
118 int dcdc2_range;
119 int dcdc3_range;
120 int dcdc4_range;
121 int pwm_mode_reg;
122 int eco_reg;
125 static int tps65912_get_range(struct tps65912_reg *pmic, int id)
127 struct tps65912 *mfd = pmic->mfd;
129 if (id > TPS65912_REG_DCDC4)
130 return 0;
132 switch (id) {
133 case TPS65912_REG_DCDC1:
134 pmic->dcdc1_range = tps65912_reg_read(mfd,
135 TPS65912_DCDC1_LIMIT);
136 if (pmic->dcdc1_range < 0)
137 return pmic->dcdc1_range;
138 pmic->dcdc1_range = (pmic->dcdc1_range &
139 DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT;
140 return pmic->dcdc1_range;
141 case TPS65912_REG_DCDC2:
142 pmic->dcdc2_range = tps65912_reg_read(mfd,
143 TPS65912_DCDC2_LIMIT);
144 if (pmic->dcdc2_range < 0)
145 return pmic->dcdc2_range;
146 pmic->dcdc2_range = (pmic->dcdc2_range &
147 DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT;
148 return pmic->dcdc2_range;
149 case TPS65912_REG_DCDC3:
150 pmic->dcdc3_range = tps65912_reg_read(mfd,
151 TPS65912_DCDC3_LIMIT);
152 if (pmic->dcdc3_range < 0)
153 return pmic->dcdc3_range;
154 pmic->dcdc3_range = (pmic->dcdc3_range &
155 DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT;
156 return pmic->dcdc3_range;
157 case TPS65912_REG_DCDC4:
158 pmic->dcdc4_range = tps65912_reg_read(mfd,
159 TPS65912_DCDC4_LIMIT);
160 if (pmic->dcdc4_range < 0)
161 return pmic->dcdc4_range;
162 pmic->dcdc4_range = (pmic->dcdc4_range &
163 DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT;
164 return pmic->dcdc4_range;
165 default:
166 return 0;
170 static unsigned long tps65912_vsel_to_uv_range0(u8 vsel)
172 unsigned long uv;
174 uv = ((vsel * 12500) + 500000);
175 return uv;
178 static unsigned long tps65912_vsel_to_uv_range1(u8 vsel)
180 unsigned long uv;
182 uv = ((vsel * 12500) + 700000);
183 return uv;
186 static unsigned long tps65912_vsel_to_uv_range2(u8 vsel)
188 unsigned long uv;
190 uv = ((vsel * 25000) + 500000);
191 return uv;
194 static unsigned long tps65912_vsel_to_uv_range3(u8 vsel)
196 unsigned long uv;
198 if (vsel == 0x3f)
199 uv = 3800000;
200 else
201 uv = ((vsel * 50000) + 500000);
203 return uv;
206 static unsigned long tps65912_vsel_to_uv_ldo(u8 vsel)
208 unsigned long uv = 0;
210 if (vsel <= 32)
211 uv = ((vsel * 25000) + 800000);
212 else if (vsel > 32 && vsel <= 60)
213 uv = (((vsel - 32) * 50000) + 1600000);
214 else if (vsel > 60)
215 uv = (((vsel - 60) * 100000) + 3000000);
217 return uv;
220 static int tps65912_get_ctrl_register(int id)
222 switch (id) {
223 case TPS65912_REG_DCDC1:
224 return TPS65912_DCDC1_AVS;
225 case TPS65912_REG_DCDC2:
226 return TPS65912_DCDC2_AVS;
227 case TPS65912_REG_DCDC3:
228 return TPS65912_DCDC3_AVS;
229 case TPS65912_REG_DCDC4:
230 return TPS65912_DCDC4_AVS;
231 case TPS65912_REG_LDO1:
232 return TPS65912_LDO1_AVS;
233 case TPS65912_REG_LDO2:
234 return TPS65912_LDO2_AVS;
235 case TPS65912_REG_LDO3:
236 return TPS65912_LDO3_AVS;
237 case TPS65912_REG_LDO4:
238 return TPS65912_LDO4_AVS;
239 case TPS65912_REG_LDO5:
240 return TPS65912_LDO5;
241 case TPS65912_REG_LDO6:
242 return TPS65912_LDO6;
243 case TPS65912_REG_LDO7:
244 return TPS65912_LDO7;
245 case TPS65912_REG_LDO8:
246 return TPS65912_LDO8;
247 case TPS65912_REG_LDO9:
248 return TPS65912_LDO9;
249 case TPS65912_REG_LDO10:
250 return TPS65912_LDO10;
251 default:
252 return -EINVAL;
256 static int tps65912_get_dcdc_sel_register(struct tps65912_reg *pmic, int id)
258 struct tps65912 *mfd = pmic->mfd;
259 int opvsel = 0, sr = 0;
260 u8 reg = 0;
262 if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_DCDC4)
263 return -EINVAL;
265 switch (id) {
266 case TPS65912_REG_DCDC1:
267 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP);
268 sr = ((opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT);
269 if (sr)
270 reg = TPS65912_DCDC1_AVS;
271 else
272 reg = TPS65912_DCDC1_OP;
273 break;
274 case TPS65912_REG_DCDC2:
275 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP);
276 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
277 if (sr)
278 reg = TPS65912_DCDC2_AVS;
279 else
280 reg = TPS65912_DCDC2_OP;
281 break;
282 case TPS65912_REG_DCDC3:
283 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP);
284 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
285 if (sr)
286 reg = TPS65912_DCDC3_AVS;
287 else
288 reg = TPS65912_DCDC3_OP;
289 break;
290 case TPS65912_REG_DCDC4:
291 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP);
292 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
293 if (sr)
294 reg = TPS65912_DCDC4_AVS;
295 else
296 reg = TPS65912_DCDC4_OP;
297 break;
299 return reg;
302 static int tps65912_get_ldo_sel_register(struct tps65912_reg *pmic, int id)
304 struct tps65912 *mfd = pmic->mfd;
305 int opvsel = 0, sr = 0;
306 u8 reg = 0;
308 if (id < TPS65912_REG_LDO1 || id > TPS65912_REG_LDO10)
309 return -EINVAL;
311 switch (id) {
312 case TPS65912_REG_LDO1:
313 opvsel = tps65912_reg_read(mfd, TPS65912_LDO1_OP);
314 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
315 if (sr)
316 reg = TPS65912_LDO1_AVS;
317 else
318 reg = TPS65912_LDO1_OP;
319 break;
320 case TPS65912_REG_LDO2:
321 opvsel = tps65912_reg_read(mfd, TPS65912_LDO2_OP);
322 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
323 if (sr)
324 reg = TPS65912_LDO2_AVS;
325 else
326 reg = TPS65912_LDO2_OP;
327 break;
328 case TPS65912_REG_LDO3:
329 opvsel = tps65912_reg_read(mfd, TPS65912_LDO3_OP);
330 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
331 if (sr)
332 reg = TPS65912_LDO3_AVS;
333 else
334 reg = TPS65912_LDO3_OP;
335 break;
336 case TPS65912_REG_LDO4:
337 opvsel = tps65912_reg_read(mfd, TPS65912_LDO4_OP);
338 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
339 if (sr)
340 reg = TPS65912_LDO4_AVS;
341 else
342 reg = TPS65912_LDO4_OP;
343 break;
344 case TPS65912_REG_LDO5:
345 reg = TPS65912_LDO5;
346 break;
347 case TPS65912_REG_LDO6:
348 reg = TPS65912_LDO6;
349 break;
350 case TPS65912_REG_LDO7:
351 reg = TPS65912_LDO7;
352 break;
353 case TPS65912_REG_LDO8:
354 reg = TPS65912_LDO8;
355 break;
356 case TPS65912_REG_LDO9:
357 reg = TPS65912_LDO9;
358 break;
359 case TPS65912_REG_LDO10:
360 reg = TPS65912_LDO10;
361 break;
364 return reg;
367 static int tps65912_get_mode_regiters(struct tps65912_reg *pmic, int id)
369 switch (id) {
370 case TPS65912_REG_DCDC1:
371 pmic->pwm_mode_reg = TPS65912_DCDC1_CTRL;
372 pmic->eco_reg = TPS65912_DCDC1_AVS;
373 break;
374 case TPS65912_REG_DCDC2:
375 pmic->pwm_mode_reg = TPS65912_DCDC2_CTRL;
376 pmic->eco_reg = TPS65912_DCDC2_AVS;
377 break;
378 case TPS65912_REG_DCDC3:
379 pmic->pwm_mode_reg = TPS65912_DCDC3_CTRL;
380 pmic->eco_reg = TPS65912_DCDC3_AVS;
381 break;
382 case TPS65912_REG_DCDC4:
383 pmic->pwm_mode_reg = TPS65912_DCDC4_CTRL;
384 pmic->eco_reg = TPS65912_DCDC4_AVS;
385 break;
386 default:
387 return -EINVAL;
390 return 0;
393 static int tps65912_reg_is_enabled(struct regulator_dev *dev)
395 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
396 struct tps65912 *mfd = pmic->mfd;
397 int reg, value, id = rdev_get_id(dev);
399 if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_LDO10)
400 return -EINVAL;
402 reg = pmic->get_ctrl_reg(id);
403 if (reg < 0)
404 return reg;
406 value = tps65912_reg_read(mfd, reg);
407 if (value < 0)
408 return value;
410 return value & TPS65912_REG_ENABLED;
413 static int tps65912_reg_enable(struct regulator_dev *dev)
415 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
416 struct tps65912 *mfd = pmic->mfd;
417 int id = rdev_get_id(dev);
418 int reg;
420 if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_LDO10)
421 return -EINVAL;
423 reg = pmic->get_ctrl_reg(id);
424 if (reg < 0)
425 return reg;
427 return tps65912_set_bits(mfd, reg, TPS65912_REG_ENABLED);
430 static int tps65912_reg_disable(struct regulator_dev *dev)
432 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
433 struct tps65912 *mfd = pmic->mfd;
434 int id = rdev_get_id(dev), reg;
436 reg = pmic->get_ctrl_reg(id);
437 if (reg < 0)
438 return reg;
440 return tps65912_clear_bits(mfd, reg, TPS65912_REG_ENABLED);
443 static int tps65912_set_mode(struct regulator_dev *dev, unsigned int mode)
445 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
446 struct tps65912 *mfd = pmic->mfd;
447 int pwm_mode, eco, id = rdev_get_id(dev);
449 tps65912_get_mode_regiters(pmic, id);
451 pwm_mode = tps65912_reg_read(mfd, pmic->pwm_mode_reg);
452 eco = tps65912_reg_read(mfd, pmic->eco_reg);
454 pwm_mode &= DCDCCTRL_DCDC_MODE_MASK;
455 eco &= DCDC_AVS_ECO_MASK;
457 switch (mode) {
458 case REGULATOR_MODE_FAST:
459 /* Verify if mode alredy set */
460 if (pwm_mode && !eco)
461 break;
462 tps65912_set_bits(mfd, pmic->pwm_mode_reg, DCDCCTRL_DCDC_MODE_MASK);
463 tps65912_clear_bits(mfd, pmic->eco_reg, DCDC_AVS_ECO_MASK);
464 break;
465 case REGULATOR_MODE_NORMAL:
466 case REGULATOR_MODE_IDLE:
467 if (!pwm_mode && !eco)
468 break;
469 tps65912_clear_bits(mfd, pmic->pwm_mode_reg, DCDCCTRL_DCDC_MODE_MASK);
470 tps65912_clear_bits(mfd, pmic->eco_reg, DCDC_AVS_ECO_MASK);
471 break;
472 case REGULATOR_MODE_STANDBY:
473 if (!pwm_mode && eco)
474 break;
475 tps65912_clear_bits(mfd, pmic->pwm_mode_reg, DCDCCTRL_DCDC_MODE_MASK);
476 tps65912_set_bits(mfd, pmic->eco_reg, DCDC_AVS_ECO_MASK);
477 break;
478 default:
479 return -EINVAL;
482 return 0;
485 static unsigned int tps65912_get_mode(struct regulator_dev *dev)
487 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
488 struct tps65912 *mfd = pmic->mfd;
489 int pwm_mode, eco, mode = 0, id = rdev_get_id(dev);
491 tps65912_get_mode_regiters(pmic, id);
493 pwm_mode = tps65912_reg_read(mfd, pmic->pwm_mode_reg);
494 eco = tps65912_reg_read(mfd, pmic->eco_reg);
496 pwm_mode &= DCDCCTRL_DCDC_MODE_MASK;
497 eco &= DCDC_AVS_ECO_MASK;
499 if (pwm_mode && !eco)
500 mode = REGULATOR_MODE_FAST;
501 else if (!pwm_mode && !eco)
502 mode = REGULATOR_MODE_NORMAL;
503 else if (!pwm_mode && eco)
504 mode = REGULATOR_MODE_STANDBY;
506 return mode;
509 static int tps65912_get_voltage_dcdc(struct regulator_dev *dev)
511 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
512 struct tps65912 *mfd = pmic->mfd;
513 int id = rdev_get_id(dev), voltage = 0, range;
514 int opvsel = 0, avsel = 0, sr, vsel;
516 switch (id) {
517 case TPS65912_REG_DCDC1:
518 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP);
519 avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS);
520 range = pmic->dcdc1_range;
521 break;
522 case TPS65912_REG_DCDC2:
523 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP);
524 avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS);
525 range = pmic->dcdc2_range;
526 break;
527 case TPS65912_REG_DCDC3:
528 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP);
529 avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS);
530 range = pmic->dcdc3_range;
531 break;
532 case TPS65912_REG_DCDC4:
533 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP);
534 avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS);
535 range = pmic->dcdc4_range;
536 break;
537 default:
538 return -EINVAL;
541 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
542 if (sr)
543 vsel = avsel;
544 else
545 vsel = opvsel;
546 vsel &= 0x3F;
548 switch (range) {
549 case 0:
550 /* 0.5 - 1.2875V in 12.5mV steps */
551 voltage = tps65912_vsel_to_uv_range0(vsel);
552 break;
553 case 1:
554 /* 0.7 - 1.4875V in 12.5mV steps */
555 voltage = tps65912_vsel_to_uv_range1(vsel);
556 break;
557 case 2:
558 /* 0.5 - 2.075V in 25mV steps */
559 voltage = tps65912_vsel_to_uv_range2(vsel);
560 break;
561 case 3:
562 /* 0.5 - 3.8V in 50mV steps */
563 voltage = tps65912_vsel_to_uv_range3(vsel);
564 break;
566 return voltage;
569 static int tps65912_set_voltage_dcdc(struct regulator_dev *dev,
570 unsigned selector)
572 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
573 struct tps65912 *mfd = pmic->mfd;
574 int id = rdev_get_id(dev);
575 int value;
576 u8 reg;
578 reg = tps65912_get_dcdc_sel_register(pmic, id);
579 value = tps65912_reg_read(mfd, reg);
580 value &= 0xC0;
581 return tps65912_reg_write(mfd, reg, selector | value);
584 static int tps65912_get_voltage_ldo(struct regulator_dev *dev)
586 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
587 struct tps65912 *mfd = pmic->mfd;
588 int id = rdev_get_id(dev);
589 int vsel = 0;
590 u8 reg;
592 reg = tps65912_get_ldo_sel_register(pmic, id);
593 vsel = tps65912_reg_read(mfd, reg);
594 vsel &= 0x3F;
596 return tps65912_vsel_to_uv_ldo(vsel);
599 static int tps65912_set_voltage_ldo(struct regulator_dev *dev,
600 unsigned selector)
602 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
603 struct tps65912 *mfd = pmic->mfd;
604 int id = rdev_get_id(dev), reg, value;
606 reg = tps65912_get_ldo_sel_register(pmic, id);
607 value = tps65912_reg_read(mfd, reg);
608 value &= 0xC0;
609 return tps65912_reg_write(mfd, reg, selector | value);
612 static int tps65912_list_voltage_dcdc(struct regulator_dev *dev,
613 unsigned selector)
615 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
616 int range, voltage = 0, id = rdev_get_id(dev);
618 switch (id) {
619 case TPS65912_REG_DCDC1:
620 range = pmic->dcdc1_range;
621 break;
622 case TPS65912_REG_DCDC2:
623 range = pmic->dcdc2_range;
624 break;
625 case TPS65912_REG_DCDC3:
626 range = pmic->dcdc3_range;
627 break;
628 case TPS65912_REG_DCDC4:
629 range = pmic->dcdc4_range;
630 break;
631 default:
632 return -EINVAL;
635 switch (range) {
636 case 0:
637 /* 0.5 - 1.2875V in 12.5mV steps */
638 voltage = tps65912_vsel_to_uv_range0(selector);
639 break;
640 case 1:
641 /* 0.7 - 1.4875V in 12.5mV steps */
642 voltage = tps65912_vsel_to_uv_range1(selector);
643 break;
644 case 2:
645 /* 0.5 - 2.075V in 25mV steps */
646 voltage = tps65912_vsel_to_uv_range2(selector);
647 break;
648 case 3:
649 /* 0.5 - 3.8V in 50mV steps */
650 voltage = tps65912_vsel_to_uv_range3(selector);
651 break;
653 return voltage;
656 static int tps65912_list_voltage_ldo(struct regulator_dev *dev,
657 unsigned selector)
659 int ldo = rdev_get_id(dev);
661 if (ldo < TPS65912_REG_LDO1 || ldo > TPS65912_REG_LDO10)
662 return -EINVAL;
664 return tps65912_vsel_to_uv_ldo(selector);
667 /* Operations permitted on DCDCx */
668 static struct regulator_ops tps65912_ops_dcdc = {
669 .is_enabled = tps65912_reg_is_enabled,
670 .enable = tps65912_reg_enable,
671 .disable = tps65912_reg_disable,
672 .set_mode = tps65912_set_mode,
673 .get_mode = tps65912_get_mode,
674 .get_voltage = tps65912_get_voltage_dcdc,
675 .set_voltage_sel = tps65912_set_voltage_dcdc,
676 .list_voltage = tps65912_list_voltage_dcdc,
679 /* Operations permitted on LDOx */
680 static struct regulator_ops tps65912_ops_ldo = {
681 .is_enabled = tps65912_reg_is_enabled,
682 .enable = tps65912_reg_enable,
683 .disable = tps65912_reg_disable,
684 .get_voltage = tps65912_get_voltage_ldo,
685 .set_voltage_sel = tps65912_set_voltage_ldo,
686 .list_voltage = tps65912_list_voltage_ldo,
689 static __devinit int tps65912_probe(struct platform_device *pdev)
691 struct tps65912 *tps65912 = dev_get_drvdata(pdev->dev.parent);
692 struct tps_info *info;
693 struct regulator_init_data *reg_data;
694 struct regulator_dev *rdev;
695 struct tps65912_reg *pmic;
696 struct tps65912_board *pmic_plat_data;
697 int i, err;
699 pmic_plat_data = dev_get_platdata(tps65912->dev);
700 if (!pmic_plat_data)
701 return -EINVAL;
703 reg_data = pmic_plat_data->tps65912_pmic_init_data;
705 pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
706 if (!pmic)
707 return -ENOMEM;
709 mutex_init(&pmic->io_lock);
710 pmic->mfd = tps65912;
711 platform_set_drvdata(pdev, pmic);
713 pmic->get_ctrl_reg = &tps65912_get_ctrl_register;
714 info = tps65912_regs;
716 for (i = 0; i < TPS65912_NUM_REGULATOR; i++, info++, reg_data++) {
717 int range = 0;
718 /* Register the regulators */
719 pmic->info[i] = info;
721 pmic->desc[i].name = info->name;
722 pmic->desc[i].id = i;
723 pmic->desc[i].n_voltages = 64;
724 pmic->desc[i].ops = (i > TPS65912_REG_DCDC4 ?
725 &tps65912_ops_ldo : &tps65912_ops_dcdc);
726 pmic->desc[i].type = REGULATOR_VOLTAGE;
727 pmic->desc[i].owner = THIS_MODULE;
728 range = tps65912_get_range(pmic, i);
729 rdev = regulator_register(&pmic->desc[i],
730 tps65912->dev, reg_data, pmic);
731 if (IS_ERR(rdev)) {
732 dev_err(tps65912->dev,
733 "failed to register %s regulator\n",
734 pdev->name);
735 err = PTR_ERR(rdev);
736 goto err;
739 /* Save regulator for cleanup */
740 pmic->rdev[i] = rdev;
742 return 0;
744 err:
745 while (--i >= 0)
746 regulator_unregister(pmic->rdev[i]);
748 kfree(pmic);
749 return err;
752 static int __devexit tps65912_remove(struct platform_device *pdev)
754 struct tps65912_reg *tps65912_reg = platform_get_drvdata(pdev);
755 int i;
757 for (i = 0; i < TPS65912_NUM_REGULATOR; i++)
758 regulator_unregister(tps65912_reg->rdev[i]);
760 kfree(tps65912_reg);
761 return 0;
764 static struct platform_driver tps65912_driver = {
765 .driver = {
766 .name = "tps65912-pmic",
767 .owner = THIS_MODULE,
769 .probe = tps65912_probe,
770 .remove = __devexit_p(tps65912_remove),
774 * tps65912_init
776 * Module init function
778 static int __init tps65912_init(void)
780 return platform_driver_register(&tps65912_driver);
782 subsys_initcall(tps65912_init);
785 * tps65912_cleanup
787 * Module exit function
789 static void __exit tps65912_cleanup(void)
791 platform_driver_unregister(&tps65912_driver);
793 module_exit(tps65912_cleanup);
795 MODULE_AUTHOR("Margarita Olaya Cabrera <magi@slimlogic.co.uk>");
796 MODULE_DESCRIPTION("TPS65912 voltage regulator driver");
797 MODULE_LICENSE("GPL v2");
798 MODULE_ALIAS("platform:tps65912-pmic");