19 #include <linux/slab.h>
21 #include <linux/usb/audio.h>
22 #include <linux/module.h>
27 #define MODNAME "US122L"
29 #include "../usbaudio.h"
67 struct usb_device *
dev =
US122L(card)->dev;
71 &
US122L(card)->midi_list, &quirk);
74 static int us144_create_usbmidi(
struct snd_card *card)
89 struct usb_device *dev =
US122L(card)->dev;
93 &
US122L(card)->midi_list, &quirk);
100 static int us122l_ctl_msg(
struct usb_device *dev,
unsigned int pipe,
114 value, index, buf, size, timeout);
122 static void pt_info_set(
struct usb_device *dev,
u8 v)
129 v, 0,
NULL, 0, 1000);
141 struct vm_fault *vmf)
156 vaddr = (
char *)s + offset;
162 vaddr = us122l->
sk.write_page +
offset;
174 return VM_FAULT_SIGBUS;
177 static void usb_stream_hwdep_vm_close(
struct vm_area_struct *area)
184 static const struct vm_operations_struct usb_stream_hwdep_vm_ops = {
185 .open = usb_stream_hwdep_vm_open,
186 .fault = usb_stream_hwdep_vm_fault,
187 .close = usb_stream_hwdep_vm_close,
205 usb_autopm_get_interface(iface);
208 usb_autopm_get_interface(iface);
212 static int usb_stream_hwdep_release(
struct snd_hwdep *hw,
struct file *file)
221 usb_autopm_put_interface(iface);
224 usb_autopm_put_interface(iface);
225 if (us122l->
first == file)
228 if (us122l->
master == file)
236 static int usb_stream_hwdep_mmap(
struct snd_hwdep *hw,
250 if (read && area->
vm_flags & VM_WRITE) {
264 area->
vm_ops = &usb_stream_hwdep_vm_ops;
265 area->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
273 static unsigned int usb_stream_hwdep_poll(
struct snd_hwdep *hw,
280 poll_wait(file, &us122l->
sk.sleep, wait);
286 if (us122l->
first == file)
301 static void us122l_stop(
struct us122l *us122l)
311 static
int us122l_set_sample_rate(
struct usb_device *dev,
int rate)
313 unsigned int ep = 0x81;
314 unsigned char data[3];
319 data[2] = rate >> 16;
320 err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
UAC_SET_CUR,
325 dev->devnum, rate, ep);
329 static bool us122l_start(
struct us122l *us122l,
330 unsigned rate,
unsigned period_frames)
334 unsigned use_packsize = 0;
335 bool success =
false;
355 rate, use_packsize, period_frames, 6))
358 err = us122l_set_sample_rate(us122l->
dev, rate);
378 unsigned cmd,
unsigned long arg)
381 struct us122l *us122l = hw->private_data;
383 unsigned min_period_frames;
409 min_period_frames = 48;
412 min_period_frames = 52;
415 min_period_frames = 104;
419 min_period_frames <<= 1;
431 else if (us122l->
master != file) {
432 if (!s ||
memcmp(cfg, &s->
cfg,
sizeof(*cfg))) {
438 if (!s ||
memcmp(cfg, &s->
cfg,
sizeof(*cfg)) ||
454 #define SND_USB_STREAM_ID "USB STREAM"
455 static int usb_stream_hwdep_new(
struct snd_card *card)
459 struct usb_device *dev =
US122L(card)->dev;
467 hw->
ops.open = usb_stream_hwdep_open;
468 hw->
ops.release = usb_stream_hwdep_release;
469 hw->
ops.ioctl = usb_stream_hwdep_ioctl;
470 hw->
ops.ioctl_compat = usb_stream_hwdep_ioctl;
471 hw->
ops.mmap = usb_stream_hwdep_mmap;
472 hw->
ops.poll = usb_stream_hwdep_poll;
474 sprintf(hw->
name,
"/proc/bus/usb/%03d/%03d/hwdeppcm",
475 dev->bus->busnum, dev->devnum);
480 static bool us122l_create_card(
struct snd_card *card)
483 struct us122l *us122l =
US122L(card);
499 pt_info_set(us122l->
dev, 0x11);
500 pt_info_set(us122l->
dev, 0x10);
502 if (!us122l_start(us122l, 44100, 256))
507 err = us144_create_usbmidi(card);
509 err = us122l_create_usbmidi(card);
515 err = usb_stream_hwdep_new(card);
530 struct us122l *us122l =
US122L(card);
533 snd_us122l_card_used[
index] = 0;
536 static int usx2y_create_card(
struct usb_device *
device,
struct snd_card **cardp)
543 if (
enable[dev] && !snd_us122l_card_used[dev])
545 if (dev >= SNDRV_CARDS)
548 sizeof(
struct us122l), &card);
551 snd_us122l_card_used[
US122L(card)->card_index =
dev] = 1;
553 US122L(card)->dev = device;
556 INIT_LIST_HEAD(&
US122L(card)->midi_list);
564 US122L(card)->dev->bus->busnum,
575 struct usb_device *device = interface_to_usbdev(intf);
579 err = usx2y_create_card(device, &card);
584 if (!us122l_create_card(card)) {
604 struct usb_device *device = interface_to_usbdev(intf);
616 intf, intf->cur_altsetting->desc.bInterfaceNumber);
617 if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
626 usb_set_intfdata(intf, card);
630 static void snd_us122l_disconnect(
struct usb_interface *intf)
633 struct us122l *us122l;
636 card = usb_get_intfdata(intf);
665 struct us122l *us122l;
668 card = usb_get_intfdata(intf);
690 struct us122l *us122l;
694 card = usb_get_intfdata(intf);
718 pt_info_set(us122l->
dev, 0x11);
719 pt_info_set(us122l->
dev, 0x10);
721 err = us122l_set_sample_rate(us122l->
dev,
722 us122l->
sk.s->cfg.sample_rate);
746 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
751 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
756 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
764 static struct usb_driver snd_us122l_usb_driver = {
765 .name =
"snd-usb-us122l",
766 .probe = snd_us122l_probe,
767 .disconnect = snd_us122l_disconnect,
768 .suspend = snd_us122l_suspend,
769 .resume = snd_us122l_resume,
770 .reset_resume = snd_us122l_resume,
771 .id_table = snd_us122l_usb_id_table,
772 .supports_autosuspend = 1