1 From 1e0dc5254a44722653bef6041e7b4ddbd689aba6 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Fri, 17 May 2024 17:35:25 +0100
4 Subject: [PATCH 1102/1135] backlight: Add a display name to the core, and a
7 The naming of backlight devices is not terribly useful for
8 associating a backlight controller with a display (assuming
9 it is attached to one).
11 Add a sysfs node that will return a display name that can be set
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
16 drivers/video/backlight/backlight.c | 21 +++++++++++++++++++++
17 include/linux/backlight.h | 15 +++++++++++++++
18 2 files changed, 36 insertions(+)
20 --- a/drivers/video/backlight/backlight.c
21 +++ b/drivers/video/backlight/backlight.c
22 @@ -285,6 +285,15 @@ static ssize_t max_brightness_show(struc
24 static DEVICE_ATTR_RO(max_brightness);
26 +static ssize_t display_name_show(struct device *dev,
27 + struct device_attribute *attr, char *buf)
29 + struct backlight_device *bd = to_backlight_device(dev);
31 + return sprintf(buf, "%s\n", bd->props.display_name);
33 +static DEVICE_ATTR_RO(display_name);
35 static ssize_t actual_brightness_show(struct device *dev,
36 struct device_attribute *attr, char *buf)
38 @@ -365,6 +374,7 @@ static struct attribute *bl_device_attrs
39 &dev_attr_max_brightness.attr,
42 + &dev_attr_display_name.attr,
45 ATTRIBUTE_GROUPS(bl_device);
46 @@ -662,6 +672,17 @@ static int of_parent_match(struct device
47 return dev->parent && dev->parent->of_node == data;
50 +int backlight_set_display_name(struct backlight_device *bd, const char *name)
55 + strscpy_pad(bd->props.display_name, name, sizeof(bd->props.display_name));
59 +EXPORT_SYMBOL(backlight_set_display_name);
62 * of_find_backlight_by_node() - find backlight device by device-tree node
63 * @node: device-tree node of the backlight device
64 --- a/include/linux/backlight.h
65 +++ b/include/linux/backlight.h
66 @@ -270,6 +270,13 @@ struct backlight_properties {
67 * @scale: The type of the brightness scale.
69 enum backlight_scale scale;
71 +#define BL_DISPLAY_NAME_LEN 32
73 + * @display_name: Optional name that can be registered to associate a
74 + * backlight device with a display device.
76 + char display_name[BL_DISPLAY_NAME_LEN];
80 @@ -478,12 +485,20 @@ of_find_backlight_by_node(struct device_
82 #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
83 struct backlight_device *devm_of_find_backlight(struct device *dev);
84 +int backlight_set_display_name(struct backlight_device *bd, const char *name);
86 static inline struct backlight_device *
87 devm_of_find_backlight(struct device *dev)
92 +static inline int backlight_set_display_name(struct backlight_device *bd,