linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/36] ALSA: Add MIDI 2.0 support
@ 2023-05-19  9:30 Takashi Iwai
  2023-05-19  9:30 ` [PATCH 07/36] ALSA: usb-audio: Define USB MIDI 2.0 specs Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2023-05-19  9:30 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Greg Kroah-Hartman, linux-usb

Hi,

this is a (largish) patch set for adding the support of MIDI 2.0
functionality, mainly targeted for USB devices.  MIDI 2.0 is a
complete overhaul of the 40-years old MIDI 1.0.  Unlike MIDI 1.0 byte
stream, MIDI 2.0 uses packets in 32bit words for Universal MIDI Packet
(UMP) protocol.  It supports both MIDI 1.0 commands for compatibility
and the extended MIDI 2.0 commands for higher resolutions and more
functions.

For supporting the UMP, the patch set extends the existing ALSA
rawmidi and sequencer interfaces, and adds the USB MIDI 2.0 support to
the standard USB-audio driver.

The rawmidi for UMP has a different device name (/dev/snd/umpC*D*) and
it reads/writes UMP packet data in 32bit CPU-native endianness.  For
the old MIDI 1.0 applications, the legacy rawmidi interface is
provided, too.

As default, USB-audio driver will take the alternate setting for MIDI
2.0 interface, and the compatibility with MIDI 1.0 is provided via the
rawmidi common layer.  However, user may let the driver falling back
to the old MIDI 1.0 interface by a module option, too.

A UMP-capable rawmidi device can create the corresponding ALSA
sequencer client(s) to support the UMP Endpoint and UMP Group
connections.  As a nature of ALSA sequencer, arbitrary connections
between clients/ports are allowed, and the ALSA sequencer core
performs the automatic conversions for the connections between a new
UMP sequencer client and a legacy MIDI 1.0 sequencer client.  It
allows the existing application to use MIDI 2.0 devices without
changes.

The MIDI-CI, which is another major extension in MIDI 2.0, isn't
covered by this patch set.  It would be implemented rather in
user-space.

Roughly speaking, the first half of this patch set is for extending
the rawmidi and USB-audio, and the second half is for extending the
ALSA sequencer interface.

The patch set is based on 6.4-rc2 kernel, but all patches can be
cleanly applicable on 6.2 and 6.3 kernels, too (while 6.1 and older
kernels would need minor adjustment for uapi header changes).

The updates for alsa-lib and alsa-utils will follow shortly later.

The author thanks members of MIDI Association OS/API Working Group,
especially Andrew Mee, for great helps for the initial design and
debugging / testing the drivers.


Takashi

---

Takashi Iwai (36):
  ALSA: rawmidi: Pass rawmidi directly to snd_rawmidi_kernel_open()
  ALSA: rawmidi: Add ioctl callback to snd_rawmidi_global_ops
  ALSA: rawmidi: UMP support
  ALSA: rawmidi: Skip UMP devices at SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE
  ALSA: ump: Additional proc output
  ALSA: usb-audio: Manage number of rawmidis globally
  ALSA: usb-audio: Define USB MIDI 2.0 specs
  ALSA: usb-audio: USB MIDI 2.0 UMP support
  ALSA: usb-audio: Get UMP EP name string from USB interface
  ALSA: usb-audio: Trim superfluous "MIDI" suffix from UMP EP name
  ALSA: usb-audio: Create UMP blocks from USB MIDI GTBs
  ALSA: ump: Redirect rawmidi substream access via own helpers
  ALSA: ump: Add legacy raw MIDI support
  ALSA: usb-audio: Enable the legacy raw MIDI support
  ALSA: usb-audio: Inform inconsistent protocols in GTBs
  ALSA: seq: Clear padded bytes at expanding events
  ALSA: seq: Add snd_seq_expand_var_event_at() helper
  ALSA: seq: Treat snd_seq_client object directly in client drivers
  ALSA: seq: Drop dead code for the old broadcast support
  ALSA: seq: Check the conflicting port at port creation
  ALSA: seq: Check validity before creating a port object
  ALSA: seq: Prohibit creating ports with special numbers
  ALSA: seq: Introduce SNDRV_SEQ_IOCTL_USER_PVERSION ioctl
  ALSA: seq: Add UMP support
  ALSA: seq: Add port inactive flag
  ALSA: seq: Support MIDI 2.0 UMP Endpoint port
  ALSA: seq: Add port direction to snd_seq_port_info
  ALSA: seq: Add UMP group number to snd_seq_port_info
  ALSA: seq: Automatic conversion of UMP events
  ALSA: seq: Allow suppressing UMP conversions
  ALSA: seq: Bind UMP device
  ALSA: seq: ump: Create UMP Endpoint port for broadcast
  ALSA: seq: Add ioctls for client UMP info query and setup
  ALSA: seq: Print UMP Endpoint and Block information in proc outputs
  ALSA: seq: Add UMP group filter
  ALSA: docs: Add MIDI 2.0 documentation

 Documentation/sound/designs/index.rst    |    1 +
 Documentation/sound/designs/midi-2.0.rst |  342 ++++++
 include/linux/usb/midi-v2.h              |   94 ++
 include/sound/asequencer.h               |    4 +
 include/sound/rawmidi.h                  |   16 +-
 include/sound/seq_device.h               |    1 +
 include/sound/seq_kernel.h               |   10 +
 include/sound/ump.h                      |  175 ++++
 include/sound/ump_msg.h                  |  540 ++++++++++
 include/uapi/sound/asequencer.h          |   83 +-
 include/uapi/sound/asound.h              |   58 +-
 sound/core/Kconfig                       |   13 +
 sound/core/Makefile                      |    3 +
 sound/core/rawmidi.c                     |  233 +++--
 sound/core/rawmidi_compat.c              |    4 +
 sound/core/seq/Kconfig                   |   14 +
 sound/core/seq/Makefile                  |    3 +
 sound/core/seq/seq_clientmgr.c           |  577 +++++++----
 sound/core/seq/seq_clientmgr.h           |   27 +-
 sound/core/seq/seq_compat.c              |    3 +
 sound/core/seq/seq_dummy.c               |    9 +
 sound/core/seq/seq_memory.c              |   98 +-
 sound/core/seq/seq_memory.h              |   19 +-
 sound/core/seq/seq_midi.c                |   12 +-
 sound/core/seq/seq_ports.c               |   46 +-
 sound/core/seq/seq_ports.h               |   23 +-
 sound/core/seq/seq_ump_client.c          |  464 +++++++++
 sound/core/seq/seq_ump_convert.c         | 1203 ++++++++++++++++++++++
 sound/core/seq/seq_ump_convert.h         |   22 +
 sound/core/seq/seq_virmidi.c             |    1 +
 sound/core/ump.c                         |  677 ++++++++++++
 sound/core/ump_convert.c                 |  520 ++++++++++
 sound/core/ump_convert.h                 |   43 +
 sound/usb/Kconfig                        |   11 +
 sound/usb/Makefile                       |    1 +
 sound/usb/card.c                         |   12 +-
 sound/usb/midi.c                         |    7 +-
 sound/usb/midi.h                         |    5 +-
 sound/usb/midi2.c                        | 1189 +++++++++++++++++++++
 sound/usb/midi2.h                        |   33 +
 sound/usb/quirks.c                       |    8 +-
 sound/usb/usbaudio.h                     |    2 +
 42 files changed, 6274 insertions(+), 332 deletions(-)
 create mode 100644 Documentation/sound/designs/midi-2.0.rst
 create mode 100644 include/linux/usb/midi-v2.h
 create mode 100644 include/sound/ump.h
 create mode 100644 include/sound/ump_msg.h
 create mode 100644 sound/core/seq/seq_ump_client.c
 create mode 100644 sound/core/seq/seq_ump_convert.c
 create mode 100644 sound/core/seq/seq_ump_convert.h
 create mode 100644 sound/core/ump.c
 create mode 100644 sound/core/ump_convert.c
 create mode 100644 sound/core/ump_convert.h
 create mode 100644 sound/usb/midi2.c
 create mode 100644 sound/usb/midi2.h

-- 
2.35.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 07/36] ALSA: usb-audio: Define USB MIDI 2.0 specs
  2023-05-19  9:30 [PATCH 00/36] ALSA: Add MIDI 2.0 support Takashi Iwai
@ 2023-05-19  9:30 ` Takashi Iwai
  2023-05-19  9:46   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2023-05-19  9:30 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Greg Kroah-Hartman, linux-usb

