Fix the missing cover-panel reaction with a 9-bit panel path and sign-off probe

Live diagnosis with the flip physically closed showed the wake chain is
intact: bananarchy-coverctl BUTTON/WAKE, the lid gate and sxmo_state.sh set
unlock all reached backend=spidev visible=1 mux=closed, with the daemon
holding /dev/spidev0.1, the gpiochip and its line handles. The outer panel
itself never reacted. Register reads over SPI return zeros (write-only
panels), gpio21 stays static, and a reversible panel-mipi-dbi-spi/spidev
rebind on spi0.0 showed the shared gpio110 D/C path is also unreadable, so
the missing piece is the panel framing: the KaiOS downstream DTS labels
gpio21 TE, not D/C, and Qualcomm MDSS SPI carries D/C as the ninth bit.

bananarchy-cover-idle now defaults to 9-bit MIPI DBI: it releases gpio21,
claims only the reset line, and frames every command and pixel as a
little-endian 9-bit word with D/C in bit 8. spi_word_bits = 8 keeps the old
D/C-GPIO path. A PROBE command walks twelve combinations of word width,
gpio13 mux level, reset/D-C polarity and 25 MHz / 5 MHz clock, re-initialising
the panel and drawing TEST bars; STATUS reports bits= and probe=case N/12.
bananarchy-cover-probe.sh drives all twelve cases with a three-second hold so
the working wiring can be written back to cover-display.conf.

wanted_device() in common.h now also matches KEY_POWER, so the pm8941_pwrkey
device (KEY_POWER only) is no longer invisible to bananarchy-volume-keys and
all three outer buttons can produce a cover wake.

Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash
57d140e9cdf05631a6620b639d143350b9984b2170592fb927c93bfb18f67a2b in
check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms
seven updated rootfs files byte-for-byte, and the bootfs sync, boot image
check, artifact sync, host tests and rebuild preflight all pass.

Eyes-on confirmation of which case lights the cover, and the cover backlight
source, are still required; this is an intermediate checkpoint.
This commit is contained in:
Luxferre committed 2026-11-10 20:56:42 +02:00
1 parent 2857ef4374
commit 5f8b7c88ac
15 files changed
+252 -28

No files matched your search

