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 |
| 39 | #define PROCESSING_UNIT 0x07 |
| 40 | #define EXTENSION_UNIT 0x08 |
| 41 | |
| 42 | #define AS_GENERAL 0x01 |
| 43 | #define FORMAT_TYPE 0x02 |
| 44 | #define FORMAT_SPECIFIC 0x03 |
| 45 | |
| 46 | #define EP_GENERAL 0x01 |
| 47 | |
| 48 | #define MS_GENERAL 0x01 |
| 49 | #define MIDI_IN_JACK 0x02 |
| 50 | #define MIDI_OUT_JACK 0x03 |
| 51 | |
| 52 | /* endpoint attributes */ |
| 53 | #define EP_ATTR_MASK 0x0c |
| 54 | #define EP_ATTR_ASYNC 0x04 |
| 55 | #define EP_ATTR_ADAPTIVE 0x08 |
| 56 | #define EP_ATTR_SYNC 0x0c |
| 57 | |
| 58 | /* cs endpoint attributes */ |
| 59 | #define EP_CS_ATTR_SAMPLE_RATE 0x01 |
| 60 | #define EP_CS_ATTR_PITCH_CONTROL 0x02 |
| 61 | #define EP_CS_ATTR_FILL_MAX 0x80 |
| 62 | |
| 63 | /* Audio Class specific Request Codes */ |
| 64 | |
| 65 | #define SET_CUR 0x01 |
| 66 | #define GET_CUR 0x81 |
| 67 | #define SET_MIN 0x02 |
| 68 | #define GET_MIN 0x82 |
| 69 | #define SET_MAX 0x03 |
| 70 | #define GET_MAX 0x83 |
| 71 | #define SET_RES 0x04 |
| 72 | #define GET_RES 0x84 |
| 73 | #define SET_MEM 0x05 |
| 74 | #define GET_MEM 0x85 |
| 75 | #define GET_STAT 0xff |
| 76 | |
| 77 | /* Terminal Control Selectors */ |
| 78 | |
| 79 | #define COPY_PROTECT_CONTROL 0x01 |
| 80 | |
| 81 | /* Endpoint Control Selectors */ |
| 82 | |
| 83 | #define SAMPLING_FREQ_CONTROL 0x01 |
| 84 | #define PITCH_CONTROL 0x02 |
| 85 | |
| 86 | /* Format Types */ |
| 87 | #define USB_FORMAT_TYPE_I 0x01 |
| 88 | #define USB_FORMAT_TYPE_II 0x02 |
| 89 | #define USB_FORMAT_TYPE_III 0x03 |
| 90 | |
| 91 | /* type I */ |
| 92 | #define USB_AUDIO_FORMAT_PCM 0x01 |
| 93 | #define USB_AUDIO_FORMAT_PCM8 0x02 |
| 94 | #define USB_AUDIO_FORMAT_IEEE_FLOAT 0x03 |
| 95 | #define USB_AUDIO_FORMAT_ALAW 0x04 |
| 96 | #define USB_AUDIO_FORMAT_MU_LAW 0x05 |
| 97 | |
| 98 | /* type II */ |
| 99 | #define USB_AUDIO_FORMAT_MPEG 0x1001 |
| 100 | #define USB_AUDIO_FORMAT_AC3 0x1002 |
| 101 | |
| 102 | /* type III */ |
| 103 | #define USB_AUDIO_FORMAT_IEC1937_AC3 0x2001 |
| 104 | #define USB_AUDIO_FORMAT_IEC1937_MPEG1_LAYER1 0x2002 |
| 105 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_NOEXT 0x2003 |
| 106 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_EXT 0x2004 |
| 107 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER1_LS 0x2005 |
| 108 | #define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER23_LS 0x2006 |
| 109 | |
| 110 | |
| 111 | /* maximum number of endpoints per interface */ |
| 112 | #define MIDI_MAX_ENDPOINTS 2 |
| 113 | |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 114 | /* handling of USB vendor/product ID pairs as 32-bit numbers */ |
| 115 | #define USB_ID(vendor, product) (((vendor) << 16) | (product)) |
| 116 | #define USB_ID_VENDOR(id) ((id) >> 16) |
| 117 | #define USB_ID_PRODUCT(id) ((u16)(id)) |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* |
| 120 | */ |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | struct snd_usb_audio { |
| 123 | int index; |
| 124 | struct usb_device *dev; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 125 | struct snd_card *card; |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 126 | u32 usb_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int shutdown; |
| 128 | int num_interfaces; |
| 129 | |
| 130 | struct list_head pcm_list; /* list of pcm streams */ |
| 131 | int pcm_devs; |
| 132 | |
| 133 | struct list_head midi_list; /* list of midi interfaces */ |
| 134 | int next_midi_device; |
| 135 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 136 | struct list_head mixer_list; /* list of mixer interfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Information about devices with broken descriptors |
| 141 | */ |
| 142 | |
| 143 | /* special values for .ifnum */ |
| 144 | #define QUIRK_NO_INTERFACE -2 |
| 145 | #define QUIRK_ANY_INTERFACE -1 |
| 146 | |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 147 | enum quirk_type { |
| 148 | QUIRK_IGNORE_INTERFACE, |
| 149 | QUIRK_COMPOSITE, |
| 150 | QUIRK_MIDI_STANDARD_INTERFACE, |
| 151 | QUIRK_MIDI_FIXED_ENDPOINT, |
| 152 | QUIRK_MIDI_YAMAHA, |
| 153 | QUIRK_MIDI_MIDIMAN, |
| 154 | QUIRK_MIDI_NOVATION, |
| 155 | QUIRK_MIDI_RAW, |
| 156 | QUIRK_MIDI_EMAGIC, |
Clemens Ladisch | cc7a59b | 2006-02-07 17:11:06 +0100 | [diff] [blame] | 157 | QUIRK_MIDI_CME, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 158 | QUIRK_AUDIO_STANDARD_INTERFACE, |
| 159 | QUIRK_AUDIO_FIXED_ENDPOINT, |
| 160 | QUIRK_AUDIO_EDIROL_UA700_UA25, |
| 161 | QUIRK_AUDIO_EDIROL_UA1000, |
Bjoern Fay | d0b0fac | 2007-02-05 12:27:21 +0100 | [diff] [blame] | 162 | QUIRK_AUDIO_EDIROL_UA101, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 163 | |
| 164 | QUIRK_TYPE_COUNT |
| 165 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | struct snd_usb_audio_quirk { |
| 168 | const char *vendor_name; |
| 169 | const char *product_name; |
| 170 | int16_t ifnum; |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 171 | uint16_t type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | const void *data; |
| 173 | }; |
| 174 | |
| 175 | /* data for QUIRK_MIDI_FIXED_ENDPOINT */ |
| 176 | struct snd_usb_midi_endpoint_info { |
| 177 | int8_t out_ep; /* ep number, 0 autodetect */ |
| 178 | uint8_t out_interval; /* interval for interrupt endpoints */ |
| 179 | int8_t in_ep; |
| 180 | uint8_t in_interval; |
| 181 | uint16_t out_cables; /* bitmask */ |
| 182 | uint16_t in_cables; /* bitmask */ |
| 183 | }; |
| 184 | |
| 185 | /* for QUIRK_MIDI_YAMAHA, data is NULL */ |
| 186 | |
| 187 | /* for QUIRK_MIDI_MIDIMAN, data points to a snd_usb_midi_endpoint_info |
| 188 | * structure (out_cables and in_cables only) */ |
| 189 | |
| 190 | /* for QUIRK_COMPOSITE, data points to an array of snd_usb_audio_quirk |
| 191 | * structures, terminated with .ifnum = -1 */ |
| 192 | |
| 193 | /* for QUIRK_AUDIO_FIXED_ENDPOINT, data points to an audioformat structure */ |
| 194 | |
| 195 | /* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */ |
| 196 | |
| 197 | /* for QUIRK_AUDIO_EDIROL_UA700_UA25/UA1000, data is NULL */ |
| 198 | |
| 199 | /* for QUIRK_IGNORE_INTERFACE, data is NULL */ |
| 200 | |
Clemens Ladisch | 6155aff | 2005-07-04 09:20:42 +0200 | [diff] [blame] | 201 | /* for QUIRK_MIDI_NOVATION and _RAW, data is NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | /* for QUIRK_MIDI_EMAGIC, data points to a snd_usb_midi_endpoint_info |
| 204 | * structure (out_cables and in_cables only) */ |
| 205 | |
Clemens Ladisch | cc7a59b | 2006-02-07 17:11:06 +0100 | [diff] [blame] | 206 | /* for QUIRK_MIDI_CME, data is NULL */ |
Clemens Ladisch | f38275f | 2005-07-25 16:17:29 +0200 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* |
| 209 | */ |
| 210 | |
| 211 | #define combine_word(s) ((*s) | ((unsigned int)(s)[1] << 8)) |
| 212 | #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) |
| 213 | #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) |
| 214 | |
| 215 | unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size); |
| 216 | |
| 217 | void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype); |
| 218 | void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype); |
| 219 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 220 | int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, |
| 221 | __u8 request, __u8 requesttype, __u16 value, __u16 index, |
| 222 | void *data, __u16 size, int timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 224 | int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 225 | void snd_usb_mixer_disconnect(struct list_head *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 227 | int snd_usb_create_midi_interface(struct snd_usb_audio *chip, struct usb_interface *iface, |
| 228 | const struct snd_usb_audio_quirk *quirk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | void snd_usbmidi_input_stop(struct list_head* p); |
| 230 | void snd_usbmidi_input_start(struct list_head* p); |
Clemens Ladisch | ee73339 | 2005-04-25 10:34:13 +0200 | [diff] [blame] | 231 | void snd_usbmidi_disconnect(struct list_head *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * retrieve usb_interface descriptor from the host interface |
| 235 | * (conditional for compatibility with the older API) |
| 236 | */ |
| 237 | #ifndef get_iface_desc |
| 238 | #define get_iface_desc(iface) (&(iface)->desc) |
| 239 | #define get_endpoint(alt,ep) (&(alt)->endpoint[ep].desc) |
| 240 | #define get_ep_desc(ep) (&(ep)->desc) |
| 241 | #define get_cfg_desc(cfg) (&(cfg)->desc) |
| 242 | #endif |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | #ifndef snd_usb_get_speed |
| 245 | #define snd_usb_get_speed(dev) ((dev)->speed) |
| 246 | #endif |
| 247 | |
| 248 | #endif /* __USBAUDIO_H */ |