From 7a8a376739f68753d21455b1c49232038b9283ae Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Fri, 17 May 2024 17:35:25 +0100 Subject: [PATCH] backlight: Add a display name to the core, and a function to set it The naming of backlight devices is not terribly useful for associating a backlight controller with a display (assuming it is attached to one). Add a sysfs node that will return a display name that can be set by other subsystems. Signed-off-by: Dave Stevenson --- drivers/video/backlight/backlight.c | 21 +++++++++++++++++++++ include/linux/backlight.h | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 86e1cdc8e36977..cfea80d4cfad51 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -285,6 +285,15 @@ static ssize_t max_brightness_show(struct device *dev, } static DEVICE_ATTR_RO(max_brightness); +static ssize_t display_name_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct backlight_device *bd = to_backlight_device(dev); + + return sprintf(buf, "%s\n", bd->props.display_name); +} +static DEVICE_ATTR_RO(display_name); + static ssize_t actual_brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -365,6 +374,7 @@ static struct attribute *bl_device_attrs[] = { &dev_attr_max_brightness.attr, &dev_attr_scale.attr, &dev_attr_type.attr, + &dev_attr_display_name.attr, NULL, }; ATTRIBUTE_GROUPS(bl_device); @@ -662,6 +672,17 @@ static int of_parent_match(struct device *dev, const void *data) return dev->parent && dev->parent->of_node == data; } +int backlight_set_display_name(struct backlight_device *bd, const char *name) +{ + if (!bd) + return -EINVAL; + + strscpy_pad(bd->props.display_name, name, sizeof(bd->props.display_name)); + + return 0; +} +EXPORT_SYMBOL(backlight_set_display_name); + /** * of_find_backlight_by_node() - find backlight device by device-tree node * @node: device-tree node of the backlight device diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 614653e07e3a86..82c01a5d7dc8bf 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -270,6 +270,13 @@ struct backlight_properties { * @scale: The type of the brightness scale. */ enum backlight_scale scale; + +#define BL_DISPLAY_NAME_LEN 32 + /** + * @display_name: Optional name that can be registered to associate a + * backlight device with a display device. + */ + char display_name[BL_DISPLAY_NAME_LEN]; }; /** @@ -438,6 +445,7 @@ devm_backlight_device_register(struct device *dev, const char *name, void backlight_device_unregister(struct backlight_device *bd); void devm_backlight_device_unregister(struct device *dev, struct backlight_device *bd); +int backlight_set_display_name(struct backlight_device *bd, const char *name); void backlight_force_update(struct backlight_device *bd, enum backlight_update_reason reason); int backlight_register_notifier(struct notifier_block *nb);