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 0x07
39 #define UAC_EXTENSION_UNIT 0x08
41 /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
42 #define UAC_AS_GENERAL 0x01
43 #define UAC_FORMAT_TYPE 0x02
44 #define UAC_FORMAT_SPECIFIC 0x03
46 /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
47 #define UAC_EP_GENERAL 0x01
49 /* A.9 Audio Class-Specific Request Codes */
59 #define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
60 #define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
61 #define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
62 #define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
63 #define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
64 #define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
65 #define UAC_SET_RES (UAC_SET_ | UAC__RES)
66 #define UAC_GET_RES (UAC_GET_ | UAC__RES)
67 #define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
68 #define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
70 #define UAC_GET_STAT 0xff
72 /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
73 #define UAC_MS_HEADER 0x01
74 #define UAC_MIDI_IN_JACK 0x02
75 #define UAC_MIDI_OUT_JACK 0x03
77 /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
78 #define UAC_MS_GENERAL 0x01
80 /* Terminals - 2.1 USB Terminal Types */
81 #define UAC_TERMINAL_UNDEFINED 0x100
82 #define UAC_TERMINAL_STREAMING 0x101
83 #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
85 /* Terminal Control Selectors */
86 /* 4.3.2 Class-Specific AC Interface Descriptor */
87 struct uac_ac_header_descriptor_v1 {
88 __u8 bLength; /* 8 + n */
89 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
90 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
91 __le16 bcdADC; /* 0x0100 */
92 __le16 wTotalLength; /* includes Unit and Terminal desc. */
93 __u8 bInCollection; /* n */
94 __u8 baInterfaceNr[]; /* [n] */
95 } __attribute__ ((packed));
97 #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
99 /* As above, but more useful for defining your own descriptors: */
100 #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
101 struct uac_ac_header_descriptor_v1_##n { \
103 __u8 bDescriptorType; \
104 __u8 bDescriptorSubtype; \
106 __le16 wTotalLength; \
107 __u8 bInCollection; \
108 __u8 baInterfaceNr[n]; \
109 } __attribute__ ((packed))
111 /* 4.3.2.1 Input Terminal Descriptor */
112 struct uac_input_terminal_descriptor {
113 __u8 bLength; /* in bytes: 12 */
114 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
115 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
116 __u8 bTerminalID; /* Constant uniquely terminal ID */
117 __le16 wTerminalType; /* USB Audio Terminal Types */
118 __u8 bAssocTerminal; /* ID of the Output Terminal associated */
119 __u8 bNrChannels; /* Number of logical output channels */
120 __le16 wChannelConfig;
123 } __attribute__ ((packed));
125 #define UAC_DT_INPUT_TERMINAL_SIZE 12
127 /* Terminals - 2.2 Input Terminal Types */
128 #define UAC_INPUT_TERMINAL_UNDEFINED 0x200
129 #define UAC_INPUT_TERMINAL_MICROPHONE 0x201
130 #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
131 #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
132 #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
133 #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
134 #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
136 /* 4.3.2.2 Output Terminal Descriptor */
137 struct uac_output_terminal_descriptor_v1 {
138 __u8 bLength; /* in bytes: 9 */
139 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
140 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
141 __u8 bTerminalID; /* Constant uniquely terminal ID */
142 __le16 wTerminalType; /* USB Audio Terminal Types */
143 __u8 bAssocTerminal; /* ID of the Input Terminal associated */
144 __u8 bSourceID; /* ID of the connected Unit or Terminal*/
146 } __attribute__ ((packed));
148 #define UAC_DT_OUTPUT_TERMINAL_SIZE 9
150 /* Terminals - 2.3 Output Terminal Types */
151 #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
152 #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
153 #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
154 #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
155 #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
156 #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
157 #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
158 #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
160 /* Set bControlSize = 2 as default setting */
161 #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
163 /* As above, but more useful for defining your own descriptors: */
164 #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
165 struct uac_feature_unit_descriptor_##ch { \
167 __u8 bDescriptorType; \
168 __u8 bDescriptorSubtype; \
172 __le16 bmaControls[ch + 1]; \
174 } __attribute__ ((packed))
176 /* 4.5.2 Class-Specific AS Interface Descriptor */
177 struct uac_as_header_descriptor_v1 {
178 __u8 bLength; /* in bytes: 7 */
179 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
180 __u8 bDescriptorSubtype; /* AS_GENERAL */
181 __u8 bTerminalLink; /* Terminal ID of connected Terminal */
182 __u8 bDelay; /* Delay introduced by the data path */
183 __le16 wFormatTag; /* The Audio Data Format */
184 } __attribute__ ((packed));
186 struct uac_as_header_descriptor_v2 {
188 __u8 bDescriptorType;
189 __u8 bDescriptorSubtype;
195 __u32 bmChannelConfig;
197 } __attribute__((packed));
199 #define UAC_DT_AS_HEADER_SIZE 7
201 /* Formats - A.1.1 Audio Data Format Type I Codes */
202 #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
203 #define UAC_FORMAT_TYPE_I_PCM 0x1
204 #define UAC_FORMAT_TYPE_I_PCM8 0x2
205 #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
206 #define UAC_FORMAT_TYPE_I_ALAW 0x4
207 #define UAC_FORMAT_TYPE_I_MULAW 0x5
209 struct uac_format_type_i_continuous_descriptor {
210 __u8 bLength; /* in bytes: 8 + (ns * 3) */
211 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
212 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
213 __u8 bFormatType; /* FORMAT_TYPE_1 */
214 __u8 bNrChannels; /* physical channels in the stream */
215 __u8 bSubframeSize; /* */
218 __u8 tLowerSamFreq[3];
219 __u8 tUpperSamFreq[3];
220 } __attribute__ ((packed));
222 #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
224 struct uac_format_type_i_discrete_descriptor {
225 __u8 bLength; /* in bytes: 8 + (ns * 3) */
226 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
227 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
228 __u8 bFormatType; /* FORMAT_TYPE_1 */
229 __u8 bNrChannels; /* physical channels in the stream */
230 __u8 bSubframeSize; /* */
234 } __attribute__ ((packed));
236 #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
237 struct uac_format_type_i_discrete_descriptor_##n { \
239 __u8 bDescriptorType; \
240 __u8 bDescriptorSubtype; \
243 __u8 bSubframeSize; \
244 __u8 bBitResolution; \
246 __u8 tSamFreq[n][3]; \
247 } __attribute__ ((packed))
249 #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
251 struct uac_format_type_i_ext_descriptor {
253 __u8 bDescriptorType;
254 __u8 bDescriptorSubtype;
260 __u8 bSideBandProtocol;
261 } __attribute__((packed));
264 /* Formats - Audio Data Format Type I Codes */
266 struct uac_format_type_ii_discrete_descriptor {
268 __u8 bDescriptorType;
269 __u8 bDescriptorSubtype;
272 __le16 wSamplesPerFrame;
275 } __attribute__((packed));
277 struct uac_format_type_ii_ext_descriptor {
279 __u8 bDescriptorType;
280 __u8 bDescriptorSubtype;
283 __u16 wSamplesPerFrame;
285 __u8 bSideBandProtocol;
286 } __attribute__((packed));
289 /* Formats - A.2 Format Type Codes */
290 #define UAC_FORMAT_TYPE_UNDEFINED 0x0
291 #define UAC_FORMAT_TYPE_I 0x1
292 #define UAC_FORMAT_TYPE_II 0x2
293 #define UAC_FORMAT_TYPE_III 0x3
294 #define UAC_EXT_FORMAT_TYPE_I 0x81
295 #define UAC_EXT_FORMAT_TYPE_II 0x82
296 #define UAC_EXT_FORMAT_TYPE_III 0x83
298 struct uac_iso_endpoint_descriptor {
299 __u8 bLength; /* in bytes: 7 */
300 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
301 __u8 bDescriptorSubtype; /* EP_GENERAL */
303 __u8 bLockDelayUnits;
306 #define UAC_ISO_ENDPOINT_DESC_SIZE 7
308 #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
309 #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
310 #define UAC_EP_CS_ATTR_FILL_MAX 0x80
312 /* Audio class v2.0: CLOCK_SOURCE descriptor */
314 struct uac_clock_source_descriptor {
316 __u8 bDescriptorType;
317 __u8 bDescriptorSubtype;
323 } __attribute__((packed));
325 /* A.10.2 Feature Unit Control Selectors */
327 struct uac_feature_unit_descriptor {
329 __u8 bDescriptorType;
330 __u8 bDescriptorSubtype;
334 __u8 controls[0]; /* variable length */
335 } __attribute__((packed));
337 #define UAC_FU_CONTROL_UNDEFINED 0x00
338 #define UAC_MUTE_CONTROL 0x01
339 #define UAC_VOLUME_CONTROL 0x02
340 #define UAC_BASS_CONTROL 0x03
341 #define UAC_MID_CONTROL 0x04
342 #define UAC_TREBLE_CONTROL 0x05
343 #define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06
344 #define UAC_AUTOMATIC_GAIN_CONTROL 0x07
345 #define UAC_DELAY_CONTROL 0x08
346 #define UAC_BASS_BOOST_CONTROL 0x09
347 #define UAC_LOUDNESS_CONTROL 0x0a
349 #define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1))
350 #define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1))
351 #define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1))
352 #define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1))
353 #define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1))
354 #define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
355 #define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
356 #define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1))
357 #define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1))
358 #define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1))
362 struct usb_audio_control {
363 struct list_head list;
367 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
368 int (*get)(struct usb_audio_control *con, u8 cmd);
371 struct usb_audio_control_selector {
372 struct list_head list;
373 struct list_head control;
377 struct usb_descriptor_header *desc;
380 #endif /* __KERNEL__ */
382 #endif /* __LINUX_USB_AUDIO_H */