mpu401_uart.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  3. * Routines for control of MPU-401 in UART mode
  4. *
  5. * MPU-401 supports UART mode which is not capable generate transmit
  6. * interrupts thus output is done via polling. Also, if irq < 0, then
  7. * input is done also via polling. Do not expect good performance.
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. * 13-03-2003:
  25. * Added support for different kind of hardware I/O. Build in choices
  26. * are port and mmio. For other kind of I/O, set mpu->read and
  27. * mpu->write to your own I/O functions.
  28. *
  29. */
  30. #include <sound/driver.h>
  31. #include <asm/io.h>
  32. #include <linux/delay.h>
  33. #include <linux/init.h>
  34. #include <linux/slab.h>
  35. #include <linux/ioport.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/errno.h>
  38. #include <sound/core.h>
  39. #include <sound/mpu401.h>
  40. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  41. MODULE_DESCRIPTION("Routines for control of MPU-401 in UART mode");
  42. MODULE_LICENSE("GPL");
  43. static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu);
  44. static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu);
  45. /*
  46. */
  47. #define snd_mpu401_input_avail(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x80))
  48. #define snd_mpu401_output_ready(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x40))
  49. #define MPU401_RESET 0xff
  50. #define MPU401_ENTER_UART 0x3f
  51. #define MPU401_ACK 0xfe
  52. /* Build in lowlevel io */
  53. static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data,
  54. unsigned long addr)
  55. {
  56. outb(data, addr);
  57. }
  58. static unsigned char mpu401_read_port(struct snd_mpu401 *mpu,
  59. unsigned long addr)
  60. {
  61. return inb(addr);
  62. }
  63. static void mpu401_write_mmio(struct snd_mpu401 *mpu, unsigned char data,
  64. unsigned long addr)
  65. {
  66. writeb(data, (void __iomem *)addr);
  67. }
  68. static unsigned char mpu401_read_mmio(struct snd_mpu401 *mpu,
  69. unsigned long addr)
  70. {
  71. return readb((void __iomem *)addr);
  72. }
  73. /* */
  74. static void snd_mpu401_uart_clear_rx(struct snd_mpu401 *mpu)
  75. {
  76. int timeout = 100000;
  77. for (; timeout > 0 && snd_mpu401_input_avail(mpu); timeout--)
  78. mpu->read(mpu, MPU401D(mpu));
  79. #ifdef CONFIG_SND_DEBUG
  80. if (timeout <= 0)
  81. snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n",
  82. mpu->read(mpu, MPU401C(mpu)));
  83. #endif
  84. }
  85. static void uart_interrupt_tx(struct snd_mpu401 *mpu)
  86. {
  87. if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) &&
  88. test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) {
  89. spin_lock(&mpu->output_lock);
  90. snd_mpu401_uart_output_write(mpu);
  91. spin_unlock(&mpu->output_lock);
  92. }
  93. }
  94. static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu)
  95. {
  96. if (mpu->info_flags & MPU401_INFO_INPUT) {
  97. spin_lock(&mpu->input_lock);
  98. if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode))
  99. snd_mpu401_uart_input_read(mpu);
  100. else
  101. snd_mpu401_uart_clear_rx(mpu);
  102. spin_unlock(&mpu->input_lock);
  103. }
  104. if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
  105. /* ok. for better Tx performance try do some output
  106. when input is done */
  107. uart_interrupt_tx(mpu);
  108. }
  109. /**
  110. * snd_mpu401_uart_interrupt - generic MPU401-UART interrupt handler
  111. * @irq: the irq number
  112. * @dev_id: mpu401 instance
  113. *
  114. * Processes the interrupt for MPU401-UART i/o.
  115. */
  116. irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id)
  117. {
  118. struct snd_mpu401 *mpu = dev_id;
  119. if (mpu == NULL)
  120. return IRQ_NONE;
  121. _snd_mpu401_uart_interrupt(mpu);
  122. return IRQ_HANDLED;
  123. }
  124. EXPORT_SYMBOL(snd_mpu401_uart_interrupt);
  125. /**
  126. * snd_mpu401_uart_interrupt_tx - generic MPU401-UART transmit irq handler
  127. * @irq: the irq number
  128. * @dev_id: mpu401 instance
  129. *
  130. * Processes the interrupt for MPU401-UART output.
  131. */
  132. irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id)
  133. {
  134. struct snd_mpu401 *mpu = dev_id;
  135. if (mpu == NULL)
  136. return IRQ_NONE;
  137. uart_interrupt_tx(mpu);
  138. return IRQ_HANDLED;
  139. }
  140. EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx);
  141. /*
  142. * timer callback
  143. * reprogram the timer and call the interrupt job
  144. */
  145. static void snd_mpu401_uart_timer(unsigned long data)
  146. {
  147. struct snd_mpu401 *mpu = (struct snd_mpu401 *)data;
  148. unsigned long flags;
  149. spin_lock_irqsave(&mpu->timer_lock, flags);
  150. /*mpu->mode |= MPU401_MODE_TIMER;*/
  151. mpu->timer.expires = 1 + jiffies;
  152. add_timer(&mpu->timer);
  153. spin_unlock_irqrestore(&mpu->timer_lock, flags);
  154. if (mpu->rmidi)
  155. _snd_mpu401_uart_interrupt(mpu);
  156. }
  157. /*
  158. * initialize the timer callback if not programmed yet
  159. */
  160. static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input)
  161. {
  162. unsigned long flags;
  163. spin_lock_irqsave (&mpu->timer_lock, flags);
  164. if (mpu->timer_invoked == 0) {
  165. init_timer(&mpu->timer);
  166. mpu->timer.data = (unsigned long)mpu;
  167. mpu->timer.function = snd_mpu401_uart_timer;
  168. mpu->timer.expires = 1 + jiffies;
  169. add_timer(&mpu->timer);
  170. }
  171. mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER :
  172. MPU401_MODE_OUTPUT_TIMER;
  173. spin_unlock_irqrestore (&mpu->timer_lock, flags);
  174. }
  175. /*
  176. * remove the timer callback if still active
  177. */
  178. static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input)
  179. {
  180. unsigned long flags;
  181. spin_lock_irqsave (&mpu->timer_lock, flags);
  182. if (mpu->timer_invoked) {
  183. mpu->timer_invoked &= input ? ~MPU401_MODE_INPUT_TIMER :
  184. ~MPU401_MODE_OUTPUT_TIMER;
  185. if (! mpu->timer_invoked)
  186. del_timer(&mpu->timer);
  187. }
  188. spin_unlock_irqrestore (&mpu->timer_lock, flags);
  189. }
  190. /*
  191. * send a UART command
  192. * return zero if successful, non-zero for some errors
  193. */
  194. static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd,
  195. int ack)
  196. {
  197. unsigned long flags;
  198. int timeout, ok;
  199. spin_lock_irqsave(&mpu->input_lock, flags);
  200. if (mpu->hardware != MPU401_HW_TRID4DWAVE) {
  201. mpu->write(mpu, 0x00, MPU401D(mpu));
  202. /*snd_mpu401_uart_clear_rx(mpu);*/
  203. }
  204. /* ok. standard MPU-401 initialization */
  205. if (mpu->hardware != MPU401_HW_SB) {
  206. for (timeout = 1000; timeout > 0 &&
  207. !snd_mpu401_output_ready(mpu); timeout--)
  208. udelay(10);
  209. #ifdef CONFIG_SND_DEBUG
  210. if (!timeout)
  211. snd_printk(KERN_ERR "cmd: tx timeout (status = 0x%x)\n",
  212. mpu->read(mpu, MPU401C(mpu)));
  213. #endif
  214. }
  215. mpu->write(mpu, cmd, MPU401C(mpu));
  216. if (ack) {
  217. ok = 0;
  218. timeout = 10000;
  219. while (!ok && timeout-- > 0) {
  220. if (snd_mpu401_input_avail(mpu)) {
  221. if (mpu->read(mpu, MPU401D(mpu)) == MPU401_ACK)
  222. ok = 1;
  223. }
  224. }
  225. if (!ok && mpu->read(mpu, MPU401D(mpu)) == MPU401_ACK)
  226. ok = 1;
  227. } else
  228. ok = 1;
  229. spin_unlock_irqrestore(&mpu->input_lock, flags);
  230. if (!ok) {
  231. snd_printk(KERN_ERR "cmd: 0x%x failed at 0x%lx "
  232. "(status = 0x%x, data = 0x%x)\n", cmd, mpu->port,
  233. mpu->read(mpu, MPU401C(mpu)),
  234. mpu->read(mpu, MPU401D(mpu)));
  235. return 1;
  236. }
  237. return 0;
  238. }
  239. /*
  240. * input/output open/close - protected by open_mutex in rawmidi.c
  241. */
  242. static int snd_mpu401_uart_input_open(struct snd_rawmidi_substream *substream)
  243. {
  244. struct snd_mpu401 *mpu;
  245. int err;
  246. mpu = substream->rmidi->private_data;
  247. if (mpu->open_input && (err = mpu->open_input(mpu)) < 0)
  248. return err;
  249. if (! test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode)) {
  250. if (snd_mpu401_uart_cmd(mpu, MPU401_RESET, 1))
  251. goto error_out;
  252. if (snd_mpu401_uart_cmd(mpu, MPU401_ENTER_UART, 1))
  253. goto error_out;
  254. }
  255. mpu->substream_input = substream;
  256. set_bit(MPU401_MODE_BIT_INPUT, &mpu->mode);
  257. return 0;
  258. error_out:
  259. if (mpu->open_input && mpu->close_input)
  260. mpu->close_input(mpu);
  261. return -EIO;
  262. }
  263. static int snd_mpu401_uart_output_open(struct snd_rawmidi_substream *substream)
  264. {
  265. struct snd_mpu401 *mpu;
  266. int err;
  267. mpu = substream->rmidi->private_data;
  268. if (mpu->open_output && (err = mpu->open_output(mpu)) < 0)
  269. return err;
  270. if (! test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) {
  271. if (snd_mpu401_uart_cmd(mpu, MPU401_RESET, 1))
  272. goto error_out;
  273. if (snd_mpu401_uart_cmd(mpu, MPU401_ENTER_UART, 1))
  274. goto error_out;
  275. }
  276. mpu->substream_output = substream;
  277. set_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode);
  278. return 0;
  279. error_out:
  280. if (mpu->open_output && mpu->close_output)
  281. mpu->close_output(mpu);
  282. return -EIO;
  283. }
  284. static int snd_mpu401_uart_input_close(struct snd_rawmidi_substream *substream)
  285. {
  286. struct snd_mpu401 *mpu;
  287. int err = 0;
  288. mpu = substream->rmidi->private_data;
  289. clear_bit(MPU401_MODE_BIT_INPUT, &mpu->mode);
  290. mpu->substream_input = NULL;
  291. if (! test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode))
  292. err = snd_mpu401_uart_cmd(mpu, MPU401_RESET, 0);
  293. if (mpu->close_input)
  294. mpu->close_input(mpu);
  295. if (err)
  296. return -EIO;
  297. return 0;
  298. }
  299. static int snd_mpu401_uart_output_close(struct snd_rawmidi_substream *substream)
  300. {
  301. struct snd_mpu401 *mpu;
  302. int err = 0;
  303. mpu = substream->rmidi->private_data;
  304. clear_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode);
  305. mpu->substream_output = NULL;
  306. if (! test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode))
  307. err = snd_mpu401_uart_cmd(mpu, MPU401_RESET, 0);
  308. if (mpu->close_output)
  309. mpu->close_output(mpu);
  310. if (err)
  311. return -EIO;
  312. return 0;
  313. }
  314. /*
  315. * trigger input callback
  316. */
  317. static void
  318. snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
  319. {
  320. unsigned long flags;
  321. struct snd_mpu401 *mpu;
  322. int max = 64;
  323. mpu = substream->rmidi->private_data;
  324. if (up) {
  325. if (! test_and_set_bit(MPU401_MODE_BIT_INPUT_TRIGGER,
  326. &mpu->mode)) {
  327. /* first time - flush FIFO */
  328. while (max-- > 0)
  329. mpu->read(mpu, MPU401D(mpu));
  330. if (mpu->irq < 0)
  331. snd_mpu401_uart_add_timer(mpu, 1);
  332. }
  333. /* read data in advance */
  334. spin_lock_irqsave(&mpu->input_lock, flags);
  335. snd_mpu401_uart_input_read(mpu);
  336. spin_unlock_irqrestore(&mpu->input_lock, flags);
  337. } else {
  338. if (mpu->irq < 0)
  339. snd_mpu401_uart_remove_timer(mpu, 1);
  340. clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode);
  341. }
  342. }
  343. /*
  344. * transfer input pending data
  345. * call with input_lock spinlock held
  346. */
  347. static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu)
  348. {
  349. int max = 128;
  350. unsigned char byte;
  351. while (max-- > 0) {
  352. if (! snd_mpu401_input_avail(mpu))
  353. break; /* input not available */
  354. byte = mpu->read(mpu, MPU401D(mpu));
  355. if (test_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode))
  356. snd_rawmidi_receive(mpu->substream_input, &byte, 1);
  357. }
  358. }
  359. /*
  360. * Tx FIFO sizes:
  361. * CS4237B - 16 bytes
  362. * AudioDrive ES1688 - 12 bytes
  363. * S3 SonicVibes - 8 bytes
  364. * SoundBlaster AWE 64 - 2 bytes (ugly hardware)
  365. */
  366. /*
  367. * write output pending bytes
  368. * call with output_lock spinlock held
  369. */
  370. static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu)
  371. {
  372. unsigned char byte;
  373. int max = 256, timeout;
  374. do {
  375. if (snd_rawmidi_transmit_peek(mpu->substream_output,
  376. &byte, 1) == 1) {
  377. for (timeout = 100; timeout > 0; timeout--) {
  378. if (snd_mpu401_output_ready(mpu))
  379. break;
  380. }
  381. if (timeout == 0)
  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 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 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_flags && 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 irq number, -1 if no interrupt for mpu
  448. * @irq_flags: the irq request flags (SA_XXX), 0 if irq was already reserved.
  449. * @rrawmidi: the pointer to store the new rawmidi instance
  450. *
  451. * Creates a new MPU-401 instance.
  452. *
  453. * Note that the rawmidi instance is returned on the rrawmidi argument,
  454. * not the mpu401 instance itself. To access to the mpu401 instance,
  455. * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast).
  456. *
  457. * Returns zero if successful, or a negative error code.
  458. */
  459. int snd_mpu401_uart_new(struct snd_card *card, int device,
  460. unsigned short hardware,
  461. unsigned long port,
  462. unsigned int info_flags,
  463. int irq, int irq_flags,
  464. struct snd_rawmidi ** rrawmidi)
  465. {
  466. struct snd_mpu401 *mpu;
  467. struct snd_rawmidi *rmidi;
  468. int in_enable, out_enable;
  469. int err;
  470. if (rrawmidi)
  471. *rrawmidi = NULL;
  472. if (! (info_flags & (MPU401_INFO_INPUT | MPU401_INFO_OUTPUT)))
  473. info_flags |= MPU401_INFO_INPUT | MPU401_INFO_OUTPUT;
  474. in_enable = (info_flags & MPU401_INFO_INPUT) ? 1 : 0;
  475. out_enable = (info_flags & MPU401_INFO_OUTPUT) ? 1 : 0;
  476. if ((err = snd_rawmidi_new(card, "MPU-401U", device,
  477. out_enable, in_enable, &rmidi)) < 0)
  478. return err;
  479. mpu = kzalloc(sizeof(*mpu), GFP_KERNEL);
  480. if (mpu == NULL) {
  481. snd_printk(KERN_ERR "mpu401_uart: cannot allocate\n");
  482. snd_device_free(card, rmidi);
  483. return -ENOMEM;
  484. }
  485. rmidi->private_data = mpu;
  486. rmidi->private_free = snd_mpu401_uart_free;
  487. spin_lock_init(&mpu->input_lock);
  488. spin_lock_init(&mpu->output_lock);
  489. spin_lock_init(&mpu->timer_lock);
  490. mpu->hardware = hardware;
  491. if (! (info_flags & MPU401_INFO_INTEGRATED)) {
  492. int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
  493. mpu->res = request_region(port, res_size, "MPU401 UART");
  494. if (mpu->res == NULL) {
  495. snd_printk(KERN_ERR "mpu401_uart: "
  496. "unable to grab port 0x%lx size %d\n",
  497. port, res_size);
  498. snd_device_free(card, rmidi);
  499. return -EBUSY;
  500. }
  501. }
  502. if (info_flags & MPU401_INFO_MMIO) {
  503. mpu->write = mpu401_write_mmio;
  504. mpu->read = mpu401_read_mmio;
  505. } else {
  506. mpu->write = mpu401_write_port;
  507. mpu->read = mpu401_read_port;
  508. }
  509. mpu->port = port;
  510. if (hardware == MPU401_HW_PC98II)
  511. mpu->cport = port + 2;
  512. else
  513. mpu->cport = port + 1;
  514. if (irq >= 0 && irq_flags) {
  515. if (request_irq(irq, snd_mpu401_uart_interrupt, irq_flags,
  516. "MPU401 UART", (void *) mpu)) {
  517. snd_printk(KERN_ERR "mpu401_uart: "
  518. "unable to grab IRQ %d\n", irq);
  519. snd_device_free(card, rmidi);
  520. return -EBUSY;
  521. }
  522. }
  523. mpu->info_flags = info_flags;
  524. mpu->irq = irq;
  525. mpu->irq_flags = irq_flags;
  526. if (card->shortname[0])
  527. snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI",
  528. card->shortname);
  529. else
  530. sprintf(rmidi->name, "MPU-401 MIDI %d-%d",card->number, device);
  531. if (out_enable) {
  532. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
  533. &snd_mpu401_uart_output);
  534. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
  535. }
  536. if (in_enable) {
  537. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
  538. &snd_mpu401_uart_input);
  539. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
  540. if (out_enable)
  541. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
  542. }
  543. mpu->rmidi = rmidi;
  544. if (rrawmidi)
  545. *rrawmidi = rmidi;
  546. return 0;
  547. }
  548. EXPORT_SYMBOL(snd_mpu401_uart_new);
  549. /*
  550. * INIT part
  551. */
  552. static int __init alsa_mpu401_uart_init(void)
  553. {
  554. return 0;
  555. }
  556. static void __exit alsa_mpu401_uart_exit(void)
  557. {
  558. }
  559. module_init(alsa_mpu401_uart_init)
  560. module_exit(alsa_mpu401_uart_exit)