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 /* State REMAP default configuration */
49 /* chip constraints on regulator behavior */
55 /* used by regulator core */
56 struct regulator_desc desc;
58 /* chip specific features */
59 unsigned long features;
62 * optional override functions for voltage set/get
63 * these are currently only used for SMPS regulators
65 int (*get_voltage)(void *data);
66 int (*set_voltage)(void *data, int target_uV);
68 /* data passed from board for external get/set voltage */
73 /* LDO control registers ... offset is from the base of its register bank.
74 * The first three registers of all power resource banks help hardware to
75 * manage the various resource groups.
77 /* Common offset in TWL4030/6030 */
79 /* TWL4030 register offsets */
82 #define VREG_DEDICATED 3 /* LDO control */
83 #define VREG_VOLTAGE_SMPS_4030 9
84 /* TWL6030 register offsets */
87 #define VREG_VOLTAGE 3
88 #define VREG_VOLTAGE_SMPS 4
89 /* TWL6030 Misc register offsets */
92 #define VREG_BC_PROC 3
93 #define VREG_BC_CLK_RST 4
95 /* TWL6030 LDO register values for CFG_STATE */
96 #define TWL6030_CFG_STATE_OFF 0x00
97 #define TWL6030_CFG_STATE_ON 0x01
98 #define TWL6030_CFG_STATE_OFF2 0x02
99 #define TWL6030_CFG_STATE_SLEEP 0x03
100 #define TWL6030_CFG_STATE_GRP_SHIFT 5
101 #define TWL6030_CFG_STATE_APP_SHIFT 2
102 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
103 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
104 TWL6030_CFG_STATE_APP_SHIFT)
106 /* Flags for SMPS Voltage reading */
107 #define SMPS_OFFSET_EN BIT(0)
108 #define SMPS_EXTENDED_EN BIT(1)
110 /* twl6025 SMPS EPROM values */
111 #define TWL6030_SMPS_OFFSET 0xB0
112 #define TWL6030_SMPS_MULT 0xB3
113 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
114 #define SMPS_MULTOFFSET_VIO BIT(1)
115 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
118 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
123 status = twl_i2c_read_u8(slave_subgp,
124 &value, info->base + offset);
125 return (status < 0) ? status : value;
129 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
132 return twl_i2c_write_u8(slave_subgp,
133 value, info->base + offset);
136 /*----------------------------------------------------------------------*/
138 /* generic power resource operations, which work on all regulators */
140 static int twlreg_grp(struct regulator_dev *rdev)
142 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
147 * Enable/disable regulators by joining/leaving the P1 (processor) group.
148 * We assume nobody else is updating the DEV_GRP registers.
150 /* definition for 4030 family */
151 #define P3_GRP_4030 BIT(7) /* "peripherals" */
152 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
153 #define P1_GRP_4030 BIT(5) /* CPU/Linux */
154 /* definition for 6030 family */
155 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
156 #define P2_GRP_6030 BIT(1) /* "peripherals" */
157 #define P1_GRP_6030 BIT(0) /* CPU/Linux */
159 static int twl4030reg_is_enabled(struct regulator_dev *rdev)
161 int state = twlreg_grp(rdev);
166 return state & P1_GRP_4030;
169 static int twl6030reg_is_enabled(struct regulator_dev *rdev)
171 struct twlreg_info *info = rdev_get_drvdata(rdev);
174 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) {
175 grp = twlreg_grp(rdev);
183 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
184 val = TWL6030_CFG_STATE_APP(val);
186 return grp && (val == TWL6030_CFG_STATE_ON);
189 static int twl4030reg_enable(struct regulator_dev *rdev)
191 struct twlreg_info *info = rdev_get_drvdata(rdev);
195 grp = twlreg_grp(rdev);
201 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
206 static int twl6030reg_enable(struct regulator_dev *rdev)
208 struct twlreg_info *info = rdev_get_drvdata(rdev);
212 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
213 grp = twlreg_grp(rdev);
217 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
218 grp << TWL6030_CFG_STATE_GRP_SHIFT |
219 TWL6030_CFG_STATE_ON);
223 static int twl4030reg_disable(struct regulator_dev *rdev)
225 struct twlreg_info *info = rdev_get_drvdata(rdev);
229 grp = twlreg_grp(rdev);
233 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
235 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
240 static int twl6030reg_disable(struct regulator_dev *rdev)
242 struct twlreg_info *info = rdev_get_drvdata(rdev);
246 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
247 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
249 /* For 6030, set the off state for all grps enabled */
250 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
251 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
252 TWL6030_CFG_STATE_OFF);
257 static int twl4030reg_get_status(struct regulator_dev *rdev)
259 int state = twlreg_grp(rdev);
265 /* assume state != WARM_RESET; we'd not be running... */
267 return REGULATOR_STATUS_OFF;
268 return (state & BIT(3))
269 ? REGULATOR_STATUS_NORMAL
270 : REGULATOR_STATUS_STANDBY;
273 static int twl6030reg_get_status(struct regulator_dev *rdev)
275 struct twlreg_info *info = rdev_get_drvdata(rdev);
278 val = twlreg_grp(rdev);
282 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
284 switch (TWL6030_CFG_STATE_APP(val)) {
285 case TWL6030_CFG_STATE_ON:
286 return REGULATOR_STATUS_NORMAL;
288 case TWL6030_CFG_STATE_SLEEP:
289 return REGULATOR_STATUS_STANDBY;
291 case TWL6030_CFG_STATE_OFF:
292 case TWL6030_CFG_STATE_OFF2:
297 return REGULATOR_STATUS_OFF;
300 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
302 struct twlreg_info *info = rdev_get_drvdata(rdev);
306 /* We can only set the mode through state machine commands... */
308 case REGULATOR_MODE_NORMAL:
309 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
311 case REGULATOR_MODE_STANDBY:
312 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
318 /* Ensure the resource is associated with some group */
319 status = twlreg_grp(rdev);
322 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
325 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
326 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
330 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
331 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
334 static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
336 struct twlreg_info *info = rdev_get_drvdata(rdev);
340 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
341 grp = twlreg_grp(rdev);
346 /* Compose the state register settings */
347 val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
348 /* We can only set the mode through state machine commands... */
350 case REGULATOR_MODE_NORMAL:
351 val |= TWL6030_CFG_STATE_ON;
353 case REGULATOR_MODE_STANDBY:
354 val |= TWL6030_CFG_STATE_SLEEP;
361 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
364 /*----------------------------------------------------------------------*/
367 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
368 * select field in its control register. We use tables indexed by VSEL
369 * to record voltages in milliVolts. (Accuracy is about three percent.)
371 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
372 * currently handled by listing two slightly different VAUX2 regulators,
373 * only one of which will be configured.
375 * VSEL values documented as "TI cannot support these values" are flagged
376 * in these tables as UNSUP() values; we normally won't assign them.
378 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
379 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
381 #define UNSUP_MASK 0x8000
383 #define UNSUP(x) (UNSUP_MASK | (x))
384 #define IS_UNSUP(info, x) \
385 ((UNSUP_MASK & (x)) && \
386 !((info)->features & TWL4030_ALLOW_UNSUPPORTED))
387 #define LDO_MV(x) (~UNSUP_MASK & (x))
390 static const u16 VAUX1_VSEL_table[] = {
391 UNSUP(1500), UNSUP(1800), 2500, 2800,
392 3000, 3000, 3000, 3000,
394 static const u16 VAUX2_4030_VSEL_table[] = {
395 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
396 1500, 1800, UNSUP(1850), 2500,
397 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
398 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
400 static const u16 VAUX2_VSEL_table[] = {
401 1700, 1700, 1900, 1300,
402 1500, 1800, 2000, 2500,
403 2100, 2800, 2200, 2300,
404 2400, 2400, 2400, 2400,
406 static const u16 VAUX3_VSEL_table[] = {
407 1500, 1800, 2500, 2800,
408 3000, 3000, 3000, 3000,
410 static const u16 VAUX4_VSEL_table[] = {
411 700, 1000, 1200, UNSUP(1300),
412 1500, 1800, UNSUP(1850), 2500,
413 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
414 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
416 static const u16 VMMC1_VSEL_table[] = {
417 1850, 2850, 3000, 3150,
419 static const u16 VMMC2_VSEL_table[] = {
420 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
421 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
422 2600, 2800, 2850, 3000,
423 3150, 3150, 3150, 3150,
425 static const u16 VPLL1_VSEL_table[] = {
426 1000, 1200, 1300, 1800,
427 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
429 static const u16 VPLL2_VSEL_table[] = {
430 700, 1000, 1200, 1300,
431 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
432 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
433 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
435 static const u16 VSIM_VSEL_table[] = {
436 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
437 2800, 3000, 3000, 3000,
439 static const u16 VDAC_VSEL_table[] = {
440 1200, 1300, 1800, 1800,
442 static const u16 VDD1_VSEL_table[] = {
445 static const u16 VDD2_VSEL_table[] = {
448 static const u16 VIO_VSEL_table[] = {
451 static const u16 VINTANA2_VSEL_table[] = {
455 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
457 struct twlreg_info *info = rdev_get_drvdata(rdev);
458 int mV = info->table[index];
460 return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000);
464 twl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
466 struct twlreg_info *info = rdev_get_drvdata(rdev);
468 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
472 static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
474 struct twlreg_info *info = rdev_get_drvdata(rdev);
475 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
481 vsel &= info->table_len - 1;
482 return LDO_MV(info->table[vsel]) * 1000;
485 static struct regulator_ops twl4030ldo_ops = {
486 .list_voltage = twl4030ldo_list_voltage,
488 .set_voltage_sel = twl4030ldo_set_voltage_sel,
489 .get_voltage = twl4030ldo_get_voltage,
491 .enable = twl4030reg_enable,
492 .disable = twl4030reg_disable,
493 .is_enabled = twl4030reg_is_enabled,
495 .set_mode = twl4030reg_set_mode,
497 .get_status = twl4030reg_get_status,
501 twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
504 struct twlreg_info *info = rdev_get_drvdata(rdev);
505 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
507 if (info->set_voltage) {
508 return info->set_voltage(info->data, min_uV);
510 twlreg_write(info, TWL_MODULE_PM_RECEIVER,
511 VREG_VOLTAGE_SMPS_4030, vsel);
517 static int twl4030smps_get_voltage(struct regulator_dev *rdev)
519 struct twlreg_info *info = rdev_get_drvdata(rdev);
522 if (info->get_voltage)
523 return info->get_voltage(info->data);
525 vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
526 VREG_VOLTAGE_SMPS_4030);
528 return vsel * 12500 + 600000;
531 static struct regulator_ops twl4030smps_ops = {
532 .set_voltage = twl4030smps_set_voltage,
533 .get_voltage = twl4030smps_get_voltage,
536 static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV,
537 int max_uV, unsigned *selector)
539 struct twlreg_info *info = rdev_get_drvdata(rdev);
541 if (info->set_voltage)
542 return info->set_voltage(info->data, min_uV);
547 static int twl6030coresmps_get_voltage(struct regulator_dev *rdev)
549 struct twlreg_info *info = rdev_get_drvdata(rdev);
551 if (info->get_voltage)
552 return info->get_voltage(info->data);
557 static struct regulator_ops twl6030coresmps_ops = {
558 .set_voltage = twl6030coresmps_set_voltage,
559 .get_voltage = twl6030coresmps_get_voltage,
562 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel)
564 struct twlreg_info *info = rdev_get_drvdata(rdev);
570 /* Linear mapping from 00000001 to 00011000:
571 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001)
573 return (info->min_mV + 100 * (sel - 1)) * 1000;
584 twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
586 struct twlreg_info *info = rdev_get_drvdata(rdev);
588 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
592 static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev)
594 struct twlreg_info *info = rdev_get_drvdata(rdev);
595 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE);
600 static struct regulator_ops twl6030ldo_ops = {
601 .list_voltage = twl6030ldo_list_voltage,
603 .set_voltage_sel = twl6030ldo_set_voltage_sel,
604 .get_voltage_sel = twl6030ldo_get_voltage_sel,
606 .enable = twl6030reg_enable,
607 .disable = twl6030reg_disable,
608 .is_enabled = twl6030reg_is_enabled,
610 .set_mode = twl6030reg_set_mode,
612 .get_status = twl6030reg_get_status,
615 /*----------------------------------------------------------------------*/
618 * Fixed voltage LDOs don't have a VSEL field to update.
620 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
622 struct twlreg_info *info = rdev_get_drvdata(rdev);
624 return info->min_mV * 1000;
627 static struct regulator_ops twl4030fixed_ops = {
628 .list_voltage = twlfixed_list_voltage,
630 .enable = twl4030reg_enable,
631 .disable = twl4030reg_disable,
632 .is_enabled = twl4030reg_is_enabled,
634 .set_mode = twl4030reg_set_mode,
636 .get_status = twl4030reg_get_status,
639 static struct regulator_ops twl6030fixed_ops = {
640 .list_voltage = twlfixed_list_voltage,
642 .enable = twl6030reg_enable,
643 .disable = twl6030reg_disable,
644 .is_enabled = twl6030reg_is_enabled,
646 .set_mode = twl6030reg_set_mode,
648 .get_status = twl6030reg_get_status,
651 static struct regulator_ops twl6030_fixed_resource = {
652 .enable = twl6030reg_enable,
653 .disable = twl6030reg_disable,
654 .is_enabled = twl6030reg_is_enabled,
655 .get_status = twl6030reg_get_status,
659 * SMPS status and control
662 static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
664 struct twlreg_info *info = rdev_get_drvdata(rdev);
668 switch (info->flags) {
678 voltage = 1350 * 1000;
681 voltage = 1500 * 1000;
684 voltage = 1800 * 1000;
687 voltage = 1900 * 1000;
690 voltage = 2100 * 1000;
693 voltage += (600000 + (12500 * (index - 1)));
696 case SMPS_EXTENDED_EN:
702 voltage = 2084 * 1000;
705 voltage = 2315 * 1000;
708 voltage = 2778 * 1000;
711 voltage = 2932 * 1000;
714 voltage = 3241 * 1000;
717 voltage = (1852000 + (38600 * (index - 1)));
720 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
726 voltage = 4167 * 1000;
729 voltage = 2315 * 1000;
732 voltage = 2778 * 1000;
735 voltage = 2932 * 1000;
738 voltage = 3241 * 1000;
741 voltage = (2161000 + (38600 * (index - 1)));
749 static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
752 struct twlreg_info *info = rdev_get_drvdata(rdev);
755 switch (info->flags) {
759 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
760 vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
763 /* Values 1..57 for vsel are linear and can be calculated
764 * values 58..62 are non linear.
766 else if ((min_uV > 1900000) && (min_uV <= 2100000))
768 else if ((min_uV > 1800000) && (min_uV <= 1900000))
770 else if ((min_uV > 1500000) && (min_uV <= 1800000))
772 else if ((min_uV > 1350000) && (min_uV <= 1500000))
774 else if ((min_uV > 1300000) && (min_uV <= 1350000))
782 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
783 vsel = DIV_ROUND_UP(min_uV - 700000, 12500);
786 /* Values 1..57 for vsel are linear and can be calculated
787 * values 58..62 are non linear.
789 else if ((min_uV > 1900000) && (min_uV <= 2100000))
791 else if ((min_uV > 1800000) && (min_uV <= 1900000))
793 else if ((min_uV > 1350000) && (min_uV <= 1800000))
795 else if ((min_uV > 1350000) && (min_uV <= 1500000))
797 else if ((min_uV > 1300000) && (min_uV <= 1350000))
802 case SMPS_EXTENDED_EN:
805 } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
806 vsel = DIV_ROUND_UP(min_uV - 1852000, 38600);
810 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
813 } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) {
814 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600);
823 static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
824 unsigned int selector)
826 struct twlreg_info *info = rdev_get_drvdata(rdev);
828 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
832 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
834 struct twlreg_info *info = rdev_get_drvdata(rdev);
836 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
839 static struct regulator_ops twlsmps_ops = {
840 .list_voltage = twl6030smps_list_voltage,
841 .map_voltage = twl6030smps_map_voltage,
843 .set_voltage_sel = twl6030smps_set_voltage_sel,
844 .get_voltage_sel = twl6030smps_get_voltage_sel,
846 .enable = twl6030reg_enable,
847 .disable = twl6030reg_disable,
848 .is_enabled = twl6030reg_is_enabled,
850 .set_mode = twl6030reg_set_mode,
852 .get_status = twl6030reg_get_status,
855 /*----------------------------------------------------------------------*/
857 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
859 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
860 remap_conf, TWL4030, twl4030fixed_ops)
861 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
862 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
863 0x0, TWL6030, twl6030fixed_ops)
865 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
866 static const struct twlreg_info TWL4030_INFO_##label = { \
869 .table_len = ARRAY_SIZE(label##_VSEL_table), \
870 .table = label##_VSEL_table, \
871 .remap = remap_conf, \
874 .id = TWL4030_REG_##label, \
875 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
876 .ops = &twl4030ldo_ops, \
877 .type = REGULATOR_VOLTAGE, \
878 .owner = THIS_MODULE, \
879 .enable_time = turnon_delay, \
883 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
884 static const struct twlreg_info TWL4030_INFO_##label = { \
887 .remap = remap_conf, \
890 .id = TWL4030_REG_##label, \
891 .ops = &twl4030smps_ops, \
892 .type = REGULATOR_VOLTAGE, \
893 .owner = THIS_MODULE, \
894 .enable_time = turnon_delay, \
898 #define TWL6030_ADJUSTABLE_SMPS(label) \
899 static const struct twlreg_info TWL6030_INFO_##label = { \
902 .id = TWL6030_REG_##label, \
903 .ops = &twl6030coresmps_ops, \
904 .type = REGULATOR_VOLTAGE, \
905 .owner = THIS_MODULE, \
909 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
910 static const struct twlreg_info TWL6030_INFO_##label = { \
912 .min_mV = min_mVolts, \
913 .max_mV = max_mVolts, \
916 .id = TWL6030_REG_##label, \
918 .ops = &twl6030ldo_ops, \
919 .type = REGULATOR_VOLTAGE, \
920 .owner = THIS_MODULE, \
924 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
925 static const struct twlreg_info TWL6025_INFO_##label = { \
927 .min_mV = min_mVolts, \
928 .max_mV = max_mVolts, \
931 .id = TWL6025_REG_##label, \
933 .ops = &twl6030ldo_ops, \
934 .type = REGULATOR_VOLTAGE, \
935 .owner = THIS_MODULE, \
939 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
940 family, operations) \
941 static const struct twlreg_info TWLFIXED_INFO_##label = { \
945 .remap = remap_conf, \
948 .id = family##_REG_##label, \
950 .ops = &operations, \
951 .type = REGULATOR_VOLTAGE, \
952 .owner = THIS_MODULE, \
953 .enable_time = turnon_delay, \
957 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
958 static struct twlreg_info TWLRES_INFO_##label = { \
962 .id = TWL6030_REG_##label, \
963 .ops = &twl6030_fixed_resource, \
964 .type = REGULATOR_VOLTAGE, \
965 .owner = THIS_MODULE, \
966 .enable_time = turnon_delay, \
970 #define TWL6025_ADJUSTABLE_SMPS(label, offset) \
971 static const struct twlreg_info TWLSMPS_INFO_##label = { \
977 .id = TWL6025_REG_##label, \
979 .ops = &twlsmps_ops, \
980 .type = REGULATOR_VOLTAGE, \
981 .owner = THIS_MODULE, \
986 * We list regulators here if systems need some level of
987 * software control over them after boot.
989 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08);
990 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08);
991 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08);
992 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08);
993 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08);
994 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08);
995 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08);
996 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00);
997 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08);
998 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00);
999 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08);
1000 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08);
1001 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08);
1002 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08);
1003 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08);
1004 /* VUSBCP is managed *only* by the USB subchip */
1005 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1006 /* Turnon-delay and remap configuration values for 6030 are not
1007 verified since the specification is not public */
1008 TWL6030_ADJUSTABLE_SMPS(VDD1);
1009 TWL6030_ADJUSTABLE_SMPS(VDD2);
1010 TWL6030_ADJUSTABLE_SMPS(VDD3);
1011 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300);
1012 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300);
1013 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300);
1014 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300);
1015 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300);
1016 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300);
1017 /* 6025 are renamed compared to 6030 versions */
1018 TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300);
1019 TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300);
1020 TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300);
1021 TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300);
1022 TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300);
1023 TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300);
1024 TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300);
1025 TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300);
1026 TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300);
1027 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08);
1028 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08);
1029 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08);
1030 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08);
1031 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08);
1032 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0);
1033 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0);
1034 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
1035 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0);
1036 TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0);
1037 TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0);
1038 TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34);
1039 TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10);
1040 TWL6025_ADJUSTABLE_SMPS(VIO, 0x16);
1042 static u8 twl_get_smps_offset(void)
1046 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1047 TWL6030_SMPS_OFFSET);
1051 static u8 twl_get_smps_mult(void)
1055 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1060 #define TWL_OF_MATCH(comp, family, label) \
1062 .compatible = comp, \
1063 .data = &family##_INFO_##label, \
1066 #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
1067 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1068 #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
1069 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
1070 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1072 static const struct of_device_id twl_of_match[] __devinitconst = {
1073 TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1),
1074 TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030),
1075 TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2),
1076 TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3),
1077 TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4),
1078 TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1),
1079 TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2),
1080 TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1),
1081 TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2),
1082 TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM),
1083 TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC),
1084 TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2),
1085 TWL4030_OF_MATCH("ti,twl4030-vio", VIO),
1086 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1),
1087 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2),
1088 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1),
1089 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2),
1090 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3),
1091 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030),
1092 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030),
1093 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030),
1094 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC),
1095 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP),
1096 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM),
1097 TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2),
1098 TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4),
1099 TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3),
1100 TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5),
1101 TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1),
1102 TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7),
1103 TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6),
1104 TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN),
1105 TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB),
1106 TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1),
1107 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG),
1108 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5),
1109 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8),
1110 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1),
1111 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA),
1112 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO),
1113 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC),
1114 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
1115 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
1116 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
1117 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3),
1118 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4),
1119 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO),
1122 MODULE_DEVICE_TABLE(of, twl_of_match);
1124 static int __devinit twlreg_probe(struct platform_device *pdev)
1127 struct twlreg_info *info;
1128 const struct twlreg_info *template;
1129 struct regulator_init_data *initdata;
1130 struct regulation_constraints *c;
1131 struct regulator_dev *rdev;
1132 struct twl_regulator_driver_data *drvdata;
1133 const struct of_device_id *match;
1134 struct regulator_config config = { };
1136 match = of_match_device(twl_of_match, &pdev->dev);
1138 template = match->data;
1139 id = template->desc.id;
1140 initdata = of_get_regulator_init_data(&pdev->dev,
1145 initdata = pdev->dev.platform_data;
1146 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
1147 template = twl_of_match[i].data;
1148 if (template && template->desc.id == id)
1151 if (i == ARRAY_SIZE(twl_of_match))
1154 drvdata = initdata->driver_data;
1165 info = kmemdup(template, sizeof (*info), GFP_KERNEL);
1170 /* copy the driver data into regulator data */
1171 info->features = drvdata->features;
1172 info->data = drvdata->data;
1173 info->set_voltage = drvdata->set_voltage;
1174 info->get_voltage = drvdata->get_voltage;
1177 /* Constrain board-specific capabilities according to what
1178 * this driver and the chip itself can actually do.
1180 c = &initdata->constraints;
1181 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1182 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1183 | REGULATOR_CHANGE_MODE
1184 | REGULATOR_CHANGE_STATUS;
1186 case TWL4030_REG_VIO:
1187 case TWL4030_REG_VDD1:
1188 case TWL4030_REG_VDD2:
1189 case TWL4030_REG_VPLL1:
1190 case TWL4030_REG_VINTANA1:
1191 case TWL4030_REG_VINTANA2:
1192 case TWL4030_REG_VINTDIG:
1193 c->always_on = true;
1200 case TWL6025_REG_SMPS3:
1201 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1202 info->flags |= SMPS_EXTENDED_EN;
1203 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1204 info->flags |= SMPS_OFFSET_EN;
1206 case TWL6025_REG_SMPS4:
1207 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1208 info->flags |= SMPS_EXTENDED_EN;
1209 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1210 info->flags |= SMPS_OFFSET_EN;
1212 case TWL6025_REG_VIO:
1213 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1214 info->flags |= SMPS_EXTENDED_EN;
1215 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1216 info->flags |= SMPS_OFFSET_EN;
1220 config.dev = &pdev->dev;
1221 config.init_data = initdata;
1222 config.driver_data = info;
1223 config.of_node = pdev->dev.of_node;
1225 rdev = regulator_register(&info->desc, &config);
1227 dev_err(&pdev->dev, "can't register %s, %ld\n",
1228 info->desc.name, PTR_ERR(rdev));
1230 return PTR_ERR(rdev);
1232 platform_set_drvdata(pdev, rdev);
1234 if (twl_class_is_4030())
1235 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
1238 /* NOTE: many regulators support short-circuit IRQs (presentable
1239 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1241 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1242 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1249 static int __devexit twlreg_remove(struct platform_device *pdev)
1251 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1252 struct twlreg_info *info = rdev->reg_data;
1254 regulator_unregister(rdev);
1259 MODULE_ALIAS("platform:twl_reg");
1261 static struct platform_driver twlreg_driver = {
1262 .probe = twlreg_probe,
1263 .remove = __devexit_p(twlreg_remove),
1264 /* NOTE: short name, to work around driver model truncation of
1265 * "twl_regulator.12" (and friends) to "twl_regulator.1".
1269 .owner = THIS_MODULE,
1270 .of_match_table = of_match_ptr(twl_of_match),
1274 static int __init twlreg_init(void)
1276 return platform_driver_register(&twlreg_driver);
1278 subsys_initcall(twlreg_init);
1280 static void __exit twlreg_exit(void)
1282 platform_driver_unregister(&twlreg_driver);
1284 module_exit(twlreg_exit)
1286 MODULE_DESCRIPTION("TWL regulator driver");
1287 MODULE_LICENSE("GPL");