Bug 257796

Summary: backlight(8) gets confused on power change
Product: Base System Reporter: Mason Loring Bliss <mason>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: bz, emaste, lwhsu, manu
Priority: ---    
Version: 13.0-RELEASE   
Hardware: Any   
OS: Any   

Description Mason Loring Bliss freebsd_triage 2021-08-12 21:21:46 UTC
I've been using backlight(8) to set my backlight brightness, and it
generally works very well, but I just noticed that if I plug in or unplug
my laptop power adapter it will go to 100% brightness. The command output
will show 100% brightless, but it appears to remember the previous value,
as if I go back to, say, 50% with "backlight 50" it presumably already
thinks it's there and will do nothing. If I choose another value, whether
higher or lower, it will correctly set that new value, after which
backlight(8) will report that value.

So:

# backlight 50
-> unplug and see backlight brighten
# backlight
brightness: 100
# backlight 50
-> nothing happens
# backlight
brightness 100
# backlight 40
-> backlight goes to 40%
# backlight 
brightness: 40
# backlight 50
-> backlight goes to 50% this time
# backlight
brightness: 50
Comment 1 Mason Loring Bliss freebsd_triage 2021-08-12 21:23:22 UTC
Sorry, forgot to add some relevant detail. FreeBSD 13, Thinkpad T420, 
drm-kmod-g20190710_1 and drm-fbsd13-kmod-5.4.92.g20210419 installed, 
i915kms loaded.
Comment 2 Emmanuel Vadot freebsd_committer freebsd_triage 2021-08-26 09:05:11 UTC
Ok I can reproduce on my laptop too, I'll see how I can fix that.
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-05-25 14:51:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e26ef41f79902991c772b59927c721aa7fa5fc64

commit e26ef41f79902991c772b59927c721aa7fa5fc64
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-05-25 14:48:10 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-05-25 14:50:25 +0000

    backlight: Update cached value when getting the brightness

    External events can cause the backlight level to change (AC adapter
    plug/unplug for example) so cache the value there too.

    PR:             257796
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    MFC after:      1 week

 sys/dev/backlight/backlight.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 4 Emmanuel Vadot freebsd_committer freebsd_triage 2022-05-25 14:51:38 UTC
Sorry for the delay I had totally forgotten about this :(
Everything should be fixed now.
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-06-01 07:13:15 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b203d3de6b1a7ab38f0a1e3d944a1c4887e31a9b

commit b203d3de6b1a7ab38f0a1e3d944a1c4887e31a9b
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-05-25 14:48:10 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-06-01 07:12:18 +0000

    backlight: Update cached value when getting the brightness

    External events can cause the backlight level to change (AC adapter
    plug/unplug for example) so cache the value there too.

    PR:             257796
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    MFC after:      1 week

    (cherry picked from commit e26ef41f79902991c772b59927c721aa7fa5fc64)

 sys/dev/backlight/backlight.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)