Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Wade Wang <wade.wang@hp.com>
To: perex@perex.cz, tiwai@suse.com, kl@kl.wtf,
	linuxhid@cosmicgizmosystems.com, wangdicheng@kylinos.cn,
	k.kosik@outlook.com, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	wade.wang@hp.com
Subject: [PATCH] ALSA: usb-audio: Fix control names for Plantronics/Poly Headsets
Date: Thu, 14 Nov 2024 14:15:53 +0800	[thread overview]
Message-ID: <20241114061553.1699264-1-wade.wang@hp.com> (raw)

Add a control name fixer for all headsets with VID 0x047F.

Signed-off-by: Terry Junge <linuxhid@cosmicgizmosystems.com>
Signed-off-by: Wade Wang <wade.wang@hp.com>
---
 sound/usb/mixer.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index bd67027c7677..110d43ace4d8 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1664,6 +1664,33 @@ static void check_no_speaker_on_headset(struct snd_kcontrol *kctl,
 	snd_ctl_rename(card, kctl, "Headphone");
 }
 
+static void fix_plt_control_name(struct snd_kcontrol *kctl)
+{
+	static const char * const names_to_remove[] = {
+		"Earphone",
+		"Microphone",
+		"Receive",
+		"Transmit",
+		NULL
+	};
+	const char * const *n2r;
+	char *dst, *src;
+	size_t len;
+
+	for (n2r = names_to_remove; *n2r; ++n2r) {
+		dst = strstr(kctl->id.name, *n2r);
+		if (dst != NULL) {
+			src = dst + strlen(*n2r);
+			len = strlen(src) + 1;
+			if ((char *)kctl->id.name != dst && *(dst - 1) == ' ')
+				--dst;
+			memmove(dst, src, len);
+		}
+	}
+	if (kctl->id.name[0] == '\0')
+		strscpy(kctl->id.name, "Headset", SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
+}
+
 static const struct usb_feature_control_info *get_feature_control_info(int control)
 {
 	int i;
@@ -1780,6 +1807,9 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
 		if (!mapped_name)
 			check_no_speaker_on_headset(kctl, mixer->chip->card);
 
+		if (USB_ID_VENDOR(mixer->chip->usb_id) == 0x047f)
+			fix_plt_control_name(kctl);
+
 		/*
 		 * determine the stream direction:
 		 * if the connected output is USB stream, then it's likely a
-- 
2.43.0


             reply	other threads:[~2024-11-14  6:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14  6:15 Wade Wang [this message]
2024-11-14  7:10 ` [PATCH] ALSA: usb-audio: Fix control names for Plantronics/Poly Headsets Takashi Iwai
2024-11-14 18:44   ` Terry Junge
2024-11-15  8:19     ` Takashi Iwai
2024-11-16  2:10       ` Terry Junge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241114061553.1699264-1-wade.wang@hp.com \
    --to=wade.wang@hp.com \
    --cc=k.kosik@outlook.com \
    --cc=kl@kl.wtf \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linuxhid@cosmicgizmosystems.com \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=wangdicheng@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox