diff mbox series

[alsa-lib,2/3] mixer: Add exception for non " Volume" suffixed capture vol-ctls used in ASoC realtek codec drivers

Message ID 20210224100551.15141-2-hdegoede@redhat.com
State Superseded
Headers show
Series [alsa-lib,1/3] mixer: Unify simple_none: base_len() exception handling | expand

Commit Message

Hans de Goede Feb. 24, 2021, 10:05 a.m. UTC
The following ASoC codec drivers:

sound/soc/codecs/rt5640.c
sound/soc/codecs/rt5645.c
sound/soc/codecs/rt5651.c
sound/soc/codecs/rt5677.c

Use capture-volume-control names like: "IN1 Boost", note the missing
" Volume" suffix. This causes the mixer code to not identify these as
volume-controls, which causes some of the dB related sm_elem_ops to
return -EINVAL.

This in turn causes alsamixer to not show dB info and causes UCM profile
HW volume control support in pulseaudio to not work properly due to the
lacking dB scale info.

This cannot be fixed on the kernel side because the non " Volume" suffixed
names are used in UCM profiles currently shipping in alsa-ucm-conf.

Add some code to the base_len() function, which is responsbile for
getting the control-type to deal with these special cases.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 src/mixer/simple_none.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 7da7de1e..262e3516 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -905,13 +905,29 @@  static const struct suf {
 	{" Volume", CTL_GLOBAL_VOLUME},
 	{NULL, 0}
 };
+
+/*
+ * Some kernel drivers use mixer-element names for capture-volumes which
+ * are not suffixed with " Capture Volume". This cannot be fixed on the
+ * kernel side because the non-suffixed names are used in UCM profiles,
+ * so we map these to CTL_CAPTURE_VOLUME based on their full name.
+ */
+const char * const capture_volume_names[] = {
+	"ADC Boost Gain",
+	"IN1 Boost",
+	"IN2 Boost",
+	"IN3 Boost",
+	NULL
+};
 #endif
 
 /* Return base length */
 static int base_len(const char *name, selem_ctl_type_t *type)
 {
-	const struct suf *p;
 	size_t nlen = strlen(name);
+	const struct suf *p;
+	char buf[32];
+	int i;
 
 	/* exception: "Capture Volume" and "Capture Switch" */
 	if (!strcmp(name, "Capture Volume")) {
@@ -923,6 +939,13 @@  static int base_len(const char *name, selem_ctl_type_t *type)
 		return strlen("Capture");
 	}
 
+	for (i = 0; capture_volume_names[i]; i++) {
+		if (!strcmp(name, capture_volume_names[i])) {
+			*type = CTL_CAPTURE_VOLUME;
+			return nlen;
+		}
+	}
+
 	p = suffixes;
 	while (p->suffix) {
 		size_t slen = strlen(p->suffix);