diff mbox

[2/2] ACPI video: work-around BIOS AML bug in _BQC

Message ID 1254340105-19372-3-git-send-email-stefan.bader@canonical.com
State Accepted
Headers show

Commit Message

Stefan Bader Sept. 30, 2009, 7:48 p.m. UTC
From: Zhang Rui <rui.zhang@intel.com>

BugLink: https://bugs.launchpad.net/bugs/428910

commit 90c53ca426cb93d15eefea79dcf6bd15ad3ffeb4 upstream

_BQC on some laptops returns an uninitialized value when it's
invoked for the first time.

Set the laptop to the maximum backlight level in this case.
http://bugzilla.kernel.org/attachment.cgi?id=22675

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
 drivers/acpi/video.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 57abb8c..54c6942 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -878,7 +878,7 @@  acpi_video_init_brightness(struct acpi_video_device *device)
 	br->flags._BCM_use_index = br->flags._BCL_use_index;
 
 	/* _BQC uses INDEX while _BCL uses VALUE in some laptops */
-	br->curr = level_old = max_level;
+	br->curr = level = max_level;
 
 	if (!device->cap._BQC)
 		goto set_level;
@@ -900,15 +900,25 @@  acpi_video_init_brightness(struct acpi_video_device *device)
 
 	br->flags._BQC_use_index = (level == max_level ? 0 : 1);
 
-	if (!br->flags._BQC_use_index)
+	if (!br->flags._BQC_use_index) {
+		/*
+		 * Set the backlight to the initial state.
+		 * On some buggy laptops, _BQC returns an uninitialized value
+		 * when invoked for the first time, i.e. level_old is invalid.
+		 * set the backlight to max_level in this case
+		 */
+		for (i = 2; i < br->count; i++)
+			if (level_old == br->levels[i])
+				level = level_old;
 		goto set_level;
+	}
 
 	if (br->flags._BCL_reversed)
 		level_old = (br->count - 1) - level_old;
-	level_old = br->levels[level_old];
+	level = br->levels[level_old];
 
 set_level:
-	result = acpi_video_device_lcd_set_level(device, level_old);
+	result = acpi_video_device_lcd_set_level(device, level);
 	if (result)
 		goto out_free_levels;