Define new structs and constants from USB MIDI 2.0 specification,
to be used in the upcoming MIDI 2.0 support in USB-audio driver.

A new class-specific endpoint descriptor and group terminal block
descriptors are defined.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/linux/usb/midi-v2.h | 94 +++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 include/linux/usb/midi-v2.h

diff --git a/include/linux/usb/midi-v2.h b/include/linux/usb/midi-v2.h
new file mode 100644
index 000000000000..ebbffcae0417
--- /dev/null
+++ b/include/linux/usb/midi-v2.h
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * <linux/usb/midi-v2.h> -- USB MIDI 2.0 definitions.
+ */
+
+#ifndef __LINUX_USB_MIDI_V2_H
+#define __LINUX_USB_MIDI_V2_H
+
+#include <linux/types.h>
+#include <linux/usb/midi.h>
+
+/* A.1 MS Class-Specific Interface Descriptor Types */
+#define USB_DT_CS_GR_TRM_BLOCK	0x26
+
+/* A.1 MS Class-Specific Interface Descriptor Subtypes */
+/* same as MIDI 1.0 */
+
+/* A.2 MS Class-Specific Endpoint Descriptor Subtypes */
+#define USB_MS_GENERAL_2_0	0x02
+
+/* A.3 MS Class-Specific Group Terminal Block Descriptor Subtypes */
+#define USB_MS_GR_TRM_BLOCK_UNDEFINED	0x00
+#define USB_MS_GR_TRM_BLOCK_HEADER	0x01
+#define USB_MS_GR_TRM_BLOCK		0x02
+
+/* A.4 MS Interface Header MIDIStreaming Class Revision */
+#define USB_MS_REV_MIDI_1_0		0x0100
+#define USB_MS_REV_MIDI_2_0		0x0200
+
+/* A.5 MS MIDI IN and OUT Jack Types */
+/* same as MIDI 1.0 */
+
+/* A.6 Group Terminal Block Types */
+#define USB_MS_GR_TRM_BLOCK_TYPE_BIDIRECTIONAL	0x00
+#define USB_MS_GR_TRM_BLOCK_TYPE_INPUT_ONLY	0x01
+#define USB_MS_GR_TRM_BLOCK_TYPE_OUTPUT_ONLY	0x02
+
+/* A.7 Group Terminal Default MIDI Protocol */
+#define USB_MS_MIDI_PROTO_UNKNOWN	0x00 /* Unknown (Use MIDI-CI) */
+#define USB_MS_MIDI_PROTO_1_0_64	0x01 /* MIDI 1.0, UMP up to 64bits */
+#define USB_MS_MIDI_PROTO_1_0_64_JRTS	0x02 /* MIDI 1.0, UMP up to 64bits, Jitter Reduction Timestamps */
+#define USB_MS_MIDI_PROTO_1_0_128	0x03 /* MIDI 1.0, UMP up to 128bits */
+#define USB_MS_MIDI_PROTO_1_0_128_JRTS	0x04 /* MIDI 1.0, UMP up to 128bits, Jitter Reduction Timestamps */
+#define USB_MS_MIDI_PROTO_2_0		0x11 /* MIDI 2.0 */
+#define USB_MS_MIDI_PROTO_2_0_JRTS	0x12 /* MIDI 2.0, Jitter Reduction Timestamps */
+
+/* 5.2.2.1 Class-Specific MS Interface Header Descriptor */
+/* Same as MIDI 1.0, use struct usb_ms_header_descriptor */
+
+/* 5.3.2 Class-Specific MIDI Streaming Data Endpoint Descriptor */
+struct usb_ms20_endpoint_descriptor {
+	__u8  bLength;			/* 4+n */
+	__u8  bDescriptorType;		/* USB_DT_CS_ENDPOINT */
+	__u8  bDescriptorSubtype;	/* USB_MS_GENERAL_2_0 */
+	__u8  bNumGrpTrmBlock;		/* Number of Group Terminal Blocks: n */
+	__u8  baAssoGrpTrmBlkID[];	/* ID of the Group Terminal Blocks [n] */
+} __packed;
+
+#define USB_DT_MS20_ENDPOINT_SIZE(n)	(4 + (n))
+
+/* As above, but more useful for defining your own descriptors: */
+#define DECLARE_USB_MS20_ENDPOINT_DESCRIPTOR(n)			\
+struct usb_ms20_endpoint_descriptor_##n {			\
+	__u8  bLength;						\
+	__u8  bDescriptorType;					\
+	__u8  bDescriptorSubtype;				\
+	__u8  bNumGrpTrmBlock;					\
+	__u8  baAssoGrpTrmBlkID[n];				\
+} __packed
+
+/* 5.4.1 Class-Specific Group Terminal Block Header Descriptor */
+struct usb_ms20_gr_trm_block_header_descriptor {
+	__u8  bLength;			/* 5 */
+	__u8  bDescriptorType;		/* USB_DT_CS_GR_TRM_BLOCK */
+	__u8  bDescriptorSubtype;	/* USB_MS_GR_TRM_BLOCK_HEADER */
+	__u16 wTotalLength;		/* Total number of bytes */
+} __packed;
+
+/* 5.4.2.1 Group Terminal Block Descriptor */
+struct usb_ms20_gr_trm_block_descriptor {
+	__u8  bLength;			/* 13 */
+	__u8  bDescriptorType;		/* USB_DT_CS_GR_TRM_BLOCK */
+	__u8  bDescriptorSubtype;	/* USB_MS_GR_TRM_BLOCK */
+	__u8  bGrpTrmBlkID;		/* ID of this Group Terminal Block */
+	__u8  bGrpTrmBlkType;		/* Group Terminal Block Type */
+	__u8  nGroupTrm;		/* The first member Group Terminal in this block */
+	__u8  nNumGroupTrm;		/* Number of member Group Terminals spanned */
+	__u8  iBlockItem;		/* String ID of Block item */
+	__u8  bMIDIProtocol;		/* Default MIDI protocol */
+	__u16 wMaxInputBandwidth;	/* Max input bandwidth capability in 4kB/s */
+	__u16 wMaxOutputBandwidth;	/* Max output bandwidth capability in 4kB/s */
+} __packed;
+
+#endif /* __LINUX_USB_MIDI_V2_H */
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 07/36] ALSA: usb-audio: Define USB MIDI 2.0 specs
  2023-05-19  9:30 ` [PATCH 07/36] ALSA: usb-audio: Define USB MIDI 2.0 specs Takashi Iwai
@ 2023-05-19  9:46   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-05-19  9:46 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel, linux-usb

On Fri, May 19, 2023 at 11:30:45AM +0200, Takashi Iwai wrote:
> Define new structs and constants from USB MIDI 2.0 specification,
> to be used in the upcoming MIDI 2.0 support in USB-audio driver.
> 
> A new class-specific endpoint descriptor and group terminal block
> descriptors are defined.
> 
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: <linux-usb@vger.kernel.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-19  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-19  9:30 [PATCH 00/36] ALSA: Add MIDI 2.0 support Takashi Iwai
2023-05-19  9:30 ` [PATCH 07/36] ALSA: usb-audio: Define USB MIDI 2.0 specs Takashi Iwai
2023-05-19  9:46   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).