diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-03-19 12:22:52 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-03-24 19:26:55 -0400 |
commit | 994fa63c5b126df6e9f31ef4e09000e2e243234b (patch) | |
tree | b6214bc68418cae8935248c4d997318702c98daf /drivers/acpi | |
parent | 2d4128a25206685aaccaf14220c8436b11c6dc01 (diff) |
ACPI / video: Fix applying indexed initial brightness value.
The value initially read via _BQC also needs to be offset by 2 to
compensate for the first 2 special items in _BCL. Introduce a helper
function that does the BQC-value-to-level conversion in order to not
needlessly duplicate code.
Signed-off-by: Danny Baumann <dannybaumann@web.de>
Reviewed-by: Aaron Lu <aaron.lu@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/video.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 8522d14972cf..3cdd0471bc63 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -458,6 +458,31 @@ static struct dmi_system_id video_dmi_table[] __initdata = { | |||
458 | {} | 458 | {} |
459 | }; | 459 | }; |
460 | 460 | ||
461 | static unsigned long long | ||
462 | acpi_video_bqc_value_to_level(struct acpi_video_device *device, | ||
463 | unsigned long long bqc_value) | ||
464 | { | ||
465 | unsigned long long level; | ||
466 | |||
467 | if (device->brightness->flags._BQC_use_index) { | ||
468 | /* | ||
469 | * _BQC returns an index that doesn't account for | ||
470 | * the first 2 items with special meaning, so we need | ||
471 | * to compensate for that by offsetting ourselves | ||
472 | */ | ||
473 | if (device->brightness->flags._BCL_reversed) | ||
474 | bqc_value = device->brightness->count - 3 - bqc_value; | ||
475 | |||
476 | level = device->brightness->levels[bqc_value + 2]; | ||
477 | } else { | ||
478 | level = bqc_value; | ||
479 | } | ||
480 | |||
481 | level += bqc_offset_aml_bug_workaround; | ||
482 | |||
483 | return level; | ||
484 | } | ||
485 | |||
461 | static int | 486 | static int |
462 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, | 487 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, |
463 | unsigned long long *level, bool raw) | 488 | unsigned long long *level, bool raw) |
@@ -480,14 +505,8 @@ acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, | |||
480 | return 0; | 505 | return 0; |
481 | } | 506 | } |
482 | 507 | ||
483 | if (device->brightness->flags._BQC_use_index) { | 508 | *level = acpi_video_bqc_value_to_level(device, *level); |
484 | if (device->brightness->flags._BCL_reversed) | ||
485 | *level = device->brightness->count | ||
486 | - 3 - (*level); | ||
487 | *level = device->brightness->levels[*level + 2]; | ||
488 | 509 | ||
489 | } | ||
490 | *level += bqc_offset_aml_bug_workaround; | ||
491 | for (i = 2; i < device->brightness->count; i++) | 510 | for (i = 2; i < device->brightness->count; i++) |
492 | if (device->brightness->levels[i] == *level) { | 511 | if (device->brightness->levels[i] == *level) { |
493 | device->brightness->curr = *level; | 512 | device->brightness->curr = *level; |
@@ -736,24 +755,19 @@ acpi_video_init_brightness(struct acpi_video_device *device) | |||
736 | 755 | ||
737 | br->flags._BQC_use_index = (level == max_level ? 0 : 1); | 756 | br->flags._BQC_use_index = (level == max_level ? 0 : 1); |
738 | 757 | ||
739 | if (!br->flags._BQC_use_index) { | 758 | if (use_bios_initial_backlight) { |
759 | level = acpi_video_bqc_value_to_level(device, level_old); | ||
740 | /* | 760 | /* |
741 | * Set the backlight to the initial state. | 761 | * On some buggy laptops, _BQC returns an uninitialized |
742 | * On some buggy laptops, _BQC returns an uninitialized value | 762 | * value when invoked for the first time, i.e. |
743 | * when invoked for the first time, i.e. level_old is invalid. | 763 | * level_old is invalid (no matter whether it's a level |
744 | * set the backlight to max_level in this case | 764 | * or an index). Set the backlight to max_level in this case. |
745 | */ | 765 | */ |
746 | if (use_bios_initial_backlight) { | 766 | for (i = 2; i < br->count; i++) |
747 | for (i = 2; i < br->count; i++) | 767 | if (level_old == br->levels[i]) |
748 | if (level_old == br->levels[i]) { | 768 | break; |
749 | level = level_old; | 769 | if (i == br->count) |
750 | break; | 770 | level = max_level; |
751 | } | ||
752 | } | ||
753 | } else { | ||
754 | if (br->flags._BCL_reversed) | ||
755 | level_old = (br->count - 1) - level_old; | ||
756 | level = br->levels[level_old]; | ||
757 | } | 771 | } |
758 | 772 | ||
759 | set_level: | 773 | set_level: |