This source file includes following definitions.
- mpu401_input_loop
- mpuintr
- poll_mpu401
- mpu401_open
- mpu401_close
- mpu401_out
- mpu401_command
- mpu401_start_read
- mpu401_end_read
- mpu401_ioctl
- mpu401_kick
- mpu401_buffer_status
- attach_mpu401
- reset_mpu401
- probe_mpu401
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
32 #include "sound_config.h"
33
34 #ifdef CONFIGURE_SOUNDCARD
35
36 #if !defined(EXCLUDE_MPU401) && !defined(EXCLUDE_MIDI)
37
38 #define DATAPORT (mpu401_base)
39 #define COMDPORT (mpu401_base+1)
40 #define STATPORT (mpu401_base+1)
41
42 #define mpu401_status() INB(STATPORT)
43 #define input_avail() (!(mpu401_status()&INPUT_AVAIL))
44 #define output_ready() (!(mpu401_status()&OUTPUT_READY))
45 #define mpu401_cmd(cmd) OUTB(cmd, COMDPORT)
46 #define mpu401_read() INB(DATAPORT)
47 #define mpu401_write(byte) OUTB(byte, DATAPORT)
48
49 #define OUTPUT_READY 0x40
50 #define INPUT_AVAIL 0x80
51 #define MPU_ACK 0xFE
52 #define MPU_RESET 0xFF
53 #define UART_MODE_ON 0x3F
54
55 static int mpu401_opened = 0;
56 static int mpu401_base = 0x330;
57 static int mpu401_irq;
58 static int mpu401_detected = 0;
59 static int my_dev;
60
61 static int reset_mpu401 (void);
62 static void (*midi_input_intr) (int dev, unsigned char data);
63
64 static void
65 mpu401_input_loop (void)
66 {
67 int count;
68
69 count = 10;
70
71 while (count)
72 if (input_avail ())
73 {
74 unsigned char c = mpu401_read ();
75
76 count = 100;
77
78 if (mpu401_opened & OPEN_READ)
79 midi_input_intr (my_dev, c);
80 }
81 else
82 while (!input_avail () && count)
83 count--;
84 }
85
86 void
87 mpuintr (int unit)
88 {
89 if (input_avail ())
90 mpu401_input_loop ();
91 }
92
93
94
95
96
97
98 static void
99 poll_mpu401 (unsigned long dummy)
100 {
101 unsigned long flags;
102
103 DEFINE_TIMER(mpu401_timer, poll_mpu401);
104
105 if (!(mpu401_opened & OPEN_READ))
106 return;
107
108 DISABLE_INTR (flags);
109
110 if (input_avail ())
111 mpu401_input_loop ();
112
113 ACTIVATE_TIMER(mpu401_timer, poll_mpu401, 1);
114
115 RESTORE_INTR (flags);
116 }
117
118 static int
119 mpu401_open (int dev, int mode,
120 void (*input) (int dev, unsigned char data),
121 void (*output) (int dev)
122 )
123 {
124 if (mpu401_opened)
125 {
126 printk ("MPU-401: Midi busy\n");
127 return RET_ERROR (EBUSY);
128 }
129
130 mpu401_input_loop ();
131
132 midi_input_intr = input;
133 mpu401_opened = mode;
134 poll_mpu401 (0);
135
136 return 0;
137 }
138
139 static void
140 mpu401_close (int dev)
141 {
142 mpu401_opened = 0;
143 }
144
145 static int
146 mpu401_out (int dev, unsigned char midi_byte)
147 {
148 int timeout;
149 unsigned long flags;
150
151
152
153
154
155 DISABLE_INTR (flags);
156
157 if (input_avail ())
158 mpu401_input_loop ();
159
160 RESTORE_INTR (flags);
161
162
163
164
165
166
167 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
168
169 if (!output_ready ())
170 {
171 printk ("MPU-401: Timeout\n");
172 return 0;
173 }
174
175 mpu401_write (midi_byte);
176 return 1;
177 }
178
179 static int
180 mpu401_command (int dev, unsigned char midi_byte)
181 {
182 return 1;
183 }
184
185 static int
186 mpu401_start_read (int dev)
187 {
188 return 0;
189 }
190
191 static int
192 mpu401_end_read (int dev)
193 {
194 return 0;
195 }
196
197 static int
198 mpu401_ioctl (int dev, unsigned cmd, unsigned arg)
199 {
200 return RET_ERROR (EINVAL);
201 }
202
203 static void
204 mpu401_kick (int dev)
205 {
206 }
207
208 static int
209 mpu401_buffer_status (int dev)
210 {
211 return 0;
212 }
213
214 static struct midi_operations mpu401_operations =
215 {
216 {"MPU-401", 0, 0, SNDCARD_MPU401},
217 mpu401_open,
218 mpu401_close,
219 mpu401_ioctl,
220 mpu401_out,
221 mpu401_start_read,
222 mpu401_end_read,
223 mpu401_kick,
224 mpu401_command,
225 mpu401_buffer_status
226 };
227
228
229 long
230 attach_mpu401 (long mem_start, struct address_info *hw_config)
231 {
232 int ok, timeout;
233 unsigned long flags;
234
235 mpu401_base = hw_config->io_base;
236 mpu401_irq = hw_config->irq;
237
238 if (!mpu401_detected)
239 return RET_ERROR (EIO);
240
241 DISABLE_INTR (flags);
242 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
243 mpu401_cmd (UART_MODE_ON);
244
245 ok = 0;
246 for (timeout = 50000; timeout > 0 && !ok; timeout--)
247 if (input_avail ())
248 if (mpu401_read () == MPU_ACK)
249 ok = 1;
250
251 RESTORE_INTR (flags);
252
253 printk (" <Roland MPU-401>");
254
255 my_dev = num_midis;
256 mpu401_dev = num_midis;
257 midi_devs[num_midis++] = &mpu401_operations;
258 return mem_start;
259 }
260
261 static int
262 reset_mpu401 (void)
263 {
264 unsigned long flags;
265 int ok, timeout, n;
266
267
268
269
270
271 ok = 0;
272
273 DISABLE_INTR (flags);
274
275 for (n = 0; n < 2 && !ok; n++)
276 {
277 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
278 mpu401_cmd (MPU_RESET);
279
280
281
282
283
284
285 for (timeout = 50000; timeout > 0 && !ok; timeout--)
286 if (input_avail ())
287 if (mpu401_read () == MPU_ACK)
288 ok = 1;
289
290 }
291
292 mpu401_opened = 0;
293 if (ok)
294 mpu401_input_loop ();
295
296 RESTORE_INTR (flags);
297
298 return ok;
299 }
300
301
302 int
303 probe_mpu401 (struct address_info *hw_config)
304 {
305 int ok = 0;
306
307 mpu401_base = hw_config->io_base;
308 mpu401_irq = hw_config->irq;
309
310 if (snd_set_irq_handler (mpu401_irq, mpuintr) < 0)
311 return 0;
312
313 ok = reset_mpu401 ();
314
315 mpu401_detected = ok;
316 return ok;
317 }
318
319 #endif
320
321 #endif