From d61f2848db004348940cfe10237091e57f5ec3ab Mon Sep 17 00:00:00 2001 From: Luxferre Date: Wed, 11 Nov 2026 07:57:38 +0200 Subject: [PATCH] Handle active-low cover backlight and restore internal panel --- AGENTS.md | 16 +- CHANGELOG.md | 10 +- MANUAL.md | 2 +- README.md | 2 +- .../rootfs/etc/bananarchy/cover-display.conf | 19 +- overlay/rootfs/usr/bin/bananarchy-cover-idle | Bin 25824 -> 29920 bytes .../usr/bin/bananarchy-display-power-sync | 118 +++++++-- .../usr/bin/bananarchy-cover-idle | Bin 25824 -> 29920 bytes scripts/check-rebuild.sh | 15 +- scripts/test-cover-kernel.py | 86 ++++-- .../bananarchy-cover-idle.c | 250 +++++++++++++++--- 11 files changed, 412 insertions(+), 106 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b779f80..08de58a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,16 +77,20 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, ` **closed only** (`bananarchy-cover-idle`); never claim gpio13/23 or send cover SPI traffic while the flip is open, gate initial activation on the main panel being DPMS-off, and always restore the mux on `LID OPEN`. - The KaiOS 3.10 DTS gives both panels shared CS0, gpio110 D/C and one PWM backlight; gpio21 is TE and gpio23 is the - external reset. Keep the exact vendor external init firmware, the debugfs command replay, the gpio23 reset pulse, - `/run/bananarchy/cover-backlight` and the `bananarchy-display-power-sync` marker exemption. The legacy 8-bit/9-bit - userspace paths, `PROBE` and `bananarchy-cover-probe.sh` remain rollback/sign-off tooling. If the cover stays dark, - `SET mux_closed_level 0` switches gpio13 polarity at runtime. + external reset. The shared PWM is active-low for the cover and active-high for the main panel: duty 0 lights the + cover, duty 14 lights the internal panel. Keep the exact vendor external init firmware, the debugfs command replay, + the gpio23 reset pulse, `/run/bananarchy/cover-backlight` (`1` = cover lit, `0` = cover dark), + `kernel_power_sync_helper` and the `/run/bananarchy/cover-bl-force` nested-udev guard. On open, restore + gpio13 low, duty 14, `bl_power=0`, DPMS On and re-init the internal panel. The legacy 8-bit/9-bit userspace paths, `PROBE` and `bananarchy-cover-probe.sh` remain + rollback/sign-off tooling. `SET mux_closed_level 0` selects the internal panel, not the cover; use + `SET kernel_backlight_invert 0|1` only if a unit's backlight polarity differs. - Keep the internal beatles panel at 25 MHz, `dc_gpio = -1` for the spidev fallback, external-panel firmware and initramfs module lists, the Xorg `card0` pin, `bananarchy-cover-diagnose.sh`, and the `scripts/test-cover-dt.py` / `scripts/test-cover-spidev.py` guards. - The shipping cover backend is `backend = kernel`: keep `bananarchy-cover-dpms.sh reinit`, the gpio13 mux claim, - the 240x240 `/dev/fb0` damage rect, the 1 s repaint against Xorg, `scripts/test-cover-kernel.py`, and the - `spidev`/`fb`/`none` rollback backends. + the 240x240 `/dev/fb0` damage rect, the 1 s repaint against Xorg, `kernel_backlight_invert = 1`, + `kernel_backlight_level = 14`, `scripts/test-cover-kernel.py`, and the `spidev`/`fb`/`none` rollback backends. + The daemon must restore the internal panel on `LID OPEN` even after a stale high gpio13 survives a restart. - Keep the 2720 Flip lid handling event-driven and instant: sticky hall state, immediate hall re-read on `EV_SW` edges, 20 ms debounce, and synchronous lid-state/lock/backlight/DPMS writes in `bananarchy-lid.c`. Closing locks the desktop; opening must keep the lock flag and wake to the passcode lockscreen, never auto-unlock. Every diff --git a/CHANGELOG.md b/CHANGELOG.md index 222fee4..772139a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,21 @@ Release versions follow the `
` format (where `2026` is `a`, Work since `a1108` has focused on reliable 2720 Flip hardware support and a reproducible boot/flash path. Earlier incremental and superseded diagnostic entries are consolidated here. +### Active-low cover backlight and reliable internal-panel handover + +- **Root cause**: eyes-on testing confirmed the outer display lights only with PWM **duty 0** while gpio13 selects the cover; the main panel uses the same PMIC PWM with the opposite polarity and needs duty 14. Leaving the cover daemon frozen with duty 0 and gpio13 high made the outer display work but left the internal panel all-white, and a daemon restart could leave gpio13 latched high because the fresh process had no linehandle to drive low. `SET mux_closed_level 0` selects the internal panel, not the cover. +- **Switch**: `kernel_backlight_invert = 1`, `kernel_backlight_level = 14`, `kernel_backlight_power_path` and `kernel_power_sync_helper` are shipped. `/run/bananarchy/cover-backlight` contains `1` while the cover is lit (duty 0, `bl_power=0`, DPMS On) and `0` while the cover owns the bus but is dark (duty 14, `bl_power=0`, DPMS On). `bananarchy-display-power-sync` reads that marker and the invert/level keys, uses `/run/bananarchy/cover-bl-force` to suppress nested udev events during a forced two-step PWM update, and is also invoked directly by the daemon after marker changes. `cover_kernel_restore_internal()` explicitly drives gpio13 low, removes the marker, restores duty 14, `bl_power=0`, DPMS On and re-initialises the internal panel on `LID OPEN`, even after a stale high mux survives a daemon restart. `SET kernel_backlight_invert 0|1` remains a runtime rollback knob. +- **Guards**: `scripts/test-cover-kernel.py` now checks the dark/lit marker contents, the active-low duty, the OFF duty on blank, normal brightness on open, mux restore, 1 s repaint and the DPMS gate. `scripts/check-rebuild.sh` guards the new config keys, source functions and the active-low display-power-sync paths. README, MANUAL and `AGENTS.md` document the polarity and handover. +- **Live verification**: the user confirmed the outer display works with duty 0. The restore sequence returned the phone to `lid=open`, `state=unlock`, brightness 14, `bl_power=0`, DPMS On and all services started; a separate gpio13 probe drove the latched mux low. The rebuilt ARM daemon, config and scripts were deployed and the closed→lit→blank→open sequence was rechecked: cover lit showed `marker=1`, `br=0`, external TE toggles, 1382586 extra `spi0.0` bytes and zero SPI errors; cover dark showed `marker=0`; `LID OPEN` removed the marker and restored gpio13 low; the final open state showed `br=14`, `bl_power=0`, DPMS On, PWM duty 100000 ns, `l17/l6` enabled and a non-white `/dev/fb0` (0 white bytes, mean 20.7). `e2fsck -fn` passed on both partitions; `debugfs` confirms all rebuilt artifacts byte-for-byte; bootfs sync, boot image check, artifact sync, six host tests and `check-rebuild.sh` pass. The standalone boot image hash is unchanged. Eyes-on confirmation of both screens after this final deployment is still pending. +- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `3fc34741cbe9a2e68ab77e7133393bd7f93c7fec1c938680405760e8d02dfa08`, pinned by `scripts/check-rebuild.sh`. + ### Vendor-init kernel cover path and persistent flip lock - **Root cause of the dark cover**: the KaiOS 3.10 downstream DTS (`0004-dts-adaptations.patch`) shows that both GC9305s share CS0, gpio110 D/C and one PMIC MPP2 PWM backlight; gpio13 selects the panel, gpio23 is the external reset and gpio21 is TE. The previous kernel backend left that shared backlight at zero, never pulsed gpio23, and replayed the internal 240x320 init instead of the stock 240x240 stream. A DPMS off/on cycle alone cannot initialise the external panel. The earlier open transition also removed the lock flag and returned straight to the unlocked desktop. - **Switch**: `nokia,beatles-gc9305-ext-panel.bin` now contains the exact vendor `fe ef 3a 05 ... 2a/2b 0..239, 11, 29` stream. While closed, `bananarchy-cover-idle` claims gpio13/gpio23, pulses reset, sends that stream through the kernel driver's `/sys/kernel/debug/dri/0/command` hook, publishes `/run/bananarchy/cover-backlight` before enabling the shared backlight, and renders a 240x240 `/dev/fb0` damage rect once per second so Xorg repaints cannot erase it. `bananarchy-display-power-sync` skips the closed-lid hard-off gate only while that marker and `lid-state=closed` are both present. `bananarchy-lid` now keeps `/tmp/bananarchy_screen_locked`, writes `sxmo.state=lock`, sends `LOCK` to `locker.so` and runs `sxmo_state.sh set lock` on open instead of auto-unlocking. - **Guards**: `scripts/test-cover-kernel.py`, `scripts/test-lid-gate.py`, `scripts/check-rebuild.sh`, `bananarchy-cover-diagnose.sh`, README, MANUAL and `AGENTS.md` now guard the vendor firmware, debugfs command hook, shared-backlight marker, 1 s repaint, DPMS-off initial gate, lock-on-open and both mux-polarity runtime knobs. The legacy `spidev`/`fb`/`none`, 8/9-bit and PROBE rollback paths remain. - **Live verification**: with the flip state injected closed and DPMS off, `BUTTON` produced `backend=kernel`, marker present, brightness 14, `bl_power=0`, DPMS On, 172800 non-zero bytes in the top 240x240 of `/dev/fb0`, 460919 extra kernel `spi0.0` bytes and zero SPI errors/timeouts. A gpiochip TE scan proved the bus routing objectively: blank had `ext(gpio21)=0 int(gpio24)=0` transitions, `mux_closed_level=0` had `ext=0 int=78`, and `mux_closed_level=1` had `ext=52 int=0`; high is the cover and low is the internal panel. A controlled close→open transition left `state=lock`, the lock flag present, the cover marker absent, `mux=free`, brightness 14, keypad 1 and DPMS On; it stayed locked after 1 s. The phone was restored to open/unlocked with all services started and zero `SPI transfer failed` messages. Eyes-on illumination still needs a human look, but the external panel's TE, shared backlight and kernel SPI traffic are now confirmed. -- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `e2ec6a35d1e7db698f929fa0ebdbed94ffd941a55fc50ceff7a223e82896e985`, pinned by `scripts/check-rebuild.sh`. `e2fsck -fn` passed on both partitions, `debugfs` confirms the rebuilt daemons, firmware, config, helper and scripts byte-for-byte, and the bootfs sync, boot image check, artifact sync, host tests and rebuild preflight pass. The standalone boot image hash is unchanged. +- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; verified raw hash `e2ec6a35d1e7db698f929fa0ebdbed94ffd941a55fc50ceff7a223e82896e985`, pinned by `scripts/check-rebuild.sh`. `e2fsck -fn` passed on both partitions, `debugfs` confirms the rebuilt daemons, firmware, config, helper and scripts byte-for-byte, and the bootfs sync, boot image check, artifact sync, host tests and rebuild preflight pass. The standalone boot image hash is unchanged Superseded by the active-low backlight rebuild below. ### Kernel-owned cover panel path (option b) diff --git a/MANUAL.md b/MANUAL.md index b1e7d45..c9d007d 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -456,7 +456,7 @@ Three native X11 games (`/usr/bin/snake`, `/usr/bin/tetris`, and `/usr/bin/scoun - **X startup and keypad**: OpenRC starts independent services in parallel; `etc/init.d/local` replaces its stock `after *` dependency, which deadlocked with parallel startup on this image. `udev_settle_timeout=2` stops missing modem firmware from holding the display manager behind a long `udevadm settle`, and `bananarchy-sshd-debug` starts independently of `local.d`. A boot-open flip reads `/run/bananarchy/lid-state` and starts in `state=unlock` with no passcode screen, so the keypad is live as soon as `dwm` starts. If the keypad is dead, check `rc-service bananarchy-lid status`, `cat /run/bananarchy/lid-state`, `sxmo_state.sh get`, `/tmp/bananarchy_screen_locked`, `DISPLAY=:0 xwininfo -id 0xa00001` and `DISPLAY=:0 xinput list`. - **Display distortion above 71% brightness**: the internal panel uses 25 MHz SPI on `nokia-beatles`, rather than the 50 MHz timing used by the other targets. This keeps the link stable when the MPP2 backlight PWM duty rises above the level-10/14 operating point. The brightness range remains 1–14 with no artificial cap, and panel offsets/init registers are unchanged. The timing can be checked with `dtc -I dtb -O dts /boot/qcom-msm8905-nokia-beatles.dtb | grep -A8 'display@0'`. - **Closing the flip**: `bananarchy-lid` keeps a sticky hall reading, re-reads gpio36/gpio92 immediately on every `EV_SW` edge, and uses a 20 ms debounce/loop. On close it writes `/run/bananarchy/lid-state`, `/tmp/bananarchy_screen_locked`, `sxmo.state`, both backlights and DPMS synchronously before spawning any hook, then runs `sxmo_state.sh set screenoff` through a generation-guarded wrapper. On open it releases the cover's shared SPI bus, restores the main panel and **keeps the desktop locked**: it writes state `lock`, sends `LOCK` to `locker.so` and runs `sxmo_state.sh set lock`, so the passcode lockscreen appears instead of an auto-unlocked desktop. A close is ~45-90 ms and an open ~10-130 ms. `bananarchy-lid-state.sh` drops stale hook spawns by lid state and generation. Check `rc-service bananarchy-lid status`, `sxmo_state.sh get`, `/tmp/bananarchy_screen_locked` and `grep -E " gpio(36|92) " /sys/kernel/debug/gpio`. If the hall polarity is inverted, set `BANANARCHY_LID_GPIO_FILE` to a different debugfs GPIO file. -- **Cover display status and behaviour**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl` (`PING`, `STATUS`, `LID CLOSED|OPEN`, `BUTTON`, `NETWORK`, `BATTERY`, `NOTIFY`, `BLANK`/`UNBLANK`, `TEST`, `SET`, `PROBE`); the native `bananarchy-coverd` is retained only for diagnostics. With the flip open the daemon does not touch the shared QUP5 SPI bus; initial closed-flip activation still requires `card0-SPI-1/dpms = Off`. The shipping single-panel DTB uses `backend = kernel`: the KaiOS 3.10 DTS shows that the two GC9305s share CS0, gpio110 D/C and one PWM backlight, while gpio13 selects the panel, gpio23 is the external reset and gpio21 is TE; a live TE scan proved high = cover and low = internal. On a closed-flip button event the daemon claims gpio13/gpio23, pulses reset, replays the exact vendor 240x240 init through `/sys/kernel/debug/dri/0/command`, publishes `/run/bananarchy/cover-backlight`, turns on the shared backlight and flushes a 240x240 `/dev/fb0` damage rect once per second. `bananarchy-display-power-sync` permits that backlight only while the marker and closed-lid state are both present; the keypad stays dark. `STATUS` reports `backend=kernel`, `mux=cover`; `BLANK` sends display-off and removes the marker; `LID OPEN` restores the mux and re-initialises the internal panel. The outer panel stays off until a trusted side-key `BUTTON` / `WAKE` arrives; it blanks after the same **Config -> Screen blank** timeout (`blank_timeout = auto`). The legacy `spidev`, 8/9-bit, `PROBE`, `SET mux_closed_level 0|1` and `SET backend none` paths remain for rollback. If the cover stays dark, try `SET mux_closed_level 0` with the flip closed and press an outer button; the runtime knob forces a fresh reset/init cycle. `bananarchy-cover-diagnose.sh` reports the debugfs hook, backlight marker, GPIO lines, DPMS, firmware and daemon state. `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py`, `scripts/test-cover-kernel.py`, `scripts/test-cover-dt.py` and `scripts/test-lid-gate.py` guard the state machine, both backends, DT layouts and lid gate on the host. The opt-in two-panel `spi-mux` DT remains experimental because its separate gpio21 D/C wiring contradicts the vendor DTS and a live test darkened the main panel; `scripts/build-beatles-no-cover-dtb.py` builds the shipping rollback DTB. +- **Cover display status and behaviour**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl` (`PING`, `STATUS`, `LID CLOSED|OPEN`, `BUTTON`, `NETWORK`, `BATTERY`, `NOTIFY`, `BLANK`/`UNBLANK`, `TEST`, `SET`, `PROBE`); the native `bananarchy-coverd` is retained only for diagnostics. With the flip open the daemon does not touch the shared QUP5 SPI bus; initial closed-flip activation still requires `card0-SPI-1/dpms = Off`. The shipping single-panel DTB uses `backend = kernel`: the KaiOS 3.10 DTS shows that the two GC9305s share CS0, gpio110 D/C and one PWM backlight, while gpio13 selects the panel, gpio23 is the external reset and gpio21 is TE. A live TE scan proved gpio13 high = cover and low = internal. On a closed-flip button event the daemon claims gpio13/gpio23, pulses reset, replays the exact vendor 240x240 init through `/sys/kernel/debug/dri/0/command`, and flushes a 240x240 `/dev/fb0` damage rect once per second. The shared PWM is active-low for the cover and active-high for the main panel: duty 0 lights the cover, duty 14 lights the internal panel. `/run/bananarchy/cover-backlight` contains `1` while the cover is lit and `0` while the cover owns the bus but is dark; `bananarchy-display-power-sync` holds the matching brightness, `bl_power` and DPMS state. `STATUS` reports `backend=kernel`, `mux=cover`; `BLANK` sends display-off and returns the external backlight to its OFF duty; `LID OPEN` restores gpio13 low, duty 14, `bl_power=0`, DPMS On and re-initialises the internal panel. The outer panel stays off until a trusted side-key `BUTTON` / `WAKE` arrives; it blanks after the same **Config -> Screen blank** timeout (`blank_timeout = auto`). The legacy `spidev`, 8/9-bit, `PROBE`, `SET mux_closed_level 0|1`, `SET kernel_backlight_invert 0|1` and `SET backend none` paths remain for rollback. `bananarchy-cover-diagnose.sh` reports the debugfs hook, backlight marker, GPIO lines, DPMS, firmware and daemon state. `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py`, `scripts/test-cover-kernel.py`, `scripts/test-cover-dt.py` and `scripts/test-lid-gate.py` guard the state machine, both backends, DT layouts and lid gate on the host. The opt-in two-panel `spi-mux` DT remains experimental because its separate gpio21 D/C wiring contradicts the vendor DTS and a live test darkened the main panel; `scripts/build-beatles-no-cover-dtb.py` builds the shipping rollback DTB. - **Camera app frozen / UI unresponsive**: check `top` for `bananarchy-volume-keys`. The daemon must be a single instance at 0% CPU; stale evdev fds are pruned by `prune_devices()`/`drop_device()` and guarded by `flock`. `rc-service bananarchy-volume-keys status` and `bananarchy-keypad-diagnose.sh` report its state. `xcamera` should return immediately and `bananarchy-photo ` should write a 600x800 JPEG. - **Camera**: `/dev/video0` is provided by the out-of-tree `msm8905-cam` module, loaded at boot by `/etc/modules-load.d/bananarchy-hardware.conf` and `etc/local.d/10-bananarchy-hardware.start`. Check with `v4l2-ctl --list-devices`; a missing node means the module did not load (previously caused by a missing `/bin/sed` breaking the `modules` service). diff --git a/README.md b/README.md index f7f93fe..0756527 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs - **Kopher SmallWeb browser (`xkopher` / `kopher` / `xsmallweb` / `smallweb.so`)**: multi-protocol SmallWeb client for **Gopher** (`gopher://`) with optional TLS (`gophers://`), **Gemini** (`gemini://`), **Spartan** (`spartan://`), and **Nex** (`nex://`), featuring WAP-style default keypad controls from [Kopher](https://code.luxferre.top/luxferre/kopher.git), user-adjustable keybindings (`~/.config/sxmo/smallweb_controls.tsv`), 10 bookmarks, custom homepage support, and link focus that always scrolls the viewport to the focused link in both wrapped and unwrapped modes. - **Webarchy Web browser (`webarchy` / `xwebarchy` / `webarchy.so`)**: full-featured HTML5/CSS3/JS web browser built on WPE / WebKit (`webkit2gtk-4.1` + `libwpe-1.0`) with Adreno 304 hardware acceleration (`WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS`, WebGL, accelerated 2D canvas, and 512 MB RAM pressure tuning), default KaiOS 4.0 User-Agent (`Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0`) with preset and custom User-Agent override (`~/.config/sxmo/webarchy_ua.txt`), `UTF-8` default encoding fallback, `Noto Sans` / `Noto Serif` (`font-noto` + `font-noto-emoji`) as the default non-monospace browser fonts and `Fira Code` with OpenType ligatures as the monospace font, full GStreamer multimedia (`MediaSource` / MSE, WebAudio, inline HTML5 `