Skip to content

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

Draft
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
sweep/cs42l-resume
Draft

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
sweep/cs42l-resume

Conversation

@RyanTheTide

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).

Assisted-by: LLM (Claude:Opus 5.5)

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