All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH alsa-lib v2 0/3] mixer: Volume control fixes
@ 2021-02-28 16:13 Hans de Goede
  2021-02-28 16:13 ` [PATCH alsa-lib v2 1/3] mixer: Unify simple_none: base_len() exception handling Hans de Goede
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Hans de Goede @ 2021-02-28 16:13 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel; +Cc: Hans de Goede

Hi All,

Here is v2 of my series of alsa-lib volume-control fixes which I wrote
while working on adding hw-volume control to UCM profiles for various
x86 ASoC setups.

New in v2 is adding an extra entry to the capture_volume_names array
for the "ADC PGA Gain Volume" control used in the es8316 codec driver
in patch 3/3.

Note that patch 3/3 is not strictly necessary to make hw-volume control
work. At least the PA hw-vol-control code does not care if the controls
are wronly marked as global-volume-controls instead of
capture-volume-controls. I mostly wrote patch 3/3 because for
correctness reasons, so if it is deemed controversial we can drop it.

Regards,

Hans


Hans de Goede (3):
  mixer: Unify simple_none: base_len() exception handling
  mixer: Add exception for non " Volume" suffixed capture vol-ctls used
    in ASoC realtek codec drivers
  mixer: Add exception for some capture-vol-ctls which have a " Volume"
    suffix

 src/mixer/simple_none.c | 83 +++++++++++++++++++++++++++++++----------
 1 file changed, 64 insertions(+), 19 deletions(-)

-- 
2.30.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH alsa-lib v2 1/3] mixer: Unify simple_none: base_len() exception handling
  2021-02-28 16:13 [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
@ 2021-02-28 16:13 ` Hans de Goede
  2021-02-28 16:13 ` [PATCH alsa-lib v2 2/3] mixer: Add exception for non " Volume" suffixed capture vol-ctls used in ASoC realtek codec drivers Hans de Goede
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2021-02-28 16:13 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel; +Cc: Hans de Goede

Unify simple_none: base_len() exception handling:

1. In the "Input Source" and "3D Control" cases the base-name is the same
   as the full-name and base_len() simply returns strlen(name).
   Instead of returning 0 when the type is unknown, set the type to
   CTL_SINGLE and return strlen(name). This allows removing the special
   case for base_len() returning 0 in simple_event_add().

2. Move the special handling for "Capture Volume" and "Capture Switch"
   from simple_event_add() to base_len(), so that we handle all exceptions
   inside base_len(). Instead of handling some special cases in base_len()
   and other special cases in simple_event_add().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 src/mixer/simple_none.c | 43 ++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index e9dc1730..7da7de1e 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -907,11 +907,22 @@ static const struct suf {
 };
 #endif
 
-/* Return base length or 0 on failure */
+/* Return base length */
 static int base_len(const char *name, selem_ctl_type_t *type)
 {
 	const struct suf *p;
 	size_t nlen = strlen(name);
+
+	/* exception: "Capture Volume" and "Capture Switch" */
+	if (!strcmp(name, "Capture Volume")) {
+		*type = CTL_CAPTURE_VOLUME;
+		return strlen("Capture");
+	}
+	if (!strcmp(name, "Capture Switch")) {
+		*type = CTL_CAPTURE_SWITCH;
+		return strlen("Capture");
+	}
+
 	p = suffixes;
 	while (p->suffix) {
 		size_t slen = strlen(p->suffix);
@@ -944,7 +955,9 @@ static int base_len(const char *name, selem_ctl_type_t *type)
 			return strlen(name);
 		}
 	}
-	return 0;
+
+	*type = CTL_SINGLE;
+	return strlen(name);
 }
 
 
@@ -1605,8 +1618,10 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
 static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
 {
 	const char *name = snd_hctl_elem_get_name(helem);
+	selem_ctl_type_t type;
+	char ename[128];
 	size_t len;
-	selem_ctl_type_t type = CTL_SINGLE; /* to shut up warning */
+
 	if (snd_hctl_elem_get_interface(helem) != SND_CTL_ELEM_IFACE_MIXER)
 		return 0;
 	if (strcmp(name, "Capture Source") == 0) {
@@ -1633,22 +1648,14 @@ static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
 		}
 		return 0;
 	}
+
 	len = base_len(name, &type);
-	if (len == 0) {
-		return simple_add1(class, name, helem, CTL_SINGLE, 0);
-	} else {
-		char ename[128];
-		if (len >= sizeof(ename))
-			len = sizeof(ename) - 1;
-		memcpy(ename, name, len);
-		ename[len] = 0;
-		/* exception: Capture Volume and Capture Switch */
-		if (type == CTL_GLOBAL_VOLUME && !strcmp(ename, "Capture"))
-			type = CTL_CAPTURE_VOLUME;
-		else if (type == CTL_GLOBAL_SWITCH && !strcmp(ename, "Capture"))
-			type = CTL_CAPTURE_SWITCH;
-		return simple_add1(class, ename, helem, type, 0);
-	}
+	if (len >= sizeof(ename))
+		len = sizeof(ename) - 1;
+	memcpy(ename, name, len);
+	ename[len] = 0;
+
+	return simple_add1(class, ename, helem, type, 0);
 }
 
 static int simple_event_remove(snd_hctl_elem_t *helem,
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH alsa-lib v2 2/3] mixer: Add exception for non " Volume" suffixed capture vol-ctls used in ASoC realtek codec drivers
  2021-02-28 16:13 [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
  2021-02-28 16:13 ` [PATCH alsa-lib v2 1/3] mixer: Unify simple_none: base_len() exception handling Hans de Goede
