Blame view

drivers/regulator/ab8500.c 21.4 KB
c789ca202   Sundar R IYER   regulator: add su...
1
2
3
4
5
  /*
   * Copyright (C) ST-Ericsson SA 2010
   *
   * License Terms: GNU General Public License v2
   *
e1159e6d9   Bengt Jonsson   regulators: Updat...
6
7
   * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
   *          Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
c789ca202   Sundar R IYER   regulator: add su...
8
9
10
   *
   * AB8500 peripheral regulators
   *
e1159e6d9   Bengt Jonsson   regulators: Updat...
11
   * AB8500 supports the following regulators:
ea05ef31f   Bengt Jonsson   regulator: add su...
12
   *   VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
c789ca202   Sundar R IYER   regulator: add su...
13
14
15
   */
  #include <linux/init.h>
  #include <linux/kernel.h>
65602c32e   Paul Gortmaker   regulator: Add mo...
16
  #include <linux/module.h>
c789ca202   Sundar R IYER   regulator: add su...
17
18
  #include <linux/err.h>
  #include <linux/platform_device.h>
47c169750   Mattias Wallin   mfd: Align ab8500...
19
  #include <linux/mfd/abx500.h>
ee66e653c   Linus Walleij   mfd: Unify abx500...
20
  #include <linux/mfd/abx500/ab8500.h>
c789ca202   Sundar R IYER   regulator: add su...
21
22
23
24
25
26
  #include <linux/regulator/driver.h>
  #include <linux/regulator/machine.h>
  #include <linux/regulator/ab8500.h>
  
  /**
   * struct ab8500_regulator_info - ab8500 regulator information
e1159e6d9   Bengt Jonsson   regulators: Updat...
27
   * @dev: device pointer
c789ca202   Sundar R IYER   regulator: add su...
28
   * @desc: regulator description
c789ca202   Sundar R IYER   regulator: add su...
29
30
31
32
   * @regulator_dev: regulator device
   * @max_uV: maximum voltage (for variable voltage supplies)
   * @min_uV: minimum voltage (for variable voltage supplies)
   * @fixed_uV: typical voltage (for fixed voltage supplies)
47c169750   Mattias Wallin   mfd: Align ab8500...
33
   * @update_bank: bank to control on/off
c789ca202   Sundar R IYER   regulator: add su...
34
   * @update_reg: register to control on/off
e1159e6d9   Bengt Jonsson   regulators: Updat...
35
36
   * @update_mask: mask to enable/disable regulator
   * @update_val_enable: bits to enable the regulator in normal (high power) mode
47c169750   Mattias Wallin   mfd: Align ab8500...
37
   * @voltage_bank: bank to control regulator voltage
c789ca202   Sundar R IYER   regulator: add su...
38
39
   * @voltage_reg: register to control regulator voltage
   * @voltage_mask: mask to control regulator voltage
e1159e6d9   Bengt Jonsson   regulators: Updat...
40
   * @voltages: supported voltage table
c789ca202   Sundar R IYER   regulator: add su...
41
   * @voltages_len: number of supported voltages for the regulator
42ab616af   Linus Walleij   regulator: add ab...
42
   * @delay: startup/set voltage delay in us
c789ca202   Sundar R IYER   regulator: add su...
43
44
45
46
   */
  struct ab8500_regulator_info {
  	struct device		*dev;
  	struct regulator_desc	desc;
c789ca202   Sundar R IYER   regulator: add su...
47
48
49
50
  	struct regulator_dev	*regulator;
  	int max_uV;
  	int min_uV;
  	int fixed_uV;
47c169750   Mattias Wallin   mfd: Align ab8500...
51
52
  	u8 update_bank;
  	u8 update_reg;
e1159e6d9   Bengt Jonsson   regulators: Updat...
53
54
  	u8 update_mask;
  	u8 update_val_enable;
47c169750   Mattias Wallin   mfd: Align ab8500...
55
56
57
  	u8 voltage_bank;
  	u8 voltage_reg;
  	u8 voltage_mask;
e1159e6d9   Bengt Jonsson   regulators: Updat...
58
  	int const *voltages;
c789ca202   Sundar R IYER   regulator: add su...
59
  	int voltages_len;
42ab616af   Linus Walleij   regulator: add ab...
60
  	unsigned int delay;
c789ca202   Sundar R IYER   regulator: add su...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  };
  
  /* voltage tables for the vauxn/vintcore supplies */
  static const int ldo_vauxn_voltages[] = {
  	1100000,
  	1200000,
  	1300000,
  	1400000,
  	1500000,
  	1800000,
  	1850000,
  	1900000,
  	2500000,
  	2650000,
  	2700000,
  	2750000,
  	2800000,
  	2900000,
  	3000000,
  	3300000,
  };
2b75151a1   Bengt Jonsson   regulators: Added...
82
83
84
85
86
87
88
89
90
91
  static const int ldo_vaux3_voltages[] = {
  	1200000,
  	1500000,
  	1800000,
  	2100000,
  	2500000,
  	2750000,
  	2790000,
  	2910000,
  };
