Blame view

drivers/regulator/ab3100.c 16.6 KB
d619bc143   Linus Walleij   regulator: AB3100...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  /*
   * drivers/regulator/ab3100.c
   *
   * Copyright (C) 2008-2009 ST-Ericsson AB
   * License terms: GNU General Public License (GPL) version 2
   * Low-level control of the AB3100 IC Low Dropout (LDO)
   * regulators, external regulator and buck converter
   * Author: Mattias Wallin <mattias.wallin@stericsson.com>
   * Author: Linus Walleij <linus.walleij@stericsson.com>
   */
  
  #include <linux/module.h>
  #include <linux/kernel.h>
  #include <linux/init.h>
  #include <linux/err.h>
  #include <linux/delay.h>
  #include <linux/platform_device.h>
  #include <linux/regulator/driver.h>
812f9e9d4   Linus Walleij   mfd: Renamed ab31...
19
  #include <linux/mfd/abx500.h>
d619bc143   Linus Walleij   regulator: AB3100...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  
  /* LDO registers and some handy masking definitions for AB3100 */
  #define AB3100_LDO_A		0x40
  #define AB3100_LDO_C		0x41
  #define AB3100_LDO_D		0x42
  #define AB3100_LDO_E		0x43
  #define AB3100_LDO_E_SLEEP	0x44
  #define AB3100_LDO_F		0x45
  #define AB3100_LDO_G		0x46
  #define AB3100_LDO_H		0x47
  #define AB3100_LDO_H_SLEEP_MODE	0
  #define AB3100_LDO_H_SLEEP_EN	2
  #define AB3100_LDO_ON		4
  #define AB3100_LDO_H_VSEL_AC	5
  #define AB3100_LDO_K		0x48
  #define AB3100_LDO_EXT		0x49
  #define AB3100_BUCK		0x4A
  #define AB3100_BUCK_SLEEP	0x4B
  #define AB3100_REG_ON_MASK	0x10
  
  /**
   * struct ab3100_regulator
   * A struct passed around the individual regulator functions
   * @platform_device: platform device holding this regulator
fa661258a   Mattias Wallin   mfd: AB3100 regis...
44
   * @dev: handle to the device
d619bc143   Linus Walleij   regulator: AB3100...
45
46
47
48
49
50
51
52
53
54
   * @plfdata: AB3100 platform data passed in at probe time
   * @regreg: regulator register number in the AB3100
   * @fixed_voltage: a fixed voltage for this regulator, if this
   *          0 the voltages array is used instead.
   * @typ_voltages: an array of available typical voltages for
   *          this regulator
   * @voltages_len: length of the array of available voltages
   */
  struct ab3100_regulator {
  	struct regulator_dev *rdev;
fa661258a   Mattias Wallin   mfd: AB3100 regis...
55
  	struct device *dev;
d619bc143   Linus Walleij   regulator: AB3100...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  	struct ab3100_platform_data *plfdata;
  	u8 regreg;
  	int fixed_voltage;
  	int const *typ_voltages;
  	u8 voltages_len;
  };
  
  /* The order in which registers are initialized */
  static const u8 ab3100_reg_init_order[AB3100_NUM_REGULATORS+2] = {
  	AB3100_LDO_A,
  	AB3100_LDO_C,
  	AB3100_LDO_E,
  	AB3100_LDO_E_SLEEP,
  	AB3100_LDO_F,
  	AB3100_LDO_G,
  	AB3100_LDO_H,
  	AB3100_LDO_K,
  	AB3100_LDO_EXT,
  	AB3100_BUCK,
  	AB3100_BUCK_SLEEP,
  	AB3100_LDO_D,
  };
  
  /* Preset (hardware defined) voltages for these regulators */
  #define LDO_A_VOLTAGE 2750000
  #define LDO_C_VOLTAGE 2650000
  #define LDO_D_VOLTAGE 2650000
9992ef40f   Mark Brown   regulator: Remove...
83
  static const int ldo_e_buck_typ_voltages[] = {
d619bc143   Linus Walleij   regulator: AB3100...
84
85
86
87
88
89
90
91
  	1800000,
  	1400000,
  	1300000,
  	1200000,
  	1100000,
  	1050000,
  	900000,
  };
