This source file includes following definitions.
- sb16midi_input_loop
- sb16midiintr
- sb16midi_open
- sb16midi_close
- sb16midi_out
- sb16midi_command
- sb16midi_start_read
- sb16midi_end_read
- sb16midi_ioctl
- sb16midi_kick
- sb16midi_buffer_status
- attach_sb16midi
- reset_sb16midi
- probe_sb16midi
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 #include "sound_config.h"
31
32 #ifdef CONFIGURE_SOUNDCARD
33
34 #if !defined(EXCLUDE_SB) && !defined(EXCLUDE_SB16) && !defined(EXCLUDE_MIDI)
35
36 #define DATAPORT (sb16midi_base)
37 #define COMDPORT (sb16midi_base+1)
38 #define STATPORT (sb16midi_base+1)
39
40 #define sb16midi_status() INB(STATPORT)
41 #define input_avail() (!(sb16midi_status()&INPUT_AVAIL))
42 #define output_ready() (!(sb16midi_status()&OUTPUT_READY))
43 #define sb16midi_cmd(cmd) OUTB(cmd, COMDPORT)
44 #define sb16midi_read() INB(DATAPORT)
45 #define sb16midi_write(byte) OUTB(byte, DATAPORT)
46
47 #define OUTPUT_READY 0x40
48 #define INPUT_AVAIL 0x80
49 #define MPU_ACK 0xFE
50 #define MPU_RESET 0xFF
51 #define UART_MODE_ON 0x3F
52
53 static int sb16midi_opened = 0;
54 static int sb16midi_base = 0x330;
55 static int sb16midi_detected = 0;
56 static int my_dev;
57
58 static int reset_sb16midi (void);
59 static void (*midi_input_intr) (int dev, unsigned char data);
60
61 extern int sbc_major;
62
63 static void
64 sb16midi_input_loop (void)
65 {
66
67 while (input_avail ())
68 {
69 unsigned char c = sb16midi_read ();
70
71 if (sb16midi_opened & OPEN_READ)
72 midi_input_intr (my_dev, c);
73 }
74 }
75
76 void
77 sb16midiintr (int unit)
78 {
79 if (input_avail ())
80 sb16midi_input_loop ();
81 }
82
83 static int
84 sb16midi_open (int dev, int mode,
85 void (*input) (int dev, unsigned char data),
86 void (*output) (int dev)
87 )
88 {
89 if (sb16midi_opened)
90 {
91 return RET_ERROR (EBUSY);
92 }
93
94 sb16midi_input_loop ();
95
96 midi_input_intr = input;
97 sb16midi_opened = mode;
98
99 return 0;
100 }
101
102 static void
103 sb16midi_close (int dev)
104 {
105 sb16midi_opened = 0;
106 }
107
108 static int
109 sb16midi_out (int dev, unsigned char midi_byte)
110 {
111 int timeout;
112 unsigned long flags;
113
114
115
116
117
118 DISABLE_INTR (flags);
119
120 if (input_avail ())
121 sb16midi_input_loop ();
122
123 RESTORE_INTR (flags);
124
125
126
127
128
129
130 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
131
132 if (!output_ready ())
133 {
134 printk ("MPU-401: Timeout\n");
135 return 0;
136 }
137
138 sb16midi_write (midi_byte);
139 return 1;
140 }
141
142 static int
143 sb16midi_command (int dev, unsigned char midi_byte)
144 {
145 return 1;
146 }
147
148 static int
149 sb16midi_start_read (int dev)
150 {
151 return 0;
152 }
153
154 static int
155 sb16midi_end_read (int dev)
156 {
157 return 0;
158 }
159
160 static int
161 sb16midi_ioctl (int dev, unsigned cmd, unsigned arg)
162 {
163 return RET_ERROR (EINVAL);
164 }
165
166 static void
167 sb16midi_kick (int dev)
168 {
169 }
170
171 static int
172 sb16midi_buffer_status (int dev)
173 {
174 return 0;
175 }
176
177 static struct midi_operations sb16midi_operations =
178 {
179 {"SoundBlaster MPU-401", 0, 0, SNDCARD_SB16MIDI},
180 sb16midi_open,
181 sb16midi_close,
182 sb16midi_ioctl,
183 sb16midi_out,
184 sb16midi_start_read,
185 sb16midi_end_read,
186 sb16midi_kick,
187 sb16midi_command,
188 sb16midi_buffer_status
189 };
190
191
192 long
193 attach_sb16midi (long mem_start, struct address_info *hw_config)
194 {
195 int ok, timeout;
196 unsigned long flags;
197
198 sb16midi_base = hw_config->io_base;
199
200 if (!sb16midi_detected)
201 return RET_ERROR (EIO);
202
203 DISABLE_INTR (flags);
204 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
205 sb16midi_cmd (UART_MODE_ON);
206
207 ok = 0;
208 for (timeout = 50000; timeout > 0 && !ok; timeout--)
209 if (input_avail ())
210 if (sb16midi_read () == MPU_ACK)
211 ok = 1;
212
213 RESTORE_INTR (flags);
214
215 printk (" <SoundBlaster MPU-401>");
216
217 my_dev = num_midis;
218 midi_devs[num_midis++] = &sb16midi_operations;
219 return mem_start;
220 }
221
222 static int
223 reset_sb16midi (void)
224 {
225 unsigned long flags;
226 int ok, timeout, n;
227
228
229
230
231
232 ok = 0;
233
234 DISABLE_INTR (flags);
235
236 for (n = 0; n < 2 && !ok; n++)
237 {
238 for (timeout = 30000; timeout < 0 && !output_ready (); timeout--);
239 sb16midi_cmd (MPU_RESET);
240
241
242
243
244
245
246 for (timeout = 50000; timeout > 0 && !ok; timeout--)
247 if (input_avail ())
248 if (sb16midi_read () == MPU_ACK)
249 ok = 1;
250
251 }
252
253 sb16midi_opened = 0;
254 if (ok)
255 sb16midi_input_loop ();
256
257 RESTORE_INTR (flags);
258
259 return ok;
260 }
261
262
263 int
264 probe_sb16midi (struct address_info *hw_config)
265 {
266 int ok = 0;
267
268 sb16midi_base = hw_config->io_base;
269 if (sbc_major < 4)
270 return 0;
271
272 if (sb_get_irq () < 0)
273 return 0;
274
275 ok = reset_sb16midi ();
276
277 sb16midi_detected = ok;
278 return ok;
279 }
280
281 #endif
282
283 #endif