Commit 325253a6 authored by Matthew Garrett's avatar Matthew Garrett Committed by Richard Purdie

backlight: Allow drivers to update the core, and generate events on changes

Certain hardware will send us events when the backlight brightness
changes. Add a function to update the value in the core, and
additionally send a uevent so that userspace can pop up appropriate
UI. The uevents are flagged depending on whether the update originated
in the kernel or from userspace, making it easier to only display UI
at the appropriate time.
Signed-off-by: default avatarMatthew Garrett <>
Signed-off-by: default avatarRichard Purdie <>
parent 0f7e7273
......@@ -73,6 +73,26 @@ static inline void backlight_unregister_fb(struct backlight_device *bd)
#endif /* CONFIG_FB */
static void backlight_generate_event(struct backlight_device *bd,
enum backlight_update_reason reason)
char *envp[2];
switch (reason) {
envp[0] = "SOURCE=sysfs";
envp[0] = "SOURCE=hotkey";
envp[0] = "SOURCE=unknown";
envp[1] = NULL;
kobject_uevent_env(&bd->dev.kobj, KOBJ_CHANGE, envp);
static ssize_t backlight_show_power(struct device *dev,
struct device_attribute *attr,char *buf)
......@@ -142,6 +162,8 @@ static ssize_t backlight_store_brightness(struct device *dev,
backlight_generate_event(bd, BACKLIGHT_UPDATE_SYSFS);
return rc;
......@@ -213,6 +235,25 @@ static struct device_attribute bl_device_attributes[] = {
* backlight_force_update - tell the backlight subsystem that hardware state
* has changed
* @bd: the backlight device to update
* Updates the internal state of the backlight in response to a hardware event,
* and generate a uevent to notify userspace
void backlight_force_update(struct backlight_device *bd,
enum backlight_update_reason reason)
if (bd->ops && bd->ops->get_brightness)
bd->props.brightness = bd->ops->get_brightness(bd);
backlight_generate_event(bd, reason);
* backlight_device_register - create and register a new object of
* backlight_device class.
......@@ -27,6 +27,11 @@
* Any other use of the locks below is probably wrong.
enum backlight_update_reason {
struct backlight_device;
struct fb_info;
......@@ -100,6 +105,8 @@ static inline void backlight_update_status(struct backlight_device *bd)
extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, struct backlight_ops *ops);
extern void backlight_device_unregister(struct backlight_device *bd);
extern void backlight_force_update(struct backlight_device *bd,
enum backlight_update_reason reason);
#define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment