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
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
71 static void
72 uart6850_input_loop (void)
73 {
74 int count;
75
76 count = 10;
77
78 while (count)
79
80
81 if (input_avail ())
82 {
83 unsigned char c = uart6850_read ();
84
85 count = 100;
86
87 if (uart6850_opened & OPEN_READ)
88 midi_input_intr (my_dev, c);
89 }
90 else
91 while (!input_avail () && count)
92 count--;
93 }
94
95 void
96 m6850intr (INTR_HANDLER_PARMS (irq, dummy))
97 {
98 if (input_avail ())
99 uart6850_input_loop ();
100 }
101
102
103
104
105
106
107 static void
108 poll_uart6850 (unsigned long dummy)
109 {
110 unsigned long flags;
111
112 DEFINE_TIMER (uart6850_timer, poll_uart6850);
113
114 if (!(uart6850_opened & OPEN_READ))
115 return;
116
117
118
119 DISABLE_INTR (flags);
120
121 if (input_avail ())
122 uart6850_input_loop ();
123
124 ACTIVATE_TIMER (uart6850_timer, poll_uart6850, 1);
125
126
127
128 RESTORE_INTR (flags);
129 }
130
131 static int
132 uart6850_open (int dev, int mode,
133 void (*input) (int dev, unsigned char data),
134 void (*output) (int dev)
135 )
136 {
137 if (uart6850_opened)
138 {
139 printk ("Midi6850: Midi busy\n");
140 return RET_ERROR (EBUSY);
141 }
142
143 uart6850_cmd (UART_RESET);
144
145 uart6850_input_loop ();
146
147 midi_input_intr = input;
148 uart6850_opened = mode;
149 poll_uart6850 (0);
150
151
152
153 return 0;
154 }
155
156 static void
157 uart6850_close (int dev)
158 {
159 uart6850_cmd (UART_MODE_ON);
160
161 uart6850_opened = 0;
162 }
163
164 static int
165 uart6850_out (int dev, unsigned char midi_byte)
166 {
167 int timeout;
168 unsigned long flags;
169
170
171
172
173
174 DISABLE_INTR (flags);
175
176 if (input_avail ())
177 uart6850_input_loop ();
178
179 RESTORE_INTR (flags);
180
181
182
183
184
185
186 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
187
188
189
190 if (!output_ready ())
191 {
192 printk ("Midi6850: Timeout\n");
193 return 0;
194 }
195
196 uart6850_write (midi_byte);
197 return 1;
198 }
199
200 static int
201 uart6850_command (int dev, unsigned char *midi_byte)
202 {
203 return 1;
204 }
205
206 static int
207 uart6850_start_read (int dev)
208 {
209 return 0;
210 }
211
212 static int
213 uart6850_end_read (int dev)
214 {
215 return 0;
216 }
217
218 static int
219 uart6850_ioctl (int dev, unsigned cmd, unsigned arg)
220 {
221 return RET_ERROR (EINVAL);
222 }
223
224 static void
225 uart6850_kick (int dev)
226 {
227 }
228
229 static int
230 uart6850_buffer_status (int dev)
231 {
232 return 0;
233
234
235 }
236
237 #define MIDI_SYNTH_NAME "6850 UART Midi"
238 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
239 #include "midi_synth.h"
240
241 static struct midi_operations uart6850_operations =
242 {
243 {"6850 UART", 0, 0, SNDCARD_UART6850},
244 &std_midi_synth,
245 {0},
246 uart6850_open,
247 uart6850_close,
248 uart6850_ioctl,
249 uart6850_out,
250 uart6850_start_read,
251 uart6850_end_read,
252 uart6850_kick,
253 uart6850_command,
254 uart6850_buffer_status
255 };
256
257
258 long
259 attach_uart6850 (long mem_start, struct address_info *hw_config)
260 {
261 int ok, timeout;
262 unsigned long flags;
263
264 if (num_midis >= MAX_MIDI_DEV)
265 {
266 printk ("Sound: Too many midi devices detected\n");
267 return mem_start;
268 }
269
270 uart6850_base = hw_config->io_base;
271 uart6850_irq = hw_config->irq;
272
273 if (!uart6850_detected)
274 return RET_ERROR (EIO);
275
276 DISABLE_INTR (flags);
277
278 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
279
280
281 uart6850_cmd (UART_MODE_ON);
282
283 ok = 1;
284
285 RESTORE_INTR (flags);
286
287 printk (" <6850 Midi Interface>");
288
289 std_midi_synth.midi_dev = my_dev = num_midis;
290 midi_devs[num_midis++] = &uart6850_operations;
291 return mem_start;
292 }
293
294 static int
295 reset_uart6850 (void)
296 {
297 uart6850_read ();
298 return 1;
299
300
301 }
302
303
304 int
305 probe_uart6850 (struct address_info *hw_config)
306 {
307 int ok = 0;
308
309 uart6850_base = hw_config->io_base;
310 uart6850_irq = hw_config->irq;
311
312 if (snd_set_irq_handler (uart6850_irq, m6850intr, "MIDI6850") < 0)
313 return 0;
314
315 ok = reset_uart6850 ();
316
317 uart6850_detected = ok;
318 return ok;
319 }
320
321 #endif
322
323 #endif