aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/usb/audio.h265
1 files changed, 263 insertions, 2 deletions
diff --git a/include/linux/usb/audio.h b/include/linux/usb/audio.h
index 8cb025fef63..b5744bc218a 100644
--- a/include/linux/usb/audio.h
+++ b/include/linux/usb/audio.h
@@ -24,10 +24,75 @@
24#define USB_SUBCLASS_AUDIOCONTROL 0x01 24#define USB_SUBCLASS_AUDIOCONTROL 0x01
25#define USB_SUBCLASS_AUDIOSTREAMING 0x02 25#define USB_SUBCLASS_AUDIOSTREAMING 0x02
26#define USB_SUBCLASS_MIDISTREAMING 0x03 26#define USB_SUBCLASS_MIDISTREAMING 0x03
27#define USB_SUBCLASS_VENDOR_SPEC 0xff
27 28
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
49/* endpoint attributes */
50#define EP_ATTR_MASK 0x0c
51#define EP_ATTR_ASYNC 0x04
52#define EP_ATTR_ADAPTIVE 0x08
53#define EP_ATTR_SYNC 0x0c
54
55/* cs endpoint attributes */
56#define EP_CS_ATTR_SAMPLE_RATE 0x01
57#define EP_CS_ATTR_PITCH_CONTROL 0x02
58#define EP_CS_ATTR_FILL_MAX 0x80
59
60/* Audio Class specific Request Codes */
61#define USB_AUDIO_SET_INTF 0x21
62#define USB_AUDIO_SET_ENDPOINT 0x22
63#define USB_AUDIO_GET_INTF 0xa1
64#define USB_AUDIO_GET_ENDPOINT 0xa2
65
66#define SET_ 0x00
67#define GET_ 0x80
68
69#define _CUR 0x1
70#define _MIN 0x2
71#define _MAX 0x3
72#define _RES 0x4
73#define _MEM 0x5
74
75#define SET_CUR (SET_ | _CUR)
76#define GET_CUR (GET_ | _CUR)
77#define SET_MIN (SET_ | _MIN)
78#define GET_MIN (GET_ | _MIN)
79#define SET_MAX (SET_ | _MAX)
80#define GET_MAX (GET_ | _MAX)
81#define SET_RES (SET_ | _RES)
82#define GET_RES (GET_ | _RES)
83#define SET_MEM (SET_ | _MEM)
84#define GET_MEM (GET_ | _MEM)
85
86#define GET_STAT 0xff
87
88#define USB_AC_TERMINAL_UNDEFINED 0x100
89#define USB_AC_TERMINAL_STREAMING 0x101
90#define USB_AC_TERMINAL_VENDOR_SPEC 0x1FF
91
92/* Terminal Control Selectors */
28/* 4.3.2 Class-Specific AC Interface Descriptor */ 93/* 4.3.2 Class-Specific AC Interface Descriptor */
29struct usb_ac_header_descriptor { 94struct usb_ac_header_descriptor {
30 __u8 bLength; /* 8+n */ 95 __u8 bLength; /* 8 + n */
31 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 96 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
32 __u8 bDescriptorSubtype; /* USB_MS_HEADER */ 97 __u8 bDescriptorSubtype; /* USB_MS_HEADER */
33 __le16 bcdADC; /* 0x0100 */ 98 __le16 bcdADC; /* 0x0100 */
@@ -36,7 +101,7 @@ struct usb_ac_header_descriptor {
36 __u8 baInterfaceNr[]; /* [n] */ 101 __u8 baInterfaceNr[]; /* [n] */
37} __attribute__ ((packed)); 102} __attribute__ ((packed));
38 103
39#define USB_DT_AC_HEADER_SIZE(n) (8+(n)) 104#define USB_DT_AC_HEADER_SIZE(n) (8 + (n))
40 105
41/* As above, but more useful for defining your own descriptors: */ 106/* As above, but more useful for defining your own descriptors: */
42#define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \ 107#define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \
@@ -50,4 +115,200 @@ struct usb_ac_header_descriptor_##n { \
50 __u8 baInterfaceNr[n]; \ 115 __u8 baInterfaceNr[n]; \
51} __attribute__ ((packed)) 116} __attribute__ ((packed))
52 117
118/* 4.3.2.1 Input Terminal Descriptor */
119struct usb_input_terminal_descriptor {
120 __u8 bLength; /* in bytes: 12 */
121 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
122 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
123 __u8 bTerminalID; /* Constant uniquely terminal ID */
124 __le16 wTerminalType; /* USB Audio Terminal Types */
125 __u8 bAssocTerminal; /* ID of the Output Terminal associated */
126 __u8 bNrChannels; /* Number of logical output channels */
127 __le16 wChannelConfig;
128 __u8 iChannelNames;
129 __u8 iTerminal;
130} __attribute__ ((packed));
131
132#define USB_DT_AC_INPUT_TERMINAL_SIZE 12
133
134#define USB_AC_INPUT_TERMINAL_UNDEFINED 0x200
135#define USB_AC_INPUT_TERMINAL_MICROPHONE 0x201
136#define USB_AC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
137#define USB_AC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
138#define USB_AC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
139#define USB_AC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
140#define USB_AC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
141
142/* 4.3.2.2 Output Terminal Descriptor */
143struct usb_output_terminal_descriptor {
144 __u8 bLength; /* in bytes: 9 */
145 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
146 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
147 __u8 bTerminalID; /* Constant uniquely terminal ID */
148 __le16 wTerminalType; /* USB Audio Terminal Types */
149 __u8 bAssocTerminal; /* ID of the Input Terminal associated */
150 __u8 bSourceID; /* ID of the connected Unit or Terminal*/
151 __u8 iTerminal;
152} __attribute__ ((packed));
153
154#define USB_DT_AC_OUTPUT_TERMINAL_SIZE 9
155
156#define USB_AC_OUTPUT_TERMINAL_UNDEFINED 0x300
157#define USB_AC_OUTPUT_TERMINAL_SPEAKER 0x301
158#define USB_AC_OUTPUT_TERMINAL_HEADPHONES 0x302
159#define USB_AC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
160#define USB_AC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
161#define USB_AC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
162#define USB_AC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
163#define USB_AC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
164
165/* Set bControlSize = 2 as default setting */
166#define USB_DT_AC_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
167
168/* As above, but more useful for defining your own descriptors: */
169#define DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(ch) \
170struct usb_ac_feature_unit_descriptor_##ch { \
171 __u8 bLength; \
172 __u8 bDescriptorType; \
173 __u8 bDescriptorSubtype; \
174 __u8 bUnitID; \
175 __u8 bSourceID; \
176 __u8 bControlSize; \
177 __le16 bmaControls[ch + 1]; \
178 __u8 iFeature; \
179} __attribute__ ((packed))
180
181/* 4.5.2 Class-Specific AS Interface Descriptor */
182struct usb_as_header_descriptor {
183 __u8 bLength; /* in bytes: 7 */
184 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
185 __u8 bDescriptorSubtype; /* AS_GENERAL */
186 __u8 bTerminalLink; /* Terminal ID of connected Terminal */
187 __u8 bDelay; /* Delay introduced by the data path */
188 __le16 wFormatTag; /* The Audio Data Format */
189} __attribute__ ((packed));
190
191#define USB_DT_AS_HEADER_SIZE 7
192
193#define USB_AS_AUDIO_FORMAT_TYPE_I_UNDEFINED 0x0
194#define USB_AS_AUDIO_FORMAT_TYPE_I_PCM 0x1
195#define USB_AS_AUDIO_FORMAT_TYPE_I_PCM8 0x2
196#define USB_AS_AUDIO_FORMAT_TYPE_I_IEEE_FLOAT 0x3
197#define USB_AS_AUDIO_FORMAT_TYPE_I_ALAW 0x4
198#define USB_AS_AUDIO_FORMAT_TYPE_I_MULAW 0x5
199
200struct usb_as_format_type_i_continuous_descriptor {
201 __u8 bLength; /* in bytes: 8 + (ns * 3) */
202 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
203 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
204 __u8 bFormatType; /* FORMAT_TYPE_1 */
205 __u8 bNrChannels; /* physical channels in the stream */
206 __u8 bSubframeSize; /* */
207 __u8 bBitResolution;
208 __u8 bSamFreqType;
209 __u8 tLowerSamFreq[3];
210 __u8 tUpperSamFreq[3];
211} __attribute__ ((packed));
212
213#define USB_AS_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
214
215struct usb_as_formate_type_i_discrete_descriptor {
216 __u8 bLength; /* in bytes: 8 + (ns * 3) */
217 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
218 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
219 __u8 bFormatType; /* FORMAT_TYPE_1 */
220 __u8 bNrChannels; /* physical channels in the stream */
221 __u8 bSubframeSize; /* */
222 __u8 bBitResolution;
223 __u8 bSamFreqType;
224 __u8 tSamFreq[][3];
225} __attribute__ ((packed));
226
227#define DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(n) \
228struct usb_as_formate_type_i_discrete_descriptor_##n { \
229 __u8 bLength; \
230 __u8 bDescriptorType; \
231 __u8 bDescriptorSubtype; \
232 __u8 bFormatType; \
233 __u8 bNrChannels; \
234 __u8 bSubframeSize; \
235 __u8 bBitResolution; \
236 __u8 bSamFreqType; \
237 __u8 tSamFreq[n][3]; \
238} __attribute__ ((packed))
239
240#define USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
241
242#define USB_AS_FORMAT_TYPE_UNDEFINED 0x0
243#define USB_AS_FORMAT_TYPE_I 0x1
244#define USB_AS_FORMAT_TYPE_II 0x2
245#define USB_AS_FORMAT_TYPE_III 0x3
246
247#define USB_AS_ENDPOINT_ASYNC (1 << 2)
248#define USB_AS_ENDPOINT_ADAPTIVE (2 << 2)
249#define USB_AS_ENDPOINT_SYNC (3 << 2)
250
251struct usb_as_iso_endpoint_descriptor {
252 __u8 bLength; /* in bytes: 7 */
253 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
254 __u8 bDescriptorSubtype; /* EP_GENERAL */
255 __u8 bmAttributes;
256 __u8 bLockDelayUnits;
257 __le16 wLockDelay;
258};
259#define USB_AS_ISO_ENDPOINT_DESC_SIZE 7
260
261#define FU_CONTROL_UNDEFINED 0x00
262#define MUTE_CONTROL 0x01
263#define VOLUME_CONTROL 0x02
264#define BASS_CONTROL 0x03
265#define MID_CONTROL 0x04
266#define TREBLE_CONTROL 0x05
267#define GRAPHIC_EQUALIZER_CONTROL 0x06
268#define AUTOMATIC_GAIN_CONTROL 0x07
269#define DELAY_CONTROL 0x08
270#define BASS_BOOST_CONTROL 0x09
271#define LOUDNESS_CONTROL 0x0a
272
273#define FU_MUTE (1 << (MUTE_CONTROL - 1))
274#define FU_VOLUME (1 << (VOLUME_CONTROL - 1))
275#define FU_BASS (1 << (BASS_CONTROL - 1))
276#define FU_MID (1 << (MID_CONTROL - 1))
277#define FU_TREBLE (1 << (TREBLE_CONTROL - 1))
278#define FU_GRAPHIC_EQ (1 << (GRAPHIC_EQUALIZER_CONTROL - 1))
279#define FU_AUTO_GAIN (1 << (AUTOMATIC_GAIN_CONTROL - 1))
280#define FU_DELAY (1 << (DELAY_CONTROL - 1))
281#define FU_BASS_BOOST (1 << (BASS_BOOST_CONTROL - 1))
282#define FU_LOUDNESS (1 << (LOUDNESS_CONTROL - 1))
283
284struct usb_audio_control {
285 struct list_head list;
286 const char *name;
287 u8 type;
288 int data[5];
289 int (*set)(struct usb_audio_control *con, u8 cmd, int value);
290 int (*get)(struct usb_audio_control *con, u8 cmd);
291};
292
293static inline int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
294{
295 con->data[cmd] = value;
296
297 return 0;
298}
299
300static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
301{
302 return con->data[cmd];
303}
304
305struct usb_audio_control_selector {
306 struct list_head list;
307 struct list_head control;
308 u8 id;
309 const char *name;
310 u8 type;
311 struct usb_descriptor_header *desc;
312};
313
53#endif /* __LINUX_USB_AUDIO_H */ 314#endif /* __LINUX_USB_AUDIO_H */