+1
View File
@@ -75,6 +75,7 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, `
screens. The shipping image drives the external GC9305 from userspace over `/dev/spidev0.1` while the flip is
**closed only** (`bananarchy-cover-idle`); never claim gpio13/21/23 or send SPI traffic while the flip is open, and
gate activation on the main panel being DPMS-off; always restore the mux to the internal panel on `LID OPEN`.
- The cover panel's D/C wiring is unsigned-off: gpio21 is TE in the KaiOS DTS, not necessarily D/C. Keep both 8-bit (`spi_word_bits = 8`) and 9-bit MIPI DBI (`9`) paths, `bananarchy-coverctl PROBE` and `bananarchy-cover-probe.sh`. Do not claim a winner without eyes-on confirmation.
- 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.
+9
View File
@@ -13,6 +13,15 @@ Release versions follow the `<year-letter><MM><DD>` 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.
### Cover panel hardware sign-off path after the button regression
- **Live diagnosis**: with the flip physically closed, `bananarchy-coverctl BUTTON`, `WAKE`, `bananarchy-lid-gate.sh wake` and `sxmo_state.sh set unlock` all reached `backend=spidev visible=1 mux=closed`, and the daemon held `/dev/spidev0.1`, the gpiochip and two line handles. So the wake chain is intact; the outer panel itself never reacts to the frames. Register-ID reads over SPI return zeros for both chip selects (the panels are write-only), and gpio21 stays static, so readback/TE cannot be used to confirm wiring. A reversible `panel-mipi-dbi-spi`/`spidev` rebind on `spi0.0` proved CS0 + the kernel-owned gpio110 D/C path is also unreadable; the phone was fully restored (`/dev/dri/card0`, `/dev/fb0`, Xorg and dwm back).
- **Wiring gap**: the KaiOS downstream DTS labels gpio21 as **TE**, not D/C, and Qualcomm MDSS SPI carries D/C as the ninth bit. The cover daemon therefore gained a **9-bit MIPI DBI mode**: when `spi_word_bits = 9` it releases gpio21, frames every command and pixel as a little-endian 9-bit word with D/C in bit 8, and claims only the reset line. 9-bit is the default because the vendor DTS has no external D/C GPIO; `spi_word_bits = 8` restores the earlier D/C-GPIO path until physical sign-off.
- **Sign-off tooling**: `bananarchy-coverctl PROBE` walks twelve combinations of word width (8/9), gpio13 mux level, reset polarity, D/C polarity and SPI clock (25 MHz / 5 MHz), re-initialising the panel and drawing `TEST bars` each time; `STATUS` reports `bits=` and `probe=case N/12`. `bananarchy-cover-probe.sh` drives the twelve cases with a three-second hold, and `bananarchy-cover-diagnose.sh` prints the active keys. `SET spi_word_bits 8|9` toggles the mode at runtime. Once the working case is known it goes into `/etc/bananarchy/cover-display.conf`.
- **Button gap**: `wanted_device()` in `common.h` only watched devices with `KEY_VOLUMEUP`/`KEY_VOLUMEDOWN`, so the `pm8941_pwrkey` device (KEY_POWER only) was invisible to `bananarchy-volume-keys`. It now also matches `KEY_POWER`, so all three outer keys can produce a cover wake even when X/dwm does not forward one.
- **Still unverified**: eyes-on confirmation of which case lights the cover, and the cover backlight source (no separate backlight/LED node exists in the DT).
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` with the 9-bit default, PROBE tooling and KEY_POWER fix; verified raw hash `57d140e9cdf05631a6620b639d143350b9984b2170592fb927c93bfb18f67a2b`, pinned by `scripts/check-rebuild.sh`. `e2fsck -fn` passed on both partitions, `debugfs` confirms the rebuilt daemons and all sign-off scripts/config 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.
### Instant flip lid switching and closed-flip event routing
- **Root cause of the close lag**: `bananarchy-lid.c` recomputed `observed` from a stale `EV_SW` mask on every 100 ms iteration and only consulted the raw hall lines every 200 ms, so `candidate` oscillated open/closed and the 80 ms debounce rarely completed. With a controlled hall-file transition on the live phone a close took over 2.2 s to blank the main panel. The hall reading is now sticky, any `EV_SW` edge forces an immediate hall re-read, the loop/debounce are 20 ms, and the daemon writes the lid state, lock flag, Sxmo state and all backlights synchronously in C before spawning hooks. A direct `xset dpms force off/on` stops or resumes Xorg's SPI flushes immediately; the Sxmo hooks run through `bananarchy-lid-state.sh`, which refuses stale spawns by lid state and a transition generation counter so a late screenoff hook cannot re-lock a just-opened flip.
+1 -1
View File
@@ -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 `<video>`/`<audio>` autoplay without user gesture requirements), unobtrusive bookmarking (`*HTTPS`/`*HTTP` header badge, `*`+`0-9` save / `#`+`0-9` load chords, and bookmark manager), and dual navigation modes (keypad link-stepping mode with NeoUI multi-tap form input by default, plus an optional `*#` accelerated mouse cursor emulation mode), and a device-aware renderer profile: the 2720 Flip uses the WebKit CPU renderer (with automatic software fallback after a WebProcess crash) while the 8110 4G keeps Adreno 304 acceleration; `~/.config/sxmo/webarchy_software_renderer` forces the CPU profile on any target. The image build also compiles the installed GSettings schema XML into `usr/share/glib-2.0/schemas/gschemas.compiled`; without that database WebKit's network process aborts with an internal error before any renderer policy can help.
- **GPS-only system time**: **Config -> Time source** switches from NTP to GNSS only (stopping `chronyd` and disabling every network-up NTP burst) and **Config -> Sync GPS time** steps the clock from a ModemManager GPS UTC value or a valid RMC fix, writes the RTC and refreshes the status bar. All GPS queries now resolve the GNSS-capable modem through `bananarchy-gps-modem.sh` instead of the ambiguous `mmcli -m any`, which fixes empty GPS data on the dual-SIM 2720 Flip. See `MANUAL.md` sections 5.6 and 5.8.
- **2720 Flip cover display behaviour**: the compiled `bananarchy-cover-idle` renderer keeps the external panel fully off while the flip is open, waits for a side-button `BUTTON` event when closed, then shows the clock, battery and compact main network indicators until the same **Config -> Screen blank** timeout expires with no further button press. `bananarchy-volume-keys` turns the external keys into trusted cover wake events, `bananarchy-cover-status.sh` publishes modem/Wi-Fi indicators from network events, and the daemon blocks in `poll()` with no timer while off. **The external 240x240 GC9305 is now driven on the shipping single-panel image**: with the flip closed the daemon claims gpio13 (SPI mux), gpio21 (D/C) and gpio23 (reset) through `/dev/gpiochip0`, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at the verified 25 MHz, and pushes RGB565 frames, but only while the main panel is DPMS-off; on open it sends display-off, restores the mux to the internal panel and releases the panel lines before Xorg can flush another main-panel frame. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed. All mux/D-C/reset polarities are config keys plus live `bananarchy-coverctl SET` knobs, and `SET backend none` is a one-command rollback. The two-panel `spi-mux` DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`, built with `scripts/build-beatles-cover-panel.py`) stays **opt-in**: a live test produced `/dev/fb1` (240x240, 32bpp) but darkened the main panel, so the shipping DTB keeps the verified single-panel layout until gpio13 and the external D/C/reset polarities are probed with eyes on the phone. `FBIOBLANK` powers the cover fbdev down when it is off, `bananarchy-cover-diagnose.sh` reports the live panel state, `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` validate the renderer, the closed-flip backend and both DT layouts on the host, and `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback. **Closing the flip now blanks and locks the main panel in tens of milliseconds**: an `EV_SW` edge triggers an immediate hall re-read, and the compiled lid daemon writes the lid state, lock flag, Sxmo state and backlights synchronously before any shell hook runs. While closed, `bananarchy-lid-gate.sh` blocks every main-panel wake (dwm, Sxmo hooks, incoming calls, external keys) and forwards it as a cover `WAKE`, so the three side buttons and any event can only light the outer panel; opening the flip instantly hands the shared bus back to the main panel. See `scripts/test-lid-gate.py`.
- **2720 Flip cover display behaviour**: the compiled `bananarchy-cover-idle` renderer keeps the external panel fully off while the flip is open, waits for a side-button `BUTTON` event when closed, then shows the clock, battery and compact main network indicators until the same **Config -> Screen blank** timeout expires with no further button press. `bananarchy-volume-keys` turns the external keys into trusted cover wake events, `bananarchy-cover-status.sh` publishes modem/Wi-Fi indicators from network events, and the daemon blocks in `poll()` with no timer while off. **The external 240x240 GC9305 is now driven on the shipping single-panel image**: with the flip closed the daemon claims gpio13 (SPI mux), gpio21 (D/C) and gpio23 (reset) through `/dev/gpiochip0`, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at the verified 25 MHz, and pushes RGB565 frames, but only while the main panel is DPMS-off; on open it sends display-off, restores the mux to the internal panel and releases the panel lines before Xorg can flush another main-panel frame. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed. All mux/D-C/reset polarities are config keys plus live `bananarchy-coverctl SET` knobs, and `SET backend none` is a one-command rollback. The two-panel `spi-mux` DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`, built with `scripts/build-beatles-cover-panel.py`) stays **opt-in**: a live test produced `/dev/fb1` (240x240, 32bpp) but darkened the main panel, so the shipping DTB keeps the verified single-panel layout until gpio13 and the external D/C/reset polarities are probed with eyes on the phone. `FBIOBLANK` powers the cover fbdev down when it is off, `bananarchy-cover-diagnose.sh` reports the live panel state, `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` validate the renderer, the closed-flip backend and both DT layouts on the host, and `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback. **Closing the flip now blanks and locks the main panel in tens of milliseconds**: an `EV_SW` edge triggers an immediate hall re-read, and the compiled lid daemon writes the lid state, lock flag, Sxmo state and backlights synchronously before any shell hook runs. While closed, `bananarchy-lid-gate.sh` blocks every main-panel wake (dwm, Sxmo hooks, incoming calls, external keys) and forwards it as a cover `WAKE`, so the three side buttons and any event can only light the outer panel; opening the flip instantly hands the shared bus back to the main panel. See `scripts/test-lid-gate.py`. The external panel wiring is still pending physical sign-off: `bananarchy-cover-idle` defaults to 9-bit MIPI DBI (D/C in bit 8, no DC GPIO) and also supports the old 8-bit D/C-on-gpio21 path (`spi_word_bits`), and `bananarchy-cover-probe.sh` walks twelve polarity/clock/word-width cases with `TEST bars` while the flip is closed; `STATUS probe=case N/12` identifies the working one.
- **GPS reception test utility (`bananarchy-gps`) and OpenStreetMap navigator (`xgps` / `xmaps` / `xnav` / `gps.so`)**: CLI GNSS/GPS diagnostic tool (`bananarchy-gps status|enable|disable|nmea|watch`) and 3-tab NeoUI GPS navigator (`1:GPS Status`, `2:OSM Map`, `3:Nav/Search`) with live NMEA/QMI PDS satellite and 3GPP cell telemetry, interactive `240x212` OpenStreetMap slippy-map tile viewer with offline PNG tile cache (`~/.cache/sxmo/osm_tiles/`), Nominatim place search, saved waypoints, and OSRM turn-by-turn route geometry and step navigation.
- **Themes (`xthemes`), wallpapers (`xwallpapers`), and ringtones (`xringtones`)**: installable `.Xresources` color and font themes (`~/.xthemes/*.xth`, 21 preinstalled schemes including `LynxLair.xth`) with live zero-restart reload across the entire UI, `dunst` notification popups (`bananarchy-sync-dunst-theme`), and terminal, alongside dedicated managers for desktop wallpapers and 3-tab call ringtones & notification/SMS alerts (`1:Ringtone`, `2:Notif/SMS`, `3:Settings`, supporting standard audio, tracker modules, and Nokia RTTTL `.nrt`/`.rtttl`/`.rtx`, Ericsson eMelody `.emy`, and IrDA iMelody `.imy` monophonic ringtones via `/usr/bin/bananarchy-melody`, wired into `sxmo_notifs.sh` and `sxmo_hook_notification.sh`) with 3-level vibration control.
@@ -44,6 +44,15 @@ reset_assert_level = 0
reset_idle_level = 1
# Keep the verified internal-panel clock on the shared bus.
spi_speed_hz = 25000000
# The KaiOS downstream DTS labels gpio21 "TE" and Qualcomm MDSS SPI sends
# D/C as the ninth bit, so the cover panel may be 8-bit (D/C on gpio21) or
# 9-bit MIPI DBI (D/C in bit 8, no DC GPIO). 8 keeps the current wiring;
# 9 releases gpio21 and sends every byte as a 9-bit word. Until the physical
# sign-off is done, use "bananarchy-coverctl PROBE" repeatedly while the flip
# is closed: it draws TEST bars and walks the polarity/word-bit/speed cases,
# reporting the active one in STATUS as probe=case N/12. 9-bit is the default
# because the vendor DTS has no external D/C GPIO; set 8 for the old wiring.
spi_word_bits = 9
# Privacy defaults: no caller name, no notification body, no text in logs.
enabled = 1
@@ -61,7 +61,7 @@ if [ -r /sys/kernel/debug/gpio ]; then
fi
if [ -r "$CONF" ]; then
printf 'backend config :\n'
grep -E '^(backend|spi_device|spi_mux_gpio|spi_dc_gpio|spi_reset_gpio|mux_open_level|mux_closed_level|dc_command_level|dc_data_level|reset_assert_level|reset_idle_level|spi_speed_hz) ' "$CONF" | sed 's/^/ /'
grep -E '^(backend|spi_device|spi_mux_gpio|spi_dc_gpio|spi_reset_gpio|mux_open_level|mux_closed_level|dc_command_level|dc_data_level|reset_assert_level|reset_idle_level|spi_speed_hz|spi_word_bits) ' "$CONF" | sed 's/^/ /'
fi
if [ -x "$COVERCTL" ]; then
printf 'daemon : %s\n' "$("$COVERCTL" STATUS 2>/dev/null || printf 'not answering')"
@@ -71,7 +71,8 @@ fi
if command -v rc-service >/dev/null 2>&1; then
rc-service bananarchy-cover-display status 2>&1 | sed 's/^/service : /'
fi
printf 'sign-off : LID CLOSED; TEST bars, then LID OPEN\n'
printf 'sign-off : bananarchy-cover-probe.sh (12 cases)\n'
printf ' watch the cover, note STATUS probe=case N/12\n'
printf ' bananarchy-coverctl SET mux_closed_level 0|1\n'
printf ' bananarchy-coverctl SET reset_assert_level 0|1\n'
printf ' bananarchy-coverctl SET dc_command_level 0|1\n'
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
# Walk the 2720 Flip external panel hardware sign-off cases.
#
# With the flip closed, each PROBE case re-inits the GC9305 with a different
# SPI word width (8-bit D/C GPIO vs 9-bit MIPI DBI), mux level, reset polarity,
# D/C polarity and clock, then draws TEST bars on the cover. Watch the outer
# screen, note the case that lights it from STATUS, then set the matching keys
# in /etc/bananarchy/cover-display.conf and restart the service.
set -u
COVERCTL="${BANANARCHY_COVERCTL:-/usr/bin/bananarchy-coverctl}"
HOLD="${BANANARCHY_COVER_PROBE_HOLD:-3}"
CASES=12
printf 'Close the flip, then watch the outer panel for %s seconds per case.\n' "$HOLD"
printf 'The active combination is printed as probe=case N/%s.\n' "$CASES"
i=1
while [ "$i" -le "$CASES" ]; do
"$COVERCTL" PROBE >/dev/null 2>&1 || true
printf '--- case %d/%d ---\n' "$i" "$CASES"
"$COVERCTL" STATUS 2>/dev/null || printf 'cover daemon is not answering\n'
sleep "$HOLD"
i=$((i + 1))
done
printf 'Done. Set the working keys in /etc/bananarchy/cover-display.conf and\n'
printf 'run: rc-service bananarchy-cover-display restart\n'
exit 0
Binary file not shown.
+9 -1
View File
@@ -373,7 +373,7 @@ fi
echo "[check] Known-good flashable image set..."
for pair in \
"69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \
"0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 images/bananarchy-nokia-beatles.img" \
"57d140e9cdf05631a6620b639d143350b9984b2170592fb927c93bfb18f67a2b images/bananarchy-nokia-beatles.img" \
"2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
set -- $pair
@@ -945,6 +945,14 @@ if ! grep -qF 'cover_wake' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-id
"$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"; then
fail "the cover daemon no longer honours a closed-flip WAKE"
fi
if ! grep -qF 'probe_cases' \
"$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c" || \
! grep -qF 'spi_word_bits' \
"$BASE_DIR/overlay/rootfs/etc/bananarchy/cover-display.conf" || \
! grep -qF 'KEY_POWER' "$BASE_DIR/src/bananarchy-daemons/common.h" || \
[ ! -x "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-probe.sh" ]; then
fail "the cover hardware sign-off probe, 9-bit mode or KEY_POWER watch is missing"
fi
if [ ! -x "$BASE_DIR/scripts/test-lid-gate.py" ] || \
! "$BASE_DIR/scripts/test-lid-gate.py" >/dev/null 2>&1; then
fail "host instant-lid / closed-flip gate test failed"
+25 -6
View File
@@ -139,7 +139,8 @@ def main():
for token in ("cover_hw_release", "cover_spi_draw", "hw_init_panel",
"mux_closed_level", "spi_speed_hz", "FBIOBLANK",
"BANANARCHY_COVER_SPI_SIM", "cover_main_panel_is_off",
"cover_wake", "pending_until",
"cover_wake", "pending_until", "probe_cases",
"spi_word_bits",
"0x28", "0x29"):
if token not in source:
sys.stderr.write("FAIL: cover daemon lost %s\n" % token)
@@ -182,7 +183,7 @@ def main():
daemon.send("LID CLOSED")
if not daemon.wait_event("claim"):
return not check(False, "closing the flip did not claim the mux")
if not daemon.wait_event("cmd fe 0") or not daemon.wait_event("cmd 29 0"):
if not daemon.wait_event("cmd fe 0 ") or not daemon.wait_event("cmd 29 0 "):
return not check(False, "external panel firmware was not replayed")
if not daemon.wait_event("frame lit=0 size=115200"):
return not check(False, "no dark frame after closing")
@@ -200,7 +201,7 @@ def main():
daemon.send("BUTTON")
if not daemon.wait_event("frame lit=1 size=115200"):
return not check(False, "BUTTON did not light the external panel")
if "cmd 29 0" not in daemon.events():
if not any(e.startswith("cmd 29 0 ") for e in daemon.events()):
return not check(False, "display-on command missing")
print("[ok] external button: lit RGB565 frame on the cover")
@@ -313,6 +314,24 @@ def main():
finally:
pend.close()
# PROBE walks the hardware sign-off cases and 9-bit words are framed.
probe, _ = run_case(root, exe, {})
try:
probe.send("LID CLOSED")
for i in range(12):
probe.send("PROBE")
if "probe=case %d/12" % (i + 1) not in probe.send("STATUS"):
return not check(False, "PROBE case %d was not reported" % (i + 1))
events = probe.events()
if not any(e.startswith("cmd fe 0 bits=9") for e in events):
return not check(False, "PROBE never exercised 9-bit MIPI DBI")
if not any(e.startswith("frame lit=1 size=230400") for e in events) and \
not any(e.startswith("frame lit=1") for e in events):
return not check(False, "PROBE did not draw the test bars")
print("[ok] PROBE cycles polarity/word-bit/speed cases with test bars")
finally:
probe.close()
# A transient lid flap must never steal the bus from a live main panel.
live, _ = run_case(root, exe, {}, dpms="On")
try:
@@ -331,16 +350,16 @@ def main():
knobs, _ = run_case(root, exe, {})
try:
knobs.send("LID CLOSED")
if not knobs.wait_event("cmd fe 0"):
if not knobs.wait_event("cmd fe 0 "):
return not check(False, "runtime-knob daemon did not init the panel")
before = len([e for e in knobs.events() if e == "cmd fe 0"])
before = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
knobs.send("SET mux_closed_level 0")
if not knobs.wait_event("release"):
return not check(False, "SET polarity did not release the panel lines")
if not check(any(e == "gpio 0" for e in knobs.events()),
"SET mux_closed_level was ignored"):
return 1
after = len([e for e in knobs.events() if e == "cmd fe 0"])
after = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
if after <= before:
return not check(False, "SET polarity did not re-init the panel")
knobs.send("SET backend none")
+12 -2
View File
@@ -16,6 +16,9 @@ LID_SRC = BASE / "src/bananarchy-daemons/bananarchy-lid.c"
COVER_SRC = BASE / "src/bananarchy-daemons/bananarchy-cover-idle.c"
GATE = BASE / "overlay/rootfs/usr/bin/bananarchy-lid-gate.sh"
LID_WRAPPER = BASE / "overlay/rootfs/usr/bin/bananarchy-lid-state.sh"
COMMON = BASE / "src/bananarchy-daemons/common.h"
COVER_CONF = BASE / "overlay/rootfs/etc/bananarchy/cover-display.conf"
PROBE_SH = BASE / "overlay/rootfs/usr/bin/bananarchy-cover-probe.sh"
WM = BASE / "overlay/rootfs/usr/bin/sxmo_wm.sh"
STATE_SH = BASE / "overlay/rootfs/usr/bin/sxmo_state.sh"
WAKE = BASE / "overlay/rootfs/usr/bin/bananarchy-screen-wake.sh"
@@ -50,8 +53,9 @@ def run_gate(profile, state, arg="", stub=None):
def main():
paths = [LID_SRC, COVER_SRC, GATE, LID_WRAPPER, WM, STATE_SH, WAKE,
DPMS_SYNC, EVENT, *INPUT_HOOKS, *HOOKS]
paths = [LID_SRC, COVER_SRC, COMMON, COVER_CONF, PROBE_SH, GATE,
LID_WRAPPER, WM, STATE_SH, WAKE, DPMS_SYNC, EVENT,
*INPUT_HOOKS, *HOOKS]
for path in paths:
if not path.is_file():
return fail("missing %s" % path.relative_to(BASE))
@@ -103,6 +107,12 @@ def main():
event = EVENT.read_text(encoding="utf-8")
if " wake)" not in event or "coverctl WAKE" not in event:
return fail("cover event bridge lost the wake forwarding case")
common = COMMON.read_text(encoding="utf-8")
if "device_has_code(fd, EV_KEY, KEY_POWER)" not in common:
return fail("the End/Power key is not watched while the flip is closed")
conf = COVER_CONF.read_text(encoding="utf-8")
if "spi_word_bits" not in conf:
return fail("the cover config lost the 8/9-bit sign-off knob")
cover = COVER_SRC.read_text(encoding="utf-8")
if "cover_wake" not in cover or 'strcmp(command, "WAKE")' not in cover:
return fail("cover daemon lost the WAKE command")
+147 -15
View File
@@ -124,6 +124,10 @@ struct cover_hw {
int reset_assert_level;
int reset_idle_level;
unsigned int speed_hz;
int word_bits;
int panel_lines;
int probe_index;
char probe_desc[96];
int sim;
int spi_enabled;
int fd_spi;
@@ -136,6 +140,30 @@ struct cover_hw {
int initialized;
};
/* Hardware sign-off cases for the external GC9305. The KaiOS downstream DTS
* calls gpio21 "TE", not D/C, and Qualcomm MDSS SPI sends D/C as the ninth
* bit, so both 8-bit (D/C on a GPIO) and 9-bit (D/C in bit 8) are plausible.
* PROBE walks these while drawing TEST bars; the working case is written to
* /etc/bananarchy/cover-display.conf afterwards. */
struct probe_case {
int bits;
int mux;
int reset;
int dc;
unsigned int speed;
};
static const struct probe_case probe_cases[] = {
/* 9-bit first: the downstream DTS labels gpio21 TE and MDSS SPI carries
* D/C in bit 8, so this is the best-supported wiring. */
{9, 1, 0, 0, 25000000}, {9, 1, 1, 0, 25000000},
{9, 0, 0, 0, 25000000}, {9, 0, 1, 0, 25000000},
{9, 1, 0, 0, 5000000}, {9, 0, 1, 0, 5000000},
{8, 1, 0, 0, 25000000}, {8, 1, 1, 0, 25000000},
{8, 1, 0, 1, 25000000}, {8, 1, 1, 1, 25000000},
{8, 0, 0, 0, 25000000}, {8, 1, 0, 0, 5000000},
};
struct glyph {
char ch;
unsigned char col[5];
@@ -530,19 +558,49 @@ static int hw_xfer(struct cover_hw *hw, const unsigned char *tx, size_t len,
static int hw_dc(struct cover_hw *hw, int level)
{
unsigned char values[2];
if(hw->word_bits == 9)
return 1;
values[0] = (unsigned char)level;
values[1] = (unsigned char)hw->reset_idle_level;
return hw_gpio_set(hw, hw->fd_panel, values, 2);
}
static int hw_reset_set(struct cover_hw *hw, int level)
{
unsigned char values[2];
if(hw->panel_lines == 1) {
values[0] = (unsigned char)level;
return hw_gpio_set(hw, hw->fd_panel, values, 1);
}
values[0] = (unsigned char)hw->dc_data_level;
values[1] = (unsigned char)level;
return hw_gpio_set(hw, hw->fd_panel, values, 2);
}
static int hw_command(struct cover_hw *hw, unsigned char cmd,
const unsigned char *params, size_t n)
{
char line[64];
snprintf(line, sizeof(line), "cmd %02x %zu", cmd, n);
snprintf(line, sizeof(line), "cmd %02x %zu bits=%d", cmd, n,
hw->word_bits);
hw_event(hw, line);
if(hw->sim)
return 1;
if(hw->word_bits == 9) {
/* MIPI DBI Type C: D/C is bit 8 of each little-endian 9-bit word. */
unsigned char buf[64];
size_t used = 0;
size_t i;
if((n + 1) * 2 > sizeof(buf))
return 0;
buf[used++] = cmd;
buf[used++] = 0;
for(i = 0; i < n; i++) {
buf[used++] = params[i];
buf[used++] = 1;
}
return hw_xfer(hw, buf, used, 1);
}
if(!hw_dc(hw, hw->dc_command_level))
return 0;
if(!hw_xfer(hw, &cmd, 1, n ? 0 : 1))
@@ -607,7 +665,6 @@ static int hw_activate(struct cover_hw *hw)
unsigned int panel_offsets[2];
unsigned char mux_default[1];
unsigned char panel_default[2];
unsigned char values[2];
int fd;
if(!hw->spi_enabled)
return 0;
@@ -631,11 +688,18 @@ static int hw_activate(struct cover_hw *hw)
hw_gpio_set(hw, hw->fd_mux, mux_value, 1);
}
if(!hw->claimed) {
panel_offsets[0] = hw->dc_gpio;
panel_offsets[1] = hw->reset_gpio;
panel_default[0] = (unsigned char)hw->dc_data_level;
panel_default[1] = (unsigned char)hw->reset_idle_level;
fd = hw_gpio_request(hw, panel_offsets, panel_default, 2);
hw->panel_lines = hw->word_bits == 9 ? 1 : 2;
if(hw->panel_lines == 1) {
panel_offsets[0] = hw->reset_gpio;
panel_default[0] = (unsigned char)hw->reset_idle_level;
} else {
panel_offsets[0] = hw->dc_gpio;
panel_offsets[1] = hw->reset_gpio;
panel_default[0] = (unsigned char)hw->dc_data_level;
panel_default[1] = (unsigned char)hw->reset_idle_level;
}
fd = hw_gpio_request(hw, panel_offsets, panel_default,
(unsigned int)hw->panel_lines);
if(fd < 0)
return 0;
hw->fd_panel = fd;
@@ -648,6 +712,7 @@ static int hw_activate(struct cover_hw *hw)
hw->fd_spi = open(hw->spi_path, O_RDWR | O_CLOEXEC);
if(hw->fd_spi < 0)
return 0;
bits = (unsigned char)hw->word_bits;
if(ioctl(hw->fd_spi, BA_SPI_IOC_WR_MODE, &mode) < 0 ||
ioctl(hw->fd_spi, BA_SPI_IOC_WR_BITS, &bits) < 0 ||
ioctl(hw->fd_spi, BA_SPI_IOC_WR_SPEED, &speed) < 0)
@@ -656,13 +721,10 @@ static int hw_activate(struct cover_hw *hw)
}
if(!hw->initialized) {
/* Reset pulse on the external panel, then replay its firmware stream. */
values[0] = (unsigned char)hw->dc_data_level;
values[1] = (unsigned char)hw->reset_assert_level;
hw_gpio_set(hw, hw->fd_panel, values, 2);
hw_reset_set(hw, hw->reset_assert_level);
if(!hw->sim)
poll(NULL, 0, 20);
values[1] = (unsigned char)hw->reset_idle_level;
hw_gpio_set(hw, hw->fd_panel, values, 2);
hw_reset_set(hw, hw->reset_idle_level);
if(!hw->sim)
poll(NULL, 0, 150);
if(!hw_init_panel(hw))
@@ -683,6 +745,37 @@ static int hw_frame(struct cover_hw *hw, const struct frame *fb, int lit)
hw_event(hw, line);
if(hw->sim)
return 1;
if(hw->word_bits == 9) {
unsigned char start[2];
unsigned char *words;
size_t i;
size_t left;
const unsigned char *p;
start[0] = 0x2c;
start[1] = 0;
if(!hw_xfer(hw, start, 2, 0))
return 0;
words = malloc(size * 2);
if(!words)
return 0;
for(i = 0; i < size; i++) {
words[i * 2] = fb->pixels[i];
words[i * 2 + 1] = 1;
}
p = words;
left = size * 2;
while(left) {
size_t chunk = left > COVER_SPI_CHUNK ? COVER_SPI_CHUNK : left;
if(!hw_xfer(hw, p, chunk, chunk == left)) {
free(words);
return 0;
}
p += chunk;
left -= chunk;
}
free(words);
return 1;
}
if(!hw_dc(hw, hw->dc_command_level))
return 0;
if(!hw_xfer(hw, &cmd, 1, 0))
@@ -904,6 +997,10 @@ static void cover_hw_init(struct cover_hw *hw)
hw->reset_assert_level = 0;
hw->reset_idle_level = 1;
hw->speed_hz = 25000000;
hw->word_bits = 9;
hw->panel_lines = 1;
hw->probe_index = -1;
safe_copy(hw->probe_desc, sizeof(hw->probe_desc), "none");
hw->fd_spi = -1;
hw->fd_chip = -1;
hw->fd_mux = -1;
@@ -1000,6 +1097,10 @@ static void read_config(const char *path, char *socket_path, size_t splen,
v = strtol(value, NULL, 10);
if(v >= 1000000 && v <= 50000000)
hw->speed_hz = (unsigned int)v;
} else if(strcmp(key, "spi_word_bits") == 0) {
v = strtol(value, NULL, 10);
if(v == 8 || v == 9)
hw->word_bits = (int)v;
}
}
fclose(handle);
@@ -1152,10 +1253,39 @@ static void handle_command(char *buffer, struct state *state,
hw->reset_assert_level = config_level(value, hw->reset_assert_level);
else if(strcmp(key, "reset_idle_level") == 0)
hw->reset_idle_level = config_level(value, hw->reset_idle_level);
else
else if(strcmp(key, "spi_word_bits") == 0) {
long bits = strtol(value, NULL, 10);
if(bits == 8 || bits == 9)
hw->word_bits = (int)bits;
else
return;
} else
return;
cover_hw_release(hw);
*redraw = 1;
} else if(strcmp(command, "PROBE") == 0) {
const struct probe_case *p;
hw->probe_index = (hw->probe_index + 1) %
(int)(sizeof(probe_cases) / sizeof(probe_cases[0]));
p = &probe_cases[hw->probe_index];
hw->word_bits = p->bits;
hw->mux_closed_level = p->mux;
hw->mux_open_level = p->mux ? 0 : 1;
hw->reset_assert_level = p->reset;
hw->reset_idle_level = p->reset ? 0 : 1;
hw->dc_command_level = p->dc;
hw->dc_data_level = p->dc ? 0 : 1;
hw->speed_hz = p->speed;
snprintf(hw->probe_desc, sizeof(hw->probe_desc),
"case %d/%d bits=%d mux=%d reset=%d dc=%d speed=%u",
hw->probe_index + 1,
(int)(sizeof(probe_cases) / sizeof(probe_cases[0])),
p->bits, p->mux, p->reset, p->dc, p->speed);
cover_hw_release(hw);
state->test = 2;
state->visible = 1;
state->last_input_ms = now_ms();
*redraw = 1;
} else if(strcmp(command, "TEST") == 0) {
char *mode = strtok_r(NULL, " \t\r\n", &save);
if(mode)
@@ -1195,11 +1325,13 @@ static void reply_for(char *buffer, const struct state *state,
} else if(strcmp(command, "STATUS") == 0) {
snprintf(reply, len,
"OK lid=%s backend=%s enabled=%d visible=%d blank_ms=%lld "
"battery=%d call=%s sms=%d network=%s spi=%d mux=%s\n",
"battery=%d call=%s sms=%d network=%s spi=%d mux=%s "
"bits=%d probe=%s\n",
state->lid, state->backend, state->enabled, state->visible,
state->blank_ms, state->battery, state->call, state->sms,
state->network, hw->spi_enabled,
hw->mux_claimed ? (hw->claimed ? "closed" : "open") : "free");
hw->mux_claimed ? (hw->claimed ? "closed" : "open") : "free",
hw->word_bits, hw->probe_desc);
} else if(strcmp(command, "LID") == 0) {
snprintf(reply, len, "OK lid=%s\n", state->lid);
} else if(strcmp(command, "TEST") == 0) {
+7 -1
View File
@@ -34,6 +34,9 @@
#define SW_KEYPAD_SLIDE 0x0a
#define KEY_VOLUMEDOWN 114
#define KEY_VOLUMEUP 115
#ifndef KEY_POWER
#define KEY_POWER 116
#endif
#define BA_IOC(dir, type, nr, size) \
(((unsigned int)(dir) << 30) | ((unsigned int)(type) << 8) | \
((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16))
@@ -173,8 +176,11 @@ static BA_UNUSED int wanted_device(int fd, enum watch_filter filter)
return device_has_code(fd, EV_SW, SW_LID) ||
device_has_code(fd, EV_SW, SW_KEYPAD_SLIDE);
}
/* The End/Power key lives on a KEY_POWER-only device (pm8941_pwrkey),
* so it must be watched too or the third outer button is invisible. */
return device_has_code(fd, EV_KEY, KEY_VOLUMEUP) ||
device_has_code(fd, EV_KEY, KEY_VOLUMEDOWN);
device_has_code(fd, EV_KEY, KEY_VOLUMEDOWN) ||
device_has_code(fd, EV_KEY, KEY_POWER);
}
static BA_UNUSED void prune_devices(struct watch_list *list)