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 /* A.5 Audio Class-Specific AC interface Descriptor Subtypes*/
30 #define INPUT_TERMINAL 0x02
31 #define OUTPUT_TERMINAL 0x03
32 #define MIXER_UNIT 0x04
33 #define SELECTOR_UNIT 0x05
34 #define FEATURE_UNIT 0x06
35 #define PROCESSING_UNIT 0x07
36 #define EXTENSION_UNIT 0x08
38 #define AS_GENERAL 0x01
39 #define FORMAT_TYPE 0x02
40 #define FORMAT_SPECIFIC 0x03
42 #define EP_GENERAL 0x01
44 #define MS_GENERAL 0x01
45 #define MIDI_IN_JACK 0x02
46 #define MIDI_OUT_JACK 0x03
48 /* cs endpoint attributes */
49 #define EP_CS_ATTR_SAMPLE_RATE 0x01
50 #define EP_CS_ATTR_PITCH_CONTROL 0x02
51 #define EP_CS_ATTR_FILL_MAX 0x80
53 /* Audio Class specific Request Codes */
54 #define USB_AUDIO_SET_INTF 0x21
55 #define USB_AUDIO_SET_ENDPOINT 0x22
56 #define USB_AUDIO_GET_INTF 0xa1
57 #define USB_AUDIO_GET_ENDPOINT 0xa2
68 #define SET_CUR (SET_ | _CUR)
69 #define GET_CUR (GET_ | _CUR)
70 #define SET_MIN (SET_ | _MIN)
71 #define GET_MIN (GET_ | _MIN)
72 #define SET_MAX (SET_ | _MAX)
73 #define GET_MAX (GET_ | _MAX)
74 #define SET_RES (SET_ | _RES)
75 #define GET_RES (GET_ | _RES)
76 #define SET_MEM (SET_ | _MEM)
77 #define GET_MEM (GET_ | _MEM)
81 #define USB_AC_TERMINAL_UNDEFINED 0x100
82 #define USB_AC_TERMINAL_STREAMING 0x101
83 #define USB_AC_TERMINAL_VENDOR_SPEC 0x1FF
85 /* Terminal Control Selectors */
86 /* 4.3.2 Class-Specific AC Interface Descriptor */
87 struct usb_ac_header_descriptor {
88 __u8 bLength; /* 8 + n */
89 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
90 __u8 bDescriptorSubtype; /* USB_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 USB_DT_AC_HEADER_SIZE(n) (8 + (n))
99 /* As above, but more useful for defining your own descriptors: */
100 #define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \
101 struct usb_ac_header_descriptor_##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 usb_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 USB_DT_AC_INPUT_TERMINAL_SIZE 12
127 #define USB_AC_INPUT_TERMINAL_UNDEFINED 0x200
128 #define USB_AC_INPUT_TERMINAL_MICROPHONE 0x201
129 #define USB_AC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
130 #define USB_AC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
131 #define USB_AC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
132 #define USB_AC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
133 #define USB_AC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
135 /* 4.3.2.2 Output Terminal Descriptor */
136 struct usb_output_terminal_descriptor {
137 __u8 bLength; /* in bytes: 9 */
138 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
139 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
140 __u8 bTerminalID; /* Constant uniquely terminal ID */
141 __le16 wTerminalType; /* USB Audio Terminal Types */
142 __u8 bAssocTerminal; /* ID of the Input Terminal associated */
143 __u8 bSourceID; /* ID of the connected Unit or Terminal*/
145 } __attribute__ ((packed));
147 #define USB_DT_AC_OUTPUT_TERMINAL_SIZE 9
149 #define USB_AC_OUTPUT_TERMINAL_UNDEFINED 0x300
150 #define USB_AC_OUTPUT_TERMINAL_SPEAKER 0x301
151 #define USB_AC_OUTPUT_TERMINAL_HEADPHONES 0x302
152 #define USB_AC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
153 #define USB_AC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
154 #define USB_AC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
155 #define USB_AC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
156 #define USB_AC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
158 /* Set bControlSize = 2 as default setting */
159 #define USB_DT_AC_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
161 /* As above, but more useful for defining your own descriptors: */
162 #define DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(ch) \
163 struct usb_ac_feature_unit_descriptor_##ch { \
165 __u8 bDescriptorType; \
166 __u8 bDescriptorSubtype; \
170 __le16 bmaControls[ch + 1]; \
172 } __attribute__ ((packed))
174 /* 4.5.2 Class-Specific AS Interface Descriptor */
175 struct usb_as_header_descriptor {
176 __u8 bLength; /* in bytes: 7 */
177 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
178 __u8 bDescriptorSubtype; /* AS_GENERAL */
179 __u8 bTerminalLink; /* Terminal ID of connected Terminal */
180 __u8 bDelay; /* Delay introduced by the data path */
181 __le16 wFormatTag; /* The Audio Data Format */
182 } __attribute__ ((packed));
184 #define USB_DT_AS_HEADER_SIZE 7
186 #define USB_AS_AUDIO_FORMAT_TYPE_I_UNDEFINED 0x0
187 #define USB_AS_AUDIO_FORMAT_TYPE_I_PCM 0x1
188 #define USB_AS_AUDIO_FORMAT_TYPE_I_PCM8 0x2
189 #define USB_AS_AUDIO_FORMAT_TYPE_I_IEEE_FLOAT 0x3
190 #define USB_AS_AUDIO_FORMAT_TYPE_I_ALAW 0x4
191 #define USB_AS_AUDIO_FORMAT_TYPE_I_MULAW 0x5
193 struct usb_as_format_type_i_continuous_descriptor {
194 __u8 bLength; /* in bytes: 8 + (ns * 3) */
195 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
196 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
197 __u8 bFormatType; /* FORMAT_TYPE_1 */
198 __u8 bNrChannels; /* physical channels in the stream */
199 __u8 bSubframeSize; /* */
202 __u8 tLowerSamFreq[3];
203 __u8 tUpperSamFreq[3];
204 } __attribute__ ((packed));
206 #define USB_AS_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
208 struct usb_as_formate_type_i_discrete_descriptor {
209 __u8 bLength; /* in bytes: 8 + (ns * 3) */
210 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
211 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
212 __u8 bFormatType; /* FORMAT_TYPE_1 */
213 __u8 bNrChannels; /* physical channels in the stream */
214 __u8 bSubframeSize; /* */
218 } __attribute__ ((packed));
220 #define DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(n) \
221 struct usb_as_formate_type_i_discrete_descriptor_##n { \
223 __u8 bDescriptorType; \
224 __u8 bDescriptorSubtype; \
227 __u8 bSubframeSize; \
228 __u8 bBitResolution; \
230 __u8 tSamFreq[n][3]; \
231 } __attribute__ ((packed))
233 #define USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
235 #define USB_AS_FORMAT_TYPE_UNDEFINED 0x0
236 #define USB_AS_FORMAT_TYPE_I 0x1
237 #define USB_AS_FORMAT_TYPE_II 0x2
238 #define USB_AS_FORMAT_TYPE_III 0x3
240 struct usb_as_iso_endpoint_descriptor {
241 __u8 bLength; /* in bytes: 7 */
242 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
243 __u8 bDescriptorSubtype; /* EP_GENERAL */
245 __u8 bLockDelayUnits;
248 #define USB_AS_ISO_ENDPOINT_DESC_SIZE 7
250 #define FU_CONTROL_UNDEFINED 0x00
251 #define MUTE_CONTROL 0x01
252 #define VOLUME_CONTROL 0x02
253 #define BASS_CONTROL 0x03
254 #define MID_CONTROL 0x04
255 #define TREBLE_CONTROL 0x05
256 #define GRAPHIC_EQUALIZER_CONTROL 0x06
257 #define AUTOMATIC_GAIN_CONTROL 0x07
258 #define DELAY_CONTROL 0x08
259 #define BASS_BOOST_CONTROL 0x09
260 #define LOUDNESS_CONTROL 0x0a
262 #define FU_MUTE (1 << (MUTE_CONTROL - 1))
263 #define FU_VOLUME (1 << (VOLUME_CONTROL - 1))
264 #define FU_BASS (1 << (BASS_CONTROL - 1))
265 #define FU_MID (1 << (MID_CONTROL - 1))
266 #define FU_TREBLE (1 << (TREBLE_CONTROL - 1))
267 #define FU_GRAPHIC_EQ (1 << (GRAPHIC_EQUALIZER_CONTROL - 1))
268 #define FU_AUTO_GAIN (1 << (AUTOMATIC_GAIN_CONTROL - 1))
269 #define FU_DELAY (1 << (DELAY_CONTROL - 1))
270 #define FU_BASS_BOOST (1 << (BASS_BOOST_CONTROL - 1))
271 #define FU_LOUDNESS (1 << (LOUDNESS_CONTROL - 1))
273 struct usb_audio_control {
274 struct list_head list;
278 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
279 int (*get)(struct usb_audio_control *con, u8 cmd);
282 static inline int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
284 con->data[cmd] = value;
289 static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
291 return con->data[cmd];
294 struct usb_audio_control_selector {
295 struct list_head list;
296 struct list_head control;
300 struct usb_descriptor_header *desc;
303 #endif /* __LINUX_USB_AUDIO_H */