1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // wm831x-ldo.c -- LDO driver for the WM831x series
4 //
5 // Copyright 2009 Wolfson Microelectronics PLC.
6 //
7 // Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/init.h>
12 #include <linux/bitops.h>
13 #include <linux/err.h>
14 #include <linux/i2c.h>
15 #include <linux/platform_device.h>
16 #include <linux/regulator/driver.h>
17 #include <linux/slab.h>
18
19 #include <linux/mfd/wm831x/core.h>
20 #include <linux/mfd/wm831x/regulator.h>
21 #include <linux/mfd/wm831x/pdata.h>
22
23 #define WM831X_LDO_MAX_NAME 9
24
25 #define WM831X_LDO_CONTROL 0
26 #define WM831X_LDO_ON_CONTROL 1
27 #define WM831X_LDO_SLEEP_CONTROL 2
28
29 #define WM831X_ALIVE_LDO_ON_CONTROL 0
30 #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1
31
32 struct wm831x_ldo {
33 char name[WM831X_LDO_MAX_NAME];
34 char supply_name[WM831X_LDO_MAX_NAME];
35 struct regulator_desc desc;
36 int base;
37 struct wm831x *wm831x;
38 struct regulator_dev *regulator;
39 };
40
41 /*
42 * Shared
43 */
44
wm831x_ldo_uv_irq(int irq,void * data)45 static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data)
46 {
47 struct wm831x_ldo *ldo = data;
48
49 regulator_lock(ldo->regulator);
50 regulator_notifier_call_chain(ldo->regulator,
51 REGULATOR_EVENT_UNDER_VOLTAGE,
52 NULL);
53 regulator_unlock(ldo->regulator);
54
55 return IRQ_HANDLED;
56 }
57
58 /*
59 * General purpose LDOs
60 */
61
62 static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = {
63 REGULATOR_LINEAR_RANGE(900000, 0, 14, 50000),
64 REGULATOR_LINEAR_RANGE(1700000, 15, 31, 100000),
65 };
66
wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev * rdev,int uV)67 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
68 int uV)
69 {
70 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
71 struct wm831x *wm831x = ldo->wm831x;
72 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
73
74 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
75 if (sel < 0)
76 return sel;
77
78 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel);
79 }
80
wm831x_gp_ldo_get_mode(struct regulator_dev * rdev)81 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
82 {
83 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
84 struct wm831x *wm831x = ldo->wm831x;
85 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
86 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
87 int ret;
88
89 ret = wm831x_reg_read(wm831x, on_reg);
90 if (ret < 0)
91 return ret;
92
93 if (!(ret & WM831X_LDO1_ON_MODE))
94 return REGULATOR_MODE_NORMAL;
95
96 ret = wm831x_reg_read(wm831x, ctrl_reg);
97 if (ret < 0)
98 return ret;
99
100 if (ret & WM831X_LDO1_LP_MODE)
101 return REGULATOR_MODE_STANDBY;
102 else
103 return REGULATOR_MODE_IDLE;
104 }
105
wm831x_gp_ldo_set_mode(struct regulator_dev * rdev,unsigned int mode)106 static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev,
107 unsigned int mode)
108 {
109 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
110 struct wm831x *wm831x = ldo->wm831x;
111 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
112 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
113 int ret;
114
115
116 switch (mode) {
117 case REGULATOR_MODE_NORMAL:
118 ret = wm831x_set_bits(wm831x, on_reg,
119 WM831X_LDO1_ON_MODE, 0);
120 if (ret < 0)
121 return ret;
122 break;
123
124 case REGULATOR_MODE_IDLE:
125 ret = wm831x_set_bits(wm831x, ctrl_reg,
126 WM831X_LDO1_LP_MODE, 0);
127 if (ret < 0)
128 return ret;
129
130 ret = wm831x_set_bits(wm831x, on_reg,
131 WM831X_LDO1_ON_MODE,
132 WM831X_LDO1_ON_MODE);
133 if (ret < 0)
134 return ret;
135 break;
136
137 case REGULATOR_MODE_STANDBY:
138 ret = wm831x_set_bits(wm831x, ctrl_reg,
139 WM831X_LDO1_LP_MODE,
140 WM831X_LDO1_LP_MODE);
141 if (ret < 0)
142 return ret;
143
144 ret = wm831x_set_bits(wm831x, on_reg,
145 WM831X_LDO1_ON_MODE,
146 WM831X_LDO1_ON_MODE);
147 if (ret < 0)
148 return ret;
149 break;
150
151 default:
152 return -EINVAL;
153 }
154
155 return 0;
156 }
157
wm831x_gp_ldo_get_status(struct regulator_dev * rdev)158 static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev)
159 {
160 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
161 struct wm831x *wm831x = ldo->wm831x;
162 int mask = 1 << rdev_get_id(rdev);
163 int ret;
164
165 /* Is the regulator on? */
166 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
167 if (ret < 0)
168 return ret;
169 if (!(ret & mask))
170 return REGULATOR_STATUS_OFF;
171
172 /* Is it reporting under voltage? */
173 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
174 if (ret < 0)
175 return ret;
176 if (ret & mask)
177 return REGULATOR_STATUS_ERROR;
178
179 ret = wm831x_gp_ldo_get_mode(rdev);
180 if (ret < 0)
181 return ret;
182 else
183 return regulator_mode_to_status(ret);
184 }
185
wm831x_gp_ldo_get_optimum_mode(struct regulator_dev * rdev,int input_uV,int output_uV,int load_uA)186 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
187 int input_uV,
188 int output_uV, int load_uA)
189 {
190 if (load_uA < 20000)
191 return REGULATOR_MODE_STANDBY;
192 if (load_uA < 50000)
193 return REGULATOR_MODE_IDLE;
194 return REGULATOR_MODE_NORMAL;
195 }
196
197
198 static const struct regulator_ops wm831x_gp_ldo_ops = {
199 .list_voltage = regulator_list_voltage_linear_range,
200 .map_voltage = regulator_map_voltage_linear_range,
201 .get_voltage_sel = regulator_get_voltage_sel_regmap,
202 .set_voltage_sel = regulator_set_voltage_sel_regmap,
203 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
204 .get_mode = wm831x_gp_ldo_get_mode,
205 .set_mode = wm831x_gp_ldo_set_mode,
206 .get_status = wm831x_gp_ldo_get_status,
207 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode,
208 .get_bypass = regulator_get_bypass_regmap,
209 .set_bypass = regulator_set_bypass_regmap,
210
211 .is_enabled = regulator_is_enabled_regmap,
212 .enable = regulator_enable_regmap,
213 .disable = regulator_disable_regmap,
214 };
215
wm831x_gp_ldo_probe(struct platform_device * pdev)216 static int wm831x_gp_ldo_probe(struct platform_device *pdev)
217 {
218 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
219 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
220 struct regulator_config config = { };
221 int id;
222 struct wm831x_ldo *ldo;
223 struct resource *res;
224 int ret, irq;
225
226 if (pdata && pdata->wm831x_num)
227 id = (pdata->wm831x_num * 10) + 1;
228 else
229 id = 0;
230 id = pdev->id - id;
231
232 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
233
234 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
235 if (!ldo)
236 return -ENOMEM;
237
238 ldo->wm831x = wm831x;
239
240 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
241 if (res == NULL) {
242 dev_err(&pdev->dev, "No REG resource\n");
243 ret = -EINVAL;
244 goto err;
245 }
246 ldo->base = res->start;
247
248 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
249 ldo->desc.name = ldo->name;
250
251 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
252 "LDO%dVDD", id + 1);
253 ldo->desc.supply_name = ldo->supply_name;
254
255 ldo->desc.id = id;
256 ldo->desc.type = REGULATOR_VOLTAGE;
257 ldo->desc.n_voltages = 32;
258 ldo->desc.ops = &wm831x_gp_ldo_ops;
259 ldo->desc.owner = THIS_MODULE;
260 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
261 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK;
262 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
263 ldo->desc.enable_mask = 1 << id;
264 ldo->desc.bypass_reg = ldo->base;
265 ldo->desc.bypass_mask = WM831X_LDO1_SWI;
266 ldo->desc.linear_ranges = wm831x_gp_ldo_ranges;
267 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_gp_ldo_ranges);
268
269 config.dev = pdev->dev.parent;
270 if (pdata)
271 config.init_data = pdata->ldo[id];
272 config.driver_data = ldo;
273 config.regmap = wm831x->regmap;
274
275 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
276 &config);
277 if (IS_ERR(ldo->regulator)) {
278 ret = PTR_ERR(ldo->regulator);
279 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
280 id + 1, ret);
281 goto err;
282 }
283
284 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
285 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
286 wm831x_ldo_uv_irq,
287 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
288 ldo->name,
289 ldo);
290 if (ret != 0) {
291 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
292 irq, ret);
293 goto err;
294 }
295
296 platform_set_drvdata(pdev, ldo);
297
298 return 0;
299
300 err:
301 return ret;
302 }
303
304 static struct platform_driver wm831x_gp_ldo_driver = {
305 .probe = wm831x_gp_ldo_probe,
306 .driver = {
307 .name = "wm831x-ldo",
308 },
309 };
310
311 /*
312 * Analogue LDOs
313 */
314
315 static const struct regulator_linear_range wm831x_aldo_ranges[] = {
316 REGULATOR_LINEAR_RANGE(1000000, 0, 12, 50000),
317 REGULATOR_LINEAR_RANGE(1700000, 13, 31, 100000),
318 };
319
wm831x_aldo_set_suspend_voltage(struct regulator_dev * rdev,int uV)320 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
321 int uV)
322 {
323 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
324 struct wm831x *wm831x = ldo->wm831x;
325 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
326
327 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
328 if (sel < 0)
329 return sel;
330
331 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel);
332 }
333
wm831x_aldo_get_mode(struct regulator_dev * rdev)334 static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
335 {
336 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
337 struct wm831x *wm831x = ldo->wm831x;
338 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
339 int ret;
340
341 ret = wm831x_reg_read(wm831x, on_reg);
342 if (ret < 0)
343 return 0;
344
345 if (ret & WM831X_LDO7_ON_MODE)
346 return REGULATOR_MODE_IDLE;
347 else
348 return REGULATOR_MODE_NORMAL;
349 }
350
wm831x_aldo_set_mode(struct regulator_dev * rdev,unsigned int mode)351 static int wm831x_aldo_set_mode(struct regulator_dev *rdev,
352 unsigned int mode)
353 {
354 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
355 struct wm831x *wm831x = ldo->wm831x;
356 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
357 int ret;
358
359
360 switch (mode) {
361 case REGULATOR_MODE_NORMAL:
362 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0);
363 if (ret < 0)
364 return ret;
365 break;
366
367 case REGULATOR_MODE_IDLE:
368 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE,
369 WM831X_LDO7_ON_MODE);
370 if (ret < 0)
371 return ret;
372 break;
373
374 default:
375 return -EINVAL;
376 }
377
378 return 0;
379 }
380
wm831x_aldo_get_status(struct regulator_dev * rdev)381 static int wm831x_aldo_get_status(struct regulator_dev *rdev)
382 {
383 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
384 struct wm831x *wm831x = ldo->wm831x;
385 int mask = 1 << rdev_get_id(rdev);
386 int ret;
387
388 /* Is the regulator on? */
389 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
390 if (ret < 0)
391 return ret;
392 if (!(ret & mask))
393 return REGULATOR_STATUS_OFF;
394
395 /* Is it reporting under voltage? */
396 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
397 if (ret < 0)
398 return ret;
399 if (ret & mask)
400 return REGULATOR_STATUS_ERROR;
401
402 ret = wm831x_aldo_get_mode(rdev);
403 if (ret < 0)
404 return ret;
405 else
406 return regulator_mode_to_status(ret);
407 }
408
409 static const struct regulator_ops wm831x_aldo_ops = {
410 .list_voltage = regulator_list_voltage_linear_range,
411 .map_voltage = regulator_map_voltage_linear_range,
412 .get_voltage_sel = regulator_get_voltage_sel_regmap,
413 .set_voltage_sel = regulator_set_voltage_sel_regmap,
414 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
415 .get_mode = wm831x_aldo_get_mode,
416 .set_mode = wm831x_aldo_set_mode,
417 .get_status = wm831x_aldo_get_status,
418 .set_bypass = regulator_set_bypass_regmap,
419 .get_bypass = regulator_get_bypass_regmap,
420
421 .is_enabled = regulator_is_enabled_regmap,
422 .enable = regulator_enable_regmap,
423 .disable = regulator_disable_regmap,
424 };
425
wm831x_aldo_probe(struct platform_device * pdev)426 static int wm831x_aldo_probe(struct platform_device *pdev)
427 {
428 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
429 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
430 struct regulator_config config = { };
431 int id;
432 struct wm831x_ldo *ldo;
433 struct resource *res;
434 int ret, irq;
435
436 if (pdata && pdata->wm831x_num)
437 id = (pdata->wm831x_num * 10) + 1;
438 else
439 id = 0;
440 id = pdev->id - id;
441
442 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
443
444 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
445 if (!ldo)
446 return -ENOMEM;
447
448 ldo->wm831x = wm831x;
449
450 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
451 if (res == NULL) {
452 dev_err(&pdev->dev, "No REG resource\n");
453 ret = -EINVAL;
454 goto err;
455 }
456 ldo->base = res->start;
457
458 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
459 ldo->desc.name = ldo->name;
460
461 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
462 "LDO%dVDD", id + 1);
463 ldo->desc.supply_name = ldo->supply_name;
464
465 ldo->desc.id = id;
466 ldo->desc.type = REGULATOR_VOLTAGE;
467 ldo->desc.n_voltages = 32;
468 ldo->desc.linear_ranges = wm831x_aldo_ranges;
469 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_aldo_ranges);
470 ldo->desc.ops = &wm831x_aldo_ops;
471 ldo->desc.owner = THIS_MODULE;
472 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
473 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK;
474 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
475 ldo->desc.enable_mask = 1 << id;
476 ldo->desc.bypass_reg = ldo->base;
477 ldo->desc.bypass_mask = WM831X_LDO7_SWI;
478
479 config.dev = pdev->dev.parent;
480 if (pdata)
481 config.init_data = pdata->ldo[id];
482 config.driver_data = ldo;
483 config.regmap = wm831x->regmap;
484
485 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
486 &config);
487 if (IS_ERR(ldo->regulator)) {
488 ret = PTR_ERR(ldo->regulator);
489 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
490 id + 1, ret);
491 goto err;
492 }
493
494 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
495 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
496 wm831x_ldo_uv_irq,
497 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
498 ldo->name, ldo);
499 if (ret != 0) {
500 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
501 irq, ret);
502 goto err;
503 }
504
505 platform_set_drvdata(pdev, ldo);
506
507 return 0;
508
509 err:
510 return ret;
511 }
512
513 static struct platform_driver wm831x_aldo_driver = {
514 .probe = wm831x_aldo_probe,
515 .driver = {
516 .name = "wm831x-aldo",
517 },
518 };
519
520 /*
521 * Alive LDO
522 */
523
524 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
525
wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev * rdev,int uV)526 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
527 int uV)
528 {
529 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
530 struct wm831x *wm831x = ldo->wm831x;
531 int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
532
533 sel = regulator_map_voltage_linear(rdev, uV, uV);
534 if (sel < 0)
535 return sel;
536
537 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel);
538 }
539
wm831x_alive_ldo_get_status(struct regulator_dev * rdev)540 static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
541 {
542 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
543 struct wm831x *wm831x = ldo->wm831x;
544 int mask = 1 << rdev_get_id(rdev);
545 int ret;
546
547 /* Is the regulator on? */
548 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
549 if (ret < 0)
550 return ret;
551 if (ret & mask)
552 return REGULATOR_STATUS_ON;
553 else
554 return REGULATOR_STATUS_OFF;
555 }
556
557 static const struct regulator_ops wm831x_alive_ldo_ops = {
558 .list_voltage = regulator_list_voltage_linear,
559 .map_voltage = regulator_map_voltage_linear,
560 .get_voltage_sel = regulator_get_voltage_sel_regmap,
561 .set_voltage_sel = regulator_set_voltage_sel_regmap,
562 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
563 .get_status = wm831x_alive_ldo_get_status,
564
565 .is_enabled = regulator_is_enabled_regmap,
566 .enable = regulator_enable_regmap,
567 .disable = regulator_disable_regmap,
568 };
569
wm831x_alive_ldo_probe(struct platform_device * pdev)570 static int wm831x_alive_ldo_probe(struct platform_device *pdev)
571 {
572 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
573 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
574 struct regulator_config config = { };
575 int id;
576 struct wm831x_ldo *ldo;
577 struct resource *res;
578 int ret;
579
580 if (pdata && pdata->wm831x_num)
581 id = (pdata->wm831x_num * 10) + 1;
582 else
583 id = 0;
584 id = pdev->id - id;
585
586
587 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
588
589 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
590 if (!ldo)
591 return -ENOMEM;
592
593 ldo->wm831x = wm831x;
594
595 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
596 if (res == NULL) {
597 dev_err(&pdev->dev, "No REG resource\n");
598 ret = -EINVAL;
599 goto err;
600 }
601 ldo->base = res->start;
602
603 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
604 ldo->desc.name = ldo->name;
605
606 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
607 "LDO%dVDD", id + 1);
608 ldo->desc.supply_name = ldo->supply_name;
609
610 ldo->desc.id = id;
611 ldo->desc.type = REGULATOR_VOLTAGE;
612 ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1;
613 ldo->desc.ops = &wm831x_alive_ldo_ops;
614 ldo->desc.owner = THIS_MODULE;
615 ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
616 ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK;
617 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
618 ldo->desc.enable_mask = 1 << id;
619 ldo->desc.min_uV = 800000;
620 ldo->desc.uV_step = 50000;
621 ldo->desc.enable_time = 1000;
622
623 config.dev = pdev->dev.parent;
624 if (pdata)
625 config.init_data = pdata->ldo[id];
626 config.driver_data = ldo;
627 config.regmap = wm831x->regmap;
628
629 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
630 &config);
631 if (IS_ERR(ldo->regulator)) {
632 ret = PTR_ERR(ldo->regulator);
633 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
634 id + 1, ret);
635 goto err;
636 }
637
638 platform_set_drvdata(pdev, ldo);
639
640 return 0;
641
642 err:
643 return ret;
644 }
645
646 static struct platform_driver wm831x_alive_ldo_driver = {
647 .probe = wm831x_alive_ldo_probe,
648 .driver = {
649 .name = "wm831x-alive-ldo",
650 },
651 };
652
653 static struct platform_driver * const drivers[] = {
654 &wm831x_gp_ldo_driver,
655 &wm831x_aldo_driver,
656 &wm831x_alive_ldo_driver,
657 };
658
wm831x_ldo_init(void)659 static int __init wm831x_ldo_init(void)
660 {
661 return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
662 }
663 subsys_initcall(wm831x_ldo_init);
664
wm831x_ldo_exit(void)665 static void __exit wm831x_ldo_exit(void)
666 {
667 platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
668 }
669 module_exit(wm831x_ldo_exit);
670
671 /* Module information */
672 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
673 MODULE_DESCRIPTION("WM831x LDO driver");
674 MODULE_LICENSE("GPL");
675 MODULE_ALIAS("platform:wm831x-ldo");
676 MODULE_ALIAS("platform:wm831x-aldo");
677 MODULE_ALIAS("platform:wm831x-aliveldo");
678