34 #include <linux/slab.h>
36 #include <linux/module.h>
38 #include <linux/errno.h>
46 static void snd_mpu401_uart_input_read(
struct snd_mpu401 * mpu);
47 static void snd_mpu401_uart_output_write(
struct snd_mpu401 * mpu);
53 #define snd_mpu401_input_avail(mpu) \
54 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_RX_EMPTY))
55 #define snd_mpu401_output_ready(mpu) \
56 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_TX_FULL))
59 static void mpu401_write_port(
struct snd_mpu401 *mpu,
unsigned char data,
65 static unsigned char mpu401_read_port(
struct snd_mpu401 *mpu,
71 static void mpu401_write_mmio(
struct snd_mpu401 *mpu,
unsigned char data,
77 static unsigned char mpu401_read_mmio(
struct snd_mpu401 *mpu,
84 static void snd_mpu401_uart_clear_rx(
struct snd_mpu401 *mpu)
89 #ifdef CONFIG_SND_DEBUG
96 static void uart_interrupt_tx(
struct snd_mpu401 *mpu)
103 snd_mpu401_uart_output_write(mpu);
108 static void _snd_mpu401_uart_interrupt(
struct snd_mpu401 *mpu)
115 snd_mpu401_uart_input_read(mpu);
117 snd_mpu401_uart_clear_rx(mpu);
118 spin_unlock_irqrestore(&mpu->
input_lock, flags);
123 uart_interrupt_tx(mpu);
139 _snd_mpu401_uart_interrupt(mpu);
158 uart_interrupt_tx(mpu);
168 static void snd_mpu401_uart_timer(
unsigned long data)
177 spin_unlock_irqrestore(&mpu->
timer_lock, flags);
179 _snd_mpu401_uart_interrupt(mpu);
185 static void snd_mpu401_uart_add_timer (
struct snd_mpu401 *mpu,
int input)
193 mpu->
timer.function = snd_mpu401_uart_timer;
199 spin_unlock_irqrestore (&mpu->
timer_lock, flags);
205 static void snd_mpu401_uart_remove_timer (
struct snd_mpu401 *mpu,
int input)
216 spin_unlock_irqrestore (&mpu->
timer_lock, flags);
224 static int snd_mpu401_uart_cmd(
struct snd_mpu401 * mpu,
unsigned char cmd,
237 for (timeout = 1000; timeout > 0 &&
240 #ifdef CONFIG_SND_DEBUG
250 while (!ok && timeout-- > 0) {
260 spin_unlock_irqrestore(&mpu->
input_lock, flags);
263 "(status = 0x%x, data = 0x%x)\n", cmd, mpu->
port,
271 static int snd_mpu401_do_reset(
struct snd_mpu401 *mpu)
288 mpu = substream->
rmidi->private_data;
292 if (snd_mpu401_do_reset(mpu) < 0)
310 mpu = substream->
rmidi->private_data;
314 if (snd_mpu401_do_reset(mpu) < 0)
332 mpu = substream->
rmidi->private_data;
349 mpu = substream->
rmidi->private_data;
371 mpu = substream->
rmidi->private_data;
379 snd_mpu401_uart_add_timer(mpu, 1);
384 snd_mpu401_uart_input_read(mpu);
385 spin_unlock_irqrestore(&mpu->
input_lock, flags);
388 snd_mpu401_uart_remove_timer(mpu, 1);
398 static void snd_mpu401_uart_input_read(
struct snd_mpu401 * mpu)
424 static void snd_mpu401_uart_output_write(
struct snd_mpu401 * mpu)
442 snd_mpu401_uart_remove_timer (mpu, 0);
457 mpu = substream->
rmidi->private_data;
466 snd_mpu401_uart_add_timer(mpu, 0);
470 snd_mpu401_uart_output_write(mpu);
474 snd_mpu401_uart_remove_timer(mpu, 0);
485 .open = snd_mpu401_uart_output_open,
486 .close = snd_mpu401_uart_output_close,
487 .trigger = snd_mpu401_uart_output_trigger,
492 .open = snd_mpu401_uart_input_open,
493 .close = snd_mpu401_uart_input_close,
494 .trigger = snd_mpu401_uart_input_trigger,
497 static void snd_mpu401_uart_free(
struct snd_rawmidi *rmidi)
533 int in_enable, out_enable;
543 out_enable, in_enable, &rmidi)) < 0)
563 "unable to grab port 0x%lx size %d\n",
570 mpu->
write = mpu401_write_mmio;
571 mpu->
read = mpu401_read_mmio;
573 mpu->
write = mpu401_write_port;
574 mpu->
read = mpu401_read_port;
578 mpu->
cport = port + 2;
580 mpu->
cport = port + 1;
583 "MPU401 UART", (
void *) mpu)) {
585 "unable to grab IRQ %d\n", irq);
601 &snd_mpu401_uart_output);
606 &snd_mpu401_uart_input);
623 static int __init alsa_mpu401_uart_init(
void)
628 static void __exit alsa_mpu401_uart_exit(
void)