[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240520-cros_ec-led-v1-1-4068fc5c051a@weissschuh.net>
Date: Mon, 20 May 2024 12:00:29 +0200
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
Thomas Weißschuh <thomas@...ssschuh.net>,
Benson Leung <bleung@...omium.org>, Guenter Roeck <groeck@...omium.org>
Cc: linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org,
chrome-platform@...ts.linux.dev, Dustin Howett <dustin@...ett.net>,
Mario Limonciello <mario.limonciello@....com>,
Thomas Weißschuh <linux@...ssschuh.net>
Subject: [PATCH 1/5] leds: introduce led_color_name function
This is similar to the existing led_colors array but is safer to use and
usable by everyone.
Getting string representations of color ids is useful for drivers
which are handling color ids anyways, for example for the multicolor API.
Signed-off-by: Thomas Weißschuh <linux@...ssschuh.net>
---
drivers/leds/led-core.c | 9 +++++++++
include/linux/leds.h | 10 ++++++++++
2 files changed, 19 insertions(+)
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 89c9806cc97f..04a49958458e 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -534,6 +534,15 @@ int led_compose_name(struct device *dev, struct led_init_data *init_data,
}
EXPORT_SYMBOL_GPL(led_compose_name);
+const char *led_color_name(u8 color_id)
+{
+ if (color_id >= ARRAY_SIZE(led_colors))
+ return NULL;
+
+ return led_colors[color_id];
+}
+EXPORT_SYMBOL_GPL(led_color_name);
+
enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode)
{
const char *state = NULL;
diff --git a/include/linux/leds.h b/include/linux/leds.h
index db6b114bb3d9..0f1b955fa3f7 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -427,6 +427,16 @@ void led_sysfs_enable(struct led_classdev *led_cdev);
int led_compose_name(struct device *dev, struct led_init_data *init_data,
char *led_classdev_name);
+/**
+ * led_color_name - get string representation of color id
+ * @color_id: The LED_COLOR_ID_* constant
+ *
+ * Get the string name of a LED_COLOR_ID_* constant.
+ *
+ * Returns: A string constant or NULL on an invalid ID.
+ */
+const char *led_color_name(u8 color_id);
+
/**
* led_sysfs_is_disabled - check if LED sysfs interface is disabled
* @led_cdev: the LED to query
--
2.45.1
Powered by blists - more mailing lists