1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * <linux/usb/audio.h> -- USB Audio definitions.
5 * Copyright (C) 2006 Thumtronics Pty Ltd.
6 * Developed for Thumtronics by Grey Innovation
7 * Ben Williamson <ben.williamson@greyinnovation.com>
9 * This software is distributed under the terms of the GNU General Public
10 * License ("GPL") version 2, as published by the Free Software Foundation.
12 * This file holds USB constants and structures defined
13 * by the USB Device Class Definition for Audio Devices.
14 * Comments below reference relevant sections of that document:
16 * http://www.usb.org/developers/devclass_docs/audio10.pdf
18 * Types and defines in this file are either specific to version 1.0 of
19 * this standard or common for newer versions.
22 #ifndef _UAPI__LINUX_USB_AUDIO_H
23 #define _UAPI__LINUX_USB_AUDIO_H
25 #include <linux/types.h>
27 /* bInterfaceProtocol values to denote the version of the standard used */
28 #define UAC_VERSION_1 0x00
29 #define UAC_VERSION_2 0x20
31 /* A.2 Audio Interface Subclass Codes */
32 #define USB_SUBCLASS_AUDIOCONTROL 0x01
33 #define USB_SUBCLASS_AUDIOSTREAMING 0x02
34 #define USB_SUBCLASS_MIDISTREAMING 0x03
36 /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
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
46 /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
47 #define UAC_AS_GENERAL 0x01
48 #define UAC_FORMAT_TYPE 0x02
49 #define UAC_FORMAT_SPECIFIC 0x03
51 /* A.7 Processing Unit Process Types */
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
60 /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
61 #define UAC_EP_GENERAL 0x01
63 /* A.9 Audio Class-Specific Request Codes */
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)
84 #define UAC_GET_STAT 0xff
86 /* A.10 Control Selector Codes */
88 /* A.10.1 Terminal Control Selectors */
89 #define UAC_TERM_COPY_PROTECT 0x01
91 /* A.10.2 Feature Unit Control Selectors */
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
103 #define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1))
105 /* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */
106 #define UAC_UD_ENABLE 0x01
107 #define UAC_UD_MODE_SELECT 0x02
109 /* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */
110 #define UAC_DP_ENABLE 0x01
111 #define UAC_DP_MODE_SELECT 0x02
113 /* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */
114 #define UAC_3D_ENABLE 0x01
115 #define UAC_3D_SPACE 0x02
117 /* A.10.3.4 Reverberation Processing Unit Control Selectors */
118 #define UAC_REVERB_ENABLE 0x01
119 #define UAC_REVERB_LEVEL 0x02
120 #define UAC_REVERB_TIME 0x03
121 #define UAC_REVERB_FEEDBACK 0x04
123 /* A.10.3.5 Chorus Processing Unit Control Selectors */
124 #define UAC_CHORUS_ENABLE 0x01
125 #define UAC_CHORUS_LEVEL 0x02
126 #define UAC_CHORUS_RATE 0x03
127 #define UAC_CHORUS_DEPTH 0x04
129 /* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */
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
137 /* A.10.4 Extension Unit Control Selectors */
138 #define UAC_XU_ENABLE 0x01
140 /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
141 #define UAC_MS_HEADER 0x01
142 #define UAC_MIDI_IN_JACK 0x02
143 #define UAC_MIDI_OUT_JACK 0x03
145 /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
146 #define UAC_MS_GENERAL 0x01
148 /* Terminals - 2.1 USB Terminal Types */
149 #define UAC_TERMINAL_UNDEFINED 0x100
150 #define UAC_TERMINAL_STREAMING 0x101
151 #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
153 /* Terminal Control Selectors */
154 /* 4.3.2 Class-Specific AC Interface Descriptor */
155 struct uac1_ac_header_descriptor
{
156 __u8 bLength
; /* 8 + n */
157 __u8 bDescriptorType
; /* USB_DT_CS_INTERFACE */
158 __u8 bDescriptorSubtype
; /* UAC_MS_HEADER */
159 __le16 bcdADC
; /* 0x0100 */
160 __le16 wTotalLength
; /* includes Unit and Terminal desc. */
161 __u8 bInCollection
; /* n */
162 __u8 baInterfaceNr
[]; /* [n] */
163 } __attribute__ ((packed
));
165 #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
167 /* As above, but more useful for defining your own descriptors: */
168 #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
169 struct uac1_ac_header_descriptor_##n { \
171 __u8 bDescriptorType; \
172 __u8 bDescriptorSubtype; \
174 __le16 wTotalLength; \
175 __u8 bInCollection; \
176 __u8 baInterfaceNr[n]; \
177 } __attribute__ ((packed))
179 /* 4.3.2.1 Input Terminal Descriptor */
180 struct uac_input_terminal_descriptor
{
181 __u8 bLength
; /* in bytes: 12 */
182 __u8 bDescriptorType
; /* CS_INTERFACE descriptor type */
183 __u8 bDescriptorSubtype
; /* INPUT_TERMINAL descriptor subtype */
184 __u8 bTerminalID
; /* Constant uniquely terminal ID */
185 __le16 wTerminalType
; /* USB Audio Terminal Types */
186 __u8 bAssocTerminal
; /* ID of the Output Terminal associated */
187 __u8 bNrChannels
; /* Number of logical output channels */
188 __le16 wChannelConfig
;
191 } __attribute__ ((packed
));
193 #define UAC_DT_INPUT_TERMINAL_SIZE 12
195 /* Terminals - 2.2 Input Terminal Types */
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
204 /* Terminals - control selectors */
206 #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
208 /* 4.3.2.2 Output Terminal Descriptor */
209 struct uac1_output_terminal_descriptor
{
210 __u8 bLength
; /* in bytes: 9 */
211 __u8 bDescriptorType
; /* CS_INTERFACE descriptor type */
212 __u8 bDescriptorSubtype
; /* OUTPUT_TERMINAL descriptor subtype */
213 __u8 bTerminalID
; /* Constant uniquely terminal ID */
214 __le16 wTerminalType
; /* USB Audio Terminal Types */
215 __u8 bAssocTerminal
; /* ID of the Input Terminal associated */
216 __u8 bSourceID
; /* ID of the connected Unit or Terminal*/
218 } __attribute__ ((packed
));
220 #define UAC_DT_OUTPUT_TERMINAL_SIZE 9
222 /* Terminals - 2.3 Output Terminal Types */
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
232 /* Set bControlSize = 2 as default setting */
233 #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
235 /* As above, but more useful for defining your own descriptors: */
236 #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
237 struct uac_feature_unit_descriptor_##ch { \
239 __u8 bDescriptorType; \
240 __u8 bDescriptorSubtype; \
244 __le16 bmaControls[ch + 1]; \
246 } __attribute__ ((packed))
248 /* 4.3.2.3 Mixer Unit Descriptor */
249 struct uac_mixer_unit_descriptor
{
251 __u8 bDescriptorType
;
252 __u8 bDescriptorSubtype
;
256 } __attribute__ ((packed
));
258 static inline __u8
uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor
*desc
)
260 return desc
->baSourceID
[desc
->bNrInPins
];
263 static inline __u32
uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor
*desc
,
266 if (protocol
== UAC_VERSION_1
)
267 return (desc
->baSourceID
[desc
->bNrInPins
+ 2] << 8) |
268 desc
->baSourceID
[desc
->bNrInPins
+ 1];
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]);
276 static inline __u8
uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor
*desc
,
279 return (protocol
== UAC_VERSION_1
) ?
280 desc
->baSourceID
[desc
->bNrInPins
+ 3] :
281 desc
->baSourceID
[desc
->bNrInPins
+ 5];
284 static inline __u8
*uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor
*desc
,
287 return (protocol
== UAC_VERSION_1
) ?
288 &desc
->baSourceID
[desc
->bNrInPins
+ 4] :
289 &desc
->baSourceID
[desc
->bNrInPins
+ 6];
292 static inline __u8
uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor
*desc
)
294 __u8
*raw
= (__u8
*) desc
;
295 return raw
[desc
->bLength
- 1];
298 /* 4.3.2.4 Selector Unit Descriptor */
299 struct uac_selector_unit_descriptor
{
301 __u8 bDescriptorType
;
302 __u8 bDescriptorSubtype
;
306 } __attribute__ ((packed
));
308 static inline __u8
uac_selector_unit_iSelector(struct uac_selector_unit_descriptor
*desc
)
310 __u8
*raw
= (__u8
*) desc
;
311 return raw
[desc
->bLength
- 1];
314 /* 4.3.2.5 Feature Unit Descriptor */
315 struct uac_feature_unit_descriptor
{
317 __u8 bDescriptorType
;
318 __u8 bDescriptorSubtype
;
322 __u8 bmaControls
[0]; /* variable length */
323 } __attribute__((packed
));
325 static inline __u8
uac_feature_unit_iFeature(struct uac_feature_unit_descriptor
*desc
)
327 __u8
*raw
= (__u8
*) desc
;
328 return raw
[desc
->bLength
- 1];
331 /* 4.3.2.6 Processing Unit Descriptors */
332 struct uac_processing_unit_descriptor
{
334 __u8 bDescriptorType
;
335 __u8 bDescriptorSubtype
;
340 } __attribute__ ((packed
));
342 static inline __u8
uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor
*desc
)
344 return desc
->baSourceID
[desc
->bNrInPins
];
347 static inline __u32
uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor
*desc
,
350 if (protocol
== UAC_VERSION_1
)
351 return (desc
->baSourceID
[desc
->bNrInPins
+ 2] << 8) |
352 desc
->baSourceID
[desc
->bNrInPins
+ 1];
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]);
360 static inline __u8
uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor
*desc
,
363 return (protocol
== UAC_VERSION_1
) ?
364 desc
->baSourceID
[desc
->bNrInPins
+ 3] :
365 desc
->baSourceID
[desc
->bNrInPins
+ 5];
368 static inline __u8
uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor
*desc
,
371 return (protocol
== UAC_VERSION_1
) ?
372 desc
->baSourceID
[desc
->bNrInPins
+ 4] :
373 desc
->baSourceID
[desc
->bNrInPins
+ 6];
376 static inline __u8
*uac_processing_unit_bmControls(struct uac_processing_unit_descriptor
*desc
,
379 return (protocol
== UAC_VERSION_1
) ?
380 &desc
->baSourceID
[desc
->bNrInPins
+ 5] :
381 &desc
->baSourceID
[desc
->bNrInPins
+ 7];
384 static inline __u8
uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor
*desc
,
387 __u8 control_size
= uac_processing_unit_bControlSize(desc
, protocol
);
388 return *(uac_processing_unit_bmControls(desc
, protocol
)
392 static inline __u8
*uac_processing_unit_specific(struct uac_processing_unit_descriptor
*desc
,
395 __u8 control_size
= uac_processing_unit_bControlSize(desc
, protocol
);
396 return uac_processing_unit_bmControls(desc
, protocol
)
400 /* 4.5.2 Class-Specific AS Interface Descriptor */
401 struct uac1_as_header_descriptor
{
402 __u8 bLength
; /* in bytes: 7 */
403 __u8 bDescriptorType
; /* USB_DT_CS_INTERFACE */
404 __u8 bDescriptorSubtype
; /* AS_GENERAL */
405 __u8 bTerminalLink
; /* Terminal ID of connected Terminal */
406 __u8 bDelay
; /* Delay introduced by the data path */
407 __le16 wFormatTag
; /* The Audio Data Format */
408 } __attribute__ ((packed
));
410 #define UAC_DT_AS_HEADER_SIZE 7
412 /* Formats - A.1.1 Audio Data Format Type I Codes */
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
420 struct uac_format_type_i_continuous_descriptor
{
421 __u8 bLength
; /* in bytes: 8 + (ns * 3) */
422 __u8 bDescriptorType
; /* USB_DT_CS_INTERFACE */
423 __u8 bDescriptorSubtype
; /* FORMAT_TYPE */
424 __u8 bFormatType
; /* FORMAT_TYPE_1 */
425 __u8 bNrChannels
; /* physical channels in the stream */
426 __u8 bSubframeSize
; /* */
429 __u8 tLowerSamFreq
[3];
430 __u8 tUpperSamFreq
[3];
431 } __attribute__ ((packed
));
433 #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
435 struct uac_format_type_i_discrete_descriptor
{
436 __u8 bLength
; /* in bytes: 8 + (ns * 3) */
437 __u8 bDescriptorType
; /* USB_DT_CS_INTERFACE */
438 __u8 bDescriptorSubtype
; /* FORMAT_TYPE */
439 __u8 bFormatType
; /* FORMAT_TYPE_1 */
440 __u8 bNrChannels
; /* physical channels in the stream */
441 __u8 bSubframeSize
; /* */
445 } __attribute__ ((packed
));
447 #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
448 struct uac_format_type_i_discrete_descriptor_##n { \
450 __u8 bDescriptorType; \
451 __u8 bDescriptorSubtype; \
454 __u8 bSubframeSize; \
455 __u8 bBitResolution; \
457 __u8 tSamFreq[n][3]; \
458 } __attribute__ ((packed))
460 #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
462 struct uac_format_type_i_ext_descriptor
{
464 __u8 bDescriptorType
;
465 __u8 bDescriptorSubtype
;
471 __u8 bSideBandProtocol
;
472 } __attribute__((packed
));
474 /* Formats - Audio Data Format Type I Codes */
476 #define UAC_FORMAT_TYPE_II_MPEG 0x1001
477 #define UAC_FORMAT_TYPE_II_AC3 0x1002
479 struct uac_format_type_ii_discrete_descriptor
{
481 __u8 bDescriptorType
;
482 __u8 bDescriptorSubtype
;
485 __le16 wSamplesPerFrame
;
488 } __attribute__((packed
));
490 struct uac_format_type_ii_ext_descriptor
{
492 __u8 bDescriptorType
;
493 __u8 bDescriptorSubtype
;
496 __le16 wSamplesPerFrame
;
498 __u8 bSideBandProtocol
;
499 } __attribute__((packed
));
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
509 /* Formats - A.2 Format Type Codes */
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
518 struct uac_iso_endpoint_descriptor
{
519 __u8 bLength
; /* in bytes: 7 */
520 __u8 bDescriptorType
; /* USB_DT_CS_ENDPOINT */
521 __u8 bDescriptorSubtype
; /* EP_GENERAL */
523 __u8 bLockDelayUnits
;
525 } __attribute__((packed
));
526 #define UAC_ISO_ENDPOINT_DESC_SIZE 7
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
532 /* status word format (3.7.1.1) */
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
539 #define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7)
540 #define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6)
542 struct uac1_status_word
{
545 } __attribute__((packed
));
548 #endif /* _UAPI__LINUX_USB_AUDIO_H */