All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Schwermer <sven@svenschwermer.de>
To: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	pavel@ucw.cz, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, dmurphy@ti.com,
	devicetree@vger.kernel.org
Cc: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
Subject: [PATCH v1 2/2] leds: multicolor: Read default-intensities property
Date: Tue,  3 May 2022 13:04:51 +0200	[thread overview]
Message-ID: <03decec200aa7550f66be8454438eb3db6a2378a.1651575831.git.sven.schwermer@disruptive-technologies.com> (raw)
In-Reply-To: <364df52a196fa0ae5db07e599995fcf8dfafb43e.1651575831.git.sven.schwermer@disruptive-technologies.com>

From: Sven Schwermer <sven.schwermer@disruptive-technologies.com>

This allows to assign intensity values taken from the firmware interface
(if available) to the indivisual sub LEDs (colors) at driver probe time,
i.e. most commonly at kernel boot time. This is crucial for setting a
specific color and early in the boot process. While it would be possible
to set a static color in the bootloader, this mechanism allows setting a
pattern (e.g. blinking) at a specific color.

Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
---
 drivers/leds/led-class-multicolor.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c
index e317408583df..eb7f11345ec1 100644
--- a/drivers/leds/led-class-multicolor.c
+++ b/drivers/leds/led-class-multicolor.c
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/property.h>
 
 #include "leds.h"
 
@@ -116,6 +117,23 @@ static struct attribute *led_multicolor_attrs[] = {
 };
 ATTRIBUTE_GROUPS(led_multicolor);
 
+static void multi_load_default_intensities(struct device *parent,
+					   struct led_classdev_mc *mcled_cdev,
+					   struct fwnode_handle *fwnode)
+{
+	u32 intensities[LED_COLOR_ID_MAX];
+	int ret;
+	int i;
+
+	ret = fwnode_property_read_u32_array(fwnode, "default-intensities",
+					     intensities, mcled_cdev->num_colors);
+	if (ret < 0 && ret != -ENODATA)
+		dev_warn(parent, "failed to read default-intensities property: %d", ret);
+
+	for (i = 0; i < ret; i++)
+		mcled_cdev->subled_info[i].intensity = intensities[i];
+}
+
 int led_classdev_multicolor_register_ext(struct device *parent,
 				     struct led_classdev_mc *mcled_cdev,
 				     struct led_init_data *init_data)
@@ -134,6 +152,9 @@ int led_classdev_multicolor_register_ext(struct device *parent,
 	led_cdev = &mcled_cdev->led_cdev;
 	mcled_cdev->led_cdev.groups = led_multicolor_groups;
 
+	if (init_data && init_data->fwnode)
+		multi_load_default_intensities(parent, mcled_cdev, init_data->fwnode);
+
 	return led_classdev_register_ext(parent, led_cdev, init_data);
 }
 EXPORT_SYMBOL_GPL(led_classdev_multicolor_register_ext);
-- 
2.36.0


  reply	other threads:[~2022-05-03 11:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 14:09 Initial multicolor LED intensities Sven Schwermer
2022-05-02 20:46 ` Pavel Machek
2022-05-03 11:04   ` [PATCH v1 1/2] dt-bindings: leds: Add multi-color default-intensities property Sven Schwermer
2022-05-03 11:04     ` Sven Schwermer [this message]
2022-05-03 11:27   ` [PATCH v2 " Sven Schwermer
2022-05-03 11:27     ` [PATCH v2 2/2] leds: multicolor: Read " Sven Schwermer
2022-05-03 13:50     ` AW: [PATCH v2 1/2] dt-bindings: leds: Add multi-color " Sven Schuchmann
2022-05-03 18:58       ` Sven Schwermer
2022-05-04  7:17         ` AW: " Sven Schuchmann
2022-05-04  9:24           ` Sven Schwermer
2022-05-08 19:55             ` Jacek Anaszewski
2022-05-10 18:31               ` Sven Schwermer
2022-05-10 22:00                 ` Jacek Anaszewski
2022-05-05  9:50   ` [PATCH v3 " Sven Schwermer
2022-05-05  9:50     ` [PATCH v3 2/2] leds: multicolor: Read " Sven Schwermer
2022-05-17  0:08     ` [PATCH v3 1/2] dt-bindings: leds: Add multi-color " Rob Herring

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=03decec200aa7550f66be8454438eb3db6a2378a.1651575831.git.sven.schwermer@disruptive-technologies.com \
    --to=sven@svenschwermer.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dmurphy@ti.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    --cc=sven.schwermer@disruptive-technologies.com \
    /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.