Skip to content

ASoC: macaudio/tas2764: speakers safe and quiet across sleep and protection withdrawals - #1077

Merged
RyanTheTide merged 2 commits into
integration/aurorafrom
kfix/spk-sleep-safe
Nov 7, 2026
Merged

RyanTheTide merged 2 commits into
integration/aurorafrom
kfix/spk-sleep-safe

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Kernel half of the speakerguardd v2 (Plan B) ship blockers: speakers broken after system sleep on the J316 (M1 Pro), J413 (M2) and J616s, alsactl errors at boot, and a click when protection is withdrawn.

The stuck speaker buses after a resume (tas2764)

Unable to sync registers 0xb3-0x313. -62, i2c-apple Timeout, status 0x10850140 and Bus is still stuck on every speaker bus, at the first sleep after a boot. Cause: a regmap debugfs dump of the amps (the speaker wiring self-check reads /sys/kernel/debug/regmap/<amp>/registers) leaves every page of the amp in the regmap cache; the resume's regcache_sync() then raw-writes one block from the page-1 quirk register 0xb3 through page 6, across reserved pages. The amp never completes it and the controller stays in its transaction. Reproduced on demand on the M2 with fleet18 (one freeze after a boot whose self-check ran).
Fix: a writeable_reg for the TAS2764/SN012776 regmap that lists the registers the driver writes, so a cache sync writes back only those. KUnit checks that every register the driver and its quirk sequences write is still writeable, and that the reserved pages are not.