9992ef40f   Mark Brown   regulator: Remove...
92
  static const int ldo_f_typ_voltages[] = {
d619bc143   Linus Walleij   regulator: AB3100...
93
94
95
96
97
98
99
100
101
  	1800000,
  	1400000,
  	1300000,
  	1200000,
  	1100000,
  	1050000,
  	2500000,
  	2650000,
  };
9992ef40f   Mark Brown   regulator: Remove...
102
  static const int ldo_g_typ_voltages[] = {
d619bc143   Linus Walleij   regulator: AB3100...
103
104
105
106
107
  	2850000,
  	2750000,
  	1800000,
  	1500000,
  };
9992ef40f   Mark Brown   regulator: Remove...
108
  static const int ldo_h_typ_voltages[] = {
d619bc143   Linus Walleij   regulator: AB3100...
109
110
111
112
113
  	2750000,
  	1800000,
  	1500000,
  	1200000,
  };
9992ef40f   Mark Brown   regulator: Remove...
114
  static const int ldo_k_typ_voltages[] = {
d619bc143   Linus Walleij   regulator: AB3100...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  	2750000,
  	1800000,
  };
  
  
  /* The regulator devices */
  static struct ab3100_regulator
  ab3100_regulators[AB3100_NUM_REGULATORS] = {
  	{
  		.regreg = AB3100_LDO_A,
  		.fixed_voltage = LDO_A_VOLTAGE,
  	},
  	{
  		.regreg = AB3100_LDO_C,
  		.fixed_voltage = LDO_C_VOLTAGE,
  	},
  	{
  		.regreg = AB3100_LDO_D,
  		.fixed_voltage = LDO_D_VOLTAGE,
  	},
  	{
  		.regreg = AB3100_LDO_E,
  		.typ_voltages = ldo_e_buck_typ_voltages,
  		.voltages_len = ARRAY_SIZE(ldo_e_buck_typ_voltages),
  	},
  	{
  		.regreg = AB3100_LDO_F,
  		.typ_voltages = ldo_f_typ_voltages,
  		.voltages_len = ARRAY_SIZE(ldo_f_typ_voltages),
  	},
  	{
  		.regreg = AB3100_LDO_G,
  		.typ_voltages = ldo_g_typ_voltages,
  		.voltages_len = ARRAY_SIZE(ldo_g_typ_voltages),
  	},
  	{
  		.regreg = AB3100_LDO_H,
  		.typ_voltages = ldo_h_typ_voltages,
  		.voltages_len = ARRAY_SIZE(ldo_h_typ_voltages),
  	},
  	{
  		.regreg = AB3100_LDO_K,
  		.typ_voltages = ldo_k_typ_voltages,
  		.voltages_len = ARRAY_SIZE(ldo_k_typ_voltages),
  	},
  	{
  		.regreg = AB3100_LDO_EXT,
  		/* No voltages for the external regulator */
  	},
  	{
  		.regreg = AB3100_BUCK,
  		.typ_voltages = ldo_e_buck_typ_voltages,
  		.voltages_len = ARRAY_SIZE(ldo_e_buck_typ_voltages),
  	},
  };
  
  /*
   * General functions for enable, disable and is_enabled used for
   * LDO: A,C,E,F,G,H,K,EXT and BUCK
   */
  static int ab3100_enable_regulator(struct regulator_dev *reg)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	int err;
  	u8 regval;
fa661258a   Mattias Wallin   mfd: AB3100 regis...
180
  	err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
d619bc143   Linus Walleij   regulator: AB3100...
181
182
183
184
185
186
187
188
189
190
191
192
193
  						&regval);
  	if (err) {
  		dev_warn(&reg->dev, "failed to get regid %d value
  ",
  			 abreg->regreg);
  		return err;
  	}
  
  	/* The regulator is already on, no reason to go further */
  	if (regval & AB3100_REG_ON_MASK)
  		return 0;
  
  	regval |= AB3100_REG_ON_MASK;
