summaryrefslogtreecommitdiffstats
path: root/drivers/sound/pas2_midi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sound/pas2_midi.c')
-rw-r--r--drivers/sound/pas2_midi.c326
1 files changed, 160 insertions, 166 deletions
diff --git a/drivers/sound/pas2_midi.c b/drivers/sound/pas2_midi.c
index 05a509f91..45b60fefd 100644
--- a/drivers/sound/pas2_midi.c
+++ b/drivers/sound/pas2_midi.c
@@ -15,7 +15,7 @@
#include "sound_config.h"
-#if defined(CONFIG_PAS) && defined(CONFIG_MIDI)
+#if ( defined(MODULE) || defined(CONFIG_PAS) ) && defined(CONFIG_MIDI)
static int midi_busy = 0, input_opened = 0;
static int my_dev;
@@ -27,87 +27,86 @@ static volatile unsigned char qhead, qtail;
static void (*midi_input_intr) (int dev, unsigned char data);
static int
-pas_midi_open (int dev, int mode,
- void (*input) (int dev, unsigned char data),
- void (*output) (int dev)
+pas_midi_open(int dev, int mode,
+ void (*input) (int dev, unsigned char data),
+ void (*output) (int dev)
)
{
- int err;
- unsigned long flags;
- unsigned char ctrl;
+ int err;
+ unsigned long flags;
+ unsigned char ctrl;
- if (midi_busy)
- {
- printk ("PAS16: Midi busy\n");
- return -EBUSY;
- }
-
- /*
- * Reset input and output FIFO pointers
- */
- pas_write (0x20 | 0x40,
- 0x178b);
-
- save_flags (flags);
- cli ();
-
- if ((err = pas_set_intr (0x10)) < 0)
- return err;
-
- /*
- * Enable input available and output FIFO empty interrupts
- */
+ if (midi_busy)
+ {
+ printk("PAS16: Midi busy\n");
+ return -EBUSY;
+ }
+ /*
+ * Reset input and output FIFO pointers
+ */
+ pas_write(0x20 | 0x40,
+ 0x178b);
- ctrl = 0;
- input_opened = 0;
- midi_input_intr = input;
+ save_flags(flags);
+ cli();
- if (mode == OPEN_READ || mode == OPEN_READWRITE)
- {
- ctrl |= 0x04; /* Enable input */
- input_opened = 1;
- }
+ if ((err = pas_set_intr(0x10)) < 0)
+ {
+ restore_flags(flags);
+ return err;
+ }
+ /*
+ * Enable input available and output FIFO empty interrupts
+ */
- if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
- {
- ctrl |= 0x08 | 0x10; /* Enable output */
- }
+ ctrl = 0;
+ input_opened = 0;
+ midi_input_intr = input;
- pas_write (ctrl, 0x178b);
+ if (mode == OPEN_READ || mode == OPEN_READWRITE)
+ {
+ ctrl |= 0x04; /* Enable input */
+ input_opened = 1;
+ }
+ if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
+ {
+ ctrl |= 0x08 | 0x10; /* Enable output */
+ }
+ pas_write(ctrl, 0x178b);
- /*
- * Acknowledge any pending interrupts
- */
+ /*
+ * Acknowledge any pending interrupts
+ */
- pas_write (0xff, 0x1B88);
+ pas_write(0xff, 0x1B88);
- restore_flags (flags);
+ restore_flags(flags);
- midi_busy = 1;
- qlen = qhead = qtail = 0;
- return 0;
+ midi_busy = 1;
+ qlen = qhead = qtail = 0;
+ return 0;
}
static void
-pas_midi_close (int dev)
+pas_midi_close(int dev)
{
- /*
- * Reset FIFO pointers, disable intrs
- */
- pas_write (0x20 | 0x40, 0x178b);
+ /*
+ * Reset FIFO pointers, disable intrs
+ */
+ pas_write(0x20 | 0x40, 0x178b);
- pas_remove_intr (0x10);
- midi_busy = 0;
+ pas_remove_intr(0x10);
+ midi_busy = 0;
}
static int
-dump_to_midi (unsigned char midi_byte)
+dump_to_midi(unsigned char midi_byte)
{
- int fifo_space, x;
+ int fifo_space, x;
- fifo_space = ((x = pas_read (0x1B89)) >> 4) & 0x0f;
+ fifo_space = ((x = pas_read(0x1B89)) >> 4) & 0x0f;
/*
* The MIDI FIFO space register and it's documentation is nonunderstandable.
@@ -117,91 +116,90 @@ dump_to_midi (unsigned char midi_byte)
* means that the buffer is empty.
*/
- if (fifo_space < 2 && fifo_space != 0) /* Full (almost) */
- {
- return 0; /* Ask upper layers to retry after some time */
- }
-
- pas_write (midi_byte, 0x178A);
+ if (fifo_space < 2 && fifo_space != 0) /* Full (almost) */
+ {
+ return 0; /* Ask upper layers to retry after some time */
+ }
+ pas_write(midi_byte, 0x178A);
- return 1;
+ return 1;
}
static int
-pas_midi_out (int dev, unsigned char midi_byte)
+pas_midi_out(int dev, unsigned char midi_byte)
{
- unsigned long flags;
+ unsigned long flags;
- /*
- * Drain the local queue first
- */
+ /*
+ * Drain the local queue first
+ */
- save_flags (flags);
- cli ();
+ save_flags(flags);
+ cli();
- while (qlen && dump_to_midi (tmp_queue[qhead]))
- {
- qlen--;
- qhead++;
- }
+ while (qlen && dump_to_midi(tmp_queue[qhead]))
+ {
+ qlen--;
+ qhead++;
+ }
- restore_flags (flags);
+ restore_flags(flags);
- /*
- * Output the byte if the local queue is empty.
- */
+ /*
+ * Output the byte if the local queue is empty.
+ */
- if (!qlen)
- if (dump_to_midi (midi_byte))
- return 1;
+ if (!qlen)
+ if (dump_to_midi(midi_byte))
+ return 1;
- /*
- * Put to the local queue
- */
+ /*
+ * Put to the local queue
+ */
- if (qlen >= 256)
- return 0; /* Local queue full */
+ if (qlen >= 256)
+ return 0; /* Local queue full */
- save_flags (flags);
- cli ();
+ save_flags(flags);
+ cli();
- tmp_queue[qtail] = midi_byte;
- qlen++;
- qtail++;
+ tmp_queue[qtail] = midi_byte;
+ qlen++;
+ qtail++;
- restore_flags (flags);
+ restore_flags(flags);
- return 1;
+ return 1;
}
static int
-pas_midi_start_read (int dev)
+pas_midi_start_read(int dev)
{
- return 0;
+ return 0;
}
static int
-pas_midi_end_read (int dev)
+pas_midi_end_read(int dev)
{
- return 0;
+ return 0;
}
static int
-pas_midi_ioctl (int dev, unsigned cmd, caddr_t arg)
+pas_midi_ioctl(int dev, unsigned cmd, caddr_t arg)
{
- return -EINVAL;
+ return -EINVAL;
}
static void
-pas_midi_kick (int dev)
+pas_midi_kick(int dev)
{
}
static int
-pas_buffer_status (int dev)
+pas_buffer_status(int dev)
{
- return qlen;
+ return qlen;
}
#define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
@@ -210,80 +208,76 @@ pas_buffer_status (int dev)
static struct midi_operations pas_midi_operations =
{
- {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS},
- &std_midi_synth,
- {0},
- pas_midi_open,
- pas_midi_close,
- pas_midi_ioctl,
- pas_midi_out,
- pas_midi_start_read,
- pas_midi_end_read,
- pas_midi_kick,
- NULL,
- pas_buffer_status,
- NULL
+ {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS},
+ &std_midi_synth,
+ {0},
+ pas_midi_open,
+ pas_midi_close,
+ pas_midi_ioctl,
+ pas_midi_out,
+ pas_midi_start_read,
+ pas_midi_end_read,
+ pas_midi_kick,
+ NULL,
+ pas_buffer_status,
+ NULL
};
void
-pas_midi_init (void)
+pas_midi_init(void)
{
- if (num_midis >= MAX_MIDI_DEV)
- {
- printk ("Sound: Too many midi devices detected\n");
- return;
- }
-
- std_midi_synth.midi_dev = my_dev = num_midis;
- midi_devs[num_midis++] = &pas_midi_operations;
- sequencer_init ();
+ int dev = sound_alloc_mididev();
+
+ if (dev == -1)
+ {
+ printk(KERN_WARNING "pas_midi_init: Too many midi devices detected\n");
+ return;
+ }
+ std_midi_synth.midi_dev = my_dev = dev;
+ midi_devs[dev] = &pas_midi_operations;
+ sequencer_init();
}
void
-pas_midi_interrupt (void)
+pas_midi_interrupt(void)
{
- unsigned char stat;
- int i, incount;
- unsigned long flags;
-
- stat = pas_read (0x1B88);
+ unsigned char stat;
+ int i, incount;
+ unsigned long flags;
- if (stat & 0x04) /* Input data available */
- {
- incount = pas_read (0x1B89) & 0x0f; /* Input FIFO size */
- if (!incount)
- incount = 16;
+ stat = pas_read(0x1B88);
- for (i = 0; i < incount; i++)
- if (input_opened)
+ if (stat & 0x04) /* Input data available */
{
- midi_input_intr (my_dev, pas_read (0x178A));
+ incount = pas_read(0x1B89) & 0x0f; /* Input FIFO size */
+ if (!incount)
+ incount = 16;
+
+ for (i = 0; i < incount; i++)
+ if (input_opened)
+ {
+ midi_input_intr(my_dev, pas_read(0x178A));
+ } else
+ pas_read(0x178A); /* Flush */
}
- else
- pas_read (0x178A); /* Flush */
- }
-
- if (stat & (0x08 | 0x10))
- {
- save_flags (flags);
- cli ();
-
- while (qlen && dump_to_midi (tmp_queue[qhead]))
- {
- qlen--;
- qhead++;
- }
-
- restore_flags (flags);
- }
-
+ if (stat & (0x08 | 0x10))
+ {
+ save_flags(flags);
+ cli();
- if (stat & 0x40)
- {
- printk ("MIDI output overrun %x,%x\n", pas_read (0x1B89), stat);
- }
+ while (qlen && dump_to_midi(tmp_queue[qhead]))
+ {
+ qlen--;
+ qhead++;
+ }
- pas_write (stat, 0x1B88); /* Acknowledge interrupts */
+ restore_flags(flags);
+ }
+ if (stat & 0x40)
+ {
+ printk("MIDI output overrun %x,%x\n", pas_read(0x1B89), stat);
+ }
+ pas_write(stat, 0x1B88); /* Acknowledge interrupts */
}
#endif