[PATCH] x86-64 - new memory map handling
[linux-2.6/history.git] / sound / oss / mad16.c
bloba4abef8fad70227588db505a969a909701a7db67
1 /*
2 * Copyright (C) by Hannu Savolainen 1993-1997
4 * mad16.c
6 * Initialization code for OPTi MAD16 compatible audio chips. Including
8 * OPTi 82C928 MAD16 (replaced by C929)
9 * OAK OTI-601D Mozart
10 * OAK OTI-605 Mozart (later version with MPU401 Midi)
11 * OPTi 82C929 MAD16 Pro
12 * OPTi 82C930
13 * OPTi 82C924
15 * These audio interface chips don't produce sound themselves. They just
16 * connect some other components (OPL-[234] and a WSS compatible codec)
17 * to the PC bus and perform I/O, DMA and IRQ address decoding. There is
18 * also a UART for the MPU-401 mode (not 82C928/Mozart).
19 * The Mozart chip appears to be compatible with the 82C928, although later
20 * issues of the card, using the OTI-605 chip, have an MPU-401 compatable Midi
21 * port. This port is configured differently to that of the OPTi audio chips.
23 * Changes
25 * Alan Cox Clean up, added module selections.
27 * A. Wik Added support for Opti924 PnP.
28 * Improved debugging support. 16-May-1998
29 * Fixed bug. 16-Jun-1998
31 * Torsten Duwe Made Opti924 PnP support non-destructive
32 * 23-Dec-1998
34 * Paul Grayson Added support for Midi on later Mozart cards.
35 * 25-Nov-1999
36 * Christoph Hellwig Adapted to module_init/module_exit.
37 * Arnaldo C. de Melo got rid of attach_uart401 21-Sep-2000
39 * Pavel Rabel Clean up Nov-2000
42 #include <linux/config.h>
43 #include <linux/init.h>
44 #include <linux/module.h>
45 #include <linux/gameport.h>
46 #include <linux/spinlock.h>
47 #include "sound_config.h"
49 #include "ad1848.h"
50 #include "sb.h"
51 #include "mpu401.h"
53 static int mad16_conf;
54 static int mad16_cdsel;
55 static struct gameport gameport;
56 static spinlock_t lock=SPIN_LOCK_UNLOCKED;
57 static int already_initialized = 0;
59 #define C928 1
60 #define MOZART 2
61 #define C929 3
62 #define C930 4
63 #define C924 5
66 * Registers
68 * The MAD16 occupies I/O ports 0xf8d to 0xf93 (fixed locations).
69 * All ports are inactive by default. They can be activated by
70 * writing 0xE2 or 0xE3 to the password register. The password is valid
71 * only until the next I/O read or write.
73 * 82C930 uses 0xE4 as the password and indirect addressing to access
74 * the config registers.
77 #define MC0_PORT 0xf8c /* Dummy port */
78 #define MC1_PORT 0xf8d /* SB address, CD-ROM interface type, joystick */
79 #define MC2_PORT 0xf8e /* CD-ROM address, IRQ, DMA, plus OPL4 bit */
80 #define MC3_PORT 0xf8f
81 #define PASSWD_REG 0xf8f
82 #define MC4_PORT 0xf90
83 #define MC5_PORT 0xf91
84 #define MC6_PORT 0xf92
85 #define MC7_PORT 0xf93
86 #define MC8_PORT 0xf94
87 #define MC9_PORT 0xf95
88 #define MC10_PORT 0xf96
89 #define MC11_PORT 0xf97
90 #define MC12_PORT 0xf98
92 static int board_type = C928;
94 static int *mad16_osp;
95 static int c931_detected; /* minor differences from C930 */
96 static char c924pnp = 0; /* " " " C924 */
97 static int debug = 0; /* debugging output */
99 #ifdef DDB
100 #undef DDB
101 #endif
102 #define DDB(x) {if (debug) x;}
104 static unsigned char mad_read(int port)
106 unsigned long flags;
107 unsigned char tmp;
109 spin_lock_irqsave(&lock,flags);
111 switch (board_type) /* Output password */
113 case C928:
114 case MOZART:
115 outb((0xE2), PASSWD_REG);
116 break;
118 case C929:
119 outb((0xE3), PASSWD_REG);
120 break;
122 case C930:
123 /* outb(( 0xE4), PASSWD_REG); */
124 break;
126 case C924:
127 /* the c924 has its ports relocated by -128 if
128 PnP is enabled -aw */
129 if (!c924pnp)
130 outb((0xE5), PASSWD_REG); else
131 outb((0xE5), PASSWD_REG - 0x80);
132 break;
135 if (board_type == C930)
137 outb((port - MC0_PORT), 0xe0e); /* Write to index reg */
138 tmp = inb(0xe0f); /* Read from data reg */
140 else
141 if (!c924pnp)
142 tmp = inb(port); else
143 tmp = inb(port-0x80);
144 spin_unlock_irqrestore(&lock,flags);
146 return tmp;
149 static void mad_write(int port, int value)
151 unsigned long flags;
153 spin_lock_irqsave(&lock,flags);
155 switch (board_type) /* Output password */
157 case C928:
158 case MOZART:
159 outb((0xE2), PASSWD_REG);
160 break;
162 case C929:
163 outb((0xE3), PASSWD_REG);
164 break;
166 case C930:
167 /* outb(( 0xE4), PASSWD_REG); */
168 break;
170 case C924:
171 if (!c924pnp)
172 outb((0xE5), PASSWD_REG); else
173 outb((0xE5), PASSWD_REG - 0x80);
174 break;
177 if (board_type == C930)
179 outb((port - MC0_PORT), 0xe0e); /* Write to index reg */
180 outb(((unsigned char) (value & 0xff)), 0xe0f);
182 else
183 if (!c924pnp)
184 outb(((unsigned char) (value & 0xff)), port); else
185 outb(((unsigned char) (value & 0xff)), port-0x80);
186 spin_unlock_irqrestore(&lock,flags);
189 static int __init detect_c930(void)
191 unsigned char tmp = mad_read(MC1_PORT);
193 if ((tmp & 0x06) != 0x06)
195 DDB(printk("Wrong C930 signature (%x)\n", tmp));
196 /* return 0; */
198 mad_write(MC1_PORT, 0);
200 if (mad_read(MC1_PORT) != 0x06)
202 DDB(printk("Wrong C930 signature2 (%x)\n", tmp));
203 /* return 0; */
205 mad_write(MC1_PORT, tmp); /* Restore bits */
207 mad_write(MC7_PORT, 0);
208 if ((tmp = mad_read(MC7_PORT)) != 0)
210 DDB(printk("MC7 not writable (%x)\n", tmp));
211 return 0;
213 mad_write(MC7_PORT, 0xcb);
214 if ((tmp = mad_read(MC7_PORT)) != 0xcb)
216 DDB(printk("MC7 not writable2 (%x)\n", tmp));
217 return 0;
220 tmp = mad_read(MC0_PORT+18);
221 if (tmp == 0xff || tmp == 0x00)
222 return 1;
223 /* We probably have a C931 */
224 DDB(printk("Detected C931 config=0x%02x\n", tmp));
225 c931_detected = 1;
228 * We cannot configure the chip if it is in PnP mode.
229 * If we have a CSN assigned (bit 8 in MC13) we first try
230 * a software reset, then a software power off, finally
231 * Clearing PnP mode. The last option is not
232 * Bit 8 in MC13
234 if ((mad_read(MC0_PORT+13) & 0x80) == 0)
235 return 1;
237 /* Software reset */
238 mad_write(MC9_PORT, 0x02);
239 mad_write(MC9_PORT, 0x00);
241 if ((mad_read(MC0_PORT+13) & 0x80) == 0)
242 return 1;
244 /* Power off, and on again */
245 mad_write(MC9_PORT, 0xc2);
246 mad_write(MC9_PORT, 0xc0);
248 if ((mad_read(MC0_PORT+13) & 0x80) == 0)
249 return 1;
251 #if 0
252 /* Force off PnP mode. This is not recommended because
253 * the PnP bios will not recognize the chip on the next
254 * warm boot and may assignd different resources to other
255 * PnP/PCI cards.
257 mad_write(MC0_PORT+17, 0x04);
258 #endif
259 return 1;
262 static int __init detect_mad16(void)
264 unsigned char tmp, tmp2, bit;
265 int i, port;
268 * Check that reading a register doesn't return bus float (0xff)
269 * when the card is accessed using password. This may fail in case
270 * the card is in low power mode. Normally at least the power saving
271 * mode bit should be 0.
274 if ((tmp = mad_read(MC1_PORT)) == 0xff)
276 DDB(printk("MC1_PORT returned 0xff\n"));
277 return 0;
279 for (i = 0xf8d; i <= 0xf98; i++)
280 if (!c924pnp)
281 DDB(printk("Port %0x (init value) = %0x\n", i, mad_read(i))) else
282 DDB(printk("Port %0x (init value) = %0x\n", i-0x80, mad_read(i)));
284 if (board_type == C930)
285 return detect_c930();
288 * Now check that the gate is closed on first I/O after writing
289 * the password. (This is how a MAD16 compatible card works).
292 if ((tmp2 = inb(MC1_PORT)) == tmp) /* It didn't close */
294 DDB(printk("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
295 return 0;
298 bit = (c924pnp) ? 0x20 : 0x80;
299 port = (c924pnp) ? MC2_PORT : MC1_PORT;
301 tmp = mad_read(port);
302 mad_write(port, tmp ^ bit); /* Toggle a bit */
303 if ((tmp2 = mad_read(port)) != (tmp ^ bit)) /* Compare the bit */
305 mad_write(port, tmp); /* Restore */
306 DDB(printk("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
307 return 0;
309 mad_write(port, tmp); /* Restore */
310 return 1; /* Bingo */
313 static int __init wss_init(struct address_info *hw_config)
315 int ad_flags = 0;
318 * Verify the WSS parameters
321 if (check_region(hw_config->io_base, 8))
323 printk(KERN_ERR "MSS: I/O port conflict\n");
324 return 0;
326 if (!ad1848_detect(hw_config->io_base + 4, &ad_flags, mad16_osp))
327 return 0;
329 * Check if the IO port returns valid signature. The original MS Sound
330 * system returns 0x04 while some cards (AudioTrix Pro for example)
331 * return 0x00.
334 if ((inb(hw_config->io_base + 3) & 0x3f) != 0x04 &&
335 (inb(hw_config->io_base + 3) & 0x3f) != 0x00)
337 DDB(printk("No MSS signature detected on port 0x%x (0x%x)\n", hw_config->io_base, inb(hw_config->io_base + 3)));
338 return 0;
340 if (hw_config->irq > 11)
342 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
343 return 0;
345 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3)
347 printk(KERN_ERR "MSS: Bad DMA %d\n", hw_config->dma);
348 return 0;
351 * Check that DMA0 is not in use with a 8 bit board.
354 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80)
356 printk("MSS: Can't use DMA0 with a 8 bit card/slot\n");
357 return 0;
359 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80)
360 printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
361 return 1;
364 static int __init init_c930(struct address_info *hw_config)
366 unsigned char cfg = 0;
368 if(c931_detected)
370 /* Bit 0 has reversd meaning. Bits 1 and 2 sese
371 reversed on write.
372 Support only IDE cdrom. IDE port programmed
373 somewhere else. */
374 cfg = (cfg & 0x09) ^ 0x07;
377 switch (hw_config->io_base)
379 case 0x530:
380 cfg |= 0x00;
381 break;
382 case 0xe80:
383 cfg |= 0x10;
384 break;
385 case 0xf40:
386 cfg |= 0x20;
387 break;
388 case 0x604:
389 cfg |= 0x30;
390 break;
391 default:
392 printk(KERN_ERR "MAD16: Invalid codec port %x\n", hw_config->io_base);
393 return 0;
395 mad_write(MC1_PORT, cfg);
397 /* MC2 is CD configuration. Don't touch it. */
399 mad_write(MC3_PORT, 0); /* Disable SB mode IRQ and DMA */
401 /* bit 2 of MC4 reverses it's meaning between the C930
402 and the C931. */
403 cfg = c931_detected ? 0x04 : 0x00;
405 mad_write(MC4_PORT, 0x52|cfg);
407 mad_write(MC5_PORT, 0x3C); /* Init it into mode2 */
408 mad_write(MC6_PORT, 0x02); /* Enable WSS, Disable MPU and SB */
409 mad_write(MC7_PORT, 0xCB);
410 mad_write(MC10_PORT, 0x11);
412 return wss_init(hw_config);
415 static int __init chip_detect(void)
417 int i;
420 * Then try to detect with the old password
422 board_type = C924;
424 DDB(printk("Detect using password = 0xE5\n"));
426 if (detect_mad16()) {
427 return 1;
430 board_type = C928;
432 DDB(printk("Detect using password = 0xE2\n"));
434 if (detect_mad16())
436 unsigned char model;
438 if (((model = mad_read(MC3_PORT)) & 0x03) == 0x03) {
439 DDB(printk("mad16.c: Mozart detected\n"));
440 board_type = MOZART;
441 } else {
442 DDB(printk("mad16.c: 82C928 detected???\n"));
443 board_type = C928;
445 return 1;
448 board_type = C929;
450 DDB(printk("Detect using password = 0xE3\n"));
452 if (detect_mad16())
454 DDB(printk("mad16.c: 82C929 detected\n"));
455 return 1;
458 if (inb(PASSWD_REG) != 0xff)
459 return 0;
462 * First relocate MC# registers to 0xe0e/0xe0f, disable password
465 outb((0xE4), PASSWD_REG);
466 outb((0x80), PASSWD_REG);
468 board_type = C930;
470 DDB(printk("Detect using password = 0xE4\n"));
472 for (i = 0xf8d; i <= 0xf93; i++)
473 DDB(printk("port %03x = %02x\n", i, mad_read(i)));
475 if(detect_mad16()) {
476 DDB(printk("mad16.c: 82C930 detected\n"));
477 return 1;
480 /* The C931 has the password reg at F8D */
481 outb((0xE4), 0xF8D);
482 outb((0x80), 0xF8D);
483 DDB(printk("Detect using password = 0xE4 for C931\n"));
485 if (detect_mad16()) {
486 return 1;
489 board_type = C924;
490 c924pnp++;
491 DDB(printk("Detect using password = 0xE5 (again), port offset -0x80\n"));
492 if (detect_mad16()) {
493 DDB(printk("mad16.c: 82C924 PnP detected\n"));
494 return 1;
497 c924pnp=0;
499 return 0;
502 static int __init probe_mad16(struct address_info *hw_config)
504 int i;
505 static int valid_ports[] =
507 0x530, 0xe80, 0xf40, 0x604
509 unsigned char tmp;
510 unsigned char cs4231_mode = 0;
512 int ad_flags = 0;
514 if (already_initialized)
515 return 0;
517 mad16_osp = hw_config->osp;
520 * Check that all ports return 0xff (bus float) when no password
521 * is written to the password register.
524 DDB(printk("--- Detecting MAD16 / Mozart ---\n"));
525 if (!chip_detect())
526 return 0;
528 if (board_type == C930)
529 return init_c930(hw_config);
532 for (i = 0xf8d; i <= 0xf93; i++)
533 if (!c924pnp)
534 DDB(printk("port %03x = %02x\n", i, mad_read(i))) else
535 DDB(printk("port %03x = %02x\n", i-0x80, mad_read(i)));
538 * Set the WSS address
541 tmp = (mad_read(MC1_PORT) & 0x0f) | 0x80; /* Enable WSS, Disable SB */
543 for (i = 0; i < 5; i++)
545 if (i > 3) /* Not a valid port */
547 printk(KERN_ERR "MAD16/Mozart: Bad WSS base address 0x%x\n", hw_config->io_base);
548 return 0;
550 if (valid_ports[i] == hw_config->io_base)
552 tmp |= i << 4; /* WSS port select bits */
553 break;
558 * Set optional CD-ROM and joystick settings.
561 tmp &= ~0x0f;
562 mad_write(MC1_PORT, tmp);
564 tmp = mad_read(MC2_PORT);
566 mad_write(MC2_PORT, tmp);
567 mad_write(MC3_PORT, 0xf0); /* Disable SB */
569 if (board_type == C924) /* Specific C924 init values */
571 mad_write(MC4_PORT, 0xA0);
572 mad_write(MC5_PORT, 0x05);
573 mad_write(MC6_PORT, 0x03);
575 if (!ad1848_detect(hw_config->io_base + 4, &ad_flags, mad16_osp))
576 return 0;
578 if (ad_flags & (AD_F_CS4231 | AD_F_CS4248))
579 cs4231_mode = 0x02; /* CS4248/CS4231 sync delay switch */
581 if (board_type == C929)
583 mad_write(MC4_PORT, 0xa2);
584 mad_write(MC5_PORT, 0xA5 | cs4231_mode);
585 mad_write(MC6_PORT, 0x03); /* Disable MPU401 */
587 else
589 mad_write(MC4_PORT, 0x02);
590 mad_write(MC5_PORT, 0x30 | cs4231_mode);
593 for (i = 0xf8d; i <= 0xf93; i++) if (!c924pnp)
594 DDB(printk("port %03x after init = %02x\n", i, mad_read(i))) else
595 DDB(printk("port %03x after init = %02x\n", i-0x80, mad_read(i)));
596 wss_init(hw_config);
598 return 1;
601 static void __init attach_mad16(struct address_info *hw_config)
604 static signed char interrupt_bits[12] = {
605 -1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20
607 signed char bits;
609 static char dma_bits[4] = {
610 1, 2, 0, 3
613 int config_port = hw_config->io_base + 0, version_port = hw_config->io_base + 3;
614 int ad_flags = 0, dma = hw_config->dma, dma2 = hw_config->dma2;
615 unsigned char dma2_bit = 0;
617 already_initialized = 1;
619 if (!ad1848_detect(hw_config->io_base + 4, &ad_flags, mad16_osp))
620 return;
623 * Set the IRQ and DMA addresses.
626 if (board_type == C930 || c924pnp)
627 interrupt_bits[5] = 0x28; /* Also IRQ5 is possible on C930 */
629 bits = interrupt_bits[hw_config->irq];
630 if (bits == -1)
631 return;
633 outb((bits | 0x40), config_port);
634 if ((inb(version_port) & 0x40) == 0)
635 printk(KERN_ERR "[IRQ Conflict?]\n");
638 * Handle the capture DMA channel
641 if (ad_flags & AD_F_CS4231 && dma2 != -1 && dma2 != dma)
643 if (!((dma == 0 && dma2 == 1) ||
644 (dma == 1 && dma2 == 0) ||
645 (dma == 3 && dma2 == 0)))
646 { /* Unsupported combination. Try to swap channels */
647 int tmp = dma;
649 dma = dma2;
650 dma2 = tmp;
652 if ((dma == 0 && dma2 == 1) || (dma == 1 && dma2 == 0) ||
653 (dma == 3 && dma2 == 0))
655 dma2_bit = 0x04; /* Enable capture DMA */
657 else
659 printk("MAD16: Invalid capture DMA\n");
660 dma2 = dma;
663 else dma2 = dma;
665 outb((bits | dma_bits[dma] | dma2_bit), config_port); /* Write IRQ+DMA setup */
667 hw_config->slots[0] = ad1848_init("mad16 WSS", hw_config->io_base + 4,
668 hw_config->irq,
669 dma,
670 dma2, 0,
671 hw_config->osp,
672 THIS_MODULE);
673 request_region(hw_config->io_base, 4, "mad16 WSS config");
676 static int __init probe_mad16_mpu(struct address_info *hw_config)
678 static int mpu_attached = 0;
679 unsigned char tmp;
681 if (!already_initialized) /* The MSS port must be initialized first */
682 return 0;
684 if (mpu_attached) /* Don't let them call this twice */
685 return 0;
686 mpu_attached = 1;
688 if (board_type < C929) /* Early chip. No MPU support. Just SB MIDI */
691 #ifdef CONFIG_MAD16_OLDCARD
693 tmp = mad_read(MC3_PORT);
696 * MAD16 SB base is defined by the WSS base. It cannot be changed
697 * alone.
698 * Ignore configured I/O base. Use the active setting.
701 if (mad_read(MC1_PORT) & 0x20)
702 hw_config->io_base = 0x240;
703 else
704 hw_config->io_base = 0x220;
706 switch (hw_config->irq)
708 case 5:
709 tmp = (tmp & 0x3f) | 0x80;
710 break;
711 case 7:
712 tmp = (tmp & 0x3f);
713 break;
714 case 11:
715 tmp = (tmp & 0x3f) | 0x40;
716 break;
717 default:
718 printk(KERN_ERR "mad16/Mozart: Invalid MIDI IRQ\n");
719 return 0;
722 mad_write(MC3_PORT, tmp | 0x04);
723 hw_config->driver_use_1 = SB_MIDI_ONLY;
724 if (!sb_dsp_detect(hw_config, 0, 0, NULL))
725 return 0;
727 if (mad_read(MC1_PORT) & 0x20)
728 hw_config->io_base = 0x240;
729 else
730 hw_config->io_base = 0x220;
732 hw_config->name = "Mad16/Mozart";
733 sb_dsp_init(hw_config, THIS_MODULE);
734 return 1;
735 #else
736 /* assuming all later Mozart cards are identified as
737 * either 82C928 or Mozart. If so, following code attempts
738 * to set MPU register. TODO - add probing
741 tmp = mad_read(MC8_PORT);
743 switch (hw_config->irq)
745 case 5:
746 tmp |= 0x08;
747 break;
748 case 7:
749 tmp |= 0x10;
750 break;
751 case 9:
752 tmp |= 0x18;
753 break;
754 case 10:
755 tmp |= 0x20;
756 break;
757 case 11:
758 tmp |= 0x28;
759 break;
760 default:
761 printk(KERN_ERR "mad16/MOZART: invalid mpu_irq\n");
762 return 0;
765 switch (hw_config->io_base)
767 case 0x300:
768 tmp |= 0x01;
769 break;
770 case 0x310:
771 tmp |= 0x03;
772 break;
773 case 0x320:
774 tmp |= 0x05;
775 break;
776 case 0x330:
777 tmp |= 0x07;
778 break;
779 default:
780 printk(KERN_ERR "mad16/MOZART: invalid mpu_io\n");
781 return 0;
784 mad_write(MC8_PORT, tmp); /* write MPU port parameters */
785 goto probe_401;
786 #endif
788 tmp = mad_read(MC6_PORT) & 0x83;
789 tmp |= 0x80; /* MPU-401 enable */
791 /* Set the MPU base bits */
793 switch (hw_config->io_base)
795 case 0x300:
796 tmp |= 0x60;
797 break;
798 case 0x310:
799 tmp |= 0x40;
800 break;
801 case 0x320:
802 tmp |= 0x20;
803 break;
804 case 0x330:
805 tmp |= 0x00;
806 break;
807 default:
808 printk(KERN_ERR "MAD16: Invalid MIDI port 0x%x\n", hw_config->io_base);
809 return 0;
812 /* Set the MPU IRQ bits */
814 switch (hw_config->irq)
816 case 5:
817 tmp |= 0x10;
818 break;
819 case 7:
820 tmp |= 0x18;
821 break;
822 case 9:
823 tmp |= 0x00;
824 break;
825 case 10:
826 tmp |= 0x08;
827 break;
828 default:
829 printk(KERN_ERR "MAD16: Invalid MIDI IRQ %d\n", hw_config->irq);
830 break;
833 mad_write(MC6_PORT, tmp); /* Write MPU401 config */
835 #ifndef CONFIG_MAD16_OLDCARD
836 probe_401:
837 #endif
838 hw_config->driver_use_1 = SB_MIDI_ONLY;
839 hw_config->name = "Mad16/Mozart";
840 return probe_uart401(hw_config, THIS_MODULE);
843 static void __exit unload_mad16(struct address_info *hw_config)
845 ad1848_unload(hw_config->io_base + 4,
846 hw_config->irq,
847 hw_config->dma,
848 hw_config->dma2, 0);
849 release_region(hw_config->io_base, 4);
850 sound_unload_audiodev(hw_config->slots[0]);
853 static void __exit unload_mad16_mpu(struct address_info *hw_config)
855 #ifdef CONFIG_MAD16_OLDCARD
856 if (board_type < C929) /* Early chip. No MPU support. Just SB MIDI */
858 sb_dsp_unload(hw_config, 0);
859 return;
861 #endif
863 unload_uart401(hw_config);
866 static struct address_info cfg;
867 static struct address_info cfg_mpu;
869 static int found_mpu;
871 static int __initdata mpu_io = 0;
872 static int __initdata mpu_irq = 0;
873 static int __initdata io = -1;
874 static int __initdata dma = -1;
875 static int __initdata dma16 = -1; /* Set this for modules that need it */
876 static int __initdata irq = -1;
877 static int __initdata cdtype = 0;
878 static int __initdata cdirq = 0;
879 static int __initdata cdport = 0x340;
880 static int __initdata cddma = -1;
881 static int __initdata opl4 = 0;
882 static int __initdata joystick = 1;
884 MODULE_PARM(mpu_io, "i");
885 MODULE_PARM(mpu_irq, "i");
886 MODULE_PARM(io,"i");
887 MODULE_PARM(dma,"i");
888 MODULE_PARM(dma16,"i");
889 MODULE_PARM(irq,"i");
890 MODULE_PARM(cdtype,"i");
891 MODULE_PARM(cdirq,"i");
892 MODULE_PARM(cdport,"i");
893 MODULE_PARM(cddma,"i");
894 MODULE_PARM(opl4,"i");
895 MODULE_PARM(joystick,"i");
896 MODULE_PARM(debug,"i");
898 static int __initdata dma_map[2][8] =
900 {0x03, -1, -1, -1, -1, 0x00, 0x01, 0x02},
901 {0x03, -1, 0x01, 0x00, -1, -1, -1, -1}
904 static int __initdata irq_map[16] =
906 0x00, -1, -1, 0x0A,
907 -1, 0x04, -1, 0x08,
908 -1, 0x10, 0x14, 0x18,
909 -1, -1, -1, -1
912 static int __init init_mad16(void)
914 int dmatype = 0;
916 printk(KERN_INFO "MAD16 audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
918 printk(KERN_INFO "CDROM ");
919 switch (cdtype)
921 case 0x00:
922 printk("Disabled");
923 cdirq = 0;
924 break;
925 case 0x02:
926 printk("Sony CDU31A");
927 dmatype = 1;
928 if(cddma == -1) cddma = 3;
929 break;
930 case 0x04:
931 printk("Mitsumi");
932 dmatype = 0;
933 if(cddma == -1) cddma = 5;
934 break;
935 case 0x06:
936 printk("Panasonic Lasermate");
937 dmatype = 1;
938 if(cddma == -1) cddma = 3;
939 break;
940 case 0x08:
941 printk("Secondary IDE");
942 dmatype = 0;
943 if(cddma == -1) cddma = 5;
944 break;
945 case 0x0A:
946 printk("Primary IDE");
947 dmatype = 0;
948 if(cddma == -1) cddma = 5;
949 break;
950 default:
951 printk("\n");
952 printk(KERN_ERR "Invalid CDROM type\n");
953 return -EINVAL;
957 * Build the config words
960 mad16_conf = (joystick ^ 1) | cdtype;
961 mad16_cdsel = 0;
962 if (opl4)
963 mad16_cdsel |= 0x20;
965 if(cdtype){
966 if (cddma > 7 || cddma < 0 || dma_map[dmatype][cddma] == -1)
968 printk("\n");
969 printk(KERN_ERR "Invalid CDROM DMA\n");
970 return -EINVAL;
972 if (cddma)
973 printk(", DMA %d", cddma);
974 else
975 printk(", no DMA");
977 if (!cdirq)
978 printk(", no IRQ");
979 else if (cdirq < 0 || cdirq > 15 || irq_map[cdirq] == -1)
981 printk(", invalid IRQ (disabling)");
982 cdirq = 0;
984 else printk(", IRQ %d", cdirq);
986 mad16_cdsel |= dma_map[dmatype][cddma];
988 if (cdtype < 0x08)
990 switch (cdport)
992 case 0x340:
993 mad16_cdsel |= 0x00;
994 break;
995 case 0x330:
996 mad16_cdsel |= 0x40;
997 break;
998 case 0x360:
999 mad16_cdsel |= 0x80;
1000 break;
1001 case 0x320:
1002 mad16_cdsel |= 0xC0;
1003 break;
1004 default:
1005 printk(KERN_ERR "Unknown CDROM I/O base %d\n", cdport);
1006 return -EINVAL;
1009 mad16_cdsel |= irq_map[cdirq];
1012 printk(".\n");
1014 cfg.io_base = io;
1015 cfg.irq = irq;
1016 cfg.dma = dma;
1017 cfg.dma2 = dma16;
1019 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
1020 printk(KERN_ERR "I/O, DMA and irq are mandatory\n");
1021 return -EINVAL;
1024 if (!probe_mad16(&cfg))
1025 return -ENODEV;
1027 cfg_mpu.io_base = mpu_io;
1028 cfg_mpu.irq = mpu_irq;
1030 attach_mad16(&cfg);
1032 found_mpu = probe_mad16_mpu(&cfg_mpu);
1034 if (joystick == 1) {
1035 /* register gameport */
1036 if (!request_region(0x201, 1, "mad16 gameport"))
1037 printk(KERN_ERR "mad16: gameport address 0x201 already in use\n");
1038 else {
1039 printk(KERN_ERR "mad16: gameport enabled at 0x201\n");
1040 gameport.io = 0x201;
1041 gameport_register_port(&gameport);
1044 else printk(KERN_ERR "mad16: gameport disabled.\n");
1045 return 0;
1048 static void __exit cleanup_mad16(void)
1050 if (found_mpu)
1051 unload_mad16_mpu(&cfg_mpu);
1052 unload_mad16(&cfg);
1055 module_init(init_mad16);
1056 module_exit(cleanup_mad16);
1058 #ifndef MODULE
1059 static int __init setup_mad16(char *str)
1061 /* io, irq */
1062 int ints[8];
1064 str = get_options(str, ARRAY_SIZE(ints), ints);
1066 io = ints[1];
1067 irq = ints[2];
1068 dma = ints[3];
1069 dma16 = ints[4];
1070 mpu_io = ints[5];
1071 mpu_irq = ints[6];
1072 joystick = ints[7];
1074 return 1;
1077 __setup("mad16=", setup_mad16);
1078 #endif
1079 MODULE_LICENSE("GPL");