1993-10-23 10:55:52 +00:00
|
|
|
/*
|
1994-03-11 10:27:25 +00:00
|
|
|
* sound/gus2_midi.c
|
1994-04-23 01:50:14 +00:00
|
|
|
*
|
1993-10-23 10:55:52 +00:00
|
|
|
* The low level driver for the GUS Midi Interface.
|
1994-04-23 01:50:14 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* Copyright by Hannu Savolainen 1993
|
1994-04-23 01:50:14 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer. 2.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
1994-04-23 01:50:14 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1994-04-23 01:50:14 +00:00
|
|
|
*
|
1995-03-05 22:11:57 +00:00
|
|
|
* gus_midi.c,v 1.6 1994/10/01 02:16:39 swallace Exp
|
1993-10-23 10:55:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sound_config.h"
|
|
|
|
|
|
|
|
#ifdef CONFIGURE_SOUNDCARD
|
|
|
|
|
|
|
|
#include "gus_hw.h"
|
|
|
|
|
|
|
|
#if !defined(EXCLUDE_GUS) && !defined(EXCLUDE_MIDI)
|
|
|
|
|
|
|
|
static int midi_busy = 0, input_opened = 0;
|
|
|
|
static int my_dev;
|
|
|
|
static int output_used = 0;
|
|
|
|
static volatile unsigned char gus_midi_control;
|
|
|
|
|
1993-10-29 03:44:07 +00:00
|
|
|
static void (*midi_input_intr) (int dev, unsigned char data);
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
static unsigned char tmp_queue[256];
|
|
|
|
static volatile int qlen;
|
|
|
|
static volatile unsigned char qhead, qtail;
|
|
|
|
extern int gus_base, gus_irq, gus_dma;
|
|
|
|
|
|
|
|
#define GUS_MIDI_STATUS() INB(u_MidiStatus)
|
|
|
|
|
|
|
|
static int
|
1993-10-29 03:44:07 +00:00
|
|
|
gus_midi_open (int dev, int mode,
|
|
|
|
void (*input) (int dev, unsigned char data),
|
|
|
|
void (*output) (int dev)
|
|
|
|
)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (midi_busy)
|
|
|
|
{
|
|
|
|
printk ("GUS: Midi busy\n");
|
|
|
|
return RET_ERROR (EBUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
OUTB (MIDI_RESET, u_MidiControl);
|
|
|
|
gus_delay ();
|
|
|
|
|
|
|
|
gus_midi_control = 0;
|
|
|
|
input_opened = 0;
|
|
|
|
|
|
|
|
if (mode == OPEN_READ || mode == OPEN_READWRITE)
|
|
|
|
{
|
|
|
|
gus_midi_control |= MIDI_ENABLE_RCV;
|
|
|
|
input_opened = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
|
|
|
|
{
|
|
|
|
gus_midi_control |= MIDI_ENABLE_XMIT;
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
OUTB (gus_midi_control, u_MidiControl); /*
|
|
|
|
* Enable
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
midi_busy = 1;
|
|
|
|
qlen = qhead = qtail = output_used = 0;
|
1993-10-29 03:44:07 +00:00
|
|
|
midi_input_intr = input;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dump_to_midi (unsigned char midi_byte)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ok = 0;
|
|
|
|
|
|
|
|
output_used = 1;
|
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
if (GUS_MIDI_STATUS () & MIDI_XMIT_EMPTY)
|
|
|
|
{
|
|
|
|
ok = 1;
|
|
|
|
OUTB (midi_byte, u_MidiData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Enable Midi xmit interrupts (again)
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
gus_midi_control |= MIDI_ENABLE_XMIT;
|
|
|
|
OUTB (gus_midi_control, u_MidiControl);
|
|
|
|
}
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gus_midi_close (int dev)
|
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Reset FIFO pointers, disable intrs
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
OUTB (MIDI_RESET, u_MidiControl);
|
|
|
|
midi_busy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gus_midi_out (int dev, unsigned char midi_byte)
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drain the local queue first
|
|
|
|
*/
|
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
while (qlen && dump_to_midi (tmp_queue[qhead]))
|
|
|
|
{
|
|
|
|
qlen--;
|
|
|
|
qhead++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output the byte if the local queue is empty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!qlen)
|
|
|
|
if (dump_to_midi (midi_byte))
|
1994-10-01 02:17:17 +00:00
|
|
|
return 1; /*
|
|
|
|
* OK
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put to the local queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (qlen >= 256)
|
1994-10-01 02:17:17 +00:00
|
|
|
return 0; /*
|
|
|
|
* Local queue full
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
tmp_queue[qtail] = midi_byte;
|
|
|
|
qlen++;
|
|
|
|
qtail++;
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gus_midi_start_read (int dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gus_midi_end_read (int dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gus_midi_ioctl (int dev, unsigned cmd, unsigned arg)
|
|
|
|
{
|
|
|
|
return RET_ERROR (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gus_midi_kick (int dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gus_midi_buffer_status (int dev)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (!output_used)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
if (qlen && dump_to_midi (tmp_queue[qhead]))
|
|
|
|
{
|
|
|
|
qlen--;
|
|
|
|
qhead++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
|
|
|
|
return (qlen > 0) | !(GUS_MIDI_STATUS () & MIDI_XMIT_EMPTY);
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
#define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
|
|
|
|
#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
|
|
|
|
#include "midi_synth.h"
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
static struct midi_operations gus_midi_operations =
|
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
{"Gravis UltraSound Midi", 0, 0, SNDCARD_GUS},
|
|
|
|
&std_midi_synth,
|
1993-10-23 10:55:52 +00:00
|
|
|
gus_midi_open,
|
|
|
|
gus_midi_close,
|
|
|
|
gus_midi_ioctl,
|
|
|
|
gus_midi_out,
|
|
|
|
gus_midi_start_read,
|
|
|
|
gus_midi_end_read,
|
|
|
|
gus_midi_kick,
|
1994-10-01 02:17:17 +00:00
|
|
|
NULL, /*
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
gus_midi_buffer_status,
|
|
|
|
NULL
|
1993-10-23 10:55:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
long
|
|
|
|
gus_midi_init (long mem_start)
|
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
if (num_midis >= MAX_MIDI_DEV)
|
|
|
|
{
|
|
|
|
printk ("Sound: Too many midi devices detected\n");
|
|
|
|
return mem_start;
|
|
|
|
}
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
OUTB (MIDI_RESET, u_MidiControl);
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
std_midi_synth.midi_dev = my_dev = num_midis;
|
1993-10-23 10:55:52 +00:00
|
|
|
midi_devs[num_midis++] = &gus_midi_operations;
|
|
|
|
return mem_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gus_midi_interrupt (int dummy)
|
|
|
|
{
|
|
|
|
unsigned char stat, data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
stat = GUS_MIDI_STATUS ();
|
|
|
|
|
|
|
|
if (stat & MIDI_RCV_FULL)
|
|
|
|
{
|
|
|
|
data = INB (u_MidiData);
|
|
|
|
if (input_opened)
|
1993-10-29 03:44:07 +00:00
|
|
|
midi_input_intr (my_dev, data);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stat & MIDI_XMIT_EMPTY)
|
|
|
|
{
|
|
|
|
while (qlen && dump_to_midi (tmp_queue[qhead]))
|
|
|
|
{
|
|
|
|
qlen--;
|
|
|
|
qhead++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!qlen)
|
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Disable Midi output interrupts, since no data in the buffer
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
gus_midi_control &= ~MIDI_ENABLE_XMIT;
|
|
|
|
OUTB (gus_midi_control, u_MidiControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat & MIDI_FRAME_ERR)
|
|
|
|
printk ("Midi framing error\n");
|
|
|
|
if (stat & MIDI_OVERRUN && input_opened)
|
|
|
|
printk ("GUS: Midi input overrun\n");
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|