c789ca202   Sundar R IYER   regulator: add su...
92
93
94
95
96
97
98
99
100
101
102
103
  static const int ldo_vintcore_voltages[] = {
  	1200000,
  	1225000,
  	1250000,
  	1275000,
  	1300000,
  	1325000,
  	1350000,
  };
  
  static int ab8500_regulator_enable(struct regulator_dev *rdev)
  {
fc24b426f   Bengt Jonsson   regulators: Modif...
104
  	int ret;
c789ca202   Sundar R IYER   regulator: add su...
105
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
fc24b426f   Bengt Jonsson   regulators: Modif...
106
107
108
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
109
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
110
  	}
c789ca202   Sundar R IYER   regulator: add su...
111

47c169750   Mattias Wallin   mfd: Align ab8500...
112
  	ret = abx500_mask_and_set_register_interruptible(info->dev,
e1159e6d9   Bengt Jonsson   regulators: Updat...
113
114
  		info->update_bank, info->update_reg,
  		info->update_mask, info->update_val_enable);
c789ca202   Sundar R IYER   regulator: add su...
115
116
117
118
  	if (ret < 0)
  		dev_err(rdev_get_dev(rdev),
  			"couldn't set enable bits for regulator
  ");
09aefa12a   Bengt Jonsson   regulators: Added...
119
120
121
122
123
124
  
  	dev_vdbg(rdev_get_dev(rdev),
  		"%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x
  ",
  		info->desc.name, info->update_bank, info->update_reg,
  		info->update_mask, info->update_val_enable);
c789ca202   Sundar R IYER   regulator: add su...
125
126
127
128
129
  	return ret;
  }
  
  static int ab8500_regulator_disable(struct regulator_dev *rdev)
  {
fc24b426f   Bengt Jonsson   regulators: Modif...
130
  	int ret;
c789ca202   Sundar R IYER   regulator: add su...
131
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
fc24b426f   Bengt Jonsson   regulators: Modif...
132
133
134
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
135
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
136
  	}
c789ca202   Sundar R IYER   regulator: add su...
137

47c169750   Mattias Wallin   mfd: Align ab8500...
138
  	ret = abx500_mask_and_set_register_interruptible(info->dev,
e1159e6d9   Bengt Jonsson   regulators: Updat...
139
140
  		info->update_bank, info->update_reg,
  		info->update_mask, 0x0);
c789ca202   Sundar R IYER   regulator: add su...
141
142
143
144
  	if (ret < 0)
  		dev_err(rdev_get_dev(rdev),
  			"couldn't set disable bits for regulator
  ");
09aefa12a   Bengt Jonsson   regulators: Added...
145
146
147
148
149
150
  
  	dev_vdbg(rdev_get_dev(rdev),
  		"%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x
  ",
  		info->desc.name, info->update_bank, info->update_reg,
  		info->update_mask, 0x0);
c789ca202   Sundar R IYER   regulator: add su...
151
152
153
154
155
  	return ret;
  }
  
  static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
  {
fc24b426f   Bengt Jonsson   regulators: Modif...
156
  	int ret;
c789ca202   Sundar R IYER   regulator: add su...
157
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
09aefa12a   Bengt Jonsson   regulators: Added...
158
  	u8 regval;
c789ca202   Sundar R IYER   regulator: add su...
159

fc24b426f   Bengt Jonsson   regulators: Modif...
160
161
162
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
163
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
164
  	}
c789ca202   Sundar R IYER   regulator: add su...
165

47c169750   Mattias Wallin   mfd: Align ab8500...
166
  	ret = abx500_get_register_interruptible(info->dev,
09aefa12a   Bengt Jonsson   regulators: Added...
167
  		info->update_bank, info->update_reg, &regval);
c789ca202   Sundar R IYER   regulator: add su...
168
169
170
171
172
173
  	if (ret < 0) {
  		dev_err(rdev_get_dev(rdev),
  			"couldn't read 0x%x register
  ", info->update_reg);
  		return ret;
  	}
09aefa12a   Bengt Jonsson   regulators: Added...
174
175
176
177
178
179
180
181
  	dev_vdbg(rdev_get_dev(rdev),
  		"%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  		" 0x%x
  ",
  		info->desc.name, info->update_bank, info->update_reg,
  		info->update_mask, regval);
  
  	if (regval & info->update_mask)
c789ca202   Sundar R IYER   regulator: add su...
182
183
184
185
186
187
188
  		return true;
  	else
  		return false;
  }
  
  static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
  {
c789ca202   Sundar R IYER   regulator: add su...
189
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
fc24b426f   Bengt Jonsson   regulators: Modif...
190
191
192
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
193
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
194
  	}
c789ca202   Sundar R IYER   regulator: add su...
195
196
197
198
  
  	/* return the uV for the fixed regulators */
  	if (info->fixed_uV)
  		return info->fixed_uV;
49990e6ef   Axel Lin   regulator: ab8500...
199
  	if (selector >= info->voltages_len)
c789ca202   Sundar R IYER   regulator: add su...
200
  		return -EINVAL;
e1159e6d9   Bengt Jonsson   regulators: Updat...
201
  	return info->voltages[selector];
