This source file includes following definitions.
- mad_read
- mad_write
- detect_mad16
- probe_mad16
- attach_mad16
- attach_mad16_mpu
- probe_mad16_mpu
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 #include "sound_config.h"
69
70 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_MAD16)
71
72 static int already_initialized = 0;
73
74 #define C928 1
75 #define MOZART 2
76 #define C929 3
77
78
79
80
81
82
83
84
85
86
87 #define MC1_PORT 0xf8d
88 #define MC2_PORT 0xf8e
89 #define MC3_PORT 0xf8f
90 #define PASSWD_REG 0xf8f
91 #define MC4_PORT 0xf90
92 #define MC5_PORT 0xf91
93 #define MC6_PORT 0xf92
94 #define MC7_PORT 0xf93
95
96 static int board_type = C928;
97
98 #ifndef DDB
99 #define DDB(x)
100 #endif
101
102 static unsigned char
103 mad_read (int port)
104 {
105 unsigned long flags;
106 unsigned char tmp;
107
108 DISABLE_INTR (flags);
109
110 switch (board_type)
111 {
112 case C928:
113 case MOZART:
114 OUTB (0xE2, PASSWD_REG);
115 break;
116
117 case C929:
118 OUTB (0xE3, PASSWD_REG);
119 break;
120 }
121
122 tmp = INB (port);
123 RESTORE_INTR (flags);
124
125 return tmp;
126 }
127
128 static void
129 mad_write (int port, int value)
130 {
131 unsigned long flags;
132
133 DISABLE_INTR (flags);
134
135 switch (board_type)
136 {
137 case C928:
138 case MOZART:
139 OUTB (0xE2, PASSWD_REG);
140 break;
141
142 case C929:
143 OUTB (0xE3, PASSWD_REG);
144 break;
145 }
146
147 OUTB ((unsigned char) (value & 0xff), port);
148 RESTORE_INTR (flags);
149 }
150
151 static int
152 detect_mad16 (void)
153 {
154 unsigned char tmp, tmp2;
155
156
157
158
159
160
161
162 if ((tmp = mad_read (MC1_PORT)) == 0xff)
163 {
164 DDB (printk ("MC1_PORT returned 0xff\n"));
165 return 0;
166 }
167
168
169
170
171
172 if ((tmp2 = INB (MC1_PORT)) == tmp)
173 {
174 DDB (printk ("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
175 return 0;
176 }
177
178 mad_write (MC1_PORT, tmp ^ 0x80);
179
180 if ((tmp2 = mad_read (MC1_PORT)) != (tmp ^ 0x80))
181 {
182 mad_write (MC1_PORT, tmp);
183 DDB (printk ("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
184 return 0;
185 }
186
187 mad_write (MC1_PORT, tmp);
188 return 1;
189
190 }
191
192 int
193 probe_mad16 (struct address_info *hw_config)
194 {
195 int i;
196 static int valid_ports[] =
197 {0x530, 0xe80, 0xf40, 0x604};
198 unsigned char tmp;
199
200 if (already_initialized)
201 return 0;
202
203
204
205
206
207
208 DDB (printk ("--- Detecting MAD16 / Mozart ---\n"));
209
210 #if 0
211 for (i = 0xf8d; i <= 0xf93; i++)
212 if (INB (i) != 0xff)
213 {
214 DDB (printk ("port 0x%03x != 0xff (0x%02x)\n", i, INB (i)));
215 return 0;
216 }
217 #endif
218
219
220
221
222 board_type = C928;
223
224 DDB (printk ("Detect using password = 0xE2\n"));
225
226 if (!detect_mad16 ())
227 {
228 board_type = C929;
229
230 DDB (printk ("Detect using password = 0xE3\n"));
231
232 if (!detect_mad16 ())
233 return 0;
234
235 printk ("mad16.c: A 82C929 detected???\n");
236 }
237 else
238 printk ("mad16.c: A 82C928 or Mozart detected???\n");
239
240 for (i = 0xf8d; i <= 0xf93; i++)
241 DDB (printk ("port %03x = %03x\n", i, mad_read (i)));
242
243
244
245
246
247 tmp = 0x80;
248
249 for (i = 0; i < 5; i++)
250 {
251 if (i > 3)
252 {
253 printk ("MAD16/Mozart: Bad WSS base address 0x%x\n", hw_config->io_base);
254 return 0;
255 }
256
257 if (valid_ports[i] == hw_config->io_base)
258 {
259 tmp |= i << 4;
260 break;
261 }
262 }
263
264
265
266
267
268 #ifdef MAD16_CONF
269 tmp |= ((MAD16_CONF) & 0x0f);
270 #endif
271 mad_write (MC1_PORT, tmp);
272
273 #if defined(MAD16_CONF) && defined(MAD16_CDSEL)
274 tmp = MAD16_CDSEL;
275 #else
276 tmp = 0x03;
277 #endif
278
279 #ifdef MAD16_OPL4
280 tmp |= 0x20;
281 #endif
282
283 mad_write (MC2_PORT, tmp);
284 mad_write (MC3_PORT, 0xf0);
285
286 if (board_type == C929)
287 {
288 mad_write (MC4_PORT, 0xa2);
289 mad_write (MC5_PORT, 0x95);
290 mad_write (MC6_PORT, 0x03);
291 }
292 else
293 {
294 mad_write (MC4_PORT, 0x02);
295 mad_write (MC5_PORT, 0x10);
296 }
297
298 for (i = 0xf8d; i <= 0xf93; i++)
299 DDB (printk ("port %03x after init = %03x\n", i, mad_read (i)));
300
301 return probe_ms_sound (hw_config);
302 }
303
304 long
305 attach_mad16 (long mem_start, struct address_info *hw_config)
306 {
307
308 already_initialized = 1;
309
310 return attach_ms_sound (mem_start, hw_config);
311 }
312
313 long
314 attach_mad16_mpu (long mem_start, struct address_info *hw_config)
315 {
316
317 #ifdef EXCLUDE_MIDI
318 return mem_start;
319 #else
320 if (!already_initialized)
321 return mem_start;
322
323 return attach_mpu401 (mem_start, hw_config);
324 #endif
325 }
326
327 int
328 probe_mad16_mpu (struct address_info *hw_config)
329 {
330 #ifdef EXCLUDE_MIDI
331 return 0;
332 #else
333 static int mpu_attached = 0;
334 static int valid_ports[] =
335 {0x330, 0x320, 0x310, 0x300};
336 static short valid_irqs[] =
337 {9, 10, 5, 7};
338 unsigned char tmp;
339
340 int i;
341
342 if (!already_initialized)
343 return 0;
344
345 if (mpu_attached)
346 return 0;
347 mpu_attached = 1;
348
349 if (board_type < C929)
350 {
351 printk ("Mozart and OPTi 82C928 based cards don't support MPU401. Sorry\n");
352 return 0;
353 }
354
355 tmp = 0x80;
356
357
358
359
360
361 for (i = 0; i < 5; i++)
362 {
363 if (i > 3)
364 {
365 printk ("MAD16 / Mozart: Invalid MIDI port 0x%x\n", hw_config->io_base);
366 return 0;
367 }
368
369 if (valid_ports[i] == hw_config->io_base)
370 {
371 tmp |= i << 5;
372 break;
373 }
374 }
375
376
377
378
379
380 for (i = 0; i < 5; i++)
381 {
382 if (i > 3)
383 {
384 printk ("MAD16 / Mozart: Invalid MIDI IRQ %d\n", hw_config->irq);
385 return 0;
386 }
387
388 if (valid_irqs[i] == hw_config->irq)
389 {
390 tmp |= i << 3;
391 break;
392 }
393
394 tmp |= 0x03;
395 mad_write (MC6_PORT, tmp);
396 }
397
398 return probe_mpu401 (hw_config);
399 #endif
400 }
401
402
403 #endif