Power on with duration; power on if brightness > 0; fix backlight device selection on KMS systems; handle multiple backlight sysfs nodes correctly#68
Open
p1r473 wants to merge 2 commits into
Conversation
On systems exposing multiple /sys/class/backlight entries (e.g. KMS/DSI on newer Raspberry Pi models), the previous name-based selection could pick a non-functional device and fail with EINVAL/EIO. Select the backlight device by probing for one that accepts a brightness write, falling back to the previous *-0045 / rpi_backlight logic if none succeed. This makes device selection robust across different kernels, display revisions, and overlays without hardcoding bus numbers or model checks. Also improve CLI input validation by rejecting "on"/"off" as SYSFS_PATH and guiding users to the proper -p flag usage.
Contributor
Author
|
Update to PR: Hi @linusg , On newer Raspberry Pi systems using KMS (e.g. Pi 5 with DSI), the kernel can expose multiple /sys/class/backlight entries:
The current selection logic picks the first "*-0045" entry by name, which can resolve to a non-functional device depending on enumeration order, causing rpi-backlight to fail at startup. This PR changes Raspberry Pi backlight selection to be capability-based instead of name-based:
This avoids hardcoding bus numbers or model checks and works across:
Additionally, the CLI now rejects "on" and "off" as positional SYSFS_PATH values and guides users to use the proper -p flag, preventing confusing tracebacks when running: |
This was referenced Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Linus,
On my Pi, I am able to successfully fade with a duration with
rpi-backlight -b 0 -d 3. However, I cant power on/off with a durationrpi-backlight -p off -d 3. I can, however, toggle with a duration just finerpi-backlight -p toggle -d 3I believe we should be able to power on/off with a duration based on this line in the code, showing the intention that power setting may indeed be set with a duration.
parser.error("-p/--set-power may only be used with -d/--duration")After checking the code, I found that powering on/off with a duration wasn't actually implemented yet
So, I added it as a feature:
-Power on/off is now supported with duration
Additionally, I found that if you set the brightness to 100 while the power is off, nothing happens. So, I added an extra 2 features:
-If setting brightness >0, turn the power on first. (This will better the user experience)
-If setting brightness to 0, turn the power off once brightness is 0. (Perhaps $ energy savings?)
I also added a quick check to the code.
-Do not try to power on if already on (This will prevent the brightness from setting to 100 if brightness is already turned up (i.e. 40) and you try to power on) which fixes #44
There is a difference between power and toggle however that needs to be reflected in the code I believe.
If its on, and you try to turn it on, nothing should happen.
If its on, and you try to toggle it, it should turn off.
Toggle does not have this problem, because if you toggle it while its already on, it will just turn off
This code prevents setting the brightness to 100 if lets say, brightness is currently 40 and you power on. Without this code, if you power on an and the screen is already, brightness will just go to 100, which is probably not what the user wanted.