Skip to content

Commit b0d6394

Browse files
glneolag-linaro
authored andcommitted
leds: lp8860: Enable regulator using enable_optional helper
This allows the regulator to be optional which is the same as done here with all the checks for NULL. This also disables on remove for us, so remove the manual disabling. Signed-off-by: Andrew Davis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 0cb55e1 commit b0d6394

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

drivers/leds/leds-lp8860.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
* @regmap: Devices register map
9292
* @eeprom_regmap: EEPROM register map
9393
* @enable_gpio: VDDIO/EN gpio to enable communication interface
94-
* @regulator: LED supply regulator pointer
9594
*/
9695
struct lp8860_led {
9796
struct mutex lock;
@@ -100,7 +99,6 @@ struct lp8860_led {
10099
struct regmap *regmap;
101100
struct regmap *eeprom_regmap;
102101
struct gpio_desc *enable_gpio;
103-
struct regulator *regulator;
104102
};
105103

106104
static const struct reg_sequence lp8860_eeprom_disp_regs[] = {
@@ -232,15 +230,6 @@ static int lp8860_init(struct lp8860_led *led)
232230
unsigned int read_buf;
233231
int ret, reg_count;
234232

235-
if (led->regulator) {
236-
ret = regulator_enable(led->regulator);
237-
if (ret) {
238-
dev_err(&led->client->dev,
239-
"Failed to enable regulator\n");
240-
return ret;
241-
}
242-
}
243-
244233
gpiod_direction_output(led->enable_gpio, 1);
245234

246235
ret = lp8860_fault_check(led);
@@ -282,13 +271,6 @@ static int lp8860_init(struct lp8860_led *led)
282271
if (ret)
283272
gpiod_direction_output(led->enable_gpio, 0);
284273

285-
if (led->regulator) {
286-
ret = regulator_disable(led->regulator);
287-
if (ret)
288-
dev_err(&led->client->dev,
289-
"Failed to disable regulator\n");
290-
}
291-
292274
return ret;
293275
}
294276

@@ -330,9 +312,10 @@ static int lp8860_probe(struct i2c_client *client)
330312
return ret;
331313
}
332314

333-
led->regulator = devm_regulator_get(&client->dev, "vled");
334-
if (IS_ERR(led->regulator))
335-
led->regulator = NULL;
315+
ret = devm_regulator_get_enable_optional(&client->dev, "vled");
316+
if (ret && ret != -ENODEV)
317+
return dev_err_probe(&client->dev, ret,
318+
"Failed to enable vled regulator\n");
336319

337320
led->client = client;
338321
led->led_dev.brightness_set_blocking = lp8860_brightness_set;
@@ -381,13 +364,6 @@ static void lp8860_remove(struct i2c_client *client)
381364
int ret;
382365

383366
gpiod_direction_output(led->enable_gpio, 0);
384-
385-
if (led->regulator) {
386-
ret = regulator_disable(led->regulator);
387-
if (ret)
388-
dev_err(&led->client->dev,
389-
"Failed to disable regulator\n");
390-
}
391367
}
392368

393369
static const struct i2c_device_id lp8860_id[] = {

0 commit comments

Comments
 (0)