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>
21 #include <linux/platform_device.h>
22 #include <linux/regulator/driver.h>
23 #include <linux/regulator/machine.h>
24 #include <linux/slab.h>
25 #include <linux/gpio.h>
26 #include <linux/mfd/tps65910.h>
27 #include <linux/regulator/of_regulator.h>
29 #define TPS65910_SUPPLY_STATE_ENABLED 0x1
30 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
32 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
33 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
35 /* supported VIO voltages in microvolts */
36 static const unsigned int VIO_VSEL_table
[] = {
37 1500000, 1800000, 2500000, 3300000,
40 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
42 /* supported VRTC voltages in microvolts */
43 static const unsigned int VRTC_VSEL_table
[] = {
47 /* supported VDD3 voltages in microvolts */
48 static const unsigned int VDD3_VSEL_table
[] = {
52 /* supported VDIG1 voltages in microvolts */
53 static const unsigned int VDIG1_VSEL_table
[] = {
54 1200000, 1500000, 1800000, 2700000,
57 /* supported VDIG2 voltages in microvolts */
58 static const unsigned int VDIG2_VSEL_table
[] = {
59 1000000, 1100000, 1200000, 1800000,
62 /* supported VPLL voltages in microvolts */
63 static const unsigned int VPLL_VSEL_table
[] = {
64 1000000, 1100000, 1800000, 2500000,
67 /* supported VDAC voltages in microvolts */
68 static const unsigned int VDAC_VSEL_table
[] = {
69 1800000, 2600000, 2800000, 2850000,
72 /* supported VAUX1 voltages in microvolts */
73 static const unsigned int VAUX1_VSEL_table
[] = {
74 1800000, 2500000, 2800000, 2850000,
77 /* supported VAUX2 voltages in microvolts */
78 static const unsigned int VAUX2_VSEL_table
[] = {
79 1800000, 2800000, 2900000, 3300000,
82 /* supported VAUX33 voltages in microvolts */
83 static const unsigned int VAUX33_VSEL_table
[] = {
84 1800000, 2000000, 2800000, 3300000,
87 /* supported VMMC voltages in microvolts */
88 static const unsigned int VMMC_VSEL_table
[] = {
89 1800000, 2800000, 3000000, 3300000,
92 /* supported BBCH voltages in microvolts */
93 static const unsigned int VBB_VSEL_table
[] = {
94 3000000, 2520000, 3150000, 5000000,
101 const unsigned int *voltage_table
;
105 static struct tps_info tps65910_regs
[] = {
109 .n_voltages
= ARRAY_SIZE(VRTC_VSEL_table
),
110 .voltage_table
= VRTC_VSEL_table
,
111 .enable_time_us
= 2200,
116 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
117 .voltage_table
= VIO_VSEL_table
,
118 .enable_time_us
= 350,
123 .enable_time_us
= 350,
128 .enable_time_us
= 350,
132 .n_voltages
= ARRAY_SIZE(VDD3_VSEL_table
),
133 .voltage_table
= VDD3_VSEL_table
,
134 .enable_time_us
= 200,
139 .n_voltages
= ARRAY_SIZE(VDIG1_VSEL_table
),
140 .voltage_table
= VDIG1_VSEL_table
,
141 .enable_time_us
= 100,
146 .n_voltages
= ARRAY_SIZE(VDIG2_VSEL_table
),
147 .voltage_table
= VDIG2_VSEL_table
,
148 .enable_time_us
= 100,
153 .n_voltages
= ARRAY_SIZE(VPLL_VSEL_table
),
154 .voltage_table
= VPLL_VSEL_table
,
155 .enable_time_us
= 100,
160 .n_voltages
= ARRAY_SIZE(VDAC_VSEL_table
),
161 .voltage_table
= VDAC_VSEL_table
,
162 .enable_time_us
= 100,
167 .n_voltages
= ARRAY_SIZE(VAUX1_VSEL_table
),
168 .voltage_table
= VAUX1_VSEL_table
,
169 .enable_time_us
= 100,
174 .n_voltages
= ARRAY_SIZE(VAUX2_VSEL_table
),
175 .voltage_table
= VAUX2_VSEL_table
,
176 .enable_time_us
= 100,
181 .n_voltages
= ARRAY_SIZE(VAUX33_VSEL_table
),
182 .voltage_table
= VAUX33_VSEL_table
,
183 .enable_time_us
= 100,
188 .n_voltages
= ARRAY_SIZE(VMMC_VSEL_table
),
189 .voltage_table
= VMMC_VSEL_table
,
190 .enable_time_us
= 100,
195 .n_voltages
= ARRAY_SIZE(VBB_VSEL_table
),
196 .voltage_table
= VBB_VSEL_table
,
200 static struct tps_info tps65911_regs
[] = {
204 .enable_time_us
= 2200,
209 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
210 .voltage_table
= VIO_VSEL_table
,
211 .enable_time_us
= 350,
217 .enable_time_us
= 350,
223 .enable_time_us
= 350,
228 .enable_time_us
= 900,
234 .enable_time_us
= 420,
240 .enable_time_us
= 420,
246 .enable_time_us
= 230,
252 .enable_time_us
= 230,
258 .enable_time_us
= 230,
264 .enable_time_us
= 230,
270 .enable_time_us
= 230,
276 .enable_time_us
= 230,
280 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
281 static unsigned int tps65910_ext_sleep_control
[] = {
283 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
284 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
285 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
286 EXT_CONTROL_REG_BITS(VDD3
, 1, 3),
287 EXT_CONTROL_REG_BITS(VDIG1
, 0, 1),
288 EXT_CONTROL_REG_BITS(VDIG2
, 0, 2),
289 EXT_CONTROL_REG_BITS(VPLL
, 0, 6),
290 EXT_CONTROL_REG_BITS(VDAC
, 0, 7),
291 EXT_CONTROL_REG_BITS(VAUX1
, 0, 3),
292 EXT_CONTROL_REG_BITS(VAUX2
, 0, 4),
293 EXT_CONTROL_REG_BITS(VAUX33
, 0, 5),
294 EXT_CONTROL_REG_BITS(VMMC
, 0, 0),
297 static unsigned int tps65911_ext_sleep_control
[] = {
299 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
300 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
301 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
302 EXT_CONTROL_REG_BITS(VDDCTRL
, 1, 3),
303 EXT_CONTROL_REG_BITS(LDO1
, 0, 1),
304 EXT_CONTROL_REG_BITS(LDO2
, 0, 2),
305 EXT_CONTROL_REG_BITS(LDO3
, 0, 7),
306 EXT_CONTROL_REG_BITS(LDO4
, 0, 6),
307 EXT_CONTROL_REG_BITS(LDO5
, 0, 3),
308 EXT_CONTROL_REG_BITS(LDO6
, 0, 0),
309 EXT_CONTROL_REG_BITS(LDO7
, 0, 5),
310 EXT_CONTROL_REG_BITS(LDO8
, 0, 4),
313 struct tps65910_reg
{
314 struct regulator_desc
*desc
;
315 struct tps65910
*mfd
;
316 struct regulator_dev
**rdev
;
317 struct tps_info
**info
;
320 int (*get_ctrl_reg
)(int);
321 unsigned int *ext_sleep_control
;
322 unsigned int board_ext_control
[TPS65910_NUM_REGS
];
325 static int tps65910_get_ctrl_register(int id
)
328 case TPS65910_REG_VRTC
:
329 return TPS65910_VRTC
;
330 case TPS65910_REG_VIO
:
332 case TPS65910_REG_VDD1
:
333 return TPS65910_VDD1
;
334 case TPS65910_REG_VDD2
:
335 return TPS65910_VDD2
;
336 case TPS65910_REG_VDD3
:
337 return TPS65910_VDD3
;
338 case TPS65910_REG_VDIG1
:
339 return TPS65910_VDIG1
;
340 case TPS65910_REG_VDIG2
:
341 return TPS65910_VDIG2
;
342 case TPS65910_REG_VPLL
:
343 return TPS65910_VPLL
;
344 case TPS65910_REG_VDAC
:
345 return TPS65910_VDAC
;
346 case TPS65910_REG_VAUX1
:
347 return TPS65910_VAUX1
;
348 case TPS65910_REG_VAUX2
:
349 return TPS65910_VAUX2
;
350 case TPS65910_REG_VAUX33
:
351 return TPS65910_VAUX33
;
352 case TPS65910_REG_VMMC
:
353 return TPS65910_VMMC
;
354 case TPS65910_REG_VBB
:
355 return TPS65910_BBCH
;
361 static int tps65911_get_ctrl_register(int id
)
364 case TPS65910_REG_VRTC
:
365 return TPS65910_VRTC
;
366 case TPS65910_REG_VIO
:
368 case TPS65910_REG_VDD1
:
369 return TPS65910_VDD1
;
370 case TPS65910_REG_VDD2
:
371 return TPS65910_VDD2
;
372 case TPS65911_REG_VDDCTRL
:
373 return TPS65911_VDDCTRL
;
374 case TPS65911_REG_LDO1
:
375 return TPS65911_LDO1
;
376 case TPS65911_REG_LDO2
:
377 return TPS65911_LDO2
;
378 case TPS65911_REG_LDO3
:
379 return TPS65911_LDO3
;
380 case TPS65911_REG_LDO4
:
381 return TPS65911_LDO4
;
382 case TPS65911_REG_LDO5
:
383 return TPS65911_LDO5
;
384 case TPS65911_REG_LDO6
:
385 return TPS65911_LDO6
;
386 case TPS65911_REG_LDO7
:
387 return TPS65911_LDO7
;
388 case TPS65911_REG_LDO8
:
389 return TPS65911_LDO8
;
395 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
397 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
398 struct tps65910
*mfd
= pmic
->mfd
;
399 int reg
, value
, id
= rdev_get_id(dev
);
401 reg
= pmic
->get_ctrl_reg(id
);
406 case REGULATOR_MODE_NORMAL
:
407 return tps65910_reg_update_bits(pmic
->mfd
, reg
,
408 LDO_ST_MODE_BIT
| LDO_ST_ON_BIT
,
410 case REGULATOR_MODE_IDLE
:
411 value
= LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
;
412 return tps65910_reg_set_bits(mfd
, reg
, value
);
413 case REGULATOR_MODE_STANDBY
:
414 return tps65910_reg_clear_bits(mfd
, reg
, LDO_ST_ON_BIT
);
420 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
422 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
423 int ret
, reg
, value
, id
= rdev_get_id(dev
);
425 reg
= pmic
->get_ctrl_reg(id
);
429 ret
= tps65910_reg_read(pmic
->mfd
, reg
, &value
);
433 if (!(value
& LDO_ST_ON_BIT
))
434 return REGULATOR_MODE_STANDBY
;
435 else if (value
& LDO_ST_MODE_BIT
)
436 return REGULATOR_MODE_IDLE
;
438 return REGULATOR_MODE_NORMAL
;
441 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev
*dev
)
443 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
444 int ret
, id
= rdev_get_id(dev
);
445 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
448 case TPS65910_REG_VDD1
:
449 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD1_OP
, &opvsel
);
452 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD1
, &mult
);
455 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
456 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD1_SR
, &srvsel
);
459 sr
= opvsel
& VDD1_OP_CMD_MASK
;
460 opvsel
&= VDD1_OP_SEL_MASK
;
461 srvsel
&= VDD1_SR_SEL_MASK
;
464 case TPS65910_REG_VDD2
:
465 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD2_OP
, &opvsel
);
468 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD2
, &mult
);
471 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
472 ret
= tps65910_reg_read(pmic
->mfd
, TPS65910_VDD2_SR
, &srvsel
);
475 sr
= opvsel
& VDD2_OP_CMD_MASK
;
476 opvsel
&= VDD2_OP_SEL_MASK
;
477 srvsel
&= VDD2_SR_SEL_MASK
;
480 case TPS65911_REG_VDDCTRL
:
481 ret
= tps65910_reg_read(pmic
->mfd
, TPS65911_VDDCTRL_OP
,
485 ret
= tps65910_reg_read(pmic
->mfd
, TPS65911_VDDCTRL_SR
,
489 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
490 opvsel
&= VDDCTRL_OP_SEL_MASK
;
491 srvsel
&= VDDCTRL_SR_SEL_MASK
;
496 /* multiplier 0 == 1 but 2,3 normal */
501 /* normalise to valid range */
504 if (srvsel
> vselmax
)
509 /* normalise to valid range*/
512 if (opvsel
> vselmax
)
519 static int tps65910_get_voltage_sel(struct regulator_dev
*dev
)
521 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
522 int ret
, reg
, value
, id
= rdev_get_id(dev
);
524 reg
= pmic
->get_ctrl_reg(id
);
528 ret
= tps65910_reg_read(pmic
->mfd
, reg
, &value
);
533 case TPS65910_REG_VIO
:
534 case TPS65910_REG_VDIG1
:
535 case TPS65910_REG_VDIG2
:
536 case TPS65910_REG_VPLL
:
537 case TPS65910_REG_VDAC
:
538 case TPS65910_REG_VAUX1
:
539 case TPS65910_REG_VAUX2
:
540 case TPS65910_REG_VAUX33
:
541 case TPS65910_REG_VMMC
:
542 value
&= LDO_SEL_MASK
;
543 value
>>= LDO_SEL_SHIFT
;
545 case TPS65910_REG_VBB
:
546 value
&= BBCH_BBSEL_MASK
;
547 value
>>= BBCH_BBSEL_SHIFT
;
556 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
558 return dev
->desc
->volt_table
[0];
561 static int tps65911_get_voltage_sel(struct regulator_dev
*dev
)
563 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
564 int ret
, id
= rdev_get_id(dev
);
565 unsigned int value
, reg
;
567 reg
= pmic
->get_ctrl_reg(id
);
569 ret
= tps65910_reg_read(pmic
->mfd
, reg
, &value
);
574 case TPS65911_REG_LDO1
:
575 case TPS65911_REG_LDO2
:
576 case TPS65911_REG_LDO4
:
577 value
&= LDO1_SEL_MASK
;
578 value
>>= LDO_SEL_SHIFT
;
580 case TPS65911_REG_LDO3
:
581 case TPS65911_REG_LDO5
:
582 case TPS65911_REG_LDO6
:
583 case TPS65911_REG_LDO7
:
584 case TPS65911_REG_LDO8
:
585 value
&= LDO3_SEL_MASK
;
586 value
>>= LDO_SEL_SHIFT
;
588 case TPS65910_REG_VIO
:
589 value
&= LDO_SEL_MASK
;
590 value
>>= LDO_SEL_SHIFT
;
599 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev
*dev
,
602 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
603 int id
= rdev_get_id(dev
), vsel
;
607 case TPS65910_REG_VDD1
:
608 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
611 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
613 tps65910_reg_update_bits(pmic
->mfd
, TPS65910_VDD1
,
615 dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
);
616 tps65910_reg_write(pmic
->mfd
, TPS65910_VDD1_OP
, vsel
);
618 case TPS65910_REG_VDD2
:
619 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
622 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
624 tps65910_reg_update_bits(pmic
->mfd
, TPS65910_VDD2
,
626 dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
);
627 tps65910_reg_write(pmic
->mfd
, TPS65910_VDD2_OP
, vsel
);
629 case TPS65911_REG_VDDCTRL
:
631 tps65910_reg_write(pmic
->mfd
, TPS65911_VDDCTRL_OP
, vsel
);
637 static int tps65910_set_voltage_sel(struct regulator_dev
*dev
,
640 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
641 int reg
, id
= rdev_get_id(dev
);
643 reg
= pmic
->get_ctrl_reg(id
);
648 case TPS65910_REG_VIO
:
649 case TPS65910_REG_VDIG1
:
650 case TPS65910_REG_VDIG2
:
651 case TPS65910_REG_VPLL
:
652 case TPS65910_REG_VDAC
:
653 case TPS65910_REG_VAUX1
:
654 case TPS65910_REG_VAUX2
:
655 case TPS65910_REG_VAUX33
:
656 case TPS65910_REG_VMMC
:
657 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO_SEL_MASK
,
658 selector
<< LDO_SEL_SHIFT
);
659 case TPS65910_REG_VBB
:
660 return tps65910_reg_update_bits(pmic
->mfd
, reg
, BBCH_BBSEL_MASK
,
661 selector
<< BBCH_BBSEL_SHIFT
);
667 static int tps65911_set_voltage_sel(struct regulator_dev
*dev
,
670 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
671 int reg
, id
= rdev_get_id(dev
);
673 reg
= pmic
->get_ctrl_reg(id
);
678 case TPS65911_REG_LDO1
:
679 case TPS65911_REG_LDO2
:
680 case TPS65911_REG_LDO4
:
681 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO1_SEL_MASK
,
682 selector
<< LDO_SEL_SHIFT
);
683 case TPS65911_REG_LDO3
:
684 case TPS65911_REG_LDO5
:
685 case TPS65911_REG_LDO6
:
686 case TPS65911_REG_LDO7
:
687 case TPS65911_REG_LDO8
:
688 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO3_SEL_MASK
,
689 selector
<< LDO_SEL_SHIFT
);
690 case TPS65910_REG_VIO
:
691 return tps65910_reg_update_bits(pmic
->mfd
, reg
, LDO_SEL_MASK
,
692 selector
<< LDO_SEL_SHIFT
);
693 case TPS65910_REG_VBB
:
694 return tps65910_reg_update_bits(pmic
->mfd
, reg
, BBCH_BBSEL_MASK
,
695 selector
<< BBCH_BBSEL_SHIFT
);
702 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
705 int volt
, mult
= 1, id
= rdev_get_id(dev
);
708 case TPS65910_REG_VDD1
:
709 case TPS65910_REG_VDD2
:
710 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
711 volt
= VDD1_2_MIN_VOLT
+
712 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
714 case TPS65911_REG_VDDCTRL
:
715 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
722 return volt
* 100 * mult
;
725 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
727 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
728 int step_mv
= 0, id
= rdev_get_id(dev
);
731 case TPS65911_REG_LDO1
:
732 case TPS65911_REG_LDO2
:
733 case TPS65911_REG_LDO4
:
734 /* The first 5 values of the selector correspond to 1V */
742 case TPS65911_REG_LDO3
:
743 case TPS65911_REG_LDO5
:
744 case TPS65911_REG_LDO6
:
745 case TPS65911_REG_LDO7
:
746 case TPS65911_REG_LDO8
:
747 /* The first 3 values of the selector correspond to 1V */
755 case TPS65910_REG_VIO
:
756 return pmic
->info
[id
]->voltage_table
[selector
];
761 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
764 /* Regulator ops (except VRTC) */
765 static struct regulator_ops tps65910_ops_dcdc
= {
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_dcdc_sel
,
772 .set_voltage_sel
= tps65910_set_voltage_dcdc_sel
,
773 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
774 .list_voltage
= tps65910_list_voltage_dcdc
,
775 .map_voltage
= regulator_map_voltage_ascend
,
778 static struct regulator_ops tps65910_ops_vdd3
= {
779 .is_enabled
= regulator_is_enabled_regmap
,
780 .enable
= regulator_enable_regmap
,
781 .disable
= regulator_disable_regmap
,
782 .set_mode
= tps65910_set_mode
,
783 .get_mode
= tps65910_get_mode
,
784 .get_voltage
= tps65910_get_voltage_vdd3
,
785 .list_voltage
= regulator_list_voltage_table
,
786 .map_voltage
= regulator_map_voltage_ascend
,
789 static struct regulator_ops tps65910_ops_vbb
= {
790 .is_enabled
= regulator_is_enabled_regmap
,
791 .enable
= regulator_enable_regmap
,
792 .disable
= regulator_disable_regmap
,
793 .set_mode
= tps65910_set_mode
,
794 .get_mode
= tps65910_get_mode
,
795 .get_voltage_sel
= tps65910_get_voltage_sel
,
796 .set_voltage_sel
= tps65910_set_voltage_sel
,
797 .list_voltage
= regulator_list_voltage_table
,
798 .map_voltage
= regulator_map_voltage_iterate
,
801 static struct regulator_ops tps65910_ops
= {
802 .is_enabled
= regulator_is_enabled_regmap
,
803 .enable
= regulator_enable_regmap
,
804 .disable
= regulator_disable_regmap
,
805 .set_mode
= tps65910_set_mode
,
806 .get_mode
= tps65910_get_mode
,
807 .get_voltage_sel
= tps65910_get_voltage_sel
,
808 .set_voltage_sel
= tps65910_set_voltage_sel
,
809 .list_voltage
= regulator_list_voltage_table
,
810 .map_voltage
= regulator_map_voltage_ascend
,
813 static struct regulator_ops tps65911_ops
= {
814 .is_enabled
= regulator_is_enabled_regmap
,
815 .enable
= regulator_enable_regmap
,
816 .disable
= regulator_disable_regmap
,
817 .set_mode
= tps65910_set_mode
,
818 .get_mode
= tps65910_get_mode
,
819 .get_voltage_sel
= tps65911_get_voltage_sel
,
820 .set_voltage_sel
= tps65911_set_voltage_sel
,
821 .list_voltage
= tps65911_list_voltage
,
822 .map_voltage
= regulator_map_voltage_ascend
,
825 static int tps65910_set_ext_sleep_config(struct tps65910_reg
*pmic
,
826 int id
, int ext_sleep_config
)
828 struct tps65910
*mfd
= pmic
->mfd
;
829 u8 regoffs
= (pmic
->ext_sleep_control
[id
] >> 8) & 0xFF;
830 u8 bit_pos
= (1 << pmic
->ext_sleep_control
[id
] & 0xFF);
834 * Regulator can not be control from multiple external input EN1, EN2
837 if (ext_sleep_config
& EXT_SLEEP_CONTROL
) {
839 en_count
= ((ext_sleep_config
&
840 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
) != 0);
841 en_count
+= ((ext_sleep_config
&
842 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
) != 0);
843 en_count
+= ((ext_sleep_config
&
844 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
) != 0);
845 en_count
+= ((ext_sleep_config
&
846 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
) != 0);
849 "External sleep control flag is not proper\n");
854 pmic
->board_ext_control
[id
] = ext_sleep_config
;
856 /* External EN1 control */
857 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
)
858 ret
= tps65910_reg_set_bits(mfd
,
859 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
861 ret
= tps65910_reg_clear_bits(mfd
,
862 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
865 "Error in configuring external control EN1\n");
869 /* External EN2 control */
870 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
)
871 ret
= tps65910_reg_set_bits(mfd
,
872 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
874 ret
= tps65910_reg_clear_bits(mfd
,
875 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
878 "Error in configuring external control EN2\n");
882 /* External EN3 control for TPS65910 LDO only */
883 if ((tps65910_chip_id(mfd
) == TPS65910
) &&
884 (id
>= TPS65910_REG_VDIG1
)) {
885 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
)
886 ret
= tps65910_reg_set_bits(mfd
,
887 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
889 ret
= tps65910_reg_clear_bits(mfd
,
890 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
893 "Error in configuring external control EN3\n");
898 /* Return if no external control is selected */
899 if (!(ext_sleep_config
& EXT_SLEEP_CONTROL
)) {
900 /* Clear all sleep controls */
901 ret
= tps65910_reg_clear_bits(mfd
,
902 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
904 ret
= tps65910_reg_clear_bits(mfd
,
905 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
908 "Error in configuring SLEEP register\n");
913 * For regulator that has separate operational and sleep register make
914 * sure that operational is used and clear sleep register to turn
915 * regulator off when external control is inactive
917 if ((id
== TPS65910_REG_VDD1
) ||
918 (id
== TPS65910_REG_VDD2
) ||
919 ((id
== TPS65911_REG_VDDCTRL
) &&
920 (tps65910_chip_id(mfd
) == TPS65911
))) {
921 int op_reg_add
= pmic
->get_ctrl_reg(id
) + 1;
922 int sr_reg_add
= pmic
->get_ctrl_reg(id
) + 2;
925 ret
= tps65910_reg_read(pmic
->mfd
, op_reg_add
, &opvsel
);
928 ret
= tps65910_reg_read(pmic
->mfd
, sr_reg_add
, &srvsel
);
932 if (opvsel
& VDD1_OP_CMD_MASK
) {
933 u8 reg_val
= srvsel
& VDD1_OP_SEL_MASK
;
935 ret
= tps65910_reg_write(pmic
->mfd
, op_reg_add
,
939 "Error in configuring op register\n");
943 ret
= tps65910_reg_write(pmic
->mfd
, sr_reg_add
, 0);
945 dev_err(mfd
->dev
, "Error in setting sr register\n");
950 ret
= tps65910_reg_clear_bits(mfd
,
951 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
953 if (ext_sleep_config
& TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
)
954 ret
= tps65910_reg_set_bits(mfd
,
955 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
957 ret
= tps65910_reg_clear_bits(mfd
,
958 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
962 "Error in configuring SLEEP register\n");
969 static struct of_regulator_match tps65910_matches
[] = {
970 { .name
= "vrtc", .driver_data
= (void *) &tps65910_regs
[0] },
971 { .name
= "vio", .driver_data
= (void *) &tps65910_regs
[1] },
972 { .name
= "vdd1", .driver_data
= (void *) &tps65910_regs
[2] },
973 { .name
= "vdd2", .driver_data
= (void *) &tps65910_regs
[3] },
974 { .name
= "vdd3", .driver_data
= (void *) &tps65910_regs
[4] },
975 { .name
= "vdig1", .driver_data
= (void *) &tps65910_regs
[5] },
976 { .name
= "vdig2", .driver_data
= (void *) &tps65910_regs
[6] },
977 { .name
= "vpll", .driver_data
= (void *) &tps65910_regs
[7] },
978 { .name
= "vdac", .driver_data
= (void *) &tps65910_regs
[8] },
979 { .name
= "vaux1", .driver_data
= (void *) &tps65910_regs
[9] },
980 { .name
= "vaux2", .driver_data
= (void *) &tps65910_regs
[10] },
981 { .name
= "vaux33", .driver_data
= (void *) &tps65910_regs
[11] },
982 { .name
= "vmmc", .driver_data
= (void *) &tps65910_regs
[12] },
983 { .name
= "vbb", .driver_data
= (void *) &tps65910_regs
[13] },
986 static struct of_regulator_match tps65911_matches
[] = {
987 { .name
= "vrtc", .driver_data
= (void *) &tps65911_regs
[0] },
988 { .name
= "vio", .driver_data
= (void *) &tps65911_regs
[1] },
989 { .name
= "vdd1", .driver_data
= (void *) &tps65911_regs
[2] },
990 { .name
= "vdd2", .driver_data
= (void *) &tps65911_regs
[3] },
991 { .name
= "vddctrl", .driver_data
= (void *) &tps65911_regs
[4] },
992 { .name
= "ldo1", .driver_data
= (void *) &tps65911_regs
[5] },
993 { .name
= "ldo2", .driver_data
= (void *) &tps65911_regs
[6] },
994 { .name
= "ldo3", .driver_data
= (void *) &tps65911_regs
[7] },
995 { .name
= "ldo4", .driver_data
= (void *) &tps65911_regs
[8] },
996 { .name
= "ldo5", .driver_data
= (void *) &tps65911_regs
[9] },
997 { .name
= "ldo6", .driver_data
= (void *) &tps65911_regs
[10] },
998 { .name
= "ldo7", .driver_data
= (void *) &tps65911_regs
[11] },
999 { .name
= "ldo8", .driver_data
= (void *) &tps65911_regs
[12] },
1002 static struct tps65910_board
*tps65910_parse_dt_reg_data(
1003 struct platform_device
*pdev
,
1004 struct of_regulator_match
**tps65910_reg_matches
)
1006 struct tps65910_board
*pmic_plat_data
;
1007 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1008 struct device_node
*np
, *regulators
;
1009 struct of_regulator_match
*matches
;
1011 int idx
= 0, ret
, count
;
1013 pmic_plat_data
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic_plat_data
),
1015 if (!pmic_plat_data
)
1018 np
= pdev
->dev
.parent
->of_node
;
1019 regulators
= of_get_child_by_name(np
, "regulators");
1021 dev_err(&pdev
->dev
, "regulator node not found\n");
1025 switch (tps65910_chip_id(tps65910
)) {
1027 count
= ARRAY_SIZE(tps65910_matches
);
1028 matches
= tps65910_matches
;
1031 count
= ARRAY_SIZE(tps65911_matches
);
1032 matches
= tps65911_matches
;
1035 of_node_put(regulators
);
1036 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1040 ret
= of_regulator_match(&pdev
->dev
, regulators
, matches
, count
);
1041 of_node_put(regulators
);
1043 dev_err(&pdev
->dev
, "Error parsing regulator init data: %d\n",
1048 *tps65910_reg_matches
= matches
;
1050 for (idx
= 0; idx
< count
; idx
++) {
1051 if (!matches
[idx
].of_node
)
1054 pmic_plat_data
->tps65910_pmic_init_data
[idx
] =
1055 matches
[idx
].init_data
;
1057 ret
= of_property_read_u32(matches
[idx
].of_node
,
1058 "ti,regulator-ext-sleep-control", &prop
);
1060 pmic_plat_data
->regulator_ext_sleep_control
[idx
] = prop
;
1064 return pmic_plat_data
;
1067 static inline struct tps65910_board
*tps65910_parse_dt_reg_data(
1068 struct platform_device
*pdev
,
1069 struct of_regulator_match
**tps65910_reg_matches
)
1071 *tps65910_reg_matches
= NULL
;
1076 static int tps65910_probe(struct platform_device
*pdev
)
1078 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1079 struct regulator_config config
= { };
1080 struct tps_info
*info
;
1081 struct regulator_dev
*rdev
;
1082 struct tps65910_reg
*pmic
;
1083 struct tps65910_board
*pmic_plat_data
;
1084 struct of_regulator_match
*tps65910_reg_matches
= NULL
;
1087 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
1088 if (!pmic_plat_data
&& tps65910
->dev
->of_node
)
1089 pmic_plat_data
= tps65910_parse_dt_reg_data(pdev
,
1090 &tps65910_reg_matches
);
1092 if (!pmic_plat_data
) {
1093 dev_err(&pdev
->dev
, "Platform data not found\n");
1097 pmic
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic
), GFP_KERNEL
);
1101 pmic
->mfd
= tps65910
;
1102 platform_set_drvdata(pdev
, pmic
);
1104 /* Give control of all register to control port */
1105 tps65910_reg_set_bits(pmic
->mfd
, TPS65910_DEVCTRL
,
1106 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
1108 switch (tps65910_chip_id(tps65910
)) {
1110 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
1111 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
1112 pmic
->ext_sleep_control
= tps65910_ext_sleep_control
;
1113 info
= tps65910_regs
;
1116 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
1117 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
1118 pmic
->ext_sleep_control
= tps65911_ext_sleep_control
;
1119 info
= tps65911_regs
;
1122 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1126 pmic
->desc
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1127 sizeof(struct regulator_desc
), GFP_KERNEL
);
1131 pmic
->info
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1132 sizeof(struct tps_info
*), GFP_KERNEL
);
1136 pmic
->rdev
= devm_kzalloc(&pdev
->dev
, pmic
->num_regulators
*
1137 sizeof(struct regulator_dev
*), GFP_KERNEL
);
1141 for (i
= 0; i
< pmic
->num_regulators
&& i
< TPS65910_NUM_REGS
;
1143 /* Register the regulators */
1144 pmic
->info
[i
] = info
;
1146 pmic
->desc
[i
].name
= info
->name
;
1147 pmic
->desc
[i
].supply_name
= info
->vin_name
;
1148 pmic
->desc
[i
].id
= i
;
1149 pmic
->desc
[i
].n_voltages
= info
->n_voltages
;
1150 pmic
->desc
[i
].enable_time
= info
->enable_time_us
;
1152 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
1153 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1154 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
1155 VDD1_2_NUM_VOLT_COARSE
;
1156 pmic
->desc
[i
].ramp_delay
= 12500;
1157 } else if (i
== TPS65910_REG_VDD3
) {
1158 if (tps65910_chip_id(tps65910
) == TPS65910
) {
1159 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
1160 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1162 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1163 pmic
->desc
[i
].ramp_delay
= 5000;
1165 } else if (i
== TPS65910_REG_VBB
&&
1166 tps65910_chip_id(tps65910
) == TPS65910
) {
1167 pmic
->desc
[i
].ops
= &tps65910_ops_vbb
;
1168 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1170 if (tps65910_chip_id(tps65910
) == TPS65910
) {
1171 pmic
->desc
[i
].ops
= &tps65910_ops
;
1172 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1174 pmic
->desc
[i
].ops
= &tps65911_ops
;
1178 err
= tps65910_set_ext_sleep_config(pmic
, i
,
1179 pmic_plat_data
->regulator_ext_sleep_control
[i
]);
1181 * Failing on regulator for configuring externally control
1182 * is not a serious issue, just throw warning.
1185 dev_warn(tps65910
->dev
,
1186 "Failed to initialise ext control config\n");
1188 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
1189 pmic
->desc
[i
].owner
= THIS_MODULE
;
1190 pmic
->desc
[i
].enable_reg
= pmic
->get_ctrl_reg(i
);
1191 pmic
->desc
[i
].enable_mask
= TPS65910_SUPPLY_STATE_ENABLED
;
1193 config
.dev
= tps65910
->dev
;
1194 config
.init_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
1195 config
.driver_data
= pmic
;
1196 config
.regmap
= tps65910
->regmap
;
1198 if (tps65910_reg_matches
)
1199 config
.of_node
= tps65910_reg_matches
[i
].of_node
;
1201 rdev
= devm_regulator_register(&pdev
->dev
, &pmic
->desc
[i
],
1204 dev_err(tps65910
->dev
,
1205 "failed to register %s regulator\n",
1207 return PTR_ERR(rdev
);
1210 /* Save regulator for cleanup */
1211 pmic
->rdev
[i
] = rdev
;
1216 static void tps65910_shutdown(struct platform_device
*pdev
)
1218 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1222 * Before bootloader jumps to kernel, it makes sure that required
1223 * external control signals are in desired state so that given rails
1224 * can be configure accordingly.
1225 * If rails are configured to be controlled from external control
1226 * then before shutting down/rebooting the system, the external
1227 * control configuration need to be remove from the rails so that
1228 * its output will be available as per register programming even
1229 * if external controls are removed. This is require when the POR
1230 * value of the control signals are not in active state and before
1231 * bootloader initializes it, the system requires the rail output
1232 * to be active for booting.
1234 for (i
= 0; i
< pmic
->num_regulators
; i
++) {
1239 err
= tps65910_set_ext_sleep_config(pmic
, i
, 0);
1242 "Error in clearing external control\n");
1246 static struct platform_driver tps65910_driver
= {
1248 .name
= "tps65910-pmic",
1250 .probe
= tps65910_probe
,
1251 .shutdown
= tps65910_shutdown
,
1254 static int __init
tps65910_init(void)
1256 return platform_driver_register(&tps65910_driver
);
1258 subsys_initcall(tps65910_init
);
1260 static void __exit
tps65910_cleanup(void)
1262 platform_driver_unregister(&tps65910_driver
);
1264 module_exit(tps65910_cleanup
);
1266 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1267 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1268 MODULE_LICENSE("GPL v2");
1269 MODULE_ALIAS("platform:tps65910-pmic");