blob: d157146c86554700092b0e6ee1b6465fc324807b [file] [log] [blame]
Sundar R IYERc789ca22010-07-13 21:48:56 +05301/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 *
Bengt Jonssone1159e62010-12-10 11:08:44 +01006 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
Sundar R IYERc789ca22010-07-13 21:48:56 +05308 *
9 * AB8500 peripheral regulators
10 *
Bengt Jonssone1159e62010-12-10 11:08:44 +010011 * AB8500 supports the following regulators:
Bengt Jonssonea05ef32011-03-10 14:43:31 +010012 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
Sundar R IYERc789ca22010-07-13 21:48:56 +053013 */
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/err.h>
17#include <linux/platform_device.h>
18#include <linux/mfd/ab8500.h>
Mattias Wallin47c16972010-09-10 17:47:56 +020019#include <linux/mfd/abx500.h>
Sundar R IYERc789ca22010-07-13 21:48:56 +053020#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22#include <linux/regulator/ab8500.h>
23
24/**
25 * struct ab8500_regulator_info - ab8500 regulator information
Bengt Jonssone1159e62010-12-10 11:08:44 +010026 * @dev: device pointer
Sundar R IYERc789ca22010-07-13 21:48:56 +053027 * @desc: regulator description
Sundar R IYERc789ca22010-07-13 21:48:56 +053028 * @regulator_dev: regulator device
29 * @max_uV: maximum voltage (for variable voltage supplies)
30 * @min_uV: minimum voltage (for variable voltage supplies)
31 * @fixed_uV: typical voltage (for fixed voltage supplies)
Mattias Wallin47c16972010-09-10 17:47:56 +020032 * @update_bank: bank to control on/off
Sundar R IYERc789ca22010-07-13 21:48:56 +053033 * @update_reg: register to control on/off
Bengt Jonssone1159e62010-12-10 11:08:44 +010034 * @update_mask: mask to enable/disable regulator
35 * @update_val_enable: bits to enable the regulator in normal (high power) mode
Mattias Wallin47c16972010-09-10 17:47:56 +020036 * @voltage_bank: bank to control regulator voltage
Sundar R IYERc789ca22010-07-13 21:48:56 +053037 * @voltage_reg: register to control regulator voltage
38 * @voltage_mask: mask to control regulator voltage
Bengt Jonssone1159e62010-12-10 11:08:44 +010039 * @voltages: supported voltage table
Sundar R IYERc789ca22010-07-13 21:48:56 +053040 * @voltages_len: number of supported voltages for the regulator
41 */
42struct ab8500_regulator_info {
43 struct device *dev;
44 struct regulator_desc desc;
Sundar R IYERc789ca22010-07-13 21:48:56 +053045 struct regulator_dev *regulator;
46 int max_uV;
47 int min_uV;
48 int fixed_uV;
Mattias Wallin47c16972010-09-10 17:47:56 +020049 u8 update_bank;
50 u8 update_reg;
Bengt Jonssone1159e62010-12-10 11:08:44 +010051 u8 update_mask;
52 u8 update_val_enable;
Mattias Wallin47c16972010-09-10 17:47:56 +020053 u8 voltage_bank;
54 u8 voltage_reg;
55 u8 voltage_mask;
Bengt Jonssone1159e62010-12-10 11:08:44 +010056 int const *voltages;
Sundar R IYERc789ca22010-07-13 21:48:56 +053057 int voltages_len;
58};
59
60/* voltage tables for the vauxn/vintcore supplies */
61static const int ldo_vauxn_voltages[] = {
62 1100000,
63 1200000,
64 1300000,
65 1400000,
66 1500000,
67 1800000,
68 1850000,
69 1900000,
70 2500000,
71 2650000,
72 2700000,
73 2750000,
74 2800000,
75 2900000,
76 3000000,
77 3300000,
78};
79
Bengt Jonsson2b751512010-12-10 11:08:43 +010080static const int ldo_vaux3_voltages[] = {
81 1200000,
82 1500000,
83 1800000,
84 2100000,
85 2500000,
86 2750000,
87 2790000,
88 2910000,
89};
90
Sundar R IYERc789ca22010-07-13 21:48:56 +053091static const int ldo_vintcore_voltages[] = {
92 1200000,
93 1225000,
94 1250000,
95 1275000,
96 1300000,
97 1325000,
98 1350000,
99};
100
101static int ab8500_regulator_enable(struct regulator_dev *rdev)
102{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100103 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530104 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
105
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100106 if (info == NULL) {
107 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530108 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100109 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530110
Mattias Wallin47c16972010-09-10 17:47:56 +0200111 ret = abx500_mask_and_set_register_interruptible(info->dev,
Bengt Jonssone1159e62010-12-10 11:08:44 +0100112 info->update_bank, info->update_reg,
113 info->update_mask, info->update_val_enable);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530114 if (ret < 0)
115 dev_err(rdev_get_dev(rdev),
116 "couldn't set enable bits for regulator\n");
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100117
118 dev_vdbg(rdev_get_dev(rdev),
119 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
120 info->desc.name, info->update_bank, info->update_reg,
121 info->update_mask, info->update_val_enable);
122
Sundar R IYERc789ca22010-07-13 21:48:56 +0530123 return ret;
124}
125
126static int ab8500_regulator_disable(struct regulator_dev *rdev)
127{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100128 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530129 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
130
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100131 if (info == NULL) {
132 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530133 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100134 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530135
Mattias Wallin47c16972010-09-10 17:47:56 +0200136 ret = abx500_mask_and_set_register_interruptible(info->dev,
Bengt Jonssone1159e62010-12-10 11:08:44 +0100137 info->update_bank, info->update_reg,
138 info->update_mask, 0x0);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530139 if (ret < 0)
140 dev_err(rdev_get_dev(rdev),
141 "couldn't set disable bits for regulator\n");
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100142
143 dev_vdbg(rdev_get_dev(rdev),
144 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
145 info->desc.name, info->update_bank, info->update_reg,
146 info->update_mask, 0x0);
147
Sundar R IYERc789ca22010-07-13 21:48:56 +0530148 return ret;
149}
150
151static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
152{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100153 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530154 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100155 u8 regval;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530156
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100157 if (info == NULL) {
158 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530159 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100160 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530161
Mattias Wallin47c16972010-09-10 17:47:56 +0200162 ret = abx500_get_register_interruptible(info->dev,
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100163 info->update_bank, info->update_reg, &regval);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530164 if (ret < 0) {
165 dev_err(rdev_get_dev(rdev),
166 "couldn't read 0x%x register\n", info->update_reg);
167 return ret;
168 }
169
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100170 dev_vdbg(rdev_get_dev(rdev),
171 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
172 " 0x%x\n",
173 info->desc.name, info->update_bank, info->update_reg,
174 info->update_mask, regval);
175
176 if (regval & info->update_mask)
Sundar R IYERc789ca22010-07-13 21:48:56 +0530177 return true;
178 else
179 return false;
180}
181
182static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
183{
Sundar R IYERc789ca22010-07-13 21:48:56 +0530184 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
185
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100186 if (info == NULL) {
187 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530188 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100189 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530190
191 /* return the uV for the fixed regulators */
192 if (info->fixed_uV)
193 return info->fixed_uV;
194
Axel Lin49990e62010-09-04 23:06:41 +0800195 if (selector >= info->voltages_len)
Sundar R IYERc789ca22010-07-13 21:48:56 +0530196 return -EINVAL;
197
Bengt Jonssone1159e62010-12-10 11:08:44 +0100198 return info->voltages[selector];
Sundar R IYERc789ca22010-07-13 21:48:56 +0530199}
200
201static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
202{
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100203 int ret, val;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530204 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100205 u8 regval;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530206
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100207 if (info == NULL) {
208 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530209 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100210 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530211
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100212 ret = abx500_get_register_interruptible(info->dev,
213 info->voltage_bank, info->voltage_reg, &regval);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530214 if (ret < 0) {
215 dev_err(rdev_get_dev(rdev),
216 "couldn't read voltage reg for regulator\n");
217 return ret;
218 }
219
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100220 dev_vdbg(rdev_get_dev(rdev),
221 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
222 " 0x%x\n",
223 info->desc.name, info->voltage_bank, info->voltage_reg,
224 info->voltage_mask, regval);
225
Sundar R IYERc789ca22010-07-13 21:48:56 +0530226 /* vintcore has a different layout */
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100227 val = regval & info->voltage_mask;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100228 if (info->desc.id == AB8500_LDO_INTCORE)
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100229 ret = info->voltages[val >> 0x3];
Sundar R IYERc789ca22010-07-13 21:48:56 +0530230 else
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100231 ret = info->voltages[val];
Sundar R IYERc789ca22010-07-13 21:48:56 +0530232
233 return ret;
234}
235
236static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
237 int min_uV, int max_uV)
238{
239 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
240 int i;
241
242 /* check the supported voltage */
243 for (i = 0; i < info->voltages_len; i++) {
Bengt Jonssone1159e62010-12-10 11:08:44 +0100244 if ((info->voltages[i] >= min_uV) &&
245 (info->voltages[i] <= max_uV))
Sundar R IYERc789ca22010-07-13 21:48:56 +0530246 return i;
247 }
248
249 return -EINVAL;
250}
251
252static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000253 int min_uV, int max_uV,
254 unsigned *selector)
Sundar R IYERc789ca22010-07-13 21:48:56 +0530255{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100256 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530257 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100258 u8 regval;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530259
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100260 if (info == NULL) {
261 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530262 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100263 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530264
265 /* get the appropriate voltages within the range */
266 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
267 if (ret < 0) {
268 dev_err(rdev_get_dev(rdev),
269 "couldn't get best voltage for regulator\n");
270 return ret;
271 }
272
Mark Brown3a93f2a2010-11-10 14:38:29 +0000273 *selector = ret;
274
Sundar R IYERc789ca22010-07-13 21:48:56 +0530275 /* set the registers for the request */
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100276 regval = (u8)ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200277 ret = abx500_mask_and_set_register_interruptible(info->dev,
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100278 info->voltage_bank, info->voltage_reg,
279 info->voltage_mask, regval);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530280 if (ret < 0)
281 dev_err(rdev_get_dev(rdev),
282 "couldn't set voltage reg for regulator\n");
283
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100284 dev_vdbg(rdev_get_dev(rdev),
285 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
286 " 0x%x\n",
287 info->desc.name, info->voltage_bank, info->voltage_reg,
288 info->voltage_mask, regval);
289
Sundar R IYERc789ca22010-07-13 21:48:56 +0530290 return ret;
291}
292
293static struct regulator_ops ab8500_regulator_ops = {
294 .enable = ab8500_regulator_enable,
295 .disable = ab8500_regulator_disable,
296 .is_enabled = ab8500_regulator_is_enabled,
297 .get_voltage = ab8500_regulator_get_voltage,
298 .set_voltage = ab8500_regulator_set_voltage,
299 .list_voltage = ab8500_list_voltage,
300};
301
302static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
303{
Sundar R IYERc789ca22010-07-13 21:48:56 +0530304 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
305
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100306 if (info == NULL) {
307 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530308 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100309 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530310
311 return info->fixed_uV;
312}
313
Bengt Jonsson6909b452010-12-10 11:08:47 +0100314static struct regulator_ops ab8500_regulator_fixed_ops = {
Sundar R IYERc789ca22010-07-13 21:48:56 +0530315 .enable = ab8500_regulator_enable,
316 .disable = ab8500_regulator_disable,
317 .is_enabled = ab8500_regulator_is_enabled,
318 .get_voltage = ab8500_fixed_get_voltage,
319 .list_voltage = ab8500_list_voltage,
320};
321
Bengt Jonsson6909b452010-12-10 11:08:47 +0100322static struct ab8500_regulator_info
323 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
Sundar R IYERc789ca22010-07-13 21:48:56 +0530324 /*
Bengt Jonssone1159e62010-12-10 11:08:44 +0100325 * Variable Voltage Regulators
326 * name, min mV, max mV,
327 * update bank, reg, mask, enable val
328 * volt bank, reg, mask, table, table length
Sundar R IYERc789ca22010-07-13 21:48:56 +0530329 */
Bengt Jonsson6909b452010-12-10 11:08:47 +0100330 [AB8500_LDO_AUX1] = {
331 .desc = {
332 .name = "LDO-AUX1",
333 .ops = &ab8500_regulator_ops,
334 .type = REGULATOR_VOLTAGE,
335 .id = AB8500_LDO_AUX1,
336 .owner = THIS_MODULE,
337 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
338 },
339 .min_uV = 1100000,
340 .max_uV = 3300000,
341 .update_bank = 0x04,
342 .update_reg = 0x09,
343 .update_mask = 0x03,
344 .update_val_enable = 0x01,
345 .voltage_bank = 0x04,
346 .voltage_reg = 0x1f,
347 .voltage_mask = 0x0f,
348 .voltages = ldo_vauxn_voltages,
349 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
350 },
351 [AB8500_LDO_AUX2] = {
352 .desc = {
353 .name = "LDO-AUX2",
354 .ops = &ab8500_regulator_ops,
355 .type = REGULATOR_VOLTAGE,
356 .id = AB8500_LDO_AUX2,
357 .owner = THIS_MODULE,
358 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
359 },
360 .min_uV = 1100000,
361 .max_uV = 3300000,
362 .update_bank = 0x04,
363 .update_reg = 0x09,
364 .update_mask = 0x0c,
365 .update_val_enable = 0x04,
366 .voltage_bank = 0x04,
367 .voltage_reg = 0x20,
368 .voltage_mask = 0x0f,
369 .voltages = ldo_vauxn_voltages,
370 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
371 },
372 [AB8500_LDO_AUX3] = {
373 .desc = {
374 .name = "LDO-AUX3",
375 .ops = &ab8500_regulator_ops,
376 .type = REGULATOR_VOLTAGE,
377 .id = AB8500_LDO_AUX3,
378 .owner = THIS_MODULE,
379 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
380 },
381 .min_uV = 1100000,
382 .max_uV = 3300000,
383 .update_bank = 0x04,
384 .update_reg = 0x0a,
385 .update_mask = 0x03,
386 .update_val_enable = 0x01,
387 .voltage_bank = 0x04,
388 .voltage_reg = 0x21,
389 .voltage_mask = 0x07,
390 .voltages = ldo_vaux3_voltages,
391 .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages),
392 },
393 [AB8500_LDO_INTCORE] = {
394 .desc = {
395 .name = "LDO-INTCORE",
396 .ops = &ab8500_regulator_ops,
397 .type = REGULATOR_VOLTAGE,
398 .id = AB8500_LDO_INTCORE,
399 .owner = THIS_MODULE,
400 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
401 },
402 .min_uV = 1100000,
403 .max_uV = 3300000,
404 .update_bank = 0x03,
405 .update_reg = 0x80,
406 .update_mask = 0x44,
407 .update_val_enable = 0x04,
408 .voltage_bank = 0x03,
409 .voltage_reg = 0x80,
410 .voltage_mask = 0x38,
411 .voltages = ldo_vintcore_voltages,
412 .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages),
413 },
Sundar R IYERc789ca22010-07-13 21:48:56 +0530414
415 /*
Bengt Jonssone1159e62010-12-10 11:08:44 +0100416 * Fixed Voltage Regulators
417 * name, fixed mV,
418 * update bank, reg, mask, enable val
Sundar R IYERc789ca22010-07-13 21:48:56 +0530419 */
Bengt Jonsson6909b452010-12-10 11:08:47 +0100420 [AB8500_LDO_TVOUT] = {
421 .desc = {
422 .name = "LDO-TVOUT",
423 .ops = &ab8500_regulator_fixed_ops,
424 .type = REGULATOR_VOLTAGE,
425 .id = AB8500_LDO_TVOUT,
426 .owner = THIS_MODULE,
427 .n_voltages = 1,
428 },
429 .fixed_uV = 2000000,
430 .update_bank = 0x03,
431 .update_reg = 0x80,
432 .update_mask = 0x82,
433 .update_val_enable = 0x02,
434 },
Bengt Jonssonea05ef32011-03-10 14:43:31 +0100435 [AB8500_LDO_USB] = {
436 .desc = {
437 .name = "LDO-USB",
438 .ops = &ab8500_regulator_fixed_ops,
439 .type = REGULATOR_VOLTAGE,
440 .id = AB8500_LDO_USB,
441 .owner = THIS_MODULE,
442 .n_voltages = 1,
443 },
444 .fixed_uV = 3300000,
445 .update_bank = 0x03,
446 .update_reg = 0x82,
447 .update_mask = 0x03,
448 .update_val_enable = 0x01,
449 },
Bengt Jonsson6909b452010-12-10 11:08:47 +0100450 [AB8500_LDO_AUDIO] = {
451 .desc = {
452 .name = "LDO-AUDIO",
453 .ops = &ab8500_regulator_fixed_ops,
454 .type = REGULATOR_VOLTAGE,
455 .id = AB8500_LDO_AUDIO,
456 .owner = THIS_MODULE,
457 .n_voltages = 1,
458 },
459 .fixed_uV = 2000000,
460 .update_bank = 0x03,
461 .update_reg = 0x83,
462 .update_mask = 0x02,
463 .update_val_enable = 0x02,
464 },
465 [AB8500_LDO_ANAMIC1] = {
466 .desc = {
467 .name = "LDO-ANAMIC1",
468 .ops = &ab8500_regulator_fixed_ops,
469 .type = REGULATOR_VOLTAGE,
470 .id = AB8500_LDO_ANAMIC1,
471 .owner = THIS_MODULE,
472 .n_voltages = 1,
473 },
474 .fixed_uV = 2050000,
475 .update_bank = 0x03,
476 .update_reg = 0x83,
477 .update_mask = 0x08,
478 .update_val_enable = 0x08,
479 },
480 [AB8500_LDO_ANAMIC2] = {
481 .desc = {
482 .name = "LDO-ANAMIC2",
483 .ops = &ab8500_regulator_fixed_ops,
484 .type = REGULATOR_VOLTAGE,
485 .id = AB8500_LDO_ANAMIC2,
486 .owner = THIS_MODULE,
487 .n_voltages = 1,
488 },
489 .fixed_uV = 2050000,
490 .update_bank = 0x03,
491 .update_reg = 0x83,
492 .update_mask = 0x10,
493 .update_val_enable = 0x10,
494 },
495 [AB8500_LDO_DMIC] = {
496 .desc = {
497 .name = "LDO-DMIC",
498 .ops = &ab8500_regulator_fixed_ops,
499 .type = REGULATOR_VOLTAGE,
500 .id = AB8500_LDO_DMIC,
501 .owner = THIS_MODULE,
502 .n_voltages = 1,
503 },
504 .fixed_uV = 1800000,
505 .update_bank = 0x03,
506 .update_reg = 0x83,
507 .update_mask = 0x04,
508 .update_val_enable = 0x04,
509 },
510 [AB8500_LDO_ANA] = {
511 .desc = {
512 .name = "LDO-ANA",
513 .ops = &ab8500_regulator_fixed_ops,
514 .type = REGULATOR_VOLTAGE,
515 .id = AB8500_LDO_ANA,
516 .owner = THIS_MODULE,
517 .n_voltages = 1,
518 },
519 .fixed_uV = 1200000,
520 .update_bank = 0x04,
521 .update_reg = 0x06,
522 .update_mask = 0x0c,
523 .update_val_enable = 0x04,
524 },
525
526
Sundar R IYERc789ca22010-07-13 21:48:56 +0530527};
528
Bengt Jonsson79568b92011-03-11 11:54:46 +0100529struct ab8500_reg_init {
530 u8 bank;
531 u8 addr;
532 u8 mask;
533};
534
535#define REG_INIT(_id, _bank, _addr, _mask) \
536 [_id] = { \
537 .bank = _bank, \
538 .addr = _addr, \
539 .mask = _mask, \
540 }
541
542static struct ab8500_reg_init ab8500_reg_init[] = {
543 /*
544 * 0x30, VanaRequestCtrl
545 * 0x0C, VpllRequestCtrl
546 * 0xc0, VextSupply1RequestCtrl
547 */
548 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
549 /*
550 * 0x03, VextSupply2RequestCtrl
551 * 0x0c, VextSupply3RequestCtrl
552 * 0x30, Vaux1RequestCtrl
553 * 0xc0, Vaux2RequestCtrl
554 */
555 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
556 /*
557 * 0x03, Vaux3RequestCtrl
558 * 0x04, SwHPReq
559 */
560 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
561 /*
562 * 0x08, VanaSysClkReq1HPValid
563 * 0x20, Vaux1SysClkReq1HPValid
564 * 0x40, Vaux2SysClkReq1HPValid
565 * 0x80, Vaux3SysClkReq1HPValid
566 */
567 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
568 /*
569 * 0x10, VextSupply1SysClkReq1HPValid
570 * 0x20, VextSupply2SysClkReq1HPValid
571 * 0x40, VextSupply3SysClkReq1HPValid
572 */
573 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
574 /*
575 * 0x08, VanaHwHPReq1Valid
576 * 0x20, Vaux1HwHPReq1Valid
577 * 0x40, Vaux2HwHPReq1Valid
578 * 0x80, Vaux3HwHPReq1Valid
579 */
580 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
581 /*
582 * 0x01, VextSupply1HwHPReq1Valid
583 * 0x02, VextSupply2HwHPReq1Valid
584 * 0x04, VextSupply3HwHPReq1Valid
585 */
586 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
587 /*
588 * 0x08, VanaHwHPReq2Valid
589 * 0x20, Vaux1HwHPReq2Valid
590 * 0x40, Vaux2HwHPReq2Valid
591 * 0x80, Vaux3HwHPReq2Valid
592 */
593 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
594 /*
595 * 0x01, VextSupply1HwHPReq2Valid
596 * 0x02, VextSupply2HwHPReq2Valid
597 * 0x04, VextSupply3HwHPReq2Valid
598 */
599 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
600 /*
601 * 0x20, VanaSwHPReqValid
602 * 0x80, Vaux1SwHPReqValid
603 */
604 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
605 /*
606 * 0x01, Vaux2SwHPReqValid
607 * 0x02, Vaux3SwHPReqValid
608 * 0x04, VextSupply1SwHPReqValid
609 * 0x08, VextSupply2SwHPReqValid
610 * 0x10, VextSupply3SwHPReqValid
611 */
612 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
613 /*
614 * 0x02, SysClkReq2Valid1
615 * ...
616 * 0x80, SysClkReq8Valid1
617 */
618 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
619 /*
620 * 0x02, SysClkReq2Valid2
621 * ...
622 * 0x80, SysClkReq8Valid2
623 */
624 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
625 /*
626 * 0x02, VTVoutEna
627 * 0x04, Vintcore12Ena
628 * 0x38, Vintcore12Sel
629 * 0x40, Vintcore12LP
630 * 0x80, VTVoutLP
631 */
632 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
633 /*
634 * 0x02, VaudioEna
635 * 0x04, VdmicEna
636 * 0x08, Vamic1Ena
637 * 0x10, Vamic2Ena
638 */
639 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
640 /*
641 * 0x01, Vamic1_dzout
642 * 0x02, Vamic2_dzout
643 */
644 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
645 /*
646 * 0x0c, VanaRegu
647 * 0x03, VpllRegu
648 */
649 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
650 /*
651 * 0x01, VrefDDREna
652 * 0x02, VrefDDRSleepMode
653 */
654 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
655 /*
656 * 0x03, VextSupply1Regu
657 * 0x0c, VextSupply2Regu
658 * 0x30, VextSupply3Regu
659 * 0x40, ExtSupply2Bypass
660 * 0x80, ExtSupply3Bypass
661 */
662 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
663 /*
664 * 0x03, Vaux1Regu
665 * 0x0c, Vaux2Regu
666 */
667 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
668 /*
669 * 0x03, Vaux3Regu
670 */
671 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
672 /*
673 * 0x3f, Vsmps1Sel1
674 */
675 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
676 /*
677 * 0x0f, Vaux1Sel
678 */
679 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
680 /*
681 * 0x0f, Vaux2Sel
682 */
683 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
684 /*
685 * 0x07, Vaux3Sel
686 */
687 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
688 /*
689 * 0x01, VextSupply12LP
690 */
691 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
692 /*
693 * 0x04, Vaux1Disch
694 * 0x08, Vaux2Disch
695 * 0x10, Vaux3Disch
696 * 0x20, Vintcore12Disch
697 * 0x40, VTVoutDisch
698 * 0x80, VaudioDisch
699 */
700 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
701 /*
702 * 0x02, VanaDisch
703 * 0x04, VdmicPullDownEna
704 * 0x10, VdmicDisch
705 */
706 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
707};
708
Sundar R IYERc789ca22010-07-13 21:48:56 +0530709static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
710{
711 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
Dan Carpenteraf54dec2010-08-14 11:03:16 +0200712 struct ab8500_platform_data *pdata;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530713 int i, err;
714
715 if (!ab8500) {
716 dev_err(&pdev->dev, "null mfd parent\n");
717 return -EINVAL;
718 }
Dan Carpenteraf54dec2010-08-14 11:03:16 +0200719 pdata = dev_get_platdata(ab8500->dev);
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100720 if (!pdata) {
721 dev_err(&pdev->dev, "null pdata\n");
722 return -EINVAL;
723 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530724
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100725 /* make sure the platform data has the correct size */
726 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
Bengt Jonsson79568b92011-03-11 11:54:46 +0100727 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100728 return -EINVAL;
729 }
730
Bengt Jonsson79568b92011-03-11 11:54:46 +0100731 /* initialize registers */
732 for (i = 0; i < pdata->num_regulator_reg_init; i++) {
733 int id;
734 u8 value;
735
736 id = pdata->regulator_reg_init[i].id;
737 value = pdata->regulator_reg_init[i].value;
738
739 /* check for configuration errors */
740 if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
741 dev_err(&pdev->dev,
742 "Configuration error: id outside range.\n");
743 return -EINVAL;
744 }
745 if (value & ~ab8500_reg_init[id].mask) {
746 dev_err(&pdev->dev,
747 "Configuration error: value outside mask.\n");
748 return -EINVAL;
749 }
750
751 /* initialize register */
752 err = abx500_mask_and_set_register_interruptible(&pdev->dev,
753 ab8500_reg_init[id].bank,
754 ab8500_reg_init[id].addr,
755 ab8500_reg_init[id].mask,
756 value);
757 if (err < 0) {
758 dev_err(&pdev->dev,
759 "Failed to initialize 0x%02x, 0x%02x.\n",
760 ab8500_reg_init[id].bank,
761 ab8500_reg_init[id].addr);
762 return err;
763 }
764 dev_vdbg(&pdev->dev,
765 " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
766 ab8500_reg_init[id].bank,
767 ab8500_reg_init[id].addr,
768 ab8500_reg_init[id].mask,
769 value);
770 }
771
Sundar R IYERc789ca22010-07-13 21:48:56 +0530772 /* register all regulators */
773 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
774 struct ab8500_regulator_info *info = NULL;
775
776 /* assign per-regulator data */
777 info = &ab8500_regulator_info[i];
778 info->dev = &pdev->dev;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530779
Bengt Jonsson2b751512010-12-10 11:08:43 +0100780 /* fix for hardware before ab8500v2.0 */
781 if (abx500_get_chip_id(info->dev) < 0x20) {
782 if (info->desc.id == AB8500_LDO_AUX3) {
783 info->desc.n_voltages =
784 ARRAY_SIZE(ldo_vauxn_voltages);
Bengt Jonssone1159e62010-12-10 11:08:44 +0100785 info->voltages = ldo_vauxn_voltages;
Bengt Jonsson2b751512010-12-10 11:08:43 +0100786 info->voltages_len =
787 ARRAY_SIZE(ldo_vauxn_voltages);
788 info->voltage_mask = 0xf;
789 }
790 }
791
792 /* register regulator with framework */
Sundar R IYERc789ca22010-07-13 21:48:56 +0530793 info->regulator = regulator_register(&info->desc, &pdev->dev,
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100794 &pdata->regulator[i], info);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530795 if (IS_ERR(info->regulator)) {
796 err = PTR_ERR(info->regulator);
797 dev_err(&pdev->dev, "failed to register regulator %s\n",
798 info->desc.name);
799 /* when we fail, un-register all earlier regulators */
Axel Lind4876a32010-08-14 21:44:04 +0800800 while (--i >= 0) {
Sundar R IYERc789ca22010-07-13 21:48:56 +0530801 info = &ab8500_regulator_info[i];
802 regulator_unregister(info->regulator);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530803 }
804 return err;
805 }
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100806
807 dev_vdbg(rdev_get_dev(info->regulator),
808 "%s-probed\n", info->desc.name);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530809 }
810
811 return 0;
812}
813
814static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
815{
816 int i;
817
818 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
819 struct ab8500_regulator_info *info = NULL;
820 info = &ab8500_regulator_info[i];
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100821
822 dev_vdbg(rdev_get_dev(info->regulator),
823 "%s-remove\n", info->desc.name);
824
Sundar R IYERc789ca22010-07-13 21:48:56 +0530825 regulator_unregister(info->regulator);
826 }
827
828 return 0;
829}
830
831static struct platform_driver ab8500_regulator_driver = {
832 .probe = ab8500_regulator_probe,
833 .remove = __devexit_p(ab8500_regulator_remove),
834 .driver = {
835 .name = "ab8500-regulator",
836 .owner = THIS_MODULE,
837 },
838};
839
840static int __init ab8500_regulator_init(void)
841{
842 int ret;
843
844 ret = platform_driver_register(&ab8500_regulator_driver);
845 if (ret != 0)
846 pr_err("Failed to register ab8500 regulator: %d\n", ret);
847
848 return ret;
849}
850subsys_initcall(ab8500_regulator_init);
851
852static void __exit ab8500_regulator_exit(void)
853{
854 platform_driver_unregister(&ab8500_regulator_driver);
855}
856module_exit(ab8500_regulator_exit);
857
858MODULE_LICENSE("GPL v2");
859MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
860MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
861MODULE_ALIAS("platform:ab8500-regulator");