Skip to content

ASoC: apple: T8140 (J700) AOP audio and macaudio routing (reworked, 12 patches) - #13

Merged
RyanTheTide merged 12 commits into
aurora-wipfrom
series/neo-audio-after-codec-20260924
Sep 25, 2026
Merged

RyanTheTide merged 12 commits into
aurora-wipfrom
series/neo-audio-after-codec-20260924

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

ASoC: apple: T8140 (J700) AOP audio and macaudio routing — v2

Reworked after the 2026-09-25 audit. Twelve patches replace the six of the
audited head (68fcd84). Based on aurora-wip at 7693112 (PR #10, #12
and the reworked PR #11 merged); the AOP audio driver uses the merged PR #11
API (ReportListener, SourceRing::read(), add/remove_report_listener(),
source_ring(), <dyn AOP>::from_child()).

Compile-tested only; nothing in this PR has been run on hardware. See the
"needs testing" list at the end.

What changed since the audited head

Dropped:

  • ASoC: preserve unconstrained DAI subformats during refinement (soc-pcm.c):
    the ALSA core always grants the STD subformat, the bug it described cannot
    occur.
  • ASoC: soc-utils: permit float32 samples through the dummy codec: no longer
    needed, the HQ microphone is not a macaudio link any more.
  • The fourth macaudio front-end ("HQ Mic") and the guards that existed only for
    it; the in-series rearm fix-up is folded into the driver patch.

Split and rewritten:

  • The cs42l42 change is two patches: standard DSP_A support (frame start on the
    LRCLK rising edge, 1.0 SCLK delay, channels back to back) and, separately,
    odd SCLK/LRCLK ratios accepted in DSP_A only; I2S keeps rejecting them. The
    J700's timing is expressed as SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF
    in the machine config instead of a half-SCLK frame delay plus a bare
    BIT(1) << CS42L42_ASP_SCPOL_SHIFT.
  • Four generic macaudio fixes, each with a Fixes: tag, ahead of the J700
    work: cancelling lock_update_work after the card is unregistered (the card
    is registered without devres for that), the lock control ops fully under
    volume_lock_mutex, no lease inherited by a new lock owner, and the timeout
    work re-arming instead of expiring a lease that a racing ping renewed. The
    "Speaker volumes locked/unlocked" messages stay at dev_info.
  • Software-gain amplifier support (AMP_MAX98360A) is its own patch, the J700
    routing another. The software-gain front-end is identified by CPU DAI name
    from the platform config, not by link id.

The AOP audio driver:

  • The HQ microphone array (hpai) is PCM 1 of the driver's own card
    (Apple<chassis>AOP, driver t8140-aop-audio; PCM 0 is the low-power
    microphone), a dmaengine PCM advertising FLOAT_LE like the other AOP
    microphones; no ASoC core changes.
  • The low-power microphone ring is read through the AOP core's
    SourceRing::read() (the buffer is no longer exposed), and the driver
    finds its AOP through <dyn AOP>::from_child(), which defers the probe
    until the core has published.
  • No AArch64 asm!: the AOP timestamp comes from
    arch_timer_read_counter()/arch_timer_get_rate() through two new Rust
    helpers (rust/helpers/arm_arch_timer.c), which compile on every
    architecture. A second small infrastructure patch adds the ALSA TLV and
    control-interface constants to the bindings.
  • The __pm_runtime_set_status(RPM_SUSPENDED) retry on a genpd device is gone;
    a leaf that fails to resume fails that open.
  • LEAP power domains and ADMAC channels are taken per open and released per
    close (the channel before the leaves), instead of being held from pcm_new to
    pcm_free.
  • Power domains are a typed PowerDomain handle; no raw pointers in
    Atomic<usize>, no per-FE channel table (the dmaengine runtime owns the
    channel), start work items are Work<Self, ID> fields of the shared data,
    C descriptors are built with Default::default() (no mem::zeroed()),
    firmware replies are parsed with bounds-checked helpers (no
    try_into().unwrap()), every unsafe impl and unsafe extern "C" fn has
    its SAFETY text; clippy is clean for the file with the kernel's settings.
  • Speaker buffer bounded at 128 KiB (341 ms) with periods up to the ADMAC
    segment size, so PipeWire quanta above 2048 frames work; the copy-time gain,
    the no-mmap speaker path and the const-asserted volume table are unchanged.
  • "Speaker Sense" is described as what it is: a digital tap of the words the
    amplifier receives, after the gain; no current or voltage.
  • Dated bench notes, the false subformat comment and per-trigger dev_dbg
    chatter are removed; hardware facts stay in the comments.

Checks run

For every one of the twelve commits, on 7693112: macaudio.o and cs42l42.o
with W=1 C=1 (sparse), rust/kernel.o, rust/helpers/helpers.o and
sound/soc/apple/t8140_aop_audio.o with W=1 (a git rebase -x pass that
rebuilds them at each commit), CLIPPY=1 and rustfmt --check for the
driver, scripts/checkpatch.pl --strict on the format-patch output, and
git diff --check. Remaining checkpatch output is the known
trailer noise ("Assisted-by expects", "Non-standard signature:
Co-authored-by"), an ENOTSUPP false positive (snd_soc_dai_set_tdm_slot()
returns it) and "Unknown commit id" for the Fixes: tags in a shallow clone.
J700 config, CONFIG_RUST=y, 16K pages, LLVM.

Not tested

Nothing was run on the machine. In particular still to confirm on hardware:
the jack link as DSP_A | IB_NF (the bring-up used an equivalent but
non-standard register setting); per-open LEAP power sequencing for the speaker
and HQ mic channels; the HQ mic as hw:AppleJ700AOP,1 (userspace configs
that used the macaudio "HQ Mic" device or the AppleJ700LPAI card need
updating); lock loss during playback (clip, XRUN, re-prepare at the lower
gain); the larger speaker buffer with PipeWire; the four lease fixes on a J700
and on a TAS-based Asahi machine; and resume from s2idle with an open speaker
stream.

🤖 Generated with Claude Code

RyanTheTide and others added 12 commits September 26, 2026 02:23
The CS42L42 and CS42L83 ASP supports a pulse-framed serial interface
besides I2S: the frame starts on the rising edge of a one-SCLK LRCLK
pulse, the first data bit follows 1.0 SCLKs later and the channels sit
back to back within the frame. On Apple's T8140 (MacBook Neo, J700)
the AOP firmware runs the CS42L83 jack link that way, with two 32-bit
slots per frame, and the host cannot change the bus format.

Accept SND_SOC_DAIFMT_DSP_A: program ASP_FRM_CFG for pulse mode with
the frame start on the LRCLK rising edge (STP) and a 1.0 SCLK frame
start delay, and place channel 2 one physical sample width after the
frame start in the same LRCLK phase instead of in the high phase.
Remember the format so hw_params can tell the two layouts apart. The
channel bit-position registers are now written for I2S as well, with
their power-on values, so that a codec that changes format between
streams does not keep the DSP_A offsets.

The bit-clock and frame inversion flags keep their meaning: a link
that launches data on the rising SCLK edge and samples it on the
falling edge is described as SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
cs42l42_asp_config() rejects any SCLK that is not an even multiple of
the sample rate, because an I2S frame is split into two equal LRCLK
phases. A pulse-framed DSP_A link has no such requirement: the LRCLK
is a pulse and the channels are placed by their bit positions, so the
frame may hold any whole number of SCLKs.

Apple's T8140 AOP firmware clocks the CS42L83 jack link at 125 SCLKs
per 48 kHz frame (6 MHz). Accept an odd ratio when the DAI is in
DSP_A, and keep the pulse width at half the frame rounded down (62
SCLKs for that link), which is how the vendor driver programs it. I2S
keeps rejecting odd ratios, as an odd frame cannot give it a 50/50
duty cycle.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The speaker back-end trigger queues lock_update_work, and that work
arms lock_timeout_work. remove() cancels only the delayed work, and it
does so while the card is still registered: devres unregisters the
card after remove() returns. A stream that is still running can
therefore queue either work after the cancellation, and the work then
runs on driver data that devres has freed.

Register the card without devres and unregister it at the start of
remove(), which closes every stream, so that no trigger can queue work
any more. Then cancel the update work, which is the one that arms the
timeout, and the timeout work after it.

Compile-tested only; not run on hardware.

Fixes: bad95a5 ("macaudio: speaker volume safety interlocks")
Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
volume_lock_mutex guards the speaker lock state, but two of the
"Speaker Volume Unlock" control ops still touch that state outside
it. The put op reads speaker_lock_owner and clears
speaker_volume_was_locked before taking the mutex, so a lock loss
recorded by the timeout work between the check and the mutex can be
consumed without ever being reported to the daemon, and the unlock op
clears the owner and the timeout with no lock at all, racing the
timeout and update works that read them.

Take the mutex for the whole of both ops.

Compile-tested only; not run on hardware.

Fixes: d856390 ("macaudio: Use an explicit mutex for the speaker volume lock")
Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The speaker volume is unlocked while the lock owner keeps pinging the
"Speaker Volume Unlock" control; each ping grants a lease of
SPEAKER_LOCK_TIMEOUT. Unlocking the control clears the owner but not
the remaining lease, so a process that locks the control next inherits
whatever was left and gets the volume unlocked before it has pinged
once, for up to a full lease.

Clear the lease and cancel its timeout when the control is unlocked
and again when it is locked, so that a new owner starts locked and
must ping to unlock.

Compile-tested only; not run on hardware.

Fixes: bad95a5 ("macaudio: speaker volume safety interlocks")
Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
macaudio_vlimit_timeout_work() expires the speaker lock lease as soon
as it runs. A ping that arrives while the work is already running
cannot cancel it: cancel_delayed_work() returns without waiting, the
ping installs a fresh lease and re-arms the timer, and the running
work then takes the mutex and expires the lease that was just renewed.
The daemon sees an unexplained lock loss and the volume is clamped
until its next ping. Disabling the timeout while the work is running
has the same effect on the remaining lease.

Check the lease deadline under the mutex: when it lies in the future,
re-arm the work for the remainder instead of expiring, and do nothing
when the timeout was disabled or the owner went away in the meantime.

Compile-tested only; not run on hardware.

Fixes: bad95a5 ("macaudio: speaker volume safety interlocks")
Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
arch_timer_read_counter() is a function pointer and
arch_timer_get_rate() is not exported, so a Rust module cannot use
either through bindgen alone. Add helpers for both, built into the
kernel like the other helpers, so that a driver can read the
architected counter through the arch timer layer (including its
erratum workarounds) instead of reading the system registers itself.
Both fall back to the header's stubs on architectures without the
arch timer, so the helpers compile everywhere.

The T8140 AOP audio driver, submitted separately, needs them: the AOP
firmware stamps power requests with the always-on 24 MHz timebase,
which is derived from the counter and its rate.

Assisted-by: LLM checkpatch
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
Generate bindings for sound/tlv.h so that a Rust driver can build a
dB-scale TLV from SNDRV_CTL_TLVT_DB_SCALE and TLV_DB_SCALE_MUTE
rather than from bare numbers, and export SNDRV_CTL_ELEM_IFACE_MIXER,
a __force cast that bindgen cannot evaluate, as a constant in the
same way as the PCM format bits.

The T8140 AOP audio driver, submitted separately, uses them for its
speaker volume control.

Assisted-by: LLM checkpatch
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
On Apple's T8140 (J700, MacBook Neo) the AOP firmware owns the audio
fabric: the ADMAC channels, the MCA serializers and the LEAP block are
run by the firmware, and the host reaches each path through an audio
EPIC service. Add a driver for the AOP's audio child that exposes them.

The driver registers a card of its own with two capture PCMs. The
low-power microphone (lpai) has no host DMA at all: the firmware
produces 16 kHz stereo S32 frames into a 512 KiB ring that the AOP
driver binds over the setup port, and reports its cursor every 3,200
frames; the report listener copies each reported span into the ALSA
buffer. The high-quality microphone array (hpai) is a PDM part behind
the AOP that comes back as float32 over leap-s ADMAC RX0; it has no
codec and no serializer of ours, so like the other AOP microphones it
is a plain dmaengine PCM on the driver's card, advertising FLOAT_LE.

For the headphone jack and the internal speaker the driver is an ASoC
component: back-end DAIs "cout" (the CS42L83 on MCA1, base-ns ADMAC
TX2/RX2) and "spkr" (the MAX98360A amplifiers on LEAP TX0, with the
SpeakerTap on base-ns RX1 as their capture side), and three DPCM
front-end PCMs on the corresponding ADMAC channels, which the J700
macaudio variant links to the codecs. A back-end attaches its service
at startup, requests "pw0 ", holds its PMGR leaves through runtime PM
and requests "pwrd", after which the firmware runs the serializer
clocks. The speaker and the microphone array start from a work item
queued by the trigger: "pwrd" makes the LEAP move samples at once, so
the DMA must already be running, and the firmware call sleeps. A PCM
underrun stops the DMA but not the service, so the speaker's prepare
retires the previous run before the stream is started again.

The speaker front-end is copy-only. The LEAP consumes float32 and the
words on the wire are 2 * value * 2^31, so 0.5 is full scale and
anything above it wraps: every S32 sample is scaled by "Speaker
Playback Volume" (0.5 dB steps below that ceiling, the top entry
asserted at compile time) and converted in the copy path, mmap is not
offered, and the buffer is bounded to 341 ms so that a gain change is
not stuck behind a long queue. macaudio's volume lock keeps the
control 20 dB down until a speaker-protection daemon takes it. The tap
that macaudio exposes as "Speaker Sense" is a digital tap: it returns
the words the amplifier received, after this gain, and senses no
current or voltage.

