Bug 203905 - amdgpu:actual_brightness has unreal/wrong value
Summary: amdgpu:actual_brightness has unreal/wrong value
Status: NEW
Alias: None
Product: Drivers
Classification: Unclassified
Component: Video(DRI - non Intel) (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: drivers_video-dri
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-15 20:02 UTC by Bjoern Franke
Modified: 2021-02-17 17:25 UTC (History)
21 users (show)

See Also:
Kernel Version: 5.1.9
Tree: Mainline
Regression: No


Attachments
dmesg (81.79 KB, text/plain)
2019-06-17 10:48 UTC, Bjoern Franke
Details
Dmesg 8-9-2020 (84.74 KB, text/plain)
2020-09-08 01:00 UTC, John Shand
Details
Journalctl 8-9-2020 (340.21 KB, text/plain)
2020-09-08 01:03 UTC, John Shand
Details

Description Bjoern Franke 2019-06-15 20:02:00 UTC
Radeon R5/R6/R7 Graphics in a Thinkpad A275 has wrong values on actual_brightness of amdgpu_bl0. While max_brightness is 255 and it can be set to 255, actual_brightness reports a 5 digit number like 12470. As a result, tools which want to change the brightness related to actual_brightness fail, as brightness does not accept any 5 digit number,
Comment 1 Michel Dänzer 2019-06-17 09:44:51 UTC
Please attach the output of dmesg.
Comment 2 Bjoern Franke 2019-06-17 10:48:16 UTC
Created attachment 283299 [details]
dmesg
Comment 3 Lukáš Krejčí 2019-09-26 21:07:32 UTC
Commit 262485a50fd4 ("drm/amd/display: Expand dc to use 16.16 bit backlight") changed the value that is returned for `actual_brightness`:

-static unsigned int dce_abm_get_current_backlight_8_bit(struct abm *abm)
+static unsigned int dce_abm_get_current_backlight(struct abm *abm)
 {
    struct dce_abm *abm_dce = TO_DCE_ABM(abm);
    unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL);
 
-   return (backlight >> 8);
+   /* return backlight in hardware format which is unsigned 17 bits, with
+    * 1 bit integer and 16 bit fractional
+    */
+   return backlight;
 }


I could not find anything official about the range of `actual_brightness`, only the following blog says that is has to be in range of `brightness`: https://nikula.org/~jani/backlight/#index3h3

I guess amdgpu_dm_backlight_get_brightness() could be changed to bring the `actual_brightness` value in range of `brightness` again since it returns the value of `brightness` in the error path anyway.
Comment 4 Sandor Ecker 2020-02-05 05:34:44 UTC
Hi,

I have the same Issue.

I have written a bug report to this:

https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-amdgpu/+bug/1861925

Maybe that is not the correct place...

Is any news regarding the problem?

Thx,
Regards,
Sandor
Comment 5 Sandor Ecker 2020-02-05 05:52:30 UTC
Would it be possible to set max_brightness to 2^16-1 ?
Comment 6 Sandor Ecker 2020-02-09 13:33:15 UTC
So it seems that the 16 bit actual_brightness is not a bug, but a feature... :)

https://github.com/torvalds/linux/commit/262485a50fd4532a8d71165190adc7a0a19bcc9e#diff-b496037255b7766a782d3f3711b50db8

So my question now:
-why are the max_brightness and brightness values in 8bit range?
Comment 7 Sandor Ecker 2020-02-10 19:16:23 UTC
I have upgraded to 5.6.rc1:

uname -a
Linux Aspire-A315-41 5.6.0-050600rc1-generic #202002092032 SMP Mon Feb 10 01:36:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


I have seen that the code has log messages like:

DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
			backlight_pwm_u16_16, backlight_pwm_u16_16);

I have set the kernel log by

echo "8" > /proc/sys/kernel/printk
cat /proc/sys/kernel/printk
8	4	1	7

but I can't see any logmessage with "New Backlight" in the output of the commands:

