TillmannBerg / Ubuntu-Dell-XPS-15-2019

How to install Ubuntu on a Dell XPS 15 2019
111 stars 28 forks source link

Screen Brightness (OLED) not working #9

Open agreco opened 4 years ago

agreco commented 4 years ago

Hey,

First of all, thank you for this guide, really useful. Much appreciated.

So, I've tried using the advice outlined in the guide, by adding the dell-brightness-up, dell-brightness-down and dell-brightness.sh files to the appropriate locations under /etc/acpi. However upon reloading acpid or rebooting, the brightness buttons do not change the brightness, and the brightness shown on screen is set to what seems to be 10% of brightness with brightness buttons toggling between 0% and 10%.

I'm currently using Kubuntu 19.10. My full spec is:

Machine: Dell XPS 7590
CPU: 9th Generation Intel® Core™ i9-9980HK, 16 MB Cache, 8 Core, up to 5 GHz 
Screen: 15.6-inch 4K UHD (3840 x 2160) OLED Anti-Reflective InfinityEdge Non-Touch Display
Graphics: NVIDIA® GeForce® GTX 1650 4GB GDDR5
RAM: 32G
Operating System: Kubuntu 19.10
KDE Plasma Version: 5.17.4
KDE Frameworks Version: 5.64.0
Qt Version: 5.12.4
Kernel Version: 5.3.0-24-generic
OS Type: 64-bit

Additionally I haven't installed the Nvidia drivers as recommended in the guide, as I'm not confident that I have enough knowledge to fix things, in case things goes awry. But I did go ahead and install powertop and thermald along with the service to help with CPU usage.

Hope this is enough information.

KenEucker commented 4 years ago

I also have a a new XPS 15 7590 and am not seeing the brightness change with the buttons. Mine boots to 100% brightness, and I can change the brightness with the command: xrandr --output eDP-1-1 --brightness 0.6

I'm running Ubuntu Budgie 19.10.

Wouter0100 commented 4 years ago

Experiencing the same on Ubuntu 19.10.

I'm able to use the script (sudo /etc/acpi/dell-brightness.sh down/up) just fine, but the brightness buttons ain't working.

What I see in my journal is the following when pressing brightness buttons, but I'm not sure of this is related somehow:

Dec 13 01:16:40 wouter0100-xps kernel: [  694.860018] ACPI BIOS Error (bug): Could not resolve symbol [\_SB.PCI0.PEG0.PEGP.BRT6.LCD], AE_NOT_FOUND (20190703/psargs-330)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.860048] No Local Variables are initialized for Method [BRT6]
Dec 13 01:16:40 wouter0100-xps kernel: [  694.860052] Initialized Arguments for Method [BRT6]:  (2 arguments defined for method invocation)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.860054]   Arg0:   00000000bcd24b74 <Obj>           Integer 0000000000000001
Dec 13 01:16:40 wouter0100-xps kernel: [  694.860064]   Arg1:   00000000f38c1dc1 <Obj>           Integer 0000000000000000
Dec 13 01:16:40 wouter0100-xps kernel: [  694.860080] ACPI Error: Aborting method \_SB.PCI0.PEG0.PEGP.BRT6 due to previous error (AE_NOT_FOUND) (20190703/psparse-529)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.860568] ACPI Error: Aborting method \EV5 due to previous error (AE_NOT_FOUND) (20190703/psparse-529)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.861013] ACPI Error: Aborting method \SMEE due to previous error (AE_NOT_FOUND) (20190703/psparse-529)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.861456] ACPI Error: Aborting method \SMIE due to previous error (AE_NOT_FOUND) (20190703/psparse-529)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.861710] ACPI Error: Aborting method \NEVT due to previous error (AE_NOT_FOUND) (20190703/psparse-529)
Dec 13 01:16:40 wouter0100-xps kernel: [  694.861978] ACPI Error: Aborting method \_SB.PCI0.LPCB.ECDV._Q66 due to previous error (AE_NOT_FOUND) (20190703/psparse-529)
Wouter0100 commented 4 years ago

I've done some debugging. It seems xrandr isn't returning any results. xrandr --verbose is empty when the script is executed by the acpi event action, although when executing through sudo and/or my own user it works perfectly fine.

