Commit 5e3b7c6b authored by Axel Lin's avatar Axel Lin Committed by Bryan Wu

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: default avatarAxel Lin <axel.lin@ingics.com>
Acked-by: default avatarShreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>
Acked-by: default avatarMilo Kim <milo.kim@ti.com>
Tested-by: default avatarMilo Kim <milo.kim@ti.com>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent a1932edf
...@@ -187,6 +187,40 @@ static void lm3530_als_configure(struct lm3530_platform_data *pdata, ...@@ -187,6 +187,40 @@ static void lm3530_als_configure(struct lm3530_platform_data *pdata,
(pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT); (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);
} }
static int lm3530_led_enable(struct lm3530_data *drvdata)
{
int ret;
if (drvdata->enable)
return 0;
ret = regulator_enable(drvdata->regulator);
if (ret) {
dev_err(drvdata->led_dev.dev, "Failed to enable vin:%d\n", ret);
return ret;
}
drvdata->enable = true;
return 0;
}
static void lm3530_led_disable(struct lm3530_data *drvdata)
{
int ret;
if (!drvdata->enable)
return;
ret = regulator_disable(drvdata->regulator);
if (ret) {
dev_err(drvdata->led_dev.dev, "Failed to disable vin:%d\n",
ret);
return;
}
drvdata->enable = false;
}
static int lm3530_init_registers(struct lm3530_data *drvdata) static int lm3530_init_registers(struct lm3530_data *drvdata)
{ {
int ret = 0; int ret = 0;
...@@ -245,15 +279,9 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) ...@@ -245,15 +279,9 @@ static int lm3530_init_registers(struct lm3530_data *drvdata)
reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */ reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */
reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */ reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */
if (!drvdata->enable) { ret = lm3530_led_enable(drvdata);
ret = regulator_enable(drvdata->regulator); if (ret)
if (ret) { return ret;
dev_err(&drvdata->client->dev,
"Enable regulator failed\n");
return ret;
}
drvdata->enable = true;
}
for (i = 0; i < LM3530_REG_MAX; i++) { for (i = 0; i < LM3530_REG_MAX; i++) {
/* do not update brightness register when pwm mode */ /* do not update brightness register when pwm mode */
...@@ -305,13 +333,8 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev, ...@@ -305,13 +333,8 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev,
else else
drvdata->brightness = brt_val; drvdata->brightness = brt_val;
if (brt_val == 0) { if (brt_val == 0)
err = regulator_disable(drvdata->regulator); lm3530_led_disable(drvdata);
if (err)
dev_err(&drvdata->client->dev,
"Disable regulator failed\n");
drvdata->enable = false;
}
break; break;
case LM3530_BL_MODE_ALS: case LM3530_BL_MODE_ALS:
break; break;
...@@ -458,8 +481,7 @@ static int lm3530_remove(struct i2c_client *client) ...@@ -458,8 +481,7 @@ static int lm3530_remove(struct i2c_client *client)
device_remove_file(drvdata->led_dev.dev, &dev_attr_mode); device_remove_file(drvdata->led_dev.dev, &dev_attr_mode);
if (drvdata->enable) lm3530_led_disable(drvdata);
regulator_disable(drvdata->regulator);
led_classdev_unregister(&drvdata->led_dev); led_classdev_unregister(&drvdata->led_dev);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment