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
Contributor

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2.

  1. All three commits (3142536, 742f75f, 9396cd4) carry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>. Commits should carry only the human author and their Signed-off-by. Drop the trailer from each commit, push the result as a new branch and open a new PR (no force push). Credit the tool with a last line Assisted-by: LLM (Anthropic:Claude Opus 5.5) in the PR body, in place of the current "Generated with Claude Code" footer.
  2. None of the three behaviours this changes has run on hardware: plugged at boot, unplug or plug during s2idle, and the wobbly-plug path at sound/soc/codecs/cs42l84.c:1043-1053. The J804 run had the codec disabled. The J873g report is attach smoke only: both jack controls read off with nothing plugged in. The code fixes a jack that reads wrong, so the proof has to be a jack that reads right with something in it.

Code checked and sound: detect_hs always sets hs_type non-zero (cs42l84.c:949/962), so the hs_type == 0 test in cs42l84_sync_plug (:1155) does mean "never detected". The IRQ is requested (:1295) before the component registers (:1340), so the attach check in set_jack (:319) runs with the thread live and under irq_lock. Remove cancels the resume work before the remote poll, which matters because detection can start the poll (:1367-1369). Suspend cancels the work while freezable tasks are already frozen, so it never races a running check. The firmware-sleep resume path is unchanged.

HW row: MacBook Pro J804 (M6), plus one M2/M3 CS42L84 laptop, on this head with default bootargs. In each case amixer -c0 cget on both jack controls plus evtest jack events must match the plug: (a) boot with headphones in, then with a headset in; (b) unplug during s2idle, and plug in during s2idle; (c) a half-seated plug pulled out during detection, with the jack reading empty afterwards. Also 0 AVC, 0 failed units, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Since this branch was cut, #1895 (2f122e3) added ring-sense plug detection selected by cirrus,ring-sense-detect: tip sense is masked and cs42l84_irq_thread takes the plug state from ring sense. The branch still merges without textual conflicts, but cs42l84_sync_plug() reads only the tip-sense status, so on a ring-detect board the attach and resume checks would act on the masked signal. Please rebase onto integration/aurora and give sync_plug() the same ring-sense path as the IRQ thread. The hardware row with a plug inserted could then include one ring-detect board as well.

@RyanTheTide

Copy link
Copy Markdown
Contributor

The jack state refresh at attach and resume is still needed. Head 9396cd421efd replays cleanly onto integration/aurora 5441428d9033, and cs42l84.o builds for arm64. The earlier review still applies: the refresh must also read ring sense on configurations that use it.

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

cs42l84_handle_plug() expands the post-detection status read from the IRQ path to jack attach and resume. That read can fail, and in that case its output does not give a tip state. Please handle the read error explicitly. The driver should unwind the tentative headset detection, keep ring IRQs masked and preserve an unsettled tip state so the next valid event can reconcile it.

A host test of the exact helper passed stable plug and unplug but failed the read-error case. With an explicit error branch that reports the tentative detection as cleared and leaves the tip in transition, all three passed. This exercises the source-level state decision. A jack inserted before probe and a plug/unplug during retained s2idle still need physical CS42L84 rows.

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.

3 participants