aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-27 09:31:17 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-07-03 15:29:29 -0400
commit495fd8c8fdefebf545f8ea01d10ae7b812931c27 (patch)
tree2fc610c5c8ba567fc8d39ac49234dbfa479b9ac7 /drivers/regulator
parent25a53dfbfbfd10c52109ada40313e058b07b4b21 (diff)
regulator: wm8994: Use core GPIO enable support
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/wm8994-regulator.c68
1 files changed, 4 insertions, 64 deletions
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index a056cee7ed46..86bb48db149e 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -26,8 +26,6 @@
26#include <linux/mfd/wm8994/pdata.h> 26#include <linux/mfd/wm8994/pdata.h>
27 27
28struct wm8994_ldo { 28struct wm8994_ldo {
29 int enable;
30 bool is_enabled;
31 struct regulator_dev *regulator; 29 struct regulator_dev *regulator;
32 struct wm8994 *wm8994; 30 struct wm8994 *wm8994;
33}; 31};
@@ -35,46 +33,7 @@ struct wm8994_ldo {
35#define WM8994_LDO1_MAX_SELECTOR 0x7 33#define WM8994_LDO1_MAX_SELECTOR 0x7
36#define WM8994_LDO2_MAX_SELECTOR 0x3 34#define WM8994_LDO2_MAX_SELECTOR 0x3
37 35
38static int wm8994_ldo_enable(struct regulator_dev *rdev)
39{
40 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
41
42 /* If we have no soft control assume that the LDO is always enabled. */
43 if (!ldo->enable)
44 return 0;
45
46 gpio_set_value_cansleep(ldo->enable, 1);
47 ldo->is_enabled = true;
48
49 return 0;
50}
51
52static int wm8994_ldo_disable(struct regulator_dev *rdev)
53{
54 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
55
56 /* If we have no soft control assume that the LDO is always enabled. */
57 if (!ldo->enable)
58 return -EINVAL;
59
60 gpio_set_value_cansleep(ldo->enable, 0);
61 ldo->is_enabled = false;
62
63 return 0;
64}
65
66static int wm8994_ldo_is_enabled(struct regulator_dev *rdev)
67{
68 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
69
70 return ldo->is_enabled;
71}
72
73static struct regulator_ops wm8994_ldo1_ops = { 36static struct regulator_ops wm8994_ldo1_ops = {
74 .enable = wm8994_ldo_enable,
75 .disable = wm8994_ldo_disable,
76 .is_enabled = wm8994_ldo_is_enabled,
77
78 .list_voltage = regulator_list_voltage_linear, 37 .list_voltage = regulator_list_voltage_linear,
79 .map_voltage = regulator_map_voltage_linear, 38 .map_voltage = regulator_map_voltage_linear,
80 .get_voltage_sel = regulator_get_voltage_sel_regmap, 39 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -108,10 +67,6 @@ static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
108} 67}
109 68
110static struct regulator_ops wm8994_ldo2_ops = { 69static struct regulator_ops wm8994_ldo2_ops = {
111 .enable = wm8994_ldo_enable,
112 .disable = wm8994_ldo_disable,
113 .is_enabled = wm8994_ldo_is_enabled,
114
115 .list_voltage = wm8994_ldo2_list_voltage, 70 .list_voltage = wm8994_ldo2_list_voltage,
116 .get_voltage_sel = regulator_get_voltage_sel_regmap, 71 .get_voltage_sel = regulator_get_voltage_sel_regmap,
117 .set_voltage_sel = regulator_set_voltage_sel_regmap, 72 .set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -163,39 +118,26 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
163 118
164 ldo->wm8994 = wm8994; 119 ldo->wm8994 = wm8994;
165 120
166 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) {
167 ldo->enable = pdata->ldo[id].enable;
168
169 ret = gpio_request_one(ldo->enable, 0, "WM8994 LDO enable");
170 if (ret < 0) {
171 dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n",
172 ret);
173 goto err;
174 }
175 } else
176 ldo->is_enabled = true;
177
178 config.dev = wm8994->dev; 121 config.dev = wm8994->dev;
179 config.driver_data = ldo; 122 config.driver_data = ldo;
180 config.regmap = wm8994->regmap; 123 config.regmap = wm8994->regmap;
181 if (pdata) 124 if (pdata) {
182 config.init_data = pdata->ldo[id].init_data; 125 config.init_data = pdata->ldo[id].init_data;
126 config.ena_gpio = pdata->ldo[id].enable;
127 }
183 128
184 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); 129 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config);
185 if (IS_ERR(ldo->regulator)) { 130 if (IS_ERR(ldo->regulator)) {
186 ret = PTR_ERR(ldo->regulator); 131 ret = PTR_ERR(ldo->regulator);
187 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", 132 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
188 id + 1, ret); 133 id + 1, ret);
189 goto err_gpio; 134 goto err;
190 } 135 }
191 136
192 platform_set_drvdata(pdev, ldo); 137 platform_set_drvdata(pdev, ldo);
193 138
194 return 0; 139 return 0;
195 140
196err_gpio:
197 if (gpio_is_valid(ldo->enable))
198 gpio_free(ldo->enable);
199err: 141err:
200 return ret; 142 return ret;
201} 143}
@@ -207,8 +149,6 @@ static __devexit int wm8994_ldo_remove(struct platform_device *pdev)
207 platform_set_drvdata(pdev, NULL); 149 platform_set_drvdata(pdev, NULL);
208 150
209 regulator_unregister(ldo->regulator); 151 regulator_unregister(ldo->regulator);
210 if (gpio_is_valid(ldo->enable))
211 gpio_free(ldo->enable);
212 152
213 return 0; 153 return 0;
214} 154}