[arch-general] Nvidia backlight control - acpi_video0/brightness changes - display doesn't?

Christian Klaue mail at ck76.de
Sun Nov 20 11:19:02 UTC 2016


Well, this won't work for me. I don't have a NVidia. But I will search
the web if there is a module for my Intel Skylake graphics. Although my
brightness script actually works perfect. The only drawback currently:
a few apps (e.g. chromium) reset the brightness to max upon their
startup.

Thanks anyway!

Christian

On Sun, 2016-11-20 at 03:08 -0600, David C. Rankin wrote:
> On 11/19/2016 03:38 AM, Christian Klaue wrote:
> > I am having exactly the same problem with my HP. I went as far as
> > decompiling the ACPI bios. When I tried to compile it again, it
> > threw a
> > huge amount of errors. So I gave up. I didn't find any solution for
> > my
> > problem. I even tried other distros. I am still kind of convinced
> > the
> > error is in the ACPI module(s) of your UEFI. If you try to blame HP
> > (as
> > many people on their forum did before) they will ask you to test on
> > Windows. Unfortunately there it works. The newest BIOS update
> > doesn't
> > fix the problem for my toy.
> > 
> > I am lucky to have an OLED. Please keep me updated if you find a
> > solution.
> 
> Christian,
> 
>   You may be in luck. I did find a solution and now my backlight
> functions as
> it should using the nvidiabl kernel module (and a small helper script
> that I
> autostart in KDE, but you could just as easily start it in .xinitrc
> for any
> desktop) Basically, you have to use either of the following two
> packages to
> build a kernel module that will work with the proprietary nvidia
> driver:
> 
> nvidia-bl
> https://aur.archlinux.org/packages/nvidia-bl/
> 
> nvidiabl
> https://aur.archlinux.org/packages/nvidiabl/
> 
>   I built them both, but haven't tried nvidia-bl, (even though it was
> easier
> to build and should do the same thing)
> 
>   To build nvidiabl, just follow the notes on its aur page and it
> builds fine.
> nvidia-bl, builds without issue, just download the tarball, unpack
> it, and
> then a makepkg -s is all that is needed.
> 
>   Both provide the kernel module:
> 
> /usr/lib/modules/extramodules-4.8-ARCH/nvidiabl.ko
> 
>   Just build, then 'modprobe nvidiabl', and you will have backlight
> control
> through:
> 
> /sys/class/backlight/nvidia_backlight/brightness
> 
>   The kicker is that nothing talks to nvidia_backlight by default,
> instead all
> the normal backlight controls use:
> 
> /sys/class/backlight/acpi_video0/brightness
> 
>   The way to get your controls to work is to watch the
> acpi_video0/brightness
> values and automatically set nvidia_backlight/brightness any time the
> earlier
> one changes value. This is where the helper script comes into play
> (actually 2
> short scripts -- the second just to ease the sudo redirection issue)
> 
>   The first script just maps values (0-20) from
> acpi_video0/brightness into a
> range of (0-127) for nvidia_backlight/brightness (it calls the second
> script
> as a helper). Just launch the first script in whatever desktop you
> are using,
> and your backlight keys should work. If not, then you just have to
> copy
> whatever value you want for your backlight/brightness to
> nvidia_backlight/brightness, e.g.
> 
>  # echo 90 > /sys/class/backlight/nvidia_backlight/brightness
> 
>   Put both scripts in the same directory. You will need to configure
> sudo
> without a password for this to work when called as your normal user
> (as when
> using the laptop keys). The first is a quick modification of the
> xbacklight
> script. It reads the xbacklight value from acpi_video0 and then does
> a rough
> scale for what the nvidia_backlight value should be. Give it some
> name like
> nvbackligh.sh:
> 
> #!/bin/sh
> 
> path=/sys/class/backlight/acpi_video0
> dest=/sys/class/backlight/nvidia_backlight
> dmax=$(<$dest/max_brightness)
> 
> luminance() {
>     read -r level < "$path"/actual_brightness
>     factor=$((dmax / max))
>     nvbrt=$((level * factor))
>     case "$nvbrt" in
>         [0-9]       )  printf "%d" $nvbrt;;
>         [0-9][0-9]  )  printf "%d" $nvbrt;;
>         [1][0-1][0-9] )  printf "%d" $nvbrt;;
>         [1][2][0-9] )  printf "127";;
>         default     )  printf "error: in value conversion\n"
>                        exit 1;;
>     esac
> }
> 
> read -r max < "$path"/max_brightness
> 
> inotifywait -me modify --format '' "$path"/actual_brightness | while
> read; do
>     if [ $UID -eq 0 ]; then
>         echo $(luminance) > "$dest"/brightness
>     else
>         sudo ./nvhelper.sh $(luminance)  # helper script
>     fi
>     printf "luminance %s\n" "$(luminance)"
> done
> 
>   The second just echos the luminance value into
> nvidia_backlight/brightness
>  which gets around sudo only applying to the echo and not the
> redirection. An
> alternative is calling it with 'su -c' (which you can configure pam
> to allow
> without a password if you are a member of the wheel group and you
> uncomment
> the first two lines in /etc/pam.d/su). The helper script nvhelper.sh
> is:
> 
> #!/bin/sh
> [ $1 -lt 0 -o $1 -gt 127 ] && exit 1  ## check value out of range
> echo $1 > /sys/class/backlight/nvidia_backlight/brightness
> 
>   If you try the aur nvidia-bl package and it works. Let me know, it
> is a
> simpler package to build. I'll try and get time to try it over the
> next week
> or so.
> 
>   So now, after a couple of days relearning xrandr, backlight, the
> sysfs and
> what goes with what in the nvidia driver, that xrandr is a software
> pixel
> darkening scheme, we came to understand the kernel model approach is
> the
> correct approach for backlight control here...and it is working
> perfectly.
> 
> (Now, if I could just get this damn HP laptop to boot grub without
> having to
> boot from USB and then boot grub on the hard drive, I'd be in great
> shape. Let
> me know if you have any questions.
> 


More information about the arch-general mailing list