Bug 13577

Summary: Broken backlight control on Acer Aspire 8930G due to buggy DSDT/ACPI Video
Product: ACPI Reporter: Hector Martin (marcan)
Component: Power-VideoAssignee: Zhang Rui (rui.zhang)
Status: CLOSED CODE_FIX    
Severity: normal CC: lenb, rui.zhang
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.29 Subsystem:
Regression: No Bisected commit-id:
Attachments: Disassembled DSDT
patch: support backlight control without _DOS
refreshed patch
refreshed patch
dmesg after patch
patch: only one backlight control device under an ACPI video bus device
patch: one ACPI video bus device for one VGA controller
patch: only one backlight control device under an ACPI video bus device
patch for upstream kernel

Description Hector Martin 2009-06-19 04:58:33 UTC
Created attachment 22005 [details]
Disassembled DSDT

Backlight controls on this laptop are broken due to a combination of factors. Apparently, the DSDT supports two methods to set the backlight:

- old WMI / proprietary method. This is supported by acer_wmi.
- ACPI Video interface

When the DSDT detects Windows Vista (which Linux seems to pretend to be), it disables the WMI method and also disables direct control using the hardware keys, instead expecting software to react to those keypresses and control it using the ACPI Video device.

When I do a very ugly EC hack to turn off Vista mode, acer_wmi works fine to set and query the brightness and also the hardware keys work directly, even without acer_wmi. Presumably this will also be the case if Linux doesn't identify itself as Vista to ACPI.

The ACPI Video Interface is broken. There are three devices supported: OVGA, PEGP.EVGA, and PEGP.NVGA. As far as I can tell, OVGA is supposed to be an integrated graphics controller that doesn't exist. EVGA and NVGA are very similar and I don't know which one corresponds to my laptop or how the driver is supposed to tell between them, but clearly one of them is the correct one and corresponds to the modular MXM card on the laptop.

OVGA would work except that it corresponds to a nonexistent PCI device, so acpi_get_physical_pci_device kills it. Hacking this out makes things work (the brightness setting is via the EC anyway, and works the same for all three devices), but that doesn't sound like a good idea.

EVGA and NVGA fail to register as video devices because they lack the _DOS method that ACPI specifies as required for backlight functionality. They do have _DOD, which isn't enough for display output switching support, but at least identifies them as video devices. They fail the acpi_is_video_device because that only checks for backlight support if one of the other three features is fully present. They also fail acpi_video_bus_check because that again wants one of the three features.

At this point I'm unsure of what the best way to fix this is. My guess would be to make acpi_is_video_device check for brightness controls even if only _DOD is present, and also make acpi_video_bus_check consider just _DOD good enough to pass a device. Then the other issue left would be the duplicated device (the backlight control is really messed up when it tries to do the same thing to two different devices). Applying those two hacks and and manually unbinding one of the devices from the driver via sysfs makes things work for me.
Comment 1 Zhang Rui 2009-06-22 02:28:17 UTC
please attach the full acpidump and dmesg output.
Comment 2 Zhang Rui 2009-06-24 01:54:24 UTC
(In reply to comment #0)
> When the DSDT detects Windows Vista (which Linux seems to pretend to be), it
> disables the WMI method and also disables direct control using the hardware
> keys, instead expecting software to react to those keypresses and control it
> using the ACPI Video device.
> 
what if you boot with acpi_osi="!Windows 2006"?

> 
> The ACPI Video Interface is broken. There are three devices supported: OVGA,
> PEGP.EVGA, and PEGP.NVGA. As far as I can tell, OVGA is supposed to be an
> integrated graphics controller that doesn't exist. EVGA and NVGA are very
> similar and I don't know which one corresponds to my laptop or how the driver
> is supposed to tell between them, but clearly one of them is the correct one
> and corresponds to the modular MXM card on the laptop.
> 
> OVGA would work except that it corresponds to a nonexistent PCI device, so
> acpi_get_physical_pci_device kills it. Hacking this out makes things work
> (the
> brightness setting is via the EC anyway, and works the same for all three
> devices), but that doesn't sound like a good idea.
> 
> EVGA and NVGA fail to register as video devices because they lack the _DOS
> method that ACPI specifies as required for backlight functionality. They do
> have _DOD, which isn't enough for display output switching support, but at
> least identifies them as video devices. They fail the acpi_is_video_device
> because that only checks for backlight support if one of the other three
> features is fully present. They also fail acpi_video_bus_check because that
> again wants one of the three features.
> 
> At this point I'm unsure of what the best way to fix this is. My guess would
> be
> to make acpi_is_video_device check for brightness controls even if only _DOD
> is
> present, and also make acpi_video_bus_check consider just _DOD good enough to
> pass a device. Then the other issue left would be the duplicated device (the
> backlight control is really messed up when it tries to do the same thing to
> two
> different devices). Applying those two hacks and and manually unbinding one
> of
> the devices from the driver via sysfs makes things work for me.

hah, then this is apperantly a BIOS problem to me because _DOS is mandatory according to the ACPI spec. But anyway, we should make it work in Linux.
what about this proposal?
1. acpi_is_video_device returns TRUE if only _DOD in found.
2. print a warning message if there is no _DOS method.
3. don't touch _DOS in ACPI video driver if it's not available.
patch will be attached later.
Comment 3 Zhang Rui 2009-06-24 02:22:46 UTC
Created attachment 22071 [details]
patch: support backlight control without _DOS

please try this patch and see if it helps.

BTW: you should be able to
1. get a warning message in the dmesg output.
2. at least one backlight sysfs I/F should be available.
3. at least one ACPI video bus device should be bind to the video driver.

please attach the
1. dmesg
2. "grep . /proc/acpi/video/*/*"
after applying the patch.
Comment 4 Hector Martin 2009-06-24 02:28:20 UTC
That isn't going to work. Check out acpi_video_bus_check: it returns -ENOENT unless either _DOS, _ROM, or _GPD/_SPD/_VPO are present.
Comment 5 Zhang Rui 2009-06-24 02:48:47 UTC
Created attachment 22072 [details]
refreshed patch

hah, you're right.
how about this one?
Comment 6 Zhang Rui 2009-06-24 07:38:28 UTC
Created attachment 22078 [details]
refreshed patch
Comment 7 Hector Martin 2009-06-24 20:07:49 UTC
Created attachment 22084 [details]
dmesg after patch

As expected, both video devices EVGA and NVGA are detected, so the brightness control "works" but the duplicated device causes erratic behavior when it is used.

$ grep . /proc/acpi/video/*/*
/proc/acpi/video/EVGA/DOS:N/A
/proc/acpi/video/EVGA/info:Switching heads:              no
/proc/acpi/video/EVGA/info:Video ROM:                    no
/proc/acpi/video/EVGA/info:Device to be POSTed on boot:  no
/proc/acpi/video/EVGA/POST:<not supported>
/proc/acpi/video/EVGA/POST_info:<not supported>
/proc/acpi/video/EVGA/ROM:<TODO>
/proc/acpi/video/NVGA/DOS:N/A
/proc/acpi/video/NVGA/info:Switching heads:              no
/proc/acpi/video/NVGA/info:Video ROM:                    no
/proc/acpi/video/NVGA/info:Device to be POSTed on boot:  no
/proc/acpi/video/NVGA/POST:<not supported>
/proc/acpi/video/NVGA/POST_info:<not supported>
/proc/acpi/video/NVGA/ROM:<TODO>

$ cat /proc/acpi/video/EVGA/LCD/brightness
levels:  10 20 30 40 50 60 70 80 90 100
current: 10
$ cat /proc/acpi/video/NVGA/LCD0/brightness
levels:  10 20 30 40 50 60 70 80 90 100
current: 10

This gets rid of the redundant EVGA device:
$ echo "device:02">/sys/bus/acpi/drivers/video/unbind

and leaves NVGA, making brightness work properly.

Any clue as to what the correct way of picking the right device should be? I think NVGA is correct on my system, and it is also more complete in the DSDT, but I don't get how the software is supposed to pick out which one to enable and use.
Comment 8 Zhang Rui 2009-06-25 01:59:42 UTC
well, hard to say which one should be used. Actually they are exactly the same to ACPI, which means that software is not able to pick one and drop another.

do you know if there is any newer BIOS available?
If no, in order to make the brightness work on this laptop, I think we need to use the dmi quirk.
Comment 9 Hector Martin 2009-06-25 02:38:01 UTC
There are no newer BIOSes available.
Comment 10 Hector Martin 2009-06-25 02:40:50 UTC
I think that, when the video device is under a parent node with the proper PCI address (as acpi_get_physical_pci_device checks the PEGP device for the address since neither NVGA nor EVGA have real ones), it should only select one of the children, not both.

So: when scanning for video devices, if the device _ADR is invalid and the parent device's _ADR is used instead, only accept the first child device.
Comment 11 Hector Martin 2009-06-25 02:43:05 UTC
Also, interesting off-topic: I've been extracting and breaking up my BIOS and found that the DSDT in there is actually by Insyde, not Acer, and that the compiler is Intel. The BIOS patches in Acer's name and the "1025" compiler ID at runtime. So this DSDT was in fact compiled by iasl.
Comment 12 Zhang Rui 2009-06-25 05:53:19 UTC
NVGA and EVGA are independent ACPI devices in this case.
It's really ugly to check these two devices and discard the second one neither in ACPI video driver or in ACPI video scan/detect code.
Comment 13 Zhang Rui 2009-06-25 05:59:01 UTC
I tried, but soon gave up. Because that's not a clean way for this issue neither.
Comment 14 Zhang Rui 2009-07-06 03:22:43 UTC
Created attachment 22223 [details]
patch: only one backlight control device under an ACPI video bus device

please try this patch and see if it helps.
Comment 15 Hector Martin 2009-07-08 18:24:42 UTC
There's a bug in the patch: the if() should check for !device->video->brightness_dev. Even with that fix, it doesn't seem to work. I still get two video devices with backlight support because they're under different "buses". Also, if I reload the video module, no backlight support is detected because the flag is already set for the bus.
Comment 16 Hector Martin 2009-07-08 18:43:04 UTC
Looks like I have further breakage anyway. I'm on 2.6.30-gentoo-r2 now, I'm tracking down some weirdness on the video driver which I think is unrelated.
Comment 17 Hector Martin 2009-07-08 20:16:53 UTC
Ok, _BQC is broken on my laptop sometimes (depends on some EC register). I've submitted a patch for that to you via email and CC'd linux-acpi.

The duplicated backlight device problem still stands though.
Comment 18 Zhang Rui 2009-07-09 01:05:36 UTC
well. you're right, I misunderstood the problem.
there are two video bus devices under the same pci device node...
Comment 19 Zhang Rui 2009-07-15 06:49:25 UTC
Created attachment 22347 [details]
patch: one ACPI video bus device for one VGA controller

please try this patch.
Comment 20 Hector Martin 2009-07-15 08:48:43 UTC
That did the trick - it only binds to the first video device (02). The second device reports an error in dmesg though:

video: probe of device:06 failed with error -17

Maybe it should be hidden or turned into a warning ("ignoring duplicate video device" or something similar).

Other than that, everything works now. Good job :)
Comment 21 Zhang Rui 2009-07-15 09:11:29 UTC
Created attachment 22351 [details]
patch: only one backlight control device under an ACPI video bus device

this patch should remove the old error message and print a warning message instead.
please give it a try.

this may bring some side effects on the other laptops, but who knows.
I'll send this patch to the ACPI test tree, but not sure it can be merged.
Comment 22 Len Brown 2009-08-30 02:20:15 UTC
applied to bugzilla-13577-video-TEST in acpi-test tree
Comment 23 Hector Martin 2009-08-30 03:37:41 UTC
Please apply attachment 22078 [details] too, both are required for this to work. 22078 makes the two video devices usable, then 22351 disables the redundant one.
Comment 24 Zhang Rui 2009-08-31 05:36:31 UTC
you can use http://patchwork.kernel.org/patch/43618/ as a replacement.
Comment 25 Len Brown 2009-11-25 03:00:40 UTC
> you can use http://patchwork.kernel.org/patch/43618/ as a replacement.

shipped upstream in 2.6.32-rc5

so do we still need the patches in comment #6 or comment #21?
Comment 26 Zhang Rui 2009-11-25 03:42:50 UTC
no,
the patch in comment #6 is replaced by patch http://patchwork.kernel.org/patch/43618/
the patch in comment #21 is kinda arbitrary. and IMO, a warning message is more acceptable here.
Comment 27 Zhang Rui 2009-11-26 06:10:27 UTC
please attach the lspci output of your laptop.
Comment 28 Zhang Rui 2009-11-26 06:21:32 UTC
does the WMI work again if you boot with kernel parameter acpi_osi="!windows 2006"?
Comment 29 Hector Martin 2009-12-08 23:36:03 UTC
2.6.32 appears to work fine. The duplicated backlight device remains, though it does not appear to be causing trouble as far as I can tell.
Comment 30 Len Brown 2009-12-16 00:48:30 UTC
please re-open if there remains an unresolved issue here.
Comment 31 Zhang Rui 2009-12-30 06:07:46 UTC
Created attachment 24374 [details]
patch for upstream kernel

this is the refreshed patch for upstream kernel, please test it.
Comment 32 Len Brown 2010-01-23 19:08:48 UTC
commit c504f8cb68eb0d6cde53ba043daff8cb34586493
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Dec 30 15:59:23 2009 +0800

    ACPI video: Prune dupe video devices, unless "video.allow_duplicates"


shipped in Linux-2.6.33-rc5
closed