@ 2021-02-28 16:13 ` Hans de Goede
  2021-02-28 16:13 ` [PATCH alsa-lib v2 3/3] mixer: Add exception for some capture-vol-ctls which have a " Volume" suffix Hans de Goede
  2021-03-04 21:50 ` [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
  3 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2021-02-28 16:13 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel; +Cc: Hans de Goede

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 --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);
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH alsa-lib v2 3/3] mixer: Add exception for some capture-vol-ctls which have a " Volume" suffix
  2021-02-28 16:13 [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
  2021-02-28 16:13 ` [PATCH alsa-lib v2 1/3] mixer: Unify simple_none: base_len() exception handling Hans de Goede
  2021-02-28 16:13 ` [PATCH alsa-lib v2 2/3] mixer: Add exception for non " Volume" suffixed capture vol-ctls used in ASoC realtek codec drivers Hans de Goede
@ 2021-02-28 16:13 ` Hans de Goede
  2021-03-04 21:50 ` [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
  3 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2021-02-28 16:13 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel; +Cc: Hans de Goede

The following ASoC codec drivers:

sound/soc/codecs/rt5659.c
sound/soc/codecs/rt5660.c
sound/soc/codecs/rt5665.c
sound/soc/codecs/rt5668.c
sound/soc/codecs/rt5670.c
sound/soc/codecs/rt5682.c

Use the following troublesome capture-volume-control names:
"IN1 Boost Volume"
"IN2 Boost Volume"
"IN3 Boost Volume"
"STO1 ADC Boost Gain Volume"
"STO2 ADC Boost Gain Volume"
"Mono ADC Boost Gain Volume"

And sound/soc/codecs/es8316.c uses "ADC PGA Gain Volume".

Note how these are suffixed with just " Volume" instead of
"Capture Volume" add some special handling for this to the base_len()
function, which is responsbile for getting the control-type,
so that the type correctly gets set to CTL_CAPTURE_VOLUME instead of
CTL_GLOBAL_VOLUME.

This correctly makes snd_mixer_selem_has_capture_volume() return true for
these (and makes snd_mixer_selem_has_common_volume() return false).

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

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 262e3516..22154647 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -914,9 +914,13 @@ static const struct suf {
  */
 const char * const capture_volume_names[] = {
 	"ADC Boost Gain",
+	"ADC PGA Gain",
 	"IN1 Boost",
 	"IN2 Boost",
 	"IN3 Boost",
+	"Mono ADC Boost Gain",
+	"STO1 ADC Boost Gain",
+	"STO2 ADC Boost Gain",
 	NULL
 };
 #endif
@@ -944,6 +948,17 @@ static int base_len(const char *name, selem_ctl_type_t *type)
 			*type = CTL_CAPTURE_VOLUME;
 			return nlen;
 		}
+
+		/*
+		 * Sometimes these have a " Volume" suffix instead of a
+		 * " Capture Volume" suffix. Check for this so that we set
+		 * type to CTL_CAPTURE_VOLUME instead of CTL_GLOBAL_VOLUME.
+		 */
+		snprintf(buf, sizeof(buf), "%s Volume", capture_volume_names[i]);
+		if (!strcmp(name, buf)) {
+			*type = CTL_CAPTURE_VOLUME;
+			return nlen - strlen(" Volume");
+		}
 	}
 
 	p = suffixes;
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH alsa-lib v2 0/3] mixer: Volume control fixes
  2021-02-28 16:13 [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
                   ` (2 preceding siblings ...)
  2021-02-28 16:13 ` [PATCH alsa-lib v2 3/3] mixer: Add exception for some capture-vol-ctls which have a " Volume" suffix Hans de Goede
@ 2021-03-04 21:50 ` Hans de Goede
  2021-03-05  9:57   ` Jaroslav Kysela
  3 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2021-03-04 21:50 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel

Hi All,

On 2/28/21 5:13 PM, Hans de Goede wrote:
> Hi All,
> 
> Here is v2 of my series of alsa-lib volume-control fixes which I wrote
> while working on adding hw-volume control to UCM profiles for various
> x86 ASoC setups.
> 
> New in v2 is adding an extra entry to the capture_volume_names array
> for the "ADC PGA Gain Volume" control used in the es8316 codec driver
> in patch 3/3.
> 
> Note that patch 3/3 is not strictly necessary to make hw-volume control
> work. At least the PA hw-vol-control code does not care if the controls
> are wronly marked as global-volume-controls instead of
> capture-volume-controls. I mostly wrote patch 3/3 because for
> correctness reasons, so if it is deemed controversial we can drop it.

Self-nack, I have some plans to make this more generic and I found
another set of control-names which need special handling (which is
the motivation to make the exception mechanism more generic).

I will post a new version sometime this weekend.

Regards,

Hans


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH alsa-lib v2 0/3] mixer: Volume control fixes
  2021-03-04 21:50 ` [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
@ 2021-03-05  9:57   ` Jaroslav Kysela
  2021-03-05 10:03     ` Hans de Goede
  0 siblings, 1 reply; 7+ messages in thread
From: Jaroslav Kysela @ 2021-03-05  9:57 UTC (permalink / raw)
  To: Hans de Goede, alsa-devel

Dne 04. 03. 21 v 22:50 Hans de Goede napsal(a):
> Hi All,
> 
> On 2/28/21 5:13 PM, Hans de Goede wrote:
>> Hi All,
>>
>> Here is v2 of my series of alsa-lib volume-control fixes which I wrote
>> while working on adding hw-volume control to UCM profiles for various
>> x86 ASoC setups.
>>
>> New in v2 is adding an extra entry to the capture_volume_names array
>> for the "ADC PGA Gain Volume" control used in the es8316 codec driver
>> in patch 3/3.
>>
>> Note that patch 3/3 is not strictly necessary to make hw-volume control
>> work. At least the PA hw-vol-control code does not care if the controls
>> are wronly marked as global-volume-controls instead of
>> capture-volume-controls. I mostly wrote patch 3/3 because for
>> correctness reasons, so if it is deemed controversial we can drop it.
> 
> Self-nack, I have some plans to make this more generic and I found
> another set of control-names which need special handling (which is
> the motivation to make the exception mechanism more generic).

I think that we should put the exceptions to a configuration file per driver,
but I haven't a time to propose a complete solution.

BTW: The first patch looks really straight, so I have a plan to merge it.

						Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH alsa-lib v2 0/3] mixer: Volume control fixes
  2021-03-05  9:57   ` Jaroslav Kysela
@ 2021-03-05 10:03     ` Hans de Goede
  0 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2021-03-05 10:03 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel

Hi,

On 3/5/21 10:57 AM, Jaroslav Kysela wrote:
> Dne 04. 03. 21 v 22:50 Hans de Goede napsal(a):
>> Hi All,
>>
>> On 2/28/21 5:13 PM, Hans de Goede wrote:
>>> Hi All,
>>>
>>> Here is v2 of my series of alsa-lib volume-control fixes which I wrote
>>> while working on adding hw-volume control to UCM profiles for various
>>> x86 ASoC setups.
>>>
>>> New in v2 is adding an extra entry to the capture_volume_names array
>>> for the "ADC PGA Gain Volume" control used in the es8316 codec driver
>>> in patch 3/3.
>>>
>>> Note that patch 3/3 is not strictly necessary to make hw-volume control
>>> work. At least the PA hw-vol-control code does not care if the controls
>>> are wronly marked as global-volume-controls instead of
>>> capture-volume-controls. I mostly wrote patch 3/3 because for
>>> correctness reasons, so if it is deemed controversial we can drop it.
>>
>> Self-nack, I have some plans to make this more generic and I found
>> another set of control-names which need special handling (which is
>> the motivation to make the exception mechanism more generic).
> 
> I think that we should put the exceptions to a configuration file per driver,
> but I haven't a time to propose a complete solution.

Yes that would be ideal. But I don't have the time for that either.

What I do have in mind should be able to serve as a basis for that.

> BTW: The first patch looks really straight, so I have a plan to merge it.

That is fine, my planned re-write of this patch-set starts at patch 2   :)

Regards,

Hans


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-05 10:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28 16:13 [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
2021-02-28 16:13 ` [PATCH alsa-lib v2 1/3] mixer: Unify simple_none: base_len() exception handling Hans de Goede
2021-02-28 16:13 ` [PATCH alsa-lib v2 2/3] mixer: Add exception for non " Volume" suffixed capture vol-ctls used in ASoC realtek codec drivers Hans de Goede
2021-02-28 16:13 ` [PATCH alsa-lib v2 3/3] mixer: Add exception for some capture-vol-ctls which have a " Volume" suffix Hans de Goede
2021-03-04 21:50 ` [PATCH alsa-lib v2 0/3] mixer: Volume control fixes Hans de Goede
2021-03-05  9:57   ` Jaroslav Kysela
2021-03-05 10:03     ` Hans de Goede

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.