[PATCH RFC 2/2] leds: rgb: leds-group-multicolor: Implement default-intensity

Stefan Wahren <[email protected]>
Newsgroups org.kernel.vger.linux-leds,org.kernel.vger.linux-devicetree
Message-ID <[email protected]>
Until now the driver initialized all LEDs with maximum intensity.
This isn't useful for LEDs, which needs to be initialized via DT.
So introduce a new DT property to define the default intensity of all
indiviual LEDs. In case the property is missing, the old behavior
is kept.

Additionally this also works with triggers. So it should be possible
to blink with a specific RGB color.

Signed-off-by: Stefan Wahren <[email protected]>
---
 drivers/leds/rgb/leds-group-multicolor.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/rgb/leds-group-multicolor.c b/drivers/leds/rgb/leds-group-multicolor.c
index 548c7dd63ba1..19913a43b8a1 100644
--- a/drivers/leds/rgb/leds-group-multicolor.c
+++ b/drivers/leds/rgb/leds-group-multicolor.c
@@ -17,6 +17,7 @@
 #include <linux/math.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 
@@ -106,11 +107,27 @@ static int leds_gmc_probe(struct platform_device *pdev)
 
 	for (i = 0; i < count; i++) {
 		struct led_classdev *led_cdev = priv->monochromatics[i];
+		u32 intensity;
 
 		subled[i].color_index = led_cdev->color;
 
-		/* Configure the LED intensity to its maximum */
-		subled[i].intensity = max_brightness;
+		ret = of_property_read_u32_index(pdev->dev.of_node, "default-intensity",
+						 i, &intensity);
+		if (ret) {
+			if (ret != -EINVAL && ret != -ENOSYS) {
+				return dev_err_probe(dev, ret,
+						     "Unable to get default-intensity[%d]\n", i);
+			}
+			subled[i].intensity = max_brightness;
+		} else if (intensity > max_brightness) {
+			return dev_err_probe(dev, -EINVAL, "default-intensity[%d] is invalid\n",
+					     i);
+		} else {
+			subled[i].intensity = intensity;
+		}
+
+		dev_dbg(dev, "subled[%d]: color_index: %u, intensity: %u\n",
+			i, subled[i].color_index, subled[i].intensity);
 	}
 
 	/* Initialise the multicolor's LED class device */
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.