1993-10-23 10:55:52 +00:00
|
|
|
/*
|
1994-03-11 10:27:25 +00:00
|
|
|
* sound/pas2_midi.c
|
1994-04-23 01:50:14 +00:00
|
|
|
*
|
1993-10-23 10:55:52 +00:00
|
|
|
* The low level driver for the PAS 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
|
|
|
*
|
1993-10-23 10:55:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sound_config.h"
|
|
|
|
|
|
|
|
#ifdef CONFIGURE_SOUNDCARD
|
|
|
|
|
|
|
|
#include "pas.h"
|
|
|
|
|
1993-10-29 03:44:07 +00:00
|
|
|
#if !defined(EXCLUDE_PAS) && !defined(EXCLUDE_MIDI) && defined(EXCLUDE_PRO_MIDI)
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
static int midi_busy = 0, input_opened = 0;
|
|
|
|
static int my_dev;
|
|
|
|
static volatile int ofifo_bytes = 0;
|
|
|
|
|
|
|
|
static unsigned char tmp_queue[256];
|
|
|
|
static volatile int qlen;
|
|
|
|
static volatile unsigned char qhead, qtail;
|
|
|
|
|
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 int
|
1993-10-29 03:44:07 +00:00
|
|
|
pas_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
|
|
|
{
|
|
|
|
int err;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char ctrl;
|
|
|
|
|
|
|
|
|
|
|
|
if (midi_busy)
|
|
|
|
{
|
|
|
|
printk ("PAS2: Midi busy\n");
|
|
|
|
return RET_ERROR (EBUSY);
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Reset input and output FIFO pointers
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
pas_write (M_C_RESET_INPUT_FIFO | M_C_RESET_OUTPUT_FIFO,
|
|
|
|
MIDI_CONTROL);
|
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
if ((err = pas_set_intr (I_M_MIDI_IRQ_ENABLE)) < 0)
|
|
|
|
return err;
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Enable input available and output FIFO empty interrupts
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
ctrl = 0;
|
|
|
|
input_opened = 0;
|
1993-10-29 03:44:07 +00:00
|
|
|
midi_input_intr = input;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
if (mode == OPEN_READ || mode == OPEN_READWRITE)
|
|
|
|
{
|
1995-07-28 21:40:49 +00:00
|
|
|
ctrl |= M_C_ENA_INPUT_IRQ; /*
|
|
|
|
* Enable input
|
1994-10-01 02:17:17 +00:00
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
input_opened = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
|
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
ctrl |= M_C_ENA_OUTPUT_IRQ | /*
|
|
|
|
* Enable output
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
M_C_ENA_OUTPUT_HALF_IRQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas_write (ctrl,
|
|
|
|
MIDI_CONTROL);
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Acknowledge any pending interrupts
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
pas_write (0xff, MIDI_STATUS);
|
|
|
|
ofifo_bytes = 0;
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
|
|
|
|
midi_busy = 1;
|
|
|
|
qlen = qhead = qtail = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pas_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
|
|
|
pas_write (M_C_RESET_INPUT_FIFO | M_C_RESET_OUTPUT_FIFO, MIDI_CONTROL);
|
|
|
|
|
|
|
|
pas_remove_intr (I_M_MIDI_IRQ_ENABLE);
|
|
|
|
midi_busy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dump_to_midi (unsigned char midi_byte)
|
|
|
|
{
|
|
|
|
int fifo_space, x;
|
|
|
|
|
|
|
|
fifo_space = ((x = pas_read (MIDI_FIFO_STATUS)) >> 4) & 0x0f;
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
if (fifo_space == 15 || (fifo_space < 2 && ofifo_bytes > 13)) /*
|
|
|
|
* Fifo
|
|
|
|
* full
|
1994-10-01 02:17:17 +00:00
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
return 0; /*
|
|
|
|
* Upper layer will call again
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ofifo_bytes++;
|
|
|
|
|
|
|
|
pas_write (midi_byte, MIDI_DATA);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pas_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
|
|
|
|
pas_midi_start_read (int dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pas_midi_end_read (int dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pas_midi_ioctl (int dev, unsigned cmd, unsigned arg)
|
|
|
|
{
|
|
|
|
return RET_ERROR (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pas_midi_kick (int dev)
|
|
|
|
{
|
|
|
|
ofifo_bytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pas_buffer_status (int dev)
|
|
|
|
{
|
|
|
|
return !qlen;
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
#define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
|
|
|
|
#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
|
|
|
|
#include "midi_synth.h"
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
static struct midi_operations pas_midi_operations =
|
|
|
|
{
|
1994-03-11 10:27:25 +00:00
|
|
|
{"Pro Audio Spectrum", 0, 0, SNDCARD_PAS},
|
1994-10-01 02:17:17 +00:00
|
|
|
&std_midi_synth,
|
1995-07-28 21:40:49 +00:00
|
|
|
{0},
|
1993-10-23 10:55:52 +00:00
|
|
|
pas_midi_open,
|
|
|
|
pas_midi_close,
|
|
|
|
pas_midi_ioctl,
|
|
|
|
pas_midi_out,
|
|
|
|
pas_midi_start_read,
|
|
|
|
pas_midi_end_read,
|
|
|
|
pas_midi_kick,
|
1994-10-01 02:17:17 +00:00
|
|
|
NULL, /*
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
pas_buffer_status,
|
|
|
|
NULL
|
1993-10-23 10:55:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
long
|
|
|
|
pas_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
std_midi_synth.midi_dev = my_dev = num_midis;
|
1993-10-23 10:55:52 +00:00
|
|
|
midi_devs[num_midis++] = &pas_midi_operations;
|
|
|
|
return mem_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pas_midi_interrupt (void)
|
|
|
|
{
|
|
|
|
unsigned char stat;
|
|
|
|
int i, incount;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
stat = pas_read (MIDI_STATUS);
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
if (stat & M_S_INPUT_AVAIL) /*
|
|
|
|
* Input byte available
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1994-10-01 02:17:17 +00:00
|
|
|
incount = pas_read (MIDI_FIFO_STATUS) & 0x0f; /*
|
|
|
|
* Input FIFO count
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
if (!incount)
|
|
|
|
incount = 16;
|
|
|
|
|
|
|
|
for (i = 0; i < incount; i++)
|
|
|
|
if (input_opened)
|
|
|
|
{
|
1993-10-29 03:44:07 +00:00
|
|
|
midi_input_intr (my_dev, pas_read (MIDI_DATA));
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
else
|
1994-10-01 02:17:17 +00:00
|
|
|
pas_read (MIDI_DATA); /*
|
|
|
|
* Flush
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stat & (M_S_OUTPUT_EMPTY | M_S_OUTPUT_HALF_EMPTY))
|
|
|
|
{
|
|
|
|
if (!(stat & M_S_OUTPUT_EMPTY))
|
|
|
|
{
|
|
|
|
ofifo_bytes = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ofifo_bytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISABLE_INTR (flags);
|
|
|
|
|
|
|
|
while (qlen && dump_to_midi (tmp_queue[qhead]))
|
|
|
|
{
|
|
|
|
qlen--;
|
|
|
|
qhead++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RESTORE_INTR (flags);
|
|
|
|
}
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
#if 0
|
1993-10-23 10:55:52 +00:00
|
|
|
if (stat & M_S_FRAMING_ERROR)
|
|
|
|
printk ("MIDI framing error\n");
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
if (stat & M_S_OUTPUT_OVERRUN)
|
|
|
|
{
|
1994-03-11 10:27:25 +00:00
|
|
|
printk ("MIDI output overrun %x,%x,%d \n", pas_read (MIDI_FIFO_STATUS), stat, ofifo_bytes);
|
1993-10-23 10:55:52 +00:00
|
|
|
ofifo_bytes = 100;
|
|
|
|
}
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
pas_write (stat, MIDI_STATUS); /*
|
|
|
|
* Acknowledge interrupts
|
1994-10-01 02:17:17 +00:00
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|