2 * wm8994-regulator.c -- Regulator driver for the WM8994
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/platform_device.h>
20 #include <linux/regulator/driver.h>
21 #include <linux/gpio.h>
22 #include <linux/slab.h>
24 #include <linux/mfd/wm8994/core.h>
25 #include <linux/mfd/wm8994/registers.h>
26 #include <linux/mfd/wm8994/pdata.h>
29 struct regulator_dev *regulator;
30 struct wm8994 *wm8994;
33 #define WM8994_LDO1_MAX_SELECTOR 0x7
34 #define WM8994_LDO2_MAX_SELECTOR 0x3
36 static struct regulator_ops wm8994_ldo1_ops = {
37 .list_voltage = regulator_list_voltage_linear,
38 .map_voltage = regulator_map_voltage_linear,
39 .get_voltage_sel = regulator_get_voltage_sel_regmap,
40 .set_voltage_sel = regulator_set_voltage_sel_regmap,
43 static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
44 unsigned int selector)
46 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
48 if (selector > WM8994_LDO2_MAX_SELECTOR)
51 switch (ldo->wm8994->type) {
53 return (selector * 100000) + 900000;
55 return (selector * 100000) + 1000000;
61 return (selector * 100000) + 950000;
69 static struct regulator_ops wm8994_ldo2_ops = {
70 .list_voltage = wm8994_ldo2_list_voltage,
71 .get_voltage_sel = regulator_get_voltage_sel_regmap,
72 .set_voltage_sel = regulator_set_voltage_sel_regmap,
75 static const struct regulator_desc wm8994_ldo_desc[] = {
79 .type = REGULATOR_VOLTAGE,
80 .n_voltages = WM8994_LDO1_MAX_SELECTOR + 1,
81 .vsel_reg = WM8994_LDO_1,
82 .vsel_mask = WM8994_LDO1_VSEL_MASK,
83 .ops = &wm8994_ldo1_ops,
92 .type = REGULATOR_VOLTAGE,
93 .n_voltages = WM8994_LDO2_MAX_SELECTOR + 1,
94 .vsel_reg = WM8994_LDO_2,
95 .vsel_mask = WM8994_LDO2_VSEL_MASK,
96 .ops = &wm8994_ldo2_ops,
102 static int wm8994_ldo_probe(struct platform_device *pdev)
104 struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
105 struct wm8994_pdata *pdata = wm8994->dev->platform_data;
106 int id = pdev->id % ARRAY_SIZE(pdata->ldo);
107 struct regulator_config config = { };
108 struct wm8994_ldo *ldo;
111 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
113 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL);
115 dev_err(&pdev->dev, "Unable to allocate private data\n");
119 ldo->wm8994 = wm8994;
121 config.dev = wm8994->dev;
122 config.driver_data = ldo;
123 config.regmap = wm8994->regmap;
125 config.init_data = pdata->ldo[id].init_data;
126 config.ena_gpio = pdata->ldo[id].enable;
129 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config);
130 if (IS_ERR(ldo->regulator)) {
131 ret = PTR_ERR(ldo->regulator);
132 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
137 platform_set_drvdata(pdev, ldo);
145 static int wm8994_ldo_remove(struct platform_device *pdev)
147 struct wm8994_ldo *ldo = platform_get_drvdata(pdev);
149 platform_set_drvdata(pdev, NULL);
151 regulator_unregister(ldo->regulator);
156 static struct platform_driver wm8994_ldo_driver = {
157 .probe = wm8994_ldo_probe,
158 .remove = wm8994_ldo_remove,
160 .name = "wm8994-ldo",
161 .owner = THIS_MODULE,
165 static int __init wm8994_ldo_init(void)
169 ret = platform_driver_register(&wm8994_ldo_driver);
171 pr_err("Failed to register Wm8994 GP LDO driver: %d\n", ret);
175 subsys_initcall(wm8994_ldo_init);
177 static void __exit wm8994_ldo_exit(void)
179 platform_driver_unregister(&wm8994_ldo_driver);
181 module_exit(wm8994_ldo_exit);
183 /* Module information */
184 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
185 MODULE_DESCRIPTION("WM8994 LDO driver");
186 MODULE_LICENSE("GPL");
187 MODULE_ALIAS("platform:wm8994-ldo");