Skip to content

Fix HP_OUT in standalone association selected as default output when disconnected#16

Merged
SergeySlice merged 1 commit intoCloverHackyColor:mainfrom
rdmitry0911:main
Mar 19, 2026
Merged

Fix HP_OUT in standalone association selected as default output when disconnected#16
SergeySlice merged 1 commit intoCloverHackyColor:mainfrom
rdmitry0911:main

Conversation

@rdmitry0911
Copy link
Contributor

Summary

On codecs where the headphone pin is in its own association (hpredir=-1, e.g. ALC897 on Gigabyte Z390 AORUS MASTER), switchHandler previously skipped it entirely. This left HPHN_ENABLE set in the pin control register regardless of whether headphones are physically present. macOS interprets HPHN_ENABLE as "headphones connected" and selects that PCM device as the default output on every reboot — even when no headphones are plugged in.

Root cause (from user dump analysis)

  • Codec: Realtek ALC897 (0x10ec0897)
  • NID 27 (Headphones, front panel): as=7, hpredir=-1 — standalone association, skipped by existing switchHandler loop
  • NID 20 (External Speaker): as=1, separate association
  • At init, NID 27 gets pin ctrl = 0xC0 (HPHN_ENABLE | OUT_ENABLE) unconditionally → macOS selects Headphones as default output

Fix

Add a second loop in switchHandler that processes HP_OUT pins in standalone associations (hpredir < 0):

  • Reads actual presence detection from hardware
  • Clears HPHN_ENABLE when no headphones are inserted → macOS does not see headphones and keeps External Speaker as default
  • Sets HPHN_ENABLE when headphones are present, and calls hpSwitchHandler to mute/unmute other output associations (e.g. external speakers)
  • Applied to both tranc and branches/zdev

Test plan

  • Boot without headphones connected → External Speaker remains the default output
  • Reboot without headphones → External Speaker still selected, no regression
  • Plug in headphones → Headphones become active, External Speaker muted
  • Unplug headphones → External Speaker restored
  • Boot with headphones connected → Headphones selected as default

🤖 Generated with Claude Code

On codecs where the headphone pin lives in its own association
(hpredir=-1, e.g. ALC897 on Gigabyte Z390 AORUS MASTER), switchHandler
previously skipped it entirely, leaving HPHN_ENABLE set in the pin
control register regardless of whether headphones are physically present.
macOS interprets HPHN_ENABLE as "headphones connected" and selects that
PCM device as the default output on every reboot.

Add a second loop in switchHandler that processes HP_OUT pins in
standalone associations: reads presence detection, clears HPHN_ENABLE
when no headphones are inserted, and calls hpSwitchHandler to
mute/unmute other output associations (e.g. external speakers)
accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SergeySlice SergeySlice merged commit 601ff6d into CloverHackyColor:main Mar 19, 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.

2 participants