blob: fb1a97bf943d2c59a96931c1f91af6c98ea6e5fa [file] [log] [blame]
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +10001/*
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
Daniel Mack8fee4af2010-02-22 23:49:10 +010028#define UAC_VERSION_1 0x00
29#define UAC_VERSION_2 0x20
30
Laurent Pinchart512ad272009-06-21 23:23:05 +020031/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -040040
Laurent Pinchart512ad272009-06-21 23:23:05 +020041/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -040045
Laurent Pinchart512ad272009-06-21 23:23:05 +020046/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
47#define UAC_EP_GENERAL 0x01
Bryan Wuc47d7b02009-06-03 09:17:57 -040048
Laurent Pinchart512ad272009-06-21 23:23:05 +020049/* A.9 Audio Class-Specific Request Codes */
50#define UAC_SET_ 0x00
51#define UAC_GET_ 0x80
Bryan Wuc47d7b02009-06-03 09:17:57 -040052
Laurent Pinchart512ad272009-06-21 23:23:05 +020053#define UAC__CUR 0x1
54#define UAC__MIN 0x2
55#define UAC__MAX 0x3
56#define UAC__RES 0x4
57#define UAC__MEM 0x5
Bryan Wuc47d7b02009-06-03 09:17:57 -040058
Laurent Pinchart512ad272009-06-21 23:23:05 +020059#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)
Bryan Wuc47d7b02009-06-03 09:17:57 -040069
Laurent Pinchart512ad272009-06-21 23:23:05 +020070#define UAC_GET_STAT 0xff
Bryan Wuc47d7b02009-06-03 09:17:57 -040071
Laurent Pinchart512ad272009-06-21 23:23:05 +020072/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -040076
Laurent Pinchart512ad272009-06-21 23:23:05 +020077/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
78#define UAC_MS_GENERAL 0x01
Bryan Wuc47d7b02009-06-03 09:17:57 -040079
Laurent Pinchart512ad272009-06-21 23:23:05 +020080/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -040084
85/* Terminal Control Selectors */
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100086/* 4.3.2 Class-Specific AC Interface Descriptor */
Daniel Mack28e1b772010-02-22 23:49:09 +010087struct uac_ac_header_descriptor_v1 {
Bryan Wuc47d7b02009-06-03 09:17:57 -040088 __u8 bLength; /* 8 + n */
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080089 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
Laurent Pinchart512ad272009-06-21 23:23:05 +020090 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080091 __le16 bcdADC; /* 0x0100 */
92 __le16 wTotalLength; /* includes Unit and Terminal desc. */
93 __u8 bInCollection; /* n */
94 __u8 baInterfaceNr[]; /* [n] */
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100095} __attribute__ ((packed));
96
Laurent Pinchart512ad272009-06-21 23:23:05 +020097#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100098
99/* As above, but more useful for defining your own descriptors: */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200100#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
Daniel Mack28e1b772010-02-22 23:49:09 +0100101struct uac_ac_header_descriptor_v1_##n { \
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +1000102 __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
Bryan Wuc47d7b02009-06-03 09:17:57 -0400111/* 4.3.2.1 Input Terminal Descriptor */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200112struct uac_input_terminal_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400113 __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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200125#define UAC_DT_INPUT_TERMINAL_SIZE 12
Bryan Wuc47d7b02009-06-03 09:17:57 -0400126
Laurent Pinchart512ad272009-06-21 23:23:05 +0200127/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -0400135
136/* 4.3.2.2 Output Terminal Descriptor */
Daniel Mack28e1b772010-02-22 23:49:09 +0100137struct uac_output_terminal_descriptor_v1 {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400138 __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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200148#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
Bryan Wuc47d7b02009-06-03 09:17:57 -0400149
Laurent Pinchart512ad272009-06-21 23:23:05 +0200150/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -0400159
160/* Set bControlSize = 2 as default setting */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200161#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
Bryan Wuc47d7b02009-06-03 09:17:57 -0400162
163/* As above, but more useful for defining your own descriptors: */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200164#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
165struct uac_feature_unit_descriptor_##ch { \
Bryan Wuc47d7b02009-06-03 09:17:57 -0400166 __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 */
Daniel Mack28e1b772010-02-22 23:49:09 +0100177struct uac_as_header_descriptor_v1 {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400178 __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
Daniel Mack8fee4af2010-02-22 23:49:10 +0100186struct 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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200199#define UAC_DT_AS_HEADER_SIZE 7
Bryan Wuc47d7b02009-06-03 09:17:57 -0400200
Laurent Pinchart512ad272009-06-21 23:23:05 +0200201/* 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
Bryan Wuc47d7b02009-06-03 09:17:57 -0400208
Laurent Pinchart512ad272009-06-21 23:23:05 +0200209struct uac_format_type_i_continuous_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400210 __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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200222#define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
Bryan Wuc47d7b02009-06-03 09:17:57 -0400223
Laurent Pinchart512ad272009-06-21 23:23:05 +0200224struct uac_format_type_i_discrete_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400225 __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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200236#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
237struct uac_format_type_i_discrete_descriptor_##n { \
Bryan Wuc47d7b02009-06-03 09:17:57 -0400238 __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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200249#define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
Bryan Wuc47d7b02009-06-03 09:17:57 -0400250
Daniel Mack8fee4af2010-02-22 23:49:10 +0100251struct 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
Daniel Mack28e1b772010-02-22 23:49:09 +0100264/* Formats - Audio Data Format Type I Codes */
265
266struct 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
Daniel Mack8fee4af2010-02-22 23:49:10 +0100277struct 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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200289/* 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
Daniel Mack8fee4af2010-02-22 23:49:10 +0100294#define UAC_EXT_FORMAT_TYPE_I 0x81
295#define UAC_EXT_FORMAT_TYPE_II 0x82
296#define UAC_EXT_FORMAT_TYPE_III 0x83
Bryan Wuc47d7b02009-06-03 09:17:57 -0400297
Laurent Pinchart512ad272009-06-21 23:23:05 +0200298struct uac_iso_endpoint_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400299 __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};
Laurent Pinchart512ad272009-06-21 23:23:05 +0200306#define UAC_ISO_ENDPOINT_DESC_SIZE 7
Bryan Wuc47d7b02009-06-03 09:17:57 -0400307
Laurent Pinchart512ad272009-06-21 23:23:05 +0200308#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
Bryan Wuc47d7b02009-06-03 09:17:57 -0400311
Daniel Mack8fee4af2010-02-22 23:49:10 +0100312/* Audio class v2.0: CLOCK_SOURCE descriptor */
313
314struct 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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200325/* A.10.2 Feature Unit Control Selectors */
Daniel Mack28e1b772010-02-22 23:49:09 +0100326
327struct 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
Laurent Pinchart512ad272009-06-21 23:23:05 +0200337#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))
Bryan Wuc47d7b02009-06-03 09:17:57 -0400359
Michael S. Tsirkinc3501302009-07-29 14:23:25 +0300360#ifdef __KERNEL__
361
Bryan Wuc47d7b02009-06-03 09:17:57 -0400362struct 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
Bryan Wuc47d7b02009-06-03 09:17:57 -0400371struct 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
Michael S. Tsirkinc3501302009-07-29 14:23:25 +0300380#endif /* __KERNEL__ */
381
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500382#endif /* __LINUX_USB_AUDIO_H */