Linux 3.11-rc2
[linux-2.6.git] / drivers / regulator / wm831x-ldo.c
blob9ff883f80878447dc2902de4cae7de8e206b47fd
1 /*
2 * wm831x-ldo.c -- LDO driver for the WM831x series
4 * Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/bitops.h>
18 #include <linux/err.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/slab.h>
24 #include <linux/mfd/wm831x/core.h>
25 #include <linux/mfd/wm831x/regulator.h>
26 #include <linux/mfd/wm831x/pdata.h>
28 #define WM831X_LDO_MAX_NAME 9
30 #define WM831X_LDO_CONTROL 0
31 #define WM831X_LDO_ON_CONTROL 1
32 #define WM831X_LDO_SLEEP_CONTROL 2
34 #define WM831X_ALIVE_LDO_ON_CONTROL 0
35 #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1
37 struct wm831x_ldo {
38 char name[WM831X_LDO_MAX_NAME];
39 char supply_name[WM831X_LDO_MAX_NAME];
40 struct regulator_desc desc;
41 int base;
42 struct wm831x *wm831x;
43 struct regulator_dev *regulator;
47 * Shared
50 static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data)
52 struct wm831x_ldo *ldo = data;
54 regulator_notifier_call_chain(ldo->regulator,
55 REGULATOR_EVENT_UNDER_VOLTAGE,
56 NULL);
58 return IRQ_HANDLED;
62 * General purpose LDOs
65 #define WM831X_GP_LDO_SELECTOR_LOW 0xe
66 #define WM831X_GP_LDO_MAX_SELECTOR 0x1f
68 static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev,
69 unsigned int selector)
71 /* 0.9-1.6V in 50mV steps */
72 if (selector <= WM831X_GP_LDO_SELECTOR_LOW)
73 return 900000 + (selector * 50000);
74 /* 1.7-3.3V in 100mV steps */
75 if (selector <= WM831X_GP_LDO_MAX_SELECTOR)
76 return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW)
77 * 100000);
78 return -EINVAL;
81 static int wm831x_gp_ldo_map_voltage(struct regulator_dev *rdev,
82 int min_uV, int max_uV)
84 int volt, vsel;
86 if (min_uV < 900000)
87 vsel = 0;
88 else if (min_uV < 1700000)
89 vsel = ((min_uV - 900000) / 50000);
90 else
91 vsel = ((min_uV - 1700000) / 100000)
92 + WM831X_GP_LDO_SELECTOR_LOW + 1;
94 volt = wm831x_gp_ldo_list_voltage(rdev, vsel);
95 if (volt < min_uV || volt > max_uV)
96 return -EINVAL;
98 return vsel;
101 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
102 int uV)
104 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
105 struct wm831x *wm831x = ldo->wm831x;
106 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
108 sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV);
109 if (sel < 0)
110 return sel;
112 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel);
115 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
117 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
118 struct wm831x *wm831x = ldo->wm831x;
119 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
120 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
121 int ret;
123 ret = wm831x_reg_read(wm831x, on_reg);
124 if (ret < 0)
125 return ret;
127 if (!(ret & WM831X_LDO1_ON_MODE))
128 return REGULATOR_MODE_NORMAL;
130 ret = wm831x_reg_read(wm831x, ctrl_reg);
131 if (ret < 0)
132 return ret;
134 if (ret & WM831X_LDO1_LP_MODE)
135 return REGULATOR_MODE_STANDBY;
136 else
137 return REGULATOR_MODE_IDLE;
140 static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev,
141 unsigned int mode)
143 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
144 struct wm831x *wm831x = ldo->wm831x;
145 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
146 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
147 int ret;
150 switch (mode) {
151 case REGULATOR_MODE_NORMAL:
152 ret = wm831x_set_bits(wm831x, on_reg,
153 WM831X_LDO1_ON_MODE, 0);
154 if (ret < 0)
155 return ret;
156 break;
158 case REGULATOR_MODE_IDLE:
159 ret = wm831x_set_bits(wm831x, ctrl_reg,
160 WM831X_LDO1_LP_MODE, 0);
161 if (ret < 0)
162 return ret;
164 ret = wm831x_set_bits(wm831x, on_reg,
165 WM831X_LDO1_ON_MODE,
166 WM831X_LDO1_ON_MODE);
167 if (ret < 0)
168 return ret;
169 break;
171 case REGULATOR_MODE_STANDBY:
172 ret = wm831x_set_bits(wm831x, ctrl_reg,
173 WM831X_LDO1_LP_MODE,
174 WM831X_LDO1_LP_MODE);
175 if (ret < 0)
176 return ret;
178 ret = wm831x_set_bits(wm831x, on_reg,
179 WM831X_LDO1_ON_MODE,
180 WM831X_LDO1_ON_MODE);
181 if (ret < 0)
182 return ret;
183 break;
185 default:
186 return -EINVAL;
189 return 0;
192 static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev)
194 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
195 struct wm831x *wm831x = ldo->wm831x;
196 int mask = 1 << rdev_get_id(rdev);
197 int ret;
199 /* Is the regulator on? */
200 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
201 if (ret < 0)
202 return ret;
203 if (!(ret & mask))
204 return REGULATOR_STATUS_OFF;
206 /* Is it reporting under voltage? */
207 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
208 if (ret < 0)
209 return ret;
210 if (ret & mask)
211 return REGULATOR_STATUS_ERROR;
213 ret = wm831x_gp_ldo_get_mode(rdev);
214 if (ret < 0)
215 return ret;
216 else
217 return regulator_mode_to_status(ret);
220 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
221 int input_uV,
222 int output_uV, int load_uA)
224 if (load_uA < 20000)
225 return REGULATOR_MODE_STANDBY;
226 if (load_uA < 50000)
227 return REGULATOR_MODE_IDLE;
228 return REGULATOR_MODE_NORMAL;
232 static struct regulator_ops wm831x_gp_ldo_ops = {
233 .list_voltage = wm831x_gp_ldo_list_voltage,
234 .map_voltage = wm831x_gp_ldo_map_voltage,
235 .get_voltage_sel = regulator_get_voltage_sel_regmap,
236 .set_voltage_sel = regulator_set_voltage_sel_regmap,
237 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
238 .get_mode = wm831x_gp_ldo_get_mode,
239 .set_mode = wm831x_gp_ldo_set_mode,
240 .get_status = wm831x_gp_ldo_get_status,
241 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode,
242 .get_bypass = regulator_get_bypass_regmap,
243 .set_bypass = regulator_set_bypass_regmap,
245 .is_enabled = regulator_is_enabled_regmap,
246 .enable = regulator_enable_regmap,
247 .disable = regulator_disable_regmap,
250 static int wm831x_gp_ldo_probe(struct platform_device *pdev)
252 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
253 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
254 struct regulator_config config = { };
255 int id;
256 struct wm831x_ldo *ldo;
257 struct resource *res;
258 int ret, irq;
260 if (pdata && pdata->wm831x_num)
261 id = (pdata->wm831x_num * 10) + 1;
262 else
263 id = 0;
264 id = pdev->id - id;
266 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
268 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
269 if (ldo == NULL) {
270 dev_err(&pdev->dev, "Unable to allocate private data\n");
271 return -ENOMEM;
274 ldo->wm831x = wm831x;
276 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
277 if (res == NULL) {
278 dev_err(&pdev->dev, "No REG resource\n");
279 ret = -EINVAL;
280 goto err;
282 ldo->base = res->start;
284 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
285 ldo->desc.name = ldo->name;
287 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
288 "LDO%dVDD", id + 1);
289 ldo->desc.supply_name = ldo->supply_name;
291 ldo->desc.id = id;
292 ldo->desc.type = REGULATOR_VOLTAGE;
293 ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1;
294 ldo->desc.ops = &wm831x_gp_ldo_ops;
295 ldo->desc.owner = THIS_MODULE;
296 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
297 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK;
298 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
299 ldo->desc.enable_mask = 1 << id;
300 ldo->desc.bypass_reg = ldo->base;
301 ldo->desc.bypass_mask = WM831X_LDO1_SWI;
303 config.dev = pdev->dev.parent;
304 if (pdata)
305 config.init_data = pdata->ldo[id];
306 config.driver_data = ldo;
307 config.regmap = wm831x->regmap;
309 ldo->regulator = regulator_register(&ldo->desc, &config);
310 if (IS_ERR(ldo->regulator)) {
311 ret = PTR_ERR(ldo->regulator);
312 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
313 id + 1, ret);
314 goto err;
317 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
318 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq,
319 IRQF_TRIGGER_RISING, ldo->name,
320 ldo);
321 if (ret != 0) {
322 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
323 irq, ret);
324 goto err_regulator;
327 platform_set_drvdata(pdev, ldo);
329 return 0;
331 err_regulator:
332 regulator_unregister(ldo->regulator);
333 err:
334 return ret;
337 static int wm831x_gp_ldo_remove(struct platform_device *pdev)
339 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
341 free_irq(wm831x_irq(ldo->wm831x,
342 platform_get_irq_byname(pdev, "UV")), ldo);
343 regulator_unregister(ldo->regulator);
345 return 0;
348 static struct platform_driver wm831x_gp_ldo_driver = {
349 .probe = wm831x_gp_ldo_probe,
350 .remove = wm831x_gp_ldo_remove,
351 .driver = {
352 .name = "wm831x-ldo",
353 .owner = THIS_MODULE,
358 * Analogue LDOs
362 #define WM831X_ALDO_SELECTOR_LOW 0xc
363 #define WM831X_ALDO_MAX_SELECTOR 0x1f
365 static int wm831x_aldo_list_voltage(struct regulator_dev *rdev,
366 unsigned int selector)
368 /* 1-1.6V in 50mV steps */
369 if (selector <= WM831X_ALDO_SELECTOR_LOW)
370 return 1000000 + (selector * 50000);
371 /* 1.7-3.5V in 100mV steps */
372 if (selector <= WM831X_ALDO_MAX_SELECTOR)
373 return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW)
374 * 100000);
375 return -EINVAL;
378 static int wm831x_aldo_map_voltage(struct regulator_dev *rdev,
379 int min_uV, int max_uV)
381 int volt, vsel;
383 if (min_uV < 1000000)
384 vsel = 0;
385 else if (min_uV < 1700000)
386 vsel = ((min_uV - 1000000) / 50000);
387 else
388 vsel = ((min_uV - 1700000) / 100000)
389 + WM831X_ALDO_SELECTOR_LOW + 1;
391 volt = wm831x_aldo_list_voltage(rdev, vsel);
392 if (volt < min_uV || volt > max_uV)
393 return -EINVAL;
395 return vsel;
399 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
400 int uV)
402 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
403 struct wm831x *wm831x = ldo->wm831x;
404 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
406 sel = wm831x_aldo_map_voltage(rdev, uV, uV);
407 if (sel < 0)
408 return sel;
410 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel);
413 static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
415 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
416 struct wm831x *wm831x = ldo->wm831x;
417 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
418 int ret;
420 ret = wm831x_reg_read(wm831x, on_reg);
421 if (ret < 0)
422 return 0;
424 if (ret & WM831X_LDO7_ON_MODE)
425 return REGULATOR_MODE_IDLE;
426 else
427 return REGULATOR_MODE_NORMAL;
430 static int wm831x_aldo_set_mode(struct regulator_dev *rdev,
431 unsigned int mode)
433 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
434 struct wm831x *wm831x = ldo->wm831x;
435 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
436 int ret;
439 switch (mode) {
440 case REGULATOR_MODE_NORMAL:
441 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0);
442 if (ret < 0)
443 return ret;
444 break;
446 case REGULATOR_MODE_IDLE:
447 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE,
448 WM831X_LDO7_ON_MODE);
449 if (ret < 0)
450 return ret;
451 break;
453 default:
454 return -EINVAL;
457 return 0;
460 static int wm831x_aldo_get_status(struct regulator_dev *rdev)
462 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
463 struct wm831x *wm831x = ldo->wm831x;
464 int mask = 1 << rdev_get_id(rdev);
465 int ret;
467 /* Is the regulator on? */
468 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
469 if (ret < 0)
470 return ret;
471 if (!(ret & mask))
472 return REGULATOR_STATUS_OFF;
474 /* Is it reporting under voltage? */
475 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
476 if (ret < 0)
477 return ret;
478 if (ret & mask)
479 return REGULATOR_STATUS_ERROR;
481 ret = wm831x_aldo_get_mode(rdev);
482 if (ret < 0)
483 return ret;
484 else
485 return regulator_mode_to_status(ret);
488 static struct regulator_ops wm831x_aldo_ops = {
489 .list_voltage = wm831x_aldo_list_voltage,
490 .map_voltage = wm831x_aldo_map_voltage,
491 .get_voltage_sel = regulator_get_voltage_sel_regmap,
492 .set_voltage_sel = regulator_set_voltage_sel_regmap,
493 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
494 .get_mode = wm831x_aldo_get_mode,
495 .set_mode = wm831x_aldo_set_mode,
496 .get_status = wm831x_aldo_get_status,
497 .set_bypass = regulator_set_bypass_regmap,
498 .get_bypass = regulator_get_bypass_regmap,
500 .is_enabled = regulator_is_enabled_regmap,
501 .enable = regulator_enable_regmap,
502 .disable = regulator_disable_regmap,
505 static int wm831x_aldo_probe(struct platform_device *pdev)
507 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
508 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
509 struct regulator_config config = { };
510 int id;
511 struct wm831x_ldo *ldo;
512 struct resource *res;
513 int ret, irq;
515 if (pdata && pdata->wm831x_num)
516 id = (pdata->wm831x_num * 10) + 1;
517 else
518 id = 0;
519 id = pdev->id - id;
521 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
523 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
524 if (ldo == NULL) {
525 dev_err(&pdev->dev, "Unable to allocate private data\n");
526 return -ENOMEM;
529 ldo->wm831x = wm831x;
531 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
532 if (res == NULL) {
533 dev_err(&pdev->dev, "No REG resource\n");
534 ret = -EINVAL;
535 goto err;
537 ldo->base = res->start;
539 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
540 ldo->desc.name = ldo->name;
542 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
543 "LDO%dVDD", id + 1);
544 ldo->desc.supply_name = ldo->supply_name;
546 ldo->desc.id = id;
547 ldo->desc.type = REGULATOR_VOLTAGE;
548 ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1;
549 ldo->desc.ops = &wm831x_aldo_ops;
550 ldo->desc.owner = THIS_MODULE;
551 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
552 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK;
553 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
554 ldo->desc.enable_mask = 1 << id;
555 ldo->desc.bypass_reg = ldo->base;
556 ldo->desc.bypass_mask = WM831X_LDO7_SWI;
558 config.dev = pdev->dev.parent;
559 if (pdata)
560 config.init_data = pdata->ldo[id];
561 config.driver_data = ldo;
562 config.regmap = wm831x->regmap;
564 ldo->regulator = regulator_register(&ldo->desc, &config);
565 if (IS_ERR(ldo->regulator)) {
566 ret = PTR_ERR(ldo->regulator);
567 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
568 id + 1, ret);
569 goto err;
572 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
573 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq,
574 IRQF_TRIGGER_RISING, ldo->name, ldo);
575 if (ret != 0) {
576 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
577 irq, ret);
578 goto err_regulator;
581 platform_set_drvdata(pdev, ldo);
583 return 0;
585 err_regulator:
586 regulator_unregister(ldo->regulator);
587 err:
588 return ret;
591 static int wm831x_aldo_remove(struct platform_device *pdev)
593 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
595 free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")),
596 ldo);
597 regulator_unregister(ldo->regulator);
599 return 0;
602 static struct platform_driver wm831x_aldo_driver = {
603 .probe = wm831x_aldo_probe,
604 .remove = wm831x_aldo_remove,
605 .driver = {
606 .name = "wm831x-aldo",
607 .owner = THIS_MODULE,
612 * Alive LDO
615 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
617 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
618 int uV)
620 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
621 struct wm831x *wm831x = ldo->wm831x;
622 int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
624 sel = regulator_map_voltage_linear(rdev, uV, uV);
625 if (sel < 0)
626 return sel;
628 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel);
631 static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
633 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
634 struct wm831x *wm831x = ldo->wm831x;
635 int mask = 1 << rdev_get_id(rdev);
636 int ret;
638 /* Is the regulator on? */
639 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
640 if (ret < 0)
641 return ret;
642 if (ret & mask)
643 return REGULATOR_STATUS_ON;
644 else
645 return REGULATOR_STATUS_OFF;
648 static struct regulator_ops wm831x_alive_ldo_ops = {
649 .list_voltage = regulator_list_voltage_linear,
650 .map_voltage = regulator_map_voltage_linear,
651 .get_voltage_sel = regulator_get_voltage_sel_regmap,
652 .set_voltage_sel = regulator_set_voltage_sel_regmap,
653 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
654 .get_status = wm831x_alive_ldo_get_status,
656 .is_enabled = regulator_is_enabled_regmap,
657 .enable = regulator_enable_regmap,
658 .disable = regulator_disable_regmap,
661 static int wm831x_alive_ldo_probe(struct platform_device *pdev)
663 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
664 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
665 struct regulator_config config = { };
666 int id;
667 struct wm831x_ldo *ldo;
668 struct resource *res;
669 int ret;
671 if (pdata && pdata->wm831x_num)
672 id = (pdata->wm831x_num * 10) + 1;
673 else
674 id = 0;
675 id = pdev->id - id;
678 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
680 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
681 if (ldo == NULL) {
682 dev_err(&pdev->dev, "Unable to allocate private data\n");
683 return -ENOMEM;
686 ldo->wm831x = wm831x;
688 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
689 if (res == NULL) {
690 dev_err(&pdev->dev, "No REG resource\n");
691 ret = -EINVAL;
692 goto err;
694 ldo->base = res->start;
696 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
697 ldo->desc.name = ldo->name;
699 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
700 "LDO%dVDD", id + 1);
701 ldo->desc.supply_name = ldo->supply_name;
703 ldo->desc.id = id;
704 ldo->desc.type = REGULATOR_VOLTAGE;
705 ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1;
706 ldo->desc.ops = &wm831x_alive_ldo_ops;
707 ldo->desc.owner = THIS_MODULE;
708 ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
709 ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK;
710 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
711 ldo->desc.enable_mask = 1 << id;
712 ldo->desc.min_uV = 800000;
713 ldo->desc.uV_step = 50000;
714 ldo->desc.enable_time = 1000;
716 config.dev = pdev->dev.parent;
717 if (pdata)
718 config.init_data = pdata->ldo[id];
719 config.driver_data = ldo;
720 config.regmap = wm831x->regmap;
722 ldo->regulator = regulator_register(&ldo->desc, &config);
723 if (IS_ERR(ldo->regulator)) {
724 ret = PTR_ERR(ldo->regulator);
725 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
726 id + 1, ret);
727 goto err;
730 platform_set_drvdata(pdev, ldo);
732 return 0;
734 err:
735 return ret;
738 static int wm831x_alive_ldo_remove(struct platform_device *pdev)
740 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
742 regulator_unregister(ldo->regulator);
744 return 0;
747 static struct platform_driver wm831x_alive_ldo_driver = {
748 .probe = wm831x_alive_ldo_probe,
749 .remove = wm831x_alive_ldo_remove,
750 .driver = {
751 .name = "wm831x-alive-ldo",
752 .owner = THIS_MODULE,
756 static int __init wm831x_ldo_init(void)
758 int ret;
760 ret = platform_driver_register(&wm831x_gp_ldo_driver);
761 if (ret != 0)
762 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret);
764 ret = platform_driver_register(&wm831x_aldo_driver);
765 if (ret != 0)
766 pr_err("Failed to register WM831x ALDO driver: %d\n", ret);
768 ret = platform_driver_register(&wm831x_alive_ldo_driver);
769 if (ret != 0)
770 pr_err("Failed to register WM831x alive LDO driver: %d\n",
771 ret);
773 return 0;
775 subsys_initcall(wm831x_ldo_init);
777 static void __exit wm831x_ldo_exit(void)
779 platform_driver_unregister(&wm831x_alive_ldo_driver);
780 platform_driver_unregister(&wm831x_aldo_driver);
781 platform_driver_unregister(&wm831x_gp_ldo_driver);
783 module_exit(wm831x_ldo_exit);
785 /* Module information */
786 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
787 MODULE_DESCRIPTION("WM831x LDO driver");
788 MODULE_LICENSE("GPL");
789 MODULE_ALIAS("platform:wm831x-ldo");
790 MODULE_ALIAS("platform:wm831x-aldo");
791 MODULE_ALIAS("platform:wm831x-aliveldo");