Skip to content

ASoC: apple: t8140-aop-audio: hide the internal mics while the lid is closed - #354

Merged
RyanTheTide merged 3 commits into
aurora-wipfrom
j700/clamshell-mic-v4
Oct 17, 2026
Merged

RyanTheTide merged 3 commits into
aurora-wipfrom
j700/clamshell-mic-v4

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

With the lid closed, the MacBook Neo's internal microphones are covered, and they used to keep presenting as the default capture source. This series lets the AOP audio driver report the internal mics as unplugged while the lid is closed, through a standard ALSA jack (Internal Mic Jack). UCM and PipeWire then hide the source and bring it back when the lid opens.

Commits

  1. ASoC: apple: t8140-aop-audio: Publish the LPAI pointer after its frames. This is an ordering fix in the capture path, which the jack work depends on.
  2. rust: helpers: Add spin_lock_irqsave() and spin_unlock_irqrestore(). These are the helpers the lid handler needs to read the input device's switch state under its event lock.
  3. ASoC: apple: t8140-aop-audio: Report the mics unplugged with the lid closed.
    • An input handler follows SW_LID.
    • The state is read under the device's event lock, at connect, at start (after a grab is released) and on every event.
    • The jack is updated from non-reentrant work, and probe reports the initial state before the card registers.

Testing

  • Review: independent, PASS (t-2364). The two carried-over MINORs concern upstream readiness: any SW_LID device counts, and the upstream form of the helper. There are 3 NITs.
  • Rebase: onto aurora-wip f001934351ed. The only conflict was test-module placement next to apple: hardening sweep (AFK/AOP ring bounds, DART flush, DCP, qspi resume) #345's tests; the code is identical to the reviewed patch.
  • MacBook Neo, attended on the reviewed series, with real lid cycles (4 cycles, 3 of them into s2idle):
    • Internal Mic Jack was off whenever the lid was closed and on whenever it was open, in every 1 s sample, within 0.4–1.4 s;
    • the PipeWire mic source was removed and restored every time, after resume too;
    • 0 WARN, 0 AOP/audio/PipeWire errors.
  • KUnit: the lid-jack suite passes 7/7; the AOP audio Rust lane and tipd/atc/lockdep lanes have 0 failures; W=1 gives 0 warnings.
  • Build: the published Neo config builds with 0 warnings.
  • Rebased tree: the Neo build of aurora-wip plus this series and tipd HPD v2 ran unattended overnight (7.1.12-aurora-t2466-g305c3dc9), compared with the default kernel:
    • boot: 0 WARN/BUG and 0 DCP/tipd/ATC/DART errors; Touch ID restored on the first attempt;
    • a passive lid-open check (with nobody there to close the lid): the jack on, the mic source present, 0 AOP/audio/PipeWire errors;
    • every display and sleep leg matched the baseline.

🤖 Generated with Claude Code

The low-power microphone's report path copies a span into the ALSA
buffer and then advances hw_ptr_frames; the .pointer callback returns
that value.  ALSA calls .pointer from a status or HWSYNC request on
another CPU, with the PCM stream lock held but not the driver's stream
state lock, so the copy and the pointer are only ordered by the atomic
itself.  Both sides used relaxed accesses, which order nothing else: on
arm64 a reader can see the new pointer before the frames behind it, and
hand userspace stale buffer contents as captured audio.

Store the pointer with release after the copy, and load it with acquire
in .pointer.  The resets at open and prepare publish a pointer too and
use release as well.  This is the message-passing pattern of the Linux
kernel memory model's MP+pooncerelease+poacquireonce test (forbidden),
where the relaxed form, MP+poonceonces, is allowed.

Fixes: eeb1126 ("ASoC: apple: Add T8140 AOP audio driver")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Rust code that has to take a spinlock owned by C code, one that the C
side takes with interrupts saved, has no way to do so: the helpers only
cover spin_lock() and spin_unlock().  An input handler resynchronizing
with its device's switch state is one such user: the input core
delivers events with dev->event_lock held and interrupts off, and a
handler reading the device's state outside of an event must hold the
same lock.

Add the irqsave/irqrestore pair, returning the flags to the caller.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…closed

Closing the lid of the MacBook Neo (J700) disconnects its internal
microphones in hardware.  Nothing tells the AP: the array then reads
back as digital silence and the low-power microphone as a constant near
negative full scale, and userspace keeps offering both as working
microphones.  A meeting app recording in clamshell mode with an external
display records nothing, and never falls back to a microphone that
works.

