ACPI video: poke display on lid open
Subsystems (2)
PATCH v2 1/1 ACPI video: poke display on lid open
Many Dell laptops have the DSDT coded to power down the display when the lid is closed, and leave it off when it is opened.
http://bugzilla.kernel.org/show_bug.cgi?id=5155
Based on ideas from Len Brown and Dmitry Torokhov, this patch creates an input handler in the video driver which monitors for lid input events. When a lid open event is detected, the video driver reactivates the LCD.
drivers/acpi/button.c +0 -2
@@ -56,8 +56,6 @@#define ACPI_BUTTON_SUBCLASS_LID "lid"#define ACPI_BUTTON_HID_LID "PNP0C0D" -#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch" -#define ACPI_BUTTON_TYPE_LID 0x05#define _COMPONENT ACPI_BUTTON_COMPONENTACPI_MODULE_NAME ("button" );
drivers/acpi/video.c +127 -12
193 lines not on this page · raw message
include/acpi/acpi_drivers.h +8 -0
@@ -140,6 +140,14 @@ static inline void unregister_hotplug_do#endif /*-------------------------------------------------------------------------- +Button +-------------------------------------------------------------------------- */ + +/* definitions shared between button and video drivers */ +#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch" +#define ACPI_BUTTON_TYPE_LID 0x05 + +/*-------------------------------------------------------------------------- Suspend/Resume -------------------------------------------------------------------------- */ #ifdef CONFIG_ACPI_SLEEP
drivers/acpi/Kconfig +3 -3
@@ -124,13 +124,13 @@ config ACPI_BUTTON config ACPI_VIDEO tristate "Video" - depends on X86 && BACKLIGHT_CLASS_DEVICE + depends on X86 && BACKLIGHT_CLASS_DEVICE && INPUT help This driver implement the ACPI Extensions For Display Adapters for integrated graphics devices on motherboard, as specified in ACPI 2.0 Specification, Appendix B, allowing to perform some basic - control like defining the video POST device, retrieving EDID information - or to setup a video output, etc. + control like defining the video POST device, retrieving EDID + information or to setup a video output, etc. Note that this is an ref. implementation only. It may or may not work for your integrated video device.
Hi Daniel,
Quoted 9 lines · Daniel Drake
Many Dell laptops have the DSDT coded to power down the display when the lid is closed, and leave it off when it is opened.
http://bugzilla.kernel.org/show_bug.cgi?id=5155
Based on ideas from Len Brown and Dmitry Torokhov, this patch creates an input handler in the video driver which monitors for lid input events. When a lid open event is detected, the video driver reactivates the LCD.
Appears to be working on my Inspiron 8100. Couple of comments:
Quoted 4 lines
drivers/acpi/video.c +4
-0+ +static int lid_connect (struct input_handler *handler,struct input_dev *dev, +const struct input_device_id *id) +{
drivers/acpi/video.c static int acpi_video_bus_put_devices(st · line 1748
Quoted 10 lines
drivers/acpi/video.c +10
-0+struct acpi_video_bus *video = handler->private; +int r; + +if (dev->id.product !=ACPI_BUTTON_TYPE_LID || +strcmp (dev->name,ACPI_BUTTON_DEVICE_NAME_LID ) !=0 ) +return -ENODEV ; + +if (video->lid_handle !=NULL ) { + printk(KERN_ERR PREFIX "trying to bind to multiple lids?\n"); +return -ENODEV ;
If we do not support multiple LIDs -EBUSY would be a better error code.
drivers/acpi/video.c static int acpi_video_bus_put_devices(st · line 1756
Quoted 8 lines
drivers/acpi/video.c +8
-0+ } + + video->lid_handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!video->lid_handle) +return -ENOMEM ; + video->lid_handle->dev = dev; + video->lid_handle->handler = handler; + video->lid_handle->private = video;
Need to setup handler->name, otherwise "cat /proc/bus/input/devices" looks "interesting".
drivers/acpi/video.c static int acpi_video_bus_put_devices(st · line 1795
Quoted 11 lines
drivers/acpi/video.c +11
-0+ +static void lid_event (struct input_handle *handle,unsigned int type, +unsigned int code,int value) +{ +struct acpi_video_device *dev, *tmp; +struct acpi_video_bus *video = handle->private; + +if (type !=EV_SW || value !=0 ) +return ; + +list_for_each_entry_safe (dev, tmp, &video->video_device_list, entry) {
Safe from what? I don't see anything altering list state in the body of this loop. Where's list locking? Also, once input core locking is in place handler_>event will be called under a spinlock with interrupts off. Can acpi_video_device_set_state be used in this case?
Below is a small cleanup patch you may want to fold into yours.
But I guess more important question if this is a good solution overall. My box already generates video bus events when I close and open the lid so maybe video.c should just call acpi_video__device_set_state() from acpi_video_bus_notify()?
Signature · 62 lines
Dmitry Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/acpi/video.c | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-) Index: work/drivers/acpi/video.c =================================================================== --- work.orig/drivers/acpi/video.c +++ work/drivers/acpi/video.c @@ -1737,6 +1737,7 @@ static int lid_connect(struct input_hand const struct input_device_id *id) { struct acpi_video_bus *video = handler->private; + struct input_handle *lid_handle; int r; if (dev->id.product != ACPI_BUTTON_TYPE_LID || @@ -1748,18 +1749,22 @@ static int lid_connect(struct input_hand return -ENODEV; } - video->lid_handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); - if (!video->lid_handle) + lid_handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); + if (!lid_handle) return -ENOMEM; - video->lid_handle->dev = dev; - video->lid_handle->handler = handler; - video->lid_handle->private = video; - r = input_register_handle(video->lid_handle); + video->lid_handle = lid_handle; + + lid_handle->dev = dev; + lid_handle->handler = handler; + lid_handle->name = "acpi-video"; + lid_handle->private = video; + + r = input_register_handle(lid_handle); if (r) goto err; - r = input_open_device(video->lid_handle); + r = input_open_device(lid_handle); if (r) goto err_unregister; @@ -1777,9 +1782,10 @@ err: static void lid_disconnect(struct input_handle *handle) { struct acpi_video_bus *video = handle->private; - input_unregister_handle(handle); + input_close_device(handle); - kfree(video->lid_handle); + input_unregister_handle(handle); + kfree(handle); video->lid_handle = NULL; }
Quoted 1 line · Dmitry Torokhov
If we do not support multiple LIDs
-EBUSYwould be a better error code.
OK.
Quoted 2 lines
Need to setup
handler->name, otherwise "cat/proc/bus/input/devices" looks "interesting".
OK.
Quoted 2 lines
Safe from what? I don't see anything altering list state in the body of this loop. Where's list locking?
The current driver has no list locking. I iterate over the list in the way that the rest of the code does.
Quoted 3 lines
Also, once input core locking is
in place handler_>event will be called under a spinlock with interrupts off. Canacpi_video_device_set_statebe used in this case?
I'm not sure, hopefully someone with more ACPI knowledge can pipe up here...
Quoted 1 line
Below is a small cleanup patch you may want to fold into yours.
Thanks, makes sense.
Quoted 4 lines
But I guess more important question if this is a good solution overall. My box already generates video bus events when I close and open the lid so maybe
video.cshould just callacpi_video__device_set_state()fromacpi_video_bus_notify()?
I think trying to handle this from video bus events would be nastier than the input event monitoring approach, because the events are neither meaningful or consistent.
The events that are generated (and the devices they are raised on) vary between Dell laptops. Also, the events you see are generated both on lid open and lid close, with no differences.
Yes, it's a really stupid DSDT in this respect. The code logic is approximately as follows: (and bear in mind that this executes on BOTH open and close)
power down display
send notification asking O/S to reinitialize PCI bus send notification asking O/S to reinitialize video bus sent notification of video status change sent notification of video status change (again)
Yes, Dell BIOSes power down the display when you close the lid, and then *again* when you open it. Yes, Dell BIOSes ask the O/S to reinitialize the whole PCI bus when you close/open your lid (fortunately Linux does not respond to this particular notification at the moment).
Daniel