Skip to content

ASoC: apple: aop-spkr: stop the speaker TX DMA only after pw1 - #3619

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/aop-spkr-tx-stop-after-pw1
Nov 29, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/aop-spkr-tx-stop-after-pw1

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2188

What: The AOP firmware crashes when the speaker serializer runs (pwrd) while the playback DMA is stopped. A front-end STOP used to stop the ADMAC TX channel at once, but the serializer only goes down to pw1 50-100 ms later, in the back-end hw_free or the next prepare.

On STOP/SUSPEND of the speaker playback front-end, the driver now fills the buffer with silence and leaves the cyclic channel running. It stops the channel only after the serializer is down:

  • after the pw1 of the back-end prepare's restart, in hw_free, at shutdown and at system suspend;
  • as a fallback, from the front-end prepare (back-end stopped without a prepare of its own, e.g. a route change mid-stream) and from the front-end close.

Stopping the channel just before pw1 is not enough: that crashed the firmware on the first cycle here, as in joske's J614c timings on #2188. The order here is the one joske tested on #2188, with 0 crashes over a day of normal use.

Playback itself is unchanged: same dmaengine path, same start order.

FIFO check: if words a stopped serializer leaves in the channel FIFO reached the next stream, they would rotate its six slots. Measured on J616C with a diagnostic build. After each deferred stop, with the serializer down (no clocks, no sound), I restarted TX0 on a zeroed buffer and read how much it fetched. Every restart took in its full 256 bytes again (27 stops × 3 probes), so a channel start resets the FIFO.