The LEAP ADMAC's channel registers only answer while the channel's own
PMGR leaf is on, so the speaker and array channels are requested per
open with their leaves powered and released before the leaves are. A
leaf that fails to power up fails that open; recovering a domain from
a failed resume is the pmdomain driver's job, not a consumer's. Power
requests carry a timestamp in the AOP's 24 MHz timebase, derived from
the architected counter through the arch timer helpers.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt clippy
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
Every speaker amplifier macaudio knows has a volume control of its
own, which the speaker lock limits. The MAX98360A on the J700 has
none: it is a fixed-gain part fed by the AOP's LEAP, and the CPU DAI
applies the volume as a software gain when it converts the samples in
its copy path. Add AMP_MAX98360A for that arrangement.

The lock machinery works as before, through the CPU DAI's "Speaker
Playback Volume" (0.5 dB steps, 127 = the amplifier's full scale, so
the -20 dB safe level is 87). Two things differ. If the limit cannot
be applied at all, the front-end refuses to play: with a software
gain the limit is the whole protection. And a lower gain cannot
change samples that were converted before it was set, so a lock event
bumps an epoch and stops the software-gain front-end stream with an
XRUN; the stream is refused until it has been prepared again under
the new epoch, which lets the CPU DAI clear its buffer. The refusal
is made in the front-end's trigger, which runs before the CPU DAI and
the back-ends are triggered (the front-end links now spell out the
default SND_SOC_DPCM_TRIGGER_PRE order that guarantees it), so a
refused start leaves the DMA untouched.

