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