mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / regulator / wm831x-ldo.c
blob2205fbc2c37b4cf9b917bafa5d1f583f7e767b49
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 static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = {
66 { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14,
67 .uV_step = 50000 },
68 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31,
69 .uV_step = 100000 },
72 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
73 int uV)
75 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
76 struct wm831x *wm831x = ldo->wm831x;
77 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
79 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
80 if (sel < 0)
81 return sel;
83 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel);
86 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
88 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
89 struct wm831x *wm831x = ldo->wm831x;
90 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
91 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
92 int ret;
94 ret = wm831x_reg_read(wm831x, on_reg);
95 if (ret < 0)
96 return ret;
98 if (!(ret & WM831X_LDO1_ON_MODE))
99 return REGULATOR_MODE_NORMAL;
101 ret = wm831x_reg_read(wm831x, ctrl_reg);
102 if (ret < 0)
103 return ret;
105 if (ret & WM831X_LDO1_LP_MODE)
106 return REGULATOR_MODE_STANDBY;
107 else
108 return REGULATOR_MODE_IDLE;
111 static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev,
112 unsigned int mode)
114 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
115 struct wm831x *wm831x = ldo->wm831x;
116 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
117 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
118 int ret;
121 switch (mode) {
122 case REGULATOR_MODE_NORMAL:
123 ret = wm831x_set_bits(wm831x, on_reg,
124 WM831X_LDO1_ON_MODE, 0);
125 if (ret < 0)
126 return ret;
127 break;
129 case REGULATOR_MODE_IDLE:
130 ret = wm831x_set_bits(wm831x, ctrl_reg,
131 WM831X_LDO1_LP_MODE, 0);
132 if (ret < 0)
133 return ret;
135 ret = wm831x_set_bits(wm831x, on_reg,
136 WM831X_LDO1_ON_MODE,
137 WM831X_LDO1_ON_MODE);
138 if (ret < 0)
139 return ret;
140 break;
142 case REGULATOR_MODE_STANDBY:
143 ret = wm831x_set_bits(wm831x, ctrl_reg,
144 WM831X_LDO1_LP_MODE,
145 WM831X_LDO1_LP_MODE);
146 if (ret < 0)
147 return ret;
149 ret = wm831x_set_bits(wm831x, on_reg,
150 WM831X_LDO1_ON_MODE,
151 WM831X_LDO1_ON_MODE);
152 if (ret < 0)
153 return ret;
154 break;
156 default:
157 return -EINVAL;
160 return 0;
163 static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev)
165 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
166 struct wm831x *wm831x = ldo->wm831x;
167 int mask = 1 << rdev_get_id(rdev);
168 int ret;
170 /* Is the regulator on? */
171 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
172 if (ret < 0)
173 return ret;
174 if (!(ret & mask))
175 return REGULATOR_STATUS_OFF;
177 /* Is it reporting under voltage? */
178 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
179 if (ret < 0)
180 return ret;
181 if (ret & mask)
182 return REGULATOR_STATUS_ERROR;
184 ret = wm831x_gp_ldo_get_mode(rdev);
185 if (ret < 0)
186 return ret;
187 else
188 return regulator_mode_to_status(ret);
191 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
192 int input_uV,
193 int output_uV, int load_uA)
195 if (load_uA < 20000)
196 return REGULATOR_MODE_STANDBY;
197 if (load_uA < 50000)
198 return REGULATOR_MODE_IDLE;
199 return REGULATOR_MODE_NORMAL;
203 static struct regulator_ops wm831x_gp_ldo_ops = {
204 .list_voltage = regulator_list_voltage_linear_range,
205 .map_voltage = regulator_map_voltage_linear_range,
206 .get_voltage_sel = regulator_get_voltage_sel_regmap,
207 .set_voltage_sel = regulator_set_voltage_sel_regmap,
208 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
209 .get_mode = wm831x_gp_ldo_get_mode,
210 .set_mode = wm831x_gp_ldo_set_mode,
211 .get_status = wm831x_gp_ldo_get_status,
212 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode,
213 .get_bypass = regulator_get_bypass_regmap,
214 .set_bypass = regulator_set_bypass_regmap,
216 .is_enabled = regulator_is_enabled_regmap,
217 .enable = regulator_enable_regmap,
218 .disable = regulator_disable_regmap,
221 static int wm831x_gp_ldo_probe(struct platform_device *pdev)
223 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
224 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
225 struct regulator_config config = { };
226 int id;
227 struct wm831x_ldo *ldo;
228 struct resource *res;
229 int ret, irq;
231 if (pdata && pdata->wm831x_num)
232 id = (pdata->wm831x_num * 10) + 1;
233 else
234 id = 0;
235 id = pdev->id - id;
237 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
239 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
240 if (ldo == NULL) {
241 dev_err(&pdev->dev, "Unable to allocate private data\n");
242 return -ENOMEM;
245 ldo->wm831x = wm831x;
247 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
248 if (res == NULL) {
249 dev_err(&pdev->dev, "No REG resource\n");
250 ret = -EINVAL;
251 goto err;
253 ldo->base = res->start;
255 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
256 ldo->desc.name = ldo->name;
258 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
259 "LDO%dVDD", id + 1);
260 ldo->desc.supply_name = ldo->supply_name;
262 ldo->desc.id = id;
263 ldo->desc.type = REGULATOR_VOLTAGE;
264 ldo->desc.n_voltages = 32;
265 ldo->desc.ops = &wm831x_gp_ldo_ops;
266 ldo->desc.owner = THIS_MODULE;
267 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
268 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK;
269 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
270 ldo->desc.enable_mask = 1 << id;
271 ldo->desc.bypass_reg = ldo->base;
272 ldo->desc.bypass_mask = WM831X_LDO1_SWI;
273 ldo->desc.linear_ranges = wm831x_gp_ldo_ranges;
274 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_gp_ldo_ranges);
276 config.dev = pdev->dev.parent;
277 if (pdata)
278 config.init_data = pdata->ldo[id];
279 config.driver_data = ldo;
280 config.regmap = wm831x->regmap;
282 ldo->regulator = regulator_register(&ldo->desc, &config);
283 if (IS_ERR(ldo->regulator)) {
284 ret = PTR_ERR(ldo->regulator);
285 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
286 id + 1, ret);
287 goto err;
290 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
291 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq,
292 IRQF_TRIGGER_RISING, ldo->name,
293 ldo);
294 if (ret != 0) {
295 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
296 irq, ret);
297 goto err_regulator;
300 platform_set_drvdata(pdev, ldo);
302 return 0;
304 err_regulator:
305 regulator_unregister(ldo->regulator);
306 err:
307 return ret;
310 static int wm831x_gp_ldo_remove(struct platform_device *pdev)
312 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
314 free_irq(wm831x_irq(ldo->wm831x,
315 platform_get_irq_byname(pdev, "UV")), ldo);
316 regulator_unregister(ldo->regulator);
318 return 0;
321 static struct platform_driver wm831x_gp_ldo_driver = {
322 .probe = wm831x_gp_ldo_probe,
323 .remove = wm831x_gp_ldo_remove,
324 .driver = {
325 .name = "wm831x-ldo",
326 .owner = THIS_MODULE,
331 * Analogue LDOs
334 static const struct regulator_linear_range wm831x_aldo_ranges[] = {
335 { .min_uV = 1000000, .max_uV = 1600000, .min_sel = 0, .max_sel = 12,
336 .uV_step = 50000 },
337 { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31,
338 .uV_step = 100000 },
341 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
342 int uV)
344 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
345 struct wm831x *wm831x = ldo->wm831x;
346 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
348 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
349 if (sel < 0)
350 return sel;
352 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel);
355 static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
357 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
358 struct wm831x *wm831x = ldo->wm831x;
359 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
360 int ret;
362 ret = wm831x_reg_read(wm831x, on_reg);
363 if (ret < 0)
364 return 0;
366 if (ret & WM831X_LDO7_ON_MODE)
367 return REGULATOR_MODE_IDLE;
368 else
369 return REGULATOR_MODE_NORMAL;
372 static int wm831x_aldo_set_mode(struct regulator_dev *rdev,
373 unsigned int mode)
375 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
376 struct wm831x *wm831x = ldo->wm831x;
377 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
378 int ret;
381 switch (mode) {
382 case REGULATOR_MODE_NORMAL:
383 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0);
384 if (ret < 0)
385 return ret;
386 break;
388 case REGULATOR_MODE_IDLE:
389 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE,
390 WM831X_LDO7_ON_MODE);
391 if (ret < 0)
392 return ret;
393 break;
395 default:
396 return -EINVAL;
399 return 0;
402 static int wm831x_aldo_get_status(struct regulator_dev *rdev)
404 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
405 struct wm831x *wm831x = ldo->wm831x;
406 int mask = 1 << rdev_get_id(rdev);
407 int ret;
409 /* Is the regulator on? */
410 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
411 if (ret < 0)
412 return ret;
413 if (!(ret & mask))
414 return REGULATOR_STATUS_OFF;
416 /* Is it reporting under voltage? */
417 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
418 if (ret < 0)
419 return ret;
420 if (ret & mask)
421 return REGULATOR_STATUS_ERROR;
423 ret = wm831x_aldo_get_mode(rdev);
424 if (ret < 0)
425 return ret;
426 else
427 return regulator_mode_to_status(ret);
430 static struct regulator_ops wm831x_aldo_ops = {
431 .list_voltage = regulator_list_voltage_linear_range,
432 .map_voltage = regulator_map_voltage_linear_range,
433 .get_voltage_sel = regulator_get_voltage_sel_regmap,
434 .set_voltage_sel = regulator_set_voltage_sel_regmap,
435 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
436 .get_mode = wm831x_aldo_get_mode,
437 .set_mode = wm831x_aldo_set_mode,
438 .get_status = wm831x_aldo_get_status,
439 .set_bypass = regulator_set_bypass_regmap,
440 .get_bypass = regulator_get_bypass_regmap,
442 .is_enabled = regulator_is_enabled_regmap,
443 .enable = regulator_enable_regmap,
444 .disable = regulator_disable_regmap,
447 static int wm831x_aldo_probe(struct platform_device *pdev)
449 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
450 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
451 struct regulator_config config = { };
452 int id;
453 struct wm831x_ldo *ldo;
454 struct resource *res;
455 int ret, irq;
457 if (pdata && pdata->wm831x_num)
458 id = (pdata->wm831x_num * 10) + 1;
459 else
460 id = 0;
461 id = pdev->id - id;
463 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
465 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
466 if (ldo == NULL) {
467 dev_err(&pdev->dev, "Unable to allocate private data\n");
468 return -ENOMEM;
471 ldo->wm831x = wm831x;
473 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
474 if (res == NULL) {
475 dev_err(&pdev->dev, "No REG resource\n");
476 ret = -EINVAL;
477 goto err;
479 ldo->base = res->start;
481 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
482 ldo->desc.name = ldo->name;
484 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
485 "LDO%dVDD", id + 1);
486 ldo->desc.supply_name = ldo->supply_name;
488 ldo->desc.id = id;
489 ldo->desc.type = REGULATOR_VOLTAGE;
490 ldo->desc.n_voltages = 32;
491 ldo->desc.linear_ranges = wm831x_aldo_ranges;
492 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_aldo_ranges);
493 ldo->desc.ops = &wm831x_aldo_ops;
494 ldo->desc.owner = THIS_MODULE;
495 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
496 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK;
497 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
498 ldo->desc.enable_mask = 1 << id;
499 ldo->desc.bypass_reg = ldo->base;
500 ldo->desc.bypass_mask = WM831X_LDO7_SWI;
502 config.dev = pdev->dev.parent;
503 if (pdata)
504 config.init_data = pdata->ldo[id];
505 config.driver_data = ldo;
506 config.regmap = wm831x->regmap;
508 ldo->regulator = regulator_register(&ldo->desc, &config);
509 if (IS_ERR(ldo->regulator)) {
510 ret = PTR_ERR(ldo->regulator);
511 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
512 id + 1, ret);
513 goto err;
516 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
517 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq,
518 IRQF_TRIGGER_RISING, ldo->name, ldo);
519 if (ret != 0) {
520 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
521 irq, ret);
522 goto err_regulator;
525 platform_set_drvdata(pdev, ldo);
527 return 0;
529 err_regulator:
530 regulator_unregister(ldo->regulator);
531 err:
532 return ret;
535 static int wm831x_aldo_remove(struct platform_device *pdev)
537 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
539 free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")),
540 ldo);
541 regulator_unregister(ldo->regulator);
543 return 0;
546 static struct platform_driver wm831x_aldo_driver = {
547 .probe = wm831x_aldo_probe,
548 .remove = wm831x_aldo_remove,
549 .driver = {
550 .name = "wm831x-aldo",
551 .owner = THIS_MODULE,
556 * Alive LDO
559 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
561 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
562 int uV)
564 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
565 struct wm831x *wm831x = ldo->wm831x;
566 int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
568 sel = regulator_map_voltage_linear(rdev, uV, uV);
569 if (sel < 0)
570 return sel;
572 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel);
575 static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
577 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
578 struct wm831x *wm831x = ldo->wm831x;
579 int mask = 1 << rdev_get_id(rdev);
580 int ret;
582 /* Is the regulator on? */
583 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
584 if (ret < 0)
585 return ret;
586 if (ret & mask)
587 return REGULATOR_STATUS_ON;
588 else
589 return REGULATOR_STATUS_OFF;
592 static struct regulator_ops wm831x_alive_ldo_ops = {
593 .list_voltage = regulator_list_voltage_linear,
594 .map_voltage = regulator_map_voltage_linear,
595 .get_voltage_sel = regulator_get_voltage_sel_regmap,
596 .set_voltage_sel = regulator_set_voltage_sel_regmap,
597 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
598 .get_status = wm831x_alive_ldo_get_status,
600 .is_enabled = regulator_is_enabled_regmap,
601 .enable = regulator_enable_regmap,
602 .disable = regulator_disable_regmap,
605 static int wm831x_alive_ldo_probe(struct platform_device *pdev)
607 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
608 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
609 struct regulator_config config = { };
610 int id;
611 struct wm831x_ldo *ldo;
612 struct resource *res;
613 int ret;
615 if (pdata && pdata->wm831x_num)
616 id = (pdata->wm831x_num * 10) + 1;
617 else
618 id = 0;
619 id = pdev->id - id;
622 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
624 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
625 if (ldo == NULL) {
626 dev_err(&pdev->dev, "Unable to allocate private data\n");
627 return -ENOMEM;
630 ldo->wm831x = wm831x;
632 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
633 if (res == NULL) {
634 dev_err(&pdev->dev, "No REG resource\n");
635 ret = -EINVAL;
636 goto err;
638 ldo->base = res->start;
640 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
641 ldo->desc.name = ldo->name;
643 snprintf(ldo->supply_name, sizeof(ldo->supply_name),
644 "LDO%dVDD", id + 1);
645 ldo->desc.supply_name = ldo->supply_name;
647 ldo->desc.id = id;
648 ldo->desc.type = REGULATOR_VOLTAGE;
649 ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1;
650 ldo->desc.ops = &wm831x_alive_ldo_ops;
651 ldo->desc.owner = THIS_MODULE;
652 ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
653 ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK;
654 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
655 ldo->desc.enable_mask = 1 << id;
656 ldo->desc.min_uV = 800000;
657 ldo->desc.uV_step = 50000;
658 ldo->desc.enable_time = 1000;
660 config.dev = pdev->dev.parent;
661 if (pdata)
662 config.init_data = pdata->ldo[id];
663 config.driver_data = ldo;
664 config.regmap = wm831x->regmap;
666 ldo->regulator = regulator_register(&ldo->desc, &config);
667 if (IS_ERR(ldo->regulator)) {
668 ret = PTR_ERR(ldo->regulator);
669 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
670 id + 1, ret);
671 goto err;
674 platform_set_drvdata(pdev, ldo);
676 return 0;
678 err:
679 return ret;
682 static int wm831x_alive_ldo_remove(struct platform_device *pdev)
684 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
686 regulator_unregister(ldo->regulator);
688 return 0;
691 static struct platform_driver wm831x_alive_ldo_driver = {
692 .probe = wm831x_alive_ldo_probe,
693 .remove = wm831x_alive_ldo_remove,
694 .driver = {
695 .name = "wm831x-alive-ldo",
696 .owner = THIS_MODULE,
700 static int __init wm831x_ldo_init(void)
702 int ret;
704 ret = platform_driver_register(&wm831x_gp_ldo_driver);
705 if (ret != 0)
706 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret);
708 ret = platform_driver_register(&wm831x_aldo_driver);
709 if (ret != 0)
710 pr_err("Failed to register WM831x ALDO driver: %d\n", ret);
712 ret = platform_driver_register(&wm831x_alive_ldo_driver);
713 if (ret != 0)
714 pr_err("Failed to register WM831x alive LDO driver: %d\n",
715 ret);
717 return 0;
719 subsys_initcall(wm831x_ldo_init);
721 static void __exit wm831x_ldo_exit(void)
723 platform_driver_unregister(&wm831x_alive_ldo_driver);
724 platform_driver_unregister(&wm831x_aldo_driver);
725 platform_driver_unregister(&wm831x_gp_ldo_driver);
727 module_exit(wm831x_ldo_exit);
729 /* Module information */
730 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
731 MODULE_DESCRIPTION("WM831x LDO driver");
732 MODULE_LICENSE("GPL");
733 MODULE_ALIAS("platform:wm831x-ldo");
734 MODULE_ALIAS("platform:wm831x-aldo");
735 MODULE_ALIAS("platform:wm831x-aliveldo");