4 * The low level driver for the PAS Midi Interface.
6 * Copyright by Hannu Savolainen 1993
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <i386/isa/sound/sound_config.h>
32 #if defined(CONFIG_PAS) && defined(CONFIG_MIDI)
33 #include <i386/isa/sound/pas_hw.h>
35 static int midi_busy = 0, input_opened = 0;
37 static volatile int ofifo_bytes = 0;
39 static u_char tmp_queue[256];
40 static volatile int qlen;
41 static volatile u_char qhead, qtail;
43 static void (*midi_input_intr) (int dev, u_char data);
46 pas_midi_open(int dev, int mode,
47 void (*input) (int dev, u_char data),
48 void (*output) (int dev)
57 printf("PAS2: Midi busy\n");
61 * Reset input and output FIFO pointers
63 pas_write(M_C_RESET_INPUT_FIFO | M_C_RESET_OUTPUT_FIFO,
68 if ((err = pas_set_intr(I_M_MIDI_IRQ_ENABLE)) < 0)
72 * Enable input available and output FIFO empty interrupts
77 midi_input_intr = input;
79 if (mode == OPEN_READ || mode == OPEN_READWRITE) {
80 ctrl |= M_C_ENA_INPUT_IRQ; /* Enable input */
83 if (mode == OPEN_WRITE || mode == OPEN_READWRITE) {
84 ctrl |= M_C_ENA_OUTPUT_IRQ | /* Enable output */
85 M_C_ENA_OUTPUT_HALF_IRQ;
91 * Acknowledge any pending interrupts
94 pas_write(0xff, MIDI_STATUS);
100 qlen = qhead = qtail = 0;
105 pas_midi_close(int dev)
109 * Reset FIFO pointers, disable intrs
111 pas_write(M_C_RESET_INPUT_FIFO | M_C_RESET_OUTPUT_FIFO, MIDI_CONTROL);
113 pas_remove_intr(I_M_MIDI_IRQ_ENABLE);
118 dump_to_midi(u_char midi_byte)
122 fifo_space = ((x = pas_read(MIDI_FIFO_STATUS)) >> 4) & 0x0f;
124 if (fifo_space == 15 || (fifo_space < 2 && ofifo_bytes > 13)) { /* Fifo full */
125 return 0; /* Upper layer will call again */
129 pas_write(midi_byte, MIDI_DATA);
135 pas_midi_out(int dev, u_char midi_byte)
141 * Drain the local queue first
146 while (qlen && dump_to_midi(tmp_queue[qhead])) {
154 * Output the byte if the local queue is empty.
158 if (dump_to_midi(midi_byte))
162 * Put to the local queue
166 return 0; /* Local queue full */
170 tmp_queue[qtail] = midi_byte;
180 pas_midi_start_read(int dev)
186 pas_midi_end_read(int dev)
192 pas_midi_ioctl(int dev, u_int cmd, ioctl_arg arg)
198 pas_midi_kick(int dev)
204 pas_buffer_status(int dev)
209 #define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
210 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
211 #include <i386/isa/sound/midi_synth.h>
213 static struct midi_operations pas_midi_operations =
215 {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS},
233 if (num_midis >= MAX_MIDI_DEV) {
234 printf("Sound: Too many midi devices detected\n");
237 std_midi_synth.midi_dev = my_dev = num_midis;
238 midi_devs[num_midis++] = &pas_midi_operations;
243 pas_midi_interrupt(void)
249 stat = pas_read(MIDI_STATUS);
251 if (stat & M_S_INPUT_AVAIL) { /* Input byte available */
252 incount = pas_read(MIDI_FIFO_STATUS) & 0x0f; /* Input FIFO count */
256 for (i = 0; i < incount; i++)
258 midi_input_intr(my_dev, pas_read(MIDI_DATA));
260 pas_read(MIDI_DATA); /* Flush */
262 if (stat & (M_S_OUTPUT_EMPTY | M_S_OUTPUT_HALF_EMPTY)) {
263 if (!(stat & M_S_OUTPUT_EMPTY)) {
271 while (qlen && dump_to_midi(tmp_queue[qhead])) {
278 if (stat & M_S_OUTPUT_OVERRUN) {
279 printf("MIDI output overrun %x,%x,%d \n", pas_read(MIDI_FIFO_STATUS), stat, ofifo_bytes);
282 pas_write(stat, MIDI_STATUS); /* Acknowledge interrupts */