1 /*
2 * Copyright (c) 2010 Daniel Mack <daniel@caiaq.de>
3 *
4 * This software is distributed under the terms of the GNU General Public
5 * License ("GPL") version 2, as published by the Free Software Foundation.
6 *
7 * This file holds USB constants and structures defined
8 * by the USB Device Class Definition for Audio Devices in version 2.0.
9 * Comments below reference relevant sections of the documents contained
10 * in http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
11 */
12
13 #ifndef __LINUX_USB_AUDIO_V2_H
14 #define __LINUX_USB_AUDIO_V2_H
15
16 #include <linux/types.h>
17
18 /* v1.0 and v2.0 of this standard have many things in common. For the rest
19 * of the definitions, please refer to audio.h */
20
21 /*
22 * bmControl field decoders
23 *
24 * From the USB Audio spec v2.0:
25 *
26 * bmaControls() is a (ch+1)-element array of 4-byte bitmaps,
27 * each containing a set of bit pairs. If a Control is present,
28 * it must be Host readable. If a certain Control is not
29 * present then the bit pair must be set to 0b00.
30 * If a Control is present but read-only, the bit pair must be
31 * set to 0b01. If a Control is also Host programmable, the bit
32 * pair must be set to 0b11. The value 0b10 is not allowed.
33 *
34 */
35
uac2_control_is_readable(u32 bmControls,u8 control)36 static inline bool uac2_control_is_readable(u32 bmControls, u8 control)
37 {
38 return (bmControls >> (control * 2)) & 0x1;
39 }
40
uac2_control_is_writeable(u32 bmControls,u8 control)41 static inline bool uac2_control_is_writeable(u32 bmControls, u8 control)
42 {
43 return (bmControls >> (control * 2)) & 0x2;
44 }
45
46 /* 4.7.2 Class-Specific AC Interface Descriptor */
47 struct uac2_ac_header_descriptor {
48 __u8 bLength; /* 9 */
49 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
50 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
51 __le16 bcdADC; /* 0x0200 */
52 __u8 bCategory;
53 __le16 wTotalLength; /* includes Unit and Terminal desc. */
54 __u8 bmControls;
55 } __packed;
56
57 /* 2.3.1.6 Type I Format Type Descriptor (Frmts20 final.pdf)*/
58 struct uac2_format_type_i_descriptor {
59 __u8 bLength; /* in bytes: 6 */
60 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
61 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
62 __u8 bFormatType; /* FORMAT_TYPE_1 */
63 __u8 bSubslotSize; /* {1,2,3,4} */
64 __u8 bBitResolution;
65 } __packed;
66
67 /* 4.7.2.1 Clock Source Descriptor */
68
69 struct uac_clock_source_descriptor {
70 __u8 bLength;
71 __u8 bDescriptorType;
72 __u8 bDescriptorSubtype;
73 __u8 bClockID;
74 __u8 bmAttributes;
75 __u8 bmControls;
76 __u8 bAssocTerminal;
77 __u8 iClockSource;
78 } __attribute__((packed));
79
80 /* bmAttribute fields */
81 #define UAC_CLOCK_SOURCE_TYPE_EXT 0x0
82 #define UAC_CLOCK_SOURCE_TYPE_INT_FIXED 0x1
83 #define UAC_CLOCK_SOURCE_TYPE_INT_VAR 0x2
84 #define UAC_CLOCK_SOURCE_TYPE_INT_PROG 0x3
85 #define UAC_CLOCK_SOURCE_SYNCED_TO_SOF (1 << 2)
86
87 /* 4.7.2.2 Clock Source Descriptor */
88
89 struct uac_clock_selector_descriptor {
90 __u8 bLength;
91 __u8 bDescriptorType;
92 __u8 bDescriptorSubtype;
93 __u8 bClockID;
94 __u8 bNrInPins;
95 __u8 baCSourceID[];
96 /* bmControls, bAssocTerminal and iClockSource omitted */
97 } __attribute__((packed));
98
99 /* 4.7.2.3 Clock Multiplier Descriptor */
100
101 struct uac_clock_multiplier_descriptor {
102 __u8 bLength;
103 __u8 bDescriptorType;
104 __u8 bDescriptorSubtype;
105 __u8 bClockID;
106 __u8 bCSourceID;
107 __u8 bmControls;
108 __u8 iClockMultiplier;
109 } __attribute__((packed));
110
111 /* 4.7.2.4 Input terminal descriptor */
112
113 struct uac2_input_terminal_descriptor {
114 __u8 bLength;
115 __u8 bDescriptorType;
116 __u8 bDescriptorSubtype;
117 __u8 bTerminalID;
118 __u16 wTerminalType;
119 __u8 bAssocTerminal;
120 __u8 bCSourceID;
121 __u8 bNrChannels;
122 __u32 bmChannelConfig;
123 __u8 iChannelNames;
124 __u16 bmControls;
125 __u8 iTerminal;
126 } __attribute__((packed));
127
128 /* 4.7.2.5 Output terminal descriptor */
129
130 struct uac2_output_terminal_descriptor {
131 __u8 bLength;
132 __u8 bDescriptorType;
133 __u8 bDescriptorSubtype;
134 __u8 bTerminalID;
135 __u16 wTerminalType;
136 __u8 bAssocTerminal;
137 __u8 bSourceID;
138 __u8 bCSourceID;
139 __u16 bmControls;
140 __u8 iTerminal;
141 } __attribute__((packed));
142
143
144
145 /* 4.7.2.8 Feature Unit Descriptor */
146
147 struct uac2_feature_unit_descriptor {
148 __u8 bLength;
149 __u8 bDescriptorType;
150 __u8 bDescriptorSubtype;
151 __u8 bUnitID;
152 __u8 bSourceID;
153 /* bmaControls is actually u32,
154 * but u8 is needed for the hybrid parser */
155 __u8 bmaControls[0]; /* variable length */
156 } __attribute__((packed));
157
158 /* 4.9.2 Class-Specific AS Interface Descriptor */
159
160 struct uac2_as_header_descriptor {
161 __u8 bLength;
162 __u8 bDescriptorType;
163 __u8 bDescriptorSubtype;
164 __u8 bTerminalLink;
165 __u8 bmControls;
166 __u8 bFormatType;
167 __u32 bmFormats;
168 __u8 bNrChannels;
169 __u32 bmChannelConfig;
170 __u8 iChannelNames;
171 } __attribute__((packed));
172
173 /* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
174
175 struct uac2_iso_endpoint_descriptor {
176 __u8 bLength; /* in bytes: 8 */
177 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
178 __u8 bDescriptorSubtype; /* EP_GENERAL */
179 __u8 bmAttributes;
180 __u8 bmControls;
181 __u8 bLockDelayUnits;
182 __le16 wLockDelay;
183 } __attribute__((packed));
184
185 #define UAC2_CONTROL_PITCH (3 << 0)
186 #define UAC2_CONTROL_DATA_OVERRUN (3 << 2)
187 #define UAC2_CONTROL_DATA_UNDERRUN (3 << 4)
188
189 /* 6.1 Interrupt Data Message */
190
191 #define UAC2_INTERRUPT_DATA_MSG_VENDOR (1 << 0)
192 #define UAC2_INTERRUPT_DATA_MSG_EP (1 << 1)
193
194 struct uac2_interrupt_data_msg {
195 __u8 bInfo;
196 __u8 bAttribute;
197 __le16 wValue;
198 __le16 wIndex;
199 } __attribute__((packed));
200
201 /* A.7 Audio Function Category Codes */
202 #define UAC2_FUNCTION_SUBCLASS_UNDEFINED 0x00
203 #define UAC2_FUNCTION_DESKTOP_SPEAKER 0x01
204 #define UAC2_FUNCTION_HOME_THEATER 0x02
205 #define UAC2_FUNCTION_MICROPHONE 0x03
206 #define UAC2_FUNCTION_HEADSET 0x04
207 #define UAC2_FUNCTION_TELEPHONE 0x05
208 #define UAC2_FUNCTION_CONVERTER 0x06
209 #define UAC2_FUNCTION_SOUND_RECORDER 0x07
210 #define UAC2_FUNCTION_IO_BOX 0x08
211 #define UAC2_FUNCTION_MUSICAL_INSTRUMENT 0x09
212 #define UAC2_FUNCTION_PRO_AUDIO 0x0a
213 #define UAC2_FUNCTION_AUDIO_VIDEO 0x0b
214 #define UAC2_FUNCTION_CONTROL_PANEL 0x0c
215 #define UAC2_FUNCTION_OTHER 0xff
216
217 /* A.9 Audio Class-Specific AC Interface Descriptor Subtypes */
218 /* see audio.h for the rest, which is identical to v1 */
219 #define UAC2_EFFECT_UNIT 0x07
220 #define UAC2_PROCESSING_UNIT_V2 0x08
221 #define UAC2_EXTENSION_UNIT_V2 0x09
222 #define UAC2_CLOCK_SOURCE 0x0a
223 #define UAC2_CLOCK_SELECTOR 0x0b
224 #define UAC2_CLOCK_MULTIPLIER 0x0c
225 #define UAC2_SAMPLE_RATE_CONVERTER 0x0d
226
227 /* A.10 Audio Class-Specific AS Interface Descriptor Subtypes */
228 /* see audio.h for the rest, which is identical to v1 */
229 #define UAC2_ENCODER 0x03
230 #define UAC2_DECODER 0x04
231
232 /* A.11 Effect Unit Effect Types */
233 #define UAC2_EFFECT_UNDEFINED 0x00
234 #define UAC2_EFFECT_PARAM_EQ 0x01
235 #define UAC2_EFFECT_REVERB 0x02
236 #define UAC2_EFFECT_MOD_DELAY 0x03
237 #define UAC2_EFFECT_DYN_RANGE_COMP 0x04
238
239 /* A.12 Processing Unit Process Types */
240 #define UAC2_PROCESS_UNDEFINED 0x00
241 #define UAC2_PROCESS_UP_DOWNMIX 0x01
242 #define UAC2_PROCESS_DOLBY_PROLOCIC 0x02
243 #define UAC2_PROCESS_STEREO_EXTENDER 0x03
244
245 /* A.14 Audio Class-Specific Request Codes */
246 #define UAC2_CS_CUR 0x01
247 #define UAC2_CS_RANGE 0x02
248 #define UAC2_CS_MEM 0x03
249
250 /* A.15 Encoder Type Codes */
251 #define UAC2_ENCODER_UNDEFINED 0x00
252 #define UAC2_ENCODER_OTHER 0x01
253 #define UAC2_ENCODER_MPEG 0x02
254 #define UAC2_ENCODER_AC3 0x03
255 #define UAC2_ENCODER_WMA 0x04
256 #define UAC2_ENCODER_DTS 0x05
257
258 /* A.16 Decoder Type Codes */
259 #define UAC2_DECODER_UNDEFINED 0x00
260 #define UAC2_DECODER_OTHER 0x01
261 #define UAC2_DECODER_MPEG 0x02
262 #define UAC2_DECODER_AC3 0x03
263 #define UAC2_DECODER_WMA 0x04
264 #define UAC2_DECODER_DTS 0x05
265
266 /* A.17.1 Clock Source Control Selectors */
267 #define UAC2_CS_UNDEFINED 0x00
268 #define UAC2_CS_CONTROL_SAM_FREQ 0x01
269 #define UAC2_CS_CONTROL_CLOCK_VALID 0x02
270
271 /* A.17.2 Clock Selector Control Selectors */
272 #define UAC2_CX_UNDEFINED 0x00
273 #define UAC2_CX_CLOCK_SELECTOR 0x01
274
275 /* A.17.3 Clock Multiplier Control Selectors */
276 #define UAC2_CM_UNDEFINED 0x00
277 #define UAC2_CM_NUMERATOR 0x01
278 #define UAC2_CM_DENOMINTATOR 0x02
279
280 /* A.17.4 Terminal Control Selectors */
281 #define UAC2_TE_UNDEFINED 0x00
282 #define UAC2_TE_COPY_PROTECT 0x01
283 #define UAC2_TE_CONNECTOR 0x02
284 #define UAC2_TE_OVERLOAD 0x03
285 #define UAC2_TE_CLUSTER 0x04
286 #define UAC2_TE_UNDERFLOW 0x05
287 #define UAC2_TE_OVERFLOW 0x06
288 #define UAC2_TE_LATENCY 0x07
289
290 /* A.17.5 Mixer Control Selectors */
291 #define UAC2_MU_UNDEFINED 0x00
292 #define UAC2_MU_MIXER 0x01
293 #define UAC2_MU_CLUSTER 0x02
294 #define UAC2_MU_UNDERFLOW 0x03
295 #define UAC2_MU_OVERFLOW 0x04
296 #define UAC2_MU_LATENCY 0x05
297
298 /* A.17.6 Selector Control Selectors */
299 #define UAC2_SU_UNDEFINED 0x00
300 #define UAC2_SU_SELECTOR 0x01
301 #define UAC2_SU_LATENCY 0x02
302
303 /* A.17.7 Feature Unit Control Selectors */
304 /* see audio.h for the rest, which is identical to v1 */
305 #define UAC2_FU_INPUT_GAIN 0x0b
306 #define UAC2_FU_INPUT_GAIN_PAD 0x0c
307 #define UAC2_FU_PHASE_INVERTER 0x0d
308 #define UAC2_FU_UNDERFLOW 0x0e
309 #define UAC2_FU_OVERFLOW 0x0f
310 #define UAC2_FU_LATENCY 0x10
311
312 /* A.17.8.1 Parametric Equalizer Section Effect Unit Control Selectors */
313 #define UAC2_PE_UNDEFINED 0x00
314 #define UAC2_PE_ENABLE 0x01
315 #define UAC2_PE_CENTERFREQ 0x02
316 #define UAC2_PE_QFACTOR 0x03
317 #define UAC2_PE_GAIN 0x04
318 #define UAC2_PE_UNDERFLOW 0x05
319 #define UAC2_PE_OVERFLOW 0x06
320 #define UAC2_PE_LATENCY 0x07
321
322 /* A.17.8.2 Reverberation Effect Unit Control Selectors */
323 #define UAC2_RV_UNDEFINED 0x00
324 #define UAC2_RV_ENABLE 0x01
325 #define UAC2_RV_TYPE 0x02
326 #define UAC2_RV_LEVEL 0x03
327 #define UAC2_RV_TIME 0x04
328 #define UAC2_RV_FEEDBACK 0x05
329 #define UAC2_RV_PREDELAY 0x06
330 #define UAC2_RV_DENSITY 0x07
331 #define UAC2_RV_HIFREQ_ROLLOFF 0x08
332 #define UAC2_RV_UNDERFLOW 0x09
333 #define UAC2_RV_OVERFLOW 0x0a
334 #define UAC2_RV_LATENCY 0x0b
335
336 /* A.17.8.3 Modulation Delay Effect Control Selectors */
337 #define UAC2_MD_UNDEFINED 0x00
338 #define UAC2_MD_ENABLE 0x01
339 #define UAC2_MD_BALANCE 0x02
340 #define UAC2_MD_RATE 0x03
341 #define UAC2_MD_DEPTH 0x04
342 #define UAC2_MD_TIME 0x05
343 #define UAC2_MD_FEEDBACK 0x06
344 #define UAC2_MD_UNDERFLOW 0x07
345 #define UAC2_MD_OVERFLOW 0x08
346 #define UAC2_MD_LATENCY 0x09
347
348 /* A.17.8.4 Dynamic Range Compressor Effect Unit Control Selectors */
349 #define UAC2_DR_UNDEFINED 0x00
350 #define UAC2_DR_ENABLE 0x01
351 #define UAC2_DR_COMPRESSION_RATE 0x02
352 #define UAC2_DR_MAXAMPL 0x03
353 #define UAC2_DR_THRESHOLD 0x04
354 #define UAC2_DR_ATTACK_TIME 0x05
355 #define UAC2_DR_RELEASE_TIME 0x06
356 #define UAC2_DR_UNDEFLOW 0x07
357 #define UAC2_DR_OVERFLOW 0x08
358 #define UAC2_DR_LATENCY 0x09
359
360 /* A.17.9.1 Up/Down-mix Processing Unit Control Selectors */
361 #define UAC2_UD_UNDEFINED 0x00
362 #define UAC2_UD_ENABLE 0x01
363 #define UAC2_UD_MODE_SELECT 0x02
364 #define UAC2_UD_CLUSTER 0x03
365 #define UAC2_UD_UNDERFLOW 0x04
366 #define UAC2_UD_OVERFLOW 0x05
367 #define UAC2_UD_LATENCY 0x06
368
369 /* A.17.9.2 Dolby Prologic[tm] Processing Unit Control Selectors */
370 #define UAC2_DP_UNDEFINED 0x00
371 #define UAC2_DP_ENABLE 0x01
372 #define UAC2_DP_MODE_SELECT 0x02
373 #define UAC2_DP_CLUSTER 0x03
374 #define UAC2_DP_UNDERFFLOW 0x04
375 #define UAC2_DP_OVERFLOW 0x05
376 #define UAC2_DP_LATENCY 0x06
377
378 /* A.17.9.3 Stereo Expander Processing Unit Control Selectors */
379 #define UAC2_ST_EXT_UNDEFINED 0x00
380 #define UAC2_ST_EXT_ENABLE 0x01
381 #define UAC2_ST_EXT_WIDTH 0x02
382 #define UAC2_ST_EXT_UNDEFLOW 0x03
383 #define UAC2_ST_EXT_OVERFLOW 0x04
384 #define UAC2_ST_EXT_LATENCY 0x05
385
386 /* A.17.10 Extension Unit Control Selectors */
387 #define UAC2_XU_UNDEFINED 0x00
388 #define UAC2_XU_ENABLE 0x01
389 #define UAC2_XU_CLUSTER 0x02
390 #define UAC2_XU_UNDERFLOW 0x03
391 #define UAC2_XU_OVERFLOW 0x04
392 #define UAC2_XU_LATENCY 0x05
393
394 /* A.17.11 AudioStreaming Interface Control Selectors */
395 #define UAC2_AS_UNDEFINED 0x00
396 #define UAC2_AS_ACT_ALT_SETTING 0x01
397 #define UAC2_AS_VAL_ALT_SETTINGS 0x02
398 #define UAC2_AS_AUDIO_DATA_FORMAT 0x03
399
400 /* A.17.12 Encoder Control Selectors */
401 #define UAC2_EN_UNDEFINED 0x00
402 #define UAC2_EN_BIT_RATE 0x01
403 #define UAC2_EN_QUALITY 0x02
404 #define UAC2_EN_VBR 0x03
405 #define UAC2_EN_TYPE 0x04
406 #define UAC2_EN_UNDERFLOW 0x05
407 #define UAC2_EN_OVERFLOW 0x06
408 #define UAC2_EN_ENCODER_ERROR 0x07
409 #define UAC2_EN_PARAM1 0x08
410 #define UAC2_EN_PARAM2 0x09
411 #define UAC2_EN_PARAM3 0x0a
412 #define UAC2_EN_PARAM4 0x0b
413 #define UAC2_EN_PARAM5 0x0c
414 #define UAC2_EN_PARAM6 0x0d
415 #define UAC2_EN_PARAM7 0x0e
416 #define UAC2_EN_PARAM8 0x0f
417
418 /* A.17.13.1 MPEG Decoder Control Selectors */
419 #define UAC2_MPEG_UNDEFINED 0x00
420 #define UAC2_MPEG_DUAL_CHANNEL 0x01
421 #define UAC2_MPEG_SECOND_STEREO 0x02
422 #define UAC2_MPEG_MULTILINGUAL 0x03
423 #define UAC2_MPEG_DYN_RANGE 0x04
424 #define UAC2_MPEG_SCALING 0x05
425 #define UAC2_MPEG_HILO_SCALING 0x06
426 #define UAC2_MPEG_UNDERFLOW 0x07
427 #define UAC2_MPEG_OVERFLOW 0x08
428 #define UAC2_MPEG_DECODER_ERROR 0x09
429
430 /* A17.13.2 AC3 Decoder Control Selectors */
431 #define UAC2_AC3_UNDEFINED 0x00
432 #define UAC2_AC3_MODE 0x01
433 #define UAC2_AC3_DYN_RANGE 0x02
434 #define UAC2_AC3_SCALING 0x03
435 #define UAC2_AC3_HILO_SCALING 0x04
436 #define UAC2_AC3_UNDERFLOW 0x05
437 #define UAC2_AC3_OVERFLOW 0x06
438 #define UAC2_AC3_DECODER_ERROR 0x07
439
440 /* A17.13.3 WMA Decoder Control Selectors */
441 #define UAC2_WMA_UNDEFINED 0x00
442 #define UAC2_WMA_UNDERFLOW 0x01
443 #define UAC2_WMA_OVERFLOW 0x02
444 #define UAC2_WMA_DECODER_ERROR 0x03
445
446 /* A17.13.4 DTS Decoder Control Selectors */
447 #define UAC2_DTS_UNDEFINED 0x00
448 #define UAC2_DTS_UNDERFLOW 0x01
449 #define UAC2_DTS_OVERFLOW 0x02
450 #define UAC2_DTS_DECODER_ERROR 0x03
451
452 /* A17.14 Endpoint Control Selectors */
453 #define UAC2_EP_CS_UNDEFINED 0x00
454 #define UAC2_EP_CS_PITCH 0x01
455 #define UAC2_EP_CS_DATA_OVERRUN 0x02
456 #define UAC2_EP_CS_DATA_UNDERRUN 0x03
457
458 #endif /* __LINUX_USB_AUDIO_V2_H */
459
460