1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef _UAPI__LINUX_USB_AUDIO_H
23#define _UAPI__LINUX_USB_AUDIO_H
24
25#include <linux/types.h>
26
27
28#define UAC_VERSION_1 0x00
29#define UAC_VERSION_2 0x20
30
31
32#define USB_SUBCLASS_AUDIOCONTROL 0x01
33#define USB_SUBCLASS_AUDIOSTREAMING 0x02
34#define USB_SUBCLASS_MIDISTREAMING 0x03
35
36
37#define UAC_HEADER 0x01
38#define UAC_INPUT_TERMINAL 0x02
39#define UAC_OUTPUT_TERMINAL 0x03
40#define UAC_MIXER_UNIT 0x04
41#define UAC_SELECTOR_UNIT 0x05
42#define UAC_FEATURE_UNIT 0x06
43#define UAC1_PROCESSING_UNIT 0x07
44#define UAC1_EXTENSION_UNIT 0x08
45
46
47#define UAC_AS_GENERAL 0x01
48#define UAC_FORMAT_TYPE 0x02
49#define UAC_FORMAT_SPECIFIC 0x03
50
51
52#define UAC_PROCESS_UNDEFINED 0x00
53#define UAC_PROCESS_UP_DOWNMIX 0x01
54#define UAC_PROCESS_DOLBY_PROLOGIC 0x02
55#define UAC_PROCESS_STEREO_EXTENDER 0x03
56#define UAC_PROCESS_REVERB 0x04
57#define UAC_PROCESS_CHORUS 0x05
58#define UAC_PROCESS_DYN_RANGE_COMP 0x06
59
60
61#define UAC_EP_GENERAL 0x01
62
63
64#define UAC_SET_ 0x00
65#define UAC_GET_ 0x80
66
67#define UAC__CUR 0x1
68#define UAC__MIN 0x2
69#define UAC__MAX 0x3
70#define UAC__RES 0x4
71#define UAC__MEM 0x5
72
73#define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
74#define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
75#define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
76#define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
77#define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
78#define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
79#define UAC_SET_RES (UAC_SET_ | UAC__RES)
80#define UAC_GET_RES (UAC_GET_ | UAC__RES)
81#define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
82#define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
83
84#define UAC_GET_STAT 0xff
85
86
87
88
89#define UAC_TERM_COPY_PROTECT 0x01
90
91
92#define UAC_FU_MUTE 0x01
93#define UAC_FU_VOLUME 0x02
94#define UAC_FU_BASS 0x03
95#define UAC_FU_MID 0x04
96#define UAC_FU_TREBLE 0x05
97#define UAC_FU_GRAPHIC_EQUALIZER 0x06
98#define UAC_FU_AUTOMATIC_GAIN 0x07
99#define UAC_FU_DELAY 0x08
100#define UAC_FU_BASS_BOOST 0x09
101#define UAC_FU_LOUDNESS 0x0a
102
103#define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1))
104
105
106#define UAC_UD_ENABLE 0x01
107#define UAC_UD_MODE_SELECT 0x02
108
109
110#define UAC_DP_ENABLE 0x01
111#define UAC_DP_MODE_SELECT 0x02
112
113
114#define UAC_3D_ENABLE 0x01
115#define UAC_3D_SPACE 0x02
116
117
118#define UAC_REVERB_ENABLE 0x01
119#define UAC_REVERB_LEVEL 0x02
120#define UAC_REVERB_TIME 0x03
121#define UAC_REVERB_FEEDBACK 0x04
122
123
124#define UAC_CHORUS_ENABLE 0x01
125#define UAC_CHORUS_LEVEL 0x02
126#define UAC_CHORUS_RATE 0x03
127#define UAC_CHORUS_DEPTH 0x04
128
129
130#define UAC_DCR_ENABLE 0x01
131#define UAC_DCR_RATE 0x02
132#define UAC_DCR_MAXAMPL 0x03
133#define UAC_DCR_THRESHOLD 0x04
134#define UAC_DCR_ATTACK_TIME 0x05
135#define UAC_DCR_RELEASE_TIME 0x06
136
137
138#define UAC_XU_ENABLE 0x01
139
140
141#define UAC_MS_HEADER 0x01
142#define UAC_MIDI_IN_JACK 0x02
143#define UAC_MIDI_OUT_JACK 0x03
144
145
146#define UAC_MS_GENERAL 0x01
147
148
149#define UAC_TERMINAL_UNDEFINED 0x100
150#define UAC_TERMINAL_STREAMING 0x101
151#define UAC_TERMINAL_VENDOR_SPEC 0x1FF
152
153
154
155struct uac1_ac_header_descriptor {
156 __u8 bLength;
157 __u8 bDescriptorType;
158 __u8 bDescriptorSubtype;
159 __le16 bcdADC;
160 __le16 wTotalLength;
161 __u8 bInCollection;
162 __u8 baInterfaceNr[];
163} __attribute__ ((packed));
164
165#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
166
167
168#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
169struct uac1_ac_header_descriptor_##n { \
170 __u8 bLength; \
171 __u8 bDescriptorType; \
172 __u8 bDescriptorSubtype; \
173 __le16 bcdADC; \
174 __le16 wTotalLength; \
175 __u8 bInCollection; \
176 __u8 baInterfaceNr[n]; \
177} __attribute__ ((packed))
178
179
180struct uac_input_terminal_descriptor {
181 __u8 bLength;
182 __u8 bDescriptorType;
183 __u8 bDescriptorSubtype;
184 __u8 bTerminalID;
185 __le16 wTerminalType;
186 __u8 bAssocTerminal;
187 __u8 bNrChannels;
188 __le16 wChannelConfig;
189 __u8 iChannelNames;
190 __u8 iTerminal;
191} __attribute__ ((packed));
192
193#define UAC_DT_INPUT_TERMINAL_SIZE 12
194
195
196#define UAC_INPUT_TERMINAL_UNDEFINED 0x200
197#define UAC_INPUT_TERMINAL_MICROPHONE 0x201
198#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
199#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
200#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
201#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
202#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
203
204
205
206#define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
207
208
209struct uac1_output_terminal_descriptor {
210 __u8 bLength;
211 __u8 bDescriptorType;
212 __u8 bDescriptorSubtype;
213 __u8 bTerminalID;
214 __le16 wTerminalType;
215 __u8 bAssocTerminal;
216 __u8 bSourceID;
217 __u8 iTerminal;
218} __attribute__ ((packed));
219
220#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
221
222
223#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
224#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
225#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
226#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
227#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
228#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
229#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
230#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
231
232
233#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
234
235
236#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
237struct uac_feature_unit_descriptor_##ch { \
238 __u8 bLength; \
239 __u8 bDescriptorType; \
240 __u8 bDescriptorSubtype; \
241 __u8 bUnitID; \
242 __u8 bSourceID; \
243 __u8 bControlSize; \
244 __le16 bmaControls[ch + 1]; \
245 __u8 iFeature; \
246} __attribute__ ((packed))
247
248
249struct uac_mixer_unit_descriptor {
250 __u8 bLength;
251 __u8 bDescriptorType;
252 __u8 bDescriptorSubtype;
253 __u8 bUnitID;
254 __u8 bNrInPins;
255 __u8 baSourceID[];
256} __attribute__ ((packed));
257
258static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc)
259{
260 return desc->baSourceID[desc->bNrInPins];
261}
262
263static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc,
264 int protocol)
265{
266 if (protocol == UAC_VERSION_1)
267 return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
268 desc->baSourceID[desc->bNrInPins + 1];
269 else
270 return (desc->baSourceID[desc->bNrInPins + 4] << 24) |
271 (desc->baSourceID[desc->bNrInPins + 3] << 16) |
272 (desc->baSourceID[desc->bNrInPins + 2] << 8) |
273 (desc->baSourceID[desc->bNrInPins + 1]);
274}
275
276static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc,
277 int protocol)
278{
279 return (protocol == UAC_VERSION_1) ?
280 desc->baSourceID[desc->bNrInPins + 3] :
281 desc->baSourceID[desc->bNrInPins + 5];
282}
283
284static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc,
285 int protocol)
286{
287 return (protocol == UAC_VERSION_1) ?
288 &desc->baSourceID[desc->bNrInPins + 4] :
289 &desc->baSourceID[desc->bNrInPins + 6];
290}
291
292static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc)
293{
294 __u8 *raw = (__u8 *) desc;
295 return raw[desc->bLength - 1];
296}
297
298
299struct uac_selector_unit_descriptor {
300 __u8 bLength;
301 __u8 bDescriptorType;
302 __u8 bDescriptorSubtype;
303 __u8 bUintID;
304 __u8 bNrInPins;
305 __u8 baSourceID[];
306} __attribute__ ((packed));
307
308static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc)
309{
310 __u8 *raw = (__u8 *) desc;
311 return raw[desc->bLength - 1];
312}
313
314
315struct uac_feature_unit_descriptor {
316 __u8 bLength;
317 __u8 bDescriptorType;
318 __u8 bDescriptorSubtype;
319 __u8 bUnitID;
320 __u8 bSourceID;
321 __u8 bControlSize;
322 __u8 bmaControls[0];
323} __attribute__((packed));
324
325static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc)
326{
327 __u8 *raw = (__u8 *) desc;
328 return raw[desc->bLength - 1];
329}
330
331
332struct uac_processing_unit_descriptor {
333 __u8 bLength;
334 __u8 bDescriptorType;
335 __u8 bDescriptorSubtype;
336 __u8 bUnitID;
337 __le16 wProcessType;
338 __u8 bNrInPins;
339 __u8 baSourceID[];
340} __attribute__ ((packed));
341
342static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc)
343{
344 return desc->baSourceID[desc->bNrInPins];
345}
346
347static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc,
348 int protocol)
349{
350 if (protocol == UAC_VERSION_1)
351 return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
352 desc->baSourceID[desc->bNrInPins + 1];
353 else
354 return (desc->baSourceID[desc->bNrInPins + 4] << 24) |
355 (desc->baSourceID[desc->bNrInPins + 3] << 16) |
356 (desc->baSourceID[desc->bNrInPins + 2] << 8) |
357 (desc->baSourceID[desc->bNrInPins + 1]);
358}
359
360static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc,
361 int protocol)
362{
363 return (protocol == UAC_VERSION_1) ?
364 desc->baSourceID[desc->bNrInPins + 3] :
365 desc->baSourceID[desc->bNrInPins + 5];
366}
367
368static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc,
369 int protocol)
370{
371 return (protocol == UAC_VERSION_1) ?
372 desc->baSourceID[desc->bNrInPins + 4] :
373 desc->baSourceID[desc->bNrInPins + 6];
374}
375
376static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc,
377 int protocol)
378{
379 return (protocol == UAC_VERSION_1) ?
380 &desc->baSourceID[desc->bNrInPins + 5] :
381 &desc->baSourceID[desc->bNrInPins + 7];
382}
383
384static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc,
385 int protocol)
386{
387 __u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
388 return *(uac_processing_unit_bmControls(desc, protocol)
389 + control_size);
390}
391
392static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc,
393 int protocol)
394{
395 __u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
396 return uac_processing_unit_bmControls(desc, protocol)
397 + control_size + 1;
398}
399
400
401struct uac1_as_header_descriptor {
402 __u8 bLength;
403 __u8 bDescriptorType;
404 __u8 bDescriptorSubtype;
405 __u8 bTerminalLink;
406 __u8 bDelay;
407 __le16 wFormatTag;
408} __attribute__ ((packed));
409
410#define UAC_DT_AS_HEADER_SIZE 7
411
412
413#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
414#define UAC_FORMAT_TYPE_I_PCM 0x1
415#define UAC_FORMAT_TYPE_I_PCM8 0x2
416#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
417#define UAC_FORMAT_TYPE_I_ALAW 0x4
418#define UAC_FORMAT_TYPE_I_MULAW 0x5
419
420struct uac_format_type_i_continuous_descriptor {
421 __u8 bLength;
422 __u8 bDescriptorType;
423 __u8 bDescriptorSubtype;
424 __u8 bFormatType;
425 __u8 bNrChannels;
426 __u8 bSubframeSize;
427 __u8 bBitResolution;
428 __u8 bSamFreqType;
429 __u8 tLowerSamFreq[3];
430 __u8 tUpperSamFreq[3];
431} __attribute__ ((packed));
432
433#define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
434
435struct uac_format_type_i_discrete_descriptor {
436 __u8 bLength;
437 __u8 bDescriptorType;
438 __u8 bDescriptorSubtype;
439 __u8 bFormatType;
440 __u8 bNrChannels;
441 __u8 bSubframeSize;
442 __u8 bBitResolution;
443 __u8 bSamFreqType;
444 __u8 tSamFreq[][3];
445} __attribute__ ((packed));
446
447#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
448struct uac_format_type_i_discrete_descriptor_##n { \
449 __u8 bLength; \
450 __u8 bDescriptorType; \
451 __u8 bDescriptorSubtype; \
452 __u8 bFormatType; \
453 __u8 bNrChannels; \
454 __u8 bSubframeSize; \
455 __u8 bBitResolution; \
456 __u8 bSamFreqType; \
457 __u8 tSamFreq[n][3]; \
458} __attribute__ ((packed))
459
460#define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
461
462struct uac_format_type_i_ext_descriptor {
463 __u8 bLength;
464 __u8 bDescriptorType;
465 __u8 bDescriptorSubtype;
466 __u8 bFormatType;
467 __u8 bSubslotSize;
468 __u8 bBitResolution;
469 __u8 bHeaderLength;
470 __u8 bControlSize;
471 __u8 bSideBandProtocol;
472} __attribute__((packed));
473
474
475
476#define UAC_FORMAT_TYPE_II_MPEG 0x1001
477#define UAC_FORMAT_TYPE_II_AC3 0x1002
478
479struct uac_format_type_ii_discrete_descriptor {
480 __u8 bLength;
481 __u8 bDescriptorType;
482 __u8 bDescriptorSubtype;
483 __u8 bFormatType;
484 __le16 wMaxBitRate;
485 __le16 wSamplesPerFrame;
486 __u8 bSamFreqType;
487 __u8 tSamFreq[][3];
488} __attribute__((packed));
489
490struct uac_format_type_ii_ext_descriptor {
491 __u8 bLength;
492 __u8 bDescriptorType;
493 __u8 bDescriptorSubtype;
494 __u8 bFormatType;
495 __le16 wMaxBitRate;
496 __le16 wSamplesPerFrame;
497 __u8 bHeaderLength;
498 __u8 bSideBandProtocol;
499} __attribute__((packed));
500
501
502#define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001
503#define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002
504#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003
505#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004
506#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005
507#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006
508
509
510#define UAC_FORMAT_TYPE_UNDEFINED 0x0
511#define UAC_FORMAT_TYPE_I 0x1
512#define UAC_FORMAT_TYPE_II 0x2
513#define UAC_FORMAT_TYPE_III 0x3
514#define UAC_EXT_FORMAT_TYPE_I 0x81
515#define UAC_EXT_FORMAT_TYPE_II 0x82
516#define UAC_EXT_FORMAT_TYPE_III 0x83
517
518struct uac_iso_endpoint_descriptor {
519 __u8 bLength;
520 __u8 bDescriptorType;
521 __u8 bDescriptorSubtype;
522 __u8 bmAttributes;
523 __u8 bLockDelayUnits;
524 __le16 wLockDelay;
525} __attribute__((packed));
526#define UAC_ISO_ENDPOINT_DESC_SIZE 7
527
528#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
529#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
530#define UAC_EP_CS_ATTR_FILL_MAX 0x80
531
532
533
534#define UAC1_STATUS_TYPE_ORIG_MASK 0x0f
535#define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0
536#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1
537#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2
538
539#define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7)
540#define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6)
541
542struct uac1_status_word {
543 __u8 bStatusType;
544 __u8 bOriginator;
545} __attribute__((packed));
546
547
548#endif
549