aBUGSworstnightmare
Posts: 5649
Joined: Tue Jun 30, 2015 1:35 pm

[SOLVED] Backlight control - generic DPI overlay

Tue Sep 13, 2022 10:27 am

I see some issues with controlling a PWM backlight.

I'm on a CM4, using the generic DPI display with a backlight connected to GPIO19

Code: Select all

dtoverlay=vc4-kms-dpi-panel,at056tn53v1
dtparam=backlight-pwm=1,backlight-pwm-chan=1,backlight-pwm-gpio=19
from config.txt

Code: Select all

pi@CM4Wave:~ $ uname -a
Linux CM4Wave 5.15.67-v8+ #1584 SMP PREEMPT Mon Sep 12 13:06:37 BST 2022 aarch64 GNU/Linux
pi@CM4Wave:~ $ raspi-gpio get
BANK0 (GPIO 0 to 27):
GPIO 0: level=1 fsel=6 alt=2 func=PCLK pull=NONE
GPIO 1: level=1 fsel=6 alt=2 func=DE pull=NONE
GPIO 2: level=1 fsel=6 alt=2 func=LCD_VSYNC pull=NONE
GPIO 3: level=1 fsel=6 alt=2 func=LCD_HSYNC pull=NONE
GPIO 4: level=1 fsel=6 alt=2 func=DPI_D0 pull=NONE
GPIO 5: level=0 fsel=6 alt=2 func=DPI_D1 pull=NONE
GPIO 6: level=0 fsel=6 alt=2 func=DPI_D2 pull=NONE
GPIO 7: level=0 fsel=6 alt=2 func=DPI_D3 pull=NONE
GPIO 8: level=1 fsel=6 alt=2 func=DPI_D4 pull=NONE
GPIO 9: level=0 fsel=6 alt=2 func=DPI_D5 pull=NONE
GPIO 10: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 11: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 12: level=0 fsel=6 alt=2 func=DPI_D8 pull=NONE
GPIO 13: level=0 fsel=6 alt=2 func=DPI_D9 pull=NONE
GPIO 14: level=1 fsel=6 alt=2 func=DPI_D10 pull=NONE
GPIO 15: level=1 fsel=6 alt=2 func=DPI_D11 pull=NONE
GPIO 16: level=1 fsel=6 alt=2 func=DPI_D12 pull=NONE
GPIO 17: level=1 fsel=6 alt=2 func=DPI_D13 pull=NONE
GPIO 18: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 19: level=0 fsel=2 alt=5 func=PWM0_1 pull=DOWN
GPIO 20: level=0 fsel=6 alt=2 func=DPI_D16 pull=NONE
GPIO 21: level=0 fsel=6 alt=2 func=DPI_D17 pull=NONE
GPIO 22: level=0 fsel=6 alt=2 func=DPI_D18 pull=NONE
GPIO 23: level=0 fsel=6 alt=2 func=DPI_D19 pull=NONE
GPIO 24: level=0 fsel=6 alt=2 func=DPI_D20 pull=NONE
GPIO 25: level=0 fsel=6 alt=2 func=DPI_D21 pull=NONE
GPIO 26: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 27: level=0 fsel=0 func=INPUT pull=DOWN
BANK1 (GPIO 28 to 45):
GPIO 28: level=1 fsel=2 alt=5 func=RGMII_MDIO pull=UP
GPIO 29: level=0 fsel=2 alt=5 func=RGMII_MDC pull=DOWN
GPIO 30: level=1 fsel=7 alt=3 func=CTS0 pull=UP
GPIO 31: level=1 fsel=7 alt=3 func=RTS0 pull=NONE
GPIO 32: level=0 fsel=7 alt=3 func=TXD0 pull=NONE
GPIO 33: level=1 fsel=7 alt=3 func=RXD0 pull=UP
GPIO 34: level=0 fsel=7 alt=3 func=SD1_CLK pull=NONE
GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD pull=UP
GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0 pull=UP
GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1 pull=UP
GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2 pull=UP
GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3 pull=UP
GPIO 40: level=1 fsel=0 func=INPUT pull=NONE
GPIO 41: level=1 fsel=0 func=INPUT pull=NONE
GPIO 42: level=0 fsel=1 func=OUTPUT pull=NONE
GPIO 43: level=1 fsel=0 func=INPUT pull=NONE
GPIO 44: level=1 fsel=0 func=INPUT pull=NONE
GPIO 45: level=1 fsel=0 func=INPUT pull=NONE
BANK2 (GPIO 46 to 53):
GPIO 46: level=0 fsel=0 func=INPUT pull=UP
GPIO 47: level=0 fsel=0 func=INPUT pull=UP
GPIO 48: level=0 fsel=4 alt=0 func=SD0_CLK pull=DOWN
GPIO 49: level=0 fsel=4 alt=0 func=SD0_CMD pull=DOWN
GPIO 50: level=0 fsel=4 alt=0 func=SD0_DAT0 pull=DOWN
GPIO 51: level=0 fsel=4 alt=0 func=SD0_DAT1 pull=DOWN
GPIO 52: level=0 fsel=4 alt=0 func=SD0_DAT2 pull=DOWN
GPIO 53: level=0 fsel=4 alt=0 func=SD0_DAT3 pull=DOWN
GPIO19 is configured correctly.
EDIT: will also not behave differently on 5.15.61!

When I now try to change the brightness only the first brightness change request (to level '10' from below example) get's executed. Brightness change is also no longer persistent (lost after reboot; display starts at default brightness level).
Below method seems no longer working, so please let me know how to control the backlight and/or let me know what's the issue.

The device tree fragment in question is https://github.com/raspberrypi/linux/bl ... i.dtsi#L62

Code: Select all

pi@CM4Wave:~ $ sudo -i

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

[code]root@CM4Wave:~# echo 10  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# cat /sys/kernel/debug/pwm
platform/fe20c000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   (backlight_pwm       ): requested enabled period: 200000 ns duty: 75294 ns polarity: normal
This brightness change requests gets executed; brightness is changed.

Code: Select all

root@CM4Wave:~# echo 1  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# cat /sys/kernel/debug/pwm
platform/fe20c000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   (backlight_pwm       ): requested enabled period: 200000 ns duty: 4705 ns polarity: normal
root@CM4Wave:~# echo 15  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# cat /sys/kernel/debug/pwm
platform/fe20c000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   (backlight_pwm       ): requested enabled period: 200000 ns duty: 200000 ns polarity: normal
None of the above brightness change requests gets 'executed' as the actual display brightness level remains on '10'.
Last edited by aBUGSworstnightmare on Thu Sep 22, 2022 12:57 pm, edited 1 time in total.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4662
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Backlight control - generic DPI overlay

Thu Sep 22, 2022 8:01 am

When I now try to change the brightness only the first brightness change request (to level '10' from below example) get's executed. Brightness change is also no longer persistent (lost after reboot; display starts at default brightness level).
Device Tree is only responsible for the initial configuration of a device and its driver - what you are describing is more complex runtime behaviour, which probably puts it outside the realm of DT. Although the VC4 KMS DPI panel overlays have been restructured, the end result should be the same, aside from the added backlight options.

1. Which was the last kernel version where this worked?

2. You suggest that backlight brightness used to persist - where do you think that was being stored?

3. The old standalone vc4-kms-dpi-at056n53v1 overlay had no backlight control - how were you configuring this previously?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4662
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Backlight control - generic DPI overlay

Thu Sep 22, 2022 8:16 am

4. If you leave off the backlight parameters to the new overlay, it should behave exactly like the old one. Try combining that with whatever you used to do to control the backlight:

Code: Select all

dtoverlay=vc4-kms-dpi-panel,at056tn53v1
# Put old backlight configuration (if any) here

aBUGSworstnightmare
Posts: 5649
Joined: Tue Jun 30, 2015 1:35 pm

Re: Backlight control - generic DPI overlay

Thu Sep 22, 2022 9:57 am

PhilE wrote: 1. Which was the last kernel version where this worked?
was on 5.10.44 back in Sept last year. I'm not adjusting brightness quite frequent as I'm running them on max brightness most of the time.

Pictures were from a different platform but with same PWM backlight fragment in DT.
First pictures shows default brightness, on second brightness got increased to max, on third brightness got lowered to min. Atm, third command will not show the same effect; display brightness will stay on max (in case one uses the same sequence).
IMG_20210916_121609.jpeg
IMG_20210916_121609.jpeg (110.64 KiB) Viewed 631 times
IMG_20210916_121628.jpeg
IMG_20210916_121628.jpeg (104.27 KiB) Viewed 631 times
IMG_20210916_121641.jpeg
IMG_20210916_121641.jpeg (114.03 KiB) Viewed 631 times
I'm compiling latest kernel atm with the overlay I've used here viewtopic.php?p=1951550&hilit=backlight#p1951780.
Will report back if that's working. If not, I will use another (older) kernel for testing with to see if that makes a difference.
PhilE wrote: 2. You suggest that backlight brightness used to persist - where do you think that was being stored?
Isn't that stored in /sys/class/backlight/backlight_pwm/actual_brightness?
PhilE wrote: 3. The old standalone vc4-kms-dpi-at056n53v1 overlay had no backlight control - how were you configuring this previously?
In the beginning there was just an on/off via GPIO. Beeing able to configure DPI displays from DT I've used a new custom overlay (see link above).

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4662
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Backlight control - generic DPI overlay

Thu Sep 22, 2022 10:40 am

/sys/class/backlight/backlight_pwm/actual_brightness is a virtual file used to interact with the backlight_pwm driver. Unless the driver has some way of persisting the state (it doesn't), this is just volatile state.

How are you setting the brightness? Your overlay and vc4-kms-dpi-panel use radically different brightness scales; yours appears to make available all possible values from 0 to 1000, while vkdp declares 16 different brightness from 0 to 255.

Try doing what I suggested in point 4 above - retaining your custom backlight control and applying it with the standard vkdp overlay.

aBUGSworstnightmare
Posts: 5649
Joined: Tue Jun 30, 2015 1:35 pm

Re: Backlight control - generic DPI overlay

Thu Sep 22, 2022 11:40 am

PhilE wrote:
Thu Sep 22, 2022 10:40 am
...
Try doing what I suggested in point 4 above - retaining your custom backlight control and applying it with the standard vkdp overlay.
Sorry PhilE for disturbing you! It's way more simpler than that: STUPID ME had the audio enabled! Will not work when one needs the PWM module for something else.

Code: Select all

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
does the trick and now backlight can be controlled nicely.
PhilE wrote:
Thu Sep 22, 2022 10:40 am
..
How are you setting the brightness? Your overlay and vc4-kms-dpi-panel use radically different brightness scales; yours appears to make available all possible values from 0 to 1000, while vkdp declares 16 different brightness from 0 to 255.
That's just the no of steps, nothing else. Should - and will by the way - not matter.
PhilE wrote:
Thu Sep 22, 2022 10:40 am
/sys/class/backlight/backlight_pwm/actual_brightness is a virtual file used to interact with the backlight_pwm driver. Unless the driver has some way of persisting the state (it doesn't), this is just volatile state.
If it's not there is must be somewhere else! Using the kernel overlay, changing BL to min level, shut down and removing power.

Wait some time (allowing everything to discharge), reboot -> backlight is NOT default, it comes up on min level. That's what I would expect btw.
Will try to shoot a short video so you can see what I see.

aBUGSworstnightmare
Posts: 5649
Joined: Tue Jun 30, 2015 1:35 pm

[SOLVED] Re: Backlight control - generic DPI overlay

Thu Sep 22, 2022 12:45 pm

o.k. here is the video https://youtu.be/XprySlktqzk
It's a hyperlapse recorded at 10x speed to make it a short clip (which is sufficient for showing the effect of the brightness changes).

commands used in that video:

Code: Select all

@CM4Wave:~ $ xrandr --output DPI-1 --primary --scale-from 1024x768
pi@CM4Wave:~ $ sudo -i

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

root@CM4Wave:~# echo 12  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# echo 10  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# echo 8  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# echo 3  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# echo 1  > /sys/class/backlight/backlight_pwm/brightness
root@CM4Wave:~# exit
logout
pi@CM4Wave:~ $ 
As one can see from the video, the brightness changes were persistent --> don't ask me where the settings get stored on reboot/shutdown (as I'm not a Linux pro).
@PhilE: would love to hear your thoughts on how this is becoming persistent.
Last edited by aBUGSworstnightmare on Thu Sep 22, 2022 2:25 pm, edited 2 times in total.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 13274
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: [SOLVED] Backlight control - generic DPI overlay

Thu Sep 22, 2022 2:22 pm

IIRC It's part of systemd that restores the display brightness.
I had to patch the Pi DSI panel driver to not return a brightness because it was always returning 0 (the ATTiny code didn't support reading it back), so it kept on going black on reboot.

The email thread on that mentions systemd-backlight@backlight\:10-0045.service (name varies with the device), with the value being stored in /var/lib/systemd/backlight/
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aBUGSworstnightmare
Posts: 5649
Joined: Tue Jun 30, 2015 1:35 pm

Re: [SOLVED] Backlight control - (not only on) generic DPI overlay

Thu Sep 22, 2022 2:24 pm

6by9 wrote:
Thu Sep 22, 2022 2:22 pm
IIRC It's part of systemd that restores the display brightness.
I had to patch the Pi DSI panel driver to not return a brightness because it was always returning 0 (the ATTiny code didn't support reading it back), so it kept on going black on reboot.

The email thread on that mentions systemd-backlight@backlight\:10-0045.service (name varies with the device), with the value being stored in /var/lib/systemd/backlight/
Thanks for sharing this!

Return to “Device Tree”