KenEucker commented 4 years ago

Here's what I get when I run the down and up scripts:

ken@ken-XPS-15-7590:~$ sudo /etc/acpi/dell-brightness.sh down
No protocol specified
Can't open display :0.0
ken@ken-XPS-15-7590:~$ sudo /etc/acpi/dell-brightness.sh up
No protocol specified
Can't open display :0.0
No protocol specified
Can't open display :0.0
Wouter0100 commented 4 years ago

@KenEucker commenting out the display variable should 'fix' that

KenEucker commented 4 years ago

@Wouter0100 commenting out line 3 (DISPLAY:=0) did not resolve the issue:

ken@ken-XPS-15-7590:~$ sudo /etc/acpi/dell-brightness.sh up
No protocol specified
Can't open display :0
No protocol specified
Can't open display :0
ken@ken-XPS-15-7590:~$ sudo /etc/acpi/dell-brightness.sh down
No protocol specified
Can't open display :0
Wouter0100 commented 4 years ago

I found a workaround to this issue, and personally - I find this a little bit neater. This because even if the brightness is adjusted from different places than the FN keys, the brightness will be adjusted.

~/.config/systemd/user/sync-brightness.service

[Unit]
Description=Sync brightness
StartLimitIntervalSec=0

[Service] 
Type=oneshot
ExecStart=/usr/local/bin/sync-brightness

~/.config/systemd/user/sync-brightness.path

[Path]
PathModified=/sys/class/backlight/intel_backlight/actual_brightness

[Install]
WantedBy=multi-user.target

And then the sync-brightness script at /usr/local/bin/sync-brightness (make it executable):

#!/bin/bash

path=/sys/class/backlight/intel_backlight

luminance() {
    read -r level < "$path"/actual_brightness
    new_brightness="$(bc -l <<< "scale = 2; $level / $max")"
    LC_NUMERIC="en_US.UTF-8" printf '%f\n' $new_brightness
}

read -r max < "$path"/max_brightness

gamma() {
    # read and invert gamma values, see https://gitlab.freedesktop.org/xorg/app/xrandr/issues/33
    gammas_inverted=$(xrandr --verbose | awk '/Gamma/ {print $2; exit}')
    IFS=':' read -r r g b <<< "$gammas_inverted"
    r=$(bc -l <<< "1/$r")
    g=$(bc -l <<< "1/$g")
    b=$(bc -l <<< "1/$b")
    LC_NUMERIC="en_US.UTF-8" printf '%f:%f:%f\n' $r $g $b
}

xrandr --output eDP-1 --brightness "$(luminance)" --gamma "$(gamma)"

The script is thanks to this gist, which I copied some of but without the ionotify part. As you can see, I used a systemd service with path file to accomplish this.

KenEucker commented 4 years ago

@Wouter0100 I created the files you showed:

~/.config/systemd/user/sync-brightness.service ~/.config/systemd/user/sync-brightness.path /usr/local/bin/sync-brightness

But I'm not seeing any success with the brightness keys. Did you modify the etc/acpi/events/dell-brightness-down and etc/acpi/events/dell-brightness-up files?

Is there anything from the original readme steps I need to revert?

Wouter0100 commented 4 years ago

I did revert everything from the README regarding the brightness. That isn't needed and may even conflict, not sure.

You should enable and start the path file and enable linger to start at boot.

systemctl --user enable sync-brightness.path systemctl --user start sync-brightness.path

Unfortunately the brightness isn't set on boot yet, and Night Light seem to reset the brightness, so you should disable that. Working on this to hopefully atleast have the brightness set on boot.

Edit: See here hoe to enable linger by the way: https://serverfault.com/questions/846441/loginctl-enable-linger-disable-linger-but-reading-linger-status

Wouter0100 commented 4 years ago

Oh, and, multi-user.target should be default.target for now. Otherwise it won't start at boot.

KenEucker commented 4 years ago

@Wouter0100 Your solution works for me, thanks! I can't the following command to work, though, so it does not get enabled on boot and I have to run the start command manually.

systemctl --user enable sync-brightness.path