The platform config names the CPU DAI that applies the gain, and the
speaker codec's output widget, since the MAX98360A codec driver calls
it "Speaker" rather than "OUT". An amplifier without a TDM interface
passes the slot assignment like the headphones do, and a speaker CPU
DAI without a capture side gets no sense route.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
Route the MacBook Neo's (T8140, J700) audio through macaudio: the
CS42L83 headset jack on the AOP's "cout" back-end and one MAX98360A
per channel on its "spkr" back-end, with the T8140 AOP audio driver
as the CPU component and its three "j700-pcm-N" front-ends in place
of the MCA's.

The AOP firmware fixes the jack link: 125 SCLKs per 48 kHz frame
(6 MHz), a pulse frame with two 32-bit slots, data launched on the
rising SCLK edge. That is DSP_A with an inverted bit clock, so the
J700 config carries its own DAI format for the links that reach a
codec and a primary bclk ratio of 125, which the codec's PLL table
accepts. The speaker back-end has no sense lines and no amplifier
controls; the volume is the CPU DAI's software gain, held 20 dB down
by the lock until a protection daemon takes it.

Compile-tested only; not run on hardware. The jack link was brought
up with the codec driven by a non-standard register setting (a half
SCLK frame delay and the SDOUT edge flipped under a normal bit
clock); the inverted-bit-clock description is the standard form of
that timing and needs confirming on the machine.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The entry already lists the driver's binding; add the driver itself.

Assisted-by: LLM checkpatch
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide RyanTheTide changed the title ASoC: apple: clean J700 AOP audio and routing ASoC: apple: T8140 (J700) AOP audio and macaudio routing (reworked, 12 patches) Sep 25, 2026
@RyanTheTide
RyanTheTide force-pushed the series/neo-audio-after-codec-20260924 branch from 68fcd84 to 90a8bea Compare September 25, 2026 16:26
@RyanTheTide
RyanTheTide marked this pull request as ready for review September 25, 2026 16:27
@RyanTheTide
RyanTheTide merged commit 671ad26 into aurora-wip Sep 25, 2026
@RyanTheTide
RyanTheTide deleted the series/neo-audio-after-codec-20260924 branch September 26, 2026 12:44
cb2206 pushed a commit to cb2206/linux that referenced this pull request Oct 5, 2026
…-reliability-20260927

Backport Eryk M3 GPU reliability fixes onto latency3
DjDeveloperr pushed a commit that referenced this pull request Oct 15, 2026
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