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
29 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
30 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
32 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
34 /* supported VIO voltages in milivolts */
35 static const u16 VIO_VSEL_table
[] = {
36 1500, 1800, 2500, 3300,
39 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
41 /* supported VDD3 voltages in milivolts */
42 static const u16 VDD3_VSEL_table
[] = {
46 /* supported VDIG1 voltages in milivolts */
47 static const u16 VDIG1_VSEL_table
[] = {
48 1200, 1500, 1800, 2700,
51 /* supported VDIG2 voltages in milivolts */
52 static const u16 VDIG2_VSEL_table
[] = {
53 1000, 1100, 1200, 1800,
56 /* supported VPLL voltages in milivolts */
57 static const u16 VPLL_VSEL_table
[] = {
58 1000, 1100, 1800, 2500,
61 /* supported VDAC voltages in milivolts */
62 static const u16 VDAC_VSEL_table
[] = {
63 1800, 2600, 2800, 2850,
66 /* supported VAUX1 voltages in milivolts */
67 static const u16 VAUX1_VSEL_table
[] = {
68 1800, 2500, 2800, 2850,
71 /* supported VAUX2 voltages in milivolts */
72 static const u16 VAUX2_VSEL_table
[] = {
73 1800, 2800, 2900, 3300,
76 /* supported VAUX33 voltages in milivolts */
77 static const u16 VAUX33_VSEL_table
[] = {
78 1800, 2000, 2800, 3300,
81 /* supported VMMC voltages in milivolts */
82 static const u16 VMMC_VSEL_table
[] = {
83 1800, 2800, 3000, 3300,
91 const u16
*voltage_table
;
95 static struct tps_info tps65910_regs
[] = {
98 .enable_time_us
= 2200,
104 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
105 .voltage_table
= VIO_VSEL_table
,
106 .enable_time_us
= 350,
112 .enable_time_us
= 350,
118 .enable_time_us
= 350,
124 .n_voltages
= ARRAY_SIZE(VDD3_VSEL_table
),
125 .voltage_table
= VDD3_VSEL_table
,
126 .enable_time_us
= 200,
132 .n_voltages
= ARRAY_SIZE(VDIG1_VSEL_table
),
133 .voltage_table
= VDIG1_VSEL_table
,
134 .enable_time_us
= 100,
140 .n_voltages
= ARRAY_SIZE(VDIG2_VSEL_table
),
141 .voltage_table
= VDIG2_VSEL_table
,
142 .enable_time_us
= 100,
148 .n_voltages
= ARRAY_SIZE(VPLL_VSEL_table
),
149 .voltage_table
= VPLL_VSEL_table
,
150 .enable_time_us
= 100,
156 .n_voltages
= ARRAY_SIZE(VDAC_VSEL_table
),
157 .voltage_table
= VDAC_VSEL_table
,
158 .enable_time_us
= 100,
164 .n_voltages
= ARRAY_SIZE(VAUX1_VSEL_table
),
165 .voltage_table
= VAUX1_VSEL_table
,
166 .enable_time_us
= 100,
172 .n_voltages
= ARRAY_SIZE(VAUX2_VSEL_table
),
173 .voltage_table
= VAUX2_VSEL_table
,
174 .enable_time_us
= 100,
180 .n_voltages
= ARRAY_SIZE(VAUX33_VSEL_table
),
181 .voltage_table
= VAUX33_VSEL_table
,
182 .enable_time_us
= 100,
188 .n_voltages
= ARRAY_SIZE(VMMC_VSEL_table
),
189 .voltage_table
= VMMC_VSEL_table
,
190 .enable_time_us
= 100,
194 static struct tps_info tps65911_regs
[] = {
197 .enable_time_us
= 2200,
203 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
204 .voltage_table
= VIO_VSEL_table
,
205 .enable_time_us
= 350,
212 .enable_time_us
= 350,
219 .enable_time_us
= 350,
226 .enable_time_us
= 900,
233 .enable_time_us
= 420,
240 .enable_time_us
= 420,
247 .enable_time_us
= 230,
254 .enable_time_us
= 230,
261 .enable_time_us
= 230,
268 .enable_time_us
= 230,
275 .enable_time_us
= 230,
282 .enable_time_us
= 230,
286 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
287 static unsigned int tps65910_ext_sleep_control
[] = {
289 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
290 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
291 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
292 EXT_CONTROL_REG_BITS(VDD3
, 1, 3),
293 EXT_CONTROL_REG_BITS(VDIG1
, 0, 1),
294 EXT_CONTROL_REG_BITS(VDIG2
, 0, 2),
295 EXT_CONTROL_REG_BITS(VPLL
, 0, 6),
296 EXT_CONTROL_REG_BITS(VDAC
, 0, 7),
297 EXT_CONTROL_REG_BITS(VAUX1
, 0, 3),
298 EXT_CONTROL_REG_BITS(VAUX2
, 0, 4),
299 EXT_CONTROL_REG_BITS(VAUX33
, 0, 5),
300 EXT_CONTROL_REG_BITS(VMMC
, 0, 0),
303 static unsigned int tps65911_ext_sleep_control
[] = {
305 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
306 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
307 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
308 EXT_CONTROL_REG_BITS(VDDCTRL
, 1, 3),
309 EXT_CONTROL_REG_BITS(LDO1
, 0, 1),
310 EXT_CONTROL_REG_BITS(LDO2
, 0, 2),
311 EXT_CONTROL_REG_BITS(LDO3
, 0, 7),
312 EXT_CONTROL_REG_BITS(LDO4
, 0, 6),
313 EXT_CONTROL_REG_BITS(LDO5
, 0, 3),
314 EXT_CONTROL_REG_BITS(LDO6
, 0, 0),
315 EXT_CONTROL_REG_BITS(LDO7
, 0, 5),
316 EXT_CONTROL_REG_BITS(LDO8
, 0, 4),
319 struct tps65910_reg
{
320 struct regulator_desc
*desc
;
321 struct tps65910
*mfd
;
322 struct regulator_dev
**rdev
;
323 struct tps_info
**info
;
327 int (*get_ctrl_reg
)(int);
328 unsigned int *ext_sleep_control
;
329 unsigned int board_ext_control
[TPS65910_NUM_REGS
];
332 static inline int tps65910_read(struct tps65910_reg
*pmic
, u8 reg
)
337 err
= pmic
->mfd
->read(pmic
->mfd
, reg
, 1, &val
);
344 static inline int tps65910_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
346 return pmic
->mfd
->write(pmic
->mfd
, reg
, 1, &val
);
349 static int tps65910_modify_bits(struct tps65910_reg
*pmic
, u8 reg
,
350 u8 set_mask
, u8 clear_mask
)
354 mutex_lock(&pmic
->mutex
);
356 data
= tps65910_read(pmic
, reg
);
358 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
365 err
= tps65910_write(pmic
, reg
, data
);
367 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
370 mutex_unlock(&pmic
->mutex
);
374 static int tps65910_reg_read(struct tps65910_reg
*pmic
, u8 reg
)
378 mutex_lock(&pmic
->mutex
);
380 data
= tps65910_read(pmic
, reg
);
382 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
384 mutex_unlock(&pmic
->mutex
);
388 static int tps65910_reg_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
392 mutex_lock(&pmic
->mutex
);
394 err
= tps65910_write(pmic
, reg
, val
);
396 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
398 mutex_unlock(&pmic
->mutex
);
402 static int tps65910_get_ctrl_register(int id
)
405 case TPS65910_REG_VRTC
:
406 return TPS65910_VRTC
;
407 case TPS65910_REG_VIO
:
409 case TPS65910_REG_VDD1
:
410 return TPS65910_VDD1
;
411 case TPS65910_REG_VDD2
:
412 return TPS65910_VDD2
;
413 case TPS65910_REG_VDD3
:
414 return TPS65910_VDD3
;
415 case TPS65910_REG_VDIG1
:
416 return TPS65910_VDIG1
;
417 case TPS65910_REG_VDIG2
:
418 return TPS65910_VDIG2
;
419 case TPS65910_REG_VPLL
:
420 return TPS65910_VPLL
;
421 case TPS65910_REG_VDAC
:
422 return TPS65910_VDAC
;
423 case TPS65910_REG_VAUX1
:
424 return TPS65910_VAUX1
;
425 case TPS65910_REG_VAUX2
:
426 return TPS65910_VAUX2
;
427 case TPS65910_REG_VAUX33
:
428 return TPS65910_VAUX33
;
429 case TPS65910_REG_VMMC
:
430 return TPS65910_VMMC
;
436 static int tps65911_get_ctrl_register(int id
)
439 case TPS65910_REG_VRTC
:
440 return TPS65910_VRTC
;
441 case TPS65910_REG_VIO
:
443 case TPS65910_REG_VDD1
:
444 return TPS65910_VDD1
;
445 case TPS65910_REG_VDD2
:
446 return TPS65910_VDD2
;
447 case TPS65911_REG_VDDCTRL
:
448 return TPS65911_VDDCTRL
;
449 case TPS65911_REG_LDO1
:
450 return TPS65911_LDO1
;
451 case TPS65911_REG_LDO2
:
452 return TPS65911_LDO2
;
453 case TPS65911_REG_LDO3
:
454 return TPS65911_LDO3
;
455 case TPS65911_REG_LDO4
:
456 return TPS65911_LDO4
;
457 case TPS65911_REG_LDO5
:
458 return TPS65911_LDO5
;
459 case TPS65911_REG_LDO6
:
460 return TPS65911_LDO6
;
461 case TPS65911_REG_LDO7
:
462 return TPS65911_LDO7
;
463 case TPS65911_REG_LDO8
:
464 return TPS65911_LDO8
;
470 static int tps65910_is_enabled(struct regulator_dev
*dev
)
472 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
473 int reg
, value
, id
= rdev_get_id(dev
);
475 reg
= pmic
->get_ctrl_reg(id
);
479 value
= tps65910_reg_read(pmic
, reg
);
483 return value
& TPS65910_SUPPLY_STATE_ENABLED
;
486 static int tps65910_enable(struct regulator_dev
*dev
)
488 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
489 struct tps65910
*mfd
= pmic
->mfd
;
490 int reg
, id
= rdev_get_id(dev
);
492 reg
= pmic
->get_ctrl_reg(id
);
496 return tps65910_set_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
499 static int tps65910_disable(struct regulator_dev
*dev
)
501 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
502 struct tps65910
*mfd
= pmic
->mfd
;
503 int reg
, id
= rdev_get_id(dev
);
505 reg
= pmic
->get_ctrl_reg(id
);
509 return tps65910_clear_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
512 static int tps65910_enable_time(struct regulator_dev
*dev
)
514 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
515 int id
= rdev_get_id(dev
);
516 return pmic
->info
[id
]->enable_time_us
;
519 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
521 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
522 struct tps65910
*mfd
= pmic
->mfd
;
523 int reg
, value
, id
= rdev_get_id(dev
);
525 reg
= pmic
->get_ctrl_reg(id
);
530 case REGULATOR_MODE_NORMAL
:
531 return tps65910_modify_bits(pmic
, reg
, LDO_ST_ON_BIT
,
533 case REGULATOR_MODE_IDLE
:
534 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
535 return tps65910_set_bits(mfd
, reg
, value
);
536 case REGULATOR_MODE_STANDBY
:
537 return tps65910_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
543 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
545 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
546 int reg
, value
, id
= rdev_get_id(dev
);
548 reg
= pmic
->get_ctrl_reg(id
);
552 value
= tps65910_reg_read(pmic
, reg
);
556 if (!(value
& LDO_ST_ON_BIT
))
557 return REGULATOR_MODE_STANDBY
;
558 else if (value
& LDO_ST_MODE_BIT
)
559 return REGULATOR_MODE_IDLE
;
561 return REGULATOR_MODE_NORMAL
;
564 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev
*dev
)
566 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
567 int id
= rdev_get_id(dev
);
568 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
571 case TPS65910_REG_VDD1
:
572 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_OP
);
573 mult
= tps65910_reg_read(pmic
, TPS65910_VDD1
);
574 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
575 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_SR
);
576 sr
= opvsel
& VDD1_OP_CMD_MASK
;
577 opvsel
&= VDD1_OP_SEL_MASK
;
578 srvsel
&= VDD1_SR_SEL_MASK
;
581 case TPS65910_REG_VDD2
:
582 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_OP
);
583 mult
= tps65910_reg_read(pmic
, TPS65910_VDD2
);
584 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
585 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_SR
);
586 sr
= opvsel
& VDD2_OP_CMD_MASK
;
587 opvsel
&= VDD2_OP_SEL_MASK
;
588 srvsel
&= VDD2_SR_SEL_MASK
;
591 case TPS65911_REG_VDDCTRL
:
592 opvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_OP
);
593 srvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_SR
);
594 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
595 opvsel
&= VDDCTRL_OP_SEL_MASK
;
596 srvsel
&= VDDCTRL_SR_SEL_MASK
;
601 /* multiplier 0 == 1 but 2,3 normal */
606 /* normalise to valid range */
609 if (srvsel
> vselmax
)
614 /* normalise to valid range*/
617 if (opvsel
> vselmax
)
624 static int tps65910_get_voltage(struct regulator_dev
*dev
)
626 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
627 int reg
, value
, id
= rdev_get_id(dev
), voltage
= 0;
629 reg
= pmic
->get_ctrl_reg(id
);
633 value
= tps65910_reg_read(pmic
, reg
);
638 case TPS65910_REG_VIO
:
639 case TPS65910_REG_VDIG1
:
640 case TPS65910_REG_VDIG2
:
641 case TPS65910_REG_VPLL
:
642 case TPS65910_REG_VDAC
:
643 case TPS65910_REG_VAUX1
:
644 case TPS65910_REG_VAUX2
:
645 case TPS65910_REG_VAUX33
:
646 case TPS65910_REG_VMMC
:
647 value
&= LDO_SEL_MASK
;
648 value
>>= LDO_SEL_SHIFT
;
654 voltage
= pmic
->info
[id
]->voltage_table
[value
] * 1000;
659 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
661 return 5 * 1000 * 1000;
664 static int tps65911_get_voltage(struct regulator_dev
*dev
)
666 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
667 int step_mv
, id
= rdev_get_id(dev
);
670 reg
= pmic
->get_ctrl_reg(id
);
672 value
= tps65910_reg_read(pmic
, reg
);
675 case TPS65911_REG_LDO1
:
676 case TPS65911_REG_LDO2
:
677 case TPS65911_REG_LDO4
:
678 value
&= LDO1_SEL_MASK
;
679 value
>>= LDO_SEL_SHIFT
;
680 /* The first 5 values of the selector correspond to 1V */
688 case TPS65911_REG_LDO3
:
689 case TPS65911_REG_LDO5
:
690 case TPS65911_REG_LDO6
:
691 case TPS65911_REG_LDO7
:
692 case TPS65911_REG_LDO8
:
693 value
&= LDO3_SEL_MASK
;
694 value
>>= LDO_SEL_SHIFT
;
695 /* The first 3 values of the selector correspond to 1V */
703 case TPS65910_REG_VIO
:
704 value
&= LDO_SEL_MASK
;
705 value
>>= LDO_SEL_SHIFT
;
706 return pmic
->info
[id
]->voltage_table
[value
] * 1000;
711 return (LDO_MIN_VOLT
+ value
* step_mv
) * 1000;
714 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev
*dev
,
717 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
718 int id
= rdev_get_id(dev
), vsel
;
722 case TPS65910_REG_VDD1
:
723 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
726 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
728 tps65910_modify_bits(pmic
, TPS65910_VDD1
,
729 (dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
),
730 VDD1_VGAIN_SEL_MASK
);
731 tps65910_reg_write(pmic
, TPS65910_VDD1_OP
, vsel
);
733 case TPS65910_REG_VDD2
:
734 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
737 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
739 tps65910_modify_bits(pmic
, TPS65910_VDD2
,
740 (dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
),
741 VDD1_VGAIN_SEL_MASK
);
742 tps65910_reg_write(pmic
, TPS65910_VDD2_OP
, vsel
);
744 case TPS65911_REG_VDDCTRL
:
746 tps65910_reg_write(pmic
, TPS65911_VDDCTRL_OP
, vsel
);
752 static int tps65910_set_voltage_sel(struct regulator_dev
*dev
,
755 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
756 int reg
, id
= rdev_get_id(dev
);
758 reg
= pmic
->get_ctrl_reg(id
);
763 case TPS65910_REG_VIO
:
764 case TPS65910_REG_VDIG1
:
765 case TPS65910_REG_VDIG2
:
766 case TPS65910_REG_VPLL
:
767 case TPS65910_REG_VDAC
:
768 case TPS65910_REG_VAUX1
:
769 case TPS65910_REG_VAUX2
:
770 case TPS65910_REG_VAUX33
:
771 case TPS65910_REG_VMMC
:
772 return tps65910_modify_bits(pmic
, reg
,
773 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
779 static int tps65911_set_voltage_sel(struct regulator_dev
*dev
,
782 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
783 int reg
, id
= rdev_get_id(dev
);
785 reg
= pmic
->get_ctrl_reg(id
);
790 case TPS65911_REG_LDO1
:
791 case TPS65911_REG_LDO2
:
792 case TPS65911_REG_LDO4
:
793 return tps65910_modify_bits(pmic
, reg
,
794 (selector
<< LDO_SEL_SHIFT
), LDO1_SEL_MASK
);
795 case TPS65911_REG_LDO3
:
796 case TPS65911_REG_LDO5
:
797 case TPS65911_REG_LDO6
:
798 case TPS65911_REG_LDO7
:
799 case TPS65911_REG_LDO8
:
800 return tps65910_modify_bits(pmic
, reg
,
801 (selector
<< LDO_SEL_SHIFT
), LDO3_SEL_MASK
);
802 case TPS65910_REG_VIO
:
803 return tps65910_modify_bits(pmic
, reg
,
804 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
811 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
814 int volt
, mult
= 1, id
= rdev_get_id(dev
);
817 case TPS65910_REG_VDD1
:
818 case TPS65910_REG_VDD2
:
819 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
820 volt
= VDD1_2_MIN_VOLT
+
821 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
823 case TPS65911_REG_VDDCTRL
:
824 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
831 return volt
* 100 * mult
;
834 static int tps65910_list_voltage(struct regulator_dev
*dev
,
837 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
838 int id
= rdev_get_id(dev
), voltage
;
840 if (id
< TPS65910_REG_VIO
|| id
> TPS65910_REG_VMMC
)
843 if (selector
>= pmic
->info
[id
]->n_voltages
)
846 voltage
= pmic
->info
[id
]->voltage_table
[selector
] * 1000;
851 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
853 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
854 int step_mv
= 0, id
= rdev_get_id(dev
);
857 case TPS65911_REG_LDO1
:
858 case TPS65911_REG_LDO2
:
859 case TPS65911_REG_LDO4
:
860 /* The first 5 values of the selector correspond to 1V */
868 case TPS65911_REG_LDO3
:
869 case TPS65911_REG_LDO5
:
870 case TPS65911_REG_LDO6
:
871 case TPS65911_REG_LDO7
:
872 case TPS65911_REG_LDO8
:
873 /* The first 3 values of the selector correspond to 1V */
881 case TPS65910_REG_VIO
:
882 return pmic
->info
[id
]->voltage_table
[selector
] * 1000;
887 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
890 static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev
*dev
,
891 unsigned int old_selector
, unsigned int new_selector
)
893 int id
= rdev_get_id(dev
);
894 int old_volt
, new_volt
;
896 old_volt
= tps65910_list_voltage_dcdc(dev
, old_selector
);
900 new_volt
= tps65910_list_voltage_dcdc(dev
, new_selector
);
904 /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
906 case TPS65910_REG_VDD1
:
907 case TPS65910_REG_VDD2
:
908 return DIV_ROUND_UP(abs(old_volt
- new_volt
), 12500);
909 case TPS65911_REG_VDDCTRL
:
910 return DIV_ROUND_UP(abs(old_volt
- new_volt
), 5000);
915 /* Regulator ops (except VRTC) */
916 static struct regulator_ops tps65910_ops_dcdc
= {
917 .is_enabled
= tps65910_is_enabled
,
918 .enable
= tps65910_enable
,
919 .disable
= tps65910_disable
,
920 .enable_time
= tps65910_enable_time
,
921 .set_mode
= tps65910_set_mode
,
922 .get_mode
= tps65910_get_mode
,
923 .get_voltage_sel
= tps65910_get_voltage_dcdc_sel
,
924 .set_voltage_sel
= tps65910_set_voltage_dcdc_sel
,
925 .set_voltage_time_sel
= tps65910_set_voltage_dcdc_time_sel
,
926 .list_voltage
= tps65910_list_voltage_dcdc
,
929 static struct regulator_ops tps65910_ops_vdd3
= {
930 .is_enabled
= tps65910_is_enabled
,
931 .enable
= tps65910_enable
,
932 .disable
= tps65910_disable
,
933 .enable_time
= tps65910_enable_time
,
934 .set_mode
= tps65910_set_mode
,
935 .get_mode
= tps65910_get_mode
,
936 .get_voltage
= tps65910_get_voltage_vdd3
,
937 .list_voltage
= tps65910_list_voltage
,
940 static struct regulator_ops tps65910_ops
= {
941 .is_enabled
= tps65910_is_enabled
,
942 .enable
= tps65910_enable
,
943 .disable
= tps65910_disable
,
944 .enable_time
= tps65910_enable_time
,
945 .set_mode
= tps65910_set_mode
,
946 .get_mode
= tps65910_get_mode
,
947 .get_voltage
= tps65910_get_voltage
,
948 .set_voltage_sel
= tps65910_set_voltage_sel
,
949 .list_voltage
= tps65910_list_voltage
,
952 static struct regulator_ops tps65911_ops
= {
953 .is_enabled
= tps65910_is_enabled
,
954 .enable
= tps65910_enable
,
955 .disable
= tps65910_disable
,
956 .enable_time
= tps65910_enable_time
,
957 .set_mode
= tps65910_set_mode
,
958 .get_mode
= tps65910_get_mode
,
959 .get_voltage
= tps65911_get_voltage
,
960 .set_voltage_sel
= tps65911_set_voltage_sel
,
961 .list_voltage
= tps65911_list_voltage
,
964 static int tps65910_set_ext_sleep_config(struct tps65910_reg
*pmic
,
965 int id
, int ext_sleep_config
)
967 struct tps65910
*mfd
= pmic
->mfd
;
968 u8 regoffs
= (pmic
->ext_sleep_control
[id
] >> 8) & 0xFF;
969 u8 bit_pos
= (1 << pmic
->ext_sleep_control
[id
] & 0xFF);
973 * Regulator can not be control from multiple external input EN1, EN2
976 if (ext_sleep_config
& EXT_SLEEP_CONTROL
) {
978 en_count
= ((ext_sleep_config
&
979 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
) != 0);
980 en_count
+= ((ext_sleep_config
&
981 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
) != 0);
982 en_count
+= ((ext_sleep_config
&
983 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
) != 0);
984 en_count
+= ((ext_sleep_config
&
985 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
) != 0);
988 "External sleep control flag is not proper\n");
993 pmic
->board_ext_control
[id
] = ext_sleep_config
;
995 /* External EN1 control */
996 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
)
997 ret
= tps65910_set_bits(mfd
,
998 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
1000 ret
= tps65910_clear_bits(mfd
,
1001 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
1004 "Error in configuring external control EN1\n");
1008 /* External EN2 control */
1009 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
)
1010 ret
= tps65910_set_bits(mfd
,
1011 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
1013 ret
= tps65910_clear_bits(mfd
,
1014 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
1017 "Error in configuring external control EN2\n");
1021 /* External EN3 control for TPS65910 LDO only */
1022 if ((tps65910_chip_id(mfd
) == TPS65910
) &&
1023 (id
>= TPS65910_REG_VDIG1
)) {
1024 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
)
1025 ret
= tps65910_set_bits(mfd
,
1026 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
1028 ret
= tps65910_clear_bits(mfd
,
1029 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
1032 "Error in configuring external control EN3\n");
1037 /* Return if no external control is selected */
1038 if (!(ext_sleep_config
& EXT_SLEEP_CONTROL
)) {
1039 /* Clear all sleep controls */
1040 ret
= tps65910_clear_bits(mfd
,
1041 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
1043 ret
= tps65910_clear_bits(mfd
,
1044 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
1047 "Error in configuring SLEEP register\n");
1052 * For regulator that has separate operational and sleep register make
1053 * sure that operational is used and clear sleep register to turn
1054 * regulator off when external control is inactive
1056 if ((id
== TPS65910_REG_VDD1
) ||
1057 (id
== TPS65910_REG_VDD2
) ||
1058 ((id
== TPS65911_REG_VDDCTRL
) &&
1059 (tps65910_chip_id(mfd
) == TPS65911
))) {
1060 int op_reg_add
= pmic
->get_ctrl_reg(id
) + 1;
1061 int sr_reg_add
= pmic
->get_ctrl_reg(id
) + 2;
1062 int opvsel
= tps65910_reg_read(pmic
, op_reg_add
);
1063 int srvsel
= tps65910_reg_read(pmic
, sr_reg_add
);
1064 if (opvsel
& VDD1_OP_CMD_MASK
) {
1065 u8 reg_val
= srvsel
& VDD1_OP_SEL_MASK
;
1066 ret
= tps65910_reg_write(pmic
, op_reg_add
, reg_val
);
1069 "Error in configuring op register\n");
1073 ret
= tps65910_reg_write(pmic
, sr_reg_add
, 0);
1075 dev_err(mfd
->dev
, "Error in settting sr register\n");
1080 ret
= tps65910_clear_bits(mfd
,
1081 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
1083 if (ext_sleep_config
& TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
)
1084 ret
= tps65910_set_bits(mfd
,
1085 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
1087 ret
= tps65910_clear_bits(mfd
,
1088 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
1092 "Error in configuring SLEEP register\n");
1097 static __devinit
int tps65910_probe(struct platform_device
*pdev
)
1099 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1100 struct tps_info
*info
;
1101 struct regulator_init_data
*reg_data
;
1102 struct regulator_dev
*rdev
;
1103 struct tps65910_reg
*pmic
;
1104 struct tps65910_board
*pmic_plat_data
;
1107 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
1108 if (!pmic_plat_data
)
1111 pmic
= kzalloc(sizeof(*pmic
), GFP_KERNEL
);
1115 mutex_init(&pmic
->mutex
);
1116 pmic
->mfd
= tps65910
;
1117 platform_set_drvdata(pdev
, pmic
);
1119 /* Give control of all register to control port */
1120 tps65910_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
1121 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
1123 switch(tps65910_chip_id(tps65910
)) {
1125 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
1126 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
1127 pmic
->ext_sleep_control
= tps65910_ext_sleep_control
;
1128 info
= tps65910_regs
;
1131 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
1132 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
1133 pmic
->ext_sleep_control
= tps65911_ext_sleep_control
;
1134 info
= tps65911_regs
;
1137 pr_err("Invalid tps chip version\n");
1142 pmic
->desc
= kcalloc(pmic
->num_regulators
,
1143 sizeof(struct regulator_desc
), GFP_KERNEL
);
1149 pmic
->info
= kcalloc(pmic
->num_regulators
,
1150 sizeof(struct tps_info
*), GFP_KERNEL
);
1156 pmic
->rdev
= kcalloc(pmic
->num_regulators
,
1157 sizeof(struct regulator_dev
*), GFP_KERNEL
);
1163 for (i
= 0; i
< pmic
->num_regulators
&& i
< TPS65910_NUM_REGS
;
1166 reg_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
1168 /* Regulator API handles empty constraints but not NULL
1173 /* Register the regulators */
1174 pmic
->info
[i
] = info
;
1176 pmic
->desc
[i
].name
= info
->name
;
1177 pmic
->desc
[i
].id
= i
;
1178 pmic
->desc
[i
].n_voltages
= info
->n_voltages
;
1180 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
1181 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1182 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
1183 VDD1_2_NUM_VOLT_COARSE
;
1184 } else if (i
== TPS65910_REG_VDD3
) {
1185 if (tps65910_chip_id(tps65910
) == TPS65910
)
1186 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
1188 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1190 if (tps65910_chip_id(tps65910
) == TPS65910
)
1191 pmic
->desc
[i
].ops
= &tps65910_ops
;
1193 pmic
->desc
[i
].ops
= &tps65911_ops
;
1196 err
= tps65910_set_ext_sleep_config(pmic
, i
,
1197 pmic_plat_data
->regulator_ext_sleep_control
[i
]);
1199 * Failing on regulator for configuring externally control
1200 * is not a serious issue, just throw warning.
1203 dev_warn(tps65910
->dev
,
1204 "Failed to initialise ext control config\n");
1206 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
1207 pmic
->desc
[i
].owner
= THIS_MODULE
;
1209 rdev
= regulator_register(&pmic
->desc
[i
],
1210 tps65910
->dev
, reg_data
, pmic
, NULL
);
1212 dev_err(tps65910
->dev
,
1213 "failed to register %s regulator\n",
1215 err
= PTR_ERR(rdev
);
1216 goto err_unregister_regulator
;
1219 /* Save regulator for cleanup */
1220 pmic
->rdev
[i
] = rdev
;
1224 err_unregister_regulator
:
1226 regulator_unregister(pmic
->rdev
[i
]);
1237 static int __devexit
tps65910_remove(struct platform_device
*pdev
)
1239 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1242 for (i
= 0; i
< pmic
->num_regulators
; i
++)
1243 regulator_unregister(pmic
->rdev
[i
]);
1252 static void tps65910_shutdown(struct platform_device
*pdev
)
1254 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1258 * Before bootloader jumps to kernel, it makes sure that required
1259 * external control signals are in desired state so that given rails
1260 * can be configure accordingly.
1261 * If rails are configured to be controlled from external control
1262 * then before shutting down/rebooting the system, the external
1263 * control configuration need to be remove from the rails so that
1264 * its output will be available as per register programming even
1265 * if external controls are removed. This is require when the POR
1266 * value of the control signals are not in active state and before
1267 * bootloader initializes it, the system requires the rail output
1268 * to be active for booting.
1270 for (i
= 0; i
< pmic
->num_regulators
; i
++) {
1275 err
= tps65910_set_ext_sleep_config(pmic
, i
, 0);
1278 "Error in clearing external control\n");
1282 static struct platform_driver tps65910_driver
= {
1284 .name
= "tps65910-pmic",
1285 .owner
= THIS_MODULE
,
1287 .probe
= tps65910_probe
,
1288 .remove
= __devexit_p(tps65910_remove
),
1289 .shutdown
= tps65910_shutdown
,
1292 static int __init
tps65910_init(void)
1294 return platform_driver_register(&tps65910_driver
);
1296 subsys_initcall(tps65910_init
);
1298 static void __exit
tps65910_cleanup(void)
1300 platform_driver_unregister(&tps65910_driver
);
1302 module_exit(tps65910_cleanup
);
1304 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1305 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1306 MODULE_LICENSE("GPL v2");
1307 MODULE_ALIAS("platform:tps65910-pmic");