Skip to content

ASoC: cs42l84: report the jack as it is at attach and after a sleep - #2112

Draft
LiamRay11 wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
LiamRay11:j804/cs42l84-jack
Draft

LiamRay11 wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
LiamRay11:j804/cs42l84-jack

Conversation

@LiamRay11

Copy link
Copy Markdown

Summary

cs42l84 learns of a plug only from a plug-sense interrupt that acts on a change. That leaves the jack reported wrong in three cases:

  • headphones already in at boot
  • a plug or unplug during a sleep that keeps the codec powered (s2idle)
  • a plug that does not stay seated during headset detection

b91208392 ("Bring the codec back after a firmware sleep") already re-detects after a firmware sleep that resets the codec. This PR covers the other cases. It is generic, with no machine gate.

Changes

  1. Move the plug/unplug bodies of the IRQ thread into cs42l84_handle_plug() / cs42l84_handle_unplug(). No functional change.

  2. If detection is invalidated because the tip did not stay plugged, treat it as an unplug: HSBIAS off, hs_type 0, jack reported empty, ring IRQs stay masked. Previously the report stayed "plugged" with nothing in the jack. The ring check now also runs only while the tip is plugged.

  3. cs42l84_sync_plug() reads the tip sense once and runs the IRQ's own path if it disagrees with the driver state. It is called:

    • from set_jack before the first report
    • from a work item on system_freezable_wq that resume queues when the codec kept power

    Suspend cancels a pending check. Everything runs under irq_lock.

Testing

On hardware: MacBook Pro 14-inch (M6, J804), 2026-11-16, tested by LiamRay11.

  • What ran: kernel 7.3.0 built from integration/aurora bf423bf0e with all nine J804 linux PRs merged (t8152-mailboxes, dart-gen3, dt-board, centauri, g18-fast-retire, cfg80211-stale-scan, smc, cs42l84-jack, and an NVMe PR that is not sent yet), plus retest-only device-tree changes that are not part of these PRs: SSD nodes (ANS mailbox, SART, NVMe), PCIe port 0 with the N1 Wi-Fi, the USB0 gadget console, and a read-only NVRAM partition. Those nodes were needed to reach the root filesystem and SSH.
  • Booted through aura on the installed root filesystem. A systemctl reboot from this kernel (watchdog restart) returned to the installed system.

Results for this PR (draft): not run. The change was built into the retest kernel, but the jack codec is disabled in that tree and the plug test needs the owner at the machine, so it was not run. This stays a draft until it is.

  • Earlier, on an older base (integration/aurora f5fa539) with an earlier version of this change, from before the reconciliation with upstream b912083: booted without headphones, the attach check reads the tip unplugged and does nothing more. No new kernel warnings.
  • Not yet tested on hardware: a real plug/unplug, headphones in at boot, and a lid sleep with something in the jack.
  • Checks on this base: sound/soc/codecs/cs42l84.o with W=1 builds without warnings.

integration/aurora has since moved to 677be395b; this branch still merges into it without conflicts.

Notes

This affects every Mac with a CS42L84. A test on another machine (for example an M2/M3 laptop) would be welcome.

Dependencies

None.

🤖 Generated with Claude Code

LiamRay11 and others added 3 commits November 16, 2026 08:41
Move the bodies of the tip plug and unplug cases of cs42l84_irq_thread()
into cs42l84_handle_plug() and cs42l84_handle_unplug(), so that the
following changes can run them outside the interrupt as well. The
register writes, their order and the debug messages are unchanged.

No functional change.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the tip sense no longer reads plugged after headset detection,
the plug path sets tip_state back to unplugged and turns HSBIAS off,
but keeps hs_type and the jack report that detection just made, and
then unmasks the ring sense interrupts. If the tip then settles
unplugged, the next tip interrupt sees no change against tip_state and
does nothing, so the jack stays reported as plugged with nothing in
it. A ring interrupt in that state, or the no-change tip interrupt
falling through to the ring check, runs headset detection again with
the jack empty.

Treat the invalidated detection as an unplug: turn HSBIAS off, clear
hs_type, report the jack empty and leave the ring interrupts masked.
If the tip then settles plugged, its interrupt is a change and
detects again, as before. Also run the ring check only while the tip
is plugged: with the tip unplugged or in transition there is nothing
to detect.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The driver learns of a plug only from its plug interrupt, which acts
on a change of the tip sense against the state saved at probe. That
leaves the jack reported wrongly in two cases:

  - Headphones already in at boot. The probe saves the tip as plugged,
    no headset detection runs and hs_type stays 0, so set_jack reports
    the jack empty until the plug is pulled and pushed in again.

  - A plug or unplug during a sleep that leaves the codec powered
    (suspend-to-idle). The interrupt is not a wake source and nothing
    reads the tip sense again on resume, so headphones pulled out
    while asleep still read plugged afterwards. A sleep that puts the
    codec in reset already detects again on resume.

Add cs42l84_sync_plug(), which reads the tip sense once and runs the
interrupt's own plug or unplug path when it disagrees with the
driver's state. It runs under irq_lock, like the interrupt thread, so
an interrupt for the same change finds the state already updated.
Call it from set_jack before the first report, and from a work item
that resume queues on system_freezable_wq when the codec kept its
power, so it runs after every device has resumed without adding the
headset detection to the resume path. Suspend cancels a check that is
still pending.

On a machine booted without headphones this adds one register read
at set_jack and after each such sleep.

Tested on a MacBook Pro (M6, J804), on an earlier base
(integration/aurora f5fa539) with an earlier version of this change:
booted without headphones, the attach check reads the tip unplugged and
does nothing more.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sithglan sithglan 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.

Test report, 2026-11-17: Apple Mac mini M6 (J873g/T8152, board 0x24). PR revision tested: 9396cd421efd94f9573103e5d9597dda86ac6d4f.

Host validation used the combined #2105–2108/#2110–2112 series (54742c617db4 on 677be395b9d2) with Clang 22. All changed driver objects built with W=1 and no new warnings; two pre-existing DART unused-helper warnings were unchanged.

cs42l84.o built with Clang 22 and W=1 with no new warnings. Hardware smoke used this patch plus its existing upstream sleep prerequisite b912083 on the separate M6 test kernel. CS42L84 revision 36 bound successfully at 0-004b; 25 ALSA controls were readable and both jack controls reported off.

Physical insertion/removal, plugged-at-boot detection and jack changes across sleep were not exercised. This is attach/control smoke coverage, not full qualification of the jack-state fix.

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