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 microvolts */
35 static const unsigned int VIO_VSEL_table
[] = {
36 1500000, 1800000, 2500000, 3300000,
39 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
41 /* supported VRTC voltages in microvolts */
42 static const unsigned int VRTC_VSEL_table
[] = {
46 /* supported VDD3 voltages in microvolts */
47 static const unsigned int VDD3_VSEL_table
[] = {
51 /* supported VDIG1 voltages in microvolts */
52 static const unsigned int VDIG1_VSEL_table
[] = {
53 1200000, 1500000, 1800000, 2700000,
56 /* supported VDIG2 voltages in microvolts */
57 static const unsigned int VDIG2_VSEL_table
[] = {
58 1000000, 1100000, 1200000, 1800000,
61 /* supported VPLL voltages in microvolts */
62 static const unsigned int VPLL_VSEL_table
[] = {
63 1000000, 1100000, 1800000, 2500000,
66 /* supported VDAC voltages in microvolts */
67 static const unsigned int VDAC_VSEL_table
[] = {
68 1800000, 2600000, 2800000, 2850000,
71 /* supported VAUX1 voltages in microvolts */
72 static const unsigned int VAUX1_VSEL_table
[] = {
73 1800000, 2500000, 2800000, 2850000,
76 /* supported VAUX2 voltages in microvolts */
77 static const unsigned int VAUX2_VSEL_table
[] = {
78 1800000, 2800000, 2900000, 3300000,
81 /* supported VAUX33 voltages in microvolts */
82 static const unsigned int VAUX33_VSEL_table
[] = {
83 1800000, 2000000, 2800000, 3300000,
86 /* supported VMMC voltages in microvolts */
87 static const unsigned int VMMC_VSEL_table
[] = {
88 1800000, 2800000, 3000000, 3300000,
95 const unsigned int *voltage_table
;
99 static struct tps_info tps65910_regs
[] = {
103 .n_voltages
= ARRAY_SIZE(VRTC_VSEL_table
),
104 .voltage_table
= VRTC_VSEL_table
,
105 .enable_time_us
= 2200,
110 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
111 .voltage_table
= VIO_VSEL_table
,
112 .enable_time_us
= 350,
117 .enable_time_us
= 350,
122 .enable_time_us
= 350,
126 .n_voltages
= ARRAY_SIZE(VDD3_VSEL_table
),
127 .voltage_table
= VDD3_VSEL_table
,
128 .enable_time_us
= 200,
133 .n_voltages
= ARRAY_SIZE(VDIG1_VSEL_table
),
134 .voltage_table
= VDIG1_VSEL_table
,
135 .enable_time_us
= 100,
140 .n_voltages
= ARRAY_SIZE(VDIG2_VSEL_table
),
141 .voltage_table
= VDIG2_VSEL_table
,
142 .enable_time_us
= 100,
147 .n_voltages
= ARRAY_SIZE(VPLL_VSEL_table
),
148 .voltage_table
= VPLL_VSEL_table
,
149 .enable_time_us
= 100,
154 .n_voltages
= ARRAY_SIZE(VDAC_VSEL_table
),
155 .voltage_table
= VDAC_VSEL_table
,
156 .enable_time_us
= 100,
161 .n_voltages
= ARRAY_SIZE(VAUX1_VSEL_table
),
162 .voltage_table
= VAUX1_VSEL_table
,
163 .enable_time_us
= 100,
168 .n_voltages
= ARRAY_SIZE(VAUX2_VSEL_table
),
169 .voltage_table
= VAUX2_VSEL_table
,
170 .enable_time_us
= 100,
175 .n_voltages
= ARRAY_SIZE(VAUX33_VSEL_table
),
176 .voltage_table
= VAUX33_VSEL_table
,
177 .enable_time_us
= 100,
182 .n_voltages
= ARRAY_SIZE(VMMC_VSEL_table
),
183 .voltage_table
= VMMC_VSEL_table
,
184 .enable_time_us
= 100,
188 static struct tps_info tps65911_regs
[] = {
192 .enable_time_us
= 2200,
197 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
198 .voltage_table
= VIO_VSEL_table
,
199 .enable_time_us
= 350,
205 .enable_time_us
= 350,
211 .enable_time_us
= 350,
216 .enable_time_us
= 900,
222 .enable_time_us
= 420,
228 .enable_time_us
= 420,
234 .enable_time_us
= 230,
240 .enable_time_us
= 230,
246 .enable_time_us
= 230,
252 .enable_time_us
= 230,
258 .enable_time_us
= 230,
264 .enable_time_us
= 230,
268 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
269 static unsigned int tps65910_ext_sleep_control
[] = {
271 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
272 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
273 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
274 EXT_CONTROL_REG_BITS(VDD3
, 1, 3),
275 EXT_CONTROL_REG_BITS(VDIG1
, 0, 1),
276 EXT_CONTROL_REG_BITS(VDIG2
, 0, 2),
277 EXT_CONTROL_REG_BITS(VPLL
, 0, 6),
278 EXT_CONTROL_REG_BITS(VDAC
, 0, 7),
279 EXT_CONTROL_REG_BITS(VAUX1
, 0, 3),
280 EXT_CONTROL_REG_BITS(VAUX2
, 0, 4),
281 EXT_CONTROL_REG_BITS(VAUX33
, 0, 5),
282 EXT_CONTROL_REG_BITS(VMMC
, 0, 0),
285 static unsigned int tps65911_ext_sleep_control
[] = {
287 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
288 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
289 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
290 EXT_CONTROL_REG_BITS(VDDCTRL
, 1, 3),
291 EXT_CONTROL_REG_BITS(LDO1
, 0, 1),
292 EXT_CONTROL_REG_BITS(LDO2
, 0, 2),
293 EXT_CONTROL_REG_BITS(LDO3
, 0, 7),
294 EXT_CONTROL_REG_BITS(LDO4
, 0, 6),
295 EXT_CONTROL_REG_BITS(LDO5
, 0, 3),
296 EXT_CONTROL_REG_BITS(LDO6
, 0, 0),
297 EXT_CONTROL_REG_BITS(LDO7
, 0, 5),
298 EXT_CONTROL_REG_BITS(LDO8
, 0, 4),
301 struct tps65910_reg
{
302 struct regulator_desc
*desc
;
303 struct tps65910
*mfd
;
304 struct regulator_dev
**rdev
;
305 struct tps_info
**info
;
308 int (*get_ctrl_reg
)(int);
309 unsigned int *ext_sleep_control
;
310 unsigned int board_ext_control
[TPS65910_NUM_REGS
];
313 static int tps65910_get_ctrl_register(int id
)
316 case TPS65910_REG_VRTC
:
317 return TPS65910_VRTC
;
318 case TPS65910_REG_VIO
:
320 case TPS65910_REG_VDD1
:
321 return TPS65910_VDD1
;
322 case TPS65910_REG_VDD2
:
323 return TPS65910_VDD2
;
324 case TPS65910_REG_VDD3
:
325 return TPS65910_VDD3
;
326 case TPS65910_REG_VDIG1
:
327 return TPS65910_VDIG1
;
328 case TPS65910_REG_VDIG2
:
329 return TPS65910_VDIG2
;
330 case TPS65910_REG_VPLL
:
331 return TPS65910_VPLL
;
332 case TPS65910_REG_VDAC
:
333 return TPS65910_VDAC
;
334 case TPS65910_REG_VAUX1
:
335 return TPS65910_VAUX1
;
336 case TPS65910_REG_VAUX2
:
337 return TPS65910_VAUX2
;
338 case TPS65910_REG_VAUX33
:
339 return TPS65910_VAUX33
;
340 case TPS65910_REG_VMMC
:
341 return TPS65910_VMMC
;
347 static int tps65911_get_ctrl_register(int id
)
350 case TPS65910_REG_VRTC
:
351 return TPS65910_VRTC
;
352 case TPS65910_REG_VIO
:
354 case TPS65910_REG_VDD1
:
355 return TPS65910_VDD1
;
356 case TPS65910_REG_VDD2
:
357 return TPS65910_VDD2
;
358 case TPS65911_REG_VDDCTRL
:
359 return TPS65911_VDDCTRL
;
360 case TPS65911_REG_LDO1
:
361 return TPS65911_LDO1
;
362 case TPS65911_REG_LDO2
:
363 return TPS65911_LDO2
;
364 case TPS65911_REG_LDO3
:
365 return TPS65911_LDO3
;
366 case TPS65911_REG_LDO4
:
367 return TPS65911_LDO4
;
368 case TPS65911_REG_LDO5
:
369 return TPS65911_LDO5
;
370 case TPS65911_REG_LDO6
:
371 return TPS65911_LDO6
;
372 case TPS65911_REG_LDO7
:
373 return TPS65911_LDO7
;
374 case TPS65911_REG_LDO8
:
375 return TPS65911_LDO8
;
381 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
383 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
384 struct tps65910
*mfd
= pmic
->mfd
;
385 int reg
, value
, id
= rdev_get_id(dev
);
387 reg
= pmic
->get_ctrl_reg(id
);
392 case REGULATOR_MODE_NORMAL
:
393 return tps65910_reg_update_bits(pmic
->mfd
, reg
,
394 LDO_ST_MODE_BIT
| LDO_ST_ON_BIT
,
396 case REGULATOR_MODE_IDLE
:
397 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
398 return tps65910_reg_set_bits(mfd
, reg
, value
);
399 case REGULATOR_MODE_STANDBY
:
400 return tps65910_reg_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
406 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
408 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
409 int ret
, reg
, value
, id
= rdev_get_id(dev
);
411 reg
= pmic
->get_ctrl_reg(id
);
415 ret
= tps65910_reg_read(pmic
->mfd
, reg
, &value
);
419 if (!(value
& LDO_ST_ON_BIT
))
420 return REGULATOR_MODE_STANDBY
;
421 else if (value
& LDO_ST_MODE_BIT
)
422 return REGULATOR_MODE_IDLE
;
424 return REGULATOR_MODE_NORMAL
;
427 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev
*dev
)
429 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
430 int ret
, id
= rdev_get_id(dev
);
431 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
434 case TPS65910_REG_VDD1
:
435 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD1_OP
, &opvsel
);
438 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD1
, &mult
);
441 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
442 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD1_SR
, &srvsel
);
445 sr
= opvsel
& VDD1_OP_CMD_MASK
;
446 opvsel
&= VDD1_OP_SEL_MASK
;
447 srvsel
&= VDD1_SR_SEL_MASK
;
450 case TPS65910_REG_VDD2
:
451 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD2_OP
, &opvsel
);
454 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD2
, &mult
);
457 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
458 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD2_SR
, &srvsel
);
461 sr
= opvsel
& VDD2_OP_CMD_MASK
;
462 opvsel
&= VDD2_OP_SEL_MASK
;
463 srvsel
&= VDD2_SR_SEL_MASK
;
466 case TPS65911_REG_VDDCTRL
:
467 ret
= tps65910_reg_read(pmic
->mfd
, TPS65911_VDDCTRL_OP
,
471 ret
= tps65910_reg_read(pmic
->mfd
, TPS65911_VDDCTRL_SR
,
475 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
476 opvsel
&= VDDCTRL_OP_SEL_MASK
;
477 srvsel
&= VDDCTRL_SR_SEL_MASK
;
482 /* multiplier 0 == 1 but 2,3 normal */
487 /* normalise to valid range */
490 if (srvsel
> vselmax
)
495 /* normalise to valid range*/
498 if (opvsel
> vselmax
)
505 static int tps65910_get_voltage_sel(struct regulator_dev
*dev
)
507 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
508 int ret
, reg
, value
, id
= rdev_get_id(dev
);
510 reg
= pmic
->get_ctrl_reg(id
);
514 ret
= tps65910_reg_read(pmic
->mfd
, reg
, &value
);
519 case TPS65910_REG_VIO
:
520 case TPS65910_REG_VDIG1
:
521 case TPS65910_REG_VDIG2
:
522 case TPS65910_REG_VPLL
:
523 case TPS65910_REG_VDAC
:
524 case TPS65910_REG_VAUX1
:
525 case TPS65910_REG_VAUX2
:
526 case TPS65910_REG_VAUX33
:
527 case TPS65910_REG_VMMC
:
528 value
&= LDO_SEL_MASK
;
529 value
>>= LDO_SEL_SHIFT
;
538 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
540 return dev
->desc
->volt_table
[0];
543 static int tps65911_get_voltage_sel(struct regulator_dev
*dev
)
545 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
546 int ret
, id
= rdev_get_id(dev
);
547 unsigned int value
, reg
;
549 reg
= pmic
->get_ctrl_reg(id
);
551 ret
= tps65910_reg_read(pmic
->mfd
, reg
, &value
);
556 case TPS65911_REG_LDO1
:
557 case TPS65911_REG_LDO2
:
558 case TPS65911_REG_LDO4
:
559 value
&= LDO1_SEL_MASK
;
560 value
>>= LDO_SEL_SHIFT
;
562 case TPS65911_REG_LDO3
:
563 case TPS65911_REG_LDO5
:
564 case TPS65911_REG_LDO6
:
565 case TPS65911_REG_LDO7
:
566 case TPS65911_REG_LDO8
:
567 value
&= LDO3_SEL_MASK
;
568 value
>>= LDO_SEL_SHIFT
;
570 case TPS65910_REG_VIO
:
571 value
&= LDO_SEL_MASK
;
572 value
>>= LDO_SEL_SHIFT
;
581 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev
*dev
,
584 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
585 int id
= rdev_get_id(dev
), vsel
;
589 case TPS65910_REG_VDD1
:
590 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
593 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
595 tps65910_reg_update_bits(pmic
->mfd
, TPS65910_VDD1
,
597 dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
);
598 tps65910_reg_write(pmic
->mfd
, TPS65910_VDD1_OP
, vsel
);
600 case TPS65910_REG_VDD2
:
601 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
604 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
606 tps65910_reg_update_bits(pmic
->mfd
, TPS65910_VDD2
,
608 dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
);
609 tps65910_reg_write(pmic
->mfd
, TPS65910_VDD2_OP
, vsel
);
611 case TPS65911_REG_VDDCTRL
:
613 tps65910_reg_write(pmic
->mfd
, TPS65911_VDDCTRL_OP
, vsel
);
619 static int tps65910_set_voltage_sel(struct regulator_dev
*dev
,
622 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
623 int reg
, id
= rdev_get_id(dev
);
625 reg
= pmic
->get_ctrl_reg(id
);
630 case TPS65910_REG_VIO
:
631 case TPS65910_REG_VDIG1
:
632 case TPS65910_REG_VDIG2
:
633 case TPS65910_REG_VPLL
:
634 case TPS65910_REG_VDAC
:
635 case TPS65910_REG_VAUX1
:
636 case TPS65910_REG_VAUX2
:
637 case TPS65910_REG_VAUX33
:
638 case TPS65910_REG_VMMC
:
639 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO_SEL_MASK
,
640 selector
<< LDO_SEL_SHIFT
);
646 static int tps65911_set_voltage_sel(struct regulator_dev
*dev
,
649 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
650 int reg
, id
= rdev_get_id(dev
);
652 reg
= pmic
->get_ctrl_reg(id
);
657 case TPS65911_REG_LDO1
:
658 case TPS65911_REG_LDO2
:
659 case TPS65911_REG_LDO4
:
660 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO1_SEL_MASK
,
661 selector
<< LDO_SEL_SHIFT
);
662 case TPS65911_REG_LDO3
:
663 case TPS65911_REG_LDO5
:
664 case TPS65911_REG_LDO6
:
665 case TPS65911_REG_LDO7
:
666 case TPS65911_REG_LDO8
:
667 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO3_SEL_MASK
,
668 selector
<< LDO_SEL_SHIFT
);
669 case TPS65910_REG_VIO
:
670 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO_SEL_MASK
,
671 selector
<< LDO_SEL_SHIFT
);
678 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
681 int volt
, mult
= 1, id
= rdev_get_id(dev
);
684 case TPS65910_REG_VDD1
:
685 case TPS65910_REG_VDD2
:
686 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
687 volt
= VDD1_2_MIN_VOLT
+
688 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
690 case TPS65911_REG_VDDCTRL
:
691 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
698 return volt
* 100 * mult
;
701 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
703 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
704 int step_mv
= 0, id
= rdev_get_id(dev
);
707 case TPS65911_REG_LDO1
:
708 case TPS65911_REG_LDO2
:
709 case TPS65911_REG_LDO4
:
710 /* The first 5 values of the selector correspond to 1V */
718 case TPS65911_REG_LDO3
:
719 case TPS65911_REG_LDO5
:
720 case TPS65911_REG_LDO6
:
721 case TPS65911_REG_LDO7
:
722 case TPS65911_REG_LDO8
:
723 /* The first 3 values of the selector correspond to 1V */
731 case TPS65910_REG_VIO
:
732 return pmic
->info
[id
]->voltage_table
[selector
];
737 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
740 /* Regulator ops (except VRTC) */
741 static struct regulator_ops tps65910_ops_dcdc
= {
742 .is_enabled
= regulator_is_enabled_regmap
,
743 .enable
= regulator_enable_regmap
,
744 .disable
= regulator_disable_regmap
,
745 .set_mode
= tps65910_set_mode
,
746 .get_mode
= tps65910_get_mode
,
747 .get_voltage_sel
= tps65910_get_voltage_dcdc_sel
,
748 .set_voltage_sel
= tps65910_set_voltage_dcdc_sel
,
749 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
750 .list_voltage
= tps65910_list_voltage_dcdc
,
751 .map_voltage
= regulator_map_voltage_ascend
,
754 static struct regulator_ops tps65910_ops_vdd3
= {
755 .is_enabled
= regulator_is_enabled_regmap
,
756 .enable
= regulator_enable_regmap
,
757 .disable
= regulator_disable_regmap
,
758 .set_mode
= tps65910_set_mode
,
759 .get_mode
= tps65910_get_mode
,
760 .get_voltage
= tps65910_get_voltage_vdd3
,
761 .list_voltage
= regulator_list_voltage_table
,
762 .map_voltage
= regulator_map_voltage_ascend
,
765 static struct regulator_ops tps65910_ops
= {
766 .is_enabled
= regulator_is_enabled_regmap
,
767 .enable
= regulator_enable_regmap
,
768 .disable
= regulator_disable_regmap
,
769 .set_mode
= tps65910_set_mode
,
770 .get_mode
= tps65910_get_mode
,
771 .get_voltage_sel
= tps65910_get_voltage_sel
,
772 .set_voltage_sel
= tps65910_set_voltage_sel
,
773 .list_voltage
= regulator_list_voltage_table
,
774 .map_voltage
= regulator_map_voltage_ascend
,
777 static struct regulator_ops tps65911_ops
= {
778 .is_enabled
= regulator_is_enabled_regmap
,
779 .enable
= regulator_enable_regmap
,
780 .disable
= regulator_disable_regmap
,
781 .set_mode
= tps65910_set_mode
,
782 .get_mode
= tps65910_get_mode
,
783 .get_voltage_sel
= tps65911_get_voltage_sel
,
784 .set_voltage_sel
= tps65911_set_voltage_sel
,
785 .list_voltage
= tps65911_list_voltage
,
786 .map_voltage
= regulator_map_voltage_ascend
,
789 static int tps65910_set_ext_sleep_config(struct tps65910_reg
*pmic
,
790 int id
, int ext_sleep_config
)
792 struct tps65910
*mfd
= pmic
->mfd
;
793 u8 regoffs
= (pmic
->ext_sleep_control
[id
] >> 8) & 0xFF;
794 u8 bit_pos
= (1 << pmic
->ext_sleep_control
[id
] & 0xFF);
798 * Regulator can not be control from multiple external input EN1, EN2
801 if (ext_sleep_config
& EXT_SLEEP_CONTROL
) {
803 en_count
= ((ext_sleep_config
&
804 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
) != 0);
805 en_count
+= ((ext_sleep_config
&
806 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
) != 0);
807 en_count
+= ((ext_sleep_config
&
808 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
) != 0);
809 en_count
+= ((ext_sleep_config
&
810 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
) != 0);
813 "External sleep control flag is not proper\n");
818 pmic
->board_ext_control
[id
] = ext_sleep_config
;
820 /* External EN1 control */
821 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
)
822 ret
= tps65910_reg_set_bits(mfd
,
823 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
825 ret
= tps65910_reg_clear_bits(mfd
,
826 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
829 "Error in configuring external control EN1\n");
833 /* External EN2 control */
834 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
)
835 ret
= tps65910_reg_set_bits(mfd
,
836 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
838 ret
= tps65910_reg_clear_bits(mfd
,
839 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
842 "Error in configuring external control EN2\n");
846 /* External EN3 control for TPS65910 LDO only */
847 if ((tps65910_chip_id(mfd
) == TPS65910
) &&
848 (id
>= TPS65910_REG_VDIG1
)) {
849 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
)
850 ret
= tps65910_reg_set_bits(mfd
,
851 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
853 ret
= tps65910_reg_clear_bits(mfd
,
854 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
857 "Error in configuring external control EN3\n");
862 /* Return if no external control is selected */
863 if (!(ext_sleep_config
& EXT_SLEEP_CONTROL
)) {
864 /* Clear all sleep controls */
865 ret
= tps65910_reg_clear_bits(mfd
,
866 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
868 ret
= tps65910_reg_clear_bits(mfd
,
869 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
872 "Error in configuring SLEEP register\n");
877 * For regulator that has separate operational and sleep register make
878 * sure that operational is used and clear sleep register to turn
879 * regulator off when external control is inactive
881 if ((id
== TPS65910_REG_VDD1
) ||
882 (id
== TPS65910_REG_VDD2
) ||
883 ((id
== TPS65911_REG_VDDCTRL
) &&
884 (tps65910_chip_id(mfd
) == TPS65911
))) {
885 int op_reg_add
= pmic
->get_ctrl_reg(id
) + 1;
886 int sr_reg_add
= pmic
->get_ctrl_reg(id
) + 2;
889 ret
= tps65910_reg_read(pmic
->mfd
, op_reg_add
, &opvsel
);
892 ret
= tps65910_reg_read(pmic
->mfd
, sr_reg_add
, &srvsel
);
896 if (opvsel
& VDD1_OP_CMD_MASK
) {
897 u8 reg_val
= srvsel
& VDD1_OP_SEL_MASK
;
899 ret
= tps65910_reg_write(pmic
->mfd
, op_reg_add
,
903 "Error in configuring op register\n");
907 ret
= tps65910_reg_write(pmic
->mfd
, sr_reg_add
, 0);
909 dev_err(mfd
->dev
, "Error in setting sr register\n");
914 ret
= tps65910_reg_clear_bits(mfd
,
915 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
917 if (ext_sleep_config
& TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
)
918 ret
= tps65910_reg_set_bits(mfd
,
919 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
921 ret
= tps65910_reg_clear_bits(mfd
,
922 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
926 "Error in configuring SLEEP register\n");
933 static struct of_regulator_match tps65910_matches
[] = {
934 { .name
= "vrtc", .driver_data
= (void *) &tps65910_regs
[0] },
935 { .name
= "vio", .driver_data
= (void *) &tps65910_regs
[1] },
936 { .name
= "vdd1", .driver_data
= (void *) &tps65910_regs
[2] },
937 { .name
= "vdd2", .driver_data
= (void *) &tps65910_regs
[3] },
938 { .name
= "vdd3", .driver_data
= (void *) &tps65910_regs
[4] },
939 { .name
= "vdig1", .driver_data
= (void *) &tps65910_regs
[5] },
940 { .name
= "vdig2", .driver_data
= (void *) &tps65910_regs
[6] },
941 { .name
= "vpll", .driver_data
= (void *) &tps65910_regs
[7] },
942 { .name
= "vdac", .driver_data
= (void *) &tps65910_regs
[8] },
943 { .name
= "vaux1", .driver_data
= (void *) &tps65910_regs
[9] },
944 { .name
= "vaux2", .driver_data
= (void *) &tps65910_regs
[10] },
945 { .name
= "vaux33", .driver_data
= (void *) &tps65910_regs
[11] },
946 { .name
= "vmmc", .driver_data
= (void *) &tps65910_regs
[12] },
949 static struct of_regulator_match tps65911_matches
[] = {
950 { .name
= "vrtc", .driver_data
= (void *) &tps65911_regs
[0] },
951 { .name
= "vio", .driver_data
= (void *) &tps65911_regs
[1] },
952 { .name
= "vdd1", .driver_data
= (void *) &tps65911_regs
[2] },
953 { .name
= "vdd2", .driver_data
= (void *) &tps65911_regs
[3] },
954 { .name
= "vddctrl", .driver_data
= (void *) &tps65911_regs
[4] },
955 { .name
= "ldo1", .driver_data
= (void *) &tps65911_regs
[5] },
956 { .name
= "ldo2", .driver_data
= (void *) &tps65911_regs
[6] },
957 { .name
= "ldo3", .driver_data
= (void *) &tps65911_regs
[7] },
958 { .name
= "ldo4", .driver_data
= (void *) &tps65911_regs
[8] },
959 { .name
= "ldo5", .driver_data
= (void *) &tps65911_regs
[9] },
960 { .name
= "ldo6", .driver_data
= (void *) &tps65911_regs
[10] },
961 { .name
= "ldo7", .driver_data
= (void *) &tps65911_regs
[11] },
962 { .name
= "ldo8", .driver_data
= (void *) &tps65911_regs
[12] },
965 static struct tps65910_board
*tps65910_parse_dt_reg_data(
966 struct platform_device
*pdev
,
967 struct of_regulator_match
**tps65910_reg_matches
)
969 struct tps65910_board
*pmic_plat_data
;
970 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
971 struct device_node
*np
, *regulators
;
972 struct of_regulator_match
*matches
;
974 int idx
= 0, ret
, count
;
976 pmic_plat_data
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic_plat_data
),
979 if (!pmic_plat_data
) {
980 dev_err(&pdev
->dev
, "Failure to alloc pdata for regulators.\n");
984 np
= of_node_get(pdev
->dev
.parent
->of_node
);
985 regulators
= of_get_child_by_name(np
, "regulators");
987 dev_err(&pdev
->dev
, "regulator node not found\n");
991 switch (tps65910_chip_id(tps65910
)) {
993 count
= ARRAY_SIZE(tps65910_matches
);
994 matches
= tps65910_matches
;
997 count
= ARRAY_SIZE(tps65911_matches
);
998 matches
= tps65911_matches
;
1001 of_node_put(regulators
);
1002 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1006 ret
= of_regulator_match(&pdev
->dev
, regulators
, matches
, count
);
1007 of_node_put(regulators
);
1009 dev_err(&pdev
->dev
, "Error parsing regulator init data: %d\n",
1014 *tps65910_reg_matches
= matches
;
1016 for (idx
= 0; idx
< count
; idx
++) {
1017 if (!matches
[idx
].init_data
|| !matches
[idx
].of_node
)
1020 pmic_plat_data
->tps65910_pmic_init_data
[idx
] =
1021 matches
[idx
].init_data
;
1023 ret
= of_property_read_u32(matches
[idx
].of_node
,
1024 "ti,regulator-ext-sleep-control", &prop
);
1026 pmic_plat_data
->regulator_ext_sleep_control
[idx
] = prop
;
1030 return pmic_plat_data
;
1033 static inline struct tps65910_board
*tps65910_parse_dt_reg_data(
1034 struct platform_device
*pdev
,
1035 struct of_regulator_match
**tps65910_reg_matches
)
1037 *tps65910_reg_matches
= NULL
;
1042 static int tps65910_probe(struct platform_device
*pdev
)
1044 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1045 struct regulator_config config
= { };
1046 struct tps_info
*info
;
1047 struct regulator_init_data
*reg_data
;
1048 struct regulator_dev
*rdev
;
1049 struct tps65910_reg
*pmic
;
1050 struct tps65910_board
*pmic_plat_data
;
1051 struct of_regulator_match
*tps65910_reg_matches
= NULL
;
1054 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
1055 if (!pmic_plat_data
&& tps65910
->dev
->of_node
)
1056 pmic_plat_data
= tps65910_parse_dt_reg_data(pdev
,
1057 &tps65910_reg_matches
);
1059 if (!pmic_plat_data
) {
1060 dev_err(&pdev
->dev
, "Platform data not found\n");
1064 pmic
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic
), GFP_KERNEL
);
1066 dev_err(&pdev
->dev
, "Memory allocation failed for pmic\n");
1070 pmic
->mfd
= tps65910
;
1071 platform_set_drvdata(pdev
, pmic
);
1073 /* Give control of all register to control port */
1074 tps65910_reg_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
1075 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
1077 switch (tps65910_chip_id(tps65910
)) {
1079 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
1080 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
1081 pmic
->ext_sleep_control
= tps65910_ext_sleep_control
;
1082 info
= tps65910_regs
;
1085 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
1086 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
1087 pmic
->ext_sleep_control
= tps65911_ext_sleep_control
;
1088 info
= tps65911_regs
;
1091 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1095 pmic
->desc
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1096 sizeof(struct regulator_desc
), GFP_KERNEL
);
1098 dev_err(&pdev
->dev
, "Memory alloc fails for desc\n");
1102 pmic
->info
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1103 sizeof(struct tps_info
*), GFP_KERNEL
);
1105 dev_err(&pdev
->dev
, "Memory alloc fails for info\n");
1109 pmic
->rdev
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1110 sizeof(struct regulator_dev
*), GFP_KERNEL
);
1112 dev_err(&pdev
->dev
, "Memory alloc fails for rdev\n");
1116 for (i
= 0; i
< pmic
->num_regulators
&& i
< TPS65910_NUM_REGS
;
1119 reg_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
1121 /* Regulator API handles empty constraints but not NULL
1126 /* Register the regulators */
1127 pmic
->info
[i
] = info
;
1129 pmic
->desc
[i
].name
= info
->name
;
1130 pmic
->desc
[i
].supply_name
= info
->vin_name
;
1131 pmic
->desc
[i
].id
= i
;
1132 pmic
->desc
[i
].n_voltages
= info
->n_voltages
;
1133 pmic
->desc
[i
].enable_time
= info
->enable_time_us
;
1135 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
1136 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1137 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
1138 VDD1_2_NUM_VOLT_COARSE
;
1139 pmic
->desc
[i
].ramp_delay
= 12500;
1140 } else if (i
== TPS65910_REG_VDD3
) {
1141 if (tps65910_chip_id(tps65910
) == TPS65910
) {
1142 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
1143 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1145 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1146 pmic
->desc
[i
].ramp_delay
= 5000;
1149 if (tps65910_chip_id(tps65910
) == TPS65910
) {
1150 pmic
->desc
[i
].ops
= &tps65910_ops
;
1151 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1153 pmic
->desc
[i
].ops
= &tps65911_ops
;
1157 err
= tps65910_set_ext_sleep_config(pmic
, i
,
1158 pmic_plat_data
->regulator_ext_sleep_control
[i
]);
1160 * Failing on regulator for configuring externally control
1161 * is not a serious issue, just throw warning.
1164 dev_warn(tps65910
->dev
,
1165 "Failed to initialise ext control config\n");
1167 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
1168 pmic
->desc
[i
].owner
= THIS_MODULE
;
1169 pmic
->desc
[i
].enable_reg
= pmic
->get_ctrl_reg(i
);
1170 pmic
->desc
[i
].enable_mask
= TPS65910_SUPPLY_STATE_ENABLED
;
1172 config
.dev
= tps65910
->dev
;
1173 config
.init_data
= reg_data
;
1174 config
.driver_data
= pmic
;
1175 config
.regmap
= tps65910
->regmap
;
1177 if (tps65910_reg_matches
)
1178 config
.of_node
= tps65910_reg_matches
[i
].of_node
;
1180 rdev
= devm_regulator_register(&pdev
->dev
, &pmic
->desc
[i
],
1183 dev_err(tps65910
->dev
,
1184 "failed to register %s regulator\n",
1186 return PTR_ERR(rdev
);
1189 /* Save regulator for cleanup */
1190 pmic
->rdev
[i
] = rdev
;
1195 static void tps65910_shutdown(struct platform_device
*pdev
)
1197 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1201 * Before bootloader jumps to kernel, it makes sure that required
1202 * external control signals are in desired state so that given rails
1203 * can be configure accordingly.
1204 * If rails are configured to be controlled from external control
1205 * then before shutting down/rebooting the system, the external
1206 * control configuration need to be remove from the rails so that
1207 * its output will be available as per register programming even
1208 * if external controls are removed. This is require when the POR
1209 * value of the control signals are not in active state and before
1210 * bootloader initializes it, the system requires the rail output
1211 * to be active for booting.
1213 for (i
= 0; i
< pmic
->num_regulators
; i
++) {
1218 err
= tps65910_set_ext_sleep_config(pmic
, i
, 0);
1221 "Error in clearing external control\n");
1225 static struct platform_driver tps65910_driver
= {
1227 .name
= "tps65910-pmic",
1228 .owner
= THIS_MODULE
,
1230 .probe
= tps65910_probe
,
1231 .shutdown
= tps65910_shutdown
,
1234 static int __init
tps65910_init(void)
1236 return platform_driver_register(&tps65910_driver
);
1238 subsys_initcall(tps65910_init
);
1240 static void __exit
tps65910_cleanup(void)
1242 platform_driver_unregister(&tps65910_driver
);
1244 module_exit(tps65910_cleanup
);
1246 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1247 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1248 MODULE_LICENSE("GPL v2");
1249 MODULE_ALIAS("platform:tps65910-pmic");