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)
33 /* supported VIO voltages in milivolts */
34 static const u16 VIO_VSEL_table
[] = {
35 1500, 1800, 2500, 3300,
38 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
40 /* supported VDD3 voltages in milivolts */
41 static const u16 VDD3_VSEL_table
[] = {
45 /* supported VDIG1 voltages in milivolts */
46 static const u16 VDIG1_VSEL_table
[] = {
47 1200, 1500, 1800, 2700,
50 /* supported VDIG2 voltages in milivolts */
51 static const u16 VDIG2_VSEL_table
[] = {
52 1000, 1100, 1200, 1800,
55 /* supported VPLL voltages in milivolts */
56 static const u16 VPLL_VSEL_table
[] = {
57 1000, 1100, 1800, 2500,
60 /* supported VDAC voltages in milivolts */
61 static const u16 VDAC_VSEL_table
[] = {
62 1800, 2600, 2800, 2850,
65 /* supported VAUX1 voltages in milivolts */
66 static const u16 VAUX1_VSEL_table
[] = {
67 1800, 2500, 2800, 2850,
70 /* supported VAUX2 voltages in milivolts */
71 static const u16 VAUX2_VSEL_table
[] = {
72 1800, 2800, 2900, 3300,
75 /* supported VAUX33 voltages in milivolts */
76 static const u16 VAUX33_VSEL_table
[] = {
77 1800, 2000, 2800, 3300,
80 /* supported VMMC voltages in milivolts */
81 static const u16 VMMC_VSEL_table
[] = {
82 1800, 2800, 3000, 3300,
90 const u16
*voltage_table
;
93 static struct tps_info tps65910_regs
[] = {
101 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
102 .voltage_table
= VIO_VSEL_table
,
118 .n_voltages
= ARRAY_SIZE(VDD3_VSEL_table
),
119 .voltage_table
= VDD3_VSEL_table
,
125 .n_voltages
= ARRAY_SIZE(VDIG1_VSEL_table
),
126 .voltage_table
= VDIG1_VSEL_table
,
132 .n_voltages
= ARRAY_SIZE(VDIG2_VSEL_table
),
133 .voltage_table
= VDIG2_VSEL_table
,
139 .n_voltages
= ARRAY_SIZE(VPLL_VSEL_table
),
140 .voltage_table
= VPLL_VSEL_table
,
146 .n_voltages
= ARRAY_SIZE(VDAC_VSEL_table
),
147 .voltage_table
= VDAC_VSEL_table
,
153 .n_voltages
= ARRAY_SIZE(VAUX1_VSEL_table
),
154 .voltage_table
= VAUX1_VSEL_table
,
160 .n_voltages
= ARRAY_SIZE(VAUX2_VSEL_table
),
161 .voltage_table
= VAUX2_VSEL_table
,
167 .n_voltages
= ARRAY_SIZE(VAUX33_VSEL_table
),
168 .voltage_table
= VAUX33_VSEL_table
,
174 .n_voltages
= ARRAY_SIZE(VMMC_VSEL_table
),
175 .voltage_table
= VMMC_VSEL_table
,
179 static struct tps_info tps65911_regs
[] = {
187 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
188 .voltage_table
= VIO_VSEL_table
,
258 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
259 static unsigned int tps65910_ext_sleep_control
[] = {
261 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
262 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
263 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
264 EXT_CONTROL_REG_BITS(VDD3
, 1, 3),
265 EXT_CONTROL_REG_BITS(VDIG1
, 0, 1),
266 EXT_CONTROL_REG_BITS(VDIG2
, 0, 2),
267 EXT_CONTROL_REG_BITS(VPLL
, 0, 6),
268 EXT_CONTROL_REG_BITS(VDAC
, 0, 7),
269 EXT_CONTROL_REG_BITS(VAUX1
, 0, 3),
270 EXT_CONTROL_REG_BITS(VAUX2
, 0, 4),
271 EXT_CONTROL_REG_BITS(VAUX33
, 0, 5),
272 EXT_CONTROL_REG_BITS(VMMC
, 0, 0),
275 static unsigned int tps65911_ext_sleep_control
[] = {
277 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
278 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
279 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
280 EXT_CONTROL_REG_BITS(VDDCTRL
, 1, 3),
281 EXT_CONTROL_REG_BITS(LDO1
, 0, 1),
282 EXT_CONTROL_REG_BITS(LDO2
, 0, 2),
283 EXT_CONTROL_REG_BITS(LDO3
, 0, 7),
284 EXT_CONTROL_REG_BITS(LDO4
, 0, 6),
285 EXT_CONTROL_REG_BITS(LDO5
, 0, 3),
286 EXT_CONTROL_REG_BITS(LDO6
, 0, 0),
287 EXT_CONTROL_REG_BITS(LDO7
, 0, 5),
288 EXT_CONTROL_REG_BITS(LDO8
, 0, 4),
291 struct tps65910_reg
{
292 struct regulator_desc
*desc
;
293 struct tps65910
*mfd
;
294 struct regulator_dev
**rdev
;
295 struct tps_info
**info
;
299 int (*get_ctrl_reg
)(int);
300 unsigned int *ext_sleep_control
;
301 unsigned int board_ext_control
[TPS65910_NUM_REGS
];
304 static inline int tps65910_read(struct tps65910_reg
*pmic
, u8 reg
)
309 err
= pmic
->mfd
->read(pmic
->mfd
, reg
, 1, &val
);
316 static inline int tps65910_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
318 return pmic
->mfd
->write(pmic
->mfd
, reg
, 1, &val
);
321 static int tps65910_modify_bits(struct tps65910_reg
*pmic
, u8 reg
,
322 u8 set_mask
, u8 clear_mask
)
326 mutex_lock(&pmic
->mutex
);
328 data
= tps65910_read(pmic
, reg
);
330 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
337 err
= tps65910_write(pmic
, reg
, data
);
339 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
342 mutex_unlock(&pmic
->mutex
);
346 static int tps65910_reg_read(struct tps65910_reg
*pmic
, u8 reg
)
350 mutex_lock(&pmic
->mutex
);
352 data
= tps65910_read(pmic
, reg
);
354 dev_err(pmic
->mfd
->dev
, "Read from reg 0x%x failed\n", reg
);
356 mutex_unlock(&pmic
->mutex
);
360 static int tps65910_reg_write(struct tps65910_reg
*pmic
, u8 reg
, u8 val
)
364 mutex_lock(&pmic
->mutex
);
366 err
= tps65910_write(pmic
, reg
, val
);
368 dev_err(pmic
->mfd
->dev
, "Write for reg 0x%x failed\n", reg
);
370 mutex_unlock(&pmic
->mutex
);
374 static int tps65910_get_ctrl_register(int id
)
377 case TPS65910_REG_VRTC
:
378 return TPS65910_VRTC
;
379 case TPS65910_REG_VIO
:
381 case TPS65910_REG_VDD1
:
382 return TPS65910_VDD1
;
383 case TPS65910_REG_VDD2
:
384 return TPS65910_VDD2
;
385 case TPS65910_REG_VDD3
:
386 return TPS65910_VDD3
;
387 case TPS65910_REG_VDIG1
:
388 return TPS65910_VDIG1
;
389 case TPS65910_REG_VDIG2
:
390 return TPS65910_VDIG2
;
391 case TPS65910_REG_VPLL
:
392 return TPS65910_VPLL
;
393 case TPS65910_REG_VDAC
:
394 return TPS65910_VDAC
;
395 case TPS65910_REG_VAUX1
:
396 return TPS65910_VAUX1
;
397 case TPS65910_REG_VAUX2
:
398 return TPS65910_VAUX2
;
399 case TPS65910_REG_VAUX33
:
400 return TPS65910_VAUX33
;
401 case TPS65910_REG_VMMC
:
402 return TPS65910_VMMC
;
408 static int tps65911_get_ctrl_register(int id
)
411 case TPS65910_REG_VRTC
:
412 return TPS65910_VRTC
;
413 case TPS65910_REG_VIO
:
415 case TPS65910_REG_VDD1
:
416 return TPS65910_VDD1
;
417 case TPS65910_REG_VDD2
:
418 return TPS65910_VDD2
;
419 case TPS65911_REG_VDDCTRL
:
420 return TPS65911_VDDCTRL
;
421 case TPS65911_REG_LDO1
:
422 return TPS65911_LDO1
;
423 case TPS65911_REG_LDO2
:
424 return TPS65911_LDO2
;
425 case TPS65911_REG_LDO3
:
426 return TPS65911_LDO3
;
427 case TPS65911_REG_LDO4
:
428 return TPS65911_LDO4
;
429 case TPS65911_REG_LDO5
:
430 return TPS65911_LDO5
;
431 case TPS65911_REG_LDO6
:
432 return TPS65911_LDO6
;
433 case TPS65911_REG_LDO7
:
434 return TPS65911_LDO7
;
435 case TPS65911_REG_LDO8
:
436 return TPS65911_LDO8
;
442 static int tps65910_is_enabled(struct regulator_dev
*dev
)
444 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
445 int reg
, value
, id
= rdev_get_id(dev
);
447 reg
= pmic
->get_ctrl_reg(id
);
451 value
= tps65910_reg_read(pmic
, reg
);
455 return value
& TPS65910_SUPPLY_STATE_ENABLED
;
458 static int tps65910_enable(struct regulator_dev
*dev
)
460 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
461 struct tps65910
*mfd
= pmic
->mfd
;
462 int reg
, id
= rdev_get_id(dev
);
464 reg
= pmic
->get_ctrl_reg(id
);
468 return tps65910_set_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
471 static int tps65910_disable(struct regulator_dev
*dev
)
473 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
474 struct tps65910
*mfd
= pmic
->mfd
;
475 int reg
, id
= rdev_get_id(dev
);
477 reg
= pmic
->get_ctrl_reg(id
);
481 return tps65910_clear_bits(mfd
, reg
, TPS65910_SUPPLY_STATE_ENABLED
);
485 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
487 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
488 struct tps65910
*mfd
= pmic
->mfd
;
489 int reg
, value
, id
= rdev_get_id(dev
);
491 reg
= pmic
->get_ctrl_reg(id
);
496 case REGULATOR_MODE_NORMAL
:
497 return tps65910_modify_bits(pmic
, reg
, LDO_ST_ON_BIT
,
499 case REGULATOR_MODE_IDLE
:
500 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
501 return tps65910_set_bits(mfd
, reg
, value
);
502 case REGULATOR_MODE_STANDBY
:
503 return tps65910_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
509 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
511 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
512 int reg
, value
, id
= rdev_get_id(dev
);
514 reg
= pmic
->get_ctrl_reg(id
);
518 value
= tps65910_reg_read(pmic
, reg
);
522 if (value
& LDO_ST_ON_BIT
)
523 return REGULATOR_MODE_STANDBY
;
524 else if (value
& LDO_ST_MODE_BIT
)
525 return REGULATOR_MODE_IDLE
;
527 return REGULATOR_MODE_NORMAL
;
530 static int tps65910_get_voltage_dcdc(struct regulator_dev
*dev
)
532 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
533 int id
= rdev_get_id(dev
), voltage
= 0;
534 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
537 case TPS65910_REG_VDD1
:
538 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_OP
);
539 mult
= tps65910_reg_read(pmic
, TPS65910_VDD1
);
540 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
541 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD1_SR
);
542 sr
= opvsel
& VDD1_OP_CMD_MASK
;
543 opvsel
&= VDD1_OP_SEL_MASK
;
544 srvsel
&= VDD1_SR_SEL_MASK
;
547 case TPS65910_REG_VDD2
:
548 opvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_OP
);
549 mult
= tps65910_reg_read(pmic
, TPS65910_VDD2
);
550 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
551 srvsel
= tps65910_reg_read(pmic
, TPS65910_VDD2_SR
);
552 sr
= opvsel
& VDD2_OP_CMD_MASK
;
553 opvsel
&= VDD2_OP_SEL_MASK
;
554 srvsel
&= VDD2_SR_SEL_MASK
;
557 case TPS65911_REG_VDDCTRL
:
558 opvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_OP
);
559 srvsel
= tps65910_reg_read(pmic
, TPS65911_VDDCTRL_SR
);
560 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
561 opvsel
&= VDDCTRL_OP_SEL_MASK
;
562 srvsel
&= VDDCTRL_SR_SEL_MASK
;
567 /* multiplier 0 == 1 but 2,3 normal */
572 /* normalise to valid range */
575 if (srvsel
> vselmax
)
579 voltage
= (srvsel
* VDD1_2_OFFSET
+ VDD1_2_MIN_VOLT
) * 100;
582 /* normalise to valid range*/
585 if (opvsel
> vselmax
)
589 voltage
= (opvsel
* VDD1_2_OFFSET
+ VDD1_2_MIN_VOLT
) * 100;
597 static int tps65910_get_voltage(struct regulator_dev
*dev
)
599 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
600 int reg
, value
, id
= rdev_get_id(dev
), voltage
= 0;
602 reg
= pmic
->get_ctrl_reg(id
);
606 value
= tps65910_reg_read(pmic
, reg
);
611 case TPS65910_REG_VIO
:
612 case TPS65910_REG_VDIG1
:
613 case TPS65910_REG_VDIG2
:
614 case TPS65910_REG_VPLL
:
615 case TPS65910_REG_VDAC
:
616 case TPS65910_REG_VAUX1
:
617 case TPS65910_REG_VAUX2
:
618 case TPS65910_REG_VAUX33
:
619 case TPS65910_REG_VMMC
:
620 value
&= LDO_SEL_MASK
;
621 value
>>= LDO_SEL_SHIFT
;
627 voltage
= pmic
->info
[id
]->voltage_table
[value
] * 1000;
632 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
634 return 5 * 1000 * 1000;
637 static int tps65911_get_voltage(struct regulator_dev
*dev
)
639 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
640 int step_mv
, id
= rdev_get_id(dev
);
643 reg
= pmic
->get_ctrl_reg(id
);
645 value
= tps65910_reg_read(pmic
, reg
);
648 case TPS65911_REG_LDO1
:
649 case TPS65911_REG_LDO2
:
650 case TPS65911_REG_LDO4
:
651 value
&= LDO1_SEL_MASK
;
652 value
>>= LDO_SEL_SHIFT
;
653 /* The first 5 values of the selector correspond to 1V */
661 case TPS65911_REG_LDO3
:
662 case TPS65911_REG_LDO5
:
663 case TPS65911_REG_LDO6
:
664 case TPS65911_REG_LDO7
:
665 case TPS65911_REG_LDO8
:
666 value
&= LDO3_SEL_MASK
;
667 value
>>= LDO_SEL_SHIFT
;
668 /* The first 3 values of the selector correspond to 1V */
676 case TPS65910_REG_VIO
:
677 return pmic
->info
[id
]->voltage_table
[value
] * 1000;
683 return (LDO_MIN_VOLT
+ value
* step_mv
) * 1000;
686 static int tps65910_set_voltage_dcdc(struct regulator_dev
*dev
,
689 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
690 int id
= rdev_get_id(dev
), vsel
;
694 case TPS65910_REG_VDD1
:
695 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
698 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
700 tps65910_modify_bits(pmic
, TPS65910_VDD1
,
701 (dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
),
702 VDD1_VGAIN_SEL_MASK
);
703 tps65910_reg_write(pmic
, TPS65910_VDD1_OP
, vsel
);
705 case TPS65910_REG_VDD2
:
706 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
709 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
711 tps65910_modify_bits(pmic
, TPS65910_VDD2
,
712 (dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
),
713 VDD1_VGAIN_SEL_MASK
);
714 tps65910_reg_write(pmic
, TPS65910_VDD2_OP
, vsel
);
716 case TPS65911_REG_VDDCTRL
:
718 tps65910_reg_write(pmic
, TPS65911_VDDCTRL_OP
, vsel
);
724 static int tps65910_set_voltage(struct regulator_dev
*dev
, unsigned selector
)
726 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
727 int reg
, id
= rdev_get_id(dev
);
729 reg
= pmic
->get_ctrl_reg(id
);
734 case TPS65910_REG_VIO
:
735 case TPS65910_REG_VDIG1
:
736 case TPS65910_REG_VDIG2
:
737 case TPS65910_REG_VPLL
:
738 case TPS65910_REG_VDAC
:
739 case TPS65910_REG_VAUX1
:
740 case TPS65910_REG_VAUX2
:
741 case TPS65910_REG_VAUX33
:
742 case TPS65910_REG_VMMC
:
743 return tps65910_modify_bits(pmic
, reg
,
744 (selector
<< LDO_SEL_SHIFT
), LDO_SEL_MASK
);
750 static int tps65911_set_voltage(struct regulator_dev
*dev
, unsigned selector
)
752 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
753 int reg
, id
= rdev_get_id(dev
);
755 reg
= pmic
->get_ctrl_reg(id
);
760 case TPS65911_REG_LDO1
:
761 case TPS65911_REG_LDO2
:
762 case TPS65911_REG_LDO4
:
763 return tps65910_modify_bits(pmic
, reg
,
764 (selector
<< LDO_SEL_SHIFT
), LDO1_SEL_MASK
);
765 case TPS65911_REG_LDO3
:
766 case TPS65911_REG_LDO5
:
767 case TPS65911_REG_LDO6
:
768 case TPS65911_REG_LDO7
:
769 case TPS65911_REG_LDO8
:
770 case TPS65910_REG_VIO
:
771 return tps65910_modify_bits(pmic
, reg
,
772 (selector
<< LDO_SEL_SHIFT
), LDO3_SEL_MASK
);
779 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
782 int volt
, mult
= 1, id
= rdev_get_id(dev
);
785 case TPS65910_REG_VDD1
:
786 case TPS65910_REG_VDD2
:
787 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
788 volt
= VDD1_2_MIN_VOLT
+
789 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
791 case TPS65911_REG_VDDCTRL
:
792 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
799 return volt
* 100 * mult
;
802 static int tps65910_list_voltage(struct regulator_dev
*dev
,
805 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
806 int id
= rdev_get_id(dev
), voltage
;
808 if (id
< TPS65910_REG_VIO
|| id
> TPS65910_REG_VMMC
)
811 if (selector
>= pmic
->info
[id
]->n_voltages
)
814 voltage
= pmic
->info
[id
]->voltage_table
[selector
] * 1000;
819 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
821 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
822 int step_mv
= 0, id
= rdev_get_id(dev
);
825 case TPS65911_REG_LDO1
:
826 case TPS65911_REG_LDO2
:
827 case TPS65911_REG_LDO4
:
828 /* The first 5 values of the selector correspond to 1V */
836 case TPS65911_REG_LDO3
:
837 case TPS65911_REG_LDO5
:
838 case TPS65911_REG_LDO6
:
839 case TPS65911_REG_LDO7
:
840 case TPS65911_REG_LDO8
:
841 /* The first 3 values of the selector correspond to 1V */
849 case TPS65910_REG_VIO
:
850 return pmic
->info
[id
]->voltage_table
[selector
] * 1000;
855 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
858 /* Regulator ops (except VRTC) */
859 static struct regulator_ops tps65910_ops_dcdc
= {
860 .is_enabled
= tps65910_is_enabled
,
861 .enable
= tps65910_enable
,
862 .disable
= tps65910_disable
,
863 .set_mode
= tps65910_set_mode
,
864 .get_mode
= tps65910_get_mode
,
865 .get_voltage
= tps65910_get_voltage_dcdc
,
866 .set_voltage_sel
= tps65910_set_voltage_dcdc
,
867 .list_voltage
= tps65910_list_voltage_dcdc
,
870 static struct regulator_ops tps65910_ops_vdd3
= {
871 .is_enabled
= tps65910_is_enabled
,
872 .enable
= tps65910_enable
,
873 .disable
= tps65910_disable
,
874 .set_mode
= tps65910_set_mode
,
875 .get_mode
= tps65910_get_mode
,
876 .get_voltage
= tps65910_get_voltage_vdd3
,
877 .list_voltage
= tps65910_list_voltage
,
880 static struct regulator_ops tps65910_ops
= {
881 .is_enabled
= tps65910_is_enabled
,
882 .enable
= tps65910_enable
,
883 .disable
= tps65910_disable
,
884 .set_mode
= tps65910_set_mode
,
885 .get_mode
= tps65910_get_mode
,
886 .get_voltage
= tps65910_get_voltage
,
887 .set_voltage_sel
= tps65910_set_voltage
,
888 .list_voltage
= tps65910_list_voltage
,
891 static struct regulator_ops tps65911_ops
= {
892 .is_enabled
= tps65910_is_enabled
,
893 .enable
= tps65910_enable
,
894 .disable
= tps65910_disable
,
895 .set_mode
= tps65910_set_mode
,
896 .get_mode
= tps65910_get_mode
,
897 .get_voltage
= tps65911_get_voltage
,
898 .set_voltage_sel
= tps65911_set_voltage
,
899 .list_voltage
= tps65911_list_voltage
,
902 static int tps65910_set_ext_sleep_config(struct tps65910_reg
*pmic
,
903 int id
, int ext_sleep_config
)
905 struct tps65910
*mfd
= pmic
->mfd
;
906 u8 regoffs
= (pmic
->ext_sleep_control
[id
] >> 8) & 0xFF;
907 u8 bit_pos
= (1 << pmic
->ext_sleep_control
[id
] & 0xFF);
911 * Regulator can not be control from multiple external input EN1, EN2
914 if (ext_sleep_config
& EXT_SLEEP_CONTROL
) {
916 en_count
= ((ext_sleep_config
&
917 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
) != 0);
918 en_count
+= ((ext_sleep_config
&
919 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
) != 0);
920 en_count
+= ((ext_sleep_config
&
921 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
) != 0);
924 "External sleep control flag is not proper\n");
929 pmic
->board_ext_control
[id
] = ext_sleep_config
;
931 /* External EN1 control */
932 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
)
933 ret
= tps65910_set_bits(mfd
,
934 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
936 ret
= tps65910_clear_bits(mfd
,
937 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
940 "Error in configuring external control EN1\n");
944 /* External EN2 control */
945 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
)
946 ret
= tps65910_set_bits(mfd
,
947 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
949 ret
= tps65910_clear_bits(mfd
,
950 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
953 "Error in configuring external control EN2\n");
957 /* External EN3 control for TPS65910 LDO only */
958 if ((tps65910_chip_id(mfd
) == TPS65910
) &&
959 (id
>= TPS65910_REG_VDIG1
)) {
960 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
)
961 ret
= tps65910_set_bits(mfd
,
962 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
964 ret
= tps65910_clear_bits(mfd
,
965 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
968 "Error in configuring external control EN3\n");
973 /* Return if no external control is selected */
974 if (!(ext_sleep_config
& EXT_SLEEP_CONTROL
)) {
975 /* Clear all sleep controls */
976 ret
= tps65910_clear_bits(mfd
,
977 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
979 ret
= tps65910_clear_bits(mfd
,
980 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
983 "Error in configuring SLEEP register\n");
988 * For regulator that has separate operational and sleep register make
989 * sure that operational is used and clear sleep register to turn
990 * regulator off when external control is inactive
992 if ((id
== TPS65910_REG_VDD1
) ||
993 (id
== TPS65910_REG_VDD2
) ||
994 ((id
== TPS65911_REG_VDDCTRL
) &&
995 (tps65910_chip_id(mfd
) == TPS65911
))) {
996 int op_reg_add
= pmic
->get_ctrl_reg(id
) + 1;
997 int sr_reg_add
= pmic
->get_ctrl_reg(id
) + 2;
998 int opvsel
= tps65910_reg_read(pmic
, op_reg_add
);
999 int srvsel
= tps65910_reg_read(pmic
, sr_reg_add
);
1000 if (opvsel
& VDD1_OP_CMD_MASK
) {
1001 u8 reg_val
= srvsel
& VDD1_OP_SEL_MASK
;
1002 ret
= tps65910_reg_write(pmic
, op_reg_add
, reg_val
);
1005 "Error in configuring op register\n");
1009 ret
= tps65910_reg_write(pmic
, sr_reg_add
, 0);
1011 dev_err(mfd
->dev
, "Error in settting sr register\n");
1016 ret
= tps65910_clear_bits(mfd
,
1017 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
1019 ret
= tps65910_set_bits(mfd
,
1020 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
1023 "Error in configuring SLEEP register\n");
1027 static __devinit
int tps65910_probe(struct platform_device
*pdev
)
1029 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1030 struct tps_info
*info
;
1031 struct regulator_init_data
*reg_data
;
1032 struct regulator_dev
*rdev
;
1033 struct tps65910_reg
*pmic
;
1034 struct tps65910_board
*pmic_plat_data
;
1037 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
1038 if (!pmic_plat_data
)
1041 pmic
= kzalloc(sizeof(*pmic
), GFP_KERNEL
);
1045 mutex_init(&pmic
->mutex
);
1046 pmic
->mfd
= tps65910
;
1047 platform_set_drvdata(pdev
, pmic
);
1049 /* Give control of all register to control port */
1050 tps65910_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
1051 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
1053 switch(tps65910_chip_id(tps65910
)) {
1055 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
1056 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
1057 pmic
->ext_sleep_control
= tps65910_ext_sleep_control
;
1058 info
= tps65910_regs
;
1061 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
1062 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
1063 pmic
->ext_sleep_control
= tps65911_ext_sleep_control
;
1064 info
= tps65911_regs
;
1067 pr_err("Invalid tps chip version\n");
1072 pmic
->desc
= kcalloc(pmic
->num_regulators
,
1073 sizeof(struct regulator_desc
), GFP_KERNEL
);
1079 pmic
->info
= kcalloc(pmic
->num_regulators
,
1080 sizeof(struct tps_info
*), GFP_KERNEL
);
1086 pmic
->rdev
= kcalloc(pmic
->num_regulators
,
1087 sizeof(struct regulator_dev
*), GFP_KERNEL
);
1093 for (i
= 0; i
< pmic
->num_regulators
&& i
< TPS65910_NUM_REGS
;
1096 reg_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
1098 /* Regulator API handles empty constraints but not NULL
1103 /* Register the regulators */
1104 pmic
->info
[i
] = info
;
1106 pmic
->desc
[i
].name
= info
->name
;
1107 pmic
->desc
[i
].id
= i
;
1108 pmic
->desc
[i
].n_voltages
= info
->n_voltages
;
1110 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
1111 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1112 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
1113 VDD1_2_NUM_VOLT_COARSE
;
1114 } else if (i
== TPS65910_REG_VDD3
) {
1115 if (tps65910_chip_id(tps65910
) == TPS65910
)
1116 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
1118 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1120 if (tps65910_chip_id(tps65910
) == TPS65910
)
1121 pmic
->desc
[i
].ops
= &tps65910_ops
;
1123 pmic
->desc
[i
].ops
= &tps65911_ops
;
1126 err
= tps65910_set_ext_sleep_config(pmic
, i
,
1127 pmic_plat_data
->regulator_ext_sleep_control
[i
]);
1129 * Failing on regulator for configuring externally control
1130 * is not a serious issue, just throw warning.
1133 dev_warn(tps65910
->dev
,
1134 "Failed to initialise ext control config\n");
1136 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
1137 pmic
->desc
[i
].owner
= THIS_MODULE
;
1139 rdev
= regulator_register(&pmic
->desc
[i
],
1140 tps65910
->dev
, reg_data
, pmic
, NULL
);
1142 dev_err(tps65910
->dev
,
1143 "failed to register %s regulator\n",
1145 err
= PTR_ERR(rdev
);
1146 goto err_unregister_regulator
;
1149 /* Save regulator for cleanup */
1150 pmic
->rdev
[i
] = rdev
;
1154 err_unregister_regulator
:
1156 regulator_unregister(pmic
->rdev
[i
]);
1167 static int __devexit
tps65910_remove(struct platform_device
*pdev
)
1169 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1172 for (i
= 0; i
< pmic
->num_regulators
; i
++)
1173 regulator_unregister(pmic
->rdev
[i
]);
1182 static void tps65910_shutdown(struct platform_device
*pdev
)
1184 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1188 * Before bootloader jumps to kernel, it makes sure that required
1189 * external control signals are in desired state so that given rails
1190 * can be configure accordingly.
1191 * If rails are configured to be controlled from external control
1192 * then before shutting down/rebooting the system, the external
1193 * control configuration need to be remove from the rails so that
1194 * its output will be available as per register programming even
1195 * if external controls are removed. This is require when the POR
1196 * value of the control signals are not in active state and before
1197 * bootloader initializes it, the system requires the rail output
1198 * to be active for booting.
1200 for (i
= 0; i
< pmic
->num_regulators
; i
++) {
1205 err
= tps65910_set_ext_sleep_config(pmic
, i
, 0);
1208 "Error in clearing external control\n");
1212 static struct platform_driver tps65910_driver
= {
1214 .name
= "tps65910-pmic",
1215 .owner
= THIS_MODULE
,
1217 .probe
= tps65910_probe
,
1218 .remove
= __devexit_p(tps65910_remove
),
1219 .shutdown
= tps65910_shutdown
,
1222 static int __init
tps65910_init(void)
1224 return platform_driver_register(&tps65910_driver
);
1226 subsys_initcall(tps65910_init
);
1228 static void __exit
tps65910_cleanup(void)
1230 platform_driver_unregister(&tps65910_driver
);
1232 module_exit(tps65910_cleanup
);
1234 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1235 MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
1236 MODULE_LICENSE("GPL v2");
1237 MODULE_ALIAS("platform:tps65910-pmic");