2 * twl-regulator.c -- support regulators in twl4030/twl6030 family chips
4 * Copyright (C) 2008 David Brownell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/slab.h>
15 #include <linux/init.h>
16 #include <linux/err.h>
17 #include <linux/platform_device.h>
19 #include <linux/of_device.h>
20 #include <linux/regulator/driver.h>
21 #include <linux/regulator/machine.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/i2c/twl.h>
27 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
28 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
29 * include an audio codec, battery charger, and more voltage regulators.
30 * These chips are often used in OMAP-based systems.
32 * This driver implements software-based resource control for various
33 * voltage regulators. This is usually augmented with state machine
38 /* start of regulator's PM_RECEIVER control register bank */
41 /* twl resource ID, for resource control state machine */
44 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
48 /* State REMAP default configuration */
51 /* chip constraints on regulator behavior */
57 /* used by regulator core */
58 struct regulator_desc desc;
60 /* chip specific features */
61 unsigned long features;
64 * optional override functions for voltage set/get
65 * these are currently only used for SMPS regulators
67 int (*get_voltage)(void *data);
68 int (*set_voltage)(void *data, int target_uV);
70 /* data passed from board for external get/set voltage */
75 /* LDO control registers ... offset is from the base of its register bank.
76 * The first three registers of all power resource banks help hardware to
77 * manage the various resource groups.
79 /* Common offset in TWL4030/6030 */
81 /* TWL4030 register offsets */
84 #define VREG_DEDICATED 3 /* LDO control */
85 #define VREG_VOLTAGE_SMPS_4030 9
86 /* TWL6030 register offsets */
89 #define VREG_VOLTAGE 3
90 #define VREG_VOLTAGE_SMPS 4
91 /* TWL6030 Misc register offsets */
94 #define VREG_BC_PROC 3
95 #define VREG_BC_CLK_RST 4
97 /* TWL6030 LDO register values for CFG_STATE */
98 #define TWL6030_CFG_STATE_OFF 0x00
99 #define TWL6030_CFG_STATE_ON 0x01
100 #define TWL6030_CFG_STATE_OFF2 0x02
101 #define TWL6030_CFG_STATE_SLEEP 0x03
102 #define TWL6030_CFG_STATE_GRP_SHIFT 5
103 #define TWL6030_CFG_STATE_APP_SHIFT 2
104 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
105 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
106 TWL6030_CFG_STATE_APP_SHIFT)
108 /* Flags for SMPS Voltage reading */
109 #define SMPS_OFFSET_EN BIT(0)
110 #define SMPS_EXTENDED_EN BIT(1)
112 /* twl6025 SMPS EPROM values */
113 #define TWL6030_SMPS_OFFSET 0xB0
114 #define TWL6030_SMPS_MULT 0xB3
115 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
116 #define SMPS_MULTOFFSET_VIO BIT(1)
117 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
120 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
125 status = twl_i2c_read_u8(slave_subgp,
126 &value, info->base + offset);
127 return (status < 0) ? status : value;
131 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
134 return twl_i2c_write_u8(slave_subgp,
135 value, info->base + offset);
138 /*----------------------------------------------------------------------*/
140 /* generic power resource operations, which work on all regulators */
142 static int twlreg_grp(struct regulator_dev *rdev)
144 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
149 * Enable/disable regulators by joining/leaving the P1 (processor) group.
150 * We assume nobody else is updating the DEV_GRP registers.
152 /* definition for 4030 family */
153 #define P3_GRP_4030 BIT(7) /* "peripherals" */
154 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
155 #define P1_GRP_4030 BIT(5) /* CPU/Linux */
156 /* definition for 6030 family */
157 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
158 #define P2_GRP_6030 BIT(1) /* "peripherals" */
159 #define P1_GRP_6030 BIT(0) /* CPU/Linux */
161 static int twl4030reg_is_enabled(struct regulator_dev *rdev)
163 int state = twlreg_grp(rdev);
168 return state & P1_GRP_4030;
171 static int twl6030reg_is_enabled(struct regulator_dev *rdev)
173 struct twlreg_info *info = rdev_get_drvdata(rdev);
176 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) {
177 grp = twlreg_grp(rdev);
185 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
186 val = TWL6030_CFG_STATE_APP(val);
188 return grp && (val == TWL6030_CFG_STATE_ON);
191 static int twl4030reg_enable(struct regulator_dev *rdev)
193 struct twlreg_info *info = rdev_get_drvdata(rdev);
197 grp = twlreg_grp(rdev);
203 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
208 static int twl6030reg_enable(struct regulator_dev *rdev)
210 struct twlreg_info *info = rdev_get_drvdata(rdev);
214 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
215 grp = twlreg_grp(rdev);
219 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
220 grp << TWL6030_CFG_STATE_GRP_SHIFT |
221 TWL6030_CFG_STATE_ON);
225 static int twl4030reg_disable(struct regulator_dev *rdev)
227 struct twlreg_info *info = rdev_get_drvdata(rdev);
231 grp = twlreg_grp(rdev);
235 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
237 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
242 static int twl6030reg_disable(struct regulator_dev *rdev)
244 struct twlreg_info *info = rdev_get_drvdata(rdev);
248 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
249 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
251 /* For 6030, set the off state for all grps enabled */
252 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
253 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
254 TWL6030_CFG_STATE_OFF);
259 static int twl4030reg_get_status(struct regulator_dev *rdev)
261 int state = twlreg_grp(rdev);
267 /* assume state != WARM_RESET; we'd not be running... */
269 return REGULATOR_STATUS_OFF;
270 return (state & BIT(3))
271 ? REGULATOR_STATUS_NORMAL
272 : REGULATOR_STATUS_STANDBY;
275 static int twl6030reg_get_status(struct regulator_dev *rdev)
277 struct twlreg_info *info = rdev_get_drvdata(rdev);
280 val = twlreg_grp(rdev);
284 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
286 switch (TWL6030_CFG_STATE_APP(val)) {
287 case TWL6030_CFG_STATE_ON:
288 return REGULATOR_STATUS_NORMAL;
290 case TWL6030_CFG_STATE_SLEEP:
291 return REGULATOR_STATUS_STANDBY;
293 case TWL6030_CFG_STATE_OFF:
294 case TWL6030_CFG_STATE_OFF2:
299 return REGULATOR_STATUS_OFF;
302 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
304 struct twlreg_info *info = rdev_get_drvdata(rdev);
308 /* We can only set the mode through state machine commands... */
310 case REGULATOR_MODE_NORMAL:
311 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
313 case REGULATOR_MODE_STANDBY:
314 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
320 /* Ensure the resource is associated with some group */
321 status = twlreg_grp(rdev);
324 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
327 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
328 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
332 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
333 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
336 static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
338 struct twlreg_info *info = rdev_get_drvdata(rdev);
342 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
343 grp = twlreg_grp(rdev);
348 /* Compose the state register settings */
349 val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
350 /* We can only set the mode through state machine commands... */
352 case REGULATOR_MODE_NORMAL:
353 val |= TWL6030_CFG_STATE_ON;
355 case REGULATOR_MODE_STANDBY:
356 val |= TWL6030_CFG_STATE_SLEEP;
363 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
366 /*----------------------------------------------------------------------*/
369 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
370 * select field in its control register. We use tables indexed by VSEL
371 * to record voltages in milliVolts. (Accuracy is about three percent.)
373 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
374 * currently handled by listing two slightly different VAUX2 regulators,
375 * only one of which will be configured.
377 * VSEL values documented as "TI cannot support these values" are flagged
378 * in these tables as UNSUP() values; we normally won't assign them.
380 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
381 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
383 #define UNSUP_MASK 0x8000
385 #define UNSUP(x) (UNSUP_MASK | (x))
386 #define IS_UNSUP(info, x) \
387 ((UNSUP_MASK & (x)) && \
388 !((info)->features & TWL4030_ALLOW_UNSUPPORTED))
389 #define LDO_MV(x) (~UNSUP_MASK & (x))
392 static const u16 VAUX1_VSEL_table[] = {
393 UNSUP(1500), UNSUP(1800), 2500, 2800,
394 3000, 3000, 3000, 3000,
396 static const u16 VAUX2_4030_VSEL_table[] = {
397 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
398 1500, 1800, UNSUP(1850), 2500,
399 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
400 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
402 static const u16 VAUX2_VSEL_table[] = {
403 1700, 1700, 1900, 1300,
404 1500, 1800, 2000, 2500,
405 2100, 2800, 2200, 2300,
406 2400, 2400, 2400, 2400,
408 static const u16 VAUX3_VSEL_table[] = {
409 1500, 1800, 2500, 2800,
410 3000, 3000, 3000, 3000,
412 static const u16 VAUX4_VSEL_table[] = {
413 700, 1000, 1200, UNSUP(1300),
414 1500, 1800, UNSUP(1850), 2500,
415 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
416 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
418 static const u16 VMMC1_VSEL_table[] = {
419 1850, 2850, 3000, 3150,
421 static const u16 VMMC2_VSEL_table[] = {
422 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
423 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
424 2600, 2800, 2850, 3000,
425 3150, 3150, 3150, 3150,
427 static const u16 VPLL1_VSEL_table[] = {
428 1000, 1200, 1300, 1800,
429 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
431 static const u16 VPLL2_VSEL_table[] = {
432 700, 1000, 1200, 1300,
433 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
434 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
435 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
437 static const u16 VSIM_VSEL_table[] = {
438 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
439 2800, 3000, 3000, 3000,
441 static const u16 VDAC_VSEL_table[] = {
442 1200, 1300, 1800, 1800,
444 static const u16 VDD1_VSEL_table[] = {
447 static const u16 VDD2_VSEL_table[] = {
450 static const u16 VIO_VSEL_table[] = {
453 static const u16 VINTANA2_VSEL_table[] = {
457 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
459 struct twlreg_info *info = rdev_get_drvdata(rdev);
460 int mV = info->table[index];
462 return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000);
466 twl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
468 struct twlreg_info *info = rdev_get_drvdata(rdev);
470 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
474 static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
476 struct twlreg_info *info = rdev_get_drvdata(rdev);
477 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
483 vsel &= info->table_len - 1;
484 return LDO_MV(info->table[vsel]) * 1000;
487 static struct regulator_ops twl4030ldo_ops = {
488 .list_voltage = twl4030ldo_list_voltage,
490 .set_voltage_sel = twl4030ldo_set_voltage_sel,
491 .get_voltage = twl4030ldo_get_voltage,
493 .enable = twl4030reg_enable,
494 .disable = twl4030reg_disable,
495 .is_enabled = twl4030reg_is_enabled,
497 .set_mode = twl4030reg_set_mode,
499 .get_status = twl4030reg_get_status,
503 twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
506 struct twlreg_info *info = rdev_get_drvdata(rdev);
507 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
509 if (info->set_voltage) {
510 return info->set_voltage(info->data, min_uV);
512 twlreg_write(info, TWL_MODULE_PM_RECEIVER,
513 VREG_VOLTAGE_SMPS_4030, vsel);
519 static int twl4030smps_get_voltage(struct regulator_dev *rdev)
521 struct twlreg_info *info = rdev_get_drvdata(rdev);
524 if (info->get_voltage)
525 return info->get_voltage(info->data);
527 vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
528 VREG_VOLTAGE_SMPS_4030);
530 return vsel * 12500 + 600000;
533 static struct regulator_ops twl4030smps_ops = {
534 .set_voltage = twl4030smps_set_voltage,
535 .get_voltage = twl4030smps_get_voltage,
538 static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV,
539 int max_uV, unsigned *selector)
541 struct twlreg_info *info = rdev_get_drvdata(rdev);
543 if (info->set_voltage)
544 return info->set_voltage(info->data, min_uV);
549 static int twl6030coresmps_get_voltage(struct regulator_dev *rdev)
551 struct twlreg_info *info = rdev_get_drvdata(rdev);
553 if (info->get_voltage)
554 return info->get_voltage(info->data);
559 static struct regulator_ops twl6030coresmps_ops = {
560 .set_voltage = twl6030coresmps_set_voltage,
561 .get_voltage = twl6030coresmps_get_voltage,
564 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel)
566 struct twlreg_info *info = rdev_get_drvdata(rdev);
572 /* Linear mapping from 00000001 to 00011000:
573 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001)
575 return (info->min_mV + 100 * (sel - 1)) * 1000;
586 twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
588 struct twlreg_info *info = rdev_get_drvdata(rdev);
590 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
594 static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev)
596 struct twlreg_info *info = rdev_get_drvdata(rdev);
597 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE);
602 static struct regulator_ops twl6030ldo_ops = {
603 .list_voltage = twl6030ldo_list_voltage,
605 .set_voltage_sel = twl6030ldo_set_voltage_sel,
606 .get_voltage_sel = twl6030ldo_get_voltage_sel,
608 .enable = twl6030reg_enable,
609 .disable = twl6030reg_disable,
610 .is_enabled = twl6030reg_is_enabled,
612 .set_mode = twl6030reg_set_mode,
614 .get_status = twl6030reg_get_status,
617 /*----------------------------------------------------------------------*/
620 * Fixed voltage LDOs don't have a VSEL field to update.
622 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
624 struct twlreg_info *info = rdev_get_drvdata(rdev);
626 return info->min_mV * 1000;
629 static struct regulator_ops twl4030fixed_ops = {
630 .list_voltage = twlfixed_list_voltage,
632 .enable = twl4030reg_enable,
633 .disable = twl4030reg_disable,
634 .is_enabled = twl4030reg_is_enabled,
636 .set_mode = twl4030reg_set_mode,
638 .get_status = twl4030reg_get_status,
641 static struct regulator_ops twl6030fixed_ops = {
642 .list_voltage = twlfixed_list_voltage,
644 .enable = twl6030reg_enable,
645 .disable = twl6030reg_disable,
646 .is_enabled = twl6030reg_is_enabled,
648 .set_mode = twl6030reg_set_mode,
650 .get_status = twl6030reg_get_status,
654 * SMPS status and control
657 static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
659 struct twlreg_info *info = rdev_get_drvdata(rdev);
663 switch (info->flags) {
673 voltage = 1350 * 1000;
676 voltage = 1500 * 1000;
679 voltage = 1800 * 1000;
682 voltage = 1900 * 1000;
685 voltage = 2100 * 1000;
688 voltage += (600000 + (12500 * (index - 1)));
691 case SMPS_EXTENDED_EN:
697 voltage = 2084 * 1000;
700 voltage = 2315 * 1000;
703 voltage = 2778 * 1000;
706 voltage = 2932 * 1000;
709 voltage = 3241 * 1000;
712 voltage = (1852000 + (38600 * (index - 1)));
715 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
721 voltage = 4167 * 1000;
724 voltage = 2315 * 1000;
727 voltage = 2778 * 1000;
730 voltage = 2932 * 1000;
733 voltage = 3241 * 1000;
736 voltage = (2161000 + (38600 * (index - 1)));
744 static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
747 struct twlreg_info *info = rdev_get_drvdata(rdev);
750 switch (info->flags) {
754 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
755 vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
758 /* Values 1..57 for vsel are linear and can be calculated
759 * values 58..62 are non linear.
761 else if ((min_uV > 1900000) && (min_uV <= 2100000))
763 else if ((min_uV > 1800000) && (min_uV <= 1900000))
765 else if ((min_uV > 1500000) && (min_uV <= 1800000))
767 else if ((min_uV > 1350000) && (min_uV <= 1500000))
769 else if ((min_uV > 1300000) && (min_uV <= 1350000))
777 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
778 vsel = DIV_ROUND_UP(min_uV - 700000, 12500);
781 /* Values 1..57 for vsel are linear and can be calculated
782 * values 58..62 are non linear.
784 else if ((min_uV > 1900000) && (min_uV <= 2100000))
786 else if ((min_uV > 1800000) && (min_uV <= 1900000))
788 else if ((min_uV > 1350000) && (min_uV <= 1800000))
790 else if ((min_uV > 1350000) && (min_uV <= 1500000))
792 else if ((min_uV > 1300000) && (min_uV <= 1350000))
797 case SMPS_EXTENDED_EN:
800 } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
801 vsel = DIV_ROUND_UP(min_uV - 1852000, 38600);
805 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
808 } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) {
809 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600);
818 static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
819 unsigned int selector)
821 struct twlreg_info *info = rdev_get_drvdata(rdev);
823 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
827 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
829 struct twlreg_info *info = rdev_get_drvdata(rdev);
831 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
834 static struct regulator_ops twlsmps_ops = {
835 .list_voltage = twl6030smps_list_voltage,
836 .map_voltage = twl6030smps_map_voltage,
838 .set_voltage_sel = twl6030smps_set_voltage_sel,
839 .get_voltage_sel = twl6030smps_get_voltage_sel,
841 .enable = twl6030reg_enable,
842 .disable = twl6030reg_disable,
843 .is_enabled = twl6030reg_is_enabled,
845 .set_mode = twl6030reg_set_mode,
847 .get_status = twl6030reg_get_status,
850 /*----------------------------------------------------------------------*/
852 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
854 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
855 remap_conf, TWL4030, twl4030fixed_ops)
856 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
857 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
858 0x0, TWL6030, twl6030fixed_ops)
860 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
861 static const struct twlreg_info TWL4030_INFO_##label = { \
864 .table_len = ARRAY_SIZE(label##_VSEL_table), \
865 .table = label##_VSEL_table, \
866 .remap = remap_conf, \
869 .id = TWL4030_REG_##label, \
870 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
871 .ops = &twl4030ldo_ops, \
872 .type = REGULATOR_VOLTAGE, \
873 .owner = THIS_MODULE, \
874 .enable_time = turnon_delay, \
878 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
879 static const struct twlreg_info TWL4030_INFO_##label = { \
882 .remap = remap_conf, \
885 .id = TWL4030_REG_##label, \
886 .ops = &twl4030smps_ops, \
887 .type = REGULATOR_VOLTAGE, \
888 .owner = THIS_MODULE, \
889 .enable_time = turnon_delay, \
893 #define TWL6030_ADJUSTABLE_SMPS(label) \
894 static const struct twlreg_info TWL6030_INFO_##label = { \
897 .id = TWL6030_REG_##label, \
898 .ops = &twl6030coresmps_ops, \
899 .type = REGULATOR_VOLTAGE, \
900 .owner = THIS_MODULE, \
904 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
905 static const struct twlreg_info TWL6030_INFO_##label = { \
907 .min_mV = min_mVolts, \
908 .max_mV = max_mVolts, \
911 .id = TWL6030_REG_##label, \
913 .ops = &twl6030ldo_ops, \
914 .type = REGULATOR_VOLTAGE, \
915 .owner = THIS_MODULE, \
919 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
920 static const struct twlreg_info TWL6025_INFO_##label = { \
922 .min_mV = min_mVolts, \
923 .max_mV = max_mVolts, \
926 .id = TWL6025_REG_##label, \
928 .ops = &twl6030ldo_ops, \
929 .type = REGULATOR_VOLTAGE, \
930 .owner = THIS_MODULE, \
934 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
935 family, operations) \
936 static const struct twlreg_info TWLFIXED_INFO_##label = { \
940 .remap = remap_conf, \
943 .id = family##_REG_##label, \
945 .ops = &operations, \
946 .type = REGULATOR_VOLTAGE, \
947 .owner = THIS_MODULE, \
948 .enable_time = turnon_delay, \
952 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
953 static struct twlreg_info TWLRES_INFO_##label = { \
957 .id = TWL6030_REG_##label, \
958 .ops = &twl6030_fixed_resource, \
959 .type = REGULATOR_VOLTAGE, \
960 .owner = THIS_MODULE, \
961 .enable_time = turnon_delay, \
965 #define TWL6025_ADJUSTABLE_SMPS(label, offset) \
966 static const struct twlreg_info TWLSMPS_INFO_##label = { \
972 .id = TWL6025_REG_##label, \
974 .ops = &twlsmps_ops, \
975 .type = REGULATOR_VOLTAGE, \
976 .owner = THIS_MODULE, \
981 * We list regulators here if systems need some level of
982 * software control over them after boot.
984 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08);
985 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08);
986 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08);
987 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08);
988 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08);
989 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08);
990 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08);
991 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00);
992 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08);
993 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00);
994 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08);
995 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08);
996 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08);
997 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08);
998 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08);
999 /* VUSBCP is managed *only* by the USB subchip */
1000 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1001 /* Turnon-delay and remap configuration values for 6030 are not
1002 verified since the specification is not public */
1003 TWL6030_ADJUSTABLE_SMPS(VDD1);
1004 TWL6030_ADJUSTABLE_SMPS(VDD2);
1005 TWL6030_ADJUSTABLE_SMPS(VDD3);
1006 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300);
1007 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300);
1008 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300);
1009 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300);
1010 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300);
1011 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300);
1012 /* 6025 are renamed compared to 6030 versions */
1013 TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300);
1014 TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300);
1015 TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300);
1016 TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300);
1017 TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300);
1018 TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300);
1019 TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300);
1020 TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300);
1021 TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300);
1022 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08);
1023 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08);
1024 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08);
1025 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08);
1026 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08);
1027 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0);
1028 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0);
1029 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
1030 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0);
1031 TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0);
1032 TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0);
1033 TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34);
1034 TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10);
1035 TWL6025_ADJUSTABLE_SMPS(VIO, 0x16);
1037 static u8 twl_get_smps_offset(void)
1041 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1042 TWL6030_SMPS_OFFSET);
1046 static u8 twl_get_smps_mult(void)
1050 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1055 #define TWL_OF_MATCH(comp, family, label) \
1057 .compatible = comp, \
1058 .data = &family##_INFO_##label, \
1061 #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
1062 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1063 #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
1064 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
1065 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1067 static const struct of_device_id twl_of_match[] __devinitconst = {
1068 TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1),
1069 TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030),
1070 TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2),
1071 TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3),
1072 TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4),
1073 TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1),
1074 TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2),
1075 TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1),
1076 TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2),
1077 TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM),
1078 TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC),
1079 TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2),
1080 TWL4030_OF_MATCH("ti,twl4030-vio", VIO),
1081 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1),
1082 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2),
1083 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1),
1084 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2),
1085 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3),
1086 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030),
1087 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030),
1088 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030),
1089 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC),
1090 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP),
1091 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM),
1092 TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2),
1093 TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4),
1094 TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3),
1095 TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5),
1096 TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1),
1097 TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7),
1098 TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6),
1099 TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN),
1100 TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB),
1101 TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1),
1102 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG),
1103 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5),
1104 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8),
1105 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1),
1106 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA),
1107 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO),
1108 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC),
1109 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
1110 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
1111 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
1112 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3),
1113 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4),
1114 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO),
1117 MODULE_DEVICE_TABLE(of, twl_of_match);
1119 static int twlreg_probe(struct platform_device *pdev)
1122 struct twlreg_info *info;
1123 const struct twlreg_info *template;
1124 struct regulator_init_data *initdata;
1125 struct regulation_constraints *c;
1126 struct regulator_dev *rdev;
1127 struct twl_regulator_driver_data *drvdata;
1128 const struct of_device_id *match;
1129 struct regulator_config config = { };
1131 match = of_match_device(twl_of_match, &pdev->dev);
1133 template = match->data;
1134 id = template->desc.id;
1135 initdata = of_get_regulator_init_data(&pdev->dev,
1140 initdata = pdev->dev.platform_data;
1141 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
1142 template = twl_of_match[i].data;
1143 if (template && template->desc.id == id)
1146 if (i == ARRAY_SIZE(twl_of_match))
1149 drvdata = initdata->driver_data;
1160 info = kmemdup(template, sizeof (*info), GFP_KERNEL);
1165 /* copy the driver data into regulator data */
1166 info->features = drvdata->features;
1167 info->data = drvdata->data;
1168 info->set_voltage = drvdata->set_voltage;
1169 info->get_voltage = drvdata->get_voltage;
1172 /* Constrain board-specific capabilities according to what
1173 * this driver and the chip itself can actually do.
1175 c = &initdata->constraints;
1176 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1177 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1178 | REGULATOR_CHANGE_MODE
1179 | REGULATOR_CHANGE_STATUS;
1181 case TWL4030_REG_VIO:
1182 case TWL4030_REG_VDD1:
1183 case TWL4030_REG_VDD2:
1184 case TWL4030_REG_VPLL1:
1185 case TWL4030_REG_VINTANA1:
1186 case TWL4030_REG_VINTANA2:
1187 case TWL4030_REG_VINTDIG:
1188 c->always_on = true;
1195 case TWL6025_REG_SMPS3:
1196 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1197 info->flags |= SMPS_EXTENDED_EN;
1198 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1199 info->flags |= SMPS_OFFSET_EN;
1201 case TWL6025_REG_SMPS4:
1202 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1203 info->flags |= SMPS_EXTENDED_EN;
1204 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1205 info->flags |= SMPS_OFFSET_EN;
1207 case TWL6025_REG_VIO:
1208 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1209 info->flags |= SMPS_EXTENDED_EN;
1210 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1211 info->flags |= SMPS_OFFSET_EN;
1215 config.dev = &pdev->dev;
1216 config.init_data = initdata;
1217 config.driver_data = info;
1218 config.of_node = pdev->dev.of_node;
1220 rdev = regulator_register(&info->desc, &config);
1222 dev_err(&pdev->dev, "can't register %s, %ld\n",
1223 info->desc.name, PTR_ERR(rdev));
1225 return PTR_ERR(rdev);
1227 platform_set_drvdata(pdev, rdev);
1229 if (twl_class_is_4030())
1230 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
1233 /* NOTE: many regulators support short-circuit IRQs (presentable
1234 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1236 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1237 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1244 static int twlreg_remove(struct platform_device *pdev)
1246 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1247 struct twlreg_info *info = rdev->reg_data;
1249 regulator_unregister(rdev);
1254 MODULE_ALIAS("platform:twl_reg");
1256 static struct platform_driver twlreg_driver = {
1257 .probe = twlreg_probe,
1258 .remove = twlreg_remove,
1259 /* NOTE: short name, to work around driver model truncation of
1260 * "twl_regulator.12" (and friends) to "twl_regulator.1".
1264 .owner = THIS_MODULE,
1265 .of_match_table = of_match_ptr(twl_of_match),
1269 static int __init twlreg_init(void)
1271 return platform_driver_register(&twlreg_driver);
1273 subsys_initcall(twlreg_init);
1275 static void __exit twlreg_exit(void)
1277 platform_driver_unregister(&twlreg_driver);
1279 module_exit(twlreg_exit)
1281 MODULE_DESCRIPTION("TWL regulator driver");
1282 MODULE_LICENSE("GPL");