fa661258a   Mattias Wallin   mfd: AB3100 regis...
194
  	err = abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg,
d619bc143   Linus Walleij   regulator: AB3100...
195
196
197
198
199
200
201
  						regval);
  	if (err) {
  		dev_warn(&reg->dev, "failed to set regid %d value
  ",
  			 abreg->regreg);
  		return err;
  	}
d619bc143   Linus Walleij   regulator: AB3100...
202
203
204
205
206
207
208
209
210
211
212
213
214
  	return 0;
  }
  
  static int ab3100_disable_regulator(struct regulator_dev *reg)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	int err;
  	u8 regval;
  
  	/*
  	 * LDO D is a special regulator. When it is disabled, the entire
  	 * system is shut down. So this is handled specially.
  	 */
176f45b9c   Linus Walleij   Fix some AB3100 r...
215
216
  	pr_info("Called ab3100_disable_regulator
  ");
d619bc143   Linus Walleij   regulator: AB3100...
217
  	if (abreg->regreg == AB3100_LDO_D) {
d619bc143   Linus Walleij   regulator: AB3100...
218
219
  		dev_info(&reg->dev, "disabling LDO D - shut down system
  ");
d619bc143   Linus Walleij   regulator: AB3100...
220
  		/* Setting LDO D to 0x00 cuts the power to the SoC */
fa661258a   Mattias Wallin   mfd: AB3100 regis...
221
  		return abx500_set_register_interruptible(abreg->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
222
  							 AB3100_LDO_D, 0x00U);
d619bc143   Linus Walleij   regulator: AB3100...
223
224
225
226
227
  	}
  
  	/*
  	 * All other regulators are handled here
  	 */
fa661258a   Mattias Wallin   mfd: AB3100 regis...
228
  	err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
d619bc143   Linus Walleij   regulator: AB3100...
229
230
231
232
233
234
235
236
  						&regval);
  	if (err) {
  		dev_err(&reg->dev, "unable to get register 0x%x
  ",
  			abreg->regreg);
  		return err;
  	}
  	regval &= ~AB3100_REG_ON_MASK;
fa661258a   Mattias Wallin   mfd: AB3100 regis...
237
  	return abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg,
d619bc143   Linus Walleij   regulator: AB3100...
238
239
240
241
242
243
244
245
  						 regval);
  }
  
  static int ab3100_is_enabled_regulator(struct regulator_dev *reg)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	u8 regval;
  	int err;
fa661258a   Mattias Wallin   mfd: AB3100 regis...
246
  	err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
d619bc143   Linus Walleij   regulator: AB3100...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  						&regval);
  	if (err) {
  		dev_err(&reg->dev, "unable to get register 0x%x
  ",
  			abreg->regreg);
  		return err;
  	}
  
  	return regval & AB3100_REG_ON_MASK;
  }
  
  static int ab3100_list_voltage_regulator(struct regulator_dev *reg,
  					 unsigned selector)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
979da89a9   Axel Lin   ab3100: fix off-b...
262
  	if (selector >= abreg->voltages_len)
d619bc143   Linus Walleij   regulator: AB3100...
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
  		return -EINVAL;
  	return abreg->typ_voltages[selector];
  }
  
  static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	u8 regval;
  	int err;
  
  	/* Return the voltage for fixed regulators immediately */
  	if (abreg->fixed_voltage)
  		return abreg->fixed_voltage;
  
  	/*
  	 * For variable types, read out setting and index into
  	 * supplied voltage list.
  	 */
fa661258a   Mattias Wallin   mfd: AB3100 regis...
281
  	err = abx500_get_register_interruptible(abreg->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
282
283
284
285
286
287
288
289
290
291
292
293
  						abreg->regreg, &regval);
  	if (err) {
  		dev_warn(&reg->dev,
  			 "failed to get regulator value in register %02x
  ",
  			 abreg->regreg);
  		return err;
  	}
  
  	/* The 3 highest bits index voltages */
  	regval &= 0xE0;
  	regval >>= 5;
