Skip to content

ASoC: cs42l42/cs42l83: one resume policy, unmute after the host clocks the stream - #2300

Open
RyanTheTide wants to merge 5 commits into
mainfrom
sweep/cs42l-resume
Open

RyanTheTide wants to merge 5 commits into
mainfrom
sweep/cs42l-resume

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The CS42L42/CS42L83 codec driver had two resume policies, each selected by a SoC compatible.

  • sound/soc/codecs/cs42l42.c (cs42l42_resume_workaround_required(), from fa52480 "ASoC: cs42l42: require playback prepare for the base-M1 SCLK workaround"): on apple,t8103 only, the unmute that ASoC's card resume sends at D2 was dropped, and playback prepare cleared SNDRV_PCM_INFO_RESUME, so user space had to prepare the stream again after every sleep. Every other host kept the D2 unmute. That unmute moves the codec from its oscillator onto SCLK while the PCM is still suspended and the host may not clock the ASP yet. Without SCLK the codec drops off I2C (a197bcb); with the PLL lock check it stays muted and nothing unmutes it when the stream resumes.
  • sound/soc/codecs/cs42l83-i2c.c:252 (of_machine_is_compatible("apple,t8140"), from 489291a "ASoC: cs42l83: defer the register restore on T8140 only"): only T8140 restored the registers from ASoC's card resume; T8103 restored them in the device resume. A defer_restore module parameter switched between the two.

Neither difference comes from the hardware. The hazard comes from how the ASP is clocked (the codec is always the clock consumer), and the deferred restore uses only ASoC's own suspend/resume order.

Change

  1. ASoC: cs42l42: hold the resume unmute until the host clocks the stream. On every host that clocks the ASP, an unmute below D0 is held. The codec DAI gets a trigger callback. The codec DAI's trigger runs after the host DAI's trigger for START, RESUME and PAUSE_RELEASE, so SCLK runs by then. The trigger is atomic, so it schedules a work that does the clock switch and the unmute. Where the PLL is used, its lock is still the codec's own check that SCLK runs; a failed lock still leaves the codec on the oscillator. A prepare at D0, or a mute, replaces a held unmute. PCM RESUME is advertised again on every host. SoundWire is clocked by its bus and keeps its D2 unmute; its prepare is back to what it was before fa52480. The SoC gate and the RESUME clearing are removed.
  2. ASoC: cs42l83: restore the registers from the card's resume on every machine. The component suspend/resume hooks are installed for every CS42L83, and defer_restore is gone. When ASoC did not suspend the codec, the device resume still restores it, as before.

CS42L42/83 users reached: T8103 (J274, J293, J313, J456, J457; cirrus,cs42l83) and T8140 (J700; cirrus,cs42l83), all behind the MCA and macaudio. On these, the MCA enables the cluster clock in the back-end prepare and the SERDES in the front-end trigger, and macaudio triggers the front-end before the back-end, so the codec's trigger is the last step of a resume. Non-Apple I2S users of cirrus,cs42l42 (ACPI machines) get the same ordering: the unmute after a card resume waits for their stream's trigger instead of running at D2. Their unmute after prepare is unchanged. SoundWire users are unchanged.

The CS42L84 driver (T600x, T8112, T602x, T603x, T604x, T8122, T8132, T6050, T8142) has no SoC gate. It unmutes at D2 behind its PLL lock check. It is left alone here: open PR #2205 reworks its resume write-back.

Credit: Thomas Glanzmann found the D2 clock hazard and wrote the PLL lock rollback (a197bcb). Chris Kearney analysed RESUME and wrote the ALSA ioctl test harness that the new cases reuse (fa52480). Diljit Singh wrote the deferred restore (ecdc0b6).

Testing

  • Builds clean (arm64, LLVM, release config, W=1): cs42l42.o, cs42l42-i2c.o, cs42l42-sdw.o, cs42l83-i2c.o. Zero warnings.
  • KUnit snd-soc-cs42l42-test on UML: 19/19 pass, 0 skipped. With the D2 hold disabled (mutant), 8 fail: the four below-D0 cases and the four resume cases; SoundWire, capture and no-PLL cases still pass.
KUnit cases

New cases drive real ALSA RESUME and PREPARE ioctls through the ASoC trigger:

  • resume_unmutes_after_host_trigger: no clock writes at D2 or D0; after RESUME (no prepare) the codec switches to the PLL and unmutes.
  • resume_prepare_replaces_held_unmute: a prepare unmutes as usual; a later START does not switch again.
  • resume_mute_drops_held_unmute: a mute before the trigger drops the held unmute.
  • resume_without_host_clock: a host that does not clock leaves the codec on the oscillator, PLL stopped, headphone muted; a prepare recovers.
  • soundwire_unmutes_below_d0: SoundWire switches at D2.

