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