c789ca202   Sundar R IYER   regulator: add su...
202
203
204
205
  }
  
  static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
  {
09aefa12a   Bengt Jonsson   regulators: Added...
206
  	int ret, val;
c789ca202   Sundar R IYER   regulator: add su...
207
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
09aefa12a   Bengt Jonsson   regulators: Added...
208
  	u8 regval;
c789ca202   Sundar R IYER   regulator: add su...
209

fc24b426f   Bengt Jonsson   regulators: Modif...
210
211
212
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
213
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
214
  	}
c789ca202   Sundar R IYER   regulator: add su...
215

09aefa12a   Bengt Jonsson   regulators: Added...
216
217
  	ret = abx500_get_register_interruptible(info->dev,
  			info->voltage_bank, info->voltage_reg, &regval);
c789ca202   Sundar R IYER   regulator: add su...
218
219
220
221
222
223
  	if (ret < 0) {
  		dev_err(rdev_get_dev(rdev),
  			"couldn't read voltage reg for regulator
  ");
  		return ret;
  	}
09aefa12a   Bengt Jonsson   regulators: Added...
224
225
226
227
228
229
  	dev_vdbg(rdev_get_dev(rdev),
  		"%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  		" 0x%x
  ",
  		info->desc.name, info->voltage_bank, info->voltage_reg,
  		info->voltage_mask, regval);
c789ca202   Sundar R IYER   regulator: add su...
230
  	/* vintcore has a different layout */
09aefa12a   Bengt Jonsson   regulators: Added...
231
  	val = regval & info->voltage_mask;
fc24b426f   Bengt Jonsson   regulators: Modif...
232
  	if (info->desc.id == AB8500_LDO_INTCORE)
09aefa12a   Bengt Jonsson   regulators: Added...
233
  		ret = info->voltages[val >> 0x3];
c789ca202   Sundar R IYER   regulator: add su...
234
  	else
09aefa12a   Bengt Jonsson   regulators: Added...
235
  		ret = info->voltages[val];
c789ca202   Sundar R IYER   regulator: add su...
236
237
238
239
240
241
242
243
244
245
246
247
  
  	return ret;
  }
  
  static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
  		int min_uV, int max_uV)
  {
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  	int i;
  
  	/* check the supported voltage */
  	for (i = 0; i < info->voltages_len; i++) {
e1159e6d9   Bengt Jonsson   regulators: Updat...
248
249
  		if ((info->voltages[i] >= min_uV) &&
  		    (info->voltages[i] <= max_uV))
c789ca202   Sundar R IYER   regulator: add su...
250
251
252
253
254
255
256
  			return i;
  	}
  
  	return -EINVAL;
  }
  
  static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
3a93f2a9f   Mark Brown   regulator: Report...
257
258
  					int min_uV, int max_uV,
  					unsigned *selector)
c789ca202   Sundar R IYER   regulator: add su...
259
  {
fc24b426f   Bengt Jonsson   regulators: Modif...
260
  	int ret;
c789ca202   Sundar R IYER   regulator: add su...
261
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
09aefa12a   Bengt Jonsson   regulators: Added...
262
  	u8 regval;
c789ca202   Sundar R IYER   regulator: add su...
263

fc24b426f   Bengt Jonsson   regulators: Modif...
264
265
266
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
267
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
268
  	}
c789ca202   Sundar R IYER   regulator: add su...
269
270
271
272
273
274
275
276
277
  
  	/* get the appropriate voltages within the range */
  	ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
  	if (ret < 0) {
  		dev_err(rdev_get_dev(rdev),
  				"couldn't get best voltage for regulator
  ");
  		return ret;
  	}
3a93f2a9f   Mark Brown   regulator: Report...
278
  	*selector = ret;
c789ca202   Sundar R IYER   regulator: add su...
279
  	/* set the registers for the request */
09aefa12a   Bengt Jonsson   regulators: Added...
280
  	regval = (u8)ret;
47c169750   Mattias Wallin   mfd: Align ab8500...
281
  	ret = abx500_mask_and_set_register_interruptible(info->dev,
09aefa12a   Bengt Jonsson   regulators: Added...
282
283
  			info->voltage_bank, info->voltage_reg,
  			info->voltage_mask, regval);
c789ca202   Sundar R IYER   regulator: add su...
284
285
286
287
  	if (ret < 0)
  		dev_err(rdev_get_dev(rdev),
  		"couldn't set voltage reg for regulator
  ");
09aefa12a   Bengt Jonsson   regulators: Added...
288
289
290
291
292
293
  	dev_vdbg(rdev_get_dev(rdev),
  		"%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  		" 0x%x
  ",
  		info->desc.name, info->voltage_bank, info->voltage_reg,
  		info->voltage_mask, regval);
c789ca202   Sundar R IYER   regulator: add su...
294
295
  	return ret;
  }
42ab616af   Linus Walleij   regulator: add ab...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
  static int ab8500_regulator_enable_time(struct regulator_dev *rdev)
  {
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  
  	return info->delay;
  }
  
  static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
  					     unsigned int old_sel,
  					     unsigned int new_sel)
  {
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  	int ret;
  
  	/* If the regulator isn't on, it won't take time here */
  	ret = ab8500_regulator_is_enabled(rdev);
  	if (ret < 0)
  		return ret;
  	if (!ret)
  		return 0;
  	return info->delay;
  }
