us122l.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. mutex_lock(&us122l->mutex);
  108. s = us122l->sk.s;
  109. if (!s)
  110. goto unlock;
  111. offset = vmf->pgoff << PAGE_SHIFT;
  112. if (offset < PAGE_ALIGN(s->read_size))
  113. vaddr = (char *)s + offset;
  114. else {
  115. offset -= PAGE_ALIGN(s->read_size);
  116. if (offset >= PAGE_ALIGN(s->write_size))
  117. goto unlock;
  118. vaddr = us122l->sk.write_page + offset;
  119. }
  120. page = virt_to_page(vaddr);
  121. get_page(page);
  122. mutex_unlock(&us122l->mutex);
  123. vmf->page = page;
  124. return 0;
  125. unlock:
  126. mutex_unlock(&us122l->mutex);
  127. return VM_FAULT_SIGBUS;
  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 const 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 = memdup_user((void *)arg, sizeof(*cfg));
  310. if (IS_ERR(cfg))
  311. return PTR_ERR(cfg);
  312. if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
  313. err = -ENXIO;
  314. goto free;
  315. }
  316. high_speed = us122l->chip.dev->speed == USB_SPEED_HIGH;
  317. if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 &&
  318. (!high_speed ||
  319. (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) ||
  320. cfg->frame_size != 6 ||
  321. cfg->period_frames > 0x3000) {
  322. err = -EINVAL;
  323. goto free;
  324. }
  325. switch (cfg->sample_rate) {
  326. case 44100:
  327. min_period_frames = 48;
  328. break;
  329. case 48000:
  330. min_period_frames = 52;
  331. break;
  332. default:
  333. min_period_frames = 104;
  334. break;
  335. }
  336. if (!high_speed)
  337. min_period_frames <<= 1;
  338. if (cfg->period_frames < min_period_frames) {
  339. err = -EINVAL;
  340. goto free;
  341. }
  342. snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
  343. mutex_lock(&us122l->mutex);
  344. if (!us122l->master)
  345. us122l->master = file;
  346. else if (us122l->master != file) {
  347. if (memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg))) {
  348. err = -EIO;
  349. goto unlock;
  350. }
  351. us122l->slave = file;
  352. }
  353. if (!us122l->sk.s ||
  354. memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg)) ||
  355. us122l->sk.s->state == usb_stream_xrun) {
  356. us122l_stop(us122l);
  357. if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames))
  358. err = -EIO;
  359. else
  360. err = 1;
  361. }
  362. unlock:
  363. mutex_unlock(&us122l->mutex);
  364. free:
  365. kfree(cfg);
  366. return err;
  367. }
  368. #define SND_USB_STREAM_ID "USB STREAM"
  369. static int usb_stream_hwdep_new(struct snd_card *card)
  370. {
  371. int err;
  372. struct snd_hwdep *hw;
  373. struct usb_device *dev = US122L(card)->chip.dev;
  374. err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw);
  375. if (err < 0)
  376. return err;
  377. hw->iface = SNDRV_HWDEP_IFACE_USB_STREAM;
  378. hw->private_data = US122L(card);
  379. hw->ops.open = usb_stream_hwdep_open;
  380. hw->ops.release = usb_stream_hwdep_release;
  381. hw->ops.ioctl = usb_stream_hwdep_ioctl;
  382. hw->ops.ioctl_compat = usb_stream_hwdep_ioctl;
  383. hw->ops.mmap = usb_stream_hwdep_mmap;
  384. hw->ops.poll = usb_stream_hwdep_poll;
  385. sprintf(hw->name, "/proc/bus/usb/%03d/%03d/hwdeppcm",
  386. dev->bus->busnum, dev->devnum);
  387. return 0;
  388. }
  389. static bool us122l_create_card(struct snd_card *card)
  390. {
  391. int err;
  392. struct us122l *us122l = US122L(card);
  393. err = usb_set_interface(us122l->chip.dev, 1, 1);
  394. if (err) {
  395. snd_printk(KERN_ERR "usb_set_interface error \n");
  396. return false;
  397. }
  398. pt_info_set(us122l->chip.dev, 0x11);
  399. pt_info_set(us122l->chip.dev, 0x10);
  400. if (!us122l_start(us122l, 44100, 256))
  401. return false;
  402. err = us122l_create_usbmidi(card);
  403. if (err < 0) {
  404. snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err);
  405. us122l_stop(us122l);
  406. return false;
  407. }
  408. err = usb_stream_hwdep_new(card);
  409. if (err < 0) {
  410. /* release the midi resources */
  411. struct list_head *p;
  412. list_for_each(p, &us122l->chip.midi_list)
  413. snd_usbmidi_disconnect(p);
  414. us122l_stop(us122l);
  415. return false;
  416. }
  417. return true;
  418. }
  419. static void snd_us122l_free(struct snd_card *card)
  420. {
  421. struct us122l *us122l = US122L(card);
  422. int index = us122l->chip.index;
  423. if (index >= 0 && index < SNDRV_CARDS)
  424. snd_us122l_card_used[index] = 0;
  425. }
  426. static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
  427. {
  428. int dev;
  429. struct snd_card *card;
  430. int err;
  431. for (dev = 0; dev < SNDRV_CARDS; ++dev)
  432. if (enable[dev] && !snd_us122l_card_used[dev])
  433. break;
  434. if (dev >= SNDRV_CARDS)
  435. return -ENODEV;
  436. err = snd_card_create(index[dev], id[dev], THIS_MODULE,
  437. sizeof(struct us122l), &card);
  438. if (err < 0)
  439. return err;
  440. snd_us122l_card_used[US122L(card)->chip.index = dev] = 1;
  441. card->private_free = snd_us122l_free;
  442. US122L(card)->chip.dev = device;
  443. US122L(card)->chip.card = card;
  444. mutex_init(&US122L(card)->mutex);
  445. init_waitqueue_head(&US122L(card)->sk.sleep);
  446. INIT_LIST_HEAD(&US122L(card)->chip.midi_list);
  447. strcpy(card->driver, "USB "NAME_ALLCAPS"");
  448. sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
  449. sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
  450. card->shortname,
  451. le16_to_cpu(device->descriptor.idVendor),
  452. le16_to_cpu(device->descriptor.idProduct),
  453. 0,
  454. US122L(card)->chip.dev->bus->busnum,
  455. US122L(card)->chip.dev->devnum
  456. );
  457. *cardp = card;
  458. return 0;
  459. }
  460. static int us122l_usb_probe(struct usb_interface *intf,
  461. const struct usb_device_id *device_id,
  462. struct snd_card **cardp)
  463. {
  464. struct usb_device *device = interface_to_usbdev(intf);
  465. struct snd_card *card;
  466. int err;
  467. err = usx2y_create_card(device, &card);
  468. if (err < 0)
  469. return err;
  470. snd_card_set_dev(card, &intf->dev);
  471. if (!us122l_create_card(card)) {
  472. snd_card_free(card);
  473. return -EINVAL;
  474. }
  475. err = snd_card_register(card);
  476. if (err < 0) {
  477. snd_card_free(card);
  478. return err;
  479. }
  480. usb_get_dev(device);
  481. *cardp = card;
  482. return 0;
  483. }
  484. static int snd_us122l_probe(struct usb_interface *intf,
  485. const struct usb_device_id *id)
  486. {
  487. struct snd_card *card;
  488. int err;
  489. snd_printdd(KERN_DEBUG"%p:%i\n",
  490. intf, intf->cur_altsetting->desc.bInterfaceNumber);
  491. if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
  492. return 0;
  493. err = us122l_usb_probe(usb_get_intf(intf), id, &card);
  494. if (err < 0) {
  495. usb_put_intf(intf);
  496. return err;
  497. }
  498. usb_set_intfdata(intf, card);
  499. return 0;
  500. }
  501. static void snd_us122l_disconnect(struct usb_interface *intf)
  502. {
  503. struct snd_card *card;
  504. struct us122l *us122l;
  505. struct list_head *p;
  506. card = usb_get_intfdata(intf);
  507. if (!card)
  508. return;
  509. snd_card_disconnect(card);
  510. us122l = US122L(card);
  511. mutex_lock(&us122l->mutex);
  512. us122l_stop(us122l);
  513. mutex_unlock(&us122l->mutex);
  514. us122l->chip.shutdown = 1;
  515. /* release the midi resources */
  516. list_for_each(p, &us122l->chip.midi_list) {
  517. snd_usbmidi_disconnect(p);
  518. }
  519. usb_put_intf(intf);
  520. usb_put_dev(us122l->chip.dev);
  521. while (atomic_read(&us122l->mmap_count))
  522. msleep(500);
  523. snd_card_free(card);
  524. }
  525. static int snd_us122l_suspend(struct usb_interface *intf, pm_message_t message)
  526. {
  527. struct snd_card *card;
  528. struct us122l *us122l;
  529. struct list_head *p;
  530. card = usb_get_intfdata(intf);
  531. if (!card)
  532. return 0;
  533. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  534. us122l = US122L(card);
  535. if (!us122l)
  536. return 0;
  537. list_for_each(p, &us122l->chip.midi_list)
  538. snd_usbmidi_input_stop(p);
  539. mutex_lock(&us122l->mutex);
  540. usb_stream_stop(&us122l->sk);
  541. mutex_unlock(&us122l->mutex);
  542. return 0;
  543. }
  544. static int snd_us122l_resume(struct usb_interface *intf)
  545. {
  546. struct snd_card *card;
  547. struct us122l *us122l;
  548. struct list_head *p;
  549. int err;
  550. card = usb_get_intfdata(intf);
  551. if (!card)
  552. return 0;
  553. us122l = US122L(card);
  554. if (!us122l)
  555. return 0;
  556. mutex_lock(&us122l->mutex);
  557. /* needed, doesn't restart without: */
  558. err = usb_set_interface(us122l->chip.dev, 1, 1);
  559. if (err) {
  560. snd_printk(KERN_ERR "usb_set_interface error \n");
  561. goto unlock;
  562. }
  563. pt_info_set(us122l->chip.dev, 0x11);
  564. pt_info_set(us122l->chip.dev, 0x10);
  565. err = us122l_set_sample_rate(us122l->chip.dev,
  566. us122l->sk.s->cfg.sample_rate);
  567. if (err < 0) {
  568. snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
  569. goto unlock;
  570. }
  571. err = usb_stream_start(&us122l->sk);
  572. if (err)
  573. goto unlock;
  574. list_for_each(p, &us122l->chip.midi_list)
  575. snd_usbmidi_input_start(p);
  576. unlock:
  577. mutex_unlock(&us122l->mutex);
  578. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  579. return err;
  580. }
  581. static struct usb_device_id snd_us122l_usb_id_table[] = {
  582. {
  583. .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
  584. .idVendor = 0x0644,
  585. .idProduct = USB_ID_US122L
  586. },
  587. /* { */ /* US-144 maybe works when @USB1.1. Untested. */
  588. /* .match_flags = USB_DEVICE_ID_MATCH_DEVICE, */
  589. /* .idVendor = 0x0644, */
  590. /* .idProduct = USB_ID_US144 */
  591. /* }, */
  592. { /* terminator */ }
  593. };
  594. MODULE_DEVICE_TABLE(usb, snd_us122l_usb_id_table);
  595. static struct usb_driver snd_us122l_usb_driver = {
  596. .name = "snd-usb-us122l",
  597. .probe = snd_us122l_probe,
  598. .disconnect = snd_us122l_disconnect,
  599. .suspend = snd_us122l_suspend,
  600. .resume = snd_us122l_resume,
  601. .reset_resume = snd_us122l_resume,
  602. .id_table = snd_us122l_usb_id_table,
  603. .supports_autosuspend = 1
  604. };
  605. static int __init snd_us122l_module_init(void)
  606. {
  607. return usb_register(&snd_us122l_usb_driver);
  608. }
  609. static void __exit snd_us122l_module_exit(void)
  610. {
  611. usb_deregister(&snd_us122l_usb_driver);
  612. }
  613. module_init(snd_us122l_module_init)
  614. module_exit(snd_us122l_module_exit)