]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/usb/audio.h
USB: Move endpoint sync type definitions from usb/audio.h to usb/ch9.h
[net-next-2.6.git] / include / linux / usb / audio.h
CommitLineData
f2ebf92c
BW
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
c47d7b09 27#define USB_SUBCLASS_VENDOR_SPEC 0xff
f2ebf92c 28
c47d7b09
BW
29/* A.5 Audio Class-Specific AC interface Descriptor Subtypes*/
30#define HEADER 0x01
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
38
39#define AS_GENERAL 0x01
40#define FORMAT_TYPE 0x02
41#define FORMAT_SPECIFIC 0x03
42
43#define EP_GENERAL 0x01
44
45#define MS_GENERAL 0x01
46#define MIDI_IN_JACK 0x02
47#define MIDI_OUT_JACK 0x03
48
c47d7b09
BW
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
53
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
59
60#define SET_ 0x00
61#define GET_ 0x80
62
63#define _CUR 0x1
64#define _MIN 0x2
65#define _MAX 0x3
66#define _RES 0x4
67#define _MEM 0x5
68
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)
79
80#define GET_STAT 0xff
81
82#define USB_AC_TERMINAL_UNDEFINED 0x100
83#define USB_AC_TERMINAL_STREAMING 0x101
84#define USB_AC_TERMINAL_VENDOR_SPEC 0x1FF
85
86/* Terminal Control Selectors */
f2ebf92c
BW
87/* 4.3.2 Class-Specific AC Interface Descriptor */
88struct usb_ac_header_descriptor {
c47d7b09 89 __u8 bLength; /* 8 + n */
41dceed5
GKH
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] */
f2ebf92c
BW
96} __attribute__ ((packed));
97
c47d7b09 98#define USB_DT_AC_HEADER_SIZE(n) (8 + (n))
f2ebf92c
BW
99
100/* As above, but more useful for defining your own descriptors: */
101#define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \
102struct usb_ac_header_descriptor_##n { \
103 __u8 bLength; \
104 __u8 bDescriptorType; \
105 __u8 bDescriptorSubtype; \
106 __le16 bcdADC; \
107 __le16 wTotalLength; \
108 __u8 bInCollection; \
109 __u8 baInterfaceNr[n]; \
110} __attribute__ ((packed))
111
c47d7b09
BW
112/* 4.3.2.1 Input Terminal Descriptor */
113struct 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;
122 __u8 iChannelNames;
123 __u8 iTerminal;
124} __attribute__ ((packed));
125
126#define USB_DT_AC_INPUT_TERMINAL_SIZE 12
127
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
135
136/* 4.3.2.2 Output Terminal Descriptor */
137struct 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*/
145 __u8 iTerminal;
146} __attribute__ ((packed));
147
148#define USB_DT_AC_OUTPUT_TERMINAL_SIZE 9
149
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
158
159/* Set bControlSize = 2 as default setting */
160#define USB_DT_AC_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
161
162/* As above, but more useful for defining your own descriptors: */
163#define DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(ch) \
164struct usb_ac_feature_unit_descriptor_##ch { \
165 __u8 bLength; \
166 __u8 bDescriptorType; \
167 __u8 bDescriptorSubtype; \
168 __u8 bUnitID; \
169 __u8 bSourceID; \
170 __u8 bControlSize; \
171 __le16 bmaControls[ch + 1]; \
172 __u8 iFeature; \
173} __attribute__ ((packed))
174
175/* 4.5.2 Class-Specific AS Interface Descriptor */
176struct 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));
184
185#define USB_DT_AS_HEADER_SIZE 7
186
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
193
194struct 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; /* */
201 __u8 bBitResolution;
202 __u8 bSamFreqType;
203 __u8 tLowerSamFreq[3];
204 __u8 tUpperSamFreq[3];
205} __attribute__ ((packed));
206
207#define USB_AS_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
208
209struct 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; /* */
216 __u8 bBitResolution;
217 __u8 bSamFreqType;
218 __u8 tSamFreq[][3];
219} __attribute__ ((packed));
220
221#define DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(n) \
222struct usb_as_formate_type_i_discrete_descriptor_##n { \
223 __u8 bLength; \
224 __u8 bDescriptorType; \
225 __u8 bDescriptorSubtype; \
226 __u8 bFormatType; \
227 __u8 bNrChannels; \
228 __u8 bSubframeSize; \
229 __u8 bBitResolution; \
230 __u8 bSamFreqType; \
231 __u8 tSamFreq[n][3]; \
232} __attribute__ ((packed))
233
234#define USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
235
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
240
c47d7b09
BW
241struct usb_as_iso_endpoint_descriptor {
242 __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};
249#define USB_AS_ISO_ENDPOINT_DESC_SIZE 7
250
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
262
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))
273
274struct usb_audio_control {
275 struct list_head list;
276 const char *name;
277 u8 type;
278 int data[5];
279 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
280 int (*get)(struct usb_audio_control *con, u8 cmd);
281};
282
283static inline int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
284{
285 con->data[cmd] = value;
286
287 return 0;
288}
289
290static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
291{
292 return con->data[cmd];
293}
294
295struct usb_audio_control_selector {
296 struct list_head list;
297 struct list_head control;
298 u8 id;
299 const char *name;
300 u8 type;
301 struct usb_descriptor_header *desc;
302};
303
dda43a0e 304#endif /* __LINUX_USB_AUDIO_H */