usb4bsd: Bring in FreeBSD's uaudio driver.
[dragonfly.git] / sys / bus / u4b / audio / uaudioreg.h
1 /*      $NetBSD: uaudioreg.h,v 1.12 2004/11/05 19:08:29 kent Exp $      */
2 /* $FreeBSD$ */
3
4 /*-
5  * Copyright (c) 1999 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net) at
10  * Carlstedt Research & Technology.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #define UAUDIO_VERSION          0x100
35
36 #define UDESC_CS_CONFIG         0x22
37 #define UDESC_CS_STRING         0x23
38 #define UDESC_CS_INTERFACE      0x24
39 #define UDESC_CS_ENDPOINT       0x25
40
41 #define UDESCSUB_AC_HEADER      1
42 #define UDESCSUB_AC_INPUT       2
43 #define UDESCSUB_AC_OUTPUT      3
44 #define UDESCSUB_AC_MIXER       4
45 #define UDESCSUB_AC_SELECTOR    5
46 #define UDESCSUB_AC_FEATURE     6
47 #define UDESCSUB_AC_PROCESSING  7
48 #define UDESCSUB_AC_EXTENSION   8
49
50 /* These macros check if the endpoint descriptor has additional fields */
51 #define UEP_MINSIZE     7
52 #define UEP_HAS_REFRESH(ep)     ((ep)->bLength >= 8)
53 #define UEP_HAS_SYNCADDR(ep)    ((ep)->bLength >= 9)
54
55 /* The first fields are identical to struct usb_endpoint_descriptor */
56 typedef struct {
57         uByte   bLength;
58         uByte   bDescriptorType;
59         uByte   bEndpointAddress;
60         uByte   bmAttributes;
61         uWord   wMaxPacketSize;
62         uByte   bInterval;
63         /*
64          * The following two entries are only used by the Audio Class.
65          * And according to the specs the Audio Class is the only one
66          * allowed to extend the endpoint descriptor.
67          * Who knows what goes on in the minds of the people in the USB
68          * standardization?  :-(
69          */
70         uByte   bRefresh;
71         uByte   bSynchAddress;
72 } __packed usb_endpoint_descriptor_audio_t;
73
74 struct usb_audio_control_descriptor {
75         uByte   bLength;
76         uByte   bDescriptorType;
77         uByte   bDescriptorSubtype;
78         uWord   bcdADC;
79         uWord   wTotalLength;
80         uByte   bInCollection;
81         uByte   baInterfaceNr[1];
82 } __packed;
83
84 struct usb_audio_streaming_interface_descriptor {
85         uByte   bLength;
86         uByte   bDescriptorType;
87         uByte   bDescriptorSubtype;
88         uByte   bTerminalLink;
89         uByte   bDelay;
90         uWord   wFormatTag;
91 } __packed;
92
93 struct usb_audio_streaming_endpoint_descriptor {
94         uByte   bLength;
95         uByte   bDescriptorType;
96         uByte   bDescriptorSubtype;
97         uByte   bmAttributes;
98 #define UA_SED_FREQ_CONTROL     0x01
99 #define UA_SED_PITCH_CONTROL    0x02
100 #define UA_SED_MAXPACKETSONLY   0x80
101         uByte   bLockDelayUnits;
102         uWord   wLockDelay;
103 } __packed;
104
105 struct usb_audio_streaming_type1_descriptor {
106         uByte   bLength;
107         uByte   bDescriptorType;
108         uByte   bDescriptorSubtype;
109         uByte   bFormatType;
110         uByte   bNrChannels;
111         uByte   bSubFrameSize;
112         uByte   bBitResolution;
113         uByte   bSamFreqType;
114 #define UA_SAMP_CONTNUOUS 0
115         uByte   tSamFreq[0];
116 #define UA_GETSAMP(p, n) (((p)->tSamFreq[((n)*3)+0]) |      \
117                           ((p)->tSamFreq[((n)*3)+1] << 8) | \
118                           ((p)->tSamFreq[((n)*3)+2] << 16))
119 #define UA_SAMP_LO(p) UA_GETSAMP(p, 0)
120 #define UA_SAMP_HI(p) UA_GETSAMP(p, 1)
121 } __packed;
122
123 struct usb_audio_cluster {
124         uByte   bNrChannels;
125         uWord   wChannelConfig;
126 #define UA_CHANNEL_LEFT         0x0001
127 #define UA_CHANNEL_RIGHT        0x0002
128 #define UA_CHANNEL_CENTER       0x0004
129 #define UA_CHANNEL_LFE          0x0008
130 #define UA_CHANNEL_L_SURROUND   0x0010
131 #define UA_CHANNEL_R_SURROUND   0x0020
132 #define UA_CHANNEL_L_CENTER     0x0040
133 #define UA_CHANNEL_R_CENTER     0x0080
134 #define UA_CHANNEL_SURROUND     0x0100
135 #define UA_CHANNEL_L_SIDE       0x0200
136 #define UA_CHANNEL_R_SIDE       0x0400
137 #define UA_CHANNEL_TOP          0x0800
138         uByte   iChannelNames;
139 } __packed;
140
141 /* Shared by all units and terminals */
142 struct usb_audio_unit {
143         uByte   bLength;
144         uByte   bDescriptorType;
145         uByte   bDescriptorSubtype;
146         uByte   bUnitId;
147 };
148
149 /* UDESCSUB_AC_INPUT */
150 struct usb_audio_input_terminal {
151         uByte   bLength;
152         uByte   bDescriptorType;
153         uByte   bDescriptorSubtype;
154         uByte   bTerminalId;
155         uWord   wTerminalType;
156         uByte   bAssocTerminal;
157         uByte   bNrChannels;
158         uWord   wChannelConfig;
159         uByte   iChannelNames;
160 /*      uByte           iTerminal; */
161 } __packed;
162
163 /* UDESCSUB_AC_OUTPUT */
164 struct usb_audio_output_terminal {
165         uByte   bLength;
166         uByte   bDescriptorType;
167         uByte   bDescriptorSubtype;
168         uByte   bTerminalId;
169         uWord   wTerminalType;
170         uByte   bAssocTerminal;
171         uByte   bSourceId;
172         uByte   iTerminal;
173 } __packed;
174
175 /* UDESCSUB_AC_MIXER */
176 struct usb_audio_mixer_unit_0 {
177         uByte   bLength;
178         uByte   bDescriptorType;
179         uByte   bDescriptorSubtype;
180         uByte   bUnitId;
181         uByte   bNrInPins;
182         uByte   baSourceId[0];          /* [bNrInPins] */
183         /* struct usb_audio_mixer_unit_1 */
184 } __packed;
185 struct usb_audio_mixer_unit_1 {
186         uByte   bNrChannels;
187         uWord   wChannelConfig;
188         uByte   iChannelNames;
189         uByte   bmControls[0];          /* [see source code] */
190         /* uByte                iMixer; */
191 } __packed;
192
193 /* UDESCSUB_AC_SELECTOR */
194 struct usb_audio_selector_unit {
195         uByte   bLength;
196         uByte   bDescriptorType;
197         uByte   bDescriptorSubtype;
198         uByte   bUnitId;
199         uByte   bNrInPins;
200         uByte   baSourceId[0];          /* [bNrInPins] */
201         /* uByte        iSelector; */
202 } __packed;
203
204 /* UDESCSUB_AC_FEATURE */
205 struct usb_audio_feature_unit {
206         uByte   bLength;
207         uByte   bDescriptorType;
208         uByte   bDescriptorSubtype;
209         uByte   bUnitId;
210         uByte   bSourceId;
211         uByte   bControlSize;
212         uByte   bmaControls[0];         /* [bControlSize * x] */
213         /* uByte        iFeature; */
214 } __packed;
215
216 /* UDESCSUB_AC_PROCESSING */
217 struct usb_audio_processing_unit_0 {
218         uByte   bLength;
219         uByte   bDescriptorType;
220         uByte   bDescriptorSubtype;
221         uByte   bUnitId;
222         uWord   wProcessType;
223         uByte   bNrInPins;
224         uByte   baSourceId[0];          /* [bNrInPins] */
225         /* struct usb_audio_processing_unit_1 */
226 } __packed;
227 struct usb_audio_processing_unit_1 {
228         uByte   bNrChannels;
229         uWord   wChannelConfig;
230         uByte   iChannelNames;
231         uByte   bControlSize;
232         uByte   bmControls[0];          /* [bControlSize] */
233 #define UA_PROC_ENABLE_MASK 1
234 } __packed;
235
236 struct usb_audio_processing_unit_updown {
237         uByte   iProcessing;
238         uByte   bNrModes;
239         uWord   waModes[0];             /* [bNrModes] */
240 } __packed;
241
242 /* UDESCSUB_AC_EXTENSION */
243 struct usb_audio_extension_unit_0 {
244         uByte   bLength;
245         uByte   bDescriptorType;
246         uByte   bDescriptorSubtype;
247         uByte   bUnitId;
248         uWord   wExtensionCode;
249         uByte   bNrInPins;
250         uByte   baSourceId[0];          /* [bNrInPins] */
251         /* struct usb_audio_extension_unit_1 */
252 } __packed;
253 struct usb_audio_extension_unit_1 {
254         uByte   bNrChannels;
255         uWord   wChannelConfig;
256         uByte   iChannelNames;
257         uByte   bControlSize;
258         uByte   bmControls[0];          /* [bControlSize] */
259 #define UA_EXT_ENABLE_MASK 1
260 #define UA_EXT_ENABLE 1
261         /* uByte                iExtension; */
262 } __packed;
263
264 /* USB terminal types */
265 #define UAT_UNDEFINED           0x0100
266 #define UAT_STREAM              0x0101
267 #define UAT_VENDOR              0x01ff
268 /* input terminal types */
269 #define UATI_UNDEFINED          0x0200
270 #define UATI_MICROPHONE         0x0201
271 #define UATI_DESKMICROPHONE     0x0202
272 #define UATI_PERSONALMICROPHONE 0x0203
273 #define UATI_OMNIMICROPHONE     0x0204
274 #define UATI_MICROPHONEARRAY    0x0205
275 #define UATI_PROCMICROPHONEARR  0x0206
276 /* output terminal types */
277 #define UATO_UNDEFINED          0x0300
278 #define UATO_SPEAKER            0x0301
279 #define UATO_HEADPHONES         0x0302
280 #define UATO_DISPLAYAUDIO       0x0303
281 #define UATO_DESKTOPSPEAKER     0x0304
282 #define UATO_ROOMSPEAKER        0x0305
283 #define UATO_COMMSPEAKER        0x0306
284 #define UATO_SUBWOOFER          0x0307
285 /* bidir terminal types */
286 #define UATB_UNDEFINED          0x0400
287 #define UATB_HANDSET            0x0401
288 #define UATB_HEADSET            0x0402
289 #define UATB_SPEAKERPHONE       0x0403
290 #define UATB_SPEAKERPHONEESUP   0x0404
291 #define UATB_SPEAKERPHONEECANC  0x0405
292 /* telephony terminal types */
293 #define UATT_UNDEFINED          0x0500
294 #define UATT_PHONELINE          0x0501
295 #define UATT_TELEPHONE          0x0502
296 #define UATT_DOWNLINEPHONE      0x0503
297 /* external terminal types */
298 #define UATE_UNDEFINED          0x0600
299 #define UATE_ANALOGCONN         0x0601
300 #define UATE_DIGITALAUIFC       0x0602
301 #define UATE_LINECONN           0x0603
302 #define UATE_LEGACYCONN         0x0604
303 #define UATE_SPDIF              0x0605
304 #define UATE_1394DA             0x0606
305 #define UATE_1394DV             0x0607
306 /* embedded function terminal types */
307 #define UATF_UNDEFINED          0x0700
308 #define UATF_CALIBNOISE         0x0701
309 #define UATF_EQUNOISE           0x0702
310 #define UATF_CDPLAYER           0x0703
311 #define UATF_DAT                0x0704
312 #define UATF_DCC                0x0705
313 #define UATF_MINIDISK           0x0706
314 #define UATF_ANALOGTAPE         0x0707
315 #define UATF_PHONOGRAPH         0x0708
316 #define UATF_VCRAUDIO           0x0709
317 #define UATF_VIDEODISCAUDIO     0x070a
318 #define UATF_DVDAUDIO           0x070b
319 #define UATF_TVTUNERAUDIO       0x070c
320 #define UATF_SATELLITE          0x070d
321 #define UATF_CABLETUNER         0x070e
322 #define UATF_DSS                0x070f
323 #define UATF_RADIORECV          0x0710
324 #define UATF_RADIOXMIT          0x0711
325 #define UATF_MULTITRACK         0x0712
326 #define UATF_SYNTHESIZER        0x0713
327
328
329 #define SET_CUR 0x01
330 #define GET_CUR 0x81
331 #define SET_MIN 0x02
332 #define GET_MIN 0x82
333 #define SET_MAX 0x03
334 #define GET_MAX 0x83
335 #define SET_RES 0x04
336 #define GET_RES 0x84
337 #define SET_MEM 0x05
338 #define GET_MEM 0x85
339 #define GET_STAT 0xff
340
341 #define MUTE_CONTROL    0x01
342 #define VOLUME_CONTROL  0x02
343 #define BASS_CONTROL    0x03
344 #define MID_CONTROL     0x04
345 #define TREBLE_CONTROL  0x05
346 #define GRAPHIC_EQUALIZER_CONTROL       0x06
347 #define AGC_CONTROL     0x07
348 #define DELAY_CONTROL   0x08
349 #define BASS_BOOST_CONTROL 0x09
350 #define LOUDNESS_CONTROL 0x0a
351
352 #define FU_MASK(u) (1 << ((u)-1))
353
354 #define MASTER_CHAN     0
355
356 #define AS_GENERAL      1
357 #define FORMAT_TYPE     2
358 #define FORMAT_SPECIFIC 3
359
360 #define UA_FMT_PCM      1
361 #define UA_FMT_PCM8     2
362 #define UA_FMT_IEEE_FLOAT 3
363 #define UA_FMT_ALAW     4
364 #define UA_FMT_MULAW    5
365 #define UA_FMT_MPEG     0x1001
366 #define UA_FMT_AC3      0x1002
367
368 #define SAMPLING_FREQ_CONTROL   0x01
369 #define PITCH_CONTROL           0x02
370
371 #define FORMAT_TYPE_UNDEFINED 0
372 #define FORMAT_TYPE_I 1
373 #define FORMAT_TYPE_II 2
374 #define FORMAT_TYPE_III 3
375
376 #define UA_PROC_MASK(n) (1<< ((n)-1))
377 #define PROCESS_UNDEFINED               0
378 #define XX_ENABLE_CONTROL                       1
379 #define UPDOWNMIX_PROCESS               1
380 #define UD_ENABLE_CONTROL                       1
381 #define UD_MODE_SELECT_CONTROL                  2
382 #define DOLBY_PROLOGIC_PROCESS          2
383 #define DP_ENABLE_CONTROL                       1
384 #define DP_MODE_SELECT_CONTROL                  2
385 #define P3D_STEREO_EXTENDER_PROCESS     3
386 #define P3D_ENABLE_CONTROL                      1
387 #define P3D_SPACIOUSNESS_CONTROL                2
388 #define REVERBATION_PROCESS             4
389 #define RV_ENABLE_CONTROL                       1
390 #define RV_LEVEL_CONTROL                        2
391 #define RV_TIME_CONTROL                 3
392 #define RV_FEEDBACK_CONTROL                     4
393 #define CHORUS_PROCESS                  5
394 #define CH_ENABLE_CONTROL                       1
395 #define CH_LEVEL_CONTROL                        2
396 #define CH_RATE_CONTROL                 3
397 #define CH_DEPTH_CONTROL                        4
398 #define DYN_RANGE_COMP_PROCESS          6
399 #define DR_ENABLE_CONTROL                       1
400 #define DR_COMPRESSION_RATE_CONTROL             2
401 #define DR_MAXAMPL_CONTROL                      3
402 #define DR_THRESHOLD_CONTROL                    4
403 #define DR_ATTACK_TIME_CONTROL                  5
404 #define DR_RELEASE_TIME_CONTROL         6