Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __USBAUDIO_H |
| 2 | #define __USBAUDIO_H |
| 3 | /* |
| 4 | * (Tentative) USB Audio Driver for ALSA |
| 5 | * |
| 6 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> |
| 7 | * |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | /* |
| 26 | */ |
| 27 | |
| 28 | #define USB_SUBCLASS_AUDIO_CONTROL 0x01 |
| 29 | #define USB_SUBCLASS_AUDIO_STREAMING 0x02 |
| 30 | #define USB_SUBCLASS_MIDI_STREAMING 0x03 |
| 31 | #define USB_SUBCLASS_VENDOR_SPEC 0xff |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define HEADER 0x01 |
| 34 | #define INPUT_TERMINAL 0x02 |
| 35 | #define OUTPUT_TERMINAL 0x03 |
| 36 | #define MIXER_UNIT 0x04 |
| 37 | #define SELECTOR_UNIT 0x05 |
| 38 | #define FEATURE_UNIT 0x06 |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 39 | #define PROCESSING_UNIT_V1 0x07 |
| 40 | #define EXTENSION_UNIT_V1 0x08 |
| 41 | |
| 42 | /* audio class v2 */ |
| 43 | #define EFFECT_UNIT 0x07 |
| 44 | #define PROCESSING_UNIT_V2 0x08 |
| 45 | #define EXTENSION_UNIT_V2 0x09 |
| 46 | #define CLOCK_SOURCE 0x0a |
| 47 | #define CLOCK_SELECTOR 0x0b |
| 48 | #define CLOCK_MULTIPLIER 0x0c |
| 49 | #define SAMPLE_RATE_CONVERTER 0x0d |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define AS_GENERAL 0x01 |
| 52 | #define FORMAT_TYPE 0x02 |
| 53 | #define FORMAT_SPECIFIC 0x03 |
| 54 | |
| 55 | #define EP_GENERAL 0x01 |
| 56 | |
| 57 | #define MS_GENERAL 0x01 |
| 58 | #define MIDI_IN_JACK 0x02 |
| 59 | #define MIDI_OUT_JACK 0x03 |
| 60 | |
| 61 | /* endpoint attributes */ |
| 62 | #define EP_ATTR_MASK 0x0c |
| 63 | #define EP_ATTR_ASYNC 0x04 |
| 64 | #define EP_ATTR_ADAPTIVE 0x08 |
| 65 | #define EP_ATTR_SYNC 0x0c |
| 66 | |
| 67 | /* cs endpoint attributes */ |
| 68 | #define EP_CS_ATTR_SAMPLE_RATE 0x01 |
| 69 | #define EP_CS_ATTR_PITCH_CONTROL 0x02 |
| 70 | #define EP_CS_ATTR_FILL_MAX 0x80 |
| 71 | |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 72 | /* Audio Class specific Request Codes (v1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | #define SET_CUR 0x01 |
| 75 | #define GET_CUR 0x81 |
| 76 | #define SET_MIN 0x02 |
| 77 | #define GET_MIN 0x82 |
| 78 | #define SET_MAX 0x03 |
| 79 | #define GET_MAX 0x83 |
| 80 | #define SET_RES 0x04 |
| 81 | #define GET_RES 0x84 |
| 82 | #define SET_MEM 0x05 |
| 83 | #define GET_MEM 0x85 |
| 84 | #define GET_STAT 0xff |
| 85 | |
Daniel Mack | 8fee4af | 2010-02-22 23:49:10 +0100 | [diff] [blame] | 86 | /* Audio Class specific Request Codes (v2) */ |
| 87 | #define CS_CUR 0x01 |
| 88 | #define CS_RANGE 0x02 |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Terminal Control Selectors */ |
| 91 | |
| 92 | #define COPY_PROTECT_CONTROL 0x01 |
| 93 | |
| 94 | /* Endpoint Control Selectors */ |
| 95 | |
| 96 | #define SAMPLING_FREQ_CONTROL 0x01 |
| 97 | #define PITCH_CONTROL 0x02 |
| 98 | |
| 99 | /* Format Types */ |
| 100 | #define USB_FORMAT_TYPE_I 0x01 |
| 101 | #define USB_FORMAT_TYPE_II 0x02 |
| 102 | #define USB_FORMAT_TYPE_III 0x03 |
| 103 | |
| 104 | /* type I */ |
| 105 | #define USB_AUDIO_FORMAT_PCM 0x01 |
| 106 | #define USB_AUDIO_FORMAT_PCM8 0x02 |
| 107 | #define USB_AUDIO_FORMAT_IEEE_FLOAT 0x03 |
| 108 | #define USB_AUDIO_FORMAT_ALAW 0x04 |
| 109 | #define USB_AUDIO_FORMAT_MU_LAW 0x05 |
| 110 | |
| 111 | /* type II */ |
| 112 | #define USB_AUDIO_FORMAT_MPEG 0x1001 |
| 113 | #define USB_AUDIO_FORMAT_AC3 0x1002 |
| 114 | |
| 115 | /* type III */ |
| 116 | #define USB_AUDIO_FORMAT_IEC1937_AC3 0x2001 |
| 117 | #define USB_AUDIO_FORMAT_IEC1937_MPEG1_LAYER1 0x2002 |
| 118 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_NOEXT 0x2003 |
| 119 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_EXT 0x2004 |
| 120 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER1_LS 0x2005 |
| 121 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER23_LS 0x2006 |
| 122 | |
| 123 | |
| 124 | /* maximum number of endpoints per interface */ |
| 125 | #define MIDI_MAX_ENDPOINTS 2 |
| 126 | |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 127 | /* handling of USB vendor/product ID pairs as 32-bit numbers */ |
| 128 | #define USB_ID(vendor, product) (((vendor) << 16) | (product)) |
| 129 | #define USB_ID_VENDOR(id) ((id) >> 16) |
| 130 | #define USB_ID_PRODUCT(id) ((u16)(id)) |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* |
| 133 | */ |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | struct snd_usb_audio { |
| 136 | int index; |
| 137 | struct usb_device *dev; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 138 | struct snd_card *card; |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 139 | u32 usb_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | int shutdown; |
John S. Gruber | 98e89f6 | 2009-12-27 12:19:58 -0500 | [diff] [blame] | 141 | unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | int num_interfaces; |
Oliver Neukum | f85bf29 | 2007-12-14 14:42:41 +0100 | [diff] [blame] | 143 | int num_suspended_intf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Daniel Mack | 53ee98f | 2010-02-22 23:49:11 +0100 | [diff] [blame^] | 145 | /* for audio class v2 */ |
| 146 | int clock_id; |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | struct list_head pcm_list; /* list of pcm streams */ |
| 149 | int pcm_devs; |
| 150 | |
| 151 | struct list_head midi_list; /* list of midi interfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 153 | struct list_head mixer_list; /* list of mixer interfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | /* |
| 157 | * Information about devices with broken descriptors |
| 158 | */ |
| 159 | |
| 160 | /* special values for .ifnum */ |
| 161 | #define QUIRK_NO_INTERFACE -2 |
| 162 | #define QUIRK_ANY_INTERFACE -1 |
| 163 | |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 164 | enum quirk_type { |
| 165 | QUIRK_IGNORE_INTERFACE, |
| 166 | QUIRK_COMPOSITE, |
| 167 | QUIRK_MIDI_STANDARD_INTERFACE, |
| 168 | QUIRK_MIDI_FIXED_ENDPOINT, |
| 169 | QUIRK_MIDI_YAMAHA, |
| 170 | QUIRK_MIDI_MIDIMAN, |
| 171 | QUIRK_MIDI_NOVATION, |
Clemens Ladisch | 55de5ef | 2009-05-27 10:49:30 +0200 | [diff] [blame] | 172 | QUIRK_MIDI_FASTLANE, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 173 | QUIRK_MIDI_EMAGIC, |
Clemens Ladisch | cc7a59b | 2006-02-07 17:11:06 +0100 | [diff] [blame] | 174 | QUIRK_MIDI_CME, |
Karsten Wiese | 030a07e | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 175 | QUIRK_MIDI_US122L, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 176 | QUIRK_AUDIO_STANDARD_INTERFACE, |
| 177 | QUIRK_AUDIO_FIXED_ENDPOINT, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 178 | QUIRK_AUDIO_EDIROL_UA1000, |
Pedro Lopez-Cabanillas | 310e0dc | 2008-10-04 16:27:36 +0200 | [diff] [blame] | 179 | QUIRK_AUDIO_EDIROL_UAXX, |
John S. Gruber | 52a7a58 | 2009-12-27 12:19:59 -0500 | [diff] [blame] | 180 | QUIRK_AUDIO_ALIGN_TRANSFER, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 181 | |
| 182 | QUIRK_TYPE_COUNT |
| 183 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | struct snd_usb_audio_quirk { |
| 186 | const char *vendor_name; |
| 187 | const char *product_name; |
| 188 | int16_t ifnum; |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 189 | uint16_t type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | const void *data; |
| 191 | }; |
| 192 | |
| 193 | /* data for QUIRK_MIDI_FIXED_ENDPOINT */ |
| 194 | struct snd_usb_midi_endpoint_info { |
| 195 | int8_t out_ep; /* ep number, 0 autodetect */ |
| 196 | uint8_t out_interval; /* interval for interrupt endpoints */ |
| 197 | int8_t in_ep; |
| 198 | uint8_t in_interval; |
| 199 | uint16_t out_cables; /* bitmask */ |
| 200 | uint16_t in_cables; /* bitmask */ |
| 201 | }; |
| 202 | |
| 203 | /* for QUIRK_MIDI_YAMAHA, data is NULL */ |
| 204 | |
| 205 | /* for QUIRK_MIDI_MIDIMAN, data points to a snd_usb_midi_endpoint_info |
| 206 | * structure (out_cables and in_cables only) */ |
| 207 | |
| 208 | /* for QUIRK_COMPOSITE, data points to an array of snd_usb_audio_quirk |
| 209 | * structures, terminated with .ifnum = -1 */ |
| 210 | |
| 211 | /* for QUIRK_AUDIO_FIXED_ENDPOINT, data points to an audioformat structure */ |
| 212 | |
| 213 | /* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */ |
| 214 | |
| 215 | /* for QUIRK_AUDIO_EDIROL_UA700_UA25/UA1000, data is NULL */ |
| 216 | |
| 217 | /* for QUIRK_IGNORE_INTERFACE, data is NULL */ |
| 218 | |
Clemens Ladisch | 6155aff | 2005-07-04 09:20:42 +0200 | [diff] [blame] | 219 | /* for QUIRK_MIDI_NOVATION and _RAW, data is NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* for QUIRK_MIDI_EMAGIC, data points to a snd_usb_midi_endpoint_info |
| 222 | * structure (out_cables and in_cables only) */ |
| 223 | |
Clemens Ladisch | cc7a59b | 2006-02-07 17:11:06 +0100 | [diff] [blame] | 224 | /* for QUIRK_MIDI_CME, data is NULL */ |
Clemens Ladisch | f38275f | 2005-07-25 16:17:29 +0200 | [diff] [blame] | 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | /* |
| 227 | */ |
| 228 | |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 229 | /*E-mu USB samplerate control quirk*/ |
| 230 | enum { |
| 231 | EMU_QUIRK_SR_44100HZ = 0, |
| 232 | EMU_QUIRK_SR_48000HZ, |
| 233 | EMU_QUIRK_SR_88200HZ, |
| 234 | EMU_QUIRK_SR_96000HZ, |
| 235 | EMU_QUIRK_SR_176400HZ, |
| 236 | EMU_QUIRK_SR_192000HZ |
| 237 | }; |
| 238 | |
Julian Anastasov | f495088 | 2009-11-06 23:44:53 +0200 | [diff] [blame] | 239 | #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) |
| 241 | #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) |
| 242 | |
| 243 | unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size); |
| 244 | |
| 245 | void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype); |
| 246 | void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype); |
| 247 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 248 | int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, |
| 249 | __u8 request, __u8 requesttype, __u16 value, __u16 index, |
| 250 | void *data, __u16 size, int timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Takashi Iwai | 7a9b806 | 2008-08-13 15:40:53 +0200 | [diff] [blame] | 252 | int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, |
| 253 | int ignore_error); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 254 | void snd_usb_mixer_disconnect(struct list_head *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Clemens Ladisch | d82af9f | 2009-11-16 12:23:46 +0100 | [diff] [blame] | 256 | int snd_usbmidi_create(struct snd_card *card, |
| 257 | struct usb_interface *iface, |
| 258 | struct list_head *midi_list, |
| 259 | const struct snd_usb_audio_quirk *quirk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | void snd_usbmidi_input_stop(struct list_head* p); |
| 261 | void snd_usbmidi_input_start(struct list_head* p); |
Clemens Ladisch | ee73339 | 2005-04-25 10:34:13 +0200 | [diff] [blame] | 262 | void snd_usbmidi_disconnect(struct list_head *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 264 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
| 265 | unsigned char samplerate_id); |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | /* |
| 268 | * retrieve usb_interface descriptor from the host interface |
| 269 | * (conditional for compatibility with the older API) |
| 270 | */ |
| 271 | #ifndef get_iface_desc |
| 272 | #define get_iface_desc(iface) (&(iface)->desc) |
| 273 | #define get_endpoint(alt,ep) (&(alt)->endpoint[ep].desc) |
| 274 | #define get_ep_desc(ep) (&(ep)->desc) |
| 275 | #define get_cfg_desc(cfg) (&(cfg)->desc) |
| 276 | #endif |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | #ifndef snd_usb_get_speed |
| 279 | #define snd_usb_get_speed(dev) ((dev)->speed) |
| 280 | #endif |
| 281 | |
| 282 | #endif /* __USBAUDIO_H */ |