Skip to content

Commit

Permalink
leds: lm3692x: Split out lm3692x_leds_disable
Browse files Browse the repository at this point in the history
Move the relevant parts out of lm3692x_remove() and call it from
there. No functional change.

Signed-off-by: Guido Günther <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Pavel Machek <[email protected]>
  • Loading branch information
agx authored and pavelmachek committed Jan 7, 2020
1 parent 5e9d7b6 commit 4a8d2be
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions drivers/leds/leds-lm3692x.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,30 @@ static int lm3692x_leds_enable(struct lm3692x_led *led)
return ret;
}

static int lm3692x_leds_disable(struct lm3692x_led *led)
{
int ret;

ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_DEVICE_EN, 0);
if (ret) {
dev_err(&led->client->dev, "Failed to disable regulator: %d\n",
ret);
return ret;
}

if (led->enable_gpio)
gpiod_direction_output(led->enable_gpio, 0);

if (led->regulator) {
ret = regulator_disable(led->regulator);
if (ret)
dev_err(&led->client->dev,
"Failed to disable regulator: %d\n", ret);
}

return ret;
}

static int lm3692x_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brt_val)
{
Expand Down Expand Up @@ -463,23 +487,9 @@ static int lm3692x_remove(struct i2c_client *client)
struct lm3692x_led *led = i2c_get_clientdata(client);
int ret;

ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_DEVICE_EN, 0);
if (ret) {
dev_err(&led->client->dev, "Failed to disable regulator: %d\n",
ret);
ret = lm3692x_leds_disable(led);
if (ret)
return ret;
}

if (led->enable_gpio)
gpiod_direction_output(led->enable_gpio, 0);

if (led->regulator) {
ret = regulator_disable(led->regulator);
if (ret)
dev_err(&led->client->dev,
"Failed to disable regulator: %d\n", ret);
}

mutex_destroy(&led->lock);

return 0;
Expand Down

0 comments on commit 4a8d2be

Please sign in to comment.