979da89a9   Axel Lin   ab3100: fix off-b...
294
  	if (regval >= abreg->voltages_len) {
d619bc143   Linus Walleij   regulator: AB3100...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  		dev_err(&reg->dev,
  			"regulator register %02x contains an illegal voltage setting
  ",
  			abreg->regreg);
  		return -EINVAL;
  	}
  
  	return abreg->typ_voltages[regval];
  }
  
  static int ab3100_get_best_voltage_index(struct regulator_dev *reg,
  				   int min_uV, int max_uV)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	int i;
  	int bestmatch;
  	int bestindex;
  
  	/*
  	 * Locate the minimum voltage fitting the criteria on
  	 * this regulator. The switchable voltages are not
  	 * in strict falling order so we need to check them
  	 * all for the best match.
  	 */
  	bestmatch = INT_MAX;
  	bestindex = -1;
  	for (i = 0; i < abreg->voltages_len; i++) {
  		if (abreg->typ_voltages[i] <= max_uV &&
  		    abreg->typ_voltages[i] >= min_uV &&
  		    abreg->typ_voltages[i] < bestmatch) {
  			bestmatch = abreg->typ_voltages[i];
  			bestindex = i;
  		}
  	}
  
  	if (bestindex < 0) {
  		dev_warn(&reg->dev, "requested %d<=x<=%d uV, out of range!
  ",
  			 min_uV, max_uV);
  		return -EINVAL;
  	}
  	return bestindex;
  }
  
  static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
3a93f2a9f   Mark Brown   regulator: Report...
340
341
  					int min_uV, int max_uV,
  					unsigned *selector)
d619bc143   Linus Walleij   regulator: AB3100...
342
343
344
345
346
347
348
349
350
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	u8 regval;
  	int err;
  	int bestindex;
  
  	bestindex = ab3100_get_best_voltage_index(reg, min_uV, max_uV);
  	if (bestindex < 0)
  		return bestindex;
3a93f2a9f   Mark Brown   regulator: Report...
351
  	*selector = bestindex;
fa661258a   Mattias Wallin   mfd: AB3100 regis...
352
  	err = abx500_get_register_interruptible(abreg->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
353
354
355
356
357
358
359
360
361
362
363
364
  						abreg->regreg, &regval);
  	if (err) {
  		dev_warn(&reg->dev,
  			 "failed to get regulator register %02x
  ",
  			 abreg->regreg);
  		return err;
  	}
  
  	/* The highest three bits control the variable regulators */
  	regval &= ~0xE0;
  	regval |= (bestindex << 5);
fa661258a   Mattias Wallin   mfd: AB3100 regis...
365
  	err = abx500_set_register_interruptible(abreg->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
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
  						abreg->regreg, regval);
  	if (err)
  		dev_warn(&reg->dev, "failed to set regulator register %02x
  ",
  			abreg->regreg);
  
  	return err;
  }
  
  static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg,
  						int uV)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  	u8 regval;
  	int err;
  	int bestindex;
  	u8 targetreg;
  
  	if (abreg->regreg == AB3100_LDO_E)
  		targetreg = AB3100_LDO_E_SLEEP;
  	else if (abreg->regreg == AB3100_BUCK)
  		targetreg = AB3100_BUCK_SLEEP;
  	else
  		return -EINVAL;
  
  	/* LDO E and BUCK have special suspend voltages you can set */
  	bestindex = ab3100_get_best_voltage_index(reg, uV, uV);
fa661258a   Mattias Wallin   mfd: AB3100 regis...
393
  	err = abx500_get_register_interruptible(abreg->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
394
395
396
397
398
399
400
401
402
403
404
405
  						targetreg, &regval);
  	if (err) {
  		dev_warn(&reg->dev,
  			 "failed to get regulator register %02x
  ",
  			 targetreg);
  		return err;
  	}
  
  	/* The highest three bits control the variable regulators */
  	regval &= ~0xE0;
  	regval |= (bestindex << 5);
fa661258a   Mattias Wallin   mfd: AB3100 regis...
406
  	err = abx500_set_register_interruptible(abreg->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
  						targetreg, regval);
  	if (err)
  		dev_warn(&reg->dev, "failed to set regulator register %02x
  ",
  			abreg->regreg);
  
  	return err;
  }
  
  /*
   * The external regulator can just define a fixed voltage.
   */
  static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  
  	return abreg->plfdata->external_voltage;
  }
19c988259   Linus Walleij   regulator: switch...
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
  static int ab3100_enable_time_regulator(struct regulator_dev *reg)
  {
  	struct ab3100_regulator *abreg = reg->reg_data;
  
  	/* Per-regulator power on delay from spec */
  	switch (abreg->regreg) {
  	case AB3100_LDO_A: /* Fallthrough */
  	case AB3100_LDO_C: /* Fallthrough */
  	case AB3100_LDO_D: /* Fallthrough */
  	case AB3100_LDO_E: /* Fallthrough */
  	case AB3100_LDO_H: /* Fallthrough */
  	case AB3100_LDO_K:
  		return 200;
  	case AB3100_LDO_F:
  		return 600;
  	case AB3100_LDO_G:
  		return 400;
  	case AB3100_BUCK:
  		return 1000;
  	default:
  		break;
  	}
  	return 0;
  }
d619bc143   Linus Walleij   regulator: AB3100...
449
450
451
452
453
  static struct regulator_ops regulator_ops_fixed = {
  	.enable      = ab3100_enable_regulator,
  	.disable     = ab3100_disable_regulator,
  	.is_enabled  = ab3100_is_enabled_regulator,
  	.get_voltage = ab3100_get_voltage_regulator,
19c988259   Linus Walleij   regulator: switch...
454
  	.enable_time = ab3100_enable_time_regulator,
d619bc143   Linus Walleij   regulator: AB3100...
455
456
457
458
459
460
461
462
463
  };
  
  static struct regulator_ops regulator_ops_variable = {
  	.enable      = ab3100_enable_regulator,
  	.disable     = ab3100_disable_regulator,
  	.is_enabled  = ab3100_is_enabled_regulator,
  	.get_voltage = ab3100_get_voltage_regulator,
  	.set_voltage = ab3100_set_voltage_regulator,
  	.list_voltage = ab3100_list_voltage_regulator,
19c988259   Linus Walleij   regulator: switch...
464
  	.enable_time = ab3100_enable_time_regulator,
d619bc143   Linus Walleij   regulator: AB3100...
465
466
467
468
469
470
471
472
473
474
  };
  
  static struct regulator_ops regulator_ops_variable_sleepable = {
  	.enable      = ab3100_enable_regulator,
  	.disable     = ab3100_disable_regulator,
  	.is_enabled  = ab3100_is_enabled_regulator,
  	.get_voltage = ab3100_get_voltage_regulator,
  	.set_voltage = ab3100_set_voltage_regulator,
  	.set_suspend_voltage = ab3100_set_suspend_voltage_regulator,
  	.list_voltage = ab3100_list_voltage_regulator,
19c988259   Linus Walleij   regulator: switch...
475
  	.enable_time = ab3100_enable_time_regulator,
d619bc143   Linus Walleij   regulator: AB3100...
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
  };
  
  /*
   * LDO EXT is an external regulator so it is really
   * not possible to set any voltage locally here, AB3100
   * is an on/off switch plain an simple. The external
   * voltage is defined in the board set-up if any.
   */
  static struct regulator_ops regulator_ops_external = {
  	.enable      = ab3100_enable_regulator,
  	.disable     = ab3100_disable_regulator,
  	.is_enabled  = ab3100_is_enabled_regulator,
  	.get_voltage = ab3100_get_voltage_regulator_external,
  };
  
  static struct regulator_desc
  ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
  	{
  		.name = "LDO_A",
  		.id   = AB3100_LDO_A,
  		.ops  = &regulator_ops_fixed,
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
498
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
499
500
501
502
503
504
  	},
  	{
  		.name = "LDO_C",
  		.id   = AB3100_LDO_C,
  		.ops  = &regulator_ops_fixed,
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
505
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
506
507
508
509
510
511
  	},
  	{
  		.name = "LDO_D",
  		.id   = AB3100_LDO_D,
  		.ops  = &regulator_ops_fixed,
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
512
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
513
514
515
516
517
  	},
  	{
  		.name = "LDO_E",
  		.id   = AB3100_LDO_E,
  		.ops  = &regulator_ops_variable_sleepable,
75f2ba8f0   Linus Walleij   regulator: Voltag...
518
  		.n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
d619bc143   Linus Walleij   regulator: AB3100...
519
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
520
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
521
522
523
524
525
  	},
  	{
  		.name = "LDO_F",
  		.id   = AB3100_LDO_F,
  		.ops  = &regulator_ops_variable,
75f2ba8f0   Linus Walleij   regulator: Voltag...
526
  		.n_voltages = ARRAY_SIZE(ldo_f_typ_voltages),
d619bc143   Linus Walleij   regulator: AB3100...
527
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
528
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
529
530
531
532
533
  	},
  	{
  		.name = "LDO_G",
  		.id   = AB3100_LDO_G,
  		.ops  = &regulator_ops_variable,
75f2ba8f0   Linus Walleij   regulator: Voltag...
534
  		.n_voltages = ARRAY_SIZE(ldo_g_typ_voltages),
d619bc143   Linus Walleij   regulator: AB3100...
535
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
536
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
537
538
539
540
541
  	},
  	{
  		.name = "LDO_H",
  		.id   = AB3100_LDO_H,
  		.ops  = &regulator_ops_variable,
75f2ba8f0   Linus Walleij   regulator: Voltag...
542
  		.n_voltages = ARRAY_SIZE(ldo_h_typ_voltages),
d619bc143   Linus Walleij   regulator: AB3100...
543
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
544
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
545
546
547
548
549
  	},
  	{
  		.name = "LDO_K",
  		.id   = AB3100_LDO_K,
  		.ops  = &regulator_ops_variable,
75f2ba8f0   Linus Walleij   regulator: Voltag...
550
  		.n_voltages = ARRAY_SIZE(ldo_k_typ_voltages),
d619bc143   Linus Walleij   regulator: AB3100...
551
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
552
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
553
554
555
556
557
558
  	},
  	{
  		.name = "LDO_EXT",
  		.id   = AB3100_LDO_EXT,
  		.ops  = &regulator_ops_external,
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
559
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
560
561
562
563
564
  	},
  	{
  		.name = "BUCK",
  		.id   = AB3100_BUCK,
  		.ops  = &regulator_ops_variable_sleepable,
75f2ba8f0   Linus Walleij   regulator: Voltag...
565
  		.n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
d619bc143   Linus Walleij   regulator: AB3100...
566
  		.type = REGULATOR_VOLTAGE,
64714354a   Axel Lin   Regulators: ab310...
567
  		.owner = THIS_MODULE,
d619bc143   Linus Walleij   regulator: AB3100...
568
569
570
571
572
573
574
575
  	},
  };
  
  /*
   * NOTE: the following functions are regulators pluralis - it is the
   * binding to the AB3100 core driver and the parent platform device
   * for all the different regulators.
   */
