sound: usxxx: cleanup chip field
[firefly-linux-kernel-4.4.55.git] / sound / usb / usx2y / us122l.c
1 /*
2  * Copyright (C) 2007, 2008 Karsten Wiese <fzu@wemgehoertderstaat.de>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <sound/core.h>
20 #include <sound/hwdep.h>
21 #include <sound/pcm.h>
22 #include <sound/initval.h>
23 #define MODNAME "US122L"
24 #include "usb_stream.c"
25 #include "../usbaudio.h"
26 #include "us122l.h"
27
28 MODULE_AUTHOR("Karsten Wiese <fzu@wemgehoertderstaat.de>");
29 MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.5");
30 MODULE_LICENSE("GPL");
31
32 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-max */
33 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* Id for this card */
34                                                         /* Enable this card */
35 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
36
37 module_param_array(index, int, NULL, 0444);
38 MODULE_PARM_DESC(index, "Index value for "NAME_ALLCAPS".");
39 module_param_array(id, charp, NULL, 0444);
40 MODULE_PARM_DESC(id, "ID string for "NAME_ALLCAPS".");
41 module_param_array(enable, bool, NULL, 0444);
42 MODULE_PARM_DESC(enable, "Enable "NAME_ALLCAPS".");
43
44 static int snd_us122l_card_used[SNDRV_CARDS];
45
46
47 static int us122l_create_usbmidi(struct snd_card *card)
48 {
49         static struct snd_usb_midi_endpoint_info quirk_data = {
50                 .out_ep = 4,
51                 .in_ep = 3,
52                 .out_cables =   0x001,
53                 .in_cables =    0x001
54         };
55         static struct snd_usb_audio_quirk quirk = {
56                 .vendor_name =  "US122L",
57                 .product_name = NAME_ALLCAPS,
58                 .ifnum =        1,
59                 .type = QUIRK_MIDI_US122L,
60                 .data = &quirk_data
61         };
62         struct usb_device *dev = US122L(card)->dev;
63         struct usb_interface *iface = usb_ifnum_to_if(dev, 1);
64
65         return snd_usbmidi_create(card, iface,
66                                   &US122L(card)->midi_list, &quirk);
67 }
68
69 static int us144_create_usbmidi(struct snd_card *card)
70 {
71         static struct snd_usb_midi_endpoint_info quirk_data = {
72                 .out_ep = 4,
73                 .in_ep = 3,
74                 .out_cables =   0x001,
75                 .in_cables =    0x001
76         };
77         static struct snd_usb_audio_quirk quirk = {
78                 .vendor_name =  "US144",
79                 .product_name = NAME_ALLCAPS,
80                 .ifnum =        0,
81                 .type = QUIRK_MIDI_US122L,
82                 .data = &quirk_data
83         };
84         struct usb_device *dev = US122L(card)->dev;
85         struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
86
87         return snd_usbmidi_create(card, iface,
88                                   &US122L(card)->midi_list, &quirk);
89 }
90
91 /*
92  * Wrapper for usb_control_msg().
93  * Allocates a temp buffer to prevent dmaing from/to the stack.
94  */
95 static int us122l_ctl_msg(struct usb_device *dev, unsigned int pipe,
96                           __u8 request, __u8 requesttype,
97                           __u16 value, __u16 index, void *data,
98                           __u16 size, int timeout)
99 {
100         int err;
101         void *buf = NULL;
102
103         if (size > 0) {
104                 buf = kmemdup(data, size, GFP_KERNEL);
105                 if (!buf)
106                         return -ENOMEM;
107         }
108         err = usb_control_msg(dev, pipe, request, requesttype,
109                               value, index, buf, size, timeout);
110         if (size > 0) {
111                 memcpy(data, buf, size);
112                 kfree(buf);
113         }
114         return err;
115 }
116
117 static void pt_info_set(struct usb_device *dev, u8 v)
118 {
119         int ret;
120
121         ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
122                               'I',
123                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
124                               v, 0, NULL, 0, 1000);
125         snd_printdd(KERN_DEBUG "%i\n", ret);
126 }
127
128 static void usb_stream_hwdep_vm_open(struct vm_area_struct *area)
129 {
130         struct us122l *us122l = area->vm_private_data;
131         atomic_inc(&us122l->mmap_count);
132         snd_printdd(KERN_DEBUG "%i\n", atomic_read(&us122l->mmap_count));
133 }
134
135 static int usb_stream_hwdep_vm_fault(struct vm_area_struct *area,
136                                      struct vm_fault *vmf)
137 {
138         unsigned long offset;
139         struct page *page;
140         void *vaddr;
141         struct us122l *us122l = area->vm_private_data;
142         struct usb_stream *s;
143
144         mutex_lock(&us122l->mutex);
145         s = us122l->sk.s;
146         if (!s)
147                 goto unlock;
148
149         offset = vmf->pgoff << PAGE_SHIFT;
150         if (offset < PAGE_ALIGN(s->read_size))
151                 vaddr = (char *)s + offset;
152         else {
153                 offset -= PAGE_ALIGN(s->read_size);
154                 if (offset >= PAGE_ALIGN(s->write_size))
155                         goto unlock;
156
157                 vaddr = us122l->sk.write_page + offset;
158         }
159         page = virt_to_page(vaddr);
160
161         get_page(page);
162         mutex_unlock(&us122l->mutex);
163
164         vmf->page = page;
165
166         return 0;
167 unlock:
168         mutex_unlock(&us122l->mutex);
169         return VM_FAULT_SIGBUS;
170 }
171
172 static void usb_stream_hwdep_vm_close(struct vm_area_struct *area)
173 {
174         struct us122l *us122l = area->vm_private_data;
175         atomic_dec(&us122l->mmap_count);
176         snd_printdd(KERN_DEBUG "%i\n", atomic_read(&us122l->mmap_count));
177 }
178
179 static const struct vm_operations_struct usb_stream_hwdep_vm_ops = {
180         .open = usb_stream_hwdep_vm_open,
181         .fault = usb_stream_hwdep_vm_fault,
182         .close = usb_stream_hwdep_vm_close,
183 };
184
185
186 static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
187 {
188         struct us122l   *us122l = hw->private_data;
189         struct usb_interface *iface;
190         snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
191         if (hw->used >= 2)
192                 return -EBUSY;
193
194         if (!us122l->first)
195                 us122l->first = file;
196
197         if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
198                 iface = usb_ifnum_to_if(us122l->dev, 0);
199                 usb_autopm_get_interface(iface);
200         }
201         iface = usb_ifnum_to_if(us122l->dev, 1);
202         usb_autopm_get_interface(iface);
203         return 0;
204 }
205
206 static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file)
207 {
208         struct us122l   *us122l = hw->private_data;
209         struct usb_interface *iface;
210         snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
211
212         if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
213                 iface = usb_ifnum_to_if(us122l->dev, 0);
214                 usb_autopm_put_interface(iface);
215         }
216         iface = usb_ifnum_to_if(us122l->dev, 1);
217         usb_autopm_put_interface(iface);
218         if (us122l->first == file)
219                 us122l->first = NULL;
220         mutex_lock(&us122l->mutex);
221         if (us122l->master == file)
222                 us122l->master = us122l->slave;
223
224         us122l->slave = NULL;
225         mutex_unlock(&us122l->mutex);
226         return 0;
227 }
228
229 static int usb_stream_hwdep_mmap(struct snd_hwdep *hw,
230                                  struct file *filp, struct vm_area_struct *area)
231 {
232         unsigned long   size = area->vm_end - area->vm_start;
233         struct us122l   *us122l = hw->private_data;
234         unsigned long offset;
235         struct usb_stream *s;
236         int err = 0;
237         bool read;
238
239         offset = area->vm_pgoff << PAGE_SHIFT;
240         mutex_lock(&us122l->mutex);
241         s = us122l->sk.s;
242         read = offset < s->read_size;
243         if (read && area->vm_flags & VM_WRITE) {
244                 err = -EPERM;
245                 goto out;
246         }
247         snd_printdd(KERN_DEBUG "%lu %u\n", size,
248                     read ? s->read_size : s->write_size);
249         /* if userspace tries to mmap beyond end of our buffer, fail */
250         if (size > PAGE_ALIGN(read ? s->read_size : s->write_size)) {
251                 snd_printk(KERN_WARNING "%lu > %u\n", size,
252                            read ? s->read_size : s->write_size);
253                 err = -EINVAL;
254                 goto out;
255         }
256
257         area->vm_ops = &usb_stream_hwdep_vm_ops;
258         area->vm_flags |= VM_RESERVED;
259         area->vm_private_data = us122l;
260         atomic_inc(&us122l->mmap_count);
261 out:
262         mutex_unlock(&us122l->mutex);
263         return err;
264 }
265
266 static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
267                                           struct file *file, poll_table *wait)
268 {
269         struct us122l   *us122l = hw->private_data;
270         struct usb_stream *s = us122l->sk.s;
271         unsigned        *polled;
272         unsigned int    mask;
273
274         poll_wait(file, &us122l->sk.sleep, wait);
275
276         switch (s->state) {
277         case usb_stream_ready:
278                 if (us122l->first == file)
279                         polled = &s->periods_polled;
280                 else
281                         polled = &us122l->second_periods_polled;
282                 if (*polled != s->periods_done) {
283                         *polled = s->periods_done;
284                         mask = POLLIN | POLLOUT | POLLWRNORM;
285                         break;
286                 }
287                 /* Fall through */
288                 mask = 0;
289                 break;
290         default:
291                 mask = POLLIN | POLLOUT | POLLWRNORM | POLLERR;
292                 break;
293         }
294         return mask;
295 }
296
297 static void us122l_stop(struct us122l *us122l)
298 {
299         struct list_head *p;
300         list_for_each(p, &us122l->midi_list)
301                 snd_usbmidi_input_stop(p);
302
303         usb_stream_stop(&us122l->sk);
304         usb_stream_free(&us122l->sk);
305 }
306
307 static int us122l_set_sample_rate(struct usb_device *dev, int rate)
308 {
309         unsigned int ep = 0x81;
310         unsigned char data[3];
311         int err;
312
313         data[0] = rate;
314         data[1] = rate >> 8;
315         data[2] = rate >> 16;
316         err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
317                              USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
318                              SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000);
319         if (err < 0)
320                 snd_printk(KERN_ERR "%d: cannot set freq %d to ep 0x%x\n",
321                            dev->devnum, rate, ep);
322         return err;
323 }
324
325 static bool us122l_start(struct us122l *us122l,
326                          unsigned rate, unsigned period_frames)
327 {
328         struct list_head *p;
329         int err;
330         unsigned use_packsize = 0;
331         bool success = false;
332
333         if (us122l->dev->speed == USB_SPEED_HIGH) {
334                 /* The us-122l's descriptor defaults to iso max_packsize 78,
335                    which isn't needed for samplerates <= 48000.
336                    Lets save some memory:
337                 */
338                 switch (rate) {
339                 case 44100:
340                         use_packsize = 36;
341                         break;
342                 case 48000:
343                         use_packsize = 42;
344                         break;
345                 case 88200:
346                         use_packsize = 72;
347                         break;
348                 }
349         }
350         if (!usb_stream_new(&us122l->sk, us122l->dev, 1, 2,
351                             rate, use_packsize, period_frames, 6))
352                 goto out;
353
354         err = us122l_set_sample_rate(us122l->dev, rate);
355         if (err < 0) {
356                 us122l_stop(us122l);
357                 snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
358                 goto out;
359         }
360         err = usb_stream_start(&us122l->sk);
361         if (err < 0) {
362                 us122l_stop(us122l);
363                 snd_printk(KERN_ERR "us122l_start error %i \n", err);
364                 goto out;
365         }
366         list_for_each(p, &us122l->midi_list)
367                 snd_usbmidi_input_start(p);
368         success = true;
369 out:
370         return success;
371 }
372
373 static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
374                                   unsigned cmd, unsigned long arg)
375 {
376         struct usb_stream_config *cfg;
377         struct us122l *us122l = hw->private_data;
378         unsigned min_period_frames;
379         int err = 0;
380         bool high_speed;
381
382         if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS)
383                 return -ENOTTY;
384
385         cfg = memdup_user((void *)arg, sizeof(*cfg));
386         if (IS_ERR(cfg))
387                 return PTR_ERR(cfg);
388
389         if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
390                 err = -ENXIO;
391                 goto free;
392         }
393         high_speed = us122l->dev->speed == USB_SPEED_HIGH;
394         if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000  &&
395              (!high_speed ||
396               (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) ||
397             cfg->frame_size != 6 ||
398             cfg->period_frames > 0x3000) {
399                 err = -EINVAL;
400                 goto free;
401         }
402         switch (cfg->sample_rate) {
403         case 44100:
404                 min_period_frames = 48;
405                 break;
406         case 48000:
407                 min_period_frames = 52;
408                 break;
409         default:
410                 min_period_frames = 104;
411                 break;
412         }
413         if (!high_speed)
414                 min_period_frames <<= 1;
415         if (cfg->period_frames < min_period_frames) {
416                 err = -EINVAL;
417                 goto free;
418         }
419
420         snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
421
422         mutex_lock(&us122l->mutex);
423         if (!us122l->master)
424                 us122l->master = file;
425         else if (us122l->master != file) {
426                 if (memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg))) {
427                         err = -EIO;
428                         goto unlock;
429                 }
430                 us122l->slave = file;
431         }
432         if (!us122l->sk.s ||
433             memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg)) ||
434             us122l->sk.s->state == usb_stream_xrun) {
435                 us122l_stop(us122l);
436                 if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames))
437                         err = -EIO;
438                 else
439                         err = 1;
440         }
441 unlock:
442         mutex_unlock(&us122l->mutex);
443 free:
444         kfree(cfg);
445         return err;
446 }
447
448 #define SND_USB_STREAM_ID "USB STREAM"
449 static int usb_stream_hwdep_new(struct snd_card *card)
450 {
451         int err;
452         struct snd_hwdep *hw;
453         struct usb_device *dev = US122L(card)->dev;
454
455         err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw);
456         if (err < 0)
457                 return err;
458
459         hw->iface = SNDRV_HWDEP_IFACE_USB_STREAM;
460         hw->private_data = US122L(card);
461         hw->ops.open = usb_stream_hwdep_open;
462         hw->ops.release = usb_stream_hwdep_release;
463         hw->ops.ioctl = usb_stream_hwdep_ioctl;
464         hw->ops.ioctl_compat = usb_stream_hwdep_ioctl;
465         hw->ops.mmap = usb_stream_hwdep_mmap;
466         hw->ops.poll = usb_stream_hwdep_poll;
467
468         sprintf(hw->name, "/proc/bus/usb/%03d/%03d/hwdeppcm",
469                 dev->bus->busnum, dev->devnum);
470         return 0;
471 }
472
473
474 static bool us122l_create_card(struct snd_card *card)
475 {
476         int err;
477         struct us122l *us122l = US122L(card);
478
479         if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
480                 err = usb_set_interface(us122l->dev, 0, 1);
481                 if (err) {
482                         snd_printk(KERN_ERR "usb_set_interface error \n");
483                         return false;
484                 }
485         }
486         err = usb_set_interface(us122l->dev, 1, 1);
487         if (err) {
488                 snd_printk(KERN_ERR "usb_set_interface error \n");
489                 return false;
490         }
491
492         pt_info_set(us122l->dev, 0x11);
493         pt_info_set(us122l->dev, 0x10);
494
495         if (!us122l_start(us122l, 44100, 256))
496                 return false;
497
498         if (us122l->dev->descriptor.idProduct == USB_ID_US144)
499                 err = us144_create_usbmidi(card);
500         else
501                 err = us122l_create_usbmidi(card);
502         if (err < 0) {
503                 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err);
504                 us122l_stop(us122l);
505                 return false;
506         }
507         err = usb_stream_hwdep_new(card);
508         if (err < 0) {
509 /* release the midi resources */
510                 struct list_head *p;
511                 list_for_each(p, &us122l->midi_list)
512                         snd_usbmidi_disconnect(p);
513
514                 us122l_stop(us122l);
515                 return false;
516         }
517         return true;
518 }
519
520 static void snd_us122l_free(struct snd_card *card)
521 {
522         struct us122l   *us122l = US122L(card);
523         int             index = us122l->card_index;
524         if (index >= 0  &&  index < SNDRV_CARDS)
525                 snd_us122l_card_used[index] = 0;
526 }
527
528 static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
529 {
530         int             dev;
531         struct snd_card *card;
532         int err;
533
534         for (dev = 0; dev < SNDRV_CARDS; ++dev)
535                 if (enable[dev] && !snd_us122l_card_used[dev])
536                         break;
537         if (dev >= SNDRV_CARDS)
538                 return -ENODEV;
539         err = snd_card_create(index[dev], id[dev], THIS_MODULE,
540                               sizeof(struct us122l), &card);
541         if (err < 0)
542                 return err;
543         snd_us122l_card_used[US122L(card)->card_index = dev] = 1;
544         card->private_free = snd_us122l_free;
545         US122L(card)->dev = device;
546         mutex_init(&US122L(card)->mutex);
547         init_waitqueue_head(&US122L(card)->sk.sleep);
548         INIT_LIST_HEAD(&US122L(card)->midi_list);
549         strcpy(card->driver, "USB "NAME_ALLCAPS"");
550         sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
551         sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
552                 card->shortname,
553                 le16_to_cpu(device->descriptor.idVendor),
554                 le16_to_cpu(device->descriptor.idProduct),
555                 0,
556                 US122L(card)->dev->bus->busnum,
557                 US122L(card)->dev->devnum
558                 );
559         *cardp = card;
560         return 0;
561 }
562
563 static int us122l_usb_probe(struct usb_interface *intf,
564                             const struct usb_device_id *device_id,
565                             struct snd_card **cardp)
566 {
567         struct usb_device *device = interface_to_usbdev(intf);
568         struct snd_card *card;
569         int err;
570
571         err = usx2y_create_card(device, &card);
572         if (err < 0)
573                 return err;
574
575         snd_card_set_dev(card, &intf->dev);
576         if (!us122l_create_card(card)) {
577                 snd_card_free(card);
578                 return -EINVAL;
579         }
580
581         err = snd_card_register(card);
582         if (err < 0) {
583                 snd_card_free(card);
584                 return err;
585         }
586
587         usb_get_intf(usb_ifnum_to_if(device, 0));
588         usb_get_dev(device);
589         *cardp = card;
590         return 0;
591 }
592
593 static int snd_us122l_probe(struct usb_interface *intf,
594                             const struct usb_device_id *id)
595 {
596         struct usb_device *device = interface_to_usbdev(intf);
597         struct snd_card *card;
598         int err;
599
600         if (device->descriptor.idProduct == USB_ID_US144
601                 && device->speed == USB_SPEED_HIGH) {
602                 snd_printk(KERN_ERR "disable ehci-hcd to run US-144 \n");
603                 return -ENODEV;
604         }
605
606         snd_printdd(KERN_DEBUG"%p:%i\n",
607                     intf, intf->cur_altsetting->desc.bInterfaceNumber);
608         if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
609                 return 0;
610
611         err = us122l_usb_probe(usb_get_intf(intf), id, &card);
612         if (err < 0) {
613                 usb_put_intf(intf);
614                 return err;
615         }
616
617         usb_set_intfdata(intf, card);
618         return 0;
619 }
620
621 static void snd_us122l_disconnect(struct usb_interface *intf)
622 {
623         struct snd_card *card;
624         struct us122l *us122l;
625         struct list_head *p;
626
627         card = usb_get_intfdata(intf);
628         if (!card)
629                 return;
630
631         snd_card_disconnect(card);
632
633         us122l = US122L(card);
634         mutex_lock(&us122l->mutex);
635         us122l_stop(us122l);
636         mutex_unlock(&us122l->mutex);
637
638 /* release the midi resources */
639         list_for_each(p, &us122l->midi_list) {
640                 snd_usbmidi_disconnect(p);
641         }
642
643         usb_put_intf(usb_ifnum_to_if(us122l->dev, 0));
644         usb_put_intf(usb_ifnum_to_if(us122l->dev, 1));
645         usb_put_dev(us122l->dev);
646
647         while (atomic_read(&us122l->mmap_count))
648                 msleep(500);
649
650         snd_card_free(card);
651 }
652
653 static int snd_us122l_suspend(struct usb_interface *intf, pm_message_t message)
654 {
655         struct snd_card *card;
656         struct us122l *us122l;
657         struct list_head *p;
658
659         card = usb_get_intfdata(intf);
660         if (!card)
661                 return 0;
662         snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
663
664         us122l = US122L(card);
665         if (!us122l)
666                 return 0;
667
668         list_for_each(p, &us122l->midi_list)
669                 snd_usbmidi_input_stop(p);
670
671         mutex_lock(&us122l->mutex);
672         usb_stream_stop(&us122l->sk);
673         mutex_unlock(&us122l->mutex);
674
675         return 0;
676 }
677
678 static int snd_us122l_resume(struct usb_interface *intf)
679 {
680         struct snd_card *card;
681         struct us122l *us122l;
682         struct list_head *p;
683         int err;
684
685         card = usb_get_intfdata(intf);
686         if (!card)
687                 return 0;
688
689         us122l = US122L(card);
690         if (!us122l)
691                 return 0;
692
693         mutex_lock(&us122l->mutex);
694         /* needed, doesn't restart without: */
695         if (us122l->dev->descriptor.idProduct == USB_ID_US144) {
696                 err = usb_set_interface(us122l->dev, 0, 1);
697                 if (err) {
698                         snd_printk(KERN_ERR "usb_set_interface error \n");
699                         goto unlock;
700                 }
701         }
702         err = usb_set_interface(us122l->dev, 1, 1);
703         if (err) {
704                 snd_printk(KERN_ERR "usb_set_interface error \n");
705                 goto unlock;
706         }
707
708         pt_info_set(us122l->dev, 0x11);
709         pt_info_set(us122l->dev, 0x10);
710
711         err = us122l_set_sample_rate(us122l->dev,
712                                      us122l->sk.s->cfg.sample_rate);
713         if (err < 0) {
714                 snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
715                 goto unlock;
716         }
717         err = usb_stream_start(&us122l->sk);
718         if (err)
719                 goto unlock;
720
721         list_for_each(p, &us122l->midi_list)
722                 snd_usbmidi_input_start(p);
723 unlock:
724         mutex_unlock(&us122l->mutex);
725         snd_power_change_state(card, SNDRV_CTL_POWER_D0);
726         return err;
727 }
728
729 static struct usb_device_id snd_us122l_usb_id_table[] = {
730         {
731                 .match_flags =  USB_DEVICE_ID_MATCH_DEVICE,
732                 .idVendor =     0x0644,
733                 .idProduct =    USB_ID_US122L
734         },
735         {       /* US-144 only works at USB1.1! Disable module ehci-hcd. */
736                 .match_flags =  USB_DEVICE_ID_MATCH_DEVICE,
737                 .idVendor =     0x0644,
738                 .idProduct =    USB_ID_US144
739         },
740         { /* terminator */ }
741 };
742
743 MODULE_DEVICE_TABLE(usb, snd_us122l_usb_id_table);
744 static struct usb_driver snd_us122l_usb_driver = {
745         .name =         "snd-usb-us122l",
746         .probe =        snd_us122l_probe,
747         .disconnect =   snd_us122l_disconnect,
748         .suspend =      snd_us122l_suspend,
749         .resume =       snd_us122l_resume,
750         .reset_resume = snd_us122l_resume,
751         .id_table =     snd_us122l_usb_id_table,
752         .supports_autosuspend = 1
753 };
754
755
756 static int __init snd_us122l_module_init(void)
757 {
758         return usb_register(&snd_us122l_usb_driver);
759 }
760
761 static void __exit snd_us122l_module_exit(void)
762 {
763         usb_deregister(&snd_us122l_usb_driver);
764 }
765
766 module_init(snd_us122l_module_init)
767 module_exit(snd_us122l_module_exit)