Skip to content

Commit 1e0dc52

Browse files
6by9pelwell
authored andcommitted
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 <dave.stevenson@raspberrypi.com>
1 parent a59df15 commit 1e0dc52

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

drivers/video/backlight/backlight.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ static ssize_t max_brightness_show(struct device *dev,
285285
}
286286
static DEVICE_ATTR_RO(max_brightness);
287287

288+
static ssize_t display_name_show(struct device *dev,
289+
struct device_attribute *attr, char *buf)
290+
{
291+
struct backlight_device *bd = to_backlight_device(dev);
292+
293+
return sprintf(buf, "%s\n", bd->props.display_name);
294+
}
295+
static DEVICE_ATTR_RO(display_name);
296+
288297
static ssize_t actual_brightness_show(struct device *dev,
289298
struct device_attribute *attr, char *buf)
290299
{
@@ -365,6 +374,7 @@ static struct attribute *bl_device_attrs[] = {
365374
&dev_attr_max_brightness.attr,
366375
&dev_attr_scale.attr,
367376
&dev_attr_type.attr,
377+
&dev_attr_display_name.attr,
368378
NULL,
369379
};
370380
ATTRIBUTE_GROUPS(bl_device);
@@ -662,6 +672,17 @@ static int of_parent_match(struct device *dev, const void *data)
662672
return dev->parent && dev->parent->of_node == data;
663673
}
664674

675+
int backlight_set_display_name(struct backlight_device *bd, const char *name)
676+
{
677+
if (!bd)
678+
return -EINVAL;
679+
680+
strscpy_pad(bd->props.display_name, name, sizeof(bd->props.display_name));
681+
682+
return 0;
683+
}
684+
EXPORT_SYMBOL(backlight_set_display_name);
685+
665686
/**
666687
* of_find_backlight_by_node() - find backlight device by device-tree node
667688
* @node: device-tree node of the backlight device

include/linux/backlight.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ struct backlight_properties {
270270
* @scale: The type of the brightness scale.
271271
*/
272272
enum backlight_scale scale;
273+
274+
#define BL_DISPLAY_NAME_LEN 32
275+
/**
276+
* @display_name: Optional name that can be registered to associate a
277+
* backlight device with a display device.
278+
*/
279+
char display_name[BL_DISPLAY_NAME_LEN];
273280
};
274281

275282
/**
@@ -478,12 +485,20 @@ of_find_backlight_by_node(struct device_node *node)
478485

479486
#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
480487
struct backlight_device *devm_of_find_backlight(struct device *dev);
488+
int backlight_set_display_name(struct backlight_device *bd, const char *name);
481489
#else
482490
static inline struct backlight_device *
483491
devm_of_find_backlight(struct device *dev)
484492
{
485493
return NULL;
486494
}
495+
496+
static inline int backlight_set_display_name(struct backlight_device *bd,
497+
const char *name)
498+
{
499+
return 0;
500+
}
501+
487502
#endif
488503

489504
#endif

0 commit comments

Comments
 (0)