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>
24 #include <linux/slab.h>
26 #include <linux/mfd/wm831x/core.h>
27 #include <linux/mfd/wm831x/regulator.h>
28 #include <linux/mfd/wm831x/pdata.h>
30 #define WM831X_BUCKV_MAX_SELECTOR 0x68
31 #define WM831X_BUCKP_MAX_SELECTOR 0x66
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
38 #define WM831X_DCDC_MAX_NAME 9
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
45 #define WM831X_DCDC_DVS_CONTROL 4
52 char name
[WM831X_DCDC_MAX_NAME
];
53 char supply_name
[WM831X_DCDC_MAX_NAME
];
54 struct regulator_desc desc
;
56 struct wm831x
*wm831x
;
57 struct regulator_dev
*regulator
;
64 static unsigned int wm831x_dcdc_get_mode(struct regulator_dev
*rdev
)
67 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
68 struct wm831x
*wm831x
= dcdc
->wm831x
;
69 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
72 val
= wm831x_reg_read(wm831x
, reg
);
76 val
= (val
& WM831X_DC1_ON_MODE_MASK
) >> WM831X_DC1_ON_MODE_SHIFT
;
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
;
93 static int wm831x_dcdc_set_mode_int(struct wm831x
*wm831x
, int reg
,
99 case REGULATOR_MODE_FAST
:
100 val
= WM831X_DCDC_MODE_FAST
;
102 case REGULATOR_MODE_NORMAL
:
103 val
= WM831X_DCDC_MODE_NORMAL
;
105 case REGULATOR_MODE_STANDBY
:
106 val
= WM831X_DCDC_MODE_STANDBY
;
108 case REGULATOR_MODE_IDLE
:
109 val
= WM831X_DCDC_MODE_IDLE
;
115 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_ON_MODE_MASK
,
116 val
<< WM831X_DC1_ON_MODE_SHIFT
);
119 static int wm831x_dcdc_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
121 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
122 struct wm831x
*wm831x
= dcdc
->wm831x
;
123 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
125 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
128 static int wm831x_dcdc_set_suspend_mode(struct regulator_dev
*rdev
,
131 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
132 struct wm831x
*wm831x
= dcdc
->wm831x
;
133 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
135 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
138 static int wm831x_dcdc_get_status(struct regulator_dev
*rdev
)
140 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
141 struct wm831x
*wm831x
= dcdc
->wm831x
;
144 /* First, check for errors */
145 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
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
;
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
;
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
;
170 /* Is the regulator on? */
171 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
174 if (!(ret
& (1 << rdev_get_id(rdev
))))
175 return REGULATOR_STATUS_OFF
;
177 /* TODO: When we handle hardware control modes so we can report the
179 return REGULATOR_STATUS_ON
;
182 static irqreturn_t
wm831x_dcdc_uv_irq(int irq
, void *data
)
184 struct wm831x_dcdc
*dcdc
= data
;
186 regulator_notifier_call_chain(dcdc
->regulator
,
187 REGULATOR_EVENT_UNDER_VOLTAGE
,
193 static irqreturn_t
wm831x_dcdc_oc_irq(int irq
, void *data
)
195 struct wm831x_dcdc
*dcdc
= data
;
197 regulator_notifier_call_chain(dcdc
->regulator
,
198 REGULATOR_EVENT_OVER_CURRENT
,
208 static const struct regulator_linear_range wm831x_buckv_ranges
[] = {
209 REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
210 REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
213 static int wm831x_buckv_set_dvs(struct regulator_dev
*rdev
, int state
)
215 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
217 if (state
== dcdc
->dvs_gpio_state
)
220 dcdc
->dvs_gpio_state
= state
;
221 gpio_set_value(dcdc
->dvs_gpio
, state
);
223 /* Should wait for DVS state change to be asserted if we have
224 * a GPIO for it, for now assume the device is configured
225 * for the fastest possible transition.
231 static int wm831x_buckv_set_voltage_sel(struct regulator_dev
*rdev
,
234 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
235 struct wm831x
*wm831x
= dcdc
->wm831x
;
236 int on_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
237 int dvs_reg
= dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
;
240 /* If this value is already set then do a GPIO update if we can */
241 if (dcdc
->dvs_gpio
&& dcdc
->on_vsel
== vsel
)
242 return wm831x_buckv_set_dvs(rdev
, 0);
244 if (dcdc
->dvs_gpio
&& dcdc
->dvs_vsel
== vsel
)
245 return wm831x_buckv_set_dvs(rdev
, 1);
247 /* Always set the ON status to the minimum voltage */
248 ret
= wm831x_set_bits(wm831x
, on_reg
, WM831X_DC1_ON_VSEL_MASK
, vsel
);
251 dcdc
->on_vsel
= vsel
;
256 /* Kick the voltage transition now */
257 ret
= wm831x_buckv_set_dvs(rdev
, 0);
262 * If this VSEL is higher than the last one we've seen then
263 * remember it as the DVS VSEL. This is optimised for CPUfreq
264 * usage where we want to get to the highest voltage very
267 if (vsel
> dcdc
->dvs_vsel
) {
268 ret
= wm831x_set_bits(wm831x
, dvs_reg
,
269 WM831X_DC1_DVS_VSEL_MASK
,
272 dcdc
->dvs_vsel
= vsel
;
274 dev_warn(wm831x
->dev
,
275 "Failed to set DCDC DVS VSEL: %d\n", ret
);
281 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev
*rdev
,
284 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
285 struct wm831x
*wm831x
= dcdc
->wm831x
;
286 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
289 vsel
= regulator_map_voltage_linear_range(rdev
, uV
, uV
);
293 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_SLP_VSEL_MASK
, vsel
);
296 static int wm831x_buckv_get_voltage_sel(struct regulator_dev
*rdev
)
298 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
300 if (dcdc
->dvs_gpio
&& dcdc
->dvs_gpio_state
)
301 return dcdc
->dvs_vsel
;
303 return dcdc
->on_vsel
;
306 /* Current limit options */
307 static const unsigned int wm831x_dcdc_ilim
[] = {
308 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000
311 static const struct regulator_ops wm831x_buckv_ops
= {
312 .set_voltage_sel
= wm831x_buckv_set_voltage_sel
,
313 .get_voltage_sel
= wm831x_buckv_get_voltage_sel
,
314 .list_voltage
= regulator_list_voltage_linear_range
,
315 .map_voltage
= regulator_map_voltage_linear_range
,
316 .set_suspend_voltage
= wm831x_buckv_set_suspend_voltage
,
317 .set_current_limit
= regulator_set_current_limit_regmap
,
318 .get_current_limit
= regulator_get_current_limit_regmap
,
320 .is_enabled
= regulator_is_enabled_regmap
,
321 .enable
= regulator_enable_regmap
,
322 .disable
= regulator_disable_regmap
,
323 .get_status
= wm831x_dcdc_get_status
,
324 .get_mode
= wm831x_dcdc_get_mode
,
325 .set_mode
= wm831x_dcdc_set_mode
,
326 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
330 * Set up DVS control. We just log errors since we can still run
331 * (with reduced performance) if we fail.
333 static void wm831x_buckv_dvs_init(struct platform_device
*pdev
,
334 struct wm831x_dcdc
*dcdc
,
335 struct wm831x_buckv_pdata
*pdata
)
337 struct wm831x
*wm831x
= dcdc
->wm831x
;
341 if (!pdata
|| !pdata
->dvs_gpio
)
344 /* gpiolib won't let us read the GPIO status so pick the higher
345 * of the two existing voltages so we take it as platform data.
347 dcdc
->dvs_gpio_state
= pdata
->dvs_init_state
;
349 ret
= devm_gpio_request_one(&pdev
->dev
, pdata
->dvs_gpio
,
350 dcdc
->dvs_gpio_state
? GPIOF_INIT_HIGH
: 0,
353 dev_err(wm831x
->dev
, "Failed to get %s DVS GPIO: %d\n",
358 dcdc
->dvs_gpio
= pdata
->dvs_gpio
;
360 switch (pdata
->dvs_control_src
) {
362 ctrl
= 2 << WM831X_DC1_DVS_SRC_SHIFT
;
365 ctrl
= 3 << WM831X_DC1_DVS_SRC_SHIFT
;
368 dev_err(wm831x
->dev
, "Invalid DVS control source %d for %s\n",
369 pdata
->dvs_control_src
, dcdc
->name
);
373 /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL
374 * to make bootstrapping a bit smoother.
376 if (!dcdc
->dvs_vsel
) {
377 ret
= wm831x_set_bits(wm831x
,
378 dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
379 WM831X_DC1_DVS_VSEL_MASK
, dcdc
->on_vsel
);
381 dcdc
->dvs_vsel
= dcdc
->on_vsel
;
383 dev_warn(wm831x
->dev
, "Failed to set DVS_VSEL: %d\n",
387 ret
= wm831x_set_bits(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
388 WM831X_DC1_DVS_SRC_MASK
, ctrl
);
390 dev_err(wm831x
->dev
, "Failed to set %s DVS source: %d\n",
395 static int wm831x_buckv_probe(struct platform_device
*pdev
)
397 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
398 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
399 struct regulator_config config
= { };
401 struct wm831x_dcdc
*dcdc
;
402 struct resource
*res
;
405 if (pdata
&& pdata
->wm831x_num
)
406 id
= (pdata
->wm831x_num
* 10) + 1;
411 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
413 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
),
418 dcdc
->wm831x
= wm831x
;
420 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
422 dev_err(&pdev
->dev
, "No REG resource\n");
426 dcdc
->base
= res
->start
;
428 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
429 dcdc
->desc
.name
= dcdc
->name
;
431 snprintf(dcdc
->supply_name
, sizeof(dcdc
->supply_name
),
433 dcdc
->desc
.supply_name
= dcdc
->supply_name
;
436 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
437 dcdc
->desc
.n_voltages
= WM831X_BUCKV_MAX_SELECTOR
+ 1;
438 dcdc
->desc
.linear_ranges
= wm831x_buckv_ranges
;
439 dcdc
->desc
.n_linear_ranges
= ARRAY_SIZE(wm831x_buckv_ranges
);
440 dcdc
->desc
.ops
= &wm831x_buckv_ops
;
441 dcdc
->desc
.owner
= THIS_MODULE
;
442 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
443 dcdc
->desc
.enable_mask
= 1 << id
;
444 dcdc
->desc
.csel_reg
= dcdc
->base
+ WM831X_DCDC_CONTROL_2
;
445 dcdc
->desc
.csel_mask
= WM831X_DC1_HC_THR_MASK
;
446 dcdc
->desc
.n_current_limits
= ARRAY_SIZE(wm831x_dcdc_ilim
);
447 dcdc
->desc
.curr_table
= wm831x_dcdc_ilim
;
449 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_ON_CONFIG
);
451 dev_err(wm831x
->dev
, "Failed to read ON VSEL: %d\n", ret
);
454 dcdc
->on_vsel
= ret
& WM831X_DC1_ON_VSEL_MASK
;
456 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
);
458 dev_err(wm831x
->dev
, "Failed to read DVS VSEL: %d\n", ret
);
461 dcdc
->dvs_vsel
= ret
& WM831X_DC1_DVS_VSEL_MASK
;
463 if (pdata
&& pdata
->dcdc
[id
])
464 wm831x_buckv_dvs_init(pdev
, dcdc
,
465 pdata
->dcdc
[id
]->driver_data
);
467 config
.dev
= pdev
->dev
.parent
;
469 config
.init_data
= pdata
->dcdc
[id
];
470 config
.driver_data
= dcdc
;
471 config
.regmap
= wm831x
->regmap
;
473 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
475 if (IS_ERR(dcdc
->regulator
)) {
476 ret
= PTR_ERR(dcdc
->regulator
);
477 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
482 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
483 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
485 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
488 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
493 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "HC"));
494 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
496 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
499 dev_err(&pdev
->dev
, "Failed to request HC IRQ %d: %d\n",
504 platform_set_drvdata(pdev
, dcdc
);
512 static struct platform_driver wm831x_buckv_driver
= {
513 .probe
= wm831x_buckv_probe
,
515 .name
= "wm831x-buckv",
523 static int wm831x_buckp_set_suspend_voltage(struct regulator_dev
*rdev
, int uV
)
525 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
526 struct wm831x
*wm831x
= dcdc
->wm831x
;
527 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
530 sel
= regulator_map_voltage_linear(rdev
, uV
, uV
);
534 return wm831x_set_bits(wm831x
, reg
, WM831X_DC3_ON_VSEL_MASK
, sel
);
537 static const struct regulator_ops wm831x_buckp_ops
= {
538 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
539 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
540 .list_voltage
= regulator_list_voltage_linear
,
541 .map_voltage
= regulator_map_voltage_linear
,
542 .set_suspend_voltage
= wm831x_buckp_set_suspend_voltage
,
544 .is_enabled
= regulator_is_enabled_regmap
,
545 .enable
= regulator_enable_regmap
,
546 .disable
= regulator_disable_regmap
,
547 .get_status
= wm831x_dcdc_get_status
,
548 .get_mode
= wm831x_dcdc_get_mode
,
549 .set_mode
= wm831x_dcdc_set_mode
,
550 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
553 static int wm831x_buckp_probe(struct platform_device
*pdev
)
555 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
556 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
557 struct regulator_config config
= { };
559 struct wm831x_dcdc
*dcdc
;
560 struct resource
*res
;
563 if (pdata
&& pdata
->wm831x_num
)
564 id
= (pdata
->wm831x_num
* 10) + 1;
569 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
571 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
),
576 dcdc
->wm831x
= wm831x
;
578 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
580 dev_err(&pdev
->dev
, "No REG resource\n");
584 dcdc
->base
= res
->start
;
586 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
587 dcdc
->desc
.name
= dcdc
->name
;
589 snprintf(dcdc
->supply_name
, sizeof(dcdc
->supply_name
),
591 dcdc
->desc
.supply_name
= dcdc
->supply_name
;
594 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
595 dcdc
->desc
.n_voltages
= WM831X_BUCKP_MAX_SELECTOR
+ 1;
596 dcdc
->desc
.ops
= &wm831x_buckp_ops
;
597 dcdc
->desc
.owner
= THIS_MODULE
;
598 dcdc
->desc
.vsel_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
599 dcdc
->desc
.vsel_mask
= WM831X_DC3_ON_VSEL_MASK
;
600 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
601 dcdc
->desc
.enable_mask
= 1 << id
;
602 dcdc
->desc
.min_uV
= 850000;
603 dcdc
->desc
.uV_step
= 25000;
605 config
.dev
= pdev
->dev
.parent
;
607 config
.init_data
= pdata
->dcdc
[id
];
608 config
.driver_data
= dcdc
;
609 config
.regmap
= wm831x
->regmap
;
611 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
613 if (IS_ERR(dcdc
->regulator
)) {
614 ret
= PTR_ERR(dcdc
->regulator
);
615 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
620 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
621 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
623 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
626 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
631 platform_set_drvdata(pdev
, dcdc
);
639 static struct platform_driver wm831x_buckp_driver
= {
640 .probe
= wm831x_buckp_probe
,
642 .name
= "wm831x-buckp",
647 * DCDC boost convertors
650 static int wm831x_boostp_get_status(struct regulator_dev
*rdev
)
652 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
653 struct wm831x
*wm831x
= dcdc
->wm831x
;
656 /* First, check for errors */
657 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
661 if (ret
& (1 << rdev_get_id(rdev
))) {
662 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
663 rdev_get_id(rdev
) + 1);
664 return REGULATOR_STATUS_ERROR
;
667 /* Is the regulator on? */
668 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
671 if (ret
& (1 << rdev_get_id(rdev
)))
672 return REGULATOR_STATUS_ON
;
674 return REGULATOR_STATUS_OFF
;
677 static const struct regulator_ops wm831x_boostp_ops
= {
678 .get_status
= wm831x_boostp_get_status
,
680 .is_enabled
= regulator_is_enabled_regmap
,
681 .enable
= regulator_enable_regmap
,
682 .disable
= regulator_disable_regmap
,
685 static int wm831x_boostp_probe(struct platform_device
*pdev
)
687 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
688 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
689 struct regulator_config config
= { };
690 int id
= pdev
->id
% ARRAY_SIZE(pdata
->dcdc
);
691 struct wm831x_dcdc
*dcdc
;
692 struct resource
*res
;
695 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
697 if (pdata
== NULL
|| pdata
->dcdc
[id
] == NULL
)
700 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
704 dcdc
->wm831x
= wm831x
;
706 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
708 dev_err(&pdev
->dev
, "No REG resource\n");
711 dcdc
->base
= res
->start
;
713 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
714 dcdc
->desc
.name
= dcdc
->name
;
716 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
717 dcdc
->desc
.ops
= &wm831x_boostp_ops
;
718 dcdc
->desc
.owner
= THIS_MODULE
;
719 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
720 dcdc
->desc
.enable_mask
= 1 << id
;
722 config
.dev
= pdev
->dev
.parent
;
724 config
.init_data
= pdata
->dcdc
[id
];
725 config
.driver_data
= dcdc
;
726 config
.regmap
= wm831x
->regmap
;
728 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
730 if (IS_ERR(dcdc
->regulator
)) {
731 ret
= PTR_ERR(dcdc
->regulator
);
732 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
737 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
738 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
740 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
744 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
749 platform_set_drvdata(pdev
, dcdc
);
754 static struct platform_driver wm831x_boostp_driver
= {
755 .probe
= wm831x_boostp_probe
,
757 .name
= "wm831x-boostp",
762 * External Power Enable
764 * These aren't actually DCDCs but look like them in hardware so share
768 #define WM831X_EPE_BASE 6
770 static const struct regulator_ops wm831x_epe_ops
= {
771 .is_enabled
= regulator_is_enabled_regmap
,
772 .enable
= regulator_enable_regmap
,
773 .disable
= regulator_disable_regmap
,
774 .get_status
= wm831x_dcdc_get_status
,
777 static int wm831x_epe_probe(struct platform_device
*pdev
)
779 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
780 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
781 struct regulator_config config
= { };
782 int id
= pdev
->id
% ARRAY_SIZE(pdata
->epe
);
783 struct wm831x_dcdc
*dcdc
;
786 dev_dbg(&pdev
->dev
, "Probing EPE%d\n", id
+ 1);
788 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
792 dcdc
->wm831x
= wm831x
;
794 /* For current parts this is correct; probably need to revisit
797 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "EPE%d", id
+ 1);
798 dcdc
->desc
.name
= dcdc
->name
;
799 dcdc
->desc
.id
= id
+ WM831X_EPE_BASE
; /* Offset in DCDC registers */
800 dcdc
->desc
.ops
= &wm831x_epe_ops
;
801 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
802 dcdc
->desc
.owner
= THIS_MODULE
;
803 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
804 dcdc
->desc
.enable_mask
= 1 << dcdc
->desc
.id
;
806 config
.dev
= pdev
->dev
.parent
;
808 config
.init_data
= pdata
->epe
[id
];
809 config
.driver_data
= dcdc
;
810 config
.regmap
= wm831x
->regmap
;
812 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
814 if (IS_ERR(dcdc
->regulator
)) {
815 ret
= PTR_ERR(dcdc
->regulator
);
816 dev_err(wm831x
->dev
, "Failed to register EPE%d: %d\n",
821 platform_set_drvdata(pdev
, dcdc
);
829 static struct platform_driver wm831x_epe_driver
= {
830 .probe
= wm831x_epe_probe
,
832 .name
= "wm831x-epe",
836 static struct platform_driver
* const drivers
[] = {
837 &wm831x_buckv_driver
,
838 &wm831x_buckp_driver
,
839 &wm831x_boostp_driver
,
843 static int __init
wm831x_dcdc_init(void)
845 return platform_register_drivers(drivers
, ARRAY_SIZE(drivers
));
847 subsys_initcall(wm831x_dcdc_init
);
849 static void __exit
wm831x_dcdc_exit(void)
851 platform_unregister_drivers(drivers
, ARRAY_SIZE(drivers
));
853 module_exit(wm831x_dcdc_exit
);
855 /* Module information */
856 MODULE_AUTHOR("Mark Brown");
857 MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
858 MODULE_LICENSE("GPL");
859 MODULE_ALIAS("platform:wm831x-buckv");
860 MODULE_ALIAS("platform:wm831x-buckp");
861 MODULE_ALIAS("platform:wm831x-boostp");
862 MODULE_ALIAS("platform:wm831x-epe");