From: "Guido Günther" <agx@sigxcpu.org>
To: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Pavel Machek <pavel@ucw.cz>, Dan Murphy <dmurphy@ti.com>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] leds: lm3692x: Disable chip on brightness 0
Date: Wed, 25 Dec 2019 12:16:39 +0100 [thread overview]
Message-ID: <e1dc56c07235063a9c0afbfc8c227b92b39ec3d4.1577272495.git.agx@sigxcpu.org> (raw)
In-Reply-To: <cover.1577272495.git.agx@sigxcpu.org>
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 <agx@sigxcpu.org>
---
drivers/leds/leds-lm3692x.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c
index d1bd9ae4e7ab..183614744b92 100644
--- a/drivers/leds/leds-lm3692x.c
+++ b/drivers/leds/leds-lm3692x.c
@@ -117,6 +117,7 @@ struct lm3692x_led {
int model_id;
u8 boost_ctrl, brightness_ctrl;
+ bool enabled;
};
static const struct reg_default lm3692x_reg_defs[] = {
@@ -170,6 +171,9 @@ static int lm3692x_leds_enable(struct lm3692x_led *led)
int enable_state;
int ret, reg_ret;
+ if (led->enabled)
+ return 0;
+
if (led->regulator) {
ret = regulator_enable(led->regulator);
if (ret) {
@@ -271,6 +275,7 @@ static int lm3692x_leds_enable(struct lm3692x_led *led)
ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_ENABLE_MASK,
enable_state | LM3692X_DEVICE_EN);
+ led->enabled = true;
return ret;
out:
dev_err(&led->client->dev, "Fail writing initialization values\n");
@@ -292,6 +297,9 @@ static int lm3692x_leds_disable(struct lm3692x_led *led)
{
int ret;
+ if (!led->enabled)
+ return 0;
+
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",
@@ -309,6 +317,7 @@ static int lm3692x_leds_disable(struct lm3692x_led *led)
"Failed to disable regulator: %d\n", ret);
}
+ led->enabled = false;
return ret;
}
@@ -322,6 +331,13 @@ static int lm3692x_brightness_set(struct led_classdev *led_cdev,
mutex_lock(&led->lock);
+ if (brt_val == 0) {
+ ret = lm3692x_leds_disable(led);
+ goto out;
+ } else {
+ lm3692x_leds_enable(led);
+ }
+
ret = lm3692x_fault_check(led);
if (ret) {
dev_err(&led->client->dev, "Cannot read/clear faults: %d\n",
--
2.23.0
next prev parent reply other threads:[~2019-12-25 11:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-25 11:16 [PATCH 0/3] leds: lm3692x: Disable chip on brightness 0 Guido Günther
2019-12-25 11:16 ` [PATCH 1/3] leds: lm3692x: Move lm3692x_init and rename to lm3692x_leds_enable Guido Günther
2019-12-26 10:15 ` Pavel Machek
2019-12-25 11:16 ` [PATCH 2/3] leds: lm3692x: Split out lm3692x_leds_disable Guido Günther
2019-12-26 10:16 ` Pavel Machek
2019-12-25 11:16 ` Guido Günther [this message]
2019-12-26 10:29 ` [PATCH 3/3] leds: lm3692x: Disable chip on brightness 0 Pavel Machek
2019-12-27 12:56 ` Guido Günther
2019-12-26 10:14 ` [PATCH 0/3] " Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e1dc56c07235063a9c0afbfc8c227b92b39ec3d4.1577272495.git.agx@sigxcpu.org \
--to=agx@sigxcpu.org \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).