Skip to content

ASoC: macaudio: open the tweeter high-pass only for an engine that runs the Mac's crossover - #993

Merged
RyanTheTide merged 1 commit into
sgv2-kernel-interfacefrom
voice/sgv2-crossover-gate
Nov 5, 2026
Merged

RyanTheTide merged 1 commit into
sgv2-kernel-interfacefrom
voice/sgv2-crossover-gate

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Stacks on #990. Retarget to sgv2-kernel-interface once #990 merges.

What

On J316, J413 and J616 a protection grant opens every tweeter amp's playback high-pass from the 800 Hz safe corner to the amp's DT corner. That is only safe when the engine ahead of the amps runs the Mac's own crossover, so the tweeters never see full-band low-frequency content. An engine without it (an older speakerguardd v2, or any other owner) would drive the tweeters far harder at low frequencies than macOS does.

This makes the grant fail closed. The owner now has to declare the crossover before a grant can open the tweeter high-pass. Without the declaration the tweeters stay at 800 Hz for the whole grant. Woofers are unchanged. Machines without tweeter_hpf_granted ignore the declaration.

ABI: Speaker Protection Crossover

  • Card control, MIXER iface, boolean, 1 value. Appended after the existing card controls (no renumbering). Present on every card with speakers.
  • Meaning of 1: the owner's engine passes every speaker channel through the Mac's own crossover and high-pass, from its tuning, ahead of the amps.
  • Read: the current declaration. Anyone can read it.
  • Lock (SNDRV_CTL_IOCTL_ELEM_LOCK): needs CAP_SYS_ADMIN, and the file must already own Speaker Protection. Otherwise -EPERM.
  • Write: needs CAP_SYS_ADMIN, and this control must be locked by the file that owns Speaker Protection. Otherwise -EPERM. Values other than 0 or 1 get -EINVAL.
  • While protection is granted (or the floor after a lapsed lease has not run yet), a write gets -EBUSY. The grant latches the declaration. To change it, release (write 0 to Speaker Protection), write the declaration, then grant again.
  • The declaration goes back to 0 (with a change notification) when the owner unlocks Speaker Protection, closes its file, or a new owner takes the lock. A lease that runs out keeps it, since the owner is the same. The floor still puts the tweeters back at 800 Hz.
  • A grant without the declaration logs No crossover declared: tweeter high-pass stays at the safe corner on machines that would otherwise open it.

Order for an owner: lock Speaker Protection, lock Speaker Protection Crossover, write 1 to it, then write the lease. The existing ordering is unchanged: on a grant the high-pass is set before the gain, and a withdrawal stops the streams, sets the safe gain and then the safe high-pass.

Tests

  • ARM64 QEMU KUnit (LLVM, PROVE_LOCKING): 60/60 pass. That is the 40 macaudio tests (1 admission, 24 protection, 11 HPF, 4 amp-level; 36 before), the 9 TAS2764 tests, and the MCA/ADMAC/soc-utils suites. New HPF cases: an undeclared grant keeps 800 Hz and cannot be opened mid-grant; the declaration is latched by a grant (-EBUSY) and takes effect on the next one; it is refused without ownership, without the lock, on another file's lock, and without CAP_SYS_ADMIN (-EPERM); it survives a lapsed lease and is cleared on unlock/close and by a new owner. The existing tests that open the tweeters now declare the crossover first. One earlier run, made while a full kernel build was loading the box, missed two timing-sensitive lease tests (lease_expires, timer_beats_a_fifo_spinner). The rerun passed both.
  • tools/testing/selftests/alsa/macaudio-fixed-controls.py: 660 attempts per input-validation setting, 0 failures.
  • checkpatch.pl --strict: clean.
  • W=1 (clang, arm64) of sound/soc/apple/ and sound/soc/codecs/tas2764.o: no warnings.
  • Test kernel for the M2 (J413): 7.3.0-aurora-sgv2xo1. Boot qualification pending.

🤖 Generated with Claude Code

On J316, J413 and J616 a protection grant opens every tweeter amp's
playback high-pass from the 800 Hz safe corner to the amp's DT corner.
That is right only when the engine ahead of the amps already splits the
band the way the machine does: the tweeters then see no low-frequency
content but the engine's own thermal pilot. An engine without that
crossover would drive the full band into the tweeters with nothing in
the way.

Make the grant fail closed. Add "Speaker Protection Crossover", a
boolean card control on which the owner of "Speaker Protection"
declares that its engine passes every speaker channel through the
machine's own crossover and high-pass ahead of the amps. A grant opens
the tweeter high-pass only while that declaration is 1; otherwise the
tweeters stay at the safe corner for the whole grant and the woofers
are unchanged.

The control is the owner's alone. Locking it needs CAP_SYS_ADMIN and
ownership of "Speaker Protection"; a write needs CAP_SYS_ADMIN and that
lock held by the owning file (-EPERM otherwise). A grant latches the
declaration: a write while granted fails with -EBUSY. The declaration
goes back to 0 when the owner unlocks "Speaker Protection" or closes
its file, and when a new owner takes it. A lease that runs out keeps
it, as the owner is the same; the floor still restores the safe corner.

The control is appended after the existing card controls, so no
control is renumbered. Machines that never open the tweeter high-pass
ignore it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

M2 (J413) hardware check, 2026-11-06, test kernel 7.3.0-aurora-sgv2xo1 (sgv2-kernel-interface + linux #990 + #993) with speakerguardd #70 + #67:

  • The self-check grant runs without a declaration: the kernel logs "No crossover declared: tweeter high-pass stays at the safe corner". The self-check passes, with sense written through the owner file.
  • v2 declares the crossover ("crossover declared to the kernel: true"; Speaker Protection Crossover = on), and the grant follows. DC_BLK0 reads 0x01, the DT corner, on all four amps.
  • Pre-stage in the live graph, with a -70 dBFS tone into the protect stage and its output captured: at 100 Hz the woofers are at -71.9 dBFS and the tweeters at -186.5 dBFS; at 3 kHz the woofers are at -88.3 and the tweeters at -83.3.
  • 0 amp faults, 0 AVC (enforcing). The M2 is restored to fleet17 with speakerguardd 0.1.

@RyanTheTide
RyanTheTide changed the base branch from fix/sgv2-dcblocker-sense to sgv2-kernel-interface November 5, 2026 15:06
@RyanTheTide
RyanTheTide merged commit 07d12e0 into sgv2-kernel-interface Nov 5, 2026
@RyanTheTide
RyanTheTide deleted the voice/sgv2-crossover-gate branch November 5, 2026 15:07
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