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/delay.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/regulator/machine.h>
19 #include <linux/i2c/twl.h>
23 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
24 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
25 * include an audio codec, battery charger, and more voltage regulators.
26 * These chips are often used in OMAP-based systems.
28 * This driver implements software-based resource control for various
29 * voltage regulators. This is usually augmented with state machine
34 /* start of regulator's PM_RECEIVER control register bank */
37 /* twl resource ID, for resource control state machine */
40 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
44 /* regulator specific turn-on delay */
47 /* State REMAP default configuration */
50 /* chip constraints on regulator behavior */
56 /* used by regulator core */
57 struct regulator_desc desc;
59 /* chip specific features */
60 unsigned long features;
64 /* LDO control registers ... offset is from the base of its register bank.
65 * The first three registers of all power resource banks help hardware to
66 * manage the various resource groups.
68 /* Common offset in TWL4030/6030 */
70 /* TWL4030 register offsets */
73 #define VREG_DEDICATED 3 /* LDO control */
74 /* TWL6030 register offsets */
77 #define VREG_VOLTAGE 3
78 #define VREG_VOLTAGE_SMPS 4
79 #define VREG_VOLTAGE_DVS_SMPS 3 //add
80 /* TWL6030 Misc register offsets */
83 #define VREG_BC_PROC 3
84 #define VREG_BC_CLK_RST 4
86 /* TWL6030 LDO register values for CFG_TRANS */
87 #define TWL6030_CFG_TRANS_STATE_MASK 0x03
88 #define TWL6030_CFG_TRANS_STATE_OFF 0x00
90 * Auto means the following:
95 #define TWL6030_CFG_TRANS_STATE_AUTO 0x01
96 #define TWL6030_CFG_TRANS_SLEEP_SHIFT 2
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_MASK 0x03
106 #define TWL6030_CFG_STATE_APP_MASK (TWL6030_CFG_STATE_MASK << \
107 TWL6030_CFG_STATE_APP_SHIFT)
108 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
109 TWL6030_CFG_STATE_APP_SHIFT)
111 /* Flags for SMPS Voltage reading */
112 #define SMPS_OFFSET_EN BIT(0)
113 #define SMPS_EXTENDED_EN BIT(1)
115 /* twl6032 SMPS EPROM values */
116 #define TWL6030_SMPS_OFFSET 0xB0
117 #define TWL6030_SMPS_MULT 0xB3
118 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
119 #define SMPS_MULTOFFSET_VIO BIT(1)
120 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
124 /* TWL6030 VUSB supplemental config registers */
125 #define TWL6030_MISC2 0xE5
126 #define TWL6030_CFG_LDO_PD2 0xF5
129 * TWL603X SMPS has 6 bits xxxx_CFG_VOLTAGE.VSEL[5:0] to configure voltages and
130 * each bit combination corresponds to a particular voltage (value 63 is
133 #define TWL603X_SMPS_VSEL_MASK 0x3F
134 #define TWL603X_SMPS_NUMBER_VOLTAGES TWL603X_SMPS_VSEL_MASK
137 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
141 status = twl_i2c_read_u8(slave_subgp,
142 &value, info->base + offset);
143 return (status < 0) ? status : value;
147 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
150 return twl_i2c_write_u8(slave_subgp,
151 value, info->base + offset);
154 /*----------------------------------------------------------------------*/
156 /* generic power resource operations, which work on all regulators */
158 static int twlreg_grp(struct regulator_dev *rdev)
160 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
165 * Enable/disable regulators by joining/leaving the P1 (processor) group.
166 * We assume nobody else is updating the DEV_GRP registers.
168 /* definition for 4030 family */
169 #define P3_GRP_4030 BIT(7) /* "peripherals" */
170 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
171 #define P1_GRP_4030 BIT(5) /* CPU/Linux */
172 /* definition for 6030 family */
173 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
174 #define P2_GRP_6030 BIT(1) /* "peripherals" */
175 #define P1_GRP_6030 BIT(0) /* CPU/Linux */
177 static int twl4030reg_is_enabled(struct regulator_dev *rdev)
179 int state = twlreg_grp(rdev);
184 return state & P1_GRP_4030;
187 static int twl6030reg_is_enabled(struct regulator_dev *rdev)
189 struct twlreg_info *info = rdev_get_drvdata(rdev);
192 if (!(info->features & TWL6032_SUBCLASS)) {
193 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
198 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
199 val = TWL6030_CFG_STATE_APP(val);
201 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
202 val &= TWL6030_CFG_STATE_MASK;
206 return grp && (val == TWL6030_CFG_STATE_ON);
209 static int twl6030reg_set_trans_state(struct regulator_dev *rdev,
212 struct twlreg_info *info = rdev_get_drvdata(rdev);
216 /* Read CFG_TRANS register of TWL6030 */
217 rval = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_TRANS);
222 mask = TWL6030_CFG_TRANS_STATE_MASK << shift;
223 val = (val << shift) & mask;
225 /* If value is already set, no need to write to reg */
226 if (val == (rval & mask))
232 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_TRANS, rval);
235 static int twl4030reg_enable(struct regulator_dev *rdev)
237 struct twlreg_info *info = rdev_get_drvdata(rdev);
241 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
247 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
254 static int twl6030reg_enable(struct regulator_dev *rdev)
256 struct twlreg_info *info = rdev_get_drvdata(rdev);
260 if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
261 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
265 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
266 grp << TWL6030_CFG_STATE_GRP_SHIFT |
267 TWL6030_CFG_STATE_ON);
269 * Ensure it stays in Auto mode when we enter suspend state.
270 * (TWL6030 in sleep mode).
273 ret = twl6030reg_set_trans_state(rdev,
274 TWL6030_CFG_TRANS_SLEEP_SHIFT,
275 TWL6030_CFG_TRANS_STATE_AUTO);
281 static int twl4030reg_disable(struct regulator_dev *rdev)
283 struct twlreg_info *info = rdev_get_drvdata(rdev);
287 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
291 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
293 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
298 static int twl6030reg_disable(struct regulator_dev *rdev)
300 struct twlreg_info *info = rdev_get_drvdata(rdev);
304 if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
305 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
307 /* For 6030, set the off state for all grps enabled */
308 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
309 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
310 TWL6030_CFG_STATE_OFF);
312 /* Ensure it remains OFF when we enter suspend (TWL6030 in sleep). */
314 ret = twl6030reg_set_trans_state(rdev,
315 TWL6030_CFG_TRANS_SLEEP_SHIFT,
316 TWL6030_CFG_TRANS_STATE_OFF);
320 static int twl4030reg_get_status(struct regulator_dev *rdev)
322 int state = twlreg_grp(rdev);
328 /* assume state != WARM_RESET; we'd not be running... */
330 return REGULATOR_STATUS_OFF;
331 return (state & BIT(3))
332 ? REGULATOR_STATUS_NORMAL
333 : REGULATOR_STATUS_STANDBY;
336 static int twl6030reg_get_status(struct regulator_dev *rdev)
338 struct twlreg_info *info = rdev_get_drvdata(rdev);
341 val = twlreg_grp(rdev);
345 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
347 if (info->features & TWL6032_SUBCLASS)
348 val &= TWL6030_CFG_STATE_MASK;
350 val = TWL6030_CFG_STATE_APP(val);
353 case TWL6030_CFG_STATE_ON:
354 return REGULATOR_STATUS_NORMAL;
356 case TWL6030_CFG_STATE_SLEEP:
357 return REGULATOR_STATUS_STANDBY;
359 case TWL6030_CFG_STATE_OFF:
360 case TWL6030_CFG_STATE_OFF2:
365 return REGULATOR_STATUS_OFF;
368 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
370 struct twlreg_info *info = rdev_get_drvdata(rdev);
374 /* We can only set the mode through state machine commands... */
376 case REGULATOR_MODE_NORMAL:
377 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
379 case REGULATOR_MODE_STANDBY:
380 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
386 /* Ensure the resource is associated with some group */
387 status = twlreg_grp(rdev);
390 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
393 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
394 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
398 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
399 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
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_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
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 static int twl6030ldo_suspend_enable(struct regulator_dev *rdev)
434 return twl6030reg_set_trans_state(rdev, TWL6030_CFG_TRANS_SLEEP_SHIFT,
435 TWL6030_CFG_TRANS_STATE_AUTO);
438 static int twl6030ldo_suspend_disable(struct regulator_dev *rdev)
440 return twl6030reg_set_trans_state(rdev, TWL6030_CFG_TRANS_SLEEP_SHIFT,
441 TWL6030_CFG_TRANS_STATE_OFF);
444 /*----------------------------------------------------------------------*/
447 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
448 * select field in its control register. We use tables indexed by VSEL
449 * to record voltages in milliVolts. (Accuracy is about three percent.)
451 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
452 * currently handled by listing two slightly different VAUX2 regulators,
453 * only one of which will be configured.
455 * VSEL values documented as "TI cannot support these values" are flagged
456 * in these tables as UNSUP() values; we normally won't assign them.
458 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
459 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
461 #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
462 #define UNSUP_MASK 0x0000
464 #define UNSUP_MASK 0x8000
467 #define UNSUP(x) (UNSUP_MASK | (x))
468 #define IS_UNSUP(x) (UNSUP_MASK & (x))
469 #define LDO_MV(x) (~UNSUP_MASK & (x))
472 static const u16 VAUX1_VSEL_table[] = {
473 UNSUP(1500), UNSUP(1800), 2500, 2800,
474 3000, 3000, 3000, 3000,
476 static const u16 VAUX2_4030_VSEL_table[] = {
477 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
478 1500, 1800, UNSUP(1850), 2500,
479 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
480 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
482 static const u16 VAUX2_VSEL_table[] = {
483 1700, 1700, 1900, 1300,
484 1500, 1800, 2000, 2500,
485 2100, 2800, 2200, 2300,
486 2400, 2400, 2400, 2400,
488 static const u16 VAUX3_VSEL_table[] = {
489 1500, 1800, 2500, 2800,
490 3000, 3000, 3000, 3000,
492 static const u16 VAUX4_VSEL_table[] = {
493 700, 1000, 1200, UNSUP(1300),
494 1500, 1800, UNSUP(1850), 2500,
495 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
496 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
498 static const u16 VMMC1_VSEL_table[] = {
499 1850, 2850, 3000, 3150,
501 static const u16 VMMC2_VSEL_table[] = {
502 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
503 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
504 2600, 2800, 2850, 3000,
505 3150, 3150, 3150, 3150,
507 static const u16 VPLL1_VSEL_table[] = {
508 1000, 1200, 1300, 1800,
509 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
511 static const u16 VPLL2_VSEL_table[] = {
512 700, 1000, 1200, 1300,
513 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
514 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
515 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
517 static const u16 VSIM_VSEL_table[] = {
518 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
519 2800, 3000, 3000, 3000,
521 static const u16 VDAC_VSEL_table[] = {
522 1200, 1300, 1800, 1800,
524 static const u16 VDD1_VSEL_table[] = {
527 static const u16 VDD2_VSEL_table[] = {
530 static const u16 VIO_VSEL_table[] = {
533 static const u16 VINTANA2_VSEL_table[] = {
537 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
539 struct twlreg_info *info = rdev_get_drvdata(rdev);
540 int mV = info->table[index];
542 return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
546 twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
549 struct twlreg_info *info = rdev_get_drvdata(rdev);
552 for (vsel = 0; vsel < info->table_len; vsel++) {
553 int mV = info->table[vsel];
558 uV = LDO_MV(mV) * 1000;
560 /* REVISIT for VAUX2, first match may not be best/lowest */
562 /* use the first in-range value */
563 if (min_uV <= uV && uV <= max_uV) {
565 return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
573 static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
575 struct twlreg_info *info = rdev_get_drvdata(rdev);
576 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
582 vsel &= info->table_len - 1;
583 return LDO_MV(info->table[vsel]) * 1000;
586 static struct regulator_ops twl4030ldo_ops = {
587 .list_voltage = twl4030ldo_list_voltage,
589 .set_voltage = twl4030ldo_set_voltage,
590 .get_voltage = twl4030ldo_get_voltage,
592 .enable = twl4030reg_enable,
593 .disable = twl4030reg_disable,
594 .is_enabled = twl4030reg_is_enabled,
596 .set_mode = twl4030reg_set_mode,
598 .get_status = twl4030reg_get_status,
601 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
603 struct twlreg_info *info = rdev_get_drvdata(rdev);
605 return ((info->min_mV + (index * 100)) * 1000);
609 twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
612 struct twlreg_info *info = rdev_get_drvdata(rdev);
615 if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
619 * Use the below formula to calculate vsel
620 * mV = 1000mv + 100mv * (vsel - 1)
622 vsel = (min_uV/1000 - 1000)/100 + 1;
624 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
628 static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
630 struct twlreg_info *info = rdev_get_drvdata(rdev);
631 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
638 * Use the below formula to calculate vsel
639 * mV = 1000mv + 100mv * (vsel - 1)
641 return (1000 + (100 * (vsel - 1))) * 1000;
644 static struct regulator_ops twl6030ldo_ops = {
645 .list_voltage = twl6030ldo_list_voltage,
647 .set_voltage = twl6030ldo_set_voltage,
648 .get_voltage = twl6030ldo_get_voltage,
650 .enable = twl6030reg_enable,
651 .disable = twl6030reg_disable,
652 .is_enabled = twl6030reg_is_enabled,
654 .set_mode = twl6030reg_set_mode,
656 .get_status = twl6030reg_get_status,
658 .set_suspend_enable = twl6030ldo_suspend_enable,
659 .set_suspend_disable = twl6030ldo_suspend_disable,
662 /*----------------------------------------------------------------------*/
665 * Fixed voltage LDOs don't have a VSEL field to update.
667 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
669 struct twlreg_info *info = rdev_get_drvdata(rdev);
671 return info->min_mV * 1000;
674 static int twlfixed_get_voltage(struct regulator_dev *rdev)
676 struct twlreg_info *info = rdev_get_drvdata(rdev);
678 return info->min_mV * 1000;
681 static struct regulator_ops twl4030fixed_ops = {
682 .list_voltage = twlfixed_list_voltage,
684 .get_voltage = twlfixed_get_voltage,
686 .enable = twl4030reg_enable,
687 .disable = twl4030reg_disable,
688 .is_enabled = twl4030reg_is_enabled,
690 .set_mode = twl4030reg_set_mode,
692 .get_status = twl4030reg_get_status,
695 static struct regulator_ops twl6030fixed_ops = {
696 .list_voltage = twlfixed_list_voltage,
698 .get_voltage = twlfixed_get_voltage,
700 .enable = twl6030reg_enable,
701 .disable = twl6030reg_disable,
702 .is_enabled = twl6030reg_is_enabled,
704 .set_mode = twl6030reg_set_mode,
706 .get_status = twl6030reg_get_status,
708 .set_suspend_enable = twl6030ldo_suspend_enable,
709 .set_suspend_disable = twl6030ldo_suspend_disable,
712 static struct regulator_ops twl6030_fixed_resource = {
713 .enable = twl6030reg_enable,
714 .disable = twl6030reg_disable,
715 .is_enabled = twl6030reg_is_enabled,
716 .get_status = twl6030reg_get_status,
720 * SMPS status and control
723 static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
725 struct twlreg_info *info = rdev_get_drvdata(rdev);
729 switch (info->flags) {
739 voltage = 1350 * 1000;
742 voltage = 1500 * 1000;
745 voltage = 1800 * 1000;
748 voltage = 1900 * 1000;
751 voltage = 2100 * 1000;
754 voltage += (600000 + (12500 * (index - 1)));
757 case SMPS_EXTENDED_EN:
763 voltage = 2084 * 1000;
766 voltage = 2315 * 1000;
769 voltage = 2778 * 1000;
772 voltage = 2932 * 1000;
775 voltage = 3241 * 1000;
778 voltage = (1852000 + (38600 * (index - 1)));
781 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
787 voltage = 4167 * 1000;
790 voltage = 2315 * 1000;
793 voltage = 2778 * 1000;
796 voltage = 2932 * 1000;
799 voltage = 3241 * 1000;
802 voltage = (2161000 + (38600 * (index - 1)));
811 twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
812 unsigned int *selector)
814 struct twlreg_info *info = rdev_get_drvdata(rdev);
817 switch (info->flags) {
821 else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
822 vsel = (min_uV - 600000) / 125;
828 /* Values 1..57 for vsel are linear and can be calculated
829 * values 58..62 are non linear.
831 else if ((min_uV > 1900000) && (max_uV >= 2100000))
833 else if ((min_uV > 1800000) && (max_uV >= 1900000))
835 else if ((min_uV > 1500000) && (max_uV >= 1800000))
837 else if ((min_uV > 1350000) && (max_uV >= 1500000))
839 else if ((min_uV > 1300000) && (max_uV >= 1350000))
847 else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
848 vsel = (min_uV - 700000) / 125;
854 /* Values 1..57 for vsel are linear and can be calculated
855 * values 58..62 are non linear.
857 else if ((min_uV > 1900000) && (max_uV >= 2100000))
859 else if ((min_uV > 1800000) && (max_uV >= 1900000))
861 else if ((min_uV > 1350000) && (max_uV >= 1800000))
863 else if ((min_uV > 1350000) && (max_uV >= 1500000))
865 else if ((min_uV > 1300000) && (max_uV >= 1350000))
870 case SMPS_EXTENDED_EN:
873 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
874 vsel = (min_uV - 1852000) / 386;
881 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
884 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
885 vsel = (min_uV - 1852000) / 386;
896 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
901 static int twl6030dvssmps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
902 unsigned int *selector)
904 struct twlreg_info *info = rdev_get_drvdata(rdev);
907 switch (info->flags) {
911 else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
912 vsel = (min_uV - 600000) / 125;
918 /* Values 1..57 for vsel are linear and can be calculated
919 * values 58..62 are non linear.
921 else if ((min_uV > 1900000) && (max_uV >= 2100000))
923 else if ((min_uV > 1800000) && (max_uV >= 1900000))
925 else if ((min_uV > 1500000) && (max_uV >= 1800000))
927 else if ((min_uV > 1350000) && (max_uV >= 1500000))
929 else if ((min_uV > 1300000) && (max_uV >= 1350000))
937 else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
938 vsel = (min_uV - 700000) / 125;
944 /* Values 1..57 for vsel are linear and can be calculated
945 * values 58..62 are non linear.
947 else if ((min_uV > 1900000) && (max_uV >= 2100000))
949 else if ((min_uV > 1800000) && (max_uV >= 1900000))
951 else if ((min_uV > 1350000) && (max_uV >= 1800000))
953 else if ((min_uV > 1350000) && (max_uV >= 1500000))
955 else if ((min_uV > 1300000) && (max_uV >= 1350000))
960 case SMPS_EXTENDED_EN:
963 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
964 vsel = (min_uV - 1852000) / 386;
971 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
974 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
975 vsel = (min_uV - 1852000) / 386;
986 return twlreg_write(info, TWL_MODULE_PM_DVS, VREG_VOLTAGE_DVS_SMPS,
990 static int twl6030dvssmps_get_voltage_sel(struct regulator_dev *rdev)
992 struct twlreg_info *info = rdev_get_drvdata(rdev);
994 return twlreg_read(info, TWL_MODULE_PM_DVS, VREG_VOLTAGE_DVS_SMPS);
997 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
999 struct twlreg_info *info = rdev_get_drvdata(rdev);
1001 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
1004 static struct regulator_ops twlsmps_ops = {
1005 .list_voltage = twl6030smps_list_voltage,
1007 .set_voltage = twl6030smps_set_voltage,
1008 .get_voltage_sel = twl6030smps_get_voltage_sel,
1010 .enable = twl6030reg_enable,
1011 .disable = twl6030reg_disable,
1012 .is_enabled = twl6030reg_is_enabled,
1014 .set_mode = twl6030reg_set_mode,
1016 .get_status = twl6030reg_get_status,
1018 .set_suspend_enable = twl6030ldo_suspend_enable,
1019 .set_suspend_disable = twl6030ldo_suspend_disable,
1022 static struct regulator_ops twl6030_external_control_pin_ops = {
1023 .enable = twl6030reg_enable,
1024 .disable = twl6030reg_disable,
1025 .is_enabled = twl6030reg_is_enabled,
1027 .set_mode = twl6030reg_set_mode,
1029 .get_status = twl6030reg_get_status,
1031 .set_suspend_enable = twl6030ldo_suspend_enable,
1032 .set_suspend_disable = twl6030ldo_suspend_disable,
1035 static struct regulator_ops twldvssmps_ops = {
1036 .list_voltage = twl6030smps_list_voltage,
1038 .set_voltage = twl6030dvssmps_set_voltage,
1039 .get_voltage_sel = twl6030dvssmps_get_voltage_sel,
1041 .enable = twl6030reg_enable,
1042 .disable = twl6030reg_disable,
1043 .is_enabled = twl6030reg_is_enabled,
1045 .set_mode = twl6030reg_set_mode,
1047 .get_status = twl6030reg_get_status,
1049 .set_suspend_enable = twl6030ldo_suspend_enable,
1050 .set_suspend_disable = twl6030ldo_suspend_disable,
1052 /*----------------------------------------------------------------------*/
1054 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
1056 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
1057 remap_conf, TWL4030, twl4030fixed_ops)
1058 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
1059 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
1060 0x0, TWL6030, twl6030fixed_ops)
1062 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
1065 .table_len = ARRAY_SIZE(label##_VSEL_table), \
1066 .table = label##_VSEL_table, \
1067 .delay = turnon_delay, \
1068 .remap = remap_conf, \
1071 .id = TWL4030_REG_##label, \
1072 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
1073 .ops = &twl4030ldo_ops, \
1074 .type = REGULATOR_VOLTAGE, \
1075 .owner = THIS_MODULE, \
1079 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
1081 .min_mV = min_mVolts, \
1082 .max_mV = max_mVolts, \
1085 .id = TWL6030_REG_##label, \
1086 .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \
1087 .ops = &twl6030ldo_ops, \
1088 .type = REGULATOR_VOLTAGE, \
1089 .owner = THIS_MODULE, \
1093 #define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
1095 .min_mV = min_mVolts, \
1096 .max_mV = max_mVolts, \
1099 .id = TWL6032_REG_##label, \
1100 .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \
1101 .ops = &twl6030ldo_ops, \
1102 .type = REGULATOR_VOLTAGE, \
1103 .owner = THIS_MODULE, \
1107 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
1108 family, operations) { \
1112 .delay = turnon_delay, \
1113 .remap = remap_conf, \
1116 .id = family##_REG_##label, \
1118 .ops = &operations, \
1119 .type = REGULATOR_VOLTAGE, \
1120 .owner = THIS_MODULE, \
1124 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \
1126 .delay = turnon_delay, \
1129 .id = TWL6030_REG_##label, \
1130 .ops = &twl6030_fixed_resource, \
1131 .type = REGULATOR_VOLTAGE, \
1132 .owner = THIS_MODULE, \
1136 #define TWL6030_ADJUSTABLE_SMPS(label, offset, min_mVolts, max_mVolts) { \
1138 .min_mV = min_mVolts, \
1139 .max_mV = max_mVolts, \
1142 .id = TWL6030_REG_##label, \
1143 .n_voltages = TWL603X_SMPS_NUMBER_VOLTAGES, \
1144 .ops = &twlsmps_ops, \
1145 .type = REGULATOR_VOLTAGE, \
1146 .owner = THIS_MODULE, \
1150 #define TWL6032_ADJUSTABLE_SMPS(label, offset) { \
1156 .id = TWL6032_REG_##label, \
1157 .n_voltages = TWL603X_SMPS_NUMBER_VOLTAGES, \
1158 .ops = &twlsmps_ops, \
1159 .type = REGULATOR_VOLTAGE, \
1160 .owner = THIS_MODULE, \
1164 #define TWL6030_EXTERNAL_CONTROL_PIN(label, offset, turnon_delay) { \
1166 .delay = turnon_delay, \
1169 .id = TWL6030_REG_##label, \
1170 .ops = &twl6030_external_control_pin_ops, \
1171 .type = REGULATOR_VOLTAGE, \
1172 .owner = THIS_MODULE, \
1177 #define TWL6032_ADJUSTABLE_DVSSMPS(label, offset) { \
1183 .id = TWL6032_REG_##label, \
1184 .n_voltages = TWL603X_SMPS_NUMBER_VOLTAGES, \
1185 .ops = &twldvssmps_ops, \
1186 .type = REGULATOR_VOLTAGE, \
1187 .owner = THIS_MODULE, \
1192 * We list regulators here if systems need some level of
1193 * software control over them after boot.
1195 static struct twlreg_info twl_regs[] = {
1196 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
1197 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
1198 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
1199 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
1200 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
1201 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
1202 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
1203 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
1204 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
1205 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
1206 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
1207 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
1208 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
1209 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
1210 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
1211 TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
1212 TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
1213 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
1214 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
1215 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
1216 /* VUSBCP is managed *only* by the USB subchip */
1218 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1219 /* Turnon-delay and remap configuration values for 6030 are not
1220 verified since the specification is not public */
1221 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300),
1222 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300),
1223 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300),
1224 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300),
1225 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300),
1226 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300),
1227 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0),
1228 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0),
1229 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0),
1230 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0),
1231 TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0),
1232 TWL6030_FIXED_RESOURCE(CLK32KAUDIO, 0x8F, 0),
1233 TWL6030_ADJUSTABLE_SMPS(VDD1, 0x22, 600, 4000),
1234 TWL6030_ADJUSTABLE_SMPS(VDD2, 0x28, 600, 4000),
1235 TWL6030_ADJUSTABLE_SMPS(VDD3, 0x2e, 600, 4000),
1236 TWL6030_ADJUSTABLE_SMPS(VMEM, 0x34, 600, 4000),
1237 TWL6030_ADJUSTABLE_SMPS(V2V1, 0x1c, 1800, 2100),
1239 /* 6032 are renamed compared to 6030 versions */
1240 TWL6032_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300),
1241 TWL6032_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300),
1242 TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300),
1243 TWL6032_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300),
1244 TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300),
1245 TWL6032_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300),
1246 TWL6032_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300),
1247 TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300),
1248 TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300),
1250 TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34),
1251 TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10),
1252 TWL6032_ADJUSTABLE_SMPS(VIO, 0x16),
1254 TWL6032_ADJUSTABLE_DVSSMPS(SMPS1, 0x22),
1255 TWL6032_ADJUSTABLE_DVSSMPS(SMPS2, 0x28),
1256 TWL6032_ADJUSTABLE_DVSSMPS(SMPS5, 0x16),
1258 TWL6030_EXTERNAL_CONTROL_PIN(SYSEN, 0x83, 0),
1259 TWL6030_EXTERNAL_CONTROL_PIN(REGEN1, 0x7d, 0),
1263 static u8 twl_get_smps_offset(void)
1267 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1268 TWL6030_SMPS_OFFSET);
1272 static u8 twl_get_smps_mult(void)
1276 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1281 static int __devinit twlreg_probe(struct platform_device *pdev)
1284 struct twlreg_info *info;
1285 struct regulator_init_data *initdata;
1286 struct regulation_constraints *c;
1287 struct regulator_dev *rdev;
1290 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
1291 if (twl_regs[i].desc.id != pdev->id)
1293 info = twl_regs + i;
1299 initdata = pdev->dev.platform_data;
1303 /* copy the features into regulator data */
1304 info->features = (unsigned long)initdata->driver_data;
1306 /* Constrain board-specific capabilities according to what
1307 * this driver and the chip itself can actually do.
1309 c = &initdata->constraints;
1310 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1311 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1312 | REGULATOR_CHANGE_MODE
1313 | REGULATOR_CHANGE_STATUS;
1315 case TWL4030_REG_VIO:
1316 case TWL4030_REG_VDD1:
1317 case TWL4030_REG_VDD2:
1318 case TWL4030_REG_VPLL1:
1319 case TWL4030_REG_VINTANA1:
1320 case TWL4030_REG_VINTANA2:
1321 case TWL4030_REG_VINTDIG:
1322 c->always_on = true;
1324 case TWL6030_REG_VUSB:
1325 /* Program CFG_LDO_PD2 register and set VUSB bit */
1326 ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, 0x1,
1327 TWL6030_CFG_LDO_PD2);
1331 /* Program MISC2 register and set bit VUSB_IN_VBAT */
1332 ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, 0x10, TWL6030_MISC2);
1341 case TWL6032_REG_SMPS3:
1342 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1343 info->flags |= SMPS_EXTENDED_EN;
1344 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1345 info->flags |= SMPS_OFFSET_EN;
1347 case TWL6032_REG_SMPS4:
1348 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1349 info->flags |= SMPS_EXTENDED_EN;
1350 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1351 info->flags |= SMPS_OFFSET_EN;
1354 case TWL6032_REG_VIO:
1355 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1356 info->flags |= SMPS_EXTENDED_EN;
1357 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1358 info->flags |= SMPS_OFFSET_EN;
1362 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
1364 dev_err(&pdev->dev, "can't register %s, %ld\n",
1365 info->desc.name, PTR_ERR(rdev));
1366 return PTR_ERR(rdev);
1368 platform_set_drvdata(pdev, rdev);
1370 if (twl_class_is_4030())
1371 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
1374 /* NOTE: many regulators support short-circuit IRQs (presentable
1375 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1377 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1378 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1385 static int __devexit twlreg_remove(struct platform_device *pdev)
1387 regulator_unregister(platform_get_drvdata(pdev));
1391 MODULE_ALIAS("platform:twl_reg");
1393 static struct platform_driver twlreg_driver = {
1394 .probe = twlreg_probe,
1395 .remove = __devexit_p(twlreg_remove),
1396 /* NOTE: short name, to work around driver model truncation of
1397 * "twl_regulator.12" (and friends) to "twl_regulator.1".
1399 .driver.name = "twl_reg",
1400 .driver.owner = THIS_MODULE,
1403 static int __init twlreg_init(void)
1405 return platform_driver_register(&twlreg_driver);
1407 subsys_initcall_sync(twlreg_init);
1409 static void __exit twlreg_exit(void)
1411 platform_driver_unregister(&twlreg_driver);
1413 module_exit(twlreg_exit)
1415 MODULE_DESCRIPTION("TWL regulator driver");
1416 MODULE_LICENSE("GPL");