The lid switch is already an input device ("Apple SMC power/lid events",
SW_LID, from macsmc-input).  Follow it with an input handler, as
hid-appletb-kbd and the input-events LED trigger follow other input
devices, and report the result as a microphone jack on the card,
"Internal Mic Jack": unplugged while any lid switch reads closed.  The
handler is a passive observer, so it does not open the device on its
own; macsmc-input reports lid changes whether or not it is open.

Every update of a switch's recorded state happens under that device's
event lock: the input core delivers events with it held, and the
handler reads the device's switch state with it held when it connects
(after opening the handle, so no event falls in between) and from its
start() callback, which the input core calls when a client that grabbed
the device releases it.  A reading can therefore never overwrite a newer
event, and events a grabbing client kept to itself are caught up with.
Readings only count once the handle is open: the input core calls
start() while registering the handle, before the handler knows whether
opening it succeeds, and a handle that fails to open is freed without a
disconnect.  A lid switch that goes away no longer counts as closed.
The count of closed switches is the only state shared between switches.

snd_jack_report() takes mutexes and is not ordered against other
callers, so a single work item makes every report, including the
initial one, which probe queues and flushes before registering the
card: reports reach ALSA in the order of the states they read.  The
jack has no input device of its own: the lid it follows already is one,
and the control is what userspace reads.

With UCM naming the jack as the microphone's JackControl, PipeWire and
PulseAudio mark the microphone port unavailable, switch the card's
profile off and fall back to another source; when the lid opens the
profile, the node and the user's default source come back.  Without
such a JackControl nothing changes.

[ryan: rebased onto aurora-wip 0daed2d + ATC PIPE park v3. #345
 (harden-all) added the parser_tests and name_tests KUnit modules at the
 end of t8140_aop_audio.rs, where this patch adds lid_tests: kept both,
 lid_tests last. The added lines are those of the reviewed patch.]
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit e38968d into aurora-wip Oct 17, 2026
@RyanTheTide
RyanTheTide deleted the j700/clamshell-mic-v4 branch October 17, 2026 14:23
RyanTheTide added a commit that referenced this pull request Oct 17, 2026
Bring the 7.2.10 assembly to the tree of the canonical top-up #7
assembly, stacked on top-up #6a 40a2ec8 so that it is a
fast-forward of that publish head. The second parent is that canonical
assembly; the tree is identical to it.

Ported from aurora-wip, each commit with cherry-pick -x and its
original author:
- #306: aurora_j700_defconfig, regenerated for 7.2.10 with savedefconfig
  from the published 7.2.10 J700 configuration (900-config-tooling);
- #354 (j700/clamshell-mic-v4), 3 commits: the LPAI pointer published
  after its frames, the spin_lock_irqsave() Rust helpers, and the mics
  reported unplugged with the lid closed (070-audio);
- #355 (j700/tipd-hpd-pulse-v2), 9 commits: the CD321x DisplayPort
  hotplug decisions, their trace events and KUnit tests (170-usb), and
  the apple-dcp selftests that compile them (200-dcp);
- #356 (fix/rust-dmabuf-xarray-20261018): the dma_buf stub gated on
  built-in DRM and the xarray KUnit values allocated before xa_lock
  (210-gpu, with the Fixes: tags of the 7.2.10 base); its dma-resv
  backport is already in asahi-wip;
- #357 (fix/sep-followups-20261018), 7 commits: dma_wmb()/dma_rmb() for
  Rust, the SEP shared buffers ordered against the mailbox, the hwrng
  and sleep glue and its tests, and the trusted-keys built-in source
  fixes (100-sep).

Our own 7.2-native commits, not on aurora-wip (100-sep): the Rust
system_dfl_wq wrapper, and the SEP, Asahi DRM and binder work moved
off the deprecated system_wq. Their AOP change is not carried: the
070-audio AOP driver already registers its services on its own
ordered queue.

Adaptations, each with a [ryan: ...] note in its commit:
- the AOP lid tests go after the parser tests, where 7.2.10 has the
  name tests (context only);
- trusted_key_core_done goes next to 7.2.10's
  trusted_key_source_migratable (context only);
- the defconfig is regenerated, not picked; its note lists the 62
  lines that differ from the 7.1 file, none of them a J700 setting.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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