backlight: Allow drivers to update the core, and generate events on changes
Subsystems (5)
PATCH 1/3 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.
--- drivers/video/backlight/backlight.c | 23 +++++++++++++++++++++++ include/linux/backlight.h | 1 + 2 files changed, 24 insertions(+), 0 deletions(-)
drivers/video/backlight/backlight.c +23 -0
@@ -120,6 +120,7 @@ static ssize_t backlight_store_brightness(struct device *dev, {int rc;struct backlight_device *bd =to_backlight_device (dev); +char *envp[] = {"SOURCE=userspace" ,NULL };unsigned long brightness; rc =strict_strtoul (buf,0 , &brightness);
@@ -142,6 +143,8 @@ static ssize_t backlight_store_brightness(struct device *dev, }mutex_unlock (&bd->ops_lock); +kobject_uevent_env (&bd->dev.kobj,KOBJ_CHANGE , envp); +return rc; }
@@ -214,6 +217,26 @@ 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) +{ +char *envp[] = {"SOURCE=kernel" ,NULL }; + +mutex_lock (&bd->ops_lock); +if (bd->ops && bd->ops->get_brightness) + bd->props.brightness = bd->ops->get_brightness (bd); +mutex_unlock (&bd->ops_lock); +kobject_uevent_env (&bd->dev.kobj,KOBJ_CHANGE , envp); +} +EXPORT_SYMBOL (backlight_force_update); + +/** * backlight_device_register - create and register a new object of * backlight_device class. * @name: the name of the new object(must be the same as the name of the
include/linux/backlight.h +1 -0
@@ -100,6 +100,7 @@ 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);#define to_backlight_device (obj) container_of(obj, struct backlight_device, dev)
Signature · 1 line
1.6.2.5
PATCH 2/3 ACPI: Update the backlight state when we change brightness
Trigger a status update when we change the brightness in the driver, thus allowing userspace to present appropriate UI.
--- drivers/acpi/video.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/acpi/video.c +2 -0
@@ -1960,6 +1960,8 @@ acpi_video_switch_brightness(struct acpi_video_device *device, int event) result =acpi_video_device_lcd_set_level (device, level_next); +backlight_force_update (device->backlight); + out:if (result) printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
Signature · 1 line
1.6.2.5
PATCH 3/3 eeepc-laptop: Update the backlight state when we change brightness
Trigger a status update when the user hits a brightness key, allowing userspace to present appropriate UI.
--- drivers/platform/x86/eeepc-laptop.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/platform/x86/eeepc-laptop.c +1 -1
@@ -641,7 +641,7 @@ static int notify_brn(void)struct backlight_device *bd = eeepc_backlight_device;if (bd) {int old = bd->props.brightness; - bd->props.brightness =read_brightness (bd); +backlight_force_update (bd);return old; }return -1 ;
Signature · 1 line
1.6.2.5
Quoted 26 lines · Matthew Garrett
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 <[email protected]>--- drivers/video/backlight/backlight.c | 23 +++++++++++++++++++++++ include/linux/backlight.h | 1 + 2 files changed, 24 insertions(+), 0 deletions(-)drivers/video/backlight/backlight.c +1
-0@@ -120,6 +120,7 @@ static ssize_t backlight_store_brightness(struct device *dev, {int rc;struct backlight_device *bd =to_backlight_device (dev); +char *envp[] = {"SOURCE=userspace" ,NULL };unsigned long brightness; rc =strict_strtoul (buf,0 , &brightness);
drivers/video/backlight/backlight.c static ssize_t backlight_store_brightness(struct device *dev, · line 147
Quoted 5 lines
drivers/video/backlight/backlight.c +2
-0@@ -142,6 +143,8 @@ static ssize_t backlight_store_brightness(struct device *dev, }mutex_unlock (&bd->ops_lock); +kobject_uevent_env (&bd->dev.kobj,KOBJ_CHANGE , envp); +
It will be better to send the event to user space only when the brightness is updated successfully.
Quoted 15 lines
drivers/video/backlight/backlight.c +8
-0return rc; }@@ -214,6 +217,26 @@ 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)
drivers/video/backlight/backlight.c static struct device_attribute bl_device_attributes[] = { · line 237
Quoted 10 lines
drivers/video/backlight/backlight.c +10
-0+{ +char *envp[] = {"SOURCE=kernel" ,NULL }; + +mutex_lock (&bd->ops_lock); +if (bd->ops && bd->ops->get_brightness) + bd->props.brightness = bd->ops->get_brightness (bd); +mutex_unlock (&bd->ops_lock); +kobject_uevent_env (&bd->dev.kobj,KOBJ_CHANGE , envp); +} +EXPORT_SYMBOL (backlight_force_update);
It seems that the acpi video driver will send the ACPI event to user space when updating the brightness.
Is it necessary to send the udev-event again?
Thanks.
Quoted 17 lines
drivers/video/backlight/backlight.c +2
-0+ +/** * backlight_device_register - create and register a new object of * backlight_device class. * @name: the name of the new object(must be the same as the name of the include/linux/backlight.h +1
-0@@ -100,6 +100,7 @@ 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);#define to_backlight_device (obj) container_of(obj, struct backlight_device, dev)
Quoted 2 lines · ykzhao
It will be better to send the event to user space only when the brightness is updated successfully.
That guarantees that we have to read back the brightness, which may be expensive on some hardware.
Quoted 3 lines
It seems that the acpi video driver will send the ACPI event to user space when updating the brightness.
Is it necessary to send the udev-event again?
Yes. There's no reason to special-case the ACPI driver.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · ykzhao
It will be better to send the event to user space only when the brightness is updated successfully.
That guarantees that we have to read back the brightness, which may be expensive on some hardware.
Oh, sorry, I see what you mean. I'll update that.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines · Matthew Garrett
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.
Any reasons to not do it using poll() support (since sysfs has it)? Or at least, do both poll and uevents?
Other than that, I like the idea a lot. thinkpad-acpi will use this event support.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 10 lines · Henrique de Moraes Holschuh
Quoted 6 lines · Matthew Garrett
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.
Any reasons to not do it using
poll()support (since sysfs has it)? Or at least, do both poll and uevents?
More code? It doesn't really seem necessary.
Quoted 2 lines
Other than that, I like the idea a lot. thinkpad-acpi will use this event support.
Good, that's one of the use-cases I wanted to deal with - but the hotkey mask stuff is complicated enough that I hadn't got round to touching that yet. The combination of this and the ALSA mixer code should get us full notification.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Matthew Garrett
Quoted 8 lines · Henrique de Moraes Holschuh
Quoted 6 lines · Matthew Garrett
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.
Quoted 4 lines
Quoted 2 lines
Any reasons to not do it using
poll()support (since sysfs has it)? Or at least, do both poll and uevents?More code? It doesn't really seem necessary.
Well, we all know just how marvelously engineered and high-bandwidth the uevent+udev+everything else channel is, don't we?
Adding the poll() notification is not expensive, one line to do it, plus a few more to find out the exact sysfs node that needs to receive the notification (hideous API, that).
Quoted 7 lines
Quoted 2 lines
Other than that, I like the idea a lot. thinkpad-acpi will use this event support.
Good, that's one of the use-cases I wanted to deal with - but the hotkey mask stuff is complicated enough that I hadn't got round to touching that yet. The combination of this and the ALSA mixer code should get us full notification.
Leave it to me. Even if it arrives a bit later than the main patch, it won't cause problems for the merging of the main work anyway, and as you said, it *IS* hairy code to do it right and it plugs right in the middle of the more confusing parts of thinkpad-acpi. I will do it in a way that makes the whole thing also usable for the mixer notifications.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 6 lines · Matthew Garrett
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.
This looks good and I like the idea.
My main concern is that we don't start getting bug reports of 'missing' events and have clearly defined expectations of when we see what kind of events. For example, should an event be emitted when low battery causes the backlight to be limited? How about console blanking events turning off the backlight? Are there any other occasions we should be emitting change events and do we need to audit other drivers?
I did look to see if we could integrate this more into the backlight core but that doesn't look to be possible unfortunately, at least not without changing the drivers which these patches start.
Also, are "userspace" and "kernel" as meaningful as they could be? Would "sysfs" and "hwkeys" make more sense and allow for other future hardware differences? Perhaps someone will tie the backlight to an ambient light sensor for example...
Cheers,
Richard
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre
Quoted 6 lines · Richard Purdie
My main concern is that we don't start getting bug reports of 'missing' events and have clearly defined expectations of when we see what kind of events. For example, should an event be emitted when low battery causes the backlight to be limited? How about console blanking events turning off the backlight? Are there any other occasions we should be emitting change events and do we need to audit other drivers?
These are all good questions. I'm working through the drivers now, and there's definitely a few more that need doing.
Quoted 4 lines
Also, are "userspace" and "kernel" as meaningful as they could be? Would "sysfs" and "hwkeys" make more sense and allow for other future hardware differences? Perhaps someone will tie the backlight to an ambient light sensor for example...
Yes, though we'd need to extend the interface slightly in that case to allow the information to be provided. The ALS case is a good one - if that ends up happening in-kernel then there probably shouldn't be a UI update.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 17 lines · Richard Purdie
Quoted 6 lines · Matthew Garrett
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.
This looks good and I like the idea.
My main concern is that we don't start getting bug reports of 'missing' events and have clearly defined expectations of when we see what kind of events. For example, should an event be emitted when low battery causes the backlight to be limited? How about console blanking events turning off the backlight? Are there any other occasions we should be emitting change events and do we need to audit other drivers?
Quoted 9 lines
I did look to see if we could integrate this more into the backlight core but that doesn't look to be possible unfortunately, at least not without changing the drivers which these patches start.
Also, are "userspace" and "kernel" as meaningful as they could be? Would "sysfs" and "hwkeys" make more sense and allow for other future hardware differences? Perhaps someone will tie the backlight to an ambient light sensor for example...
Hah, I just finished a patch to introduce the ACPI als driver.
I'm not quite familiar with the status of ALS support in Linux kernel. and here is my questions,
I don't think we have a generic sysfs driver for ALS, i.e. ALS class device, right?
do you guys think it's reasonable to have one?
thanks,
rui
Quoted 7 lines · Zhang Rui
Quoted 1 line
Also, are "userspace" and "kernel" as meaningful as they could be?
Would
Quoted 4 lines
"sysfs" and "hwkeys" make more sense and allow for other future hardware differences? Perhaps someone will tie the backlight to an ambient light sensor for example...
Quoted 7 lines
Hah, I just finished a patch to introduce the ACPI als driver.
I'm not quite familiar with the status of ALS support in Linux kernel. and here is my questions,
I don't think we have a generic sysfs driver for ALS, i.e. ALS class device, right?
do you guys think it's reasonable to have one?
We don't have one that I'm aware of.
The first question is what information and configuration options are we likely to have with ALS sensors? If its just a light level reading, the input subsystem is ideally suited for sharing that. Is there configuration we need to expose?
Cheers,
Richard
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre
Quoted 16 lines · Richard Purdie
Quoted 7 lines · Zhang Rui
Quoted 1 line
Also, are "userspace" and "kernel" as meaningful as they could be?
Would
Quoted 4 lines
"sysfs" and "hwkeys" make more sense and allow for other future hardware differences? Perhaps someone will tie the backlight to an ambient light sensor for example...
Quoted 7 lines
Hah, I just finished a patch to introduce the ACPI als driver.
I'm not quite familiar with the status of ALS support in Linux kernel. and here is my questions,
I don't think we have a generic sysfs driver for ALS, i.e. ALS class device, right?
do you guys think it's reasonable to have one?
Quoted 7 lines
We don't have one that I'm aware of.
The first question is what information and configuration options are we likely to have with ALS sensors? If its just a light level reading, the input subsystem is ideally suited for sharing that. Is there configuration we need to expose?
For an ACPI ALS device, only these two are mandatory
1. the current ambient light illuminance.
2. A list of luminance mappings, including the "display luminance adjustment" and "ambient light illuminance", which can be used by OS to determine the ambient light policy.
IMO, the ALS driver should just export these info to user space, and we can do the display backlight adjustment in user space,
via /sys/class/backlight.
thanks,
rui
Quoted 8 lines · Zhang Rui
Quoted 7 lines · Richard Purdie
We don't have one that I'm aware of.
The first question is what information and configuration options are we likely to have with ALS sensors? If its just a light level reading, the input subsystem is ideally suited for sharing that. Is there configuration we need to expose?
Quoted 5 lines
For an ACPI ALS device, only these two are mandatory
1. the current ambient light illuminance.
2. A list of luminance mappings, including the "display luminance adjustment" and "ambient light illuminance", which can be used by OS to determine the ambient light policy.
So there are basically two values we're ever interested in at a given point in time. The current ambient light reading and the corresponding display luminance adjustment. Both of those could just be exposed as an input device really?
Quoted 3 lines
IMO, the ALS driver should just export these info to user space, and we can do the display backlight adjustment in user space,
via/sys/class/backlight.
Agreed, userspace should be where policy is decided. Having a standalone module which connected the two together with a "default" policy might be acceptable too though? If userspace then wants to handle things it just makes sure the module is not loaded.
Cheers,
Richard
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre
Quoted 4 lines · Richard Purdie
So there are basically two values we're ever interested in at a given point in time. The current ambient light reading and the corresponding display luminance adjustment. Both of those could just be exposed as an input device really?
The alternative would be hwmon, I guess.
Quoted 4 lines
Agreed, userspace should be where policy is decided. Having a standalone module which connected the two together with a "default" policy might be acceptable too though? If userspace then wants to handle things it just makes sure the module is not loaded.
You want smoothing even in a default policy, and doing that well might be a bit much for the kernel?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Richard Purdie
So there are basically two values we're ever interested in at a given point in time. The current ambient light reading and the corresponding display luminance adjustment. Both of those could just be exposed as an input device really?
The alternative would be hwmon, I guess.
you mean convert an ACPI ALS device to a hwmon device?
Quoted 9 lines
Quoted 5 lines
Agreed, userspace should be where policy is decided. Having a standalone module which connected the two together with a "default" policy might be acceptable too though? If userspace then wants to handle things it just makes sure the module is not loaded.
You want smoothing even in a default policy, and doing that well might be a bit much for the kernel?
sorry, I don't understand.
do you mean that there should be a default policy in the kernel?
thanks,
rui
Quoted 11 lines · Zhang Rui
Quoted 8 lines · Matthew Garrett
Quoted 4 lines · Richard Purdie
So there are basically two values we're ever interested in at a given point in time. The current ambient light reading and the corresponding display luminance adjustment. Both of those could just be exposed as an input device really?
The alternative would be hwmon, I guess.
you mean convert an ACPI ALS device to a hwmon device?
Yes.
Quoted 5 lines
Quoted 3 lines
You want smoothing even in a default policy, and doing that well might be a bit much for the kernel?
sorry, I don't understand.
do you mean that there should be a default policy in the kernel?
No, I mean that the only default policy you could reasonably have in the kernel would be tying the backlight directly to the ALS. And that sucks. You need some degree of smoothing, and that's a job better left to userspace.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
You want smoothing even in a default policy, and doing that well might be a bit much for the kernel?
sorry, I don't understand.
do you mean that there should be a default policy in the kernel?No, I mean that the only default policy you could reasonably have in the kernel would be tying the backlight directly to the ALS. And that sucks. You need some degree of smoothing, and that's a job better left to userspace.
How would that be done? Wake up userspace 100times a second so it can read an integer and ardd it to running average?
Is ALS device stupid sensor, or can it do some smoothing/watermarks itself?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 7 lines · Pavel Machek
Quoted 4 lines
No, I mean that the only default policy you could reasonably have in the kernel would be tying the backlight directly to the ALS. And that sucks. You need some degree of smoothing, and that's a job better left to userspace.
How would that be done? Wake up userspace 100times a second so it can read an integer and ardd it to running average?
I don't think you'd need more than once a second, possibly modified by the size of the change since the last measurement. Response doesn't need to be immediate.
Quoted 2 lines
Is ALS device stupid sensor, or can it do some smoothing/watermarks itself?
Generally stupid.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Pavel Machek
Quoted 4 lines
No, I mean that the only default policy you could reasonably have in the kernel would be tying the backlight directly to the ALS. And that sucks. You need some degree of smoothing, and that's a job better left to userspace.
Quoted 6 lines
Quoted 2 lines
How would that be done? Wake up userspace 100times a second so it can read an integer and ardd it to running average?
I don't think you'd need more than once a second, possibly modified by the size of the change since the last measurement. Response doesn't need to be immediate.
It depends how fancy your algorithm is really. If its not that complex and not floating point etc. then you probably could have some basic kernel implementation in a few lines of code which used a timer callback to smooth things out. I agree that userspace should be able to run the show if it wants to or its some horrible complex calculation though.
Assuming no complaints I'll queue the patches from this series in the backlight tree in the next could of days. I'll probably include the ACPI bits since they're more backlight than APCI unless Len has an objection.
Cheers,
Richard
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre