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