Failed to enable unit: Invalid argument

I've tried to track down a solution for this but haven't been able to get anything to stick.

I appreciate you following up on this solution and I hope that this discussion adds to the work that @TillmannBerg has provided here. If I do get something working for my XPS 15 7590 I'll consider forking this repository and adding the solutions that worked for my machine since they appear to be different solutions that what other's find success in.

Wouter0100 commented 4 years ago

@KenEucker I'll be creating a gist later on with some small steps on how to provision my workaround.

Regardless, it seems your unit file is faulty somehow. Could you check with systemd-analyze verify [file]?

KenEucker commented 4 years ago

@Wouter0100 I can't get that command to recognize the unit. I've tried the command, with and without sudo. But I get the following:

ken@ken-XPS-15-7590:~/Dev/vvv$ sudo systemd-analyze verify ~/.config/systemd/user/sync-brightness.path
/lib/systemd/system/dbus.socket:4: ListenStream= references a path below legacy directory /var/run/, updating /var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
File /lib/systemd/system/systemd-udevd.service:26 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
/lib/systemd/system/smbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/smbd.pid → /run/samba/smbd.pid; please update the unit file accordingly.
/lib/systemd/system/nmbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/nmbd.pid → /run/samba/nmbd.pid; please update the unit file accordingly.
/lib/systemd/system/rpc-statd.service:13: PIDFile= references a path below legacy directory /var/run/, updating /var/run/rpc.statd.pid → /run/rpc.statd.pid; please update the unit file accordingly.
snap-slack-20.mount: Unit is bound to inactive unit dev-loop7.device. Stopping, too.
snap-core-8213.mount: Unit is bound to inactive unit dev-loop6.device. Stopping, too.
snap-spotify-36.mount: Unit is bound to inactive unit dev-loop1.device. Stopping, too.
snap-ubuntu\x2dbudgie\x2dwelcome-145.mount: Unit is bound to inactive unit dev-loop0.device. Stopping, too.
snap-ubuntu\x2dbudgie\x2dwelcome-150.mount: Unit is bound to inactive unit dev-loop3.device. Stopping, too.

ken@ken-XPS-15-7590:~/Dev/vvv$ sudo systemd-analyze verify ~/.config/systemd/user/sync-brightness.service
/lib/systemd/system/dbus.socket:4: ListenStream= references a path below legacy directory /var/run/, updating /var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
File /lib/systemd/system/systemd-udevd.service:26 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
/lib/systemd/system/smbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/smbd.pid → /run/samba/smbd.pid; please update the unit file accordingly.
/lib/systemd/system/nmbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/nmbd.pid → /run/samba/nmbd.pid; please update the unit file accordingly.
/lib/systemd/system/rpc-statd.service:13: PIDFile= references a path below legacy directory /var/run/, updating /var/run/rpc.statd.pid → /run/rpc.statd.pid; please update the unit file accordingly.
snap-slack-20.mount: Unit is bound to inactive unit dev-loop7.device. Stopping, too.
snap-code-22.mount: Unit is bound to inactive unit dev-loop2.device. Stopping, too.
snap-ubuntu\x2dbudgie\x2dwelcome-150.mount: Unit is bound to inactive unit dev-loop3.device. Stopping, too.
snap-code-21.mount: Unit is bound to inactive unit dev-loop4.device. Stopping, too.

ken@ken-XPS-15-7590:~/Dev/vvv$ systemd-analyze verify ~/.config/systemd/user/sync-brightness.service
/lib/systemd/system/dbus.socket:4: ListenStream= references a path below legacy directory /var/run/, updating /var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
File /lib/systemd/system/systemd-udevd.service:26 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
/lib/systemd/system/smbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/smbd.pid → /run/samba/smbd.pid; please update the unit file accordingly.
/lib/systemd/system/nmbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/nmbd.pid → /run/samba/nmbd.pid; please update the unit file accordingly.
/lib/systemd/system/rpc-statd.service:13: PIDFile= references a path below legacy directory /var/run/, updating /var/run/rpc.statd.pid → /run/rpc.statd.pid; please update the unit file accordingly.
Failed to acquire watch file descriptor: No space left on device

