usbmidi.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  1. /*
  2. * usbmidi.c - ALSA USB MIDI driver
  3. *
  4. * Copyright (c) 2002-2005 Clemens Ladisch
  5. * All rights reserved.
  6. *
  7. * Based on the OSS usb-midi driver by NAGANO Daisuke,
  8. * NetBSD's umidi driver by Takuya SHIOZAKI,
  9. * the "USB Device Class Definition for MIDI Devices" by Roland
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed and/or modified under the
  21. * terms of the GNU General Public License as published by the Free Software
  22. * Foundation; either version 2 of the License, or (at your option) any later
  23. * version.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  29. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. */
  37. #include <sound/driver.h>
  38. #include <linux/kernel.h>
  39. #include <linux/types.h>
  40. #include <linux/bitops.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/string.h>
  44. #include <linux/init.h>
  45. #include <linux/slab.h>
  46. #include <linux/timer.h>
  47. #include <linux/usb.h>
  48. #include <sound/core.h>
  49. #include <sound/rawmidi.h>
  50. #include "usbaudio.h"
  51. /*
  52. * define this to log all USB packets
  53. */
  54. /* #define DUMP_PACKETS */
  55. /*
  56. * how long to wait after some USB errors, so that khubd can disconnect() us
  57. * without too many spurious errors
  58. */
  59. #define ERROR_DELAY_JIFFIES (HZ / 10)
  60. MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  61. MODULE_DESCRIPTION("USB Audio/MIDI helper module");
  62. MODULE_LICENSE("Dual BSD/GPL");
  63. struct usb_ms_header_descriptor {
  64. __u8 bLength;
  65. __u8 bDescriptorType;
  66. __u8 bDescriptorSubtype;
  67. __u8 bcdMSC[2];
  68. __le16 wTotalLength;
  69. } __attribute__ ((packed));
  70. struct usb_ms_endpoint_descriptor {
  71. __u8 bLength;
  72. __u8 bDescriptorType;
  73. __u8 bDescriptorSubtype;
  74. __u8 bNumEmbMIDIJack;
  75. __u8 baAssocJackID[0];
  76. } __attribute__ ((packed));
  77. struct snd_usb_midi_in_endpoint;
  78. struct snd_usb_midi_out_endpoint;
  79. struct snd_usb_midi_endpoint;
  80. struct usb_protocol_ops {
  81. void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int);
  82. void (*output)(struct snd_usb_midi_out_endpoint*);
  83. void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t);
  84. void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint*);
  85. void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint*);
  86. };
  87. struct snd_usb_midi {
  88. struct snd_usb_audio *chip;
  89. struct usb_interface *iface;
  90. const struct snd_usb_audio_quirk *quirk;
  91. struct snd_rawmidi *rmidi;
  92. struct usb_protocol_ops* usb_protocol_ops;
  93. struct list_head list;
  94. struct timer_list error_timer;
  95. struct snd_usb_midi_endpoint {
  96. struct snd_usb_midi_out_endpoint *out;
  97. struct snd_usb_midi_in_endpoint *in;
  98. } endpoints[MIDI_MAX_ENDPOINTS];
  99. unsigned long input_triggered;
  100. };
  101. struct snd_usb_midi_out_endpoint {
  102. struct snd_usb_midi* umidi;
  103. struct urb* urb;
  104. int urb_active;
  105. int max_transfer; /* size of urb buffer */
  106. struct tasklet_struct tasklet;
  107. spinlock_t buffer_lock;
  108. struct usbmidi_out_port {
  109. struct snd_usb_midi_out_endpoint* ep;
  110. struct snd_rawmidi_substream *substream;
  111. int active;
  112. uint8_t cable; /* cable number << 4 */
  113. uint8_t state;
  114. #define STATE_UNKNOWN 0
  115. #define STATE_1PARAM 1
  116. #define STATE_2PARAM_1 2
  117. #define STATE_2PARAM_2 3
  118. #define STATE_SYSEX_0 4
  119. #define STATE_SYSEX_1 5
  120. #define STATE_SYSEX_2 6
  121. uint8_t data[2];
  122. } ports[0x10];
  123. int current_port;
  124. };
  125. struct snd_usb_midi_in_endpoint {
  126. struct snd_usb_midi* umidi;
  127. struct urb* urb;
  128. struct usbmidi_in_port {
  129. struct snd_rawmidi_substream *substream;
  130. } ports[0x10];
  131. u8 seen_f5;
  132. u8 error_resubmit;
  133. int current_port;
  134. };
  135. static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep);
  136. static const uint8_t snd_usbmidi_cin_length[] = {
  137. 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
  138. };
  139. /*
  140. * Submits the URB, with error handling.
  141. */
  142. static int snd_usbmidi_submit_urb(struct urb* urb, gfp_t flags)
  143. {
  144. int err = usb_submit_urb(urb, flags);
  145. if (err < 0 && err != -ENODEV)
  146. snd_printk(KERN_ERR "usb_submit_urb: %d\n", err);
  147. return err;
  148. }
  149. /*
  150. * Error handling for URB completion functions.
  151. */
  152. static int snd_usbmidi_urb_error(int status)
  153. {
  154. switch (status) {
  155. /* manually unlinked, or device gone */
  156. case -ENOENT:
  157. case -ECONNRESET:
  158. case -ESHUTDOWN:
  159. case -ENODEV:
  160. return -ENODEV;
  161. /* errors that might occur during unplugging */
  162. case -EPROTO: /* EHCI */
  163. case -ETIMEDOUT: /* OHCI */
  164. case -EILSEQ: /* UHCI */
  165. return -EIO;
  166. default:
  167. snd_printk(KERN_ERR "urb status %d\n", status);
  168. return 0; /* continue */
  169. }
  170. }
  171. /*
  172. * Receives a chunk of MIDI data.
  173. */
  174. static void snd_usbmidi_input_data(struct snd_usb_midi_in_endpoint* ep, int portidx,
  175. uint8_t* data, int length)
  176. {
  177. struct usbmidi_in_port* port = &ep->ports[portidx];
  178. if (!port->substream) {
  179. snd_printd("unexpected port %d!\n", portidx);
  180. return;
  181. }
  182. if (!test_bit(port->substream->number, &ep->umidi->input_triggered))
  183. return;
  184. snd_rawmidi_receive(port->substream, data, length);
  185. }
  186. #ifdef DUMP_PACKETS
  187. static void dump_urb(const char *type, const u8 *data, int length)
  188. {
  189. snd_printk(KERN_DEBUG "%s packet: [", type);
  190. for (; length > 0; ++data, --length)
  191. printk(" %02x", *data);
  192. printk(" ]\n");
  193. }
  194. #else
  195. #define dump_urb(type, data, length) /* nothing */
  196. #endif
  197. /*
  198. * Processes the data read from the device.
  199. */
  200. static void snd_usbmidi_in_urb_complete(struct urb* urb, struct pt_regs *regs)
  201. {
  202. struct snd_usb_midi_in_endpoint* ep = urb->context;
  203. if (urb->status == 0) {
  204. dump_urb("received", urb->transfer_buffer, urb->actual_length);
  205. ep->umidi->usb_protocol_ops->input(ep, urb->transfer_buffer,
  206. urb->actual_length);
  207. } else {
  208. int err = snd_usbmidi_urb_error(urb->status);
  209. if (err < 0) {
  210. if (err != -ENODEV) {
  211. ep->error_resubmit = 1;
  212. mod_timer(&ep->umidi->error_timer,
  213. jiffies + ERROR_DELAY_JIFFIES);
  214. }
  215. return;
  216. }
  217. }
  218. urb->dev = ep->umidi->chip->dev;
  219. snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
  220. }
  221. static void snd_usbmidi_out_urb_complete(struct urb* urb, struct pt_regs *regs)
  222. {
  223. struct snd_usb_midi_out_endpoint* ep = urb->context;
  224. spin_lock(&ep->buffer_lock);
  225. ep->urb_active = 0;
  226. spin_unlock(&ep->buffer_lock);
  227. if (urb->status < 0) {
  228. int err = snd_usbmidi_urb_error(urb->status);
  229. if (err < 0) {
  230. if (err != -ENODEV)
  231. mod_timer(&ep->umidi->error_timer,
  232. jiffies + ERROR_DELAY_JIFFIES);
  233. return;
  234. }
  235. }
  236. snd_usbmidi_do_output(ep);
  237. }
  238. /*
  239. * This is called when some data should be transferred to the device
  240. * (from one or more substreams).
  241. */
  242. static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
  243. {
  244. struct urb* urb = ep->urb;
  245. unsigned long flags;
  246. spin_lock_irqsave(&ep->buffer_lock, flags);
  247. if (ep->urb_active || ep->umidi->chip->shutdown) {
  248. spin_unlock_irqrestore(&ep->buffer_lock, flags);
  249. return;
  250. }
  251. urb->transfer_buffer_length = 0;
  252. ep->umidi->usb_protocol_ops->output(ep);
  253. if (urb->transfer_buffer_length > 0) {
  254. dump_urb("sending", urb->transfer_buffer,
  255. urb->transfer_buffer_length);
  256. urb->dev = ep->umidi->chip->dev;
  257. ep->urb_active = snd_usbmidi_submit_urb(urb, GFP_ATOMIC) >= 0;
  258. }
  259. spin_unlock_irqrestore(&ep->buffer_lock, flags);
  260. }
  261. static void snd_usbmidi_out_tasklet(unsigned long data)
  262. {
  263. struct snd_usb_midi_out_endpoint* ep = (struct snd_usb_midi_out_endpoint *) data;
  264. snd_usbmidi_do_output(ep);
  265. }
  266. /* called after transfers had been interrupted due to some USB error */
  267. static void snd_usbmidi_error_timer(unsigned long data)
  268. {
  269. struct snd_usb_midi *umidi = (struct snd_usb_midi *)data;
  270. int i;
  271. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  272. struct snd_usb_midi_in_endpoint *in = umidi->endpoints[i].in;
  273. if (in && in->error_resubmit) {
  274. in->error_resubmit = 0;
  275. in->urb->dev = umidi->chip->dev;
  276. snd_usbmidi_submit_urb(in->urb, GFP_ATOMIC);
  277. }
  278. if (umidi->endpoints[i].out)
  279. snd_usbmidi_do_output(umidi->endpoints[i].out);
  280. }
  281. }
  282. /* helper function to send static data that may not DMA-able */
  283. static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
  284. const void *data, int len)
  285. {
  286. int err;
  287. void *buf = kmalloc(len, GFP_KERNEL);
  288. if (!buf)
  289. return -ENOMEM;
  290. memcpy(buf, data, len);
  291. dump_urb("sending", buf, len);
  292. err = usb_bulk_msg(ep->umidi->chip->dev, ep->urb->pipe, buf, len,
  293. NULL, 250);
  294. kfree(buf);
  295. return err;
  296. }
  297. /*
  298. * Standard USB MIDI protocol: see the spec.
  299. * Midiman protocol: like the standard protocol, but the control byte is the
  300. * fourth byte in each packet, and uses length instead of CIN.
  301. */
  302. static void snd_usbmidi_standard_input(struct snd_usb_midi_in_endpoint* ep,
  303. uint8_t* buffer, int buffer_length)
  304. {
  305. int i;
  306. for (i = 0; i + 3 < buffer_length; i += 4)
  307. if (buffer[i] != 0) {
  308. int cable = buffer[i] >> 4;
  309. int length = snd_usbmidi_cin_length[buffer[i] & 0x0f];
  310. snd_usbmidi_input_data(ep, cable, &buffer[i + 1], length);
  311. }
  312. }
  313. static void snd_usbmidi_midiman_input(struct snd_usb_midi_in_endpoint* ep,
  314. uint8_t* buffer, int buffer_length)
  315. {
  316. int i;
  317. for (i = 0; i + 3 < buffer_length; i += 4)
  318. if (buffer[i + 3] != 0) {
  319. int port = buffer[i + 3] >> 4;
  320. int length = buffer[i + 3] & 3;
  321. snd_usbmidi_input_data(ep, port, &buffer[i], length);
  322. }
  323. }
  324. /*
  325. * Adds one USB MIDI packet to the output buffer.
  326. */
  327. static void snd_usbmidi_output_standard_packet(struct urb* urb, uint8_t p0,
  328. uint8_t p1, uint8_t p2, uint8_t p3)
  329. {
  330. uint8_t* buf = (uint8_t*)urb->transfer_buffer + urb->transfer_buffer_length;
  331. buf[0] = p0;
  332. buf[1] = p1;
  333. buf[2] = p2;
  334. buf[3] = p3;
  335. urb->transfer_buffer_length += 4;
  336. }
  337. /*
  338. * Adds one Midiman packet to the output buffer.
  339. */
  340. static void snd_usbmidi_output_midiman_packet(struct urb* urb, uint8_t p0,
  341. uint8_t p1, uint8_t p2, uint8_t p3)
  342. {
  343. uint8_t* buf = (uint8_t*)urb->transfer_buffer + urb->transfer_buffer_length;
  344. buf[0] = p1;
  345. buf[1] = p2;
  346. buf[2] = p3;
  347. buf[3] = (p0 & 0xf0) | snd_usbmidi_cin_length[p0 & 0x0f];
  348. urb->transfer_buffer_length += 4;
  349. }
  350. /*
  351. * Converts MIDI commands to USB MIDI packets.
  352. */
  353. static void snd_usbmidi_transmit_byte(struct usbmidi_out_port* port,
  354. uint8_t b, struct urb* urb)
  355. {
  356. uint8_t p0 = port->cable;
  357. void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t) =
  358. port->ep->umidi->usb_protocol_ops->output_packet;
  359. if (b >= 0xf8) {
  360. output_packet(urb, p0 | 0x0f, b, 0, 0);
  361. } else if (b >= 0xf0) {
  362. switch (b) {
  363. case 0xf0:
  364. port->data[0] = b;
  365. port->state = STATE_SYSEX_1;
  366. break;
  367. case 0xf1:
  368. case 0xf3:
  369. port->data[0] = b;
  370. port->state = STATE_1PARAM;
  371. break;
  372. case 0xf2:
  373. port->data[0] = b;
  374. port->state = STATE_2PARAM_1;
  375. break;
  376. case 0xf4:
  377. case 0xf5:
  378. port->state = STATE_UNKNOWN;
  379. break;
  380. case 0xf6:
  381. output_packet(urb, p0 | 0x05, 0xf6, 0, 0);
  382. port->state = STATE_UNKNOWN;
  383. break;
  384. case 0xf7:
  385. switch (port->state) {
  386. case STATE_SYSEX_0:
  387. output_packet(urb, p0 | 0x05, 0xf7, 0, 0);
  388. break;
  389. case STATE_SYSEX_1:
  390. output_packet(urb, p0 | 0x06, port->data[0], 0xf7, 0);
  391. break;
  392. case STATE_SYSEX_2:
  393. output_packet(urb, p0 | 0x07, port->data[0], port->data[1], 0xf7);
  394. break;
  395. }
  396. port->state = STATE_UNKNOWN;
  397. break;
  398. }
  399. } else if (b >= 0x80) {
  400. port->data[0] = b;
  401. if (b >= 0xc0 && b <= 0xdf)
  402. port->state = STATE_1PARAM;
  403. else
  404. port->state = STATE_2PARAM_1;
  405. } else { /* b < 0x80 */
  406. switch (port->state) {
  407. case STATE_1PARAM:
  408. if (port->data[0] < 0xf0) {
  409. p0 |= port->data[0] >> 4;
  410. } else {
  411. p0 |= 0x02;
  412. port->state = STATE_UNKNOWN;
  413. }
  414. output_packet(urb, p0, port->data[0], b, 0);
  415. break;
  416. case STATE_2PARAM_1:
  417. port->data[1] = b;
  418. port->state = STATE_2PARAM_2;
  419. break;
  420. case STATE_2PARAM_2:
  421. if (port->data[0] < 0xf0) {
  422. p0 |= port->data[0] >> 4;
  423. port->state = STATE_2PARAM_1;
  424. } else {
  425. p0 |= 0x03;
  426. port->state = STATE_UNKNOWN;
  427. }
  428. output_packet(urb, p0, port->data[0], port->data[1], b);
  429. break;
  430. case STATE_SYSEX_0:
  431. port->data[0] = b;
  432. port->state = STATE_SYSEX_1;
  433. break;
  434. case STATE_SYSEX_1:
  435. port->data[1] = b;
  436. port->state = STATE_SYSEX_2;
  437. break;
  438. case STATE_SYSEX_2:
  439. output_packet(urb, p0 | 0x04, port->data[0], port->data[1], b);
  440. port->state = STATE_SYSEX_0;
  441. break;
  442. }
  443. }
  444. }
  445. static void snd_usbmidi_standard_output(struct snd_usb_midi_out_endpoint* ep)
  446. {
  447. struct urb* urb = ep->urb;
  448. int p;
  449. /* FIXME: lower-numbered ports can starve higher-numbered ports */
  450. for (p = 0; p < 0x10; ++p) {
  451. struct usbmidi_out_port* port = &ep->ports[p];
  452. if (!port->active)
  453. continue;
  454. while (urb->transfer_buffer_length + 3 < ep->max_transfer) {
  455. uint8_t b;
  456. if (snd_rawmidi_transmit(port->substream, &b, 1) != 1) {
  457. port->active = 0;
  458. break;
  459. }
  460. snd_usbmidi_transmit_byte(port, b, urb);
  461. }
  462. }
  463. }
  464. static struct usb_protocol_ops snd_usbmidi_standard_ops = {
  465. .input = snd_usbmidi_standard_input,
  466. .output = snd_usbmidi_standard_output,
  467. .output_packet = snd_usbmidi_output_standard_packet,
  468. };
  469. static struct usb_protocol_ops snd_usbmidi_midiman_ops = {
  470. .input = snd_usbmidi_midiman_input,
  471. .output = snd_usbmidi_standard_output,
  472. .output_packet = snd_usbmidi_output_midiman_packet,
  473. };
  474. /*
  475. * Novation USB MIDI protocol: number of data bytes is in the first byte
  476. * (when receiving) (+1!) or in the second byte (when sending); data begins
  477. * at the third byte.
  478. */
  479. static void snd_usbmidi_novation_input(struct snd_usb_midi_in_endpoint* ep,
  480. uint8_t* buffer, int buffer_length)
  481. {
  482. if (buffer_length < 2 || !buffer[0] || buffer_length < buffer[0] + 1)
  483. return;
  484. snd_usbmidi_input_data(ep, 0, &buffer[2], buffer[0] - 1);
  485. }
  486. static void snd_usbmidi_novation_output(struct snd_usb_midi_out_endpoint* ep)
  487. {
  488. uint8_t* transfer_buffer;
  489. int count;
  490. if (!ep->ports[0].active)
  491. return;
  492. transfer_buffer = ep->urb->transfer_buffer;
  493. count = snd_rawmidi_transmit(ep->ports[0].substream,
  494. &transfer_buffer[2],
  495. ep->max_transfer - 2);
  496. if (count < 1) {
  497. ep->ports[0].active = 0;
  498. return;
  499. }
  500. transfer_buffer[0] = 0;
  501. transfer_buffer[1] = count;
  502. ep->urb->transfer_buffer_length = 2 + count;
  503. }
  504. static struct usb_protocol_ops snd_usbmidi_novation_ops = {
  505. .input = snd_usbmidi_novation_input,
  506. .output = snd_usbmidi_novation_output,
  507. };
  508. /*
  509. * "raw" protocol: used by the MOTU FastLane.
  510. */
  511. static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint* ep,
  512. uint8_t* buffer, int buffer_length)
  513. {
  514. snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
  515. }
  516. static void snd_usbmidi_raw_output(struct snd_usb_midi_out_endpoint* ep)
  517. {
  518. int count;
  519. if (!ep->ports[0].active)
  520. return;
  521. count = snd_rawmidi_transmit(ep->ports[0].substream,
  522. ep->urb->transfer_buffer,
  523. ep->max_transfer);
  524. if (count < 1) {
  525. ep->ports[0].active = 0;
  526. return;
  527. }
  528. ep->urb->transfer_buffer_length = count;
  529. }
  530. static struct usb_protocol_ops snd_usbmidi_raw_ops = {
  531. .input = snd_usbmidi_raw_input,
  532. .output = snd_usbmidi_raw_output,
  533. };
  534. /*
  535. * Emagic USB MIDI protocol: raw MIDI with "F5 xx" port switching.
  536. */
  537. static void snd_usbmidi_emagic_init_out(struct snd_usb_midi_out_endpoint* ep)
  538. {
  539. static const u8 init_data[] = {
  540. /* initialization magic: "get version" */
  541. 0xf0,
  542. 0x00, 0x20, 0x31, /* Emagic */
  543. 0x64, /* Unitor8 */
  544. 0x0b, /* version number request */
  545. 0x00, /* command version */
  546. 0x00, /* EEPROM, box 0 */
  547. 0xf7
  548. };
  549. send_bulk_static_data(ep, init_data, sizeof(init_data));
  550. /* while we're at it, pour on more magic */
  551. send_bulk_static_data(ep, init_data, sizeof(init_data));
  552. }
  553. static void snd_usbmidi_emagic_finish_out(struct snd_usb_midi_out_endpoint* ep)
  554. {
  555. static const u8 finish_data[] = {
  556. /* switch to patch mode with last preset */
  557. 0xf0,
  558. 0x00, 0x20, 0x31, /* Emagic */
  559. 0x64, /* Unitor8 */
  560. 0x10, /* patch switch command */
  561. 0x00, /* command version */
  562. 0x7f, /* to all boxes */
  563. 0x40, /* last preset in EEPROM */
  564. 0xf7
  565. };
  566. send_bulk_static_data(ep, finish_data, sizeof(finish_data));
  567. }
  568. static void snd_usbmidi_emagic_input(struct snd_usb_midi_in_endpoint* ep,
  569. uint8_t* buffer, int buffer_length)
  570. {
  571. int i;
  572. /* FF indicates end of valid data */
  573. for (i = 0; i < buffer_length; ++i)
  574. if (buffer[i] == 0xff) {
  575. buffer_length = i;
  576. break;
  577. }
  578. /* handle F5 at end of last buffer */
  579. if (ep->seen_f5)
  580. goto switch_port;
  581. while (buffer_length > 0) {
  582. /* determine size of data until next F5 */
  583. for (i = 0; i < buffer_length; ++i)
  584. if (buffer[i] == 0xf5)
  585. break;
  586. snd_usbmidi_input_data(ep, ep->current_port, buffer, i);
  587. buffer += i;
  588. buffer_length -= i;
  589. if (buffer_length <= 0)
  590. break;
  591. /* assert(buffer[0] == 0xf5); */
  592. ep->seen_f5 = 1;
  593. ++buffer;
  594. --buffer_length;
  595. switch_port:
  596. if (buffer_length <= 0)
  597. break;
  598. if (buffer[0] < 0x80) {
  599. ep->current_port = (buffer[0] - 1) & 15;
  600. ++buffer;
  601. --buffer_length;
  602. }
  603. ep->seen_f5 = 0;
  604. }
  605. }
  606. static void snd_usbmidi_emagic_output(struct snd_usb_midi_out_endpoint* ep)
  607. {
  608. int port0 = ep->current_port;
  609. uint8_t* buf = ep->urb->transfer_buffer;
  610. int buf_free = ep->max_transfer;
  611. int length, i;
  612. for (i = 0; i < 0x10; ++i) {
  613. /* round-robin, starting at the last current port */
  614. int portnum = (port0 + i) & 15;
  615. struct usbmidi_out_port* port = &ep->ports[portnum];
  616. if (!port->active)
  617. continue;
  618. if (snd_rawmidi_transmit_peek(port->substream, buf, 1) != 1) {
  619. port->active = 0;
  620. continue;
  621. }
  622. if (portnum != ep->current_port) {
  623. if (buf_free < 2)
  624. break;
  625. ep->current_port = portnum;
  626. buf[0] = 0xf5;
  627. buf[1] = (portnum + 1) & 15;
  628. buf += 2;
  629. buf_free -= 2;
  630. }
  631. if (buf_free < 1)
  632. break;
  633. length = snd_rawmidi_transmit(port->substream, buf, buf_free);
  634. if (length > 0) {
  635. buf += length;
  636. buf_free -= length;
  637. if (buf_free < 1)
  638. break;
  639. }
  640. }
  641. if (buf_free < ep->max_transfer && buf_free > 0) {
  642. *buf = 0xff;
  643. --buf_free;
  644. }
  645. ep->urb->transfer_buffer_length = ep->max_transfer - buf_free;
  646. }
  647. static struct usb_protocol_ops snd_usbmidi_emagic_ops = {
  648. .input = snd_usbmidi_emagic_input,
  649. .output = snd_usbmidi_emagic_output,
  650. .init_out_endpoint = snd_usbmidi_emagic_init_out,
  651. .finish_out_endpoint = snd_usbmidi_emagic_finish_out,
  652. };
  653. static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
  654. {
  655. struct snd_usb_midi* umidi = substream->rmidi->private_data;
  656. struct usbmidi_out_port* port = NULL;
  657. int i, j;
  658. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
  659. if (umidi->endpoints[i].out)
  660. for (j = 0; j < 0x10; ++j)
  661. if (umidi->endpoints[i].out->ports[j].substream == substream) {
  662. port = &umidi->endpoints[i].out->ports[j];
  663. break;
  664. }
  665. if (!port) {
  666. snd_BUG();
  667. return -ENXIO;
  668. }
  669. substream->runtime->private_data = port;
  670. port->state = STATE_UNKNOWN;
  671. return 0;
  672. }
  673. static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
  674. {
  675. return 0;
  676. }
  677. static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream, int up)
  678. {
  679. struct usbmidi_out_port* port = (struct usbmidi_out_port*)substream->runtime->private_data;
  680. port->active = up;
  681. if (up) {
  682. if (port->ep->umidi->chip->shutdown) {
  683. /* gobble up remaining bytes to prevent wait in
  684. * snd_rawmidi_drain_output */
  685. while (!snd_rawmidi_transmit_empty(substream))
  686. snd_rawmidi_transmit_ack(substream, 1);
  687. return;
  688. }
  689. tasklet_hi_schedule(&port->ep->tasklet);
  690. }
  691. }
  692. static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
  693. {
  694. return 0;
  695. }
  696. static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
  697. {
  698. return 0;
  699. }
  700. static void snd_usbmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
  701. {
  702. struct snd_usb_midi* umidi = substream->rmidi->private_data;
  703. if (up)
  704. set_bit(substream->number, &umidi->input_triggered);
  705. else
  706. clear_bit(substream->number, &umidi->input_triggered);
  707. }
  708. static struct snd_rawmidi_ops snd_usbmidi_output_ops = {
  709. .open = snd_usbmidi_output_open,
  710. .close = snd_usbmidi_output_close,
  711. .trigger = snd_usbmidi_output_trigger,
  712. };
  713. static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
  714. .open = snd_usbmidi_input_open,
  715. .close = snd_usbmidi_input_close,
  716. .trigger = snd_usbmidi_input_trigger
  717. };
  718. /*
  719. * Frees an input endpoint.
  720. * May be called when ep hasn't been initialized completely.
  721. */
  722. static void snd_usbmidi_in_endpoint_delete(struct snd_usb_midi_in_endpoint* ep)
  723. {
  724. if (ep->urb) {
  725. usb_buffer_free(ep->umidi->chip->dev,
  726. ep->urb->transfer_buffer_length,
  727. ep->urb->transfer_buffer,
  728. ep->urb->transfer_dma);
  729. usb_free_urb(ep->urb);
  730. }
  731. kfree(ep);
  732. }
  733. /*
  734. * Creates an input endpoint.
  735. */
  736. static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
  737. struct snd_usb_midi_endpoint_info* ep_info,
  738. struct snd_usb_midi_endpoint* rep)
  739. {
  740. struct snd_usb_midi_in_endpoint* ep;
  741. void* buffer;
  742. unsigned int pipe;
  743. int length;
  744. rep->in = NULL;
  745. ep = kzalloc(sizeof(*ep), GFP_KERNEL);
  746. if (!ep)
  747. return -ENOMEM;
  748. ep->umidi = umidi;
  749. ep->urb = usb_alloc_urb(0, GFP_KERNEL);
  750. if (!ep->urb) {
  751. snd_usbmidi_in_endpoint_delete(ep);
  752. return -ENOMEM;
  753. }
  754. if (ep_info->in_interval)
  755. pipe = usb_rcvintpipe(umidi->chip->dev, ep_info->in_ep);
  756. else
  757. pipe = usb_rcvbulkpipe(umidi->chip->dev, ep_info->in_ep);
  758. length = usb_maxpacket(umidi->chip->dev, pipe, 0);
  759. buffer = usb_buffer_alloc(umidi->chip->dev, length, GFP_KERNEL,
  760. &ep->urb->transfer_dma);
  761. if (!buffer) {
  762. snd_usbmidi_in_endpoint_delete(ep);
  763. return -ENOMEM;
  764. }
  765. if (ep_info->in_interval)
  766. usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer,
  767. length, snd_usbmidi_in_urb_complete, ep,
  768. ep_info->in_interval);
  769. else
  770. usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
  771. length, snd_usbmidi_in_urb_complete, ep);
  772. ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
  773. rep->in = ep;
  774. return 0;
  775. }
  776. static unsigned int snd_usbmidi_count_bits(unsigned int x)
  777. {
  778. unsigned int bits = 0;
  779. for (; x; x >>= 1)
  780. bits += x & 1;
  781. return bits;
  782. }
  783. /*
  784. * Frees an output endpoint.
  785. * May be called when ep hasn't been initialized completely.
  786. */
  787. static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint* ep)
  788. {
  789. if (ep->urb) {
  790. usb_buffer_free(ep->umidi->chip->dev, ep->max_transfer,
  791. ep->urb->transfer_buffer,
  792. ep->urb->transfer_dma);
  793. usb_free_urb(ep->urb);
  794. }
  795. kfree(ep);
  796. }
  797. /*
  798. * Creates an output endpoint, and initializes output ports.
  799. */
  800. static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
  801. struct snd_usb_midi_endpoint_info* ep_info,
  802. struct snd_usb_midi_endpoint* rep)
  803. {
  804. struct snd_usb_midi_out_endpoint* ep;
  805. int i;
  806. unsigned int pipe;
  807. void* buffer;
  808. rep->out = NULL;
  809. ep = kzalloc(sizeof(*ep), GFP_KERNEL);
  810. if (!ep)
  811. return -ENOMEM;
  812. ep->umidi = umidi;
  813. ep->urb = usb_alloc_urb(0, GFP_KERNEL);
  814. if (!ep->urb) {
  815. snd_usbmidi_out_endpoint_delete(ep);
  816. return -ENOMEM;
  817. }
  818. /* we never use interrupt output pipes */
  819. pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep);
  820. ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1);
  821. buffer = usb_buffer_alloc(umidi->chip->dev, ep->max_transfer,
  822. GFP_KERNEL, &ep->urb->transfer_dma);
  823. if (!buffer) {
  824. snd_usbmidi_out_endpoint_delete(ep);
  825. return -ENOMEM;
  826. }
  827. usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
  828. ep->max_transfer, snd_usbmidi_out_urb_complete, ep);
  829. ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
  830. spin_lock_init(&ep->buffer_lock);
  831. tasklet_init(&ep->tasklet, snd_usbmidi_out_tasklet, (unsigned long)ep);
  832. for (i = 0; i < 0x10; ++i)
  833. if (ep_info->out_cables & (1 << i)) {
  834. ep->ports[i].ep = ep;
  835. ep->ports[i].cable = i << 4;
  836. }
  837. if (umidi->usb_protocol_ops->init_out_endpoint)
  838. umidi->usb_protocol_ops->init_out_endpoint(ep);
  839. rep->out = ep;
  840. return 0;
  841. }
  842. /*
  843. * Frees everything.
  844. */
  845. static void snd_usbmidi_free(struct snd_usb_midi* umidi)
  846. {
  847. int i;
  848. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  849. struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
  850. if (ep->out)
  851. snd_usbmidi_out_endpoint_delete(ep->out);
  852. if (ep->in)
  853. snd_usbmidi_in_endpoint_delete(ep->in);
  854. }
  855. kfree(umidi);
  856. }
  857. /*
  858. * Unlinks all URBs (must be done before the usb_device is deleted).
  859. */
  860. void snd_usbmidi_disconnect(struct list_head* p)
  861. {
  862. struct snd_usb_midi* umidi;
  863. int i;
  864. umidi = list_entry(p, struct snd_usb_midi, list);
  865. del_timer_sync(&umidi->error_timer);
  866. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  867. struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
  868. if (ep->out)
  869. tasklet_kill(&ep->out->tasklet);
  870. if (ep->out && ep->out->urb) {
  871. usb_kill_urb(ep->out->urb);
  872. if (umidi->usb_protocol_ops->finish_out_endpoint)
  873. umidi->usb_protocol_ops->finish_out_endpoint(ep->out);
  874. }
  875. if (ep->in && ep->in->urb)
  876. usb_kill_urb(ep->in->urb);
  877. }
  878. }
  879. static void snd_usbmidi_rawmidi_free(struct snd_rawmidi *rmidi)
  880. {
  881. struct snd_usb_midi* umidi = rmidi->private_data;
  882. snd_usbmidi_free(umidi);
  883. }
  884. static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_midi* umidi,
  885. int stream, int number)
  886. {
  887. struct list_head* list;
  888. list_for_each(list, &umidi->rmidi->streams[stream].substreams) {
  889. struct snd_rawmidi_substream *substream = list_entry(list, struct snd_rawmidi_substream, list);
  890. if (substream->number == number)
  891. return substream;
  892. }
  893. return NULL;
  894. }
  895. /*
  896. * This list specifies names for ports that do not fit into the standard
  897. * "(product) MIDI (n)" schema because they aren't external MIDI ports,
  898. * such as internal control or synthesizer ports.
  899. */
  900. static struct {
  901. u32 id;
  902. int port;
  903. const char *name_format;
  904. } snd_usbmidi_port_names[] = {
  905. /* Roland UA-100 */
  906. { USB_ID(0x0582, 0x0000), 2, "%s Control" },
  907. /* Roland SC-8850 */
  908. { USB_ID(0x0582, 0x0003), 0, "%s Part A" },
  909. { USB_ID(0x0582, 0x0003), 1, "%s Part B" },
  910. { USB_ID(0x0582, 0x0003), 2, "%s Part C" },
  911. { USB_ID(0x0582, 0x0003), 3, "%s Part D" },
  912. { USB_ID(0x0582, 0x0003), 4, "%s MIDI 1" },
  913. { USB_ID(0x0582, 0x0003), 5, "%s MIDI 2" },
  914. /* Roland U-8 */
  915. { USB_ID(0x0582, 0x0004), 0, "%s MIDI" },
  916. { USB_ID(0x0582, 0x0004), 1, "%s Control" },
  917. /* Roland SC-8820 */
  918. { USB_ID(0x0582, 0x0007), 0, "%s Part A" },
  919. { USB_ID(0x0582, 0x0007), 1, "%s Part B" },
  920. { USB_ID(0x0582, 0x0007), 2, "%s MIDI" },
  921. /* Roland SK-500 */
  922. { USB_ID(0x0582, 0x000b), 0, "%s Part A" },
  923. { USB_ID(0x0582, 0x000b), 1, "%s Part B" },
  924. { USB_ID(0x0582, 0x000b), 2, "%s MIDI" },
  925. /* Roland SC-D70 */
  926. { USB_ID(0x0582, 0x000c), 0, "%s Part A" },
  927. { USB_ID(0x0582, 0x000c), 1, "%s Part B" },
  928. { USB_ID(0x0582, 0x000c), 2, "%s MIDI" },
  929. /* Edirol UM-880 */
  930. { USB_ID(0x0582, 0x0014), 8, "%s Control" },
  931. /* Edirol SD-90 */
  932. { USB_ID(0x0582, 0x0016), 0, "%s Part A" },
  933. { USB_ID(0x0582, 0x0016), 1, "%s Part B" },
  934. { USB_ID(0x0582, 0x0016), 2, "%s MIDI 1" },
  935. { USB_ID(0x0582, 0x0016), 3, "%s MIDI 2" },
  936. /* Edirol UM-550 */
  937. { USB_ID(0x0582, 0x0023), 5, "%s Control" },
  938. /* Edirol SD-20 */
  939. { USB_ID(0x0582, 0x0027), 0, "%s Part A" },
  940. { USB_ID(0x0582, 0x0027), 1, "%s Part B" },
  941. { USB_ID(0x0582, 0x0027), 2, "%s MIDI" },
  942. /* Edirol SD-80 */
  943. { USB_ID(0x0582, 0x0029), 0, "%s Part A" },
  944. { USB_ID(0x0582, 0x0029), 1, "%s Part B" },
  945. { USB_ID(0x0582, 0x0029), 2, "%s MIDI 1" },
  946. { USB_ID(0x0582, 0x0029), 3, "%s MIDI 2" },
  947. /* Edirol UA-700 */
  948. { USB_ID(0x0582, 0x002b), 0, "%s MIDI" },
  949. { USB_ID(0x0582, 0x002b), 1, "%s Control" },
  950. /* Roland VariOS */
  951. { USB_ID(0x0582, 0x002f), 0, "%s MIDI" },
  952. { USB_ID(0x0582, 0x002f), 1, "%s External MIDI" },
  953. { USB_ID(0x0582, 0x002f), 2, "%s Sync" },
  954. /* Edirol PCR */
  955. { USB_ID(0x0582, 0x0033), 0, "%s MIDI" },
  956. { USB_ID(0x0582, 0x0033), 1, "%s 1" },
  957. { USB_ID(0x0582, 0x0033), 2, "%s 2" },
  958. /* BOSS GS-10 */
  959. { USB_ID(0x0582, 0x003b), 0, "%s MIDI" },
  960. { USB_ID(0x0582, 0x003b), 1, "%s Control" },
  961. /* Edirol UA-1000 */
  962. { USB_ID(0x0582, 0x0044), 0, "%s MIDI" },
  963. { USB_ID(0x0582, 0x0044), 1, "%s Control" },
  964. /* Edirol UR-80 */
  965. { USB_ID(0x0582, 0x0048), 0, "%s MIDI" },
  966. { USB_ID(0x0582, 0x0048), 1, "%s 1" },
  967. { USB_ID(0x0582, 0x0048), 2, "%s 2" },
  968. /* Edirol PCR-A */
  969. { USB_ID(0x0582, 0x004d), 0, "%s MIDI" },
  970. { USB_ID(0x0582, 0x004d), 1, "%s 1" },
  971. { USB_ID(0x0582, 0x004d), 2, "%s 2" },
  972. /* M-Audio MidiSport 8x8 */
  973. { USB_ID(0x0763, 0x1031), 8, "%s Control" },
  974. { USB_ID(0x0763, 0x1033), 8, "%s Control" },
  975. /* MOTU Fastlane */
  976. { USB_ID(0x07fd, 0x0001), 0, "%s MIDI A" },
  977. { USB_ID(0x07fd, 0x0001), 1, "%s MIDI B" },
  978. /* Emagic Unitor8/AMT8/MT4 */
  979. { USB_ID(0x086a, 0x0001), 8, "%s Broadcast" },
  980. { USB_ID(0x086a, 0x0002), 8, "%s Broadcast" },
  981. { USB_ID(0x086a, 0x0003), 4, "%s Broadcast" },
  982. };
  983. static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
  984. int stream, int number,
  985. struct snd_rawmidi_substream ** rsubstream)
  986. {
  987. int i;
  988. const char *name_format;
  989. struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number);
  990. if (!substream) {
  991. snd_printd(KERN_ERR "substream %d:%d not found\n", stream, number);
  992. return;
  993. }
  994. /* TODO: read port name from jack descriptor */
  995. name_format = "%s MIDI %d";
  996. for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_names); ++i) {
  997. if (snd_usbmidi_port_names[i].id == umidi->chip->usb_id &&
  998. snd_usbmidi_port_names[i].port == number) {
  999. name_format = snd_usbmidi_port_names[i].name_format;
  1000. break;
  1001. }
  1002. }
  1003. snprintf(substream->name, sizeof(substream->name),
  1004. name_format, umidi->chip->card->shortname, number + 1);
  1005. *rsubstream = substream;
  1006. }
  1007. /*
  1008. * Creates the endpoints and their ports.
  1009. */
  1010. static int snd_usbmidi_create_endpoints(struct snd_usb_midi* umidi,
  1011. struct snd_usb_midi_endpoint_info* endpoints)
  1012. {
  1013. int i, j, err;
  1014. int out_ports = 0, in_ports = 0;
  1015. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1016. if (endpoints[i].out_cables) {
  1017. err = snd_usbmidi_out_endpoint_create(umidi, &endpoints[i],
  1018. &umidi->endpoints[i]);
  1019. if (err < 0)
  1020. return err;
  1021. }
  1022. if (endpoints[i].in_cables) {
  1023. err = snd_usbmidi_in_endpoint_create(umidi, &endpoints[i],
  1024. &umidi->endpoints[i]);
  1025. if (err < 0)
  1026. return err;
  1027. }
  1028. for (j = 0; j < 0x10; ++j) {
  1029. if (endpoints[i].out_cables & (1 << j)) {
  1030. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_OUTPUT, out_ports,
  1031. &umidi->endpoints[i].out->ports[j].substream);
  1032. ++out_ports;
  1033. }
  1034. if (endpoints[i].in_cables & (1 << j)) {
  1035. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_INPUT, in_ports,
  1036. &umidi->endpoints[i].in->ports[j].substream);
  1037. ++in_ports;
  1038. }
  1039. }
  1040. }
  1041. snd_printdd(KERN_INFO "created %d output and %d input ports\n",
  1042. out_ports, in_ports);
  1043. return 0;
  1044. }
  1045. /*
  1046. * Returns MIDIStreaming device capabilities.
  1047. */
  1048. static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
  1049. struct snd_usb_midi_endpoint_info* endpoints)
  1050. {
  1051. struct usb_interface* intf;
  1052. struct usb_host_interface *hostif;
  1053. struct usb_interface_descriptor* intfd;
  1054. struct usb_ms_header_descriptor* ms_header;
  1055. struct usb_host_endpoint *hostep;
  1056. struct usb_endpoint_descriptor* ep;
  1057. struct usb_ms_endpoint_descriptor* ms_ep;
  1058. int i, epidx;
  1059. intf = umidi->iface;
  1060. if (!intf)
  1061. return -ENXIO;
  1062. hostif = &intf->altsetting[0];
  1063. intfd = get_iface_desc(hostif);
  1064. ms_header = (struct usb_ms_header_descriptor*)hostif->extra;
  1065. if (hostif->extralen >= 7 &&
  1066. ms_header->bLength >= 7 &&
  1067. ms_header->bDescriptorType == USB_DT_CS_INTERFACE &&
  1068. ms_header->bDescriptorSubtype == HEADER)
  1069. snd_printdd(KERN_INFO "MIDIStreaming version %02x.%02x\n",
  1070. ms_header->bcdMSC[1], ms_header->bcdMSC[0]);
  1071. else
  1072. snd_printk(KERN_WARNING "MIDIStreaming interface descriptor not found\n");
  1073. epidx = 0;
  1074. for (i = 0; i < intfd->bNumEndpoints; ++i) {
  1075. hostep = &hostif->endpoint[i];
  1076. ep = get_ep_desc(hostep);
  1077. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK &&
  1078. (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
  1079. continue;
  1080. ms_ep = (struct usb_ms_endpoint_descriptor*)hostep->extra;
  1081. if (hostep->extralen < 4 ||
  1082. ms_ep->bLength < 4 ||
  1083. ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT ||
  1084. ms_ep->bDescriptorSubtype != MS_GENERAL)
  1085. continue;
  1086. if ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
  1087. if (endpoints[epidx].out_ep) {
  1088. if (++epidx >= MIDI_MAX_ENDPOINTS) {
  1089. snd_printk(KERN_WARNING "too many endpoints\n");
  1090. break;
  1091. }
  1092. }
  1093. endpoints[epidx].out_ep = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1094. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1095. endpoints[epidx].out_interval = ep->bInterval;
  1096. endpoints[epidx].out_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
  1097. snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
  1098. ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
  1099. } else {
  1100. if (endpoints[epidx].in_ep) {
  1101. if (++epidx >= MIDI_MAX_ENDPOINTS) {
  1102. snd_printk(KERN_WARNING "too many endpoints\n");
  1103. break;
  1104. }
  1105. }
  1106. endpoints[epidx].in_ep = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1107. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1108. endpoints[epidx].in_interval = ep->bInterval;
  1109. endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
  1110. snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
  1111. ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
  1112. }
  1113. }
  1114. return 0;
  1115. }
  1116. /*
  1117. * On Roland devices, use the second alternate setting to be able to use
  1118. * the interrupt input endpoint.
  1119. */
  1120. static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi* umidi)
  1121. {
  1122. struct usb_interface* intf;
  1123. struct usb_host_interface *hostif;
  1124. struct usb_interface_descriptor* intfd;
  1125. intf = umidi->iface;
  1126. if (!intf || intf->num_altsetting != 2)
  1127. return;
  1128. hostif = &intf->altsetting[1];
  1129. intfd = get_iface_desc(hostif);
  1130. if (intfd->bNumEndpoints != 2 ||
  1131. (get_endpoint(hostif, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK ||
  1132. (get_endpoint(hostif, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
  1133. return;
  1134. snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n",
  1135. intfd->bAlternateSetting);
  1136. usb_set_interface(umidi->chip->dev, intfd->bInterfaceNumber,
  1137. intfd->bAlternateSetting);
  1138. }
  1139. /*
  1140. * Try to find any usable endpoints in the interface.
  1141. */
  1142. static int snd_usbmidi_detect_endpoints(struct snd_usb_midi* umidi,
  1143. struct snd_usb_midi_endpoint_info* endpoint,
  1144. int max_endpoints)
  1145. {
  1146. struct usb_interface* intf;
  1147. struct usb_host_interface *hostif;
  1148. struct usb_interface_descriptor* intfd;
  1149. struct usb_endpoint_descriptor* epd;
  1150. int i, out_eps = 0, in_eps = 0;
  1151. if (USB_ID_VENDOR(umidi->chip->usb_id) == 0x0582)
  1152. snd_usbmidi_switch_roland_altsetting(umidi);
  1153. if (endpoint[0].out_ep || endpoint[0].in_ep)
  1154. return 0;
  1155. intf = umidi->iface;
  1156. if (!intf || intf->num_altsetting < 1)
  1157. return -ENOENT;
  1158. hostif = intf->cur_altsetting;
  1159. intfd = get_iface_desc(hostif);
  1160. for (i = 0; i < intfd->bNumEndpoints; ++i) {
  1161. epd = get_endpoint(hostif, i);
  1162. if ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK &&
  1163. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
  1164. continue;
  1165. if (out_eps < max_endpoints &&
  1166. (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
  1167. endpoint[out_eps].out_ep = epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1168. if ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1169. endpoint[out_eps].out_interval = epd->bInterval;
  1170. ++out_eps;
  1171. }
  1172. if (in_eps < max_endpoints &&
  1173. (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
  1174. endpoint[in_eps].in_ep = epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1175. if ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1176. endpoint[in_eps].in_interval = epd->bInterval;
  1177. ++in_eps;
  1178. }
  1179. }
  1180. return (out_eps || in_eps) ? 0 : -ENOENT;
  1181. }
  1182. /*
  1183. * Detects the endpoints for one-port-per-endpoint protocols.
  1184. */
  1185. static int snd_usbmidi_detect_per_port_endpoints(struct snd_usb_midi* umidi,
  1186. struct snd_usb_midi_endpoint_info* endpoints)
  1187. {
  1188. int err, i;
  1189. err = snd_usbmidi_detect_endpoints(umidi, endpoints, MIDI_MAX_ENDPOINTS);
  1190. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1191. if (endpoints[i].out_ep)
  1192. endpoints[i].out_cables = 0x0001;
  1193. if (endpoints[i].in_ep)
  1194. endpoints[i].in_cables = 0x0001;
  1195. }
  1196. return err;
  1197. }
  1198. /*
  1199. * Detects the endpoints and ports of Yamaha devices.
  1200. */
  1201. static int snd_usbmidi_detect_yamaha(struct snd_usb_midi* umidi,
  1202. struct snd_usb_midi_endpoint_info* endpoint)
  1203. {
  1204. struct usb_interface* intf;
  1205. struct usb_host_interface *hostif;
  1206. struct usb_interface_descriptor* intfd;
  1207. uint8_t* cs_desc;
  1208. intf = umidi->iface;
  1209. if (!intf)
  1210. return -ENOENT;
  1211. hostif = intf->altsetting;
  1212. intfd = get_iface_desc(hostif);
  1213. if (intfd->bNumEndpoints < 1)
  1214. return -ENOENT;
  1215. /*
  1216. * For each port there is one MIDI_IN/OUT_JACK descriptor, not
  1217. * necessarily with any useful contents. So simply count 'em.
  1218. */
  1219. for (cs_desc = hostif->extra;
  1220. cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
  1221. cs_desc += cs_desc[0]) {
  1222. if (cs_desc[1] == CS_AUDIO_INTERFACE) {
  1223. if (cs_desc[2] == MIDI_IN_JACK)
  1224. endpoint->in_cables = (endpoint->in_cables << 1) | 1;
  1225. else if (cs_desc[2] == MIDI_OUT_JACK)
  1226. endpoint->out_cables = (endpoint->out_cables << 1) | 1;
  1227. }
  1228. }
  1229. if (!endpoint->in_cables && !endpoint->out_cables)
  1230. return -ENOENT;
  1231. return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
  1232. }
  1233. /*
  1234. * Creates the endpoints and their ports for Midiman devices.
  1235. */
  1236. static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi,
  1237. struct snd_usb_midi_endpoint_info* endpoint)
  1238. {
  1239. struct snd_usb_midi_endpoint_info ep_info;
  1240. struct usb_interface* intf;
  1241. struct usb_host_interface *hostif;
  1242. struct usb_interface_descriptor* intfd;
  1243. struct usb_endpoint_descriptor* epd;
  1244. int cable, err;
  1245. intf = umidi->iface;
  1246. if (!intf)
  1247. return -ENOENT;
  1248. hostif = intf->altsetting;
  1249. intfd = get_iface_desc(hostif);
  1250. /*
  1251. * The various MidiSport devices have more or less random endpoint
  1252. * numbers, so we have to identify the endpoints by their index in
  1253. * the descriptor array, like the driver for that other OS does.
  1254. *
  1255. * There is one interrupt input endpoint for all input ports, one
  1256. * bulk output endpoint for even-numbered ports, and one for odd-
  1257. * numbered ports. Both bulk output endpoints have corresponding
  1258. * input bulk endpoints (at indices 1 and 3) which aren't used.
  1259. */
  1260. if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) {
  1261. snd_printdd(KERN_ERR "not enough endpoints\n");
  1262. return -ENOENT;
  1263. }
  1264. epd = get_endpoint(hostif, 0);
  1265. if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_IN ||
  1266. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) {
  1267. snd_printdd(KERN_ERR "endpoint[0] isn't interrupt\n");
  1268. return -ENXIO;
  1269. }
  1270. epd = get_endpoint(hostif, 2);
  1271. if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_OUT ||
  1272. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK) {
  1273. snd_printdd(KERN_ERR "endpoint[2] isn't bulk output\n");
  1274. return -ENXIO;
  1275. }
  1276. if (endpoint->out_cables > 0x0001) {
  1277. epd = get_endpoint(hostif, 4);
  1278. if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_OUT ||
  1279. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK) {
  1280. snd_printdd(KERN_ERR "endpoint[4] isn't bulk output\n");
  1281. return -ENXIO;
  1282. }
  1283. }
  1284. ep_info.out_ep = get_endpoint(hostif, 2)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1285. ep_info.out_cables = endpoint->out_cables & 0x5555;
  1286. err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->endpoints[0]);
  1287. if (err < 0)
  1288. return err;
  1289. ep_info.in_ep = get_endpoint(hostif, 0)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1290. ep_info.in_interval = get_endpoint(hostif, 0)->bInterval;
  1291. ep_info.in_cables = endpoint->in_cables;
  1292. err = snd_usbmidi_in_endpoint_create(umidi, &ep_info, &umidi->endpoints[0]);
  1293. if (err < 0)
  1294. return err;
  1295. if (endpoint->out_cables > 0x0001) {
  1296. ep_info.out_ep = get_endpoint(hostif, 4)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1297. ep_info.out_cables = endpoint->out_cables & 0xaaaa;
  1298. err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->endpoints[1]);
  1299. if (err < 0)
  1300. return err;
  1301. }
  1302. for (cable = 0; cable < 0x10; ++cable) {
  1303. if (endpoint->out_cables & (1 << cable))
  1304. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_OUTPUT, cable,
  1305. &umidi->endpoints[cable & 1].out->ports[cable].substream);
  1306. if (endpoint->in_cables & (1 << cable))
  1307. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_INPUT, cable,
  1308. &umidi->endpoints[0].in->ports[cable].substream);
  1309. }
  1310. return 0;
  1311. }
  1312. static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
  1313. int out_ports, int in_ports)
  1314. {
  1315. struct snd_rawmidi *rmidi;
  1316. int err;
  1317. err = snd_rawmidi_new(umidi->chip->card, "USB MIDI",
  1318. umidi->chip->next_midi_device++,
  1319. out_ports, in_ports, &rmidi);
  1320. if (err < 0)
  1321. return err;
  1322. strcpy(rmidi->name, umidi->chip->card->shortname);
  1323. rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
  1324. SNDRV_RAWMIDI_INFO_INPUT |
  1325. SNDRV_RAWMIDI_INFO_DUPLEX;
  1326. rmidi->private_data = umidi;
  1327. rmidi->private_free = snd_usbmidi_rawmidi_free;
  1328. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops);
  1329. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_usbmidi_input_ops);
  1330. umidi->rmidi = rmidi;
  1331. return 0;
  1332. }
  1333. /*
  1334. * Temporarily stop input.
  1335. */
  1336. void snd_usbmidi_input_stop(struct list_head* p)
  1337. {
  1338. struct snd_usb_midi* umidi;
  1339. int i;
  1340. umidi = list_entry(p, struct snd_usb_midi, list);
  1341. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1342. struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
  1343. if (ep->in)
  1344. usb_kill_urb(ep->in->urb);
  1345. }
  1346. }
  1347. static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
  1348. {
  1349. if (ep) {
  1350. struct urb* urb = ep->urb;
  1351. urb->dev = ep->umidi->chip->dev;
  1352. snd_usbmidi_submit_urb(urb, GFP_KERNEL);
  1353. }
  1354. }
  1355. /*
  1356. * Resume input after a call to snd_usbmidi_input_stop().
  1357. */
  1358. void snd_usbmidi_input_start(struct list_head* p)
  1359. {
  1360. struct snd_usb_midi* umidi;
  1361. int i;
  1362. umidi = list_entry(p, struct snd_usb_midi, list);
  1363. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
  1364. snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
  1365. }
  1366. /*
  1367. * Creates and registers everything needed for a MIDI streaming interface.
  1368. */
  1369. int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
  1370. struct usb_interface* iface,
  1371. const struct snd_usb_audio_quirk* quirk)
  1372. {
  1373. struct snd_usb_midi* umidi;
  1374. struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
  1375. int out_ports, in_ports;
  1376. int i, err;
  1377. umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
  1378. if (!umidi)
  1379. return -ENOMEM;
  1380. umidi->chip = chip;
  1381. umidi->iface = iface;
  1382. umidi->quirk = quirk;
  1383. umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
  1384. init_timer(&umidi->error_timer);
  1385. umidi->error_timer.function = snd_usbmidi_error_timer;
  1386. umidi->error_timer.data = (unsigned long)umidi;
  1387. /* detect the endpoint(s) to use */
  1388. memset(endpoints, 0, sizeof(endpoints));
  1389. switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
  1390. case QUIRK_MIDI_STANDARD_INTERFACE:
  1391. err = snd_usbmidi_get_ms_info(umidi, endpoints);
  1392. break;
  1393. case QUIRK_MIDI_FIXED_ENDPOINT:
  1394. memcpy(&endpoints[0], quirk->data,
  1395. sizeof(struct snd_usb_midi_endpoint_info));
  1396. err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
  1397. break;
  1398. case QUIRK_MIDI_YAMAHA:
  1399. err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
  1400. break;
  1401. case QUIRK_MIDI_MIDIMAN:
  1402. umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops;
  1403. memcpy(&endpoints[0], quirk->data,
  1404. sizeof(struct snd_usb_midi_endpoint_info));
  1405. err = 0;
  1406. break;
  1407. case QUIRK_MIDI_NOVATION:
  1408. umidi->usb_protocol_ops = &snd_usbmidi_novation_ops;
  1409. err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
  1410. break;
  1411. case QUIRK_MIDI_RAW:
  1412. umidi->usb_protocol_ops = &snd_usbmidi_raw_ops;
  1413. err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
  1414. break;
  1415. case QUIRK_MIDI_EMAGIC:
  1416. umidi->usb_protocol_ops = &snd_usbmidi_emagic_ops;
  1417. memcpy(&endpoints[0], quirk->data,
  1418. sizeof(struct snd_usb_midi_endpoint_info));
  1419. err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
  1420. break;
  1421. case QUIRK_MIDI_MIDITECH:
  1422. err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
  1423. break;
  1424. default:
  1425. snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
  1426. err = -ENXIO;
  1427. break;
  1428. }
  1429. if (err < 0) {
  1430. kfree(umidi);
  1431. return err;
  1432. }
  1433. /* create rawmidi device */
  1434. out_ports = 0;
  1435. in_ports = 0;
  1436. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1437. out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables);
  1438. in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables);
  1439. }
  1440. err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
  1441. if (err < 0) {
  1442. kfree(umidi);
  1443. return err;
  1444. }
  1445. /* create endpoint/port structures */
  1446. if (quirk && quirk->type == QUIRK_MIDI_MIDIMAN)
  1447. err = snd_usbmidi_create_endpoints_midiman(umidi, &endpoints[0]);
  1448. else
  1449. err = snd_usbmidi_create_endpoints(umidi, endpoints);
  1450. if (err < 0) {
  1451. snd_usbmidi_free(umidi);
  1452. return err;
  1453. }
  1454. list_add(&umidi->list, &umidi->chip->midi_list);
  1455. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
  1456. snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
  1457. return 0;
  1458. }
  1459. EXPORT_SYMBOL(snd_usb_create_midi_interface);
  1460. EXPORT_SYMBOL(snd_usbmidi_input_stop);
  1461. EXPORT_SYMBOL(snd_usbmidi_input_start);
  1462. EXPORT_SYMBOL(snd_usbmidi_disconnect);