Skip to content

ASoC: cs42l42/cs42l84: Apple headset remote (vol up/down, play/pause) - #9

Merged
RyanTheTide merged 4 commits into
aurora-wipfrom
remote/cs42l84-apple-headset-remote
Sep 25, 2026
Merged

RyanTheTide merged 4 commits into
aurora-wipfrom
remote/cs42l84-apple-headset-remote

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Adds Apple wired-headset remote support (centre button = play/pause, plus volume up/down) across both Cirrus codec families used on Apple Silicon Macs, reported through ALSA as ordinary jack button/key events.

  1. cs42l42: handle jack interrupt I/O and resume errors: checks every snapshot read and the runtime-PM acquisition in cs42l42_irq_thread(). It uses RPM_TRANSPARENT because the I2C transport never enables runtime PM.
  2. cs42l42: CS42L83 remote: identifies the remote over the mic-bias line, then decodes its button pulses from interrupts. If identification fails, the analogue detector takes over.
  3. cs42l84: CS42L84 remote: these status bits are undocumented and were characterised at register level on a running CS42L84. They are polled while a headset is attached, because the chip has no known interrupt for them.
  4. macaudio: maps SND_JACK_BTN_0..3 to KEY_PLAYPAUSE / KEY_VOLUMEUP / KEY_VOLUMEDOWN / KEY_VOICECOMMAND on the headphone jack.

Should work on (codec confirmed): every M1/M2/M3 Mac, M4 (Mac Mini + MacBook Air), M4 Max (MacBook Pro), M5 (MacBook Air), and M5 Pro (MacBook Pro). CS42L83 = M1 generation (t8103) + MacBook Neo. CS42L84 = everything else above.

Unknown (codec unconfirmed): M4 Pro (same board family as the M4 Max), M5 Max (same board family as the M5 Pro).

@RyanTheTide
RyanTheTide force-pushed the remote/cs42l84-apple-headset-remote branch 2 times, most recently from 62f8c8c to ffa3944 Compare September 23, 2026 12:07
A failed status or mask read leaves part of the interrupt snapshot
uninitialized, and the handler can then interpret that data as headset
or button events. It also carries on with register access after a
failed runtime resume.

Check the runtime-PM acquisition and each snapshot read before
processing any events, returning IRQ_NONE otherwise and logging failed
reads. Acquire the device with RPM_TRANSPARENT: the I2C transport never
enables runtime PM, and a plain pm_runtime_resume_and_get() would fail
with -EACCES there and drop every jack interrupt. Release the IRQ mutex
and PM reference on every exit path through a single error label.
Should the codec stop responding altogether, IRQ_NONE lets the
spurious-interrupt detector disable the level-triggered line instead of
leaving it storming.

Fixes: 2c394ca ("ASoC: Add support for CS42L42 codec")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Apple wired headset volume buttons use a microphone-bias signalling
protocol instead of the resistor levels handled by the analogue detector.
The CS42L83 can identify these remotes and decode their button indications
without an audio stream or an external serial clock.

After CTIA or OMTP detection, perform a bounded identification exchange on
CS42L83. Wait for the receive acknowledgment rather than the earlier
transmit-complete indication, which can expose an incomplete identifier.
Validate all three identifier symbols before enabling remote reception.
Restore the analogue detector on timeout, a short, an invalid identifier,
or a register-access error.

Preserve the receiver's raw volume indications before applying the
analogue interrupt masks. Report volume indications as press/release
pairs and use short-detect transitions for the centre button. Discard
pre-identification button state, and clear events latched while the
detector is reconfigured before unmasking its interrupts again. Restore
the saved detector settings on unplug, redetection and suspend under the
existing IRQ mutex, releasing any remote button still held.

Select this capability from the CS42L83 device identity. No board-specific
property, clock provider, work item or extra power reference is needed.
The CS42L42 continues to use its analogue detector.

The undocumented CS42L83 sequence was independently implemented from
register-level reverse engineering and validated on a J700 with a B0
codec and Apple wired earbuds. Other boards and codec revisions have not
been hardware-tested. The machine driver must expose the appropriate
SND_JACK_BTN capabilities and key mappings.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Apple wired headset volume buttons and the centre play/pause button
use a microphone-bias signalling protocol rather than the CTIA/OMTP
resistor levels used for plug-type detection. The CS42L84 already
exposes status bits for this over its microphone-detect block, but
they are undocumented, unlike CS42L83's, and CS42L84 raises no known
interrupt for them.

Poll CS42L84_REMOTE_BUTTON_STATUS1 and the short-detect bit of
HS_DET_STATUS2 at a fixed cadence while a mic-equipped headset is
attached, and report press/release pairs on each rising edge,
matching how the preceding CS42L83 patch reports its volume pulses.
The centre button is therefore reported as a momentary press; a long
press is not distinguished. The first sample after polling starts only
establishes a baseline, so a line that is already shorted at detection
is not reported as a press.

Start polling once plug detection has settled and stop it on unplug
or redetection, guarded by the same irq_lock used elsewhere for
plug-state transitions. The poll runs on the freezable workqueue so it
does not access the codec across system suspend, and is registered as
resource-managed delayed work so it is cancelled if probe fails after
a plug interrupt has already started it.

The undocumented CS42L84 bits were identified by reverse engineering
against a running CS42L84 on a J316 (MacBook Pro 16"), reading raw
register state live via I2C while triggering the remote's buttons,
and cross-checking candidate bits against the equivalent CS42L83
mechanism.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
CS42L83 and CS42L84 now decode Apple wired-headset remote presses (see
the preceding cs42l42 and cs42l84 patches) and report them as
SND_JACK_BTN_0..2 on the codec's jack. When CS42L83 falls back to its
analogue detector for other headsets, it can also report SND_JACK_BTN_3.

Request those bits on the headphone jack and map them to the usual keys
so userspace sees ordinary input events: centre button to
KEY_PLAYPAUSE, volume up/down to KEY_VOLUMEUP and KEY_VOLUMEDOWN, and a
fourth button to KEY_VOICECOMMAND, matching other CS42L42-family
machine drivers.

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