mpu401_uart.c 16 KB

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