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 6
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
38 char name
[WM831X_LDO_MAX_NAME
];
39 struct regulator_desc desc
;
41 struct wm831x
*wm831x
;
42 struct regulator_dev
*regulator
;
49 static int wm831x_ldo_is_enabled(struct regulator_dev
*rdev
)
51 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
52 struct wm831x
*wm831x
= ldo
->wm831x
;
53 int mask
= 1 << rdev_get_id(rdev
);
56 reg
= wm831x_reg_read(wm831x
, WM831X_LDO_ENABLE
);
66 static int wm831x_ldo_enable(struct regulator_dev
*rdev
)
68 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
69 struct wm831x
*wm831x
= ldo
->wm831x
;
70 int mask
= 1 << rdev_get_id(rdev
);
72 return wm831x_set_bits(wm831x
, WM831X_LDO_ENABLE
, mask
, mask
);
75 static int wm831x_ldo_disable(struct regulator_dev
*rdev
)
77 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
78 struct wm831x
*wm831x
= ldo
->wm831x
;
79 int mask
= 1 << rdev_get_id(rdev
);
81 return wm831x_set_bits(wm831x
, WM831X_LDO_ENABLE
, mask
, 0);
84 static irqreturn_t
wm831x_ldo_uv_irq(int irq
, void *data
)
86 struct wm831x_ldo
*ldo
= data
;
88 regulator_notifier_call_chain(ldo
->regulator
,
89 REGULATOR_EVENT_UNDER_VOLTAGE
,
96 * General purpose LDOs
99 #define WM831X_GP_LDO_SELECTOR_LOW 0xe
100 #define WM831X_GP_LDO_MAX_SELECTOR 0x1f
102 static int wm831x_gp_ldo_list_voltage(struct regulator_dev
*rdev
,
103 unsigned int selector
)
105 /* 0.9-1.6V in 50mV steps */
106 if (selector
<= WM831X_GP_LDO_SELECTOR_LOW
)
107 return 900000 + (selector
* 50000);
108 /* 1.7-3.3V in 50mV steps */
109 if (selector
<= WM831X_GP_LDO_MAX_SELECTOR
)
110 return 1600000 + ((selector
- WM831X_GP_LDO_SELECTOR_LOW
)
115 static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
116 int min_uV
, int max_uV
)
118 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
119 struct wm831x
*wm831x
= ldo
->wm831x
;
124 else if (min_uV
< 1700000)
125 vsel
= ((min_uV
- 900000) / 50000);
127 vsel
= ((min_uV
- 1700000) / 100000)
128 + WM831X_GP_LDO_SELECTOR_LOW
+ 1;
130 ret
= wm831x_gp_ldo_list_voltage(rdev
, vsel
);
133 if (ret
< min_uV
|| ret
> max_uV
)
136 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO1_ON_VSEL_MASK
, vsel
);
139 static int wm831x_gp_ldo_set_voltage(struct regulator_dev
*rdev
,
140 int min_uV
, int max_uV
)
142 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
143 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
145 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
148 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
151 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
152 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
154 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
157 static int wm831x_gp_ldo_get_voltage(struct regulator_dev
*rdev
)
159 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
160 struct wm831x
*wm831x
= ldo
->wm831x
;
161 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
164 ret
= wm831x_reg_read(wm831x
, reg
);
168 ret
&= WM831X_LDO1_ON_VSEL_MASK
;
170 return wm831x_gp_ldo_list_voltage(rdev
, ret
);
173 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev
*rdev
)
175 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
176 struct wm831x
*wm831x
= ldo
->wm831x
;
177 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
178 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
181 ret
= wm831x_reg_read(wm831x
, on_reg
);
185 if (!(ret
& WM831X_LDO1_ON_MODE
))
186 return REGULATOR_MODE_NORMAL
;
188 ret
= wm831x_reg_read(wm831x
, ctrl_reg
);
192 if (ret
& WM831X_LDO1_LP_MODE
)
193 return REGULATOR_MODE_STANDBY
;
195 return REGULATOR_MODE_IDLE
;
198 static int wm831x_gp_ldo_set_mode(struct regulator_dev
*rdev
,
201 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
202 struct wm831x
*wm831x
= ldo
->wm831x
;
203 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
204 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
209 case REGULATOR_MODE_NORMAL
:
210 ret
= wm831x_set_bits(wm831x
, on_reg
,
211 WM831X_LDO1_ON_MODE
, 0);
216 case REGULATOR_MODE_IDLE
:
217 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
218 WM831X_LDO1_LP_MODE
, 0);
222 ret
= wm831x_set_bits(wm831x
, on_reg
,
224 WM831X_LDO1_ON_MODE
);
229 case REGULATOR_MODE_STANDBY
:
230 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
232 WM831X_LDO1_LP_MODE
);
236 ret
= wm831x_set_bits(wm831x
, on_reg
,
238 WM831X_LDO1_ON_MODE
);
250 static int wm831x_gp_ldo_get_status(struct regulator_dev
*rdev
)
252 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
253 struct wm831x
*wm831x
= ldo
->wm831x
;
254 int mask
= 1 << rdev_get_id(rdev
);
257 /* Is the regulator on? */
258 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
262 return REGULATOR_STATUS_OFF
;
264 /* Is it reporting under voltage? */
265 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
267 return REGULATOR_STATUS_ERROR
;
269 ret
= wm831x_gp_ldo_get_mode(rdev
);
273 return regulator_mode_to_status(ret
);
276 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev
*rdev
,
278 int output_uV
, int load_uA
)
281 return REGULATOR_MODE_STANDBY
;
283 return REGULATOR_MODE_IDLE
;
284 return REGULATOR_MODE_NORMAL
;
288 static struct regulator_ops wm831x_gp_ldo_ops
= {
289 .list_voltage
= wm831x_gp_ldo_list_voltage
,
290 .get_voltage
= wm831x_gp_ldo_get_voltage
,
291 .set_voltage
= wm831x_gp_ldo_set_voltage
,
292 .set_suspend_voltage
= wm831x_gp_ldo_set_suspend_voltage
,
293 .get_mode
= wm831x_gp_ldo_get_mode
,
294 .set_mode
= wm831x_gp_ldo_set_mode
,
295 .get_status
= wm831x_gp_ldo_get_status
,
296 .get_optimum_mode
= wm831x_gp_ldo_get_optimum_mode
,
298 .is_enabled
= wm831x_ldo_is_enabled
,
299 .enable
= wm831x_ldo_enable
,
300 .disable
= wm831x_ldo_disable
,
303 static __devinit
int wm831x_gp_ldo_probe(struct platform_device
*pdev
)
305 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
306 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
307 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
308 struct wm831x_ldo
*ldo
;
309 struct resource
*res
;
312 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
314 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
317 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
319 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
323 ldo
->wm831x
= wm831x
;
325 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
327 dev_err(&pdev
->dev
, "No I/O resource\n");
331 ldo
->base
= res
->start
;
333 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
334 ldo
->desc
.name
= ldo
->name
;
336 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
337 ldo
->desc
.n_voltages
= WM831X_GP_LDO_MAX_SELECTOR
+ 1;
338 ldo
->desc
.ops
= &wm831x_gp_ldo_ops
;
339 ldo
->desc
.owner
= THIS_MODULE
;
341 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
342 pdata
->ldo
[id
], ldo
);
343 if (IS_ERR(ldo
->regulator
)) {
344 ret
= PTR_ERR(ldo
->regulator
);
345 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
350 irq
= platform_get_irq_byname(pdev
, "UV");
351 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
352 IRQF_TRIGGER_RISING
, ldo
->name
,
355 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
360 platform_set_drvdata(pdev
, ldo
);
365 regulator_unregister(ldo
->regulator
);
371 static __devexit
int wm831x_gp_ldo_remove(struct platform_device
*pdev
)
373 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
374 struct wm831x
*wm831x
= ldo
->wm831x
;
376 platform_set_drvdata(pdev
, NULL
);
378 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
379 regulator_unregister(ldo
->regulator
);
385 static struct platform_driver wm831x_gp_ldo_driver
= {
386 .probe
= wm831x_gp_ldo_probe
,
387 .remove
= __devexit_p(wm831x_gp_ldo_remove
),
389 .name
= "wm831x-ldo",
390 .owner
= THIS_MODULE
,
399 #define WM831X_ALDO_SELECTOR_LOW 0xc
400 #define WM831X_ALDO_MAX_SELECTOR 0x1f
402 static int wm831x_aldo_list_voltage(struct regulator_dev
*rdev
,
403 unsigned int selector
)
405 /* 1-1.6V in 50mV steps */
406 if (selector
<= WM831X_ALDO_SELECTOR_LOW
)
407 return 1000000 + (selector
* 50000);
408 /* 1.7-3.5V in 50mV steps */
409 if (selector
<= WM831X_ALDO_MAX_SELECTOR
)
410 return 1600000 + ((selector
- WM831X_ALDO_SELECTOR_LOW
)
415 static int wm831x_aldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
416 int min_uV
, int max_uV
)
418 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
419 struct wm831x
*wm831x
= ldo
->wm831x
;
422 if (min_uV
< 1000000)
424 else if (min_uV
< 1700000)
425 vsel
= ((min_uV
- 1000000) / 50000);
427 vsel
= ((min_uV
- 1700000) / 100000)
428 + WM831X_ALDO_SELECTOR_LOW
+ 1;
430 ret
= wm831x_aldo_list_voltage(rdev
, vsel
);
433 if (ret
< min_uV
|| ret
> max_uV
)
436 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO7_ON_VSEL_MASK
, vsel
);
439 static int wm831x_aldo_set_voltage(struct regulator_dev
*rdev
,
440 int min_uV
, int max_uV
)
442 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
443 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
445 return wm831x_aldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
448 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev
*rdev
,
451 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
452 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
454 return wm831x_aldo_set_voltage_int(rdev
, reg
, uV
, uV
);
457 static int wm831x_aldo_get_voltage(struct regulator_dev
*rdev
)
459 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
460 struct wm831x
*wm831x
= ldo
->wm831x
;
461 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
464 ret
= wm831x_reg_read(wm831x
, reg
);
468 ret
&= WM831X_LDO7_ON_VSEL_MASK
;
470 return wm831x_aldo_list_voltage(rdev
, ret
);
473 static unsigned int wm831x_aldo_get_mode(struct regulator_dev
*rdev
)
475 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
476 struct wm831x
*wm831x
= ldo
->wm831x
;
477 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
480 ret
= wm831x_reg_read(wm831x
, on_reg
);
484 if (ret
& WM831X_LDO7_ON_MODE
)
485 return REGULATOR_MODE_IDLE
;
487 return REGULATOR_MODE_NORMAL
;
490 static int wm831x_aldo_set_mode(struct regulator_dev
*rdev
,
493 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
494 struct wm831x
*wm831x
= ldo
->wm831x
;
495 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
496 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
501 case REGULATOR_MODE_NORMAL
:
502 ret
= wm831x_set_bits(wm831x
, on_reg
,
503 WM831X_LDO7_ON_MODE
, 0);
508 case REGULATOR_MODE_IDLE
:
509 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
511 WM831X_LDO7_ON_MODE
);
523 static int wm831x_aldo_get_status(struct regulator_dev
*rdev
)
525 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
526 struct wm831x
*wm831x
= ldo
->wm831x
;
527 int mask
= 1 << rdev_get_id(rdev
);
530 /* Is the regulator on? */
531 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
535 return REGULATOR_STATUS_OFF
;
537 /* Is it reporting under voltage? */
538 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
540 return REGULATOR_STATUS_ERROR
;
542 ret
= wm831x_aldo_get_mode(rdev
);
546 return regulator_mode_to_status(ret
);
549 static struct regulator_ops wm831x_aldo_ops
= {
550 .list_voltage
= wm831x_aldo_list_voltage
,
551 .get_voltage
= wm831x_aldo_get_voltage
,
552 .set_voltage
= wm831x_aldo_set_voltage
,
553 .set_suspend_voltage
= wm831x_aldo_set_suspend_voltage
,
554 .get_mode
= wm831x_aldo_get_mode
,
555 .set_mode
= wm831x_aldo_set_mode
,
556 .get_status
= wm831x_aldo_get_status
,
558 .is_enabled
= wm831x_ldo_is_enabled
,
559 .enable
= wm831x_ldo_enable
,
560 .disable
= wm831x_ldo_disable
,
563 static __devinit
int wm831x_aldo_probe(struct platform_device
*pdev
)
565 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
566 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
567 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
568 struct wm831x_ldo
*ldo
;
569 struct resource
*res
;
572 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
574 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
577 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
579 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
583 ldo
->wm831x
= wm831x
;
585 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
587 dev_err(&pdev
->dev
, "No I/O resource\n");
591 ldo
->base
= res
->start
;
593 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
594 ldo
->desc
.name
= ldo
->name
;
596 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
597 ldo
->desc
.n_voltages
= WM831X_ALDO_MAX_SELECTOR
+ 1;
598 ldo
->desc
.ops
= &wm831x_aldo_ops
;
599 ldo
->desc
.owner
= THIS_MODULE
;
601 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
602 pdata
->ldo
[id
], ldo
);
603 if (IS_ERR(ldo
->regulator
)) {
604 ret
= PTR_ERR(ldo
->regulator
);
605 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
610 irq
= platform_get_irq_byname(pdev
, "UV");
611 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
612 IRQF_TRIGGER_RISING
, ldo
->name
,
615 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
620 platform_set_drvdata(pdev
, ldo
);
625 regulator_unregister(ldo
->regulator
);
631 static __devexit
int wm831x_aldo_remove(struct platform_device
*pdev
)
633 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
634 struct wm831x
*wm831x
= ldo
->wm831x
;
636 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
637 regulator_unregister(ldo
->regulator
);
643 static struct platform_driver wm831x_aldo_driver
= {
644 .probe
= wm831x_aldo_probe
,
645 .remove
= __devexit_p(wm831x_aldo_remove
),
647 .name
= "wm831x-aldo",
648 .owner
= THIS_MODULE
,
656 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
658 static int wm831x_alive_ldo_list_voltage(struct regulator_dev
*rdev
,
659 unsigned int selector
)
661 /* 0.8-1.55V in 50mV steps */
662 if (selector
<= WM831X_ALIVE_LDO_MAX_SELECTOR
)
663 return 800000 + (selector
* 50000);
667 static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev
*rdev
,
669 int min_uV
, int max_uV
)
671 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
672 struct wm831x
*wm831x
= ldo
->wm831x
;
675 vsel
= (min_uV
- 800000) / 50000;
677 ret
= wm831x_alive_ldo_list_voltage(rdev
, vsel
);
680 if (ret
< min_uV
|| ret
> max_uV
)
683 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO11_ON_VSEL_MASK
, vsel
);
686 static int wm831x_alive_ldo_set_voltage(struct regulator_dev
*rdev
,
687 int min_uV
, int max_uV
)
689 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
690 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
692 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
695 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
698 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
699 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_SLEEP_CONTROL
;
701 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
704 static int wm831x_alive_ldo_get_voltage(struct regulator_dev
*rdev
)
706 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
707 struct wm831x
*wm831x
= ldo
->wm831x
;
708 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
711 ret
= wm831x_reg_read(wm831x
, reg
);
715 ret
&= WM831X_LDO11_ON_VSEL_MASK
;
717 return wm831x_alive_ldo_list_voltage(rdev
, ret
);
720 static int wm831x_alive_ldo_get_status(struct regulator_dev
*rdev
)
722 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
723 struct wm831x
*wm831x
= ldo
->wm831x
;
724 int mask
= 1 << rdev_get_id(rdev
);
727 /* Is the regulator on? */
728 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
732 return REGULATOR_STATUS_ON
;
734 return REGULATOR_STATUS_OFF
;
737 static struct regulator_ops wm831x_alive_ldo_ops
= {
738 .list_voltage
= wm831x_alive_ldo_list_voltage
,
739 .get_voltage
= wm831x_alive_ldo_get_voltage
,
740 .set_voltage
= wm831x_alive_ldo_set_voltage
,
741 .set_suspend_voltage
= wm831x_alive_ldo_set_suspend_voltage
,
742 .get_status
= wm831x_alive_ldo_get_status
,
744 .is_enabled
= wm831x_ldo_is_enabled
,
745 .enable
= wm831x_ldo_enable
,
746 .disable
= wm831x_ldo_disable
,
749 static __devinit
int wm831x_alive_ldo_probe(struct platform_device
*pdev
)
751 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
752 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
753 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
754 struct wm831x_ldo
*ldo
;
755 struct resource
*res
;
758 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
760 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
763 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
765 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
769 ldo
->wm831x
= wm831x
;
771 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
773 dev_err(&pdev
->dev
, "No I/O resource\n");
777 ldo
->base
= res
->start
;
779 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
780 ldo
->desc
.name
= ldo
->name
;
782 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
783 ldo
->desc
.n_voltages
= WM831X_ALIVE_LDO_MAX_SELECTOR
+ 1;
784 ldo
->desc
.ops
= &wm831x_alive_ldo_ops
;
785 ldo
->desc
.owner
= THIS_MODULE
;
787 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
788 pdata
->ldo
[id
], ldo
);
789 if (IS_ERR(ldo
->regulator
)) {
790 ret
= PTR_ERR(ldo
->regulator
);
791 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
796 platform_set_drvdata(pdev
, ldo
);
805 static __devexit
int wm831x_alive_ldo_remove(struct platform_device
*pdev
)
807 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
809 regulator_unregister(ldo
->regulator
);
815 static struct platform_driver wm831x_alive_ldo_driver
= {
816 .probe
= wm831x_alive_ldo_probe
,
817 .remove
= __devexit_p(wm831x_alive_ldo_remove
),
819 .name
= "wm831x-alive-ldo",
820 .owner
= THIS_MODULE
,
824 static int __init
wm831x_ldo_init(void)
828 ret
= platform_driver_register(&wm831x_gp_ldo_driver
);
830 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret
);
832 ret
= platform_driver_register(&wm831x_aldo_driver
);
834 pr_err("Failed to register WM831x ALDO driver: %d\n", ret
);
836 ret
= platform_driver_register(&wm831x_alive_ldo_driver
);
838 pr_err("Failed to register WM831x alive LDO driver: %d\n",
843 subsys_initcall(wm831x_ldo_init
);
845 static void __exit
wm831x_ldo_exit(void)
847 platform_driver_unregister(&wm831x_alive_ldo_driver
);
848 platform_driver_unregister(&wm831x_aldo_driver
);
849 platform_driver_unregister(&wm831x_gp_ldo_driver
);
851 module_exit(wm831x_ldo_exit
);
853 /* Module information */
854 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
855 MODULE_DESCRIPTION("WM831x LDO driver");
856 MODULE_LICENSE("GPL");
857 MODULE_ALIAS("platform:wm831x-ldo");
858 MODULE_ALIAS("platform:wm831x-aldo");
859 MODULE_ALIAS("platform:wm831x-aliveldo");