Skip to content

ASoC: apple: mca: sample the J615 speaker sense one bit clock later - #2589

Merged
DjDeveloperr merged 3 commits into
integration/aurorafrom
audio/j615-sense-rx-delay
Nov 20, 2026
Merged

DjDeveloperr merged 3 commits into
integration/aurorafrom
audio/j615-sense-rx-delay

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem

On the MacBook Air 15" M3 (J615), speakersafetyd exits at the start of every speaker stream with Left Tweeter: Negative power, bad ivsense data?. It happens on every boot (26 of 26 observed). systemd restarts it in "warm" mode, so the speakers stay held at maximum gain reduction after every boot. When a restart storm hits StartLimitBurst the daemon is gone and the speakers stay locked.

The daemon is right. Recordings of the sense capture during the stream the system opens at boot (silence, nothing played on purpose) show every one of the 12 voltage/current words shifted by one bit. Each word's top bit is the previous slot's last bit, and the rest is the real word shifted right. Silence then reads as several watts on all six amps (-4.5 to +4.1 W), not just the tweeter, which is simply the first speaker the daemon checks. The proof that the shift is one bit late: the first channel of the frame, whose previous slot is idle, never reads negative. Shifting the words back by one bit gives under 0.04 mW on every amp, i.e. silence.

Change

  • dt-bindings (apple,mca): optional apple,rx-delay-bclks, one entry per port: how many bit clocks late that port's received data arrives because of board signal timing (0 or 1).
  • mca: a cluster capturing from such ports starts its RX bit count that much later (the largest delay of its source ports). Without the property nothing changes. A small helper, with KUnit cases.
  • t8122-j615: ports 0 and 1 (the speakers) are one bit clock late.

The J615 uses the same macOS speaker-stream description as the M2 Air 15" (J415), where the same Linux format works, so this is board/SoC timing. It's described in the DT rather than gated on a board or chip.

Testing

  • J615, macOS 27.2 firmware, lab kernel 7.3 (cold one-shot boots, nothing played; the boot-time stream is silence):
    • with the receiver one bit later: speakersafetyd survives the stream start for the first time on this Mac (no restart), and the captured period reads 0.0000 W on all six amps;
    • negative control, this exact mca.c with the DT property absent: unchanged, the daemon exits as before with the one-bit-late signature;
    • exact PR form (this mca.c built for the lab kernel + the J615 DT property): PASS on a fresh boot, daemon survives the stream start (no restart), 0.0000 W on all six amps.
  • KUnit (apple-mca-capture-sync, x86_64 qemu): 4/4 pass, including the new mca_rx_delay_of_ports. checkpatch --strict clean; dt_binding_check and CHECK_DTBS (t8122-j613/j615) clean; W=1 clean.

