Repository navigation
ASoC: cs42l84: write the registers back without leaving events latched - #2205
Conversation
984b7c8 to
00f350b
Compare
|
Blockers: 1. The write-back is correct. sound/soc/codecs/cs42l84.c:1319-1343 restores the plug-detection registers first, in
Nit: HW row: the resume path is shared by every CS42L84 Mac that sleeps via firmware, so add one more besides the J713 (J604 or J616s). Run 3 deep sleeps (empty, headset in, unplugged during sleep) on this head built in, not as an out-of-tree module, with jack state and Assisted-by: LLM (Claude:Opus 5.5) |
|
Blockers: 1.
The write-back itself looks right. Plug detection is restored first in the order Rows still needed: this head built in (not as a module), plus one more cs42l84 Mac besides the J713 (J604 or J616s). On each, 3 firmware deep sleeps (jack empty, headset in, unplugged during the sleep), with the jack state and |
00f350b to
7952eb8
Compare
|
Thanks. I dropped the The Air runs so far used this exact code as an out-of-tree module on an a7dd26e kernel; I'll add in-tree rows when the Air next gets a kernel with this head. I don't have a J604 or J616s. |
|
On "built in (not as a module)": every Aurora kernel config builds this driver as a module. |
|
Re-review of 7952eb8: No blockers.
The two earlier nits (a comment near the HW row: the J713 rows on a kernel built at this head (3 firmware deep sleeps: jack empty, headset in, unplugged during the sleep, with jack state and Assisted-by: LLM (Claude:Opus 5.5) |
|
Merge-train note: #1895 (J604 cs42l84 init) landed in batch 1 (integration/aurora 606d37e) and conflicts with this branch in |
|
Heads-up: at 7952eb8 this no longer merges cleanly into |
|
@niteria, a tidy-up pass over the open PRs here. These of yours need something:
If any of these are no longer needed, closing them helps; otherwise a merge or rebase onto integration/aurora is usually all they need. Thanks! |
After a firmware sleep, the codec comes out of reset and the resume writes its cached registers back with regcache_sync(), in address order, with the interrupt still off. Turning tip and ring sensing on latches plug events at once, as do some later writes (MSM_BLOCK_EN3 among them), and the remote button sources come up latched (0x60 in REMOTE_BUTTON_STATUS1). Nothing reads them, and the codec stops answering the bus a write or two later: the write times out (-ETIME), the resume fails, and the jack stays dead until the driver is bound again. On the MacBook Air (M4, J713) this happened on every deep sleep. Write plug detection back first, in the order the probe sets it up, then every other register the cache holds, once each, in address order, and read the plug interrupt status after each write to clear what it latched, as the interrupt thread does. The remote button status is read once, after plug detection. A KUnit suite checks that order, that the plug detection list matches what the probe writes, and that a codec that stops answering ends the write-back with the error. Fixes: b912083 ("ASoC: cs42l84: Bring the codec back after a firmware sleep") Signed-off-by: Bartosz Nitka <niteria@gmail.com>
A headset unplugged during a firmware sleep leaves its bias on. The resume writes the cache back, the 2.7 V mic bias included, finds the jack empty and reports it, but unlike the interrupt thread's unplug path it does not call cs42l84_revert_hs(). The bias stays powered, disconnected from the jack, until the next plug. Revert the headset setup when the jack is empty after the wake, on both the tip-sense and ring-sense paths, as the unplug paths do. Fixes: b912083 ("ASoC: cs42l84: Bring the codec back after a firmware sleep") Fixes: 2f122e3 ("ASoC: cs42l84: add ring-sense plug detection, selected from DT") Signed-off-by: Bartosz Nitka <niteria@gmail.com>
7952eb8 to
60fbca7
Compare
|
Rebased onto
KUnit ( |
|
Re-checked 60fbca7: the conflict with #1895 is resolved in the right order ( Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review on live head 60fbca7a90d63d72f3fcda1c0ebcab8f62969275 (base integration/aurora, mergeable CLEAN, all 7 CI checks green).
Verdict: REQUEST_CHANGES — code (§1–§4, §6) is clean with no code or attribution blockers; blocked solely on §5 hardware evidence for the rebased head 60fbca7a90d6.
Checklist audit (§1–§6)
- §1 No model gating: PASS (code). No chip/SoC/board/firmware gates.
cs42l84_restore_regs()andcs42l84_revert_hs()apply uniformly across both tip-sense and DT-selectedcirrus,ring-sense-detectpaths. Multi-Mac hardware coverage is tracked under §5 below. - §2 Production-ready, no hacks: PASS. Verified
sound/soc/codecs/cs42l84.c,cs42l84.h,cs42l84-test.c, andKconfig:- Locking & IRQ safety:
cs42l84_suspend()disables the IRQ and cancelsremote_poll_workbefore takingirq_lockand asserting reset.cs42l84_resume()runs reset release, ID read,cs42l84_restore_regs(), plug redetection, andcs42l84_revert_hs()/cs42l84_detect_hs()underirq_lockwith the IRQ still disabled, re-enabling it only afterirq_lockis released. No IRQ race window. - Regmap / cache / volatile semantics:
cs42l84_plug_detect_regs[]matchescs42l84_setup_plug_detect()(guarded bysnd-soc-cs42l84-sleep-test).TSRS_PLUG_INT_STATUSandREMOTE_BUTTON_STATUS1are volatile so every clear-read hits I2C.regcache_reg_cached()skips uncached and volatile registers. Any bus error aborts immediately and jumps toerr:(leavingcache_only=true, cache dirty, codec in reset, IRQ disabled,sleep_reset=true). - Buildability:
DEFINE_SIMPLE_DEV_PM_OPSavoids unused-function warnings underCONFIG_PM_SLEEP=n; modularCONFIG_SND_SOC_CS42L84=mandCONFIG_SND_SOC_CS42L84_TEST=y/nare clean. - Non-blocking notes (no code change required):
regcache_sync_region()leavesmap->cache_dirtyset. Nothing incs42l84.cor ASoC core callsregcache_sync()on this regmap today, so it is safe, though a one-line comment at the call site would guard future changes.- On
cirrus,ring-sense-detecthardware (J604),cs42l84_ring_detect_init()runs beforecs42l84_restore_regs()and writesTIP_SENSE_CTL2,0x1471,0x1478,0x1480without intermediateTSRS_PLUG_INT_STATUSreads;cs42l84_restore_regs()then re-writes those cached registers with per-write status reads, followed by the post-restoreREMOTE_BUTTON_STATUS1read. This rebased interaction has not yet been exercised on J604 hardware (see §5).
- Locking & IRQ safety:
- §3 Safety: PASS. No hardcoded safety limits/thresholds. Commit
60fbca7a90d6improves safety by powering down the 2.7 V mic bias (MISC_DET_CTL0x1f→0x03) on unplug-during-sleep across both tip-sense and ring-sense paths. - §4 Clean-room & attribution: PASS. Clean-room. Both commits (
08acd2e1e6d5,60fbca7a90d6) carry human author/committer and humanSigned-off-by:only (zero AI trailers in commits). PR body carriesAssisted-by:. - §5 Evidence: BLOCKER.
- Existing evidence: J713 (MacBook Air M4) deep-sleep results in the PR body (5 empty, 3 headset-in, 1 plug-in, 2 unplug; playback checked on 5;
MISC_DET_CTL0x03checked on unplug) were collected on an olderintegration/auroraa7dd26e6kernel using an out-of-treesnd-soc-cs42l84.ko(with 7 of those 11 runs predating the bias-revert commit), prior to the rebase ontod1b022dc34fb(#1895/2f122e3977e4). On live head60fbca7a90d6, only UML KUnit (snd-soc-cs42l84*19/19) and CI (7/7 green; note CIkunitruns SEP suites only) have run. No post-sleep headset capture check and no §5 regression tuple (0 SELinux denials, 0 failed units, 0 new kernel errors) have been posted.
- Existing evidence: J713 (MacBook Air M4) deep-sleep results in the PR body (5 empty, 3 headset-in, 1 plug-in, 2 unplug; playback checked on 5;
- §6 Naming: PASS.
Exact §5 hardware rows still needed for APPROVE / MERGETRAIN-LINUX4
- J713 (MacBook Air M4) booted on a kernel + in-tree
snd-soc-cs42l84.kobuilt from live head60fbca7a90d6(default kernel cmdline):- Firmware deep-sleep suspend/resume covering all 4 jack states, reporting exact kernel/build SHA, jack state,
MISC_DET_CTLreadback, and 0-62/-ETIMEerrors on each:- Jack empty across deep sleep
- Headset (with mic) plugged in across deep sleep — verify both playback and headset mic capture after wake
- Headset plugged in during sleep — verify jack detection + playback/capture after wake
- Headset unplugged during sleep — verify empty jack report, speaker playback, and
MISC_DET_CTL=0x03(bias off)
- Live jack plug/unplug cycle after wake (confirms IRQ re-enabled cleanly with no latched-event lockup)
- §5 regression tuple on that boot:
0 SELinux denials, 0 failed units, 0 new kernel errors
- Firmware deep-sleep suspend/resume covering all 4 jack states, reporting exact kernel/build SHA, jack state,
- One additional CS42L84 Mac on
60fbca7a90d6(cross-Mac coverage per §1/§5; can be run by another team member):- J604 (preferred, exercises the newly rebased
cirrus,ring-sense-detectresume pathcs42l84_ring_detect_init()→cs42l84_restore_regs()→REMOTE_BUTTON_STATUS1read →cs42l84_revert_hs()) and/or J615 (tip-sense, as offered earlier in the thread):- 3 firmware deep sleeps (jack empty, headset in, unplugged during sleep) with jack state +
MISC_DET_CTLreadback, post-wake playback/capture + plug/unplug check, and0 SELinux denials, 0 failed units, 0 new kernel errors.
- 3 firmware deep sleeps (jack empty, headset in, unplugged during sleep) with jack state +
- J604 (preferred, exercises the newly rebased
Once those rows are posted on 60fbca7a90d6, this is ready for APPROVE and MERGETRAIN-LINUX4.
|
J713 (MacBook Air 13" M4, macOS 26.6.2 firmware) §5 hardware verification on live head
4 firmware deep sleeps (
|
| # | Case | Before | After | Audio / Mic check | Codec / I2C -62/-ETIME |
|---|---|---|---|---|---|
| 1 | Empty jack across deep sleep (0 -> 1) |
hp=off mic=off, devid=0x42, MISC_DET_CTL=0x03 (bias 0 V) |
hp=off mic=off, devid=0x42, MISC_DET_CTL=0x03 (bias 0 V) |
— | 0 |
| 2 | Headset (with mic) plugged in during sleep (1 -> 2) |
hp=off mic=off, MISC_DET_CTL=0x03 (0 V) |
hp=on mic=on, devid=0x42, MISC_DET_CTL=0x1f (bias 2.7 V) |
PipeWire headset playback (alsa_output.platform-sound-jack.HiFi__Headphones__sink) OK; headset mic capture (alsa_input.platform-sound-jack.HiFi__Headset__source) OK (55,296 frames @ 48 kHz, peak 2036, RMS 70.3, 53,511 non-zero) |
0 |
| 3 | Headset in across deep sleep (2 -> 3) |
hp=on mic=on, MISC_DET_CTL=0x1f (2.7 V) |
hp=on mic=on, devid=0x42, MISC_DET_CTL=0x1f (bias 2.7 V) |
PipeWire headset playback OK; headset mic capture OK (54,272 frames @ 48 kHz, peak 3664, RMS 112.3, 52,560 non-zero) | 0 |
| 4 | Headset unplugged during sleep (3 -> 4) |
hp=on mic=on, MISC_DET_CTL=0x1f (2.7 V) |
hp=off mic=off, devid=0x42, MISC_DET_CTL=0x03 (bias 0 V) |
Protected speaker playback via PipeWire + speakerguardd-v2 (sgv2.voicing.j713) OK |
0 |
| 5 | Live plug-in + unplug while awake after wake 4 | hp=off mic=off, MISC_DET_CTL=0x03 |
Plug: hp=on mic=on, MISC_DET_CTL=0x1f (2.7 V) → Unplug: hp=off mic=off, MISC_DET_CTL=0x03 (0 V) |
— | 0 |
§5 regression tuple (same boot)
- SELinux denials:
0(NixOS; no SELinux present) - Failed systemd units:
0(systemctl --failedempty at preflight and after the 4 sleeps + live cycle) - New kernel errors:
0cs42l84/i2c-apple/ASoC/ audio errors across the boot and all 4 deep sleeps + live plug/unplug cycle. (Unrelated baseline errors observed on this NixOS/26.6.2 Stage 2 setup:asixUSB Ethernet MII teardown messages on sleep,apple-ave-EINVALfirmware segment size mismatch at boot,apple-sleepnon-blocking warningsdma-controller isn't bound/isp_sys is on: 0x23ff, and an unrelateddwc3-apple-95device-mode abort on USB-C port 1 before that cable was unplugged.)
Still needed from another team member for the second-board row: J604 (ring-sense path) and/or J615 on 60fbca7a90d6 (@RyanTheTide / @DjDeveloperr).
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 60fbca7a90d6
Blockers: none.
Checked: no Apple material, no gates, no hardcoded limits. Plug detection is written back first, in probe's order, with the latched status read after each write; the rebase keeps cs42l84_ring_detect_init() before the restore. Your J713 row at this head covers four deep sleeps (empty, plug-in, headset across sleep, unplug), playback and mic capture, no -62 errors and 0 failed units, with speaker playback through speakerguardd. KUnit 19/19, CI green. This replaces my earlier review: that row was the only open item, and it's in.
Evidence
Read both commits (cs42l84.c, the KUnit suite, Kconfig) and the J713 row from 11-23. A J604 or J615 run, which uses the ring-sense path, is a check after the merge. Nit: regcache_sync_region() leaves cache_dirty set; a comment at the call site would help whoever touches it next.
Superseded by the review at 60fbca7
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
After a deep sleep, the cs42l84 headphone codec stops answering the bus while its registers are written back, so the jack stays dead until the driver is bound again. On the MacBook Air (M4, J713) this happened on every deep sleep:
Cause
The resume (b912083) releases the reset, checks the device ID, and writes the cache back with
regcache_sync(), in address order, with the interrupt still off. Turning tip and ring sensing on latches plug events at once (TSRS_PLUG_INT_STATUSreads 0xd right afterTIP_SENSE_CTL2), some later writes latch more (MSM_BLOCK_EN3), and the remote button sources come up latched (REMOTE_BUTTON_STATUS1= 0x60, as #1895 found on the J604). Nothing reads them, and a write or two later the codec stops answering. Which register fails moves with the order; the latched events are what it follows. A rebind (probe's sequence, with the interrupt live) works at any time after the wake.Change
Two fixes to the resume from b912083.
Write the registers back without leaving events latched. Plug detection is written back first, in the order
cs42l84_setup_plug_detect()sets it up, andREMOTE_BUTTON_STATUS1is read once after it. Then every other register the cache holds is written once, in address order.TSRS_PLUG_INT_STATUSis read after every write to clear what it latched, as the interrupt thread does.A KUnit suite,
snd-soc-cs42l84-sleep-test, runs the write-back on a regmap with the driver's cache and volatile registers. It checks that order, that the plug detection list matches what the probe writes, and that a codec that stops answering ends the write-back with the error.Power the headset bias down after an unplug in a sleep. When a headset was unplugged during the sleep, the resume reported the empty jack but, unlike the interrupt thread's unplug path, did not call
cs42l84_revert_hs(). The headset's 2.7 V mic bias (MISC_DET_CTL0x1f) stayed on, disconnected from the jack, until the next plug. The resume now reverts the headset setup as the unplug path does.Tested
J713 (MacBook Air M4), integration/aurora a7dd26e with this as an out-of-tree snd-soc-cs42l84.ko (the cs42l84 files are unchanged on integration since), the built-in 3.5 mm jack and a headset whose mic the codec detects, so the cache holds the mic bias on across a sleep with it plugged in. Woken by the RTC (rtc1) or the power key.
Before: every deep sleep failed to restore the codec (-62), and the jack stayed dead until a rebind.
Playback was checked by ear after five of them: the headset after the music, idle and plug-in sleeps, and the speakers after both unplugs. After an unplug in a sleep
MISC_DET_CTLreads 0x03 (bias off), where it read 0x1f without the bias fix. The headset-in sleeps, three of the empty ones and one unplug ran without the bias fix, which only changes what the resume does when it finds the jack empty.KUnit on UML:
snd-soc-cs42l84-test17/17 andsnd-soc-cs42l84-sleep-test2/2. The new suite fails on the oldregcache_sync()write-back and on five other mutations: plug detection written a second time, no status read, the list out of step with the probe, no button read, errors ignored.Host tests (tools/asahi/run-host-tests.py, full run): 427/427 on each commit and on the base. It merges cleanly with #2112 (jack reporting at attach and after a sleep that keeps the codec powered), which covers a different case, and with #1895.