This source file includes following definitions.
- mpuintr
- 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 void
65 mpuintr (int unit)
66 {
67 while (input_avail ())
68 {
69 unsigned char c = mpu401_read ();
70
71 if (mpu401_opened & OPEN_READ)
72 midi_input_intr (my_dev, c);
73 }
74 }
75
76 static int
77 mpu401_open (int dev, int mode,
78 void (*input) (int dev, unsigned char data),
79 void (*output) (int dev)
80 )
81 {
82 if (mpu401_opened)
83 {
84 printk ("MPU-401: Midi busy\n");
85 return RET_ERROR (EBUSY);
86 }
87
88 mpuintr (0);
89
90 midi_input_intr = input;
91 mpu401_opened = mode;
92
93 return 0;
94 }
95
96 static void
97 mpu401_close (int dev)
98 {
99 mpu401_opened = 0;
100 }
101
102 static int
103 mpu401_out (int dev, unsigned char midi_byte)
104 {
105 int timeout;
106 unsigned long flags;
107
108
109
110
111
112 DISABLE_INTR (flags);
113
114 if (input_avail ())
115 mpuintr (0);
116
117 RESTORE_INTR (flags);
118
119
120
121
122
123
124 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
125
126 if (!output_ready ())
127 {
128 printk ("MPU-401: Timeout\n");
129 return 0;
130 }
131
132 mpu401_write (midi_byte);
133 return 1;
134 }
135
136 static int
137 mpu401_command (int dev, unsigned char midi_byte)
138 {
139 return 1;
140 }
141
142 static int
143 mpu401_start_read (int dev)
144 {
145 return 0;
146 }
147
148 static int
149 mpu401_end_read (int dev)
150 {
151 return 0;
152 }
153
154 static int
155 mpu401_ioctl (int dev, unsigned cmd, unsigned arg)
156 {
157 return RET_ERROR (EINVAL);
158 }
159
160 static void
161 mpu401_kick (int dev)
162 {
163 }
164
165 static int
166 mpu401_buffer_status (int dev)
167 {
168 return 0;
169 }
170
171 static struct midi_operations mpu401_operations =
172 {
173 {"MPU-401", 0, 0, SNDCARD_MPU401},
174 mpu401_open,
175 mpu401_close,
176 mpu401_ioctl,
177 mpu401_out,
178 mpu401_start_read,
179 mpu401_end_read,
180 mpu401_kick,
181 mpu401_command,
182 mpu401_buffer_status
183 };
184
185
186 long
187 attach_mpu401 (long mem_start, struct address_info *hw_config)
188 {
189 int ok, timeout;
190 unsigned long flags;
191
192 mpu401_base = hw_config->io_base;
193 mpu401_irq = hw_config->irq;
194
195 if (!mpu401_detected)
196 return RET_ERROR (EIO);
197
198 DISABLE_INTR (flags);
199 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
200 mpu401_cmd (UART_MODE_ON);
201
202 ok = 0;
203 for (timeout = 50000; timeout > 0 && !ok; timeout--)
204 if (input_avail ())
205 if (mpu401_read () == MPU_ACK)
206 ok = 1;
207
208 RESTORE_INTR (flags);
209
210 printk (" <Roland MPU-401>");
211
212 my_dev = num_midis;
213 mpu401_dev = num_midis;
214 midi_devs[num_midis++] = &mpu401_operations;
215 return mem_start;
216 }
217
218 static int
219 reset_mpu401 (void)
220 {
221 unsigned long flags;
222 int ok, timeout, n;
223
224
225
226
227
228 ok = 0;
229
230 DISABLE_INTR (flags);
231
232 for (n = 0; n < 2 && !ok; n++)
233 {
234 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
235 mpu401_cmd (MPU_RESET);
236
237
238
239
240
241
242 for (timeout = 50000; timeout > 0 && !ok; timeout--)
243 if (input_avail ())
244 if (mpu401_read () == MPU_ACK)
245 ok = 1;
246
247 }
248
249 mpu401_opened = 0;
250 if (ok)
251 mpuintr (0);
252
253 RESTORE_INTR (flags);
254
255 return ok;
256 }
257
258
259 int
260 probe_mpu401 (struct address_info *hw_config)
261 {
262 int ok = 0;
263
264 mpu401_base = hw_config->io_base;
265 mpu401_irq = hw_config->irq;
266
267 if (snd_set_irq_handler (mpu401_irq, mpuintr) < 0)
268 return 0;
269
270 ok = reset_mpu401 ();
271
272 mpu401_detected = ok;
273 return ok;
274 }
275
276 #endif
277
278 #endif