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