diff mbox series

[RFC,alsa-ucm-conf] sof-hda-dsp: Use Master mixer to control volume with dual stereo speakers

Message ID 20200703072302.16876-1-benjamin.poirier@gmail.com (mailing list archive)
State New, archived
Headers show
Series [RFC,alsa-ucm-conf] sof-hda-dsp: Use Master mixer to control volume with dual stereo speakers | expand

Commit Message

Benjamin Poirier July 3, 2020, 7:23 a.m. UTC
The Lenovo ThinkPad X1 Carbon 7th is a laptop with two sets of stereo
speakers driven from a single stereo output. The volume of each set of
speakers can be controlled independently through two separate mixers. In
that case, one of those mixers serves a dual purpose: it also controls
headphone volume.

With the current ucm profile, when outputting to speakers, pulseaudio uses
only the mixer for the front speakers to control volume. This is
ineffective; rear speaker volume must be controlled as well. In order to
control both sets of speakers at once, indicate that the Master mixer
should be used.

Moreover, when switching between speaker and headphone outputs, the level
of the dual purpose mixer should be restored. Since this kind of constraint
cannot be described with ucm, indicate that the Master mixer should be used
to control volume instead when outputting to headphones.

This patch depends on a modification to the snd_hda_codec_realtek kernel
driver used on that system to rename one of the controls.

Signed-off-by: Benjamin Poirier <benjamin.poirier@gmail.com>
---

Note that I plan to submit the related kernel patch upstream shortly, in
the meantime, it is available here:
https://github.com/gobenji/thinkpad-x1-gen7-sound

Also note that this patch is based on commit 38e5906cd1b1 ("sof-hda-dsp:
fix the device order (Hdmi devices)"). While testing with libasound built
from alsa-lib git head 485930ea5dc8 ("ucm: substitution - remove duplicate
allow_empty assignment"), alsa-ucm-conf versions including dcef48f13d4f
("HDA-Intel: add support for AMD acp microphone devices") and newer do not
work for me. I've tested up to current head, ffe0cab5cfce ("sof-hda-dsp:
use sof-hda-dsp/Hdmi.conf").
Looking at the output of `pulseaudio --log-level=debug`, things go wrong
at:
I: [pulseaudio] (alsa-lib)main.c: error: failed to import sof-hda-dsp use case configuration -17


 ucm2/sof-hda-dsp/HiFi.conf | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/ucm2/sof-hda-dsp/HiFi.conf b/ucm2/sof-hda-dsp/HiFi.conf
index 62358e2..661a086 100644
--- a/ucm2/sof-hda-dsp/HiFi.conf
+++ b/ucm2/sof-hda-dsp/HiFi.conf
@@ -25,10 +25,22 @@  SectionDevice."Headphones" {
 	Value {
 		PlaybackPriority 200
 		PlaybackPCM "hw:${CardId}"
-		PlaybackMixerElem "Headphone"
 		PlaybackMasterElem "Master"
-		PlaybackVolume "Headphone Playback Volume"
 		PlaybackSwitch "Headphone Playback Switch"
+		If.hpmixer {
+			Condition {
+				Type ControlExists
+				Control "name='Headphone/Bass Speaker Playback Volume'"
+			}
+			True {
+				PlaybackMixerElem "Master"
+				PlaybackVolume "Master Playback Volume"
+			}
+			False {
+				PlaybackMixerElem "Headphone"
+				PlaybackVolume "Headphone Playback Volume"
+			}
+		}
 		If.jack {
 			Condition {
 				Type ControlExists
@@ -77,10 +89,22 @@  SectionDevice."Speaker" {
 	Value {
 		PlaybackPriority 100
 		PlaybackPCM "hw:${CardId}"
-		PlaybackMixerElem "Speaker"
 		PlaybackMasterElem "Master"
-		PlaybackVolume "Speaker Playback Volume"
 		PlaybackSwitch "Speaker Playback Switch"
+		If.spkmixer {
+			Condition {
+				Type ControlExists
+				Control "name='Headphone/Bass Speaker Playback Volume'"
+			}
+			True {
+				PlaybackMixerElem "Master"
+				PlaybackVolume "Master Playback Volume"
+			}
+			False {
+				PlaybackMixerElem "Speaker"
+				PlaybackVolume "Speaker Playback Volume"
+			}
+		}
 	}
 }