blob: eaf9dffe0a01bea235e5b4be98aa3d49b4120e59 [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
Laurent Pinchart512ad272009-06-21 23:23:05 +020028/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
29#define UAC_HEADER 0x01
30#define UAC_INPUT_TERMINAL 0x02
31#define UAC_OUTPUT_TERMINAL 0x03
32#define UAC_MIXER_UNIT 0x04
33#define UAC_SELECTOR_UNIT 0x05
34#define UAC_FEATURE_UNIT 0x06
35#define UAC_PROCESSING_UNIT 0x07
36#define UAC_EXTENSION_UNIT 0x08
Bryan Wuc47d7b02009-06-03 09:17:57 -040037
Laurent Pinchart512ad272009-06-21 23:23:05 +020038/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
39#define UAC_AS_GENERAL 0x01
40#define UAC_FORMAT_TYPE 0x02
41#define UAC_FORMAT_SPECIFIC 0x03
Bryan Wuc47d7b02009-06-03 09:17:57 -040042
Laurent Pinchart512ad272009-06-21 23:23:05 +020043/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
44#define UAC_EP_GENERAL 0x01
Bryan Wuc47d7b02009-06-03 09:17:57 -040045
Laurent Pinchart512ad272009-06-21 23:23:05 +020046/* A.9 Audio Class-Specific Request Codes */
47#define UAC_SET_ 0x00
48#define UAC_GET_ 0x80
Bryan Wuc47d7b02009-06-03 09:17:57 -040049
Laurent Pinchart512ad272009-06-21 23:23:05 +020050#define UAC__CUR 0x1
51#define UAC__MIN 0x2
52#define UAC__MAX 0x3
53#define UAC__RES 0x4
54#define UAC__MEM 0x5
Bryan Wuc47d7b02009-06-03 09:17:57 -040055
Laurent Pinchart512ad272009-06-21 23:23:05 +020056#define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
57#define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
58#define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
59#define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
60#define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
61#define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
62#define UAC_SET_RES (UAC_SET_ | UAC__RES)
63#define UAC_GET_RES (UAC_GET_ | UAC__RES)
64#define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
65#define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
Bryan Wuc47d7b02009-06-03 09:17:57 -040066
Laurent Pinchart512ad272009-06-21 23:23:05 +020067#define UAC_GET_STAT 0xff
Bryan Wuc47d7b02009-06-03 09:17:57 -040068
Laurent Pinchart512ad272009-06-21 23:23:05 +020069/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
70#define UAC_MS_HEADER 0x01
71#define UAC_MIDI_IN_JACK 0x02
72#define UAC_MIDI_OUT_JACK 0x03
Bryan Wuc47d7b02009-06-03 09:17:57 -040073
Laurent Pinchart512ad272009-06-21 23:23:05 +020074/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
75#define UAC_MS_GENERAL 0x01
Bryan Wuc47d7b02009-06-03 09:17:57 -040076
Laurent Pinchart512ad272009-06-21 23:23:05 +020077/* Terminals - 2.1 USB Terminal Types */
78#define UAC_TERMINAL_UNDEFINED 0x100
79#define UAC_TERMINAL_STREAMING 0x101
80#define UAC_TERMINAL_VENDOR_SPEC 0x1FF
Bryan Wuc47d7b02009-06-03 09:17:57 -040081
82/* Terminal Control Selectors */
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100083/* 4.3.2 Class-Specific AC Interface Descriptor */
Laurent Pinchart512ad272009-06-21 23:23:05 +020084struct uac_ac_header_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -040085 __u8 bLength; /* 8 + n */
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080086 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
Laurent Pinchart512ad272009-06-21 23:23:05 +020087 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080088 __le16 bcdADC; /* 0x0100 */
89 __le16 wTotalLength; /* includes Unit and Terminal desc. */
90 __u8 bInCollection; /* n */
91 __u8 baInterfaceNr[]; /* [n] */
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100092} __attribute__ ((packed));
93
Laurent Pinchart512ad272009-06-21 23:23:05 +020094#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100095
96/* As above, but more useful for defining your own descriptors: */
Laurent Pinchart512ad272009-06-21 23:23:05 +020097#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
98struct uac_ac_header_descriptor_##n { \
Ben Williamsonf2ebf92c2006-08-01 11:28:16 +100099 __u8 bLength; \
100 __u8 bDescriptorType; \
101 __u8 bDescriptorSubtype; \
102 __le16 bcdADC; \
103 __le16 wTotalLength; \
104 __u8 bInCollection; \
105 __u8 baInterfaceNr[n]; \
106} __attribute__ ((packed))
107
Bryan Wuc47d7b02009-06-03 09:17:57 -0400108/* 4.3.2.1 Input Terminal Descriptor */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200109struct uac_input_terminal_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400110 __u8 bLength; /* in bytes: 12 */
111 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
112 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
113 __u8 bTerminalID; /* Constant uniquely terminal ID */
114 __le16 wTerminalType; /* USB Audio Terminal Types */
115 __u8 bAssocTerminal; /* ID of the Output Terminal associated */
116 __u8 bNrChannels; /* Number of logical output channels */
117 __le16 wChannelConfig;
118 __u8 iChannelNames;
119 __u8 iTerminal;
120} __attribute__ ((packed));
121
Laurent Pinchart512ad272009-06-21 23:23:05 +0200122#define UAC_DT_INPUT_TERMINAL_SIZE 12
Bryan Wuc47d7b02009-06-03 09:17:57 -0400123
Laurent Pinchart512ad272009-06-21 23:23:05 +0200124/* Terminals - 2.2 Input Terminal Types */
125#define UAC_INPUT_TERMINAL_UNDEFINED 0x200
126#define UAC_INPUT_TERMINAL_MICROPHONE 0x201
127#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
128#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
129#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
130#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
131#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
Bryan Wuc47d7b02009-06-03 09:17:57 -0400132
133/* 4.3.2.2 Output Terminal Descriptor */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200134struct uac_output_terminal_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400135 __u8 bLength; /* in bytes: 9 */
136 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
137 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
138 __u8 bTerminalID; /* Constant uniquely terminal ID */
139 __le16 wTerminalType; /* USB Audio Terminal Types */
140 __u8 bAssocTerminal; /* ID of the Input Terminal associated */
141 __u8 bSourceID; /* ID of the connected Unit or Terminal*/
142 __u8 iTerminal;
143} __attribute__ ((packed));
144
Laurent Pinchart512ad272009-06-21 23:23:05 +0200145#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
Bryan Wuc47d7b02009-06-03 09:17:57 -0400146
Laurent Pinchart512ad272009-06-21 23:23:05 +0200147/* Terminals - 2.3 Output Terminal Types */
148#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
149#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
150#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
151#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
152#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
153#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
154#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
155#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
Bryan Wuc47d7b02009-06-03 09:17:57 -0400156
157/* Set bControlSize = 2 as default setting */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200158#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
Bryan Wuc47d7b02009-06-03 09:17:57 -0400159
160/* As above, but more useful for defining your own descriptors: */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200161#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
162struct uac_feature_unit_descriptor_##ch { \
Bryan Wuc47d7b02009-06-03 09:17:57 -0400163 __u8 bLength; \
164 __u8 bDescriptorType; \
165 __u8 bDescriptorSubtype; \
166 __u8 bUnitID; \
167 __u8 bSourceID; \
168 __u8 bControlSize; \
169 __le16 bmaControls[ch + 1]; \
170 __u8 iFeature; \
171} __attribute__ ((packed))
172
173/* 4.5.2 Class-Specific AS Interface Descriptor */
Laurent Pinchart512ad272009-06-21 23:23:05 +0200174struct uac_as_header_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400175 __u8 bLength; /* in bytes: 7 */
176 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
177 __u8 bDescriptorSubtype; /* AS_GENERAL */
178 __u8 bTerminalLink; /* Terminal ID of connected Terminal */
179 __u8 bDelay; /* Delay introduced by the data path */
180 __le16 wFormatTag; /* The Audio Data Format */
181} __attribute__ ((packed));
182
Laurent Pinchart512ad272009-06-21 23:23:05 +0200183#define UAC_DT_AS_HEADER_SIZE 7
Bryan Wuc47d7b02009-06-03 09:17:57 -0400184
Laurent Pinchart512ad272009-06-21 23:23:05 +0200185/* Formats - A.1.1 Audio Data Format Type I Codes */
186#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
187#define UAC_FORMAT_TYPE_I_PCM 0x1
188#define UAC_FORMAT_TYPE_I_PCM8 0x2
189#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
190#define UAC_FORMAT_TYPE_I_ALAW 0x4
191#define UAC_FORMAT_TYPE_I_MULAW 0x5
Bryan Wuc47d7b02009-06-03 09:17:57 -0400192
Laurent Pinchart512ad272009-06-21 23:23:05 +0200193struct uac_format_type_i_continuous_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400194 __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; /* */
200 __u8 bBitResolution;
201 __u8 bSamFreqType;
202 __u8 tLowerSamFreq[3];
203 __u8 tUpperSamFreq[3];
204} __attribute__ ((packed));
205
Laurent Pinchart512ad272009-06-21 23:23:05 +0200206#define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
Bryan Wuc47d7b02009-06-03 09:17:57 -0400207
Laurent Pinchart512ad272009-06-21 23:23:05 +0200208struct uac_format_type_i_discrete_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400209 __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; /* */
215 __u8 bBitResolution;
216 __u8 bSamFreqType;
217 __u8 tSamFreq[][3];
218} __attribute__ ((packed));
219
Laurent Pinchart512ad272009-06-21 23:23:05 +0200220#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
221struct uac_format_type_i_discrete_descriptor_##n { \
Bryan Wuc47d7b02009-06-03 09:17:57 -0400222 __u8 bLength; \
223 __u8 bDescriptorType; \
224 __u8 bDescriptorSubtype; \
225 __u8 bFormatType; \
226 __u8 bNrChannels; \
227 __u8 bSubframeSize; \
228 __u8 bBitResolution; \
229 __u8 bSamFreqType; \
230 __u8 tSamFreq[n][3]; \
231} __attribute__ ((packed))
232
Laurent Pinchart512ad272009-06-21 23:23:05 +0200233#define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
Bryan Wuc47d7b02009-06-03 09:17:57 -0400234
Laurent Pinchart512ad272009-06-21 23:23:05 +0200235/* Formats - A.2 Format Type Codes */
236#define UAC_FORMAT_TYPE_UNDEFINED 0x0
237#define UAC_FORMAT_TYPE_I 0x1
238#define UAC_FORMAT_TYPE_II 0x2
239#define UAC_FORMAT_TYPE_III 0x3
Bryan Wuc47d7b02009-06-03 09:17:57 -0400240
Laurent Pinchart512ad272009-06-21 23:23:05 +0200241struct uac_iso_endpoint_descriptor {
Bryan Wuc47d7b02009-06-03 09:17:57 -0400242 __u8 bLength; /* in bytes: 7 */
243 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
244 __u8 bDescriptorSubtype; /* EP_GENERAL */
245 __u8 bmAttributes;
246 __u8 bLockDelayUnits;
247 __le16 wLockDelay;
248};
Laurent Pinchart512ad272009-06-21 23:23:05 +0200249#define UAC_ISO_ENDPOINT_DESC_SIZE 7
Bryan Wuc47d7b02009-06-03 09:17:57 -0400250
Laurent Pinchart512ad272009-06-21 23:23:05 +0200251#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
252#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
253#define UAC_EP_CS_ATTR_FILL_MAX 0x80
Bryan Wuc47d7b02009-06-03 09:17:57 -0400254
Laurent Pinchart512ad272009-06-21 23:23:05 +0200255/* A.10.2 Feature Unit Control Selectors */
256#define UAC_FU_CONTROL_UNDEFINED 0x00
257#define UAC_MUTE_CONTROL 0x01
258#define UAC_VOLUME_CONTROL 0x02
259#define UAC_BASS_CONTROL 0x03
260#define UAC_MID_CONTROL 0x04
261#define UAC_TREBLE_CONTROL 0x05
262#define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06
263#define UAC_AUTOMATIC_GAIN_CONTROL 0x07
264#define UAC_DELAY_CONTROL 0x08
265#define UAC_BASS_BOOST_CONTROL 0x09
266#define UAC_LOUDNESS_CONTROL 0x0a
267
268#define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1))
269#define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1))
270#define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1))
271#define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1))
272#define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1))
273#define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
274#define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
275#define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1))
276#define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1))
277#define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1))
Bryan Wuc47d7b02009-06-03 09:17:57 -0400278
Michael S. Tsirkinc3501302009-07-29 14:23:25 +0300279#ifdef __KERNEL__
280
Bryan Wuc47d7b02009-06-03 09:17:57 -0400281struct usb_audio_control {
282 struct list_head list;
283 const char *name;
284 u8 type;
285 int data[5];
286 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
287 int (*get)(struct usb_audio_control *con, u8 cmd);
288};
289
Bryan Wuc47d7b02009-06-03 09:17:57 -0400290struct usb_audio_control_selector {
291 struct list_head list;
292 struct list_head control;
293 u8 id;
294 const char *name;
295 u8 type;
296 struct usb_descriptor_header *desc;
297};
298
Michael S. Tsirkinc3501302009-07-29 14:23:25 +0300299#endif /* __KERNEL__ */
300
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500301#endif /* __LINUX_USB_AUDIO_H */