Skip to content

ASoC: cs42l84: write the registers back without leaving events latched - #2205

Open
niteria wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
niteria:j713/cs42l84-sleep
Open

niteria wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
niteria:j713/cs42l84-sleep

Conversation

@niteria

@niteria niteria commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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:

i2c-apple 3ad014000.i2c: Timeout, status 0x08010100
cs42l84 0-004b: not back after the sleep: writing the registers back failed: -62

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_STATUS reads 0xd right after TIP_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, and REMOTE_BUTTON_STATUS1 is read once after it. Then every other register the cache holds is written once, in address order. TSRS_PLUG_INT_STATUS is 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_CTL 0x1f) 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.

Deep sleep Codec restored, jack reported as it was
Jack empty 5 of 5
Headset in throughout 3 of 3, one with music playing across the sleep, which carried on after the wake
Plugged in during the sleep 1 of 1
Unplugged during the sleep 2 of 2

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_CTL reads 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-test 17/17 and snd-soc-cs42l84-sleep-test 2/2. The new suite fails on the old regcache_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.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

The write-back is correct. sound/soc/codecs/cs42l84.c:1319-1343 restores the plug-detection registers first, in cs42l84_setup_plug_detect()'s order (the KUnit suite keeps the list in step). It then restores every other cached, non-volatile register once, with TSRS_PLUG_INT_STATUS read after each write. It runs under irq_lock with the interrupt off. An error goes to err, which leaves the codec in reset with the cache marked dirty. The new cs42l84_revert_hs() on the empty-jack path (:1432) matches the interrupt thread's unplug handling and runs under the lock it expects.

  1. Both commits (6773976, 00f350b) carry Assisted-by: LLM. Keep only the human Signed-off-by in the commits. The PR body's last line should be Assisted-by: LLM (<Vendor>:<Model>), not "Generated with Claude Code".

Nit: regcache_sync_region() does not clear cache_dirty/no_sync_defaults the way regcache_sync() did, so the map stays marked dirty after a good resume. Nothing at this head calls regcache_sync() later, but a one-line comment at :1421 would keep a later full sync from undoing the ordering.

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 MISC_DET_CTL read back after each, plus 0 failed units, 0 AVC and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

  1. Both commits (6773976, 00f350b) still carry Assisted-by: LLM in their messages. Please drop that line from both commits and keep only the Signed-off-by. The code can stay as it is.

The write-back itself looks right. Plug detection is restored first in the order cs42l84_setup_plug_detect() writes it (the new KUnit suite checks the list against the function). Every other cached register is written once in address order, with TSRS_PLUG_INT_STATUS read after each write. All of this runs under irq_lock with the interrupt off, and a bus error leaves the codec in reset. cs42l84_revert_hs() on the empty-jack path matches the interrupt thread's unplug handling. Two optional nits. (a) regcache_sync_region() leaves cache_dirty set, so a short comment near the call would stop a later full regcache_sync() from undoing the ordering. (b) On an empty jack the write-back briefly turns the cached headset bias back on before the revert drops it. Seeding the revert values into the cache before the write-back, like the clock registers already are, would avoid that.

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 MISC_DET_CTL read back after each and no new kernel errors.

@niteria

niteria commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I dropped the Assisted-by line from both commits; the code is unchanged (a range-diff against 00f350b shows only that line). The description now ends with Assisted-by: LLM (Claude:Opus 5.5).

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.

@niteria

niteria commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

On "built in (not as a module)": every Aurora kernel config builds this driver as a module. CONFIG_SND_SOC_CS42L84=m, with CONFIG_SND_SOC_APPLE_MACAUDIO=m (which selects it), is set in linux's arch/arm64/configs/asahi.config and the tools/aurora-sep release16/18/19 recipes, and in fedora-aurora's packages/kernel-aurora/config, alarm-aurora's packages/linux-aurora/config and nixos-aurora's kernel/config. So the in-tree rows will use the module from a kernel built at this head, as all of these ship it.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 7952eb8: No blockers.

  1. Resolved: the Assisted-by: LLM line is gone from both commits (0bf366a, 7952eb8). Each now ends with only the human Signed-off-by, and the PR body's last line is Assisted-by: LLM (Claude:Opus 5.5). The new commits sit on the same parent (0abc2f3) and have the same trees as 6773976 and 00f350b, so the code is unchanged since the last review and still looks right.
  2. On the "built in" part of the row: you are right. CONFIG_SND_SOC_CS42L84=m is what every config ships, so a module from a kernel built at this head is the right thing to test. I withdraw the ask to build it in.

The two earlier nits (a comment near the regcache_sync_region() call about cache_dirty, and the headset bias briefly coming back on during the write-back before the revert on an empty jack) are still optional.

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 MISC_DET_CTL read back after each, 0 failed units, 0 AVC, 0 new kernel errors). Then the same 3 sleeps on one more cs42l84 Mac (J604 or J616s), which someone else on the team will need to run.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train note: #1895 (J604 cs42l84 init) landed in batch 1 (integration/aurora 606d37e) and conflicts with this branch in sound/soc/codecs/cs42l84.c. Our re-review of 7952eb8 is still no blockers. Please merge integration/aurora into the branch (or rebase onto a new one); it goes into a later batch once clean, green and with Dj's verdict.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Heads-up: at 7952eb8 this no longer merges cleanly into integration/aurora (now b241e35). It conflicts in sound/soc/codecs/cs42l84.c with 2f122e3 "ASoC: cs42l84: add ring-sense plug detection, selected from DT" (merged through #1895). Both touch the plug/resume paths. A rebase onto the current tip is needed before this can be merged or carried in a fleet kernel. The M3 Air 15 (J615, cs42l84) uses this change today, so I can run a J615 jack/sleep row on the rebased head.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@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>
@niteria

niteria commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto integration/aurora (d1b022dc34fb), resolving the #1895 (2f122e3977e4) conflict in cs42l84_resume():

  • Kept cs42l84_ring_detect_init() before cs42l84_restore_regs() and the post-restore REMOTE_BUTTON_STATUS1 read (08acd2e1e6d5).
  • Added cs42l84_revert_hs() to the ring-sense empty-jack branch as well as the tip-sense one (60fbca7a90d6).

KUnit (snd-soc-cs42l84*) passes 19/19 on UML; the non-ring_detect path (J713) is unchanged. Thanks for offering to run the J615 row!

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-checked 60fbca7: the conflict with #1895 is resolved in the right order (cs42l84_ring_detect_init() before the register restore, then the button-status read), and applying cs42l84_revert_hs() on the ring-sense empty-jack branch matches the tip-sense one, so a headset bias cached before suspend doesn't survive into an empty jack on either detection mode. The non-ring-detect path (J713) is unchanged. LGTM.

Assisted-by: LLM (Claude:Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants