2 * <linux/usb/audio.h> -- USB Audio definitions.
4 * Copyright (C) 2006 Thumtronics Pty Ltd.
5 * Developed for Thumtronics by Grey Innovation
6 * Ben Williamson <ben.williamson@greyinnovation.com>
8 * This software is distributed under the terms of the GNU General Public
9 * License ("GPL") version 2, as published by the Free Software Foundation.
11 * This file holds USB constants and structures defined
12 * by the USB Device Class Definition for Audio Devices.
13 * Comments below reference relevant sections of that document:
15 * http://www.usb.org/developers/devclass_docs/audio10.pdf
18 #ifndef __LINUX_USB_AUDIO_H
19 #define __LINUX_USB_AUDIO_H
21 #include <linux/types.h>
23 /* A.2 Audio Interface Subclass Codes */
24 #define USB_SUBCLASS_AUDIOCONTROL 0x01
25 #define USB_SUBCLASS_AUDIOSTREAMING 0x02
26 #define USB_SUBCLASS_MIDISTREAMING 0x03
28 #define UAC_VERSION_1 0x00
29 #define UAC_VERSION_2 0x20
31 /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
32 #define UAC_HEADER 0x01
33 #define UAC_INPUT_TERMINAL 0x02
34 #define UAC_OUTPUT_TERMINAL 0x03
35 #define UAC_MIXER_UNIT 0x04
36 #define UAC_SELECTOR_UNIT 0x05
37 #define UAC_FEATURE_UNIT 0x06
38 #define UAC_PROCESSING_UNIT_V1 0x07
39 #define UAC_EXTENSION_UNIT_V1 0x08
42 #define UAC_EFFECT_UNIT 0x07
43 #define UAC_PROCESSING_UNIT_V2 0x08
44 #define UAC_EXTENSION_UNIT_V2 0x09
45 #define UAC_CLOCK_SOURCE 0x0a
46 #define UAC_CLOCK_SELECTOR 0x0b
47 #define UAC_CLOCK_MULTIPLIER 0x0c
48 #define UAC_SAMPLE_RATE_CONVERTER 0x0d
50 /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
51 #define UAC_AS_GENERAL 0x01
52 #define UAC_FORMAT_TYPE 0x02
53 #define UAC_FORMAT_SPECIFIC 0x03
55 /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
56 #define UAC_EP_GENERAL 0x01
58 /* A.9 Audio Class-Specific Request Codes */
68 #define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
69 #define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
70 #define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
71 #define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
72 #define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
73 #define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
74 #define UAC_SET_RES (UAC_SET_ | UAC__RES)
75 #define UAC_GET_RES (UAC_GET_ | UAC__RES)
76 #define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
77 #define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
79 #define UAC_GET_STAT 0xff
81 /* Audio class v2.0 handles all the parameter calls differently */
82 #define UAC2_CS_CUR 0x01
83 #define UAC2_CS_RANGE 0x02
85 /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
86 #define UAC_MS_HEADER 0x01
87 #define UAC_MIDI_IN_JACK 0x02
88 #define UAC_MIDI_OUT_JACK 0x03
90 /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
91 #define UAC_MS_GENERAL 0x01
93 /* Terminals - 2.1 USB Terminal Types */
94 #define UAC_TERMINAL_UNDEFINED 0x100
95 #define UAC_TERMINAL_STREAMING 0x101
96 #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
98 /* Terminal Control Selectors */
99 /* 4.3.2 Class-Specific AC Interface Descriptor */
100 struct uac_ac_header_descriptor_v1 {
101 __u8 bLength; /* 8 + n */
102 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
103 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
104 __le16 bcdADC; /* 0x0100 */
105 __le16 wTotalLength; /* includes Unit and Terminal desc. */
106 __u8 bInCollection; /* n */
107 __u8 baInterfaceNr[]; /* [n] */
108 } __attribute__ ((packed));
110 #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
112 /* As above, but more useful for defining your own descriptors: */
113 #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
114 struct uac_ac_header_descriptor_v1_##n { \
116 __u8 bDescriptorType; \
117 __u8 bDescriptorSubtype; \
119 __le16 wTotalLength; \
120 __u8 bInCollection; \
121 __u8 baInterfaceNr[n]; \
122 } __attribute__ ((packed))
124 /* 4.3.2.1 Input Terminal Descriptor */
125 struct uac_input_terminal_descriptor {
126 __u8 bLength; /* in bytes: 12 */
127 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
128 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
129 __u8 bTerminalID; /* Constant uniquely terminal ID */
130 __le16 wTerminalType; /* USB Audio Terminal Types */
131 __u8 bAssocTerminal; /* ID of the Output Terminal associated */
132 __u8 bNrChannels; /* Number of logical output channels */
133 __le16 wChannelConfig;
136 } __attribute__ ((packed));
138 #define UAC_DT_INPUT_TERMINAL_SIZE 12
140 /* Terminals - 2.2 Input Terminal Types */
141 #define UAC_INPUT_TERMINAL_UNDEFINED 0x200
142 #define UAC_INPUT_TERMINAL_MICROPHONE 0x201
143 #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
144 #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
145 #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
146 #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
147 #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
149 /* Terminals - control selectors */
151 #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
153 /* 4.3.2.2 Output Terminal Descriptor */
154 struct uac_output_terminal_descriptor_v1 {
155 __u8 bLength; /* in bytes: 9 */
156 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
157 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
158 __u8 bTerminalID; /* Constant uniquely terminal ID */
159 __le16 wTerminalType; /* USB Audio Terminal Types */
160 __u8 bAssocTerminal; /* ID of the Input Terminal associated */
161 __u8 bSourceID; /* ID of the connected Unit or Terminal*/
163 } __attribute__ ((packed));
165 #define UAC_DT_OUTPUT_TERMINAL_SIZE 9
167 /* Terminals - 2.3 Output Terminal Types */
168 #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
169 #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
170 #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
171 #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
172 #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
173 #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
174 #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
175 #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
177 /* Set bControlSize = 2 as default setting */
178 #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
180 /* As above, but more useful for defining your own descriptors: */
181 #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
182 struct uac_feature_unit_descriptor_##ch { \
184 __u8 bDescriptorType; \
185 __u8 bDescriptorSubtype; \
189 __le16 bmaControls[ch + 1]; \
191 } __attribute__ ((packed))
193 /* 4.5.2 Class-Specific AS Interface Descriptor */
194 struct uac_as_header_descriptor_v1 {
195 __u8 bLength; /* in bytes: 7 */
196 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
197 __u8 bDescriptorSubtype; /* AS_GENERAL */
198 __u8 bTerminalLink; /* Terminal ID of connected Terminal */
199 __u8 bDelay; /* Delay introduced by the data path */
200 __le16 wFormatTag; /* The Audio Data Format */
201 } __attribute__ ((packed));
203 struct uac_as_header_descriptor_v2 {
205 __u8 bDescriptorType;
206 __u8 bDescriptorSubtype;
212 __u32 bmChannelConfig;
214 } __attribute__((packed));
216 #define UAC_DT_AS_HEADER_SIZE 7
218 /* Formats - A.1.1 Audio Data Format Type I Codes */
219 #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
220 #define UAC_FORMAT_TYPE_I_PCM 0x1
221 #define UAC_FORMAT_TYPE_I_PCM8 0x2
222 #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
223 #define UAC_FORMAT_TYPE_I_ALAW 0x4
224 #define UAC_FORMAT_TYPE_I_MULAW 0x5
226 struct uac_format_type_i_continuous_descriptor {
227 __u8 bLength; /* in bytes: 8 + (ns * 3) */
228 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
229 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
230 __u8 bFormatType; /* FORMAT_TYPE_1 */
231 __u8 bNrChannels; /* physical channels in the stream */
232 __u8 bSubframeSize; /* */
235 __u8 tLowerSamFreq[3];
236 __u8 tUpperSamFreq[3];
237 } __attribute__ ((packed));
239 #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
241 struct uac_format_type_i_discrete_descriptor {
242 __u8 bLength; /* in bytes: 8 + (ns * 3) */
243 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
244 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
245 __u8 bFormatType; /* FORMAT_TYPE_1 */
246 __u8 bNrChannels; /* physical channels in the stream */
247 __u8 bSubframeSize; /* */
251 } __attribute__ ((packed));
253 #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
254 struct uac_format_type_i_discrete_descriptor_##n { \
256 __u8 bDescriptorType; \
257 __u8 bDescriptorSubtype; \
260 __u8 bSubframeSize; \
261 __u8 bBitResolution; \
263 __u8 tSamFreq[n][3]; \
264 } __attribute__ ((packed))
266 #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
268 struct uac_format_type_i_ext_descriptor {
270 __u8 bDescriptorType;
271 __u8 bDescriptorSubtype;
277 __u8 bSideBandProtocol;
278 } __attribute__((packed));
281 /* Formats - Audio Data Format Type I Codes */
283 #define UAC_FORMAT_TYPE_II_MPEG 0x1001
284 #define UAC_FORMAT_TYPE_II_AC3 0x1002
286 struct uac_format_type_ii_discrete_descriptor {
288 __u8 bDescriptorType;
289 __u8 bDescriptorSubtype;
292 __le16 wSamplesPerFrame;
295 } __attribute__((packed));
297 struct uac_format_type_ii_ext_descriptor {
299 __u8 bDescriptorType;
300 __u8 bDescriptorSubtype;
303 __u16 wSamplesPerFrame;
305 __u8 bSideBandProtocol;
306 } __attribute__((packed));
309 #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001
310 #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002
311 #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003
312 #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004
313 #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005
314 #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006
316 /* Formats - A.2 Format Type Codes */
317 #define UAC_FORMAT_TYPE_UNDEFINED 0x0
318 #define UAC_FORMAT_TYPE_I 0x1
319 #define UAC_FORMAT_TYPE_II 0x2
320 #define UAC_FORMAT_TYPE_III 0x3
321 #define UAC_EXT_FORMAT_TYPE_I 0x81
322 #define UAC_EXT_FORMAT_TYPE_II 0x82
323 #define UAC_EXT_FORMAT_TYPE_III 0x83
325 struct uac_iso_endpoint_descriptor {
326 __u8 bLength; /* in bytes: 7 */
327 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
328 __u8 bDescriptorSubtype; /* EP_GENERAL */
330 __u8 bLockDelayUnits;
333 #define UAC_ISO_ENDPOINT_DESC_SIZE 7
335 #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
336 #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
337 #define UAC_EP_CS_ATTR_FILL_MAX 0x80
339 /* Audio class v2.0: CLOCK_SOURCE descriptor */
341 struct uac_clock_source_descriptor {
343 __u8 bDescriptorType;
344 __u8 bDescriptorSubtype;
350 } __attribute__((packed));
352 /* A.10.2 Feature Unit Control Selectors */
354 struct uac_feature_unit_descriptor {
356 __u8 bDescriptorType;
357 __u8 bDescriptorSubtype;
361 __u8 controls[0]; /* variable length */
362 } __attribute__((packed));
364 #define UAC_FU_CONTROL_UNDEFINED 0x00
365 #define UAC_MUTE_CONTROL 0x01
366 #define UAC_VOLUME_CONTROL 0x02
367 #define UAC_BASS_CONTROL 0x03
368 #define UAC_MID_CONTROL 0x04
369 #define UAC_TREBLE_CONTROL 0x05
370 #define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06
371 #define UAC_AUTOMATIC_GAIN_CONTROL 0x07
372 #define UAC_DELAY_CONTROL 0x08
373 #define UAC_BASS_BOOST_CONTROL 0x09
374 #define UAC_LOUDNESS_CONTROL 0x0a
376 #define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1))
377 #define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1))
378 #define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1))
379 #define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1))
380 #define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1))
381 #define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
382 #define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
383 #define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1))
384 #define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1))
385 #define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1))
389 struct usb_audio_control {
390 struct list_head list;
394 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
395 int (*get)(struct usb_audio_control *con, u8 cmd);
398 struct usb_audio_control_selector {
399 struct list_head list;
400 struct list_head control;
404 struct usb_descriptor_header *desc;
407 #endif /* __KERNEL__ */
409 #endif /* __LINUX_USB_AUDIO_H */