4 * The low level driver for the GUS 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_GUS) && defined(CONFIG_MIDI)
33 #include <i386/isa/sound/gus_hw.h>
35 static int midi_busy = 0, input_opened = 0;
37 static int output_used = 0;
38 static volatile unsigned char gus_midi_control;
40 static void (*midi_input_intr) (int dev, unsigned char data);
42 static unsigned char tmp_queue[256];
43 static volatile int qlen;
44 static volatile unsigned char qhead, qtail;
45 extern int gus_base, gus_irq, gus_dma;
46 extern sound_os_info *gus_osp;
48 #define GUS_MIDI_STATUS() inb( u_MidiStatus)
51 gus_midi_open(int dev, int mode,
52 void (*input) (int dev, unsigned char data),
53 void (*output) (int dev)
58 printf("GUS: Midi busy\n");
61 outb(u_MidiControl, MIDI_RESET);
67 if (mode == OPEN_READ || mode == OPEN_READWRITE) {
68 gus_midi_control |= MIDI_ENABLE_RCV;
71 if (mode == OPEN_WRITE || mode == OPEN_READWRITE) {
72 gus_midi_control |= MIDI_ENABLE_XMIT;
74 outb(u_MidiControl, gus_midi_control); /* Enable */
77 qlen = qhead = qtail = output_used = 0;
78 midi_input_intr = input;
84 dump_to_midi(unsigned char midi_byte)
93 if (GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY) {
95 outb(u_MidiData, midi_byte);
98 * Enable Midi xmit interrupts (again)
100 gus_midi_control |= MIDI_ENABLE_XMIT;
101 outb(u_MidiControl, gus_midi_control);
109 gus_midi_close(int dev)
112 * Reset FIFO pointers, disable intrs
115 outb(u_MidiControl, MIDI_RESET);
120 gus_midi_out(int dev, unsigned char midi_byte)
126 * Drain the local queue first
131 while (qlen && dump_to_midi(tmp_queue[qhead])) {
139 * Output the byte if the local queue is empty.
143 if (dump_to_midi(midi_byte))
147 * Put to the local queue
151 return 0; /* Local queue full */
155 tmp_queue[qtail] = midi_byte;
165 gus_midi_start_read(int dev)
171 gus_midi_end_read(int dev)
177 gus_midi_ioctl(int dev, unsigned cmd, ioctl_arg arg)
183 gus_midi_kick(int dev)
188 gus_midi_buffer_status(int dev)
197 if (qlen && dump_to_midi(tmp_queue[qhead])) {
203 return (qlen > 0) | !(GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY);
206 #define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
207 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
208 #include <i386/isa/sound/midi_synth.h>
210 static struct midi_operations gus_midi_operations =
212 {"Gravis UltraSound Midi", 0, 0, SNDCARD_GUS},
223 gus_midi_buffer_status,
230 if (num_midis >= MAX_MIDI_DEV) {
231 printf("Sound: Too many midi devices detected\n");
234 outb(u_MidiControl, MIDI_RESET);
236 std_midi_synth.midi_dev = my_dev = num_midis;
237 midi_devs[num_midis++] = &gus_midi_operations;
242 gus_midi_interrupt(int dummy)
244 unsigned char stat, data;
249 stat = GUS_MIDI_STATUS();
251 if (stat & MIDI_RCV_FULL) {
252 data = inb(u_MidiData);
254 midi_input_intr(my_dev, data);
256 if (stat & MIDI_XMIT_EMPTY) {
257 while (qlen && dump_to_midi(tmp_queue[qhead])) {
264 * Disable Midi output interrupts, since no data in
267 gus_midi_control &= ~MIDI_ENABLE_XMIT;
268 outb(u_MidiControl, gus_midi_control);