xref: /linux-6.15/include/uapi/linux/usb/midi.h (revision e2be04c7)
1*e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
25e1ddb48SDavid Howells /*
35e1ddb48SDavid Howells  * <linux/usb/midi.h> -- USB MIDI definitions.
45e1ddb48SDavid Howells  *
55e1ddb48SDavid Howells  * Copyright (C) 2006 Thumtronics Pty Ltd.
65e1ddb48SDavid Howells  * Developed for Thumtronics by Grey Innovation
75e1ddb48SDavid Howells  * Ben Williamson <[email protected]>
85e1ddb48SDavid Howells  *
95e1ddb48SDavid Howells  * This software is distributed under the terms of the GNU General Public
105e1ddb48SDavid Howells  * License ("GPL") version 2, as published by the Free Software Foundation.
115e1ddb48SDavid Howells  *
125e1ddb48SDavid Howells  * This file holds USB constants and structures defined
135e1ddb48SDavid Howells  * by the USB Device Class Definition for MIDI Devices.
145e1ddb48SDavid Howells  * Comments below reference relevant sections of that document:
155e1ddb48SDavid Howells  *
165e1ddb48SDavid Howells  * http://www.usb.org/developers/devclass_docs/midi10.pdf
175e1ddb48SDavid Howells  */
185e1ddb48SDavid Howells 
195e1ddb48SDavid Howells #ifndef __LINUX_USB_MIDI_H
205e1ddb48SDavid Howells #define __LINUX_USB_MIDI_H
215e1ddb48SDavid Howells 
225e1ddb48SDavid Howells #include <linux/types.h>
235e1ddb48SDavid Howells 
245e1ddb48SDavid Howells /* A.1  MS Class-Specific Interface Descriptor Subtypes */
255e1ddb48SDavid Howells #define USB_MS_HEADER		0x01
265e1ddb48SDavid Howells #define USB_MS_MIDI_IN_JACK	0x02
275e1ddb48SDavid Howells #define USB_MS_MIDI_OUT_JACK	0x03
285e1ddb48SDavid Howells #define USB_MS_ELEMENT		0x04
295e1ddb48SDavid Howells 
305e1ddb48SDavid Howells /* A.2  MS Class-Specific Endpoint Descriptor Subtypes */
315e1ddb48SDavid Howells #define USB_MS_GENERAL		0x01
325e1ddb48SDavid Howells 
335e1ddb48SDavid Howells /* A.3  MS MIDI IN and OUT Jack Types */
345e1ddb48SDavid Howells #define USB_MS_EMBEDDED		0x01
355e1ddb48SDavid Howells #define USB_MS_EXTERNAL		0x02
365e1ddb48SDavid Howells 
375e1ddb48SDavid Howells /* 6.1.2.1  Class-Specific MS Interface Header Descriptor */
385e1ddb48SDavid Howells struct usb_ms_header_descriptor {
395e1ddb48SDavid Howells 	__u8  bLength;
405e1ddb48SDavid Howells 	__u8  bDescriptorType;
415e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;
425e1ddb48SDavid Howells 	__le16 bcdMSC;
435e1ddb48SDavid Howells 	__le16 wTotalLength;
445e1ddb48SDavid Howells } __attribute__ ((packed));
455e1ddb48SDavid Howells 
465e1ddb48SDavid Howells #define USB_DT_MS_HEADER_SIZE	7
475e1ddb48SDavid Howells 
485e1ddb48SDavid Howells /* 6.1.2.2  MIDI IN Jack Descriptor */
495e1ddb48SDavid Howells struct usb_midi_in_jack_descriptor {
505e1ddb48SDavid Howells 	__u8  bLength;
515e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
525e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* USB_MS_MIDI_IN_JACK */
535e1ddb48SDavid Howells 	__u8  bJackType;		/* USB_MS_EMBEDDED/EXTERNAL */
545e1ddb48SDavid Howells 	__u8  bJackID;
555e1ddb48SDavid Howells 	__u8  iJack;
565e1ddb48SDavid Howells } __attribute__ ((packed));
575e1ddb48SDavid Howells 
585e1ddb48SDavid Howells #define USB_DT_MIDI_IN_SIZE	6
595e1ddb48SDavid Howells 
605e1ddb48SDavid Howells struct usb_midi_source_pin {
615e1ddb48SDavid Howells 	__u8  baSourceID;
625e1ddb48SDavid Howells 	__u8  baSourcePin;
635e1ddb48SDavid Howells } __attribute__ ((packed));
645e1ddb48SDavid Howells 
655e1ddb48SDavid Howells /* 6.1.2.3  MIDI OUT Jack Descriptor */
665e1ddb48SDavid Howells struct usb_midi_out_jack_descriptor {
675e1ddb48SDavid Howells 	__u8  bLength;
685e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
695e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* USB_MS_MIDI_OUT_JACK */
705e1ddb48SDavid Howells 	__u8  bJackType;		/* USB_MS_EMBEDDED/EXTERNAL */
715e1ddb48SDavid Howells 	__u8  bJackID;
725e1ddb48SDavid Howells 	__u8  bNrInputPins;		/* p */
735e1ddb48SDavid Howells 	struct usb_midi_source_pin pins[]; /* [p] */
745e1ddb48SDavid Howells 	/*__u8  iJack;  -- omitted due to variable-sized pins[] */
755e1ddb48SDavid Howells } __attribute__ ((packed));
765e1ddb48SDavid Howells 
775e1ddb48SDavid Howells #define USB_DT_MIDI_OUT_SIZE(p)	(7 + 2 * (p))
785e1ddb48SDavid Howells 
795e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */
805e1ddb48SDavid Howells #define DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(p)			\
815e1ddb48SDavid Howells struct usb_midi_out_jack_descriptor_##p {			\
825e1ddb48SDavid Howells 	__u8  bLength;						\
835e1ddb48SDavid Howells 	__u8  bDescriptorType;					\
845e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;				\
855e1ddb48SDavid Howells 	__u8  bJackType;					\
865e1ddb48SDavid Howells 	__u8  bJackID;						\
875e1ddb48SDavid Howells 	__u8  bNrInputPins;					\
885e1ddb48SDavid Howells 	struct usb_midi_source_pin pins[p];			\
895e1ddb48SDavid Howells 	__u8  iJack;						\
905e1ddb48SDavid Howells } __attribute__ ((packed))
915e1ddb48SDavid Howells 
925e1ddb48SDavid Howells /* 6.2.2  Class-Specific MS Bulk Data Endpoint Descriptor */
935e1ddb48SDavid Howells struct usb_ms_endpoint_descriptor {
945e1ddb48SDavid Howells 	__u8  bLength;			/* 4+n */
955e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_ENDPOINT */
965e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* USB_MS_GENERAL */
975e1ddb48SDavid Howells 	__u8  bNumEmbMIDIJack;		/* n */
985e1ddb48SDavid Howells 	__u8  baAssocJackID[];		/* [n] */
995e1ddb48SDavid Howells } __attribute__ ((packed));
1005e1ddb48SDavid Howells 
1015e1ddb48SDavid Howells #define USB_DT_MS_ENDPOINT_SIZE(n)	(4 + (n))
1025e1ddb48SDavid Howells 
1035e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */
1045e1ddb48SDavid Howells #define DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(n)			\
1055e1ddb48SDavid Howells struct usb_ms_endpoint_descriptor_##n {				\
1065e1ddb48SDavid Howells 	__u8  bLength;						\
1075e1ddb48SDavid Howells 	__u8  bDescriptorType;					\
1085e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;				\
1095e1ddb48SDavid Howells 	__u8  bNumEmbMIDIJack;					\
1105e1ddb48SDavid Howells 	__u8  baAssocJackID[n];					\
1115e1ddb48SDavid Howells } __attribute__ ((packed))
1125e1ddb48SDavid Howells 
1135e1ddb48SDavid Howells #endif /* __LINUX_USB_MIDI_H */
114