2 * twl-regulator.c -- support regulators in twl4030/twl6030 family chips
4 * Copyright (C) 2008 David Brownell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/slab.h>
15 #include <linux/init.h>
16 #include <linux/err.h>
17 #include <linux/platform_device.h>
19 #include <linux/of_device.h>
20 #include <linux/regulator/driver.h>
21 #include <linux/regulator/machine.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/i2c/twl.h>
24 #include <linux/delay.h>
27 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
28 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
29 * include an audio codec, battery charger, and more voltage regulators.
30 * These chips are often used in OMAP-based systems.
32 * This driver implements software-based resource control for various
33 * voltage regulators. This is usually augmented with state machine
38 /* start of regulator's PM_RECEIVER control register bank */
41 /* twl resource ID, for resource control state machine */
44 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
48 /* State REMAP default configuration */
51 /* chip constraints on regulator behavior */
57 /* used by regulator core */
58 struct regulator_desc desc
;
60 /* chip specific features */
61 unsigned long features
;
64 * optional override functions for voltage set/get
65 * these are currently only used for SMPS regulators
67 int (*get_voltage
)(void *data
);
68 int (*set_voltage
)(void *data
, int target_uV
);
70 /* data passed from board for external get/set voltage */
75 /* LDO control registers ... offset is from the base of its register bank.
76 * The first three registers of all power resource banks help hardware to
77 * manage the various resource groups.
79 /* Common offset in TWL4030/6030 */
81 /* TWL4030 register offsets */
84 #define VREG_DEDICATED 3 /* LDO control */
85 #define VREG_VOLTAGE_SMPS_4030 9
86 /* TWL6030 register offsets */
89 #define VREG_VOLTAGE 3
90 #define VREG_VOLTAGE_SMPS 4
91 /* TWL6030 Misc register offsets */
94 #define VREG_BC_PROC 3
95 #define VREG_BC_CLK_RST 4
97 /* TWL6030 LDO register values for CFG_STATE */
98 #define TWL6030_CFG_STATE_OFF 0x00
99 #define TWL6030_CFG_STATE_ON 0x01
100 #define TWL6030_CFG_STATE_OFF2 0x02
101 #define TWL6030_CFG_STATE_SLEEP 0x03
102 #define TWL6030_CFG_STATE_GRP_SHIFT 5
103 #define TWL6030_CFG_STATE_APP_SHIFT 2
104 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
105 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
106 TWL6030_CFG_STATE_APP_SHIFT)
108 /* Flags for SMPS Voltage reading */
109 #define SMPS_OFFSET_EN BIT(0)
110 #define SMPS_EXTENDED_EN BIT(1)
112 /* twl6032 SMPS EPROM values */
113 #define TWL6030_SMPS_OFFSET 0xB0
114 #define TWL6030_SMPS_MULT 0xB3
115 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
116 #define SMPS_MULTOFFSET_VIO BIT(1)
117 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
120 twlreg_read(struct twlreg_info
*info
, unsigned slave_subgp
, unsigned offset
)
125 status
= twl_i2c_read_u8(slave_subgp
,
126 &value
, info
->base
+ offset
);
127 return (status
< 0) ? status
: value
;
131 twlreg_write(struct twlreg_info
*info
, unsigned slave_subgp
, unsigned offset
,
134 return twl_i2c_write_u8(slave_subgp
,
135 value
, info
->base
+ offset
);
138 /*----------------------------------------------------------------------*/
140 /* generic power resource operations, which work on all regulators */
142 static int twlreg_grp(struct regulator_dev
*rdev
)
144 return twlreg_read(rdev_get_drvdata(rdev
), TWL_MODULE_PM_RECEIVER
,
149 * Enable/disable regulators by joining/leaving the P1 (processor) group.
150 * We assume nobody else is updating the DEV_GRP registers.
152 /* definition for 4030 family */
153 #define P3_GRP_4030 BIT(7) /* "peripherals" */
154 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
155 #define P1_GRP_4030 BIT(5) /* CPU/Linux */
156 /* definition for 6030 family */
157 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
158 #define P2_GRP_6030 BIT(1) /* "peripherals" */
159 #define P1_GRP_6030 BIT(0) /* CPU/Linux */
161 static int twl4030reg_is_enabled(struct regulator_dev
*rdev
)
163 int state
= twlreg_grp(rdev
);
168 return state
& P1_GRP_4030
;
171 static int twl6030reg_is_enabled(struct regulator_dev
*rdev
)
173 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
176 if (!(twl_class_is_6030() && (info
->features
& TWL6032_SUBCLASS
))) {
177 grp
= twlreg_grp(rdev
);
185 val
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
);
186 val
= TWL6030_CFG_STATE_APP(val
);
188 return grp
&& (val
== TWL6030_CFG_STATE_ON
);
191 #define PB_I2C_BUSY BIT(0)
192 #define PB_I2C_BWEN BIT(1)
194 /* Wait until buffer empty/ready to send a word on power bus. */
195 static int twl4030_wait_pb_ready(void)
203 ret
= twl_i2c_read_u8(TWL_MODULE_PM_MASTER
, &val
,
204 TWL4030_PM_MASTER_PB_CFG
);
208 if (!(val
& PB_I2C_BUSY
))
218 /* Send a word over the powerbus */
219 static int twl4030_send_pb_msg(unsigned msg
)
224 /* save powerbus configuration */
225 ret
= twl_i2c_read_u8(TWL_MODULE_PM_MASTER
, &val
,
226 TWL4030_PM_MASTER_PB_CFG
);
230 /* Enable i2c access to powerbus */
231 ret
= twl_i2c_write_u8(TWL_MODULE_PM_MASTER
, val
| PB_I2C_BWEN
,
232 TWL4030_PM_MASTER_PB_CFG
);
236 ret
= twl4030_wait_pb_ready();
240 ret
= twl_i2c_write_u8(TWL_MODULE_PM_MASTER
, msg
>> 8,
241 TWL4030_PM_MASTER_PB_WORD_MSB
);
245 ret
= twl_i2c_write_u8(TWL_MODULE_PM_MASTER
, msg
& 0xff,
246 TWL4030_PM_MASTER_PB_WORD_LSB
);
250 ret
= twl4030_wait_pb_ready();
254 /* Restore powerbus configuration */
255 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER
, val
,
256 TWL4030_PM_MASTER_PB_CFG
);
259 static int twl4030reg_enable(struct regulator_dev
*rdev
)
261 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
265 grp
= twlreg_grp(rdev
);
271 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_GRP
, grp
);
276 static int twl6030reg_enable(struct regulator_dev
*rdev
)
278 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
282 if (!(twl_class_is_6030() && (info
->features
& TWL6032_SUBCLASS
)))
283 grp
= twlreg_grp(rdev
);
287 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
,
288 grp
<< TWL6030_CFG_STATE_GRP_SHIFT
|
289 TWL6030_CFG_STATE_ON
);
293 static int twl4030reg_disable(struct regulator_dev
*rdev
)
295 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
299 grp
= twlreg_grp(rdev
);
303 grp
&= ~(P1_GRP_4030
| P2_GRP_4030
| P3_GRP_4030
);
305 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_GRP
, grp
);
310 static int twl6030reg_disable(struct regulator_dev
*rdev
)
312 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
316 if (!(twl_class_is_6030() && (info
->features
& TWL6032_SUBCLASS
)))
317 grp
= P1_GRP_6030
| P2_GRP_6030
| P3_GRP_6030
;
319 /* For 6030, set the off state for all grps enabled */
320 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
,
321 (grp
) << TWL6030_CFG_STATE_GRP_SHIFT
|
322 TWL6030_CFG_STATE_OFF
);
327 static int twl4030reg_get_status(struct regulator_dev
*rdev
)
329 int state
= twlreg_grp(rdev
);
335 /* assume state != WARM_RESET; we'd not be running... */
337 return REGULATOR_STATUS_OFF
;
338 return (state
& BIT(3))
339 ? REGULATOR_STATUS_NORMAL
340 : REGULATOR_STATUS_STANDBY
;
343 static int twl6030reg_get_status(struct regulator_dev
*rdev
)
345 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
348 val
= twlreg_grp(rdev
);
352 val
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
);
354 switch (TWL6030_CFG_STATE_APP(val
)) {
355 case TWL6030_CFG_STATE_ON
:
356 return REGULATOR_STATUS_NORMAL
;
358 case TWL6030_CFG_STATE_SLEEP
:
359 return REGULATOR_STATUS_STANDBY
;
361 case TWL6030_CFG_STATE_OFF
:
362 case TWL6030_CFG_STATE_OFF2
:
367 return REGULATOR_STATUS_OFF
;
370 static int twl4030reg_set_mode(struct regulator_dev
*rdev
, unsigned mode
)
372 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
375 /* We can only set the mode through state machine commands... */
377 case REGULATOR_MODE_NORMAL
:
378 message
= MSG_SINGULAR(DEV_GRP_P1
, info
->id
, RES_STATE_ACTIVE
);
380 case REGULATOR_MODE_STANDBY
:
381 message
= MSG_SINGULAR(DEV_GRP_P1
, info
->id
, RES_STATE_SLEEP
);
387 return twl4030_send_pb_msg(message
);
390 static inline unsigned int twl4030reg_map_mode(unsigned int mode
)
393 case RES_STATE_ACTIVE
:
394 return REGULATOR_MODE_NORMAL
;
395 case RES_STATE_SLEEP
:
396 return REGULATOR_MODE_STANDBY
;
402 static int twl6030reg_set_mode(struct regulator_dev
*rdev
, unsigned mode
)
404 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
408 if (!(twl_class_is_6030() && (info
->features
& TWL6032_SUBCLASS
)))
409 grp
= twlreg_grp(rdev
);
414 /* Compose the state register settings */
415 val
= grp
<< TWL6030_CFG_STATE_GRP_SHIFT
;
416 /* We can only set the mode through state machine commands... */
418 case REGULATOR_MODE_NORMAL
:
419 val
|= TWL6030_CFG_STATE_ON
;
421 case REGULATOR_MODE_STANDBY
:
422 val
|= TWL6030_CFG_STATE_SLEEP
;
429 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
, val
);
432 /*----------------------------------------------------------------------*/
435 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
436 * select field in its control register. We use tables indexed by VSEL
437 * to record voltages in milliVolts. (Accuracy is about three percent.)
439 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
440 * currently handled by listing two slightly different VAUX2 regulators,
441 * only one of which will be configured.
443 * VSEL values documented as "TI cannot support these values" are flagged
444 * in these tables as UNSUP() values; we normally won't assign them.
446 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
447 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
449 #define UNSUP_MASK 0x8000
451 #define UNSUP(x) (UNSUP_MASK | (x))
452 #define IS_UNSUP(info, x) \
453 ((UNSUP_MASK & (x)) && \
454 !((info)->features & TWL4030_ALLOW_UNSUPPORTED))
455 #define LDO_MV(x) (~UNSUP_MASK & (x))
458 static const u16 VAUX1_VSEL_table
[] = {
459 UNSUP(1500), UNSUP(1800), 2500, 2800,
460 3000, 3000, 3000, 3000,
462 static const u16 VAUX2_4030_VSEL_table
[] = {
463 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
464 1500, 1800, UNSUP(1850), 2500,
465 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
466 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
468 static const u16 VAUX2_VSEL_table
[] = {
469 1700, 1700, 1900, 1300,
470 1500, 1800, 2000, 2500,
471 2100, 2800, 2200, 2300,
472 2400, 2400, 2400, 2400,
474 static const u16 VAUX3_VSEL_table
[] = {
475 1500, 1800, 2500, 2800,
476 3000, 3000, 3000, 3000,
478 static const u16 VAUX4_VSEL_table
[] = {
479 700, 1000, 1200, UNSUP(1300),
480 1500, 1800, UNSUP(1850), 2500,
481 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
482 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
484 static const u16 VMMC1_VSEL_table
[] = {
485 1850, 2850, 3000, 3150,
487 static const u16 VMMC2_VSEL_table
[] = {
488 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
489 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
490 2600, 2800, 2850, 3000,
491 3150, 3150, 3150, 3150,
493 static const u16 VPLL1_VSEL_table
[] = {
494 1000, 1200, 1300, 1800,
495 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
497 static const u16 VPLL2_VSEL_table
[] = {
498 700, 1000, 1200, 1300,
499 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
500 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
501 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
503 static const u16 VSIM_VSEL_table
[] = {
504 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
505 2800, 3000, 3000, 3000,
507 static const u16 VDAC_VSEL_table
[] = {
508 1200, 1300, 1800, 1800,
510 static const u16 VIO_VSEL_table
[] = {
513 static const u16 VINTANA2_VSEL_table
[] = {
517 static int twl4030ldo_list_voltage(struct regulator_dev
*rdev
, unsigned index
)
519 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
520 int mV
= info
->table
[index
];
522 return IS_UNSUP(info
, mV
) ? 0 : (LDO_MV(mV
) * 1000);
526 twl4030ldo_set_voltage_sel(struct regulator_dev
*rdev
, unsigned selector
)
528 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
530 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE
,
534 static int twl4030ldo_get_voltage_sel(struct regulator_dev
*rdev
)
536 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
537 int vsel
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE
);
542 vsel
&= info
->table_len
- 1;
546 static struct regulator_ops twl4030ldo_ops
= {
547 .list_voltage
= twl4030ldo_list_voltage
,
549 .set_voltage_sel
= twl4030ldo_set_voltage_sel
,
550 .get_voltage_sel
= twl4030ldo_get_voltage_sel
,
552 .enable
= twl4030reg_enable
,
553 .disable
= twl4030reg_disable
,
554 .is_enabled
= twl4030reg_is_enabled
,
556 .set_mode
= twl4030reg_set_mode
,
558 .get_status
= twl4030reg_get_status
,
562 twl4030smps_set_voltage(struct regulator_dev
*rdev
, int min_uV
, int max_uV
,
565 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
566 int vsel
= DIV_ROUND_UP(min_uV
- 600000, 12500);
568 if (info
->set_voltage
) {
569 return info
->set_voltage(info
->data
, min_uV
);
571 twlreg_write(info
, TWL_MODULE_PM_RECEIVER
,
572 VREG_VOLTAGE_SMPS_4030
, vsel
);
578 static int twl4030smps_get_voltage(struct regulator_dev
*rdev
)
580 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
583 if (info
->get_voltage
)
584 return info
->get_voltage(info
->data
);
586 vsel
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
,
587 VREG_VOLTAGE_SMPS_4030
);
589 return vsel
* 12500 + 600000;
592 static struct regulator_ops twl4030smps_ops
= {
593 .set_voltage
= twl4030smps_set_voltage
,
594 .get_voltage
= twl4030smps_get_voltage
,
597 static int twl6030coresmps_set_voltage(struct regulator_dev
*rdev
, int min_uV
,
598 int max_uV
, unsigned *selector
)
600 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
602 if (info
->set_voltage
)
603 return info
->set_voltage(info
->data
, min_uV
);
608 static int twl6030coresmps_get_voltage(struct regulator_dev
*rdev
)
610 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
612 if (info
->get_voltage
)
613 return info
->get_voltage(info
->data
);
618 static struct regulator_ops twl6030coresmps_ops
= {
619 .set_voltage
= twl6030coresmps_set_voltage
,
620 .get_voltage
= twl6030coresmps_get_voltage
,
623 static int twl6030ldo_list_voltage(struct regulator_dev
*rdev
, unsigned sel
)
625 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
631 /* Linear mapping from 00000001 to 00011000:
632 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001)
634 return (info
->min_mV
+ 100 * (sel
- 1)) * 1000;
645 twl6030ldo_set_voltage_sel(struct regulator_dev
*rdev
, unsigned selector
)
647 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
649 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE
,
653 static int twl6030ldo_get_voltage_sel(struct regulator_dev
*rdev
)
655 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
656 int vsel
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE
);
661 static struct regulator_ops twl6030ldo_ops
= {
662 .list_voltage
= twl6030ldo_list_voltage
,
664 .set_voltage_sel
= twl6030ldo_set_voltage_sel
,
665 .get_voltage_sel
= twl6030ldo_get_voltage_sel
,
667 .enable
= twl6030reg_enable
,
668 .disable
= twl6030reg_disable
,
669 .is_enabled
= twl6030reg_is_enabled
,
671 .set_mode
= twl6030reg_set_mode
,
673 .get_status
= twl6030reg_get_status
,
676 /*----------------------------------------------------------------------*/
678 static struct regulator_ops twl4030fixed_ops
= {
679 .list_voltage
= regulator_list_voltage_linear
,
681 .enable
= twl4030reg_enable
,
682 .disable
= twl4030reg_disable
,
683 .is_enabled
= twl4030reg_is_enabled
,
685 .set_mode
= twl4030reg_set_mode
,
687 .get_status
= twl4030reg_get_status
,
690 static struct regulator_ops twl6030fixed_ops
= {
691 .list_voltage
= regulator_list_voltage_linear
,
693 .enable
= twl6030reg_enable
,
694 .disable
= twl6030reg_disable
,
695 .is_enabled
= twl6030reg_is_enabled
,
697 .set_mode
= twl6030reg_set_mode
,
699 .get_status
= twl6030reg_get_status
,
703 * SMPS status and control
706 static int twl6030smps_list_voltage(struct regulator_dev
*rdev
, unsigned index
)
708 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
712 switch (info
->flags
) {
722 voltage
= 1350 * 1000;
725 voltage
= 1500 * 1000;
728 voltage
= 1800 * 1000;
731 voltage
= 1900 * 1000;
734 voltage
= 2100 * 1000;
737 voltage
+= (600000 + (12500 * (index
- 1)));
740 case SMPS_EXTENDED_EN
:
746 voltage
= 2084 * 1000;
749 voltage
= 2315 * 1000;
752 voltage
= 2778 * 1000;
755 voltage
= 2932 * 1000;
758 voltage
= 3241 * 1000;
761 voltage
= (1852000 + (38600 * (index
- 1)));
764 case SMPS_OFFSET_EN
| SMPS_EXTENDED_EN
:
770 voltage
= 4167 * 1000;
773 voltage
= 2315 * 1000;
776 voltage
= 2778 * 1000;
779 voltage
= 2932 * 1000;
782 voltage
= 3241 * 1000;
785 voltage
= (2161000 + (38600 * (index
- 1)));
793 static int twl6030smps_map_voltage(struct regulator_dev
*rdev
, int min_uV
,
796 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
799 switch (info
->flags
) {
803 else if ((min_uV
>= 600000) && (min_uV
<= 1300000)) {
804 vsel
= DIV_ROUND_UP(min_uV
- 600000, 12500);
807 /* Values 1..57 for vsel are linear and can be calculated
808 * values 58..62 are non linear.
810 else if ((min_uV
> 1900000) && (min_uV
<= 2100000))
812 else if ((min_uV
> 1800000) && (min_uV
<= 1900000))
814 else if ((min_uV
> 1500000) && (min_uV
<= 1800000))
816 else if ((min_uV
> 1350000) && (min_uV
<= 1500000))
818 else if ((min_uV
> 1300000) && (min_uV
<= 1350000))
826 else if ((min_uV
>= 700000) && (min_uV
<= 1420000)) {
827 vsel
= DIV_ROUND_UP(min_uV
- 700000, 12500);
830 /* Values 1..57 for vsel are linear and can be calculated
831 * values 58..62 are non linear.
833 else if ((min_uV
> 1900000) && (min_uV
<= 2100000))
835 else if ((min_uV
> 1800000) && (min_uV
<= 1900000))
837 else if ((min_uV
> 1350000) && (min_uV
<= 1800000))
839 else if ((min_uV
> 1350000) && (min_uV
<= 1500000))
841 else if ((min_uV
> 1300000) && (min_uV
<= 1350000))
846 case SMPS_EXTENDED_EN
:
849 } else if ((min_uV
>= 1852000) && (max_uV
<= 4013600)) {
850 vsel
= DIV_ROUND_UP(min_uV
- 1852000, 38600);
854 case SMPS_OFFSET_EN
|SMPS_EXTENDED_EN
:
857 } else if ((min_uV
>= 2161000) && (min_uV
<= 4321000)) {
858 vsel
= DIV_ROUND_UP(min_uV
- 2161000, 38600);
867 static int twl6030smps_set_voltage_sel(struct regulator_dev
*rdev
,
868 unsigned int selector
)
870 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
872 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE_SMPS
,
876 static int twl6030smps_get_voltage_sel(struct regulator_dev
*rdev
)
878 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
880 return twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE_SMPS
);
883 static struct regulator_ops twlsmps_ops
= {
884 .list_voltage
= twl6030smps_list_voltage
,
885 .map_voltage
= twl6030smps_map_voltage
,
887 .set_voltage_sel
= twl6030smps_set_voltage_sel
,
888 .get_voltage_sel
= twl6030smps_get_voltage_sel
,
890 .enable
= twl6030reg_enable
,
891 .disable
= twl6030reg_disable
,
892 .is_enabled
= twl6030reg_is_enabled
,
894 .set_mode
= twl6030reg_set_mode
,
896 .get_status
= twl6030reg_get_status
,
899 /*----------------------------------------------------------------------*/
901 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
903 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
904 remap_conf, TWL4030, twl4030fixed_ops, \
906 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
907 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
908 0x0, TWL6030, twl6030fixed_ops, NULL)
910 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
911 static const struct twlreg_info TWL4030_INFO_##label = { \
914 .table_len = ARRAY_SIZE(label##_VSEL_table), \
915 .table = label##_VSEL_table, \
916 .remap = remap_conf, \
919 .id = TWL4030_REG_##label, \
920 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
921 .ops = &twl4030ldo_ops, \
922 .type = REGULATOR_VOLTAGE, \
923 .owner = THIS_MODULE, \
924 .enable_time = turnon_delay, \
925 .of_map_mode = twl4030reg_map_mode, \
929 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
930 static const struct twlreg_info TWL4030_INFO_##label = { \
933 .remap = remap_conf, \
936 .id = TWL4030_REG_##label, \
937 .ops = &twl4030smps_ops, \
938 .type = REGULATOR_VOLTAGE, \
939 .owner = THIS_MODULE, \
940 .enable_time = turnon_delay, \
941 .of_map_mode = twl4030reg_map_mode, \
945 #define TWL6030_ADJUSTABLE_SMPS(label) \
946 static const struct twlreg_info TWL6030_INFO_##label = { \
949 .id = TWL6030_REG_##label, \
950 .ops = &twl6030coresmps_ops, \
951 .type = REGULATOR_VOLTAGE, \
952 .owner = THIS_MODULE, \
956 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
957 static const struct twlreg_info TWL6030_INFO_##label = { \
959 .min_mV = min_mVolts, \
960 .max_mV = max_mVolts, \
963 .id = TWL6030_REG_##label, \
965 .ops = &twl6030ldo_ops, \
966 .type = REGULATOR_VOLTAGE, \
967 .owner = THIS_MODULE, \
971 #define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
972 static const struct twlreg_info TWL6032_INFO_##label = { \
974 .min_mV = min_mVolts, \
975 .max_mV = max_mVolts, \
978 .id = TWL6032_REG_##label, \
980 .ops = &twl6030ldo_ops, \
981 .type = REGULATOR_VOLTAGE, \
982 .owner = THIS_MODULE, \
986 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
987 family, operations, map_mode) \
988 static const struct twlreg_info TWLFIXED_INFO_##label = { \
992 .remap = remap_conf, \
995 .id = family##_REG_##label, \
997 .ops = &operations, \
998 .type = REGULATOR_VOLTAGE, \
999 .owner = THIS_MODULE, \
1000 .min_uV = mVolts * 1000, \
1001 .enable_time = turnon_delay, \
1002 .of_map_mode = map_mode, \
1006 #define TWL6032_ADJUSTABLE_SMPS(label, offset) \
1007 static const struct twlreg_info TWLSMPS_INFO_##label = { \
1013 .id = TWL6032_REG_##label, \
1015 .ops = &twlsmps_ops, \
1016 .type = REGULATOR_VOLTAGE, \
1017 .owner = THIS_MODULE, \
1022 * We list regulators here if systems need some level of
1023 * software control over them after boot.
1025 TWL4030_ADJUSTABLE_LDO(VAUX1
, 0x17, 1, 100, 0x08);
1026 TWL4030_ADJUSTABLE_LDO(VAUX2_4030
, 0x1b, 2, 100, 0x08);
1027 TWL4030_ADJUSTABLE_LDO(VAUX2
, 0x1b, 2, 100, 0x08);
1028 TWL4030_ADJUSTABLE_LDO(VAUX3
, 0x1f, 3, 100, 0x08);
1029 TWL4030_ADJUSTABLE_LDO(VAUX4
, 0x23, 4, 100, 0x08);
1030 TWL4030_ADJUSTABLE_LDO(VMMC1
, 0x27, 5, 100, 0x08);
1031 TWL4030_ADJUSTABLE_LDO(VMMC2
, 0x2b, 6, 100, 0x08);
1032 TWL4030_ADJUSTABLE_LDO(VPLL1
, 0x2f, 7, 100, 0x00);
1033 TWL4030_ADJUSTABLE_LDO(VPLL2
, 0x33, 8, 100, 0x08);
1034 TWL4030_ADJUSTABLE_LDO(VSIM
, 0x37, 9, 100, 0x00);
1035 TWL4030_ADJUSTABLE_LDO(VDAC
, 0x3b, 10, 100, 0x08);
1036 TWL4030_ADJUSTABLE_LDO(VINTANA2
, 0x43, 12, 100, 0x08);
1037 TWL4030_ADJUSTABLE_LDO(VIO
, 0x4b, 14, 1000, 0x08);
1038 TWL4030_ADJUSTABLE_SMPS(VDD1
, 0x55, 15, 1000, 0x08);
1039 TWL4030_ADJUSTABLE_SMPS(VDD2
, 0x63, 16, 1000, 0x08);
1040 /* VUSBCP is managed *only* by the USB subchip */
1041 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1042 /* Turnon-delay and remap configuration values for 6030 are not
1043 verified since the specification is not public */
1044 TWL6030_ADJUSTABLE_SMPS(VDD1
);
1045 TWL6030_ADJUSTABLE_SMPS(VDD2
);
1046 TWL6030_ADJUSTABLE_SMPS(VDD3
);
1047 TWL6030_ADJUSTABLE_LDO(VAUX1_6030
, 0x54, 1000, 3300);
1048 TWL6030_ADJUSTABLE_LDO(VAUX2_6030
, 0x58, 1000, 3300);
1049 TWL6030_ADJUSTABLE_LDO(VAUX3_6030
, 0x5c, 1000, 3300);
1050 TWL6030_ADJUSTABLE_LDO(VMMC
, 0x68, 1000, 3300);
1051 TWL6030_ADJUSTABLE_LDO(VPP
, 0x6c, 1000, 3300);
1052 TWL6030_ADJUSTABLE_LDO(VUSIM
, 0x74, 1000, 3300);
1053 /* 6025 are renamed compared to 6030 versions */
1054 TWL6032_ADJUSTABLE_LDO(LDO2
, 0x54, 1000, 3300);
1055 TWL6032_ADJUSTABLE_LDO(LDO4
, 0x58, 1000, 3300);
1056 TWL6032_ADJUSTABLE_LDO(LDO3
, 0x5c, 1000, 3300);
1057 TWL6032_ADJUSTABLE_LDO(LDO5
, 0x68, 1000, 3300);
1058 TWL6032_ADJUSTABLE_LDO(LDO1
, 0x6c, 1000, 3300);
1059 TWL6032_ADJUSTABLE_LDO(LDO7
, 0x74, 1000, 3300);
1060 TWL6032_ADJUSTABLE_LDO(LDO6
, 0x60, 1000, 3300);
1061 TWL6032_ADJUSTABLE_LDO(LDOLN
, 0x64, 1000, 3300);
1062 TWL6032_ADJUSTABLE_LDO(LDOUSB
, 0x70, 1000, 3300);
1063 TWL4030_FIXED_LDO(VINTANA1
, 0x3f, 1500, 11, 100, 0x08);
1064 TWL4030_FIXED_LDO(VINTDIG
, 0x47, 1500, 13, 100, 0x08);
1065 TWL4030_FIXED_LDO(VUSB1V5
, 0x71, 1500, 17, 100, 0x08);
1066 TWL4030_FIXED_LDO(VUSB1V8
, 0x74, 1800, 18, 100, 0x08);
1067 TWL4030_FIXED_LDO(VUSB3V1
, 0x77, 3100, 19, 150, 0x08);
1068 TWL6030_FIXED_LDO(VANA
, 0x50, 2100, 0);
1069 TWL6030_FIXED_LDO(VCXIO
, 0x60, 1800, 0);
1070 TWL6030_FIXED_LDO(VDAC
, 0x64, 1800, 0);
1071 TWL6030_FIXED_LDO(VUSB
, 0x70, 3300, 0);
1072 TWL6030_FIXED_LDO(V1V8
, 0x16, 1800, 0);
1073 TWL6030_FIXED_LDO(V2V1
, 0x1c, 2100, 0);
1074 TWL6032_ADJUSTABLE_SMPS(SMPS3
, 0x34);
1075 TWL6032_ADJUSTABLE_SMPS(SMPS4
, 0x10);
1076 TWL6032_ADJUSTABLE_SMPS(VIO
, 0x16);
1078 static u8
twl_get_smps_offset(void)
1082 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER
, &value
,
1083 TWL6030_SMPS_OFFSET
);
1087 static u8
twl_get_smps_mult(void)
1091 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER
, &value
,
1096 #define TWL_OF_MATCH(comp, family, label) \
1098 .compatible = comp, \
1099 .data = &family##_INFO_##label, \
1102 #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
1103 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1104 #define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label)
1105 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
1106 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1108 static const struct of_device_id twl_of_match
[] = {
1109 TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1
),
1110 TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030
),
1111 TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2
),
1112 TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3
),
1113 TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4
),
1114 TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1
),
1115 TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2
),
1116 TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1
),
1117 TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2
),
1118 TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM
),
1119 TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC
),
1120 TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2
),
1121 TWL4030_OF_MATCH("ti,twl4030-vio", VIO
),
1122 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1
),
1123 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2
),
1124 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1
),
1125 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2
),
1126 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3
),
1127 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030
),
1128 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030
),
1129 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030
),
1130 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC
),
1131 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP
),
1132 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM
),
1133 TWL6032_OF_MATCH("ti,twl6032-ldo2", LDO2
),
1134 TWL6032_OF_MATCH("ti,twl6032-ldo4", LDO4
),
1135 TWL6032_OF_MATCH("ti,twl6032-ldo3", LDO3
),
1136 TWL6032_OF_MATCH("ti,twl6032-ldo5", LDO5
),
1137 TWL6032_OF_MATCH("ti,twl6032-ldo1", LDO1
),
1138 TWL6032_OF_MATCH("ti,twl6032-ldo7", LDO7
),
1139 TWL6032_OF_MATCH("ti,twl6032-ldo6", LDO6
),
1140 TWL6032_OF_MATCH("ti,twl6032-ldoln", LDOLN
),
1141 TWL6032_OF_MATCH("ti,twl6032-ldousb", LDOUSB
),
1142 TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1
),
1143 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG
),
1144 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5
),
1145 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8
),
1146 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1
),
1147 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA
),
1148 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO
),
1149 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC
),
1150 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB
),
1151 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8
),
1152 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1
),
1153 TWLSMPS_OF_MATCH("ti,twl6032-smps3", SMPS3
),
1154 TWLSMPS_OF_MATCH("ti,twl6032-smps4", SMPS4
),
1155 TWLSMPS_OF_MATCH("ti,twl6032-vio", VIO
),
1158 MODULE_DEVICE_TABLE(of
, twl_of_match
);
1160 static int twlreg_probe(struct platform_device
*pdev
)
1163 struct twlreg_info
*info
;
1164 const struct twlreg_info
*template;
1165 struct regulator_init_data
*initdata
;
1166 struct regulation_constraints
*c
;
1167 struct regulator_dev
*rdev
;
1168 struct twl_regulator_driver_data
*drvdata
;
1169 const struct of_device_id
*match
;
1170 struct regulator_config config
= { };
1172 match
= of_match_device(twl_of_match
, &pdev
->dev
);
1174 template = match
->data
;
1175 id
= template->desc
.id
;
1176 initdata
= of_get_regulator_init_data(&pdev
->dev
,
1182 initdata
= dev_get_platdata(&pdev
->dev
);
1183 for (i
= 0, template = NULL
; i
< ARRAY_SIZE(twl_of_match
); i
++) {
1184 template = twl_of_match
[i
].data
;
1185 if (template && template->desc
.id
== id
)
1188 if (i
== ARRAY_SIZE(twl_of_match
))
1191 drvdata
= initdata
->driver_data
;
1202 info
= devm_kmemdup(&pdev
->dev
, template, sizeof(*info
), GFP_KERNEL
);
1207 /* copy the driver data into regulator data */
1208 info
->features
= drvdata
->features
;
1209 info
->data
= drvdata
->data
;
1210 info
->set_voltage
= drvdata
->set_voltage
;
1211 info
->get_voltage
= drvdata
->get_voltage
;
1214 /* Constrain board-specific capabilities according to what
1215 * this driver and the chip itself can actually do.
1217 c
= &initdata
->constraints
;
1218 c
->valid_modes_mask
&= REGULATOR_MODE_NORMAL
| REGULATOR_MODE_STANDBY
;
1219 c
->valid_ops_mask
&= REGULATOR_CHANGE_VOLTAGE
1220 | REGULATOR_CHANGE_MODE
1221 | REGULATOR_CHANGE_STATUS
;
1223 case TWL4030_REG_VIO
:
1224 case TWL4030_REG_VDD1
:
1225 case TWL4030_REG_VDD2
:
1226 case TWL4030_REG_VPLL1
:
1227 case TWL4030_REG_VINTANA1
:
1228 case TWL4030_REG_VINTANA2
:
1229 case TWL4030_REG_VINTDIG
:
1230 c
->always_on
= true;
1237 case TWL6032_REG_SMPS3
:
1238 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3
)
1239 info
->flags
|= SMPS_EXTENDED_EN
;
1240 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3
)
1241 info
->flags
|= SMPS_OFFSET_EN
;
1243 case TWL6032_REG_SMPS4
:
1244 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4
)
1245 info
->flags
|= SMPS_EXTENDED_EN
;
1246 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4
)
1247 info
->flags
|= SMPS_OFFSET_EN
;
1249 case TWL6032_REG_VIO
:
1250 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO
)
1251 info
->flags
|= SMPS_EXTENDED_EN
;
1252 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO
)
1253 info
->flags
|= SMPS_OFFSET_EN
;
1257 config
.dev
= &pdev
->dev
;
1258 config
.init_data
= initdata
;
1259 config
.driver_data
= info
;
1260 config
.of_node
= pdev
->dev
.of_node
;
1262 rdev
= devm_regulator_register(&pdev
->dev
, &info
->desc
, &config
);
1264 dev_err(&pdev
->dev
, "can't register %s, %ld\n",
1265 info
->desc
.name
, PTR_ERR(rdev
));
1266 return PTR_ERR(rdev
);
1268 platform_set_drvdata(pdev
, rdev
);
1270 if (twl_class_is_4030())
1271 twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_REMAP
,
1274 /* NOTE: many regulators support short-circuit IRQs (presentable
1275 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1277 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1278 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1285 MODULE_ALIAS("platform:twl_reg");
1287 static struct platform_driver twlreg_driver
= {
1288 .probe
= twlreg_probe
,
1289 /* NOTE: short name, to work around driver model truncation of
1290 * "twl_regulator.12" (and friends) to "twl_regulator.1".
1294 .of_match_table
= of_match_ptr(twl_of_match
),
1298 static int __init
twlreg_init(void)
1300 return platform_driver_register(&twlreg_driver
);
1302 subsys_initcall(twlreg_init
);
1304 static void __exit
twlreg_exit(void)
1306 platform_driver_unregister(&twlreg_driver
);
1308 module_exit(twlreg_exit
)
1310 MODULE_DESCRIPTION("TWL regulator driver");
1311 MODULE_LICENSE("GPL");