2 * usbus428.c - ALSA USB US-428 Driver
4 2004-07-13 Karsten Wiese
6 Don't sleep in START/STOP callbacks anymore.
7 us428 channels C/D not handled just for this version, sorry.
9 2004-06-21 Karsten Wiese
11 Temporarely suspend midi input
12 to sanely call usb_set_interface() when setting format.
14 2004-06-12 Karsten Wiese
16 Made it thus the following rule is enforced:
17 "All pcm substreams of one usX2Y have to operate at the same rate & format."
19 2004-04-06 Karsten Wiese
21 Runs on 2.6.5 kernel without any "--with-debug=" things.
22 us224 reported running.
24 2004-01-14 Karsten Wiese
26 Runs with 2.6.1 kernel.
28 2003-12-30 Karsten Wiese
30 Fix 24Bit 4Channel capturing for the us428.
32 2003-11-27 Karsten Wiese, Martin Langer
35 us224 could be tested by uncommenting the sections containing USB_ID_US224
37 2003-11-03 Karsten Wiese
40 "arecord -D hw:1 -c 2 -r 48000 -M -f S24_3LE|aplay -D hw:1 -c 2 -r 48000 -M -f S24_3LE" works.
42 2003-08-22 Karsten Wiese
44 Removed EZUSB Firmware. First Stage Firmwaredownload is now done by tascam-firmware downloader.
46 http://usb-midi-fw.sourceforge.net/tascam-firmware.tar.gz
48 2003-06-18 Karsten Wiese
50 changed to compile with kernel 2.4.21 and alsa 0.9.4
52 2002-10-16 Karsten Wiese
54 compiles again with alsa-current.
55 USB_ISO_ASAP not used anymore (most of the time), instead
56 urb->start_frame is calculated here now, some calls inside usb-driver don't need to happen anymore.
58 To get the best out of this:
59 Disable APM-support in the kernel as APM-BIOS calls (once each second) hard disable interrupt for many precious milliseconds.
60 This helped me much on my slowish PII 400 & PIII 500.
61 ACPI yet untested but might cause the same bad behaviour.
62 Use a kernel with lowlatency and preemptiv patches applied.
63 To autoload snd-usb-midi append a line
64 post-install snd-usb-us428 modprobe snd-usb-midi
68 sliders, knobs, lights not yet handled except MASTER Volume slider.
69 "pcm -c 2" doesn't work. "pcm -c 2 -m direct_interleaved" does.
70 KDE3: "Enable full duplex operation" deadlocks.
73 2002-08-31 Karsten Wiese
74 Version 0.0.3: audio also simplex;
75 simplifying: iso urbs only 1 packet, melted structs.
76 ASYNC_UNLINK not used anymore: no more crashes so far.....
79 2002-08-09 Karsten Wiese
80 Version 0.0.2: midi works with snd-usb-midi, audio (only fullduplex now) with i.e. bristol.
81 The firmware has been sniffed from win2k us-428 driver 3.09.
83 * Copyright (c) 2002 Karsten Wiese
85 * This program is free software; you can redistribute it and/or modify
86 * it under the terms of the GNU General Public License as published by
87 * the Free Software Foundation; either version 2 of the License, or
88 * (at your option) any later version.
90 * This program is distributed in the hope that it will be useful,
91 * but WITHOUT ANY WARRANTY; without even the implied warranty of
92 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93 * GNU General Public License for more details.
95 * You should have received a copy of the GNU General Public License
96 * along with this program; if not, write to the Free Software
97 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
100 #include <sound/driver.h>
101 #include <linux/init.h>
102 #include <linux/module.h>
103 #include <linux/moduleparam.h>
104 #include <linux/interrupt.h>
105 #include <linux/usb.h>
106 #include <sound/core.h>
107 #include <sound/initval.h>
108 #include <sound/pcm.h>
110 #include <sound/rawmidi.h>
112 #include "usbusx2y.h"
113 #include "usX2Yhwdep.h"
117 MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
118 MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.7.2");
119 MODULE_LICENSE("GPL");
120 MODULE_SUPPORTED_DEVICE("{{TASCAM(0x1604), "NAME_ALLCAPS"(0x8001)(0x8005)(0x8007) }}");
122 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
123 static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
124 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
125 static int boot_devs;
127 module_param_array(index, int, boot_devs, 0444);
128 MODULE_PARM_DESC(index, "Index value for "NAME_ALLCAPS".");
129 module_param_array(id, charp, boot_devs, 0444);
130 MODULE_PARM_DESC(id, "ID string for "NAME_ALLCAPS".");
131 module_param_array(enable, bool, boot_devs, 0444);
132 MODULE_PARM_DESC(enable, "Enable "NAME_ALLCAPS".");
135 static int snd_usX2Y_card_used[SNDRV_CARDS];
137 static void usX2Y_usb_disconnect(struct usb_device* usb_device, void* ptr);
138 static void snd_usX2Y_card_private_free(snd_card_t *card);
141 * pipe 4 is used for switching the lamps, setting samplerate, volumes ....
143 static void i_usX2Y_Out04Int(struct urb* urb, struct pt_regs *regs)
145 #ifdef CONFIG_SND_DEBUG
148 usX2Ydev_t* usX2Y = urb->context;
149 for (i = 0; i < 10 && usX2Y->AS04.urb[i] != urb; i++);
150 snd_printdd("i_usX2Y_Out04Int() urb %i status=%i\n", i, urb->status);
155 static void i_usX2Y_In04Int(struct urb* urb, struct pt_regs *regs)
158 usX2Ydev_t *usX2Y = urb->context;
159 us428ctls_sharedmem_t *us428ctls = usX2Y->us428ctls_sharedmem;
161 usX2Y->In04IntCalls++;
164 snd_printdd("Interrupt Pipe 4 came back with status=%i\n", urb->status);
168 // printk("%i:0x%02X ", 8, (int)((unsigned char*)usX2Y->In04Buf)[8]); Master volume shows 0 here if fader is at max during boot ?!?
171 if (-2 == us428ctls->CtlSnapShotLast) {
173 memcpy(usX2Y->In04Last, usX2Y->In04Buf, sizeof(usX2Y->In04Last));
174 us428ctls->CtlSnapShotLast = -1;
177 for (i = 0; i < 21; i++) {
178 if (usX2Y->In04Last[i] != ((char*)usX2Y->In04Buf)[i]) {
181 usX2Y->In04Last[i] = ((char*)usX2Y->In04Buf)[i];
186 int n = us428ctls->CtlSnapShotLast + 1;
187 if (n >= N_us428_ctl_BUFS || n < 0)
189 memcpy(us428ctls->CtlSnapShot + n, usX2Y->In04Buf, sizeof(us428ctls->CtlSnapShot[0]));
190 us428ctls->CtlSnapShotDiffersAt[n] = diff;
191 us428ctls->CtlSnapShotLast = n;
192 wake_up(&usX2Y->us428ctls_wait_queue_head);
198 if (0 == usX2Y->US04->submitted)
200 err = usb_submit_urb(usX2Y->US04->urb[usX2Y->US04->submitted++], GFP_ATOMIC);
201 while (!err && usX2Y->US04->submitted < usX2Y->US04->len);
203 if (us428ctls && us428ctls->p4outLast >= 0 && us428ctls->p4outLast < N_us428_p4out_BUFS) {
204 if (us428ctls->p4outLast != us428ctls->p4outSent) {
205 int j, send = us428ctls->p4outSent + 1;
206 if (send >= N_us428_p4out_BUFS)
208 for (j = 0; j < URBS_AsyncSeq && !err; ++j)
209 if (0 == usX2Y->AS04.urb[j]->status) {
210 us428_p4out_t *p4out = us428ctls->p4out + send; // FIXME if more then 1 p4out is new, 1 gets lost.
211 usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->chip.dev,
212 usb_sndbulkpipe(usX2Y->chip.dev, 0x04), &p4out->val.vol,
213 p4out->type == eLT_Light ? sizeof(us428_lights_t) : 5,
214 i_usX2Y_Out04Int, usX2Y);
215 err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC);
216 us428ctls->p4outSent = send;
223 snd_printk("In04Int() usb_submit_urb err=%i\n", err);
226 urb->dev = usX2Y->chip.dev;
227 usb_submit_urb(urb, GFP_ATOMIC);
233 int usX2Y_AsyncSeq04_init(usX2Ydev_t* usX2Y)
238 if (NULL == (usX2Y->AS04.buffer = kmalloc(URB_DataLen_AsyncSeq*URBS_AsyncSeq, GFP_KERNEL))) {
241 for (i = 0; i < URBS_AsyncSeq; ++i) {
242 if (NULL == (usX2Y->AS04.urb[i] = usb_alloc_urb(0, GFP_KERNEL))) {
246 usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->chip.dev,
247 usb_sndbulkpipe(usX2Y->chip.dev, 0x04),
248 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0,
249 i_usX2Y_Out04Int, usX2Y
255 int usX2Y_In04_init(usX2Ydev_t* usX2Y)
258 if (! (usX2Y->In04urb = usb_alloc_urb(0, GFP_KERNEL)))
261 if (! (usX2Y->In04Buf = kmalloc(21, GFP_KERNEL))) {
262 usb_free_urb(usX2Y->In04urb);
266 init_waitqueue_head(&usX2Y->In04WaitQueue);
267 usb_fill_int_urb(usX2Y->In04urb, usX2Y->chip.dev, usb_rcvintpipe(usX2Y->chip.dev, 0x4),
269 i_usX2Y_In04Int, usX2Y,
271 err = usb_submit_urb(usX2Y->In04urb, GFP_KERNEL);
275 static void usX2Y_unlinkSeq(snd_usX2Y_AsyncSeq_t* S)
278 for (i = 0; i < URBS_AsyncSeq; ++i) {
280 usb_unlink_urb(S->urb[i]);
281 usb_free_urb(S->urb[i]);
290 static struct usb_device_id snd_usX2Y_usb_id_table[] = {
292 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
294 .idProduct = USB_ID_US428
297 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
299 .idProduct = USB_ID_US122
302 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
304 .idProduct = USB_ID_US224
309 static snd_card_t* usX2Y_create_card(struct usb_device* device)
313 for (dev = 0; dev < SNDRV_CARDS; ++dev)
314 if (enable[dev] && !snd_usX2Y_card_used[dev])
316 if (dev >= SNDRV_CARDS)
318 card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(usX2Ydev_t));
321 snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1;
322 card->private_free = snd_usX2Y_card_private_free;
323 usX2Y(card)->chip.dev = device;
324 usX2Y(card)->chip.card = card;
325 init_MUTEX (&usX2Y(card)->open_mutex);
326 INIT_LIST_HEAD(&usX2Y(card)->chip.midi_list);
327 strcpy(card->driver, "USB "NAME_ALLCAPS"");
328 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
329 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
331 device->descriptor.idVendor, device->descriptor.idProduct,
332 0,//us428(card)->usbmidi.ifnum,
333 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum
335 snd_card_set_dev(card, &device->dev);
340 static void* usX2Y_usb_probe(struct usb_device* device, struct usb_interface *intf, const struct usb_device_id* device_id)
344 if (device->descriptor.idVendor != 0x1604 ||
345 (device->descriptor.idProduct != USB_ID_US122 &&
346 device->descriptor.idProduct != USB_ID_US224 &&
347 device->descriptor.idProduct != USB_ID_US428) ||
348 !(card = usX2Y_create_card(device)))
350 if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
351 (err = snd_card_register(card)) < 0) {
359 * new 2.5 USB kernel API
361 static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id)
364 chip = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id);
366 dev_set_drvdata(&intf->dev, chip);
372 static void snd_usX2Y_disconnect(struct usb_interface *intf)
374 usX2Y_usb_disconnect(interface_to_usbdev(intf),
375 dev_get_drvdata(&intf->dev));
378 MODULE_DEVICE_TABLE(usb, snd_usX2Y_usb_id_table);
379 static struct usb_driver snd_usX2Y_usb_driver = {
380 .owner = THIS_MODULE,
381 .name = "snd-usb-usx2y",
382 .probe = snd_usX2Y_probe,
383 .disconnect = snd_usX2Y_disconnect,
384 .id_table = snd_usX2Y_usb_id_table,
387 static void snd_usX2Y_card_private_free(snd_card_t *card)
389 if (usX2Y(card)->In04Buf)
390 kfree(usX2Y(card)->In04Buf);
391 usb_free_urb(usX2Y(card)->In04urb);
392 if (usX2Y(card)->us428ctls_sharedmem)
393 snd_free_pages(usX2Y(card)->us428ctls_sharedmem, sizeof(*usX2Y(card)->us428ctls_sharedmem));
394 if (usX2Y(card)->chip.index >= 0 && usX2Y(card)->chip.index < SNDRV_CARDS)
395 snd_usX2Y_card_used[usX2Y(card)->chip.index] = 0;
401 static void usX2Y_usb_disconnect(struct usb_device* device, void* ptr)
404 usX2Ydev_t* usX2Y = usX2Y((snd_card_t*)ptr);
406 if (usX2Y->chip_status == USX2Y_STAT_CHIP_HUP) // on 2.6.1 kernel snd_usbmidi_disconnect()
407 return; // calls us back. better leave :-) .
408 usX2Y->chip.shutdown = 1;
409 usX2Y->chip_status = USX2Y_STAT_CHIP_HUP;
410 usX2Y_unlinkSeq(&usX2Y->AS04);
411 usb_unlink_urb(usX2Y->In04urb);
412 snd_card_disconnect((snd_card_t*)ptr);
413 /* release the midi resources */
414 list_for_each(p, &usX2Y->chip.midi_list) {
415 snd_usbmidi_disconnect(p, &snd_usX2Y_usb_driver);
417 if (usX2Y->us428ctls_sharedmem)
418 wake_up(&usX2Y->us428ctls_wait_queue_head);
419 snd_card_free_in_thread((snd_card_t*)ptr);
423 static int __init snd_usX2Y_module_init(void)
425 return usb_register(&snd_usX2Y_usb_driver);
428 static void __exit snd_usX2Y_module_exit(void)
430 usb_deregister(&snd_usX2Y_usb_driver);
433 module_init(snd_usX2Y_module_init)
434 module_exit(snd_usX2Y_module_exit)