Tested (J616C, MacBook Pro 16" M4 Max, 7.3.0-j616c-parity5+ with this commit; aop_spkr.rs is identical on main):

  • Muted stop/start cycles (1 s of silence, 6-9 s apart, full hw_free path each time):
    • before: AOP crash at cycle 5;
    • after: 40/40 and 25/25 with no crash.
  • 60 short muted clips back to back, and 24 forced quantum changes during one stream (12 stop/re-prepare/restart cycles through run()): 0 crashes.
  • A few minutes of normal video playback at 25 % volume, by ear: no pops, no AOP crash.
  • ARM64 cross-build (LLVM=1) of snd-soc-aop: no errors or warnings.

Risk: Apple AOP speaker playback path only (sound/soc/apple/aop_spkr.rs); the jack services are unchanged.

Not yet: other spkr boards (J614c/J616s), and a suspend/resume cycle with playback running.

Supersedes: #3474 (its driver-owned TX ring caused audible pops here; closing it).

The AOP firmware crashes when the speaker serializer runs (pwrd) with
the playback DMA stopped (aurora-silicon#2188). A front-end STOP
used to stop the DMA at once, while the serializer only goes down to
pw1 50-100 ms later, in hw_free or the next prepare.

On STOP or SUSPEND of the speaker playback front-end, fill the buffer
with silence and leave the cyclic channel running. It is terminated
only after the serializer is down: after the pw1 in the back-end
prepare's restart, in hw_free, at shutdown, at system suspend, or, if
none of those ran, from the front-end close through the same stop.
Stopping it right before the pw1 is not enough: that still crashed the
firmware on the first cycle.

The words left in the channel FIFO when the serializer stops do not
reach the next stream: with the serializer down, a channel restarted
after such a stop takes in its full 256 bytes again every time (27/27
stops), so a start resets the FIFO and the next stream meets an empty
FIFO on a fresh serializer, as before.

sync_stop skips a channel whose stop is deferred, a START with a stop
still deferred is refused, and the managed buffer is preallocated so a
late period callback never sees it freed.

J616C, muted start/stop cycles (1 s of silence, 6-9 s apart): the
current driver crashed the AOP at cycle 5; with this, 25/25 with no
crash.

Signed-off-by: AxxzyWasTaken <[email protected]>

@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: HOLD at 9439bf96 — clean, well-reasoned speaker TX deferred-stop implementation in sound/soc/apple/aop_spkr.rs; awaiting fork CI approval/run and an exact-head hardware row at 9439bf96.
Blockers:

  1. Run hosted CI (kunit, host-tests, readiness) on this fork PR and confirm green at 9439bf96.
  2. Post a hardware verification row citing exact head 9439bf96 (J616C, plus regression check: SELinux denials, failed units, new kernel errors; a suspend/resume cycle with playback active is also worth covering before merge given the SNDRV_PCM_TRIGGER_SUSPEND path).
    Checked: sound/soc/apple/aop_spkr.rs (Service::defer_tx_stop, finish_tx_stop, finish_tx_stop_if_down, tx_stop_deferred, put, run, stop_locked, suspend, pcm_open_dmaengine, pcm_close, pcm_prepare, pcm_trigger, pcm_sync_stop, be_service, be_prepare, be_hw_free), commit hygiene, and J616C test evidence.
Evidence
  • Code verification (sound/soc/apple/aop_spkr.rs):
    • tx_started (AtomicBool) cleanly gates defer_tx_stop() so an undo-STOP after an upstream START failure never defers an unstarted channel; START fails closed with -EBUSY if tx_stop_deferred(chan) is still true.
    • SNDRV_PCM_INFO_PAUSE and SNDRV_PCM_INFO_RESUME are already cleared in pcm_open_dmaengine(), so PAUSE_PUSH/RESUME cannot bypass the deferred-stop state machine.
    • Preallocating the managed DMA buffer at PCM_BUFFER_MAX with max = 0 (snd_pcm_set_managed_buffer()) ensures hw_params / hw_free never free the backing buffer while a deferred cyclic TX channel is still reading silence from it.
    • Every serializer-down transition (Service::run() after quiesce() + STATE_PW1, Service::stop_locked() covering be_hw_free and suspend(), Service::put(), pcm_prepare() when !st.running, and pcm_close() before snd_dmaengine_pcm_close_release_chan()) cleanly terminates and synchronizes the deferred channel via deferred_tx.swap(null_mut(), AcqRel) -> device_terminate_all + device_synchronize.
    • be_service() restricts be_prepare/be_hw_free serializer transitions to playback ((_, playback) => (&ctx.spkr, playback)), so sense-capture front-ends cannot race finish_tx_stop() against active speaker playback.
  • Nit (non-blocking):
    • In pcm_close(), if a deferred stop somehow reaches close with st.running == true (e.g., if be_hw_free never ran), svc.stop() drops the serializer to STATE_PW1 without muting codecs first; normal ALSA close runs be_hw_free (which mutes amps first) before pcm_close, so this is only a last-resort safety net before releasing the DMA channel.
  • Hygiene: Single commit with DCO Signed-off-by:, MERGEABLE on main.

@RyanTheTide

Copy link
Copy Markdown
Contributor

J616s row (MacBook Pro 16" M4 Pro, T6040), muted only: digital zeros into the speakerguardd v2 sink with the sink muted the whole time, so no audible output. v2 still gated the amps.

Kernel: the J616s's saved EDGE kernel (933f822, 7.3.0-aurora-edge, CI build) with only this PR's commit cherry-picked (aop_spkr.rs at 933f822 is identical to this PR's parent), built with the Mac's own EDGE config as 7.3.0-aurora-e3619+. Booted once as a one-shot; DTB and Stage 2 unchanged. speakerguardd-v2 0.64 (e0672aca), PipeWire.

Control first, on the unpatched EDGE kernel, same boot conditions:

  • Muted stop/start cycles (1 s of zeros, 6-9 s gaps, speaker PCM back to closed between cycles, so the full hw_free path every time): AOP crash at cycle 35 (apple_aop 510c10000.aop: RTKit: co-processor has crashed, 6 s after a protection re-grant).

With this PR (7.3.0-aurora-e3619+):

  • 40/40 muted stop/start cycles, same script: 0 crashes.
  • 60 back-to-back 0.3 s muted clips: 0 crashes.
  • Forced re-prepares during one running stream: clock.force-quantum alternated 1024/512 every 3 s, 2 x 24 changes (at 1024 v2 holds the speakers and the speaker PCM closes; at 512 it is RUNNING again, so each pair is a stop from RUNNING plus a re-prepare and restart): 0 crashes.
  • s2idle suspend/resume with the muted stream RUNNING (rtcwake -d rtc1 -m mem -s 25): entry 00:50:17, exit 00:50:43, protection re-granted 2 s after resume, 5 more stop/start cycles after it: 0 crashes.
  • Whole boot: 0 AOP crashes, 137 protection grants, 0 failed units, Enforcing. The J616s is back on its saved EDGE kernel.

Not covered here: audible playback (speakers are silent in the lab tonight).

Tested: J616s M4 Pro at ab73509a (this PR's 9439bf9 on EDGE 933f822): 0 AOP crashes over 45 muted cycles, 60 clips, 48 re-prepares and one s2idle cycle; unpatched EDGE control crashed at cycle 35.

@github-actions github-actions Bot added area:audio Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Merge readiness at 9439bf96: not ready yet

Check Detail
CI at head ok 2 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at 9439bf96
Conflicts ok none
PR text no add a 'Tested:' line; 'one-way' or 'two-way' in Risk (guide)

Areas: area:audio

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

@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: MERGE at 9439bf96

Blockers: none

Checked:

  • Upgrading prior HOLD at 9439bf96: exact-head J616s (M4 Pro, T6040) hardware verification posted (7.3.0-aurora-e3619+, built from EDGE config with 9439bf96 applied on an identical aop_spkr.rs base): unpatched EDGE control crashed AOP at muted cycle 35, whereas 9439bf96 ran 45/45 muted stop/start cycles, 60 back-to-back clips, 48 forced re-prepares (clock.force-quantum 1024/512), and 1 s2idle suspend/resume with stream RUNNING with 0 AOP crashes, 137 protection grants, and 0 failed units.
  • Re-verified sound/soc/apple/aop_spkr.rs deferred TX DMA stop ordering: front-end STOP/SUSPEND silences the cyclic buffer while leaving DMA running until after back-end pw1 / hw_free / shutdown / suspend, with clean front-end prepare/close fallbacks and FIFO/slot check on J616C.
Evidence
  • sound/soc/apple/aop_spkr.rs at 9439bf96b781f500c7716414ed7427f6818ec09f, MERGEABLE on main.
  • J616s control vs patched row (#issuecomment-7256873040): unpatched crash at cycle 35 -> patched 0 crashes across 45 stop/start cycles, 60 short clips, 48 forced re-prepares, and s2idle.
  • Note: PR body still lacks Tested: and Risk: two-way lines flagged by pr-readiness; add before merge so readiness goes green.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 9439bf96. App approved; J616s control-vs-patched row (45 cycles, 0 crashes vs a control crash at 35). One thing before merge: @AxxzyWasTaken, please add the two PR-text lines, Tested: J616s at 9439bf96: ... and Risk: two-way · <Macs with the AOP speaker path>, so pr-text passes. It merges 1 h after the ping once CI is green, unless anyone objects.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at 9439bf96. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J616s-control-vs-patched;needs-Tested/Risk-lines. (5) There's no blocking review. (6) Dj was pinged here 66 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 6c5075f into aurora-silicon:main Nov 29, 2026
3 checks passed
@joske

joske commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

J614c (MacBook Pro 14" M4 Max) on main 8f8a076 + #2170 #3200 (unrelated g17 changes), legacy speakersafetyd selected via Speaker Protection Interface:

Thanks for picking this up!

@e-fu

e-fu commented Dec 1, 2026

Copy link
Copy Markdown

Tested (J614s, MacBook Pro 14" M4 Pro, T6040), A/B on the same machine and rig:

Rig: muted stop/start cycles through speakerguardd v2 (sgv2.voicing.j614): 1 s of digital silence, sink muted at 0, stream volume 0, 6-9 s apart. Each cycle verifies that the speaker PCM went open → closed, which is the full hw_free path. The rig aborts at the first AOP crash.

arm cycles AOP crashes
A (-47) 114 (36 + 78) 1, at cycle 79: co-processor has crashed → spkr pw1 failed: EINVAL, spkr idle failed: EINVAL
B (this PR) 104 (40 + 64) 0

Not yet: suspend/resume with playback running.

@e-fu

e-fu commented Dec 1, 2026

Copy link
Copy Markdown

J614s addendum (same machine and rig as my row above), closing its "Not yet": kernel B (844781f + 726da32 + 9439bf9, plus the #2371 commits, which don't touch audio).

  • s2idle suspend/resume with a muted stream RUNNING through speakerguardd v2. The sink was muted at 0, the stream volume was 0 and the stream was digital silence. Wake was by RTC (rtcwake -d rtc1 -m mem -s 25, about 28 s asleep). After resume the stream was still RUNNING, v2 re-granted protection about 1 s after the thaw, and there were 0 AOP crashes.
  • After that, 5/5 muted stop/start cycles: 0 crashes.

Tested: J614s at 9439bf9 on 844781f: one s2idle cycle with playback running, then 5 stop/start cycles, 0 AOP crashes.

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

J614c: AOP firmware crashes at speaker start/stop, speakers dead until reboot

4 participants