Still to run

  • Daytime: a speaker stream longer than one period (silent all-zero playback, then real audio with Ryan's OK) to confirm the steady state, and that playback itself is unaffected (this only moves the capture sampling point).
  • J613 (13" M3 Air): same SoC, four amps; aura#291 reports its daemon running, so it is left without the property. A sense capture there would settle whether it needs the same.
Evidence detail
  • Recordings: speakersafetyd 3.0.0 --sense-capture of the first period of each daemon start, 12 x S16 at 48 kHz, 4096 frames. Raw values cluster at 0..+-17 and +-32745..32767 (e.g. 32762 = 0x7FFA = -12 >> 1 with a 0 top bit; -32761 = 0x8007 = 14 >> 1 with a 1 top bit).
  • Per-amp power, raw vs shifted back: LW1 -0.55 W / +0.0004 mW, RW1 -0.13 W / +0.0007 mW, LT -2.29 W / -0.0017 mW, RT -2.55 W / +0.027 mW, LW2 -4.39 W / -0.0033 mW, RW2 +4.10 W / +0.037 mW (one boot; three boots alike).
  • A one-sample V/I skew (the J813 current_delay_samples fix) does not change the raw numbers, so it is not that class.

Assisted-by: LLM (Claude:Opus 5.5)

…late

On some boards the data that devices send to an MCA port arrives later
than the DAI format places it. On the MacBook Air 15" M3 (J615) the six
speaker amps' voltage and current sense words reach their two ports one
bit clock late, so every received word comes in shifted by one bit.

Add an optional per-port apple,rx-delay-bclks array: the number of bit
clocks by which that port's received data is late. Only 0 and 1 have
been seen.

Signed-off-by: Ryan Murray <[email protected]>
When a cluster captures from ports that the device tree lists in
apple,rx-delay-bclks, start its RX bit count that many bit clocks later
than the DAI format does, taking the largest delay of its source ports.
Without the property nothing changes.

On the J615 the speaker sense capture otherwise sees each word one bit
late: its top bit is the previous slot's last bit. speakersafetyd then
reads amps that draw watts in silence and exits at the start of every
speaker stream, which leaves the speakers held at their safe level.

Signed-off-by: Ryan Murray <[email protected]>
…k late

The J615's six SN012776 amps return their voltage and current sense
words to MCA ports 0 and 1 one bit clock later than the I2S format
places them. Describe that so that the sense capture samples them where
they are.

Signed-off-by: Ryan Murray <[email protected]>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at ff41fe2. Approve.

Scope (sense capture only, DT-driven)

  • sound/soc/apple/mca.c:721-724: the new write is guarded by !is_tx, so it touches only the cluster's RX serdes REG_RX_SERDES_BITSTART. Speaker playback (TX bitstart, serdes conf, gain, amp enables) is not touched.
  • sound/soc/apple/mca.c:1405-1411: rx_delay comes from apple,rx-delay-bclks only. If the property is absent, of_property_read_u32_index leaves the kzalloc'd 0, and values above 1 are refused and treated as 0. There is no compatible or chip list.
  • On every other board the capture hw_params now writes back cl->rx_bitstart + 0, which is the value mca_fe_set_fmt already wrote (mca.c:615-618). The register value is the same, and Ryan's negative control (this mca.c, no property, J615) shows that. Rewriting it on every hw_params is also correct when a cluster switches between late and on-time ports.
  • The sleep save/restore (mca.c:1522-1527) reads RXA+0xc back from hardware, so the delayed bitstart survives a firmware-path suspend with the sense stream open.
  • arch/arm64/boot/dts/apple/t8122-j615.dts:114-120: <1 1 0 0 0 0> matches the six clusters in t8122.dtsi (6 clocks) and the speaker link on <&mca 0>, <&mca 1>. The jack on port 2 stays at 0. J613 and all other SoCs are unchanged.

Binding

  • Documentation/devicetree/bindings/sound/apple,mca.yaml:113-124: documented, uint32-array of 4..6 entries, each at most 1, matching the driver's clamp. dt-checks is still running on this head.

Safety

  • No amp limit, gain, idle mode or playback path changes. Nothing reaches the amps earlier than before. The visible effect is that speakersafetyd no longer exits at stream start, so the amps stay under the daemon's protection instead of in warm-restart lockdown.
  • The evidence for the one-bit direction is strong: silence decodes to under 0.04 mW on all six amps once shifted. But it is silence only. The daemon's model under load still needs the playback row below before any distro pin picks this up for J615.

Notes (non-blocking)

  • The mca_rx_delay_of_ports KUnit case is not in the CI host-test set. It passes per Ryan's x86_64 qemu run.
  • Using the max delay means a capture that mixes a late port with an on-time port would sample the on-time port late. This is documented in the helper and test, and no current DT does it.

Post-merge row (required): J615 real speaker playback through speakersafetyd at 5% volume, with Ryan's OK: silent all-zero stream for more than one period, then real audio. Check NRestarts 0, plausible per-amp power, and no gain-reduction lockup. If it fails: git revert -m 1 <merge sha> on integration/aurora.

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.

2 participants