Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * caiaq.c: ALSA driver for caiaq/NativeInstruments devices |
| 3 | * |
| 4 | * Copyright (c) 2007 Daniel Mack <daniel@caiaq.de> |
| 5 | * Karsten Wiese <fzu@wemgehoertderstaat.de> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/interrupt.h> |
Daniel Mack | e431cf4 | 2009-03-28 21:19:49 +0100 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/gfp.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 27 | #include <linux/usb.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 28 | #include <sound/initval.h> |
Daniel Mack | e431cf4 | 2009-03-28 21:19:49 +0100 | [diff] [blame] | 29 | #include <sound/core.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 30 | #include <sound/pcm.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 31 | |
Daniel Mack | 936e7d0 | 2009-04-01 19:05:39 +0200 | [diff] [blame] | 32 | #include "device.h" |
| 33 | #include "audio.h" |
| 34 | #include "midi.h" |
| 35 | #include "control.h" |
| 36 | #include "input.h" |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 37 | |
| 38 | MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); |
Daniel Mack | 6008fd5 | 2010-09-10 16:12:34 +0800 | [diff] [blame] | 39 | MODULE_DESCRIPTION("caiaq USB audio"); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 40 | MODULE_LICENSE("GPL"); |
| 41 | MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 42 | "{Native Instruments, RigKontrol3}," |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 43 | "{Native Instruments, Kore Controller}," |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 44 | "{Native Instruments, Kore Controller 2}," |
Daniel Mack | f3e9d5d | 2008-05-08 15:42:15 +0200 | [diff] [blame] | 45 | "{Native Instruments, Audio Kontrol 1}," |
Daniel Mack | b30c494 | 2009-07-22 14:13:35 +0200 | [diff] [blame] | 46 | "{Native Instruments, Audio 2 DJ}," |
Daniel Mack | 2165592 | 2009-01-16 11:03:19 +0100 | [diff] [blame] | 47 | "{Native Instruments, Audio 4 DJ}," |
Daniel Mack | f3e9d5d | 2008-05-08 15:42:15 +0200 | [diff] [blame] | 48 | "{Native Instruments, Audio 8 DJ}," |
Daniel Mack | df8d81a | 2010-09-01 16:23:46 +0800 | [diff] [blame] | 49 | "{Native Instruments, Traktor Audio 2}," |
Daniel Mack | 2165592 | 2009-01-16 11:03:19 +0100 | [diff] [blame] | 50 | "{Native Instruments, Session I/O}," |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 51 | "{Native Instruments, GuitarRig mobile}" |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 52 | "{Native Instruments, Traktor Kontrol X1}" |
| 53 | "{Native Instruments, Traktor Kontrol S4}"); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 54 | |
| 55 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ |
| 56 | static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ |
| 57 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 58 | static int snd_card_used[SNDRV_CARDS]; |
| 59 | |
| 60 | module_param_array(index, int, NULL, 0444); |
| 61 | MODULE_PARM_DESC(index, "Index value for the caiaq sound device"); |
| 62 | module_param_array(id, charp, NULL, 0444); |
| 63 | MODULE_PARM_DESC(id, "ID string for the caiaq soundcard."); |
| 64 | module_param_array(enable, bool, NULL, 0444); |
| 65 | MODULE_PARM_DESC(enable, "Enable the caiaq soundcard."); |
| 66 | |
| 67 | enum { |
| 68 | SAMPLERATE_44100 = 0, |
| 69 | SAMPLERATE_48000 = 1, |
| 70 | SAMPLERATE_96000 = 2, |
| 71 | SAMPLERATE_192000 = 3, |
| 72 | SAMPLERATE_88200 = 4, |
| 73 | SAMPLERATE_INVALID = 0xff |
| 74 | }; |
| 75 | |
| 76 | enum { |
| 77 | DEPTH_NONE = 0, |
| 78 | DEPTH_16 = 1, |
| 79 | DEPTH_24 = 2, |
| 80 | DEPTH_32 = 3 |
| 81 | }; |
| 82 | |
| 83 | static struct usb_device_id snd_usb_id_table[] = { |
| 84 | { |
| 85 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 86 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 87 | .idProduct = USB_PID_RIGKONTROL2 |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 88 | }, |
| 89 | { |
| 90 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 91 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 92 | .idProduct = USB_PID_RIGKONTROL3 |
| 93 | }, |
| 94 | { |
| 95 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 96 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 97 | .idProduct = USB_PID_KORECONTROLLER |
| 98 | }, |
| 99 | { |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 100 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 101 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 102 | .idProduct = USB_PID_KORECONTROLLER2 |
| 103 | }, |
| 104 | { |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 105 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 106 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 107 | .idProduct = USB_PID_AK1 |
| 108 | }, |
| 109 | { |
| 110 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 111 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 112 | .idProduct = USB_PID_AUDIO8DJ |
| 113 | }, |
Daniel Mack | f3e9d5d | 2008-05-08 15:42:15 +0200 | [diff] [blame] | 114 | { |
| 115 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 116 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 117 | .idProduct = USB_PID_SESSIONIO |
| 118 | }, |
Daniel Mack | 2165592 | 2009-01-16 11:03:19 +0100 | [diff] [blame] | 119 | { |
| 120 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 121 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 122 | .idProduct = USB_PID_GUITARRIGMOBILE |
| 123 | }, |
| 124 | { |
| 125 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 126 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 127 | .idProduct = USB_PID_AUDIO4DJ |
| 128 | }, |
Daniel Mack | b30c494 | 2009-07-22 14:13:35 +0200 | [diff] [blame] | 129 | { |
| 130 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 131 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 132 | .idProduct = USB_PID_AUDIO2DJ |
| 133 | }, |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 134 | { |
| 135 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 136 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 137 | .idProduct = USB_PID_TRAKTORKONTROLX1 |
| 138 | }, |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 139 | { |
| 140 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 141 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 142 | .idProduct = USB_PID_TRAKTORKONTROLS4 |
| 143 | }, |
Daniel Mack | df8d81a | 2010-09-01 16:23:46 +0800 | [diff] [blame] | 144 | { |
| 145 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 146 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
| 147 | .idProduct = USB_PID_TRAKTORAUDIO2 |
| 148 | }, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 149 | { /* terminator */ } |
| 150 | }; |
| 151 | |
| 152 | static void usb_ep1_command_reply_dispatch (struct urb* urb) |
| 153 | { |
| 154 | int ret; |
| 155 | struct snd_usb_caiaqdev *dev = urb->context; |
| 156 | unsigned char *buf = urb->transfer_buffer; |
| 157 | |
| 158 | if (urb->status || !dev) { |
| 159 | log("received EP1 urb->status = %i\n", urb->status); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | switch(buf[0]) { |
| 164 | case EP1_CMD_GET_DEVICE_INFO: |
| 165 | memcpy(&dev->spec, buf+1, sizeof(struct caiaq_device_spec)); |
| 166 | dev->spec.fw_version = le16_to_cpu(dev->spec.fw_version); |
| 167 | debug("device spec (firmware %d): audio: %d in, %d out, " |
| 168 | "MIDI: %d in, %d out, data alignment %d\n", |
| 169 | dev->spec.fw_version, |
| 170 | dev->spec.num_analog_audio_in, |
| 171 | dev->spec.num_analog_audio_out, |
| 172 | dev->spec.num_midi_in, |
| 173 | dev->spec.num_midi_out, |
| 174 | dev->spec.data_alignment); |
| 175 | |
| 176 | dev->spec_received++; |
| 177 | wake_up(&dev->ep1_wait_queue); |
| 178 | break; |
| 179 | case EP1_CMD_AUDIO_PARAMS: |
| 180 | dev->audio_parm_answer = buf[1]; |
| 181 | wake_up(&dev->ep1_wait_queue); |
| 182 | break; |
| 183 | case EP1_CMD_MIDI_READ: |
| 184 | snd_usb_caiaq_midi_handle_input(dev, buf[1], buf + 3, buf[2]); |
| 185 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 186 | case EP1_CMD_READ_IO: |
| 187 | if (dev->chip.usb_id == |
| 188 | USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)) { |
| 189 | if (urb->actual_length > sizeof(dev->control_state)) |
| 190 | urb->actual_length = sizeof(dev->control_state); |
| 191 | memcpy(dev->control_state, buf + 1, urb->actual_length); |
| 192 | wake_up(&dev->ep1_wait_queue); |
| 193 | break; |
| 194 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 195 | #ifdef CONFIG_SND_USB_CAIAQ_INPUT |
| 196 | case EP1_CMD_READ_ERP: |
| 197 | case EP1_CMD_READ_ANALOG: |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 198 | snd_usb_caiaq_input_dispatch(dev, buf, urb->actual_length); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 199 | #endif |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 200 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | dev->ep1_in_urb.actual_length = 0; |
| 204 | ret = usb_submit_urb(&dev->ep1_in_urb, GFP_ATOMIC); |
| 205 | if (ret < 0) |
| 206 | log("unable to submit urb. OOM!?\n"); |
| 207 | } |
| 208 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 209 | int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *dev, |
| 210 | unsigned char command, |
| 211 | const unsigned char *buffer, |
| 212 | int len) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 213 | { |
| 214 | int actual_len; |
| 215 | struct usb_device *usb_dev = dev->chip.dev; |
| 216 | |
| 217 | if (!usb_dev) |
| 218 | return -EIO; |
| 219 | |
| 220 | if (len > EP1_BUFSIZE - 1) |
| 221 | len = EP1_BUFSIZE - 1; |
| 222 | |
| 223 | if (buffer && len > 0) |
| 224 | memcpy(dev->ep1_out_buf+1, buffer, len); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 225 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 226 | dev->ep1_out_buf[0] = command; |
| 227 | return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1), |
| 228 | dev->ep1_out_buf, len+1, &actual_len, 200); |
| 229 | } |
| 230 | |
| 231 | int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev, |
| 232 | int rate, int depth, int bpp) |
| 233 | { |
| 234 | int ret; |
| 235 | char tmp[5]; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 236 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 237 | switch (rate) { |
| 238 | case 44100: tmp[0] = SAMPLERATE_44100; break; |
| 239 | case 48000: tmp[0] = SAMPLERATE_48000; break; |
| 240 | case 88200: tmp[0] = SAMPLERATE_88200; break; |
| 241 | case 96000: tmp[0] = SAMPLERATE_96000; break; |
| 242 | case 192000: tmp[0] = SAMPLERATE_192000; break; |
| 243 | default: return -EINVAL; |
| 244 | } |
| 245 | |
| 246 | switch (depth) { |
| 247 | case 16: tmp[1] = DEPTH_16; break; |
| 248 | case 24: tmp[1] = DEPTH_24; break; |
| 249 | default: return -EINVAL; |
| 250 | } |
| 251 | |
| 252 | tmp[2] = bpp & 0xff; |
| 253 | tmp[3] = bpp >> 8; |
| 254 | tmp[4] = 1; /* packets per microframe */ |
| 255 | |
| 256 | debug("setting audio params: %d Hz, %d bits, %d bpp\n", |
| 257 | rate, depth, bpp); |
| 258 | |
| 259 | dev->audio_parm_answer = -1; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 260 | ret = snd_usb_caiaq_send_command(dev, EP1_CMD_AUDIO_PARAMS, |
| 261 | tmp, sizeof(tmp)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 262 | |
| 263 | if (ret) |
| 264 | return ret; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 265 | |
| 266 | if (!wait_event_timeout(dev->ep1_wait_queue, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 267 | dev->audio_parm_answer >= 0, HZ)) |
| 268 | return -EPIPE; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 269 | |
| 270 | if (dev->audio_parm_answer != 1) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 271 | debug("unable to set the device's audio params\n"); |
Daniel Mack | 9311c9b | 2009-03-18 11:03:54 +0100 | [diff] [blame] | 272 | else |
| 273 | dev->bpp = bpp; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 274 | |
| 275 | return dev->audio_parm_answer == 1 ? 0 : -EINVAL; |
| 276 | } |
| 277 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 278 | int snd_usb_caiaq_set_auto_msg(struct snd_usb_caiaqdev *dev, |
| 279 | int digital, int analog, int erp) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 280 | { |
| 281 | char tmp[3] = { digital, analog, erp }; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 282 | return snd_usb_caiaq_send_command(dev, EP1_CMD_AUTO_MSG, |
| 283 | tmp, sizeof(tmp)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Sam Ravnborg | c598195 | 2008-02-22 18:46:47 +0100 | [diff] [blame] | 286 | static void __devinit setup_card(struct snd_usb_caiaqdev *dev) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 287 | { |
| 288 | int ret; |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 289 | char val[4]; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 290 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 291 | /* device-specific startup specials */ |
| 292 | switch (dev->chip.usb_id) { |
| 293 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): |
| 294 | /* RigKontrol2 - display centered dash ('-') */ |
| 295 | val[0] = 0x00; |
| 296 | val[1] = 0x00; |
| 297 | val[2] = 0x01; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 298 | snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, val, 3); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 299 | break; |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 300 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
| 301 | /* RigKontrol2 - display two centered dashes ('--') */ |
| 302 | val[0] = 0x00; |
| 303 | val[1] = 0x40; |
| 304 | val[2] = 0x40; |
| 305 | val[3] = 0x00; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 306 | snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, val, 4); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 307 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 308 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): |
| 309 | /* Audio Kontrol 1 - make USB-LED stop blinking */ |
| 310 | val[0] = 0x00; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 311 | snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, val, 1); |
| 312 | break; |
| 313 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): |
| 314 | /* Audio 8 DJ - trigger read of current settings */ |
| 315 | dev->control_state[0] = 0xff; |
| 316 | snd_usb_caiaq_set_auto_msg(dev, 1, 0, 0); |
| 317 | snd_usb_caiaq_send_command(dev, EP1_CMD_READ_IO, NULL, 0); |
| 318 | |
| 319 | if (!wait_event_timeout(dev->ep1_wait_queue, |
| 320 | dev->control_state[0] != 0xff, HZ)) |
| 321 | return; |
| 322 | |
| 323 | /* fix up some defaults */ |
| 324 | if ((dev->control_state[1] != 2) || |
| 325 | (dev->control_state[2] != 3) || |
| 326 | (dev->control_state[4] != 2)) { |
| 327 | dev->control_state[1] = 2; |
| 328 | dev->control_state[2] = 3; |
| 329 | dev->control_state[4] = 2; |
| 330 | snd_usb_caiaq_send_command(dev, |
| 331 | EP1_CMD_WRITE_IO, dev->control_state, 6); |
| 332 | } |
| 333 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 334 | break; |
| 335 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 336 | |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 337 | if (dev->spec.num_analog_audio_out + |
| 338 | dev->spec.num_analog_audio_in + |
| 339 | dev->spec.num_digital_audio_out + |
| 340 | dev->spec.num_digital_audio_in > 0) { |
| 341 | ret = snd_usb_caiaq_audio_init(dev); |
| 342 | if (ret < 0) |
| 343 | log("Unable to set up audio system (ret=%d)\n", ret); |
| 344 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 345 | |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 346 | if (dev->spec.num_midi_in + |
| 347 | dev->spec.num_midi_out > 0) { |
| 348 | ret = snd_usb_caiaq_midi_init(dev); |
| 349 | if (ret < 0) |
| 350 | log("Unable to set up MIDI system (ret=%d)\n", ret); |
| 351 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 352 | |
| 353 | #ifdef CONFIG_SND_USB_CAIAQ_INPUT |
| 354 | ret = snd_usb_caiaq_input_init(dev); |
| 355 | if (ret < 0) |
| 356 | log("Unable to set up input system (ret=%d)\n", ret); |
| 357 | #endif |
| 358 | |
| 359 | /* finally, register the card and all its sub-instances */ |
| 360 | ret = snd_card_register(dev->chip.card); |
| 361 | if (ret < 0) { |
| 362 | log("snd_card_register() returned %d\n", ret); |
| 363 | snd_card_free(dev->chip.card); |
| 364 | } |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 365 | |
| 366 | ret = snd_usb_caiaq_control_init(dev); |
| 367 | if (ret < 0) |
| 368 | log("Unable to set up control system (ret=%d)\n", ret); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Daniel Mack | 563c2bf | 2009-07-02 10:46:35 +0200 | [diff] [blame] | 371 | static int create_card(struct usb_device *usb_dev, |
| 372 | struct usb_interface *intf, |
| 373 | struct snd_card **cardp) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 374 | { |
| 375 | int devnum; |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 376 | int err; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 377 | struct snd_card *card; |
| 378 | struct snd_usb_caiaqdev *dev; |
| 379 | |
| 380 | for (devnum = 0; devnum < SNDRV_CARDS; devnum++) |
| 381 | if (enable[devnum] && !snd_card_used[devnum]) |
| 382 | break; |
| 383 | |
| 384 | if (devnum >= SNDRV_CARDS) |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 385 | return -ENODEV; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 386 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 387 | err = snd_card_create(index[devnum], id[devnum], THIS_MODULE, |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 388 | sizeof(struct snd_usb_caiaqdev), &card); |
| 389 | if (err < 0) |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 390 | return err; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 391 | |
| 392 | dev = caiaqdev(card); |
| 393 | dev->chip.dev = usb_dev; |
| 394 | dev->chip.card = card; |
Al Viro | 8c5330a | 2008-05-21 06:32:11 +0100 | [diff] [blame] | 395 | dev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor), |
| 396 | le16_to_cpu(usb_dev->descriptor.idProduct)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 397 | spin_lock_init(&dev->spinlock); |
Daniel Mack | 563c2bf | 2009-07-02 10:46:35 +0200 | [diff] [blame] | 398 | snd_card_set_dev(card, &intf->dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 399 | |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 400 | *cardp = card; |
| 401 | return 0; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Sam Ravnborg | c598195 | 2008-02-22 18:46:47 +0100 | [diff] [blame] | 404 | static int __devinit init_card(struct snd_usb_caiaqdev *dev) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 405 | { |
Daniel Mack | bafeee5 | 2009-06-02 12:36:39 +0200 | [diff] [blame] | 406 | char *c, usbpath[32]; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 407 | struct usb_device *usb_dev = dev->chip.dev; |
| 408 | struct snd_card *card = dev->chip.card; |
Daniel Mack | bafeee5 | 2009-06-02 12:36:39 +0200 | [diff] [blame] | 409 | int err, len; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 410 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 411 | if (usb_set_interface(usb_dev, 0, 1) != 0) { |
| 412 | log("can't set alt interface.\n"); |
| 413 | return -EIO; |
| 414 | } |
| 415 | |
| 416 | usb_init_urb(&dev->ep1_in_urb); |
| 417 | usb_init_urb(&dev->midi_out_urb); |
| 418 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 419 | usb_fill_bulk_urb(&dev->ep1_in_urb, usb_dev, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 420 | usb_rcvbulkpipe(usb_dev, 0x1), |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 421 | dev->ep1_in_buf, EP1_BUFSIZE, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 422 | usb_ep1_command_reply_dispatch, dev); |
| 423 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 424 | usb_fill_bulk_urb(&dev->midi_out_urb, usb_dev, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 425 | usb_sndbulkpipe(usb_dev, 0x1), |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 426 | dev->midi_out_buf, EP1_BUFSIZE, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 427 | snd_usb_caiaq_midi_output_done, dev); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 428 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 429 | init_waitqueue_head(&dev->ep1_wait_queue); |
| 430 | init_waitqueue_head(&dev->prepare_wait_queue); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 431 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 432 | if (usb_submit_urb(&dev->ep1_in_urb, GFP_KERNEL) != 0) |
| 433 | return -EIO; |
| 434 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 435 | err = snd_usb_caiaq_send_command(dev, EP1_CMD_GET_DEVICE_INFO, NULL, 0); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 436 | if (err) |
| 437 | return err; |
| 438 | |
| 439 | if (!wait_event_timeout(dev->ep1_wait_queue, dev->spec_received, HZ)) |
| 440 | return -ENODEV; |
| 441 | |
| 442 | usb_string(usb_dev, usb_dev->descriptor.iManufacturer, |
| 443 | dev->vendor_name, CAIAQ_USB_STR_LEN); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 444 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 445 | usb_string(usb_dev, usb_dev->descriptor.iProduct, |
| 446 | dev->product_name, CAIAQ_USB_STR_LEN); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 447 | |
Daniel Mack | d3873a1 | 2009-06-01 21:36:25 +0200 | [diff] [blame] | 448 | strlcpy(card->driver, MODNAME, sizeof(card->driver)); |
| 449 | strlcpy(card->shortname, dev->product_name, sizeof(card->shortname)); |
Daniel Mack | 955f2d9 | 2009-06-10 21:32:01 +0200 | [diff] [blame] | 450 | strlcpy(card->mixername, dev->product_name, sizeof(card->mixername)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 451 | |
Daniel Mack | bafeee5 | 2009-06-02 12:36:39 +0200 | [diff] [blame] | 452 | /* if the id was not passed as module option, fill it with a shortened |
| 453 | * version of the product string which does not contain any |
| 454 | * whitespaces */ |
| 455 | |
| 456 | if (*card->id == '\0') { |
| 457 | char id[sizeof(card->id)]; |
| 458 | |
| 459 | memset(id, 0, sizeof(id)); |
| 460 | |
| 461 | for (c = card->shortname, len = 0; |
| 462 | *c && len < sizeof(card->id); c++) |
| 463 | if (*c != ' ') |
| 464 | id[len++] = *c; |
| 465 | |
| 466 | snd_card_set_id(card, id); |
| 467 | } |
| 468 | |
Daniel Mack | 1a1df6f | 2009-06-01 21:36:26 +0200 | [diff] [blame] | 469 | usb_make_path(usb_dev, usbpath, sizeof(usbpath)); |
| 470 | snprintf(card->longname, sizeof(card->longname), |
| 471 | "%s %s (%s)", |
| 472 | dev->vendor_name, dev->product_name, usbpath); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 473 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 474 | setup_card(dev); |
| 475 | return 0; |
| 476 | } |
| 477 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 478 | static int __devinit snd_probe(struct usb_interface *intf, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 479 | const struct usb_device_id *id) |
| 480 | { |
| 481 | int ret; |
| 482 | struct snd_card *card; |
| 483 | struct usb_device *device = interface_to_usbdev(intf); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 484 | |
Daniel Mack | 563c2bf | 2009-07-02 10:46:35 +0200 | [diff] [blame] | 485 | ret = create_card(device, intf, &card); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 486 | |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 487 | if (ret < 0) |
| 488 | return ret; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 489 | |
Julia Lawall | f4e9749 | 2009-01-01 18:14:35 +0100 | [diff] [blame] | 490 | usb_set_intfdata(intf, card); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 491 | ret = init_card(caiaqdev(card)); |
| 492 | if (ret < 0) { |
| 493 | log("unable to init card! (ret=%d)\n", ret); |
| 494 | snd_card_free(card); |
| 495 | return ret; |
| 496 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 497 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | static void snd_disconnect(struct usb_interface *intf) |
| 502 | { |
| 503 | struct snd_usb_caiaqdev *dev; |
Julia Lawall | f4e9749 | 2009-01-01 18:14:35 +0100 | [diff] [blame] | 504 | struct snd_card *card = usb_get_intfdata(intf); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 505 | |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 506 | debug("%s(%p)\n", __func__, intf); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 507 | |
| 508 | if (!card) |
| 509 | return; |
| 510 | |
| 511 | dev = caiaqdev(card); |
| 512 | snd_card_disconnect(card); |
| 513 | |
| 514 | #ifdef CONFIG_SND_USB_CAIAQ_INPUT |
| 515 | snd_usb_caiaq_input_free(dev); |
| 516 | #endif |
| 517 | snd_usb_caiaq_audio_free(dev); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 518 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 519 | usb_kill_urb(&dev->ep1_in_urb); |
| 520 | usb_kill_urb(&dev->midi_out_urb); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 521 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 522 | snd_card_free(card); |
| 523 | usb_reset_device(interface_to_usbdev(intf)); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | MODULE_DEVICE_TABLE(usb, snd_usb_id_table); |
| 528 | static struct usb_driver snd_usb_driver = { |
| 529 | .name = MODNAME, |
| 530 | .probe = snd_probe, |
| 531 | .disconnect = snd_disconnect, |
| 532 | .id_table = snd_usb_id_table, |
| 533 | }; |
| 534 | |
| 535 | static int __init snd_module_init(void) |
| 536 | { |
| 537 | return usb_register(&snd_usb_driver); |
| 538 | } |
| 539 | |
| 540 | static void __exit snd_module_exit(void) |
| 541 | { |
| 542 | usb_deregister(&snd_usb_driver); |
| 543 | } |
| 544 | |
| 545 | module_init(snd_module_init) |
| 546 | module_exit(snd_module_exit) |
| 547 | |