Message ID | 20250113235212.78127-3-linuxhid@cosmicgizmosystems.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Introduce Poly/Plantronics mute event support | expand |
Signed-off-by: Wade Wang <wade.wang@hp.com>
On Tue, 14 Jan 2025 00:51:59 +0100, Terry Junge wrote: > > +/* > + * 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) I personally find this style of argument is difficult to use. That said, IMO, it's better to stick with the argument struct snd_ctl_elem_id *id and access via id->name as in your earlier patch; it's more idiomatic, and easier to read. thanks, Takashi
On 1/14/25 4:38 AM, Takashi Iwai wrote: > On Tue, 14 Jan 2025 00:51:59 +0100, > Terry Junge wrote: >> >> +/* >> + * 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) > > I personally find this style of argument is difficult to use. > That said, IMO, it's better to stick with the argument > struct snd_ctl_elem_id *id > and access via id->name as in your earlier patch; it's more idiomatic, > and easier to read. > So, is the coding of the rest of the function body acceptable if I just pass a struct snd_ctl_elem_id *id instead of an unsigned char[44] *name ? If not, what else do I need to address in V4 so it will be accepted? thanks, Terry > > thanks, > > Takashi
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); }
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 <linuxhid@cosmicgizmosystems.com> Cc: stable@vger.kernel.org --- 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(+)