c789ca202   Sundar R IYER   regulator: add su...
318
319
320
321
322
323
324
  static struct regulator_ops ab8500_regulator_ops = {
  	.enable		= ab8500_regulator_enable,
  	.disable	= ab8500_regulator_disable,
  	.is_enabled	= ab8500_regulator_is_enabled,
  	.get_voltage	= ab8500_regulator_get_voltage,
  	.set_voltage	= ab8500_regulator_set_voltage,
  	.list_voltage	= ab8500_list_voltage,
42ab616af   Linus Walleij   regulator: add ab...
325
326
  	.enable_time	= ab8500_regulator_enable_time,
  	.set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
c789ca202   Sundar R IYER   regulator: add su...
327
328
329
330
  };
  
  static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
  {
c789ca202   Sundar R IYER   regulator: add su...
331
  	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
fc24b426f   Bengt Jonsson   regulators: Modif...
332
333
334
  	if (info == NULL) {
  		dev_err(rdev_get_dev(rdev), "regulator info null pointer
  ");
c789ca202   Sundar R IYER   regulator: add su...
335
  		return -EINVAL;
fc24b426f   Bengt Jonsson   regulators: Modif...
336
  	}
c789ca202   Sundar R IYER   regulator: add su...
337
338
339
  
  	return info->fixed_uV;
  }
6909b4522   Bengt Jonsson   regulators: Remov...
340
  static struct regulator_ops ab8500_regulator_fixed_ops = {
c789ca202   Sundar R IYER   regulator: add su...
341
342
343
344
345
  	.enable		= ab8500_regulator_enable,
  	.disable	= ab8500_regulator_disable,
  	.is_enabled	= ab8500_regulator_is_enabled,
  	.get_voltage	= ab8500_fixed_get_voltage,
  	.list_voltage	= ab8500_list_voltage,
42ab616af   Linus Walleij   regulator: add ab...
346
347
  	.enable_time	= ab8500_regulator_enable_time,
  	.set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
c789ca202   Sundar R IYER   regulator: add su...
348
  };
6909b4522   Bengt Jonsson   regulators: Remov...
349
350
  static struct ab8500_regulator_info
  		ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
c789ca202   Sundar R IYER   regulator: add su...
351
  	/*
e1159e6d9   Bengt Jonsson   regulators: Updat...
352
353
354
355
  	 * Variable Voltage Regulators
  	 *   name, min mV, max mV,
  	 *   update bank, reg, mask, enable val
  	 *   volt bank, reg, mask, table, table length
c789ca202   Sundar R IYER   regulator: add su...
356
  	 */
6909b4522   Bengt Jonsson   regulators: Remov...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  	[AB8500_LDO_AUX1] = {
  		.desc = {
  			.name		= "LDO-AUX1",
  			.ops		= &ab8500_regulator_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_AUX1,
  			.owner		= THIS_MODULE,
  			.n_voltages	= ARRAY_SIZE(ldo_vauxn_voltages),
  		},
  		.min_uV			= 1100000,
  		.max_uV			= 3300000,
  		.update_bank		= 0x04,
  		.update_reg		= 0x09,
  		.update_mask		= 0x03,
  		.update_val_enable	= 0x01,
  		.voltage_bank		= 0x04,
  		.voltage_reg		= 0x1f,
  		.voltage_mask		= 0x0f,
  		.voltages		= ldo_vauxn_voltages,
  		.voltages_len		= ARRAY_SIZE(ldo_vauxn_voltages),
  	},
  	[AB8500_LDO_AUX2] = {
  		.desc = {
  			.name		= "LDO-AUX2",
  			.ops		= &ab8500_regulator_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_AUX2,
  			.owner		= THIS_MODULE,
  			.n_voltages	= ARRAY_SIZE(ldo_vauxn_voltages),
  		},
  		.min_uV			= 1100000,
  		.max_uV			= 3300000,
  		.update_bank		= 0x04,
  		.update_reg		= 0x09,
  		.update_mask		= 0x0c,
  		.update_val_enable	= 0x04,
  		.voltage_bank		= 0x04,
  		.voltage_reg		= 0x20,
  		.voltage_mask		= 0x0f,
  		.voltages		= ldo_vauxn_voltages,
  		.voltages_len		= ARRAY_SIZE(ldo_vauxn_voltages),
  	},
  	[AB8500_LDO_AUX3] = {
  		.desc = {
  			.name		= "LDO-AUX3",
  			.ops		= &ab8500_regulator_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_AUX3,
  			.owner		= THIS_MODULE,
  			.n_voltages	= ARRAY_SIZE(ldo_vaux3_voltages),
  		},
  		.min_uV			= 1100000,
  		.max_uV			= 3300000,
  		.update_bank		= 0x04,
  		.update_reg		= 0x0a,
  		.update_mask		= 0x03,
  		.update_val_enable	= 0x01,
  		.voltage_bank		= 0x04,
  		.voltage_reg		= 0x21,
  		.voltage_mask		= 0x07,
  		.voltages		= ldo_vaux3_voltages,
  		.voltages_len		= ARRAY_SIZE(ldo_vaux3_voltages),
  	},
  	[AB8500_LDO_INTCORE] = {
  		.desc = {
  			.name		= "LDO-INTCORE",
  			.ops		= &ab8500_regulator_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_INTCORE,
  			.owner		= THIS_MODULE,
  			.n_voltages	= ARRAY_SIZE(ldo_vintcore_voltages),
  		},
  		.min_uV			= 1100000,
  		.max_uV			= 3300000,
  		.update_bank		= 0x03,
  		.update_reg		= 0x80,
  		.update_mask		= 0x44,
  		.update_val_enable	= 0x04,
  		.voltage_bank		= 0x03,
  		.voltage_reg		= 0x80,
  		.voltage_mask		= 0x38,
  		.voltages		= ldo_vintcore_voltages,
  		.voltages_len		= ARRAY_SIZE(ldo_vintcore_voltages),
  	},
c789ca202   Sundar R IYER   regulator: add su...
441
442
  
  	/*
e1159e6d9   Bengt Jonsson   regulators: Updat...
443
444
445
  	 * Fixed Voltage Regulators
  	 *   name, fixed mV,
  	 *   update bank, reg, mask, enable val
c789ca202   Sundar R IYER   regulator: add su...
446
  	 */
6909b4522   Bengt Jonsson   regulators: Remov...
447
448
449
450
451
452
453
454
455
  	[AB8500_LDO_TVOUT] = {
  		.desc = {
  			.name		= "LDO-TVOUT",
  			.ops		= &ab8500_regulator_fixed_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_TVOUT,
  			.owner		= THIS_MODULE,
  			.n_voltages	= 1,
  		},
42ab616af   Linus Walleij   regulator: add ab...
456
  		.delay			= 10000,
6909b4522   Bengt Jonsson   regulators: Remov...
457
458
459
460
461
462
  		.fixed_uV		= 2000000,
  		.update_bank		= 0x03,
  		.update_reg		= 0x80,
  		.update_mask		= 0x82,
  		.update_val_enable	= 0x02,
  	},
ea05ef31f   Bengt Jonsson   regulator: add su...
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
  	[AB8500_LDO_USB] = {
  		.desc = {
  			.name           = "LDO-USB",
  			.ops            = &ab8500_regulator_fixed_ops,
  			.type           = REGULATOR_VOLTAGE,
  			.id             = AB8500_LDO_USB,
  			.owner          = THIS_MODULE,
  			.n_voltages     = 1,
  		},
  		.fixed_uV               = 3300000,
  		.update_bank            = 0x03,
  		.update_reg             = 0x82,
  		.update_mask            = 0x03,
  		.update_val_enable      = 0x01,
  	},
6909b4522   Bengt Jonsson   regulators: Remov...
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
  	[AB8500_LDO_AUDIO] = {
  		.desc = {
  			.name		= "LDO-AUDIO",
  			.ops		= &ab8500_regulator_fixed_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_AUDIO,
  			.owner		= THIS_MODULE,
  			.n_voltages	= 1,
  		},
  		.fixed_uV		= 2000000,
  		.update_bank		= 0x03,
  		.update_reg		= 0x83,
  		.update_mask		= 0x02,
  		.update_val_enable	= 0x02,
  	},
  	[AB8500_LDO_ANAMIC1] = {
  		.desc = {
  			.name		= "LDO-ANAMIC1",
  			.ops		= &ab8500_regulator_fixed_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_ANAMIC1,
  			.owner		= THIS_MODULE,
  			.n_voltages	= 1,
  		},
  		.fixed_uV		= 2050000,
  		.update_bank		= 0x03,
  		.update_reg		= 0x83,
  		.update_mask		= 0x08,
  		.update_val_enable	= 0x08,
  	},
  	[AB8500_LDO_ANAMIC2] = {
  		.desc = {
  			.name		= "LDO-ANAMIC2",
  			.ops		= &ab8500_regulator_fixed_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_ANAMIC2,
  			.owner		= THIS_MODULE,
  			.n_voltages	= 1,
  		},
  		.fixed_uV		= 2050000,
  		.update_bank		= 0x03,
  		.update_reg		= 0x83,
  		.update_mask		= 0x10,
  		.update_val_enable	= 0x10,
  	},
  	[AB8500_LDO_DMIC] = {
  		.desc = {
  			.name		= "LDO-DMIC",
  			.ops		= &ab8500_regulator_fixed_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_DMIC,
  			.owner		= THIS_MODULE,
  			.n_voltages	= 1,
  		},
  		.fixed_uV		= 1800000,
  		.update_bank		= 0x03,
  		.update_reg		= 0x83,
  		.update_mask		= 0x04,
  		.update_val_enable	= 0x04,
  	},
  	[AB8500_LDO_ANA] = {
  		.desc = {
  			.name		= "LDO-ANA",
  			.ops		= &ab8500_regulator_fixed_ops,
  			.type		= REGULATOR_VOLTAGE,
  			.id		= AB8500_LDO_ANA,
  			.owner		= THIS_MODULE,
  			.n_voltages	= 1,
  		},
  		.fixed_uV		= 1200000,
  		.update_bank		= 0x04,
  		.update_reg		= 0x06,
  		.update_mask		= 0x0c,
  		.update_val_enable	= 0x04,
  	},
c789ca202   Sundar R IYER   regulator: add su...
553
  };
