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
27 #define USB_SUBCLASS_VENDOR_SPEC 0xff
29 /* A.5 Audio Class-Specific AC interface Descriptor Subtypes*/
31 #define INPUT_TERMINAL 0x02
32 #define OUTPUT_TERMINAL 0x03
33 #define MIXER_UNIT 0x04
34 #define SELECTOR_UNIT 0x05
35 #define FEATURE_UNIT 0x06
36 #define PROCESSING_UNIT 0x07
37 #define EXTENSION_UNIT 0x08
39 #define AS_GENERAL 0x01
40 #define FORMAT_TYPE 0x02
41 #define FORMAT_SPECIFIC 0x03
43 #define EP_GENERAL 0x01
45 #define MS_GENERAL 0x01
46 #define MIDI_IN_JACK 0x02
47 #define MIDI_OUT_JACK 0x03
49 /* cs endpoint attributes */
50 #define EP_CS_ATTR_SAMPLE_RATE 0x01
51 #define EP_CS_ATTR_PITCH_CONTROL 0x02
52 #define EP_CS_ATTR_FILL_MAX 0x80
54 /* Audio Class specific Request Codes */
55 #define USB_AUDIO_SET_INTF 0x21
56 #define USB_AUDIO_SET_ENDPOINT 0x22
57 #define USB_AUDIO_GET_INTF 0xa1
58 #define USB_AUDIO_GET_ENDPOINT 0xa2
69 #define SET_CUR (SET_ | _CUR)
70 #define GET_CUR (GET_ | _CUR)
71 #define SET_MIN (SET_ | _MIN)
72 #define GET_MIN (GET_ | _MIN)
73 #define SET_MAX (SET_ | _MAX)
74 #define GET_MAX (GET_ | _MAX)
75 #define SET_RES (SET_ | _RES)
76 #define GET_RES (GET_ | _RES)
77 #define SET_MEM (SET_ | _MEM)
78 #define GET_MEM (GET_ | _MEM)
82 #define USB_AC_TERMINAL_UNDEFINED 0x100
83 #define USB_AC_TERMINAL_STREAMING 0x101
84 #define USB_AC_TERMINAL_VENDOR_SPEC 0x1FF
86 /* Terminal Control Selectors */
87 /* 4.3.2 Class-Specific AC Interface Descriptor */
88 struct usb_ac_header_descriptor {
89 __u8 bLength; /* 8 + n */
90 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
91 __u8 bDescriptorSubtype; /* USB_MS_HEADER */
92 __le16 bcdADC; /* 0x0100 */
93 __le16 wTotalLength; /* includes Unit and Terminal desc. */
94 __u8 bInCollection; /* n */
95 __u8 baInterfaceNr[]; /* [n] */
96 } __attribute__ ((packed));
98 #define USB_DT_AC_HEADER_SIZE(n) (8 + (n))
100 /* As above, but more useful for defining your own descriptors: */
101 #define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \
102 struct usb_ac_header_descriptor_##n { \
104 __u8 bDescriptorType; \
105 __u8 bDescriptorSubtype; \
107 __le16 wTotalLength; \
108 __u8 bInCollection; \
109 __u8 baInterfaceNr[n]; \
110 } __attribute__ ((packed))
112 /* 4.3.2.1 Input Terminal Descriptor */
113 struct usb_input_terminal_descriptor {
114 __u8 bLength; /* in bytes: 12 */
115 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
116 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
117 __u8 bTerminalID; /* Constant uniquely terminal ID */
118 __le16 wTerminalType; /* USB Audio Terminal Types */
119 __u8 bAssocTerminal; /* ID of the Output Terminal associated */
120 __u8 bNrChannels; /* Number of logical output channels */
121 __le16 wChannelConfig;
124 } __attribute__ ((packed));
126 #define USB_DT_AC_INPUT_TERMINAL_SIZE 12
128 #define USB_AC_INPUT_TERMINAL_UNDEFINED 0x200
129 #define USB_AC_INPUT_TERMINAL_MICROPHONE 0x201
130 #define USB_AC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
131 #define USB_AC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
132 #define USB_AC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
133 #define USB_AC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
134 #define USB_AC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
136 /* 4.3.2.2 Output Terminal Descriptor */
137 struct usb_output_terminal_descriptor {
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 USB_DT_AC_OUTPUT_TERMINAL_SIZE 9
150 #define USB_AC_OUTPUT_TERMINAL_UNDEFINED 0x300
151 #define USB_AC_OUTPUT_TERMINAL_SPEAKER 0x301
152 #define USB_AC_OUTPUT_TERMINAL_HEADPHONES 0x302
153 #define USB_AC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
154 #define USB_AC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
155 #define USB_AC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
156 #define USB_AC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
157 #define USB_AC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
159 /* Set bControlSize = 2 as default setting */
160 #define USB_DT_AC_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
162 /* As above, but more useful for defining your own descriptors: */
163 #define DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(ch) \
164 struct usb_ac_feature_unit_descriptor_##ch { \
166 __u8 bDescriptorType; \
167 __u8 bDescriptorSubtype; \
171 __le16 bmaControls[ch + 1]; \
173 } __attribute__ ((packed))
175 /* 4.5.2 Class-Specific AS Interface Descriptor */
176 struct usb_as_header_descriptor {
177 __u8 bLength; /* in bytes: 7 */
178 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
179 __u8 bDescriptorSubtype; /* AS_GENERAL */
180 __u8 bTerminalLink; /* Terminal ID of connected Terminal */
181 __u8 bDelay; /* Delay introduced by the data path */
182 __le16 wFormatTag; /* The Audio Data Format */
183 } __attribute__ ((packed));
185 #define USB_DT_AS_HEADER_SIZE 7
187 #define USB_AS_AUDIO_FORMAT_TYPE_I_UNDEFINED 0x0
188 #define USB_AS_AUDIO_FORMAT_TYPE_I_PCM 0x1
189 #define USB_AS_AUDIO_FORMAT_TYPE_I_PCM8 0x2
190 #define USB_AS_AUDIO_FORMAT_TYPE_I_IEEE_FLOAT 0x3
191 #define USB_AS_AUDIO_FORMAT_TYPE_I_ALAW 0x4
192 #define USB_AS_AUDIO_FORMAT_TYPE_I_MULAW 0x5
194 struct usb_as_format_type_i_continuous_descriptor {
195 __u8 bLength; /* in bytes: 8 + (ns * 3) */
196 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
197 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
198 __u8 bFormatType; /* FORMAT_TYPE_1 */
199 __u8 bNrChannels; /* physical channels in the stream */
200 __u8 bSubframeSize; /* */
203 __u8 tLowerSamFreq[3];
204 __u8 tUpperSamFreq[3];
205 } __attribute__ ((packed));
207 #define USB_AS_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
209 struct usb_as_formate_type_i_discrete_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; /* */
219 } __attribute__ ((packed));
221 #define DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(n) \
222 struct usb_as_formate_type_i_discrete_descriptor_##n { \
224 __u8 bDescriptorType; \
225 __u8 bDescriptorSubtype; \
228 __u8 bSubframeSize; \
229 __u8 bBitResolution; \
231 __u8 tSamFreq[n][3]; \
232 } __attribute__ ((packed))
234 #define USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
236 #define USB_AS_FORMAT_TYPE_UNDEFINED 0x0
237 #define USB_AS_FORMAT_TYPE_I 0x1
238 #define USB_AS_FORMAT_TYPE_II 0x2
239 #define USB_AS_FORMAT_TYPE_III 0x3
241 struct usb_as_iso_endpoint_descriptor {
242 __u8 bLength; /* in bytes: 7 */
243 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
244 __u8 bDescriptorSubtype; /* EP_GENERAL */
246 __u8 bLockDelayUnits;
249 #define USB_AS_ISO_ENDPOINT_DESC_SIZE 7
251 #define FU_CONTROL_UNDEFINED 0x00
252 #define MUTE_CONTROL 0x01
253 #define VOLUME_CONTROL 0x02
254 #define BASS_CONTROL 0x03
255 #define MID_CONTROL 0x04
256 #define TREBLE_CONTROL 0x05
257 #define GRAPHIC_EQUALIZER_CONTROL 0x06
258 #define AUTOMATIC_GAIN_CONTROL 0x07
259 #define DELAY_CONTROL 0x08
260 #define BASS_BOOST_CONTROL 0x09
261 #define LOUDNESS_CONTROL 0x0a
263 #define FU_MUTE (1 << (MUTE_CONTROL - 1))
264 #define FU_VOLUME (1 << (VOLUME_CONTROL - 1))
265 #define FU_BASS (1 << (BASS_CONTROL - 1))
266 #define FU_MID (1 << (MID_CONTROL - 1))
267 #define FU_TREBLE (1 << (TREBLE_CONTROL - 1))
268 #define FU_GRAPHIC_EQ (1 << (GRAPHIC_EQUALIZER_CONTROL - 1))
269 #define FU_AUTO_GAIN (1 << (AUTOMATIC_GAIN_CONTROL - 1))
270 #define FU_DELAY (1 << (DELAY_CONTROL - 1))
271 #define FU_BASS_BOOST (1 << (BASS_BOOST_CONTROL - 1))
272 #define FU_LOUDNESS (1 << (LOUDNESS_CONTROL - 1))
274 struct usb_audio_control {
275 struct list_head list;
279 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
280 int (*get)(struct usb_audio_control *con, u8 cmd);
283 static inline int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
285 con->data[cmd] = value;
290 static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
292 return con->data[cmd];
295 struct usb_audio_control_selector {
296 struct list_head list;
297 struct list_head control;
301 struct usb_descriptor_header *desc;
304 #endif /* __LINUX_USB_AUDIO_H */