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

@@ -1,27 +1,27 @@
SectionDevice."Earpiece" {
Comment "Earpiece playback"
Comment "Earpiece playback"
ConflictingDevice [
"Headphones"
]
ConflictingDevice [
"Speaker"
"Headphones"
]
EnableSequence [
cset "name='RX1 MIX1 INP1' RX1"
cset "name='RDAC2 MUX' RX1"
cset "name='EAR_S' 1"
## gain to +6dB
cset "name='RX1 Digital Volume' 90"
]
EnableSequence [
cset "name='RX1 MIX1 INP1' 'RX1'"
cset "name='RDAC2 MUX' 'RX1'"
cset "name='EAR_S' 1"
cset "name='RX1 Digital Volume' 90"
]
DisableSequence [
cset "name='RX1 Digital Volume' 0"
cset "name='EAR_S' 0"
cset "name='RX1 MIX1 INP1' ZERO"
]
DisableSequence [
cset "name='RX1 Digital Volume' 0"
cset "name='EAR_S' 0"
cset "name='RX1 MIX1 INP1' 'ZERO'"
]
Value {
PlaybackPCM "${var:WcdPlaybackPCM}"
PlaybackChannels 2
PlaybackPriority 100
}
Value {
PlaybackPCM "${var:WcdPlaybackPCM}"
PlaybackChannels 2
PlaybackPriority 200
}
}
@@ -0,0 +1,33 @@
SectionDevice."Headphones" {
Comment "Headphones playback"
ConflictingDevice [
"Speaker"
"Earpiece"
]
EnableSequence [
cset "name='RX1 MIX1 INP1' 'RX1'"
cset "name='RX2 MIX1 INP1' 'RX2'"
cset "name='RDAC2 MUX' 'RX2'"
cset "name='HPHL' 1"
cset "name='HPHR' 1"
cset "name='RX1 Digital Volume' 84"
cset "name='RX2 Digital Volume' 84"
]
DisableSequence [
cset "name='RX1 Digital Volume' 0"
cset "name='RX2 Digital Volume' 0"
cset "name='HPHL' 0"
cset "name='HPHR' 0"
cset "name='RX1 MIX1 INP1' 'ZERO'"
cset "name='RX2 MIX1 INP1' 'ZERO'"
]
Value {
PlaybackPCM "${var:WcdPlaybackPCM}"
PlaybackChannels 2
PlaybackPriority 250
}
}
@@ -0,0 +1,27 @@
SectionDevice."Headset" {
Comment "Headset Microphone"
ConflictingDevice [
"Mic1"
]
EnableSequence [
cset "name='DEC1 MUX' 'ADC2'"
cset "name='CIC1 MUX' 'AMIC'"
cset "name='ADC2 Volume' 8"
cset "name='ADC2 MUX' 'INP2'"
cset "name='TX1 Digital Volume' 88"
]
DisableSequence [
cset "name='ADC2 MUX' 'ZERO'"
cset "name='ADC2 Volume' 0"
cset "name='DEC1 MUX' 'ZERO'"
]
Value {
CapturePCM "${var:WcdCapturePCM}"
CaptureChannels 2
CapturePriority 300
}
}
@@ -0,0 +1,25 @@
SectionDevice."Mic1" {
Comment "Primary Microphone"
ConflictingDevice [
"Headset"
]
EnableSequence [
cset "name='DEC1 MUX' 'ADC1'"
cset "name='CIC1 MUX' 'AMIC'"
cset "name='ADC1 Volume' 8"
cset "name='TX1 Digital Volume' 88"
]
DisableSequence [
cset "name='DEC1 MUX' 'ZERO'"
cset "name='ADC1 Volume' 0"
]
Value {
CapturePCM "${var:WcdCapturePCM}"
CaptureChannels 2
CapturePriority 400
}
}
@@ -1,27 +1,26 @@
SectionDevice."Speaker" {
Comment "Speaker playback"
Comment "Speaker playback"
ConflictingDevice [
"Headphones"
"Earpiece"
]
ConflictingDevice [
"Earpiece"
"Headphones"
]
EnableSequence [
cset "name='SPK DAC Switch' 1"
cset "name='RX3 MIX1 INP1' RX1"
## gain to +8dB
cset "name='RX3 Digital Volume' 92"
]
EnableSequence [
cset "name='RX3 MIX1 INP1' 'RX1'"
cset "name='SPK DAC Switch' 1"
cset "name='RX3 Digital Volume' 88"
]
DisableSequence [
cset "name='RX3 Digital Volume' 0"
cset "name='SPK DAC Switch' 0"
cset "name='RX3 MIX1 INP1' ZERO"
]
DisableSequence [
cset "name='RX3 Digital Volume' 0"
cset "name='SPK DAC Switch' 0"
cset "name='RX3 MIX1 INP1' 'ZERO'"
]
Value {
PlaybackPCM "${var:WcdPlaybackPCM}"
PlaybackChannels 2
PlaybackPriority 200
}
Value {
PlaybackPCM "${var:WcdPlaybackPCM}"
PlaybackChannels 2
PlaybackPriority 300
}
}
@@ -152,8 +152,7 @@ finish() {
fi
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
if ! is_call_picked_up; then
amixer -c 0 cset "name='RX3 Digital Volume'" "$SAVED_RX3" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SAVED_SPK_VOL}%" >/dev/null 2>&1 || true
sxmo_audio.sh device apply >/dev/null 2>&1 || true
fi
exit 0
}
@@ -170,8 +169,7 @@ ring() {
if [ "${SXMO_RINGVOL:-100}" -le 0 ] || [ -z "${SXMO_RINGTONE:-}" ] || [ ! -f "$SXMO_RINGTONE" ]; then
return 0
fi
ring_rx3=$(( 60 + SXMO_RINGVOL * 24 / 100 ))
pw_vol="$(awk -v v="$SXMO_RINGVOL" 'BEGIN { printf "%.2f", v / 100.0 }')"
ring_rx3=$(( 56 + (SXMO_RINGVOL * 32 + 50) / 100 ))
(
rchild=""
@@ -187,7 +185,7 @@ cset "name='RX3 MIX1 INP1'" 3
cset "name='RX3 Digital Volume'" $ring_rx3
EOF
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
(
for d in 0.15 0.40; do
@@ -198,7 +196,7 @@ cset "name='SPK DAC Switch'" 1
cset "name='RX3 MIX1 INP1'" 3
cset "name='RX3 Digital Volume'" $ring_rx3
EOF
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
done
) &
vhelper="$!"
@@ -217,8 +215,8 @@ EOF
while [ "$i" -lt "$loops" ]; do
should_stop_ringing && break
amixer -c 0 cset "name='RX3 Digital Volume'" "$ring_rx3" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
pw-play --volume="$pw_vol" "$SXMO_RINGTONE" >/dev/null 2>&1 &
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
pw-play --volume=1.0 "$SXMO_RINGTONE" >/dev/null 2>&1 &
rchild="$!"
wait "$rchild" 2>/dev/null
rc="$?"
@@ -239,7 +237,7 @@ EOF
if [ "$use_pw" -eq 0 ] && ! should_stop_ringing; then
mpv --no-config --no-terminal --no-resume-playback --quiet --vo=null --no-video \
--ao=pipewire,pulse,alsa --audio-channels=stereo --audio-samplerate=48000 \
--volume-max=150 --volume="$SXMO_RINGVOL" \
--volume-max=100 --volume=100 \
--loop="$loops" "$SXMO_RINGTONE" </dev/null >/dev/null 2>&1 &
rchild="$!"
wait "$rchild" 2>/dev/null || true
@@ -47,20 +47,7 @@ if [ -z "$SXMO_NO_AUDIO" ]; then
superctl start sxmo_soundmonitor
(
sleep 1
spk_vol=100
if [ -r "$XDG_CONFIG_HOME/sxmo/speaker_vol" ]; then
read -r spk_vol < "$XDG_CONFIG_HOME/sxmo/speaker_vol" 2>/dev/null || spk_vol=100
fi
case "$spk_vol" in ''|*[!0-9]*) spk_vol=100 ;; esac
if [ "$spk_vol" -le 0 ]; then
amixer -c 0 cset "name='RX3 Digital Volume'" 0 >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ 0% >/dev/null 2>&1 || true
else
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
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${spk_vol}%" >/dev/null 2>&1 || true
fi
sxmo_audio.sh device apply >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
) &
fi