1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120#include <linux/init.h>
121#include <linux/module.h>
122#include <linux/moduleparam.h>
123#include <linux/slab.h>
124#include <linux/interrupt.h>
125#include <linux/usb.h>
126#include <sound/core.h>
127#include <sound/initval.h>
128#include <sound/pcm.h>
129
130#include <sound/rawmidi.h>
131#include "usx2y.h"
132#include "usbusx2y.h"
133#include "usX2Yhwdep.h"
134
135
136
137MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
138MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.8.7.2");
139MODULE_LICENSE("GPL");
140MODULE_SUPPORTED_DEVICE("{{TASCAM(0x1604),"NAME_ALLCAPS"(0x8001)(0x8005)(0x8007)}}");
141
142static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
143static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
144static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
145
146module_param_array(index, int, NULL, 0444);
147MODULE_PARM_DESC(index, "Index value for "NAME_ALLCAPS".");
148module_param_array(id, charp, NULL, 0444);
149MODULE_PARM_DESC(id, "ID string for "NAME_ALLCAPS".");
150module_param_array(enable, bool, NULL, 0444);
151MODULE_PARM_DESC(enable, "Enable "NAME_ALLCAPS".");
152
153
154static int snd_usX2Y_card_used[SNDRV_CARDS];
155
156static void usX2Y_usb_disconnect(struct usb_device* usb_device, void* ptr);
157static void snd_usX2Y_card_private_free(struct snd_card *card);
158
159
160
161
162static void i_usX2Y_Out04Int(struct urb *urb)
163{
164#ifdef CONFIG_SND_DEBUG
165 if (urb->status) {
166 int i;
167 struct usX2Ydev *usX2Y = urb->context;
168 for (i = 0; i < 10 && usX2Y->AS04.urb[i] != urb; i++);
169 snd_printdd("i_usX2Y_Out04Int() urb %i status=%i\n", i, urb->status);
170 }
171#endif
172}
173
174static void i_usX2Y_In04Int(struct urb *urb)
175{
176 int err = 0;
177 struct usX2Ydev *usX2Y = urb->context;
178 struct us428ctls_sharedmem *us428ctls = usX2Y->us428ctls_sharedmem;
179
180 usX2Y->In04IntCalls++;
181
182 if (urb->status) {
183 snd_printdd("Interrupt Pipe 4 came back with status=%i\n", urb->status);
184 return;
185 }
186
187
188 if (us428ctls) {
189 int diff = -1;
190 if (-2 == us428ctls->CtlSnapShotLast) {
191 diff = 0;
192 memcpy(usX2Y->In04Last, usX2Y->In04Buf, sizeof(usX2Y->In04Last));
193 us428ctls->CtlSnapShotLast = -1;
194 } else {
195 int i;
196 for (i = 0; i < 21; i++) {
197 if (usX2Y->In04Last[i] != ((char*)usX2Y->In04Buf)[i]) {
198 if (diff < 0)
199 diff = i;
200 usX2Y->In04Last[i] = ((char*)usX2Y->In04Buf)[i];
201 }
202 }
203 }
204 if (0 <= diff) {
205 int n = us428ctls->CtlSnapShotLast + 1;
206 if (n >= N_us428_ctl_BUFS || n < 0)
207 n = 0;
208 memcpy(us428ctls->CtlSnapShot + n, usX2Y->In04Buf, sizeof(us428ctls->CtlSnapShot[0]));
209 us428ctls->CtlSnapShotDiffersAt[n] = diff;
210 us428ctls->CtlSnapShotLast = n;
211 wake_up(&usX2Y->us428ctls_wait_queue_head);
212 }
213 }
214
215
216 if (usX2Y->US04) {
217 if (0 == usX2Y->US04->submitted)
218 do {
219 err = usb_submit_urb(usX2Y->US04->urb[usX2Y->US04->submitted++], GFP_ATOMIC);
220 } while (!err && usX2Y->US04->submitted < usX2Y->US04->len);
221 } else
222 if (us428ctls && us428ctls->p4outLast >= 0 && us428ctls->p4outLast < N_us428_p4out_BUFS) {
223 if (us428ctls->p4outLast != us428ctls->p4outSent) {
224 int j, send = us428ctls->p4outSent + 1;
225 if (send >= N_us428_p4out_BUFS)
226 send = 0;
227 for (j = 0; j < URBS_AsyncSeq && !err; ++j)
228 if (0 == usX2Y->AS04.urb[j]->status) {
229 struct us428_p4out *p4out = us428ctls->p4out + send;
230 usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->dev,
231 usb_sndbulkpipe(usX2Y->dev, 0x04), &p4out->val.vol,
232 p4out->type == eLT_Light ? sizeof(struct us428_lights) : 5,
233 i_usX2Y_Out04Int, usX2Y);
234 err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC);
235 us428ctls->p4outSent = send;
236 break;
237 }
238 }
239 }
240
241 if (err)
242 snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err);
243
244 urb->dev = usX2Y->dev;
245 usb_submit_urb(urb, GFP_ATOMIC);
246}
247
248
249
250
251int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y)
252{
253 int err = 0,
254 i;
255
256 usX2Y->AS04.buffer = kmalloc_array(URBS_AsyncSeq,
257 URB_DataLen_AsyncSeq, GFP_KERNEL);
258 if (NULL == usX2Y->AS04.buffer) {
259 err = -ENOMEM;
260 } else
261 for (i = 0; i < URBS_AsyncSeq; ++i) {
262 if (NULL == (usX2Y->AS04.urb[i] = usb_alloc_urb(0, GFP_KERNEL))) {
263 err = -ENOMEM;
264 break;
265 }
266 usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->dev,
267 usb_sndbulkpipe(usX2Y->dev, 0x04),
268 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0,
269 i_usX2Y_Out04Int, usX2Y
270 );
271 err = usb_urb_ep_type_check(usX2Y->AS04.urb[i]);
272 if (err < 0)
273 break;
274 }
275 return err;
276}
277
278int usX2Y_In04_init(struct usX2Ydev *usX2Y)
279{
280 if (! (usX2Y->In04urb = usb_alloc_urb(0, GFP_KERNEL)))
281 return -ENOMEM;
282
283 if (! (usX2Y->In04Buf = kmalloc(21, GFP_KERNEL)))
284 return -ENOMEM;
285
286 init_waitqueue_head(&usX2Y->In04WaitQueue);
287 usb_fill_int_urb(usX2Y->In04urb, usX2Y->dev, usb_rcvintpipe(usX2Y->dev, 0x4),
288 usX2Y->In04Buf, 21,
289 i_usX2Y_In04Int, usX2Y,
290 10);
291 if (usb_urb_ep_type_check(usX2Y->In04urb))
292 return -EINVAL;
293 return usb_submit_urb(usX2Y->In04urb, GFP_KERNEL);
294}
295
296static void usX2Y_unlinkSeq(struct snd_usX2Y_AsyncSeq *S)
297{
298 int i;
299 for (i = 0; i < URBS_AsyncSeq; ++i) {
300 usb_kill_urb(S->urb[i]);
301 usb_free_urb(S->urb[i]);
302 S->urb[i] = NULL;
303 }
304 kfree(S->buffer);
305}
306
307
308static const struct usb_device_id snd_usX2Y_usb_id_table[] = {
309 {
310 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
311 .idVendor = 0x1604,
312 .idProduct = USB_ID_US428
313 },
314 {
315 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
316 .idVendor = 0x1604,
317 .idProduct = USB_ID_US122
318 },
319 {
320 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
321 .idVendor = 0x1604,
322 .idProduct = USB_ID_US224
323 },
324 { }
325};
326
327static int usX2Y_create_card(struct usb_device *device,
328 struct usb_interface *intf,
329 struct snd_card **cardp)
330{
331 int dev;
332 struct snd_card * card;
333 int err;
334
335 for (dev = 0; dev < SNDRV_CARDS; ++dev)
336 if (enable[dev] && !snd_usX2Y_card_used[dev])
337 break;
338 if (dev >= SNDRV_CARDS)
339 return -ENODEV;
340 err = snd_card_new(&intf->dev, index[dev], id[dev], THIS_MODULE,
341 sizeof(struct usX2Ydev), &card);
342 if (err < 0)
343 return err;
344 snd_usX2Y_card_used[usX2Y(card)->card_index = dev] = 1;
345 card->private_free = snd_usX2Y_card_private_free;
346 usX2Y(card)->dev = device;
347 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue);
348 mutex_init(&usX2Y(card)->pcm_mutex);
349 INIT_LIST_HEAD(&usX2Y(card)->midi_list);
350 strcpy(card->driver, "USB "NAME_ALLCAPS"");
351 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
352 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
353 card->shortname,
354 le16_to_cpu(device->descriptor.idVendor),
355 le16_to_cpu(device->descriptor.idProduct),
356 0,
357 usX2Y(card)->dev->bus->busnum, usX2Y(card)->dev->devnum
358 );
359 *cardp = card;
360 return 0;
361}
362
363
364static int usX2Y_usb_probe(struct usb_device *device,
365 struct usb_interface *intf,
366 const struct usb_device_id *device_id,
367 struct snd_card **cardp)
368{
369 int err;
370 struct snd_card * card;
371
372 *cardp = NULL;
373 if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 ||
374 (le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 &&
375 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 &&
376 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428))
377 return -EINVAL;
378
379 err = usX2Y_create_card(device, intf, &card);
380 if (err < 0)
381 return err;
382 if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
383 (err = snd_card_register(card)) < 0) {
384 snd_card_free(card);
385 return err;
386 }
387 *cardp = card;
388 return 0;
389}
390
391
392
393
394static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id)
395{
396 struct snd_card *card;
397 int err;
398
399 err = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id, &card);
400 if (err < 0)
401 return err;
402 dev_set_drvdata(&intf->dev, card);
403 return 0;
404}
405
406static void snd_usX2Y_disconnect(struct usb_interface *intf)
407{
408 usX2Y_usb_disconnect(interface_to_usbdev(intf),
409 usb_get_intfdata(intf));
410}
411
412MODULE_DEVICE_TABLE(usb, snd_usX2Y_usb_id_table);
413static struct usb_driver snd_usX2Y_usb_driver = {
414 .name = "snd-usb-usx2y",
415 .probe = snd_usX2Y_probe,
416 .disconnect = snd_usX2Y_disconnect,
417 .id_table = snd_usX2Y_usb_id_table,
418};
419
420static void snd_usX2Y_card_private_free(struct snd_card *card)
421{
422 kfree(usX2Y(card)->In04Buf);
423 usb_free_urb(usX2Y(card)->In04urb);
424 if (usX2Y(card)->us428ctls_sharedmem)
425 free_pages_exact(usX2Y(card)->us428ctls_sharedmem,
426 sizeof(*usX2Y(card)->us428ctls_sharedmem));
427 if (usX2Y(card)->card_index >= 0 && usX2Y(card)->card_index < SNDRV_CARDS)
428 snd_usX2Y_card_used[usX2Y(card)->card_index] = 0;
429}
430
431
432
433
434static void usX2Y_usb_disconnect(struct usb_device *device, void* ptr)
435{
436 if (ptr) {
437 struct snd_card *card = ptr;
438 struct usX2Ydev *usX2Y = usX2Y(card);
439 struct list_head *p;
440 usX2Y->chip_status = USX2Y_STAT_CHIP_HUP;
441 usX2Y_unlinkSeq(&usX2Y->AS04);
442 usb_kill_urb(usX2Y->In04urb);
443 snd_card_disconnect(card);
444
445 list_for_each(p, &usX2Y->midi_list) {
446 snd_usbmidi_disconnect(p);
447 }
448 if (usX2Y->us428ctls_sharedmem)
449 wake_up(&usX2Y->us428ctls_wait_queue_head);
450 snd_card_free(card);
451 }
452}
453
454module_usb_driver(snd_usX2Y_usb_driver);
455