diff options
author | Matthew Garrett <mjg@redhat.com> | 2009-07-14 12:06:02 -0400 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2009-09-21 16:03:58 -0400 |
commit | 325253a6b2de4bdfa9ef0e28b5df8a4a4fe2b677 (patch) | |
tree | a9fff6fda2ac9f36b494779e76e66222ce540b28 /drivers/video/backlight/backlight.c | |
parent | 0f7e7273803aa03ad7a0e210461a3db9d35e7abb (diff) |
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>
Diffstat (limited to 'drivers/video/backlight/backlight.c')
-rw-r--r-- | drivers/video/backlight/backlight.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 157057c79ca3..6e1446ae7f52 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c | |||
@@ -73,6 +73,26 @@ static inline void backlight_unregister_fb(struct backlight_device *bd) | |||
73 | } | 73 | } |
74 | #endif /* CONFIG_FB */ | 74 | #endif /* CONFIG_FB */ |
75 | 75 | ||
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 | |||
76 | static ssize_t backlight_show_power(struct device *dev, | 96 | static ssize_t backlight_show_power(struct device *dev, |
77 | struct device_attribute *attr,char *buf) | 97 | struct device_attribute *attr,char *buf) |
78 | { | 98 | { |
@@ -142,6 +162,8 @@ static ssize_t backlight_store_brightness(struct device *dev, | |||
142 | } | 162 | } |
143 | mutex_unlock(&bd->ops_lock); | 163 | mutex_unlock(&bd->ops_lock); |
144 | 164 | ||
165 | backlight_generate_event(bd, BACKLIGHT_UPDATE_SYSFS); | ||
166 | |||
145 | return rc; | 167 | return rc; |
146 | } | 168 | } |
147 | 169 | ||
@@ -214,6 +236,25 @@ static struct device_attribute bl_device_attributes[] = { | |||
214 | }; | 236 | }; |
215 | 237 | ||
216 | /** | 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 | |||
257 | /** | ||
217 | * backlight_device_register - create and register a new object of | 258 | * backlight_device_register - create and register a new object of |
218 | * backlight_device class. | 259 | * backlight_device class. |
219 | * @name: the name of the new object(must be the same as the name of the | 260 | * @name: the name of the new object(must be the same as the name of the |