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