This source file includes following definitions.
- uart6850_status
- uart6850_cmd
- uart6850_read
- uart6850_write
- uart6850_input_loop
- m6850intr
- poll_uart6850
- uart6850_open
- uart6850_close
- uart6850_out
- uart6850_command
- uart6850_start_read
- uart6850_end_read
- uart6850_ioctl
- uart6850_kick
- uart6850_buffer_status
- attach_uart6850
- reset_uart6850
- probe_uart6850
- unload_uart6850
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 #include <linux/config.h>
28
29
30
31
32
33 #include "sound_config.h"
34
35 #if defined(CONFIG_UART6850) && defined(CONFIG_MIDI)
36
37 static int uart6850_base = 0x330;
38
39 static int *uart6850_osp;
40
41 #define DATAPORT (uart6850_base)
42 #define COMDPORT (uart6850_base+1)
43 #define STATPORT (uart6850_base+1)
44
45 static int
46 uart6850_status (void)
47 {
48 return inb (STATPORT);
49 }
50 #define input_avail() (uart6850_status()&INPUT_AVAIL)
51 #define output_ready() (uart6850_status()&OUTPUT_READY)
52 static void
53 uart6850_cmd (unsigned char cmd)
54 {
55 outb (cmd, COMDPORT);
56 }
57 static int
58 uart6850_read (void)
59 {
60 return inb (DATAPORT);
61 }
62 static void
63 uart6850_write (unsigned char byte)
64 {
65 outb (byte, DATAPORT);
66 }
67
68 #define OUTPUT_READY 0x02
69 #define INPUT_AVAIL 0x01
70
71 #define UART_RESET 0x95
72 #define UART_MODE_ON 0x03
73
74 static int uart6850_opened = 0;
75 static int uart6850_irq;
76 static int uart6850_detected = 0;
77 static int my_dev;
78
79 static int reset_uart6850 (void);
80 static void (*midi_input_intr) (int dev, unsigned char data);
81 static void poll_uart6850 (unsigned long dummy);
82
83
84 static struct timer_list uart6850_timer =
85 {NULL, NULL, 0, 0, poll_uart6850};
86
87 static void
88 uart6850_input_loop (void)
89 {
90 int count;
91
92 count = 10;
93
94 while (count)
95
96
97 if (input_avail ())
98 {
99 unsigned char c = uart6850_read ();
100
101 count = 100;
102
103 if (uart6850_opened & OPEN_READ)
104 midi_input_intr (my_dev, c);
105 }
106 else
107 while (!input_avail () && count)
108 count--;
109 }
110
111 void
112 m6850intr (int irq, struct pt_regs *dummy)
113 {
114 if (input_avail ())
115 uart6850_input_loop ();
116 }
117
118
119
120
121
122
123 static void
124 poll_uart6850 (unsigned long dummy)
125 {
126 unsigned long flags;
127
128 if (!(uart6850_opened & OPEN_READ))
129 return;
130
131 save_flags (flags);
132 cli ();
133
134 if (input_avail ())
135 uart6850_input_loop ();
136
137
138 {
139 uart6850_timer.expires = (1) + jiffies;
140 add_timer (&uart6850_timer);
141 };
142
143
144
145 restore_flags (flags);
146 }
147
148 static int
149 uart6850_open (int dev, int mode,
150 void (*input) (int dev, unsigned char data),
151 void (*output) (int dev)
152 )
153 {
154 if (uart6850_opened)
155 {
156 printk ("Midi6850: Midi busy\n");
157 return -EBUSY;
158 }
159
160 ;
161 uart6850_cmd (UART_RESET);
162
163 uart6850_input_loop ();
164
165 midi_input_intr = input;
166 uart6850_opened = mode;
167 poll_uart6850 (0);
168
169
170
171 return 0;
172 }
173
174 static void
175 uart6850_close (int dev)
176 {
177 uart6850_cmd (UART_MODE_ON);
178
179 del_timer (&uart6850_timer);;
180 uart6850_opened = 0;
181 }
182
183 static int
184 uart6850_out (int dev, unsigned char midi_byte)
185 {
186 int timeout;
187 unsigned long flags;
188
189
190
191
192
193 save_flags (flags);
194 cli ();
195
196 if (input_avail ())
197 uart6850_input_loop ();
198
199 restore_flags (flags);
200
201
202
203
204
205
206 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
207
208
209
210 if (!output_ready ())
211 {
212 printk ("Midi6850: Timeout\n");
213 return 0;
214 }
215
216 uart6850_write (midi_byte);
217 return 1;
218 }
219
220 static int
221 uart6850_command (int dev, unsigned char *midi_byte)
222 {
223 return 1;
224 }
225
226 static int
227 uart6850_start_read (int dev)
228 {
229 return 0;
230 }
231
232 static int
233 uart6850_end_read (int dev)
234 {
235 return 0;
236 }
237
238 static int
239 uart6850_ioctl (int dev, unsigned cmd, caddr_t arg)
240 {
241 return -EINVAL;
242 }
243
244 static void
245 uart6850_kick (int dev)
246 {
247 }
248
249 static int
250 uart6850_buffer_status (int dev)
251 {
252 return 0;
253
254
255 }
256
257 #define MIDI_SYNTH_NAME "6850 UART Midi"
258 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
259 #include "midi_synth.h"
260
261 static struct midi_operations uart6850_operations =
262 {
263 {"6850 UART", 0, 0, SNDCARD_UART6850},
264 &std_midi_synth,
265 {0},
266 uart6850_open,
267 uart6850_close,
268 uart6850_ioctl,
269 uart6850_out,
270 uart6850_start_read,
271 uart6850_end_read,
272 uart6850_kick,
273 uart6850_command,
274 uart6850_buffer_status
275 };
276
277
278 long
279 attach_uart6850 (long mem_start, struct address_info *hw_config)
280 {
281 int ok, timeout;
282 unsigned long flags;
283
284 if (num_midis >= MAX_MIDI_DEV)
285 {
286 printk ("Sound: Too many midi devices detected\n");
287 return mem_start;
288 }
289
290 uart6850_base = hw_config->io_base;
291 uart6850_osp = hw_config->osp;
292 uart6850_irq = hw_config->irq;
293
294 if (!uart6850_detected)
295 return -EIO;
296
297 save_flags (flags);
298 cli ();
299
300 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
301
302
303 uart6850_cmd (UART_MODE_ON);
304
305 ok = 1;
306
307 restore_flags (flags);
308
309 conf_printf ("6850 Midi Interface", hw_config);
310
311 std_midi_synth.midi_dev = my_dev = num_midis;
312 midi_devs[num_midis++] = &uart6850_operations;
313 return mem_start;
314 }
315
316 static int
317 reset_uart6850 (void)
318 {
319 uart6850_read ();
320 return 1;
321
322
323 }
324
325
326 int
327 probe_uart6850 (struct address_info *hw_config)
328 {
329 int ok = 0;
330
331 uart6850_osp = hw_config->osp;
332 uart6850_base = hw_config->io_base;
333 uart6850_irq = hw_config->irq;
334
335 if (snd_set_irq_handler (uart6850_irq, m6850intr, "MIDI6850", uart6850_osp) < 0)
336 return 0;
337
338 ok = reset_uart6850 ();
339
340 uart6850_detected = ok;
341 return ok;
342 }
343
344 void
345 unload_uart6850 (struct address_info *hw_config)
346 {
347 snd_release_irq (hw_config->irq);
348 }
349
350 #endif