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