Implement headphone autodetection, earpiece routing, and linear volume controls

- Fix msm8916-wcd ALSA UCM2 configs (Earpiece.conf, Speaker.conf,
  Headphones.conf, PrimaryMic.conf, HeadsetMic.conf) so Speaker,
  Earpiece, and Headphones outputs and Mic1/Headset inputs are always
  available and mutually exclusive without invalid mixer controls
- Add event-driven wired headphone/headset jack detection and automatic
  audio routing in sxmo_soundmonitor.sh via evtest on the msm8916
  Headset Jack input device
- Make Earpiece, Speaker, and Headphones first-class routable output
  devices across sxmo_audio.sh, sxmo_modemaudio.sh, xdrawer, dmenu, and
  callscreen
- Make volume controls strictly linear across all channels by keeping
  PipeWire software gain at unity (100%) when unmuted and linearly
  mapping 0-100% to hardware digital volume registers (RX3 for Speaker,
  RX1 for Earpiece, RX1+RX2 for Headphones, TX1+ADC for Microphone)
This commit is contained in:
Luxferre committed 2026-10-29 20:42:26 +02:00
1 parent e42eb573ed
commit 370f8b085c
33 files changed
+1351 -488

No files matched your search

+36 -41
View File
@@ -5,66 +5,61 @@ export PATH="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/hooks:/usr/share/sxmo/defaul
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo"
enable_call_audio_mode() {
pactl set-card-profile alsa_card.comprC0 off >/dev/null 2>&1 || true
pactl set-card-profile alsa_card.platform-7702000.sound "HiFi (Earpiece, Mic1)" >/dev/null 2>&1 || true
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
printf "1\n" > /tmp/sxmo_in_call 2>/dev/null || true
# If wired headphones are plugged in or currently routed, keep call audio on Headphones;
# otherwise route voice call audio to Earpiece by default.
cur_out="$(sxmo_audio.sh device get 2>/dev/null || printf "Speaker")"
jack_plugged=0
if [ -r /tmp/sxmo_jack_plugged ]; then
read -r jack_plugged < /tmp/sxmo_jack_plugged 2>/dev/null || jack_plugged=0
fi
if [ "$jack_plugged" = "1" ] || [ "$cur_out" = "Headphones" ]; then
target_out="Headphones"
else
target_out="Earpiece"
fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cset "name='SPK DAC Switch'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 MIX1 INP1'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 Digital Volume'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 MIX1 INP1'" 'RX1' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RDAC2 MUX'" 'RX1' >/dev/null 2>&1 || true
amixer -c 0 cset "name='EAR_S'" 'Switch' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 Mute Switch'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 Digital Volume'" 88 >/dev/null 2>&1 || true
amixer -c 0 cset "name='CIC1 MUX'" 'AMIC' >/dev/null 2>&1 || true
amixer -c 0 cset "name='DEC1 MUX'" 'ADC1' >/dev/null 2>&1 || true
amixer -c 0 cset "name='ADC1 Volume'" 8 >/dev/null 2>&1 || true
amixer -c 0 cset "name='TX1 Digital Volume'" 88 >/dev/null 2>&1 || true
fi
sxmo_log "Enabled ALSA voice call audio mode (Earpiece)."
sxmo_log "Enabled ALSA voice call audio mode ($target_out)."
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
return 0
}
disable_call_audio_mode() {
spk_vol=85
if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/speaker_vol" ]; then
read -r spk_vol < "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/speaker_vol" 2>/dev/null || spk_vol=85
fi
case "$spk_vol" in ''|*[!0-9]*) spk_vol=85 ;; esac
[ "$spk_vol" -gt 100 ] && spk_vol=100
rm -f /tmp/sxmo_in_call /tmp/sxmo_call_vol 2>/dev/null || true
pactl set-card-profile alsa_card.comprC0 off >/dev/null 2>&1 || true
if ! pactl list sinks short 2>/dev/null | grep -q "Speaker"; then
pactl set-card-profile alsa_card.platform-7702000.sound "HiFi (Mic1, Speaker)" >/dev/null 2>&1 || true
jack_plugged=0
if [ -r /tmp/sxmo_jack_plugged ]; then
read -r jack_plugged < /tmp/sxmo_jack_plugged 2>/dev/null || jack_plugged=0
fi
if [ "$jack_plugged" = "1" ]; then
target_out="Headphones"
else
target_out="Speaker"
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='EAR_S'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 MIX1 INP1'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 Digital Volume'" 84 >/dev/null 2>&1 || true
amixer -c 0 cset "name='TX1 Digital Volume'" 84 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 MIX1 INP1'" 'RX1' >/dev/null 2>&1 || true
if [ "$spk_vol" -gt 0 ]; then
rx3_hw=$(( 60 + spk_vol * 32 / 100 ))
amixer -c 0 cset "name='SPK DAC Switch'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 Digital Volume'" "$rx3_hw" >/dev/null 2>&1 || true
else
amixer -c 0 cset "name='SPK DAC Switch'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 Digital Volume'" 0 >/dev/null 2>&1 || true
fi
fi
wpctl set-mute @DEFAULT_AUDIO_SINK@ "$([ "$spk_vol" -le 0 ] && echo 1 || echo 0)" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${spk_vol}%" >/dev/null 2>&1 || true
sxmo_log "Disabled ALSA voice call audio mode (Speaker)."
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
sxmo_log "Disabled ALSA voice call audio mode ($target_out)."
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
return 0
}