mpu401_uart.c 16 KB

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