2 * tps65910.c -- TI tps65910
4 * Copyright 2010 Texas Instruments Inc.
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
7 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
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/tps65910.h>
28 #define TPS65910_REG_VRTC 0
29 #define TPS65910_REG_VIO 1
30 #define TPS65910_REG_VDD1 2
31 #define TPS65910_REG_VDD2 3
32 #define TPS65910_REG_VDD3 4
33 #define TPS65910_REG_VDIG1 5
34 #define TPS65910_REG_VDIG2 6
35 #define TPS65910_REG_VPLL 7
36 #define TPS65910_REG_VDAC 8
37 #define TPS65910_REG_VAUX1 9
38 #define TPS65910_REG_VAUX2 10
39 #define TPS65910_REG_VAUX33 11
40 #define TPS65910_REG_VMMC 12
42 #define TPS65911_REG_VDDCTRL 4
43 #define TPS65911_REG_LDO1 5
44 #define TPS65911_REG_LDO2 6
45 #define TPS65911_REG_LDO3 7
46 #define TPS65911_REG_LDO4 8
47 #define TPS65911_REG_LDO5 9
48 #define TPS65911_REG_LDO6 10
49 #define TPS65911_REG_LDO7 11
50 #define TPS65911_REG_LDO8 12
52 #define TPS65910_SUPPLY_STATE_ENABLED 0x1
54 /* supported VIO voltages in milivolts */
55 static const u16 VIO_VSEL_table
[] = {
56 1500, 1800, 2500, 3300,
59 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
61 /* supported VDD3 voltages in milivolts */
62 static const u16 VDD3_VSEL_table
[] = {
66 /* supported VDIG1 voltages in milivolts */
67 static const u16 VDIG1_VSEL_table
[] = {
68 1200, 1500, 1800, 2700,
71 /* supported VDIG2 voltages in milivolts */
72 static const u16 VDIG2_VSEL_table
[] = {
73 1000, 1100, 1200, 1800,
76 /* supported VPLL voltages in milivolts */
77 static const u16 VPLL_VSEL_table
[] = {
78 1000, 1100, 1800, 2500,
81 /* supported VDAC voltages in milivolts */
82 static const u16 VDAC_VSEL_table
[] = {
83 1800, 2600, 2800, 2850,
86 /* supported VAUX1 voltages in milivolts */
87 static const u16 VAUX1_VSEL_table
[] = {
88 1800, 2500, 2800, 2850,
91 /* supported VAUX2 voltages in milivolts */
92 static const u16 VAUX2_VSEL_table
[] = {
93 1800, 2800, 2900, 3300,
96 /* supported VAUX33 voltages in milivolts */
97 static const u16 VAUX33_VSEL_table
[] = {
98 1800, 2000, 2800, 3300,
101 /* supported VMMC voltages in milivolts */
102 static const u16 VMMC_VSEL_table
[] = {
103 1800, 2800, 3000, 3300,
114 static struct tps_info tps65910_regs
[] = {
122 .table_len
= ARRAY_SIZE(VIO_VSEL_table
),
123 .table
= VIO_VSEL_table
,
139 .table_len
= ARRAY_SIZE(VDD3_VSEL_table
),
140 .table
= VDD3_VSEL_table
,
146 .table_len
= ARRAY_SIZE(VDIG1_VSEL_table
),
147 .table
= VDIG1_VSEL_table
,
153 .table_len
= ARRAY_SIZE(VDIG2_VSEL_table
),
154 .table
= VDIG2_VSEL_table
,
160 .table_len
= ARRAY_SIZE(VPLL_VSEL_table
),
161 .table
= VPLL_VSEL_table
,
167 .table_len
= ARRAY_SIZE(VDAC_VSEL_table
),
168 .table
= VDAC_VSEL_table
,
174 .table_len
= ARRAY_SIZE(VAUX1_VSEL_table
),
175 .table
= VAUX1_VSEL_table
,
181 .table_len
= ARRAY_SIZE(VAUX2_VSEL_table
),
182 .table
= VAUX2_VSEL_table
,
188 .table_len
= ARRAY_SIZE(VAUX33_VSEL_table
),
189 .table
= VAUX33_VSEL_table
,
195 .table_len
= ARRAY_SIZE(VMMC_VSEL_table
),
196 .table
= VMMC_VSEL_table
,
200 static struct tps_info tps65911_regs
[] = {
205 .table_len
= ARRAY_SIZE(VIO_VSEL_table
),
206 .table
= VIO_VSEL_table
,
265 struct tps65910_reg
{
266 struct regulator_desc
*desc
;
267 struct tps65910
*mfd
;
268 struct regulator_dev
**rdev
;
269 struct tps_info
**info
;
273 int (*get_ctrl_reg
)(int);
276 static inline int tps65910_read(struct tps65910_reg
*pmic
, u8 reg
)
281 err
= pmic
->mfd
->read(pmic
->mfd
, reg
, 1, &val
);
288 static inline int tps65910_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
290 return pmic
->mfd
->write(pmic
->mfd
, reg
, 1, &val
);
293 static int tps65910_modify_bits(struct tps65910_reg
*pmic
, u8 reg
,
294 u8 set_mask
, u8 clear_mask
)
298 mutex_lock(&pmic
->mutex
);
300 data
= tps65910_read(pmic
, reg
);
302 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
309 err
= tps65910_write(pmic
, reg
, data
);
311 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
314 mutex_unlock(&pmic
->mutex
);
318 static int tps65910_reg_read(struct tps65910_reg
*pmic
, u8 reg
)
322 mutex_lock(&pmic
->mutex
);
324 data
= tps65910_read(pmic
, reg
);
326 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
328 mutex_unlock(&pmic
->mutex
);
332 static int tps65910_reg_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
336 mutex_lock(&pmic
->mutex
);
338 err
= tps65910_write(pmic
, reg
, val
);
340 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
342 mutex_unlock(&pmic
->mutex
);
346 static int tps65910_get_ctrl_register(int id
)
349 case TPS65910_REG_VRTC
:
350 return TPS65910_VRTC
;
351 case TPS65910_REG_VIO
:
353 case TPS65910_REG_VDD1
:
354 return TPS65910_VDD1
;
355 case TPS65910_REG_VDD2
:
356 return TPS65910_VDD2
;
357 case TPS65910_REG_VDD3
:
358 return TPS65910_VDD3
;
359 case TPS65910_REG_VDIG1
:
360 return TPS65910_VDIG1
;
361 case TPS65910_REG_VDIG2
:
362 return TPS65910_VDIG2
;
363 case TPS65910_REG_VPLL
:
364 return TPS65910_VPLL
;
365 case TPS65910_REG_VDAC
:
366 return TPS65910_VDAC
;
367 case TPS65910_REG_VAUX1
:
368 return TPS65910_VAUX1
;
369 case TPS65910_REG_VAUX2
:
370 return TPS65910_VAUX2
;
371 case TPS65910_REG_VAUX33
:
372 return TPS65910_VAUX33
;
373 case TPS65910_REG_VMMC
:
374 return TPS65910_VMMC
;
380 static int tps65911_get_ctrl_register(int id
)
383 case TPS65910_REG_VRTC
:
384 return TPS65910_VRTC
;
385 case TPS65910_REG_VIO
:
387 case TPS65910_REG_VDD1
:
388 return TPS65910_VDD1
;
389 case TPS65910_REG_VDD2
:
390 return TPS65910_VDD2
;
391 case TPS65911_REG_VDDCTRL
:
392 return TPS65911_VDDCTRL
;
393 case TPS65911_REG_LDO1
:
394 return TPS65911_LDO1
;
395 case TPS65911_REG_LDO2
:
396 return TPS65911_LDO2
;
397 case TPS65911_REG_LDO3
:
398 return TPS65911_LDO3
;
399 case TPS65911_REG_LDO4
:
400 return TPS65911_LDO4
;
401 case TPS65911_REG_LDO5
:
402 return TPS65911_LDO5
;
403 case TPS65911_REG_LDO6
:
404 return TPS65911_LDO6
;
405 case TPS65911_REG_LDO7
:
406 return TPS65911_LDO7
;
407 case TPS65911_REG_LDO8
:
408 return TPS65911_LDO8
;
414 static int tps65910_is_enabled(struct regulator_dev
*dev
)
416 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
417 int reg
, value
, id
= rdev_get_id(dev
);
419 reg
= pmic
->get_ctrl_reg(id
);
423 value
= tps65910_reg_read(pmic
, reg
);
427 return value
& TPS65910_SUPPLY_STATE_ENABLED
;
430 static int tps65910_enable(struct regulator_dev
*dev
)
432 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
433 struct tps65910
*mfd
= pmic
->mfd
;
434 int reg
, id
= rdev_get_id(dev
);
436 reg
= pmic
->get_ctrl_reg(id
);
440 return tps65910_set_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
443 static int tps65910_disable(struct regulator_dev
*dev
)
445 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
446 struct tps65910
*mfd
= pmic
->mfd
;
447 int reg
, id
= rdev_get_id(dev
);
449 reg
= pmic
->get_ctrl_reg(id
);
453 return tps65910_clear_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
457 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
459 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
460 struct tps65910
*mfd
= pmic
->mfd
;
461 int reg
, value
, id
= rdev_get_id(dev
);
463 reg
= pmic
->get_ctrl_reg(id
);
468 case REGULATOR_MODE_NORMAL
:
469 return tps65910_modify_bits(pmic
, reg
, LDO_ST_ON_BIT
,
471 case REGULATOR_MODE_IDLE
:
472 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
473 return tps65910_set_bits(mfd
, reg
, value
);
474 case REGULATOR_MODE_STANDBY
:
475 return tps65910_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
481 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
483 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
484 int reg
, value
, id
= rdev_get_id(dev
);
486 reg
= pmic
->get_ctrl_reg(id
);
490 value
= tps65910_reg_read(pmic
, reg
);
494 if (value
& LDO_ST_ON_BIT
)
495 return REGULATOR_MODE_STANDBY
;
496 else if (value
& LDO_ST_MODE_BIT
)
497 return REGULATOR_MODE_IDLE
;
499 return REGULATOR_MODE_NORMAL
;
502 static int tps65910_get_voltage_dcdc(struct regulator_dev
*dev
)
504 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
505 int id
= rdev_get_id(dev
), voltage
= 0;
506 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
509 case TPS65910_REG_VDD1
:
510 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_OP
);
511 mult
= tps65910_reg_read(pmic
, TPS65910_VDD1
);
512 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
513 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_SR
);
514 sr
= opvsel
& VDD1_OP_CMD_MASK
;
515 opvsel
&= VDD1_OP_SEL_MASK
;
516 srvsel
&= VDD1_SR_SEL_MASK
;
519 case TPS65910_REG_VDD2
:
520 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_OP
);
521 mult
= tps65910_reg_read(pmic
, TPS65910_VDD2
);
522 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
523 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_SR
);
524 sr
= opvsel
& VDD2_OP_CMD_MASK
;
525 opvsel
&= VDD2_OP_SEL_MASK
;
526 srvsel
&= VDD2_SR_SEL_MASK
;
529 case TPS65911_REG_VDDCTRL
:
530 opvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_OP
);
531 srvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_SR
);
532 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
533 opvsel
&= VDDCTRL_OP_SEL_MASK
;
534 srvsel
&= VDDCTRL_SR_SEL_MASK
;
539 /* multiplier 0 == 1 but 2,3 normal */
544 /* normalise to valid range */
547 if (srvsel
> vselmax
)
551 voltage
= (srvsel
* VDD1_2_OFFSET
+ VDD1_2_MIN_VOLT
) * 100;
554 /* normalise to valid range*/
557 if (opvsel
> vselmax
)
561 voltage
= (opvsel
* VDD1_2_OFFSET
+ VDD1_2_MIN_VOLT
) * 100;
569 static int tps65910_get_voltage(struct regulator_dev
*dev
)
571 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
572 int reg
, value
, id
= rdev_get_id(dev
), voltage
= 0;
574 reg
= pmic
->get_ctrl_reg(id
);
578 value
= tps65910_reg_read(pmic
, reg
);
583 case TPS65910_REG_VIO
:
584 case TPS65910_REG_VDIG1
:
585 case TPS65910_REG_VDIG2
:
586 case TPS65910_REG_VPLL
:
587 case TPS65910_REG_VDAC
:
588 case TPS65910_REG_VAUX1
:
589 case TPS65910_REG_VAUX2
:
590 case TPS65910_REG_VAUX33
:
591 case TPS65910_REG_VMMC
:
592 value
&= LDO_SEL_MASK
;
593 value
>>= LDO_SEL_SHIFT
;
599 voltage
= pmic
->info
[id
]->table
[value
] * 1000;
604 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
606 return 5 * 1000 * 1000;
609 static int tps65911_get_voltage(struct regulator_dev
*dev
)
611 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
612 int step_mv
, id
= rdev_get_id(dev
);
615 reg
= pmic
->get_ctrl_reg(id
);
617 value
= tps65910_reg_read(pmic
, reg
);
620 case TPS65911_REG_LDO1
:
621 case TPS65911_REG_LDO2
:
622 case TPS65911_REG_LDO4
:
623 value
&= LDO1_SEL_MASK
;
624 value
>>= LDO_SEL_SHIFT
;
625 /* The first 5 values of the selector correspond to 1V */
633 case TPS65911_REG_LDO3
:
634 case TPS65911_REG_LDO5
:
635 case TPS65911_REG_LDO6
:
636 case TPS65911_REG_LDO7
:
637 case TPS65911_REG_LDO8
:
638 value
&= LDO3_SEL_MASK
;
639 value
>>= LDO_SEL_SHIFT
;
640 /* The first 3 values of the selector correspond to 1V */
648 case TPS65910_REG_VIO
:
649 return pmic
->info
[id
]->table
[value
] * 1000;
655 return (LDO_MIN_VOLT
+ value
* step_mv
) * 1000;
658 static int tps65910_set_voltage_dcdc(struct regulator_dev
*dev
,
661 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
662 int id
= rdev_get_id(dev
), vsel
;
666 case TPS65910_REG_VDD1
:
667 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLTS
) + 1;
670 vsel
= (selector
% VDD1_2_NUM_VOLTS
) + 3;
672 tps65910_modify_bits(pmic
, TPS65910_VDD1
,
673 (dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
),
674 VDD1_VGAIN_SEL_MASK
);
675 tps65910_reg_write(pmic
, TPS65910_VDD1_OP
, vsel
);
677 case TPS65910_REG_VDD2
:
678 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLTS
) + 1;
681 vsel
= (selector
% VDD1_2_NUM_VOLTS
) + 3;
683 tps65910_modify_bits(pmic
, TPS65910_VDD2
,
684 (dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
),
685 VDD1_VGAIN_SEL_MASK
);
686 tps65910_reg_write(pmic
, TPS65910_VDD2_OP
, vsel
);
688 case TPS65911_REG_VDDCTRL
:
690 tps65910_reg_write(pmic
, TPS65911_VDDCTRL_OP
, vsel
);
696 static int tps65910_set_voltage(struct regulator_dev
*dev
, unsigned selector
)
698 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
699 int reg
, id
= rdev_get_id(dev
);
701 reg
= pmic
->get_ctrl_reg(id
);
706 case TPS65910_REG_VIO
:
707 case TPS65910_REG_VDIG1
:
708 case TPS65910_REG_VDIG2
:
709 case TPS65910_REG_VPLL
:
710 case TPS65910_REG_VDAC
:
711 case TPS65910_REG_VAUX1
:
712 case TPS65910_REG_VAUX2
:
713 case TPS65910_REG_VAUX33
:
714 case TPS65910_REG_VMMC
:
715 return tps65910_modify_bits(pmic
, reg
,
716 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
722 static int tps65911_set_voltage(struct regulator_dev
*dev
, unsigned selector
)
724 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
725 int reg
, id
= rdev_get_id(dev
);
727 reg
= pmic
->get_ctrl_reg(id
);
732 case TPS65911_REG_LDO1
:
733 case TPS65911_REG_LDO2
:
734 case TPS65911_REG_LDO4
:
735 return tps65910_modify_bits(pmic
, reg
,
736 (selector
<< LDO_SEL_SHIFT
), LDO1_SEL_MASK
);
737 case TPS65911_REG_LDO3
:
738 case TPS65911_REG_LDO5
:
739 case TPS65911_REG_LDO6
:
740 case TPS65911_REG_LDO7
:
741 case TPS65911_REG_LDO8
:
742 case TPS65910_REG_VIO
:
743 return tps65910_modify_bits(pmic
, reg
,
744 (selector
<< LDO_SEL_SHIFT
), LDO3_SEL_MASK
);
751 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
754 int volt
, mult
= 1, id
= rdev_get_id(dev
);
757 case TPS65910_REG_VDD1
:
758 case TPS65910_REG_VDD2
:
759 mult
= (selector
/ VDD1_2_NUM_VOLTS
) + 1;
760 volt
= VDD1_2_MIN_VOLT
+
761 (selector
% VDD1_2_NUM_VOLTS
) * VDD1_2_OFFSET
;
763 case TPS65911_REG_VDDCTRL
:
764 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
771 return volt
* 100 * mult
;
774 static int tps65910_list_voltage(struct regulator_dev
*dev
,
777 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
778 int id
= rdev_get_id(dev
), voltage
;
780 if (id
< TPS65910_REG_VIO
|| id
> TPS65910_REG_VMMC
)
783 if (selector
>= pmic
->info
[id
]->table_len
)
786 voltage
= pmic
->info
[id
]->table
[selector
] * 1000;
791 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
793 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
794 int step_mv
= 0, id
= rdev_get_id(dev
);
797 case TPS65911_REG_LDO1
:
798 case TPS65911_REG_LDO2
:
799 case TPS65911_REG_LDO4
:
800 /* The first 5 values of the selector correspond to 1V */
808 case TPS65911_REG_LDO3
:
809 case TPS65911_REG_LDO5
:
810 case TPS65911_REG_LDO6
:
811 case TPS65911_REG_LDO7
:
812 case TPS65911_REG_LDO8
:
813 /* The first 3 values of the selector correspond to 1V */
821 case TPS65910_REG_VIO
:
822 return pmic
->info
[id
]->table
[selector
] * 1000;
827 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
830 /* Regulator ops (except VRTC) */
831 static struct regulator_ops tps65910_ops_dcdc
= {
832 .is_enabled
= tps65910_is_enabled
,
833 .enable
= tps65910_enable
,
834 .disable
= tps65910_disable
,
835 .set_mode
= tps65910_set_mode
,
836 .get_mode
= tps65910_get_mode
,
837 .get_voltage
= tps65910_get_voltage_dcdc
,
838 .set_voltage_sel
= tps65910_set_voltage_dcdc
,
839 .list_voltage
= tps65910_list_voltage_dcdc
,
842 static struct regulator_ops tps65910_ops_vdd3
= {
843 .is_enabled
= tps65910_is_enabled
,
844 .enable
= tps65910_enable
,
845 .disable
= tps65910_disable
,
846 .set_mode
= tps65910_set_mode
,
847 .get_mode
= tps65910_get_mode
,
848 .get_voltage
= tps65910_get_voltage_vdd3
,
849 .list_voltage
= tps65910_list_voltage
,
852 static struct regulator_ops tps65910_ops
= {
853 .is_enabled
= tps65910_is_enabled
,
854 .enable
= tps65910_enable
,
855 .disable
= tps65910_disable
,
856 .set_mode
= tps65910_set_mode
,
857 .get_mode
= tps65910_get_mode
,
858 .get_voltage
= tps65910_get_voltage
,
859 .set_voltage_sel
= tps65910_set_voltage
,
860 .list_voltage
= tps65910_list_voltage
,
863 static struct regulator_ops tps65911_ops
= {
864 .is_enabled
= tps65910_is_enabled
,
865 .enable
= tps65910_enable
,
866 .disable
= tps65910_disable
,
867 .set_mode
= tps65910_set_mode
,
868 .get_mode
= tps65910_get_mode
,
869 .get_voltage
= tps65911_get_voltage
,
870 .set_voltage_sel
= tps65911_set_voltage
,
871 .list_voltage
= tps65911_list_voltage
,
874 static __devinit
int tps65910_probe(struct platform_device
*pdev
)
876 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
877 struct tps_info
*info
;
878 struct regulator_init_data
*reg_data
;
879 struct regulator_dev
*rdev
;
880 struct tps65910_reg
*pmic
;
881 struct tps65910_board
*pmic_plat_data
;
884 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
888 reg_data
= pmic_plat_data
->tps65910_pmic_init_data
;
890 pmic
= kzalloc(sizeof(*pmic
), GFP_KERNEL
);
894 mutex_init(&pmic
->mutex
);
895 pmic
->mfd
= tps65910
;
896 platform_set_drvdata(pdev
, pmic
);
898 /* Give control of all register to control port */
899 tps65910_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
900 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
902 switch(tps65910_chip_id(tps65910
)) {
904 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
905 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
906 info
= tps65910_regs
;
909 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
910 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
911 info
= tps65911_regs
;
914 pr_err("Invalid tps chip version\n");
919 pmic
->desc
= kcalloc(pmic
->num_regulators
,
920 sizeof(struct regulator_desc
), GFP_KERNEL
);
926 pmic
->info
= kcalloc(pmic
->num_regulators
,
927 sizeof(struct tps_info
*), GFP_KERNEL
);
933 pmic
->rdev
= kcalloc(pmic
->num_regulators
,
934 sizeof(struct regulator_dev
*), GFP_KERNEL
);
940 for (i
= 0; i
< pmic
->num_regulators
; i
++, info
++, reg_data
++) {
941 /* Register the regulators */
942 pmic
->info
[i
] = info
;
944 pmic
->desc
[i
].name
= info
->name
;
945 pmic
->desc
[i
].id
= i
;
946 pmic
->desc
[i
].n_voltages
= info
->table_len
;
948 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
949 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
950 } else if (i
== TPS65910_REG_VDD3
) {
951 if (tps65910_chip_id(tps65910
) == TPS65910
)
952 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
954 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
956 if (tps65910_chip_id(tps65910
) == TPS65910
)
957 pmic
->desc
[i
].ops
= &tps65910_ops
;
959 pmic
->desc
[i
].ops
= &tps65911_ops
;
962 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
963 pmic
->desc
[i
].owner
= THIS_MODULE
;
965 rdev
= regulator_register(&pmic
->desc
[i
],
966 tps65910
->dev
, reg_data
, pmic
);
968 dev_err(tps65910
->dev
,
969 "failed to register %s regulator\n",
972 goto err_unregister_regulator
;
975 /* Save regulator for cleanup */
976 pmic
->rdev
[i
] = rdev
;
980 err_unregister_regulator
:
982 regulator_unregister(pmic
->rdev
[i
]);
993 static int __devexit
tps65910_remove(struct platform_device
*pdev
)
995 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
998 for (i
= 0; i
< pmic
->num_regulators
; i
++)
999 regulator_unregister(pmic
->rdev
[i
]);
1008 static struct platform_driver tps65910_driver
= {
1010 .name
= "tps65910-pmic",
1011 .owner
= THIS_MODULE
,
1013 .probe
= tps65910_probe
,
1014 .remove
= __devexit_p(tps65910_remove
),
1017 static int __init
tps65910_init(void)
1019 return platform_driver_register(&tps65910_driver
);
1021 subsys_initcall(tps65910_init
);
1023 static void __exit
tps65910_cleanup(void)
1025 platform_driver_unregister(&tps65910_driver
);
1027 module_exit(tps65910_cleanup
);
1029 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1030 MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
1031 MODULE_LICENSE("GPL v2");
1032 MODULE_ALIAS("platform:tps65910-pmic");