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 int wm831x_buckv_list_voltage(struct regulator_dev *rdev,
213 if (selector <= WM831X_BUCKV_MAX_SELECTOR)
214 return 600000 + ((selector - 0x8) * 12500);
218 static int wm831x_buckv_map_voltage(struct regulator_dev *rdev,
219 int min_uV, int max_uV)
225 else if (min_uV <= 1800000)
226 vsel = DIV_ROUND_UP(min_uV - 600000, 12500) + 8;
230 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
236 static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
238 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
240 if (state == dcdc->dvs_gpio_state)
243 dcdc->dvs_gpio_state = state;
244 gpio_set_value(dcdc->dvs_gpio, state);
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.
254 static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
257 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
258 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;
263 /* If this value is already set then do a GPIO update if we can */
264 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel)
265 return wm831x_buckv_set_dvs(rdev, 0);
267 if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel)
268 return wm831x_buckv_set_dvs(rdev, 1);
270 /* Always set the ON status to the minimum voltage */
271 ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel);
274 dcdc->on_vsel = vsel;
279 /* Kick the voltage transition now */
280 ret = wm831x_buckv_set_dvs(rdev, 0);
285 * If this VSEL is higher than the last one we've seen then
286 * remember it as the DVS VSEL. This is optimised for CPUfreq
287 * usage where we want to get to the highest voltage very
290 if (vsel > dcdc->dvs_vsel) {
291 ret = wm831x_set_bits(wm831x, dvs_reg,
292 WM831X_DC1_DVS_VSEL_MASK,
295 dcdc->dvs_vsel = vsel;
297 dev_warn(wm831x->dev,
298 "Failed to set DCDC DVS VSEL: %d\n", ret);
304 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
307 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
308 struct wm831x *wm831x = dcdc->wm831x;
309 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
312 vsel = wm831x_buckv_map_voltage(rdev, uV, uV);
316 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel);
319 static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
321 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
323 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state)
324 return dcdc->dvs_vsel;
326 return dcdc->on_vsel;
329 /* Current limit options */
330 static u16 wm831x_dcdc_ilim[] = {
331 125, 250, 375, 500, 625, 750, 875, 1000
334 static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
335 int min_uA, int max_uA)
337 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
338 struct wm831x *wm831x = dcdc->wm831x;
339 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
342 for (i = ARRAY_SIZE(wm831x_dcdc_ilim) - 1; i >= 0; i--) {
343 if ((min_uA <= wm831x_dcdc_ilim[i]) &&
344 (wm831x_dcdc_ilim[i] <= max_uA))
345 return wm831x_set_bits(wm831x, reg,
346 WM831X_DC1_HC_THR_MASK,
347 i << WM831X_DC1_HC_THR_SHIFT);
353 static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
355 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
356 struct wm831x *wm831x = dcdc->wm831x;
357 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
360 val = wm831x_reg_read(wm831x, reg);
364 val = (val & WM831X_DC1_HC_THR_MASK) >> WM831X_DC1_HC_THR_SHIFT;
365 return wm831x_dcdc_ilim[val];
368 static const struct regulator_ops wm831x_buckv_ops = {
369 .set_voltage_sel = wm831x_buckv_set_voltage_sel,
370 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
371 .list_voltage = wm831x_buckv_list_voltage,
372 .map_voltage = wm831x_buckv_map_voltage,
373 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
374 .set_current_limit = wm831x_buckv_set_current_limit,
375 .get_current_limit = wm831x_buckv_get_current_limit,
377 .is_enabled = regulator_is_enabled_regmap,
378 .enable = regulator_enable_regmap,
379 .disable = regulator_disable_regmap,
380 .get_status = wm831x_dcdc_get_status,
381 .get_mode = wm831x_dcdc_get_mode,
382 .set_mode = wm831x_dcdc_set_mode,
383 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
387 * Set up DVS control. We just log errors since we can still run
388 * (with reduced performance) if we fail.
390 static void wm831x_buckv_dvs_init(struct platform_device *pdev,
391 struct wm831x_dcdc *dcdc,
392 struct wm831x_buckv_pdata *pdata)
394 struct wm831x *wm831x = dcdc->wm831x;
398 if (!pdata || !pdata->dvs_gpio)
401 /* gpiolib won't let us read the GPIO status so pick the higher
402 * of the two existing voltages so we take it as platform data.
404 dcdc->dvs_gpio_state = pdata->dvs_init_state;
406 ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio,
407 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0,
410 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n",
415 dcdc->dvs_gpio = pdata->dvs_gpio;
417 switch (pdata->dvs_control_src) {
419 ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT;
422 ctrl = 3 << WM831X_DC1_DVS_SRC_SHIFT;
425 dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n",
426 pdata->dvs_control_src, dcdc->name);
430 /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL
431 * to make bootstrapping a bit smoother.
433 if (!dcdc->dvs_vsel) {
434 ret = wm831x_set_bits(wm831x,
435 dcdc->base + WM831X_DCDC_DVS_CONTROL,
436 WM831X_DC1_DVS_VSEL_MASK, dcdc->on_vsel);
438 dcdc->dvs_vsel = dcdc->on_vsel;
440 dev_warn(wm831x->dev, "Failed to set DVS_VSEL: %d\n",
444 ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL,
445 WM831X_DC1_DVS_SRC_MASK, ctrl);
447 dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n",
452 static int wm831x_buckv_probe(struct platform_device *pdev)
454 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
455 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
456 struct regulator_config config = { };
458 struct wm831x_dcdc *dcdc;
459 struct resource *res;
462 if (pdata && pdata->wm831x_num)
463 id = (pdata->wm831x_num * 10) + 1;
468 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
470 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
475 dcdc->wm831x = wm831x;
477 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
479 dev_err(&pdev->dev, "No REG resource\n");
483 dcdc->base = res->start;
485 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
486 dcdc->desc.name = dcdc->name;
488 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name),
490 dcdc->desc.supply_name = dcdc->supply_name;
493 dcdc->desc.type = REGULATOR_VOLTAGE;
494 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1;
495 dcdc->desc.ops = &wm831x_buckv_ops;
496 dcdc->desc.owner = THIS_MODULE;
497 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
498 dcdc->desc.enable_mask = 1 << id;
500 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
502 dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret);
505 dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK;
507 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL);
509 dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret);
512 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
514 if (pdata && pdata->dcdc[id])
515 wm831x_buckv_dvs_init(pdev, dcdc,
516 pdata->dcdc[id]->driver_data);
518 config.dev = pdev->dev.parent;
520 config.init_data = pdata->dcdc[id];
521 config.driver_data = dcdc;
522 config.regmap = wm831x->regmap;
524 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
526 if (IS_ERR(dcdc->regulator)) {
527 ret = PTR_ERR(dcdc->regulator);
528 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
533 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
534 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
536 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
539 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
544 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC"));
545 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
547 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
550 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n",
555 platform_set_drvdata(pdev, dcdc);
563 static struct platform_driver wm831x_buckv_driver = {
564 .probe = wm831x_buckv_probe,
566 .name = "wm831x-buckv",
574 static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, int uV)
576 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
577 struct wm831x *wm831x = dcdc->wm831x;
578 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
581 sel = regulator_map_voltage_linear(rdev, uV, uV);
585 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, sel);
588 static const struct regulator_ops wm831x_buckp_ops = {
589 .set_voltage_sel = regulator_set_voltage_sel_regmap,
590 .get_voltage_sel = regulator_get_voltage_sel_regmap,
591 .list_voltage = regulator_list_voltage_linear,
592 .map_voltage = regulator_map_voltage_linear,
593 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
595 .is_enabled = regulator_is_enabled_regmap,
596 .enable = regulator_enable_regmap,
597 .disable = regulator_disable_regmap,
598 .get_status = wm831x_dcdc_get_status,
599 .get_mode = wm831x_dcdc_get_mode,
600 .set_mode = wm831x_dcdc_set_mode,
601 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
604 static int wm831x_buckp_probe(struct platform_device *pdev)
606 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
607 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
608 struct regulator_config config = { };
610 struct wm831x_dcdc *dcdc;
611 struct resource *res;
614 if (pdata && pdata->wm831x_num)
615 id = (pdata->wm831x_num * 10) + 1;
620 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
622 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
627 dcdc->wm831x = wm831x;
629 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
631 dev_err(&pdev->dev, "No REG resource\n");
635 dcdc->base = res->start;
637 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
638 dcdc->desc.name = dcdc->name;
640 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name),
642 dcdc->desc.supply_name = dcdc->supply_name;
645 dcdc->desc.type = REGULATOR_VOLTAGE;
646 dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1;
647 dcdc->desc.ops = &wm831x_buckp_ops;
648 dcdc->desc.owner = THIS_MODULE;
649 dcdc->desc.vsel_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
650 dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK;
651 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
652 dcdc->desc.enable_mask = 1 << id;
653 dcdc->desc.min_uV = 850000;
654 dcdc->desc.uV_step = 25000;
656 config.dev = pdev->dev.parent;
658 config.init_data = pdata->dcdc[id];
659 config.driver_data = dcdc;
660 config.regmap = wm831x->regmap;
662 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
664 if (IS_ERR(dcdc->regulator)) {
665 ret = PTR_ERR(dcdc->regulator);
666 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
671 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
672 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
674 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
677 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
682 platform_set_drvdata(pdev, dcdc);
690 static struct platform_driver wm831x_buckp_driver = {
691 .probe = wm831x_buckp_probe,
693 .name = "wm831x-buckp",
698 * DCDC boost convertors
701 static int wm831x_boostp_get_status(struct regulator_dev *rdev)
703 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
704 struct wm831x *wm831x = dcdc->wm831x;
707 /* First, check for errors */
708 ret = wm831x_reg_read(wm831x, WM831X_DCDC_UV_STATUS);
712 if (ret & (1 << rdev_get_id(rdev))) {
713 dev_dbg(wm831x->dev, "DCDC%d under voltage\n",
714 rdev_get_id(rdev) + 1);
715 return REGULATOR_STATUS_ERROR;
718 /* Is the regulator on? */
719 ret = wm831x_reg_read(wm831x, WM831X_DCDC_STATUS);
722 if (ret & (1 << rdev_get_id(rdev)))
723 return REGULATOR_STATUS_ON;
725 return REGULATOR_STATUS_OFF;
728 static const struct regulator_ops wm831x_boostp_ops = {
729 .get_status = wm831x_boostp_get_status,
731 .is_enabled = regulator_is_enabled_regmap,
732 .enable = regulator_enable_regmap,
733 .disable = regulator_disable_regmap,
736 static int wm831x_boostp_probe(struct platform_device *pdev)
738 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
739 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
740 struct regulator_config config = { };
741 int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
742 struct wm831x_dcdc *dcdc;
743 struct resource *res;
746 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
748 if (pdata == NULL || pdata->dcdc[id] == NULL)
751 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
755 dcdc->wm831x = wm831x;
757 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
759 dev_err(&pdev->dev, "No REG resource\n");
762 dcdc->base = res->start;
764 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
765 dcdc->desc.name = dcdc->name;
767 dcdc->desc.type = REGULATOR_VOLTAGE;
768 dcdc->desc.ops = &wm831x_boostp_ops;
769 dcdc->desc.owner = THIS_MODULE;
770 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
771 dcdc->desc.enable_mask = 1 << id;
773 config.dev = pdev->dev.parent;
775 config.init_data = pdata->dcdc[id];
776 config.driver_data = dcdc;
777 config.regmap = wm831x->regmap;
779 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
781 if (IS_ERR(dcdc->regulator)) {
782 ret = PTR_ERR(dcdc->regulator);
783 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
788 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
789 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
791 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
795 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
800 platform_set_drvdata(pdev, dcdc);
805 static struct platform_driver wm831x_boostp_driver = {
806 .probe = wm831x_boostp_probe,
808 .name = "wm831x-boostp",
813 * External Power Enable
815 * These aren't actually DCDCs but look like them in hardware so share
819 #define WM831X_EPE_BASE 6
821 static const struct regulator_ops wm831x_epe_ops = {
822 .is_enabled = regulator_is_enabled_regmap,
823 .enable = regulator_enable_regmap,
824 .disable = regulator_disable_regmap,
825 .get_status = wm831x_dcdc_get_status,
828 static int wm831x_epe_probe(struct platform_device *pdev)
830 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
831 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
832 struct regulator_config config = { };
833 int id = pdev->id % ARRAY_SIZE(pdata->epe);
834 struct wm831x_dcdc *dcdc;
837 dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1);
839 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
843 dcdc->wm831x = wm831x;
845 /* For current parts this is correct; probably need to revisit
848 snprintf(dcdc->name, sizeof(dcdc->name), "EPE%d", id + 1);
849 dcdc->desc.name = dcdc->name;
850 dcdc->desc.id = id + WM831X_EPE_BASE; /* Offset in DCDC registers */
851 dcdc->desc.ops = &wm831x_epe_ops;
852 dcdc->desc.type = REGULATOR_VOLTAGE;
853 dcdc->desc.owner = THIS_MODULE;
854 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
855 dcdc->desc.enable_mask = 1 << dcdc->desc.id;
857 config.dev = pdev->dev.parent;
859 config.init_data = pdata->epe[id];
860 config.driver_data = dcdc;
861 config.regmap = wm831x->regmap;
863 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
865 if (IS_ERR(dcdc->regulator)) {
866 ret = PTR_ERR(dcdc->regulator);
867 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n",
872 platform_set_drvdata(pdev, dcdc);
880 static struct platform_driver wm831x_epe_driver = {
881 .probe = wm831x_epe_probe,
883 .name = "wm831x-epe",
887 static struct platform_driver * const drivers[] = {
888 &wm831x_buckv_driver,
889 &wm831x_buckp_driver,
890 &wm831x_boostp_driver,
894 static int __init wm831x_dcdc_init(void)
896 return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
898 subsys_initcall(wm831x_dcdc_init);
900 static void __exit wm831x_dcdc_exit(void)
902 platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
904 module_exit(wm831x_dcdc_exit);
906 /* Module information */
907 MODULE_AUTHOR("Mark Brown");
908 MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
909 MODULE_LICENSE("GPL");
910 MODULE_ALIAS("platform:wm831x-buckv");
911 MODULE_ALIAS("platform:wm831x-buckp");
912 MODULE_ALIAS("platform:wm831x-boostp");
913 MODULE_ALIAS("platform:wm831x-epe");