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 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 54 | u8 flags; |
| 55 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 56 | /* used by regulator core */ |
| 57 | struct regulator_desc desc; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 58 | |
| 59 | /* chip specific features */ |
| 60 | unsigned long features; |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * optional override functions for voltage set/get |
| 64 | * these are currently only used for SMPS regulators |
| 65 | */ |
| 66 | int (*get_voltage)(void *data); |
| 67 | int (*set_voltage)(void *data, int target_uV); |
| 68 | |
| 69 | /* data passed from board for external get/set voltage */ |
| 70 | void *data; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | |
| 74 | /* LDO control registers ... offset is from the base of its register bank. |
| 75 | * The first three registers of all power resource banks help hardware to |
| 76 | * manage the various resource groups. |
| 77 | */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 78 | /* Common offset in TWL4030/6030 */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 79 | #define VREG_GRP 0 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 80 | /* TWL4030 register offsets */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 81 | #define VREG_TYPE 1 |
| 82 | #define VREG_REMAP 2 |
| 83 | #define VREG_DEDICATED 3 /* LDO control */ |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 84 | #define VREG_VOLTAGE_SMPS_4030 9 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 85 | /* TWL6030 register offsets */ |
| 86 | #define VREG_TRANS 1 |
| 87 | #define VREG_STATE 2 |
| 88 | #define VREG_VOLTAGE 3 |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 89 | #define VREG_VOLTAGE_SMPS 4 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 90 | /* TWL6030 Misc register offsets */ |
| 91 | #define VREG_BC_ALL 1 |
| 92 | #define VREG_BC_REF 2 |
| 93 | #define VREG_BC_PROC 3 |
| 94 | #define VREG_BC_CLK_RST 4 |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 95 | |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 96 | /* TWL6030 LDO register values for CFG_STATE */ |
| 97 | #define TWL6030_CFG_STATE_OFF 0x00 |
| 98 | #define TWL6030_CFG_STATE_ON 0x01 |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 99 | #define TWL6030_CFG_STATE_OFF2 0x02 |
| 100 | #define TWL6030_CFG_STATE_SLEEP 0x03 |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 101 | #define TWL6030_CFG_STATE_GRP_SHIFT 5 |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 102 | #define TWL6030_CFG_STATE_APP_SHIFT 2 |
| 103 | #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT) |
| 104 | #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\ |
| 105 | TWL6030_CFG_STATE_APP_SHIFT) |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 106 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 107 | /* Flags for SMPS Voltage reading */ |
| 108 | #define SMPS_OFFSET_EN BIT(0) |
| 109 | #define SMPS_EXTENDED_EN BIT(1) |
| 110 | |
| 111 | /* twl6025 SMPS EPROM values */ |
| 112 | #define TWL6030_SMPS_OFFSET 0xB0 |
| 113 | #define TWL6030_SMPS_MULT 0xB3 |
| 114 | #define SMPS_MULTOFFSET_SMPS4 BIT(0) |
| 115 | #define SMPS_MULTOFFSET_VIO BIT(1) |
| 116 | #define SMPS_MULTOFFSET_SMPS3 BIT(6) |
| 117 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 118 | static inline int |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 119 | twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 120 | { |
| 121 | u8 value; |
| 122 | int status; |
| 123 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 124 | status = twl_i2c_read_u8(slave_subgp, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 125 | &value, info->base + offset); |
| 126 | return (status < 0) ? status : value; |
| 127 | } |
| 128 | |
| 129 | static inline int |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 130 | twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset, |
| 131 | u8 value) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 132 | { |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 133 | return twl_i2c_write_u8(slave_subgp, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 134 | value, info->base + offset); |
| 135 | } |
| 136 | |
| 137 | /*----------------------------------------------------------------------*/ |
| 138 | |
| 139 | /* generic power resource operations, which work on all regulators */ |
| 140 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 141 | static int twlreg_grp(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 142 | { |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 143 | return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER, |
| 144 | VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Enable/disable regulators by joining/leaving the P1 (processor) group. |
| 149 | * We assume nobody else is updating the DEV_GRP registers. |
| 150 | */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 151 | /* definition for 4030 family */ |
| 152 | #define P3_GRP_4030 BIT(7) /* "peripherals" */ |
| 153 | #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */ |
| 154 | #define P1_GRP_4030 BIT(5) /* CPU/Linux */ |
| 155 | /* definition for 6030 family */ |
| 156 | #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */ |
| 157 | #define P2_GRP_6030 BIT(1) /* "peripherals" */ |
| 158 | #define P1_GRP_6030 BIT(0) /* CPU/Linux */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 159 | |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 160 | static int twl4030reg_is_enabled(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 161 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 162 | int state = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 163 | |
| 164 | if (state < 0) |
| 165 | return state; |
| 166 | |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 167 | return state & P1_GRP_4030; |
| 168 | } |
| 169 | |
| 170 | static int twl6030reg_is_enabled(struct regulator_dev *rdev) |
| 171 | { |
| 172 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 173 | int grp = 0, val; |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 174 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 175 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
| 176 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 177 | if (grp < 0) |
| 178 | return grp; |
| 179 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 180 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
| 181 | grp &= P1_GRP_6030; |
| 182 | else |
| 183 | grp = 1; |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 184 | |
| 185 | val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); |
| 186 | val = TWL6030_CFG_STATE_APP(val); |
| 187 | |
| 188 | return grp && (val == TWL6030_CFG_STATE_ON); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 191 | static int twl4030reg_enable(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 192 | { |
| 193 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 194 | int grp; |
Juha Keski-Saari | 53b8a9d | 2009-12-16 14:55:26 +0200 | [diff] [blame] | 195 | int ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 196 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 197 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 198 | if (grp < 0) |
| 199 | return grp; |
| 200 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 201 | grp |= P1_GRP_4030; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 202 | |
Juha Keski-Saari | 53b8a9d | 2009-12-16 14:55:26 +0200 | [diff] [blame] | 203 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
| 204 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 205 | udelay(info->delay); |
| 206 | |
| 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | static int twl6030reg_enable(struct regulator_dev *rdev) |
| 211 | { |
| 212 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 213 | int grp = 0; |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 214 | int ret; |
| 215 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 216 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
| 217 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 218 | if (grp < 0) |
| 219 | return grp; |
| 220 | |
| 221 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, |
| 222 | grp << TWL6030_CFG_STATE_GRP_SHIFT | |
| 223 | TWL6030_CFG_STATE_ON); |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 224 | |
Juha Keski-Saari | 53b8a9d | 2009-12-16 14:55:26 +0200 | [diff] [blame] | 225 | udelay(info->delay); |
| 226 | |
| 227 | return ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 230 | static int twl4030reg_disable(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 231 | { |
| 232 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 233 | int grp; |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 234 | int ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 235 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 236 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 237 | if (grp < 0) |
| 238 | return grp; |
| 239 | |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 240 | grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030); |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 241 | |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 242 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
| 243 | |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | static int twl6030reg_disable(struct regulator_dev *rdev) |
| 248 | { |
| 249 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 250 | int grp = 0; |
| 251 | int ret; |
| 252 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 253 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
| 254 | grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030; |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 255 | |
| 256 | /* For 6030, set the off state for all grps enabled */ |
| 257 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, |
| 258 | (grp) << TWL6030_CFG_STATE_GRP_SHIFT | |
| 259 | TWL6030_CFG_STATE_OFF); |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 260 | |
| 261 | return ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 264 | static int twl4030reg_get_status(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 265 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 266 | int state = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 267 | |
| 268 | if (state < 0) |
| 269 | return state; |
| 270 | state &= 0x0f; |
| 271 | |
| 272 | /* assume state != WARM_RESET; we'd not be running... */ |
| 273 | if (!state) |
| 274 | return REGULATOR_STATUS_OFF; |
| 275 | return (state & BIT(3)) |
| 276 | ? REGULATOR_STATUS_NORMAL |
| 277 | : REGULATOR_STATUS_STANDBY; |
| 278 | } |
| 279 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 280 | static int twl6030reg_get_status(struct regulator_dev *rdev) |
| 281 | { |
| 282 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 283 | int val; |
| 284 | |
| 285 | val = twlreg_grp(rdev); |
| 286 | if (val < 0) |
| 287 | return val; |
| 288 | |
| 289 | val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); |
| 290 | |
| 291 | switch (TWL6030_CFG_STATE_APP(val)) { |
| 292 | case TWL6030_CFG_STATE_ON: |
| 293 | return REGULATOR_STATUS_NORMAL; |
| 294 | |
| 295 | case TWL6030_CFG_STATE_SLEEP: |
| 296 | return REGULATOR_STATUS_STANDBY; |
| 297 | |
| 298 | case TWL6030_CFG_STATE_OFF: |
| 299 | case TWL6030_CFG_STATE_OFF2: |
| 300 | default: |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | return REGULATOR_STATUS_OFF; |
| 305 | } |
| 306 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 307 | static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 308 | { |
| 309 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 310 | unsigned message; |
| 311 | int status; |
| 312 | |
| 313 | /* We can only set the mode through state machine commands... */ |
| 314 | switch (mode) { |
| 315 | case REGULATOR_MODE_NORMAL: |
| 316 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); |
| 317 | break; |
| 318 | case REGULATOR_MODE_STANDBY: |
| 319 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); |
| 320 | break; |
| 321 | default: |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | |
| 325 | /* Ensure the resource is associated with some group */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 326 | status = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 327 | if (status < 0) |
| 328 | return status; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 329 | if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030))) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 330 | return -EACCES; |
| 331 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 332 | status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
Axel Lin | b9e26bc | 2010-10-22 16:38:22 +0800 | [diff] [blame] | 333 | message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB); |
| 334 | if (status < 0) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 335 | return status; |
| 336 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 337 | return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
Axel Lin | b9e26bc | 2010-10-22 16:38:22 +0800 | [diff] [blame] | 338 | message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 341 | static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) |
| 342 | { |
| 343 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 344 | int grp = 0; |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 345 | int val; |
| 346 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 347 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
| 348 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 349 | |
| 350 | if (grp < 0) |
| 351 | return grp; |
| 352 | |
| 353 | /* Compose the state register settings */ |
| 354 | val = grp << TWL6030_CFG_STATE_GRP_SHIFT; |
| 355 | /* We can only set the mode through state machine commands... */ |
| 356 | switch (mode) { |
| 357 | case REGULATOR_MODE_NORMAL: |
| 358 | val |= TWL6030_CFG_STATE_ON; |
| 359 | break; |
| 360 | case REGULATOR_MODE_STANDBY: |
| 361 | val |= TWL6030_CFG_STATE_SLEEP; |
| 362 | break; |
| 363 | |
| 364 | default: |
| 365 | return -EINVAL; |
| 366 | } |
| 367 | |
| 368 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val); |
| 369 | } |
| 370 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 371 | /*----------------------------------------------------------------------*/ |
| 372 | |
| 373 | /* |
| 374 | * Support for adjustable-voltage LDOs uses a four bit (or less) voltage |
| 375 | * select field in its control register. We use tables indexed by VSEL |
| 376 | * to record voltages in milliVolts. (Accuracy is about three percent.) |
| 377 | * |
| 378 | * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; |
| 379 | * currently handled by listing two slightly different VAUX2 regulators, |
| 380 | * only one of which will be configured. |
| 381 | * |
| 382 | * VSEL values documented as "TI cannot support these values" are flagged |
| 383 | * in these tables as UNSUP() values; we normally won't assign them. |
Adrian Hunter | d6bb69c | 2009-03-06 14:51:30 +0200 | [diff] [blame] | 384 | * |
| 385 | * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. |
| 386 | * 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] | 387 | */ |
| 388 | #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED |
| 389 | #define UNSUP_MASK 0x0000 |
| 390 | #else |
| 391 | #define UNSUP_MASK 0x8000 |
| 392 | #endif |
| 393 | |
| 394 | #define UNSUP(x) (UNSUP_MASK | (x)) |
| 395 | #define IS_UNSUP(x) (UNSUP_MASK & (x)) |
| 396 | #define LDO_MV(x) (~UNSUP_MASK & (x)) |
| 397 | |
| 398 | |
| 399 | static const u16 VAUX1_VSEL_table[] = { |
| 400 | UNSUP(1500), UNSUP(1800), 2500, 2800, |
| 401 | 3000, 3000, 3000, 3000, |
| 402 | }; |
| 403 | static const u16 VAUX2_4030_VSEL_table[] = { |
| 404 | UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, |
| 405 | 1500, 1800, UNSUP(1850), 2500, |
| 406 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), |
| 407 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
| 408 | }; |
| 409 | static const u16 VAUX2_VSEL_table[] = { |
| 410 | 1700, 1700, 1900, 1300, |
| 411 | 1500, 1800, 2000, 2500, |
| 412 | 2100, 2800, 2200, 2300, |
| 413 | 2400, 2400, 2400, 2400, |
| 414 | }; |
| 415 | static const u16 VAUX3_VSEL_table[] = { |
| 416 | 1500, 1800, 2500, 2800, |
Adrian Hunter | d6bb69c | 2009-03-06 14:51:30 +0200 | [diff] [blame] | 417 | 3000, 3000, 3000, 3000, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 418 | }; |
| 419 | static const u16 VAUX4_VSEL_table[] = { |
| 420 | 700, 1000, 1200, UNSUP(1300), |
| 421 | 1500, 1800, UNSUP(1850), 2500, |
David Brownell | 1897e74 | 2009-03-10 11:51:15 -0800 | [diff] [blame] | 422 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), |
| 423 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 424 | }; |
| 425 | static const u16 VMMC1_VSEL_table[] = { |
| 426 | 1850, 2850, 3000, 3150, |
| 427 | }; |
| 428 | static const u16 VMMC2_VSEL_table[] = { |
| 429 | UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), |
| 430 | UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), |
| 431 | 2600, 2800, 2850, 3000, |
| 432 | 3150, 3150, 3150, 3150, |
| 433 | }; |
| 434 | static const u16 VPLL1_VSEL_table[] = { |
| 435 | 1000, 1200, 1300, 1800, |
| 436 | UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), |
| 437 | }; |
| 438 | static const u16 VPLL2_VSEL_table[] = { |
| 439 | 700, 1000, 1200, 1300, |
| 440 | UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), |
| 441 | UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), |
| 442 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
| 443 | }; |
| 444 | static const u16 VSIM_VSEL_table[] = { |
| 445 | UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, |
| 446 | 2800, 3000, 3000, 3000, |
| 447 | }; |
| 448 | static const u16 VDAC_VSEL_table[] = { |
| 449 | 1200, 1300, 1800, 1800, |
| 450 | }; |
Juha Keski-Saari | 07fc493 | 2009-12-16 15:27:55 +0200 | [diff] [blame] | 451 | static const u16 VDD1_VSEL_table[] = { |
| 452 | 800, 1450, |
| 453 | }; |
| 454 | static const u16 VDD2_VSEL_table[] = { |
| 455 | 800, 1450, 1500, |
| 456 | }; |
| 457 | static const u16 VIO_VSEL_table[] = { |
| 458 | 1800, 1850, |
| 459 | }; |
| 460 | static const u16 VINTANA2_VSEL_table[] = { |
| 461 | 2500, 2750, |
| 462 | }; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 463 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 464 | static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 465 | { |
| 466 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 467 | int mV = info->table[index]; |
| 468 | |
| 469 | return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000); |
| 470 | } |
| 471 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 472 | static int |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 473 | twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, |
| 474 | unsigned *selector) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 475 | { |
| 476 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 477 | int vsel; |
| 478 | |
| 479 | for (vsel = 0; vsel < info->table_len; vsel++) { |
| 480 | int mV = info->table[vsel]; |
| 481 | int uV; |
| 482 | |
| 483 | if (IS_UNSUP(mV)) |
| 484 | continue; |
| 485 | uV = LDO_MV(mV) * 1000; |
| 486 | |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 487 | /* REVISIT for VAUX2, first match may not be best/lowest */ |
| 488 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 489 | /* use the first in-range value */ |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 490 | if (min_uV <= uV && uV <= max_uV) { |
| 491 | *selector = vsel; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 492 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, |
| 493 | VREG_VOLTAGE, vsel); |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 494 | } |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | return -EDOM; |
| 498 | } |
| 499 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 500 | static int twl4030ldo_get_voltage(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 501 | { |
| 502 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 503 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, |
| 504 | VREG_VOLTAGE); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 505 | |
| 506 | if (vsel < 0) |
| 507 | return vsel; |
| 508 | |
| 509 | vsel &= info->table_len - 1; |
| 510 | return LDO_MV(info->table[vsel]) * 1000; |
| 511 | } |
| 512 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 513 | static struct regulator_ops twl4030ldo_ops = { |
| 514 | .list_voltage = twl4030ldo_list_voltage, |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 515 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 516 | .set_voltage = twl4030ldo_set_voltage, |
| 517 | .get_voltage = twl4030ldo_get_voltage, |
| 518 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 519 | .enable = twl4030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 520 | .disable = twl4030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 521 | .is_enabled = twl4030reg_is_enabled, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 522 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 523 | .set_mode = twl4030reg_set_mode, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 524 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 525 | .get_status = twl4030reg_get_status, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 526 | }; |
| 527 | |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 528 | static int |
| 529 | twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, |
| 530 | unsigned *selector) |
| 531 | { |
| 532 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 533 | int vsel = DIV_ROUND_UP(min_uV - 600000, 12500); |
| 534 | |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 535 | if (info->set_voltage) { |
| 536 | return info->set_voltage(info->data, min_uV); |
| 537 | } else { |
| 538 | twlreg_write(info, TWL_MODULE_PM_RECEIVER, |
| 539 | VREG_VOLTAGE_SMPS_4030, vsel); |
| 540 | } |
| 541 | |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int twl4030smps_get_voltage(struct regulator_dev *rdev) |
| 546 | { |
| 547 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 548 | int vsel; |
| 549 | |
| 550 | if (info->get_voltage) |
| 551 | return info->get_voltage(info->data); |
| 552 | |
| 553 | vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 554 | VREG_VOLTAGE_SMPS_4030); |
| 555 | |
| 556 | return vsel * 12500 + 600000; |
| 557 | } |
| 558 | |
| 559 | static struct regulator_ops twl4030smps_ops = { |
| 560 | .set_voltage = twl4030smps_set_voltage, |
| 561 | .get_voltage = twl4030smps_get_voltage, |
| 562 | }; |
| 563 | |
Tero Kristo | 34a3844 | 2012-02-28 15:09:10 +0530 | [diff] [blame^] | 564 | static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, |
| 565 | int max_uV, unsigned *selector) |
| 566 | { |
| 567 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 568 | |
| 569 | if (info->set_voltage) |
| 570 | return info->set_voltage(info->data, min_uV); |
| 571 | |
| 572 | return -ENODEV; |
| 573 | } |
| 574 | |
| 575 | static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) |
| 576 | { |
| 577 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 578 | |
| 579 | if (info->get_voltage) |
| 580 | return info->get_voltage(info->data); |
| 581 | |
| 582 | return -ENODEV; |
| 583 | } |
| 584 | |
| 585 | static struct regulator_ops twl6030coresmps_ops = { |
| 586 | .set_voltage = twl6030coresmps_set_voltage, |
| 587 | .get_voltage = twl6030coresmps_get_voltage, |
| 588 | }; |
| 589 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 590 | static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) |
| 591 | { |
| 592 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 593 | |
| 594 | return ((info->min_mV + (index * 100)) * 1000); |
| 595 | } |
| 596 | |
| 597 | static int |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 598 | twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, |
| 599 | unsigned *selector) |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 600 | { |
| 601 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 602 | int vsel; |
| 603 | |
| 604 | if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV)) |
| 605 | return -EDOM; |
| 606 | |
| 607 | /* |
| 608 | * Use the below formula to calculate vsel |
| 609 | * mV = 1000mv + 100mv * (vsel - 1) |
| 610 | */ |
| 611 | vsel = (min_uV/1000 - 1000)/100 + 1; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 612 | *selector = vsel; |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 613 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel); |
| 614 | |
| 615 | } |
| 616 | |
| 617 | static int twl6030ldo_get_voltage(struct regulator_dev *rdev) |
| 618 | { |
| 619 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 620 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, |
| 621 | VREG_VOLTAGE); |
| 622 | |
| 623 | if (vsel < 0) |
| 624 | return vsel; |
| 625 | |
| 626 | /* |
| 627 | * Use the below formula to calculate vsel |
| 628 | * mV = 1000mv + 100mv * (vsel - 1) |
| 629 | */ |
| 630 | return (1000 + (100 * (vsel - 1))) * 1000; |
| 631 | } |
| 632 | |
| 633 | static struct regulator_ops twl6030ldo_ops = { |
| 634 | .list_voltage = twl6030ldo_list_voltage, |
| 635 | |
| 636 | .set_voltage = twl6030ldo_set_voltage, |
| 637 | .get_voltage = twl6030ldo_get_voltage, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 638 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 639 | .enable = twl6030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 640 | .disable = twl6030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 641 | .is_enabled = twl6030reg_is_enabled, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 642 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 643 | .set_mode = twl6030reg_set_mode, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 644 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 645 | .get_status = twl6030reg_get_status, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 646 | }; |
| 647 | |
| 648 | /*----------------------------------------------------------------------*/ |
| 649 | |
| 650 | /* |
| 651 | * Fixed voltage LDOs don't have a VSEL field to update. |
| 652 | */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 653 | static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index) |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 654 | { |
| 655 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 656 | |
| 657 | return info->min_mV * 1000; |
| 658 | } |
| 659 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 660 | static int twlfixed_get_voltage(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 661 | { |
| 662 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 663 | |
| 664 | return info->min_mV * 1000; |
| 665 | } |
| 666 | |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 667 | static struct regulator_ops twl4030fixed_ops = { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 668 | .list_voltage = twlfixed_list_voltage, |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 669 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 670 | .get_voltage = twlfixed_get_voltage, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 671 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 672 | .enable = twl4030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 673 | .disable = twl4030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 674 | .is_enabled = twl4030reg_is_enabled, |
| 675 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 676 | .set_mode = twl4030reg_set_mode, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 677 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 678 | .get_status = twl4030reg_get_status, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | static struct regulator_ops twl6030fixed_ops = { |
| 682 | .list_voltage = twlfixed_list_voltage, |
| 683 | |
| 684 | .get_voltage = twlfixed_get_voltage, |
| 685 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 686 | .enable = twl6030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 687 | .disable = twl6030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 688 | .is_enabled = twl6030reg_is_enabled, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 689 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 690 | .set_mode = twl6030reg_set_mode, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 691 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 692 | .get_status = twl6030reg_get_status, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 693 | }; |
| 694 | |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 695 | static struct regulator_ops twl6030_fixed_resource = { |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 696 | .enable = twl6030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 697 | .disable = twl6030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 698 | .is_enabled = twl6030reg_is_enabled, |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 699 | .get_status = twl6030reg_get_status, |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 700 | }; |
| 701 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 702 | /* |
| 703 | * SMPS status and control |
| 704 | */ |
| 705 | |
| 706 | static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index) |
| 707 | { |
| 708 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 709 | |
| 710 | int voltage = 0; |
| 711 | |
| 712 | switch (info->flags) { |
| 713 | case SMPS_OFFSET_EN: |
| 714 | voltage = 100000; |
| 715 | /* fall through */ |
| 716 | case 0: |
| 717 | switch (index) { |
| 718 | case 0: |
| 719 | voltage = 0; |
| 720 | break; |
| 721 | case 58: |
| 722 | voltage = 1350 * 1000; |
| 723 | break; |
| 724 | case 59: |
| 725 | voltage = 1500 * 1000; |
| 726 | break; |
| 727 | case 60: |
| 728 | voltage = 1800 * 1000; |
| 729 | break; |
| 730 | case 61: |
| 731 | voltage = 1900 * 1000; |
| 732 | break; |
| 733 | case 62: |
| 734 | voltage = 2100 * 1000; |
| 735 | break; |
| 736 | default: |
| 737 | voltage += (600000 + (12500 * (index - 1))); |
| 738 | } |
| 739 | break; |
| 740 | case SMPS_EXTENDED_EN: |
| 741 | switch (index) { |
| 742 | case 0: |
| 743 | voltage = 0; |
| 744 | break; |
| 745 | case 58: |
| 746 | voltage = 2084 * 1000; |
| 747 | break; |
| 748 | case 59: |
| 749 | voltage = 2315 * 1000; |
| 750 | break; |
| 751 | case 60: |
| 752 | voltage = 2778 * 1000; |
| 753 | break; |
| 754 | case 61: |
| 755 | voltage = 2932 * 1000; |
| 756 | break; |
| 757 | case 62: |
| 758 | voltage = 3241 * 1000; |
| 759 | break; |
| 760 | default: |
| 761 | voltage = (1852000 + (38600 * (index - 1))); |
| 762 | } |
| 763 | break; |
| 764 | case SMPS_OFFSET_EN | SMPS_EXTENDED_EN: |
| 765 | switch (index) { |
| 766 | case 0: |
| 767 | voltage = 0; |
| 768 | break; |
| 769 | case 58: |
| 770 | voltage = 4167 * 1000; |
| 771 | break; |
| 772 | case 59: |
| 773 | voltage = 2315 * 1000; |
| 774 | break; |
| 775 | case 60: |
| 776 | voltage = 2778 * 1000; |
| 777 | break; |
| 778 | case 61: |
| 779 | voltage = 2932 * 1000; |
| 780 | break; |
| 781 | case 62: |
| 782 | voltage = 3241 * 1000; |
| 783 | break; |
| 784 | default: |
| 785 | voltage = (2161000 + (38600 * (index - 1))); |
| 786 | } |
| 787 | break; |
| 788 | } |
| 789 | |
| 790 | return voltage; |
| 791 | } |
| 792 | |
| 793 | static int |
| 794 | twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, |
| 795 | unsigned int *selector) |
| 796 | { |
| 797 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 798 | int vsel = 0; |
| 799 | |
| 800 | switch (info->flags) { |
| 801 | case 0: |
| 802 | if (min_uV == 0) |
| 803 | vsel = 0; |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 804 | else if ((min_uV >= 600000) && (min_uV <= 1300000)) { |
| 805 | int calc_uV; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 806 | vsel = (min_uV - 600000) / 125; |
| 807 | if (vsel % 100) |
| 808 | vsel += 100; |
| 809 | vsel /= 100; |
| 810 | vsel++; |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 811 | calc_uV = twl6030smps_list_voltage(rdev, vsel); |
| 812 | if (calc_uV > max_uV) |
| 813 | return -EINVAL; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 814 | } |
| 815 | /* Values 1..57 for vsel are linear and can be calculated |
| 816 | * values 58..62 are non linear. |
| 817 | */ |
| 818 | else if ((min_uV > 1900000) && (max_uV >= 2100000)) |
| 819 | vsel = 62; |
| 820 | else if ((min_uV > 1800000) && (max_uV >= 1900000)) |
| 821 | vsel = 61; |
| 822 | else if ((min_uV > 1500000) && (max_uV >= 1800000)) |
| 823 | vsel = 60; |
| 824 | else if ((min_uV > 1350000) && (max_uV >= 1500000)) |
| 825 | vsel = 59; |
| 826 | else if ((min_uV > 1300000) && (max_uV >= 1350000)) |
| 827 | vsel = 58; |
| 828 | else |
| 829 | return -EINVAL; |
| 830 | break; |
| 831 | case SMPS_OFFSET_EN: |
| 832 | if (min_uV == 0) |
| 833 | vsel = 0; |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 834 | else if ((min_uV >= 700000) && (min_uV <= 1420000)) { |
| 835 | int calc_uV; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 836 | vsel = (min_uV - 700000) / 125; |
| 837 | if (vsel % 100) |
| 838 | vsel += 100; |
| 839 | vsel /= 100; |
| 840 | vsel++; |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 841 | calc_uV = twl6030smps_list_voltage(rdev, vsel); |
| 842 | if (calc_uV > max_uV) |
| 843 | return -EINVAL; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 844 | } |
| 845 | /* Values 1..57 for vsel are linear and can be calculated |
| 846 | * values 58..62 are non linear. |
| 847 | */ |
| 848 | else if ((min_uV > 1900000) && (max_uV >= 2100000)) |
| 849 | vsel = 62; |
| 850 | else if ((min_uV > 1800000) && (max_uV >= 1900000)) |
| 851 | vsel = 61; |
| 852 | else if ((min_uV > 1350000) && (max_uV >= 1800000)) |
| 853 | vsel = 60; |
| 854 | else if ((min_uV > 1350000) && (max_uV >= 1500000)) |
| 855 | vsel = 59; |
| 856 | else if ((min_uV > 1300000) && (max_uV >= 1350000)) |
| 857 | vsel = 58; |
| 858 | else |
| 859 | return -EINVAL; |
| 860 | break; |
| 861 | case SMPS_EXTENDED_EN: |
| 862 | if (min_uV == 0) |
| 863 | vsel = 0; |
| 864 | else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { |
| 865 | vsel = (min_uV - 1852000) / 386; |
| 866 | if (vsel % 100) |
| 867 | vsel += 100; |
| 868 | vsel /= 100; |
| 869 | vsel++; |
| 870 | } |
| 871 | break; |
| 872 | case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: |
| 873 | if (min_uV == 0) |
| 874 | vsel = 0; |
| 875 | else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 876 | vsel = (min_uV - 2161000) / 386; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 877 | if (vsel % 100) |
| 878 | vsel += 100; |
| 879 | vsel /= 100; |
| 880 | vsel++; |
| 881 | } |
| 882 | break; |
| 883 | } |
| 884 | |
| 885 | *selector = vsel; |
| 886 | |
| 887 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, |
| 888 | vsel); |
| 889 | } |
| 890 | |
| 891 | static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) |
| 892 | { |
| 893 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 894 | |
| 895 | return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS); |
| 896 | } |
| 897 | |
| 898 | static struct regulator_ops twlsmps_ops = { |
| 899 | .list_voltage = twl6030smps_list_voltage, |
| 900 | |
| 901 | .set_voltage = twl6030smps_set_voltage, |
| 902 | .get_voltage_sel = twl6030smps_get_voltage_sel, |
| 903 | |
| 904 | .enable = twl6030reg_enable, |
| 905 | .disable = twl6030reg_disable, |
| 906 | .is_enabled = twl6030reg_is_enabled, |
| 907 | |
| 908 | .set_mode = twl6030reg_set_mode, |
| 909 | |
| 910 | .get_status = twl6030reg_get_status, |
| 911 | }; |
| 912 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 913 | /*----------------------------------------------------------------------*/ |
| 914 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 915 | #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
| 916 | remap_conf) \ |
| 917 | TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 918 | remap_conf, TWL4030, twl4030fixed_ops) |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 919 | #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \ |
| 920 | TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 921 | 0x0, TWL6030, twl6030fixed_ops) |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 922 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 923 | #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 924 | .base = offset, \ |
| 925 | .id = num, \ |
| 926 | .table_len = ARRAY_SIZE(label##_VSEL_table), \ |
| 927 | .table = label##_VSEL_table, \ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 928 | .delay = turnon_delay, \ |
| 929 | .remap = remap_conf, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 930 | .desc = { \ |
| 931 | .name = #label, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 932 | .id = TWL4030_REG_##label, \ |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 933 | .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 934 | .ops = &twl4030ldo_ops, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 935 | .type = REGULATOR_VOLTAGE, \ |
| 936 | .owner = THIS_MODULE, \ |
| 937 | }, \ |
| 938 | } |
| 939 | |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 940 | #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ |
| 941 | { \ |
| 942 | .base = offset, \ |
| 943 | .id = num, \ |
| 944 | .delay = turnon_delay, \ |
| 945 | .remap = remap_conf, \ |
| 946 | .desc = { \ |
| 947 | .name = #label, \ |
| 948 | .id = TWL4030_REG_##label, \ |
| 949 | .ops = &twl4030smps_ops, \ |
| 950 | .type = REGULATOR_VOLTAGE, \ |
| 951 | .owner = THIS_MODULE, \ |
| 952 | }, \ |
| 953 | } |
| 954 | |
Tero Kristo | 34a3844 | 2012-02-28 15:09:10 +0530 | [diff] [blame^] | 955 | #define TWL6030_ADJUSTABLE_SMPS(label) { \ |
| 956 | .desc = { \ |
| 957 | .name = #label, \ |
| 958 | .id = TWL6030_REG_##label, \ |
| 959 | .ops = &twl6030coresmps_ops, \ |
| 960 | .type = REGULATOR_VOLTAGE, \ |
| 961 | .owner = THIS_MODULE, \ |
| 962 | }, \ |
| 963 | } |
| 964 | |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 965 | #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 966 | .base = offset, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 967 | .min_mV = min_mVolts, \ |
| 968 | .max_mV = max_mVolts, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 969 | .desc = { \ |
| 970 | .name = #label, \ |
| 971 | .id = TWL6030_REG_##label, \ |
Colin Cross | 7736f11 | 2011-05-27 12:25:27 -0700 | [diff] [blame] | 972 | .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 973 | .ops = &twl6030ldo_ops, \ |
| 974 | .type = REGULATOR_VOLTAGE, \ |
| 975 | .owner = THIS_MODULE, \ |
| 976 | }, \ |
| 977 | } |
| 978 | |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 979 | #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 980 | .base = offset, \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 981 | .min_mV = min_mVolts, \ |
| 982 | .max_mV = max_mVolts, \ |
| 983 | .desc = { \ |
| 984 | .name = #label, \ |
| 985 | .id = TWL6025_REG_##label, \ |
| 986 | .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \ |
| 987 | .ops = &twl6030ldo_ops, \ |
| 988 | .type = REGULATOR_VOLTAGE, \ |
| 989 | .owner = THIS_MODULE, \ |
| 990 | }, \ |
| 991 | } |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 992 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 993 | #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 994 | family, operations) { \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 995 | .base = offset, \ |
| 996 | .id = num, \ |
| 997 | .min_mV = mVolts, \ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 998 | .delay = turnon_delay, \ |
| 999 | .remap = remap_conf, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1000 | .desc = { \ |
| 1001 | .name = #label, \ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1002 | .id = family##_REG_##label, \ |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 1003 | .n_voltages = 1, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 1004 | .ops = &operations, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1005 | .type = REGULATOR_VOLTAGE, \ |
| 1006 | .owner = THIS_MODULE, \ |
| 1007 | }, \ |
| 1008 | } |
| 1009 | |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 1010 | #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \ |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 1011 | .base = offset, \ |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 1012 | .delay = turnon_delay, \ |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 1013 | .desc = { \ |
| 1014 | .name = #label, \ |
| 1015 | .id = TWL6030_REG_##label, \ |
| 1016 | .ops = &twl6030_fixed_resource, \ |
| 1017 | .type = REGULATOR_VOLTAGE, \ |
| 1018 | .owner = THIS_MODULE, \ |
| 1019 | }, \ |
| 1020 | } |
| 1021 | |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 1022 | #define TWL6025_ADJUSTABLE_SMPS(label, offset) { \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1023 | .base = offset, \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1024 | .min_mV = 600, \ |
| 1025 | .max_mV = 2100, \ |
| 1026 | .desc = { \ |
| 1027 | .name = #label, \ |
| 1028 | .id = TWL6025_REG_##label, \ |
| 1029 | .n_voltages = 63, \ |
| 1030 | .ops = &twlsmps_ops, \ |
| 1031 | .type = REGULATOR_VOLTAGE, \ |
| 1032 | .owner = THIS_MODULE, \ |
| 1033 | }, \ |
| 1034 | } |
| 1035 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1036 | /* |
| 1037 | * We list regulators here if systems need some level of |
| 1038 | * software control over them after boot. |
| 1039 | */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1040 | static struct twlreg_info twl_regs[] = { |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 1041 | TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08), |
| 1042 | TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08), |
| 1043 | TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08), |
| 1044 | TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08), |
| 1045 | TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08), |
| 1046 | TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08), |
| 1047 | TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08), |
| 1048 | TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00), |
| 1049 | TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08), |
| 1050 | TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00), |
| 1051 | TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08), |
| 1052 | TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08), |
| 1053 | TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08), |
| 1054 | TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08), |
| 1055 | TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08), |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 1056 | TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08), |
| 1057 | TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08), |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 1058 | TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08), |
| 1059 | TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08), |
| 1060 | TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1061 | /* VUSBCP is managed *only* by the USB subchip */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 1062 | |
| 1063 | /* 6030 REG with base as PMC Slave Misc : 0x0030 */ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 1064 | /* Turnon-delay and remap configuration values for 6030 are not |
| 1065 | verified since the specification is not public */ |
Tero Kristo | 34a3844 | 2012-02-28 15:09:10 +0530 | [diff] [blame^] | 1066 | TWL6030_ADJUSTABLE_SMPS(VDD1), |
| 1067 | TWL6030_ADJUSTABLE_SMPS(VDD2), |
| 1068 | TWL6030_ADJUSTABLE_SMPS(VDD3), |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 1069 | TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300), |
| 1070 | TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300), |
| 1071 | TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300), |
| 1072 | TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300), |
| 1073 | TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300), |
| 1074 | TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300), |
| 1075 | TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0), |
| 1076 | TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0), |
| 1077 | TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0), |
| 1078 | TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0), |
| 1079 | TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0), |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1080 | |
| 1081 | /* 6025 are renamed compared to 6030 versions */ |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 1082 | TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300), |
| 1083 | TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300), |
| 1084 | TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300), |
| 1085 | TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300), |
| 1086 | TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300), |
| 1087 | TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300), |
| 1088 | TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300), |
| 1089 | TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300), |
| 1090 | TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300), |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1091 | |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 1092 | TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34), |
| 1093 | TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10), |
| 1094 | TWL6025_ADJUSTABLE_SMPS(VIO, 0x16), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1095 | }; |
| 1096 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1097 | static u8 twl_get_smps_offset(void) |
| 1098 | { |
| 1099 | u8 value; |
| 1100 | |
| 1101 | twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, |
| 1102 | TWL6030_SMPS_OFFSET); |
| 1103 | return value; |
| 1104 | } |
| 1105 | |
| 1106 | static u8 twl_get_smps_mult(void) |
| 1107 | { |
| 1108 | u8 value; |
| 1109 | |
| 1110 | twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, |
| 1111 | TWL6030_SMPS_MULT); |
| 1112 | return value; |
| 1113 | } |
| 1114 | |
Dmitry Torokhov | 24c2902 | 2010-02-23 23:38:01 -0800 | [diff] [blame] | 1115 | static int __devinit twlreg_probe(struct platform_device *pdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1116 | { |
| 1117 | int i; |
| 1118 | struct twlreg_info *info; |
| 1119 | struct regulator_init_data *initdata; |
| 1120 | struct regulation_constraints *c; |
| 1121 | struct regulator_dev *rdev; |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 1122 | struct twl_regulator_driver_data *drvdata; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1123 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1124 | for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) { |
| 1125 | if (twl_regs[i].desc.id != pdev->id) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1126 | continue; |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1127 | info = twl_regs + i; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1128 | break; |
| 1129 | } |
| 1130 | if (!info) |
| 1131 | return -ENODEV; |
| 1132 | |
| 1133 | initdata = pdev->dev.platform_data; |
| 1134 | if (!initdata) |
| 1135 | return -EINVAL; |
| 1136 | |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 1137 | drvdata = initdata->driver_data; |
| 1138 | |
| 1139 | if (!drvdata) |
| 1140 | return -EINVAL; |
| 1141 | |
| 1142 | /* copy the driver data into regulator data */ |
| 1143 | info->features = drvdata->features; |
| 1144 | info->data = drvdata->data; |
| 1145 | info->set_voltage = drvdata->set_voltage; |
| 1146 | info->get_voltage = drvdata->get_voltage; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1147 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1148 | /* Constrain board-specific capabilities according to what |
| 1149 | * this driver and the chip itself can actually do. |
| 1150 | */ |
| 1151 | c = &initdata->constraints; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1152 | c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; |
| 1153 | c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE |
| 1154 | | REGULATOR_CHANGE_MODE |
| 1155 | | REGULATOR_CHANGE_STATUS; |
Juha Keski-Saari | 205e5cd | 2009-12-16 15:27:56 +0200 | [diff] [blame] | 1156 | switch (pdev->id) { |
| 1157 | case TWL4030_REG_VIO: |
| 1158 | case TWL4030_REG_VDD1: |
| 1159 | case TWL4030_REG_VDD2: |
| 1160 | case TWL4030_REG_VPLL1: |
| 1161 | case TWL4030_REG_VINTANA1: |
| 1162 | case TWL4030_REG_VINTANA2: |
| 1163 | case TWL4030_REG_VINTDIG: |
| 1164 | c->always_on = true; |
| 1165 | break; |
| 1166 | default: |
| 1167 | break; |
| 1168 | } |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1169 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1170 | switch (pdev->id) { |
| 1171 | case TWL6025_REG_SMPS3: |
| 1172 | if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) |
| 1173 | info->flags |= SMPS_EXTENDED_EN; |
| 1174 | if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3) |
| 1175 | info->flags |= SMPS_OFFSET_EN; |
| 1176 | break; |
| 1177 | case TWL6025_REG_SMPS4: |
| 1178 | if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4) |
| 1179 | info->flags |= SMPS_EXTENDED_EN; |
| 1180 | if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4) |
| 1181 | info->flags |= SMPS_OFFSET_EN; |
| 1182 | break; |
| 1183 | case TWL6025_REG_VIO: |
| 1184 | if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO) |
| 1185 | info->flags |= SMPS_EXTENDED_EN; |
| 1186 | if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO) |
| 1187 | info->flags |= SMPS_OFFSET_EN; |
| 1188 | break; |
| 1189 | } |
| 1190 | |
Rajendra Nayak | 2c043bc | 2011-11-18 16:47:19 +0530 | [diff] [blame] | 1191 | rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, NULL); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1192 | if (IS_ERR(rdev)) { |
| 1193 | dev_err(&pdev->dev, "can't register %s, %ld\n", |
| 1194 | info->desc.name, PTR_ERR(rdev)); |
| 1195 | return PTR_ERR(rdev); |
| 1196 | } |
| 1197 | platform_set_drvdata(pdev, rdev); |
| 1198 | |
Saquib Herman | 776dc92 | 2011-04-01 10:22:43 +0530 | [diff] [blame] | 1199 | if (twl_class_is_4030()) |
| 1200 | twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, |
Juha Keski-Saari | 30010fa | 2009-12-16 15:27:58 +0200 | [diff] [blame] | 1201 | info->remap); |
| 1202 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1203 | /* NOTE: many regulators support short-circuit IRQs (presentable |
| 1204 | * as REGULATOR_OVER_CURRENT notifications?) configured via: |
| 1205 | * - SC_CONFIG |
| 1206 | * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) |
| 1207 | * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) |
| 1208 | * - IT_CONFIG |
| 1209 | */ |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1214 | static int __devexit twlreg_remove(struct platform_device *pdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1215 | { |
| 1216 | regulator_unregister(platform_get_drvdata(pdev)); |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1220 | MODULE_ALIAS("platform:twl_reg"); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1221 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1222 | static struct platform_driver twlreg_driver = { |
| 1223 | .probe = twlreg_probe, |
| 1224 | .remove = __devexit_p(twlreg_remove), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1225 | /* NOTE: short name, to work around driver model truncation of |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1226 | * "twl_regulator.12" (and friends) to "twl_regulator.1". |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1227 | */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1228 | .driver.name = "twl_reg", |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1229 | .driver.owner = THIS_MODULE, |
| 1230 | }; |
| 1231 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1232 | static int __init twlreg_init(void) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1233 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1234 | return platform_driver_register(&twlreg_driver); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1235 | } |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1236 | subsys_initcall(twlreg_init); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1237 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1238 | static void __exit twlreg_exit(void) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1239 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1240 | platform_driver_unregister(&twlreg_driver); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1241 | } |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1242 | module_exit(twlreg_exit) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1243 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1244 | MODULE_DESCRIPTION("TWL regulator driver"); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1245 | MODULE_LICENSE("GPL"); |