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/init.h>
14 #include <linux/err.h>
15 #include <linux/platform_device.h>
17 #include <linux/of_device.h>
18 #include <linux/regulator/driver.h>
19 #include <linux/regulator/machine.h>
20 #include <linux/regulator/of_regulator.h>
21 #include <linux/i2c/twl.h>
25 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
26 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
27 * include an audio codec, battery charger, and more voltage regulators.
28 * These chips are often used in OMAP-based systems.
30 * This driver implements software-based resource control for various
31 * voltage regulators. This is usually augmented with state machine
36 /* start of regulator's PM_RECEIVER control register bank */
39 /* twl resource ID, for resource control state machine */
42 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
46 /* regulator specific turn-on delay */
49 /* State REMAP default configuration */
52 /* chip constraints on regulator behavior */
58 /* used by regulator core */
59 struct regulator_desc desc
;
61 /* chip specific features */
62 unsigned long features
;
65 * optional override functions for voltage set/get
66 * these are currently only used for SMPS regulators
68 int (*get_voltage
)(void *data
);
69 int (*set_voltage
)(void *data
, int target_uV
);
71 /* data passed from board for external get/set voltage */
76 /* LDO control registers ... offset is from the base of its register bank.
77 * The first three registers of all power resource banks help hardware to
78 * manage the various resource groups.
80 /* Common offset in TWL4030/6030 */
82 /* TWL4030 register offsets */
85 #define VREG_DEDICATED 3 /* LDO control */
86 #define VREG_VOLTAGE_SMPS_4030 9
87 /* TWL6030 register offsets */
90 #define VREG_VOLTAGE 3
91 #define VREG_VOLTAGE_SMPS 4
92 /* TWL6030 Misc register offsets */
95 #define VREG_BC_PROC 3
96 #define VREG_BC_CLK_RST 4
98 /* TWL6030 LDO register values for CFG_STATE */
99 #define TWL6030_CFG_STATE_OFF 0x00
100 #define TWL6030_CFG_STATE_ON 0x01
101 #define TWL6030_CFG_STATE_OFF2 0x02
102 #define TWL6030_CFG_STATE_SLEEP 0x03
103 #define TWL6030_CFG_STATE_GRP_SHIFT 5
104 #define TWL6030_CFG_STATE_APP_SHIFT 2
105 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
106 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
107 TWL6030_CFG_STATE_APP_SHIFT)
109 /* Flags for SMPS Voltage reading */
110 #define SMPS_OFFSET_EN BIT(0)
111 #define SMPS_EXTENDED_EN BIT(1)
113 /* twl6025 SMPS EPROM values */
114 #define TWL6030_SMPS_OFFSET 0xB0
115 #define TWL6030_SMPS_MULT 0xB3
116 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
117 #define SMPS_MULTOFFSET_VIO BIT(1)
118 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
121 twlreg_read(struct twlreg_info
*info
, unsigned slave_subgp
, unsigned offset
)
126 status
= twl_i2c_read_u8(slave_subgp
,
127 &value
, info
->base
+ offset
);
128 return (status
< 0) ? status
: value
;
132 twlreg_write(struct twlreg_info
*info
, unsigned slave_subgp
, unsigned offset
,
135 return twl_i2c_write_u8(slave_subgp
,
136 value
, info
->base
+ offset
);
139 /*----------------------------------------------------------------------*/
141 /* generic power resource operations, which work on all regulators */
143 static int twlreg_grp(struct regulator_dev
*rdev
)
145 return twlreg_read(rdev_get_drvdata(rdev
), TWL_MODULE_PM_RECEIVER
,
150 * Enable/disable regulators by joining/leaving the P1 (processor) group.
151 * We assume nobody else is updating the DEV_GRP registers.
153 /* definition for 4030 family */
154 #define P3_GRP_4030 BIT(7) /* "peripherals" */
155 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
156 #define P1_GRP_4030 BIT(5) /* CPU/Linux */
157 /* definition for 6030 family */
158 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
159 #define P2_GRP_6030 BIT(1) /* "peripherals" */
160 #define P1_GRP_6030 BIT(0) /* CPU/Linux */
162 static int twl4030reg_is_enabled(struct regulator_dev
*rdev
)
164 int state
= twlreg_grp(rdev
);
169 return state
& P1_GRP_4030
;
172 static int twl6030reg_is_enabled(struct regulator_dev
*rdev
)
174 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
177 if (!(twl_class_is_6030() && (info
->features
& TWL6025_SUBCLASS
))) {
178 grp
= twlreg_grp(rdev
);
186 val
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
);
187 val
= TWL6030_CFG_STATE_APP(val
);
189 return grp
&& (val
== TWL6030_CFG_STATE_ON
);
192 static int twl4030reg_enable(struct regulator_dev
*rdev
)
194 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
198 grp
= twlreg_grp(rdev
);
204 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_GRP
, grp
);
209 static int twl6030reg_enable(struct regulator_dev
*rdev
)
211 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
215 if (!(twl_class_is_6030() && (info
->features
& TWL6025_SUBCLASS
)))
216 grp
= twlreg_grp(rdev
);
220 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
,
221 grp
<< TWL6030_CFG_STATE_GRP_SHIFT
|
222 TWL6030_CFG_STATE_ON
);
226 static int twl4030reg_enable_time(struct regulator_dev
*rdev
)
228 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
233 static int twl6030reg_enable_time(struct regulator_dev
*rdev
)
235 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
240 static int twl4030reg_disable(struct regulator_dev
*rdev
)
242 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
246 grp
= twlreg_grp(rdev
);
250 grp
&= ~(P1_GRP_4030
| P2_GRP_4030
| P3_GRP_4030
);
252 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_GRP
, grp
);
257 static int twl6030reg_disable(struct regulator_dev
*rdev
)
259 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
263 if (!(twl_class_is_6030() && (info
->features
& TWL6025_SUBCLASS
)))
264 grp
= P1_GRP_6030
| P2_GRP_6030
| P3_GRP_6030
;
266 /* For 6030, set the off state for all grps enabled */
267 ret
= twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
,
268 (grp
) << TWL6030_CFG_STATE_GRP_SHIFT
|
269 TWL6030_CFG_STATE_OFF
);
274 static int twl4030reg_get_status(struct regulator_dev
*rdev
)
276 int state
= twlreg_grp(rdev
);
282 /* assume state != WARM_RESET; we'd not be running... */
284 return REGULATOR_STATUS_OFF
;
285 return (state
& BIT(3))
286 ? REGULATOR_STATUS_NORMAL
287 : REGULATOR_STATUS_STANDBY
;
290 static int twl6030reg_get_status(struct regulator_dev
*rdev
)
292 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
295 val
= twlreg_grp(rdev
);
299 val
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
);
301 switch (TWL6030_CFG_STATE_APP(val
)) {
302 case TWL6030_CFG_STATE_ON
:
303 return REGULATOR_STATUS_NORMAL
;
305 case TWL6030_CFG_STATE_SLEEP
:
306 return REGULATOR_STATUS_STANDBY
;
308 case TWL6030_CFG_STATE_OFF
:
309 case TWL6030_CFG_STATE_OFF2
:
314 return REGULATOR_STATUS_OFF
;
317 static int twl4030reg_set_mode(struct regulator_dev
*rdev
, unsigned mode
)
319 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
323 /* We can only set the mode through state machine commands... */
325 case REGULATOR_MODE_NORMAL
:
326 message
= MSG_SINGULAR(DEV_GRP_P1
, info
->id
, RES_STATE_ACTIVE
);
328 case REGULATOR_MODE_STANDBY
:
329 message
= MSG_SINGULAR(DEV_GRP_P1
, info
->id
, RES_STATE_SLEEP
);
335 /* Ensure the resource is associated with some group */
336 status
= twlreg_grp(rdev
);
339 if (!(status
& (P3_GRP_4030
| P2_GRP_4030
| P1_GRP_4030
)))
342 status
= twl_i2c_write_u8(TWL_MODULE_PM_MASTER
,
343 message
>> 8, TWL4030_PM_MASTER_PB_WORD_MSB
);
347 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER
,
348 message
& 0xff, TWL4030_PM_MASTER_PB_WORD_LSB
);
351 static int twl6030reg_set_mode(struct regulator_dev
*rdev
, unsigned mode
)
353 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
357 if (!(twl_class_is_6030() && (info
->features
& TWL6025_SUBCLASS
)))
358 grp
= twlreg_grp(rdev
);
363 /* Compose the state register settings */
364 val
= grp
<< TWL6030_CFG_STATE_GRP_SHIFT
;
365 /* We can only set the mode through state machine commands... */
367 case REGULATOR_MODE_NORMAL
:
368 val
|= TWL6030_CFG_STATE_ON
;
370 case REGULATOR_MODE_STANDBY
:
371 val
|= TWL6030_CFG_STATE_SLEEP
;
378 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_STATE
, val
);
381 /*----------------------------------------------------------------------*/
384 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
385 * select field in its control register. We use tables indexed by VSEL
386 * to record voltages in milliVolts. (Accuracy is about three percent.)
388 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
389 * currently handled by listing two slightly different VAUX2 regulators,
390 * only one of which will be configured.
392 * VSEL values documented as "TI cannot support these values" are flagged
393 * in these tables as UNSUP() values; we normally won't assign them.
395 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
396 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
398 #define UNSUP_MASK 0x8000
400 #define UNSUP(x) (UNSUP_MASK | (x))
401 #define IS_UNSUP(info, x) \
402 ((UNSUP_MASK & (x)) && \
403 !((info)->features & TWL4030_ALLOW_UNSUPPORTED))
404 #define LDO_MV(x) (~UNSUP_MASK & (x))
407 static const u16 VAUX1_VSEL_table
[] = {
408 UNSUP(1500), UNSUP(1800), 2500, 2800,
409 3000, 3000, 3000, 3000,
411 static const u16 VAUX2_4030_VSEL_table
[] = {
412 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
413 1500, 1800, UNSUP(1850), 2500,
414 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
415 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
417 static const u16 VAUX2_VSEL_table
[] = {
418 1700, 1700, 1900, 1300,
419 1500, 1800, 2000, 2500,
420 2100, 2800, 2200, 2300,
421 2400, 2400, 2400, 2400,
423 static const u16 VAUX3_VSEL_table
[] = {
424 1500, 1800, 2500, 2800,
425 3000, 3000, 3000, 3000,
427 static const u16 VAUX4_VSEL_table
[] = {
428 700, 1000, 1200, UNSUP(1300),
429 1500, 1800, UNSUP(1850), 2500,
430 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
431 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
433 static const u16 VMMC1_VSEL_table
[] = {
434 1850, 2850, 3000, 3150,
436 static const u16 VMMC2_VSEL_table
[] = {
437 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
438 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
439 2600, 2800, 2850, 3000,
440 3150, 3150, 3150, 3150,
442 static const u16 VPLL1_VSEL_table
[] = {
443 1000, 1200, 1300, 1800,
444 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
446 static const u16 VPLL2_VSEL_table
[] = {
447 700, 1000, 1200, 1300,
448 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
449 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
450 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
452 static const u16 VSIM_VSEL_table
[] = {
453 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
454 2800, 3000, 3000, 3000,
456 static const u16 VDAC_VSEL_table
[] = {
457 1200, 1300, 1800, 1800,
459 static const u16 VDD1_VSEL_table
[] = {
462 static const u16 VDD2_VSEL_table
[] = {
465 static const u16 VIO_VSEL_table
[] = {
468 static const u16 VINTANA2_VSEL_table
[] = {
472 static int twl4030ldo_list_voltage(struct regulator_dev
*rdev
, unsigned index
)
474 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
475 int mV
= info
->table
[index
];
477 return IS_UNSUP(info
, mV
) ? 0 : (LDO_MV(mV
) * 1000);
481 twl4030ldo_set_voltage_sel(struct regulator_dev
*rdev
, unsigned selector
)
483 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
485 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE
,
489 static int twl4030ldo_get_voltage(struct regulator_dev
*rdev
)
491 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
492 int vsel
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
,
498 vsel
&= info
->table_len
- 1;
499 return LDO_MV(info
->table
[vsel
]) * 1000;
502 static struct regulator_ops twl4030ldo_ops
= {
503 .list_voltage
= twl4030ldo_list_voltage
,
505 .set_voltage_sel
= twl4030ldo_set_voltage_sel
,
506 .get_voltage
= twl4030ldo_get_voltage
,
508 .enable
= twl4030reg_enable
,
509 .disable
= twl4030reg_disable
,
510 .is_enabled
= twl4030reg_is_enabled
,
511 .enable_time
= twl4030reg_enable_time
,
513 .set_mode
= twl4030reg_set_mode
,
515 .get_status
= twl4030reg_get_status
,
519 twl4030smps_set_voltage(struct regulator_dev
*rdev
, int min_uV
, int max_uV
,
522 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
523 int vsel
= DIV_ROUND_UP(min_uV
- 600000, 12500);
525 if (info
->set_voltage
) {
526 return info
->set_voltage(info
->data
, min_uV
);
528 twlreg_write(info
, TWL_MODULE_PM_RECEIVER
,
529 VREG_VOLTAGE_SMPS_4030
, vsel
);
535 static int twl4030smps_get_voltage(struct regulator_dev
*rdev
)
537 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
540 if (info
->get_voltage
)
541 return info
->get_voltage(info
->data
);
543 vsel
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
,
544 VREG_VOLTAGE_SMPS_4030
);
546 return vsel
* 12500 + 600000;
549 static struct regulator_ops twl4030smps_ops
= {
550 .set_voltage
= twl4030smps_set_voltage
,
551 .get_voltage
= twl4030smps_get_voltage
,
554 static int twl6030coresmps_set_voltage(struct regulator_dev
*rdev
, int min_uV
,
555 int max_uV
, unsigned *selector
)
557 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
559 if (info
->set_voltage
)
560 return info
->set_voltage(info
->data
, min_uV
);
565 static int twl6030coresmps_get_voltage(struct regulator_dev
*rdev
)
567 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
569 if (info
->get_voltage
)
570 return info
->get_voltage(info
->data
);
575 static struct regulator_ops twl6030coresmps_ops
= {
576 .set_voltage
= twl6030coresmps_set_voltage
,
577 .get_voltage
= twl6030coresmps_get_voltage
,
580 static int twl6030ldo_list_voltage(struct regulator_dev
*rdev
, unsigned index
)
582 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
584 return ((info
->min_mV
+ (index
* 100)) * 1000);
588 twl6030ldo_set_voltage(struct regulator_dev
*rdev
, int min_uV
, int max_uV
,
591 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
594 if ((min_uV
/1000 < info
->min_mV
) || (max_uV
/1000 > info
->max_mV
))
598 * Use the below formula to calculate vsel
599 * mV = 1000mv + 100mv * (vsel - 1)
601 vsel
= (min_uV
/1000 - 1000)/100 + 1;
603 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE
, vsel
);
607 static int twl6030ldo_get_voltage(struct regulator_dev
*rdev
)
609 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
610 int vsel
= twlreg_read(info
, TWL_MODULE_PM_RECEIVER
,
617 * Use the below formula to calculate vsel
618 * mV = 1000mv + 100mv * (vsel - 1)
620 return (1000 + (100 * (vsel
- 1))) * 1000;
623 static struct regulator_ops twl6030ldo_ops
= {
624 .list_voltage
= twl6030ldo_list_voltage
,
626 .set_voltage
= twl6030ldo_set_voltage
,
627 .get_voltage
= twl6030ldo_get_voltage
,
629 .enable
= twl6030reg_enable
,
630 .disable
= twl6030reg_disable
,
631 .is_enabled
= twl6030reg_is_enabled
,
632 .enable_time
= twl6030reg_enable_time
,
634 .set_mode
= twl6030reg_set_mode
,
636 .get_status
= twl6030reg_get_status
,
639 /*----------------------------------------------------------------------*/
642 * Fixed voltage LDOs don't have a VSEL field to update.
644 static int twlfixed_list_voltage(struct regulator_dev
*rdev
, unsigned index
)
646 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
648 return info
->min_mV
* 1000;
651 static int twlfixed_get_voltage(struct regulator_dev
*rdev
)
653 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
655 return info
->min_mV
* 1000;
658 static struct regulator_ops twl4030fixed_ops
= {
659 .list_voltage
= twlfixed_list_voltage
,
661 .get_voltage
= twlfixed_get_voltage
,
663 .enable
= twl4030reg_enable
,
664 .disable
= twl4030reg_disable
,
665 .is_enabled
= twl4030reg_is_enabled
,
666 .enable_time
= twl4030reg_enable_time
,
668 .set_mode
= twl4030reg_set_mode
,
670 .get_status
= twl4030reg_get_status
,
673 static struct regulator_ops twl6030fixed_ops
= {
674 .list_voltage
= twlfixed_list_voltage
,
676 .get_voltage
= twlfixed_get_voltage
,
678 .enable
= twl6030reg_enable
,
679 .disable
= twl6030reg_disable
,
680 .is_enabled
= twl6030reg_is_enabled
,
681 .enable_time
= twl6030reg_enable_time
,
683 .set_mode
= twl6030reg_set_mode
,
685 .get_status
= twl6030reg_get_status
,
688 static struct regulator_ops twl6030_fixed_resource
= {
689 .enable
= twl6030reg_enable
,
690 .disable
= twl6030reg_disable
,
691 .is_enabled
= twl6030reg_is_enabled
,
692 .enable_time
= twl6030reg_enable_time
,
693 .get_status
= twl6030reg_get_status
,
697 * SMPS status and control
700 static int twl6030smps_list_voltage(struct regulator_dev
*rdev
, unsigned index
)
702 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
706 switch (info
->flags
) {
716 voltage
= 1350 * 1000;
719 voltage
= 1500 * 1000;
722 voltage
= 1800 * 1000;
725 voltage
= 1900 * 1000;
728 voltage
= 2100 * 1000;
731 voltage
+= (600000 + (12500 * (index
- 1)));
734 case SMPS_EXTENDED_EN
:
740 voltage
= 2084 * 1000;
743 voltage
= 2315 * 1000;
746 voltage
= 2778 * 1000;
749 voltage
= 2932 * 1000;
752 voltage
= 3241 * 1000;
755 voltage
= (1852000 + (38600 * (index
- 1)));
758 case SMPS_OFFSET_EN
| SMPS_EXTENDED_EN
:
764 voltage
= 4167 * 1000;
767 voltage
= 2315 * 1000;
770 voltage
= 2778 * 1000;
773 voltage
= 2932 * 1000;
776 voltage
= 3241 * 1000;
779 voltage
= (2161000 + (38600 * (index
- 1)));
788 twl6030smps_set_voltage(struct regulator_dev
*rdev
, int min_uV
, int max_uV
,
789 unsigned int *selector
)
791 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
794 switch (info
->flags
) {
798 else if ((min_uV
>= 600000) && (min_uV
<= 1300000)) {
800 vsel
= DIV_ROUND_UP(min_uV
- 600000, 12500);
802 calc_uV
= twl6030smps_list_voltage(rdev
, vsel
);
803 if (calc_uV
> max_uV
)
806 /* Values 1..57 for vsel are linear and can be calculated
807 * values 58..62 are non linear.
809 else if ((min_uV
> 1900000) && (max_uV
>= 2100000))
811 else if ((min_uV
> 1800000) && (max_uV
>= 1900000))
813 else if ((min_uV
> 1500000) && (max_uV
>= 1800000))
815 else if ((min_uV
> 1350000) && (max_uV
>= 1500000))
817 else if ((min_uV
> 1300000) && (max_uV
>= 1350000))
825 else if ((min_uV
>= 700000) && (min_uV
<= 1420000)) {
827 vsel
= DIV_ROUND_UP(min_uV
- 700000, 12500);
829 calc_uV
= twl6030smps_list_voltage(rdev
, vsel
);
830 if (calc_uV
> max_uV
)
833 /* Values 1..57 for vsel are linear and can be calculated
834 * values 58..62 are non linear.
836 else if ((min_uV
> 1900000) && (max_uV
>= 2100000))
838 else if ((min_uV
> 1800000) && (max_uV
>= 1900000))
840 else if ((min_uV
> 1350000) && (max_uV
>= 1800000))
842 else if ((min_uV
> 1350000) && (max_uV
>= 1500000))
844 else if ((min_uV
> 1300000) && (max_uV
>= 1350000))
849 case SMPS_EXTENDED_EN
:
852 } else if ((min_uV
>= 1852000) && (max_uV
<= 4013600)) {
853 vsel
= DIV_ROUND_UP(min_uV
- 1852000, 38600);
857 case SMPS_OFFSET_EN
|SMPS_EXTENDED_EN
:
860 } else if ((min_uV
>= 2161000) && (max_uV
<= 4321000)) {
861 vsel
= DIV_ROUND_UP(min_uV
- 2161000, 38600);
869 return twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE_SMPS
,
873 static int twl6030smps_get_voltage_sel(struct regulator_dev
*rdev
)
875 struct twlreg_info
*info
= rdev_get_drvdata(rdev
);
877 return twlreg_read(info
, TWL_MODULE_PM_RECEIVER
, VREG_VOLTAGE_SMPS
);
880 static struct regulator_ops twlsmps_ops
= {
881 .list_voltage
= twl6030smps_list_voltage
,
883 .set_voltage
= twl6030smps_set_voltage
,
884 .get_voltage_sel
= twl6030smps_get_voltage_sel
,
886 .enable
= twl6030reg_enable
,
887 .disable
= twl6030reg_disable
,
888 .is_enabled
= twl6030reg_is_enabled
,
889 .enable_time
= twl6030reg_enable_time
,
891 .set_mode
= twl6030reg_set_mode
,
893 .get_status
= twl6030reg_get_status
,
896 /*----------------------------------------------------------------------*/
898 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
900 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
901 remap_conf, TWL4030, twl4030fixed_ops)
902 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
903 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
904 0x0, TWL6030, twl6030fixed_ops)
906 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
907 static struct twlreg_info TWL4030_INFO_##label = { \
910 .table_len = ARRAY_SIZE(label##_VSEL_table), \
911 .table = label##_VSEL_table, \
912 .delay = turnon_delay, \
913 .remap = remap_conf, \
916 .id = TWL4030_REG_##label, \
917 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
918 .ops = &twl4030ldo_ops, \
919 .type = REGULATOR_VOLTAGE, \
920 .owner = THIS_MODULE, \
924 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
925 static struct twlreg_info TWL4030_INFO_##label = { \
928 .delay = turnon_delay, \
929 .remap = remap_conf, \
932 .id = TWL4030_REG_##label, \
933 .ops = &twl4030smps_ops, \
934 .type = REGULATOR_VOLTAGE, \
935 .owner = THIS_MODULE, \
939 #define TWL6030_ADJUSTABLE_SMPS(label) \
940 static struct twlreg_info TWL6030_INFO_##label = { \
943 .id = TWL6030_REG_##label, \
944 .ops = &twl6030coresmps_ops, \
945 .type = REGULATOR_VOLTAGE, \
946 .owner = THIS_MODULE, \
950 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
951 static struct twlreg_info TWL6030_INFO_##label = { \
953 .min_mV = min_mVolts, \
954 .max_mV = max_mVolts, \
957 .id = TWL6030_REG_##label, \
958 .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \
959 .ops = &twl6030ldo_ops, \
960 .type = REGULATOR_VOLTAGE, \
961 .owner = THIS_MODULE, \
965 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
966 static struct twlreg_info TWL6025_INFO_##label = { \
968 .min_mV = min_mVolts, \
969 .max_mV = max_mVolts, \
972 .id = TWL6025_REG_##label, \
973 .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \
974 .ops = &twl6030ldo_ops, \
975 .type = REGULATOR_VOLTAGE, \
976 .owner = THIS_MODULE, \
980 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
981 family, operations) \
982 static struct twlreg_info TWLFIXED_INFO_##label = { \
986 .delay = turnon_delay, \
987 .remap = remap_conf, \
990 .id = family##_REG_##label, \
992 .ops = &operations, \
993 .type = REGULATOR_VOLTAGE, \
994 .owner = THIS_MODULE, \
998 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
999 static struct twlreg_info TWLRES_INFO_##label = { \
1001 .delay = turnon_delay, \
1004 .id = TWL6030_REG_##label, \
1005 .ops = &twl6030_fixed_resource, \
1006 .type = REGULATOR_VOLTAGE, \
1007 .owner = THIS_MODULE, \
1011 #define TWL6025_ADJUSTABLE_SMPS(label, offset) \
1012 static struct twlreg_info TWLSMPS_INFO_##label = { \
1018 .id = TWL6025_REG_##label, \
1020 .ops = &twlsmps_ops, \
1021 .type = REGULATOR_VOLTAGE, \
1022 .owner = THIS_MODULE, \
1027 * We list regulators here if systems need some level of
1028 * software control over them after boot.
1030 TWL4030_ADJUSTABLE_LDO(VAUX1
, 0x17, 1, 100, 0x08);
1031 TWL4030_ADJUSTABLE_LDO(VAUX2_4030
, 0x1b, 2, 100, 0x08);
1032 TWL4030_ADJUSTABLE_LDO(VAUX2
, 0x1b, 2, 100, 0x08);
1033 TWL4030_ADJUSTABLE_LDO(VAUX3
, 0x1f, 3, 100, 0x08);
1034 TWL4030_ADJUSTABLE_LDO(VAUX4
, 0x23, 4, 100, 0x08);
1035 TWL4030_ADJUSTABLE_LDO(VMMC1
, 0x27, 5, 100, 0x08);
1036 TWL4030_ADJUSTABLE_LDO(VMMC2
, 0x2b, 6, 100, 0x08);
1037 TWL4030_ADJUSTABLE_LDO(VPLL1
, 0x2f, 7, 100, 0x00);
1038 TWL4030_ADJUSTABLE_LDO(VPLL2
, 0x33, 8, 100, 0x08);
1039 TWL4030_ADJUSTABLE_LDO(VSIM
, 0x37, 9, 100, 0x00);
1040 TWL4030_ADJUSTABLE_LDO(VDAC
, 0x3b, 10, 100, 0x08);
1041 TWL4030_ADJUSTABLE_LDO(VINTANA2
, 0x43, 12, 100, 0x08);
1042 TWL4030_ADJUSTABLE_LDO(VIO
, 0x4b, 14, 1000, 0x08);
1043 TWL4030_ADJUSTABLE_SMPS(VDD1
, 0x55, 15, 1000, 0x08);
1044 TWL4030_ADJUSTABLE_SMPS(VDD2
, 0x63, 16, 1000, 0x08);
1045 /* VUSBCP is managed *only* by the USB subchip */
1046 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1047 /* Turnon-delay and remap configuration values for 6030 are not
1048 verified since the specification is not public */
1049 TWL6030_ADJUSTABLE_SMPS(VDD1
);
1050 TWL6030_ADJUSTABLE_SMPS(VDD2
);
1051 TWL6030_ADJUSTABLE_SMPS(VDD3
);
1052 TWL6030_ADJUSTABLE_LDO(VAUX1_6030
, 0x54, 1000, 3300);
1053 TWL6030_ADJUSTABLE_LDO(VAUX2_6030
, 0x58, 1000, 3300);
1054 TWL6030_ADJUSTABLE_LDO(VAUX3_6030
, 0x5c, 1000, 3300);
1055 TWL6030_ADJUSTABLE_LDO(VMMC
, 0x68, 1000, 3300);
1056 TWL6030_ADJUSTABLE_LDO(VPP
, 0x6c, 1000, 3300);
1057 TWL6030_ADJUSTABLE_LDO(VUSIM
, 0x74, 1000, 3300);
1058 /* 6025 are renamed compared to 6030 versions */
1059 TWL6025_ADJUSTABLE_LDO(LDO2
, 0x54, 1000, 3300);
1060 TWL6025_ADJUSTABLE_LDO(LDO4
, 0x58, 1000, 3300);
1061 TWL6025_ADJUSTABLE_LDO(LDO3
, 0x5c, 1000, 3300);
1062 TWL6025_ADJUSTABLE_LDO(LDO5
, 0x68, 1000, 3300);
1063 TWL6025_ADJUSTABLE_LDO(LDO1
, 0x6c, 1000, 3300);
1064 TWL6025_ADJUSTABLE_LDO(LDO7
, 0x74, 1000, 3300);
1065 TWL6025_ADJUSTABLE_LDO(LDO6
, 0x60, 1000, 3300);
1066 TWL6025_ADJUSTABLE_LDO(LDOLN
, 0x64, 1000, 3300);
1067 TWL6025_ADJUSTABLE_LDO(LDOUSB
, 0x70, 1000, 3300);
1068 TWL4030_FIXED_LDO(VINTANA2
, 0x3f, 1500, 11, 100, 0x08);
1069 TWL4030_FIXED_LDO(VINTDIG
, 0x47, 1500, 13, 100, 0x08);
1070 TWL4030_FIXED_LDO(VUSB1V5
, 0x71, 1500, 17, 100, 0x08);
1071 TWL4030_FIXED_LDO(VUSB1V8
, 0x74, 1800, 18, 100, 0x08);
1072 TWL4030_FIXED_LDO(VUSB3V1
, 0x77, 3100, 19, 150, 0x08);
1073 TWL6030_FIXED_LDO(VANA
, 0x50, 2100, 0);
1074 TWL6030_FIXED_LDO(VCXIO
, 0x60, 1800, 0);
1075 TWL6030_FIXED_LDO(VDAC
, 0x64, 1800, 0);
1076 TWL6030_FIXED_LDO(VUSB
, 0x70, 3300, 0);
1077 TWL6030_FIXED_LDO(V1V8
, 0x16, 1800, 0);
1078 TWL6030_FIXED_LDO(V2V1
, 0x1c, 2100, 0);
1079 TWL6030_FIXED_RESOURCE(CLK32KG
, 0x8C, 0);
1080 TWL6025_ADJUSTABLE_SMPS(SMPS3
, 0x34);
1081 TWL6025_ADJUSTABLE_SMPS(SMPS4
, 0x10);
1082 TWL6025_ADJUSTABLE_SMPS(VIO
, 0x16);
1084 static u8
twl_get_smps_offset(void)
1088 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER
, &value
,
1089 TWL6030_SMPS_OFFSET
);
1093 static u8
twl_get_smps_mult(void)
1097 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER
, &value
,
1102 #define TWL_OF_MATCH(comp, family, label) \
1104 .compatible = comp, \
1105 .data = &family##_INFO_##label, \
1108 #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
1109 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1110 #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
1111 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
1112 #define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label)
1113 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1115 static const struct of_device_id twl_of_match
[] __devinitconst
= {
1116 TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1
),
1117 TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030
),
1118 TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2
),
1119 TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3
),
1120 TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4
),
1121 TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1
),
1122 TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2
),
1123 TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1
),
1124 TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2
),
1125 TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM
),
1126 TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC
),
1127 TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2
),
1128 TWL4030_OF_MATCH("ti,twl4030-vio", VIO
),
1129 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1
),
1130 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2
),
1131 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1
),
1132 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2
),
1133 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3
),
1134 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030
),
1135 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030
),
1136 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030
),
1137 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC
),
1138 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP
),
1139 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM
),
1140 TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2
),
1141 TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4
),
1142 TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3
),
1143 TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5
),
1144 TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1
),
1145 TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7
),
1146 TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6
),
1147 TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN
),
1148 TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB
),
1149 TWLFIXED_OF_MATCH("ti,twl4030-vintana2", VINTANA2
),
1150 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG
),
1151 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5
),
1152 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8
),
1153 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1
),
1154 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA
),
1155 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO
),
1156 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC
),
1157 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB
),
1158 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8
),
1159 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1
),
1160 TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG
),
1161 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3
),
1162 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4
),
1163 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO
),
1166 MODULE_DEVICE_TABLE(of
, twl_of_match
);
1168 static int __devinit
twlreg_probe(struct platform_device
*pdev
)
1171 struct twlreg_info
*info
;
1172 struct regulator_init_data
*initdata
;
1173 struct regulation_constraints
*c
;
1174 struct regulator_dev
*rdev
;
1175 struct twl_regulator_driver_data
*drvdata
;
1176 const struct of_device_id
*match
;
1177 struct regulator_config config
= { };
1179 match
= of_match_device(twl_of_match
, &pdev
->dev
);
1183 initdata
= of_get_regulator_init_data(&pdev
->dev
,
1188 initdata
= pdev
->dev
.platform_data
;
1189 for (i
= 0, info
= NULL
; i
< ARRAY_SIZE(twl_of_match
); i
++) {
1190 info
= twl_of_match
[i
].data
;
1191 if (info
&& info
->desc
.id
== id
)
1194 if (i
== ARRAY_SIZE(twl_of_match
))
1197 drvdata
= initdata
->driver_data
;
1209 /* copy the driver data into regulator data */
1210 info
->features
= drvdata
->features
;
1211 info
->data
= drvdata
->data
;
1212 info
->set_voltage
= drvdata
->set_voltage
;
1213 info
->get_voltage
= drvdata
->get_voltage
;
1216 /* Constrain board-specific capabilities according to what
1217 * this driver and the chip itself can actually do.
1219 c
= &initdata
->constraints
;
1220 c
->valid_modes_mask
&= REGULATOR_MODE_NORMAL
| REGULATOR_MODE_STANDBY
;
1221 c
->valid_ops_mask
&= REGULATOR_CHANGE_VOLTAGE
1222 | REGULATOR_CHANGE_MODE
1223 | REGULATOR_CHANGE_STATUS
;
1225 case TWL4030_REG_VIO
:
1226 case TWL4030_REG_VDD1
:
1227 case TWL4030_REG_VDD2
:
1228 case TWL4030_REG_VPLL1
:
1229 case TWL4030_REG_VINTANA1
:
1230 case TWL4030_REG_VINTANA2
:
1231 case TWL4030_REG_VINTDIG
:
1232 c
->always_on
= true;
1239 case TWL6025_REG_SMPS3
:
1240 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3
)
1241 info
->flags
|= SMPS_EXTENDED_EN
;
1242 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3
)
1243 info
->flags
|= SMPS_OFFSET_EN
;
1245 case TWL6025_REG_SMPS4
:
1246 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4
)
1247 info
->flags
|= SMPS_EXTENDED_EN
;
1248 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4
)
1249 info
->flags
|= SMPS_OFFSET_EN
;
1251 case TWL6025_REG_VIO
:
1252 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO
)
1253 info
->flags
|= SMPS_EXTENDED_EN
;
1254 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO
)
1255 info
->flags
|= SMPS_OFFSET_EN
;
1259 config
.dev
= &pdev
->dev
;
1260 config
.init_data
= initdata
;
1261 config
.driver_data
= info
;
1262 config
.of_node
= pdev
->dev
.of_node
;
1264 rdev
= regulator_register(&info
->desc
, &config
);
1266 dev_err(&pdev
->dev
, "can't register %s, %ld\n",
1267 info
->desc
.name
, PTR_ERR(rdev
));
1268 return PTR_ERR(rdev
);
1270 platform_set_drvdata(pdev
, rdev
);
1272 if (twl_class_is_4030())
1273 twlreg_write(info
, TWL_MODULE_PM_RECEIVER
, VREG_REMAP
,
1276 /* NOTE: many regulators support short-circuit IRQs (presentable
1277 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1279 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1280 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1287 static int __devexit
twlreg_remove(struct platform_device
*pdev
)
1289 regulator_unregister(platform_get_drvdata(pdev
));
1293 MODULE_ALIAS("platform:twl_reg");
1295 static struct platform_driver twlreg_driver
= {
1296 .probe
= twlreg_probe
,
1297 .remove
= __devexit_p(twlreg_remove
),
1298 /* NOTE: short name, to work around driver model truncation of
1299 * "twl_regulator.12" (and friends) to "twl_regulator.1".
1303 .owner
= THIS_MODULE
,
1304 .of_match_table
= of_match_ptr(twl_of_match
),
1308 static int __init
twlreg_init(void)
1310 return platform_driver_register(&twlreg_driver
);
1312 subsys_initcall(twlreg_init
);
1314 static void __exit
twlreg_exit(void)
1316 platform_driver_unregister(&twlreg_driver
);
1318 module_exit(twlreg_exit
)
1320 MODULE_DESCRIPTION("TWL regulator driver");
1321 MODULE_LICENSE("GPL");