All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Pavel Machek" <pavel@ucw.cz>, "Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Marek Behún" <kabel@kernel.org>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] leds: syscon: Implement support for value property
Date: Wed,  6 Jul 2022 13:28:28 +0200	[thread overview]
Message-ID: <20220706112828.27278-2-pali@kernel.org> (raw)
In-Reply-To: <20220706112828.27278-1-pali@kernel.org>

This new value property specify when is LED enabled. By default its value
is from the mask and therefore LED is enabled when bit is set. This change
allows to define inverted logic (0 - enable LED, 1 - disable LED) by
setting value property to zero.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/leds/leds-syscon.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-syscon.c b/drivers/leds/leds-syscon.c
index 7eddb8ecb44e..337a0bada967 100644
--- a/drivers/leds/leds-syscon.c
+++ b/drivers/leds/leds-syscon.c
@@ -29,6 +29,7 @@ struct syscon_led {
 	struct regmap *map;
 	u32 offset;
 	u32 mask;
+	u32 value;
 	bool state;
 };
 
@@ -41,10 +42,10 @@ static void syscon_led_set(struct led_classdev *led_cdev,
 	int ret;
 
 	if (value == LED_OFF) {
-		val = 0;
+		val = ~sled->value;
 		sled->state = false;
 	} else {
-		val = sled->mask;
+		val = sled->value;
 		sled->state = true;
 	}
 
@@ -85,6 +86,8 @@ static int syscon_led_probe(struct platform_device *pdev)
 		return -EINVAL;
 	if (of_property_read_u32(np, "mask", &sled->mask))
 		return -EINVAL;
+	if (of_property_read_u32(np, "value", &sled->value))
+		sled->value = sled->mask;
 
 	state = of_get_property(np, "default-state", NULL);
 	if (state) {
@@ -94,18 +97,19 @@ static int syscon_led_probe(struct platform_device *pdev)
 			ret = regmap_read(map, sled->offset, &val);
 			if (ret < 0)
 				return ret;
-			sled->state = !!(val & sled->mask);
+			sled->state = (val & sled->mask) == sled->value;
 		} else if (!strcmp(state, "on")) {
 			sled->state = true;
 			ret = regmap_update_bits(map, sled->offset,
 						 sled->mask,
-						 sled->mask);
+						 sled->value);
 			if (ret < 0)
 				return ret;
 		} else {
 			sled->state = false;
 			ret = regmap_update_bits(map, sled->offset,
-						 sled->mask, 0);
+						 sled->mask,
+						 ~sled->value);
 			if (ret < 0)
 				return ret;
 		}
-- 
2.20.1


  reply	other threads:[~2022-07-06 11:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 11:28 [PATCH 1/2] dt-bindings: leds: register-bit-led: Add value property Pali Rohár
2022-07-06 11:28 ` Pali Rohár [this message]
2022-07-06 16:21 ` Rob Herring
2022-07-06 16:23   ` Pali Rohár
2022-07-11 12:06     ` Linus Walleij
2022-07-11 12:10       ` Pali Rohár
2022-07-11 12:21         ` Linus Walleij

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=20220706112828.27278-2-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kabel@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.