ken@ken-XPS-15-7590:~/Dev/vvv$ systemd-analyze verify ~/.config/systemd/user/sync-brightness.path
/lib/systemd/system/dbus.socket:4: ListenStream= references a path below legacy directory /var/run/, updating /var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
File /lib/systemd/system/systemd-udevd.service:26 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
/lib/systemd/system/smbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/smbd.pid → /run/samba/smbd.pid; please update the unit file accordingly.
/lib/systemd/system/nmbd.service:9: PIDFile= references a path below legacy directory /var/run/, updating /var/run/samba/nmbd.pid → /run/samba/nmbd.pid; please update the unit file accordingly.
/lib/systemd/system/rpc-statd.service:13: PIDFile= references a path below legacy directory /var/run/, updating /var/run/rpc.statd.pid → /run/rpc.statd.pid; please update the unit file accordingly.
Failed to acquire watch file descriptor: No space left on device 
Had-rien commented 4 years ago

Hello, First thanks for the guide and working on those issue, it has helped me a lot.

I have tried the TIlmannBerg solution and yours and it seems that it depends on the graphic card to pick the best one.

I tried setting the nvidia on "mixed" mode to get best of both I have found that it's more of the worst without more setup probably. However with this mode your brightness service was working as expected.

I then switched to only intel graphics and now it stopped working.

I have found that /sys/class/backlight/intel_backlight/actual_brightness always returns the same value now (46649). I also have /sys/class/backlight/dell_backlight/actual_brightness that responds well to function keys and xfce brightness slider (values from 0 to 15) but does not actually modify screen backlight.

I can still use xrandr to manually modify backlight setting.

I will try to modify the script to use dell_backlight informations.

Edit : Issue was on my side, I added acpi_backlight=vendor acpi_osi=! acpi_osi=\"Windows 2015\" to my grub config wich was a mistake. I still have an issue with the function keys but backlight settings works.

Wouter0100 commented 4 years ago

I switched to icc-brightness. This works flawlessly, unfortunately still no PWM based dimming and thus a limited colour range, resulting in odd black fades, but still - better then my solution which didn't work at boot and sometimes seem to reset to the default brightness somehow.

eleijonmarck commented 4 years ago
❯ sudo /etc/acpi/dell-brightness.sh down
Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0.0
Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0.0

I somehow get MIT-MAGIC-COOKIE :dagger:

eleijonmarck commented 4 years ago

@Wouter0100 hmm.. weirdly enough is it that nothing have worked for me.

tillmanberg - dell-brightness / wouter - systemd / icc-brightness

Fresh install of ubuntu 19.10 :-1:

Is there something I am missing?

However, I am able to set the brightness myself with:

$ xrandr --output eDP-1-1 --brightness 0.7
Wouter0100 commented 4 years ago

@eleijonmarck switch to icc-brightness. Works flawlessly for me the last months.

eleijonmarck commented 4 years ago

@eleijonmarck switch to icc-brightness. Works flawlessly for me the last months.

hmm yea. I just tried it:

$ cd
$ git clone https://github.com/udifuchs/icc-brightness
$ cd icc-brightness
$ make
$ sudo make install

But did not work for me on restart.

eleijonmarck commented 4 years ago
❯ icc-brightness apply
profile object path '/org/freedesktop/ColorManager/profiles/icc_3838ba26ddf77b01f82d1559480936e8_eleijonmarck_1000' does not exist for this device
Traceback (most recent call last):
  File "/usr/local/bin/icc-brightness", line 157, in <module>
    main()
  File "/usr/local/bin/icc-brightness", line 132, in main
    icc_brightness_apply()
  File "/usr/local/bin/icc-brightness", line 108, in icc_brightness_apply
    icc_brightness(brightness, max_brightness)
  File "/usr/local/bin/icc-brightness", line 94, in icc_brightness
    get_device_id(), object_path], check=True)
  File "/usr/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['colormgr', 'device-make-profile-default', '/org/freedesktop/ColorManager/devices/xrandr_eDP_1_1_eleijonmarck_1000', '/org/freedesktop/ColorManager/profiles/icc_3838ba26ddf77b01f82d1559480936e8_eleijonmarck_1000']' returned non-zero exit status 1.
eleijonmarck commented 4 years ago

@Wouter0100 maybe something do with: https://github.com/udifuchs/icc-brightness/issues/19

eleijonmarck commented 4 years ago

@Wouter0100 also this issue:

https://github.com/udifuchs/icc-brightness/issues/16

eleijonmarck commented 4 years ago

For anyone else.

I ended up switching to the additional drivers Xorg to be able to make suspend and brightness work.

TillmannBerg commented 4 years ago

Which drivers exactly? Do you have a link?

eleijonmarck commented 4 years ago

@TillmannBerg from the software and updates application.

I go into additional drivers and do not select the Nvidia one. But change to X.Org.

image

$ dpkg -l |grep xserver-xorg-core 
ii  xserver-xorg-core                          2:1.20.5+git20191008-0ubuntu1          amd64        Xorg X server - core server

version: 2:1.20.5+git20191008-0ubuntu1

eleijonmarck commented 4 years ago

@TillmannBerg my power consumption went from 100%/hour to 1%/hour when suspended.

Now my xps is finally on par with how my thinkpad was WITHOUT any tweaks. :dancer:

.

I would actually say that following tillmann first and then this repo made all the difference.

https://github.com/MuDiAhmed/Ubuntu-Dell-XPS-15-2019

agreco commented 4 years ago

Hey, apologies for not getting back with my 2 cents sooner! I've tried all of the above recommendations to no avail.

I tried icc-brightness and unfortunately it requires a re-installation every time KDE updates. I switched Nvidia drivers to X.Org and the brightness keys don't work at all.

I'm still able to change brightness via the cmd line, eg: xrandr --output eDP-1 --brightness 0.7. So at least this works.

EgbertW commented 4 years ago

Never mind, it's not the solution I thought this fixed it while running acpid in foreground mode. It fixes it for that situation but when running through Systemd it doesn't work anymore. I'll keep looking.


Original message For what it's worth, I managed to fix the /etc/acpi/dell_brightness.sh script by granting access to the X Session:

$ xhost +local:

Afterwards, the acpi events and the brightness is adjusted. I simply added this command to /etc/X11/Xsession to make it persistent.

I'm not entirely sure about the security implications of this, though.

noopurphalak commented 4 years ago

@eleijonmarck I was following instructions in https://github.com/MuDiAhmed/Ubuntu-Dell-XPS-15-2019. The brightness works after running sudo make oled_xrandr_install. But, when I reboot, the brightness again doesn't work until I run the sudo command again. Can you tell me how you fixed this?

eleijonmarck commented 4 years ago

@noopurphalak hm I am sorry.. but this was way too long ago. I'l see if I have some notes

noopurphalak commented 3 years ago

@eleijonmarck It would be wonderful if you can, all the rest of the commands worked just fine, only command I am having an issue with is that for the brightness control.

noopurphalak commented 3 years ago

@eleijonmarck I was following instructions in https://github.com/MuDiAhmed/Ubuntu-Dell-XPS-15-2019. The brightness works after running sudo make oled_xrandr_install. But, when I reboot, the brightness again doesn't work until I run the sudo command again. Can you tell me how you fixed this?

Can some one please help me with the quoted issue?

eleijonmarck commented 3 years ago

@noopurphalak the only notes I could find was: using this script i had: https://github.com/eleijonmarck/dotfiles/blob/master/.ubuntu.sh

also disabling bluetooth entierly. Meaning I cannot even enable the bluetooth from the computer. I spent way too much time with this unfortunately so I do not have much notes, just tried out a bunch of stuff and now it works. And I am too afraid to change anything :crab:

rmaree commented 3 years ago

@noopurphalak I had the same issue on Ubuntu 19.10 and from time to time there were also conflicts with the "daylight/night" configuration. On Ubuntu 20.04 I'm now using the OLED dimmer extension, it works well ! It is explained on this webpage: https://kaigo.medium.com/ubuntu-20-04-on-dell-xps-15-9570-14efd881f0d2 You might find other useful information there.

noopurphalak commented 3 years ago

@rmaree Thanks a lot...the extension works like a charm.