aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/ab8500.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/ab8500.c')
-rw-r--r--drivers/regulator/ab8500.c725
1 files changed, 595 insertions, 130 deletions
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index 28c7ae67cec9..02f3c2333c83 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -3,59 +3,60 @@
3 * 3 *
4 * License Terms: GNU General Public License v2 4 * License Terms: GNU General Public License v2
5 * 5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 6 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
7 * 8 *
8 * AB8500 peripheral regulators 9 * AB8500 peripheral regulators
9 * 10 *
10 * AB8500 supports the following regulators, 11 * AB8500 supports the following regulators:
11 * LDOs - VAUDIO, VANAMIC2/2, VDIGMIC, VINTCORE12, VTVOUT, 12 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
12 * VAUX1/2/3, VANA
13 *
14 * for DB8500 cut 1.0 and previous versions of the silicon, all accesses
15 * to registers are through the DB8500 SPI. In cut 1.1 onwards, these
16 * accesses are through the DB8500 PRCMU I2C
17 *
18 */ 13 */
19#include <linux/init.h> 14#include <linux/init.h>
20#include <linux/kernel.h> 15#include <linux/kernel.h>
21#include <linux/err.h> 16#include <linux/err.h>
22#include <linux/platform_device.h> 17#include <linux/platform_device.h>
23#include <linux/mfd/ab8500.h> 18#include <linux/mfd/ab8500.h>
19#include <linux/mfd/abx500.h>
24#include <linux/regulator/driver.h> 20#include <linux/regulator/driver.h>
25#include <linux/regulator/machine.h> 21#include <linux/regulator/machine.h>
26#include <linux/regulator/ab8500.h> 22#include <linux/regulator/ab8500.h>
27 23
28/** 24/**
29 * struct ab8500_regulator_info - ab8500 regulator information 25 * struct ab8500_regulator_info - ab8500 regulator information
26 * @dev: device pointer
30 * @desc: regulator description 27 * @desc: regulator description
31 * @ab8500: ab8500 parent
32 * @regulator_dev: regulator device 28 * @regulator_dev: regulator device
33 * @max_uV: maximum voltage (for variable voltage supplies) 29 * @max_uV: maximum voltage (for variable voltage supplies)
34 * @min_uV: minimum voltage (for variable voltage supplies) 30 * @min_uV: minimum voltage (for variable voltage supplies)
35 * @fixed_uV: typical voltage (for fixed voltage supplies) 31 * @fixed_uV: typical voltage (for fixed voltage supplies)
32 * @update_bank: bank to control on/off
36 * @update_reg: register to control on/off 33 * @update_reg: register to control on/off
37 * @mask: mask to enable/disable regulator 34 * @update_mask: mask to enable/disable regulator
38 * @enable: bits to enable the regulator in normal(high power) mode 35 * @update_val_enable: bits to enable the regulator in normal (high power) mode
36 * @voltage_bank: bank to control regulator voltage
39 * @voltage_reg: register to control regulator voltage 37 * @voltage_reg: register to control regulator voltage
40 * @voltage_mask: mask to control regulator voltage 38 * @voltage_mask: mask to control regulator voltage
41 * @supported_voltages: supported voltage table 39 * @voltages: supported voltage table
42 * @voltages_len: number of supported voltages for the regulator 40 * @voltages_len: number of supported voltages for the regulator
41 * @delay: startup/set voltage delay in us
43 */ 42 */
44struct ab8500_regulator_info { 43struct ab8500_regulator_info {
45 struct device *dev; 44 struct device *dev;
46 struct regulator_desc desc; 45 struct regulator_desc desc;
47 struct ab8500 *ab8500;
48 struct regulator_dev *regulator; 46 struct regulator_dev *regulator;
49 int max_uV; 47 int max_uV;
50 int min_uV; 48 int min_uV;
51 int fixed_uV; 49 int fixed_uV;
52 int update_reg; 50 u8 update_bank;
53 int mask; 51 u8 update_reg;
54 int enable; 52 u8 update_mask;
55 int voltage_reg; 53 u8 update_val_enable;
56 int voltage_mask; 54 u8 voltage_bank;
57 int const *supported_voltages; 55 u8 voltage_reg;
56 u8 voltage_mask;
57 int const *voltages;
58 int voltages_len; 58 int voltages_len;
59 unsigned int delay;
59}; 60};
60 61
61/* voltage tables for the vauxn/vintcore supplies */ 62/* voltage tables for the vauxn/vintcore supplies */
@@ -78,6 +79,17 @@ static const int ldo_vauxn_voltages[] = {
78 3300000, 79 3300000,
79}; 80};
80 81
82static const int ldo_vaux3_voltages[] = {
83 1200000,
84 1500000,
85 1800000,
86 2100000,
87 2500000,
88 2750000,
89 2790000,
90 2910000,
91};
92
81static const int ldo_vintcore_voltages[] = { 93static const int ldo_vintcore_voltages[] = {
82 1200000, 94 1200000,
83 1225000, 95 1225000,
@@ -90,55 +102,80 @@ static const int ldo_vintcore_voltages[] = {
90 102
91static int ab8500_regulator_enable(struct regulator_dev *rdev) 103static int ab8500_regulator_enable(struct regulator_dev *rdev)
92{ 104{
93 int regulator_id, ret; 105 int ret;
94 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 106 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
95 107
96 regulator_id = rdev_get_id(rdev); 108 if (info == NULL) {
97 if (regulator_id >= AB8500_NUM_REGULATORS) 109 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
98 return -EINVAL; 110 return -EINVAL;
111 }
99 112
100 ret = ab8500_set_bits(info->ab8500, info->update_reg, 113 ret = abx500_mask_and_set_register_interruptible(info->dev,
101 info->mask, info->enable); 114 info->update_bank, info->update_reg,
115 info->update_mask, info->update_val_enable);
102 if (ret < 0) 116 if (ret < 0)
103 dev_err(rdev_get_dev(rdev), 117 dev_err(rdev_get_dev(rdev),
104 "couldn't set enable bits for regulator\n"); 118 "couldn't set enable bits for regulator\n");
119
120 dev_vdbg(rdev_get_dev(rdev),
121 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
122 info->desc.name, info->update_bank, info->update_reg,
123 info->update_mask, info->update_val_enable);
124
105 return ret; 125 return ret;
106} 126}
107 127
108static int ab8500_regulator_disable(struct regulator_dev *rdev) 128static int ab8500_regulator_disable(struct regulator_dev *rdev)
109{ 129{
110 int regulator_id, ret; 130 int ret;
111 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 131 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
112 132
113 regulator_id = rdev_get_id(rdev); 133 if (info == NULL) {
114 if (regulator_id >= AB8500_NUM_REGULATORS) 134 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
115 return -EINVAL; 135 return -EINVAL;
136 }
116 137
117 ret = ab8500_set_bits(info->ab8500, info->update_reg, 138 ret = abx500_mask_and_set_register_interruptible(info->dev,
118 info->mask, 0x0); 139 info->update_bank, info->update_reg,
140 info->update_mask, 0x0);
119 if (ret < 0) 141 if (ret < 0)
120 dev_err(rdev_get_dev(rdev), 142 dev_err(rdev_get_dev(rdev),
121 "couldn't set disable bits for regulator\n"); 143 "couldn't set disable bits for regulator\n");
144
145 dev_vdbg(rdev_get_dev(rdev),
146 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
147 info->desc.name, info->update_bank, info->update_reg,
148 info->update_mask, 0x0);
149
122 return ret; 150 return ret;
123} 151}
124 152
125static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) 153static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
126{ 154{
127 int regulator_id, ret; 155 int ret;
128 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 156 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
157 u8 regval;
129 158
130 regulator_id = rdev_get_id(rdev); 159 if (info == NULL) {
131 if (regulator_id >= AB8500_NUM_REGULATORS) 160 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
132 return -EINVAL; 161 return -EINVAL;
162 }
133 163
134 ret = ab8500_read(info->ab8500, info->update_reg); 164 ret = abx500_get_register_interruptible(info->dev,
165 info->update_bank, info->update_reg, &regval);
135 if (ret < 0) { 166 if (ret < 0) {
136 dev_err(rdev_get_dev(rdev), 167 dev_err(rdev_get_dev(rdev),
137 "couldn't read 0x%x register\n", info->update_reg); 168 "couldn't read 0x%x register\n", info->update_reg);
138 return ret; 169 return ret;
139 } 170 }
140 171
141 if (ret & info->mask) 172 dev_vdbg(rdev_get_dev(rdev),
173 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
174 " 0x%x\n",
175 info->desc.name, info->update_bank, info->update_reg,
176 info->update_mask, regval);
177
178 if (regval & info->update_mask)
142 return true; 179 return true;
143 else 180 else
144 return false; 181 return false;
@@ -146,12 +183,12 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
146 183
147static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) 184static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
148{ 185{
149 int regulator_id;
150 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 186 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
151 187
152 regulator_id = rdev_get_id(rdev); 188 if (info == NULL) {
153 if (regulator_id >= AB8500_NUM_REGULATORS) 189 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
154 return -EINVAL; 190 return -EINVAL;
191 }
155 192
156 /* return the uV for the fixed regulators */ 193 /* return the uV for the fixed regulators */
157 if (info->fixed_uV) 194 if (info->fixed_uV)
@@ -160,31 +197,40 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
160 if (selector >= info->voltages_len) 197 if (selector >= info->voltages_len)
161 return -EINVAL; 198 return -EINVAL;
162 199
163 return info->supported_voltages[selector]; 200 return info->voltages[selector];
164} 201}
165 202
166static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) 203static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
167{ 204{
168 int regulator_id, ret, val; 205 int ret, val;
169 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 206 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
207 u8 regval;
170 208
171 regulator_id = rdev_get_id(rdev); 209 if (info == NULL) {
172 if (regulator_id >= AB8500_NUM_REGULATORS) 210 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
173 return -EINVAL; 211 return -EINVAL;
212 }
174 213
175 ret = ab8500_read(info->ab8500, info->voltage_reg); 214 ret = abx500_get_register_interruptible(info->dev,
215 info->voltage_bank, info->voltage_reg, &regval);
176 if (ret < 0) { 216 if (ret < 0) {
177 dev_err(rdev_get_dev(rdev), 217 dev_err(rdev_get_dev(rdev),
178 "couldn't read voltage reg for regulator\n"); 218 "couldn't read voltage reg for regulator\n");
179 return ret; 219 return ret;
180 } 220 }
181 221
222 dev_vdbg(rdev_get_dev(rdev),
223 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
224 " 0x%x\n",
225 info->desc.name, info->voltage_bank, info->voltage_reg,
226 info->voltage_mask, regval);
227
182 /* vintcore has a different layout */ 228 /* vintcore has a different layout */
183 val = ret & info->voltage_mask; 229 val = regval & info->voltage_mask;
184 if (regulator_id == AB8500_LDO_INTCORE) 230 if (info->desc.id == AB8500_LDO_INTCORE)
185 ret = info->supported_voltages[val >> 0x3]; 231 ret = info->voltages[val >> 0x3];
186 else 232 else
187 ret = info->supported_voltages[val]; 233 ret = info->voltages[val];
188 234
189 return ret; 235 return ret;
190} 236}
@@ -197,8 +243,8 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
197 243
198 /* check the supported voltage */ 244 /* check the supported voltage */
199 for (i = 0; i < info->voltages_len; i++) { 245 for (i = 0; i < info->voltages_len; i++) {
200 if ((info->supported_voltages[i] >= min_uV) && 246 if ((info->voltages[i] >= min_uV) &&
201 (info->supported_voltages[i] <= max_uV)) 247 (info->voltages[i] <= max_uV))
202 return i; 248 return i;
203 } 249 }
204 250
@@ -206,14 +252,17 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
206} 252}
207 253
208static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, 254static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
209 int min_uV, int max_uV) 255 int min_uV, int max_uV,
256 unsigned *selector)
210{ 257{
211 int regulator_id, ret; 258 int ret;
212 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 259 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
260 u8 regval;
213 261
214 regulator_id = rdev_get_id(rdev); 262 if (info == NULL) {
215 if (regulator_id >= AB8500_NUM_REGULATORS) 263 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
216 return -EINVAL; 264 return -EINVAL;
265 }
217 266
218 /* get the appropriate voltages within the range */ 267 /* get the appropriate voltages within the range */
219 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV); 268 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
@@ -223,16 +272,49 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
223 return ret; 272 return ret;
224 } 273 }
225 274
275 *selector = ret;
276
226 /* set the registers for the request */ 277 /* set the registers for the request */
227 ret = ab8500_set_bits(info->ab8500, info->voltage_reg, 278 regval = (u8)ret;
228 info->voltage_mask, ret); 279 ret = abx500_mask_and_set_register_interruptible(info->dev,
280 info->voltage_bank, info->voltage_reg,
281 info->voltage_mask, regval);
229 if (ret < 0) 282 if (ret < 0)
230 dev_err(rdev_get_dev(rdev), 283 dev_err(rdev_get_dev(rdev),
231 "couldn't set voltage reg for regulator\n"); 284 "couldn't set voltage reg for regulator\n");
232 285
286 dev_vdbg(rdev_get_dev(rdev),
287 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
288 " 0x%x\n",
289 info->desc.name, info->voltage_bank, info->voltage_reg,
290 info->voltage_mask, regval);
291
233 return ret; 292 return ret;
234} 293}
235 294
295static int ab8500_regulator_enable_time(struct regulator_dev *rdev)
296{
297 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
298
299 return info->delay;
300}
301
302static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
303 unsigned int old_sel,
304 unsigned int new_sel)
305{
306 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
307 int ret;
308
309 /* If the regulator isn't on, it won't take time here */
310 ret = ab8500_regulator_is_enabled(rdev);
311 if (ret < 0)
312 return ret;
313 if (!ret)
314 return 0;
315 return info->delay;
316}
317
236static struct regulator_ops ab8500_regulator_ops = { 318static struct regulator_ops ab8500_regulator_ops = {
237 .enable = ab8500_regulator_enable, 319 .enable = ab8500_regulator_enable,
238 .disable = ab8500_regulator_disable, 320 .disable = ab8500_regulator_disable,
@@ -240,106 +322,419 @@ static struct regulator_ops ab8500_regulator_ops = {
240 .get_voltage = ab8500_regulator_get_voltage, 322 .get_voltage = ab8500_regulator_get_voltage,
241 .set_voltage = ab8500_regulator_set_voltage, 323 .set_voltage = ab8500_regulator_set_voltage,
242 .list_voltage = ab8500_list_voltage, 324 .list_voltage = ab8500_list_voltage,
325 .enable_time = ab8500_regulator_enable_time,
326 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
243}; 327};
244 328
245static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) 329static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
246{ 330{
247 int regulator_id;
248 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 331 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
249 332
250 regulator_id = rdev_get_id(rdev); 333 if (info == NULL) {
251 if (regulator_id >= AB8500_NUM_REGULATORS) 334 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
252 return -EINVAL; 335 return -EINVAL;
336 }
253 337
254 return info->fixed_uV; 338 return info->fixed_uV;
255} 339}
256 340
257static struct regulator_ops ab8500_ldo_fixed_ops = { 341static struct regulator_ops ab8500_regulator_fixed_ops = {
258 .enable = ab8500_regulator_enable, 342 .enable = ab8500_regulator_enable,
259 .disable = ab8500_regulator_disable, 343 .disable = ab8500_regulator_disable,
260 .is_enabled = ab8500_regulator_is_enabled, 344 .is_enabled = ab8500_regulator_is_enabled,
261 .get_voltage = ab8500_fixed_get_voltage, 345 .get_voltage = ab8500_fixed_get_voltage,
262 .list_voltage = ab8500_list_voltage, 346 .list_voltage = ab8500_list_voltage,
347 .enable_time = ab8500_regulator_enable_time,
348 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
263}; 349};
264 350
265#define AB8500_LDO(_id, min, max, reg, reg_mask, reg_enable, \ 351static struct ab8500_regulator_info
266 volt_reg, volt_mask, voltages, \ 352 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
267 len_volts) \
268{ \
269 .desc = { \
270 .name = "LDO-" #_id, \
271 .ops = &ab8500_regulator_ops, \
272 .type = REGULATOR_VOLTAGE, \
273 .id = AB8500_LDO_##_id, \
274 .owner = THIS_MODULE, \
275 }, \
276 .min_uV = (min) * 1000, \
277 .max_uV = (max) * 1000, \
278 .update_reg = reg, \
279 .mask = reg_mask, \
280 .enable = reg_enable, \
281 .voltage_reg = volt_reg, \
282 .voltage_mask = volt_mask, \
283 .supported_voltages = voltages, \
284 .voltages_len = len_volts, \
285 .fixed_uV = 0, \
286}
287
288#define AB8500_FIXED_LDO(_id, fixed, reg, reg_mask, \
289 reg_enable) \
290{ \
291 .desc = { \
292 .name = "LDO-" #_id, \
293 .ops = &ab8500_ldo_fixed_ops, \
294 .type = REGULATOR_VOLTAGE, \
295 .id = AB8500_LDO_##_id, \
296 .owner = THIS_MODULE, \
297 }, \
298 .fixed_uV = fixed * 1000, \
299 .update_reg = reg, \
300 .mask = reg_mask, \
301 .enable = reg_enable, \
302}
303
304static struct ab8500_regulator_info ab8500_regulator_info[] = {
305 /* 353 /*
306 * Variable Voltage LDOs 354 * Variable Voltage Regulators
307 * name, min uV, max uV, ctrl reg, reg mask, enable mask, 355 * name, min mV, max mV,
308 * volt ctrl reg, volt ctrl mask, volt table, num supported volts 356 * update bank, reg, mask, enable val
357 * volt bank, reg, mask, table, table length
309 */ 358 */
310 AB8500_LDO(AUX1, 1100, 3300, 0x0409, 0x3, 0x1, 0x041f, 0xf, 359 [AB8500_LDO_AUX1] = {
311 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 360 .desc = {
312 AB8500_LDO(AUX2, 1100, 3300, 0x0409, 0xc, 0x4, 0x0420, 0xf, 361 .name = "LDO-AUX1",
313 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 362 .ops = &ab8500_regulator_ops,
314 AB8500_LDO(AUX3, 1100, 3300, 0x040a, 0x3, 0x1, 0x0421, 0xf, 363 .type = REGULATOR_VOLTAGE,
315 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 364 .id = AB8500_LDO_AUX1,
316 AB8500_LDO(INTCORE, 1100, 3300, 0x0380, 0x4, 0x4, 0x0380, 0x38, 365 .owner = THIS_MODULE,
317 ldo_vintcore_voltages, ARRAY_SIZE(ldo_vintcore_voltages)), 366 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
367 },
368 .min_uV = 1100000,
369 .max_uV = 3300000,
370 .update_bank = 0x04,
371 .update_reg = 0x09,
372 .update_mask = 0x03,
373 .update_val_enable = 0x01,
374 .voltage_bank = 0x04,
375 .voltage_reg = 0x1f,
376 .voltage_mask = 0x0f,
377 .voltages = ldo_vauxn_voltages,
378 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
379 },
380 [AB8500_LDO_AUX2] = {
381 .desc = {
382 .name = "LDO-AUX2",
383 .ops = &ab8500_regulator_ops,
384 .type = REGULATOR_VOLTAGE,
385 .id = AB8500_LDO_AUX2,
386 .owner = THIS_MODULE,
387 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
388 },
389 .min_uV = 1100000,
390 .max_uV = 3300000,
391 .update_bank = 0x04,
392 .update_reg = 0x09,
393 .update_mask = 0x0c,
394 .update_val_enable = 0x04,
395 .voltage_bank = 0x04,
396 .voltage_reg = 0x20,
397 .voltage_mask = 0x0f,
398 .voltages = ldo_vauxn_voltages,
399 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
400 },
401 [AB8500_LDO_AUX3] = {
402 .desc = {
403 .name = "LDO-AUX3",
404 .ops = &ab8500_regulator_ops,
405 .type = REGULATOR_VOLTAGE,
406 .id = AB8500_LDO_AUX3,
407 .owner = THIS_MODULE,
408 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
409 },
410 .min_uV = 1100000,
411 .max_uV = 3300000,
412 .update_bank = 0x04,
413 .update_reg = 0x0a,
414 .update_mask = 0x03,
415 .update_val_enable = 0x01,
416 .voltage_bank = 0x04,
417 .voltage_reg = 0x21,
418 .voltage_mask = 0x07,
419 .voltages = ldo_vaux3_voltages,
420 .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages),
421 },
422 [AB8500_LDO_INTCORE] = {
423 .desc = {
424 .name = "LDO-INTCORE",
425 .ops = &ab8500_regulator_ops,
426 .type = REGULATOR_VOLTAGE,
427 .id = AB8500_LDO_INTCORE,
428 .owner = THIS_MODULE,
429 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
430 },
431 .min_uV = 1100000,
432 .max_uV = 3300000,
433 .update_bank = 0x03,
434 .update_reg = 0x80,
435 .update_mask = 0x44,
436 .update_val_enable = 0x04,
437 .voltage_bank = 0x03,
438 .voltage_reg = 0x80,
439 .voltage_mask = 0x38,
440 .voltages = ldo_vintcore_voltages,
441 .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages),
442 },
318 443
319 /* 444 /*
320 * Fixed Voltage LDOs 445 * Fixed Voltage Regulators
321 * name, o/p uV, ctrl reg, enable, disable 446 * name, fixed mV,
447 * update bank, reg, mask, enable val
322 */ 448 */
323 AB8500_FIXED_LDO(TVOUT, 2000, 0x0380, 0x2, 0x2), 449 [AB8500_LDO_TVOUT] = {
324 AB8500_FIXED_LDO(AUDIO, 2000, 0x0383, 0x2, 0x2), 450 .desc = {
325 AB8500_FIXED_LDO(ANAMIC1, 2050, 0x0383, 0x4, 0x4), 451 .name = "LDO-TVOUT",
326 AB8500_FIXED_LDO(ANAMIC2, 2050, 0x0383, 0x8, 0x8), 452 .ops = &ab8500_regulator_fixed_ops,
327 AB8500_FIXED_LDO(DMIC, 1800, 0x0383, 0x10, 0x10), 453 .type = REGULATOR_VOLTAGE,
328 AB8500_FIXED_LDO(ANA, 1200, 0x0383, 0xc, 0x4), 454 .id = AB8500_LDO_TVOUT,
455 .owner = THIS_MODULE,
456 .n_voltages = 1,
457 },
458 .delay = 10000,
459 .fixed_uV = 2000000,
460 .update_bank = 0x03,
461 .update_reg = 0x80,
462 .update_mask = 0x82,
463 .update_val_enable = 0x02,
464 },
465 [AB8500_LDO_USB] = {
466 .desc = {
467 .name = "LDO-USB",
468 .ops = &ab8500_regulator_fixed_ops,
469 .type = REGULATOR_VOLTAGE,
470 .id = AB8500_LDO_USB,
471 .owner = THIS_MODULE,
472 .n_voltages = 1,
473 },
474 .fixed_uV = 3300000,
475 .update_bank = 0x03,
476 .update_reg = 0x82,
477 .update_mask = 0x03,
478 .update_val_enable = 0x01,
479 },
480 [AB8500_LDO_AUDIO] = {
481 .desc = {
482 .name = "LDO-AUDIO",
483 .ops = &ab8500_regulator_fixed_ops,
484 .type = REGULATOR_VOLTAGE,
485 .id = AB8500_LDO_AUDIO,
486 .owner = THIS_MODULE,
487 .n_voltages = 1,
488 },
489 .fixed_uV = 2000000,
490 .update_bank = 0x03,
491 .update_reg = 0x83,
492 .update_mask = 0x02,
493 .update_val_enable = 0x02,
494 },
495 [AB8500_LDO_ANAMIC1] = {
496 .desc = {
497 .name = "LDO-ANAMIC1",
498 .ops = &ab8500_regulator_fixed_ops,
499 .type = REGULATOR_VOLTAGE,
500 .id = AB8500_LDO_ANAMIC1,
501 .owner = THIS_MODULE,
502 .n_voltages = 1,
503 },
504 .fixed_uV = 2050000,
505 .update_bank = 0x03,
506 .update_reg = 0x83,
507 .update_mask = 0x08,
508 .update_val_enable = 0x08,
509 },
510 [AB8500_LDO_ANAMIC2] = {
511 .desc = {
512 .name = "LDO-ANAMIC2",
513 .ops = &ab8500_regulator_fixed_ops,
514 .type = REGULATOR_VOLTAGE,
515 .id = AB8500_LDO_ANAMIC2,
516 .owner = THIS_MODULE,
517 .n_voltages = 1,
518 },
519 .fixed_uV = 2050000,
520 .update_bank = 0x03,
521 .update_reg = 0x83,
522 .update_mask = 0x10,
523 .update_val_enable = 0x10,
524 },
525 [AB8500_LDO_DMIC] = {
526 .desc = {
527 .name = "LDO-DMIC",
528 .ops = &ab8500_regulator_fixed_ops,
529 .type = REGULATOR_VOLTAGE,
530 .id = AB8500_LDO_DMIC,
531 .owner = THIS_MODULE,
532 .n_voltages = 1,
533 },
534 .fixed_uV = 1800000,
535 .update_bank = 0x03,
536 .update_reg = 0x83,
537 .update_mask = 0x04,
538 .update_val_enable = 0x04,
539 },
540 [AB8500_LDO_ANA] = {
541 .desc = {
542 .name = "LDO-ANA",
543 .ops = &ab8500_regulator_fixed_ops,
544 .type = REGULATOR_VOLTAGE,
545 .id = AB8500_LDO_ANA,
546 .owner = THIS_MODULE,
547 .n_voltages = 1,
548 },
549 .fixed_uV = 1200000,
550 .update_bank = 0x04,
551 .update_reg = 0x06,
552 .update_mask = 0x0c,
553 .update_val_enable = 0x04,
554 },
555
556
329}; 557};
330 558
331static inline struct ab8500_regulator_info *find_regulator_info(int id) 559struct ab8500_reg_init {
332{ 560 u8 bank;
333 struct ab8500_regulator_info *info; 561 u8 addr;
334 int i; 562 u8 mask;
563};
335 564
336 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 565#define REG_INIT(_id, _bank, _addr, _mask) \
337 info = &ab8500_regulator_info[i]; 566 [_id] = { \
338 if (info->desc.id == id) 567 .bank = _bank, \
339 return info; 568 .addr = _addr, \
569 .mask = _mask, \
340 } 570 }
341 return NULL; 571
342} 572static struct ab8500_reg_init ab8500_reg_init[] = {
573 /*
574 * 0x30, VanaRequestCtrl
575 * 0x0C, VpllRequestCtrl
576 * 0xc0, VextSupply1RequestCtrl
577 */
578 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
579 /*
580 * 0x03, VextSupply2RequestCtrl
581 * 0x0c, VextSupply3RequestCtrl
582 * 0x30, Vaux1RequestCtrl
583 * 0xc0, Vaux2RequestCtrl
584 */
585 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
586 /*
587 * 0x03, Vaux3RequestCtrl
588 * 0x04, SwHPReq
589 */
590 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
591 /*
592 * 0x08, VanaSysClkReq1HPValid
593 * 0x20, Vaux1SysClkReq1HPValid
594 * 0x40, Vaux2SysClkReq1HPValid
595 * 0x80, Vaux3SysClkReq1HPValid
596 */
597 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
598 /*
599 * 0x10, VextSupply1SysClkReq1HPValid
600 * 0x20, VextSupply2SysClkReq1HPValid
601 * 0x40, VextSupply3SysClkReq1HPValid
602 */
603 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
604 /*
605 * 0x08, VanaHwHPReq1Valid
606 * 0x20, Vaux1HwHPReq1Valid
607 * 0x40, Vaux2HwHPReq1Valid
608 * 0x80, Vaux3HwHPReq1Valid
609 */
610 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
611 /*
612 * 0x01, VextSupply1HwHPReq1Valid
613 * 0x02, VextSupply2HwHPReq1Valid
614 * 0x04, VextSupply3HwHPReq1Valid
615 */
616 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
617 /*
618 * 0x08, VanaHwHPReq2Valid
619 * 0x20, Vaux1HwHPReq2Valid
620 * 0x40, Vaux2HwHPReq2Valid
621 * 0x80, Vaux3HwHPReq2Valid
622 */
623 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
624 /*
625 * 0x01, VextSupply1HwHPReq2Valid
626 * 0x02, VextSupply2HwHPReq2Valid
627 * 0x04, VextSupply3HwHPReq2Valid
628 */
629 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
630 /*
631 * 0x20, VanaSwHPReqValid
632 * 0x80, Vaux1SwHPReqValid
633 */
634 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
635 /*
636 * 0x01, Vaux2SwHPReqValid
637 * 0x02, Vaux3SwHPReqValid
638 * 0x04, VextSupply1SwHPReqValid
639 * 0x08, VextSupply2SwHPReqValid
640 * 0x10, VextSupply3SwHPReqValid
641 */
642 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
643 /*
644 * 0x02, SysClkReq2Valid1
645 * ...
646 * 0x80, SysClkReq8Valid1
647 */
648 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
649 /*
650 * 0x02, SysClkReq2Valid2
651 * ...
652 * 0x80, SysClkReq8Valid2
653 */
654 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
655 /*
656 * 0x02, VTVoutEna
657 * 0x04, Vintcore12Ena
658 * 0x38, Vintcore12Sel
659 * 0x40, Vintcore12LP
660 * 0x80, VTVoutLP
661 */
662 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
663 /*
664 * 0x02, VaudioEna
665 * 0x04, VdmicEna
666 * 0x08, Vamic1Ena
667 * 0x10, Vamic2Ena
668 */
669 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
670 /*
671 * 0x01, Vamic1_dzout
672 * 0x02, Vamic2_dzout
673 */
674 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
675 /*
676 * 0x0c, VanaRegu
677 * 0x03, VpllRegu
678 */
679 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
680 /*
681 * 0x01, VrefDDREna
682 * 0x02, VrefDDRSleepMode
683 */
684 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
685 /*
686 * 0x03, VextSupply1Regu
687 * 0x0c, VextSupply2Regu
688 * 0x30, VextSupply3Regu
689 * 0x40, ExtSupply2Bypass
690 * 0x80, ExtSupply3Bypass
691 */
692 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
693 /*
694 * 0x03, Vaux1Regu
695 * 0x0c, Vaux2Regu
696 */
697 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
698 /*
699 * 0x03, Vaux3Regu
700 */
701 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
702 /*
703 * 0x3f, Vsmps1Sel1
704 */
705 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
706 /*
707 * 0x0f, Vaux1Sel
708 */
709 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
710 /*
711 * 0x0f, Vaux2Sel
712 */
713 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
714 /*
715 * 0x07, Vaux3Sel
716 */
717 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
718 /*
719 * 0x01, VextSupply12LP
720 */
721 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
722 /*
723 * 0x04, Vaux1Disch
724 * 0x08, Vaux2Disch
725 * 0x10, Vaux3Disch
726 * 0x20, Vintcore12Disch
727 * 0x40, VTVoutDisch
728 * 0x80, VaudioDisch
729 */
730 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
731 /*
732 * 0x02, VanaDisch
733 * 0x04, VdmicPullDownEna
734 * 0x10, VdmicDisch
735 */
736 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
737};
343 738
344static __devinit int ab8500_regulator_probe(struct platform_device *pdev) 739static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
345{ 740{
@@ -352,6 +747,57 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
352 return -EINVAL; 747 return -EINVAL;
353 } 748 }
354 pdata = dev_get_platdata(ab8500->dev); 749 pdata = dev_get_platdata(ab8500->dev);
750 if (!pdata) {
751 dev_err(&pdev->dev, "null pdata\n");
752 return -EINVAL;
753 }
754
755 /* make sure the platform data has the correct size */
756 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
757 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
758 return -EINVAL;
759 }
760
761 /* initialize registers */
762 for (i = 0; i < pdata->num_regulator_reg_init; i++) {
763 int id;
764 u8 value;
765
766 id = pdata->regulator_reg_init[i].id;
767 value = pdata->regulator_reg_init[i].value;
768
769 /* check for configuration errors */
770 if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
771 dev_err(&pdev->dev,
772 "Configuration error: id outside range.\n");
773 return -EINVAL;
774 }
775 if (value & ~ab8500_reg_init[id].mask) {
776 dev_err(&pdev->dev,
777 "Configuration error: value outside mask.\n");
778 return -EINVAL;
779 }
780
781 /* initialize register */
782 err = abx500_mask_and_set_register_interruptible(&pdev->dev,
783 ab8500_reg_init[id].bank,
784 ab8500_reg_init[id].addr,
785 ab8500_reg_init[id].mask,
786 value);
787 if (err < 0) {
788 dev_err(&pdev->dev,
789 "Failed to initialize 0x%02x, 0x%02x.\n",
790 ab8500_reg_init[id].bank,
791 ab8500_reg_init[id].addr);
792 return err;
793 }
794 dev_vdbg(&pdev->dev,
795 " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
796 ab8500_reg_init[id].bank,
797 ab8500_reg_init[id].addr,
798 ab8500_reg_init[id].mask,
799 value);
800 }
355 801
356 /* register all regulators */ 802 /* register all regulators */
357 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 803 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
@@ -360,10 +806,22 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
360 /* assign per-regulator data */ 806 /* assign per-regulator data */
361 info = &ab8500_regulator_info[i]; 807 info = &ab8500_regulator_info[i];
362 info->dev = &pdev->dev; 808 info->dev = &pdev->dev;
363 info->ab8500 = ab8500;
364 809
810 /* fix for hardware before ab8500v2.0 */
811 if (abx500_get_chip_id(info->dev) < 0x20) {
812 if (info->desc.id == AB8500_LDO_AUX3) {
813 info->desc.n_voltages =
814 ARRAY_SIZE(ldo_vauxn_voltages);
815 info->voltages = ldo_vauxn_voltages;
816 info->voltages_len =
817 ARRAY_SIZE(ldo_vauxn_voltages);
818 info->voltage_mask = 0xf;
819 }
820 }
821
822 /* register regulator with framework */
365 info->regulator = regulator_register(&info->desc, &pdev->dev, 823 info->regulator = regulator_register(&info->desc, &pdev->dev,
366 pdata->regulator[i], info); 824 &pdata->regulator[i], info);
367 if (IS_ERR(info->regulator)) { 825 if (IS_ERR(info->regulator)) {
368 err = PTR_ERR(info->regulator); 826 err = PTR_ERR(info->regulator);
369 dev_err(&pdev->dev, "failed to register regulator %s\n", 827 dev_err(&pdev->dev, "failed to register regulator %s\n",
@@ -375,6 +833,9 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
375 } 833 }
376 return err; 834 return err;
377 } 835 }
836
837 dev_vdbg(rdev_get_dev(info->regulator),
838 "%s-probed\n", info->desc.name);
378 } 839 }
379 840
380 return 0; 841 return 0;
@@ -387,6 +848,10 @@ static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
387 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 848 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
388 struct ab8500_regulator_info *info = NULL; 849 struct ab8500_regulator_info *info = NULL;
389 info = &ab8500_regulator_info[i]; 850 info = &ab8500_regulator_info[i];
851
852 dev_vdbg(rdev_get_dev(info->regulator),
853 "%s-remove\n", info->desc.name);
854
390 regulator_unregister(info->regulator); 855 regulator_unregister(info->regulator);
391 } 856 }
392 857