98bf7c057   Dmitry Torokhov   Regulators: ab310...
576
  static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
d619bc143   Linus Walleij   regulator: AB3100...
577
  {
a771e36e1   Samuel Ortiz   mfd: Use mfd cell...
578
  	struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
d619bc143   Linus Walleij   regulator: AB3100...
579
580
581
582
583
  	int err = 0;
  	u8 data;
  	int i;
  
  	/* Check chip state */
fa661258a   Mattias Wallin   mfd: AB3100 regis...
584
  	err = abx500_get_register_interruptible(&pdev->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
  						AB3100_LDO_D, &data);
  	if (err) {
  		dev_err(&pdev->dev, "could not read initial status of LDO_D
  ");
  		return err;
  	}
  	if (data & 0x10)
  		dev_notice(&pdev->dev,
  			   "chip is already in active mode (Warm start)
  ");
  	else
  		dev_notice(&pdev->dev,
  			   "chip is in inactive mode (Cold start)
  ");
  
  	/* Set up regulators */
  	for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
fa661258a   Mattias Wallin   mfd: AB3100 regis...
602
  		err = abx500_set_register_interruptible(&pdev->dev, 0,
d619bc143   Linus Walleij   regulator: AB3100...
603
604
605
606
607
608
609
610
611
  					ab3100_reg_init_order[i],
  					plfdata->reg_initvals[i]);
  		if (err) {
  			dev_err(&pdev->dev, "regulator initialization failed with error %d
  ",
  				err);
  			return err;
  		}
  	}
d619bc143   Linus Walleij   regulator: AB3100...
612
613
614
615
616
617
618
619
620
621
622
623
  	/* Register the regulators */
  	for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
  		struct ab3100_regulator *reg = &ab3100_regulators[i];
  		struct regulator_dev *rdev;
  
  		/*
  		 * Initialize per-regulator struct.
  		 * Inherit platform data, this comes down from the
  		 * i2c boarddata, from the machine. So if you want to
  		 * see what it looks like for a certain machine, go
  		 * into the machine I2C setup.
  		 */
fa661258a   Mattias Wallin   mfd: AB3100 regis...
624
  		reg->dev = &pdev->dev;
d619bc143   Linus Walleij   regulator: AB3100...
625
626
627
628
629
630
631
632
633
  		reg->plfdata = plfdata;
  
  		/*
  		 * Register the regulator, pass around
  		 * the ab3100_regulator struct
  		 */
  		rdev = regulator_register(&ab3100_regulator_desc[i],
  					  &pdev->dev,
  					  &plfdata->reg_constraints[i],
2c043bcbf   Rajendra Nayak   regulator: pass a...
634
  					  reg, NULL);
d619bc143   Linus Walleij   regulator: AB3100...
635
636
637
638
639
640
641
642
  
  		if (IS_ERR(rdev)) {
  			err = PTR_ERR(rdev);
  			dev_err(&pdev->dev,
  				"%s: failed to register regulator %s err %d
  ",
  				__func__, ab3100_regulator_desc[i].name,
  				err);
d619bc143   Linus Walleij   regulator: AB3100...
643
  			/* remove the already registered regulators */
b3fcf3e57   Axel Lin   regulator: ab3100...
644
  			while (--i >= 0)
d619bc143   Linus Walleij   regulator: AB3100...
645
  				regulator_unregister(ab3100_regulators[i].rdev);
d619bc143   Linus Walleij   regulator: AB3100...
646
647
648
649
650
651
652
653
654
  			return err;
  		}
  
  		/* Then set a pointer back to the registered regulator */
  		reg->rdev = rdev;
  	}
  
  	return 0;
  }
98bf7c057   Dmitry Torokhov   Regulators: ab310...
655
  static int __devexit ab3100_regulators_remove(struct platform_device *pdev)
d619bc143   Linus Walleij   regulator: AB3100...
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
  {
  	int i;
  
  	for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
  		struct ab3100_regulator *reg = &ab3100_regulators[i];
  
  		regulator_unregister(reg->rdev);
  	}
  	return 0;
  }
  
  static struct platform_driver ab3100_regulators_driver = {
  	.driver = {
  		.name  = "ab3100-regulators",
  		.owner = THIS_MODULE,
  	},
  	.probe = ab3100_regulators_probe,
98bf7c057   Dmitry Torokhov   Regulators: ab310...
673
  	.remove = __devexit_p(ab3100_regulators_remove),
d619bc143   Linus Walleij   regulator: AB3100...
674
675
676
677
678
679
680
681
682
  };
  
  static __init int ab3100_regulators_init(void)
  {
  	return platform_driver_register(&ab3100_regulators_driver);
  }
  
  static __exit void ab3100_regulators_exit(void)
  {
176f45b9c   Linus Walleij   Fix some AB3100 r...
683
  	platform_driver_unregister(&ab3100_regulators_driver);
d619bc143   Linus Walleij   regulator: AB3100...
684
685
686
687
688
689
690
691
692
  }
  
  subsys_initcall(ab3100_regulators_init);
  module_exit(ab3100_regulators_exit);
  
  MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
  MODULE_DESCRIPTION("AB3100 Regulator driver");
  MODULE_LICENSE("GPL");
  MODULE_ALIAS("platform:ab3100-regulators");