4 * The low level driver for the PAS Midi Interface.
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
13 #include <linux/config.h>
16 #include "sound_config.h"
21 static int midi_busy
= 0, input_opened
= 0;
26 static unsigned char tmp_queue
[256];
27 static volatile int qlen
;
28 static volatile unsigned char qhead
, qtail
;
30 static void (*midi_input_intr
) (int dev
, unsigned char data
);
32 static int pas_midi_open(int dev
, int mode
,
33 void (*input
) (int dev
, unsigned char data
),
34 void (*output
) (int dev
)
46 * Reset input and output FIFO pointers
48 pas_write(0x20 | 0x40,
54 if ((err
= pas_set_intr(0x10)) < 0)
60 * Enable input available and output FIFO empty interrupts
65 midi_input_intr
= input
;
67 if (mode
== OPEN_READ
|| mode
== OPEN_READWRITE
)
69 ctrl
|= 0x04; /* Enable input */
72 if (mode
== OPEN_WRITE
|| mode
== OPEN_READWRITE
)
74 ctrl
|= 0x08 | 0x10; /* Enable output */
76 pas_write(ctrl
, 0x178b);
79 * Acknowledge any pending interrupts
82 pas_write(0xff, 0x1B88);
87 qlen
= qhead
= qtail
= 0;
91 static void pas_midi_close(int dev
)
95 * Reset FIFO pointers, disable intrs
97 pas_write(0x20 | 0x40, 0x178b);
99 pas_remove_intr(0x10);
103 static int dump_to_midi(unsigned char midi_byte
)
107 fifo_space
= ((x
= pas_read(0x1B89)) >> 4) & 0x0f;
110 * The MIDI FIFO space register and it's documentation is nonunderstandable.
111 * There seem to be no way to differentiate between buffer full and buffer
112 * empty situations. For this reason we don't never write the buffer
113 * completely full. In this way we can assume that 0 (or is it 15)
114 * means that the buffer is empty.
117 if (fifo_space
< 2 && fifo_space
!= 0) /* Full (almost) */
118 return 0; /* Ask upper layers to retry after some time */
120 pas_write(midi_byte
, 0x178A);
125 static int pas_midi_out(int dev
, unsigned char midi_byte
)
131 * Drain the local queue first
137 while (qlen
&& dump_to_midi(tmp_queue
[qhead
]))
143 restore_flags(flags
);
146 * Output the byte if the local queue is empty.
150 if (dump_to_midi(midi_byte
))
154 * Put to the local queue
158 return 0; /* Local queue full */
163 tmp_queue
[qtail
] = midi_byte
;
167 restore_flags(flags
);
172 static int pas_midi_start_read(int dev
)
177 static int pas_midi_end_read(int dev
)
182 static void pas_midi_kick(int dev
)
186 static int pas_buffer_status(int dev
)
191 #define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
192 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
193 #include "midi_synth.h"
195 static struct midi_operations pas_midi_operations
=
197 {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS
},
212 void pas_midi_init(void)
214 int dev
= sound_alloc_mididev();
218 printk(KERN_WARNING
"pas_midi_init: Too many midi devices detected\n");
221 std_midi_synth
.midi_dev
= my_dev
= dev
;
222 midi_devs
[dev
] = &pas_midi_operations
;
227 void pas_midi_interrupt(void)
233 stat
= pas_read(0x1B88);
235 if (stat
& 0x04) /* Input data available */
237 incount
= pas_read(0x1B89) & 0x0f; /* Input FIFO size */
241 for (i
= 0; i
< incount
; i
++)
244 midi_input_intr(my_dev
, pas_read(0x178A));
246 pas_read(0x178A); /* Flush */
248 if (stat
& (0x08 | 0x10))
253 while (qlen
&& dump_to_midi(tmp_queue
[qhead
]))
259 restore_flags(flags
);
263 printk(KERN_WARNING
"MIDI output overrun %x,%x\n", pas_read(0x1B89), stat
);
265 pas_write(stat
, 0x1B88); /* Acknowledge interrupts */