Repository navigation
ASoC: cs42l42/cs42l83: one resume policy, unmute after the host clocks the stream - #2300
Draft
RyanTheTide wants to merge 2 commits into
Draft
RyanTheTide wants to merge 2 commits into
RyanTheTide wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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"): onapple,t8103only, the unmute that ASoC's card resume sends at D2 was dropped, and playback prepare clearedSNDRV_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. Adefer_restoremodule 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
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 atriggercallback. 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.ASoC: cs42l83: restore the registers from the card's resume on every machine. The component suspend/resume hooks are installed for every CS42L83, anddefer_restoreis 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 ofcirrus,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
cs42l42.o,cs42l42-i2c.o,cs42l42-sdw.o,cs42l83-i2c.o. Zero warnings.snd-soc-cs42l42-teston 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):
Row commands (Neo)
Expected: aplay keeps running across all three sleeps with no
-ESTRPIPEre-prepare and no xrun storm (it resumes through RESUME);--test-positionprints 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> contentssucceeds). 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)