From patchwork Tue Dec 24 06:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wade Wang X-Patchwork-Id: 13919710 Received: from us-smtp-delivery-162.mimecast.com (us-smtp-delivery-162.mimecast.com [170.10.129.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 787EB16DEB1 for ; Tue, 24 Dec 2024 07:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.162 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735023948; cv=none; b=iMO3KQDbB7WxMgCny+WhENswE2MDfRm2mFjwmEXQ09nkj2ek73Y58LcXqo8j0DJEOPC/W/fEoCZB3PMjVfA5rXLJmSQjWyczlTFC63kS9QGpK2vqGTTQub3OFMg7qfHy9hDmpqWla7W4viiYDYO+Bqa/2OQKrWNcaknchmZNjM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735023948; c=relaxed/simple; bh=qUkkLHrQ4WXcKVnQImhnpoTl7P/786aruC+18Jg/tz0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:content-type; b=pmDchub3zEq+H6UKWM/w+zeWfX9pbg1/PydA9trE+Q/jnVhV7T3viZH3Pe1klQZq+V2mf90+u95eNExax9sJ86tc7/1Q3EL+xoygRRN3JlGNK2tZB1q8Vs9tveUS1M86hpyPm6es5iWw3RWc6tzWUIhsfuAoqSMX51uI78O8zRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=hp.com; spf=pass smtp.mailfrom=hp.com; dkim=pass (1024-bit key) header.d=hp.com header.i=@hp.com header.b=JTX+lDlp; arc=none smtp.client-ip=170.10.129.162 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=hp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hp.com header.i=@hp.com header.b="JTX+lDlp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hp.com; s=mimecast20180716; t=1735023945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=daS+cNBbyPVNBsY+IGPoUbU95r5o0SLP4Vy1d8J8nRg=; b=JTX+lDlpRTBeQTp1RBvcKArAefhYtB25uvBn6NN1/QHxRilnPATcFLAu9DvzDmSCKE+mPk xA+MUY/mtxND8L332TDBzZwWKtQ9KmJFnf+Uh2K8q8ErJIpDWwFOyGLY5QsMv5qGlA7X2G PGO149MVwPgkbFSl16b6F87Dad3L628= Received: from g8t13017g.inc.hp.com (hpi-bastion.austin2.mail.core.hp.com [15.72.64.135]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-lBsB8_oZOVCOAyMum7ziIg-1; Tue, 24 Dec 2024 02:05:44 -0500 X-MC-Unique: lBsB8_oZOVCOAyMum7ziIg-1 X-Mimecast-MFC-AGG-ID: lBsB8_oZOVCOAyMum7ziIg Received: from g8t13020g.inc.hpicorp.net (g8t13020g.inc.hpicorp.net [15.60.27.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by g8t13017g.inc.hp.com (Postfix) with ESMTPS id 8B9DB6000E8D; Tue, 24 Dec 2024 07:05:43 +0000 (UTC) Received: from mail.hp.com (unknown [15.32.134.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by g8t13020g.inc.hpicorp.net (Postfix) with ESMTPS id 1A96A600009B; Tue, 24 Dec 2024 07:05:41 +0000 (UTC) Received: from cdc-linux-buildsrv17.. (localhost [127.0.0.1]) by mail.hp.com (Postfix) with ESMTP id 4FCB7A42C03; Tue, 24 Dec 2024 14:53:45 +0800 (CST) From: Wade Wang To: jikos@kernel.org, tiwai@suse.com, bentiss@kernel.org, perex@perex.cz, linuxhid@cosmicgizmosystems.com Cc: wade.wang@hp.com, linux-sound@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/2] ALSA: usb-audio: Add quirk for Plantronics headsets to fix control names Date: Tue, 24 Dec 2024 14:53:40 +0800 Message-Id: <20241224065340.1870687-2-wade.wang@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241224065340.1870687-1-wade.wang@hp.com> References: <20241224065340.1870687-1-wade.wang@hp.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GO-rtFEqx-bgA5U7X7y9I2OP0sbO8a-ArM8gcnMhU9s_1735023943 X-Mimecast-Originator: hp.com content-type: text/plain; charset=WINDOWS-1252; x-default=true From: Terry Junge 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 Signed-off-by: Wade Wang Cc: stable@vger.kernel.org --- V1 -> V2: Add comments, usb_audio_dbg() calls, fix leading space case sound/usb/mixer_quirks.c | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 23fcd680167d..5728c03dc49f 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -4216,6 +4216,67 @@ 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 removes nonstandard source names. By the time + * this function is called the control name will look like one of these: + * "source names Playback Volume" + * "source names Playback Switch" + * "source names Capture Volume" + * "source names Capture Switch" + * First it scans through the list and removes any found name(s) by moving the + * remaining string and its null terminator over the found name and its leading + * space, if it has one. + * Second, if all source names were removed, it puts back "Headset" + * otherwise removes a leading space, if there is one. + */ +static void snd_fix_plt_control_name(struct usb_mixer_interface *mixer, + struct snd_kcontrol *kctl) +{ + /* no variant of "Sidetone" should be added to this list */ + static const char * const names_to_remove[] = { + "Earphone", + "Microphone", + "Receive", + "Transmit", + NULL + }; + const char * const *n2r; + char *dst, *src, *last = NULL; + size_t len = 0; + + for (n2r = names_to_remove; *n2r; ++n2r) { + dst = strstr(kctl->id.name, *n2r); + if (dst) { + usb_audio_dbg(mixer->chip, "found %s in %s\n", + *n2r, kctl->id.name); + src = dst + strlen(*n2r); + len = strlen(src) + 1; + if ((char *)kctl->id.name != dst && *(dst - 1) == ' ') + --dst; + last = memmove(dst, src, len); + usb_audio_dbg(mixer->chip, "now %s\n", kctl->id.name); + } + } + if (!len) { + usb_audio_dbg(mixer->chip, "no change in %s\n", kctl->id.name); + return; + } + if (len <= sizeof " Playback Volume" && (char *)kctl->id.name == last) { + char rcat[sizeof(kctl->id.name)] = { "Headset" }; + + strlcat(rcat, kctl->id.name, sizeof(rcat)); + strscpy(kctl->id.name, rcat, sizeof(kctl->id.name)); + usb_audio_dbg(mixer->chip, "now %s\n", kctl->id.name); + } else if (kctl->id.name[0] == ' ') { + dst = kctl->id.name; + src = dst + 1; + len = strlen(src) + 1; + memmove(dst, src, len); + usb_audio_dbg(mixer->chip, "now %s\n", kctl->id.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 +4294,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_control_name(mixer, kctl); }