us122l.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. #include <sound/core.h>
  19. #include <sound/hwdep.h>
  20. #include <sound/pcm.h>
  21. #include <sound/initval.h>
  22. #define MODNAME "US122L"
  23. #include "usb_stream.c"
  24. #include "../usbaudio.h"
  25. #include "us122l.h"
  26. MODULE_AUTHOR("Karsten Wiese <fzu@wemgehoertderstaat.de>");
  27. MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.5");
  28. MODULE_LICENSE("GPL");
  29. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
  30. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
  31. /* Enable this card */
  32. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  33. module_param_array(index, int, NULL, 0444);
  34. MODULE_PARM_DESC(index, "Index value for "NAME_ALLCAPS".");
  35. module_param_array(id, charp, NULL, 0444);
  36. MODULE_PARM_DESC(id, "ID string for "NAME_ALLCAPS".");
  37. module_param_array(enable, bool, NULL, 0444);
  38. MODULE_PARM_DESC(enable, "Enable "NAME_ALLCAPS".");
  39. static int snd_us122l_card_used[SNDRV_CARDS];
  40. static int us122l_create_usbmidi(struct snd_card *card)
  41. {
  42. static struct snd_usb_midi_endpoint_info quirk_data = {
  43. .out_ep = 4,
  44. .in_ep = 3,
  45. .out_cables = 0x001,
  46. .in_cables = 0x001
  47. };
  48. static struct snd_usb_audio_quirk quirk = {
  49. .vendor_name = "US122L",
  50. .product_name = NAME_ALLCAPS,
  51. .ifnum = 1,
  52. .type = QUIRK_MIDI_US122L,
  53. .data = &quirk_data
  54. };
  55. struct usb_device *dev = US122L(card)->chip.dev;
  56. struct usb_interface *iface = usb_ifnum_to_if(dev, 1);
  57. return snd_usb_create_midi_interface(&US122L(card)->chip,
  58. iface, &quirk);
  59. }
  60. /*
  61. * Wrapper for usb_control_msg().
  62. * Allocates a temp buffer to prevent dmaing from/to the stack.
  63. */
  64. static int us122l_ctl_msg(struct usb_device *dev, unsigned int pipe,
  65. __u8 request, __u8 requesttype,
  66. __u16 value, __u16 index, void *data,
  67. __u16 size, int timeout)
  68. {
  69. int err;
  70. void *buf = NULL;
  71. if (size > 0) {
  72. buf = kmemdup(data, size, GFP_KERNEL);
  73. if (!buf)
  74. return -ENOMEM;
  75. }
  76. err = usb_control_msg(dev, pipe, request, requesttype,
  77. value, index, buf, size, timeout);
  78. if (size > 0) {
  79. memcpy(data, buf, size);
  80. kfree(buf);
  81. }
  82. return err;
  83. }
  84. static void pt_info_set(struct usb_device *dev, u8 v)
  85. {
  86. int ret;
  87. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  88. 'I',
  89. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  90. v, 0, NULL, 0, 1000);
  91. snd_printdd(KERN_DEBUG "%i\n", ret);
  92. }
  93. static void usb_stream_hwdep_vm_open(struct vm_area_struct *area)
  94. {
  95. struct us122l *us122l = area->vm_private_data;
  96. atomic_inc(&us122l->mmap_count);
  97. snd_printdd(KERN_DEBUG "%i\n", atomic_read(&us122l->mmap_count));
  98. }
  99. static int usb_stream_hwdep_vm_fault(struct vm_area_struct *area,
  100. struct vm_fault *vmf)
  101. {
  102. unsigned long offset;
  103. struct page *page;
  104. void *vaddr;
  105. struct us122l *us122l = area->vm_private_data;
  106. struct usb_stream *s;
  107. int vm_f = VM_FAULT_SIGBUS;
  108. mutex_lock(&us122l->mutex);
  109. s = us122l->sk.s;
  110. if (!s)
  111. goto out;
  112. offset = vmf->pgoff << PAGE_SHIFT;
  113. if (offset < PAGE_ALIGN(s->read_size))
  114. vaddr = (char *)s + offset;
  115. else {
  116. offset -= PAGE_ALIGN(s->read_size);
  117. if (offset >= PAGE_ALIGN(s->write_size))
  118. goto out;
  119. vaddr = us122l->sk.write_page + offset;
  120. }
  121. page = virt_to_page(vaddr);
  122. get_page(page);
  123. mutex_unlock(&us122l->mutex);
  124. vmf->page = page;
  125. vm_f = 0;
  126. out:
  127. return vm_f;
  128. }
  129. static void usb_stream_hwdep_vm_close(struct vm_area_struct *area)
  130. {
  131. struct us122l *us122l = area->vm_private_data;
  132. atomic_dec(&us122l->mmap_count);
  133. snd_printdd(KERN_DEBUG "%i\n", atomic_read(&us122l->mmap_count));
  134. }
  135. static struct vm_operations_struct usb_stream_hwdep_vm_ops = {
  136. .open = usb_stream_hwdep_vm_open,
  137. .fault = usb_stream_hwdep_vm_fault,
  138. .close = usb_stream_hwdep_vm_close,
  139. };
  140. static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
  141. {
  142. struct us122l *us122l = hw->private_data;
  143. struct usb_interface *iface;
  144. snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
  145. if (hw->used >= 2)
  146. return -EBUSY;
  147. if (!us122l->first)
  148. us122l->first = file;
  149. iface = usb_ifnum_to_if(us122l->chip.dev, 1);
  150. usb_autopm_get_interface(iface);
  151. return 0;
  152. }
  153. static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file)
  154. {
  155. struct us122l *us122l = hw->private_data;
  156. struct usb_interface *iface = usb_ifnum_to_if(us122l->chip.dev, 1);
  157. snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
  158. usb_autopm_put_interface(iface);
  159. if (us122l->first == file)
  160. us122l->first = NULL;
  161. mutex_lock(&us122l->mutex);
  162. if (us122l->master == file)
  163. us122l->master = us122l->slave;
  164. us122l->slave = NULL;
  165. mutex_unlock(&us122l->mutex);
  166. return 0;
  167. }
  168. static int usb_stream_hwdep_mmap(struct snd_hwdep *hw,
  169. struct file *filp, struct vm_area_struct *area)
  170. {
  171. unsigned long size = area->vm_end - area->vm_start;
  172. struct us122l *us122l = hw->private_data;
  173. unsigned long offset;
  174. struct usb_stream *s;
  175. int err = 0;
  176. bool read;
  177. offset = area->vm_pgoff << PAGE_SHIFT;
  178. mutex_lock(&us122l->mutex);
  179. s = us122l->sk.s;
  180. read = offset < s->read_size;
  181. if (read && area->vm_flags & VM_WRITE) {
  182. err = -EPERM;
  183. goto out;
  184. }
  185. snd_printdd(KERN_DEBUG "%lu %u\n", size,
  186. read ? s->read_size : s->write_size);
  187. /* if userspace tries to mmap beyond end of our buffer, fail */
  188. if (size > PAGE_ALIGN(read ? s->read_size : s->write_size)) {
  189. snd_printk(KERN_WARNING "%lu > %u\n", size,
  190. read ? s->read_size : s->write_size);
  191. err = -EINVAL;
  192. goto out;
  193. }
  194. area->vm_ops = &usb_stream_hwdep_vm_ops;
  195. area->vm_flags |= VM_RESERVED;
  196. area->vm_private_data = us122l;
  197. atomic_inc(&us122l->mmap_count);
  198. out:
  199. mutex_unlock(&us122l->mutex);
  200. return err;
  201. }
  202. static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
  203. struct file *file, poll_table *wait)
  204. {
  205. struct us122l *us122l = hw->private_data;
  206. struct usb_stream *s = us122l->sk.s;
  207. unsigned *polled;
  208. unsigned int mask;
  209. poll_wait(file, &us122l->sk.sleep, wait);
  210. switch (s->state) {
  211. case usb_stream_ready:
  212. if (us122l->first == file)
  213. polled = &s->periods_polled;
  214. else
  215. polled = &us122l->second_periods_polled;
  216. if (*polled != s->periods_done) {
  217. *polled = s->periods_done;
  218. mask = POLLIN | POLLOUT | POLLWRNORM;
  219. break;
  220. }
  221. /* Fall through */
  222. mask = 0;
  223. break;
  224. default:
  225. mask = POLLIN | POLLOUT | POLLWRNORM | POLLERR;
  226. break;
  227. }
  228. return mask;
  229. }
  230. static void us122l_stop(struct us122l *us122l)
  231. {
  232. struct list_head *p;
  233. list_for_each(p, &us122l->chip.midi_list)
  234. snd_usbmidi_input_stop(p);
  235. usb_stream_stop(&us122l->sk);
  236. usb_stream_free(&us122l->sk);
  237. }
  238. static int us122l_set_sample_rate(struct usb_device *dev, int rate)
  239. {
  240. unsigned int ep = 0x81;
  241. unsigned char data[3];
  242. int err;
  243. data[0] = rate;
  244. data[1] = rate >> 8;
  245. data[2] = rate >> 16;
  246. err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
  247. USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
  248. SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000);
  249. if (err < 0)
  250. snd_printk(KERN_ERR "%d: cannot set freq %d to ep 0x%x\n",
  251. dev->devnum, rate, ep);
  252. return err;
  253. }
  254. static bool us122l_start(struct us122l *us122l,
  255. unsigned rate, unsigned period_frames)
  256. {
  257. struct list_head *p;
  258. int err;
  259. unsigned use_packsize = 0;
  260. bool success = false;
  261. if (us122l->chip.dev->speed == USB_SPEED_HIGH) {
  262. /* The us-122l's descriptor defaults to iso max_packsize 78,
  263. which isn't needed for samplerates <= 48000.
  264. Lets save some memory:
  265. */
  266. switch (rate) {
  267. case 44100:
  268. use_packsize = 36;
  269. break;
  270. case 48000:
  271. use_packsize = 42;
  272. break;
  273. case 88200:
  274. use_packsize = 72;
  275. break;
  276. }
  277. }
  278. if (!usb_stream_new(&us122l->sk, us122l->chip.dev, 1, 2,
  279. rate, use_packsize, period_frames, 6))
  280. goto out;
  281. err = us122l_set_sample_rate(us122l->chip.dev, rate);
  282. if (err < 0) {
  283. us122l_stop(us122l);
  284. snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
  285. goto out;
  286. }
  287. err = usb_stream_start(&us122l->sk);
  288. if (err < 0) {
  289. us122l_stop(us122l);
  290. snd_printk(KERN_ERR "us122l_start error %i \n", err);
  291. goto out;
  292. }
  293. list_for_each(p, &us122l->chip.midi_list)
  294. snd_usbmidi_input_start(p);
  295. success = true;
  296. out:
  297. return success;
  298. }
  299. static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
  300. unsigned cmd, unsigned long arg)
  301. {
  302. struct usb_stream_config *cfg;
  303. struct us122l *us122l = hw->private_data;
  304. unsigned min_period_frames;
  305. int err = 0;
  306. bool high_speed;
  307. if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS)
  308. return -ENOTTY;
  309. cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  310. if (!cfg)
  311. return -ENOMEM;
  312. if (copy_from_user(cfg, (void *)arg, sizeof(*cfg))) {
  313. err = -EFAULT;
  314. goto free;
  315. }
  316. if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
  317. err = -ENXIO;
  318. goto free;
  319. }
  320. high_speed = us122l->chip.dev->speed == USB_SPEED_HIGH;
  321. if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 &&
  322. (!high_speed ||
  323. (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) ||
  324. cfg->frame_size != 6 ||
  325. cfg->period_frames > 0x3000) {
  326. err = -EINVAL;
  327. goto free;
  328. }
  329. switch (cfg->sample_rate) {
  330. case 44100:
  331. min_period_frames = 48;
  332. break;
  333. case 48000:
  334. min_period_frames = 52;
  335. break;
  336. default:
  337. min_period_frames = 104;
  338. break;
  339. }
  340. if (!high_speed)
  341. min_period_frames <<= 1;
  342. if (cfg->period_frames < min_period_frames) {
  343. err = -EINVAL;
  344. goto free;
  345. }
  346. snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
  347. mutex_lock(&us122l->mutex);
  348. if (!us122l->master)
  349. us122l->master = file;
  350. else if (us122l->master != file) {
  351. if (memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg))) {
  352. err = -EIO;
  353. goto unlock;
  354. }
  355. us122l->slave = file;
  356. }
  357. if (!us122l->sk.s ||
  358. memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg)) ||
  359. us122l->sk.s->state == usb_stream_xrun) {
  360. us122l_stop(us122l);
  361. if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames))
  362. err = -EIO;
  363. else
  364. err = 1;
  365. }
  366. unlock:
  367. mutex_unlock(&us122l->mutex);
  368. free:
  369. kfree(cfg);
  370. return err;
  371. }
  372. #define SND_USB_STREAM_ID "USB STREAM"
  373. static int usb_stream_hwdep_new(struct snd_card *card)
  374. {
  375. int err;
  376. struct snd_hwdep *hw;
  377. struct usb_device *dev = US122L(card)->chip.dev;
  378. err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw);
  379. if (err < 0)
  380. return err;
  381. hw->iface = SNDRV_HWDEP_IFACE_USB_STREAM;
  382. hw->private_data = US122L(card);
  383. hw->ops.open = usb_stream_hwdep_open;
  384. hw->ops.release = usb_stream_hwdep_release;
  385. hw->ops.ioctl = usb_stream_hwdep_ioctl;
  386. hw->ops.ioctl_compat = usb_stream_hwdep_ioctl;
  387. hw->ops.mmap = usb_stream_hwdep_mmap;
  388. hw->ops.poll = usb_stream_hwdep_poll;
  389. sprintf(hw->name, "/proc/bus/usb/%03d/%03d/hwdeppcm",
  390. dev->bus->busnum, dev->devnum);
  391. return 0;
  392. }
  393. static bool us122l_create_card(struct snd_card *card)
  394. {
  395. int err;
  396. struct us122l *us122l = US122L(card);
  397. err = usb_set_interface(us122l->chip.dev, 1, 1);
  398. if (err) {
  399. snd_printk(KERN_ERR "usb_set_interface error \n");
  400. return false;
  401. }
  402. pt_info_set(us122l->chip.dev, 0x11);
  403. pt_info_set(us122l->chip.dev, 0x10);
  404. if (!us122l_start(us122l, 44100, 256))
  405. return false;
  406. err = us122l_create_usbmidi(card);
  407. if (err < 0) {
  408. snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err);
  409. us122l_stop(us122l);
  410. return false;
  411. }
  412. err = usb_stream_hwdep_new(card);
  413. if (err < 0) {
  414. /* release the midi resources */
  415. struct list_head *p;
  416. list_for_each(p, &us122l->chip.midi_list)
  417. snd_usbmidi_disconnect(p);
  418. us122l_stop(us122l);
  419. return false;
  420. }
  421. return true;
  422. }
  423. static struct snd_card *usx2y_create_card(struct usb_device *device)
  424. {
  425. int dev;
  426. struct snd_card *card;
  427. for (dev = 0; dev < SNDRV_CARDS; ++dev)
  428. if (enable[dev] && !snd_us122l_card_used[dev])
  429. break;
  430. if (dev >= SNDRV_CARDS)
  431. return NULL;
  432. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  433. sizeof(struct us122l));
  434. if (!card)
  435. return NULL;
  436. snd_us122l_card_used[US122L(card)->chip.index = dev] = 1;
  437. US122L(card)->chip.dev = device;
  438. US122L(card)->chip.card = card;
  439. mutex_init(&US122L(card)->mutex);
  440. init_waitqueue_head(&US122L(card)->sk.sleep);
  441. INIT_LIST_HEAD(&US122L(card)->chip.midi_list);
  442. strcpy(card->driver, "USB "NAME_ALLCAPS"");
  443. sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
  444. sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
  445. card->shortname,
  446. le16_to_cpu(device->descriptor.idVendor),
  447. le16_to_cpu(device->descriptor.idProduct),
  448. 0,
  449. US122L(card)->chip.dev->bus->busnum,
  450. US122L(card)->chip.dev->devnum
  451. );
  452. snd_card_set_dev(card, &device->dev);
  453. return card;
  454. }
  455. static void *us122l_usb_probe(struct usb_interface *intf,
  456. const struct usb_device_id *device_id)
  457. {
  458. struct usb_device *device = interface_to_usbdev(intf);
  459. struct snd_card *card = usx2y_create_card(device);
  460. if (!card)
  461. return NULL;
  462. if (!us122l_create_card(card) ||
  463. snd_card_register(card) < 0) {
  464. snd_card_free(card);
  465. return NULL;
  466. }
  467. usb_get_dev(device);
  468. return card;
  469. }
  470. static int snd_us122l_probe(struct usb_interface *intf,
  471. const struct usb_device_id *id)
  472. {
  473. struct snd_card *card;
  474. snd_printdd(KERN_DEBUG"%p:%i\n",
  475. intf, intf->cur_altsetting->desc.bInterfaceNumber);
  476. if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
  477. return 0;
  478. card = us122l_usb_probe(usb_get_intf(intf), id);
  479. if (card) {
  480. usb_set_intfdata(intf, card);
  481. return 0;
  482. }
  483. usb_put_intf(intf);
  484. return -EIO;
  485. }
  486. static void snd_us122l_disconnect(struct usb_interface *intf)
  487. {
  488. struct snd_card *card;
  489. struct us122l *us122l;
  490. struct list_head *p;
  491. card = usb_get_intfdata(intf);
  492. if (!card)
  493. return;
  494. snd_card_disconnect(card);
  495. us122l = US122L(card);
  496. mutex_lock(&us122l->mutex);
  497. us122l_stop(us122l);
  498. mutex_unlock(&us122l->mutex);
  499. us122l->chip.shutdown = 1;
  500. /* release the midi resources */
  501. list_for_each(p, &us122l->chip.midi_list) {
  502. snd_usbmidi_disconnect(p);
  503. }
  504. usb_put_intf(intf);
  505. usb_put_dev(US122L(card)->chip.dev);
  506. while (atomic_read(&us122l->mmap_count))
  507. msleep(500);
  508. snd_card_free(card);
  509. }
  510. static int snd_us122l_suspend(struct usb_interface *intf, pm_message_t message)
  511. {
  512. struct snd_card *card;
  513. struct us122l *us122l;
  514. struct list_head *p;
  515. card = dev_get_drvdata(&intf->dev);
  516. if (!card)
  517. return 0;
  518. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  519. us122l = US122L(card);
  520. if (!us122l)
  521. return 0;
  522. list_for_each(p, &us122l->chip.midi_list)
  523. snd_usbmidi_input_stop(p);
  524. mutex_lock(&us122l->mutex);
  525. usb_stream_stop(&us122l->sk);
  526. mutex_unlock(&us122l->mutex);
  527. return 0;
  528. }
  529. static int snd_us122l_resume(struct usb_interface *intf)
  530. {
  531. struct snd_card *card;
  532. struct us122l *us122l;
  533. struct list_head *p;
  534. int err;
  535. card = dev_get_drvdata(&intf->dev);
  536. if (!card)
  537. return 0;
  538. us122l = US122L(card);
  539. if (!us122l)
  540. return 0;
  541. mutex_lock(&us122l->mutex);
  542. /* needed, doesn't restart without: */
  543. err = usb_set_interface(us122l->chip.dev, 1, 1);
  544. if (err) {
  545. snd_printk(KERN_ERR "usb_set_interface error \n");
  546. goto unlock;
  547. }
  548. pt_info_set(us122l->chip.dev, 0x11);
  549. pt_info_set(us122l->chip.dev, 0x10);
  550. err = us122l_set_sample_rate(us122l->chip.dev,
  551. us122l->sk.s->cfg.sample_rate);
  552. if (err < 0) {
  553. snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
  554. goto unlock;
  555. }
  556. err = usb_stream_start(&us122l->sk);
  557. if (err)
  558. goto unlock;
  559. list_for_each(p, &us122l->chip.midi_list)
  560. snd_usbmidi_input_start(p);
  561. unlock:
  562. mutex_unlock(&us122l->mutex);
  563. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  564. return err;
  565. }
  566. static struct usb_device_id snd_us122l_usb_id_table[] = {
  567. {
  568. .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
  569. .idVendor = 0x0644,
  570. .idProduct = USB_ID_US122L
  571. },
  572. /* { */ /* US-144 maybe works when @USB1.1. Untested. */
  573. /* .match_flags = USB_DEVICE_ID_MATCH_DEVICE, */
  574. /* .idVendor = 0x0644, */
  575. /* .idProduct = USB_ID_US144 */
  576. /* }, */
  577. { /* terminator */ }
  578. };
  579. MODULE_DEVICE_TABLE(usb, snd_us122l_usb_id_table);
  580. static struct usb_driver snd_us122l_usb_driver = {
  581. .name = "snd-usb-us122l",
  582. .probe = snd_us122l_probe,
  583. .disconnect = snd_us122l_disconnect,
  584. .suspend = snd_us122l_suspend,
  585. .resume = snd_us122l_resume,
  586. .reset_resume = snd_us122l_resume,
  587. .id_table = snd_us122l_usb_id_table,
  588. .supports_autosuspend = 1
  589. };
  590. static int __init snd_us122l_module_init(void)
  591. {
  592. return usb_register(&snd_us122l_usb_driver);
  593. }
  594. static void __exit snd_us122l_module_exit(void)
  595. {
  596. usb_deregister(&snd_us122l_usb_driver);
  597. }
  598. module_init(snd_us122l_module_init)
  599. module_exit(snd_us122l_module_exit)