4 * The low level driver for the PAS Midi Interface.
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
13 * Bartlomiej Zolnierkiewicz : Added __init to pas_init_mixer()
16 #include <linux/init.h>
17 #include <linux/spinlock.h>
18 #include "sound_config.h"
22 extern spinlock_t pas_lock
;
24 static int midi_busy
, input_opened
;
29 static unsigned char tmp_queue
[256];
30 static volatile int qlen
;
31 static volatile unsigned char qhead
, qtail
;
33 static void (*midi_input_intr
) (int dev
, unsigned char data
);
35 static int pas_midi_open(int dev
, int mode
,
36 void (*input
) (int dev
, unsigned char data
),
37 void (*output
) (int dev
)
49 * Reset input and output FIFO pointers
51 pas_write(0x20 | 0x40,
54 spin_lock_irqsave(&pas_lock
, flags
);
56 if ((err
= pas_set_intr(0x10)) < 0)
58 spin_unlock_irqrestore(&pas_lock
, flags
);
62 * Enable input available and output FIFO empty interrupts
67 midi_input_intr
= input
;
69 if (mode
== OPEN_READ
|| mode
== OPEN_READWRITE
)
71 ctrl
|= 0x04; /* Enable input */
74 if (mode
== OPEN_WRITE
|| mode
== OPEN_READWRITE
)
76 ctrl
|= 0x08 | 0x10; /* Enable output */
78 pas_write(ctrl
, 0x178b);
81 * Acknowledge any pending interrupts
84 pas_write(0xff, 0x1B88);
86 spin_unlock_irqrestore(&pas_lock
, flags
);
89 qlen
= qhead
= qtail
= 0;
93 static void pas_midi_close(int dev
)
97 * Reset FIFO pointers, disable intrs
99 pas_write(0x20 | 0x40, 0x178b);
101 pas_remove_intr(0x10);
105 static int dump_to_midi(unsigned char midi_byte
)
109 fifo_space
= ((x
= pas_read(0x1B89)) >> 4) & 0x0f;
112 * The MIDI FIFO space register and it's documentation is nonunderstandable.
113 * There seem to be no way to differentiate between buffer full and buffer
114 * empty situations. For this reason we don't never write the buffer
115 * completely full. In this way we can assume that 0 (or is it 15)
116 * means that the buffer is empty.
119 if (fifo_space
< 2 && fifo_space
!= 0) /* Full (almost) */
120 return 0; /* Ask upper layers to retry after some time */
122 pas_write(midi_byte
, 0x178A);
127 static int pas_midi_out(int dev
, unsigned char midi_byte
)
133 * Drain the local queue first
136 spin_lock_irqsave(&pas_lock
, flags
);
138 while (qlen
&& dump_to_midi(tmp_queue
[qhead
]))
144 spin_unlock_irqrestore(&pas_lock
, flags
);
147 * Output the byte if the local queue is empty.
151 if (dump_to_midi(midi_byte
))
155 * Put to the local queue
159 return 0; /* Local queue full */
161 spin_lock_irqsave(&pas_lock
, flags
);
163 tmp_queue
[qtail
] = midi_byte
;
167 spin_unlock_irqrestore(&pas_lock
, flags
);
172 static int pas_midi_start_read(int dev
)
177 static int pas_midi_end_read(int dev
)
182 static void pas_midi_kick(int dev
)
186 static int pas_buffer_status(int dev
)
191 #define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
192 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
193 #include "midi_synth.h"
195 static struct midi_operations pas_midi_operations
=
197 .owner
= THIS_MODULE
,
198 .info
= {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS
},
199 .converter
= &std_midi_synth
,
201 .open
= pas_midi_open
,
202 .close
= pas_midi_close
,
203 .outputc
= pas_midi_out
,
204 .start_read
= pas_midi_start_read
,
205 .end_read
= pas_midi_end_read
,
206 .kick
= pas_midi_kick
,
207 .buffer_status
= pas_buffer_status
,
210 void __init
pas_midi_init(void)
212 int dev
= sound_alloc_mididev();
216 printk(KERN_WARNING
"pas_midi_init: Too many midi devices detected\n");
219 std_midi_synth
.midi_dev
= my_dev
= dev
;
220 midi_devs
[dev
] = &pas_midi_operations
;
225 void pas_midi_interrupt(void)
230 stat
= pas_read(0x1B88);
232 if (stat
& 0x04) /* Input data available */
234 incount
= pas_read(0x1B89) & 0x0f; /* Input FIFO size */
238 for (i
= 0; i
< incount
; i
++)
241 midi_input_intr(my_dev
, pas_read(0x178A));
243 pas_read(0x178A); /* Flush */
245 if (stat
& (0x08 | 0x10))
247 spin_lock(&pas_lock
);/* called in irq context */
249 while (qlen
&& dump_to_midi(tmp_queue
[qhead
]))
255 spin_unlock(&pas_lock
);
259 printk(KERN_WARNING
"MIDI output overrun %x,%x\n", pas_read(0x1B89), stat
);
261 pas_write(stat
, 0x1B88); /* Acknowledge interrupts */