From 47900e09b0d0bb8b9ecc45427fefa9c9528d2f7d Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Sun, 1 Nov 2026 14:55:47 -0647 Subject: [PATCH] omamobile-device-tegu 0.2.6: the USB rescue closes the switch after a replug the gadget didn't see Unplugging the palmtop from the laptop and plugging it back left it off the bus: the switch read 0x00 with VBUS present, but the gadget still read configured, so the rescue never looked. Without a Type-C driver dwc3 hears of no unplug. While configured, the rescue now reads the switch every 10 s. --- packages/omamobile-device-tegu/README.md | 2 +- .../bin/omamobile-tegu-usb-rescue | 17 +++++++++++++++++ .../omamobile-device-tegu/test/usb-rescue | 19 ++++++++++++++++--- packages/omamobile-device-tegu/version | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/omamobile-device-tegu/README.md b/packages/omamobile-device-tegu/README.md index 4caa42c58..5d9dafe74 100644 --- a/packages/omamobile-device-tegu/README.md +++ b/packages/omamobile-device-tegu/README.md @@ -16,7 +16,7 @@ packaged yet. What is here is what runs on in-tree drivers. | `vendor/modprobe.d/omamobile-tegu-display.conf`, `omamobile-tegu-clk-acpm.conf` | `/usr/lib/modprobe.d` | 120 Hz as the ceiling and the panel really off on DPMS (the DSI commands themselves are allowed by the graphics start, for google-tg4c only); the GPU DVFS ceiling at 890 MHz | | `bin/omamobile-tegu-aoc-start` + `vendor/systemd/system/omamobile-tegu-aoc.service` + `vendor/modprobe.d/omamobile-tegu-aoc.conf` | `/usr/bin`, `/usr/lib/systemd/system` (enabled; also `omamobile-aoc.service`), `/usr/lib/modprobe.d` | Boots the AoC (audio and sensor DSP) hang-safe: Trusty, the GSA, the AoC drivers, `aoc-tegu.bin`, waits for its 93 services, then loads the TAS2572 amplifiers. See below | | `bin/omamobile-bt-addr` + `vendor/systemd/system/omamobile-bt-addr@.service` + `vendor/udev/rules.d/80-omamobile-bt-addr.rules` | `/usr/bin`, `/usr/lib/systemd/system`, `/usr/lib/udev/rules.d` | Gives the BCM4383 its real Bluetooth address from the bootloader's device tree when the controller appears, powering it on once first (set on a never-powered controller, the kernel withdraws the index for good). The Pixel 7 Pro's script, with the extra waits the 9a needed | -| `bin/omamobile-tegu-usb-rescue` + `src/tegu-tcpc-switch.c` + `vendor/systemd/system/omamobile-tegu-usb-rescue.service` | `/usr/bin`, `/usr/lib/systemd/system` (enabled by a vendor wants link) | Closes the MAX77779's USB data switch after a cable replug while no Type-C driver owns the chip; with one loaded it exits. The helper reads the chip's identity and VBUS before its one write and never forces an address a driver holds | +| `bin/omamobile-tegu-usb-rescue` + `src/tegu-tcpc-switch.c` + `vendor/systemd/system/omamobile-tegu-usb-rescue.service` | `/usr/bin`, `/usr/lib/systemd/system` (enabled by a vendor wants link) | Closes the MAX77779's USB data switch after a cable replug while no Type-C driver owns the chip, also when the gadget still reads "configured" from before the unplug (dwc3 never hears of one without a Type-C driver, so the switch is read every 10 s while configured); with one loaded it exits. The helper reads the chip's identity and VBUS before its one write and never forces an address a driver holds | | `bin/omamobile-tegu-charge-limit` + `vendor/udev/rules.d/75-omamobile-tegu-charger.rules` | `/usr/bin`, `/usr/lib/udev/rules.d` | Applies `/etc/omamobile/charge-limit` (a percentage, say `80`): charging stops there and starts again 5 below. With the kernel's `max77779-charger` driver, which has charge inhibit and no end threshold, udev runs it on every battery change and it switches `charge_behaviour` between `inhibit-charge` and `auto` by the battery's capacity. No file: charge to 100 % | | `bin/omamobile-setup-system` | `/usr/bin` | System setup for Omarchy's lifecycle (omamobile-firstboot runs it): UTF-8 locale, timezone, NTP, and enables the sensor proxy and the NFC link opener (`omamobile-nfc-open`). Not the fingerprint service, speaker protection or the GNSS socket yet (see the script) | | `vendor/systemd/system-sleep/omamobile-tegu-wifi` | `/usr/lib/systemd/system-sleep` | Keeps Wi-Fi loaded across s2idle when `/etc/omamobile/wifi-keep-across-sleep` exists (the chip reloads its firmware on resume and iwd reconnects; the hook checks that from a transient unit, `omamobile-tegu-wifi-check`, so the lock screen doesn't wait for it), otherwise unloads and reloads brcmfmac around the sleep; after a sleep that lost Wi-Fi it unloads for the rest of the boot. It reloads the in-tree `brcmfmac`; a phone still running an out-of-tree build of it keeps its own hook until the Wi-Fi series lands | diff --git a/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue b/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue index ad5f3aea8..b33e8f0d2 100755 --- a/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue +++ b/packages/omamobile-device-tegu/bin/omamobile-tegu-usb-rescue @@ -14,6 +14,12 @@ # OMAMOBILE_TEGU_ROOT: a scratch root for the package tests; # OMAMOBILE_TEGU_RESCUE_GRACE: seconds the gadget may stay unconfigured # before the chip is read (default 4; then once per grace period). +# A configured gadget isn't proof the cable stayed in: with no Type-C +# driver, dwc3 never hears of an unplug, so after a replug the gadget can +# still read "configured" with the switch open and the phone off the bus. +# So while configured, the switch is read once per +# OMAMOBILE_TEGU_RESCUE_STALE seconds (default 10), and closed if it is +# open with VBUS present. set -uo pipefail root=${OMAMOBILE_TEGU_ROOT:-} @@ -22,6 +28,7 @@ if [[ -n $root ]]; then fi tool=${TEGU_TCPC_SWITCH:-/usr/bin/tegu-tcpc-switch} grace=${OMAMOBILE_TEGU_RESCUE_GRACE:-4} +stale=${OMAMOBILE_TEGU_RESCUE_STALE:-10} once=0 [[ ${1:-} == --once ]] && once=1 log() { echo "omamobile-tegu-usb-rescue: $*"; } @@ -33,6 +40,7 @@ gadget_state() { cat "$root"/sys/class/udc/*/state 2>/dev/null | head -1; } vbus_present() { local p; p=$("$tool" power 2>/dev/null | tail -1); [[ -n $p ]] && (( (p & 4) != 0 )); } open_since=0 +checked=0 log "watching the gadget state and the TCPC data switch" while :; do if tcpm_owns; then @@ -42,6 +50,15 @@ while :; do state=$(gadget_state) if [[ $state == configured ]]; then open_since=0 + now=$(date +%s) + if (( now - checked >= stale )); then + checked=$now + sw=$("$tool" switch 2>/dev/null | tail -1) + if [[ -n $sw && $sw != 0x09 ]] && vbus_present; then + log "gadget configured but USBSW_CTRL $sw with VBUS present (a replug the gadget didn't see): closing the data switch" + "$tool" connect 2>&1 | tail -1 + fi + fi else now=$(date +%s) (( open_since == 0 )) && open_since=$now diff --git a/packages/omamobile-device-tegu/test/usb-rescue b/packages/omamobile-device-tegu/test/usb-rescue index 377d7eaa3..30a94c375 100755 --- a/packages/omamobile-device-tegu/test/usb-rescue +++ b/packages/omamobile-device-tegu/test/usb-rescue @@ -1,7 +1,8 @@ #!/bin/bash # SPDX-License-Identifier: MIT # omamobile-tegu-usb-rescue in a scratch root, one pass at a time: a -# configured gadget is left alone, an open switch on an unconfigured gadget +# configured gadget only has its switch read, and closed if a replug left it +# open with VBUS, an open switch on an unconfigured gadget # with VBUS is closed once, a closed switch is not written, the cable out # (no VBUS) costs one register read and no log line, and a Type-C driver # that owns the chip ends the watch before the chip is read. @@ -12,6 +13,7 @@ fail() { printf 'not ok - usb-rescue: %s\n' "$1" >&2; exit 1; } tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT export OMAMOBILE_TEGU_ROOT=$tmp/root export OMAMOBILE_TEGU_RESCUE_GRACE=0 +export OMAMOBILE_TEGU_RESCUE_STALE=0 export TEST_LOG=$tmp/calls export TEGU_TCPC_SWITCH=$tmp/bin/tegu-tcpc-switch udc=$OMAMOBILE_TEGU_ROOT/sys/class/udc/11110000.dwc3 @@ -26,8 +28,19 @@ chmod +x "$tmp/bin/tegu-tcpc-switch" calls() { tr '\n' ' ' < "$TEST_LOG" | sed 's/ $//'; } : > "$TEST_LOG"; echo configured > "$udc/state" -SW=0x00 "$script" --once >/dev/null -[[ -z $(calls) ]] || fail "a configured gadget was touched: $(calls)" +out=$(SW=0x09 "$script" --once) +[[ $(calls) == "switch" && $out != *closing* ]] || fail "a configured gadget with the switch closed: one read, nothing else: $(calls)" + +# configured, but the switch is open with VBUS: a replug dwc3 never saw +: > "$TEST_LOG" +out=$(SW=0x00 "$script" --once) +[[ $(calls) == "switch power connect" ]] || fail "a stale configured gadget's open switch was not closed: $(calls)" +[[ $out == *"a replug the gadget didn't see"* ]] || fail "the stale-gadget close is not logged" + +# configured and open with the cable out: nothing written, nothing logged +: > "$TEST_LOG" +out=$(PW=0x00 SW=0x00 "$script" --once) +[[ $(calls) == "switch power" && $out != *closing* ]] || fail "a stale gadget with the cable out was written: $(calls)" : > "$TEST_LOG"; echo 'not attached' > "$udc/state" out=$(SW=0x00 "$script" --once) diff --git a/packages/omamobile-device-tegu/version b/packages/omamobile-device-tegu/version index 3a4036fb4..53a75d673 100644 --- a/packages/omamobile-device-tegu/version +++ b/packages/omamobile-device-tegu/version @@ -1 +1 @@ -0.2.5 +0.2.6