Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 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 |
Daniel Mack | 7e84789 | 2010-03-11 21:13:20 +0100 | [diff] [blame] | 16 | * |
| 17 | * Types and defines in this file are either specific to version 1.0 of |
| 18 | * this standard or common for newer versions. |
Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef __LINUX_USB_AUDIO_H |
| 22 | #define __LINUX_USB_AUDIO_H |
| 23 | |
| 24 | #include <linux/types.h> |
| 25 | |
Daniel Mack | 7e84789 | 2010-03-11 21:13:20 +0100 | [diff] [blame] | 26 | /* bInterfaceProtocol values to denote the version of the standard used */ |
| 27 | #define UAC_VERSION_1 0x00 |
| 28 | #define UAC_VERSION_2 0x20 |
| 29 | |
Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 30 | /* A.2 Audio Interface Subclass Codes */ |
| 31 | #define USB_SUBCLASS_AUDIOCONTROL 0x01 |
| 32 | #define USB_SUBCLASS_AUDIOSTREAMING 0x02 |
| 33 | #define USB_SUBCLASS_MIDISTREAMING 0x03 |
| 34 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 35 | /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ |
| 36 | #define UAC_HEADER 0x01 |
| 37 | #define UAC_INPUT_TERMINAL 0x02 |
| 38 | #define UAC_OUTPUT_TERMINAL 0x03 |
| 39 | #define UAC_MIXER_UNIT 0x04 |
| 40 | #define UAC_SELECTOR_UNIT 0x05 |
| 41 | #define UAC_FEATURE_UNIT 0x06 |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 42 | #define UAC_PROCESSING_UNIT_V1 0x07 |
| 43 | #define UAC_EXTENSION_UNIT_V1 0x08 |
| 44 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 45 | /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ |
| 46 | #define UAC_AS_GENERAL 0x01 |
| 47 | #define UAC_FORMAT_TYPE 0x02 |
| 48 | #define UAC_FORMAT_SPECIFIC 0x03 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 49 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 50 | /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ |
| 51 | #define UAC_EP_GENERAL 0x01 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 52 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 53 | /* A.9 Audio Class-Specific Request Codes */ |
| 54 | #define UAC_SET_ 0x00 |
| 55 | #define UAC_GET_ 0x80 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 56 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 57 | #define UAC__CUR 0x1 |
| 58 | #define UAC__MIN 0x2 |
| 59 | #define UAC__MAX 0x3 |
| 60 | #define UAC__RES 0x4 |
| 61 | #define UAC__MEM 0x5 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 62 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 63 | #define UAC_SET_CUR (UAC_SET_ | UAC__CUR) |
| 64 | #define UAC_GET_CUR (UAC_GET_ | UAC__CUR) |
| 65 | #define UAC_SET_MIN (UAC_SET_ | UAC__MIN) |
| 66 | #define UAC_GET_MIN (UAC_GET_ | UAC__MIN) |
| 67 | #define UAC_SET_MAX (UAC_SET_ | UAC__MAX) |
| 68 | #define UAC_GET_MAX (UAC_GET_ | UAC__MAX) |
| 69 | #define UAC_SET_RES (UAC_SET_ | UAC__RES) |
| 70 | #define UAC_GET_RES (UAC_GET_ | UAC__RES) |
| 71 | #define UAC_SET_MEM (UAC_SET_ | UAC__MEM) |
| 72 | #define UAC_GET_MEM (UAC_GET_ | UAC__MEM) |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 73 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 74 | #define UAC_GET_STAT 0xff |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 75 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 76 | /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */ |
| 77 | #define UAC_MS_HEADER 0x01 |
| 78 | #define UAC_MIDI_IN_JACK 0x02 |
| 79 | #define UAC_MIDI_OUT_JACK 0x03 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 80 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 81 | /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */ |
| 82 | #define UAC_MS_GENERAL 0x01 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 83 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 84 | /* Terminals - 2.1 USB Terminal Types */ |
| 85 | #define UAC_TERMINAL_UNDEFINED 0x100 |
| 86 | #define UAC_TERMINAL_STREAMING 0x101 |
| 87 | #define UAC_TERMINAL_VENDOR_SPEC 0x1FF |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 88 | |
| 89 | /* Terminal Control Selectors */ |
Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 90 | /* 4.3.2 Class-Specific AC Interface Descriptor */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 91 | struct uac_ac_header_descriptor_v1 { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 92 | __u8 bLength; /* 8 + n */ |
Greg Kroah-Hartman | 41dceed | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 93 | __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 94 | __u8 bDescriptorSubtype; /* UAC_MS_HEADER */ |
Greg Kroah-Hartman | 41dceed | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 95 | __le16 bcdADC; /* 0x0100 */ |
| 96 | __le16 wTotalLength; /* includes Unit and Terminal desc. */ |
| 97 | __u8 bInCollection; /* n */ |
| 98 | __u8 baInterfaceNr[]; /* [n] */ |
Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 99 | } __attribute__ ((packed)); |
| 100 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 101 | #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n)) |
Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 102 | |
| 103 | /* As above, but more useful for defining your own descriptors: */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 104 | #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 105 | struct uac_ac_header_descriptor_v1_##n { \ |
Ben Williamson | f2ebf92c | 2006-08-01 11:28:16 +1000 | [diff] [blame] | 106 | __u8 bLength; \ |
| 107 | __u8 bDescriptorType; \ |
| 108 | __u8 bDescriptorSubtype; \ |
| 109 | __le16 bcdADC; \ |
| 110 | __le16 wTotalLength; \ |
| 111 | __u8 bInCollection; \ |
| 112 | __u8 baInterfaceNr[n]; \ |
| 113 | } __attribute__ ((packed)) |
| 114 | |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 115 | /* 4.3.2.1 Input Terminal Descriptor */ |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 116 | struct uac_input_terminal_descriptor { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 117 | __u8 bLength; /* in bytes: 12 */ |
| 118 | __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ |
| 119 | __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */ |
| 120 | __u8 bTerminalID; /* Constant uniquely terminal ID */ |
| 121 | __le16 wTerminalType; /* USB Audio Terminal Types */ |
| 122 | __u8 bAssocTerminal; /* ID of the Output Terminal associated */ |
| 123 | __u8 bNrChannels; /* Number of logical output channels */ |
| 124 | __le16 wChannelConfig; |
| 125 | __u8 iChannelNames; |
| 126 | __u8 iTerminal; |
| 127 | } __attribute__ ((packed)); |
| 128 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 129 | #define UAC_DT_INPUT_TERMINAL_SIZE 12 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 130 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 131 | /* Terminals - 2.2 Input Terminal Types */ |
| 132 | #define UAC_INPUT_TERMINAL_UNDEFINED 0x200 |
| 133 | #define UAC_INPUT_TERMINAL_MICROPHONE 0x201 |
| 134 | #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202 |
| 135 | #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203 |
| 136 | #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204 |
| 137 | #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205 |
| 138 | #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 139 | |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 140 | /* Terminals - control selectors */ |
| 141 | |
| 142 | #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01 |
| 143 | |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 144 | /* 4.3.2.2 Output Terminal Descriptor */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 145 | struct uac_output_terminal_descriptor_v1 { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 146 | __u8 bLength; /* in bytes: 9 */ |
| 147 | __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ |
| 148 | __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */ |
| 149 | __u8 bTerminalID; /* Constant uniquely terminal ID */ |
| 150 | __le16 wTerminalType; /* USB Audio Terminal Types */ |
| 151 | __u8 bAssocTerminal; /* ID of the Input Terminal associated */ |
| 152 | __u8 bSourceID; /* ID of the connected Unit or Terminal*/ |
| 153 | __u8 iTerminal; |
| 154 | } __attribute__ ((packed)); |
| 155 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 156 | #define UAC_DT_OUTPUT_TERMINAL_SIZE 9 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 157 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 158 | /* Terminals - 2.3 Output Terminal Types */ |
| 159 | #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300 |
| 160 | #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301 |
| 161 | #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302 |
| 162 | #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303 |
| 163 | #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304 |
| 164 | #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305 |
| 165 | #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306 |
| 166 | #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 167 | |
| 168 | /* Set bControlSize = 2 as default setting */ |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 169 | #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2) |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 170 | |
| 171 | /* As above, but more useful for defining your own descriptors: */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 172 | #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \ |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 173 | struct uac_feature_unit_descriptor_##ch { \ |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 174 | __u8 bLength; \ |
| 175 | __u8 bDescriptorType; \ |
| 176 | __u8 bDescriptorSubtype; \ |
| 177 | __u8 bUnitID; \ |
| 178 | __u8 bSourceID; \ |
| 179 | __u8 bControlSize; \ |
| 180 | __le16 bmaControls[ch + 1]; \ |
| 181 | __u8 iFeature; \ |
| 182 | } __attribute__ ((packed)) |
| 183 | |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 184 | /* 4.3.2.3 Mixer Unit Descriptor */ |
| 185 | struct uac_mixer_unit_descriptor { |
| 186 | __u8 bLength; |
| 187 | __u8 bDescriptorType; |
| 188 | __u8 bDescriptorSubtype; |
| 189 | __u8 bUnitID; |
| 190 | __u8 bNrInPins; |
| 191 | __u8 baSourceID[]; |
| 192 | } __attribute__ ((packed)); |
| 193 | |
| 194 | static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc) |
| 195 | { |
| 196 | return desc->baSourceID[desc->bNrInPins]; |
| 197 | } |
| 198 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 199 | static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc, |
| 200 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 201 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 202 | if (protocol == UAC_VERSION_1) |
| 203 | return (desc->baSourceID[desc->bNrInPins + 2] << 8) | |
| 204 | desc->baSourceID[desc->bNrInPins + 1]; |
| 205 | else |
| 206 | return (desc->baSourceID[desc->bNrInPins + 4] << 24) | |
| 207 | (desc->baSourceID[desc->bNrInPins + 3] << 16) | |
| 208 | (desc->baSourceID[desc->bNrInPins + 2] << 8) | |
| 209 | (desc->baSourceID[desc->bNrInPins + 1]); |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 212 | static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc, |
| 213 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 214 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 215 | return (protocol == UAC_VERSION_1) ? |
| 216 | desc->baSourceID[desc->bNrInPins + 3] : |
| 217 | desc->baSourceID[desc->bNrInPins + 5]; |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 220 | static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc, |
| 221 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 222 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 223 | return (protocol == UAC_VERSION_1) ? |
| 224 | &desc->baSourceID[desc->bNrInPins + 4] : |
| 225 | &desc->baSourceID[desc->bNrInPins + 6]; |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc) |
| 229 | { |
| 230 | __u8 *raw = (__u8 *) desc; |
| 231 | return raw[desc->bLength - 1]; |
| 232 | } |
| 233 | |
| 234 | /* 4.3.2.4 Selector Unit Descriptor */ |
| 235 | struct uac_selector_unit_descriptor { |
| 236 | __u8 bLength; |
| 237 | __u8 bDescriptorType; |
| 238 | __u8 bDescriptorSubtype; |
| 239 | __u8 bUintID; |
| 240 | __u8 bNrInPins; |
| 241 | __u8 baSourceID[]; |
| 242 | } __attribute__ ((packed)); |
| 243 | |
| 244 | static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc) |
| 245 | { |
| 246 | __u8 *raw = (__u8 *) desc; |
Daniel Mack | 5e68888 | 2010-05-08 11:24:56 +0200 | [diff] [blame] | 247 | return raw[9 + desc->bLength - 1]; |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* 4.3.2.5 Feature Unit Descriptor */ |
| 251 | struct uac_feature_unit_descriptor { |
| 252 | __u8 bLength; |
| 253 | __u8 bDescriptorType; |
| 254 | __u8 bDescriptorSubtype; |
| 255 | __u8 bUnitID; |
| 256 | __u8 bSourceID; |
| 257 | __u8 bControlSize; |
| 258 | __u8 bmaControls[0]; /* variable length */ |
| 259 | } __attribute__((packed)); |
| 260 | |
| 261 | static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc) |
| 262 | { |
| 263 | __u8 *raw = (__u8 *) desc; |
| 264 | return raw[desc->bLength - 1]; |
| 265 | } |
| 266 | |
| 267 | /* 4.3.2.6 Processing Unit Descriptors */ |
| 268 | struct uac_processing_unit_descriptor { |
| 269 | __u8 bLength; |
| 270 | __u8 bDescriptorType; |
| 271 | __u8 bDescriptorSubtype; |
| 272 | __u8 bUnitID; |
| 273 | __u16 wProcessType; |
| 274 | __u8 bNrInPins; |
| 275 | __u8 baSourceID[]; |
| 276 | } __attribute__ ((packed)); |
| 277 | |
| 278 | static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc) |
| 279 | { |
| 280 | return desc->baSourceID[desc->bNrInPins]; |
| 281 | } |
| 282 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 283 | static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc, |
| 284 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 285 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 286 | if (protocol == UAC_VERSION_1) |
| 287 | return (desc->baSourceID[desc->bNrInPins + 2] << 8) | |
| 288 | desc->baSourceID[desc->bNrInPins + 1]; |
| 289 | else |
| 290 | return (desc->baSourceID[desc->bNrInPins + 4] << 24) | |
| 291 | (desc->baSourceID[desc->bNrInPins + 3] << 16) | |
| 292 | (desc->baSourceID[desc->bNrInPins + 2] << 8) | |
| 293 | (desc->baSourceID[desc->bNrInPins + 1]); |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 296 | static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc, |
| 297 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 298 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 299 | return (protocol == UAC_VERSION_1) ? |
| 300 | desc->baSourceID[desc->bNrInPins + 3] : |
| 301 | desc->baSourceID[desc->bNrInPins + 5]; |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 302 | } |
| 303 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 304 | static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc, |
| 305 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 306 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 307 | return (protocol == UAC_VERSION_1) ? |
| 308 | desc->baSourceID[desc->bNrInPins + 4] : |
| 309 | desc->baSourceID[desc->bNrInPins + 6]; |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 312 | static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc, |
| 313 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 314 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 315 | return (protocol == UAC_VERSION_1) ? |
| 316 | &desc->baSourceID[desc->bNrInPins + 5] : |
| 317 | &desc->baSourceID[desc->bNrInPins + 7]; |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 320 | static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc, |
| 321 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 322 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 323 | __u8 control_size = uac_processing_unit_bControlSize(desc, protocol); |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 324 | return desc->baSourceID[desc->bNrInPins + control_size]; |
| 325 | } |
| 326 | |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 327 | static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc, |
| 328 | int protocol) |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 329 | { |
Daniel Mack | 23caaf1 | 2010-03-11 21:13:25 +0100 | [diff] [blame] | 330 | __u8 control_size = uac_processing_unit_bControlSize(desc, protocol); |
Daniel Mack | 99fc864 | 2010-03-11 21:13:24 +0100 | [diff] [blame] | 331 | return &desc->baSourceID[desc->bNrInPins + control_size + 1]; |
| 332 | } |
| 333 | |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 334 | /* 4.5.2 Class-Specific AS Interface Descriptor */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 335 | struct uac_as_header_descriptor_v1 { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 336 | __u8 bLength; /* in bytes: 7 */ |
| 337 | __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ |
| 338 | __u8 bDescriptorSubtype; /* AS_GENERAL */ |
| 339 | __u8 bTerminalLink; /* Terminal ID of connected Terminal */ |
| 340 | __u8 bDelay; /* Delay introduced by the data path */ |
| 341 | __le16 wFormatTag; /* The Audio Data Format */ |
| 342 | } __attribute__ ((packed)); |
| 343 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 344 | #define UAC_DT_AS_HEADER_SIZE 7 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 345 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 346 | /* Formats - A.1.1 Audio Data Format Type I Codes */ |
| 347 | #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0 |
| 348 | #define UAC_FORMAT_TYPE_I_PCM 0x1 |
| 349 | #define UAC_FORMAT_TYPE_I_PCM8 0x2 |
| 350 | #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3 |
| 351 | #define UAC_FORMAT_TYPE_I_ALAW 0x4 |
| 352 | #define UAC_FORMAT_TYPE_I_MULAW 0x5 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 353 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 354 | struct uac_format_type_i_continuous_descriptor { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 355 | __u8 bLength; /* in bytes: 8 + (ns * 3) */ |
| 356 | __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ |
| 357 | __u8 bDescriptorSubtype; /* FORMAT_TYPE */ |
| 358 | __u8 bFormatType; /* FORMAT_TYPE_1 */ |
| 359 | __u8 bNrChannels; /* physical channels in the stream */ |
| 360 | __u8 bSubframeSize; /* */ |
| 361 | __u8 bBitResolution; |
| 362 | __u8 bSamFreqType; |
| 363 | __u8 tLowerSamFreq[3]; |
| 364 | __u8 tUpperSamFreq[3]; |
| 365 | } __attribute__ ((packed)); |
| 366 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 367 | #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 368 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 369 | struct uac_format_type_i_discrete_descriptor { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 370 | __u8 bLength; /* in bytes: 8 + (ns * 3) */ |
| 371 | __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ |
| 372 | __u8 bDescriptorSubtype; /* FORMAT_TYPE */ |
| 373 | __u8 bFormatType; /* FORMAT_TYPE_1 */ |
| 374 | __u8 bNrChannels; /* physical channels in the stream */ |
| 375 | __u8 bSubframeSize; /* */ |
| 376 | __u8 bBitResolution; |
| 377 | __u8 bSamFreqType; |
| 378 | __u8 tSamFreq[][3]; |
| 379 | } __attribute__ ((packed)); |
| 380 | |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 381 | #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \ |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 382 | struct uac_format_type_i_discrete_descriptor_##n { \ |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 383 | __u8 bLength; \ |
| 384 | __u8 bDescriptorType; \ |
| 385 | __u8 bDescriptorSubtype; \ |
| 386 | __u8 bFormatType; \ |
| 387 | __u8 bNrChannels; \ |
| 388 | __u8 bSubframeSize; \ |
| 389 | __u8 bBitResolution; \ |
| 390 | __u8 bSamFreqType; \ |
| 391 | __u8 tSamFreq[n][3]; \ |
| 392 | } __attribute__ ((packed)) |
| 393 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 394 | #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3)) |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 395 | |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 396 | struct uac_format_type_i_ext_descriptor { |
| 397 | __u8 bLength; |
| 398 | __u8 bDescriptorType; |
| 399 | __u8 bDescriptorSubtype; |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 400 | __u8 bFormatType; |
Daniel Mack | 2b9ddcb | 2010-03-04 19:46:18 +0100 | [diff] [blame] | 401 | __u8 bSubslotSize; |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 402 | __u8 bBitResolution; |
| 403 | __u8 bHeaderLength; |
| 404 | __u8 bControlSize; |
| 405 | __u8 bSideBandProtocol; |
| 406 | } __attribute__((packed)); |
| 407 | |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 408 | /* Formats - Audio Data Format Type I Codes */ |
| 409 | |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 410 | #define UAC_FORMAT_TYPE_II_MPEG 0x1001 |
| 411 | #define UAC_FORMAT_TYPE_II_AC3 0x1002 |
| 412 | |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 413 | struct uac_format_type_ii_discrete_descriptor { |
| 414 | __u8 bLength; |
| 415 | __u8 bDescriptorType; |
| 416 | __u8 bDescriptorSubtype; |
| 417 | __u8 bFormatType; |
| 418 | __le16 wMaxBitRate; |
| 419 | __le16 wSamplesPerFrame; |
| 420 | __u8 bSamFreqType; |
| 421 | __u8 tSamFreq[][3]; |
| 422 | } __attribute__((packed)); |
| 423 | |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 424 | struct uac_format_type_ii_ext_descriptor { |
| 425 | __u8 bLength; |
| 426 | __u8 bDescriptorType; |
| 427 | __u8 bDescriptorSubtype; |
| 428 | __u8 bFormatType; |
| 429 | __u16 wMaxBitRate; |
| 430 | __u16 wSamplesPerFrame; |
| 431 | __u8 bHeaderLength; |
| 432 | __u8 bSideBandProtocol; |
| 433 | } __attribute__((packed)); |
| 434 | |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 435 | /* type III */ |
| 436 | #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001 |
| 437 | #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002 |
| 438 | #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003 |
| 439 | #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004 |
| 440 | #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005 |
| 441 | #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006 |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 442 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 443 | /* Formats - A.2 Format Type Codes */ |
| 444 | #define UAC_FORMAT_TYPE_UNDEFINED 0x0 |
| 445 | #define UAC_FORMAT_TYPE_I 0x1 |
| 446 | #define UAC_FORMAT_TYPE_II 0x2 |
| 447 | #define UAC_FORMAT_TYPE_III 0x3 |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 448 | #define UAC_EXT_FORMAT_TYPE_I 0x81 |
| 449 | #define UAC_EXT_FORMAT_TYPE_II 0x82 |
| 450 | #define UAC_EXT_FORMAT_TYPE_III 0x83 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 451 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 452 | struct uac_iso_endpoint_descriptor { |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 453 | __u8 bLength; /* in bytes: 7 */ |
| 454 | __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */ |
| 455 | __u8 bDescriptorSubtype; /* EP_GENERAL */ |
| 456 | __u8 bmAttributes; |
| 457 | __u8 bLockDelayUnits; |
| 458 | __le16 wLockDelay; |
Daniel Mack | 0350b6a | 2010-05-11 18:13:49 +0200 | [diff] [blame] | 459 | } __attribute__((packed)); |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 460 | #define UAC_ISO_ENDPOINT_DESC_SIZE 7 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 461 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 462 | #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01 |
| 463 | #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02 |
| 464 | #define UAC_EP_CS_ATTR_FILL_MAX 0x80 |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 465 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 466 | /* A.10.2 Feature Unit Control Selectors */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 467 | |
Laurent Pinchart | 512ad27 | 2009-06-21 23:23:05 +0200 | [diff] [blame] | 468 | #define UAC_FU_CONTROL_UNDEFINED 0x00 |
| 469 | #define UAC_MUTE_CONTROL 0x01 |
| 470 | #define UAC_VOLUME_CONTROL 0x02 |
| 471 | #define UAC_BASS_CONTROL 0x03 |
| 472 | #define UAC_MID_CONTROL 0x04 |
| 473 | #define UAC_TREBLE_CONTROL 0x05 |
| 474 | #define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06 |
| 475 | #define UAC_AUTOMATIC_GAIN_CONTROL 0x07 |
| 476 | #define UAC_DELAY_CONTROL 0x08 |
| 477 | #define UAC_BASS_BOOST_CONTROL 0x09 |
| 478 | #define UAC_LOUDNESS_CONTROL 0x0a |
| 479 | |
| 480 | #define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1)) |
| 481 | #define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1)) |
| 482 | #define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1)) |
| 483 | #define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1)) |
| 484 | #define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1)) |
| 485 | #define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1)) |
| 486 | #define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1)) |
| 487 | #define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1)) |
| 488 | #define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1)) |
| 489 | #define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1)) |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 490 | |
Daniel Mack | e213e9c | 2010-05-11 18:13:50 +0200 | [diff] [blame] | 491 | /* status word format (3.7.1.1) */ |
| 492 | |
| 493 | #define UAC1_STATUS_TYPE_ORIG_MASK 0x0f |
| 494 | #define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0 |
| 495 | #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1 |
| 496 | #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2 |
| 497 | |
| 498 | #define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7) |
| 499 | #define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6) |
| 500 | |
| 501 | struct uac1_status_word { |
| 502 | __u8 bStatusType; |
| 503 | __u8 bOriginator; |
| 504 | } __attribute__((packed)); |
| 505 | |
Michael S. Tsirkin | c350130 | 2009-07-29 14:23:25 +0300 | [diff] [blame] | 506 | #ifdef __KERNEL__ |
| 507 | |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 508 | struct usb_audio_control { |
| 509 | struct list_head list; |
| 510 | const char *name; |
| 511 | u8 type; |
| 512 | int data[5]; |
| 513 | int (*set)(struct usb_audio_control *con, u8 cmd, int value); |
| 514 | int (*get)(struct usb_audio_control *con, u8 cmd); |
| 515 | }; |
| 516 | |
Bryan Wu | c47d7b0 | 2009-06-03 09:17:57 -0400 | [diff] [blame] | 517 | struct usb_audio_control_selector { |
| 518 | struct list_head list; |
| 519 | struct list_head control; |
| 520 | u8 id; |
| 521 | const char *name; |
| 522 | u8 type; |
| 523 | struct usb_descriptor_header *desc; |
| 524 | }; |
| 525 | |
Michael S. Tsirkin | c350130 | 2009-07-29 14:23:25 +0300 | [diff] [blame] | 526 | #endif /* __KERNEL__ */ |
| 527 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 528 | #endif /* __LINUX_USB_AUDIO_H */ |