From patchwork Mon Jan 13 23:51:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Junge X-Patchwork-Id: 857064 Received: from cosmicgizmosystems.com (cosmicgizmosystems.com [63.249.102.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3BDE1FA143; Mon, 13 Jan 2025 23:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.249.102.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736812351; cv=none; b=ZpU3MUf2oQL8YIwCnm7ADY/s6CTAuDAutyLRmBNVEBWYbEkfSAP7bChsgrwoLDlBmwISxKWFt3BrgqSoiaNSeMId0gATSsGo1KRk5so8WkJ3m7XNNg/Rj+SkR57cmoBwQaNKvVWky1OqYUdHkV2GxxTOlejltTMikkFZQzHIf14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736812351; c=relaxed/simple; bh=URrLT1unKCZxtHvRGyf/ENZY15mdDJnP26UrWTfP1EI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t4Cim2YmJb09hA38h1pgN7NzYxMPikG1anC2XhULh1o4t2hcqJxsHyuO6toDGED+qI6lb7gBmjxBefAC9g7afyFMyr600/n/rkLqOBRY3AEs+k2CxGMfobLBuBn1sdrSkbvl2wiB9xEsiE1wcdlFu7UkmeIu57/7c7qd5ONyEyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cosmicgizmosystems.com; spf=pass smtp.mailfrom=cosmicgizmosystems.com; arc=none smtp.client-ip=63.249.102.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cosmicgizmosystems.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cosmicgizmosystems.com Received: from terrys-Precision-M4600.hsd1.wa.comcast.net (c-73-190-111-195.hsd1.wa.comcast.net [73.190.111.195]) by host11.cruzio.com (Postfix) with ESMTPSA id 77E9922A2F9A; Mon, 13 Jan 2025 15:52:28 -0800 (PST) From: Terry Junge To: Jiri Kosina , Takashi Iwai , Wade Wang , Benjamin Tissoires , Jaroslav Kysela Cc: Terry Junge , linux-input@vger.kernel.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] ALSA: usb-audio: Add quirk for Plantronics headsets to fix control names Date: Mon, 13 Jan 2025 15:51:59 -0800 Message-ID: <20250113235212.78127-3-linuxhid@cosmicgizmosystems.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113235212.78127-1-linuxhid@cosmicgizmosystems.com> References: <20250113235212.78127-1-linuxhid@cosmicgizmosystems.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Many Poly/Plantronics headset families name the feature, input, and/or output units in a such a way to produce control names that are not recognized by user space. As such, the volume and mute events do not get routed to the headset's audio controls. As an example from a product family: The microphone mute control is named Headset Microphone Capture Switch and the headset volume control is named Headset Earphone Playback Volume The quirk fixes these to become Headset Capture Switch Headset Playback Volume Signed-off-by: Terry Junge Cc: stable@vger.kernel.org Signed-off-by: Wade Wang --- V1 -> V2: Add comments, usb_audio_dbg() calls, fix leading space case V2 -> V3: Recode as per Takashi's suggestions, equivalent functionality sound/usb/mixer_quirks.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 23fcd680167d..58cb676873a6 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -4216,6 +4216,52 @@ static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer, } } + +/* + * Some Plantronics headsets have control names that don't meet ALSA naming + * standards. This function fixes nonstandard source names. By the time + * this function is called the control name should look like one of these: + * "source names Playback Volume" + * "source names Playback Switch" + * "source names Capture Volume" + * "source names Capture Switch" + * If any of the trigger words are found in the name then the name will + * be changed to: + * "Headset Playback Volume" + * "Headset Playback Switch" + * "Headset Capture Volume" + * "Headset Capture Switch" + * depending on the current suffix. + */ +static void snd_fix_plt_name(struct snd_usb_audio *chip, + typeof_member(struct snd_ctl_elem_id, name) * name) +{ + /* no variant of "Sidetone" should be added to this list */ + static const char * const trigger[] = { + "Earphone", "Microphone", "Receive", "Transmit" + }; + static const char * const suffix[] = { + " Playback Volume", " Playback Switch", + " Capture Volume", " Capture Switch" + }; + int i; + + for (i = 0; i < ARRAY_SIZE(trigger); i++) + if (strstr(*name, trigger[i])) + goto triggered; + usb_audio_dbg(chip, "no change in %s\n", *name); + return; + +triggered: + for (i = 0; i < ARRAY_SIZE(suffix); i++) + if (strstr(*name, suffix[i])) { + usb_audio_dbg(chip, "fixing kctl name %s\n", *name); + snprintf(*name, sizeof(*name), "Headset%s", suffix[i]); + return; + } + usb_audio_dbg(chip, "something wrong in kctl name %s\n", *name); +} + void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, struct usb_mixer_elem_info *cval, int unitid, struct snd_kcontrol *kctl) @@ -4233,5 +4279,10 @@ void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, cval->min_mute = 1; break; } + + /* ALSA-ify some Plantronics headset control names */ + if (USB_ID_VENDOR(mixer->chip->usb_id) == 0x047f && + (cval->control == UAC_FU_MUTE || cval->control == UAC_FU_VOLUME)) + snd_fix_plt_name(mixer->chip, &kctl->id.name); }