summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@traphandler.com>2023-07-28 18:37:29 +0300
committerLee Jones <lee@kernel.org>2023-08-17 11:00:34 +0300
commitc7d80059b086c4986cd994a1973ec7a5d75f8eea (patch)
treeb93389acfcb0c97f22b2493f98db93a69bef0c0a /drivers/leds
parentafb48153220d35f330d0d979792920a31f7d9a81 (diff)
downloadlinux-c7d80059b086c4986cd994a1973ec7a5d75f8eea.tar.xz
leds: class: Store the color index in struct led_classdev
Store the color of the LED so that it is not lost after the LED's name has been composed. This color information can then be exposed to the user space or used by the LED consumer. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com> Link: https://lore.kernel.org/r/20230728153731.3742339-3-jjhiblot@traphandler.com Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/led-class.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 78068b06d009..4bcbd46ec75a 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -76,6 +76,19 @@ static ssize_t max_brightness_show(struct device *dev,
}
static DEVICE_ATTR_RO(max_brightness);
+static ssize_t color_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ const char *color_text = "invalid";
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+ if (led_cdev->color < LED_COLOR_ID_MAX)
+ color_text = led_colors[led_cdev->color];
+
+ return sysfs_emit(buf, "%s\n", color_text);
+}
+static DEVICE_ATTR_RO(color);
+
#ifdef CONFIG_LEDS_TRIGGERS
static BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0);
static struct bin_attribute *led_trigger_bin_attrs[] = {
@@ -90,6 +103,7 @@ static const struct attribute_group led_trigger_group = {
static struct attribute *led_class_attrs[] = {
&dev_attr_brightness.attr,
&dev_attr_max_brightness.attr,
+ &dev_attr_color.attr,
NULL,
};
@@ -486,6 +500,10 @@ int led_classdev_register_ext(struct device *parent,
fwnode_property_read_u32(init_data->fwnode,
"max-brightness",
&led_cdev->max_brightness);
+
+ if (fwnode_property_present(init_data->fwnode, "color"))
+ fwnode_property_read_u32(init_data->fwnode, "color",
+ &led_cdev->color);
}
} else {
proposed_name = led_cdev->name;
@@ -495,6 +513,9 @@ int led_classdev_register_ext(struct device *parent,
if (ret < 0)
return ret;
+ if (led_cdev->color >= LED_COLOR_ID_MAX)
+ dev_warn(parent, "LED %s color identifier out of range\n", final_name);
+
mutex_init(&led_cdev->led_access);
mutex_lock(&led_cdev->led_access);
led_cdev->dev = device_create_with_groups(leds_class, parent, 0,