79568b941   Bengt Jonsson   regulator: initia...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
  struct ab8500_reg_init {
  	u8 bank;
  	u8 addr;
  	u8 mask;
  };
  
  #define REG_INIT(_id, _bank, _addr, _mask)	\
  	[_id] = {				\
  		.bank = _bank,			\
  		.addr = _addr,			\
  		.mask = _mask,			\
  	}
  
  static struct ab8500_reg_init ab8500_reg_init[] = {
  	/*
  	 * 0x30, VanaRequestCtrl
  	 * 0x0C, VpllRequestCtrl
  	 * 0xc0, VextSupply1RequestCtrl
  	 */
  	REG_INIT(AB8500_REGUREQUESTCTRL2,	0x03, 0x04, 0xfc),
  	/*
  	 * 0x03, VextSupply2RequestCtrl
  	 * 0x0c, VextSupply3RequestCtrl
  	 * 0x30, Vaux1RequestCtrl
  	 * 0xc0, Vaux2RequestCtrl
  	 */
  	REG_INIT(AB8500_REGUREQUESTCTRL3,	0x03, 0x05, 0xff),
  	/*
  	 * 0x03, Vaux3RequestCtrl
  	 * 0x04, SwHPReq
  	 */
  	REG_INIT(AB8500_REGUREQUESTCTRL4,	0x03, 0x06, 0x07),
  	/*
  	 * 0x08, VanaSysClkReq1HPValid
  	 * 0x20, Vaux1SysClkReq1HPValid
  	 * 0x40, Vaux2SysClkReq1HPValid
  	 * 0x80, Vaux3SysClkReq1HPValid
  	 */
  	REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1,	0x03, 0x07, 0xe8),
  	/*
  	 * 0x10, VextSupply1SysClkReq1HPValid
  	 * 0x20, VextSupply2SysClkReq1HPValid
  	 * 0x40, VextSupply3SysClkReq1HPValid
  	 */
  	REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2,	0x03, 0x08, 0x70),
  	/*
  	 * 0x08, VanaHwHPReq1Valid
  	 * 0x20, Vaux1HwHPReq1Valid
  	 * 0x40, Vaux2HwHPReq1Valid
  	 * 0x80, Vaux3HwHPReq1Valid
  	 */
  	REG_INIT(AB8500_REGUHWHPREQ1VALID1,	0x03, 0x09, 0xe8),
  	/*
  	 * 0x01, VextSupply1HwHPReq1Valid
  	 * 0x02, VextSupply2HwHPReq1Valid
  	 * 0x04, VextSupply3HwHPReq1Valid
  	 */
  	REG_INIT(AB8500_REGUHWHPREQ1VALID2,	0x03, 0x0a, 0x07),
  	/*
  	 * 0x08, VanaHwHPReq2Valid
  	 * 0x20, Vaux1HwHPReq2Valid
  	 * 0x40, Vaux2HwHPReq2Valid
  	 * 0x80, Vaux3HwHPReq2Valid
  	 */
  	REG_INIT(AB8500_REGUHWHPREQ2VALID1,	0x03, 0x0b, 0xe8),
  	/*
  	 * 0x01, VextSupply1HwHPReq2Valid
  	 * 0x02, VextSupply2HwHPReq2Valid
  	 * 0x04, VextSupply3HwHPReq2Valid
  	 */
  	REG_INIT(AB8500_REGUHWHPREQ2VALID2,	0x03, 0x0c, 0x07),
  	/*
  	 * 0x20, VanaSwHPReqValid
  	 * 0x80, Vaux1SwHPReqValid
  	 */
  	REG_INIT(AB8500_REGUSWHPREQVALID1,	0x03, 0x0d, 0xa0),
  	/*
  	 * 0x01, Vaux2SwHPReqValid
  	 * 0x02, Vaux3SwHPReqValid
  	 * 0x04, VextSupply1SwHPReqValid
  	 * 0x08, VextSupply2SwHPReqValid
  	 * 0x10, VextSupply3SwHPReqValid
  	 */
  	REG_INIT(AB8500_REGUSWHPREQVALID2,	0x03, 0x0e, 0x1f),
  	/*
  	 * 0x02, SysClkReq2Valid1
  	 * ...
  	 * 0x80, SysClkReq8Valid1
  	 */
  	REG_INIT(AB8500_REGUSYSCLKREQVALID1,	0x03, 0x0f, 0xfe),
  	/*
  	 * 0x02, SysClkReq2Valid2
  	 * ...
  	 * 0x80, SysClkReq8Valid2
  	 */
  	REG_INIT(AB8500_REGUSYSCLKREQVALID2,	0x03, 0x10, 0xfe),
  	/*
  	 * 0x02, VTVoutEna
  	 * 0x04, Vintcore12Ena
  	 * 0x38, Vintcore12Sel
  	 * 0x40, Vintcore12LP
  	 * 0x80, VTVoutLP
  	 */
  	REG_INIT(AB8500_REGUMISC1,		0x03, 0x80, 0xfe),
  	/*
  	 * 0x02, VaudioEna
  	 * 0x04, VdmicEna
  	 * 0x08, Vamic1Ena
  	 * 0x10, Vamic2Ena
  	 */
  	REG_INIT(AB8500_VAUDIOSUPPLY,		0x03, 0x83, 0x1e),
  	/*
  	 * 0x01, Vamic1_dzout
  	 * 0x02, Vamic2_dzout
  	 */
  	REG_INIT(AB8500_REGUCTRL1VAMIC,		0x03, 0x84, 0x03),
  	/*
  	 * 0x0c, VanaRegu
  	 * 0x03, VpllRegu
  	 */
  	REG_INIT(AB8500_VPLLVANAREGU,		0x04, 0x06, 0x0f),
  	/*
  	 * 0x01, VrefDDREna
  	 * 0x02, VrefDDRSleepMode
  	 */
  	REG_INIT(AB8500_VREFDDR,		0x04, 0x07, 0x03),
  	/*
  	 * 0x03, VextSupply1Regu
  	 * 0x0c, VextSupply2Regu
  	 * 0x30, VextSupply3Regu
  	 * 0x40, ExtSupply2Bypass
  	 * 0x80, ExtSupply3Bypass
  	 */
  	REG_INIT(AB8500_EXTSUPPLYREGU,		0x04, 0x08, 0xff),
  	/*
  	 * 0x03, Vaux1Regu
  	 * 0x0c, Vaux2Regu
  	 */
  	REG_INIT(AB8500_VAUX12REGU,		0x04, 0x09, 0x0f),
  	/*
  	 * 0x03, Vaux3Regu
  	 */
  	REG_INIT(AB8500_VRF1VAUX3REGU,		0x04, 0x0a, 0x03),
  	/*
  	 * 0x3f, Vsmps1Sel1
  	 */
  	REG_INIT(AB8500_VSMPS1SEL1,		0x04, 0x13, 0x3f),
  	/*
  	 * 0x0f, Vaux1Sel
  	 */
  	REG_INIT(AB8500_VAUX1SEL,		0x04, 0x1f, 0x0f),
  	/*
  	 * 0x0f, Vaux2Sel
  	 */
  	REG_INIT(AB8500_VAUX2SEL,		0x04, 0x20, 0x0f),
  	/*
  	 * 0x07, Vaux3Sel
  	 */
  	REG_INIT(AB8500_VRF1VAUX3SEL,		0x04, 0x21, 0x07),
  	/*
  	 * 0x01, VextSupply12LP
  	 */
  	REG_INIT(AB8500_REGUCTRL2SPARE,		0x04, 0x22, 0x01),
  	/*
  	 * 0x04, Vaux1Disch
  	 * 0x08, Vaux2Disch
  	 * 0x10, Vaux3Disch
  	 * 0x20, Vintcore12Disch
  	 * 0x40, VTVoutDisch
  	 * 0x80, VaudioDisch
  	 */
  	REG_INIT(AB8500_REGUCTRLDISCH,		0x04, 0x43, 0xfc),
  	/*
  	 * 0x02, VanaDisch
  	 * 0x04, VdmicPullDownEna
  	 * 0x10, VdmicDisch
  	 */
  	REG_INIT(AB8500_REGUCTRLDISCH2,		0x04, 0x44, 0x16),
  };
