blob: 02f3c2333c8374d81f3bec3a1e2fb714f4c71095 [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
Linus Walleij42ab6162011-03-17 13:25:02 +010041 * @delay: startup/set voltage delay in us
Sundar R IYERc789ca22010-07-13 21:48:56 +053042 */
43struct ab8500_regulator_info {
44 struct device *dev;
45 struct regulator_desc desc;
Sundar R IYERc789ca22010-07-13 21:48:56 +053046 struct regulator_dev *regulator;
47 int max_uV;
48 int min_uV;
49 int fixed_uV;
Mattias Wallin47c16972010-09-10 17:47:56 +020050 u8 update_bank;
51 u8 update_reg;
Bengt Jonssone1159e62010-12-10 11:08:44 +010052 u8 update_mask;
53 u8 update_val_enable;
Mattias Wallin47c16972010-09-10 17:47:56 +020054 u8 voltage_bank;
55 u8 voltage_reg;
56 u8 voltage_mask;
Bengt Jonssone1159e62010-12-10 11:08:44 +010057 int const *voltages;
Sundar R IYERc789ca22010-07-13 21:48:56 +053058 int voltages_len;
Linus Walleij42ab6162011-03-17 13:25:02 +010059 unsigned int delay;
Sundar R IYERc789ca22010-07-13 21:48:56 +053060};
61
62/* voltage tables for the vauxn/vintcore supplies */
63static const int ldo_vauxn_voltages[] = {
64 1100000,
65 1200000,
66 1300000,
67 1400000,
68 1500000,
69 1800000,
70 1850000,
71 1900000,
72 2500000,
73 2650000,
74 2700000,
75 2750000,
76 2800000,
77 2900000,
78 3000000,
79 3300000,
80};
81
Bengt Jonsson2b751512010-12-10 11:08:43 +010082static const int ldo_vaux3_voltages[] = {
83 1200000,
84 1500000,
85 1800000,
86 2100000,
87 2500000,
88 2750000,
89 2790000,
90 2910000,
91};
92
Sundar R IYERc789ca22010-07-13 21:48:56 +053093static const int ldo_vintcore_voltages[] = {
94 1200000,
95 1225000,
96 1250000,
97 1275000,
98 1300000,
99 1325000,
100 1350000,
101};
102
103static int ab8500_regulator_enable(struct regulator_dev *rdev)
104{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100105 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530106 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
107
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100108 if (info == NULL) {
109 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530110 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100111 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530112
Mattias Wallin47c16972010-09-10 17:47:56 +0200113 ret = abx500_mask_and_set_register_interruptible(info->dev,
Bengt Jonssone1159e62010-12-10 11:08:44 +0100114 info->update_bank, info->update_reg,
115 info->update_mask, info->update_val_enable);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530116 if (ret < 0)
117 dev_err(rdev_get_dev(rdev),
118 "couldn't set enable bits for regulator\n");
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100119
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
Sundar R IYERc789ca22010-07-13 21:48:56 +0530125 return ret;
126}
127
128static int ab8500_regulator_disable(struct regulator_dev *rdev)
129{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100130 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530131 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
132
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100133 if (info == NULL) {
134 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530135 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100136 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530137
Mattias Wallin47c16972010-09-10 17:47:56 +0200138 ret = abx500_mask_and_set_register_interruptible(info->dev,
Bengt Jonssone1159e62010-12-10 11:08:44 +0100139 info->update_bank, info->update_reg,
140 info->update_mask, 0x0);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530141 if (ret < 0)
142 dev_err(rdev_get_dev(rdev),
143 "couldn't set disable bits for regulator\n");
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100144
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
Sundar R IYERc789ca22010-07-13 21:48:56 +0530150 return ret;
151}
152
153static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
154{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100155 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530156 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100157 u8 regval;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530158
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100159 if (info == NULL) {
160 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530161 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100162 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530163
Mattias Wallin47c16972010-09-10 17:47:56 +0200164 ret = abx500_get_register_interruptible(info->dev,
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100165 info->update_bank, info->update_reg, &regval);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530166 if (ret < 0) {
167 dev_err(rdev_get_dev(rdev),
168 "couldn't read 0x%x register\n", info->update_reg);
169 return ret;
170 }
171
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100172 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)
Sundar R IYERc789ca22010-07-13 21:48:56 +0530179 return true;
180 else
181 return false;
182}
183
184static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
185{
Sundar R IYERc789ca22010-07-13 21:48:56 +0530186 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
187
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100188 if (info == NULL) {
189 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530190 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100191 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530192
193 /* return the uV for the fixed regulators */
194 if (info->fixed_uV)
195 return info->fixed_uV;
196
Axel Lin49990e62010-09-04 23:06:41 +0800197 if (selector >= info->voltages_len)
Sundar R IYERc789ca22010-07-13 21:48:56 +0530198 return -EINVAL;
199
Bengt Jonssone1159e62010-12-10 11:08:44 +0100200 return info->voltages[selector];
Sundar R IYERc789ca22010-07-13 21:48:56 +0530201}
202
203static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
204{
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100205 int ret, val;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530206 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100207 u8 regval;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530208
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100209 if (info == NULL) {
210 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530211 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100212 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530213
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100214 ret = abx500_get_register_interruptible(info->dev,
215 info->voltage_bank, info->voltage_reg, &regval);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530216 if (ret < 0) {
217 dev_err(rdev_get_dev(rdev),
218 "couldn't read voltage reg for regulator\n");
219 return ret;
220 }
221
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100222 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
Sundar R IYERc789ca22010-07-13 21:48:56 +0530228 /* vintcore has a different layout */
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100229 val = regval & info->voltage_mask;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100230 if (info->desc.id == AB8500_LDO_INTCORE)
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100231 ret = info->voltages[val >> 0x3];
Sundar R IYERc789ca22010-07-13 21:48:56 +0530232 else
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100233 ret = info->voltages[val];
Sundar R IYERc789ca22010-07-13 21:48:56 +0530234
235 return ret;
236}
237
238static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
239 int min_uV, int max_uV)
240{
241 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
242 int i;
243
244 /* check the supported voltage */
245 for (i = 0; i < info->voltages_len; i++) {
Bengt Jonssone1159e62010-12-10 11:08:44 +0100246 if ((info->voltages[i] >= min_uV) &&
247 (info->voltages[i] <= max_uV))
Sundar R IYERc789ca22010-07-13 21:48:56 +0530248 return i;
249 }
250
251 return -EINVAL;
252}
253
254static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000255 int min_uV, int max_uV,
256 unsigned *selector)
Sundar R IYERc789ca22010-07-13 21:48:56 +0530257{
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100258 int ret;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530259 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100260 u8 regval;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530261
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100262 if (info == NULL) {
263 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530264 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100265 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530266
267 /* get the appropriate voltages within the range */
268 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
269 if (ret < 0) {
270 dev_err(rdev_get_dev(rdev),
271 "couldn't get best voltage for regulator\n");
272 return ret;
273 }
274
Mark Brown3a93f2a2010-11-10 14:38:29 +0000275 *selector = ret;
276
Sundar R IYERc789ca22010-07-13 21:48:56 +0530277 /* set the registers for the request */
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100278 regval = (u8)ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200279 ret = abx500_mask_and_set_register_interruptible(info->dev,
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100280 info->voltage_bank, info->voltage_reg,
281 info->voltage_mask, regval);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530282 if (ret < 0)
283 dev_err(rdev_get_dev(rdev),
284 "couldn't set voltage reg for regulator\n");
285
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100286 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
Sundar R IYERc789ca22010-07-13 21:48:56 +0530292 return ret;
293}
294
Linus Walleij42ab6162011-03-17 13:25:02 +0100295static 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
Sundar R IYERc789ca22010-07-13 21:48:56 +0530318static struct regulator_ops ab8500_regulator_ops = {
319 .enable = ab8500_regulator_enable,
320 .disable = ab8500_regulator_disable,
321 .is_enabled = ab8500_regulator_is_enabled,
322 .get_voltage = ab8500_regulator_get_voltage,
323 .set_voltage = ab8500_regulator_set_voltage,
324 .list_voltage = ab8500_list_voltage,
Linus Walleij42ab6162011-03-17 13:25:02 +0100325 .enable_time = ab8500_regulator_enable_time,
326 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
Sundar R IYERc789ca22010-07-13 21:48:56 +0530327};
328
329static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
330{
Sundar R IYERc789ca22010-07-13 21:48:56 +0530331 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
332
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100333 if (info == NULL) {
334 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
Sundar R IYERc789ca22010-07-13 21:48:56 +0530335 return -EINVAL;
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100336 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530337
338 return info->fixed_uV;
339}
340
Bengt Jonsson6909b452010-12-10 11:08:47 +0100341static struct regulator_ops ab8500_regulator_fixed_ops = {
Sundar R IYERc789ca22010-07-13 21:48:56 +0530342 .enable = ab8500_regulator_enable,
343 .disable = ab8500_regulator_disable,
344 .is_enabled = ab8500_regulator_is_enabled,
345 .get_voltage = ab8500_fixed_get_voltage,
346 .list_voltage = ab8500_list_voltage,
Linus Walleij42ab6162011-03-17 13:25:02 +0100347 .enable_time = ab8500_regulator_enable_time,
348 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
Sundar R IYERc789ca22010-07-13 21:48:56 +0530349};
350
Bengt Jonsson6909b452010-12-10 11:08:47 +0100351static struct ab8500_regulator_info
352 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
Sundar R IYERc789ca22010-07-13 21:48:56 +0530353 /*
Bengt Jonssone1159e62010-12-10 11:08:44 +0100354 * Variable Voltage Regulators
355 * name, min mV, max mV,
356 * update bank, reg, mask, enable val
357 * volt bank, reg, mask, table, table length
Sundar R IYERc789ca22010-07-13 21:48:56 +0530358 */
Bengt Jonsson6909b452010-12-10 11:08:47 +0100359 [AB8500_LDO_AUX1] = {
360 .desc = {
361 .name = "LDO-AUX1",
362 .ops = &ab8500_regulator_ops,
363 .type = REGULATOR_VOLTAGE,
364 .id = AB8500_LDO_AUX1,
365 .owner = THIS_MODULE,
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 },
Sundar R IYERc789ca22010-07-13 21:48:56 +0530443
444 /*
Bengt Jonssone1159e62010-12-10 11:08:44 +0100445 * Fixed Voltage Regulators
446 * name, fixed mV,
447 * update bank, reg, mask, enable val
Sundar R IYERc789ca22010-07-13 21:48:56 +0530448 */
Bengt Jonsson6909b452010-12-10 11:08:47 +0100449 [AB8500_LDO_TVOUT] = {
450 .desc = {
451 .name = "LDO-TVOUT",
452 .ops = &ab8500_regulator_fixed_ops,
453 .type = REGULATOR_VOLTAGE,
454 .id = AB8500_LDO_TVOUT,
455 .owner = THIS_MODULE,
456 .n_voltages = 1,
457 },
Linus Walleij42ab6162011-03-17 13:25:02 +0100458 .delay = 10000,
Bengt Jonsson6909b452010-12-10 11:08:47 +0100459 .fixed_uV = 2000000,
460 .update_bank = 0x03,
461 .update_reg = 0x80,
462 .update_mask = 0x82,
463 .update_val_enable = 0x02,
464 },
Bengt Jonssonea05ef32011-03-10 14:43:31 +0100465 [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 },
Bengt Jonsson6909b452010-12-10 11:08:47 +0100480 [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
Sundar R IYERc789ca22010-07-13 21:48:56 +0530557};
558
Bengt Jonsson79568b942011-03-11 11:54:46 +0100559struct ab8500_reg_init {
560 u8 bank;
561 u8 addr;
562 u8 mask;
563};
564
565#define REG_INIT(_id, _bank, _addr, _mask) \
566 [_id] = { \
567 .bank = _bank, \
568 .addr = _addr, \
569 .mask = _mask, \
570 }
571
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};
738
Sundar R IYERc789ca22010-07-13 21:48:56 +0530739static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
740{
741 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
Dan Carpenteraf54dec2010-08-14 11:03:16 +0200742 struct ab8500_platform_data *pdata;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530743 int i, err;
744
745 if (!ab8500) {
746 dev_err(&pdev->dev, "null mfd parent\n");
747 return -EINVAL;
748 }
Dan Carpenteraf54dec2010-08-14 11:03:16 +0200749 pdata = dev_get_platdata(ab8500->dev);
Bengt Jonssonfc24b422010-12-10 11:08:45 +0100750 if (!pdata) {
751 dev_err(&pdev->dev, "null pdata\n");
752 return -EINVAL;
753 }
Sundar R IYERc789ca22010-07-13 21:48:56 +0530754
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100755 /* make sure the platform data has the correct size */
756 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
Bengt Jonsson79568b942011-03-11 11:54:46 +0100757 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100758 return -EINVAL;
759 }
760
Bengt Jonsson79568b942011-03-11 11:54:46 +0100761 /* 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 }
801
Sundar R IYERc789ca22010-07-13 21:48:56 +0530802 /* register all regulators */
803 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
804 struct ab8500_regulator_info *info = NULL;
805
806 /* assign per-regulator data */
807 info = &ab8500_regulator_info[i];
808 info->dev = &pdev->dev;
Sundar R IYERc789ca22010-07-13 21:48:56 +0530809
Bengt Jonsson2b751512010-12-10 11:08:43 +0100810 /* 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);
Bengt Jonssone1159e62010-12-10 11:08:44 +0100815 info->voltages = ldo_vauxn_voltages;
Bengt Jonsson2b751512010-12-10 11:08:43 +0100816 info->voltages_len =
817 ARRAY_SIZE(ldo_vauxn_voltages);
818 info->voltage_mask = 0xf;
819 }
820 }
821
822 /* register regulator with framework */
Sundar R IYERc789ca22010-07-13 21:48:56 +0530823 info->regulator = regulator_register(&info->desc, &pdev->dev,
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100824 &pdata->regulator[i], info);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530825 if (IS_ERR(info->regulator)) {
826 err = PTR_ERR(info->regulator);
827 dev_err(&pdev->dev, "failed to register regulator %s\n",
828 info->desc.name);
829 /* when we fail, un-register all earlier regulators */
Axel Lind4876a32010-08-14 21:44:04 +0800830 while (--i >= 0) {
Sundar R IYERc789ca22010-07-13 21:48:56 +0530831 info = &ab8500_regulator_info[i];
832 regulator_unregister(info->regulator);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530833 }
834 return err;
835 }
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100836
837 dev_vdbg(rdev_get_dev(info->regulator),
838 "%s-probed\n", info->desc.name);
Sundar R IYERc789ca22010-07-13 21:48:56 +0530839 }
840
841 return 0;
842}
843
844static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
845{
846 int i;
847
848 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
849 struct ab8500_regulator_info *info = NULL;
850 info = &ab8500_regulator_info[i];
Bengt Jonsson09aefa12010-12-10 11:08:46 +0100851
852 dev_vdbg(rdev_get_dev(info->regulator),
853 "%s-remove\n", info->desc.name);
854
Sundar R IYERc789ca22010-07-13 21:48:56 +0530855 regulator_unregister(info->regulator);
856 }
857
858 return 0;
859}
860
861static struct platform_driver ab8500_regulator_driver = {
862 .probe = ab8500_regulator_probe,
863 .remove = __devexit_p(ab8500_regulator_remove),
864 .driver = {
865 .name = "ab8500-regulator",
866 .owner = THIS_MODULE,
867 },
868};
869
870static int __init ab8500_regulator_init(void)
871{
872 int ret;
873
874 ret = platform_driver_register(&ab8500_regulator_driver);
875 if (ret != 0)
876 pr_err("Failed to register ab8500 regulator: %d\n", ret);
877
878 return ret;
879}
880subsys_initcall(ab8500_regulator_init);
881
882static void __exit ab8500_regulator_exit(void)
883{
884 platform_driver_unregister(&ab8500_regulator_driver);
885}
886module_exit(ab8500_regulator_exit);
887
888MODULE_LICENSE("GPL v2");
889MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
890MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
891MODULE_ALIAS("platform:ab8500-regulator");