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_SUPPLY_STATE_ENABLED 0x1
30 /* supported VIO voltages in milivolts */
31 static const u16 VIO_VSEL_table
[] = {
32 1500, 1800, 2500, 3300,
35 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
37 /* supported VDD3 voltages in milivolts */
38 static const u16 VDD3_VSEL_table
[] = {
42 /* supported VDIG1 voltages in milivolts */
43 static const u16 VDIG1_VSEL_table
[] = {
44 1200, 1500, 1800, 2700,
47 /* supported VDIG2 voltages in milivolts */
48 static const u16 VDIG2_VSEL_table
[] = {
49 1000, 1100, 1200, 1800,
52 /* supported VPLL voltages in milivolts */
53 static const u16 VPLL_VSEL_table
[] = {
54 1000, 1100, 1800, 2500,
57 /* supported VDAC voltages in milivolts */
58 static const u16 VDAC_VSEL_table
[] = {
59 1800, 2600, 2800, 2850,
62 /* supported VAUX1 voltages in milivolts */
63 static const u16 VAUX1_VSEL_table
[] = {
64 1800, 2500, 2800, 2850,
67 /* supported VAUX2 voltages in milivolts */
68 static const u16 VAUX2_VSEL_table
[] = {
69 1800, 2800, 2900, 3300,
72 /* supported VAUX33 voltages in milivolts */
73 static const u16 VAUX33_VSEL_table
[] = {
74 1800, 2000, 2800, 3300,
77 /* supported VMMC voltages in milivolts */
78 static const u16 VMMC_VSEL_table
[] = {
79 1800, 2800, 3000, 3300,
90 static struct tps_info tps65910_regs
[] = {
98 .table_len
= ARRAY_SIZE(VIO_VSEL_table
),
99 .table
= VIO_VSEL_table
,
115 .table_len
= ARRAY_SIZE(VDD3_VSEL_table
),
116 .table
= VDD3_VSEL_table
,
122 .table_len
= ARRAY_SIZE(VDIG1_VSEL_table
),
123 .table
= VDIG1_VSEL_table
,
129 .table_len
= ARRAY_SIZE(VDIG2_VSEL_table
),
130 .table
= VDIG2_VSEL_table
,
136 .table_len
= ARRAY_SIZE(VPLL_VSEL_table
),
137 .table
= VPLL_VSEL_table
,
143 .table_len
= ARRAY_SIZE(VDAC_VSEL_table
),
144 .table
= VDAC_VSEL_table
,
150 .table_len
= ARRAY_SIZE(VAUX1_VSEL_table
),
151 .table
= VAUX1_VSEL_table
,
157 .table_len
= ARRAY_SIZE(VAUX2_VSEL_table
),
158 .table
= VAUX2_VSEL_table
,
164 .table_len
= ARRAY_SIZE(VAUX33_VSEL_table
),
165 .table
= VAUX33_VSEL_table
,
171 .table_len
= ARRAY_SIZE(VMMC_VSEL_table
),
172 .table
= VMMC_VSEL_table
,
176 static struct tps_info tps65911_regs
[] = {
181 .table_len
= ARRAY_SIZE(VIO_VSEL_table
),
182 .table
= VIO_VSEL_table
,
241 struct tps65910_reg
{
242 struct regulator_desc
*desc
;
243 struct tps65910
*mfd
;
244 struct regulator_dev
**rdev
;
245 struct tps_info
**info
;
249 int (*get_ctrl_reg
)(int);
252 static inline int tps65910_read(struct tps65910_reg
*pmic
, u8 reg
)
257 err
= pmic
->mfd
->read(pmic
->mfd
, reg
, 1, &val
);
264 static inline int tps65910_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
266 return pmic
->mfd
->write(pmic
->mfd
, reg
, 1, &val
);
269 static int tps65910_modify_bits(struct tps65910_reg
*pmic
, u8 reg
,
270 u8 set_mask
, u8 clear_mask
)
274 mutex_lock(&pmic
->mutex
);
276 data
= tps65910_read(pmic
, reg
);
278 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
285 err
= tps65910_write(pmic
, reg
, data
);
287 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
290 mutex_unlock(&pmic
->mutex
);
294 static int tps65910_reg_read(struct tps65910_reg
*pmic
, u8 reg
)
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
);
304 mutex_unlock(&pmic
->mutex
);
308 static int tps65910_reg_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
312 mutex_lock(&pmic
->mutex
);
314 err
= tps65910_write(pmic
, reg
, val
);
316 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
318 mutex_unlock(&pmic
->mutex
);
322 static int tps65910_get_ctrl_register(int id
)
325 case TPS65910_REG_VRTC
:
326 return TPS65910_VRTC
;
327 case TPS65910_REG_VIO
:
329 case TPS65910_REG_VDD1
:
330 return TPS65910_VDD1
;
331 case TPS65910_REG_VDD2
:
332 return TPS65910_VDD2
;
333 case TPS65910_REG_VDD3
:
334 return TPS65910_VDD3
;
335 case TPS65910_REG_VDIG1
:
336 return TPS65910_VDIG1
;
337 case TPS65910_REG_VDIG2
:
338 return TPS65910_VDIG2
;
339 case TPS65910_REG_VPLL
:
340 return TPS65910_VPLL
;
341 case TPS65910_REG_VDAC
:
342 return TPS65910_VDAC
;
343 case TPS65910_REG_VAUX1
:
344 return TPS65910_VAUX1
;
345 case TPS65910_REG_VAUX2
:
346 return TPS65910_VAUX2
;
347 case TPS65910_REG_VAUX33
:
348 return TPS65910_VAUX33
;
349 case TPS65910_REG_VMMC
:
350 return TPS65910_VMMC
;
356 static int tps65911_get_ctrl_register(int id
)
359 case TPS65910_REG_VRTC
:
360 return TPS65910_VRTC
;
361 case TPS65910_REG_VIO
:
363 case TPS65910_REG_VDD1
:
364 return TPS65910_VDD1
;
365 case TPS65910_REG_VDD2
:
366 return TPS65910_VDD2
;
367 case TPS65911_REG_VDDCTRL
:
368 return TPS65911_VDDCTRL
;
369 case TPS65911_REG_LDO1
:
370 return TPS65911_LDO1
;
371 case TPS65911_REG_LDO2
:
372 return TPS65911_LDO2
;
373 case TPS65911_REG_LDO3
:
374 return TPS65911_LDO3
;
375 case TPS65911_REG_LDO4
:
376 return TPS65911_LDO4
;
377 case TPS65911_REG_LDO5
:
378 return TPS65911_LDO5
;
379 case TPS65911_REG_LDO6
:
380 return TPS65911_LDO6
;
381 case TPS65911_REG_LDO7
:
382 return TPS65911_LDO7
;
383 case TPS65911_REG_LDO8
:
384 return TPS65911_LDO8
;
390 static int tps65910_is_enabled(struct regulator_dev
*dev
)
392 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
393 int reg
, value
, id
= rdev_get_id(dev
);
395 reg
= pmic
->get_ctrl_reg(id
);
399 value
= tps65910_reg_read(pmic
, reg
);
403 return value
& TPS65910_SUPPLY_STATE_ENABLED
;
406 static int tps65910_enable(struct regulator_dev
*dev
)
408 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
409 struct tps65910
*mfd
= pmic
->mfd
;
410 int reg
, id
= rdev_get_id(dev
);
412 reg
= pmic
->get_ctrl_reg(id
);
416 return tps65910_set_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
419 static int tps65910_disable(struct regulator_dev
*dev
)
421 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
422 struct tps65910
*mfd
= pmic
->mfd
;
423 int reg
, id
= rdev_get_id(dev
);
425 reg
= pmic
->get_ctrl_reg(id
);
429 return tps65910_clear_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
433 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
435 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
436 struct tps65910
*mfd
= pmic
->mfd
;
437 int reg
, value
, id
= rdev_get_id(dev
);
439 reg
= pmic
->get_ctrl_reg(id
);
444 case REGULATOR_MODE_NORMAL
:
445 return tps65910_modify_bits(pmic
, reg
, LDO_ST_ON_BIT
,
447 case REGULATOR_MODE_IDLE
:
448 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
449 return tps65910_set_bits(mfd
, reg
, value
);
450 case REGULATOR_MODE_STANDBY
:
451 return tps65910_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
457 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
459 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
460 int reg
, value
, id
= rdev_get_id(dev
);
462 reg
= pmic
->get_ctrl_reg(id
);
466 value
= tps65910_reg_read(pmic
, reg
);
470 if (value
& LDO_ST_ON_BIT
)
471 return REGULATOR_MODE_STANDBY
;
472 else if (value
& LDO_ST_MODE_BIT
)
473 return REGULATOR_MODE_IDLE
;
475 return REGULATOR_MODE_NORMAL
;
478 static int tps65910_get_voltage_dcdc(struct regulator_dev
*dev
)
480 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
481 int id
= rdev_get_id(dev
), voltage
= 0;
482 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
485 case TPS65910_REG_VDD1
:
486 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_OP
);
487 mult
= tps65910_reg_read(pmic
, TPS65910_VDD1
);
488 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
489 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_SR
);
490 sr
= opvsel
& VDD1_OP_CMD_MASK
;
491 opvsel
&= VDD1_OP_SEL_MASK
;
492 srvsel
&= VDD1_SR_SEL_MASK
;
495 case TPS65910_REG_VDD2
:
496 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_OP
);
497 mult
= tps65910_reg_read(pmic
, TPS65910_VDD2
);
498 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
499 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_SR
);
500 sr
= opvsel
& VDD2_OP_CMD_MASK
;
501 opvsel
&= VDD2_OP_SEL_MASK
;
502 srvsel
&= VDD2_SR_SEL_MASK
;
505 case TPS65911_REG_VDDCTRL
:
506 opvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_OP
);
507 srvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_SR
);
508 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
509 opvsel
&= VDDCTRL_OP_SEL_MASK
;
510 srvsel
&= VDDCTRL_SR_SEL_MASK
;
515 /* multiplier 0 == 1 but 2,3 normal */
520 /* normalise to valid range */
523 if (srvsel
> vselmax
)
527 voltage
= (srvsel
* VDD1_2_OFFSET
+ VDD1_2_MIN_VOLT
) * 100;
530 /* normalise to valid range*/
533 if (opvsel
> vselmax
)
537 voltage
= (opvsel
* VDD1_2_OFFSET
+ VDD1_2_MIN_VOLT
) * 100;
545 static int tps65910_get_voltage(struct regulator_dev
*dev
)
547 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
548 int reg
, value
, id
= rdev_get_id(dev
), voltage
= 0;
550 reg
= pmic
->get_ctrl_reg(id
);
554 value
= tps65910_reg_read(pmic
, reg
);
559 case TPS65910_REG_VIO
:
560 case TPS65910_REG_VDIG1
:
561 case TPS65910_REG_VDIG2
:
562 case TPS65910_REG_VPLL
:
563 case TPS65910_REG_VDAC
:
564 case TPS65910_REG_VAUX1
:
565 case TPS65910_REG_VAUX2
:
566 case TPS65910_REG_VAUX33
:
567 case TPS65910_REG_VMMC
:
568 value
&= LDO_SEL_MASK
;
569 value
>>= LDO_SEL_SHIFT
;
575 voltage
= pmic
->info
[id
]->table
[value
] * 1000;
580 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
582 return 5 * 1000 * 1000;
585 static int tps65911_get_voltage(struct regulator_dev
*dev
)
587 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
588 int step_mv
, id
= rdev_get_id(dev
);
591 reg
= pmic
->get_ctrl_reg(id
);
593 value
= tps65910_reg_read(pmic
, reg
);
596 case TPS65911_REG_LDO1
:
597 case TPS65911_REG_LDO2
:
598 case TPS65911_REG_LDO4
:
599 value
&= LDO1_SEL_MASK
;
600 value
>>= LDO_SEL_SHIFT
;
601 /* The first 5 values of the selector correspond to 1V */
609 case TPS65911_REG_LDO3
:
610 case TPS65911_REG_LDO5
:
611 case TPS65911_REG_LDO6
:
612 case TPS65911_REG_LDO7
:
613 case TPS65911_REG_LDO8
:
614 value
&= LDO3_SEL_MASK
;
615 value
>>= LDO_SEL_SHIFT
;
616 /* The first 3 values of the selector correspond to 1V */
624 case TPS65910_REG_VIO
:
625 return pmic
->info
[id
]->table
[value
] * 1000;
631 return (LDO_MIN_VOLT
+ value
* step_mv
) * 1000;
634 static int tps65910_set_voltage_dcdc(struct regulator_dev
*dev
,
637 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
638 int id
= rdev_get_id(dev
), vsel
;
642 case TPS65910_REG_VDD1
:
643 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
646 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
648 tps65910_modify_bits(pmic
, TPS65910_VDD1
,
649 (dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
),
650 VDD1_VGAIN_SEL_MASK
);
651 tps65910_reg_write(pmic
, TPS65910_VDD1_OP
, vsel
);
653 case TPS65910_REG_VDD2
:
654 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
657 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
659 tps65910_modify_bits(pmic
, TPS65910_VDD2
,
660 (dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
),
661 VDD1_VGAIN_SEL_MASK
);
662 tps65910_reg_write(pmic
, TPS65910_VDD2_OP
, vsel
);
664 case TPS65911_REG_VDDCTRL
:
666 tps65910_reg_write(pmic
, TPS65911_VDDCTRL_OP
, vsel
);
672 static int tps65910_set_voltage(struct regulator_dev
*dev
, unsigned selector
)
674 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
675 int reg
, id
= rdev_get_id(dev
);
677 reg
= pmic
->get_ctrl_reg(id
);
682 case TPS65910_REG_VIO
:
683 case TPS65910_REG_VDIG1
:
684 case TPS65910_REG_VDIG2
:
685 case TPS65910_REG_VPLL
:
686 case TPS65910_REG_VDAC
:
687 case TPS65910_REG_VAUX1
:
688 case TPS65910_REG_VAUX2
:
689 case TPS65910_REG_VAUX33
:
690 case TPS65910_REG_VMMC
:
691 return tps65910_modify_bits(pmic
, reg
,
692 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
698 static int tps65911_set_voltage(struct regulator_dev
*dev
, unsigned selector
)
700 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
701 int reg
, id
= rdev_get_id(dev
);
703 reg
= pmic
->get_ctrl_reg(id
);
708 case TPS65911_REG_LDO1
:
709 case TPS65911_REG_LDO2
:
710 case TPS65911_REG_LDO4
:
711 return tps65910_modify_bits(pmic
, reg
,
712 (selector
<< LDO_SEL_SHIFT
), LDO1_SEL_MASK
);
713 case TPS65911_REG_LDO3
:
714 case TPS65911_REG_LDO5
:
715 case TPS65911_REG_LDO6
:
716 case TPS65911_REG_LDO7
:
717 case TPS65911_REG_LDO8
:
718 case TPS65910_REG_VIO
:
719 return tps65910_modify_bits(pmic
, reg
,
720 (selector
<< LDO_SEL_SHIFT
), LDO3_SEL_MASK
);
727 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
730 int volt
, mult
= 1, id
= rdev_get_id(dev
);
733 case TPS65910_REG_VDD1
:
734 case TPS65910_REG_VDD2
:
735 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
736 volt
= VDD1_2_MIN_VOLT
+
737 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
739 case TPS65911_REG_VDDCTRL
:
740 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
747 return volt
* 100 * mult
;
750 static int tps65910_list_voltage(struct regulator_dev
*dev
,
753 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
754 int id
= rdev_get_id(dev
), voltage
;
756 if (id
< TPS65910_REG_VIO
|| id
> TPS65910_REG_VMMC
)
759 if (selector
>= pmic
->info
[id
]->table_len
)
762 voltage
= pmic
->info
[id
]->table
[selector
] * 1000;
767 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
769 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
770 int step_mv
= 0, id
= rdev_get_id(dev
);
773 case TPS65911_REG_LDO1
:
774 case TPS65911_REG_LDO2
:
775 case TPS65911_REG_LDO4
:
776 /* The first 5 values of the selector correspond to 1V */
784 case TPS65911_REG_LDO3
:
785 case TPS65911_REG_LDO5
:
786 case TPS65911_REG_LDO6
:
787 case TPS65911_REG_LDO7
:
788 case TPS65911_REG_LDO8
:
789 /* The first 3 values of the selector correspond to 1V */
797 case TPS65910_REG_VIO
:
798 return pmic
->info
[id
]->table
[selector
] * 1000;
803 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
806 /* Regulator ops (except VRTC) */
807 static struct regulator_ops tps65910_ops_dcdc
= {
808 .is_enabled
= tps65910_is_enabled
,
809 .enable
= tps65910_enable
,
810 .disable
= tps65910_disable
,
811 .set_mode
= tps65910_set_mode
,
812 .get_mode
= tps65910_get_mode
,
813 .get_voltage
= tps65910_get_voltage_dcdc
,
814 .set_voltage_sel
= tps65910_set_voltage_dcdc
,
815 .list_voltage
= tps65910_list_voltage_dcdc
,
818 static struct regulator_ops tps65910_ops_vdd3
= {
819 .is_enabled
= tps65910_is_enabled
,
820 .enable
= tps65910_enable
,
821 .disable
= tps65910_disable
,
822 .set_mode
= tps65910_set_mode
,
823 .get_mode
= tps65910_get_mode
,
824 .get_voltage
= tps65910_get_voltage_vdd3
,
825 .list_voltage
= tps65910_list_voltage
,
828 static struct regulator_ops tps65910_ops
= {
829 .is_enabled
= tps65910_is_enabled
,
830 .enable
= tps65910_enable
,
831 .disable
= tps65910_disable
,
832 .set_mode
= tps65910_set_mode
,
833 .get_mode
= tps65910_get_mode
,
834 .get_voltage
= tps65910_get_voltage
,
835 .set_voltage_sel
= tps65910_set_voltage
,
836 .list_voltage
= tps65910_list_voltage
,
839 static struct regulator_ops tps65911_ops
= {
840 .is_enabled
= tps65910_is_enabled
,
841 .enable
= tps65910_enable
,
842 .disable
= tps65910_disable
,
843 .set_mode
= tps65910_set_mode
,
844 .get_mode
= tps65910_get_mode
,
845 .get_voltage
= tps65911_get_voltage
,
846 .set_voltage_sel
= tps65911_set_voltage
,
847 .list_voltage
= tps65911_list_voltage
,
850 static __devinit
int tps65910_probe(struct platform_device
*pdev
)
852 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
853 struct tps_info
*info
;
854 struct regulator_init_data
*reg_data
;
855 struct regulator_dev
*rdev
;
856 struct tps65910_reg
*pmic
;
857 struct tps65910_board
*pmic_plat_data
;
860 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
864 pmic
= kzalloc(sizeof(*pmic
), GFP_KERNEL
);
868 mutex_init(&pmic
->mutex
);
869 pmic
->mfd
= tps65910
;
870 platform_set_drvdata(pdev
, pmic
);
872 /* Give control of all register to control port */
873 tps65910_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
874 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
876 switch(tps65910_chip_id(tps65910
)) {
878 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
879 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
880 info
= tps65910_regs
;
883 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
884 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
885 info
= tps65911_regs
;
888 pr_err("Invalid tps chip version\n");
893 pmic
->desc
= kcalloc(pmic
->num_regulators
,
894 sizeof(struct regulator_desc
), GFP_KERNEL
);
900 pmic
->info
= kcalloc(pmic
->num_regulators
,
901 sizeof(struct tps_info
*), GFP_KERNEL
);
907 pmic
->rdev
= kcalloc(pmic
->num_regulators
,
908 sizeof(struct regulator_dev
*), GFP_KERNEL
);
914 for (i
= 0; i
< pmic
->num_regulators
&& i
< TPS65910_NUM_REGS
;
917 reg_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
919 /* Regulator API handles empty constraints but not NULL
924 /* Register the regulators */
925 pmic
->info
[i
] = info
;
927 pmic
->desc
[i
].name
= info
->name
;
928 pmic
->desc
[i
].id
= i
;
929 pmic
->desc
[i
].n_voltages
= info
->table_len
;
931 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
932 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
933 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
934 VDD1_2_NUM_VOLT_COARSE
;
935 } else if (i
== TPS65910_REG_VDD3
) {
936 if (tps65910_chip_id(tps65910
) == TPS65910
)
937 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
939 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
941 if (tps65910_chip_id(tps65910
) == TPS65910
)
942 pmic
->desc
[i
].ops
= &tps65910_ops
;
944 pmic
->desc
[i
].ops
= &tps65911_ops
;
947 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
948 pmic
->desc
[i
].owner
= THIS_MODULE
;
950 rdev
= regulator_register(&pmic
->desc
[i
],
951 tps65910
->dev
, reg_data
, pmic
, NULL
);
953 dev_err(tps65910
->dev
,
954 "failed to register %s regulator\n",
957 goto err_unregister_regulator
;
960 /* Save regulator for cleanup */
961 pmic
->rdev
[i
] = rdev
;
965 err_unregister_regulator
:
967 regulator_unregister(pmic
->rdev
[i
]);
978 static int __devexit
tps65910_remove(struct platform_device
*pdev
)
980 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
983 for (i
= 0; i
< pmic
->num_regulators
; i
++)
984 regulator_unregister(pmic
->rdev
[i
]);
993 static struct platform_driver tps65910_driver
= {
995 .name
= "tps65910-pmic",
996 .owner
= THIS_MODULE
,
998 .probe
= tps65910_probe
,
999 .remove
= __devexit_p(tps65910_remove
),
1002 static int __init
tps65910_init(void)
1004 return platform_driver_register(&tps65910_driver
);
1006 subsys_initcall(tps65910_init
);
1008 static void __exit
tps65910_cleanup(void)
1010 platform_driver_unregister(&tps65910_driver
);
1012 module_exit(tps65910_cleanup
);
1014 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1015 MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
1016 MODULE_LICENSE("GPL v2");
1017 MODULE_ALIAS("platform:tps65910-pmic");