Skip to content

Commit 260718b

Browse files
agxpavelmachek
authored andcommitted
leds: lm3692x: Disable chip on brightness 0
Otherwise there's a noticeable glow even with brightness 0. Also turning off the regulator can save additional power. Signed-off-by: Guido Günther <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent 4a8d2be commit 260718b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

drivers/leds/leds-lm3692x.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ struct lm3692x_led {
116116
int led_enable;
117117
int model_id;
118118

119-
u8 boost_ctrl;
119+
u8 boost_ctrl, brightness_ctrl;
120+
bool enabled;
120121
};
121122

122123
static const struct reg_default lm3692x_reg_defs[] = {
@@ -170,6 +171,9 @@ static int lm3692x_leds_enable(struct lm3692x_led *led)
170171
int enable_state;
171172
int ret, reg_ret;
172173

174+
if (led->enabled)
175+
return 0;
176+
173177
if (led->regulator) {
174178
ret = regulator_enable(led->regulator);
175179
if (ret) {
@@ -272,6 +276,7 @@ static int lm3692x_leds_enable(struct lm3692x_led *led)
272276
ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_ENABLE_MASK,
273277
enable_state | LM3692X_DEVICE_EN);
274278

279+
led->enabled = true;
275280
return ret;
276281
out:
277282
dev_err(&led->client->dev, "Fail writing initialization values\n");
@@ -293,6 +298,9 @@ static int lm3692x_leds_disable(struct lm3692x_led *led)
293298
{
294299
int ret;
295300

301+
if (!led->enabled)
302+
return 0;
303+
296304
ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_DEVICE_EN, 0);
297305
if (ret) {
298306
dev_err(&led->client->dev, "Failed to disable regulator: %d\n",
@@ -310,6 +318,7 @@ static int lm3692x_leds_disable(struct lm3692x_led *led)
310318
"Failed to disable regulator: %d\n", ret);
311319
}
312320

321+
led->enabled = false;
313322
return ret;
314323
}
315324

@@ -323,6 +332,13 @@ static int lm3692x_brightness_set(struct led_classdev *led_cdev,
323332

324333
mutex_lock(&led->lock);
325334

335+
if (brt_val == 0) {
336+
ret = lm3692x_leds_disable(led);
337+
goto out;
338+
} else {
339+
lm3692x_leds_enable(led);
340+
}
341+
326342
ret = lm3692x_fault_check(led);
327343
if (ret) {
328344
dev_err(&led->client->dev, "Cannot read/clear faults: %d\n",

0 commit comments

Comments
 (0)