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.

🤖 Generated with Claude Code

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")
Assisted-by: LLM
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, as the
unplug path does.

Fixes: b912083 ("ASoC: cs42l84: Bring the codec back after a firmware sleep")
Assisted-by: LLM
Signed-off-by: Bartosz Nitka <niteria@gmail.com>
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.

1 participant