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;
63 * optional override functions for voltage set/get
64 * these are currently only used for SMPS regulators
66 int (*get_voltage)(void *data);
67 int (*set_voltage)(void *data, int target_uV);
69 /* data passed from board for external get/set voltage */
74 /* LDO control registers ... offset is from the base of its register bank.
75 * The first three registers of all power resource banks help hardware to
76 * manage the various resource groups.
78 /* Common offset in TWL4030/6030 */
80 /* TWL4030 register offsets */
83 #define VREG_DEDICATED 3 /* LDO control */
84 #define VREG_VOLTAGE_SMPS_4030 9
85 /* TWL6030 register offsets */
88 #define VREG_VOLTAGE 3
89 #define VREG_VOLTAGE_SMPS 4
90 /* TWL6030 Misc register offsets */
93 #define VREG_BC_PROC 3
94 #define VREG_BC_CLK_RST 4
96 /* TWL6030 LDO register values for CFG_STATE */
97 #define TWL6030_CFG_STATE_OFF 0x00
98 #define TWL6030_CFG_STATE_ON 0x01
99 #define TWL6030_CFG_STATE_OFF2 0x02
100 #define TWL6030_CFG_STATE_SLEEP 0x03
101 #define TWL6030_CFG_STATE_GRP_SHIFT 5
102 #define TWL6030_CFG_STATE_APP_SHIFT 2
103 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
104 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
105 TWL6030_CFG_STATE_APP_SHIFT)
107 /* Flags for SMPS Voltage reading */
108 #define SMPS_OFFSET_EN BIT(0)
109 #define SMPS_EXTENDED_EN BIT(1)
111 /* twl6025 SMPS EPROM values */
112 #define TWL6030_SMPS_OFFSET 0xB0
113 #define TWL6030_SMPS_MULT 0xB3
114 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
115 #define SMPS_MULTOFFSET_VIO BIT(1)
116 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
119 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
124 status = twl_i2c_read_u8(slave_subgp,
125 &value, info->base + offset);
126 return (status < 0) ? status : value;
130 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
133 return twl_i2c_write_u8(slave_subgp,
134 value, info->base + offset);
137 /*----------------------------------------------------------------------*/
139 /* generic power resource operations, which work on all regulators */
141 static int twlreg_grp(struct regulator_dev *rdev)
143 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
148 * Enable/disable regulators by joining/leaving the P1 (processor) group.
149 * We assume nobody else is updating the DEV_GRP registers.
151 /* definition for 4030 family */
152 #define P3_GRP_4030 BIT(7) /* "peripherals" */
153 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
154 #define P1_GRP_4030 BIT(5) /* CPU/Linux */
155 /* definition for 6030 family */
156 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
157 #define P2_GRP_6030 BIT(1) /* "peripherals" */
158 #define P1_GRP_6030 BIT(0) /* CPU/Linux */
160 static int twl4030reg_is_enabled(struct regulator_dev *rdev)
162 int state = twlreg_grp(rdev);
167 return state & P1_GRP_4030;
170 static int twl6030reg_is_enabled(struct regulator_dev *rdev)
172 struct twlreg_info *info = rdev_get_drvdata(rdev);
175 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
176 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
180 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
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 static int twl4030reg_enable(struct regulator_dev *rdev)
193 struct twlreg_info *info = rdev_get_drvdata(rdev);
197 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
203 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
210 static int twl6030reg_enable(struct regulator_dev *rdev)
212 struct twlreg_info *info = rdev_get_drvdata(rdev);
216 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
217 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
221 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
222 grp << TWL6030_CFG_STATE_GRP_SHIFT |
223 TWL6030_CFG_STATE_ON);
230 static int twl4030reg_disable(struct regulator_dev *rdev)
232 struct twlreg_info *info = rdev_get_drvdata(rdev);
236 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
240 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
242 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
247 static int twl6030reg_disable(struct regulator_dev *rdev)
249 struct twlreg_info *info = rdev_get_drvdata(rdev);
253 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
254 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
256 /* For 6030, set the off state for all grps enabled */
257 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
258 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
259 TWL6030_CFG_STATE_OFF);
264 static int twl4030reg_get_status(struct regulator_dev *rdev)
266 int state = twlreg_grp(rdev);
272 /* assume state != WARM_RESET; we'd not be running... */
274 return REGULATOR_STATUS_OFF;
275 return (state & BIT(3))
276 ? REGULATOR_STATUS_NORMAL
277 : REGULATOR_STATUS_STANDBY;
280 static int twl6030reg_get_status(struct regulator_dev *rdev)
282 struct twlreg_info *info = rdev_get_drvdata(rdev);
285 val = twlreg_grp(rdev);
289 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
291 switch (TWL6030_CFG_STATE_APP(val)) {
292 case TWL6030_CFG_STATE_ON:
293 return REGULATOR_STATUS_NORMAL;
295 case TWL6030_CFG_STATE_SLEEP:
296 return REGULATOR_STATUS_STANDBY;
298 case TWL6030_CFG_STATE_OFF:
299 case TWL6030_CFG_STATE_OFF2:
304 return REGULATOR_STATUS_OFF;
307 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
309 struct twlreg_info *info = rdev_get_drvdata(rdev);
313 /* We can only set the mode through state machine commands... */
315 case REGULATOR_MODE_NORMAL:
316 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
318 case REGULATOR_MODE_STANDBY:
319 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
325 /* Ensure the resource is associated with some group */
326 status = twlreg_grp(rdev);
329 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
332 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
333 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
337 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
338 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
341 static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
343 struct twlreg_info *info = rdev_get_drvdata(rdev);
347 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
348 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
353 /* Compose the state register settings */
354 val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
355 /* We can only set the mode through state machine commands... */
357 case REGULATOR_MODE_NORMAL:
358 val |= TWL6030_CFG_STATE_ON;
360 case REGULATOR_MODE_STANDBY:
361 val |= TWL6030_CFG_STATE_SLEEP;
368 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
371 /*----------------------------------------------------------------------*/
374 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
375 * select field in its control register. We use tables indexed by VSEL
376 * to record voltages in milliVolts. (Accuracy is about three percent.)
378 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
379 * currently handled by listing two slightly different VAUX2 regulators,
380 * only one of which will be configured.
382 * VSEL values documented as "TI cannot support these values" are flagged
383 * in these tables as UNSUP() values; we normally won't assign them.
385 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
386 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
388 #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
389 #define UNSUP_MASK 0x0000
391 #define UNSUP_MASK 0x8000
394 #define UNSUP(x) (UNSUP_MASK | (x))
395 #define IS_UNSUP(x) (UNSUP_MASK & (x))
396 #define LDO_MV(x) (~UNSUP_MASK & (x))
399 static const u16 VAUX1_VSEL_table[] = {
400 UNSUP(1500), UNSUP(1800), 2500, 2800,
401 3000, 3000, 3000, 3000,
403 static const u16 VAUX2_4030_VSEL_table[] = {
404 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
405 1500, 1800, UNSUP(1850), 2500,
406 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
407 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
409 static const u16 VAUX2_VSEL_table[] = {
410 1700, 1700, 1900, 1300,
411 1500, 1800, 2000, 2500,
412 2100, 2800, 2200, 2300,
413 2400, 2400, 2400, 2400,
415 static const u16 VAUX3_VSEL_table[] = {
416 1500, 1800, 2500, 2800,
417 3000, 3000, 3000, 3000,
419 static const u16 VAUX4_VSEL_table[] = {
420 700, 1000, 1200, UNSUP(1300),
421 1500, 1800, UNSUP(1850), 2500,
422 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
423 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
425 static const u16 VMMC1_VSEL_table[] = {
426 1850, 2850, 3000, 3150,
428 static const u16 VMMC2_VSEL_table[] = {
429 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
430 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
431 2600, 2800, 2850, 3000,
432 3150, 3150, 3150, 3150,
434 static const u16 VPLL1_VSEL_table[] = {
435 1000, 1200, 1300, 1800,
436 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
438 static const u16 VPLL2_VSEL_table[] = {
439 700, 1000, 1200, 1300,
440 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
441 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
442 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
444 static const u16 VSIM_VSEL_table[] = {
445 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
446 2800, 3000, 3000, 3000,
448 static const u16 VDAC_VSEL_table[] = {
449 1200, 1300, 1800, 1800,
451 static const u16 VDD1_VSEL_table[] = {
454 static const u16 VDD2_VSEL_table[] = {
457 static const u16 VIO_VSEL_table[] = {
460 static const u16 VINTANA2_VSEL_table[] = {
464 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
466 struct twlreg_info *info = rdev_get_drvdata(rdev);
467 int mV = info->table[index];
469 return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
473 twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
476 struct twlreg_info *info = rdev_get_drvdata(rdev);
479 for (vsel = 0; vsel < info->table_len; vsel++) {
480 int mV = info->table[vsel];
485 uV = LDO_MV(mV) * 1000;
487 /* REVISIT for VAUX2, first match may not be best/lowest */
489 /* use the first in-range value */
490 if (min_uV <= uV && uV <= max_uV) {
492 return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
500 static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
502 struct twlreg_info *info = rdev_get_drvdata(rdev);
503 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
509 vsel &= info->table_len - 1;
510 return LDO_MV(info->table[vsel]) * 1000;
513 static struct regulator_ops twl4030ldo_ops = {
514 .list_voltage = twl4030ldo_list_voltage,
516 .set_voltage = twl4030ldo_set_voltage,
517 .get_voltage = twl4030ldo_get_voltage,
519 .enable = twl4030reg_enable,
520 .disable = twl4030reg_disable,
521 .is_enabled = twl4030reg_is_enabled,
523 .set_mode = twl4030reg_set_mode,
525 .get_status = twl4030reg_get_status,
529 twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
532 struct twlreg_info *info = rdev_get_drvdata(rdev);
533 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
535 if (info->set_voltage) {
536 return info->set_voltage(info->data, min_uV);
538 twlreg_write(info, TWL_MODULE_PM_RECEIVER,
539 VREG_VOLTAGE_SMPS_4030, vsel);
545 static int twl4030smps_get_voltage(struct regulator_dev *rdev)
547 struct twlreg_info *info = rdev_get_drvdata(rdev);
550 if (info->get_voltage)
551 return info->get_voltage(info->data);
553 vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
554 VREG_VOLTAGE_SMPS_4030);
556 return vsel * 12500 + 600000;
559 static struct regulator_ops twl4030smps_ops = {
560 .set_voltage = twl4030smps_set_voltage,
561 .get_voltage = twl4030smps_get_voltage,
564 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
566 struct twlreg_info *info = rdev_get_drvdata(rdev);
568 return ((info->min_mV + (index * 100)) * 1000);
572 twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
575 struct twlreg_info *info = rdev_get_drvdata(rdev);
578 if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
582 * Use the below formula to calculate vsel
583 * mV = 1000mv + 100mv * (vsel - 1)
585 vsel = (min_uV/1000 - 1000)/100 + 1;
587 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
591 static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
593 struct twlreg_info *info = rdev_get_drvdata(rdev);
594 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
601 * Use the below formula to calculate vsel
602 * mV = 1000mv + 100mv * (vsel - 1)
604 return (1000 + (100 * (vsel - 1))) * 1000;
607 static struct regulator_ops twl6030ldo_ops = {
608 .list_voltage = twl6030ldo_list_voltage,
610 .set_voltage = twl6030ldo_set_voltage,
611 .get_voltage = twl6030ldo_get_voltage,
613 .enable = twl6030reg_enable,
614 .disable = twl6030reg_disable,
615 .is_enabled = twl6030reg_is_enabled,
617 .set_mode = twl6030reg_set_mode,
619 .get_status = twl6030reg_get_status,
622 /*----------------------------------------------------------------------*/
625 * Fixed voltage LDOs don't have a VSEL field to update.
627 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
629 struct twlreg_info *info = rdev_get_drvdata(rdev);
631 return info->min_mV * 1000;
634 static int twlfixed_get_voltage(struct regulator_dev *rdev)
636 struct twlreg_info *info = rdev_get_drvdata(rdev);
638 return info->min_mV * 1000;
641 static struct regulator_ops twl4030fixed_ops = {
642 .list_voltage = twlfixed_list_voltage,
644 .get_voltage = twlfixed_get_voltage,
646 .enable = twl4030reg_enable,
647 .disable = twl4030reg_disable,
648 .is_enabled = twl4030reg_is_enabled,
650 .set_mode = twl4030reg_set_mode,
652 .get_status = twl4030reg_get_status,
655 static struct regulator_ops twl6030fixed_ops = {
656 .list_voltage = twlfixed_list_voltage,
658 .get_voltage = twlfixed_get_voltage,
660 .enable = twl6030reg_enable,
661 .disable = twl6030reg_disable,
662 .is_enabled = twl6030reg_is_enabled,
664 .set_mode = twl6030reg_set_mode,
666 .get_status = twl6030reg_get_status,
669 static struct regulator_ops twl6030_fixed_resource = {
670 .enable = twl6030reg_enable,
671 .disable = twl6030reg_disable,
672 .is_enabled = twl6030reg_is_enabled,
673 .get_status = twl6030reg_get_status,
677 * SMPS status and control
680 static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
682 struct twlreg_info *info = rdev_get_drvdata(rdev);
686 switch (info->flags) {
696 voltage = 1350 * 1000;
699 voltage = 1500 * 1000;
702 voltage = 1800 * 1000;
705 voltage = 1900 * 1000;
708 voltage = 2100 * 1000;
711 voltage += (600000 + (12500 * (index - 1)));
714 case SMPS_EXTENDED_EN:
720 voltage = 2084 * 1000;
723 voltage = 2315 * 1000;
726 voltage = 2778 * 1000;
729 voltage = 2932 * 1000;
732 voltage = 3241 * 1000;
735 voltage = (1852000 + (38600 * (index - 1)));
738 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
744 voltage = 4167 * 1000;
747 voltage = 2315 * 1000;
750 voltage = 2778 * 1000;
753 voltage = 2932 * 1000;
756 voltage = 3241 * 1000;
759 voltage = (2161000 + (38600 * (index - 1)));
768 twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
769 unsigned int *selector)
771 struct twlreg_info *info = rdev_get_drvdata(rdev);
774 switch (info->flags) {
778 else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
779 vsel = (min_uV - 600000) / 125;
785 /* Values 1..57 for vsel are linear and can be calculated
786 * values 58..62 are non linear.
788 else if ((min_uV > 1900000) && (max_uV >= 2100000))
790 else if ((min_uV > 1800000) && (max_uV >= 1900000))
792 else if ((min_uV > 1500000) && (max_uV >= 1800000))
794 else if ((min_uV > 1350000) && (max_uV >= 1500000))
796 else if ((min_uV > 1300000) && (max_uV >= 1350000))
804 else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
805 vsel = (min_uV - 700000) / 125;
811 /* Values 1..57 for vsel are linear and can be calculated
812 * values 58..62 are non linear.
814 else if ((min_uV > 1900000) && (max_uV >= 2100000))
816 else if ((min_uV > 1800000) && (max_uV >= 1900000))
818 else if ((min_uV > 1350000) && (max_uV >= 1800000))
820 else if ((min_uV > 1350000) && (max_uV >= 1500000))
822 else if ((min_uV > 1300000) && (max_uV >= 1350000))
827 case SMPS_EXTENDED_EN:
830 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
831 vsel = (min_uV - 1852000) / 386;
838 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
841 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
842 vsel = (min_uV - 1852000) / 386;
853 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
857 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
859 struct twlreg_info *info = rdev_get_drvdata(rdev);
861 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
864 static struct regulator_ops twlsmps_ops = {
865 .list_voltage = twl6030smps_list_voltage,
867 .set_voltage = twl6030smps_set_voltage,
868 .get_voltage_sel = twl6030smps_get_voltage_sel,
870 .enable = twl6030reg_enable,
871 .disable = twl6030reg_disable,
872 .is_enabled = twl6030reg_is_enabled,
874 .set_mode = twl6030reg_set_mode,
876 .get_status = twl6030reg_get_status,
879 /*----------------------------------------------------------------------*/
881 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
883 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
884 remap_conf, TWL4030, twl4030fixed_ops)
885 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
886 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
887 0x0, TWL6030, twl6030fixed_ops)
889 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
892 .table_len = ARRAY_SIZE(label##_VSEL_table), \
893 .table = label##_VSEL_table, \
894 .delay = turnon_delay, \
895 .remap = remap_conf, \
898 .id = TWL4030_REG_##label, \
899 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
900 .ops = &twl4030ldo_ops, \
901 .type = REGULATOR_VOLTAGE, \
902 .owner = THIS_MODULE, \
906 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
910 .delay = turnon_delay, \
911 .remap = remap_conf, \
914 .id = TWL4030_REG_##label, \
915 .ops = &twl4030smps_ops, \
916 .type = REGULATOR_VOLTAGE, \
917 .owner = THIS_MODULE, \
921 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
923 .min_mV = min_mVolts, \
924 .max_mV = max_mVolts, \
927 .id = TWL6030_REG_##label, \
928 .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \
929 .ops = &twl6030ldo_ops, \
930 .type = REGULATOR_VOLTAGE, \
931 .owner = THIS_MODULE, \
935 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
937 .min_mV = min_mVolts, \
938 .max_mV = max_mVolts, \
941 .id = TWL6025_REG_##label, \
942 .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \
943 .ops = &twl6030ldo_ops, \
944 .type = REGULATOR_VOLTAGE, \
945 .owner = THIS_MODULE, \
949 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
950 family, operations) { \
954 .delay = turnon_delay, \
955 .remap = remap_conf, \
958 .id = family##_REG_##label, \
960 .ops = &operations, \
961 .type = REGULATOR_VOLTAGE, \
962 .owner = THIS_MODULE, \
966 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \
968 .delay = turnon_delay, \
971 .id = TWL6030_REG_##label, \
972 .ops = &twl6030_fixed_resource, \
973 .type = REGULATOR_VOLTAGE, \
974 .owner = THIS_MODULE, \
978 #define TWL6025_ADJUSTABLE_SMPS(label, offset) { \
984 .id = TWL6025_REG_##label, \
986 .ops = &twlsmps_ops, \
987 .type = REGULATOR_VOLTAGE, \
988 .owner = THIS_MODULE, \
993 * We list regulators here if systems need some level of
994 * software control over them after boot.
996 static struct twlreg_info twl_regs[] = {
997 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
998 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
999 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
1000 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
1001 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
1002 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
1003 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
1004 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
1005 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
1006 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
1007 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
1008 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
1009 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
1010 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
1011 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
1012 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08),
1013 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08),
1014 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
1015 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
1016 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
1017 /* VUSBCP is managed *only* by the USB subchip */
1019 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1020 /* Turnon-delay and remap configuration values for 6030 are not
1021 verified since the specification is not public */
1022 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300),
1023 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300),
1024 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300),
1025 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300),
1026 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300),
1027 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300),
1028 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0),
1029 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0),
1030 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0),
1031 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0),
1032 TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0),
1034 /* 6025 are renamed compared to 6030 versions */
1035 TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300),
1036 TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300),
1037 TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300),
1038 TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300),
1039 TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300),
1040 TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300),
1041 TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300),
1042 TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300),
1043 TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300),
1045 TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34),
1046 TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10),
1047 TWL6025_ADJUSTABLE_SMPS(VIO, 0x16),
1050 static u8 twl_get_smps_offset(void)
1054 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1055 TWL6030_SMPS_OFFSET);
1059 static u8 twl_get_smps_mult(void)
1063 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1068 static int __devinit twlreg_probe(struct platform_device *pdev)
1071 struct twlreg_info *info;
1072 struct regulator_init_data *initdata;
1073 struct regulation_constraints *c;
1074 struct regulator_dev *rdev;
1075 struct twl_regulator_driver_data *drvdata;
1077 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
1078 if (twl_regs[i].desc.id != pdev->id)
1080 info = twl_regs + i;
1086 initdata = pdev->dev.platform_data;
1090 drvdata = initdata->driver_data;
1095 /* copy the driver data into regulator data */
1096 info->features = drvdata->features;
1097 info->data = drvdata->data;
1098 info->set_voltage = drvdata->set_voltage;
1099 info->get_voltage = drvdata->get_voltage;
1101 /* Constrain board-specific capabilities according to what
1102 * this driver and the chip itself can actually do.
1104 c = &initdata->constraints;
1105 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1106 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1107 | REGULATOR_CHANGE_MODE
1108 | REGULATOR_CHANGE_STATUS;
1110 case TWL4030_REG_VIO:
1111 case TWL4030_REG_VDD1:
1112 case TWL4030_REG_VDD2:
1113 case TWL4030_REG_VPLL1:
1114 case TWL4030_REG_VINTANA1:
1115 case TWL4030_REG_VINTANA2:
1116 case TWL4030_REG_VINTDIG:
1117 c->always_on = true;
1124 case TWL6025_REG_SMPS3:
1125 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1126 info->flags |= SMPS_EXTENDED_EN;
1127 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1128 info->flags |= SMPS_OFFSET_EN;
1130 case TWL6025_REG_SMPS4:
1131 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1132 info->flags |= SMPS_EXTENDED_EN;
1133 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1134 info->flags |= SMPS_OFFSET_EN;
1136 case TWL6025_REG_VIO:
1137 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1138 info->flags |= SMPS_EXTENDED_EN;
1139 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1140 info->flags |= SMPS_OFFSET_EN;
1144 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
1146 dev_err(&pdev->dev, "can't register %s, %ld\n",
1147 info->desc.name, PTR_ERR(rdev));
1148 return PTR_ERR(rdev);
1150 platform_set_drvdata(pdev, rdev);
1152 if (twl_class_is_4030())
1153 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
1156 /* NOTE: many regulators support short-circuit IRQs (presentable
1157 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1159 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1160 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1167 static int __devexit twlreg_remove(struct platform_device *pdev)
1169 regulator_unregister(platform_get_drvdata(pdev));
1173 MODULE_ALIAS("platform:twl_reg");
1175 static struct platform_driver twlreg_driver = {
1176 .probe = twlreg_probe,
1177 .remove = __devexit_p(twlreg_remove),
1178 /* NOTE: short name, to work around driver model truncation of
1179 * "twl_regulator.12" (and friends) to "twl_regulator.1".
1181 .driver.name = "twl_reg",
1182 .driver.owner = THIS_MODULE,
1185 static int __init twlreg_init(void)
1187 return platform_driver_register(&twlreg_driver);
1189 subsys_initcall(twlreg_init);
1191 static void __exit twlreg_exit(void)
1193 platform_driver_unregister(&twlreg_driver);
1195 module_exit(twlreg_exit)
1197 MODULE_DESCRIPTION("TWL regulator driver");
1198 MODULE_LICENSE("GPL");