This source file includes following definitions.
- GUS_MIDI_STATUS
- gus_midi_open
- dump_to_midi
- gus_midi_close
- gus_midi_out
- gus_midi_start_read
- gus_midi_end_read
- gus_midi_ioctl
- gus_midi_kick
- gus_midi_buffer_status
- gus_midi_init
- gus_midi_interrupt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <linux/config.h>
30
31
32 #include "sound_config.h"
33
34 #include "gus_hw.h"
35
36 #if defined(CONFIG_GUS) && defined(CONFIG_MIDI)
37
38 static int midi_busy = 0, input_opened = 0;
39 static int my_dev;
40 static int output_used = 0;
41 static volatile unsigned char gus_midi_control;
42
43 static void (*midi_input_intr) (int dev, unsigned char data);
44
45 static unsigned char tmp_queue[256];
46 static volatile int qlen;
47 static volatile unsigned char qhead, qtail;
48 extern int gus_base, gus_irq, gus_dma;
49 extern int *gus_osp;
50
51 static int
52 GUS_MIDI_STATUS (void)
53 {
54 return inb (u_MidiStatus);
55 }
56
57 static int
58 gus_midi_open (int dev, int mode,
59 void (*input) (int dev, unsigned char data),
60 void (*output) (int dev)
61 )
62 {
63
64 if (midi_busy)
65 {
66 printk ("GUS: Midi busy\n");
67 return -EBUSY;
68 }
69
70 outb (MIDI_RESET, u_MidiControl);
71 gus_delay ();
72
73 gus_midi_control = 0;
74 input_opened = 0;
75
76 if (mode == OPEN_READ || mode == OPEN_READWRITE)
77 {
78 gus_midi_control |= MIDI_ENABLE_RCV;
79 input_opened = 1;
80 }
81
82
83 outb (gus_midi_control, u_MidiControl);
84
85 midi_busy = 1;
86 qlen = qhead = qtail = output_used = 0;
87 midi_input_intr = input;
88
89 return 0;
90 }
91
92 static int
93 dump_to_midi (unsigned char midi_byte)
94 {
95 unsigned long flags;
96 int ok = 0;
97
98 output_used = 1;
99
100 save_flags (flags);
101 cli ();
102
103 if (GUS_MIDI_STATUS () & MIDI_XMIT_EMPTY)
104 {
105 ok = 1;
106 outb (midi_byte, u_MidiData);
107 }
108 else
109 {
110
111
112
113 gus_midi_control |= MIDI_ENABLE_XMIT;
114 outb (gus_midi_control, u_MidiControl);
115 }
116
117 restore_flags (flags);
118 return ok;
119 }
120
121 static void
122 gus_midi_close (int dev)
123 {
124
125
126
127
128 outb (MIDI_RESET, u_MidiControl);
129 midi_busy = 0;
130 }
131
132 static int
133 gus_midi_out (int dev, unsigned char midi_byte)
134 {
135
136 unsigned long flags;
137
138
139
140
141
142 save_flags (flags);
143 cli ();
144
145 while (qlen && dump_to_midi (tmp_queue[qhead]))
146 {
147 qlen--;
148 qhead++;
149 }
150
151 restore_flags (flags);
152
153
154
155
156
157 if (!qlen)
158 if (dump_to_midi (midi_byte))
159 return 1;
160
161
162
163
164
165
166
167 if (qlen >= 256)
168 return 0;
169
170
171
172 save_flags (flags);
173 cli ();
174
175 tmp_queue[qtail] = midi_byte;
176 qlen++;
177 qtail++;
178
179 restore_flags (flags);
180
181 return 1;
182 }
183
184 static int
185 gus_midi_start_read (int dev)
186 {
187 return 0;
188 }
189
190 static int
191 gus_midi_end_read (int dev)
192 {
193 return 0;
194 }
195
196 static int
197 gus_midi_ioctl (int dev, unsigned cmd, caddr_t arg)
198 {
199 return -EINVAL;
200 }
201
202 static void
203 gus_midi_kick (int dev)
204 {
205 }
206
207 static int
208 gus_midi_buffer_status (int dev)
209 {
210 unsigned long flags;
211
212 if (!output_used)
213 return 0;
214
215 save_flags (flags);
216 cli ();
217
218 if (qlen && dump_to_midi (tmp_queue[qhead]))
219 {
220 qlen--;
221 qhead++;
222 }
223
224 restore_flags (flags);
225
226 return (qlen > 0) | !(GUS_MIDI_STATUS () & MIDI_XMIT_EMPTY);
227 }
228
229 #define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
230 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
231 #include "midi_synth.h"
232
233 static struct midi_operations gus_midi_operations =
234 {
235 {"Gravis UltraSound Midi", 0, 0, SNDCARD_GUS},
236 &std_midi_synth,
237 {0},
238 gus_midi_open,
239 gus_midi_close,
240 gus_midi_ioctl,
241 gus_midi_out,
242 gus_midi_start_read,
243 gus_midi_end_read,
244 gus_midi_kick,
245 NULL,
246
247
248 gus_midi_buffer_status,
249 NULL
250 };
251
252 long
253 gus_midi_init (long mem_start)
254 {
255 if (num_midis >= MAX_MIDI_DEV)
256 {
257 printk ("Sound: Too many midi devices detected\n");
258 return mem_start;
259 }
260
261 outb (MIDI_RESET, u_MidiControl);
262
263 std_midi_synth.midi_dev = my_dev = num_midis;
264 midi_devs[num_midis++] = &gus_midi_operations;
265 return mem_start;
266 }
267
268 void
269 gus_midi_interrupt (int dummy)
270 {
271 volatile unsigned char stat, data;
272 unsigned long flags;
273 int timeout = 10;
274
275 save_flags (flags);
276 cli ();
277
278 while (timeout-- > 0 && (stat = GUS_MIDI_STATUS ()) & (MIDI_RCV_FULL | MIDI_XMIT_EMPTY))
279 {
280 if (stat & MIDI_RCV_FULL)
281 {
282 data = inb (u_MidiData);
283 if (input_opened)
284 midi_input_intr (my_dev, data);
285 }
286
287 if (stat & MIDI_XMIT_EMPTY)
288 {
289 while (qlen && dump_to_midi (tmp_queue[qhead]))
290 {
291 qlen--;
292 qhead++;
293 }
294
295 if (!qlen)
296 {
297
298
299
300 gus_midi_control &= ~MIDI_ENABLE_XMIT;
301 outb (gus_midi_control, u_MidiControl);
302 outb (gus_midi_control, u_MidiControl);
303 }
304 }
305
306 }
307
308 restore_flags (flags);
309 }
310
311 #endif