Skip to content

Commit 325253a

Browse files
Matthew Garrettrpurdie
authored andcommitted
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: Matthew Garrett <mjg@redhat.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
1 parent 0f7e727 commit 325253a

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎drivers/video/backlight/backlight.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ static inline void backlight_unregister_fb(struct backlight_device *bd)
7373
}
7474
#endif /* CONFIG_FB */
7575

76+
static void backlight_generate_event(struct backlight_device *bd,
77+
enum backlight_update_reason reason)
78+
{
79+
char *envp[2];
80+
81+
switch (reason) {
82+
case BACKLIGHT_UPDATE_SYSFS:
83+
envp[0] = "SOURCE=sysfs";
84+
break;
85+
case BACKLIGHT_UPDATE_HOTKEY:
86+
envp[0] = "SOURCE=hotkey";
87+
break;
88+
default:
89+
envp[0] = "SOURCE=unknown";
90+
break;
91+
}
92+
envp[1] = NULL;
93+
kobject_uevent_env(&bd->dev.kobj, KOBJ_CHANGE, envp);
94+
}
95+
7696
static ssize_t backlight_show_power(struct device *dev,
7797
struct device_attribute *attr,char *buf)
7898
{
@@ -142,6 +162,8 @@ static ssize_t backlight_store_brightness(struct device *dev,
142162
}
143163
mutex_unlock(&bd->ops_lock);
144164

165+
backlight_generate_event(bd, BACKLIGHT_UPDATE_SYSFS);
166+
145167
return rc;
146168
}
147169

@@ -213,6 +235,25 @@ static struct device_attribute bl_device_attributes[] = {
213235
__ATTR_NULL,
214236
};
215237

238+
/**
239+
* backlight_force_update - tell the backlight subsystem that hardware state
240+
* has changed
241+
* @bd: the backlight device to update
242+
*
243+
* Updates the internal state of the backlight in response to a hardware event,
244+
* and generate a uevent to notify userspace
245+
*/
246+
void backlight_force_update(struct backlight_device *bd,
247+
enum backlight_update_reason reason)
248+
{
249+
mutex_lock(&bd->ops_lock);
250+
if (bd->ops && bd->ops->get_brightness)
251+
bd->props.brightness = bd->ops->get_brightness(bd);
252+
mutex_unlock(&bd->ops_lock);
253+
backlight_generate_event(bd, reason);
254+
}
255+
EXPORT_SYMBOL(backlight_force_update);
256+
216257
/**
217258
* backlight_device_register - create and register a new object of
218259
* backlight_device class.

‎include/linux/backlight.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
* Any other use of the locks below is probably wrong.
2828
*/
2929

30+
enum backlight_update_reason {
31+
BACKLIGHT_UPDATE_HOTKEY,
32+
BACKLIGHT_UPDATE_SYSFS,
33+
};
34+
3035
struct backlight_device;
3136
struct fb_info;
3237

@@ -100,6 +105,8 @@ static inline void backlight_update_status(struct backlight_device *bd)
100105
extern struct backlight_device *backlight_device_register(const char *name,
101106
struct device *dev, void *devdata, struct backlight_ops *ops);
102107
extern void backlight_device_unregister(struct backlight_device *bd);
108+
extern void backlight_force_update(struct backlight_device *bd,
109+
enum backlight_update_reason reason);
103110

104111
#define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
105112

0 commit comments

Comments
 (0)