Skip to content

omamobile-device-tegu 0.2.14: restore the panel's brightness once DSI commands are allowed (#512) - #600

Open
den-kloot wants to merge 1 commit into
derekross:mainfrom
den-kloot:device-tegu-backlight-restore
Open

den-kloot wants to merge 1 commit into
derekross:mainfrom
den-kloot:device-tegu-backlight-restore

Conversation

@den-kloot

Copy link
Copy Markdown
Contributor

What and why

Fixes #512. On the Pixel 9a, systemd-backlight@backlight:19440000.dsi.0.service fails at every boot, so the saved brightness is never restored. The panel's backlight is registered when gs_dsim_cmd binds the panel, ahead of omamobile-tegu-graphics-start, and udev starts the restore right then. Until the start sets gs_dsim_cmd.allow_tx, a brightness write gets EPERM, and the second try hits the start limit.

The fix is in the display step of omamobile-tegu-graphics-start. When its write to allow_tx worked, it looks at each backlight's systemd-backlight@ unit:

  • one still activating gets up to 5 s to finish;
  • a failed one is reset (for the start limit) and started again, with a journal line either way;
  • one that worked, or that udev hasn't started yet, is left alone;
  • a second failure is logged and does not fail the start.

An ordering drop-in was not used: systemd-backlight@ is Before=sysinit.target, and the start runs after it.

Device and build

Checks (no phone needed)

  • tools/pr-check upstream/main passes
  • tests/all: not run
  • packages/omamobile-device-tegu/test/all passes on the phone
  • Commit has an area prefix and a body that says why; AI help is a Co-Authored-By: trailer, no Signed-off-by:

test/graphics-start now stubs systemctl; before, nothing in the script called it. The tests check:

  • the reset comes before the start, and the journal line is written;
  • an active or an inactive restore is left alone;
  • without allow_tx (another panel) nothing is restored;
  • a second failure is logged without failing the start;
  • without a backlight, systemctl is not called.

Against the previous script, the first check fails.

On the phone

  • I ran this on my own phone, as a hand copy of the script over omamobile-device-tegu 0.2.9 (whose script is identical to main's), across two boots on 2026-11-10:
    • First boot: nothing was restored. gs_dsim_cmd shows the bool parameter as Y, and that version read allow_tx back and compared it with 1. The start now remembers whether its own write worked.
    • Second boot (journalctl -b):
      06:47:35 systemd[1]: systemd-backlight@backlight:19440000.dsi.0.service: Failed with result 'start-limit-hit'.
      06:47:35 omamobile-tegu-graphics: panel google-tg4c.2d408004: DSI commands allowed (gs_dsim_cmd.allow_tx=1)
      06:47:36 omamobile-tegu-graphics: 19440000.dsi.0: the saved brightness, refused before DSI commands were allowed, is restored
      06:47:36 systemd[1]: Finished Load/Save Screen Backlight Brightness of backlight:19440000.dsi.0.
      06:47:42 omamobile-tegu-graphics: up: GPU, display, haptics, torch, gauge 74 %, Bluetooth, NFC, Wi-Fi (wlp1s0)
      
      The unit stays active afterwards.
  • How it was tested: the agent (Claude Code, on the phone) wrote the change, ran the tests, installed the script and read the journals. I (the owner) said yes to both reboots and to sending it.
  • What I did not test: a built 0.2.14 package, the palmtop, a boot where udev starts the restore after allow_tx.
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)

🤖 Generated with Claude Code

… commands are allowed (derekross#512)

On the Pixel 9a, systemd-backlight@backlight:19440000.dsi.0.service fails
at every boot, so the saved brightness is never restored. The panel's
backlight is registered when gs_dsim_cmd binds the panel, ahead of
omamobile-tegu-graphics-start, and udev starts the restore right then;
until the start sets gs_dsim_cmd.allow_tx, a brightness write gets EPERM.
The journal of a second 9a (not the palmtop), 2026-11-09, device-tegu 0.2.10:

  17:48:12 systemd-backlight[732]: 19440000.dsi.0: Failed to write system
           'brightness' attribute: Operation not permitted
  17:48:12 systemd[1]: Failed to start Load/Save Screen Backlight
           Brightness of backlight:19440000.dsi.0.

After the display step, when its write to allow_tx worked, the start looks at each
backlight's systemd-backlight@ unit: it waits up to 5 s for one that is
still activating, and a failed one is reset (the issue's boot also hit the
start limit) and started again, with a line in the journal either way. A
restore that worked, or one udev hasn't started yet, is left alone, and a
second failure is logged without failing the start. An ordering drop-in
was not used: systemd-backlight@ is Before=sysinit.target, and the start
runs after it.

test/graphics-start stubs systemctl (it was not stubbed, and nothing called
it) and checks the reset before the start, the log line, the active and
inactive cases, no restore without allow_tx (another panel), a second
failure, and no call without a backlight; against the previous script the
first check fails. test/all on that 9a: all ok.

On that 9a, booted with this script (2026-11-10 06:47), the restore
fails at 06:47:35 as before, allow_tx is set, and then:

  06:47:36 omamobile-tegu-graphics: 19440000.dsi.0: the saved brightness,
           refused before DSI commands were allowed, is restored
  06:47:36 systemd[1]: Finished Load/Save Screen Backlight Brightness of
           backlight:19440000.dsi.0.

The first boot with it found nothing to do: gs_dsim_cmd shows the bool
parameter as Y, so the start keeps whether its own write worked rather
than reading allow_tx back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, this is a careful fix, and the write-up of the first boot (the
kernel shows the bool as Y, so the script remembers its own write
instead of reading it back) is the kind of detail that saves the next
person an hour. The test covers the cases I'd have asked for, and I
checked that 0.2.9's script is the same as main's, so your two boots count
for this change.

Two small changes before I merge:

  1. Bound the restart. systemctl start waits for the job, and
    systemd-backlight@ has a 90 s timeout, while the whole graphics start
    has 120 s and is still in its display phase at that point. If the
    brightness write ever hangs, the start loses 90 s, the later steps run
    out of time, and the next boot finds the marker and leaves the GPU,
    display and Wi-Fi off. timeout 10 systemctl start "$unit" (logging
    the "failed again" line when it gives up) keeps a brightness restore
    from costing that. Calling restore_backlight at the very end of the
    script, after the last driver step, would be better still, if you
    don't mind the brightness arriving a few seconds later.
  2. Only when the display came up. As written, the restore also runs
    when gs_decon failed to load or bind, since it sits after that
    if/elif/else. That path hasn't run on a phone. Could you call it
    only where the display step succeeded, and add that case to the test
    (the suite already has FAIL_MODULE)?

One question, not a condition: what does the first boot with the fix
restore? The unit has failed at every boot until now, so its save at
shutdown never ran, and the stored level is an old one. And after that, a
reboot taken while the screen is dark would save that level. If you can,
try one reboot with the screen off and tell me what the screen shows
afterwards.

On the version: please leave it, I'll set it at merge. Main is at 0.2.10
and #372 and #483 aren't ready, so this will go in as 0.2.11 and those two
move up when they land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pixel 9a: systemd-backlight fails at every boot (brightness restored before allow_tx is set)

2 participants