usb: gadget: Add support for USB MIDI 2.0 function driver
authorTakashi Iwai <tiwai@suse.de>
Tue, 25 Jul 2023 06:22:00 +0000 (08:22 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Jul 2023 04:38:14 +0000 (06:38 +0200)
commit8b645922b22303cec4628dbbbf6c8553d1cdec87
treed90649e839162aec4b2c9aa3bf24bdb2527afa4b
parentd6ef688786beafc0fda8f12afaee313cabb4456e
usb: gadget: Add support for USB MIDI 2.0 function driver

This patch adds the support for USB MIDI 2.0 gadget function driver.
The driver emulates a USB MIDI 2.0 interface with one or more UMP
Endpoints, where each of UMP Endpoint is a pair of MIDI Endpoints for
handling MIDI 2.0 UMP packets.  When the function driver is bound, the
driver creates an ALSA card object with UMP rawmidi devices.  This is
a kind of loop-back where the incoming and upcoming UMP packets
from/to the MIDI 2.0 UMP Endpoints are transferred as-is.  In
addition, legacy (MIDI 1.0) rawmidi devices are created, so that
legacy applications can work in the gadget side, too.

When a USB MIDI 2.0 gadget interface appears, the connected host can
use it with the snd-usb-audio driver where MIDI 2.0 support is
enabled.  Both gadget and connected hosts will have the similar UMP
Endpoint and Function Block (or Group Terminal Block) information.
Slight differences are the direction and UI-hint bits; it's due to the
nature of gadget driver, and the input/output direction is swapped in
both sides (the input for gadget is the output for host, and vice
versa).

The driver supports the brand-new UMP v1.1 feature, including the UMP
Stream message handling for providing UMP Endpoint and Function Block
information as well as dealing with the MIDI protocol switch.  The
driver responds to UMP Stream messages by itself.  OTOH, MIDI-CI
message handling isn't implemented in the kernel driver; it should be
processed in the user-space through the loopback UMP device.

As of this patch, the whole configuration is fixed, providing only one
bidirectional UMP Endpoint containing a single FB/GTB with a single
UMP Group.  The configuration will be dynamically changeable in the
following patches.

The traditional MIDI 1.0 is still provided in the altset 0 (which is
mandatory per spec).  But it's only about the configuration, and no
actual I/O will be running for the altset 0 as of this patch.  The
proper support MIDI 1.0 altset will follow in later patches, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20230725062206.9674-2-tiwai@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/Kconfig
drivers/usb/gadget/function/Makefile
drivers/usb/gadget/function/f_midi2.c [new file with mode: 0644]
drivers/usb/gadget/function/u_midi2.h [new file with mode: 0644]