grep -i "new backli" /var/log/*
dmesg |grep -i "back"

Maybe it does not reach that line of code? Or the log should be visible somewhere else... ? 

Can somebody help...?
Comment 8 Flo Bock 2020-07-30 06:15:51 UTC
With recent systemd changes, the 16 bit values in actual_brightness break saving and restoring the backlight values using AMDGPU. According to a closed issue on Github, Lennart Poettering sees this as a kernel issue[1]. Is there any good reason for actual_brightness to be 16bit, whereas both max_brightness and brightness are 8bit?

[1]: https://github.com/systemd/systemd/issues/16600
Comment 9 Kunal Bhat 2020-08-01 12:04:53 UTC
(In reply to Flo Bock from comment #8)
> With recent systemd changes, the 16 bit values in actual_brightness break
> saving and restoring the backlight values using AMDGPU. According to a
> closed issue on Github, Lennart Poettering sees this as a kernel issue[1].
> Is there any good reason for actual_brightness to be 16bit, whereas both
> max_brightness and brightness are 8bit?
> 
> [1]: https://github.com/systemd/systemd/issues/16600



I believe it's there to provide a higher range of precision for the backlight. Not sure why they never extended the range for max_brightness. 
 
The systemd devs are adamant that this is a driver issue, and aren't ready to implement a work around for it. 
I believe this is the open issue with the discussions right now:
https://github.com/systemd/systemd/issues/16630
Comment 10 Alexander Monakov 2020-08-03 20:13:43 UTC
Proposed patch: https://lore.kernel.org/lkml/20200803200218.2167-1-amonakov@ispras.ru/
Comment 11 Alexander Monakov 2020-08-04 20:15:24 UTC
v2 patch: https://lore.kernel.org/lkml/20200804201313.6464-1-amonakov@ispras.ru/
Comment 12 rugk 2020-08-17 09:46:21 UTC
(Backlink only) Same issue reported on https://discussion.fedoraproject.org/t/amd-amdgpu-bl0-backlight-not-restored/20445?u=rugk
Comment 13 shanmukhateja@gmail.com 2020-08-31 10:46:46 UTC
I have built a workaround for this issue by forking systemd-backlight for the time-being. It has been tested on my ASUS TUF FX505DT with Ryzen 3550H.

https://github.com/shanmukhateja/systemd/tree/fix-amdgpu-backlight
Comment 14 Xia Mu 2020-09-01 19:07:34 UTC
The bug should be fixed in 5.9.0-0.rc3. I tested it on my laptop with AMD Ryzen 7 PRO 4750U CPU with Renoir GPU.
Comment 15 John Shand 2020-09-08 00:59:17 UTC
i have had this problem as well.  was recently working well with kernel 5.8.7.  i then install ucode-amd and then grub-mkconfig -o /boot/grub/grub.cfg to set the changes.  grub automatically made the new code image work with initramfs and then, backlight went back to about 20% or 255.

would this have anything to do with amd's ucode image??
Comment 16 John Shand 2020-09-08 01:00:26 UTC
Created attachment 292417 [details]
Dmesg 8-9-2020
Comment 17 John Shand 2020-09-08 01:03:00 UTC
Created attachment 292419 [details]
Journalctl 8-9-2020
Comment 18 Germán Ríos González 2020-11-23 21:02:48 UTC
(In reply to Xia Mu from comment #14)
> The bug should be fixed in 5.9.0-0.rc3. I tested it on my laptop with AMD
> Ryzen 7 PRO 4750U CPU with Renoir GPU.

I'm actually using 5.9.9-200.fc33.x86_64 and the problem it's still there
Comment 19 kurmikon 2020-12-07 10:17:33 UTC
I confirm that the bug is not fixed in 5.9.12.

https://github.com/systemd/systemd/issues/17826

As Poettering pointed out, actual_brightness is read-only and reports the brightness currently in effect, while brightness is writable and reports the value set by userspace.

Not only the actual brightness is in a different range that breaks systemd backlight restoring service at startup, but on my device its value is also fixed on the same value while it should reflect the correct level on brightness changes.

Brightness at the maximum:
/sys/class/backlight/amdgpu_bl0/actual_brightness > 249
/sys/class/backlight/amdgpu_bl0/brightness > 255
/sys/class/backlight/amdgpu_bl0/max_brightness > 255

Brightness at the minimum:
/sys/class/backlight/amdgpu_bl0/actual_brightness > 249
/sys/class/backlight/amdgpu_bl0/brightness > 2
/sys/class/backlight/amdgpu_bl0/max_brightness > 255
Comment 20 Antony J.R 2021-02-02 14:06:50 UTC
I can confirm that the bug is still not fixed even in 5.11-rc6 (the latest kernel at the time of writing).

I can't control brightness also.

I have a AMD Ryzen 7 4800H APU which has Renoir Graphics.

The brightness control only works with Fedora Workstation 32 with Linux Kernel 5.6.6 but with 5.11-rc6 brightness control does not work at all.
Comment 21 Paulo Nascimento 2021-02-07 22:17:49 UTC
I confirm that the bug is not fixed in kenel 5.11-rc3

max brightness:
[pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/actual_brightness
311
[pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/brightness
255
[pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/max_brightness
255

min brightness:
[pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/actual_brightness
311
[pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/brightness
0
[pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/max_brightness
255

My laptop has an amd ryzen 5 4600h with renoir igpu and nvidia dgpu. 
Tests are done with renoir igpu:

[pn@pn-legion backlight]$ inxi -G
Graphics:  Device-1: NVIDIA TU116M [GeForce GTX 1660 Ti Mobile] driver: nouveau v: kernel 
           Device-2: Advanced Micro Devices [AMD/ATI] Renoir driver: amdgpu v: kernel 
           Device-3: Chicony Integrated Camera type: USB driver: uvcvideo 
           Display: x11 server: X.Org 1.20.10 driver: loaded: amdgpu,ati,modesetting,nouveau resolution: 1920x1080~120Hz 
           OpenGL: renderer: AMD RENOIR (DRM 3.40.0 5.11.0-1-MANJARO LLVM 11.0.1) v: 4.6 Mesa 20.3.3
Comment 22 Antony J.R 2021-02-08 20:47:44 UTC
Created attachment 295123 [details]
attachment-28816-0.html

A workaround for this is done by the OpenSUSE folks, Please see
https://bugzilla.opensuse.org/show_bug.cgi?id=1180749

The only distro which fixes this is OpenSUSE. This is because there is a
bug in the mainline kernel and kernel devs are not responding to us for
some reason(maybe file a new issue???).

The problem is that the kernel uses aux for backlight control but our
systems don't support backlight control via aux. So disabling aux
completely from amdgpu kernel module can give us backlight control for the
iGPU. I've tested it and it works just find.

Regards,
Antony J.R

On Mon, Feb 8, 2021 at 3:47 AM <bugzilla-daemon@bugzilla.kernel.org> wrote:

> https://bugzilla.kernel.org/show_bug.cgi?id=203905
>
> Paulo Nascimento (paulo.ulusu@googlemail.com) changed:
>
>            What    |Removed                     |Added
>
> ----------------------------------------------------------------------------
>                  CC|                            |
> paulo.ulusu@googlemail.com
>
> --- Comment #21 from Paulo Nascimento (paulo.ulusu@googlemail.com) ---
> I confirm that the bug is not fixed in kenel 5.11-rc3
>
> max brightness:
> [pn@pn-legion backlight]$ cat
> /sys/class/backlight/amdgpu_bl1/actual_brightness
> 311
> [pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/brightness
> 255
> [pn@pn-legion backlight]$ cat
> /sys/class/backlight/amdgpu_bl1/max_brightness
> 255
>
> min brightness:
> [pn@pn-legion backlight]$ cat
> /sys/class/backlight/amdgpu_bl1/actual_brightness
> 311
> [pn@pn-legion backlight]$ cat /sys/class/backlight/amdgpu_bl1/brightness
> 0
> [pn@pn-legion backlight]$ cat
> /sys/class/backlight/amdgpu_bl1/max_brightness
> 255
>
> My laptop has an amd ryzen 5 4600h with renoir igpu and nvidia dgpu.
> Tests are done with renoir igpu:
>
> [pn@pn-legion backlight]$ inxi -G
> Graphics:  Device-1: NVIDIA TU116M [GeForce GTX 1660 Ti Mobile] driver:
> nouveau
> v: kernel
>            Device-2: Advanced Micro Devices [AMD/ATI] Renoir driver:
> amdgpu v:
> kernel
>            Device-3: Chicony Integrated Camera type: USB driver: uvcvideo
>            Display: x11 server: X.Org 1.20.10 driver: loaded:
> amdgpu,ati,modesetting,nouveau resolution: 1920x1080~120Hz
>            OpenGL: renderer: AMD RENOIR (DRM 3.40.0 5.11.0-1-MANJARO LLVM
> 11.0.1) v: 4.6 Mesa 20.3.3
>
> --
> You may reply to this email to add a comment.
>
> You are receiving this mail because:
> You are on the CC list for the bug.
Comment 23 m11.1l1.f64 2021-02-17 17:24:20 UTC
There's a workaround here



I hope it helps :)



simply write this into `/etc/systemd/system/backlight-fix.service`:

```
[Unit]
Description=Dummy service for attempting to start the problematic amdgpu_bl0 service

[Service]
Type=simple
ExecStart=systemctl start systemd-backlight@backlight:amdgpu_bl0

[Install]
WantedBy=multi-user.target
```

And then `sudo systemctl enable --now backlight-fix.service`

Bingo!!

The problem is gone

Note You need to log in before you can comment on or make changes to this bug.