Skip to content

Commit fcd6a3b

Browse files
pgratz1claude
andcommitted
RK3576: Switch audio to DP sink on Alt Mode connection
When a DP Alt Mode display is connected, save the current PipeWire default sink and switch to the DP audio sink (identified by the DP controller address 27e40000 in the PipeWire sink node name). Restore the saved sink on disconnect. The DP audio sink is created automatically at kernel probe time by the DRM_BRIDGE_OP_DP_AUDIO framework (hdmi-audio-codec platform device). The exact PipeWire sink name may need adjustment after first-boot testing, but the 27e40000 pattern should match it uniquely since the internal ES8388 codec is on a different bus address. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 44901a7 commit fcd6a3b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • projects/ROCKNIX/packages/sysutils/system-utils/sources/scripts

projects/ROCKNIX/packages/sysutils/system-utils/sources/scripts/dp_monitor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ls /sys/class/drm/card*-DP-* /sys/class/drm/card*-HDMI-A-* 2>/dev/null | grep -q . || exit 0
1818

1919
_LAST_STATE="init"
20+
_SAVED_AUDIO_SINK=""
2021

2122
_get_active_externals() {
2223
wlr-randr 2>/dev/null | awk '
@@ -30,6 +31,13 @@ _get_all_internals() {
3031
wlr-randr 2>/dev/null | awk '/^(DSI|eDP|LVDS)-/ { print $1 }'
3132
}
3233

34+
# Returns the PipeWire sink for DP audio (hdmi-audio-codec on 27e40000.dp).
35+
# The sink node name includes the DP controller address after the framework
36+
# creates an hdmi-audio-codec platform device at probe time.
37+
_get_dp_audio_sink() {
38+
pactl list short sinks 2>/dev/null | awk '/27e40000/ { print $2; exit }'
39+
}
40+
3341
_apply() {
3442
local state="internal"
3543
[ -n "$(_get_active_externals)" ] && state="external"
@@ -48,12 +56,20 @@ _apply() {
4856
fi
4957
# Stop USB gadget: its data lanes conflict with DP Alt Mode on RK3576
5058
systemctl is-active --quiet usbgadget && systemctl stop usbgadget
59+
# Switch audio output to DP sink; save current default to restore later
60+
local dp_sink
61+
_SAVED_AUDIO_SINK=$(pactl get-default-sink 2>/dev/null || true)
62+
dp_sink=$(_get_dp_audio_sink)
63+
[ -n "$dp_sink" ] && pactl set-default-sink "$dp_sink" 2>/dev/null || true
5164
else
5265
# Only re-enable internal panels on actual disconnect, not first-boot
5366
if [ "$prev" != "init" ]; then
5467
while IFS= read -r out; do
5568
wlr-randr --output "$out" --preferred --on 2>/dev/null
5669
done < <(_get_all_internals)
70+
# Restore saved audio sink
71+
[ -n "$_SAVED_AUDIO_SINK" ] && pactl set-default-sink "$_SAVED_AUDIO_SINK" 2>/dev/null || true
72+
_SAVED_AUDIO_SINK=""
5773
fi
5874
fi
5975

0 commit comments

Comments
 (0)