1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * tps65910.c -- TI tps65910
5 * Copyright 2010 Texas Instruments Inc.
7 * Author: Graeme Gregory <gg@slimlogic.co.uk>
8 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/err.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/regulator/machine.h>
19 #include <linux/slab.h>
20 #include <linux/mfd/tps65910.h>
21 #include <linux/regulator/of_regulator.h>
23 #define TPS65910_SUPPLY_STATE_ENABLED 0x1
24 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
25 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
26 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
27 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
29 /* supported VIO voltages in microvolts */
30 static const unsigned int VIO_VSEL_table
[] = {
31 1500000, 1800000, 2500000, 3300000,
34 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
36 /* supported VRTC voltages in microvolts */
37 static const unsigned int VRTC_VSEL_table
[] = {
41 /* supported VDD3 voltages in microvolts */
42 static const unsigned int VDD3_VSEL_table
[] = {
46 /* supported VDIG1 voltages in microvolts */
47 static const unsigned int VDIG1_VSEL_table
[] = {
48 1200000, 1500000, 1800000, 2700000,
51 /* supported VDIG2 voltages in microvolts */
52 static const unsigned int VDIG2_VSEL_table
[] = {
53 1000000, 1100000, 1200000, 1800000,
56 /* supported VPLL voltages in microvolts */
57 static const unsigned int VPLL_VSEL_table
[] = {
58 1000000, 1100000, 1800000, 2500000,
61 /* supported VDAC voltages in microvolts */
62 static const unsigned int VDAC_VSEL_table
[] = {
63 1800000, 2600000, 2800000, 2850000,
66 /* supported VAUX1 voltages in microvolts */
67 static const unsigned int VAUX1_VSEL_table
[] = {
68 1800000, 2500000, 2800000, 2850000,
71 /* supported VAUX2 voltages in microvolts */
72 static const unsigned int VAUX2_VSEL_table
[] = {
73 1800000, 2800000, 2900000, 3300000,
76 /* supported VAUX33 voltages in microvolts */
77 static const unsigned int VAUX33_VSEL_table
[] = {
78 1800000, 2000000, 2800000, 3300000,
81 /* supported VMMC voltages in microvolts */
82 static const unsigned int VMMC_VSEL_table
[] = {
83 1800000, 2800000, 3000000, 3300000,
86 /* supported BBCH voltages in microvolts */
87 static const unsigned int VBB_VSEL_table
[] = {
88 3000000, 2520000, 3150000, 5000000,
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,
189 .n_voltages
= ARRAY_SIZE(VBB_VSEL_table
),
190 .voltage_table
= VBB_VSEL_table
,
194 static struct tps_info tps65911_regs
[] = {
198 .enable_time_us
= 2200,
203 .n_voltages
= ARRAY_SIZE(VIO_VSEL_table
),
204 .voltage_table
= VIO_VSEL_table
,
205 .enable_time_us
= 350,
211 .enable_time_us
= 350,
217 .enable_time_us
= 350,
222 .enable_time_us
= 900,
228 .enable_time_us
= 420,
234 .enable_time_us
= 420,
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,
270 .enable_time_us
= 230,
274 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
275 static unsigned int tps65910_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(VDD3
, 1, 3),
281 EXT_CONTROL_REG_BITS(VDIG1
, 0, 1),
282 EXT_CONTROL_REG_BITS(VDIG2
, 0, 2),
283 EXT_CONTROL_REG_BITS(VPLL
, 0, 6),
284 EXT_CONTROL_REG_BITS(VDAC
, 0, 7),
285 EXT_CONTROL_REG_BITS(VAUX1
, 0, 3),
286 EXT_CONTROL_REG_BITS(VAUX2
, 0, 4),
287 EXT_CONTROL_REG_BITS(VAUX33
, 0, 5),
288 EXT_CONTROL_REG_BITS(VMMC
, 0, 0),
291 static unsigned int tps65911_ext_sleep_control
[] = {
293 EXT_CONTROL_REG_BITS(VIO
, 1, 0),
294 EXT_CONTROL_REG_BITS(VDD1
, 1, 1),
295 EXT_CONTROL_REG_BITS(VDD2
, 1, 2),
296 EXT_CONTROL_REG_BITS(VDDCTRL
, 1, 3),
297 EXT_CONTROL_REG_BITS(LDO1
, 0, 1),
298 EXT_CONTROL_REG_BITS(LDO2
, 0, 2),
299 EXT_CONTROL_REG_BITS(LDO3
, 0, 7),
300 EXT_CONTROL_REG_BITS(LDO4
, 0, 6),
301 EXT_CONTROL_REG_BITS(LDO5
, 0, 3),
302 EXT_CONTROL_REG_BITS(LDO6
, 0, 0),
303 EXT_CONTROL_REG_BITS(LDO7
, 0, 5),
304 EXT_CONTROL_REG_BITS(LDO8
, 0, 4),
307 struct tps65910_reg
{
308 struct regulator_desc
*desc
;
309 struct tps65910
*mfd
;
310 struct regulator_dev
**rdev
;
311 struct tps_info
**info
;
314 int (*get_ctrl_reg
)(int);
315 unsigned int *ext_sleep_control
;
316 unsigned int board_ext_control
[TPS65910_NUM_REGS
];
319 static int tps65910_get_ctrl_register(int id
)
322 case TPS65910_REG_VRTC
:
323 return TPS65910_VRTC
;
324 case TPS65910_REG_VIO
:
326 case TPS65910_REG_VDD1
:
327 return TPS65910_VDD1
;
328 case TPS65910_REG_VDD2
:
329 return TPS65910_VDD2
;
330 case TPS65910_REG_VDD3
:
331 return TPS65910_VDD3
;
332 case TPS65910_REG_VDIG1
:
333 return TPS65910_VDIG1
;
334 case TPS65910_REG_VDIG2
:
335 return TPS65910_VDIG2
;
336 case TPS65910_REG_VPLL
:
337 return TPS65910_VPLL
;
338 case TPS65910_REG_VDAC
:
339 return TPS65910_VDAC
;
340 case TPS65910_REG_VAUX1
:
341 return TPS65910_VAUX1
;
342 case TPS65910_REG_VAUX2
:
343 return TPS65910_VAUX2
;
344 case TPS65910_REG_VAUX33
:
345 return TPS65910_VAUX33
;
346 case TPS65910_REG_VMMC
:
347 return TPS65910_VMMC
;
348 case TPS65910_REG_VBB
:
349 return TPS65910_BBCH
;
355 static int tps65911_get_ctrl_register(int id
)
358 case TPS65910_REG_VRTC
:
359 return TPS65910_VRTC
;
360 case TPS65910_REG_VIO
:
362 case TPS65910_REG_VDD1
:
363 return TPS65910_VDD1
;
364 case TPS65910_REG_VDD2
:
365 return TPS65910_VDD2
;
366 case TPS65911_REG_VDDCTRL
:
367 return TPS65911_VDDCTRL
;
368 case TPS65911_REG_LDO1
:
369 return TPS65911_LDO1
;
370 case TPS65911_REG_LDO2
:
371 return TPS65911_LDO2
;
372 case TPS65911_REG_LDO3
:
373 return TPS65911_LDO3
;
374 case TPS65911_REG_LDO4
:
375 return TPS65911_LDO4
;
376 case TPS65911_REG_LDO5
:
377 return TPS65911_LDO5
;
378 case TPS65911_REG_LDO6
:
379 return TPS65911_LDO6
;
380 case TPS65911_REG_LDO7
:
381 return TPS65911_LDO7
;
382 case TPS65911_REG_LDO8
:
383 return TPS65911_LDO8
;
389 static int tps65910_set_mode(struct regulator_dev
*dev
, unsigned int mode
)
391 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
392 struct regmap
*regmap
= rdev_get_regmap(dev
);
393 int reg
, id
= rdev_get_id(dev
);
395 reg
= pmic
->get_ctrl_reg(id
);
400 case REGULATOR_MODE_NORMAL
:
401 return regmap_update_bits(regmap
, reg
,
402 LDO_ST_MODE_BIT
| LDO_ST_ON_BIT
,
404 case REGULATOR_MODE_IDLE
:
405 return regmap_set_bits(regmap
, reg
,
406 LDO_ST_ON_BIT
| LDO_ST_MODE_BIT
);
407 case REGULATOR_MODE_STANDBY
:
408 return regmap_clear_bits(regmap
, reg
, LDO_ST_ON_BIT
);
414 static unsigned int tps65910_get_mode(struct regulator_dev
*dev
)
416 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
417 struct regmap
*regmap
= rdev_get_regmap(dev
);
418 int ret
, reg
, value
, id
= rdev_get_id(dev
);
420 reg
= pmic
->get_ctrl_reg(id
);
424 ret
= regmap_read(regmap
, reg
, &value
);
428 if (!(value
& LDO_ST_ON_BIT
))
429 return REGULATOR_MODE_STANDBY
;
430 else if (value
& LDO_ST_MODE_BIT
)
431 return REGULATOR_MODE_IDLE
;
433 return REGULATOR_MODE_NORMAL
;
436 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev
*dev
)
438 struct regmap
*regmap
= rdev_get_regmap(dev
);
439 int ret
, id
= rdev_get_id(dev
);
440 int opvsel
= 0, srvsel
= 0, vselmax
= 0, mult
= 0, sr
= 0;
443 case TPS65910_REG_VDD1
:
444 ret
= regmap_read(regmap
, TPS65910_VDD1_OP
, &opvsel
);
447 ret
= regmap_read(regmap
, TPS65910_VDD1
, &mult
);
450 mult
= (mult
& VDD1_VGAIN_SEL_MASK
) >> VDD1_VGAIN_SEL_SHIFT
;
451 ret
= regmap_read(regmap
, TPS65910_VDD1_SR
, &srvsel
);
454 sr
= opvsel
& VDD1_OP_CMD_MASK
;
455 opvsel
&= VDD1_OP_SEL_MASK
;
456 srvsel
&= VDD1_SR_SEL_MASK
;
459 case TPS65910_REG_VDD2
:
460 ret
= regmap_read(regmap
, TPS65910_VDD2_OP
, &opvsel
);
463 ret
= regmap_read(regmap
, TPS65910_VDD2
, &mult
);
466 mult
= (mult
& VDD2_VGAIN_SEL_MASK
) >> VDD2_VGAIN_SEL_SHIFT
;
467 ret
= regmap_read(regmap
, TPS65910_VDD2_SR
, &srvsel
);
470 sr
= opvsel
& VDD2_OP_CMD_MASK
;
471 opvsel
&= VDD2_OP_SEL_MASK
;
472 srvsel
&= VDD2_SR_SEL_MASK
;
475 case TPS65911_REG_VDDCTRL
:
476 ret
= regmap_read(regmap
, TPS65911_VDDCTRL_OP
, &opvsel
);
479 ret
= regmap_read(regmap
, TPS65911_VDDCTRL_SR
, &srvsel
);
482 sr
= opvsel
& VDDCTRL_OP_CMD_MASK
;
483 opvsel
&= VDDCTRL_OP_SEL_MASK
;
484 srvsel
&= VDDCTRL_SR_SEL_MASK
;
489 /* multiplier 0 == 1 but 2,3 normal */
494 /* normalise to valid range */
497 if (srvsel
> vselmax
)
502 /* normalise to valid range*/
505 if (opvsel
> vselmax
)
512 static int tps65910_get_voltage_sel(struct regulator_dev
*dev
)
514 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
515 struct regmap
*regmap
= rdev_get_regmap(dev
);
516 int ret
, reg
, value
, id
= rdev_get_id(dev
);
518 reg
= pmic
->get_ctrl_reg(id
);
522 ret
= regmap_read(regmap
, reg
, &value
);
527 case TPS65910_REG_VIO
:
528 case TPS65910_REG_VDIG1
:
529 case TPS65910_REG_VDIG2
:
530 case TPS65910_REG_VPLL
:
531 case TPS65910_REG_VDAC
:
532 case TPS65910_REG_VAUX1
:
533 case TPS65910_REG_VAUX2
:
534 case TPS65910_REG_VAUX33
:
535 case TPS65910_REG_VMMC
:
536 value
&= LDO_SEL_MASK
;
537 value
>>= LDO_SEL_SHIFT
;
539 case TPS65910_REG_VBB
:
540 value
&= BBCH_BBSEL_MASK
;
541 value
>>= BBCH_BBSEL_SHIFT
;
550 static int tps65910_get_voltage_vdd3(struct regulator_dev
*dev
)
552 return dev
->desc
->volt_table
[0];
555 static int tps65911_get_voltage_sel(struct regulator_dev
*dev
)
557 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
558 struct regmap
*regmap
= rdev_get_regmap(dev
);
559 int ret
, id
= rdev_get_id(dev
);
560 unsigned int value
, reg
;
562 reg
= pmic
->get_ctrl_reg(id
);
564 ret
= regmap_read(regmap
, reg
, &value
);
569 case TPS65911_REG_LDO1
:
570 case TPS65911_REG_LDO2
:
571 case TPS65911_REG_LDO4
:
572 value
&= LDO1_SEL_MASK
;
573 value
>>= LDO_SEL_SHIFT
;
575 case TPS65911_REG_LDO3
:
576 case TPS65911_REG_LDO5
:
577 case TPS65911_REG_LDO6
:
578 case TPS65911_REG_LDO7
:
579 case TPS65911_REG_LDO8
:
580 value
&= LDO3_SEL_MASK
;
581 value
>>= LDO_SEL_SHIFT
;
583 case TPS65910_REG_VIO
:
584 value
&= LDO_SEL_MASK
;
585 value
>>= LDO_SEL_SHIFT
;
594 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev
*dev
,
597 struct regmap
*regmap
= rdev_get_regmap(dev
);
598 int id
= rdev_get_id(dev
), vsel
;
602 case TPS65910_REG_VDD1
:
603 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
606 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
608 regmap_update_bits(regmap
, TPS65910_VDD1
, VDD1_VGAIN_SEL_MASK
,
609 dcdc_mult
<< VDD1_VGAIN_SEL_SHIFT
);
610 regmap_write(regmap
, TPS65910_VDD1_OP
, vsel
);
612 case TPS65910_REG_VDD2
:
613 dcdc_mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
616 vsel
= (selector
% VDD1_2_NUM_VOLT_FINE
) + 3;
618 regmap_update_bits(regmap
, TPS65910_VDD2
, VDD1_VGAIN_SEL_MASK
,
619 dcdc_mult
<< VDD2_VGAIN_SEL_SHIFT
);
620 regmap_write(regmap
, TPS65910_VDD2_OP
, vsel
);
622 case TPS65911_REG_VDDCTRL
:
624 regmap_write(regmap
, TPS65911_VDDCTRL_OP
, vsel
);
631 static int tps65910_set_voltage_sel(struct regulator_dev
*dev
,
634 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
635 struct regmap
*regmap
= rdev_get_regmap(dev
);
636 int reg
, id
= rdev_get_id(dev
);
638 reg
= pmic
->get_ctrl_reg(id
);
643 case TPS65910_REG_VIO
:
644 case TPS65910_REG_VDIG1
:
645 case TPS65910_REG_VDIG2
:
646 case TPS65910_REG_VPLL
:
647 case TPS65910_REG_VDAC
:
648 case TPS65910_REG_VAUX1
:
649 case TPS65910_REG_VAUX2
:
650 case TPS65910_REG_VAUX33
:
651 case TPS65910_REG_VMMC
:
652 return regmap_update_bits(regmap
, reg
, LDO_SEL_MASK
,
653 selector
<< LDO_SEL_SHIFT
);
654 case TPS65910_REG_VBB
:
655 return regmap_update_bits(regmap
, reg
, BBCH_BBSEL_MASK
,
656 selector
<< BBCH_BBSEL_SHIFT
);
662 static int tps65911_set_voltage_sel(struct regulator_dev
*dev
,
665 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
666 struct regmap
*regmap
= rdev_get_regmap(dev
);
667 int reg
, id
= rdev_get_id(dev
);
669 reg
= pmic
->get_ctrl_reg(id
);
674 case TPS65911_REG_LDO1
:
675 case TPS65911_REG_LDO2
:
676 case TPS65911_REG_LDO4
:
677 return regmap_update_bits(regmap
, reg
, LDO1_SEL_MASK
,
678 selector
<< LDO_SEL_SHIFT
);
679 case TPS65911_REG_LDO3
:
680 case TPS65911_REG_LDO5
:
681 case TPS65911_REG_LDO6
:
682 case TPS65911_REG_LDO7
:
683 case TPS65911_REG_LDO8
:
684 return regmap_update_bits(regmap
, reg
, LDO3_SEL_MASK
,
685 selector
<< LDO_SEL_SHIFT
);
686 case TPS65910_REG_VIO
:
687 return regmap_update_bits(regmap
, reg
, LDO_SEL_MASK
,
688 selector
<< LDO_SEL_SHIFT
);
689 case TPS65910_REG_VBB
:
690 return regmap_update_bits(regmap
, reg
, BBCH_BBSEL_MASK
,
691 selector
<< BBCH_BBSEL_SHIFT
);
698 static int tps65910_list_voltage_dcdc(struct regulator_dev
*dev
,
701 int volt
, mult
= 1, id
= rdev_get_id(dev
);
704 case TPS65910_REG_VDD1
:
705 case TPS65910_REG_VDD2
:
706 mult
= (selector
/ VDD1_2_NUM_VOLT_FINE
) + 1;
707 volt
= VDD1_2_MIN_VOLT
+
708 (selector
% VDD1_2_NUM_VOLT_FINE
) * VDD1_2_OFFSET
;
710 case TPS65911_REG_VDDCTRL
:
711 volt
= VDDCTRL_MIN_VOLT
+ (selector
* VDDCTRL_OFFSET
);
718 return volt
* 100 * mult
;
721 static int tps65911_list_voltage(struct regulator_dev
*dev
, unsigned selector
)
723 struct tps65910_reg
*pmic
= rdev_get_drvdata(dev
);
724 int step_mv
= 0, id
= rdev_get_id(dev
);
727 case TPS65911_REG_LDO1
:
728 case TPS65911_REG_LDO2
:
729 case TPS65911_REG_LDO4
:
730 /* The first 5 values of the selector correspond to 1V */
738 case TPS65911_REG_LDO3
:
739 case TPS65911_REG_LDO5
:
740 case TPS65911_REG_LDO6
:
741 case TPS65911_REG_LDO7
:
742 case TPS65911_REG_LDO8
:
743 /* The first 3 values of the selector correspond to 1V */
751 case TPS65910_REG_VIO
:
752 return pmic
->info
[id
]->voltage_table
[selector
];
757 return (LDO_MIN_VOLT
+ selector
* step_mv
) * 1000;
760 /* Regulator ops (except VRTC) */
761 static const struct regulator_ops tps65910_ops_dcdc
= {
762 .is_enabled
= regulator_is_enabled_regmap
,
763 .enable
= regulator_enable_regmap
,
764 .disable
= regulator_disable_regmap
,
765 .set_mode
= tps65910_set_mode
,
766 .get_mode
= tps65910_get_mode
,
767 .get_voltage_sel
= tps65910_get_voltage_dcdc_sel
,
768 .set_voltage_sel
= tps65910_set_voltage_dcdc_sel
,
769 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
770 .list_voltage
= tps65910_list_voltage_dcdc
,
771 .map_voltage
= regulator_map_voltage_ascend
,
774 static const struct regulator_ops tps65910_ops_vdd3
= {
775 .is_enabled
= regulator_is_enabled_regmap
,
776 .enable
= regulator_enable_regmap
,
777 .disable
= regulator_disable_regmap
,
778 .set_mode
= tps65910_set_mode
,
779 .get_mode
= tps65910_get_mode
,
780 .get_voltage
= tps65910_get_voltage_vdd3
,
781 .list_voltage
= regulator_list_voltage_table
,
782 .map_voltage
= regulator_map_voltage_ascend
,
785 static const struct regulator_ops tps65910_ops_vbb
= {
786 .is_enabled
= regulator_is_enabled_regmap
,
787 .enable
= regulator_enable_regmap
,
788 .disable
= regulator_disable_regmap
,
789 .set_mode
= tps65910_set_mode
,
790 .get_mode
= tps65910_get_mode
,
791 .get_voltage_sel
= tps65910_get_voltage_sel
,
792 .set_voltage_sel
= tps65910_set_voltage_sel
,
793 .list_voltage
= regulator_list_voltage_table
,
794 .map_voltage
= regulator_map_voltage_iterate
,
797 static const struct regulator_ops tps65910_ops
= {
798 .is_enabled
= regulator_is_enabled_regmap
,
799 .enable
= regulator_enable_regmap
,
800 .disable
= regulator_disable_regmap
,
801 .set_mode
= tps65910_set_mode
,
802 .get_mode
= tps65910_get_mode
,
803 .get_voltage_sel
= tps65910_get_voltage_sel
,
804 .set_voltage_sel
= tps65910_set_voltage_sel
,
805 .list_voltage
= regulator_list_voltage_table
,
806 .map_voltage
= regulator_map_voltage_ascend
,
809 static const struct regulator_ops tps65911_ops
= {
810 .is_enabled
= regulator_is_enabled_regmap
,
811 .enable
= regulator_enable_regmap
,
812 .disable
= regulator_disable_regmap
,
813 .set_mode
= tps65910_set_mode
,
814 .get_mode
= tps65910_get_mode
,
815 .get_voltage_sel
= tps65911_get_voltage_sel
,
816 .set_voltage_sel
= tps65911_set_voltage_sel
,
817 .list_voltage
= tps65911_list_voltage
,
818 .map_voltage
= regulator_map_voltage_ascend
,
821 static int tps65910_set_ext_sleep_config(struct tps65910_reg
*pmic
,
822 int id
, int ext_sleep_config
)
824 struct tps65910
*mfd
= pmic
->mfd
;
825 u8 regoffs
= (pmic
->ext_sleep_control
[id
] >> 8) & 0xFF;
826 u8 bit_pos
= (1 << pmic
->ext_sleep_control
[id
] & 0xFF);
830 * Regulator can not be control from multiple external input EN1, EN2
833 if (ext_sleep_config
& EXT_SLEEP_CONTROL
) {
835 en_count
= ((ext_sleep_config
&
836 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
) != 0);
837 en_count
+= ((ext_sleep_config
&
838 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
) != 0);
839 en_count
+= ((ext_sleep_config
&
840 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
) != 0);
841 en_count
+= ((ext_sleep_config
&
842 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
) != 0);
845 "External sleep control flag is not proper\n");
850 pmic
->board_ext_control
[id
] = ext_sleep_config
;
852 /* External EN1 control */
853 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1
)
854 ret
= regmap_set_bits(mfd
->regmap
,
855 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
857 ret
= regmap_clear_bits(mfd
->regmap
,
858 TPS65910_EN1_LDO_ASS
+ regoffs
, bit_pos
);
861 "Error in configuring external control EN1\n");
865 /* External EN2 control */
866 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2
)
867 ret
= regmap_set_bits(mfd
->regmap
,
868 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
870 ret
= regmap_clear_bits(mfd
->regmap
,
871 TPS65910_EN2_LDO_ASS
+ regoffs
, bit_pos
);
874 "Error in configuring external control EN2\n");
878 /* External EN3 control for TPS65910 LDO only */
879 if ((tps65910_chip_id(mfd
) == TPS65910
) &&
880 (id
>= TPS65910_REG_VDIG1
)) {
881 if (ext_sleep_config
& TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3
)
882 ret
= regmap_set_bits(mfd
->regmap
,
883 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
885 ret
= regmap_clear_bits(mfd
->regmap
,
886 TPS65910_EN3_LDO_ASS
+ regoffs
, bit_pos
);
889 "Error in configuring external control EN3\n");
894 /* Return if no external control is selected */
895 if (!(ext_sleep_config
& EXT_SLEEP_CONTROL
)) {
896 /* Clear all sleep controls */
897 ret
= regmap_clear_bits(mfd
->regmap
,
898 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
900 ret
= regmap_clear_bits(mfd
->regmap
,
901 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
904 "Error in configuring SLEEP register\n");
909 * For regulator that has separate operational and sleep register make
910 * sure that operational is used and clear sleep register to turn
911 * regulator off when external control is inactive
913 if ((id
== TPS65910_REG_VDD1
) ||
914 (id
== TPS65910_REG_VDD2
) ||
915 ((id
== TPS65911_REG_VDDCTRL
) &&
916 (tps65910_chip_id(mfd
) == TPS65911
))) {
917 int op_reg_add
= pmic
->get_ctrl_reg(id
) + 1;
918 int sr_reg_add
= pmic
->get_ctrl_reg(id
) + 2;
921 ret
= regmap_read(mfd
->regmap
, op_reg_add
, &opvsel
);
924 ret
= regmap_read(mfd
->regmap
, sr_reg_add
, &srvsel
);
928 if (opvsel
& VDD1_OP_CMD_MASK
) {
929 u8 reg_val
= srvsel
& VDD1_OP_SEL_MASK
;
931 ret
= regmap_write(mfd
->regmap
, op_reg_add
, reg_val
);
934 "Error in configuring op register\n");
938 ret
= regmap_write(mfd
->regmap
, sr_reg_add
, 0);
940 dev_err(mfd
->dev
, "Error in setting sr register\n");
945 ret
= regmap_clear_bits(mfd
->regmap
,
946 TPS65910_SLEEP_KEEP_LDO_ON
+ regoffs
, bit_pos
);
948 if (ext_sleep_config
& TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP
)
949 ret
= regmap_set_bits(mfd
->regmap
,
950 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
952 ret
= regmap_clear_bits(mfd
->regmap
,
953 TPS65910_SLEEP_SET_LDO_OFF
+ regoffs
, bit_pos
);
957 "Error in configuring SLEEP register\n");
964 static struct of_regulator_match tps65910_matches
[] = {
965 { .name
= "vrtc", .driver_data
= (void *) &tps65910_regs
[0] },
966 { .name
= "vio", .driver_data
= (void *) &tps65910_regs
[1] },
967 { .name
= "vdd1", .driver_data
= (void *) &tps65910_regs
[2] },
968 { .name
= "vdd2", .driver_data
= (void *) &tps65910_regs
[3] },
969 { .name
= "vdd3", .driver_data
= (void *) &tps65910_regs
[4] },
970 { .name
= "vdig1", .driver_data
= (void *) &tps65910_regs
[5] },
971 { .name
= "vdig2", .driver_data
= (void *) &tps65910_regs
[6] },
972 { .name
= "vpll", .driver_data
= (void *) &tps65910_regs
[7] },
973 { .name
= "vdac", .driver_data
= (void *) &tps65910_regs
[8] },
974 { .name
= "vaux1", .driver_data
= (void *) &tps65910_regs
[9] },
975 { .name
= "vaux2", .driver_data
= (void *) &tps65910_regs
[10] },
976 { .name
= "vaux33", .driver_data
= (void *) &tps65910_regs
[11] },
977 { .name
= "vmmc", .driver_data
= (void *) &tps65910_regs
[12] },
978 { .name
= "vbb", .driver_data
= (void *) &tps65910_regs
[13] },
981 static struct of_regulator_match tps65911_matches
[] = {
982 { .name
= "vrtc", .driver_data
= (void *) &tps65911_regs
[0] },
983 { .name
= "vio", .driver_data
= (void *) &tps65911_regs
[1] },
984 { .name
= "vdd1", .driver_data
= (void *) &tps65911_regs
[2] },
985 { .name
= "vdd2", .driver_data
= (void *) &tps65911_regs
[3] },
986 { .name
= "vddctrl", .driver_data
= (void *) &tps65911_regs
[4] },
987 { .name
= "ldo1", .driver_data
= (void *) &tps65911_regs
[5] },
988 { .name
= "ldo2", .driver_data
= (void *) &tps65911_regs
[6] },
989 { .name
= "ldo3", .driver_data
= (void *) &tps65911_regs
[7] },
990 { .name
= "ldo4", .driver_data
= (void *) &tps65911_regs
[8] },
991 { .name
= "ldo5", .driver_data
= (void *) &tps65911_regs
[9] },
992 { .name
= "ldo6", .driver_data
= (void *) &tps65911_regs
[10] },
993 { .name
= "ldo7", .driver_data
= (void *) &tps65911_regs
[11] },
994 { .name
= "ldo8", .driver_data
= (void *) &tps65911_regs
[12] },
997 static struct tps65910_board
*tps65910_parse_dt_reg_data(
998 struct platform_device
*pdev
,
999 struct of_regulator_match
**tps65910_reg_matches
)
1001 struct tps65910_board
*pmic_plat_data
;
1002 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1003 struct device_node
*np
, *regulators
;
1004 struct of_regulator_match
*matches
;
1006 int idx
= 0, ret
, count
;
1008 pmic_plat_data
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic_plat_data
),
1010 if (!pmic_plat_data
)
1013 np
= pdev
->dev
.parent
->of_node
;
1014 regulators
= of_get_child_by_name(np
, "regulators");
1016 dev_err(&pdev
->dev
, "regulator node not found\n");
1020 switch (tps65910_chip_id(tps65910
)) {
1022 count
= ARRAY_SIZE(tps65910_matches
);
1023 matches
= tps65910_matches
;
1026 count
= ARRAY_SIZE(tps65911_matches
);
1027 matches
= tps65911_matches
;
1030 of_node_put(regulators
);
1031 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1035 ret
= of_regulator_match(&pdev
->dev
, regulators
, matches
, count
);
1036 of_node_put(regulators
);
1038 dev_err(&pdev
->dev
, "Error parsing regulator init data: %d\n",
1043 *tps65910_reg_matches
= matches
;
1045 for (idx
= 0; idx
< count
; idx
++) {
1046 if (!matches
[idx
].of_node
)
1049 pmic_plat_data
->tps65910_pmic_init_data
[idx
] =
1050 matches
[idx
].init_data
;
1052 ret
= of_property_read_u32(matches
[idx
].of_node
,
1053 "ti,regulator-ext-sleep-control", &prop
);
1055 pmic_plat_data
->regulator_ext_sleep_control
[idx
] = prop
;
1059 return pmic_plat_data
;
1062 static inline struct tps65910_board
*tps65910_parse_dt_reg_data(
1063 struct platform_device
*pdev
,
1064 struct of_regulator_match
**tps65910_reg_matches
)
1066 *tps65910_reg_matches
= NULL
;
1071 static int tps65910_probe(struct platform_device
*pdev
)
1073 struct tps65910
*tps65910
= dev_get_drvdata(pdev
->dev
.parent
);
1074 struct regulator_config config
= { };
1075 struct tps_info
*info
;
1076 struct regulator_dev
*rdev
;
1077 struct tps65910_reg
*pmic
;
1078 struct tps65910_board
*pmic_plat_data
;
1079 struct of_regulator_match
*tps65910_reg_matches
= NULL
;
1082 pmic_plat_data
= dev_get_platdata(tps65910
->dev
);
1083 if (!pmic_plat_data
&& tps65910
->dev
->of_node
)
1084 pmic_plat_data
= tps65910_parse_dt_reg_data(pdev
,
1085 &tps65910_reg_matches
);
1087 if (!pmic_plat_data
) {
1088 dev_err(&pdev
->dev
, "Platform data not found\n");
1092 pmic
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic
), GFP_KERNEL
);
1096 pmic
->mfd
= tps65910
;
1097 platform_set_drvdata(pdev
, pmic
);
1099 /* Give control of all register to control port */
1100 err
= regmap_set_bits(pmic
->mfd
->regmap
, TPS65910_DEVCTRL
,
1101 DEVCTRL_SR_CTL_I2C_SEL_MASK
);
1105 switch (tps65910_chip_id(tps65910
)) {
1107 BUILD_BUG_ON(TPS65910_NUM_REGS
< ARRAY_SIZE(tps65910_regs
));
1108 pmic
->get_ctrl_reg
= &tps65910_get_ctrl_register
;
1109 pmic
->num_regulators
= ARRAY_SIZE(tps65910_regs
);
1110 pmic
->ext_sleep_control
= tps65910_ext_sleep_control
;
1111 info
= tps65910_regs
;
1112 /* Work around silicon erratum SWCZ010: output programmed
1113 * voltage level can go higher than expected or crash
1114 * Workaround: use no synchronization of DCDC clocks
1116 regmap_clear_bits(pmic
->mfd
->regmap
, TPS65910_DCDCCTRL
,
1117 DCDCCTRL_DCDCCKSYNC_MASK
);
1120 BUILD_BUG_ON(TPS65910_NUM_REGS
< ARRAY_SIZE(tps65911_regs
));
1121 pmic
->get_ctrl_reg
= &tps65911_get_ctrl_register
;
1122 pmic
->num_regulators
= ARRAY_SIZE(tps65911_regs
);
1123 pmic
->ext_sleep_control
= tps65911_ext_sleep_control
;
1124 info
= tps65911_regs
;
1127 dev_err(&pdev
->dev
, "Invalid tps chip version\n");
1131 pmic
->desc
= devm_kcalloc(&pdev
->dev
,
1132 pmic
->num_regulators
,
1133 sizeof(struct regulator_desc
),
1138 pmic
->info
= devm_kcalloc(&pdev
->dev
,
1139 pmic
->num_regulators
,
1140 sizeof(struct tps_info
*),
1145 pmic
->rdev
= devm_kcalloc(&pdev
->dev
,
1146 pmic
->num_regulators
,
1147 sizeof(struct regulator_dev
*),
1152 for (i
= 0; i
< pmic
->num_regulators
; i
++, info
++) {
1153 /* Register the regulators */
1154 pmic
->info
[i
] = info
;
1156 pmic
->desc
[i
].name
= info
->name
;
1157 pmic
->desc
[i
].supply_name
= info
->vin_name
;
1158 pmic
->desc
[i
].id
= i
;
1159 pmic
->desc
[i
].n_voltages
= info
->n_voltages
;
1160 pmic
->desc
[i
].enable_time
= info
->enable_time_us
;
1162 if (i
== TPS65910_REG_VDD1
|| i
== TPS65910_REG_VDD2
) {
1163 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1164 pmic
->desc
[i
].n_voltages
= VDD1_2_NUM_VOLT_FINE
*
1165 VDD1_2_NUM_VOLT_COARSE
;
1166 pmic
->desc
[i
].ramp_delay
= 12500;
1167 } else if (i
== TPS65910_REG_VDD3
) {
1168 if (tps65910_chip_id(tps65910
) == TPS65910
) {
1169 pmic
->desc
[i
].ops
= &tps65910_ops_vdd3
;
1170 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1172 pmic
->desc
[i
].ops
= &tps65910_ops_dcdc
;
1173 pmic
->desc
[i
].ramp_delay
= 5000;
1175 } else if (i
== TPS65910_REG_VBB
&&
1176 tps65910_chip_id(tps65910
) == TPS65910
) {
1177 pmic
->desc
[i
].ops
= &tps65910_ops_vbb
;
1178 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1180 if (tps65910_chip_id(tps65910
) == TPS65910
) {
1181 pmic
->desc
[i
].ops
= &tps65910_ops
;
1182 pmic
->desc
[i
].volt_table
= info
->voltage_table
;
1184 pmic
->desc
[i
].ops
= &tps65911_ops
;
1188 err
= tps65910_set_ext_sleep_config(pmic
, i
,
1189 pmic_plat_data
->regulator_ext_sleep_control
[i
]);
1191 * Failing on regulator for configuring externally control
1192 * is not a serious issue, just throw warning.
1195 dev_warn(tps65910
->dev
,
1196 "Failed to initialise ext control config\n");
1198 pmic
->desc
[i
].type
= REGULATOR_VOLTAGE
;
1199 pmic
->desc
[i
].owner
= THIS_MODULE
;
1200 pmic
->desc
[i
].enable_reg
= pmic
->get_ctrl_reg(i
);
1201 pmic
->desc
[i
].enable_mask
= TPS65910_SUPPLY_STATE_ENABLED
;
1203 config
.dev
= tps65910
->dev
;
1204 config
.init_data
= pmic_plat_data
->tps65910_pmic_init_data
[i
];
1205 config
.driver_data
= pmic
;
1206 config
.regmap
= tps65910
->regmap
;
1208 if (tps65910_reg_matches
)
1209 config
.of_node
= tps65910_reg_matches
[i
].of_node
;
1211 rdev
= devm_regulator_register(&pdev
->dev
, &pmic
->desc
[i
],
1214 return dev_err_probe(tps65910
->dev
, PTR_ERR(rdev
),
1215 "failed to register %s regulator\n",
1218 /* Save regulator for cleanup */
1219 pmic
->rdev
[i
] = rdev
;
1224 static void tps65910_shutdown(struct platform_device
*pdev
)
1226 struct tps65910_reg
*pmic
= platform_get_drvdata(pdev
);
1230 * Before bootloader jumps to kernel, it makes sure that required
1231 * external control signals are in desired state so that given rails
1232 * can be configure accordingly.
1233 * If rails are configured to be controlled from external control
1234 * then before shutting down/rebooting the system, the external
1235 * control configuration need to be remove from the rails so that
1236 * its output will be available as per register programming even
1237 * if external controls are removed. This is require when the POR
1238 * value of the control signals are not in active state and before
1239 * bootloader initializes it, the system requires the rail output
1240 * to be active for booting.
1242 for (i
= 0; i
< pmic
->num_regulators
; i
++) {
1247 err
= tps65910_set_ext_sleep_config(pmic
, i
, 0);
1250 "Error in clearing external control\n");
1254 static struct platform_driver tps65910_driver
= {
1256 .name
= "tps65910-pmic",
1257 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
1259 .probe
= tps65910_probe
,
1260 .shutdown
= tps65910_shutdown
,
1263 static int __init
tps65910_init(void)
1265 return platform_driver_register(&tps65910_driver
);
1267 subsys_initcall(tps65910_init
);
1269 static void __exit
tps65910_cleanup(void)
1271 platform_driver_unregister(&tps65910_driver
);
1273 module_exit(tps65910_cleanup
);
1275 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1276 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1277 MODULE_LICENSE("GPL v2");
1278 MODULE_ALIAS("platform:tps65910-pmic");