c789ca202   Sundar R IYER   regulator: add su...
733
734
735
  static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
  {
  	struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
af54decd6   Dan Carpenter   regulator/ab8500:...
736
  	struct ab8500_platform_data *pdata;
c789ca202   Sundar R IYER   regulator: add su...
737
738
739
740
741
742
743
  	int i, err;
  
  	if (!ab8500) {
  		dev_err(&pdev->dev, "null mfd parent
  ");
  		return -EINVAL;
  	}
af54decd6   Dan Carpenter   regulator/ab8500:...
744
  	pdata = dev_get_platdata(ab8500->dev);
fc24b426f   Bengt Jonsson   regulators: Modif...
745
746
747
748
749
  	if (!pdata) {
  		dev_err(&pdev->dev, "null pdata
  ");
  		return -EINVAL;
  	}
c789ca202   Sundar R IYER   regulator: add su...
750

cb189b07d   Bengt Jonsson   regulators: Moved...
751
752
  	/* make sure the platform data has the correct size */
  	if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
79568b941   Bengt Jonsson   regulator: initia...
753
754
  		dev_err(&pdev->dev, "Configuration error: size mismatch.
  ");
cb189b07d   Bengt Jonsson   regulators: Moved...
755
756
  		return -EINVAL;
  	}
79568b941   Bengt Jonsson   regulator: initia...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
  	/* initialize registers */
  	for (i = 0; i < pdata->num_regulator_reg_init; i++) {
  		int id;
  		u8 value;
  
  		id = pdata->regulator_reg_init[i].id;
  		value = pdata->regulator_reg_init[i].value;
  
  		/* check for configuration errors */
  		if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
  			dev_err(&pdev->dev,
  				"Configuration error: id outside range.
  ");
  			return -EINVAL;
  		}
  		if (value & ~ab8500_reg_init[id].mask) {
  			dev_err(&pdev->dev,
  				"Configuration error: value outside mask.
  ");
  			return -EINVAL;
  		}
  
  		/* initialize register */
  		err = abx500_mask_and_set_register_interruptible(&pdev->dev,
  			ab8500_reg_init[id].bank,
  			ab8500_reg_init[id].addr,
  			ab8500_reg_init[id].mask,
  			value);
  		if (err < 0) {
  			dev_err(&pdev->dev,
  				"Failed to initialize 0x%02x, 0x%02x.
  ",
  				ab8500_reg_init[id].bank,
  				ab8500_reg_init[id].addr);
  			return err;
  		}
  		dev_vdbg(&pdev->dev,
  			"  init: 0x%02x, 0x%02x, 0x%02x, 0x%02x
  ",
  			ab8500_reg_init[id].bank,
  			ab8500_reg_init[id].addr,
  			ab8500_reg_init[id].mask,
  			value);
  	}
c789ca202   Sundar R IYER   regulator: add su...
801
802
803
804
805
806
807
  	/* register all regulators */
  	for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  		struct ab8500_regulator_info *info = NULL;
  
  		/* assign per-regulator data */
  		info = &ab8500_regulator_info[i];
  		info->dev = &pdev->dev;
c789ca202   Sundar R IYER   regulator: add su...
808

2b75151a1   Bengt Jonsson   regulators: Added...
809
810
811
812
813
  		/* fix for hardware before ab8500v2.0 */
  		if (abx500_get_chip_id(info->dev) < 0x20) {
  			if (info->desc.id == AB8500_LDO_AUX3) {
  				info->desc.n_voltages =
  					ARRAY_SIZE(ldo_vauxn_voltages);
e1159e6d9   Bengt Jonsson   regulators: Updat...
814
  				info->voltages = ldo_vauxn_voltages;
2b75151a1   Bengt Jonsson   regulators: Added...
815
816
817
818
819
820
821
  				info->voltages_len =
  					ARRAY_SIZE(ldo_vauxn_voltages);
  				info->voltage_mask = 0xf;
  			}
  		}
  
  		/* register regulator with framework */
c789ca202   Sundar R IYER   regulator: add su...
822
  		info->regulator = regulator_register(&info->desc, &pdev->dev,
2c043bcbf   Rajendra Nayak   regulator: pass a...
823
  				&pdata->regulator[i], info, NULL);
c789ca202   Sundar R IYER   regulator: add su...
824
825
826
827
828
829
  		if (IS_ERR(info->regulator)) {
  			err = PTR_ERR(info->regulator);
  			dev_err(&pdev->dev, "failed to register regulator %s
  ",
  					info->desc.name);
  			/* when we fail, un-register all earlier regulators */
d4876a3bc   Axel Lin   regulator: ab8500...
830
  			while (--i >= 0) {
c789ca202   Sundar R IYER   regulator: add su...
831
832
  				info = &ab8500_regulator_info[i];
  				regulator_unregister(info->regulator);
c789ca202   Sundar R IYER   regulator: add su...
833
834
835
  			}
  			return err;
  		}
09aefa12a   Bengt Jonsson   regulators: Added...
836
837
838
839
  
  		dev_vdbg(rdev_get_dev(info->regulator),
  			"%s-probed
  ", info->desc.name);
c789ca202   Sundar R IYER   regulator: add su...
840
841
842
843
844
845
846
847
848
849
850
851
  	}
  
  	return 0;
  }
  
  static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
  {
  	int i;
  
  	for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  		struct ab8500_regulator_info *info = NULL;
  		info = &ab8500_regulator_info[i];
09aefa12a   Bengt Jonsson   regulators: Added...
852
853
854
855
  
  		dev_vdbg(rdev_get_dev(info->regulator),
  			"%s-remove
  ", info->desc.name);
c789ca202   Sundar R IYER   regulator: add su...
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
  		regulator_unregister(info->regulator);
  	}
  
  	return 0;
  }
  
  static struct platform_driver ab8500_regulator_driver = {
  	.probe = ab8500_regulator_probe,
  	.remove = __devexit_p(ab8500_regulator_remove),
  	.driver         = {
  		.name   = "ab8500-regulator",
  		.owner  = THIS_MODULE,
  	},
  };
  
  static int __init ab8500_regulator_init(void)
  {
  	int ret;
  
  	ret = platform_driver_register(&ab8500_regulator_driver);
  	if (ret != 0)
  		pr_err("Failed to register ab8500 regulator: %d
  ", ret);
  
  	return ret;
  }
  subsys_initcall(ab8500_regulator_init);
  
  static void __exit ab8500_regulator_exit(void)
  {
  	platform_driver_unregister(&ab8500_regulator_driver);
  }
  module_exit(ab8500_regulator_exit);
  
  MODULE_LICENSE("GPL v2");
  MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
  MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
  MODULE_ALIAS("platform:ab8500-regulator");