]> git.ipfire.org Git - thirdparty/openwrt.git/blob
22e48d1f533a1567efc34ff3401c01834bd8cacd
[thirdparty/openwrt.git] /
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
5 function to set it
6
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).
10
11 Add a sysfs node that will return a display name that can be set
12 by other subsystems.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 ---
16 drivers/video/backlight/backlight.c | 21 +++++++++++++++++++++
17 include/linux/backlight.h | 15 +++++++++++++++
18 2 files changed, 36 insertions(+)
19
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
23 }
24 static DEVICE_ATTR_RO(max_brightness);
25
26 +static ssize_t display_name_show(struct device *dev,
27 + struct device_attribute *attr, char *buf)
28 +{
29 + struct backlight_device *bd = to_backlight_device(dev);
30 +
31 + return sprintf(buf, "%s\n", bd->props.display_name);
32 +}
33 +static DEVICE_ATTR_RO(display_name);
34 +
35 static ssize_t actual_brightness_show(struct device *dev,
36 struct device_attribute *attr, char *buf)
37 {
38 @@ -365,6 +374,7 @@ static struct attribute *bl_device_attrs
39 &dev_attr_max_brightness.attr,
40 &dev_attr_scale.attr,
41 &dev_attr_type.attr,
42 + &dev_attr_display_name.attr,
43 NULL,
44 };
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;
48 }
49
50 +int backlight_set_display_name(struct backlight_device *bd, const char *name)
51 +{
52 + if (!bd)
53 + return -EINVAL;
54 +
55 + strscpy_pad(bd->props.display_name, name, sizeof(bd->props.display_name));
56 +
57 + return 0;
58 +}
59 +EXPORT_SYMBOL(backlight_set_display_name);
60 +
61 /**
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.
68 */
69 enum backlight_scale scale;
70 +
71 +#define BL_DISPLAY_NAME_LEN 32
72 + /**
73 + * @display_name: Optional name that can be registered to associate a
74 + * backlight device with a display device.
75 + */
76 + char display_name[BL_DISPLAY_NAME_LEN];
77 };
78
79 /**
80 @@ -478,12 +485,20 @@ of_find_backlight_by_node(struct device_
81
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);
85 #else
86 static inline struct backlight_device *
87 devm_of_find_backlight(struct device *dev)
88 {
89 return NULL;
90 }
91 +
92 +static inline int backlight_set_display_name(struct backlight_device *bd,
93 + const char *name)
94 +{
95 + return 0;
96 +}
97 +
98 #endif
99
100 #endif