This source file includes following definitions.
- sb16midi_status
- sb16midi_cmd
- sb16midi_read
- sb16midi_write
- sb16midi_input_loop
- sb16midiintr
- sbmidiintr
- sb16midi_open
- sb16midi_close
- sb16midi_out
- sb16midi_start_read
- sb16midi_end_read
- sb16midi_ioctl
- sb16midi_kick
- sb16midi_buffer_status
- enter_uart_mode
- attach_sb16midi
- reset_sb16midi
- probe_sb16midi
- unload_sb16midi
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 #if defined(CONFIG_SB) && defined(CONFIG_MIDI)
35
36 #include "sb.h"
37
38 #define DATAPORT (sb16midi_base)
39 #define COMDPORT (sb16midi_base+1)
40 #define STATPORT (sb16midi_base+1)
41
42 extern int *sb_osp;
43 static int sb16midi_base = 0;
44
45 static int
46 sb16midi_status (void)
47 {
48 return inb (STATPORT);
49 }
50 #define input_avail() (!(sb16midi_status()&INPUT_AVAIL))
51 #define output_ready() (!(sb16midi_status()&OUTPUT_READY))
52 static void
53 sb16midi_cmd (unsigned char cmd)
54 {
55 outb (cmd, COMDPORT);
56 }
57 static int
58 sb16midi_read (void)
59 {
60 return inb (DATAPORT);
61 }
62 static void
63 sb16midi_write (unsigned char byte)
64 {
65 outb (byte, DATAPORT);
66 }
67
68 #define OUTPUT_READY 0x40
69 #define INPUT_AVAIL 0x80
70 #define MPU_ACK 0xFE
71 #define MPU_RESET 0xFF
72 #define UART_MODE_ON 0x3F
73
74 static int sb16midi_opened = 0;
75 static int sb16midi_detected = 0;
76 static int my_dev;
77 extern int sbc_base;
78
79 extern int Jazz16_detected;
80 extern int AudioDrive;
81
82 static int reset_sb16midi (void);
83 static void (*midi_input_intr) (int dev, unsigned char data);
84 static volatile unsigned char input_byte;
85
86 static void
87 sb16midi_input_loop (void)
88 {
89 while (input_avail ())
90 {
91 unsigned char c = sb16midi_read ();
92
93 if (c == MPU_ACK)
94 input_byte = c;
95 else if (sb16midi_opened & OPEN_READ && midi_input_intr)
96 midi_input_intr (my_dev, c);
97 }
98 }
99
100 void
101 sb16midiintr (int unit)
102 {
103 if (sb16midi_base == 0)
104 return;
105
106 if (input_avail ())
107 sb16midi_input_loop ();
108 }
109
110 void
111 sbmidiintr (int irq, void *dev_id, struct pt_regs *dummy)
112 {
113 if (input_avail ())
114 sb16midi_input_loop ();
115 }
116
117 static int
118 sb16midi_open (int dev, int mode,
119 void (*input) (int dev, unsigned char data),
120 void (*output) (int dev)
121 )
122 {
123 if (sb16midi_opened)
124 {
125 return -EBUSY;
126 }
127
128 while (input_avail ())
129 sb16midi_read ();
130
131 midi_input_intr = input;
132 sb16midi_opened = mode;
133
134 return 0;
135 }
136
137 static void
138 sb16midi_close (int dev)
139 {
140 sb16midi_opened = 0;
141 }
142
143 static int
144 sb16midi_out (int dev, unsigned char midi_byte)
145 {
146 int timeout;
147 unsigned long flags;
148
149
150
151
152
153 save_flags (flags);
154 cli ();
155
156 if (input_avail ())
157 sb16midi_input_loop ();
158
159 restore_flags (flags);
160
161
162
163
164
165
166 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
167
168
169
170 if (!output_ready ())
171 {
172 printk ("MPU-401: Timeout\n");
173 return 0;
174 }
175
176 sb16midi_write (midi_byte);
177 return 1;
178 }
179
180 static int
181 sb16midi_start_read (int dev)
182 {
183 return 0;
184 }
185
186 static int
187 sb16midi_end_read (int dev)
188 {
189 return 0;
190 }
191
192 static int
193 sb16midi_ioctl (int dev, unsigned cmd, caddr_t arg)
194 {
195 return -EINVAL;
196 }
197
198 static void
199 sb16midi_kick (int dev)
200 {
201 }
202
203 static int
204 sb16midi_buffer_status (int dev)
205 {
206 return 0;
207
208
209 }
210
211 #define MIDI_SYNTH_NAME "SoundBlaster MPU"
212 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
213 #include "midi_synth.h"
214
215 static struct midi_operations sb16midi_operations =
216 {
217 {"SoundBlaster MPU", 0, 0, SNDCARD_SB16MIDI},
218 &std_midi_synth,
219 {0},
220 sb16midi_open,
221 sb16midi_close,
222 sb16midi_ioctl,
223 sb16midi_out,
224 sb16midi_start_read,
225 sb16midi_end_read,
226 sb16midi_kick,
227 NULL,
228 sb16midi_buffer_status,
229 NULL
230 };
231
232 static void
233 enter_uart_mode (void)
234 {
235 int ok, timeout;
236 unsigned long flags;
237
238 save_flags (flags);
239 cli ();
240 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
241
242 input_byte = 0;
243 sb16midi_cmd (UART_MODE_ON);
244
245 ok = 0;
246 for (timeout = 50000; timeout > 0 && !ok; timeout--)
247 if (input_byte == MPU_ACK)
248 ok = 1;
249 else if (input_avail ())
250 if (sb16midi_read () == MPU_ACK)
251 ok = 1;
252
253 restore_flags (flags);
254 }
255
256 long
257 attach_sb16midi (long mem_start, struct address_info *hw_config)
258 {
259 sb16midi_base = hw_config->io_base;
260
261 if (!sb16midi_detected)
262 return mem_start;
263
264 request_region (hw_config->io_base, 4, "SB MIDI");
265 enter_uart_mode ();
266
267 if (num_midis >= MAX_MIDI_DEV)
268 {
269 printk ("Sound: Too many midi devices detected\n");
270 return mem_start;
271 }
272
273 conf_printf ("SoundBlaster MPU-401", hw_config);
274
275 std_midi_synth.midi_dev = my_dev = num_midis;
276 midi_devs[num_midis++] = &sb16midi_operations;
277 return mem_start;
278 }
279
280 static int
281 reset_sb16midi (void)
282 {
283 int ok, timeout, n;
284
285
286
287
288
289 ok = 0;
290
291
292
293 for (n = 0; n < 2 && !ok; n++)
294 {
295 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
296
297
298 input_byte = 0;
299 sb16midi_cmd (MPU_RESET);
300
301
302
303
304
305
306
307
308 for (timeout = 50000; timeout > 0 && !ok; timeout--)
309 if (input_byte == MPU_ACK)
310 ok = 1;
311 else if (input_avail ())
312 if (sb16midi_read () == MPU_ACK)
313 ok = 1;
314
315 }
316
317 sb16midi_opened = 0;
318 if (ok)
319 sb16midi_input_loop ();
320
321
322
323
324
325 return ok;
326 }
327
328 int
329 probe_sb16midi (struct address_info *hw_config)
330 {
331 int ok = 0;
332 extern int sbc_major;
333
334 extern void ess_midi_init (struct address_info *hw_config);
335 extern void Jazz16_midi_init (struct address_info *hw_config);
336
337 if (check_region (hw_config->io_base, 4))
338 return 0;
339
340 if (AudioDrive)
341 ess_midi_init (hw_config);
342 else if (Jazz16_detected)
343 Jazz16_midi_init (hw_config);
344 else if (sbc_major < 4)
345 return 0;
346
347 sb16midi_base = hw_config->io_base;
348
349 if (sb_get_irq () < 0)
350 return 0;
351
352 ok = reset_sb16midi ();
353
354 sb16midi_detected = ok;
355 return ok;
356 }
357
358 void
359 unload_sb16midi (struct address_info *hw_config)
360 {
361 release_region (hw_config->io_base, 4);
362 }
363
364 #endif