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