ALSA USB quirk mixer driver question

Hi all!
I'm currently trying to develop an usb quirk mixer driver for a desktop USB audio interface.
The interface exposes the following:
- interface 0-2 are USB UAC compliant, bound to by snd-usb-audio, and working flawlessly
- interface 3 is vendor specific, and we can ignore it (used for firmware updates)
- interface 4 exposes a non-standard mixer with a HID interface exposing 2 interrupt endpoints, and is used by the vendor windows app.
I have studied the protocol with usbpcap and can successfully talk to the interface on the userspace, but i had a question regarding how to proceed in the kernel.
This is because, after creating a new entry in `sound/usb/mixer_quirks.c` with all the needed controls, userspace can interact with them, etc.
I can't figure out how to tell ALSA to bind to the correct interface for the mixer (and kick out usbhid). Looking at the other quirk mixer drivers it doesn't look (?) like any other quirk mixer driver is binding to a *different* interface, not even `sound/usb/mixer_scarlett.c`.
Generally, in a standalone USB driver you'd have tracking/teardown handled easily with a callback, but i'm having trouble with the dependencies here. (simply using `usb_sndintpipe()` or `usb_interrupt_msg()` triggers kernel oopses, so that's probably not it)
What i think i have to do is to use `usb_get_intf()`, then i have to somehow claim it (does `usb_driver_claim_interface()` work here?). But `usb_get_intf()` requires me to then release the interface with `usb_put_intf()`, and it doesn't look like there's anywhere for me to do that. (`snd_usb_mixer_elem_free()`? doesn't look like the order is correct)
`iface_ref_find()` would sorta do what i need, but i cannot use it here.
Could someone please point me in the right direction? I'm very stuck at the moment.
Thanks,
Lena

On Fri, 14 Feb 2025 13:05:13 +0100, Lena wrote:
Hi all!
I'm currently trying to develop an usb quirk mixer driver for a desktop USB audio interface.
The interface exposes the following:
interface 0-2 are USB UAC compliant, bound to by snd-usb-audio, and working flawlessly
interface 3 is vendor specific, and we can ignore it (used for firmware updates)
interface 4 exposes a non-standard mixer with a HID interface exposing 2 interrupt endpoints, and is used by the vendor windows app.
I have studied the protocol with usbpcap and can successfully talk to the interface on the userspace, but i had a question regarding how to proceed in the kernel.
This is because, after creating a new entry in `sound/usb/mixer_quirks.c` with all the needed controls, userspace can interact with them, etc.
I can't figure out how to tell ALSA to bind to the correct interface for the mixer (and kick out usbhid). Looking at the other quirk mixer drivers it doesn't look (?) like any other quirk mixer driver is binding to a *different* interface, not even `sound/usb/mixer_scarlett.c`.
The HID device won't be bound with the sound driver, and the mixer "quirks" found in USB-audio driver aren't for managing HID interfaces but only about audio interfaces. That said, what you'd need would be to write rather a HID driver for the interface. The plumbing of both interfaces is done in the upper level, typically in user space.
HTH,
Takashi
Generally, in a standalone USB driver you'd have tracking/teardown handled easily with a callback, but i'm having trouble with the dependencies here. (simply using `usb_sndintpipe()` or `usb_interrupt_msg()` triggers kernel oopses, so that's probably not it)
What i think i have to do is to use `usb_get_intf()`, then i have to somehow claim it (does `usb_driver_claim_interface()` work here?). But `usb_get_intf()` requires me to then release the interface with `usb_put_intf()`, and it doesn't look like there's anywhere for me to do that. (`snd_usb_mixer_elem_free()`? doesn't look like the order is correct)
`iface_ref_find()` would sorta do what i need, but i cannot use it here.
Could someone please point me in the right direction? I'm very stuck at the moment.
Thanks,
Lena

Thanks for the reply!
So, if i understand correctly, instead of going through sound/usb/mixer_quirks.c, i need to create a standalone USBHID driver that exposes the ALSA kcontrols and then the ALSA userspace understands that it's the same interface and 'links' the UAC/isochronous audio part and the standalone ALSA mixer kcontrol part that has the volume knobs, mute, output select and input impedance/phantom power/headphone gain switches such that an userspace application (like alsamixer) treats it all as a single thing.
Does this driver then belong in sound/usb/ (given it imports the API in <sound/control.h>) or somewhere else (e.g. drivers/hid/usbhid/, drivers/usb/)?
Thanks again,
Lena

On Thu, 27 Feb 2025 00:15:01 +0100, Lena wrote:
Thanks for the reply!
So, if i understand correctly, instead of going through sound/usb/mixer_quirks.c, i need to create a standalone USBHID driver that exposes the ALSA kcontrols and then the ALSA userspace understands that it's the same interface and 'links' the UAC/isochronous audio part and the standalone ALSA mixer kcontrol part that has the volume knobs, mute, output select and input impedance/phantom power/headphone gain switches such that an userspace application (like alsamixer) treats it all as a single thing.
Well, how to manage HID device is other question. Usually a HID device provides the controls via input device API. It's not prohibited to use a sound API (in this case you'd need to create your own sound card object), though.
Does this driver then belong in sound/usb/ (given it imports the API in <sound/control.h>) or somewhere else (e.g. drivers/hid/usbhid/, drivers/usb/)?
Not likely. It'll be a pure HID driver.
HTH,
Takashi
participants (2)
-
Lena
-
Takashi Iwai