24 #include <linux/time.h>
28 static void snd_gf1_interrupt_midi_in(
struct snd_gus_card * gus)
37 stat = snd_gf1_uart_stat(gus);
44 data = snd_gf1_uart_get(gus);
45 if (!(gus->
gf1.uart_cmd & 0x80)) {
50 gus->
gf1.uart_framing++;
54 byte = snd_gf1_uart_get(gus);
58 gus->
gf1.uart_overrun++;
63 static void snd_gf1_interrupt_midi_out(
struct snd_gus_card * gus)
69 if (snd_gf1_uart_stat(gus) & 0x01)
70 snd_gf1_interrupt_midi_in(gus);
73 if (snd_gf1_uart_stat(gus) & 0x02) {
75 snd_gf1_uart_cmd(gus, gus->
gf1.uart_cmd & ~0x20);
77 snd_gf1_uart_put(gus, byte);
83 static void snd_gf1_uart_reset(
struct snd_gus_card * gus,
int close)
85 snd_gf1_uart_cmd(gus, 0x03);
88 snd_gf1_uart_cmd(gus, 0x00);
97 gus = substream->
rmidi->private_data;
99 if (!(gus->
gf1.uart_cmd & 0x80)) {
100 snd_gf1_uart_reset(gus, 0);
102 gus->
gf1.interrupt_handler_midi_out = snd_gf1_interrupt_midi_out;
117 gus = substream->
rmidi->private_data;
119 if (gus->
gf1.interrupt_handler_midi_out != snd_gf1_interrupt_midi_out) {
120 snd_gf1_uart_reset(gus, 0);
122 gus->
gf1.interrupt_handler_midi_in = snd_gf1_interrupt_midi_in;
125 for (i = 0; i < 1000 && (snd_gf1_uart_stat(gus) & 0x01); i++)
126 snd_gf1_uart_get(gus);
133 "read init - enable = %i, cmd = 0x%x, stat = 0x%x\n",
136 "[0x%x] reg (ctrl/status) = 0x%x, reg (data) = 0x%x "
138 gus->
gf1.port + 0x100,
inb(gus->
gf1.port + 0x100),
139 inb(gus->
gf1.port + 0x101),
inb(gus->
gf1.port + 0x102));
149 gus = substream->
rmidi->private_data;
151 if (gus->
gf1.interrupt_handler_midi_in != snd_gf1_interrupt_midi_in)
152 snd_gf1_uart_reset(gus, 1);
164 gus = substream->
rmidi->private_data;
166 if (gus->
gf1.interrupt_handler_midi_out != snd_gf1_interrupt_midi_out)
167 snd_gf1_uart_reset(gus, 1);
179 gus = substream->
rmidi->private_data;
183 if ((gus->
gf1.uart_cmd & 0x80) == 0)
184 snd_gf1_uart_cmd(gus, gus->
gf1.uart_cmd | 0x80);
186 if (gus->
gf1.uart_cmd & 0x80)
187 snd_gf1_uart_cmd(gus, gus->
gf1.uart_cmd & ~0x80);
199 gus = substream->
rmidi->private_data;
203 if ((gus->
gf1.uart_cmd & 0x20) == 0) {
207 while (timeout-- > 0 && snd_gf1_uart_stat(gus) & 0x01);
210 if (gus->
gf1.uart_cmd & 0x20) {
214 if (snd_gf1_uart_stat(gus) & 0x02) {
219 snd_gf1_uart_put(gus, byte);
221 snd_gf1_uart_cmd(gus, gus->
gf1.uart_cmd | 0x20);
224 if (gus->
gf1.uart_cmd & 0x20)
225 snd_gf1_uart_cmd(gus, gus->
gf1.uart_cmd & ~0x20);
232 .open = snd_gf1_uart_output_open,
233 .close = snd_gf1_uart_output_close,
234 .trigger = snd_gf1_uart_output_trigger,
239 .open = snd_gf1_uart_input_open,
240 .close = snd_gf1_uart_input_close,
241 .trigger = snd_gf1_uart_input_trigger,