Protection withdrawals (macaudio)

  • The floor after a withdrawal writes the amps from inside the kernel (the owner's file closing, the lease worker, a release). Unlike a userspace control write, it didn't wait for the card. It now closes the start gate and stops the streams at once, as before, then waits for the card to be back at D0 before it writes any amp. A grant needs D0.
  • "Speaker Protection" and "Speaker Protection Crossover" are INACTIVE (and VOLATILE), so alsactl's restore and mixers leave them alone. Only their owner may write them, so the boot restore used to fail with Cannot write control ... Invalid argument / Operation not permitted (2 lines on every M2 boot). Owner writes are unchanged.
  • A release, the owner gone or a new owner ramps the amps' digital gain down under the playing stream before it stops: 11 steps from -2 to -50 dB, at least 0.5 ms apart, at most 10 ms and never past the lease's end. Before this, the stop was a click (a J616s kill test caught one 100 ms block at -0.4 dBFS, above the music's -3.1 dBFS peak). A lapsed lease, system sleep, a failure and the J700's software gain still withdraw at once.
  • Refused speaker starts stay out of the kernel log (counted, one summary line at the next grant), as before. The "snd_pcm_start: Operation not permitted" storm across a sleep comes from PipeWire retrying; speakerguardd#84/Moved · 🧩 T6034 · M3 Max, 14-core — board index #85 close the PCMs before sleep.

Not in this PR

MCA loses its cluster registers across system sleep when a speaker PCM stays open through it (with the PCMs closed before sleep, which speakerguardd now does, nothing is in use). Restoring them at resume hangs the J316, so that change is still WIP on kfix/mca-sleep-restore-wip and needs to go through the clock-then-domain order of the prepare path.

Testing

  • KUnit (arm64, qemu): apple-* 53/53 on the final tree (protection suite incl. 6 new cases: INACTIVE access, ramp shape and <20 ms withdrawal, no ramp past the lease / on hard withdrawals / on the J700, floor waits for D0 with the gate closed, grant needs D0; the known load-sensitive macaudio_spk_timer_beats_a_fifo_spinner failed once on a loaded box, as before this series); tas2764 11/11 (2 new).
  • W=1: macaudio.o, tas2764.o: 0 warnings. checkpatch --strict: clean.
  • J413 (M2), test kernel 7.3.0-aurora-fleet18k1 (integration 068dfce + this series), fresh boot with the wiring self-check's regmap dump, speakerguardd v2 alpha.1 403b362 (1 s watchdog, PCMs held open), s2idle (pm_test=platform) x6: 6/6 regranted (0.8-1.5 s), 0 stuck buses, 0 I2C timeouts, 0 sync failures, 0 amp faults, 0 floor failures, 0 AVC (SELinux enforcing). Same Mac on fleet18 (without this series): buses stuck at the first freeze.
  • M2 boot: 0 alsactl 'Cannot write control' lines (fleet18: 2 per boot).
  • J616s, same test kernel, fresh boot with the self-check's dump, v2 alpha.1 (1 s watchdog, PCMs held open), s2idle x6: 6/6 regranted (0.5-0.9 s), 0 stuck buses, 0 I2C timeouts, 0 sync failures, 0 amp faults, 0 AVC. On fleet18 the same conditions stuck both speaker buses at cycle 1. Boot: 0 alsactl errors. Silent kill -9 of the supervisor x3 (the ramped withdrawal path, no playback): withdrawn, regranted in 0.8 s, 0 faults, all six Amp Fault Status 0. (No audible click measurement: audio is off on the Macs for now; the ramp is covered by KUnit.)

🤖 Generated with Claude Code

…and click-free

Three problems with how speaker protection is withdrawn, seen with the
protection supervisor running across system sleep and in the audible
kill test:

1. The floor after a withdrawal writes the amps through their controls'
   put callbacks from inside the kernel: from the owner's file closing,
   the lease timer's worker or a release. A write from userspace waits
   for the card to be powered (snd_power_ref_and_wait() in the control
   ioctls); these do not. An owner that dies while the card resumes (a
   supervisor killed by its watchdog at thaw) then writes the amps
   while their codecs sync their registers and ASoC brings the streams
   back. Wait for the card to reach D0 before any amp write of the
   floor, after closing the start gate and queueing the stream stop,
   which happen at once as before. A grant on a card that is not
   powered returns -EBUSY. (A card going away still gets the floor.)

2. alsactl restore writes every writable control it saved, and at boot
   fails on "Speaker Protection" and "Speaker Protection Crossover" with
   -EPERM: only their owner may write them. They are state between the
   kernel and the protection supervisor, not mixer settings. Mark both
   INACTIVE (and VOLATILE) so that mixers and alsactl's restore leave
   them alone; the owner's writes are unchanged, as the core does not
   gate writes on INACTIVE.

3. A release, the owner gone or a new owner stopped a playing stream
   with the amps still at the operating gain: the stop is a click (a
   single 100 ms analysis block at -0.4 dBFS on a J616s, above the
   music's -3.1 dBFS peak). On amps with a digital gain in 0.5 dB steps
   (SN012776/TAS2764, TAS5770), ramp the gain down in eleven roughly
   even steps from -2 to -50 dB, at least 0.5 ms apart, while the
   stream still plays, then stop it and set the floor. The start gate
   is closed first, the ramp never runs past the lease's end and takes
   at most 10 ms, and it runs only on a powered card. A lapsed lease,
   a system sleep and a failure still withdraw at once, as does the
   J700's software gain.

Refused speaker starts stay quiet in the kernel log (quiet_trigger_eperm)
and are counted; the next grant reports them once.

KUnit: the ownership controls' access, the ramp (falling steps ending at
the floor, a withdrawal under 20 ms, only the speaker volumes), no ramp
past the lease or on the hard withdrawals or the J700, a floor that
waits for D0 with the gate already closed, and a grant that needs D0.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
A regmap debugfs dump of a TAS2764/SN012776 ("registers") reads every
register of every page and leaves all of them in the cache. The next
system sleep marks the cache dirty, and the resume's regcache_sync()
then writes back everything cached as raw blocks of contiguous
registers: from the page 1 quirk register at 0xb3 through the page 6
quirk registers at 0x313, across pages the amp reserves. The amp never
completes that transfer, the I2C controller stays in its transaction
(SMSTA 0x10850140) and every amp on the bus is gone until the next
boot:

  i2c-apple 23501c000.i2c: Timeout, status 0x10850140
  tas2764 3-003c: Unable to sync registers 0xb3-0x313. -62
  i2c-apple 23501c000.i2c: Bus is still stuck (status 0x10850140 ...)

A speaker wiring self-check that reads the amps' registers through
debugfs does exactly that dump, so the first sleep after such a check
broke the speakers on the J413 (M2), J316 (M1 Pro) and J616s alike.
The controller reset of commit 1dcabed ("i2c: pasemi: Reset a
controller that stays stuck in a transaction") recovers the bus, but
the write that stuck it is the bug.

Give the regmap a writeable_reg: page 0, the page 1 and page 6
registers of the quirk sequences and the SDOUT high-impedance masks,
and TI's quirk pages. regcache_sync() skips registers that are not
writeable, so a cache sync writes back only what the driver wrote.
Every register the driver and its quirk sequences write stays
writeable, which KUnit checks.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 7, 2026 05:04
@RyanTheTide
RyanTheTide merged commit b8ae494 into integration/aurora Nov 7, 2026
1 check passed
RyanTheTide added a commit that referenced this pull request Nov 7, 2026
Brings aurora-wip up to the tested release branch: CTXR execmem
(#985, #1079), KFIX speaker sleep and resume fixes (#1077, #1080),
JPEG v2 (#1072), Jonathan's G17 and USB work (#1073-#1076), brcmfmac
flowring count (#1081), ANE H16 startup restart (#1066) and the
Touch ID per-prompt match (#904).

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide
RyanTheTide deleted the kfix/spk-sleep-safe branch November 16, 2026 05:09
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