ALSA: usbaudio: introduce new types for audio class v2
[safe/jmp/linux-2.6] / include / linux / usb / audio.h
1 /*
2  * <linux/usb/audio.h> -- USB Audio definitions.
3  *
4  * Copyright (C) 2006 Thumtronics Pty Ltd.
5  * Developed for Thumtronics by Grey Innovation
6  * Ben Williamson <ben.williamson@greyinnovation.com>
7  *
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.
10  *
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:
14  *
15  * http://www.usb.org/developers/devclass_docs/audio10.pdf
16  */
17
18 #ifndef __LINUX_USB_AUDIO_H
19 #define __LINUX_USB_AUDIO_H
20
21 #include <linux/types.h>
22
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
28 #define UAC_VERSION_1                   0x00
29 #define UAC_VERSION_2                   0x20
30
31 /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
32 #define UAC_HEADER                      0x01
33 #define UAC_INPUT_TERMINAL              0x02
34 #define UAC_OUTPUT_TERMINAL             0x03
35 #define UAC_MIXER_UNIT                  0x04
36 #define UAC_SELECTOR_UNIT               0x05
37 #define UAC_FEATURE_UNIT                0x06
38 #define UAC_PROCESSING_UNIT             0x07
39 #define UAC_EXTENSION_UNIT              0x08
40
41 /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
42 #define UAC_AS_GENERAL                  0x01
43 #define UAC_FORMAT_TYPE                 0x02
44 #define UAC_FORMAT_SPECIFIC             0x03
45
46 /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
47 #define UAC_EP_GENERAL                  0x01
48
49 /* A.9 Audio Class-Specific Request Codes */
50 #define UAC_SET_                        0x00
51 #define UAC_GET_                        0x80
52
53 #define UAC__CUR                        0x1
54 #define UAC__MIN                        0x2
55 #define UAC__MAX                        0x3
56 #define UAC__RES                        0x4
57 #define UAC__MEM                        0x5
58
59 #define UAC_SET_CUR                     (UAC_SET_ | UAC__CUR)
60 #define UAC_GET_CUR                     (UAC_GET_ | UAC__CUR)
61 #define UAC_SET_MIN                     (UAC_SET_ | UAC__MIN)
62 #define UAC_GET_MIN                     (UAC_GET_ | UAC__MIN)
63 #define UAC_SET_MAX                     (UAC_SET_ | UAC__MAX)
64 #define UAC_GET_MAX                     (UAC_GET_ | UAC__MAX)
65 #define UAC_SET_RES                     (UAC_SET_ | UAC__RES)
66 #define UAC_GET_RES                     (UAC_GET_ | UAC__RES)
67 #define UAC_SET_MEM                     (UAC_SET_ | UAC__MEM)
68 #define UAC_GET_MEM                     (UAC_GET_ | UAC__MEM)
69
70 #define UAC_GET_STAT                    0xff
71
72 /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
73 #define UAC_MS_HEADER                   0x01
74 #define UAC_MIDI_IN_JACK                0x02
75 #define UAC_MIDI_OUT_JACK               0x03
76
77 /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
78 #define UAC_MS_GENERAL                  0x01
79
80 /* Terminals - 2.1 USB Terminal Types */
81 #define UAC_TERMINAL_UNDEFINED          0x100
82 #define UAC_TERMINAL_STREAMING          0x101
83 #define UAC_TERMINAL_VENDOR_SPEC        0x1FF
84
85 /* Terminal Control Selectors */
86 /* 4.3.2  Class-Specific AC Interface Descriptor */
87 struct uac_ac_header_descriptor_v1 {
88         __u8  bLength;                  /* 8 + n */
89         __u8  bDescriptorType;          /* USB_DT_CS_INTERFACE */
90         __u8  bDescriptorSubtype;       /* UAC_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));
96
97 #define UAC_DT_AC_HEADER_SIZE(n)        (8 + (n))
98
99 /* As above, but more useful for defining your own descriptors: */
100 #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n)                     \
101 struct uac_ac_header_descriptor_v1_##n {                        \
102         __u8  bLength;                                          \
103         __u8  bDescriptorType;                                  \
104         __u8  bDescriptorSubtype;                               \
105         __le16 bcdADC;                                          \
106         __le16 wTotalLength;                                    \
107         __u8  bInCollection;                                    \
108         __u8  baInterfaceNr[n];                                 \
109 } __attribute__ ((packed))
110
111 /* 4.3.2.1 Input Terminal Descriptor */
112 struct uac_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;
121         __u8  iChannelNames;
122         __u8  iTerminal;
123 } __attribute__ ((packed));
124
125 #define UAC_DT_INPUT_TERMINAL_SIZE                      12
126
127 /* Terminals - 2.2 Input Terminal Types */
128 #define UAC_INPUT_TERMINAL_UNDEFINED                    0x200
129 #define UAC_INPUT_TERMINAL_MICROPHONE                   0x201
130 #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE           0x202
131 #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE          0x203
132 #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE          0x204
133 #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY             0x205
134 #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY        0x206
135
136 /* 4.3.2.2 Output Terminal Descriptor */
137 struct uac_output_terminal_descriptor_v1 {
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*/
145         __u8  iTerminal;
146 } __attribute__ ((packed));
147
148 #define UAC_DT_OUTPUT_TERMINAL_SIZE                     9
149
150 /* Terminals - 2.3 Output Terminal Types */
151 #define UAC_OUTPUT_TERMINAL_UNDEFINED                   0x300
152 #define UAC_OUTPUT_TERMINAL_SPEAKER                     0x301
153 #define UAC_OUTPUT_TERMINAL_HEADPHONES                  0x302
154 #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO  0x303
155 #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER             0x304
156 #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER                0x305
157 #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER       0x306
158 #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER    0x307
159
160 /* Set bControlSize = 2 as default setting */
161 #define UAC_DT_FEATURE_UNIT_SIZE(ch)            (7 + ((ch) + 1) * 2)
162
163 /* As above, but more useful for defining your own descriptors: */
164 #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch)                 \
165 struct uac_feature_unit_descriptor_##ch {                       \
166         __u8  bLength;                                          \
167         __u8  bDescriptorType;                                  \
168         __u8  bDescriptorSubtype;                               \
169         __u8  bUnitID;                                          \
170         __u8  bSourceID;                                        \
171         __u8  bControlSize;                                     \
172         __le16 bmaControls[ch + 1];                             \
173         __u8  iFeature;                                         \
174 } __attribute__ ((packed))
175
176 /* 4.5.2 Class-Specific AS Interface Descriptor */
177 struct uac_as_header_descriptor_v1 {
178         __u8  bLength;                  /* in bytes: 7 */
179         __u8  bDescriptorType;          /* USB_DT_CS_INTERFACE */
180         __u8  bDescriptorSubtype;       /* AS_GENERAL */
181         __u8  bTerminalLink;            /* Terminal ID of connected Terminal */
182         __u8  bDelay;                   /* Delay introduced by the data path */
183         __le16 wFormatTag;              /* The Audio Data Format */
184 } __attribute__ ((packed));
185
186 struct uac_as_header_descriptor_v2 {
187         __u8 bLength;
188         __u8 bDescriptorType;
189         __u8 bDescriptorSubtype;
190         __u8 bTerminalLink;
191         __u8 bmControls;
192         __u8 bFormatType;
193         __u32 bmFormats;
194         __u8 bNrChannels;
195         __u32 bmChannelConfig;
196         __u8 iChannelNames;
197 } __attribute__((packed));
198
199 #define UAC_DT_AS_HEADER_SIZE           7
200
201 /* Formats - A.1.1 Audio Data Format Type I Codes */
202 #define UAC_FORMAT_TYPE_I_UNDEFINED     0x0
203 #define UAC_FORMAT_TYPE_I_PCM           0x1
204 #define UAC_FORMAT_TYPE_I_PCM8          0x2
205 #define UAC_FORMAT_TYPE_I_IEEE_FLOAT    0x3
206 #define UAC_FORMAT_TYPE_I_ALAW          0x4
207 #define UAC_FORMAT_TYPE_I_MULAW         0x5
208
209 struct uac_format_type_i_continuous_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;            /* */
216         __u8  bBitResolution;
217         __u8  bSamFreqType;
218         __u8  tLowerSamFreq[3];
219         __u8  tUpperSamFreq[3];
220 } __attribute__ ((packed));
221
222 #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE  14
223
224 struct uac_format_type_i_discrete_descriptor {
225         __u8  bLength;                  /* in bytes: 8 + (ns * 3) */
226         __u8  bDescriptorType;          /* USB_DT_CS_INTERFACE */
227         __u8  bDescriptorSubtype;       /* FORMAT_TYPE */
228         __u8  bFormatType;              /* FORMAT_TYPE_1 */
229         __u8  bNrChannels;              /* physical channels in the stream */
230         __u8  bSubframeSize;            /* */
231         __u8  bBitResolution;
232         __u8  bSamFreqType;
233         __u8  tSamFreq[][3];
234 } __attribute__ ((packed));
235
236 #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n)              \
237 struct uac_format_type_i_discrete_descriptor_##n {              \
238         __u8  bLength;                                          \
239         __u8  bDescriptorType;                                  \
240         __u8  bDescriptorSubtype;                               \
241         __u8  bFormatType;                                      \
242         __u8  bNrChannels;                                      \
243         __u8  bSubframeSize;                                    \
244         __u8  bBitResolution;                                   \
245         __u8  bSamFreqType;                                     \
246         __u8  tSamFreq[n][3];                                   \
247 } __attribute__ ((packed))
248
249 #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
250
251 struct uac_format_type_i_ext_descriptor {
252         __u8 bLength;
253         __u8 bDescriptorType;
254         __u8 bDescriptorSubtype;
255         __u8 bSubslotSize;
256         __u8 bFormatType;
257         __u8 bBitResolution;
258         __u8 bHeaderLength;
259         __u8 bControlSize;
260         __u8 bSideBandProtocol;
261 } __attribute__((packed));
262
263
264 /* Formats - Audio Data Format Type I Codes */
265
266 struct uac_format_type_ii_discrete_descriptor {
267         __u8 bLength;
268         __u8 bDescriptorType;
269         __u8 bDescriptorSubtype;
270         __u8 bFormatType;
271         __le16 wMaxBitRate;
272         __le16 wSamplesPerFrame;
273         __u8 bSamFreqType;
274         __u8 tSamFreq[][3];
275 } __attribute__((packed));
276
277 struct uac_format_type_ii_ext_descriptor {
278         __u8 bLength;
279         __u8 bDescriptorType;
280         __u8 bDescriptorSubtype;
281         __u8 bFormatType;
282         __u16 wMaxBitRate;
283         __u16 wSamplesPerFrame;
284         __u8 bHeaderLength;
285         __u8 bSideBandProtocol;
286 } __attribute__((packed));
287
288
289 /* Formats - A.2 Format Type Codes */
290 #define UAC_FORMAT_TYPE_UNDEFINED       0x0
291 #define UAC_FORMAT_TYPE_I               0x1
292 #define UAC_FORMAT_TYPE_II              0x2
293 #define UAC_FORMAT_TYPE_III             0x3
294 #define UAC_EXT_FORMAT_TYPE_I           0x81
295 #define UAC_EXT_FORMAT_TYPE_II          0x82
296 #define UAC_EXT_FORMAT_TYPE_III         0x83
297
298 struct uac_iso_endpoint_descriptor {
299         __u8  bLength;                  /* in bytes: 7 */
300         __u8  bDescriptorType;          /* USB_DT_CS_ENDPOINT */
301         __u8  bDescriptorSubtype;       /* EP_GENERAL */
302         __u8  bmAttributes;
303         __u8  bLockDelayUnits;
304         __le16 wLockDelay;
305 };
306 #define UAC_ISO_ENDPOINT_DESC_SIZE      7
307
308 #define UAC_EP_CS_ATTR_SAMPLE_RATE      0x01
309 #define UAC_EP_CS_ATTR_PITCH_CONTROL    0x02
310 #define UAC_EP_CS_ATTR_FILL_MAX         0x80
311
312 /* Audio class v2.0: CLOCK_SOURCE descriptor */
313
314 struct uac_clock_source_descriptor {
315         __u8 bLength;
316         __u8 bDescriptorType;
317         __u8 bDescriptorSubtype;
318         __u8 bClockID;
319         __u8 bmAttributes;
320         __u8 bmControls;
321         __u8 bAssocTerminal;
322         __u8 iClockSource;
323 } __attribute__((packed));
324
325 /* A.10.2 Feature Unit Control Selectors */
326
327 struct uac_feature_unit_descriptor {
328         __u8 bLength;
329         __u8 bDescriptorType;
330         __u8 bDescriptorSubtype;
331         __u8 bUnitID;
332         __u8 bSourceID;
333         __u8 bControlSize;
334         __u8 controls[0]; /* variable length */
335 } __attribute__((packed));
336
337 #define UAC_FU_CONTROL_UNDEFINED        0x00
338 #define UAC_MUTE_CONTROL                0x01
339 #define UAC_VOLUME_CONTROL              0x02
340 #define UAC_BASS_CONTROL                0x03
341 #define UAC_MID_CONTROL                 0x04
342 #define UAC_TREBLE_CONTROL              0x05
343 #define UAC_GRAPHIC_EQUALIZER_CONTROL   0x06
344 #define UAC_AUTOMATIC_GAIN_CONTROL      0x07
345 #define UAC_DELAY_CONTROL               0x08
346 #define UAC_BASS_BOOST_CONTROL          0x09
347 #define UAC_LOUDNESS_CONTROL            0x0a
348
349 #define UAC_FU_MUTE             (1 << (UAC_MUTE_CONTROL - 1))
350 #define UAC_FU_VOLUME           (1 << (UAC_VOLUME_CONTROL - 1))
351 #define UAC_FU_BASS             (1 << (UAC_BASS_CONTROL - 1))
352 #define UAC_FU_MID              (1 << (UAC_MID_CONTROL - 1))
353 #define UAC_FU_TREBLE           (1 << (UAC_TREBLE_CONTROL - 1))
354 #define UAC_FU_GRAPHIC_EQ       (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
355 #define UAC_FU_AUTO_GAIN        (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
356 #define UAC_FU_DELAY            (1 << (UAC_DELAY_CONTROL - 1))
357 #define UAC_FU_BASS_BOOST       (1 << (UAC_BASS_BOOST_CONTROL - 1))
358 #define UAC_FU_LOUDNESS         (1 << (UAC_LOUDNESS_CONTROL - 1))
359
360 #ifdef __KERNEL__
361
362 struct usb_audio_control {
363         struct list_head list;
364         const char *name;
365         u8 type;
366         int data[5];
367         int (*set)(struct usb_audio_control *con, u8 cmd, int value);
368         int (*get)(struct usb_audio_control *con, u8 cmd);
369 };
370
371 struct usb_audio_control_selector {
372         struct list_head list;
373         struct list_head control;
374         u8 id;
375         const char *name;
376         u8 type;
377         struct usb_descriptor_header *desc;
378 };
379
380 #endif /* __KERNEL__ */
381
382 #endif /* __LINUX_USB_AUDIO_H */