Kept: unmute_below_d0_does_nothing (now also checks the held bit), capture_resume_remains_supported, and the PLL lock/timeout/mute cases. Removed with the gate: the admission matrix, the RESUME refusal cases, and the per-stream RESUME capability case.

Still to run

Only the Neo (J700, T8140) in the lab has this codec. M1 Pro (J316s), M2 (J413) and J616s use CS42L84, which this does not touch; one boot each to confirm no change in dmesg | grep -i cs42l. No base M1 is in the lab; T8103 is argued from the shared code path above.

Neo rows, silent only (digital zeros on the headphone jack PCM, jack volume at minimum, never the speaker PCM):

  • hardware rows: pending (lead fills in)
Row commands (Neo)
# jack PCM: the macaudio card's jack device; check with aplay -l
amixer -c <card> sset 'Jack Mixer' 0               # jack codec volume at minimum (control 'Jack Mixer Volume')
aplay -D hw:<card>,<jack dev> -f S16_LE -c 2 -r 48000 --test-position /dev/zero &
for i in 1 2 3; do rtcwake -d rtc0 -m freeze -s 15; sleep 5; done   # Neo wake RTC is rtc0
kill %1
dmesg | grep -iE 'cs42l|PLL failed|unmute after resume|mca' 

Expected: aplay keeps running across all three sleeps with no -ESTRPIPE re-prepare and no xrun storm (it resumes through RESUME); --test-position prints no position errors after each wake; no "PLL failed to lock" and no "unmute after resume failed"; the codec still answers on I2C after each wake (jack plug state reported in /proc/asound/card*/ controls, amixer -c <card> contents succeeds). If debugfs regmap is present: compare /sys/kernel/debug/regmap/0-0048/registers (i2c0, codec@48) (cached) with a readback before and after one sleep for the clock registers 0x1107 (OSC_SWITCH = 1 while playing) and 0x1501 (PLL start).

ASoC's card resume unmutes the playback DAIs that were active at suspend
while the card is at D2 and the PCM is still suspended. The CS42L42/83
ASP is always a clock consumer, and the unmute moves the codec from its
internal oscillator onto SCLK, through the PLL where the rate needs it.
The host need not clock the ASP at that point. Leaving the oscillator
without SCLK takes the codec off the I2C bus, see commit a197bcb
("ASoC: cs42l42: keep the codec on the oscillator until SCLK runs").
With the PLL lock check that commit added, the codec stays on the
oscillator and muted instead, and nothing unmutes it when the stream
resumes.

