From 8675b979b9a4bf86f7bf3b8ed1290391b0b1d593 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Tue, 19 Mar 2013 16:22:52 +0000 Subject: [PATCH] --- yaml --- r: 367607 b: refs/heads/master c: 994fa63c5b126df6e9f31ef4e09000e2e243234b h: refs/heads/master i: 367605: 1e06b081696747caa82e15b6636eb4a9844d3bbb 367603: 1d26946db9701b373f0a458cfde4fc3e27e57035 367599: 014658f9ce28c213a201e96d3b094e6f42dce769 v: v3 --- [refs] | 2 +- trunk/drivers/acpi/video.c | 60 +++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/[refs] b/[refs] index 1517e451aa76..41a64204d680 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 2d4128a25206685aaccaf14220c8436b11c6dc01 +refs/heads/master: 994fa63c5b126df6e9f31ef4e09000e2e243234b diff --git a/trunk/drivers/acpi/video.c b/trunk/drivers/acpi/video.c index 8522d14972cf..3cdd0471bc63 100644 --- a/trunk/drivers/acpi/video.c +++ b/trunk/drivers/acpi/video.c @@ -458,6 +458,31 @@ static struct dmi_system_id video_dmi_table[] __initdata = { {} }; +static unsigned long long +acpi_video_bqc_value_to_level(struct acpi_video_device *device, + unsigned long long bqc_value) +{ + unsigned long long level; + + if (device->brightness->flags._BQC_use_index) { + /* + * _BQC returns an index that doesn't account for + * the first 2 items with special meaning, so we need + * to compensate for that by offsetting ourselves + */ + if (device->brightness->flags._BCL_reversed) + bqc_value = device->brightness->count - 3 - bqc_value; + + level = device->brightness->levels[bqc_value + 2]; + } else { + level = bqc_value; + } + + level += bqc_offset_aml_bug_workaround; + + return level; +} + static int acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, unsigned long long *level, bool raw) @@ -480,14 +505,8 @@ acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, return 0; } - if (device->brightness->flags._BQC_use_index) { - if (device->brightness->flags._BCL_reversed) - *level = device->brightness->count - - 3 - (*level); - *level = device->brightness->levels[*level + 2]; + *level = acpi_video_bqc_value_to_level(device, *level); - } - *level += bqc_offset_aml_bug_workaround; for (i = 2; i < device->brightness->count; i++) if (device->brightness->levels[i] == *level) { device->brightness->curr = *level; @@ -736,24 +755,19 @@ 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 (use_bios_initial_backlight) { + level = acpi_video_bqc_value_to_level(device, level_old); /* - * 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 + * On some buggy laptops, _BQC returns an uninitialized + * value when invoked for the first time, i.e. + * level_old is invalid (no matter whether it's a level + * or an index). Set the backlight to max_level in this case. */ - if (use_bios_initial_backlight) { - for (i = 2; i < br->count; i++) - if (level_old == br->levels[i]) { - level = level_old; - break; - } - } - } else { - if (br->flags._BCL_reversed) - level_old = (br->count - 1) - level_old; - level = br->levels[level_old]; + for (i = 2; i < br->count; i++) + if (level_old == br->levels[i]) + break; + if (i == br->count) + level = max_level; } set_level: