public inbox for linux-leds@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Brophy <professorjonny98@gmail.com>
To: lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
	Andriy Shevencho <andriy.shevchenko@linux.intel.com>,
	Jonathan Brophy <professor_jonny@hotmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Radoslav Tsvetkov <rtsvetkov@gradotech.eu>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org
Subject: [RFC PATCH 1/2] leds: core: Add support for led-instance property
Date: Mon, 29 Dec 2025 07:22:44 +1300	[thread overview]
Message-ID: <20251228182252.1550173-2-professorjonny98@gmail.com> (raw)
In-Reply-To: <20251228182252.1550173-1-professorjonny98@gmail.com>

From: Jonathan Brophy <professor_jonny@hotmail.com>

Add support for parsing an optional "led-instance" device tree property
that provides a third component in LED naming for deterministic
identification when multiple LEDs share the same function and color.

The led-instance becomes part of the LED name as:
  color:function:instance

This solves the non-deterministic _1, _2 suffix problem for hardware
with many identical LEDs (e.g., 48-port network switches).

Signed-off-by: Jonathan Brophy <professor_jonny@hotmail.com>
---
 drivers/leds/led-core.c | 43 +++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 59473f286b31..5a72dbe44303 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -475,7 +475,8 @@ EXPORT_SYMBOL_GPL(led_sysfs_enable);

 static void led_parse_fwnode_props(struct device *dev,
 				   struct fwnode_handle *fwnode,
-				   struct led_properties *props)
+				   struct led_properties *props,
+				   const char **instance)
 {
 	int ret;

@@ -501,7 +502,7 @@ static void led_parse_fwnode_props(struct device *dev,


 	if (!fwnode_property_present(fwnode, "function"))
-		return;
+		goto parse_instance;

 	ret = fwnode_property_read_string(fwnode, "function", &props->function);
 	if (ret) {
@@ -511,7 +512,7 @@ static void led_parse_fwnode_props(struct device *dev,
 	}

 	if (!fwnode_property_present(fwnode, "function-enumerator"))
-		return;
+		goto parse_instance;

 	ret = fwnode_property_read_u32(fwnode, "function-enumerator",
 				       &props->func_enum);
@@ -522,6 +523,14 @@ static void led_parse_fwnode_props(struct device *dev,
 	} else {
 		props->func_enum_present = true;
 	}
+
+parse_instance:
+	/* Parse optional instance identifier */
+	if (fwnode_property_present(fwnode, "led-instance")) {
+		ret = fwnode_property_read_string(fwnode, "led-instance", instance);
+		if (ret)
+			dev_err(dev, "Error parsing 'led-instance' property (%d)\n", ret);
+	}
 }

 int led_compose_name(struct device *dev, struct led_init_data *init_data,
@@ -530,12 +539,13 @@ int led_compose_name(struct device *dev, struct led_init_data *init_data,
 	struct led_properties props = {};
 	struct fwnode_handle *fwnode = init_data->fwnode;
 	const char *devicename = init_data->devicename;
+	const char *instance = NULL;
 	int n;

 	if (!led_classdev_name)
 		return -EINVAL;

-	led_parse_fwnode_props(dev, fwnode, &props);
+	led_parse_fwnode_props(dev, fwnode, &props, &instance);

 	if (props.label) {
 		/*
@@ -554,13 +564,26 @@ int led_compose_name(struct device *dev, struct led_init_data *init_data,
 		char tmp_buf[LED_MAX_NAME_SIZE];

 		if (props.func_enum_present) {
-			n = snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s-%d",
-				     props.color_present ? led_colors[props.color] : "",
-				     props.function ?: "", props.func_enum);
+			if (instance) {
+				n = snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s-%d:%s",
+					     props.color_present ? led_colors[props.color] : "",
+					     props.function ?: "", props.func_enum,
+					     instance);
+			} else {
+				n = snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s-%d",
+					     props.color_present ? led_colors[props.color] : "",
+					     props.function ?: "", props.func_enum);
+			}
 		} else {
-			n = snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s",
-				     props.color_present ? led_colors[props.color] : "",
-				     props.function ?: "");
+			if (instance) {
+				n = snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s:%s",
+					     props.color_present ? led_colors[props.color] : "",
+					     props.function ?: "", instance);
+			} else {
+				n = snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s",
+					     props.color_present ? led_colors[props.color] : "",
+					     props.function ?: "");
+			}
 		}
 		if (n >= LED_MAX_NAME_SIZE)
 			return -E2BIG;
--
2.43.0

  reply	other threads:[~2025-12-28 18:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-28 18:22 [RFC PATCH 0/2] leds: Add optional instance identifier for deterministic naming Jonathan Brophy
2025-12-28 18:22 ` Jonathan Brophy [this message]
2025-12-28 18:35   ` [RFC PATCH 1/2] leds: core: Add support for led-instance property Andriy Shevencho
2025-12-28 18:43     ` Jonathan Brophy
2025-12-28 19:56       ` Andriy Shevencho
2025-12-28 18:22 ` [RFC PATCH 2/2] dt-bindings: leds: common: Add " Jonathan Brophy
2025-12-30 18:28   ` Rob Herring (Arm)
2026-01-02 10:12   ` Krzysztof Kozlowski
2025-12-28 18:31 ` [RFC PATCH 0/2] leds: Add optional instance identifier for deterministic naming Andriy Shevencho
2025-12-28 19:14   ` Jonathan Brophy
2025-12-28 19:59     ` Andriy Shevencho
2025-12-28 20:03     ` Andriy Shevencho
2025-12-29 11:16 ` Jacek Anaszewski
2025-12-29 12:30   ` Andriy Shevencho
2025-12-29 14:28     ` Jacek Anaszewski
2025-12-29 14:45       ` Andriy Shevencho
2025-12-29 23:59       ` Jonathan Brophy
2025-12-30 16:35         ` Jacek Anaszewski

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=20251228182252.1550173-2-professorjonny98@gmail.com \
    --to=professorjonny98@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=professor_jonny@hotmail.com \
    --cc=robh@kernel.org \
    --cc=rtsvetkov@gradotech.eu \
    /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