at v2.6.34 409 lines 13 kB view raw
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 27 28#define UAC_VERSION_1 0x00 29#define UAC_VERSION_2 0x20 30 31/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ 32#define UAC_HEADER 0x01 33#define UAC_INPUT_TERMINAL 0x02 34#define UAC_OUTPUT_TERMINAL 0x03 35#define UAC_MIXER_UNIT 0x04 36#define UAC_SELECTOR_UNIT 0x05 37#define UAC_FEATURE_UNIT 0x06 38#define UAC_PROCESSING_UNIT_V1 0x07 39#define UAC_EXTENSION_UNIT_V1 0x08 40 41/* UAC v2.0 types */ 42#define UAC_EFFECT_UNIT 0x07 43#define UAC_PROCESSING_UNIT_V2 0x08 44#define UAC_EXTENSION_UNIT_V2 0x09 45#define UAC_CLOCK_SOURCE 0x0a 46#define UAC_CLOCK_SELECTOR 0x0b 47#define UAC_CLOCK_MULTIPLIER 0x0c 48#define UAC_SAMPLE_RATE_CONVERTER 0x0d 49 50/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ 51#define UAC_AS_GENERAL 0x01 52#define UAC_FORMAT_TYPE 0x02 53#define UAC_FORMAT_SPECIFIC 0x03 54 55/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ 56#define UAC_EP_GENERAL 0x01 57 58/* A.9 Audio Class-Specific Request Codes */ 59#define UAC_SET_ 0x00 60#define UAC_GET_ 0x80 61 62#define UAC__CUR 0x1 63#define UAC__MIN 0x2 64#define UAC__MAX 0x3 65#define UAC__RES 0x4 66#define UAC__MEM 0x5 67 68#define UAC_SET_CUR (UAC_SET_ | UAC__CUR) 69#define UAC_GET_CUR (UAC_GET_ | UAC__CUR) 70#define UAC_SET_MIN (UAC_SET_ | UAC__MIN) 71#define UAC_GET_MIN (UAC_GET_ | UAC__MIN) 72#define UAC_SET_MAX (UAC_SET_ | UAC__MAX) 73#define UAC_GET_MAX (UAC_GET_ | UAC__MAX) 74#define UAC_SET_RES (UAC_SET_ | UAC__RES) 75#define UAC_GET_RES (UAC_GET_ | UAC__RES) 76#define UAC_SET_MEM (UAC_SET_ | UAC__MEM) 77#define UAC_GET_MEM (UAC_GET_ | UAC__MEM) 78 79#define UAC_GET_STAT 0xff 80 81/* Audio class v2.0 handles all the parameter calls differently */ 82#define UAC2_CS_CUR 0x01 83#define UAC2_CS_RANGE 0x02 84 85/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */ 86#define UAC_MS_HEADER 0x01 87#define UAC_MIDI_IN_JACK 0x02 88#define UAC_MIDI_OUT_JACK 0x03 89 90/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */ 91#define UAC_MS_GENERAL 0x01 92 93/* Terminals - 2.1 USB Terminal Types */ 94#define UAC_TERMINAL_UNDEFINED 0x100 95#define UAC_TERMINAL_STREAMING 0x101 96#define UAC_TERMINAL_VENDOR_SPEC 0x1FF 97 98/* Terminal Control Selectors */ 99/* 4.3.2 Class-Specific AC Interface Descriptor */ 100struct uac_ac_header_descriptor_v1 { 101 __u8 bLength; /* 8 + n */ 102 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 103 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */ 104 __le16 bcdADC; /* 0x0100 */ 105 __le16 wTotalLength; /* includes Unit and Terminal desc. */ 106 __u8 bInCollection; /* n */ 107 __u8 baInterfaceNr[]; /* [n] */ 108} __attribute__ ((packed)); 109 110#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n)) 111 112/* As above, but more useful for defining your own descriptors: */ 113#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \ 114struct uac_ac_header_descriptor_v1_##n { \ 115 __u8 bLength; \ 116 __u8 bDescriptorType; \ 117 __u8 bDescriptorSubtype; \ 118 __le16 bcdADC; \ 119 __le16 wTotalLength; \ 120 __u8 bInCollection; \ 121 __u8 baInterfaceNr[n]; \ 122} __attribute__ ((packed)) 123 124/* 4.3.2.1 Input Terminal Descriptor */ 125struct uac_input_terminal_descriptor { 126 __u8 bLength; /* in bytes: 12 */ 127 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 128 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */ 129 __u8 bTerminalID; /* Constant uniquely terminal ID */ 130 __le16 wTerminalType; /* USB Audio Terminal Types */ 131 __u8 bAssocTerminal; /* ID of the Output Terminal associated */ 132 __u8 bNrChannels; /* Number of logical output channels */ 133 __le16 wChannelConfig; 134 __u8 iChannelNames; 135 __u8 iTerminal; 136} __attribute__ ((packed)); 137 138#define UAC_DT_INPUT_TERMINAL_SIZE 12 139 140/* Terminals - 2.2 Input Terminal Types */ 141#define UAC_INPUT_TERMINAL_UNDEFINED 0x200 142#define UAC_INPUT_TERMINAL_MICROPHONE 0x201 143#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202 144#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203 145#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204 146#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205 147#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206 148 149/* Terminals - control selectors */ 150 151#define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01 152 153/* 4.3.2.2 Output Terminal Descriptor */ 154struct uac_output_terminal_descriptor_v1 { 155 __u8 bLength; /* in bytes: 9 */ 156 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 157 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */ 158 __u8 bTerminalID; /* Constant uniquely terminal ID */ 159 __le16 wTerminalType; /* USB Audio Terminal Types */ 160 __u8 bAssocTerminal; /* ID of the Input Terminal associated */ 161 __u8 bSourceID; /* ID of the connected Unit or Terminal*/ 162 __u8 iTerminal; 163} __attribute__ ((packed)); 164 165#define UAC_DT_OUTPUT_TERMINAL_SIZE 9 166 167/* Terminals - 2.3 Output Terminal Types */ 168#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300 169#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301 170#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302 171#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303 172#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304 173#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305 174#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306 175#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307 176 177/* Set bControlSize = 2 as default setting */ 178#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2) 179 180/* As above, but more useful for defining your own descriptors: */ 181#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \ 182struct uac_feature_unit_descriptor_##ch { \ 183 __u8 bLength; \ 184 __u8 bDescriptorType; \ 185 __u8 bDescriptorSubtype; \ 186 __u8 bUnitID; \ 187 __u8 bSourceID; \ 188 __u8 bControlSize; \ 189 __le16 bmaControls[ch + 1]; \ 190 __u8 iFeature; \ 191} __attribute__ ((packed)) 192 193/* 4.5.2 Class-Specific AS Interface Descriptor */ 194struct uac_as_header_descriptor_v1 { 195 __u8 bLength; /* in bytes: 7 */ 196 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 197 __u8 bDescriptorSubtype; /* AS_GENERAL */ 198 __u8 bTerminalLink; /* Terminal ID of connected Terminal */ 199 __u8 bDelay; /* Delay introduced by the data path */ 200 __le16 wFormatTag; /* The Audio Data Format */ 201} __attribute__ ((packed)); 202 203struct uac_as_header_descriptor_v2 { 204 __u8 bLength; 205 __u8 bDescriptorType; 206 __u8 bDescriptorSubtype; 207 __u8 bTerminalLink; 208 __u8 bmControls; 209 __u8 bFormatType; 210 __u32 bmFormats; 211 __u8 bNrChannels; 212 __u32 bmChannelConfig; 213 __u8 iChannelNames; 214} __attribute__((packed)); 215 216#define UAC_DT_AS_HEADER_SIZE 7 217 218/* Formats - A.1.1 Audio Data Format Type I Codes */ 219#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0 220#define UAC_FORMAT_TYPE_I_PCM 0x1 221#define UAC_FORMAT_TYPE_I_PCM8 0x2 222#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3 223#define UAC_FORMAT_TYPE_I_ALAW 0x4 224#define UAC_FORMAT_TYPE_I_MULAW 0x5 225 226struct uac_format_type_i_continuous_descriptor { 227 __u8 bLength; /* in bytes: 8 + (ns * 3) */ 228 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 229 __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 230 __u8 bFormatType; /* FORMAT_TYPE_1 */ 231 __u8 bNrChannels; /* physical channels in the stream */ 232 __u8 bSubframeSize; /* */ 233 __u8 bBitResolution; 234 __u8 bSamFreqType; 235 __u8 tLowerSamFreq[3]; 236 __u8 tUpperSamFreq[3]; 237} __attribute__ ((packed)); 238 239#define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14 240 241struct uac_format_type_i_discrete_descriptor { 242 __u8 bLength; /* in bytes: 8 + (ns * 3) */ 243 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 244 __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 245 __u8 bFormatType; /* FORMAT_TYPE_1 */ 246 __u8 bNrChannels; /* physical channels in the stream */ 247 __u8 bSubframeSize; /* */ 248 __u8 bBitResolution; 249 __u8 bSamFreqType; 250 __u8 tSamFreq[][3]; 251} __attribute__ ((packed)); 252 253#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \ 254struct uac_format_type_i_discrete_descriptor_##n { \ 255 __u8 bLength; \ 256 __u8 bDescriptorType; \ 257 __u8 bDescriptorSubtype; \ 258 __u8 bFormatType; \ 259 __u8 bNrChannels; \ 260 __u8 bSubframeSize; \ 261 __u8 bBitResolution; \ 262 __u8 bSamFreqType; \ 263 __u8 tSamFreq[n][3]; \ 264} __attribute__ ((packed)) 265 266#define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3)) 267 268struct uac_format_type_i_ext_descriptor { 269 __u8 bLength; 270 __u8 bDescriptorType; 271 __u8 bDescriptorSubtype; 272 __u8 bFormatType; 273 __u8 bSubslotSize; 274 __u8 bBitResolution; 275 __u8 bHeaderLength; 276 __u8 bControlSize; 277 __u8 bSideBandProtocol; 278} __attribute__((packed)); 279 280 281/* Formats - Audio Data Format Type I Codes */ 282 283#define UAC_FORMAT_TYPE_II_MPEG 0x1001 284#define UAC_FORMAT_TYPE_II_AC3 0x1002 285 286struct uac_format_type_ii_discrete_descriptor { 287 __u8 bLength; 288 __u8 bDescriptorType; 289 __u8 bDescriptorSubtype; 290 __u8 bFormatType; 291 __le16 wMaxBitRate; 292 __le16 wSamplesPerFrame; 293 __u8 bSamFreqType; 294 __u8 tSamFreq[][3]; 295} __attribute__((packed)); 296 297struct uac_format_type_ii_ext_descriptor { 298 __u8 bLength; 299 __u8 bDescriptorType; 300 __u8 bDescriptorSubtype; 301 __u8 bFormatType; 302 __u16 wMaxBitRate; 303 __u16 wSamplesPerFrame; 304 __u8 bHeaderLength; 305 __u8 bSideBandProtocol; 306} __attribute__((packed)); 307 308/* type III */ 309#define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001 310#define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002 311#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003 312#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004 313#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005 314#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006 315 316/* Formats - A.2 Format Type Codes */ 317#define UAC_FORMAT_TYPE_UNDEFINED 0x0 318#define UAC_FORMAT_TYPE_I 0x1 319#define UAC_FORMAT_TYPE_II 0x2 320#define UAC_FORMAT_TYPE_III 0x3 321#define UAC_EXT_FORMAT_TYPE_I 0x81 322#define UAC_EXT_FORMAT_TYPE_II 0x82 323#define UAC_EXT_FORMAT_TYPE_III 0x83 324 325struct uac_iso_endpoint_descriptor { 326 __u8 bLength; /* in bytes: 7 */ 327 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */ 328 __u8 bDescriptorSubtype; /* EP_GENERAL */ 329 __u8 bmAttributes; 330 __u8 bLockDelayUnits; 331 __le16 wLockDelay; 332}; 333#define UAC_ISO_ENDPOINT_DESC_SIZE 7 334 335#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01 336#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02 337#define UAC_EP_CS_ATTR_FILL_MAX 0x80 338 339/* Audio class v2.0: CLOCK_SOURCE descriptor */ 340 341struct uac_clock_source_descriptor { 342 __u8 bLength; 343 __u8 bDescriptorType; 344 __u8 bDescriptorSubtype; 345 __u8 bClockID; 346 __u8 bmAttributes; 347 __u8 bmControls; 348 __u8 bAssocTerminal; 349 __u8 iClockSource; 350} __attribute__((packed)); 351 352/* A.10.2 Feature Unit Control Selectors */ 353 354struct uac_feature_unit_descriptor { 355 __u8 bLength; 356 __u8 bDescriptorType; 357 __u8 bDescriptorSubtype; 358 __u8 bUnitID; 359 __u8 bSourceID; 360 __u8 bControlSize; 361 __u8 controls[0]; /* variable length */ 362} __attribute__((packed)); 363 364#define UAC_FU_CONTROL_UNDEFINED 0x00 365#define UAC_MUTE_CONTROL 0x01 366#define UAC_VOLUME_CONTROL 0x02 367#define UAC_BASS_CONTROL 0x03 368#define UAC_MID_CONTROL 0x04 369#define UAC_TREBLE_CONTROL 0x05 370#define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06 371#define UAC_AUTOMATIC_GAIN_CONTROL 0x07 372#define UAC_DELAY_CONTROL 0x08 373#define UAC_BASS_BOOST_CONTROL 0x09 374#define UAC_LOUDNESS_CONTROL 0x0a 375 376#define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1)) 377#define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1)) 378#define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1)) 379#define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1)) 380#define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1)) 381#define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1)) 382#define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1)) 383#define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1)) 384#define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1)) 385#define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1)) 386 387#ifdef __KERNEL__ 388 389struct usb_audio_control { 390 struct list_head list; 391 const char *name; 392 u8 type; 393 int data[5]; 394 int (*set)(struct usb_audio_control *con, u8 cmd, int value); 395 int (*get)(struct usb_audio_control *con, u8 cmd); 396}; 397 398struct usb_audio_control_selector { 399 struct list_head list; 400 struct list_head control; 401 u8 id; 402 const char *name; 403 u8 type; 404 struct usb_descriptor_header *desc; 405}; 406 407#endif /* __KERNEL__ */ 408 409#endif /* __LINUX_USB_AUDIO_H */