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