Commit fa52480 ("ASoC: cs42l42: require playback prepare for the
base-M1 SCLK workaround") handled this on base M1 (apple,t8103) only. It
skipped the D2 unmute there and cleared SNDRV_PCM_INFO_RESUME from
playback, so user space had to prepare the stream again. Every other host kept the D2
unmute, including the T8140 with the same CS42L83 behind the same MCA
host. The hazard comes from how the ASP is clocked, not from the SoC.

Hold the D2 unmute on every host that clocks the ASP. The codec DAI's
trigger runs after the host DAI's trigger for START, RESUME and
PAUSE_RELEASE, so SCLK runs by then (on Apple machines the MCA enables
the cluster clock in the back-end prepare and the SERDES in the
front-end trigger, which runs before the back-end's). The trigger is
atomic and the switch sleeps on I2C, so the trigger schedules a work
that does the clock switch and the unmute. Where the PLL is used, its
lock is still the codec's own check that SCLK runs, and a failed lock
still leaves the codec on the oscillator. A prepare at D0 or a mute
replaces a held unmute. PCM RESUME is advertised again on every host, so
a resumed stream plays without a new prepare.

SoundWire is clocked by its bus and keeps the D2 unmute. Its prepare is
back to what it was before that commit.

The KUnit cases drive real RESUME and PREPARE ioctls through the ASoC
trigger: RESUME without a prepare unmutes after the host trigger, a
prepare replaces the held unmute, a mute drops it, a host that does not
clock leaves the codec on the oscillator and muted, and SoundWire
unmutes at D2. The admission matrix and the RESUME refusal cases go with
the gate.

The D2 clock hazard and the PLL lock rollback were found by Thomas
Glanzmann; the RESUME analysis and the ALSA ioctl test harness are Chris
Kearney's.

Fixes: fa52480 ("ASoC: cs42l42: require playback prepare for the base-M1 SCLK workaround")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…machine

Commit ecdc0b6 ("ASoC: cs42l83: restore the registers from the
card's resume") moved the register restore after a sleep (about 100 ms
of I2C writes) from the device's resume into ASoC's deferred card
resume, which keeps user space off the card until it has run. Commit
489291a ("ASoC: cs42l83: defer the register restore on T8140
only") then limited that to T8140, because it was measured on the J700
only.

Nothing in the mechanism depends on the SoC: ASoC's component suspend
and resume, the powered completion and the restore lock behave the same
on every machine. The CS42L83 is the same part on the T8103 machines
(J274, J293, J313, J456, J457) and on the J700, on the same I2C and MCA
host blocks. Install the component hooks for every CS42L83, and drop the
defer_restore module parameter, so the codec has one restore policy.

When ASoC did not suspend the codec (a path kept powered over the
sleep), the device's resume still restores the registers itself.

Fixes: 489291a ("ASoC: cs42l83: defer the register restore on T8140 only")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Looks good; approve once the Neo resume row (and a T8103 owner row) is on the head.

Checked at d57449c. Holding the D2 unmute until the codec DAI trigger is sound on the MCA. The codec DAI trigger runs after the CPU DAIs (cpu dais come first in for_each_rtd_dais). The MCA keeps its cluster clock from BE prepare to BE shutdown (sound/soc/apple/mca.c:794-830, :879-905) and re-enables the SERDES in the FE trigger (:254-268), so SCLK is running when sound/soc/codecs/cs42l42.c:1242 fires. stream_lock serialises mute_stream() with the work, a mute or a D0 unmute clears the held bit, and the work is cancelled in suspend (:2634) and remove (:2965). The cs42l83 change only widens hooks that already run on the J700, and the module parameter goes away with it. CI is green and the PR merges cleanly.

  1. sound/soc/codecs/cs42l42.c:1157-1170: the work calls test_and_clear_bit() on the held unmute before cs42l42_unmute_locked(). If the PLL then fails to lock, the unmute is gone for good. RESUME is now advertised, so user space will not prepare again, and the headphone stays muted until the stream is closed. On T8103 that is a step back from today's forced re-prepare. Fix: on failure, set the resume_unmute bit again so the next START/RESUME/PAUSE_RELEASE retries, and keep the dev_warn.
  2. This brings back SNDRV_PCM_INFO_RESUME on T8103, the one host where fa52480 removed it on purpose, and the only evidence is KUnit. The ordering argument above holds for the MCA. The PR still needs one real resume on the J700 (the only lab Mac with this codec) before it merges. A base-M1 owner run should follow before this goes into a release.
  3. Nit: the body's "hardware rows: pending (lead fills in)" is a placeholder. Replace it with results or with "to run".

HW row: Neo J700 on head, silent jack row as written in the PR (zeros, jack at minimum, never the speaker PCM). aplay keeps running across 3x s2idle via RESUME, with no re-prepare, no "PLL failed to lock" and no "unmute after resume failed". The codec answers on I2C after each wake, and cs42l42 reg 0x1107 reads back OSC_SWITCH=1 while playing. 0 AVC, 0 failed units, no new kernel errors. Then the same on a base-M1 (J293/J313) owner Mac.

Assisted-by: LLM (Claude:Opus 5.5)

The resume unmute work cleared the held unmute with test_and_clear_bit()
before cs42l42_unmute_locked() had run. When the PLL then failed to lock,
the codec rightly stayed on the oscillator, but the pending unmute was
gone. PCM RESUME is advertised, so user space does not prepare the stream
again, and nothing else unmutes it: the headphone stayed muted until the
stream was closed.

Only clear the held unmute once the unmute has been applied. On failure,
keep it held and drop the stream's "clocked" mark, so the next START,
RESUME or PAUSE_RELEASE trigger from the host schedules the work again
and retries the switch with SCLK running. A mute or a prepare at D0 still
replaces the held unmute as before. The dev_warn stays.

Extend the KUnit resume-without-host-clock case to check that the unmute
is still held after the failed lock, and add a case where the next START
from a clocking host switches the codec to the PLL and unmutes it without
a new prepare.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Added bf8ba56: keep the held resume unmute when the PLL fails to lock (with PCM RESUME there may be no new prepare, so the headphone stayed muted). KUnit: cs42l42 suite 20/20 incl. a new 'next START from a clocking host unmutes' case. Still owed: J700 resume row (headphone, s2idle wake without a new prepare).

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Row: Neo (J700, T8140, cs42l83), silent. Combined one-shot kernel 7.3.0-aurora-dsw2 (main 2a173ca + this PR's head bf8ba56 + 14 other drafts; none of the others touches sound/soc/codecs/). Nothing was played; the jack had nothing plugged in.

  • snd_soc_cs42l83_i2c parameters: edge kernel defer_restore; with this PR none (removed as intended).
  • amixer -c 1 contents before and after one 15 s s2idle (rtc0, rc 0): every cs42l83/macaudio control is identical after the wake, same as on the edge kernel. The only changed line is the read-only volatile Speaker Protection Sleeps counter (0 to 1), which counts that sleep.
  • Boot: 0 failed units, Enforcing, 0 WARN/BUG; the only error-level line is the baseline dwc3 genpd_prepare -11 from the s2idle. The Neo went back to its saved edge kernel, verified.
    Still to run before undraft: an actual jack resume with headphones plugged in (unmute held until the host clocks run), and T8103 (no lab Mac). The PR stays a draft until then, and while the CI queue is saturated.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Updated: merged main @f02bd68a08cb (110e8c9, clean merge; main's only nearby change is the cs42l84 write-back fix, a different driver). No code change beyond the merge; the review's code points were already addressed (bf8ba56 keeps the held unmute when the PLL fails to lock).

Local build on the merged head: aurora_defconfig (RUST off), LLVM=1 ARCH=arm64 W=1: cs42l42.o, cs42l42-i2c.o, cs42l42-sdw.o, cs42l42-test.o and cs42l83-i2c.o build with no warnings. The removed defer_restore module parameter matches the no-module-parameter rule.

Still needed (queued in HWROWS): the Neo row with headphones plugged in (s2idle mid-stream, audio back without a new prepare), and a T8103 owner row (no M1 in the lab).

@RyanTheTide
RyanTheTide marked this pull request as ready for review December 5, 2026 01:04
@RyanTheTide
RyanTheTide requested review from a team as code owners December 5, 2026 01:04
@github-actions github-actions Bot added area:audio Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) and removed ci-failing A check failed at the PR head (bot) labels Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Merge readiness at c1d351d2: not ready yet

Check Detail
CI at head no failing: KUnit dcp-topology asahi
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes no requested by aurora-silicon-review
Hardware row at head no no line with the head SHA c1d351d2, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:audio

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware row at exact head c1d351d26368 on the Neo (J700, cs42l83): PARTIAL (silent only).

  • No headphones plugged in (Headphone Jack off) and no playback allowed on this run, so the mid-stream resume was not run.
  • modinfo snd_soc_cs42l83_i2c has no parameters (no defer_restore); 0 PLL failed to lock / cs42l83 I2C errors over 4 s2idle + 3 deep sleeps; amixer contents of the codec card identical before/after 3 sleeps except the read-only Speaker Protection Sleeps counter (0 -> 3).
  • Still needed: the headphone playback-across-sleep row and a T8103 row.

How: one combined test kernel for eight PRs, not this PR alone. Kernel 7.3.0-aurora-ci = main d0684a06 + merge commits of linux#2712 b6887f88, #2300 c1d351d2, #1990 83ef8b0f, #3742 798c2cde, #2350 5f18911e, #2398 75b30c6c, #1814 775f31d2, #2402 07660961 (all merged clean, test commit 03a571ef, cloud build https://github.com/aurora-silicon/linux/actions/runs/47474056726). Booted as a one-shot on the lab Neo (J700, T8140, 26.6.2 stub) with this kernel's own t8140-j700.dtb in a trial Stage 2 (live aura 1.0.0b19 + U-Boot, only the DTB swapped), default cmdline, silent (no audio playback). Boot health on the test kernel: 0 error-level kernel lines, 0 AVC, 0 failed units. Saved default restored after.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at c1d351d

Failure: In sound/soc/codecs/cs42l42.c, the deferred worker checks resume_unmute_clocked once, then polls for lock and switches to SCLK. STOP, SUSPEND or PAUSE_PUSH can clear the bit and stop the MCA serializer after the worker has observed PLL lock, while its transfer to SCLK and headphone unmute are still outstanding. The worker's mutex does not cover the atomic trigger or keep the host clock running. I replayed the exact worker, unmute and trigger with a fake codec under GCC and Clang. Stopping before the worker suppressed the writes. Stopping immediately after the successful lock observation still switched to the absent clock, unmuted, and consumed the pending bit. Make the host clock lifetime cover the final switch or order stop and pause against completion of the sleepable transition. Include a fixture that stops the clock after the worker has started.

Checked: the earlier lock-timeout fix retains the pending unmute, the uninterrupted host control passed, and the SoundWire prepare path still performs its PLL setup. The exact Neo receipt is silent and partial. It does not exercise that resumed-stream transition.

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) labels Dec 5, 2026

This branch has not been deployed

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

Labels

area:audio Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant