Bug 72491

Summary: acpi backlight does not expose full brightness on Haswell-ULT
Product: ACPI Reporter: Nico Schottelius (nico-bugzilla.kernel.org)
Component: Power-VideoAssignee: Aaron Lu (aaron.lu)
Status: CLOSED CODE_FIX    
Severity: normal CC: aaron.lu, mike.cloaked, solenskiner
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.13.6-1-ARCH Subsystem:
Regression: No Bisected commit-id:
Attachments: acpidump
dmesg
Restore backlight conversion precision

Description Nico Schottelius 2014-03-19 17:54:04 UTC
When trying to increase the backlight to the maximum via acpi, it only reaches 765 of 937 as seen in the intel driver.

How to reproduce:

% xbacklight -set 100
% cat /sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight/brightness 
765

% cat /sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight/max_brightness 
937


echo'ing 937 > the brightness file increases the backlight a lot and imho this maximum value should be exposed via ACPI.


This is a follow up of a bug reported at x.org: https://bugs.freedesktop.org/show_bug.cgi?id=75085


Background information:

Lenovo Yoga 2 Pro
[18:50] artist:intel_backlight% lspci
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 09)
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 09)
00:03.0 Audio device: Intel Corporation Device 0a0c (rev 09)
00:04.0 Signal processing controller: Intel Corporation Device 0a03 (rev 09)
00:14.0 USB controller: Intel Corporation Lynx Point-LP USB xHCI HC (rev 04)
00:16.0 Communication controller: Intel Corporation Lynx Point-LP HECI #0 (rev 04)
00:1b.0 Audio device: Intel Corporation Lynx Point-LP HD Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 1 (rev e4)
00:1d.0 USB controller: Intel Corporation Lynx Point-LP USB EHCI #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation Lynx Point-LP LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation Lynx Point-LP SATA Controller 1 [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation Lynx Point-LP SMBus Controller (rev 04)
00:1f.6 Signal processing controller: Intel Corporation Lynx Point-LP Thermal (rev 04)
01:00.0 Network controller: Intel Corporation Wireless 7260 (rev 6b)

[18:52] artist:intel_backlight% X -version          

X.Org X Server 1.15.0
Release Date: 2013-12-27
X Protocol Version 11, Revision 0
Build Operating System: Linux 3.12.5-1-ARCH x86_64 
Current Operating System: Linux artist 3.13.6-1-ARCH #1 SMP PREEMPT Fri Mar 7 22:47:48 CET 2014 x86_64
Kernel command line: BOOT_IMAGE=/vmlinuz-linux root=/dev/mapper/root rw cryptdevice=/dev/sda3:root quiet
Build Date: 09 January 2014  08:47:24AM
 
Current version of pixman: 0.32.4
	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.



[18:53] artist:intel_backlight% pacman -Q | grep -e xorg -e "^linux "
linux 3.13.6-1
xorg-bdftopcf 1.0.4-1
xorg-font-util 1.3.0-1
xorg-font-utils 7.6-3
xorg-fonts-100dpi 1.0.1-4
xorg-fonts-75dpi 1.0.3-1
xorg-fonts-alias 1.0.3-1
xorg-fonts-encodings 1.0.4-3
xorg-fonts-misc 1.0.1-2
xorg-luit 1.1.1-2
xorg-mkfontdir 1.0.7-1
xorg-mkfontscale 1.1.1-1
xorg-server 1.15.0-5
xorg-server-common 1.15.0-5
xorg-server-devel 1.15.0-5
xorg-server-xnest 1.15.0-5
xorg-setxkbmap 1.3.0-1
xorg-util-macros 1.18.0-1
xorg-xauth 1.0.8-1
xorg-xbacklight 1.2.0-1
xorg-xdpyinfo 1.3.1-1
xorg-xev 1.2.1-1
xorg-xinit 1.3.3-3
xorg-xinput 1.6.1-1
xorg-xkbcomp 1.2.4-1
xorg-xkill 1.0.4-1
xorg-xrandr 1.4.1-1
xorg-xrdb 1.1.0-1
xorg-xset 1.2.3-1
xorg-xsetroot 1.1.1-1
xorg-xwd 1.0.6-1
Comment 1 Aaron Lu 2014-03-20 08:44:27 UTC
acpidump and dmesg please.
Comment 2 Nico Schottelius 2014-03-20 08:52:34 UTC
Created attachment 130081 [details]
acpidump
Comment 3 Nico Schottelius 2014-03-20 08:53:50 UTC
Created attachment 130091 [details]
dmesg
Comment 4 Nico Schottelius 2014-03-20 08:55:04 UTC
Let me know if you need any further information.

Cheers,

Nico
Comment 5 Aaron Lu 2014-03-20 09:14:15 UTC
Oh I see, it's my bad.
It's caused by commit:
commit 22505b82a2800bddb67908522833bef96dd15845
Author: Aaron Lu <aaron.lu@intel.com>
Date:   Fri Aug 2 09:16:03 2013 +0800

    drm/i915: avoid brightness overflow when doing scale

Where to avoid a integer overflow, I modified the backlight level scale code:

 	/* scale to hardware */
-	level = level * freq / max;
+	if (freq < max)
+		level = level * freq / max;
+	else
+		level = freq / max * level;

And the freq=937, max=255, level=255, yields the result=765. We lose some precision here. Looks like simply using an u64 should solve this problem.
Will prepare a patch later.
Comment 6 Aaron Lu 2014-03-21 01:57:15 UTC
Created attachment 130151 [details]
Restore backlight conversion precision

Please test this patch, thanks.
Comment 7 Aaron Lu 2014-03-31 05:55:05 UTC
ping
Comment 8 Nico Schottelius 2014-04-04 09:59:50 UTC
... compiling (seriously)

bugzilla-daemon@bugzilla.kernel.org [Mon, Mar 31, 2014 at 05:55:05AM +0000]:
> https://bugzilla.kernel.org/show_bug.cgi?id=72491
> 
> --- Comment #7 from Aaron Lu <aaron.lu@intel.com> ---
> ping
> 
> -- 
> You are receiving this mail because:
> You reported the bug.
Comment 9 Nico Schottelius 2014-04-07 17:50:44 UTC
Works fine!
Comment 10 Aaron Lu 2014-04-28 03:22:11 UTC
Patch sent out to mailing list for review:
http://lists.freedesktop.org/archives/intel-gfx/2014-April/044350.html
Comment 11 Mike Cloaked 2014-05-05 20:35:09 UTC
I am not sure if the bug I filed at https://bugs.freedesktop.org/show_bug.cgi?id=78200 is a dup of this bug or not? Also I filed that against systemd which may well be the wrong component and perhaps it should have been for acpi?
Comment 12 Jani Nikula 2014-05-15 11:08:07 UTC
Fix pushed to drm-intel-fixes (and drm-intel-nightly) as

commit 721e82c08c1afd6b47367b0e0c4a62140b0667f3
Author: Aaron Lu <aaron.lu@intel.com>
Date:   Mon May 12 16:55:45 2014 +0800

    drm/i915: restore backlight precision when converting from ACPI

Thanks for the report and the fix.

It appears we fixed Mike's issue in comment #11 too, so all is well. (Fingers crossed.)
Comment 13 Alan 2014-12-10 19:28:24 UTC
*** Bug 84911 has been marked as a duplicate of this bug. ***