David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1 | /* |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 2 | * twl-regulator.c -- support regulators in twl4030/twl6030 family chips |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 David Brownell |
| 5 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/regulator/driver.h> |
| 17 | #include <linux/regulator/machine.h> |
Santosh Shilimkar | b07682b | 2009-12-13 20:05:51 +0100 | [diff] [blame] | 18 | #include <linux/i2c/twl.h> |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 19 | |
| 20 | |
| 21 | /* |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 22 | * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 23 | * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions |
| 24 | * include an audio codec, battery charger, and more voltage regulators. |
| 25 | * These chips are often used in OMAP-based systems. |
| 26 | * |
| 27 | * This driver implements software-based resource control for various |
| 28 | * voltage regulators. This is usually augmented with state machine |
| 29 | * based control. |
| 30 | */ |
| 31 | |
| 32 | struct twlreg_info { |
| 33 | /* start of regulator's PM_RECEIVER control register bank */ |
| 34 | u8 base; |
| 35 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 36 | /* twl resource ID, for resource control state machine */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 37 | u8 id; |
| 38 | |
| 39 | /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ |
| 40 | u8 table_len; |
| 41 | const u16 *table; |
| 42 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 43 | /* regulator specific turn-on delay */ |
| 44 | u16 delay; |
| 45 | |
| 46 | /* State REMAP default configuration */ |
| 47 | u8 remap; |
| 48 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 49 | /* chip constraints on regulator behavior */ |
| 50 | u16 min_mV; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 51 | |
| 52 | /* used by regulator core */ |
| 53 | struct regulator_desc desc; |
| 54 | }; |
| 55 | |
| 56 | |
| 57 | /* LDO control registers ... offset is from the base of its register bank. |
| 58 | * The first three registers of all power resource banks help hardware to |
| 59 | * manage the various resource groups. |
| 60 | */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 61 | /* Common offset in TWL4030/6030 */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 62 | #define VREG_GRP 0 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 63 | /* TWL4030 register offsets */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 64 | #define VREG_TYPE 1 |
| 65 | #define VREG_REMAP 2 |
| 66 | #define VREG_DEDICATED 3 /* LDO control */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 67 | /* TWL6030 register offsets */ |
| 68 | #define VREG_TRANS 1 |
| 69 | #define VREG_STATE 2 |
| 70 | #define VREG_VOLTAGE 3 |
| 71 | /* TWL6030 Misc register offsets */ |
| 72 | #define VREG_BC_ALL 1 |
| 73 | #define VREG_BC_REF 2 |
| 74 | #define VREG_BC_PROC 3 |
| 75 | #define VREG_BC_CLK_RST 4 |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 76 | |
| 77 | static inline int |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 78 | twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 79 | { |
| 80 | u8 value; |
| 81 | int status; |
| 82 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 83 | status = twl_i2c_read_u8(slave_subgp, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 84 | &value, info->base + offset); |
| 85 | return (status < 0) ? status : value; |
| 86 | } |
| 87 | |
| 88 | static inline int |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 89 | twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset, |
| 90 | u8 value) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 91 | { |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 92 | return twl_i2c_write_u8(slave_subgp, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 93 | value, info->base + offset); |
| 94 | } |
| 95 | |
| 96 | /*----------------------------------------------------------------------*/ |
| 97 | |
| 98 | /* generic power resource operations, which work on all regulators */ |
| 99 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 100 | static int twlreg_grp(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 101 | { |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 102 | return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER, |
| 103 | VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Enable/disable regulators by joining/leaving the P1 (processor) group. |
| 108 | * We assume nobody else is updating the DEV_GRP registers. |
| 109 | */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 110 | /* definition for 4030 family */ |
| 111 | #define P3_GRP_4030 BIT(7) /* "peripherals" */ |
| 112 | #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */ |
| 113 | #define P1_GRP_4030 BIT(5) /* CPU/Linux */ |
| 114 | /* definition for 6030 family */ |
| 115 | #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */ |
| 116 | #define P2_GRP_6030 BIT(1) /* "peripherals" */ |
| 117 | #define P1_GRP_6030 BIT(0) /* CPU/Linux */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 118 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 119 | static int twlreg_is_enabled(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 120 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 121 | int state = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 122 | |
| 123 | if (state < 0) |
| 124 | return state; |
| 125 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 126 | if (twl_class_is_4030()) |
| 127 | state &= P1_GRP_4030; |
| 128 | else |
| 129 | state &= P1_GRP_6030; |
| 130 | return state; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 133 | static int twlreg_enable(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 134 | { |
| 135 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 136 | int grp; |
| 137 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 138 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 139 | if (grp < 0) |
| 140 | return grp; |
| 141 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 142 | if (twl_class_is_4030()) |
| 143 | grp |= P1_GRP_4030; |
| 144 | else |
| 145 | grp |= P1_GRP_6030; |
| 146 | |
| 147 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 150 | static int twlreg_disable(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 151 | { |
| 152 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 153 | int grp; |
| 154 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 155 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 156 | if (grp < 0) |
| 157 | return grp; |
| 158 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 159 | if (twl_class_is_4030()) |
| 160 | grp &= ~P1_GRP_4030; |
| 161 | else |
| 162 | grp &= ~P1_GRP_6030; |
| 163 | |
| 164 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 167 | static int twlreg_get_status(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 168 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 169 | int state = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 170 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 171 | if (twl_class_is_6030()) |
| 172 | return 0; /* FIXME return for 6030 regulator */ |
| 173 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 174 | if (state < 0) |
| 175 | return state; |
| 176 | state &= 0x0f; |
| 177 | |
| 178 | /* assume state != WARM_RESET; we'd not be running... */ |
| 179 | if (!state) |
| 180 | return REGULATOR_STATUS_OFF; |
| 181 | return (state & BIT(3)) |
| 182 | ? REGULATOR_STATUS_NORMAL |
| 183 | : REGULATOR_STATUS_STANDBY; |
| 184 | } |
| 185 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 186 | static int twlreg_set_mode(struct regulator_dev *rdev, unsigned mode) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 187 | { |
| 188 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 189 | unsigned message; |
| 190 | int status; |
| 191 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 192 | if (twl_class_is_6030()) |
| 193 | return 0; /* FIXME return for 6030 regulator */ |
| 194 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 195 | /* We can only set the mode through state machine commands... */ |
| 196 | switch (mode) { |
| 197 | case REGULATOR_MODE_NORMAL: |
| 198 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); |
| 199 | break; |
| 200 | case REGULATOR_MODE_STANDBY: |
| 201 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); |
| 202 | break; |
| 203 | default: |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
| 207 | /* Ensure the resource is associated with some group */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 208 | status = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 209 | if (status < 0) |
| 210 | return status; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 211 | if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030))) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 212 | return -EACCES; |
| 213 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 214 | status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 215 | message >> 8, 0x15 /* PB_WORD_MSB */ ); |
| 216 | if (status >= 0) |
| 217 | return status; |
| 218 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 219 | return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 220 | message, 0x16 /* PB_WORD_LSB */ ); |
| 221 | } |
| 222 | |
| 223 | /*----------------------------------------------------------------------*/ |
| 224 | |
| 225 | /* |
| 226 | * Support for adjustable-voltage LDOs uses a four bit (or less) voltage |
| 227 | * select field in its control register. We use tables indexed by VSEL |
| 228 | * to record voltages in milliVolts. (Accuracy is about three percent.) |
| 229 | * |
| 230 | * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; |
| 231 | * currently handled by listing two slightly different VAUX2 regulators, |
| 232 | * only one of which will be configured. |
| 233 | * |
| 234 | * VSEL values documented as "TI cannot support these values" are flagged |
| 235 | * in these tables as UNSUP() values; we normally won't assign them. |
Adrian Hunter | d6bb69c | 2009-03-06 14:51:30 +0200 | [diff] [blame] | 236 | * |
| 237 | * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. |
| 238 | * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 239 | */ |
| 240 | #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED |
| 241 | #define UNSUP_MASK 0x0000 |
| 242 | #else |
| 243 | #define UNSUP_MASK 0x8000 |
| 244 | #endif |
| 245 | |
| 246 | #define UNSUP(x) (UNSUP_MASK | (x)) |
| 247 | #define IS_UNSUP(x) (UNSUP_MASK & (x)) |
| 248 | #define LDO_MV(x) (~UNSUP_MASK & (x)) |
| 249 | |
| 250 | |
| 251 | static const u16 VAUX1_VSEL_table[] = { |
| 252 | UNSUP(1500), UNSUP(1800), 2500, 2800, |
| 253 | 3000, 3000, 3000, 3000, |
| 254 | }; |
| 255 | static const u16 VAUX2_4030_VSEL_table[] = { |
| 256 | UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, |
| 257 | 1500, 1800, UNSUP(1850), 2500, |
| 258 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), |
| 259 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
| 260 | }; |
| 261 | static const u16 VAUX2_VSEL_table[] = { |
| 262 | 1700, 1700, 1900, 1300, |
| 263 | 1500, 1800, 2000, 2500, |
| 264 | 2100, 2800, 2200, 2300, |
| 265 | 2400, 2400, 2400, 2400, |
| 266 | }; |
| 267 | static const u16 VAUX3_VSEL_table[] = { |
| 268 | 1500, 1800, 2500, 2800, |
Adrian Hunter | d6bb69c | 2009-03-06 14:51:30 +0200 | [diff] [blame] | 269 | 3000, 3000, 3000, 3000, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 270 | }; |
| 271 | static const u16 VAUX4_VSEL_table[] = { |
| 272 | 700, 1000, 1200, UNSUP(1300), |
| 273 | 1500, 1800, UNSUP(1850), 2500, |
David Brownell | 1897e74 | 2009-03-10 11:51:15 -0800 | [diff] [blame] | 274 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), |
| 275 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 276 | }; |
| 277 | static const u16 VMMC1_VSEL_table[] = { |
| 278 | 1850, 2850, 3000, 3150, |
| 279 | }; |
| 280 | static const u16 VMMC2_VSEL_table[] = { |
| 281 | UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), |
| 282 | UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), |
| 283 | 2600, 2800, 2850, 3000, |
| 284 | 3150, 3150, 3150, 3150, |
| 285 | }; |
| 286 | static const u16 VPLL1_VSEL_table[] = { |
| 287 | 1000, 1200, 1300, 1800, |
| 288 | UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), |
| 289 | }; |
| 290 | static const u16 VPLL2_VSEL_table[] = { |
| 291 | 700, 1000, 1200, 1300, |
| 292 | UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), |
| 293 | UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), |
| 294 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
| 295 | }; |
| 296 | static const u16 VSIM_VSEL_table[] = { |
| 297 | UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, |
| 298 | 2800, 3000, 3000, 3000, |
| 299 | }; |
| 300 | static const u16 VDAC_VSEL_table[] = { |
| 301 | 1200, 1300, 1800, 1800, |
| 302 | }; |
Juha Keski-Saari | 07fc493 | 2009-12-16 15:27:55 +0200 | [diff] [blame] | 303 | static const u16 VDD1_VSEL_table[] = { |
| 304 | 800, 1450, |
| 305 | }; |
| 306 | static const u16 VDD2_VSEL_table[] = { |
| 307 | 800, 1450, 1500, |
| 308 | }; |
| 309 | static const u16 VIO_VSEL_table[] = { |
| 310 | 1800, 1850, |
| 311 | }; |
| 312 | static const u16 VINTANA2_VSEL_table[] = { |
| 313 | 2500, 2750, |
| 314 | }; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 315 | static const u16 VAUX1_6030_VSEL_table[] = { |
| 316 | 1000, 1300, 1800, 2500, |
| 317 | 2800, 2900, 3000, 3000, |
| 318 | }; |
| 319 | static const u16 VAUX2_6030_VSEL_table[] = { |
| 320 | 1200, 1800, 2500, 2750, |
| 321 | 2800, 2800, 2800, 2800, |
| 322 | }; |
| 323 | static const u16 VAUX3_6030_VSEL_table[] = { |
| 324 | 1000, 1200, 1300, 1800, |
| 325 | 2500, 2800, 3000, 3000, |
| 326 | }; |
| 327 | static const u16 VMMC_VSEL_table[] = { |
| 328 | 1200, 1800, 2800, 2900, |
| 329 | 3000, 3000, 3000, 3000, |
| 330 | }; |
| 331 | static const u16 VPP_VSEL_table[] = { |
| 332 | 1800, 1900, 2000, 2100, |
| 333 | 2200, 2300, 2400, 2500, |
| 334 | }; |
| 335 | static const u16 VUSIM_VSEL_table[] = { |
| 336 | 1200, 1800, 2500, 2900, |
| 337 | }; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 338 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 339 | static int twlldo_list_voltage(struct regulator_dev *rdev, unsigned index) |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 340 | { |
| 341 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 342 | int mV = info->table[index]; |
| 343 | |
| 344 | return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000); |
| 345 | } |
| 346 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 347 | static int |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 348 | twlldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 349 | { |
| 350 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 351 | int vsel; |
| 352 | |
| 353 | for (vsel = 0; vsel < info->table_len; vsel++) { |
| 354 | int mV = info->table[vsel]; |
| 355 | int uV; |
| 356 | |
| 357 | if (IS_UNSUP(mV)) |
| 358 | continue; |
| 359 | uV = LDO_MV(mV) * 1000; |
| 360 | |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 361 | /* REVISIT for VAUX2, first match may not be best/lowest */ |
| 362 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 363 | /* use the first in-range value */ |
| 364 | if (min_uV <= uV && uV <= max_uV) |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 365 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, |
| 366 | VREG_VOLTAGE, vsel); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | return -EDOM; |
| 370 | } |
| 371 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 372 | static int twlldo_get_voltage(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 373 | { |
| 374 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 375 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, |
| 376 | VREG_VOLTAGE); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 377 | |
| 378 | if (vsel < 0) |
| 379 | return vsel; |
| 380 | |
| 381 | vsel &= info->table_len - 1; |
| 382 | return LDO_MV(info->table[vsel]) * 1000; |
| 383 | } |
| 384 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 385 | static struct regulator_ops twlldo_ops = { |
| 386 | .list_voltage = twlldo_list_voltage, |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 387 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 388 | .set_voltage = twlldo_set_voltage, |
| 389 | .get_voltage = twlldo_get_voltage, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 390 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 391 | .enable = twlreg_enable, |
| 392 | .disable = twlreg_disable, |
| 393 | .is_enabled = twlreg_is_enabled, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 394 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 395 | .set_mode = twlreg_set_mode, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 396 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 397 | .get_status = twlreg_get_status, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | /*----------------------------------------------------------------------*/ |
| 401 | |
| 402 | /* |
| 403 | * Fixed voltage LDOs don't have a VSEL field to update. |
| 404 | */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 405 | static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index) |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 406 | { |
| 407 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 408 | |
| 409 | return info->min_mV * 1000; |
| 410 | } |
| 411 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 412 | static int twlfixed_get_voltage(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 413 | { |
| 414 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 415 | |
| 416 | return info->min_mV * 1000; |
| 417 | } |
| 418 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 419 | static struct regulator_ops twlfixed_ops = { |
| 420 | .list_voltage = twlfixed_list_voltage, |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 421 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 422 | .get_voltage = twlfixed_get_voltage, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 423 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 424 | .enable = twlreg_enable, |
| 425 | .disable = twlreg_disable, |
| 426 | .is_enabled = twlreg_is_enabled, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 427 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 428 | .set_mode = twlreg_set_mode, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 429 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 430 | .get_status = twlreg_get_status, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | /*----------------------------------------------------------------------*/ |
| 434 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 435 | #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ |
| 436 | TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \ |
| 437 | remap_conf, TWL4030) |
| 438 | #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
| 439 | remap_conf) \ |
| 440 | TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
| 441 | remap_conf, TWL4030) |
| 442 | #define TWL6030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \ |
| 443 | remap_conf) \ |
| 444 | TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \ |
| 445 | remap_conf, TWL6030) |
| 446 | #define TWL6030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
| 447 | remap_conf) \ |
| 448 | TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
| 449 | remap_conf, TWL6030) |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 450 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 451 | #define TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf, \ |
| 452 | family) { \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 453 | .base = offset, \ |
| 454 | .id = num, \ |
| 455 | .table_len = ARRAY_SIZE(label##_VSEL_table), \ |
| 456 | .table = label##_VSEL_table, \ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 457 | .delay = turnon_delay, \ |
| 458 | .remap = remap_conf, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 459 | .desc = { \ |
| 460 | .name = #label, \ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 461 | .id = family##_REG_##label, \ |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 462 | .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 463 | .ops = &twlldo_ops, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 464 | .type = REGULATOR_VOLTAGE, \ |
| 465 | .owner = THIS_MODULE, \ |
| 466 | }, \ |
| 467 | } |
| 468 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 469 | #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ |
| 470 | family) { \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 471 | .base = offset, \ |
| 472 | .id = num, \ |
| 473 | .min_mV = mVolts, \ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 474 | .delay = turnon_delay, \ |
| 475 | .remap = remap_conf, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 476 | .desc = { \ |
| 477 | .name = #label, \ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 478 | .id = family##_REG_##label, \ |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 479 | .n_voltages = 1, \ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 480 | .ops = &twlfixed_ops, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 481 | .type = REGULATOR_VOLTAGE, \ |
| 482 | .owner = THIS_MODULE, \ |
| 483 | }, \ |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * We list regulators here if systems need some level of |
| 488 | * software control over them after boot. |
| 489 | */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 490 | static struct twlreg_info twl_regs[] = { |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 491 | TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08), |
| 492 | TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08), |
| 493 | TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08), |
| 494 | TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08), |
| 495 | TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08), |
| 496 | TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08), |
| 497 | TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08), |
| 498 | TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00), |
| 499 | TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08), |
| 500 | TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00), |
| 501 | TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08), |
| 502 | TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08), |
| 503 | TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08), |
| 504 | TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08), |
| 505 | TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08), |
| 506 | TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08), |
| 507 | TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08), |
| 508 | TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08), |
| 509 | TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08), |
| 510 | TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 511 | /* VUSBCP is managed *only* by the USB subchip */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 512 | |
| 513 | /* 6030 REG with base as PMC Slave Misc : 0x0030 */ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame^] | 514 | /* Turnon-delay and remap configuration values for 6030 are not |
| 515 | verified since the specification is not public */ |
| 516 | TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1, 0, 0x08), |
| 517 | TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 2, 0, 0x08), |
| 518 | TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 3, 0, 0x08), |
| 519 | TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 4, 0, 0x08), |
| 520 | TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 5, 0, 0x08), |
| 521 | TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 7, 0, 0x08), |
| 522 | TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0, 0x08), |
| 523 | TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0, 0x08), |
| 524 | TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0, 0x08), |
| 525 | TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0, 0x08) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 526 | }; |
| 527 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 528 | static int twlreg_probe(struct platform_device *pdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 529 | { |
| 530 | int i; |
| 531 | struct twlreg_info *info; |
| 532 | struct regulator_init_data *initdata; |
| 533 | struct regulation_constraints *c; |
| 534 | struct regulator_dev *rdev; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 535 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 536 | for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) { |
| 537 | if (twl_regs[i].desc.id != pdev->id) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 538 | continue; |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 539 | info = twl_regs + i; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 540 | break; |
| 541 | } |
| 542 | if (!info) |
| 543 | return -ENODEV; |
| 544 | |
| 545 | initdata = pdev->dev.platform_data; |
| 546 | if (!initdata) |
| 547 | return -EINVAL; |
| 548 | |
| 549 | /* Constrain board-specific capabilities according to what |
| 550 | * this driver and the chip itself can actually do. |
| 551 | */ |
| 552 | c = &initdata->constraints; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 553 | c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; |
| 554 | c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE |
| 555 | | REGULATOR_CHANGE_MODE |
| 556 | | REGULATOR_CHANGE_STATUS; |
Juha Keski-Saari | 205e5cd | 2009-12-16 15:27:56 +0200 | [diff] [blame] | 557 | switch (pdev->id) { |
| 558 | case TWL4030_REG_VIO: |
| 559 | case TWL4030_REG_VDD1: |
| 560 | case TWL4030_REG_VDD2: |
| 561 | case TWL4030_REG_VPLL1: |
| 562 | case TWL4030_REG_VINTANA1: |
| 563 | case TWL4030_REG_VINTANA2: |
| 564 | case TWL4030_REG_VINTDIG: |
| 565 | c->always_on = true; |
| 566 | break; |
| 567 | default: |
| 568 | break; |
| 569 | } |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 570 | |
| 571 | rdev = regulator_register(&info->desc, &pdev->dev, initdata, info); |
| 572 | if (IS_ERR(rdev)) { |
| 573 | dev_err(&pdev->dev, "can't register %s, %ld\n", |
| 574 | info->desc.name, PTR_ERR(rdev)); |
| 575 | return PTR_ERR(rdev); |
| 576 | } |
| 577 | platform_set_drvdata(pdev, rdev); |
| 578 | |
| 579 | /* NOTE: many regulators support short-circuit IRQs (presentable |
| 580 | * as REGULATOR_OVER_CURRENT notifications?) configured via: |
| 581 | * - SC_CONFIG |
| 582 | * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) |
| 583 | * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) |
| 584 | * - IT_CONFIG |
| 585 | */ |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 590 | static int __devexit twlreg_remove(struct platform_device *pdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 591 | { |
| 592 | regulator_unregister(platform_get_drvdata(pdev)); |
| 593 | return 0; |
| 594 | } |
| 595 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 596 | MODULE_ALIAS("platform:twl_reg"); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 597 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 598 | static struct platform_driver twlreg_driver = { |
| 599 | .probe = twlreg_probe, |
| 600 | .remove = __devexit_p(twlreg_remove), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 601 | /* NOTE: short name, to work around driver model truncation of |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 602 | * "twl_regulator.12" (and friends) to "twl_regulator.1". |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 603 | */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 604 | .driver.name = "twl_reg", |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 605 | .driver.owner = THIS_MODULE, |
| 606 | }; |
| 607 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 608 | static int __init twlreg_init(void) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 609 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 610 | return platform_driver_register(&twlreg_driver); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 611 | } |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 612 | subsys_initcall(twlreg_init); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 613 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 614 | static void __exit twlreg_exit(void) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 615 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 616 | platform_driver_unregister(&twlreg_driver); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 617 | } |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 618 | module_exit(twlreg_exit) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 619 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 620 | MODULE_DESCRIPTION("TWL regulator driver"); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 621 | MODULE_LICENSE("GPL"); |