diff options
author | Axel Lin <axel.lin@ingics.com> | 2013-01-05 02:33:43 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-01-07 06:13:08 -0500 |
commit | b9bb09111a4f5dbf8a0bd7df77ec79d3fdf9e5d2 (patch) | |
tree | 90d54e6b8a6c3369dc585f5f6f1de6fd324c7aa5 /drivers/regulator | |
parent | f02a3917b3bc65149cc077396896f2ae5a2fbe4a (diff) |
regulator: lp8788-ldo: Use ldo->en_pin to check if regulator is enabled by external pin
ldo->en_pin is set iff the regulator is enabled by external pin.
This patch sets ldo->en_pin to NULL if lp8788_gpio_request_ldo_en() fails, then
we can use it to determinate if the regulator is controlled by external pin or
register.
lp8788_get_ldo_enable_mode(), lp8788_ldo_ctrl_by_extern_pin() and
lp8788_ldo_is_enabled_by_extern_pin() functions are not used now, remove them.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Milo Kim <milo.kim@ti.com>
Tested-by: Milo Kim <milo.kim@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/lp8788-ldo.c | 107 |
1 files changed, 14 insertions, 93 deletions
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c index 416bb6088ab5..cd5a14ad9263 100644 --- a/drivers/regulator/lp8788-ldo.c +++ b/drivers/regulator/lp8788-ldo.c | |||
@@ -88,11 +88,6 @@ | |||
88 | #define ENABLE GPIOF_OUT_INIT_HIGH | 88 | #define ENABLE GPIOF_OUT_INIT_HIGH |
89 | #define DISABLE GPIOF_OUT_INIT_LOW | 89 | #define DISABLE GPIOF_OUT_INIT_LOW |
90 | 90 | ||
91 | enum lp8788_enable_mode { | ||
92 | REGISTER, | ||
93 | EXTPIN, | ||
94 | }; | ||
95 | |||
96 | enum lp8788_ldo_id { | 91 | enum lp8788_ldo_id { |
97 | DLDO1, | 92 | DLDO1, |
98 | DLDO2, | 93 | DLDO2, |
@@ -189,114 +184,38 @@ static enum lp8788_ldo_id lp8788_aldo_id[] = { | |||
189 | ALDO10, | 184 | ALDO10, |
190 | }; | 185 | }; |
191 | 186 | ||
192 | /* DLDO 7, 9 and 11, ALDO 1 ~ 5 and 7 | ||
193 | : can be enabled either by external pin or by i2c register */ | ||
194 | static enum lp8788_enable_mode | ||
195 | lp8788_get_ldo_enable_mode(struct lp8788_ldo *ldo, enum lp8788_ldo_id id) | ||
196 | { | ||
197 | int ret; | ||
198 | u8 val, mask; | ||
199 | |||
200 | ret = lp8788_read_byte(ldo->lp, LP8788_EN_SEL, &val); | ||
201 | if (ret) | ||
202 | return ret; | ||
203 | |||
204 | switch (id) { | ||
205 | case DLDO7: | ||
206 | mask = LP8788_EN_SEL_DLDO7_M; | ||
207 | break; | ||
208 | case DLDO9: | ||
209 | case DLDO11: | ||
210 | mask = LP8788_EN_SEL_DLDO911_M; | ||
211 | break; | ||
212 | case ALDO1: | ||
213 | mask = LP8788_EN_SEL_ALDO1_M; | ||
214 | break; | ||
215 | case ALDO2 ... ALDO4: | ||
216 | mask = LP8788_EN_SEL_ALDO234_M; | ||
217 | break; | ||
218 | case ALDO5: | ||
219 | mask = LP8788_EN_SEL_ALDO5_M; | ||
220 | break; | ||
221 | case ALDO7: | ||
222 | mask = LP8788_EN_SEL_ALDO7_M; | ||
223 | break; | ||
224 | default: | ||
225 | return REGISTER; | ||
226 | } | ||
227 | |||
228 | return val & mask ? EXTPIN : REGISTER; | ||
229 | } | ||
230 | |||
231 | static int lp8788_ldo_ctrl_by_extern_pin(struct lp8788_ldo *ldo, int pinstate) | ||
232 | { | ||
233 | struct lp8788_ldo_enable_pin *pin = ldo->en_pin; | ||
234 | |||
235 | if (!pin) | ||
236 | return -EINVAL; | ||
237 | |||
238 | if (gpio_is_valid(pin->gpio)) | ||
239 | gpio_set_value(pin->gpio, pinstate); | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int lp8788_ldo_is_enabled_by_extern_pin(struct lp8788_ldo *ldo) | ||
245 | { | ||
246 | struct lp8788_ldo_enable_pin *pin = ldo->en_pin; | ||
247 | |||
248 | if (!pin) | ||
249 | return -EINVAL; | ||
250 | |||
251 | return gpio_get_value(pin->gpio) ? 1 : 0; | ||
252 | } | ||
253 | |||
254 | static int lp8788_ldo_enable(struct regulator_dev *rdev) | 187 | static int lp8788_ldo_enable(struct regulator_dev *rdev) |
255 | { | 188 | { |
256 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | 189 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); |
257 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
258 | enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id); | ||
259 | 190 | ||
260 | switch (mode) { | 191 | if (ldo->en_pin) { |
261 | case EXTPIN: | 192 | gpio_set_value(ldo->en_pin->gpio, ENABLE); |
262 | return lp8788_ldo_ctrl_by_extern_pin(ldo, ENABLE); | 193 | return 0; |
263 | case REGISTER: | 194 | } else { |
264 | return regulator_enable_regmap(rdev); | 195 | return regulator_enable_regmap(rdev); |
265 | default: | ||
266 | return -EINVAL; | ||
267 | } | 196 | } |
268 | } | 197 | } |
269 | 198 | ||
270 | static int lp8788_ldo_disable(struct regulator_dev *rdev) | 199 | static int lp8788_ldo_disable(struct regulator_dev *rdev) |
271 | { | 200 | { |
272 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | 201 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); |
273 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
274 | enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id); | ||
275 | 202 | ||
276 | switch (mode) { | 203 | if (ldo->en_pin) { |
277 | case EXTPIN: | 204 | gpio_set_value(ldo->en_pin->gpio, DISABLE); |
278 | return lp8788_ldo_ctrl_by_extern_pin(ldo, DISABLE); | 205 | return 0; |
279 | case REGISTER: | 206 | } else { |
280 | return regulator_disable_regmap(rdev); | 207 | return regulator_disable_regmap(rdev); |
281 | default: | ||
282 | return -EINVAL; | ||
283 | } | 208 | } |
284 | } | 209 | } |
285 | 210 | ||
286 | static int lp8788_ldo_is_enabled(struct regulator_dev *rdev) | 211 | static int lp8788_ldo_is_enabled(struct regulator_dev *rdev) |
287 | { | 212 | { |
288 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | 213 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); |
289 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
290 | enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id); | ||
291 | 214 | ||
292 | switch (mode) { | 215 | if (ldo->en_pin) |
293 | case EXTPIN: | 216 | return gpio_get_value(ldo->en_pin->gpio) ? 1 : 0; |
294 | return lp8788_ldo_is_enabled_by_extern_pin(ldo); | 217 | else |
295 | case REGISTER: | ||
296 | return regulator_is_enabled_regmap(rdev); | 218 | return regulator_is_enabled_regmap(rdev); |
297 | default: | ||
298 | return -EINVAL; | ||
299 | } | ||
300 | } | 219 | } |
301 | 220 | ||
302 | static int lp8788_ldo_enable_time(struct regulator_dev *rdev) | 221 | static int lp8788_ldo_enable_time(struct regulator_dev *rdev) |
@@ -696,8 +615,10 @@ static int lp8788_config_ldo_enable_mode(struct platform_device *pdev, | |||
696 | ldo->en_pin = pdata->ldo_pin[enable_id]; | 615 | ldo->en_pin = pdata->ldo_pin[enable_id]; |
697 | 616 | ||
698 | ret = lp8788_gpio_request_ldo_en(pdev, ldo, enable_id); | 617 | ret = lp8788_gpio_request_ldo_en(pdev, ldo, enable_id); |
699 | if (ret) | 618 | if (ret) { |
619 | ldo->en_pin = NULL; | ||
700 | goto set_default_ldo_enable_mode; | 620 | goto set_default_ldo_enable_mode; |
621 | } | ||
701 | 622 | ||
702 | return ret; | 623 | return ret; |
703 | 624 | ||