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