xref: /linux/include/uapi/linux/usb/audio.h (revision 5e1ddb481776a487b15b40579a000b279ce527c9)
1*5e1ddb48SDavid Howells /*
2*5e1ddb48SDavid Howells  * <linux/usb/audio.h> -- USB Audio definitions.
3*5e1ddb48SDavid Howells  *
4*5e1ddb48SDavid Howells  * Copyright (C) 2006 Thumtronics Pty Ltd.
5*5e1ddb48SDavid Howells  * Developed for Thumtronics by Grey Innovation
6*5e1ddb48SDavid Howells  * Ben Williamson <ben.williamson@greyinnovation.com>
7*5e1ddb48SDavid Howells  *
8*5e1ddb48SDavid Howells  * This software is distributed under the terms of the GNU General Public
9*5e1ddb48SDavid Howells  * License ("GPL") version 2, as published by the Free Software Foundation.
10*5e1ddb48SDavid Howells  *
11*5e1ddb48SDavid Howells  * This file holds USB constants and structures defined
12*5e1ddb48SDavid Howells  * by the USB Device Class Definition for Audio Devices.
13*5e1ddb48SDavid Howells  * Comments below reference relevant sections of that document:
14*5e1ddb48SDavid Howells  *
15*5e1ddb48SDavid Howells  * http://www.usb.org/developers/devclass_docs/audio10.pdf
16*5e1ddb48SDavid Howells  *
17*5e1ddb48SDavid Howells  * Types and defines in this file are either specific to version 1.0 of
18*5e1ddb48SDavid Howells  * this standard or common for newer versions.
19*5e1ddb48SDavid Howells  */
20*5e1ddb48SDavid Howells 
21*5e1ddb48SDavid Howells #ifndef _UAPI__LINUX_USB_AUDIO_H
22*5e1ddb48SDavid Howells #define _UAPI__LINUX_USB_AUDIO_H
23*5e1ddb48SDavid Howells 
24*5e1ddb48SDavid Howells #include <linux/types.h>
25*5e1ddb48SDavid Howells 
26*5e1ddb48SDavid Howells /* bInterfaceProtocol values to denote the version of the standard used */
27*5e1ddb48SDavid Howells #define UAC_VERSION_1			0x00
28*5e1ddb48SDavid Howells #define UAC_VERSION_2			0x20
29*5e1ddb48SDavid Howells 
30*5e1ddb48SDavid Howells /* A.2 Audio Interface Subclass Codes */
31*5e1ddb48SDavid Howells #define USB_SUBCLASS_AUDIOCONTROL	0x01
32*5e1ddb48SDavid Howells #define USB_SUBCLASS_AUDIOSTREAMING	0x02
33*5e1ddb48SDavid Howells #define USB_SUBCLASS_MIDISTREAMING	0x03
34*5e1ddb48SDavid Howells 
35*5e1ddb48SDavid Howells /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
36*5e1ddb48SDavid Howells #define UAC_HEADER			0x01
37*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL		0x02
38*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL		0x03
39*5e1ddb48SDavid Howells #define UAC_MIXER_UNIT			0x04
40*5e1ddb48SDavid Howells #define UAC_SELECTOR_UNIT		0x05
41*5e1ddb48SDavid Howells #define UAC_FEATURE_UNIT		0x06
42*5e1ddb48SDavid Howells #define UAC1_PROCESSING_UNIT		0x07
43*5e1ddb48SDavid Howells #define UAC1_EXTENSION_UNIT		0x08
44*5e1ddb48SDavid Howells 
45*5e1ddb48SDavid Howells /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
46*5e1ddb48SDavid Howells #define UAC_AS_GENERAL			0x01
47*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE			0x02
48*5e1ddb48SDavid Howells #define UAC_FORMAT_SPECIFIC		0x03
49*5e1ddb48SDavid Howells 
50*5e1ddb48SDavid Howells /* A.7 Processing Unit Process Types */
51*5e1ddb48SDavid Howells #define UAC_PROCESS_UNDEFINED		0x00
52*5e1ddb48SDavid Howells #define UAC_PROCESS_UP_DOWNMIX		0x01
53*5e1ddb48SDavid Howells #define UAC_PROCESS_DOLBY_PROLOGIC	0x02
54*5e1ddb48SDavid Howells #define UAC_PROCESS_STEREO_EXTENDER	0x03
55*5e1ddb48SDavid Howells #define UAC_PROCESS_REVERB		0x04
56*5e1ddb48SDavid Howells #define UAC_PROCESS_CHORUS		0x05
57*5e1ddb48SDavid Howells #define UAC_PROCESS_DYN_RANGE_COMP	0x06
58*5e1ddb48SDavid Howells 
59*5e1ddb48SDavid Howells /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
60*5e1ddb48SDavid Howells #define UAC_EP_GENERAL			0x01
61*5e1ddb48SDavid Howells 
62*5e1ddb48SDavid Howells /* A.9 Audio Class-Specific Request Codes */
63*5e1ddb48SDavid Howells #define UAC_SET_			0x00
64*5e1ddb48SDavid Howells #define UAC_GET_			0x80
65*5e1ddb48SDavid Howells 
66*5e1ddb48SDavid Howells #define UAC__CUR			0x1
67*5e1ddb48SDavid Howells #define UAC__MIN			0x2
68*5e1ddb48SDavid Howells #define UAC__MAX			0x3
69*5e1ddb48SDavid Howells #define UAC__RES			0x4
70*5e1ddb48SDavid Howells #define UAC__MEM			0x5
71*5e1ddb48SDavid Howells 
72*5e1ddb48SDavid Howells #define UAC_SET_CUR			(UAC_SET_ | UAC__CUR)
73*5e1ddb48SDavid Howells #define UAC_GET_CUR			(UAC_GET_ | UAC__CUR)
74*5e1ddb48SDavid Howells #define UAC_SET_MIN			(UAC_SET_ | UAC__MIN)
75*5e1ddb48SDavid Howells #define UAC_GET_MIN			(UAC_GET_ | UAC__MIN)
76*5e1ddb48SDavid Howells #define UAC_SET_MAX			(UAC_SET_ | UAC__MAX)
77*5e1ddb48SDavid Howells #define UAC_GET_MAX			(UAC_GET_ | UAC__MAX)
78*5e1ddb48SDavid Howells #define UAC_SET_RES			(UAC_SET_ | UAC__RES)
79*5e1ddb48SDavid Howells #define UAC_GET_RES			(UAC_GET_ | UAC__RES)
80*5e1ddb48SDavid Howells #define UAC_SET_MEM			(UAC_SET_ | UAC__MEM)
81*5e1ddb48SDavid Howells #define UAC_GET_MEM			(UAC_GET_ | UAC__MEM)
82*5e1ddb48SDavid Howells 
83*5e1ddb48SDavid Howells #define UAC_GET_STAT			0xff
84*5e1ddb48SDavid Howells 
85*5e1ddb48SDavid Howells /* A.10 Control Selector Codes */
86*5e1ddb48SDavid Howells 
87*5e1ddb48SDavid Howells /* A.10.1 Terminal Control Selectors */
88*5e1ddb48SDavid Howells #define UAC_TERM_COPY_PROTECT		0x01
89*5e1ddb48SDavid Howells 
90*5e1ddb48SDavid Howells /* A.10.2 Feature Unit Control Selectors */
91*5e1ddb48SDavid Howells #define UAC_FU_MUTE			0x01
92*5e1ddb48SDavid Howells #define UAC_FU_VOLUME			0x02
93*5e1ddb48SDavid Howells #define UAC_FU_BASS			0x03
94*5e1ddb48SDavid Howells #define UAC_FU_MID			0x04
95*5e1ddb48SDavid Howells #define UAC_FU_TREBLE			0x05
96*5e1ddb48SDavid Howells #define UAC_FU_GRAPHIC_EQUALIZER	0x06
97*5e1ddb48SDavid Howells #define UAC_FU_AUTOMATIC_GAIN		0x07
98*5e1ddb48SDavid Howells #define UAC_FU_DELAY			0x08
99*5e1ddb48SDavid Howells #define UAC_FU_BASS_BOOST		0x09
100*5e1ddb48SDavid Howells #define UAC_FU_LOUDNESS			0x0a
101*5e1ddb48SDavid Howells 
102*5e1ddb48SDavid Howells #define UAC_CONTROL_BIT(CS)	(1 << ((CS) - 1))
103*5e1ddb48SDavid Howells 
104*5e1ddb48SDavid Howells /* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */
105*5e1ddb48SDavid Howells #define UAC_UD_ENABLE			0x01
106*5e1ddb48SDavid Howells #define UAC_UD_MODE_SELECT		0x02
107*5e1ddb48SDavid Howells 
108*5e1ddb48SDavid Howells /* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */
109*5e1ddb48SDavid Howells #define UAC_DP_ENABLE			0x01
110*5e1ddb48SDavid Howells #define UAC_DP_MODE_SELECT		0x02
111*5e1ddb48SDavid Howells 
112*5e1ddb48SDavid Howells /* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */
113*5e1ddb48SDavid Howells #define UAC_3D_ENABLE			0x01
114*5e1ddb48SDavid Howells #define UAC_3D_SPACE			0x02
115*5e1ddb48SDavid Howells 
116*5e1ddb48SDavid Howells /* A.10.3.4 Reverberation Processing Unit Control Selectors */
117*5e1ddb48SDavid Howells #define UAC_REVERB_ENABLE		0x01
118*5e1ddb48SDavid Howells #define UAC_REVERB_LEVEL		0x02
119*5e1ddb48SDavid Howells #define UAC_REVERB_TIME			0x03
120*5e1ddb48SDavid Howells #define UAC_REVERB_FEEDBACK		0x04
121*5e1ddb48SDavid Howells 
122*5e1ddb48SDavid Howells /* A.10.3.5 Chorus Processing Unit Control Selectors */
123*5e1ddb48SDavid Howells #define UAC_CHORUS_ENABLE		0x01
124*5e1ddb48SDavid Howells #define UAC_CHORUS_LEVEL		0x02
125*5e1ddb48SDavid Howells #define UAC_CHORUS_RATE			0x03
126*5e1ddb48SDavid Howells #define UAC_CHORUS_DEPTH		0x04
127*5e1ddb48SDavid Howells 
128*5e1ddb48SDavid Howells /* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */
129*5e1ddb48SDavid Howells #define UAC_DCR_ENABLE			0x01
130*5e1ddb48SDavid Howells #define UAC_DCR_RATE			0x02
131*5e1ddb48SDavid Howells #define UAC_DCR_MAXAMPL			0x03
132*5e1ddb48SDavid Howells #define UAC_DCR_THRESHOLD		0x04
133*5e1ddb48SDavid Howells #define UAC_DCR_ATTACK_TIME		0x05
134*5e1ddb48SDavid Howells #define UAC_DCR_RELEASE_TIME		0x06
135*5e1ddb48SDavid Howells 
136*5e1ddb48SDavid Howells /* A.10.4 Extension Unit Control Selectors */
137*5e1ddb48SDavid Howells #define UAC_XU_ENABLE			0x01
138*5e1ddb48SDavid Howells 
139*5e1ddb48SDavid Howells /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
140*5e1ddb48SDavid Howells #define UAC_MS_HEADER			0x01
141*5e1ddb48SDavid Howells #define UAC_MIDI_IN_JACK		0x02
142*5e1ddb48SDavid Howells #define UAC_MIDI_OUT_JACK		0x03
143*5e1ddb48SDavid Howells 
144*5e1ddb48SDavid Howells /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
145*5e1ddb48SDavid Howells #define UAC_MS_GENERAL			0x01
146*5e1ddb48SDavid Howells 
147*5e1ddb48SDavid Howells /* Terminals - 2.1 USB Terminal Types */
148*5e1ddb48SDavid Howells #define UAC_TERMINAL_UNDEFINED		0x100
149*5e1ddb48SDavid Howells #define UAC_TERMINAL_STREAMING		0x101
150*5e1ddb48SDavid Howells #define UAC_TERMINAL_VENDOR_SPEC	0x1FF
151*5e1ddb48SDavid Howells 
152*5e1ddb48SDavid Howells /* Terminal Control Selectors */
153*5e1ddb48SDavid Howells /* 4.3.2  Class-Specific AC Interface Descriptor */
154*5e1ddb48SDavid Howells struct uac1_ac_header_descriptor {
155*5e1ddb48SDavid Howells 	__u8  bLength;			/* 8 + n */
156*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
157*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* UAC_MS_HEADER */
158*5e1ddb48SDavid Howells 	__le16 bcdADC;			/* 0x0100 */
159*5e1ddb48SDavid Howells 	__le16 wTotalLength;		/* includes Unit and Terminal desc. */
160*5e1ddb48SDavid Howells 	__u8  bInCollection;		/* n */
161*5e1ddb48SDavid Howells 	__u8  baInterfaceNr[];		/* [n] */
162*5e1ddb48SDavid Howells } __attribute__ ((packed));
163*5e1ddb48SDavid Howells 
164*5e1ddb48SDavid Howells #define UAC_DT_AC_HEADER_SIZE(n)	(8 + (n))
165*5e1ddb48SDavid Howells 
166*5e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */
167*5e1ddb48SDavid Howells #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n)			\
168*5e1ddb48SDavid Howells struct uac1_ac_header_descriptor_##n {			\
169*5e1ddb48SDavid Howells 	__u8  bLength;						\
170*5e1ddb48SDavid Howells 	__u8  bDescriptorType;					\
171*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;				\
172*5e1ddb48SDavid Howells 	__le16 bcdADC;						\
173*5e1ddb48SDavid Howells 	__le16 wTotalLength;					\
174*5e1ddb48SDavid Howells 	__u8  bInCollection;					\
175*5e1ddb48SDavid Howells 	__u8  baInterfaceNr[n];					\
176*5e1ddb48SDavid Howells } __attribute__ ((packed))
177*5e1ddb48SDavid Howells 
178*5e1ddb48SDavid Howells /* 4.3.2.1 Input Terminal Descriptor */
179*5e1ddb48SDavid Howells struct uac_input_terminal_descriptor {
180*5e1ddb48SDavid Howells 	__u8  bLength;			/* in bytes: 12 */
181*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* CS_INTERFACE descriptor type */
182*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* INPUT_TERMINAL descriptor subtype */
183*5e1ddb48SDavid Howells 	__u8  bTerminalID;		/* Constant uniquely terminal ID */
184*5e1ddb48SDavid Howells 	__le16 wTerminalType;		/* USB Audio Terminal Types */
185*5e1ddb48SDavid Howells 	__u8  bAssocTerminal;		/* ID of the Output Terminal associated */
186*5e1ddb48SDavid Howells 	__u8  bNrChannels;		/* Number of logical output channels */
187*5e1ddb48SDavid Howells 	__le16 wChannelConfig;
188*5e1ddb48SDavid Howells 	__u8  iChannelNames;
189*5e1ddb48SDavid Howells 	__u8  iTerminal;
190*5e1ddb48SDavid Howells } __attribute__ ((packed));
191*5e1ddb48SDavid Howells 
192*5e1ddb48SDavid Howells #define UAC_DT_INPUT_TERMINAL_SIZE			12
193*5e1ddb48SDavid Howells 
194*5e1ddb48SDavid Howells /* Terminals - 2.2 Input Terminal Types */
195*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_UNDEFINED			0x200
196*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_MICROPHONE			0x201
197*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE		0x202
198*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE		0x203
199*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE		0x204
200*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY		0x205
201*5e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY	0x206
202*5e1ddb48SDavid Howells 
203*5e1ddb48SDavid Howells /* Terminals - control selectors */
204*5e1ddb48SDavid Howells 
205*5e1ddb48SDavid Howells #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL		0x01
206*5e1ddb48SDavid Howells 
207*5e1ddb48SDavid Howells /* 4.3.2.2 Output Terminal Descriptor */
208*5e1ddb48SDavid Howells struct uac1_output_terminal_descriptor {
209*5e1ddb48SDavid Howells 	__u8  bLength;			/* in bytes: 9 */
210*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* CS_INTERFACE descriptor type */
211*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* OUTPUT_TERMINAL descriptor subtype */
212*5e1ddb48SDavid Howells 	__u8  bTerminalID;		/* Constant uniquely terminal ID */
213*5e1ddb48SDavid Howells 	__le16 wTerminalType;		/* USB Audio Terminal Types */
214*5e1ddb48SDavid Howells 	__u8  bAssocTerminal;		/* ID of the Input Terminal associated */
215*5e1ddb48SDavid Howells 	__u8  bSourceID;		/* ID of the connected Unit or Terminal*/
216*5e1ddb48SDavid Howells 	__u8  iTerminal;
217*5e1ddb48SDavid Howells } __attribute__ ((packed));
218*5e1ddb48SDavid Howells 
219*5e1ddb48SDavid Howells #define UAC_DT_OUTPUT_TERMINAL_SIZE			9
220*5e1ddb48SDavid Howells 
221*5e1ddb48SDavid Howells /* Terminals - 2.3 Output Terminal Types */
222*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_UNDEFINED			0x300
223*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_SPEAKER			0x301
224*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_HEADPHONES			0x302
225*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO	0x303
226*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER		0x304
227*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER		0x305
228*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER	0x306
229*5e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER	0x307
230*5e1ddb48SDavid Howells 
231*5e1ddb48SDavid Howells /* Set bControlSize = 2 as default setting */
232*5e1ddb48SDavid Howells #define UAC_DT_FEATURE_UNIT_SIZE(ch)		(7 + ((ch) + 1) * 2)
233*5e1ddb48SDavid Howells 
234*5e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */
235*5e1ddb48SDavid Howells #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch)			\
236*5e1ddb48SDavid Howells struct uac_feature_unit_descriptor_##ch {			\
237*5e1ddb48SDavid Howells 	__u8  bLength;						\
238*5e1ddb48SDavid Howells 	__u8  bDescriptorType;					\
239*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;				\
240*5e1ddb48SDavid Howells 	__u8  bUnitID;						\
241*5e1ddb48SDavid Howells 	__u8  bSourceID;					\
242*5e1ddb48SDavid Howells 	__u8  bControlSize;					\
243*5e1ddb48SDavid Howells 	__le16 bmaControls[ch + 1];				\
244*5e1ddb48SDavid Howells 	__u8  iFeature;						\
245*5e1ddb48SDavid Howells } __attribute__ ((packed))
246*5e1ddb48SDavid Howells 
247*5e1ddb48SDavid Howells /* 4.3.2.3 Mixer Unit Descriptor */
248*5e1ddb48SDavid Howells struct uac_mixer_unit_descriptor {
249*5e1ddb48SDavid Howells 	__u8 bLength;
250*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
251*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
252*5e1ddb48SDavid Howells 	__u8 bUnitID;
253*5e1ddb48SDavid Howells 	__u8 bNrInPins;
254*5e1ddb48SDavid Howells 	__u8 baSourceID[];
255*5e1ddb48SDavid Howells } __attribute__ ((packed));
256*5e1ddb48SDavid Howells 
257*5e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc)
258*5e1ddb48SDavid Howells {
259*5e1ddb48SDavid Howells 	return desc->baSourceID[desc->bNrInPins];
260*5e1ddb48SDavid Howells }
261*5e1ddb48SDavid Howells 
262*5e1ddb48SDavid Howells static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc,
263*5e1ddb48SDavid Howells 						  int protocol)
264*5e1ddb48SDavid Howells {
265*5e1ddb48SDavid Howells 	if (protocol == UAC_VERSION_1)
266*5e1ddb48SDavid Howells 		return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
267*5e1ddb48SDavid Howells 			desc->baSourceID[desc->bNrInPins + 1];
268*5e1ddb48SDavid Howells 	else
269*5e1ddb48SDavid Howells 		return  (desc->baSourceID[desc->bNrInPins + 4] << 24) |
270*5e1ddb48SDavid Howells 			(desc->baSourceID[desc->bNrInPins + 3] << 16) |
271*5e1ddb48SDavid Howells 			(desc->baSourceID[desc->bNrInPins + 2] << 8)  |
272*5e1ddb48SDavid Howells 			(desc->baSourceID[desc->bNrInPins + 1]);
273*5e1ddb48SDavid Howells }
274*5e1ddb48SDavid Howells 
275*5e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc,
276*5e1ddb48SDavid Howells 						int protocol)
277*5e1ddb48SDavid Howells {
278*5e1ddb48SDavid Howells 	return (protocol == UAC_VERSION_1) ?
279*5e1ddb48SDavid Howells 		desc->baSourceID[desc->bNrInPins + 3] :
280*5e1ddb48SDavid Howells 		desc->baSourceID[desc->bNrInPins + 5];
281*5e1ddb48SDavid Howells }
282*5e1ddb48SDavid Howells 
283*5e1ddb48SDavid Howells static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc,
284*5e1ddb48SDavid Howells 					      int protocol)
285*5e1ddb48SDavid Howells {
286*5e1ddb48SDavid Howells 	return (protocol == UAC_VERSION_1) ?
287*5e1ddb48SDavid Howells 		&desc->baSourceID[desc->bNrInPins + 4] :
288*5e1ddb48SDavid Howells 		&desc->baSourceID[desc->bNrInPins + 6];
289*5e1ddb48SDavid Howells }
290*5e1ddb48SDavid Howells 
291*5e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc)
292*5e1ddb48SDavid Howells {
293*5e1ddb48SDavid Howells 	__u8 *raw = (__u8 *) desc;
294*5e1ddb48SDavid Howells 	return raw[desc->bLength - 1];
295*5e1ddb48SDavid Howells }
296*5e1ddb48SDavid Howells 
297*5e1ddb48SDavid Howells /* 4.3.2.4 Selector Unit Descriptor */
298*5e1ddb48SDavid Howells struct uac_selector_unit_descriptor {
299*5e1ddb48SDavid Howells 	__u8 bLength;
300*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
301*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
302*5e1ddb48SDavid Howells 	__u8 bUintID;
303*5e1ddb48SDavid Howells 	__u8 bNrInPins;
304*5e1ddb48SDavid Howells 	__u8 baSourceID[];
305*5e1ddb48SDavid Howells } __attribute__ ((packed));
306*5e1ddb48SDavid Howells 
307*5e1ddb48SDavid Howells static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc)
308*5e1ddb48SDavid Howells {
309*5e1ddb48SDavid Howells 	__u8 *raw = (__u8 *) desc;
310*5e1ddb48SDavid Howells 	return raw[desc->bLength - 1];
311*5e1ddb48SDavid Howells }
312*5e1ddb48SDavid Howells 
313*5e1ddb48SDavid Howells /* 4.3.2.5 Feature Unit Descriptor */
314*5e1ddb48SDavid Howells struct uac_feature_unit_descriptor {
315*5e1ddb48SDavid Howells 	__u8 bLength;
316*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
317*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
318*5e1ddb48SDavid Howells 	__u8 bUnitID;
319*5e1ddb48SDavid Howells 	__u8 bSourceID;
320*5e1ddb48SDavid Howells 	__u8 bControlSize;
321*5e1ddb48SDavid Howells 	__u8 bmaControls[0]; /* variable length */
322*5e1ddb48SDavid Howells } __attribute__((packed));
323*5e1ddb48SDavid Howells 
324*5e1ddb48SDavid Howells static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc)
325*5e1ddb48SDavid Howells {
326*5e1ddb48SDavid Howells 	__u8 *raw = (__u8 *) desc;
327*5e1ddb48SDavid Howells 	return raw[desc->bLength - 1];
328*5e1ddb48SDavid Howells }
329*5e1ddb48SDavid Howells 
330*5e1ddb48SDavid Howells /* 4.3.2.6 Processing Unit Descriptors */
331*5e1ddb48SDavid Howells struct uac_processing_unit_descriptor {
332*5e1ddb48SDavid Howells 	__u8 bLength;
333*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
334*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
335*5e1ddb48SDavid Howells 	__u8 bUnitID;
336*5e1ddb48SDavid Howells 	__u16 wProcessType;
337*5e1ddb48SDavid Howells 	__u8 bNrInPins;
338*5e1ddb48SDavid Howells 	__u8 baSourceID[];
339*5e1ddb48SDavid Howells } __attribute__ ((packed));
340*5e1ddb48SDavid Howells 
341*5e1ddb48SDavid Howells static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc)
342*5e1ddb48SDavid Howells {
343*5e1ddb48SDavid Howells 	return desc->baSourceID[desc->bNrInPins];
344*5e1ddb48SDavid Howells }
345*5e1ddb48SDavid Howells 
346*5e1ddb48SDavid Howells static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc,
347*5e1ddb48SDavid Howells 						       int protocol)
348*5e1ddb48SDavid Howells {
349*5e1ddb48SDavid Howells 	if (protocol == UAC_VERSION_1)
350*5e1ddb48SDavid Howells 		return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
351*5e1ddb48SDavid Howells 			desc->baSourceID[desc->bNrInPins + 1];
352*5e1ddb48SDavid Howells 	else
353*5e1ddb48SDavid Howells 		return  (desc->baSourceID[desc->bNrInPins + 4] << 24) |
354*5e1ddb48SDavid Howells 			(desc->baSourceID[desc->bNrInPins + 3] << 16) |
355*5e1ddb48SDavid Howells 			(desc->baSourceID[desc->bNrInPins + 2] << 8)  |
356*5e1ddb48SDavid Howells 			(desc->baSourceID[desc->bNrInPins + 1]);
357*5e1ddb48SDavid Howells }
358*5e1ddb48SDavid Howells 
359*5e1ddb48SDavid Howells static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc,
360*5e1ddb48SDavid Howells 						     int protocol)
361*5e1ddb48SDavid Howells {
362*5e1ddb48SDavid Howells 	return (protocol == UAC_VERSION_1) ?
363*5e1ddb48SDavid Howells 		desc->baSourceID[desc->bNrInPins + 3] :
364*5e1ddb48SDavid Howells 		desc->baSourceID[desc->bNrInPins + 5];
365*5e1ddb48SDavid Howells }
366*5e1ddb48SDavid Howells 
367*5e1ddb48SDavid Howells static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc,
368*5e1ddb48SDavid Howells 						    int protocol)
369*5e1ddb48SDavid Howells {
370*5e1ddb48SDavid Howells 	return (protocol == UAC_VERSION_1) ?
371*5e1ddb48SDavid Howells 		desc->baSourceID[desc->bNrInPins + 4] :
372*5e1ddb48SDavid Howells 		desc->baSourceID[desc->bNrInPins + 6];
373*5e1ddb48SDavid Howells }
374*5e1ddb48SDavid Howells 
375*5e1ddb48SDavid Howells static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc,
376*5e1ddb48SDavid Howells 						   int protocol)
377*5e1ddb48SDavid Howells {
378*5e1ddb48SDavid Howells 	return (protocol == UAC_VERSION_1) ?
379*5e1ddb48SDavid Howells 		&desc->baSourceID[desc->bNrInPins + 5] :
380*5e1ddb48SDavid Howells 		&desc->baSourceID[desc->bNrInPins + 7];
381*5e1ddb48SDavid Howells }
382*5e1ddb48SDavid Howells 
383*5e1ddb48SDavid Howells static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc,
384*5e1ddb48SDavid Howells 						   int protocol)
385*5e1ddb48SDavid Howells {
386*5e1ddb48SDavid Howells 	__u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
387*5e1ddb48SDavid Howells 	return desc->baSourceID[desc->bNrInPins + control_size];
388*5e1ddb48SDavid Howells }
389*5e1ddb48SDavid Howells 
390*5e1ddb48SDavid Howells static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc,
391*5e1ddb48SDavid Howells 						 int protocol)
392*5e1ddb48SDavid Howells {
393*5e1ddb48SDavid Howells 	__u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
394*5e1ddb48SDavid Howells 	return &desc->baSourceID[desc->bNrInPins + control_size + 1];
395*5e1ddb48SDavid Howells }
396*5e1ddb48SDavid Howells 
397*5e1ddb48SDavid Howells /* 4.5.2 Class-Specific AS Interface Descriptor */
398*5e1ddb48SDavid Howells struct uac1_as_header_descriptor {
399*5e1ddb48SDavid Howells 	__u8  bLength;			/* in bytes: 7 */
400*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
401*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* AS_GENERAL */
402*5e1ddb48SDavid Howells 	__u8  bTerminalLink;		/* Terminal ID of connected Terminal */
403*5e1ddb48SDavid Howells 	__u8  bDelay;			/* Delay introduced by the data path */
404*5e1ddb48SDavid Howells 	__le16 wFormatTag;		/* The Audio Data Format */
405*5e1ddb48SDavid Howells } __attribute__ ((packed));
406*5e1ddb48SDavid Howells 
407*5e1ddb48SDavid Howells #define UAC_DT_AS_HEADER_SIZE		7
408*5e1ddb48SDavid Howells 
409*5e1ddb48SDavid Howells /* Formats - A.1.1 Audio Data Format Type I Codes */
410*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_UNDEFINED	0x0
411*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_PCM		0x1
412*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_PCM8		0x2
413*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_IEEE_FLOAT	0x3
414*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_ALAW		0x4
415*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_MULAW		0x5
416*5e1ddb48SDavid Howells 
417*5e1ddb48SDavid Howells struct uac_format_type_i_continuous_descriptor {
418*5e1ddb48SDavid Howells 	__u8  bLength;			/* in bytes: 8 + (ns * 3) */
419*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
420*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* FORMAT_TYPE */
421*5e1ddb48SDavid Howells 	__u8  bFormatType;		/* FORMAT_TYPE_1 */
422*5e1ddb48SDavid Howells 	__u8  bNrChannels;		/* physical channels in the stream */
423*5e1ddb48SDavid Howells 	__u8  bSubframeSize;		/* */
424*5e1ddb48SDavid Howells 	__u8  bBitResolution;
425*5e1ddb48SDavid Howells 	__u8  bSamFreqType;
426*5e1ddb48SDavid Howells 	__u8  tLowerSamFreq[3];
427*5e1ddb48SDavid Howells 	__u8  tUpperSamFreq[3];
428*5e1ddb48SDavid Howells } __attribute__ ((packed));
429*5e1ddb48SDavid Howells 
430*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE	14
431*5e1ddb48SDavid Howells 
432*5e1ddb48SDavid Howells struct uac_format_type_i_discrete_descriptor {
433*5e1ddb48SDavid Howells 	__u8  bLength;			/* in bytes: 8 + (ns * 3) */
434*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
435*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* FORMAT_TYPE */
436*5e1ddb48SDavid Howells 	__u8  bFormatType;		/* FORMAT_TYPE_1 */
437*5e1ddb48SDavid Howells 	__u8  bNrChannels;		/* physical channels in the stream */
438*5e1ddb48SDavid Howells 	__u8  bSubframeSize;		/* */
439*5e1ddb48SDavid Howells 	__u8  bBitResolution;
440*5e1ddb48SDavid Howells 	__u8  bSamFreqType;
441*5e1ddb48SDavid Howells 	__u8  tSamFreq[][3];
442*5e1ddb48SDavid Howells } __attribute__ ((packed));
443*5e1ddb48SDavid Howells 
444*5e1ddb48SDavid Howells #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n)		\
445*5e1ddb48SDavid Howells struct uac_format_type_i_discrete_descriptor_##n {		\
446*5e1ddb48SDavid Howells 	__u8  bLength;						\
447*5e1ddb48SDavid Howells 	__u8  bDescriptorType;					\
448*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;				\
449*5e1ddb48SDavid Howells 	__u8  bFormatType;					\
450*5e1ddb48SDavid Howells 	__u8  bNrChannels;					\
451*5e1ddb48SDavid Howells 	__u8  bSubframeSize;					\
452*5e1ddb48SDavid Howells 	__u8  bBitResolution;					\
453*5e1ddb48SDavid Howells 	__u8  bSamFreqType;					\
454*5e1ddb48SDavid Howells 	__u8  tSamFreq[n][3];					\
455*5e1ddb48SDavid Howells } __attribute__ ((packed))
456*5e1ddb48SDavid Howells 
457*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n)	(8 + (n * 3))
458*5e1ddb48SDavid Howells 
459*5e1ddb48SDavid Howells struct uac_format_type_i_ext_descriptor {
460*5e1ddb48SDavid Howells 	__u8 bLength;
461*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
462*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
463*5e1ddb48SDavid Howells 	__u8 bFormatType;
464*5e1ddb48SDavid Howells 	__u8 bSubslotSize;
465*5e1ddb48SDavid Howells 	__u8 bBitResolution;
466*5e1ddb48SDavid Howells 	__u8 bHeaderLength;
467*5e1ddb48SDavid Howells 	__u8 bControlSize;
468*5e1ddb48SDavid Howells 	__u8 bSideBandProtocol;
469*5e1ddb48SDavid Howells } __attribute__((packed));
470*5e1ddb48SDavid Howells 
471*5e1ddb48SDavid Howells /* Formats - Audio Data Format Type I Codes */
472*5e1ddb48SDavid Howells 
473*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II_MPEG	0x1001
474*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II_AC3	0x1002
475*5e1ddb48SDavid Howells 
476*5e1ddb48SDavid Howells struct uac_format_type_ii_discrete_descriptor {
477*5e1ddb48SDavid Howells 	__u8 bLength;
478*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
479*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
480*5e1ddb48SDavid Howells 	__u8 bFormatType;
481*5e1ddb48SDavid Howells 	__le16 wMaxBitRate;
482*5e1ddb48SDavid Howells 	__le16 wSamplesPerFrame;
483*5e1ddb48SDavid Howells 	__u8 bSamFreqType;
484*5e1ddb48SDavid Howells 	__u8 tSamFreq[][3];
485*5e1ddb48SDavid Howells } __attribute__((packed));
486*5e1ddb48SDavid Howells 
487*5e1ddb48SDavid Howells struct uac_format_type_ii_ext_descriptor {
488*5e1ddb48SDavid Howells 	__u8 bLength;
489*5e1ddb48SDavid Howells 	__u8 bDescriptorType;
490*5e1ddb48SDavid Howells 	__u8 bDescriptorSubtype;
491*5e1ddb48SDavid Howells 	__u8 bFormatType;
492*5e1ddb48SDavid Howells 	__u16 wMaxBitRate;
493*5e1ddb48SDavid Howells 	__u16 wSamplesPerFrame;
494*5e1ddb48SDavid Howells 	__u8 bHeaderLength;
495*5e1ddb48SDavid Howells 	__u8 bSideBandProtocol;
496*5e1ddb48SDavid Howells } __attribute__((packed));
497*5e1ddb48SDavid Howells 
498*5e1ddb48SDavid Howells /* type III */
499*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_AC3	0x2001
500*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1	0x2002
501*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT	0x2003
502*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT	0x2004
503*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS	0x2005
504*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS	0x2006
505*5e1ddb48SDavid Howells 
506*5e1ddb48SDavid Howells /* Formats - A.2 Format Type Codes */
507*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_UNDEFINED	0x0
508*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I		0x1
509*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II		0x2
510*5e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III		0x3
511*5e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_I		0x81
512*5e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_II		0x82
513*5e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_III		0x83
514*5e1ddb48SDavid Howells 
515*5e1ddb48SDavid Howells struct uac_iso_endpoint_descriptor {
516*5e1ddb48SDavid Howells 	__u8  bLength;			/* in bytes: 7 */
517*5e1ddb48SDavid Howells 	__u8  bDescriptorType;		/* USB_DT_CS_ENDPOINT */
518*5e1ddb48SDavid Howells 	__u8  bDescriptorSubtype;	/* EP_GENERAL */
519*5e1ddb48SDavid Howells 	__u8  bmAttributes;
520*5e1ddb48SDavid Howells 	__u8  bLockDelayUnits;
521*5e1ddb48SDavid Howells 	__le16 wLockDelay;
522*5e1ddb48SDavid Howells } __attribute__((packed));
523*5e1ddb48SDavid Howells #define UAC_ISO_ENDPOINT_DESC_SIZE	7
524*5e1ddb48SDavid Howells 
525*5e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_SAMPLE_RATE	0x01
526*5e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_PITCH_CONTROL	0x02
527*5e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_FILL_MAX		0x80
528*5e1ddb48SDavid Howells 
529*5e1ddb48SDavid Howells /* status word format (3.7.1.1) */
530*5e1ddb48SDavid Howells 
531*5e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_MASK		0x0f
532*5e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF	0x0
533*5e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF	0x1
534*5e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP	0x2
535*5e1ddb48SDavid Howells 
536*5e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_IRQ_PENDING		(1 << 7)
537*5e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_MEM_CHANGED		(1 << 6)
538*5e1ddb48SDavid Howells 
539*5e1ddb48SDavid Howells struct uac1_status_word {
540*5e1ddb48SDavid Howells 	__u8 bStatusType;
541*5e1ddb48SDavid Howells 	__u8 bOriginator;
542*5e1ddb48SDavid Howells } __attribute__((packed));
543*5e1ddb48SDavid Howells 
544*5e1ddb48SDavid Howells 
545*5e1ddb48SDavid Howells #endif /* _UAPI__LINUX_USB_AUDIO_H */
546