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