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>
This commit is contained in:
Takashi Iwai 2023-07-25 08:22:00 +02:00 committed by Greg Kroah-Hartman
parent d6ef688786
commit 8b645922b2
4 changed files with 1790 additions and 0 deletions

View File

@ -208,6 +208,9 @@ config USB_F_UVC
config USB_F_MIDI
tristate
config USB_F_MIDI2
tristate
config USB_F_HID
tristate
@ -436,6 +439,21 @@ config USB_CONFIGFS_F_MIDI
connections can then be made on the gadget system, using
ALSA's aconnect utility etc.
config USB_CONFIGFS_F_MIDI2
bool "MIDI 2.0 function"
depends on USB_CONFIGFS
depends on SND
select USB_LIBCOMPOSITE
select SND_UMP
select SND_UMP_LEGACY_RAWMIDI
select USB_F_MIDI2
help
The MIDI 2.0 function driver provides the generic emulated
USB MIDI 2.0 interface, looped back to ALSA UMP rawmidi
device on the gadget host. It supports UMP 1.1 spec and
responds UMP Stream messages for UMP Endpoint and Function
Block information / configuration.
config USB_CONFIGFS_F_HID
bool "HID function"
depends on USB_CONFIGFS

View File

@ -44,6 +44,8 @@ usb_f_uvc-y := f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_configfs.o
obj-$(CONFIG_USB_F_UVC) += usb_f_uvc.o
usb_f_midi-y := f_midi.o
obj-$(CONFIG_USB_F_MIDI) += usb_f_midi.o
usb_f_midi2-y := f_midi2.o
obj-$(CONFIG_USB_F_MIDI2) += usb_f_midi2.o
usb_f_hid-y := f_hid.o
obj-$(CONFIG_USB_F_HID) += usb_f_hid.o
usb_f_printer-y := f_printer.o

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Utility definitions for MIDI 2.0 function
*/
#ifndef U_MIDI2_H
#define U_MIDI2_H
#include <linux/usb/composite.h>
#include <sound/asound.h>
struct f_midi2_opts;
struct f_midi2_ep_opts;
struct f_midi2_block_opts;
/* UMP Function Block info */
struct f_midi2_block_info {
unsigned int direction; /* FB direction: 1-3 */
unsigned int first_group; /* first UMP group: 0-15 */
unsigned int num_groups; /* number of UMP groups: 1-16 */
unsigned int ui_hint; /* UI-hint: 0-3 */
unsigned int midi_ci_version; /* MIDI-CI version: 0-255 */
unsigned int sysex8_streams; /* number of sysex8 streams: 0-255 */
unsigned int is_midi1; /* MIDI 1.0 port: 0-2 */
bool active; /* FB active flag: bool */
const char *name; /* FB name */
};
/* UMP Endpoint info */
struct f_midi2_ep_info {
unsigned int protocol_caps; /* protocol capabilities: 1-3 */
unsigned int protocol; /* default protocol: 1-2 */
unsigned int manufacturer; /* manufacturer id: 0-0xffffff */
unsigned int family; /* device family id: 0-0xffff */
unsigned int model; /* device model id: 0x-0xffff */
unsigned int sw_revision; /* software revision: 32bit */
const char *ep_name; /* Endpoint name */
const char *product_id; /* Product ID */
};
struct f_midi2_card_info {
bool process_ump; /* process UMP stream: bool */
bool static_block; /* static FBs: bool */
unsigned int req_buf_size; /* request buffer size */
unsigned int num_reqs; /* number of requests */
const char *iface_name; /* interface name */
};
struct f_midi2_block_opts {
struct config_group group;
unsigned int id;
struct f_midi2_block_info info;
struct f_midi2_ep_opts *ep;
};
struct f_midi2_ep_opts {
struct config_group group;
unsigned int index;
struct f_midi2_ep_info info;
struct f_midi2_block_opts *blks[SNDRV_UMP_MAX_BLOCKS];
struct f_midi2_opts *opts;
};
#define MAX_UMP_EPS 4
#define MAX_CABLES 16
struct f_midi2_opts {
struct usb_function_instance func_inst;
struct mutex lock;
int refcnt;
struct f_midi2_card_info info;
unsigned int num_eps;
struct f_midi2_ep_opts *eps[MAX_UMP_EPS];
};
#endif /* U_MIDI2_H */