usbmidi.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  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;
  779. for (bits = 0; x; ++bits)
  780. x &= 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. /* Edirol UM-3EX */
  973. { USB_ID(0x0582, 0x009a), 3, "%s Control" },
  974. /* M-Audio MidiSport 8x8 */
  975. { USB_ID(0x0763, 0x1031), 8, "%s Control" },
  976. { USB_ID(0x0763, 0x1033), 8, "%s Control" },
  977. /* MOTU Fastlane */
  978. { USB_ID(0x07fd, 0x0001), 0, "%s MIDI A" },
  979. { USB_ID(0x07fd, 0x0001), 1, "%s MIDI B" },
  980. /* Emagic Unitor8/AMT8/MT4 */
  981. { USB_ID(0x086a, 0x0001), 8, "%s Broadcast" },
  982. { USB_ID(0x086a, 0x0002), 8, "%s Broadcast" },
  983. { USB_ID(0x086a, 0x0003), 4, "%s Broadcast" },
  984. };
  985. static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
  986. int stream, int number,
  987. struct snd_rawmidi_substream ** rsubstream)
  988. {
  989. int i;
  990. const char *name_format;
  991. struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number);
  992. if (!substream) {
  993. snd_printd(KERN_ERR "substream %d:%d not found\n", stream, number);
  994. return;
  995. }
  996. /* TODO: read port name from jack descriptor */
  997. name_format = "%s MIDI %d";
  998. for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_names); ++i) {
  999. if (snd_usbmidi_port_names[i].id == umidi->chip->usb_id &&
  1000. snd_usbmidi_port_names[i].port == number) {
  1001. name_format = snd_usbmidi_port_names[i].name_format;
  1002. break;
  1003. }
  1004. }
  1005. snprintf(substream->name, sizeof(substream->name),
  1006. name_format, umidi->chip->card->shortname, number + 1);
  1007. *rsubstream = substream;
  1008. }
  1009. /*
  1010. * Creates the endpoints and their ports.
  1011. */
  1012. static int snd_usbmidi_create_endpoints(struct snd_usb_midi* umidi,
  1013. struct snd_usb_midi_endpoint_info* endpoints)
  1014. {
  1015. int i, j, err;
  1016. int out_ports = 0, in_ports = 0;
  1017. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1018. if (endpoints[i].out_cables) {
  1019. err = snd_usbmidi_out_endpoint_create(umidi, &endpoints[i],
  1020. &umidi->endpoints[i]);
  1021. if (err < 0)
  1022. return err;
  1023. }
  1024. if (endpoints[i].in_cables) {
  1025. err = snd_usbmidi_in_endpoint_create(umidi, &endpoints[i],
  1026. &umidi->endpoints[i]);
  1027. if (err < 0)
  1028. return err;
  1029. }
  1030. for (j = 0; j < 0x10; ++j) {
  1031. if (endpoints[i].out_cables & (1 << j)) {
  1032. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_OUTPUT, out_ports,
  1033. &umidi->endpoints[i].out->ports[j].substream);
  1034. ++out_ports;
  1035. }
  1036. if (endpoints[i].in_cables & (1 << j)) {
  1037. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_INPUT, in_ports,
  1038. &umidi->endpoints[i].in->ports[j].substream);
  1039. ++in_ports;
  1040. }
  1041. }
  1042. }
  1043. snd_printdd(KERN_INFO "created %d output and %d input ports\n",
  1044. out_ports, in_ports);
  1045. return 0;
  1046. }
  1047. /*
  1048. * Returns MIDIStreaming device capabilities.
  1049. */
  1050. static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
  1051. struct snd_usb_midi_endpoint_info* endpoints)
  1052. {
  1053. struct usb_interface* intf;
  1054. struct usb_host_interface *hostif;
  1055. struct usb_interface_descriptor* intfd;
  1056. struct usb_ms_header_descriptor* ms_header;
  1057. struct usb_host_endpoint *hostep;
  1058. struct usb_endpoint_descriptor* ep;
  1059. struct usb_ms_endpoint_descriptor* ms_ep;
  1060. int i, epidx;
  1061. intf = umidi->iface;
  1062. if (!intf)
  1063. return -ENXIO;
  1064. hostif = &intf->altsetting[0];
  1065. intfd = get_iface_desc(hostif);
  1066. ms_header = (struct usb_ms_header_descriptor*)hostif->extra;
  1067. if (hostif->extralen >= 7 &&
  1068. ms_header->bLength >= 7 &&
  1069. ms_header->bDescriptorType == USB_DT_CS_INTERFACE &&
  1070. ms_header->bDescriptorSubtype == HEADER)
  1071. snd_printdd(KERN_INFO "MIDIStreaming version %02x.%02x\n",
  1072. ms_header->bcdMSC[1], ms_header->bcdMSC[0]);
  1073. else
  1074. snd_printk(KERN_WARNING "MIDIStreaming interface descriptor not found\n");
  1075. epidx = 0;
  1076. for (i = 0; i < intfd->bNumEndpoints; ++i) {
  1077. hostep = &hostif->endpoint[i];
  1078. ep = get_ep_desc(hostep);
  1079. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK &&
  1080. (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
  1081. continue;
  1082. ms_ep = (struct usb_ms_endpoint_descriptor*)hostep->extra;
  1083. if (hostep->extralen < 4 ||
  1084. ms_ep->bLength < 4 ||
  1085. ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT ||
  1086. ms_ep->bDescriptorSubtype != MS_GENERAL)
  1087. continue;
  1088. if ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
  1089. if (endpoints[epidx].out_ep) {
  1090. if (++epidx >= MIDI_MAX_ENDPOINTS) {
  1091. snd_printk(KERN_WARNING "too many endpoints\n");
  1092. break;
  1093. }
  1094. }
  1095. endpoints[epidx].out_ep = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1096. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1097. endpoints[epidx].out_interval = ep->bInterval;
  1098. endpoints[epidx].out_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
  1099. snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
  1100. ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
  1101. } else {
  1102. if (endpoints[epidx].in_ep) {
  1103. if (++epidx >= MIDI_MAX_ENDPOINTS) {
  1104. snd_printk(KERN_WARNING "too many endpoints\n");
  1105. break;
  1106. }
  1107. }
  1108. endpoints[epidx].in_ep = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1109. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1110. endpoints[epidx].in_interval = ep->bInterval;
  1111. endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
  1112. snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
  1113. ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
  1114. }
  1115. }
  1116. return 0;
  1117. }
  1118. /*
  1119. * On Roland devices, use the second alternate setting to be able to use
  1120. * the interrupt input endpoint.
  1121. */
  1122. static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi* umidi)
  1123. {
  1124. struct usb_interface* intf;
  1125. struct usb_host_interface *hostif;
  1126. struct usb_interface_descriptor* intfd;
  1127. intf = umidi->iface;
  1128. if (!intf || intf->num_altsetting != 2)
  1129. return;
  1130. hostif = &intf->altsetting[1];
  1131. intfd = get_iface_desc(hostif);
  1132. if (intfd->bNumEndpoints != 2 ||
  1133. (get_endpoint(hostif, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK ||
  1134. (get_endpoint(hostif, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
  1135. return;
  1136. snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n",
  1137. intfd->bAlternateSetting);
  1138. usb_set_interface(umidi->chip->dev, intfd->bInterfaceNumber,
  1139. intfd->bAlternateSetting);
  1140. }
  1141. /*
  1142. * Try to find any usable endpoints in the interface.
  1143. */
  1144. static int snd_usbmidi_detect_endpoints(struct snd_usb_midi* umidi,
  1145. struct snd_usb_midi_endpoint_info* endpoint,
  1146. int max_endpoints)
  1147. {
  1148. struct usb_interface* intf;
  1149. struct usb_host_interface *hostif;
  1150. struct usb_interface_descriptor* intfd;
  1151. struct usb_endpoint_descriptor* epd;
  1152. int i, out_eps = 0, in_eps = 0;
  1153. if (USB_ID_VENDOR(umidi->chip->usb_id) == 0x0582)
  1154. snd_usbmidi_switch_roland_altsetting(umidi);
  1155. if (endpoint[0].out_ep || endpoint[0].in_ep)
  1156. return 0;
  1157. intf = umidi->iface;
  1158. if (!intf || intf->num_altsetting < 1)
  1159. return -ENOENT;
  1160. hostif = intf->cur_altsetting;
  1161. intfd = get_iface_desc(hostif);
  1162. for (i = 0; i < intfd->bNumEndpoints; ++i) {
  1163. epd = get_endpoint(hostif, i);
  1164. if ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK &&
  1165. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
  1166. continue;
  1167. if (out_eps < max_endpoints &&
  1168. (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
  1169. endpoint[out_eps].out_ep = epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1170. if ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1171. endpoint[out_eps].out_interval = epd->bInterval;
  1172. ++out_eps;
  1173. }
  1174. if (in_eps < max_endpoints &&
  1175. (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
  1176. endpoint[in_eps].in_ep = epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1177. if ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
  1178. endpoint[in_eps].in_interval = epd->bInterval;
  1179. ++in_eps;
  1180. }
  1181. }
  1182. return (out_eps || in_eps) ? 0 : -ENOENT;
  1183. }
  1184. /*
  1185. * Detects the endpoints for one-port-per-endpoint protocols.
  1186. */
  1187. static int snd_usbmidi_detect_per_port_endpoints(struct snd_usb_midi* umidi,
  1188. struct snd_usb_midi_endpoint_info* endpoints)
  1189. {
  1190. int err, i;
  1191. err = snd_usbmidi_detect_endpoints(umidi, endpoints, MIDI_MAX_ENDPOINTS);
  1192. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1193. if (endpoints[i].out_ep)
  1194. endpoints[i].out_cables = 0x0001;
  1195. if (endpoints[i].in_ep)
  1196. endpoints[i].in_cables = 0x0001;
  1197. }
  1198. return err;
  1199. }
  1200. /*
  1201. * Detects the endpoints and ports of Yamaha devices.
  1202. */
  1203. static int snd_usbmidi_detect_yamaha(struct snd_usb_midi* umidi,
  1204. struct snd_usb_midi_endpoint_info* endpoint)
  1205. {
  1206. struct usb_interface* intf;
  1207. struct usb_host_interface *hostif;
  1208. struct usb_interface_descriptor* intfd;
  1209. uint8_t* cs_desc;
  1210. intf = umidi->iface;
  1211. if (!intf)
  1212. return -ENOENT;
  1213. hostif = intf->altsetting;
  1214. intfd = get_iface_desc(hostif);
  1215. if (intfd->bNumEndpoints < 1)
  1216. return -ENOENT;
  1217. /*
  1218. * For each port there is one MIDI_IN/OUT_JACK descriptor, not
  1219. * necessarily with any useful contents. So simply count 'em.
  1220. */
  1221. for (cs_desc = hostif->extra;
  1222. cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
  1223. cs_desc += cs_desc[0]) {
  1224. if (cs_desc[1] == CS_AUDIO_INTERFACE) {
  1225. if (cs_desc[2] == MIDI_IN_JACK)
  1226. endpoint->in_cables = (endpoint->in_cables << 1) | 1;
  1227. else if (cs_desc[2] == MIDI_OUT_JACK)
  1228. endpoint->out_cables = (endpoint->out_cables << 1) | 1;
  1229. }
  1230. }
  1231. if (!endpoint->in_cables && !endpoint->out_cables)
  1232. return -ENOENT;
  1233. return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
  1234. }
  1235. /*
  1236. * Creates the endpoints and their ports for Midiman devices.
  1237. */
  1238. static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi,
  1239. struct snd_usb_midi_endpoint_info* endpoint)
  1240. {
  1241. struct snd_usb_midi_endpoint_info ep_info;
  1242. struct usb_interface* intf;
  1243. struct usb_host_interface *hostif;
  1244. struct usb_interface_descriptor* intfd;
  1245. struct usb_endpoint_descriptor* epd;
  1246. int cable, err;
  1247. intf = umidi->iface;
  1248. if (!intf)
  1249. return -ENOENT;
  1250. hostif = intf->altsetting;
  1251. intfd = get_iface_desc(hostif);
  1252. /*
  1253. * The various MidiSport devices have more or less random endpoint
  1254. * numbers, so we have to identify the endpoints by their index in
  1255. * the descriptor array, like the driver for that other OS does.
  1256. *
  1257. * There is one interrupt input endpoint for all input ports, one
  1258. * bulk output endpoint for even-numbered ports, and one for odd-
  1259. * numbered ports. Both bulk output endpoints have corresponding
  1260. * input bulk endpoints (at indices 1 and 3) which aren't used.
  1261. */
  1262. if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) {
  1263. snd_printdd(KERN_ERR "not enough endpoints\n");
  1264. return -ENOENT;
  1265. }
  1266. epd = get_endpoint(hostif, 0);
  1267. if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_IN ||
  1268. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) {
  1269. snd_printdd(KERN_ERR "endpoint[0] isn't interrupt\n");
  1270. return -ENXIO;
  1271. }
  1272. epd = get_endpoint(hostif, 2);
  1273. if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_OUT ||
  1274. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK) {
  1275. snd_printdd(KERN_ERR "endpoint[2] isn't bulk output\n");
  1276. return -ENXIO;
  1277. }
  1278. if (endpoint->out_cables > 0x0001) {
  1279. epd = get_endpoint(hostif, 4);
  1280. if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_OUT ||
  1281. (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK) {
  1282. snd_printdd(KERN_ERR "endpoint[4] isn't bulk output\n");
  1283. return -ENXIO;
  1284. }
  1285. }
  1286. ep_info.out_ep = get_endpoint(hostif, 2)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1287. ep_info.out_cables = endpoint->out_cables & 0x5555;
  1288. err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->endpoints[0]);
  1289. if (err < 0)
  1290. return err;
  1291. ep_info.in_ep = get_endpoint(hostif, 0)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1292. ep_info.in_interval = get_endpoint(hostif, 0)->bInterval;
  1293. ep_info.in_cables = endpoint->in_cables;
  1294. err = snd_usbmidi_in_endpoint_create(umidi, &ep_info, &umidi->endpoints[0]);
  1295. if (err < 0)
  1296. return err;
  1297. if (endpoint->out_cables > 0x0001) {
  1298. ep_info.out_ep = get_endpoint(hostif, 4)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1299. ep_info.out_cables = endpoint->out_cables & 0xaaaa;
  1300. err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->endpoints[1]);
  1301. if (err < 0)
  1302. return err;
  1303. }
  1304. for (cable = 0; cable < 0x10; ++cable) {
  1305. if (endpoint->out_cables & (1 << cable))
  1306. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_OUTPUT, cable,
  1307. &umidi->endpoints[cable & 1].out->ports[cable].substream);
  1308. if (endpoint->in_cables & (1 << cable))
  1309. snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_INPUT, cable,
  1310. &umidi->endpoints[0].in->ports[cable].substream);
  1311. }
  1312. return 0;
  1313. }
  1314. static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
  1315. int out_ports, int in_ports)
  1316. {
  1317. struct snd_rawmidi *rmidi;
  1318. int err;
  1319. err = snd_rawmidi_new(umidi->chip->card, "USB MIDI",
  1320. umidi->chip->next_midi_device++,
  1321. out_ports, in_ports, &rmidi);
  1322. if (err < 0)
  1323. return err;
  1324. strcpy(rmidi->name, umidi->chip->card->shortname);
  1325. rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
  1326. SNDRV_RAWMIDI_INFO_INPUT |
  1327. SNDRV_RAWMIDI_INFO_DUPLEX;
  1328. rmidi->private_data = umidi;
  1329. rmidi->private_free = snd_usbmidi_rawmidi_free;
  1330. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops);
  1331. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_usbmidi_input_ops);
  1332. umidi->rmidi = rmidi;
  1333. return 0;
  1334. }
  1335. /*
  1336. * Temporarily stop input.
  1337. */
  1338. void snd_usbmidi_input_stop(struct list_head* p)
  1339. {
  1340. struct snd_usb_midi* umidi;
  1341. int i;
  1342. umidi = list_entry(p, struct snd_usb_midi, list);
  1343. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1344. struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
  1345. if (ep->in)
  1346. usb_kill_urb(ep->in->urb);
  1347. }
  1348. }
  1349. static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
  1350. {
  1351. if (ep) {
  1352. struct urb* urb = ep->urb;
  1353. urb->dev = ep->umidi->chip->dev;
  1354. snd_usbmidi_submit_urb(urb, GFP_KERNEL);
  1355. }
  1356. }
  1357. /*
  1358. * Resume input after a call to snd_usbmidi_input_stop().
  1359. */
  1360. void snd_usbmidi_input_start(struct list_head* p)
  1361. {
  1362. struct snd_usb_midi* umidi;
  1363. int i;
  1364. umidi = list_entry(p, struct snd_usb_midi, list);
  1365. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
  1366. snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
  1367. }
  1368. /*
  1369. * Creates and registers everything needed for a MIDI streaming interface.
  1370. */
  1371. int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
  1372. struct usb_interface* iface,
  1373. const struct snd_usb_audio_quirk* quirk)
  1374. {
  1375. struct snd_usb_midi* umidi;
  1376. struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
  1377. int out_ports, in_ports;
  1378. int i, err;
  1379. umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
  1380. if (!umidi)
  1381. return -ENOMEM;
  1382. umidi->chip = chip;
  1383. umidi->iface = iface;
  1384. umidi->quirk = quirk;
  1385. umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
  1386. init_timer(&umidi->error_timer);
  1387. umidi->error_timer.function = snd_usbmidi_error_timer;
  1388. umidi->error_timer.data = (unsigned long)umidi;
  1389. /* detect the endpoint(s) to use */
  1390. memset(endpoints, 0, sizeof(endpoints));
  1391. switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
  1392. case QUIRK_MIDI_STANDARD_INTERFACE:
  1393. err = snd_usbmidi_get_ms_info(umidi, endpoints);
  1394. break;
  1395. case QUIRK_MIDI_FIXED_ENDPOINT:
  1396. memcpy(&endpoints[0], quirk->data,
  1397. sizeof(struct snd_usb_midi_endpoint_info));
  1398. err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
  1399. break;
  1400. case QUIRK_MIDI_YAMAHA:
  1401. err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
  1402. break;
  1403. case QUIRK_MIDI_MIDIMAN:
  1404. umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops;
  1405. memcpy(&endpoints[0], quirk->data,
  1406. sizeof(struct snd_usb_midi_endpoint_info));
  1407. err = 0;
  1408. break;
  1409. case QUIRK_MIDI_NOVATION:
  1410. umidi->usb_protocol_ops = &snd_usbmidi_novation_ops;
  1411. err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
  1412. break;
  1413. case QUIRK_MIDI_RAW:
  1414. umidi->usb_protocol_ops = &snd_usbmidi_raw_ops;
  1415. err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
  1416. break;
  1417. case QUIRK_MIDI_EMAGIC:
  1418. umidi->usb_protocol_ops = &snd_usbmidi_emagic_ops;
  1419. memcpy(&endpoints[0], quirk->data,
  1420. sizeof(struct snd_usb_midi_endpoint_info));
  1421. err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
  1422. break;
  1423. case QUIRK_MIDI_CME:
  1424. err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
  1425. break;
  1426. default:
  1427. snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
  1428. err = -ENXIO;
  1429. break;
  1430. }
  1431. if (err < 0) {
  1432. kfree(umidi);
  1433. return err;
  1434. }
  1435. /* create rawmidi device */
  1436. out_ports = 0;
  1437. in_ports = 0;
  1438. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
  1439. out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables);
  1440. in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables);
  1441. }
  1442. err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
  1443. if (err < 0) {
  1444. kfree(umidi);
  1445. return err;
  1446. }
  1447. /* create endpoint/port structures */
  1448. if (quirk && quirk->type == QUIRK_MIDI_MIDIMAN)
  1449. err = snd_usbmidi_create_endpoints_midiman(umidi, &endpoints[0]);
  1450. else
  1451. err = snd_usbmidi_create_endpoints(umidi, endpoints);
  1452. if (err < 0) {
  1453. snd_usbmidi_free(umidi);
  1454. return err;
  1455. }
  1456. list_add(&umidi->list, &umidi->chip->midi_list);
  1457. for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
  1458. snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
  1459. return 0;
  1460. }
  1461. EXPORT_SYMBOL(snd_usb_create_midi_interface);
  1462. EXPORT_SYMBOL(snd_usbmidi_input_stop);
  1463. EXPORT_SYMBOL(snd_usbmidi_input_start);
  1464. EXPORT_SYMBOL(snd_usbmidi_disconnect);