mpu401_uart.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. * Routines for control of MPU-401 in UART mode
  5. *
  6. * MPU-401 supports UART mode which is not capable generate transmit
  7. * interrupts thus output is done via polling. Without interrupt,
  8. * input is done also via polling. Do not expect good performance.
  9. *
  10. * 13-03-2003:
  11. * Added support for different kind of hardware I/O. Build in choices
  12. * are port and mmio. For other kind of I/O, set mpu->read and
  13. * mpu->write to your own I/O functions.
  14. */
  15. #include <linux/io.h>
  16. #include <linux/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/ioport.h>
  20. #include <linux/module.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/errno.h>
  23. #include <sound/core.h>
  24. #include <sound/mpu401.h>
  25. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  26. MODULE_DESCRIPTION("Routines for control of MPU-401 in UART mode");
  27. MODULE_LICENSE("GPL");
  28. static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu);
  29. static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu);
  30. /*
  31. */
  32. #define snd_mpu401_input_avail(mpu) \
  33. (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_RX_EMPTY))
  34. #define snd_mpu401_output_ready(mpu) \
  35. (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_TX_FULL))
  36. /* Build in lowlevel io */
  37. static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data,
  38. unsigned long addr)
  39. {
  40. outb(data, addr);
  41. }
  42. static unsigned char mpu401_read_port(struct snd_mpu401 *mpu,
  43. unsigned long addr)
  44. {
  45. return inb(addr);
  46. }
  47. static void mpu401_write_mmio(struct snd_mpu401 *mpu, unsigned char data,
  48. unsigned long addr)
  49. {
  50. writeb(data, (void __iomem *)addr);
  51. }
  52. static unsigned char mpu401_read_mmio(struct snd_mpu401 *mpu,
  53. unsigned long addr)
  54. {
  55. return readb((void __iomem *)addr);
  56. }
  57. /* */
  58. static void snd_mpu401_uart_clear_rx(struct snd_mpu401 *mpu)
  59. {
  60. int timeout = 100000;
  61. for (; timeout > 0 && snd_mpu401_input_avail(mpu); timeout--)
  62. mpu->read(mpu, MPU401D(mpu));
  63. #ifdef CONFIG_SND_DEBUG
  64. if (timeout <= 0)
  65. dev_err(mpu->rmidi->dev,
  66. "cmd: clear rx timeout (status = 0x%x)\n",
  67. mpu->read(mpu, MPU401C(mpu)));
  68. #endif
  69. }
  70. static void uart_interrupt_tx(struct snd_mpu401 *mpu)
  71. {
  72. if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) &&
  73. test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) {
  74. guard(spinlock_irqsave)(&mpu->output_lock);
  75. snd_mpu401_uart_output_write(mpu);
  76. }
  77. }
  78. static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu)
  79. {
  80. if (mpu->info_flags & MPU401_INFO_INPUT) {
  81. guard(spinlock_irqsave)(&mpu->input_lock);
  82. if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode))
  83. snd_mpu401_uart_input_read(mpu);
  84. else
  85. snd_mpu401_uart_clear_rx(mpu);
  86. }
  87. if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
  88. /* ok. for better Tx performance try do some output
  89. when input is done */
  90. uart_interrupt_tx(mpu);
  91. }
  92. /**
  93. * snd_mpu401_uart_interrupt - generic MPU401-UART interrupt handler
  94. * @irq: the irq number
  95. * @dev_id: mpu401 instance
  96. *
  97. * Processes the interrupt for MPU401-UART i/o.
  98. *
  99. * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise.
  100. */
  101. irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id)
  102. {
  103. struct snd_mpu401 *mpu = dev_id;
  104. if (!mpu)
  105. return IRQ_NONE;
  106. _snd_mpu401_uart_interrupt(mpu);
  107. return IRQ_HANDLED;
  108. }
  109. EXPORT_SYMBOL(snd_mpu401_uart_interrupt);
  110. /**
  111. * snd_mpu401_uart_interrupt_tx - generic MPU401-UART transmit irq handler
  112. * @irq: the irq number
  113. * @dev_id: mpu401 instance
  114. *
  115. * Processes the interrupt for MPU401-UART output.
  116. *
  117. * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise.
  118. */
  119. irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id)
  120. {
  121. struct snd_mpu401 *mpu = dev_id;
  122. if (!mpu)
  123. return IRQ_NONE;
  124. uart_interrupt_tx(mpu);
  125. return IRQ_HANDLED;
  126. }
  127. EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx);
  128. /*
  129. * timer callback
  130. * reprogram the timer and call the interrupt job
  131. */
  132. static void snd_mpu401_uart_timer(struct timer_list *t)
  133. {
  134. struct snd_mpu401 *mpu = timer_container_of(mpu, t, timer);
  135. scoped_guard(spinlock_irqsave, &mpu->timer_lock) {
  136. /*mpu->mode |= MPU401_MODE_TIMER;*/
  137. mod_timer(&mpu->timer, 1 + jiffies);
  138. }
  139. if (mpu->rmidi)
  140. _snd_mpu401_uart_interrupt(mpu);
  141. }
  142. /*
  143. * initialize the timer callback if not programmed yet
  144. */
  145. static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input)
  146. {
  147. guard(spinlock_irqsave)(&mpu->timer_lock);
  148. if (mpu->timer_invoked == 0) {
  149. timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0);
  150. mod_timer(&mpu->timer, 1 + jiffies);
  151. }
  152. mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER :
  153. MPU401_MODE_OUTPUT_TIMER;
  154. }
  155. /*
  156. * remove the timer callback if still active
  157. */
  158. static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input)
  159. {
  160. guard(spinlock_irqsave)(&mpu->timer_lock);
  161. if (mpu->timer_invoked) {
  162. mpu->timer_invoked &= input ? ~MPU401_MODE_INPUT_TIMER :
  163. ~MPU401_MODE_OUTPUT_TIMER;
  164. if (! mpu->timer_invoked)
  165. timer_delete(&mpu->timer);
  166. }
  167. }
  168. /*
  169. * send a UART command
  170. * return zero if successful, non-zero for some errors
  171. */
  172. static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd,
  173. int ack)
  174. {
  175. int timeout, ok;
  176. guard(spinlock_irqsave)(&mpu->input_lock);
  177. if (mpu->hardware != MPU401_HW_TRID4DWAVE) {
  178. mpu->write(mpu, 0x00, MPU401D(mpu));
  179. /*snd_mpu401_uart_clear_rx(mpu);*/
  180. }
  181. /* ok. standard MPU-401 initialization */
  182. if (mpu->hardware != MPU401_HW_SB) {
  183. for (timeout = 1000; timeout > 0 &&
  184. !snd_mpu401_output_ready(mpu); timeout--)
  185. udelay(10);
  186. #ifdef CONFIG_SND_DEBUG
  187. if (!timeout)
  188. dev_err(mpu->rmidi->dev,
  189. "cmd: tx timeout (status = 0x%x)\n",
  190. mpu->read(mpu, MPU401C(mpu)));
  191. #endif
  192. }
  193. mpu->write(mpu, cmd, MPU401C(mpu));
  194. if (ack && !(mpu->info_flags & MPU401_INFO_NO_ACK)) {
  195. ok = 0;
  196. timeout = 10000;
  197. while (!ok && timeout-- > 0) {
  198. if (snd_mpu401_input_avail(mpu)) {
  199. if (mpu->read(mpu, MPU401D(mpu)) == MPU401_ACK)
  200. ok = 1;
  201. }
  202. }
  203. if (!ok && mpu->read(mpu, MPU401D(mpu)) == MPU401_ACK)
  204. ok = 1;
  205. } else
  206. ok = 1;
  207. if (!ok) {
  208. dev_err(mpu->rmidi->dev,
  209. "cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)\n",
  210. cmd, mpu->port,
  211. mpu->read(mpu, MPU401C(mpu)),
  212. mpu->read(mpu, MPU401D(mpu)));
  213. return 1;
  214. }
  215. return 0;
  216. }
  217. static int snd_mpu401_do_reset(struct snd_mpu401 *mpu)
  218. {
  219. if (snd_mpu401_uart_cmd(mpu, MPU401_RESET, 1))
  220. return -EIO;
  221. if (snd_mpu401_uart_cmd(mpu, MPU401_ENTER_UART, 0))
  222. return -EIO;
  223. return 0;
  224. }
  225. /*
  226. * input/output open/close - protected by open_mutex in rawmidi.c
  227. */
  228. static int snd_mpu401_uart_input_open(struct snd_rawmidi_substream *substream)
  229. {
  230. struct snd_mpu401 *mpu;
  231. int err;
  232. mpu = substream->rmidi->private_data;
  233. if (mpu->open_input) {
  234. err = mpu->open_input(mpu);
  235. if (err < 0)
  236. return err;
  237. }
  238. if (! test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode)) {
  239. if (snd_mpu401_do_reset(mpu) < 0)
  240. goto error_out;
  241. }
  242. mpu->substream_input = substream;
  243. set_bit(MPU401_MODE_BIT_INPUT, &mpu->mode);
  244. return 0;
  245. error_out:
  246. if (mpu->open_input && mpu->close_input)
  247. mpu->close_input(mpu);
  248. return -EIO;
  249. }
  250. static int snd_mpu401_uart_output_open(struct snd_rawmidi_substream *substream)
  251. {
  252. struct snd_mpu401 *mpu;
  253. int err;
  254. mpu = substream->rmidi->private_data;
  255. if (mpu->open_output) {
  256. err = mpu->open_output(mpu);
  257. if (err < 0)
  258. return err;
  259. }
  260. if (! test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) {
  261. if (snd_mpu401_do_reset(mpu) < 0)
  262. goto error_out;
  263. }
  264. mpu->substream_output = substream;
  265. set_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode);
  266. return 0;
  267. error_out:
  268. if (mpu->open_output && mpu->close_output)
  269. mpu->close_output(mpu);
  270. return -EIO;
  271. }
  272. static int snd_mpu401_uart_input_close(struct snd_rawmidi_substream *substream)
  273. {
  274. struct snd_mpu401 *mpu;
  275. int err = 0;
  276. mpu = substream->rmidi->private_data;
  277. clear_bit(MPU401_MODE_BIT_INPUT, &mpu->mode);
  278. mpu->substream_input = NULL;
  279. if (! test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode))
  280. err = snd_mpu401_uart_cmd(mpu, MPU401_RESET, 0);
  281. if (mpu->close_input)
  282. mpu->close_input(mpu);
  283. if (err)
  284. return -EIO;
  285. return 0;
  286. }
  287. static int snd_mpu401_uart_output_close(struct snd_rawmidi_substream *substream)
  288. {
  289. struct snd_mpu401 *mpu;
  290. int err = 0;
  291. mpu = substream->rmidi->private_data;
  292. clear_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode);
  293. mpu->substream_output = NULL;
  294. if (! test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode))
  295. err = snd_mpu401_uart_cmd(mpu, MPU401_RESET, 0);
  296. if (mpu->close_output)
  297. mpu->close_output(mpu);
  298. if (err)
  299. return -EIO;
  300. return 0;
  301. }
  302. /*
  303. * trigger input callback
  304. */
  305. static void
  306. snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
  307. {
  308. struct snd_mpu401 *mpu;
  309. int max = 64;
  310. mpu = substream->rmidi->private_data;
  311. if (up) {
  312. if (! test_and_set_bit(MPU401_MODE_BIT_INPUT_TRIGGER,
  313. &mpu->mode)) {
  314. /* first time - flush FIFO */
  315. while (max-- > 0)
  316. mpu->read(mpu, MPU401D(mpu));
  317. if (mpu->info_flags & MPU401_INFO_USE_TIMER)
  318. snd_mpu401_uart_add_timer(mpu, 1);
  319. }
  320. /* read data in advance */
  321. guard(spinlock_irqsave)(&mpu->input_lock);
  322. snd_mpu401_uart_input_read(mpu);
  323. } else {
  324. if (mpu->info_flags & MPU401_INFO_USE_TIMER)
  325. snd_mpu401_uart_remove_timer(mpu, 1);
  326. clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode);
  327. }
  328. }
  329. /*
  330. * transfer input pending data
  331. * call with input_lock spinlock held
  332. */
  333. static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu)
  334. {
  335. int max = 128;
  336. unsigned char byte;
  337. while (max-- > 0) {
  338. if (! snd_mpu401_input_avail(mpu))
  339. break; /* input not available */
  340. byte = mpu->read(mpu, MPU401D(mpu));
  341. if (test_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode))
  342. snd_rawmidi_receive(mpu->substream_input, &byte, 1);
  343. }
  344. }
  345. /*
  346. * Tx FIFO sizes:
  347. * CS4237B - 16 bytes
  348. * AudioDrive ES1688 - 12 bytes
  349. * S3 SonicVibes - 8 bytes
  350. * SoundBlaster AWE 64 - 2 bytes (ugly hardware)
  351. */
  352. /*
  353. * write output pending bytes
  354. * call with output_lock spinlock held
  355. */
  356. static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu)
  357. {
  358. unsigned char byte;
  359. int max = 256;
  360. do {
  361. if (snd_rawmidi_transmit_peek(mpu->substream_output,
  362. &byte, 1) == 1) {
  363. /*
  364. * Try twice because there is hardware that insists on
  365. * setting the output busy bit after each write.
  366. */
  367. if (!snd_mpu401_output_ready(mpu) &&
  368. !snd_mpu401_output_ready(mpu))
  369. break; /* Tx FIFO full - try again later */
  370. mpu->write(mpu, byte, MPU401D(mpu));
  371. snd_rawmidi_transmit_ack(mpu->substream_output, 1);
  372. } else {
  373. snd_mpu401_uart_remove_timer (mpu, 0);
  374. break; /* no other data - leave the tx loop */
  375. }
  376. } while (--max > 0);
  377. }
  378. /*
  379. * output trigger callback
  380. */
  381. static void
  382. snd_mpu401_uart_output_trigger(struct snd_rawmidi_substream *substream, int up)
  383. {
  384. struct snd_mpu401 *mpu;
  385. mpu = substream->rmidi->private_data;
  386. if (up) {
  387. set_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode);
  388. /* try to add the timer at each output trigger,
  389. * since the output timer might have been removed in
  390. * snd_mpu401_uart_output_write().
  391. */
  392. if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
  393. snd_mpu401_uart_add_timer(mpu, 0);
  394. /* output pending data */
  395. guard(spinlock_irqsave)(&mpu->output_lock);
  396. snd_mpu401_uart_output_write(mpu);
  397. } else {
  398. if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
  399. snd_mpu401_uart_remove_timer(mpu, 0);
  400. clear_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode);
  401. }
  402. }
  403. /*
  404. */
  405. static const struct snd_rawmidi_ops snd_mpu401_uart_output =
  406. {
  407. .open = snd_mpu401_uart_output_open,
  408. .close = snd_mpu401_uart_output_close,
  409. .trigger = snd_mpu401_uart_output_trigger,
  410. };
  411. static const struct snd_rawmidi_ops snd_mpu401_uart_input =
  412. {
  413. .open = snd_mpu401_uart_input_open,
  414. .close = snd_mpu401_uart_input_close,
  415. .trigger = snd_mpu401_uart_input_trigger,
  416. };
  417. static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)
  418. {
  419. struct snd_mpu401 *mpu = rmidi->private_data;
  420. if (mpu->irq >= 0)
  421. free_irq(mpu->irq, (void *) mpu);
  422. release_and_free_resource(mpu->res);
  423. kfree(mpu);
  424. }
  425. /**
  426. * snd_mpu401_uart_new - create an MPU401-UART instance
  427. * @card: the card instance
  428. * @device: the device index, zero-based
  429. * @hardware: the hardware type, MPU401_HW_XXXX
  430. * @port: the base address of MPU401 port
  431. * @info_flags: bitflags MPU401_INFO_XXX
  432. * @irq: the ISA irq number, -1 if not to be allocated
  433. * @rrawmidi: the pointer to store the new rawmidi instance
  434. *
  435. * Creates a new MPU-401 instance.
  436. *
  437. * Note that the rawmidi instance is returned on the rrawmidi argument,
  438. * not the mpu401 instance itself. To access to the mpu401 instance,
  439. * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast).
  440. *
  441. * Return: Zero if successful, or a negative error code.
  442. */
  443. int snd_mpu401_uart_new(struct snd_card *card, int device,
  444. unsigned short hardware,
  445. unsigned long port,
  446. unsigned int info_flags,
  447. int irq,
  448. struct snd_rawmidi ** rrawmidi)
  449. {
  450. struct snd_mpu401 *mpu;
  451. struct snd_rawmidi *rmidi;
  452. int in_enable, out_enable;
  453. int err;
  454. if (rrawmidi)
  455. *rrawmidi = NULL;
  456. if (! (info_flags & (MPU401_INFO_INPUT | MPU401_INFO_OUTPUT)))
  457. info_flags |= MPU401_INFO_INPUT | MPU401_INFO_OUTPUT;
  458. in_enable = (info_flags & MPU401_INFO_INPUT) ? 1 : 0;
  459. out_enable = (info_flags & MPU401_INFO_OUTPUT) ? 1 : 0;
  460. err = snd_rawmidi_new(card, "MPU-401U", device,
  461. out_enable, in_enable, &rmidi);
  462. if (err < 0)
  463. return err;
  464. mpu = kzalloc_obj(*mpu);
  465. if (!mpu) {
  466. err = -ENOMEM;
  467. goto free_device;
  468. }
  469. rmidi->private_data = mpu;
  470. rmidi->private_free = snd_mpu401_uart_free;
  471. spin_lock_init(&mpu->input_lock);
  472. spin_lock_init(&mpu->output_lock);
  473. spin_lock_init(&mpu->timer_lock);
  474. mpu->hardware = hardware;
  475. mpu->irq = -1;
  476. mpu->rmidi = rmidi;
  477. if (! (info_flags & MPU401_INFO_INTEGRATED)) {
  478. int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
  479. mpu->res = request_region(port, res_size, "MPU401 UART");
  480. if (!mpu->res) {
  481. dev_err(rmidi->dev,
  482. "mpu401_uart: unable to grab port 0x%lx size %d\n",
  483. port, res_size);
  484. err = -EBUSY;
  485. goto free_device;
  486. }
  487. }
  488. if (info_flags & MPU401_INFO_MMIO) {
  489. mpu->write = mpu401_write_mmio;
  490. mpu->read = mpu401_read_mmio;
  491. } else {
  492. mpu->write = mpu401_write_port;
  493. mpu->read = mpu401_read_port;
  494. }
  495. mpu->port = port;
  496. if (hardware == MPU401_HW_PC98II)
  497. mpu->cport = port + 2;
  498. else
  499. mpu->cport = port + 1;
  500. if (irq >= 0) {
  501. if (request_irq(irq, snd_mpu401_uart_interrupt, 0,
  502. "MPU401 UART", (void *) mpu)) {
  503. dev_err(rmidi->dev,
  504. "mpu401_uart: unable to grab IRQ %d\n", irq);
  505. err = -EBUSY;
  506. goto free_device;
  507. }
  508. }
  509. if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK))
  510. info_flags |= MPU401_INFO_USE_TIMER;
  511. mpu->info_flags = info_flags;
  512. mpu->irq = irq;
  513. if (card->shortname[0])
  514. snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI",
  515. card->shortname);
  516. else
  517. sprintf(rmidi->name, "MPU-401 MIDI %d-%d",card->number, device);
  518. if (out_enable) {
  519. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
  520. &snd_mpu401_uart_output);
  521. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
  522. }
  523. if (in_enable) {
  524. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
  525. &snd_mpu401_uart_input);
  526. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
  527. if (out_enable)
  528. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
  529. }
  530. if (rrawmidi)
  531. *rrawmidi = rmidi;
  532. return 0;
  533. free_device:
  534. snd_device_free(card, rmidi);
  535. return err;
  536. }
  537. EXPORT_SYMBOL(snd_mpu401_uart_new);