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 <[email protected]> 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 #define USB_SUBCLASS_VENDOR_SPEC 0xff 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 */ 93 /* 4.3.2 Class-Specific AC Interface Descriptor */ 94 struct usb_ac_header_descriptor { 95 __u8 bLength; /* 8 + n */ 96 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 97 __u8 bDescriptorSubtype; /* USB_MS_HEADER */ 98 __le16 bcdADC; /* 0x0100 */ 99 __le16 wTotalLength; /* includes Unit and Terminal desc. */ 100 __u8 bInCollection; /* n */ 101 __u8 baInterfaceNr[]; /* [n] */ 102 } __attribute__ ((packed)); 103 104 #define USB_DT_AC_HEADER_SIZE(n) (8 + (n)) 105 106 /* As above, but more useful for defining your own descriptors: */ 107 #define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \ 108 struct usb_ac_header_descriptor_##n { \ 109 __u8 bLength; \ 110 __u8 bDescriptorType; \ 111 __u8 bDescriptorSubtype; \ 112 __le16 bcdADC; \ 113 __le16 wTotalLength; \ 114 __u8 bInCollection; \ 115 __u8 baInterfaceNr[n]; \ 116 } __attribute__ ((packed)) 117 118 /* 4.3.2.1 Input Terminal Descriptor */ 119 struct 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 */ 143 struct 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) \ 170 struct 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 */ 182 struct 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 200 struct 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 215 struct 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) \ 228 struct 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 251 struct 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 284 struct 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 293 static 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 300 static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd) 301 { 302 return con->data[cmd]; 303 } 304 305 struct 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 314 #endif /* __LINUX_USB_AUDIO_H */ 315