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/slab.h>
24 #include <linux/gpio.h>
25 #include <linux/mfd/tps65910.h>
26 #include <linux/regulator/of_regulator.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 millivolts */
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 millivolts */
42 static const u16 VDD3_VSEL_table
[] = {
46 /* supported VDIG1 voltages in millivolts */
47 static const u16 VDIG1_VSEL_table
[] = {
48 1200, 1500, 1800, 2700,
51 /* supported VDIG2 voltages in millivolts */
52 static const u16 VDIG2_VSEL_table
[] = {
53 1000, 1100, 1200, 1800,
56 /* supported VPLL voltages in millivolts */
57 static const u16 VPLL_VSEL_table
[] = {
58 1000, 1100, 1800, 2500,
61 /* supported VDAC voltages in millivolts */
62 static const u16 VDAC_VSEL_table
[] = {
63 1800, 2600, 2800, 2850,
66 /* supported VAUX1 voltages in millivolts */
67 static const u16 VAUX1_VSEL_table
[] = {
68 1800, 2500, 2800, 2850,
71 /* supported VAUX2 voltages in millivolts */
72 static const u16 VAUX2_VSEL_table
[] = {
73 1800, 2800, 2900, 3300,
76 /* supported VAUX33 voltages in millivolts */
77 static const u16 VAUX33_VSEL_table
[] = {
78 1800, 2000, 2800, 3300,
81 /* supported VMMC voltages in millivolts */
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
= tps65910_reg_read(pmic
->mfd
, reg
, &val
);
344 static int tps65910_modify_bits(struct tps65910_reg
*pmic
, u8 reg
,
345 u8 set_mask
, u8 clear_mask
)
349 mutex_lock(&pmic
->mutex
);
351 data
= tps65910_read(pmic
, reg
);
353 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
360 err
= tps65910_reg_write(pmic
->mfd
, reg
, data
);
362 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
365 mutex_unlock(&pmic
->mutex
);
369 static int tps65910_reg_read_locked(struct tps65910_reg
*pmic
, u8 reg
)
373 mutex_lock(&pmic
->mutex
);
375 data
= tps65910_read(pmic
, reg
);
377 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
379 mutex_unlock(&pmic
->mutex
);
383 static int tps65910_reg_write_locked(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
387 mutex_lock(&pmic
->mutex
);
389 err
= tps65910_reg_write(pmic
->mfd
, reg
, val
);
391 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
393 mutex_unlock(&pmic
->mutex
);
397 static int tps65910_get_ctrl_register(int id
)
400 case TPS65910_REG_VRTC
:
401 return TPS65910_VRTC
;
402 case TPS65910_REG_VIO
:
404 case TPS65910_REG_VDD1
:
405 return TPS65910_VDD1
;
406 case TPS65910_REG_VDD2
:
407 return TPS65910_VDD2
;
408 case TPS65910_REG_VDD3
:
409 return TPS65910_VDD3
;
410 case TPS65910_REG_VDIG1
:
411 return TPS65910_VDIG1
;
412 case TPS65910_REG_VDIG2
:
413 return TPS65910_VDIG2
;
414 case TPS65910_REG_VPLL
:
415 return TPS65910_VPLL
;
416 case TPS65910_REG_VDAC
:
417 return TPS65910_VDAC
;
418 case TPS65910_REG_VAUX1
:
419 return TPS65910_VAUX1
;
420 case TPS65910_REG_VAUX2
:
421 return TPS65910_VAUX2
;
422 case TPS65910_REG_VAUX33
:
423 return TPS65910_VAUX33
;
424 case TPS65910_REG_VMMC
:
425 return TPS65910_VMMC
;
431 static int tps65911_get_ctrl_register(int id
)
434 case TPS65910_REG_VRTC
:
435 return TPS65910_VRTC
;
436 case TPS65910_REG_VIO
:
438 case TPS65910_REG_VDD1
:
439 return TPS65910_VDD1
;
440 case TPS65910_REG_VDD2
:
441 return TPS65910_VDD2
;
442 case TPS65911_REG_VDDCTRL
:
443 return TPS65911_VDDCTRL
;
444 case TPS65911_REG_LDO1
:
445 return TPS65911_LDO1
;
446 case TPS65911_REG_LDO2
:
447 return TPS65911_LDO2
;
448 case TPS65911_REG_LDO3
:
449 return TPS65911_LDO3
;
450 case TPS65911_REG_LDO4
:
451 return TPS65911_LDO4
;
452 case TPS65911_REG_LDO5
:
453 return TPS65911_LDO5
;
454 case TPS65911_REG_LDO6
:
455 return TPS65911_LDO6
;
456 case TPS65911_REG_LDO7
:
457 return TPS65911_LDO7
;
458 case TPS65911_REG_LDO8
:
459 return TPS65911_LDO8
;
465 static int tps65910_enable_time(struct regulator_dev
*dev
)
467 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
468 int id
= rdev_get_id(dev
);
469 return pmic
->info
[id
]->enable_time_us
;
472 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
474 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
475 struct tps65910
*mfd
= pmic
->mfd
;
476 int reg
, value
, id
= rdev_get_id(dev
);
478 reg
= pmic
->get_ctrl_reg(id
);
483 case REGULATOR_MODE_NORMAL
:
484 return tps65910_modify_bits(pmic
, reg
, LDO_ST_ON_BIT
,
486 case REGULATOR_MODE_IDLE
:
487 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
488 return tps65910_reg_set_bits(mfd
, reg
, value
);
489 case REGULATOR_MODE_STANDBY
:
490 return tps65910_reg_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
496 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
498 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
499 int reg
, value
, id
= rdev_get_id(dev
);
501 reg
= pmic
->get_ctrl_reg(id
);
505 value
= tps65910_reg_read_locked(pmic
, reg
);
509 if (!(value
& LDO_ST_ON_BIT
))
510 return REGULATOR_MODE_STANDBY
;
511 else if (value
& LDO_ST_MODE_BIT
)
512 return REGULATOR_MODE_IDLE
;
514 return REGULATOR_MODE_NORMAL
;
517 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev
*dev
)
519 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
520 int id
= rdev_get_id(dev
);
521 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
524 case TPS65910_REG_VDD1
:
525 opvsel
= tps65910_reg_read_locked(pmic
, TPS65910_VDD1_OP
);
526 mult
= tps65910_reg_read_locked(pmic
, TPS65910_VDD1
);
527 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
528 srvsel
= tps65910_reg_read_locked(pmic
, TPS65910_VDD1_SR
);
529 sr
= opvsel
& VDD1_OP_CMD_MASK
;
530 opvsel
&= VDD1_OP_SEL_MASK
;
531 srvsel
&= VDD1_SR_SEL_MASK
;
534 case TPS65910_REG_VDD2
:
535 opvsel
= tps65910_reg_read_locked(pmic
, TPS65910_VDD2_OP
);
536 mult
= tps65910_reg_read_locked(pmic
, TPS65910_VDD2
);
537 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
538 srvsel
= tps65910_reg_read_locked(pmic
, TPS65910_VDD2_SR
);
539 sr
= opvsel
& VDD2_OP_CMD_MASK
;
540 opvsel
&= VDD2_OP_SEL_MASK
;
541 srvsel
&= VDD2_SR_SEL_MASK
;
544 case TPS65911_REG_VDDCTRL
:
545 opvsel
= tps65910_reg_read_locked(pmic
, TPS65911_VDDCTRL_OP
);
546 srvsel
= tps65910_reg_read_locked(pmic
, TPS65911_VDDCTRL_SR
);
547 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
548 opvsel
&= VDDCTRL_OP_SEL_MASK
;
549 srvsel
&= VDDCTRL_SR_SEL_MASK
;
554 /* multiplier 0 == 1 but 2,3 normal */
559 /* normalise to valid range */
562 if (srvsel
> vselmax
)
567 /* normalise to valid range*/
570 if (opvsel
> vselmax
)
577 static int tps65910_get_voltage_sel(struct regulator_dev
*dev
)
579 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
580 int reg
, value
, id
= rdev_get_id(dev
);
582 reg
= pmic
->get_ctrl_reg(id
);
586 value
= tps65910_reg_read_locked(pmic
, reg
);
591 case TPS65910_REG_VIO
:
592 case TPS65910_REG_VDIG1
:
593 case TPS65910_REG_VDIG2
:
594 case TPS65910_REG_VPLL
:
595 case TPS65910_REG_VDAC
:
596 case TPS65910_REG_VAUX1
:
597 case TPS65910_REG_VAUX2
:
598 case TPS65910_REG_VAUX33
:
599 case TPS65910_REG_VMMC
:
600 value
&= LDO_SEL_MASK
;
601 value
>>= LDO_SEL_SHIFT
;
610 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
612 return 5 * 1000 * 1000;
615 static int tps65911_get_voltage_sel(struct regulator_dev
*dev
)
617 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
618 int id
= rdev_get_id(dev
);
621 reg
= pmic
->get_ctrl_reg(id
);
623 value
= tps65910_reg_read_locked(pmic
, reg
);
626 case TPS65911_REG_LDO1
:
627 case TPS65911_REG_LDO2
:
628 case TPS65911_REG_LDO4
:
629 value
&= LDO1_SEL_MASK
;
630 value
>>= LDO_SEL_SHIFT
;
632 case TPS65911_REG_LDO3
:
633 case TPS65911_REG_LDO5
:
634 case TPS65911_REG_LDO6
:
635 case TPS65911_REG_LDO7
:
636 case TPS65911_REG_LDO8
:
637 value
&= LDO3_SEL_MASK
;
638 value
>>= LDO_SEL_SHIFT
;
640 case TPS65910_REG_VIO
:
641 value
&= LDO_SEL_MASK
;
642 value
>>= LDO_SEL_SHIFT
;
651 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev
*dev
,
654 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
655 int id
= rdev_get_id(dev
), vsel
;
659 case TPS65910_REG_VDD1
:
660 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
663 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
665 tps65910_modify_bits(pmic
, TPS65910_VDD1
,
666 (dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
),
667 VDD1_VGAIN_SEL_MASK
);
668 tps65910_reg_write_locked(pmic
, TPS65910_VDD1_OP
, vsel
);
670 case TPS65910_REG_VDD2
:
671 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
674 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
676 tps65910_modify_bits(pmic
, TPS65910_VDD2
,
677 (dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
),
678 VDD1_VGAIN_SEL_MASK
);
679 tps65910_reg_write_locked(pmic
, TPS65910_VDD2_OP
, vsel
);
681 case TPS65911_REG_VDDCTRL
:
683 tps65910_reg_write_locked(pmic
, TPS65911_VDDCTRL_OP
, vsel
);
689 static int tps65910_set_voltage_sel(struct regulator_dev
*dev
,
692 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
693 int reg
, id
= rdev_get_id(dev
);
695 reg
= pmic
->get_ctrl_reg(id
);
700 case TPS65910_REG_VIO
:
701 case TPS65910_REG_VDIG1
:
702 case TPS65910_REG_VDIG2
:
703 case TPS65910_REG_VPLL
:
704 case TPS65910_REG_VDAC
:
705 case TPS65910_REG_VAUX1
:
706 case TPS65910_REG_VAUX2
:
707 case TPS65910_REG_VAUX33
:
708 case TPS65910_REG_VMMC
:
709 return tps65910_modify_bits(pmic
, reg
,
710 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
716 static int tps65911_set_voltage_sel(struct regulator_dev
*dev
,
719 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
720 int reg
, id
= rdev_get_id(dev
);
722 reg
= pmic
->get_ctrl_reg(id
);
727 case TPS65911_REG_LDO1
:
728 case TPS65911_REG_LDO2
:
729 case TPS65911_REG_LDO4
:
730 return tps65910_modify_bits(pmic
, reg
,
731 (selector
<< LDO_SEL_SHIFT
), LDO1_SEL_MASK
);
732 case TPS65911_REG_LDO3
:
733 case TPS65911_REG_LDO5
:
734 case TPS65911_REG_LDO6
:
735 case TPS65911_REG_LDO7
:
736 case TPS65911_REG_LDO8
:
737 return tps65910_modify_bits(pmic
, reg
,
738 (selector
<< LDO_SEL_SHIFT
), LDO3_SEL_MASK
);
739 case TPS65910_REG_VIO
:
740 return tps65910_modify_bits(pmic
, reg
,
741 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
748 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
751 int volt
, mult
= 1, id
= rdev_get_id(dev
);
754 case TPS65910_REG_VDD1
:
755 case TPS65910_REG_VDD2
:
756 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
757 volt
= VDD1_2_MIN_VOLT
+
758 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
760 case TPS65911_REG_VDDCTRL
:
761 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
768 return volt
* 100 * mult
;
771 static int tps65910_list_voltage(struct regulator_dev
*dev
,
774 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
775 int id
= rdev_get_id(dev
), voltage
;
777 if (id
< TPS65910_REG_VIO
|| id
> TPS65910_REG_VMMC
)
780 if (selector
>= pmic
->info
[id
]->n_voltages
)
783 voltage
= pmic
->info
[id
]->voltage_table
[selector
] * 1000;
788 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
790 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
791 int step_mv
= 0, id
= rdev_get_id(dev
);
794 case TPS65911_REG_LDO1
:
795 case TPS65911_REG_LDO2
:
796 case TPS65911_REG_LDO4
:
797 /* The first 5 values of the selector correspond to 1V */
805 case TPS65911_REG_LDO3
:
806 case TPS65911_REG_LDO5
:
807 case TPS65911_REG_LDO6
:
808 case TPS65911_REG_LDO7
:
809 case TPS65911_REG_LDO8
:
810 /* The first 3 values of the selector correspond to 1V */
818 case TPS65910_REG_VIO
:
819 return pmic
->info
[id
]->voltage_table
[selector
] * 1000;
824 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
827 static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev
*dev
,
828 unsigned int old_selector
, unsigned int new_selector
)
830 int id
= rdev_get_id(dev
);
831 int old_volt
, new_volt
;
833 old_volt
= tps65910_list_voltage_dcdc(dev
, old_selector
);
837 new_volt
= tps65910_list_voltage_dcdc(dev
, new_selector
);
841 /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
843 case TPS65910_REG_VDD1
:
844 case TPS65910_REG_VDD2
:
845 return DIV_ROUND_UP(abs(old_volt
- new_volt
), 12500);
846 case TPS65911_REG_VDDCTRL
:
847 return DIV_ROUND_UP(abs(old_volt
- new_volt
), 5000);
852 /* Regulator ops (except VRTC) */
853 static struct regulator_ops tps65910_ops_dcdc
= {
854 .is_enabled
= regulator_is_enabled_regmap
,
855 .enable
= regulator_enable_regmap
,
856 .disable
= regulator_disable_regmap
,
857 .enable_time
= tps65910_enable_time
,
858 .set_mode
= tps65910_set_mode
,
859 .get_mode
= tps65910_get_mode
,
860 .get_voltage_sel
= tps65910_get_voltage_dcdc_sel
,
861 .set_voltage_sel
= tps65910_set_voltage_dcdc_sel
,
862 .set_voltage_time_sel
= tps65910_set_voltage_dcdc_time_sel
,
863 .list_voltage
= tps65910_list_voltage_dcdc
,
866 static struct regulator_ops tps65910_ops_vdd3
= {
867 .is_enabled
= regulator_is_enabled_regmap
,
868 .enable
= regulator_enable_regmap
,
869 .disable
= regulator_disable_regmap
,
870 .enable_time
= tps65910_enable_time
,
871 .set_mode
= tps65910_set_mode
,
872 .get_mode
= tps65910_get_mode
,
873 .get_voltage
= tps65910_get_voltage_vdd3
,
874 .list_voltage
= tps65910_list_voltage
,
877 static struct regulator_ops tps65910_ops
= {
878 .is_enabled
= regulator_is_enabled_regmap
,
879 .enable
= regulator_enable_regmap
,
880 .disable
= regulator_disable_regmap
,
881 .enable_time
= tps65910_enable_time
,
882 .set_mode
= tps65910_set_mode
,
883 .get_mode
= tps65910_get_mode
,
884 .get_voltage_sel
= tps65910_get_voltage_sel
,
885 .set_voltage_sel
= tps65910_set_voltage_sel
,
886 .list_voltage
= tps65910_list_voltage
,
889 static struct regulator_ops tps65911_ops
= {
890 .is_enabled
= regulator_is_enabled_regmap
,
891 .enable
= regulator_enable_regmap
,
892 .disable
= regulator_disable_regmap
,
893 .enable_time
= tps65910_enable_time
,
894 .set_mode
= tps65910_set_mode
,
895 .get_mode
= tps65910_get_mode
,
896 .get_voltage_sel
= tps65911_get_voltage_sel
,
897 .set_voltage_sel
= tps65911_set_voltage_sel
,
898 .list_voltage
= tps65911_list_voltage
,
901 static int tps65910_set_ext_sleep_config(struct tps65910_reg
*pmic
,
902 int id
, int ext_sleep_config
)
904 struct tps65910
*mfd
= pmic
->mfd
;
905 u8 regoffs
= (pmic
->ext_sleep_control
[id
] >> 8) & 0xFF;
906 u8 bit_pos
= (1 << pmic
->ext_sleep_control
[id
] & 0xFF);
910 * Regulator can not be control from multiple external input EN1, EN2
913 if (ext_sleep_config
& EXT_SLEEP_CONTROL
) {
915 en_count
= ((ext_sleep_config
&
916 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
) != 0);
917 en_count
+= ((ext_sleep_config
&
918 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
) != 0);
919 en_count
+= ((ext_sleep_config
&
920 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
) != 0);
921 en_count
+= ((ext_sleep_config
&
922 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
) != 0);
925 "External sleep control flag is not proper\n");
930 pmic
->board_ext_control
[id
] = ext_sleep_config
;
932 /* External EN1 control */
933 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
)
934 ret
= tps65910_reg_set_bits(mfd
,
935 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
937 ret
= tps65910_reg_clear_bits(mfd
,
938 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
941 "Error in configuring external control EN1\n");
945 /* External EN2 control */
946 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
)
947 ret
= tps65910_reg_set_bits(mfd
,
948 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
950 ret
= tps65910_reg_clear_bits(mfd
,
951 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
954 "Error in configuring external control EN2\n");
958 /* External EN3 control for TPS65910 LDO only */
959 if ((tps65910_chip_id(mfd
) == TPS65910
) &&
960 (id
>= TPS65910_REG_VDIG1
)) {
961 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
)
962 ret
= tps65910_reg_set_bits(mfd
,
963 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
965 ret
= tps65910_reg_clear_bits(mfd
,
966 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
969 "Error in configuring external control EN3\n");
974 /* Return if no external control is selected */
975 if (!(ext_sleep_config
& EXT_SLEEP_CONTROL
)) {
976 /* Clear all sleep controls */
977 ret
= tps65910_reg_clear_bits(mfd
,
978 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
980 ret
= tps65910_reg_clear_bits(mfd
,
981 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
984 "Error in configuring SLEEP register\n");
989 * For regulator that has separate operational and sleep register make
990 * sure that operational is used and clear sleep register to turn
991 * regulator off when external control is inactive
993 if ((id
== TPS65910_REG_VDD1
) ||
994 (id
== TPS65910_REG_VDD2
) ||
995 ((id
== TPS65911_REG_VDDCTRL
) &&
996 (tps65910_chip_id(mfd
) == TPS65911
))) {
997 int op_reg_add
= pmic
->get_ctrl_reg(id
) + 1;
998 int sr_reg_add
= pmic
->get_ctrl_reg(id
) + 2;
999 int opvsel
= tps65910_reg_read_locked(pmic
, op_reg_add
);
1000 int srvsel
= tps65910_reg_read_locked(pmic
, sr_reg_add
);
1001 if (opvsel
& VDD1_OP_CMD_MASK
) {
1002 u8 reg_val
= srvsel
& VDD1_OP_SEL_MASK
;
1003 ret
= tps65910_reg_write_locked(pmic
, op_reg_add
,
1007 "Error in configuring op register\n");
1011 ret
= tps65910_reg_write_locked(pmic
, sr_reg_add
, 0);
1013 dev_err(mfd
->dev
, "Error in settting sr register\n");
1018 ret
= tps65910_reg_clear_bits(mfd
,
1019 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
1021 if (ext_sleep_config
& TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
)
1022 ret
= tps65910_reg_set_bits(mfd
,
1023 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
1025 ret
= tps65910_reg_clear_bits(mfd
,
1026 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
1030 "Error in configuring SLEEP register\n");
1037 static struct of_regulator_match tps65910_matches
[] = {
1038 { .name
= "vrtc", .driver_data
= (void *) &tps65910_regs
[0] },
1039 { .name
= "vio", .driver_data
= (void *) &tps65910_regs
[1] },
1040 { .name
= "vdd1", .driver_data
= (void *) &tps65910_regs
[2] },
1041 { .name
= "vdd2", .driver_data
= (void *) &tps65910_regs
[3] },
1042 { .name
= "vdd3", .driver_data
= (void *) &tps65910_regs
[4] },
1043 { .name
= "vdig1", .driver_data
= (void *) &tps65910_regs
[5] },
1044 { .name
= "vdig2", .driver_data
= (void *) &tps65910_regs
[6] },
1045 { .name
= "vpll", .driver_data
= (void *) &tps65910_regs
[7] },
1046 { .name
= "vdac", .driver_data
= (void *) &tps65910_regs
[8] },
1047 { .name
= "vaux1", .driver_data
= (void *) &tps65910_regs
[9] },
1048 { .name
= "vaux2", .driver_data
= (void *) &tps65910_regs
[10] },
1049 { .name
= "vaux33", .driver_data
= (void *) &tps65910_regs
[11] },
1050 { .name
= "vmmc", .driver_data
= (void *) &tps65910_regs
[12] },
1053 static struct of_regulator_match tps65911_matches
[] = {
1054 { .name
= "vrtc", .driver_data
= (void *) &tps65911_regs
[0] },
1055 { .name
= "vio", .driver_data
= (void *) &tps65911_regs
[1] },
1056 { .name
= "vdd1", .driver_data
= (void *) &tps65911_regs
[2] },
1057 { .name
= "vdd2", .driver_data
= (void *) &tps65911_regs
[3] },
1058 { .name
= "vddctrl", .driver_data
= (void *) &tps65911_regs
[4] },
1059 { .name
= "ldo1", .driver_data
= (void *) &tps65911_regs
[5] },
1060 { .name
= "ldo2", .driver_data
= (void *) &tps65911_regs
[6] },
1061 { .name
= "ldo3", .driver_data
= (void *) &tps65911_regs
[7] },
1062 { .name
= "ldo4", .driver_data
= (void *) &tps65911_regs
[8] },
1063 { .name
= "ldo5", .driver_data
= (void *) &tps65911_regs
[9] },
1064 { .name
= "ldo6", .driver_data
= (void *) &tps65911_regs
[10] },
1065 { .name
= "ldo7", .driver_data
= (void *) &tps65911_regs
[11] },
1066 { .name
= "ldo8", .driver_data
= (void *) &tps65911_regs
[12] },
1069 static struct tps65910_board
*tps65910_parse_dt_reg_data(
1070 struct platform_device
*pdev
,
1071 struct of_regulator_match
**tps65910_reg_matches
)
1073 struct tps65910_board
*pmic_plat_data
;
1074 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1075 struct device_node
*np
= pdev
->dev
.parent
->of_node
;
1076 struct device_node
*regulators
;
1077 struct of_regulator_match
*matches
;
1079 int idx
= 0, ret
, count
;
1081 pmic_plat_data
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic_plat_data
),
1084 if (!pmic_plat_data
) {
1085 dev_err(&pdev
->dev
, "Failure to alloc pdata for regulators.\n");
1089 regulators
= of_find_node_by_name(np
, "regulators");
1091 dev_err(&pdev
->dev
, "regulator node not found\n");
1095 switch (tps65910_chip_id(tps65910
)) {
1097 count
= ARRAY_SIZE(tps65910_matches
);
1098 matches
= tps65910_matches
;
1101 count
= ARRAY_SIZE(tps65911_matches
);
1102 matches
= tps65911_matches
;
1105 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1109 ret
= of_regulator_match(pdev
->dev
.parent
, regulators
, matches
, count
);
1111 dev_err(&pdev
->dev
, "Error parsing regulator init data: %d\n",
1116 *tps65910_reg_matches
= matches
;
1118 for (idx
= 0; idx
< count
; idx
++) {
1119 if (!matches
[idx
].init_data
|| !matches
[idx
].of_node
)
1122 pmic_plat_data
->tps65910_pmic_init_data
[idx
] =
1123 matches
[idx
].init_data
;
1125 ret
= of_property_read_u32(matches
[idx
].of_node
,
1126 "ti,regulator-ext-sleep-control", &prop
);
1128 pmic_plat_data
->regulator_ext_sleep_control
[idx
] = prop
;
1131 return pmic_plat_data
;
1134 static inline struct tps65910_board
*tps65910_parse_dt_reg_data(
1135 struct platform_device
*pdev
,
1136 struct of_regulator_match
**tps65910_reg_matches
)
1138 *tps65910_reg_matches
= NULL
;
1143 static __devinit
int tps65910_probe(struct platform_device
*pdev
)
1145 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1146 struct regulator_config config
= { };
1147 struct tps_info
*info
;
1148 struct regulator_init_data
*reg_data
;
1149 struct regulator_dev
*rdev
;
1150 struct tps65910_reg
*pmic
;
1151 struct tps65910_board
*pmic_plat_data
;
1152 struct of_regulator_match
*tps65910_reg_matches
= NULL
;
1155 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
1156 if (!pmic_plat_data
&& tps65910
->dev
->of_node
)
1157 pmic_plat_data
= tps65910_parse_dt_reg_data(pdev
,
1158 &tps65910_reg_matches
);
1160 if (!pmic_plat_data
) {
1161 dev_err(&pdev
->dev
, "Platform data not found\n");
1165 pmic
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic
), GFP_KERNEL
);
1167 dev_err(&pdev
->dev
, "Memory allocation failed for pmic\n");
1171 mutex_init(&pmic
->mutex
);
1172 pmic
->mfd
= tps65910
;
1173 platform_set_drvdata(pdev
, pmic
);
1175 /* Give control of all register to control port */
1176 tps65910_reg_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
1177 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
1179 switch(tps65910_chip_id(tps65910
)) {
1181 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
1182 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
1183 pmic
->ext_sleep_control
= tps65910_ext_sleep_control
;
1184 info
= tps65910_regs
;
1187 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
1188 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
1189 pmic
->ext_sleep_control
= tps65911_ext_sleep_control
;
1190 info
= tps65911_regs
;
1193 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1197 pmic
->desc
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1198 sizeof(struct regulator_desc
), GFP_KERNEL
);
1200 dev_err(&pdev
->dev
, "Memory alloc fails for desc\n");
1204 pmic
->info
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1205 sizeof(struct tps_info
*), GFP_KERNEL
);
1207 dev_err(&pdev
->dev
, "Memory alloc fails for info\n");
1211 pmic
->rdev
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1212 sizeof(struct regulator_dev
*), GFP_KERNEL
);
1214 dev_err(&pdev
->dev
, "Memory alloc fails for rdev\n");
1218 for (i
= 0; i
< pmic
->num_regulators
&& i
< TPS65910_NUM_REGS
;
1221 reg_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
1223 /* Regulator API handles empty constraints but not NULL
1228 /* Register the regulators */
1229 pmic
->info
[i
] = info
;
1231 pmic
->desc
[i
].name
= info
->name
;
1232 pmic
->desc
[i
].id
= i
;
1233 pmic
->desc
[i
].n_voltages
= info
->n_voltages
;
1235 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
1236 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1237 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
1238 VDD1_2_NUM_VOLT_COARSE
;
1239 } else if (i
== TPS65910_REG_VDD3
) {
1240 if (tps65910_chip_id(tps65910
) == TPS65910
)
1241 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
1243 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1245 if (tps65910_chip_id(tps65910
) == TPS65910
)
1246 pmic
->desc
[i
].ops
= &tps65910_ops
;
1248 pmic
->desc
[i
].ops
= &tps65911_ops
;
1251 err
= tps65910_set_ext_sleep_config(pmic
, i
,
1252 pmic_plat_data
->regulator_ext_sleep_control
[i
]);
1254 * Failing on regulator for configuring externally control
1255 * is not a serious issue, just throw warning.
1258 dev_warn(tps65910
->dev
,
1259 "Failed to initialise ext control config\n");
1261 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
1262 pmic
->desc
[i
].owner
= THIS_MODULE
;
1263 pmic
->desc
[i
].enable_reg
= pmic
->get_ctrl_reg(i
);
1264 pmic
->desc
[i
].enable_mask
= TPS65910_SUPPLY_STATE_ENABLED
;
1266 config
.dev
= tps65910
->dev
;
1267 config
.init_data
= reg_data
;
1268 config
.driver_data
= pmic
;
1269 config
.regmap
= tps65910
->regmap
;
1271 if (tps65910_reg_matches
)
1272 config
.of_node
= tps65910_reg_matches
[i
].of_node
;
1274 rdev
= regulator_register(&pmic
->desc
[i
], &config
);
1276 dev_err(tps65910
->dev
,
1277 "failed to register %s regulator\n",
1279 err
= PTR_ERR(rdev
);
1280 goto err_unregister_regulator
;
1283 /* Save regulator for cleanup */
1284 pmic
->rdev
[i
] = rdev
;
1288 err_unregister_regulator
:
1290 regulator_unregister(pmic
->rdev
[i
]);
1294 static int __devexit
tps65910_remove(struct platform_device
*pdev
)
1296 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1299 for (i
= 0; i
< pmic
->num_regulators
; i
++)
1300 regulator_unregister(pmic
->rdev
[i
]);
1305 static void tps65910_shutdown(struct platform_device
*pdev
)
1307 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1311 * Before bootloader jumps to kernel, it makes sure that required
1312 * external control signals are in desired state so that given rails
1313 * can be configure accordingly.
1314 * If rails are configured to be controlled from external control
1315 * then before shutting down/rebooting the system, the external
1316 * control configuration need to be remove from the rails so that
1317 * its output will be available as per register programming even
1318 * if external controls are removed. This is require when the POR
1319 * value of the control signals are not in active state and before
1320 * bootloader initializes it, the system requires the rail output
1321 * to be active for booting.
1323 for (i
= 0; i
< pmic
->num_regulators
; i
++) {
1328 err
= tps65910_set_ext_sleep_config(pmic
, i
, 0);
1331 "Error in clearing external control\n");
1335 static struct platform_driver tps65910_driver
= {
1337 .name
= "tps65910-pmic",
1338 .owner
= THIS_MODULE
,
1340 .probe
= tps65910_probe
,
1341 .remove
= __devexit_p(tps65910_remove
),
1342 .shutdown
= tps65910_shutdown
,
1345 static int __init
tps65910_init(void)
1347 return platform_driver_register(&tps65910_driver
);
1349 subsys_initcall(tps65910_init
);
1351 static void __exit
tps65910_cleanup(void)
1353 platform_driver_unregister(&tps65910_driver
);
1355 module_exit(tps65910_cleanup
);
1357 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1358 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1359 MODULE_LICENSE("GPL v2");
1360 MODULE_ALIAS("platform:tps65910-pmic");