blob: a885911bb5fce9c3adf4640b2e65fbbe97c7bf9b [file] [log] [blame]
Mark Browne4ee8312009-07-28 15:21:49 +01001/*
2 * wm831x-dcdc.c -- DC-DC buck convertor driver for the WM831x series
3 *
4 * Copyright 2009 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
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.
12 */
13
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>
Mark Browne24a04c2009-09-22 08:47:11 -070022#include <linux/regulator/machine.h>
23#include <linux/gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Mark Browne4ee8312009-07-28 15:21:49 +010025
26#include <linux/mfd/wm831x/core.h>
27#include <linux/mfd/wm831x/regulator.h>
28#include <linux/mfd/wm831x/pdata.h>
29
30#define WM831X_BUCKV_MAX_SELECTOR 0x68
31#define WM831X_BUCKP_MAX_SELECTOR 0x66
32
33#define WM831X_DCDC_MODE_FAST 0
34#define WM831X_DCDC_MODE_NORMAL 1
35#define WM831X_DCDC_MODE_IDLE 2
36#define WM831X_DCDC_MODE_STANDBY 3
37
Mark Brown82caa972012-03-28 21:40:42 +010038#define WM831X_DCDC_MAX_NAME 9
Mark Browne4ee8312009-07-28 15:21:49 +010039
40/* Register offsets in control block */
41#define WM831X_DCDC_CONTROL_1 0
42#define WM831X_DCDC_CONTROL_2 1
43#define WM831X_DCDC_ON_CONFIG 2
44#define WM831X_DCDC_SLEEP_CONTROL 3
Mark Browne24a04c2009-09-22 08:47:11 -070045#define WM831X_DCDC_DVS_CONTROL 4
Mark Browne4ee8312009-07-28 15:21:49 +010046
47/*
48 * Shared
49 */
50
51struct wm831x_dcdc {
52 char name[WM831X_DCDC_MAX_NAME];
Mark Brown82caa972012-03-28 21:40:42 +010053 char supply_name[WM831X_DCDC_MAX_NAME];
Mark Browne4ee8312009-07-28 15:21:49 +010054 struct regulator_desc desc;
55 int base;
56 struct wm831x *wm831x;
57 struct regulator_dev *regulator;
Mark Browne24a04c2009-09-22 08:47:11 -070058 int dvs_gpio;
59 int dvs_gpio_state;
60 int on_vsel;
61 int dvs_vsel;
Mark Browne4ee8312009-07-28 15:21:49 +010062};
63
Mark Browne4ee8312009-07-28 15:21:49 +010064static unsigned int wm831x_dcdc_get_mode(struct regulator_dev *rdev)
65
66{
67 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
68 struct wm831x *wm831x = dcdc->wm831x;
69 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
70 int val;
71
72 val = wm831x_reg_read(wm831x, reg);
73 if (val < 0)
74 return val;
75
76 val = (val & WM831X_DC1_ON_MODE_MASK) >> WM831X_DC1_ON_MODE_SHIFT;
77
78 switch (val) {
79 case WM831X_DCDC_MODE_FAST:
80 return REGULATOR_MODE_FAST;
81 case WM831X_DCDC_MODE_NORMAL:
82 return REGULATOR_MODE_NORMAL;
83 case WM831X_DCDC_MODE_STANDBY:
84 return REGULATOR_MODE_STANDBY;
85 case WM831X_DCDC_MODE_IDLE:
86 return REGULATOR_MODE_IDLE;
87 default:
88 BUG();
Mark Brown9ee291a2011-02-02 20:17:22 +000089 return -EINVAL;
Mark Browne4ee8312009-07-28 15:21:49 +010090 }
91}
92
93static int wm831x_dcdc_set_mode_int(struct wm831x *wm831x, int reg,
94 unsigned int mode)
95{
96 int val;
97
98 switch (mode) {
99 case REGULATOR_MODE_FAST:
100 val = WM831X_DCDC_MODE_FAST;
101 break;
102 case REGULATOR_MODE_NORMAL:
103 val = WM831X_DCDC_MODE_NORMAL;
104 break;
105 case REGULATOR_MODE_STANDBY:
106 val = WM831X_DCDC_MODE_STANDBY;
107 break;
108 case REGULATOR_MODE_IDLE:
109 val = WM831X_DCDC_MODE_IDLE;
110 break;
111 default:
112 return -EINVAL;
113 }
114
115 return wm831x_set_bits(wm831x, reg, WM831X_DC1_ON_MODE_MASK,
116 val << WM831X_DC1_ON_MODE_SHIFT);
117}
118
119static int wm831x_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode)
120{
121 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
122 struct wm831x *wm831x = dcdc->wm831x;
123 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
124
125 return wm831x_dcdc_set_mode_int(wm831x, reg, mode);
126}
127
128static int wm831x_dcdc_set_suspend_mode(struct regulator_dev *rdev,
129 unsigned int mode)
130{
131 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
132 struct wm831x *wm831x = dcdc->wm831x;
133 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
134
135 return wm831x_dcdc_set_mode_int(wm831x, reg, mode);
136}
137
138static int wm831x_dcdc_get_status(struct regulator_dev *rdev)
139{
140 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
141 struct wm831x *wm831x = dcdc->wm831x;
142 int ret;
143
144 /* First, check for errors */
145 ret = wm831x_reg_read(wm831x, WM831X_DCDC_UV_STATUS);
146 if (ret < 0)
147 return ret;
148
149 if (ret & (1 << rdev_get_id(rdev))) {
150 dev_dbg(wm831x->dev, "DCDC%d under voltage\n",
151 rdev_get_id(rdev) + 1);
152 return REGULATOR_STATUS_ERROR;
153 }
154
155 /* DCDC1 and DCDC2 can additionally detect high voltage/current */
156 if (rdev_get_id(rdev) < 2) {
157 if (ret & (WM831X_DC1_OV_STS << rdev_get_id(rdev))) {
158 dev_dbg(wm831x->dev, "DCDC%d over voltage\n",
159 rdev_get_id(rdev) + 1);
160 return REGULATOR_STATUS_ERROR;
161 }
162
163 if (ret & (WM831X_DC1_HC_STS << rdev_get_id(rdev))) {
164 dev_dbg(wm831x->dev, "DCDC%d over current\n",
165 rdev_get_id(rdev) + 1);
166 return REGULATOR_STATUS_ERROR;
167 }
168 }
169
170 /* Is the regulator on? */
171 ret = wm831x_reg_read(wm831x, WM831X_DCDC_STATUS);
172 if (ret < 0)
173 return ret;
174 if (!(ret & (1 << rdev_get_id(rdev))))
175 return REGULATOR_STATUS_OFF;
176
177 /* TODO: When we handle hardware control modes so we can report the
178 * current mode. */
179 return REGULATOR_STATUS_ON;
180}
181
182static irqreturn_t wm831x_dcdc_uv_irq(int irq, void *data)
183{
184 struct wm831x_dcdc *dcdc = data;
185
186 regulator_notifier_call_chain(dcdc->regulator,
187 REGULATOR_EVENT_UNDER_VOLTAGE,
188 NULL);
189
190 return IRQ_HANDLED;
191}
192
193static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data)
194{
195 struct wm831x_dcdc *dcdc = data;
196
197 regulator_notifier_call_chain(dcdc->regulator,
198 REGULATOR_EVENT_OVER_CURRENT,
199 NULL);
200
201 return IRQ_HANDLED;
202}
203
204/*
205 * BUCKV specifics
206 */
207
208static int wm831x_buckv_list_voltage(struct regulator_dev *rdev,
209 unsigned selector)
210{
211 if (selector <= 0x8)
212 return 600000;
213 if (selector <= WM831X_BUCKV_MAX_SELECTOR)
214 return 600000 + ((selector - 0x8) * 12500);
215 return -EINVAL;
216}
217
Mark Browne24a04c2009-09-22 08:47:11 -0700218static int wm831x_buckv_select_min_voltage(struct regulator_dev *rdev,
219 int min_uV, int max_uV)
Mark Browne4ee8312009-07-28 15:21:49 +0100220{
Mark Browne4ee8312009-07-28 15:21:49 +0100221 u16 vsel;
222
223 if (min_uV < 600000)
224 vsel = 0;
225 else if (min_uV <= 1800000)
226 vsel = ((min_uV - 600000) / 12500) + 8;
227 else
228 return -EINVAL;
229
230 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
231 return -EINVAL;
232
Mark Browne24a04c2009-09-22 08:47:11 -0700233 return vsel;
234}
235
Mark Browne24a04c2009-09-22 08:47:11 -0700236static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
237{
238 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
239
240 if (state == dcdc->dvs_gpio_state)
241 return 0;
242
243 dcdc->dvs_gpio_state = state;
244 gpio_set_value(dcdc->dvs_gpio, state);
245
246 /* Should wait for DVS state change to be asserted if we have
247 * a GPIO for it, for now assume the device is configured
248 * for the fastest possible transition.
249 */
250
251 return 0;
Mark Browne4ee8312009-07-28 15:21:49 +0100252}
253
254static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000255 int min_uV, int max_uV, unsigned *selector)
Mark Browne4ee8312009-07-28 15:21:49 +0100256{
257 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
Mark Browne24a04c2009-09-22 08:47:11 -0700258 struct wm831x *wm831x = dcdc->wm831x;
259 int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
260 int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL;
261 int vsel, ret;
Mark Browne4ee8312009-07-28 15:21:49 +0100262
Mark Browne24a04c2009-09-22 08:47:11 -0700263 vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV);
264 if (vsel < 0)
265 return vsel;
266
Mark Brown3a93f2a2010-11-10 14:38:29 +0000267 *selector = vsel;
268
Mark Browne24a04c2009-09-22 08:47:11 -0700269 /* If this value is already set then do a GPIO update if we can */
270 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel)
271 return wm831x_buckv_set_dvs(rdev, 0);
272
273 if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel)
274 return wm831x_buckv_set_dvs(rdev, 1);
275
276 /* Always set the ON status to the minimum voltage */
277 ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel);
278 if (ret < 0)
279 return ret;
280 dcdc->on_vsel = vsel;
281
282 if (!dcdc->dvs_gpio)
283 return ret;
284
285 /* Kick the voltage transition now */
286 ret = wm831x_buckv_set_dvs(rdev, 0);
287 if (ret < 0)
288 return ret;
289
Mark Brown88cda602011-07-25 22:20:34 +0100290 /*
291 * If this VSEL is higher than the last one we've seen then
292 * remember it as the DVS VSEL. This is optimised for CPUfreq
293 * usage where we want to get to the highest voltage very
294 * quickly.
295 */
296 if (vsel > dcdc->dvs_vsel) {
297 ret = wm831x_set_bits(wm831x, dvs_reg,
298 WM831X_DC1_DVS_VSEL_MASK,
299 dcdc->dvs_vsel);
300 if (ret == 0)
301 dcdc->dvs_vsel = vsel;
302 else
303 dev_warn(wm831x->dev,
304 "Failed to set DCDC DVS VSEL: %d\n", ret);
Mark Browne24a04c2009-09-22 08:47:11 -0700305 }
306
Mark Browne24a04c2009-09-22 08:47:11 -0700307 return 0;
Mark Browne4ee8312009-07-28 15:21:49 +0100308}
309
310static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
Mark Browne24a04c2009-09-22 08:47:11 -0700311 int uV)
Mark Browne4ee8312009-07-28 15:21:49 +0100312{
313 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
Mark Browne24a04c2009-09-22 08:47:11 -0700314 struct wm831x *wm831x = dcdc->wm831x;
Mark Browne4ee8312009-07-28 15:21:49 +0100315 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
Mark Browne24a04c2009-09-22 08:47:11 -0700316 int vsel;
Mark Browne4ee8312009-07-28 15:21:49 +0100317
Mark Browne24a04c2009-09-22 08:47:11 -0700318 vsel = wm831x_buckv_select_min_voltage(rdev, uV, uV);
319 if (vsel < 0)
320 return vsel;
321
322 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel);
Mark Browne4ee8312009-07-28 15:21:49 +0100323}
324
Mark Brownafb8bb82010-12-10 17:28:08 +0000325static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
Mark Browne4ee8312009-07-28 15:21:49 +0100326{
327 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
Mark Browne4ee8312009-07-28 15:21:49 +0100328
Mark Browne24a04c2009-09-22 08:47:11 -0700329 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state)
Mark Brownafb8bb82010-12-10 17:28:08 +0000330 return dcdc->dvs_vsel;
Mark Browne24a04c2009-09-22 08:47:11 -0700331 else
Mark Brownafb8bb82010-12-10 17:28:08 +0000332 return dcdc->on_vsel;
Mark Browne4ee8312009-07-28 15:21:49 +0100333}
334
335/* Current limit options */
336static u16 wm831x_dcdc_ilim[] = {
337 125, 250, 375, 500, 625, 750, 875, 1000
338};
339
340static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
341 int min_uA, int max_uA)
342{
343 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
344 struct wm831x *wm831x = dcdc->wm831x;
345 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
346 int i;
347
348 for (i = 0; i < ARRAY_SIZE(wm831x_dcdc_ilim); i++) {
Axel Lina171e782012-03-27 15:17:26 +0800349 if ((min_uA <= wm831x_dcdc_ilim[i]) &&
350 (wm831x_dcdc_ilim[i] <= max_uA))
Mark Browne4ee8312009-07-28 15:21:49 +0100351 break;
352 }
353 if (i == ARRAY_SIZE(wm831x_dcdc_ilim))
354 return -EINVAL;
355
Axel Lin09bf14b2012-03-15 15:53:05 +0800356 return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK,
357 i << WM831X_DC1_HC_THR_SHIFT);
Mark Browne4ee8312009-07-28 15:21:49 +0100358}
359
360static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
361{
362 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
363 struct wm831x *wm831x = dcdc->wm831x;
364 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
365 int val;
366
367 val = wm831x_reg_read(wm831x, reg);
368 if (val < 0)
369 return val;
370
Axel Lin09bf14b2012-03-15 15:53:05 +0800371 val = (val & WM831X_DC1_HC_THR_MASK) >> WM831X_DC1_HC_THR_SHIFT;
372 return wm831x_dcdc_ilim[val];
Mark Browne4ee8312009-07-28 15:21:49 +0100373}
374
375static struct regulator_ops wm831x_buckv_ops = {
376 .set_voltage = wm831x_buckv_set_voltage,
Mark Brownafb8bb82010-12-10 17:28:08 +0000377 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
Mark Browne4ee8312009-07-28 15:21:49 +0100378 .list_voltage = wm831x_buckv_list_voltage,
379 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
380 .set_current_limit = wm831x_buckv_set_current_limit,
381 .get_current_limit = wm831x_buckv_get_current_limit,
382
Mark Brown3d138fc2012-04-15 12:38:42 +0100383 .is_enabled = regulator_is_enabled_regmap,
384 .enable = regulator_enable_regmap,
385 .disable = regulator_disable_regmap,
Mark Browne4ee8312009-07-28 15:21:49 +0100386 .get_status = wm831x_dcdc_get_status,
387 .get_mode = wm831x_dcdc_get_mode,
388 .set_mode = wm831x_dcdc_set_mode,
389 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
390};
391
Mark Browne24a04c2009-09-22 08:47:11 -0700392/*
393 * Set up DVS control. We just log errors since we can still run
394 * (with reduced performance) if we fail.
395 */
396static __devinit void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc,
397 struct wm831x_buckv_pdata *pdata)
398{
399 struct wm831x *wm831x = dcdc->wm831x;
400 int ret;
401 u16 ctrl;
402
403 if (!pdata || !pdata->dvs_gpio)
404 return;
405
Mark Browne24a04c2009-09-22 08:47:11 -0700406 /* gpiolib won't let us read the GPIO status so pick the higher
407 * of the two existing voltages so we take it as platform data.
408 */
409 dcdc->dvs_gpio_state = pdata->dvs_init_state;
410
Mark Brown053fa1b2012-05-07 18:19:08 +0100411 ret = gpio_request_one(pdata->dvs_gpio,
412 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0,
413 "DCDC DVS");
Mark Browne24a04c2009-09-22 08:47:11 -0700414 if (ret < 0) {
Mark Brown053fa1b2012-05-07 18:19:08 +0100415 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n",
Mark Browne24a04c2009-09-22 08:47:11 -0700416 dcdc->name, ret);
Mark Browne24a04c2009-09-22 08:47:11 -0700417 return;
418 }
419
420 dcdc->dvs_gpio = pdata->dvs_gpio;
Mark Brownb47ba9fd2011-07-25 22:20:32 +0100421
422 switch (pdata->dvs_control_src) {
423 case 1:
424 ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT;
425 break;
426 case 2:
427 ctrl = 3 << WM831X_DC1_DVS_SRC_SHIFT;
428 break;
429 default:
430 dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n",
431 pdata->dvs_control_src, dcdc->name);
432 return;
433 }
434
Mark Brownc439b8f2011-07-25 22:20:33 +0100435 /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL
436 * to make bootstrapping a bit smoother.
437 */
438 if (!dcdc->dvs_vsel) {
439 ret = wm831x_set_bits(wm831x,
440 dcdc->base + WM831X_DCDC_DVS_CONTROL,
441 WM831X_DC1_DVS_VSEL_MASK, dcdc->on_vsel);
442 if (ret == 0)
443 dcdc->dvs_vsel = dcdc->on_vsel;
444 else
445 dev_warn(wm831x->dev, "Failed to set DVS_VSEL: %d\n",
446 ret);
447 }
448
Mark Brownb47ba9fd2011-07-25 22:20:32 +0100449 ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL,
450 WM831X_DC1_DVS_SRC_MASK, ctrl);
451 if (ret < 0) {
452 dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n",
453 dcdc->name, ret);
454 }
Mark Browne24a04c2009-09-22 08:47:11 -0700455}
456
Mark Browne4ee8312009-07-28 15:21:49 +0100457static __devinit int wm831x_buckv_probe(struct platform_device *pdev)
458{
459 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
460 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
Mark Brownc172708d2012-04-04 00:50:22 +0100461 struct regulator_config config = { };
Mark Brown137a6352011-07-25 22:20:29 +0100462 int id;
Mark Browne4ee8312009-07-28 15:21:49 +0100463 struct wm831x_dcdc *dcdc;
464 struct resource *res;
465 int ret, irq;
466
Mark Brown137a6352011-07-25 22:20:29 +0100467 if (pdata && pdata->wm831x_num)
468 id = (pdata->wm831x_num * 10) + 1;
469 else
470 id = 0;
471 id = pdev->id - id;
472
Mark Browne4ee8312009-07-28 15:21:49 +0100473 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
474
Mark Brownfded2f42011-12-15 02:11:14 +0800475 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
476 GFP_KERNEL);
Mark Browne4ee8312009-07-28 15:21:49 +0100477 if (dcdc == NULL) {
478 dev_err(&pdev->dev, "Unable to allocate private data\n");
479 return -ENOMEM;
480 }
481
482 dcdc->wm831x = wm831x;
483
484 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
485 if (res == NULL) {
486 dev_err(&pdev->dev, "No I/O resource\n");
487 ret = -EINVAL;
488 goto err;
489 }
490 dcdc->base = res->start;
491
492 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
493 dcdc->desc.name = dcdc->name;
Mark Brown82caa972012-03-28 21:40:42 +0100494
495 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name),
496 "DC%dVDD", id + 1);
497 dcdc->desc.supply_name = dcdc->supply_name;
498
Mark Browne4ee8312009-07-28 15:21:49 +0100499 dcdc->desc.id = id;
500 dcdc->desc.type = REGULATOR_VOLTAGE;
501 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1;
502 dcdc->desc.ops = &wm831x_buckv_ops;
503 dcdc->desc.owner = THIS_MODULE;
Mark Brown3d138fc2012-04-15 12:38:42 +0100504 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
505 dcdc->desc.enable_mask = 1 << id;
Mark Browne4ee8312009-07-28 15:21:49 +0100506
Mark Browne24a04c2009-09-22 08:47:11 -0700507 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
508 if (ret < 0) {
509 dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret);
510 goto err;
511 }
512 dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK;
513
Mark Browna1b81dd2011-07-25 22:20:30 +0100514 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL);
Mark Browne24a04c2009-09-22 08:47:11 -0700515 if (ret < 0) {
516 dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret);
517 goto err;
518 }
519 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
520
Mark Brownf0b067d2012-05-14 11:37:09 +0100521 if (pdata && pdata->dcdc[id])
Mark Browne24a04c2009-09-22 08:47:11 -0700522 wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data);
523
Mark Brownc172708d2012-04-04 00:50:22 +0100524 config.dev = pdev->dev.parent;
Mark Brownb7ca8782012-05-10 00:41:02 +0100525 if (pdata)
526 config.init_data = pdata->dcdc[id];
Mark Brownc172708d2012-04-04 00:50:22 +0100527 config.driver_data = dcdc;
Mark Brown3d138fc2012-04-15 12:38:42 +0100528 config.regmap = wm831x->regmap;
Mark Brownc172708d2012-04-04 00:50:22 +0100529
530 dcdc->regulator = regulator_register(&dcdc->desc, &config);
Mark Browne4ee8312009-07-28 15:21:49 +0100531 if (IS_ERR(dcdc->regulator)) {
532 ret = PTR_ERR(dcdc->regulator);
533 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
534 id + 1, ret);
535 goto err;
536 }
537
538 irq = platform_get_irq_byname(pdev, "UV");
Mark Browndfda9c22011-03-01 16:50:43 +0000539 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq,
540 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
Mark Browne4ee8312009-07-28 15:21:49 +0100541 if (ret != 0) {
542 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
543 irq, ret);
544 goto err_regulator;
545 }
546
547 irq = platform_get_irq_byname(pdev, "HC");
Mark Browndfda9c22011-03-01 16:50:43 +0000548 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_oc_irq,
549 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
Mark Browne4ee8312009-07-28 15:21:49 +0100550 if (ret != 0) {
551 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n",
552 irq, ret);
553 goto err_uv;
554 }
555
556 platform_set_drvdata(pdev, dcdc);
557
558 return 0;
559
560err_uv:
Mark Browndfda9c22011-03-01 16:50:43 +0000561 free_irq(platform_get_irq_byname(pdev, "UV"), dcdc);
Mark Browne4ee8312009-07-28 15:21:49 +0100562err_regulator:
563 regulator_unregister(dcdc->regulator);
564err:
Mark Browne24a04c2009-09-22 08:47:11 -0700565 if (dcdc->dvs_gpio)
566 gpio_free(dcdc->dvs_gpio);
Mark Browne4ee8312009-07-28 15:21:49 +0100567 return ret;
568}
569
570static __devexit int wm831x_buckv_remove(struct platform_device *pdev)
571{
572 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
Mark Browne4ee8312009-07-28 15:21:49 +0100573
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800574 platform_set_drvdata(pdev, NULL);
575
Mark Brown69952362011-03-18 12:43:35 +0000576 free_irq(platform_get_irq_byname(pdev, "HC"), dcdc);
577 free_irq(platform_get_irq_byname(pdev, "UV"), dcdc);
Mark Browne4ee8312009-07-28 15:21:49 +0100578 regulator_unregister(dcdc->regulator);
Mark Browne24a04c2009-09-22 08:47:11 -0700579 if (dcdc->dvs_gpio)
580 gpio_free(dcdc->dvs_gpio);
Mark Browne4ee8312009-07-28 15:21:49 +0100581
582 return 0;
583}
584
585static struct platform_driver wm831x_buckv_driver = {
586 .probe = wm831x_buckv_probe,
587 .remove = __devexit_p(wm831x_buckv_remove),
588 .driver = {
589 .name = "wm831x-buckv",
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800590 .owner = THIS_MODULE,
Mark Browne4ee8312009-07-28 15:21:49 +0100591 },
592};
593
594/*
595 * BUCKP specifics
596 */
597
598static int wm831x_buckp_list_voltage(struct regulator_dev *rdev,
599 unsigned selector)
600{
601 if (selector <= WM831X_BUCKP_MAX_SELECTOR)
602 return 850000 + (selector * 25000);
603 else
604 return -EINVAL;
605}
606
607static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000608 int min_uV, int max_uV, int *selector)
Mark Browne4ee8312009-07-28 15:21:49 +0100609{
610 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
611 struct wm831x *wm831x = dcdc->wm831x;
612 u16 vsel;
613
614 if (min_uV <= 34000000)
615 vsel = (min_uV - 850000) / 25000;
616 else
617 return -EINVAL;
618
619 if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV)
620 return -EINVAL;
621
Mark Brown3a93f2a2010-11-10 14:38:29 +0000622 *selector = vsel;
623
Mark Browne4ee8312009-07-28 15:21:49 +0100624 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel);
625}
626
627static int wm831x_buckp_set_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000628 int min_uV, int max_uV,
629 unsigned *selector)
Mark Browne4ee8312009-07-28 15:21:49 +0100630{
631 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
632 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
633
Mark Brown3a93f2a2010-11-10 14:38:29 +0000634 return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV,
635 selector);
Mark Browne4ee8312009-07-28 15:21:49 +0100636}
637
638static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev,
639 int uV)
640{
641 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
642 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
Mark Brown3a93f2a2010-11-10 14:38:29 +0000643 unsigned selector;
Mark Browne4ee8312009-07-28 15:21:49 +0100644
Mark Brown3a93f2a2010-11-10 14:38:29 +0000645 return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector);
Mark Browne4ee8312009-07-28 15:21:49 +0100646}
647
Mark Browne4ee8312009-07-28 15:21:49 +0100648static struct regulator_ops wm831x_buckp_ops = {
649 .set_voltage = wm831x_buckp_set_voltage,
Mark Brown817436e2012-04-15 11:55:34 +0100650 .get_voltage_sel = regulator_get_voltage_sel_regmap,
Mark Browne4ee8312009-07-28 15:21:49 +0100651 .list_voltage = wm831x_buckp_list_voltage,
652 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
653
Mark Brown3d138fc2012-04-15 12:38:42 +0100654 .is_enabled = regulator_is_enabled_regmap,
655 .enable = regulator_enable_regmap,
656 .disable = regulator_disable_regmap,
Mark Browne4ee8312009-07-28 15:21:49 +0100657 .get_status = wm831x_dcdc_get_status,
658 .get_mode = wm831x_dcdc_get_mode,
659 .set_mode = wm831x_dcdc_set_mode,
660 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
661};
662
663static __devinit int wm831x_buckp_probe(struct platform_device *pdev)
664{
665 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
666 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
Mark Brownc172708d2012-04-04 00:50:22 +0100667 struct regulator_config config = { };
Mark Brown137a6352011-07-25 22:20:29 +0100668 int id;
Mark Browne4ee8312009-07-28 15:21:49 +0100669 struct wm831x_dcdc *dcdc;
670 struct resource *res;
671 int ret, irq;
672
Mark Brown137a6352011-07-25 22:20:29 +0100673 if (pdata && pdata->wm831x_num)
674 id = (pdata->wm831x_num * 10) + 1;
675 else
676 id = 0;
677 id = pdev->id - id;
678
Mark Browne4ee8312009-07-28 15:21:49 +0100679 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
680
Mark Brownfded2f42011-12-15 02:11:14 +0800681 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
682 GFP_KERNEL);
Mark Browne4ee8312009-07-28 15:21:49 +0100683 if (dcdc == NULL) {
684 dev_err(&pdev->dev, "Unable to allocate private data\n");
685 return -ENOMEM;
686 }
687
688 dcdc->wm831x = wm831x;
689
690 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
691 if (res == NULL) {
692 dev_err(&pdev->dev, "No I/O resource\n");
693 ret = -EINVAL;
694 goto err;
695 }
696 dcdc->base = res->start;
697
698 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
699 dcdc->desc.name = dcdc->name;
Mark Brown82caa972012-03-28 21:40:42 +0100700
701 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name),
702 "DC%dVDD", id + 1);
703 dcdc->desc.supply_name = dcdc->supply_name;
704
Mark Browne4ee8312009-07-28 15:21:49 +0100705 dcdc->desc.id = id;
706 dcdc->desc.type = REGULATOR_VOLTAGE;
707 dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1;
708 dcdc->desc.ops = &wm831x_buckp_ops;
709 dcdc->desc.owner = THIS_MODULE;
Mark Brown817436e2012-04-15 11:55:34 +0100710 dcdc->desc.vsel_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
711 dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK;
Mark Brown3d138fc2012-04-15 12:38:42 +0100712 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
713 dcdc->desc.enable_mask = 1 << id;
Mark Browne4ee8312009-07-28 15:21:49 +0100714
Mark Brownc172708d2012-04-04 00:50:22 +0100715 config.dev = pdev->dev.parent;
Mark Brownb7ca8782012-05-10 00:41:02 +0100716 if (pdata)
717 config.init_data = pdata->dcdc[id];
Mark Brownc172708d2012-04-04 00:50:22 +0100718 config.driver_data = dcdc;
Mark Brown817436e2012-04-15 11:55:34 +0100719 config.regmap = wm831x->regmap;
Mark Brownc172708d2012-04-04 00:50:22 +0100720
721 dcdc->regulator = regulator_register(&dcdc->desc, &config);
Mark Browne4ee8312009-07-28 15:21:49 +0100722 if (IS_ERR(dcdc->regulator)) {
723 ret = PTR_ERR(dcdc->regulator);
724 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
725 id + 1, ret);
726 goto err;
727 }
728
729 irq = platform_get_irq_byname(pdev, "UV");
Mark Browndfda9c22011-03-01 16:50:43 +0000730 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq,
731 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
Mark Browne4ee8312009-07-28 15:21:49 +0100732 if (ret != 0) {
733 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
734 irq, ret);
735 goto err_regulator;
736 }
737
738 platform_set_drvdata(pdev, dcdc);
739
740 return 0;
741
742err_regulator:
743 regulator_unregister(dcdc->regulator);
744err:
Mark Browne4ee8312009-07-28 15:21:49 +0100745 return ret;
746}
747
748static __devexit int wm831x_buckp_remove(struct platform_device *pdev)
749{
750 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
Mark Browne4ee8312009-07-28 15:21:49 +0100751
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800752 platform_set_drvdata(pdev, NULL);
753
Mark Brown69952362011-03-18 12:43:35 +0000754 free_irq(platform_get_irq_byname(pdev, "UV"), dcdc);
Mark Browne4ee8312009-07-28 15:21:49 +0100755 regulator_unregister(dcdc->regulator);
Mark Browne4ee8312009-07-28 15:21:49 +0100756
757 return 0;
758}
759
760static struct platform_driver wm831x_buckp_driver = {
761 .probe = wm831x_buckp_probe,
762 .remove = __devexit_p(wm831x_buckp_remove),
763 .driver = {
764 .name = "wm831x-buckp",
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800765 .owner = THIS_MODULE,
Mark Browne4ee8312009-07-28 15:21:49 +0100766 },
767};
768
Mark Brown8267a9b2009-07-28 15:22:23 +0100769/*
Mark Brown13048502009-07-28 15:23:16 +0100770 * DCDC boost convertors
771 */
772
773static int wm831x_boostp_get_status(struct regulator_dev *rdev)
774{
775 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
776 struct wm831x *wm831x = dcdc->wm831x;
777 int ret;
778
779 /* First, check for errors */
780 ret = wm831x_reg_read(wm831x, WM831X_DCDC_UV_STATUS);
781 if (ret < 0)
782 return ret;
783
784 if (ret & (1 << rdev_get_id(rdev))) {
785 dev_dbg(wm831x->dev, "DCDC%d under voltage\n",
786 rdev_get_id(rdev) + 1);
787 return REGULATOR_STATUS_ERROR;
788 }
789
790 /* Is the regulator on? */
791 ret = wm831x_reg_read(wm831x, WM831X_DCDC_STATUS);
792 if (ret < 0)
793 return ret;
794 if (ret & (1 << rdev_get_id(rdev)))
795 return REGULATOR_STATUS_ON;
796 else
797 return REGULATOR_STATUS_OFF;
798}
799
800static struct regulator_ops wm831x_boostp_ops = {
801 .get_status = wm831x_boostp_get_status,
802
Mark Brown3d138fc2012-04-15 12:38:42 +0100803 .is_enabled = regulator_is_enabled_regmap,
804 .enable = regulator_enable_regmap,
805 .disable = regulator_disable_regmap,
Mark Brown13048502009-07-28 15:23:16 +0100806};
807
808static __devinit int wm831x_boostp_probe(struct platform_device *pdev)
809{
810 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
811 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
Mark Brownc172708d2012-04-04 00:50:22 +0100812 struct regulator_config config = { };
Mark Brown13048502009-07-28 15:23:16 +0100813 int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
814 struct wm831x_dcdc *dcdc;
815 struct resource *res;
816 int ret, irq;
817
818 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
819
820 if (pdata == NULL || pdata->dcdc[id] == NULL)
821 return -ENODEV;
822
Axel Lin4c601652012-03-23 17:00:01 +0800823 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
Mark Brown13048502009-07-28 15:23:16 +0100824 if (dcdc == NULL) {
825 dev_err(&pdev->dev, "Unable to allocate private data\n");
826 return -ENOMEM;
827 }
828
829 dcdc->wm831x = wm831x;
830
831 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
832 if (res == NULL) {
833 dev_err(&pdev->dev, "No I/O resource\n");
834 ret = -EINVAL;
835 goto err;
836 }
837 dcdc->base = res->start;
838
839 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
840 dcdc->desc.name = dcdc->name;
841 dcdc->desc.id = id;
842 dcdc->desc.type = REGULATOR_VOLTAGE;
843 dcdc->desc.ops = &wm831x_boostp_ops;
844 dcdc->desc.owner = THIS_MODULE;
Mark Brown3d138fc2012-04-15 12:38:42 +0100845 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
846 dcdc->desc.enable_mask = 1 << id;
Mark Brown13048502009-07-28 15:23:16 +0100847
Mark Brownc172708d2012-04-04 00:50:22 +0100848 config.dev = pdev->dev.parent;
Mark Brownf0b067d2012-05-14 11:37:09 +0100849 if (pdata)
850 config.init_data = pdata->dcdc[id];
Mark Brownc172708d2012-04-04 00:50:22 +0100851 config.driver_data = dcdc;
Mark Brown3d138fc2012-04-15 12:38:42 +0100852 config.regmap = wm831x->regmap;
Mark Brownc172708d2012-04-04 00:50:22 +0100853
854 dcdc->regulator = regulator_register(&dcdc->desc, &config);
Mark Brown13048502009-07-28 15:23:16 +0100855 if (IS_ERR(dcdc->regulator)) {
856 ret = PTR_ERR(dcdc->regulator);
857 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
858 id + 1, ret);
859 goto err;
860 }
861
862 irq = platform_get_irq_byname(pdev, "UV");
Mark Browndfda9c22011-03-01 16:50:43 +0000863 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq,
864 IRQF_TRIGGER_RISING, dcdc->name,
865 dcdc);
Mark Brown13048502009-07-28 15:23:16 +0100866 if (ret != 0) {
867 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
868 irq, ret);
869 goto err_regulator;
870 }
871
872 platform_set_drvdata(pdev, dcdc);
873
874 return 0;
875
876err_regulator:
877 regulator_unregister(dcdc->regulator);
878err:
Mark Brown13048502009-07-28 15:23:16 +0100879 return ret;
880}
881
882static __devexit int wm831x_boostp_remove(struct platform_device *pdev)
883{
884 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
Mark Brown13048502009-07-28 15:23:16 +0100885
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800886 platform_set_drvdata(pdev, NULL);
887
Mark Browndfda9c22011-03-01 16:50:43 +0000888 free_irq(platform_get_irq_byname(pdev, "UV"), dcdc);
Mark Brown13048502009-07-28 15:23:16 +0100889 regulator_unregister(dcdc->regulator);
Mark Brown13048502009-07-28 15:23:16 +0100890
891 return 0;
892}
893
894static struct platform_driver wm831x_boostp_driver = {
895 .probe = wm831x_boostp_probe,
896 .remove = __devexit_p(wm831x_boostp_remove),
897 .driver = {
898 .name = "wm831x-boostp",
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800899 .owner = THIS_MODULE,
Mark Brown13048502009-07-28 15:23:16 +0100900 },
901};
902
903/*
Mark Brown8267a9b2009-07-28 15:22:23 +0100904 * External Power Enable
905 *
906 * These aren't actually DCDCs but look like them in hardware so share
907 * code.
908 */
909
910#define WM831X_EPE_BASE 6
911
912static struct regulator_ops wm831x_epe_ops = {
Mark Brown3d138fc2012-04-15 12:38:42 +0100913 .is_enabled = regulator_is_enabled_regmap,
914 .enable = regulator_enable_regmap,
915 .disable = regulator_disable_regmap,
Mark Brown8267a9b2009-07-28 15:22:23 +0100916 .get_status = wm831x_dcdc_get_status,
917};
918
919static __devinit int wm831x_epe_probe(struct platform_device *pdev)
920{
921 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
922 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
Mark Brownc172708d2012-04-04 00:50:22 +0100923 struct regulator_config config = { };
Mark Brown8267a9b2009-07-28 15:22:23 +0100924 int id = pdev->id % ARRAY_SIZE(pdata->epe);
925 struct wm831x_dcdc *dcdc;
926 int ret;
927
928 dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1);
929
Axel Lin4c601652012-03-23 17:00:01 +0800930 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
Mark Brown8267a9b2009-07-28 15:22:23 +0100931 if (dcdc == NULL) {
932 dev_err(&pdev->dev, "Unable to allocate private data\n");
933 return -ENOMEM;
934 }
935
936 dcdc->wm831x = wm831x;
937
938 /* For current parts this is correct; probably need to revisit
939 * in future.
940 */
941 snprintf(dcdc->name, sizeof(dcdc->name), "EPE%d", id + 1);
942 dcdc->desc.name = dcdc->name;
943 dcdc->desc.id = id + WM831X_EPE_BASE; /* Offset in DCDC registers */
944 dcdc->desc.ops = &wm831x_epe_ops;
945 dcdc->desc.type = REGULATOR_VOLTAGE;
946 dcdc->desc.owner = THIS_MODULE;
Mark Brown3d138fc2012-04-15 12:38:42 +0100947 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
948 dcdc->desc.enable_mask = 1 << dcdc->desc.id;
Mark Brown8267a9b2009-07-28 15:22:23 +0100949
Mark Brownc172708d2012-04-04 00:50:22 +0100950 config.dev = pdev->dev.parent;
Mark Brownb7ca8782012-05-10 00:41:02 +0100951 if (pdata)
952 config.init_data = pdata->epe[id];
Mark Brownc172708d2012-04-04 00:50:22 +0100953 config.driver_data = dcdc;
Mark Brown3d138fc2012-04-15 12:38:42 +0100954 config.regmap = wm831x->regmap;
Mark Brownc172708d2012-04-04 00:50:22 +0100955
956 dcdc->regulator = regulator_register(&dcdc->desc, &config);
Mark Brown8267a9b2009-07-28 15:22:23 +0100957 if (IS_ERR(dcdc->regulator)) {
958 ret = PTR_ERR(dcdc->regulator);
959 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n",
960 id + 1, ret);
961 goto err;
962 }
963
964 platform_set_drvdata(pdev, dcdc);
965
966 return 0;
967
968err:
Mark Brown8267a9b2009-07-28 15:22:23 +0100969 return ret;
970}
971
972static __devexit int wm831x_epe_remove(struct platform_device *pdev)
973{
974 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
975
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800976 platform_set_drvdata(pdev, NULL);
Mark Brown8267a9b2009-07-28 15:22:23 +0100977 regulator_unregister(dcdc->regulator);
Mark Brown8267a9b2009-07-28 15:22:23 +0100978
979 return 0;
980}
981
982static struct platform_driver wm831x_epe_driver = {
983 .probe = wm831x_epe_probe,
984 .remove = __devexit_p(wm831x_epe_remove),
985 .driver = {
986 .name = "wm831x-epe",
Dmitry Torokhoveb66d562010-02-23 23:38:39 -0800987 .owner = THIS_MODULE,
Mark Brown8267a9b2009-07-28 15:22:23 +0100988 },
989};
990
Mark Browne4ee8312009-07-28 15:21:49 +0100991static int __init wm831x_dcdc_init(void)
992{
993 int ret;
994 ret = platform_driver_register(&wm831x_buckv_driver);
995 if (ret != 0)
996 pr_err("Failed to register WM831x BUCKV driver: %d\n", ret);
997
998 ret = platform_driver_register(&wm831x_buckp_driver);
999 if (ret != 0)
1000 pr_err("Failed to register WM831x BUCKP driver: %d\n", ret);
1001
Mark Brown13048502009-07-28 15:23:16 +01001002 ret = platform_driver_register(&wm831x_boostp_driver);
1003 if (ret != 0)
1004 pr_err("Failed to register WM831x BOOST driver: %d\n", ret);
1005
Mark Brown8267a9b2009-07-28 15:22:23 +01001006 ret = platform_driver_register(&wm831x_epe_driver);
1007 if (ret != 0)
1008 pr_err("Failed to register WM831x EPE driver: %d\n", ret);
1009
Mark Browne4ee8312009-07-28 15:21:49 +01001010 return 0;
1011}
1012subsys_initcall(wm831x_dcdc_init);
1013
1014static void __exit wm831x_dcdc_exit(void)
1015{
Mark Brown8267a9b2009-07-28 15:22:23 +01001016 platform_driver_unregister(&wm831x_epe_driver);
Mark Brown13048502009-07-28 15:23:16 +01001017 platform_driver_unregister(&wm831x_boostp_driver);
Mark Browne4ee8312009-07-28 15:21:49 +01001018 platform_driver_unregister(&wm831x_buckp_driver);
1019 platform_driver_unregister(&wm831x_buckv_driver);
1020}
1021module_exit(wm831x_dcdc_exit);
1022
1023/* Module information */
1024MODULE_AUTHOR("Mark Brown");
1025MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
1026MODULE_LICENSE("GPL");
1027MODULE_ALIAS("platform:wm831x-buckv");
1028MODULE_ALIAS("platform:wm831x-buckp");
Mark Brown24b43152011-07-25 22:20:31 +01001029MODULE_ALIAS("platform:wm831x-epe");