Legion 5 pro brightness control doesn't work on ubuntu 20.04 with nvidia driver 460

My laptop seems to be on max brightness and the brightness control slider/Fn keys have no effect on the screen brightness except showing a pop-up notification of the slider. This problem isn't really new to the legion series (or some other laptops) but unlike other (old) legion 5 laptops, none of the potential solutions worked for me for Ubuntu 20.04.2. There are solutions for the exact same laptop on a different variant of Ubuntu and Manjaro but that still doesn't work on normal Ubuntu 20.04 which is why it is a bit confusing.

So my laptop's configuration is AMD 5800H + Nvidia RTX3070. I am currently on mainline kernel 5.10.0-051000-generic with ubuntu 20.04.2. I have added the Nvidia graphics PPA and currently on driver v460.67. I am on dGPU mode (graphics card directly connected to screen). This the conf location:

 /usr/share/X11/xorg.conf.d$ ll
total 36
drwxr-xr-x 2 root root 4096 Apr  6 21:34 ./
drwxr-xr-x 5 root root 4096 Feb  9 19:50 ../
-rw-r--r-- 1 root root   92 Okt 22  2019 10-amdgpu.conf
-rw-r--r-- 1 root root  239 Apr  6 20:34 10-nvidia-brightness.conf
-rw-r--r-- 1 root root  206 Apr  6 21:34 10-nvidia.conf
-rw-r--r-- 1 root root 1350 Jan 17 10:13 10-quirks.conf
-rw-r--r-- 1 root root   92 Okt 22  2019 10-radeon.conf
-rw-r--r-- 1 root root 1429 Aug 13  2019 40-libinput.conf
-rw-r--r-- 1 root root 3458 Mär 11  2020 70-wacom.conf

Here are the output of relevant files:

/usr/share/X11/xorg.conf.d$ cat 10-nvidia-brightness.conf 
Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce RTX 3070 Laptop GPU"
    Option         "RegistryDwords" "EnableBrightnessControl=1"
EndSection

/usr/share/X11/xorg.conf.d$ cat 10-nvidia.conf 
Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

Note: Even for 10-nvidia.conf, I have tried the Option "RegistryDwords" "EnableBrightnessControl=1" but still no results.

I have blacklisted nouveau drivers:

cat /etc/modprobe.d/blacklist-nvidia-nouveau.conf 
blacklist nouveau
options nouveau modeset=0

And also added the below so that Nvidia drivers load first:

cat /etc/initramfs-tools/modules
# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax:  module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod

# Other settings...
nvidia
nvidia-drm
nvidia-modeset

I have tried to add parameters to the grub such as acpi_backlight=vendor, acpi_backlight=video, acpi_backlight=none, acpi_backlight=native, video.use_native_backlight=1 but none of them work.

So here are few relevant outputs if someone requires it:

sudo lshw -C display
  *-display                 
       description: VGA compatible controller
       product: NVIDIA Corporation
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:01:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
       configuration: driver=nvidia latency=0
       resources: iomemory:fa0-f9f iomemory:fc0-fbf irq:76 memory:d0000000-d0ffffff memory:fa00000000-fbffffffff memory:fc00000000-fc01ffffff ioport:2000(size=128) memory:d1080000-d10fffff

lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation Device 24dd (rev a1)

There is also a bug https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-455/+bug/1905591 in the driver which caused people with different laptops to have similar problems but for some, their problem was solved by adding modules to /etc/initramfs-tools/modules but for some it is still not solved. Now here is another thing, I have seen two reports with the same laptop as me mention that it is working for them by following a few combinations of the above-mentioned steps:

  1. This guy uses Regolith Linux 1.5.3 https://www.reddit.com/r/GamingLaptops/comments/ls9k5r/legion_5_pro_other_info_64gb_ram_upgrade_linux/

  2. This guy uses Manjaro https://www.reddit.com/r/LenovoLegion/comments/miqbv4/lenovo_legion_5_pro_actual_linux_experience_and/

I have also tried Kernel 5.11.11 but still, it doesn't work and one final thing, changing the slider or pressing the buttons changes the value of the file /sys/class/backlight/nvidia_0/brightness the other two files always show this :

cat actual_brightness
0
cat max_brightness 
100

So this is everything I have tried and tested. If anyone has any new ideas or pointers regarding this issue, I would be really grateful to know that.

One final thing, I am currently using xrandr --output DP-4 --brightness 0.5 to save my eyes right now. Would be helpful if someone could comment if this would be helpful to reduce (in any way) the strain on the backlight of the screen on the hardware level, since it is normally at max brightness.

Edit: Below there are two correct answers, one for hybrid mode (already marked correct) and another for discrete mode (which mentions a new kernel parameter mentioned in arch wiki).


Solution 1:

I have the same Legion and for the moment I managed to control the brightness following this guide (many thanks to u/fkorol, I am using kernel 5.11.16): https://www.reddit.com/r/linux_gaming/comments/mmptqi/lenovo_legion_5_ubuntu_2004_final_guide_dream/

I report here the main part of what is written in the link above in case it will disappear:

First step: In the BIOS (F2 at lenovo screen) must set to HYBRID mode.

1- Install the mainline software to upgrade the kernel version to the latest 5.11.x version:

sudo add-apt-repository ppa:cappelikan/ppa

sudo apt update

sudo apt install mainline

Then open mainline and install the latest availible (5.11.11 at the time of write this post).

Reboot the laptop

2- with 5.11.11 or newer, edit grub and add the entry amdgpu.backlight=0

sudo nano /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amdgpu.backlight=0"

sudo update-grub

Reboot the laptop again

That all!, with 5.11 the touchpad works natively, and with this tweak to the grub the brightness work perfectly in hybrid mode.

and I add few more notes:

  • use always "dynamic" mode in the BIOS settings

  • between point 1) and 2) you can install nvidia-drivers-460

  • if you install the nvidia drivers, after the installation you should launch:

    sudo prime-select on-demand

  • In this status your computer will use the iGPU for all the activities. If you want to use the dGPU for a task, you can define before the command these variables __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia

So for example you can launch glxheads command on dGPU with:

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxheads

Solution 2:

For discrete mode. Now, it works for me (ubuntu 20.04.3) with the kernel (v5.11.0.34.36) parameter:

nvidia.NVreg_RegistryDwords=EnableBrightnessControl=1

And nvidia drivers 460.91.03. No need to do anything else (of course you need to do a sudo update-grub).

The parameter is mentioned in arch wiki

https://wiki.archlinux.org/title/NVIDIA#Enabling_brightness_control

Also, don't use both (one is for hybrid which is mentioned in another answer and one for discrete as menioned in this answer) the kernel parameters at the same time.

All Credits to @Chaplan from legion discord for finding this.