Fix MBHC wired headphone autodetection across all targets for a1125 (ampere)

Retain PM8909 MBHC digital debounce clock (DIG_CLK_CTL_D_MBHC_CLK_EN) and master bias (CDC_A_MASTER_BIAS_CTL = 0x30) across s2 standby gating while keeping the 100 uA button ISRC and button IRQs disabled when unplugged, check CDC_A_MBHC_RESULT_2 on boot/set_jack/switch IRQs with 3/4-pole FSM classification, fix iface=CARD jack queries, event coalescing, and stale unplugged Headphones boot fallback in bananarchy-soundmonitor and sxmo audio scripts, harden host tests against CPU contention, and rebuild all a1125 (ampere) target images.
This commit is contained in:
Luxferre committed 2026-11-24 11:00:06 +02:00
1 parent aba38a58f2
commit 9619cc9541
19 files changed
+516 -93

No files matched your search

+2 -1
View File
@@ -112,7 +112,8 @@ EOF
echo "[2m/5] Applying system-core keypad debouncer patch..."
patch -p1 < /bananarchy/patches/kernel/0014-input-core-keypad-debouncer.patch
fi
if ! grep -q "msm8916_wcd_digital_force_sync_ctl" sound/soc/codecs/msm8916-wcd-digital.c 2>/dev/null; then
if ! grep -q "msm8916_wcd_digital_force_sync_ctl" sound/soc/codecs/msm8916-wcd-digital.c 2>/dev/null || \
! grep -q "CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE" sound/soc/codecs/msm8916-wcd-analog.c 2>/dev/null; then
echo "[2n/5] Applying WCD digital 48 kHz interpolator and CAJON analog codec patch..."
patch -p1 < /bananarchy/patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch
fi
+7 -7
View File
@@ -564,15 +564,15 @@ fi
echo "[check] Known-good flashable image set..."
for pair in \
"6279d2b99600aee7751f501257ac48d485eaeee3b3f31c0f98a2b8522400bcd1 images/bananarchy-nokia-argon.img" \
"f067a130984d7fe6f79fdf46b3ff657bbe19fe12400e5db1e6ebd4cac24d1e6c images/bananarchy-nokia-beatles.img" \
"d32c7a38ac85df7faa71d2649d7c6ead1adcef0af39c3e91f08993965ddd44b9 images/boot-bananarchy-nokia-beatles.img" \
"5df590a5c0a74a1594882e3d83a81c7691bdd3bfc396a320eb6e84e27f41b356 images/bananarchy-nokia-argon.img" \
"55cb9c17347735ff066f9a88f3b3e5c574281296ff78ac796cf79e2bbd0c2b81 images/bananarchy-nokia-beatles.img" \
"4500324c8c875588b60063befb9f852069ce5a84b70c92025708c412ddc9a30e images/boot-bananarchy-nokia-beatles.img" \
"f13db705a714aaebd2d8fcc2e0f7266d0e40268c0a276208117dfdf9d8f45351 images/boot-lk2nd-nokia-beatles-display.img" \
"4d6733b633ca78ec7fe5de93e1ed0564a3aa116088aee3634147759a414af2c7 images/bananarchy-nokia-coconut.img" \
"fdad08c8501de6b53c6ac76b7886849834fc8840ffec289b41a5c58e924ac803 images/boot-bananarchy-nokia-coconut.img" \
"5d629a64b6c82b0ce46af7135e2eff8620142043903c2e65f27a7163a9b21b32 images/bananarchy-nokia-coconut.img" \
"c6c1d3fe3ad8eae39cc0ec6eeae14de136fd7524430976cb39ba79255a5dd9c2 images/boot-bananarchy-nokia-coconut.img" \
"9a5bd2da6cfd95c745d9c1acb2e3bc61afa339824810e3d160bf079e17b23192 images/boot-lk2nd-nokia-coconut-display.img" \
"068f4fa606bee9c63ac6044902e04a28d596b04edcd230d9703a2687951ee4bb images/bananarchy-nokia-sparkler.img" \
"026852df5acc871738322ff1de3febf91c097f0f1d745fbbe71f22661023b0e2 images/boot-bananarchy-nokia-sparkler.img" \
"efd541291277e702f67b18b9bf90a7571e459c87c124a705d6dad265dc032be8 images/bananarchy-nokia-sparkler.img" \
"ba922d89ad0a778086ef6a400d48b816125ad017d24d5bd81ad601d77293342e images/boot-bananarchy-nokia-sparkler.img" \
"120ade81bc5416263a1afd95a29981675358b98516e105e5ed611edf258a29f7 images/boot-lk2nd-nokia-sparkler-display.img"; do
set -- $pair
want=$1
+77 -1
View File
@@ -200,11 +200,21 @@ def check_patch_0015():
"pm8916_wcd_analog_enable_hphr_dac",
"pm8916_wcd_analog_enable_hph_pa",
"pm8916_wcd_analog_apply_defaults(component, true);",
"CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE",
"pm8916_mbhc_plug_present",
"DIG_CLK_CTL_D_MBHC_CLK_EN",
"CDC_A_MASTER_BIAS_CTL, 0x30",
"snd_soc_jack_report(jack, initial_report, hs_jack_mask);",
"phys_ins != waiting_ins",
]
for tok in required:
if tok not in txt:
return fail(f"0015 patch missing required token: {tok}")
analog_diff = txt.split("diff --git a/sound/soc/codecs/msm8916-wcd-digital.c")[0]
if "+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x00);" in analog_diff:
return fail("0015 must not zero CDC_A_MASTER_BIAS_CTL on s2 idle gating")
if ".volatile_reg" in txt:
return fail("0015 patch must not set .volatile_reg on msm8916_codec_regmap_config")
@@ -313,10 +323,76 @@ def check_gain_staging():
return fail("sxmo_audio.sh missing PipeWire unity sync guard, @DEFAULT_AUDIO_SINK@, or sink wait")
soundmon_txt = read_text(SOUNDMONITOR_C)
for tok in ("has_internal_sink", "internal_synced"):
for tok in (
"has_internal_sink",
"internal_synced",
"drain_jack_events",
"last_hp_plugged",
"iface=CARD,name='Headphone Jack'",
"iface=CARD,name='Mic Jack'",
):
if tok not in soundmon_txt:
return fail(f"bananarchy-soundmonitor.c missing {tok}")
gcc = shutil.which("gcc")
if gcc:
with tempfile.TemporaryDirectory(prefix="ba_soundmon_") as td:
exe = os.path.join(td, "bananarchy-soundmonitor")
bld = subprocess.run(
[
gcc, "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-I", os.path.dirname(SOUNDMONITOR_C),
SOUNDMONITOR_C, "-o", exe,
],
capture_output=True,
text=True,
)
if bld.returncode != 0:
return fail(f"host gcc build of bananarchy-soundmonitor.c failed:\n{bld.stderr}")
with tempfile.TemporaryDirectory(prefix="ba_audio_dev_") as td:
tmp_dir = os.path.join(td, "tmp")
cfg_dir = os.path.join(td, "cfg")
bin_dir = os.path.join(td, "bin")
os.makedirs(tmp_dir, exist_ok=True)
os.makedirs(cfg_dir, exist_ok=True)
os.makedirs(bin_dir, exist_ok=True)
mock_pactl = os.path.join(bin_dir, "pactl")
with open(mock_pactl, "w", encoding="utf-8") as handle:
handle.write("#!/bin/sh\nexit 0\n")
os.chmod(mock_pactl, 0o755)
patched_sh = os.path.join(td, "sxmo_audio.sh")
with open(patched_sh, "w", encoding="utf-8") as handle:
handle.write(audio_txt.replace("/tmp/", tmp_dir + "/"))
env = dict(os.environ)
env["XDG_CONFIG_HOME"] = td
env["CFG_DIR"] = cfg_dir
env["PATH"] = bin_dir + ":" + env.get("PATH", "")
# Rewrite CFG_DIR to cfg_dir explicitly via a symlink sxmo -> cfg_dir.
os.symlink(cfg_dir, os.path.join(td, "sxmo"))
with open(os.path.join(cfg_dir, "audio_out_device"), "w", encoding="utf-8") as handle:
handle.write("Headphones\n")
with open(os.path.join(cfg_dir, "audio_in_device"), "w", encoding="utf-8") as handle:
handle.write("Headset\n")
with open(os.path.join(tmp_dir, "sxmo_jack_plugged"), "w", encoding="utf-8") as handle:
handle.write("0\n")
r_out = subprocess.run(["sh", patched_sh, "device", "get"], env=env, capture_output=True, text=True, check=True)
r_in = subprocess.run(["sh", patched_sh, "device", "getinput"], env=env, capture_output=True, text=True, check=True)
if r_out.stdout.strip() != "Speaker" or r_in.stdout.strip() != "Mic1":
return fail(f"unplugged boot fallback failed: out={r_out.stdout!r} in={r_in.stdout!r}")
for p in ("sxmo_audio_out_device", "sxmo_audio_in_device"):
fp = os.path.join(tmp_dir, p)
if os.path.exists(fp):
os.unlink(fp)
with open(os.path.join(tmp_dir, "sxmo_jack_plugged"), "w", encoding="utf-8") as handle:
handle.write("1\n")
r_out2 = subprocess.run(["sh", patched_sh, "device", "get"], env=env, capture_output=True, text=True, check=True)
r_in2 = subprocess.run(["sh", patched_sh, "device", "getinput"], env=env, capture_output=True, text=True, check=True)
if r_out2.stdout.strip() != "Headphones" or r_in2.stdout.strip() != "Headset":
return fail(f"plugged boot preservation failed: out={r_out2.stdout!r} in={r_in2.stdout!r}")
probe_script = r"""
set -eu
. "%s" >/dev/null 2>&1 || true
+10 -2
View File
@@ -351,16 +351,24 @@ 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("frame lit=0"):
return not check(False, "runtime-knob daemon did not init the panel")
before = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
if before <= 0:
return not check(False, "runtime-knob daemon logged no init stream")
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")
deadline = time.time() + 5.0
after = before
while time.time() < deadline:
after = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
if after > before and any(e == "gpio 0" for e in knobs.events()):
break
time.sleep(0.05)
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.startswith("cmd fe 0 ")])
if after <= before:
return not check(False, "SET polarity did not re-init the panel")
knobs.send("SET backend none")
+17 -23
View File
@@ -39,26 +39,17 @@ def setup_mocks(tmp: pathlib.Path) -> dict:
write_exec(
mock_bin / "logger",
"#!/usr/bin/env python3\n"
"import os, pathlib, sys\n"
"log_path = pathlib.Path(os.environ['MOCK_LOGGER_LOG'])\n"
"args = sys.argv[1:]\n"
"i = 0\n"
"while i < len(args):\n"
" a = args[i]\n"
" if a == '-s':\n"
" i += 1\n"
" elif a in ('-t', '-p'):\n"
" if i + 1 >= len(args):\n"
" sys.exit(1)\n"
" i += 2\n"
" elif a.startswith('-'):\n"
" sys.stderr.write(f'logger: unrecognized option: {a}\\n')\n"
" sys.exit(1)\n"
" else:\n"
" break\n"
"with log_path.open('a', encoding='utf-8') as f:\n"
" f.write(' '.join(args) + '\\n')\n",
"#!/bin/sh\n"
"orig=\"$*\"\n"
"while [ $# -gt 0 ]; do\n"
" case \"$1\" in\n"
" -s) shift ;;\n"
" -t|-p) [ $# -ge 2 ] || exit 1; shift 2 ;;\n"
" -*) echo \"logger: unrecognized option: $1\" >&2; exit 1 ;;\n"
" *) break ;;\n"
" esac\n"
"done\n"
"printf '%s\\n' \"$orig\" >> \"$MOCK_LOGGER_LOG\"\n",
)
write_exec(
@@ -251,7 +242,7 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
res, calls, elapsed, _ = run_filter(ctx, state_no_dnsmasq, ifn, act)
assert res.returncode == 0, f"{ifn} {act} failed: {res.stderr}"
assert calls == [], f"unexpected dnsmasq calls when not running: {calls}"
assert elapsed < 1.0, f"expected fast exit, took {elapsed:.2f}s"
assert elapsed < 3.0, f"expected fast exit, took {elapsed:.2f}s"
# 2. Wi-Fi early SLAAC RA before DHCPv4 completes, then dhcp4-change recovery
ctx["nm_resolv"].write_text("# Generated by NetworkManager\nnameserver 127.0.0.1\n", encoding="utf-8")
@@ -274,7 +265,7 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
}
res, calls, elapsed, _ = run_filter(ctx, state_slaac_race, "wlan0", "up")
assert res.returncode == 0, res.stderr
assert elapsed < 1.0, f"blocking sleep detected in 50-dns-filter.sh ({elapsed:.2f}s)"
assert elapsed < 3.0, f"blocking sleep detected in 50-dns-filter.sh ({elapsed:.2f}s)"
assert "SetFilterA b false" in calls, f"early SLAAC RA must not block IPv4 A records: {calls}"
state_dhcp4_done = {
@@ -293,7 +284,7 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
}
res, calls, elapsed, _ = run_filter(ctx, state_dhcp4_done, "wlan0", "dhcp4-change")
assert res.returncode == 0, res.stderr
assert elapsed < 1.0, f"dhcp4-change took too long ({elapsed:.2f}s)"
assert elapsed < 3.0, f"dhcp4-change took too long ({elapsed:.2f}s)"
assert calls == ["SetFilterA b false", "SetFilterAAAA b true", "ClearCache"], f"unexpected dhcp4-change calls: {calls}"
# 3. True dual-stack (2001:db8::2/64 GUA + IPv4)
@@ -393,6 +384,9 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
def test_static_invariants() -> None:
dns_filter = DNS_FILTER.read_text(encoding="utf-8")
assert "sleep " not in dns_filter, "50-dns-filter.sh must stay non-blocking"
dns_conf = DNS_CONF.read_text(encoding="utf-8")
assert "dns=dnsmasq" in dns_conf and "rc-manager=file" in dns_conf, dns_conf