22 #include <linux/time.h>
27 #define EMU10K1_MIDI_MODE_INPUT (1<<0)
28 #define EMU10K1_MIDI_MODE_OUTPUT (1<<1)
30 static inline unsigned char mpu401_read(
struct snd_emu10k1 *
emu,
36 return inb(emu->port + mpu->port + idx);
39 static inline void mpu401_write(
struct snd_emu10k1 *
emu,
45 outb(data, emu->port + mpu->port + idx);
48 #define mpu401_write_data(emu, mpu, data) mpu401_write(emu, mpu, data, 0)
49 #define mpu401_write_cmd(emu, mpu, data) mpu401_write(emu, mpu, data, 1)
50 #define mpu401_read_data(emu, mpu) mpu401_read(emu, mpu, 0)
51 #define mpu401_read_stat(emu, mpu) mpu401_read(emu, mpu, 1)
53 #define mpu401_input_avail(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x80))
54 #define mpu401_output_ready(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x40))
56 #define MPU401_RESET 0xff
57 #define MPU401_ENTER_UART 0x3f
58 #define MPU401_ACK 0xfe
60 static void mpu401_clear_rx(
struct snd_emu10k1 *emu,
struct snd_emu10k1_midi *mpu)
65 #ifdef CONFIG_SND_DEBUG
75 static void do_emu10k1_midi_interrupt(
struct snd_emu10k1 *emu,
struct snd_emu10k1_midi *midi,
unsigned int status)
79 if (midi->rmidi ==
NULL) {
84 spin_lock(&midi->input_lock);
87 mpu401_clear_rx(emu, midi);
90 if (midi->substream_input)
94 spin_unlock(&midi->input_lock);
96 spin_lock(&midi->output_lock);
98 if (midi->substream_output &&
105 spin_unlock(&midi->output_lock);
108 static void snd_emu10k1_midi_interrupt(
struct snd_emu10k1 *emu,
unsigned int status)
110 do_emu10k1_midi_interrupt(emu, &emu->midi, status);
113 static void snd_emu10k1_midi_interrupt2(
struct snd_emu10k1 *emu,
unsigned int status)
115 do_emu10k1_midi_interrupt(emu, &emu->midi2, status);
118 static int snd_emu10k1_midi_cmd(
struct snd_emu10k1 * emu,
struct snd_emu10k1_midi *midi,
unsigned char cmd,
int ack)
131 while (!ok && timeout-- > 0) {
142 spin_unlock_irqrestore(&midi->input_lock, flags);
144 snd_printk(
KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
155 struct snd_emu10k1 *emu;
164 midi->substream_input = substream;
166 spin_unlock_irqrestore(&midi->open_lock, flags);
172 spin_unlock_irqrestore(&midi->open_lock, flags);
182 struct snd_emu10k1 *emu;
191 midi->substream_output = substream;
193 spin_unlock_irqrestore(&midi->open_lock, flags);
199 spin_unlock_irqrestore(&midi->open_lock, flags);
209 struct snd_emu10k1 *emu;
220 midi->substream_input =
NULL;
222 spin_unlock_irqrestore(&midi->open_lock, flags);
225 spin_unlock_irqrestore(&midi->open_lock, flags);
232 struct snd_emu10k1 *emu;
243 midi->substream_output =
NULL;
245 spin_unlock_irqrestore(&midi->open_lock, flags);
248 spin_unlock_irqrestore(&midi->open_lock, flags);
255 struct snd_emu10k1 *emu;
269 struct snd_emu10k1 *emu;
288 spin_unlock_irqrestore(&midi->output_lock, flags);
297 spin_unlock_irqrestore(&midi->output_lock, flags);
310 .open = snd_emu10k1_midi_output_open,
311 .close = snd_emu10k1_midi_output_close,
312 .trigger = snd_emu10k1_midi_output_trigger,
317 .open = snd_emu10k1_midi_input_open,
318 .close = snd_emu10k1_midi_input_close,
319 .trigger = snd_emu10k1_midi_input_trigger,
322 static void snd_emu10k1_midi_free(
struct snd_rawmidi *rmidi)
325 midi->interrupt =
NULL;
334 if ((err =
snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0)
357 if ((err = emu10k1_midi_init(emu, midi, 0,
"EMU10K1 MPU-401 (UART)")) < 0)
365 midi->interrupt = snd_emu10k1_midi_interrupt;
375 if ((err = emu10k1_midi_init(emu, midi, 0,
"Audigy MPU-401 (UART)")) < 0)
380 midi->port = A_MUDATA1;
383 midi->interrupt = snd_emu10k1_midi_interrupt;
386 if ((err = emu10k1_midi_init(emu, midi, 1,
"Audigy MPU-401 #2")) < 0)
389 midi->tx_enable = INTE_A_MIDITXENABLE2;
390 midi->rx_enable = INTE_A_MIDIRXENABLE2;
391 midi->port = A_MUDATA2;
392 midi->ipr_tx = IPR_A_MIDITRANSBUFEMPTY2;
393 midi->ipr_rx = IPR_A_MIDIRECVBUFEMPTY2;
394 midi->interrupt = snd_emu10k1_midi_interrupt2;