2 * wm831x-dcdc.c -- DC-DC buck convertor 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/regulator/machine.h>
23 #include <linux/gpio.h>
25 #include <linux/mfd/wm831x/core.h>
26 #include <linux/mfd/wm831x/regulator.h>
27 #include <linux/mfd/wm831x/pdata.h>
29 #define WM831X_BUCKV_MAX_SELECTOR 0x68
30 #define WM831X_BUCKP_MAX_SELECTOR 0x66
32 #define WM831X_DCDC_MODE_FAST 0
33 #define WM831X_DCDC_MODE_NORMAL 1
34 #define WM831X_DCDC_MODE_IDLE 2
35 #define WM831X_DCDC_MODE_STANDBY 3
37 #define WM831X_DCDC_MAX_NAME 6
39 /* Register offsets in control block */
40 #define WM831X_DCDC_CONTROL_1 0
41 #define WM831X_DCDC_CONTROL_2 1
42 #define WM831X_DCDC_ON_CONFIG 2
43 #define WM831X_DCDC_SLEEP_CONTROL 3
44 #define WM831X_DCDC_DVS_CONTROL 4
51 char name
[WM831X_DCDC_MAX_NAME
];
52 struct regulator_desc desc
;
54 struct wm831x
*wm831x
;
55 struct regulator_dev
*regulator
;
62 static int wm831x_dcdc_is_enabled(struct regulator_dev
*rdev
)
64 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
65 struct wm831x
*wm831x
= dcdc
->wm831x
;
66 int mask
= 1 << rdev_get_id(rdev
);
69 reg
= wm831x_reg_read(wm831x
, WM831X_DCDC_ENABLE
);
79 static int wm831x_dcdc_enable(struct regulator_dev
*rdev
)
81 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
82 struct wm831x
*wm831x
= dcdc
->wm831x
;
83 int mask
= 1 << rdev_get_id(rdev
);
85 return wm831x_set_bits(wm831x
, WM831X_DCDC_ENABLE
, mask
, mask
);
88 static int wm831x_dcdc_disable(struct regulator_dev
*rdev
)
90 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
91 struct wm831x
*wm831x
= dcdc
->wm831x
;
92 int mask
= 1 << rdev_get_id(rdev
);
94 return wm831x_set_bits(wm831x
, WM831X_DCDC_ENABLE
, mask
, 0);
97 static unsigned int wm831x_dcdc_get_mode(struct regulator_dev
*rdev
)
100 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
101 struct wm831x
*wm831x
= dcdc
->wm831x
;
102 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
105 val
= wm831x_reg_read(wm831x
, reg
);
109 val
= (val
& WM831X_DC1_ON_MODE_MASK
) >> WM831X_DC1_ON_MODE_SHIFT
;
112 case WM831X_DCDC_MODE_FAST
:
113 return REGULATOR_MODE_FAST
;
114 case WM831X_DCDC_MODE_NORMAL
:
115 return REGULATOR_MODE_NORMAL
;
116 case WM831X_DCDC_MODE_STANDBY
:
117 return REGULATOR_MODE_STANDBY
;
118 case WM831X_DCDC_MODE_IDLE
:
119 return REGULATOR_MODE_IDLE
;
125 static int wm831x_dcdc_set_mode_int(struct wm831x
*wm831x
, int reg
,
131 case REGULATOR_MODE_FAST
:
132 val
= WM831X_DCDC_MODE_FAST
;
134 case REGULATOR_MODE_NORMAL
:
135 val
= WM831X_DCDC_MODE_NORMAL
;
137 case REGULATOR_MODE_STANDBY
:
138 val
= WM831X_DCDC_MODE_STANDBY
;
140 case REGULATOR_MODE_IDLE
:
141 val
= WM831X_DCDC_MODE_IDLE
;
147 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_ON_MODE_MASK
,
148 val
<< WM831X_DC1_ON_MODE_SHIFT
);
151 static int wm831x_dcdc_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
153 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
154 struct wm831x
*wm831x
= dcdc
->wm831x
;
155 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
157 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
160 static int wm831x_dcdc_set_suspend_mode(struct regulator_dev
*rdev
,
163 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
164 struct wm831x
*wm831x
= dcdc
->wm831x
;
165 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
167 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
170 static int wm831x_dcdc_get_status(struct regulator_dev
*rdev
)
172 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
173 struct wm831x
*wm831x
= dcdc
->wm831x
;
176 /* First, check for errors */
177 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
181 if (ret
& (1 << rdev_get_id(rdev
))) {
182 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
183 rdev_get_id(rdev
) + 1);
184 return REGULATOR_STATUS_ERROR
;
187 /* DCDC1 and DCDC2 can additionally detect high voltage/current */
188 if (rdev_get_id(rdev
) < 2) {
189 if (ret
& (WM831X_DC1_OV_STS
<< rdev_get_id(rdev
))) {
190 dev_dbg(wm831x
->dev
, "DCDC%d over voltage\n",
191 rdev_get_id(rdev
) + 1);
192 return REGULATOR_STATUS_ERROR
;
195 if (ret
& (WM831X_DC1_HC_STS
<< rdev_get_id(rdev
))) {
196 dev_dbg(wm831x
->dev
, "DCDC%d over current\n",
197 rdev_get_id(rdev
) + 1);
198 return REGULATOR_STATUS_ERROR
;
202 /* Is the regulator on? */
203 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
206 if (!(ret
& (1 << rdev_get_id(rdev
))))
207 return REGULATOR_STATUS_OFF
;
209 /* TODO: When we handle hardware control modes so we can report the
211 return REGULATOR_STATUS_ON
;
214 static irqreturn_t
wm831x_dcdc_uv_irq(int irq
, void *data
)
216 struct wm831x_dcdc
*dcdc
= data
;
218 regulator_notifier_call_chain(dcdc
->regulator
,
219 REGULATOR_EVENT_UNDER_VOLTAGE
,
225 static irqreturn_t
wm831x_dcdc_oc_irq(int irq
, void *data
)
227 struct wm831x_dcdc
*dcdc
= data
;
229 regulator_notifier_call_chain(dcdc
->regulator
,
230 REGULATOR_EVENT_OVER_CURRENT
,
240 static int wm831x_buckv_list_voltage(struct regulator_dev
*rdev
,
245 if (selector
<= WM831X_BUCKV_MAX_SELECTOR
)
246 return 600000 + ((selector
- 0x8) * 12500);
250 static int wm831x_buckv_select_min_voltage(struct regulator_dev
*rdev
,
251 int min_uV
, int max_uV
)
257 else if (min_uV
<= 1800000)
258 vsel
= ((min_uV
- 600000) / 12500) + 8;
262 if (wm831x_buckv_list_voltage(rdev
, vsel
) > max_uV
)
268 static int wm831x_buckv_select_max_voltage(struct regulator_dev
*rdev
,
269 int min_uV
, int max_uV
)
273 if (max_uV
< 600000 || max_uV
> 1800000)
276 vsel
= ((max_uV
- 600000) / 12500) + 8;
278 if (wm831x_buckv_list_voltage(rdev
, vsel
) < min_uV
||
279 wm831x_buckv_list_voltage(rdev
, vsel
) < max_uV
)
285 static int wm831x_buckv_set_dvs(struct regulator_dev
*rdev
, int state
)
287 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
289 if (state
== dcdc
->dvs_gpio_state
)
292 dcdc
->dvs_gpio_state
= state
;
293 gpio_set_value(dcdc
->dvs_gpio
, state
);
295 /* Should wait for DVS state change to be asserted if we have
296 * a GPIO for it, for now assume the device is configured
297 * for the fastest possible transition.
303 static int wm831x_buckv_set_voltage(struct regulator_dev
*rdev
,
304 int min_uV
, int max_uV
)
306 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
307 struct wm831x
*wm831x
= dcdc
->wm831x
;
308 int on_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
309 int dvs_reg
= dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
;
312 vsel
= wm831x_buckv_select_min_voltage(rdev
, min_uV
, max_uV
);
316 /* If this value is already set then do a GPIO update if we can */
317 if (dcdc
->dvs_gpio
&& dcdc
->on_vsel
== vsel
)
318 return wm831x_buckv_set_dvs(rdev
, 0);
320 if (dcdc
->dvs_gpio
&& dcdc
->dvs_vsel
== vsel
)
321 return wm831x_buckv_set_dvs(rdev
, 1);
323 /* Always set the ON status to the minimum voltage */
324 ret
= wm831x_set_bits(wm831x
, on_reg
, WM831X_DC1_ON_VSEL_MASK
, vsel
);
327 dcdc
->on_vsel
= vsel
;
332 /* Kick the voltage transition now */
333 ret
= wm831x_buckv_set_dvs(rdev
, 0);
337 /* Set the high voltage as the DVS voltage. This is optimised
338 * for CPUfreq usage, most processors will keep the maximum
339 * voltage constant and lower the minimum with the frequency. */
340 vsel
= wm831x_buckv_select_max_voltage(rdev
, min_uV
, max_uV
);
342 /* This should never happen - at worst the same vsel
343 * should be chosen */
348 /* Don't bother if it's the same VSEL we're already using */
349 if (vsel
== dcdc
->on_vsel
)
352 ret
= wm831x_set_bits(wm831x
, dvs_reg
, WM831X_DC1_DVS_VSEL_MASK
, vsel
);
354 dcdc
->dvs_vsel
= vsel
;
356 dev_warn(wm831x
->dev
, "Failed to set DCDC DVS VSEL: %d\n",
362 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev
*rdev
,
365 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
366 struct wm831x
*wm831x
= dcdc
->wm831x
;
367 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
370 vsel
= wm831x_buckv_select_min_voltage(rdev
, uV
, uV
);
374 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_SLP_VSEL_MASK
, vsel
);
377 static int wm831x_buckv_get_voltage(struct regulator_dev
*rdev
)
379 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
381 if (dcdc
->dvs_gpio
&& dcdc
->dvs_gpio_state
)
382 return wm831x_buckv_list_voltage(rdev
, dcdc
->dvs_vsel
);
384 return wm831x_buckv_list_voltage(rdev
, dcdc
->on_vsel
);
387 /* Current limit options */
388 static u16 wm831x_dcdc_ilim
[] = {
389 125, 250, 375, 500, 625, 750, 875, 1000
392 static int wm831x_buckv_set_current_limit(struct regulator_dev
*rdev
,
393 int min_uA
, int max_uA
)
395 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
396 struct wm831x
*wm831x
= dcdc
->wm831x
;
397 u16 reg
= dcdc
->base
+ WM831X_DCDC_CONTROL_2
;
400 for (i
= 0; i
< ARRAY_SIZE(wm831x_dcdc_ilim
); i
++) {
401 if (max_uA
<= wm831x_dcdc_ilim
[i
])
404 if (i
== ARRAY_SIZE(wm831x_dcdc_ilim
))
407 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_HC_THR_MASK
, i
);
410 static int wm831x_buckv_get_current_limit(struct regulator_dev
*rdev
)
412 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
413 struct wm831x
*wm831x
= dcdc
->wm831x
;
414 u16 reg
= dcdc
->base
+ WM831X_DCDC_CONTROL_2
;
417 val
= wm831x_reg_read(wm831x
, reg
);
421 return wm831x_dcdc_ilim
[val
& WM831X_DC1_HC_THR_MASK
];
424 static struct regulator_ops wm831x_buckv_ops
= {
425 .set_voltage
= wm831x_buckv_set_voltage
,
426 .get_voltage
= wm831x_buckv_get_voltage
,
427 .list_voltage
= wm831x_buckv_list_voltage
,
428 .set_suspend_voltage
= wm831x_buckv_set_suspend_voltage
,
429 .set_current_limit
= wm831x_buckv_set_current_limit
,
430 .get_current_limit
= wm831x_buckv_get_current_limit
,
432 .is_enabled
= wm831x_dcdc_is_enabled
,
433 .enable
= wm831x_dcdc_enable
,
434 .disable
= wm831x_dcdc_disable
,
435 .get_status
= wm831x_dcdc_get_status
,
436 .get_mode
= wm831x_dcdc_get_mode
,
437 .set_mode
= wm831x_dcdc_set_mode
,
438 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
442 * Set up DVS control. We just log errors since we can still run
443 * (with reduced performance) if we fail.
445 static __devinit
void wm831x_buckv_dvs_init(struct wm831x_dcdc
*dcdc
,
446 struct wm831x_buckv_pdata
*pdata
)
448 struct wm831x
*wm831x
= dcdc
->wm831x
;
452 if (!pdata
|| !pdata
->dvs_gpio
)
455 switch (pdata
->dvs_control_src
) {
457 ctrl
= 2 << WM831X_DC1_DVS_SRC_SHIFT
;
460 ctrl
= 3 << WM831X_DC1_DVS_SRC_SHIFT
;
463 dev_err(wm831x
->dev
, "Invalid DVS control source %d for %s\n",
464 pdata
->dvs_control_src
, dcdc
->name
);
468 ret
= wm831x_set_bits(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
469 WM831X_DC1_DVS_SRC_MASK
, ctrl
);
471 dev_err(wm831x
->dev
, "Failed to set %s DVS source: %d\n",
476 ret
= gpio_request(pdata
->dvs_gpio
, "DCDC DVS");
478 dev_err(wm831x
->dev
, "Failed to get %s DVS GPIO: %d\n",
483 /* gpiolib won't let us read the GPIO status so pick the higher
484 * of the two existing voltages so we take it as platform data.
486 dcdc
->dvs_gpio_state
= pdata
->dvs_init_state
;
488 ret
= gpio_direction_output(pdata
->dvs_gpio
, dcdc
->dvs_gpio_state
);
490 dev_err(wm831x
->dev
, "Failed to enable %s DVS GPIO: %d\n",
492 gpio_free(pdata
->dvs_gpio
);
496 dcdc
->dvs_gpio
= pdata
->dvs_gpio
;
499 static __devinit
int wm831x_buckv_probe(struct platform_device
*pdev
)
501 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
502 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
503 int id
= pdev
->id
% ARRAY_SIZE(pdata
->dcdc
);
504 struct wm831x_dcdc
*dcdc
;
505 struct resource
*res
;
508 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
510 if (pdata
== NULL
|| pdata
->dcdc
[id
] == NULL
)
513 dcdc
= kzalloc(sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
515 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
519 dcdc
->wm831x
= wm831x
;
521 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
523 dev_err(&pdev
->dev
, "No I/O resource\n");
527 dcdc
->base
= res
->start
;
529 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
530 dcdc
->desc
.name
= dcdc
->name
;
532 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
533 dcdc
->desc
.n_voltages
= WM831X_BUCKV_MAX_SELECTOR
+ 1;
534 dcdc
->desc
.ops
= &wm831x_buckv_ops
;
535 dcdc
->desc
.owner
= THIS_MODULE
;
537 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_ON_CONFIG
);
539 dev_err(wm831x
->dev
, "Failed to read ON VSEL: %d\n", ret
);
542 dcdc
->on_vsel
= ret
& WM831X_DC1_ON_VSEL_MASK
;
544 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_ON_CONFIG
);
546 dev_err(wm831x
->dev
, "Failed to read DVS VSEL: %d\n", ret
);
549 dcdc
->dvs_vsel
= ret
& WM831X_DC1_DVS_VSEL_MASK
;
552 wm831x_buckv_dvs_init(dcdc
, pdata
->dcdc
[id
]->driver_data
);
554 dcdc
->regulator
= regulator_register(&dcdc
->desc
, &pdev
->dev
,
555 pdata
->dcdc
[id
], dcdc
);
556 if (IS_ERR(dcdc
->regulator
)) {
557 ret
= PTR_ERR(dcdc
->regulator
);
558 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
563 irq
= platform_get_irq_byname(pdev
, "UV");
564 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_dcdc_uv_irq
,
565 IRQF_TRIGGER_RISING
, dcdc
->name
,
568 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
573 irq
= platform_get_irq_byname(pdev
, "HC");
574 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_dcdc_oc_irq
,
575 IRQF_TRIGGER_RISING
, dcdc
->name
,
578 dev_err(&pdev
->dev
, "Failed to request HC IRQ %d: %d\n",
583 platform_set_drvdata(pdev
, dcdc
);
588 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), dcdc
);
590 regulator_unregister(dcdc
->regulator
);
593 gpio_free(dcdc
->dvs_gpio
);
598 static __devexit
int wm831x_buckv_remove(struct platform_device
*pdev
)
600 struct wm831x_dcdc
*dcdc
= platform_get_drvdata(pdev
);
601 struct wm831x
*wm831x
= dcdc
->wm831x
;
603 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "HC"), dcdc
);
604 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), dcdc
);
605 regulator_unregister(dcdc
->regulator
);
607 gpio_free(dcdc
->dvs_gpio
);
613 static struct platform_driver wm831x_buckv_driver
= {
614 .probe
= wm831x_buckv_probe
,
615 .remove
= __devexit_p(wm831x_buckv_remove
),
617 .name
= "wm831x-buckv",
625 static int wm831x_buckp_list_voltage(struct regulator_dev
*rdev
,
628 if (selector
<= WM831X_BUCKP_MAX_SELECTOR
)
629 return 850000 + (selector
* 25000);
634 static int wm831x_buckp_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
635 int min_uV
, int max_uV
)
637 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
638 struct wm831x
*wm831x
= dcdc
->wm831x
;
641 if (min_uV
<= 34000000)
642 vsel
= (min_uV
- 850000) / 25000;
646 if (wm831x_buckp_list_voltage(rdev
, vsel
) > max_uV
)
649 return wm831x_set_bits(wm831x
, reg
, WM831X_DC3_ON_VSEL_MASK
, vsel
);
652 static int wm831x_buckp_set_voltage(struct regulator_dev
*rdev
,
653 int min_uV
, int max_uV
)
655 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
656 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
658 return wm831x_buckp_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
661 static int wm831x_buckp_set_suspend_voltage(struct regulator_dev
*rdev
,
664 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
665 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
667 return wm831x_buckp_set_voltage_int(rdev
, reg
, uV
, uV
);
670 static int wm831x_buckp_get_voltage(struct regulator_dev
*rdev
)
672 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
673 struct wm831x
*wm831x
= dcdc
->wm831x
;
674 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
677 val
= wm831x_reg_read(wm831x
, reg
);
681 return wm831x_buckp_list_voltage(rdev
, val
& WM831X_DC3_ON_VSEL_MASK
);
684 static struct regulator_ops wm831x_buckp_ops
= {
685 .set_voltage
= wm831x_buckp_set_voltage
,
686 .get_voltage
= wm831x_buckp_get_voltage
,
687 .list_voltage
= wm831x_buckp_list_voltage
,
688 .set_suspend_voltage
= wm831x_buckp_set_suspend_voltage
,
690 .is_enabled
= wm831x_dcdc_is_enabled
,
691 .enable
= wm831x_dcdc_enable
,
692 .disable
= wm831x_dcdc_disable
,
693 .get_status
= wm831x_dcdc_get_status
,
694 .get_mode
= wm831x_dcdc_get_mode
,
695 .set_mode
= wm831x_dcdc_set_mode
,
696 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
699 static __devinit
int wm831x_buckp_probe(struct platform_device
*pdev
)
701 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
702 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
703 int id
= pdev
->id
% ARRAY_SIZE(pdata
->dcdc
);
704 struct wm831x_dcdc
*dcdc
;
705 struct resource
*res
;
708 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
710 if (pdata
== NULL
|| pdata
->dcdc
[id
] == NULL
)
713 dcdc
= kzalloc(sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
715 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
719 dcdc
->wm831x
= wm831x
;
721 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
723 dev_err(&pdev
->dev
, "No I/O resource\n");
727 dcdc
->base
= res
->start
;
729 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
730 dcdc
->desc
.name
= dcdc
->name
;
732 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
733 dcdc
->desc
.n_voltages
= WM831X_BUCKP_MAX_SELECTOR
+ 1;
734 dcdc
->desc
.ops
= &wm831x_buckp_ops
;
735 dcdc
->desc
.owner
= THIS_MODULE
;
737 dcdc
->regulator
= regulator_register(&dcdc
->desc
, &pdev
->dev
,
738 pdata
->dcdc
[id
], dcdc
);
739 if (IS_ERR(dcdc
->regulator
)) {
740 ret
= PTR_ERR(dcdc
->regulator
);
741 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
746 irq
= platform_get_irq_byname(pdev
, "UV");
747 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_dcdc_uv_irq
,
748 IRQF_TRIGGER_RISING
, dcdc
->name
,
751 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
756 platform_set_drvdata(pdev
, dcdc
);
761 regulator_unregister(dcdc
->regulator
);
767 static __devexit
int wm831x_buckp_remove(struct platform_device
*pdev
)
769 struct wm831x_dcdc
*dcdc
= platform_get_drvdata(pdev
);
770 struct wm831x
*wm831x
= dcdc
->wm831x
;
772 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), dcdc
);
773 regulator_unregister(dcdc
->regulator
);
779 static struct platform_driver wm831x_buckp_driver
= {
780 .probe
= wm831x_buckp_probe
,
781 .remove
= __devexit_p(wm831x_buckp_remove
),
783 .name
= "wm831x-buckp",
788 * DCDC boost convertors
791 static int wm831x_boostp_get_status(struct regulator_dev
*rdev
)
793 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
794 struct wm831x
*wm831x
= dcdc
->wm831x
;
797 /* First, check for errors */
798 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
802 if (ret
& (1 << rdev_get_id(rdev
))) {
803 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
804 rdev_get_id(rdev
) + 1);
805 return REGULATOR_STATUS_ERROR
;
808 /* Is the regulator on? */
809 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
812 if (ret
& (1 << rdev_get_id(rdev
)))
813 return REGULATOR_STATUS_ON
;
815 return REGULATOR_STATUS_OFF
;
818 static struct regulator_ops wm831x_boostp_ops
= {
819 .get_status
= wm831x_boostp_get_status
,
821 .is_enabled
= wm831x_dcdc_is_enabled
,
822 .enable
= wm831x_dcdc_enable
,
823 .disable
= wm831x_dcdc_disable
,
826 static __devinit
int wm831x_boostp_probe(struct platform_device
*pdev
)
828 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
829 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
830 int id
= pdev
->id
% ARRAY_SIZE(pdata
->dcdc
);
831 struct wm831x_dcdc
*dcdc
;
832 struct resource
*res
;
835 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
837 if (pdata
== NULL
|| pdata
->dcdc
[id
] == NULL
)
840 dcdc
= kzalloc(sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
842 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
846 dcdc
->wm831x
= wm831x
;
848 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
850 dev_err(&pdev
->dev
, "No I/O resource\n");
854 dcdc
->base
= res
->start
;
856 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
857 dcdc
->desc
.name
= dcdc
->name
;
859 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
860 dcdc
->desc
.ops
= &wm831x_boostp_ops
;
861 dcdc
->desc
.owner
= THIS_MODULE
;
863 dcdc
->regulator
= regulator_register(&dcdc
->desc
, &pdev
->dev
,
864 pdata
->dcdc
[id
], dcdc
);
865 if (IS_ERR(dcdc
->regulator
)) {
866 ret
= PTR_ERR(dcdc
->regulator
);
867 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
872 irq
= platform_get_irq_byname(pdev
, "UV");
873 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_dcdc_uv_irq
,
874 IRQF_TRIGGER_RISING
, dcdc
->name
,
877 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
882 platform_set_drvdata(pdev
, dcdc
);
887 regulator_unregister(dcdc
->regulator
);
893 static __devexit
int wm831x_boostp_remove(struct platform_device
*pdev
)
895 struct wm831x_dcdc
*dcdc
= platform_get_drvdata(pdev
);
896 struct wm831x
*wm831x
= dcdc
->wm831x
;
898 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), dcdc
);
899 regulator_unregister(dcdc
->regulator
);
905 static struct platform_driver wm831x_boostp_driver
= {
906 .probe
= wm831x_boostp_probe
,
907 .remove
= __devexit_p(wm831x_boostp_remove
),
909 .name
= "wm831x-boostp",
914 * External Power Enable
916 * These aren't actually DCDCs but look like them in hardware so share
920 #define WM831X_EPE_BASE 6
922 static struct regulator_ops wm831x_epe_ops
= {
923 .is_enabled
= wm831x_dcdc_is_enabled
,
924 .enable
= wm831x_dcdc_enable
,
925 .disable
= wm831x_dcdc_disable
,
926 .get_status
= wm831x_dcdc_get_status
,
929 static __devinit
int wm831x_epe_probe(struct platform_device
*pdev
)
931 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
932 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
933 int id
= pdev
->id
% ARRAY_SIZE(pdata
->epe
);
934 struct wm831x_dcdc
*dcdc
;
937 dev_dbg(&pdev
->dev
, "Probing EPE%d\n", id
+ 1);
939 if (pdata
== NULL
|| pdata
->epe
[id
] == NULL
)
942 dcdc
= kzalloc(sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
944 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
948 dcdc
->wm831x
= wm831x
;
950 /* For current parts this is correct; probably need to revisit
953 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "EPE%d", id
+ 1);
954 dcdc
->desc
.name
= dcdc
->name
;
955 dcdc
->desc
.id
= id
+ WM831X_EPE_BASE
; /* Offset in DCDC registers */
956 dcdc
->desc
.ops
= &wm831x_epe_ops
;
957 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
958 dcdc
->desc
.owner
= THIS_MODULE
;
960 dcdc
->regulator
= regulator_register(&dcdc
->desc
, &pdev
->dev
,
961 pdata
->epe
[id
], dcdc
);
962 if (IS_ERR(dcdc
->regulator
)) {
963 ret
= PTR_ERR(dcdc
->regulator
);
964 dev_err(wm831x
->dev
, "Failed to register EPE%d: %d\n",
969 platform_set_drvdata(pdev
, dcdc
);
978 static __devexit
int wm831x_epe_remove(struct platform_device
*pdev
)
980 struct wm831x_dcdc
*dcdc
= platform_get_drvdata(pdev
);
982 regulator_unregister(dcdc
->regulator
);
988 static struct platform_driver wm831x_epe_driver
= {
989 .probe
= wm831x_epe_probe
,
990 .remove
= __devexit_p(wm831x_epe_remove
),
992 .name
= "wm831x-epe",
996 static int __init
wm831x_dcdc_init(void)
999 ret
= platform_driver_register(&wm831x_buckv_driver
);
1001 pr_err("Failed to register WM831x BUCKV driver: %d\n", ret
);
1003 ret
= platform_driver_register(&wm831x_buckp_driver
);
1005 pr_err("Failed to register WM831x BUCKP driver: %d\n", ret
);
1007 ret
= platform_driver_register(&wm831x_boostp_driver
);
1009 pr_err("Failed to register WM831x BOOST driver: %d\n", ret
);
1011 ret
= platform_driver_register(&wm831x_epe_driver
);
1013 pr_err("Failed to register WM831x EPE driver: %d\n", ret
);
1017 subsys_initcall(wm831x_dcdc_init
);
1019 static void __exit
wm831x_dcdc_exit(void)
1021 platform_driver_unregister(&wm831x_epe_driver
);
1022 platform_driver_unregister(&wm831x_boostp_driver
);
1023 platform_driver_unregister(&wm831x_buckp_driver
);
1024 platform_driver_unregister(&wm831x_buckv_driver
);
1026 module_exit(wm831x_dcdc_exit
);
1028 /* Module information */
1029 MODULE_AUTHOR("Mark Brown");
1030 MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
1031 MODULE_LICENSE("GPL");
1032 MODULE_ALIAS("platform:wm831x-buckv");
1033 MODULE_ALIAS("platform:wm831x-buckp");