Skip to content

Commit

Permalink
backlight: Add a display name to the core, and a function to set it
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
6by9 committed May 17, 2024
1 parent a2bf679 commit 7a8a376
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/video/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions include/linux/backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7a8a376

Please sign in to comment.