aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lm3530.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2012-12-19 19:59:43 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-01 20:47:06 -0500
commit5e3b7c6b1cb1a579a65fa77c7f785d94013025be (patch)
treec8a910b1bb7c67eb1b9b5dbea84fd3682f504516 /drivers/leds/leds-lm3530.c
parenta1932edf8baaf2b09ad72b119c1f9749ad4397f2 (diff)
leds: lm3530: Ensure drvdata->enable has correct status if regulator_disable fails
Add lm3530_led_enable() and lm3530_led_disable() helper functions. This ensures setting drvdata->enable to correct status if regulator_disable fails. Signed-off-by: Axel Lin <axel.lin@ingics.com> Acked-by: Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com> Acked-by: Milo Kim <milo.kim@ti.com> Tested-by: Milo Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds/leds-lm3530.c')
-rw-r--r--drivers/leds/leds-lm3530.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c
index 214145483836..a036a19040fe 100644
--- a/drivers/leds/leds-lm3530.c
+++ b/drivers/leds/leds-lm3530.c
@@ -187,6 +187,40 @@ static void lm3530_als_configure(struct lm3530_platform_data *pdata,
187 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT); 187 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);
188} 188}
189 189
190static int lm3530_led_enable(struct lm3530_data *drvdata)
191{
192 int ret;
193
194 if (drvdata->enable)
195 return 0;
196
197 ret = regulator_enable(drvdata->regulator);
198 if (ret) {
199 dev_err(drvdata->led_dev.dev, "Failed to enable vin:%d\n", ret);
200 return ret;
201 }
202
203 drvdata->enable = true;
204 return 0;
205}
206
207static void lm3530_led_disable(struct lm3530_data *drvdata)
208{
209 int ret;
210
211 if (!drvdata->enable)
212 return;
213
214 ret = regulator_disable(drvdata->regulator);
215 if (ret) {
216 dev_err(drvdata->led_dev.dev, "Failed to disable vin:%d\n",
217 ret);
218 return;
219 }
220
221 drvdata->enable = false;
222}
223
190static int lm3530_init_registers(struct lm3530_data *drvdata) 224static int lm3530_init_registers(struct lm3530_data *drvdata)
191{ 225{
192 int ret = 0; 226 int ret = 0;
@@ -245,15 +279,9 @@ static int lm3530_init_registers(struct lm3530_data *drvdata)
245 reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */ 279 reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */
246 reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */ 280 reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */
247 281
248 if (!drvdata->enable) { 282 ret = lm3530_led_enable(drvdata);
249 ret = regulator_enable(drvdata->regulator); 283 if (ret)
250 if (ret) { 284 return ret;
251 dev_err(&drvdata->client->dev,
252 "Enable regulator failed\n");
253 return ret;
254 }
255 drvdata->enable = true;
256 }
257 285
258 for (i = 0; i < LM3530_REG_MAX; i++) { 286 for (i = 0; i < LM3530_REG_MAX; i++) {
259 /* do not update brightness register when pwm mode */ 287 /* do not update brightness register when pwm mode */
@@ -305,13 +333,8 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev,
305 else 333 else
306 drvdata->brightness = brt_val; 334 drvdata->brightness = brt_val;
307 335
308 if (brt_val == 0) { 336 if (brt_val == 0)
309 err = regulator_disable(drvdata->regulator); 337 lm3530_led_disable(drvdata);
310 if (err)
311 dev_err(&drvdata->client->dev,
312 "Disable regulator failed\n");
313 drvdata->enable = false;
314 }
315 break; 338 break;
316 case LM3530_BL_MODE_ALS: 339 case LM3530_BL_MODE_ALS:
317 break; 340 break;
@@ -458,8 +481,7 @@ static int lm3530_remove(struct i2c_client *client)
458 481
459 device_remove_file(drvdata->led_dev.dev, &dev_attr_mode); 482 device_remove_file(drvdata->led_dev.dev, &dev_attr_mode);
460 483
461 if (drvdata->enable) 484 lm3530_led_disable(drvdata);
462 regulator_disable(drvdata->regulator);
463 led_classdev_unregister(&drvdata->led_dev); 485 led_classdev_unregister(&drvdata->led_dev);
464 return 0; 486 return 0;
465} 487}