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