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