4 * Initialization code for OPTi MAD16 compatible audio chips. Including
6 * OPTi 82C928 MAD16 (replaced by C929) OAK OTI-601D Mozart
7 * OPTi 82C929 MAD16 Pro
9 * These audio interface chips don't prduce sound themselves. They just connect
10 * some other components (OPL-[234] and a WSS compatible codec) to the PC bus
11 * and perform I/O, DMA and IRQ address decoding. There is also a UART for
12 * the MPU-401 mode (not 82C928/Mozart). The Mozart chip appears to be
13 * compatible with the 82C928 (can anybody confirm this?).
15 * NOTE! If you want to set CD-ROM address and/or joystick enable, define
16 * MAD16_CONF in local.h as combination of the following bits:
18 * 0x01 - joystick disabled
20 * CD-ROM type selection (select just one): 0x00 - none 0x02 - Sony 31A
21 * 0x04 - Mitsumi 0x06 - Panasonic (type "LaserMate", not
22 * "SoundBlaster") 0x08 - Secondary IDE (address 0x170) 0x0a - Primary
25 * For example Mitsumi with joystick disabled = 0x04|0x01 = 0x05 For example
26 * LaserMate (for use with sbpcd) plus joystick = 0x06
28 * MAD16_CDSEL: This defaults to CD I/O 0x340, no IRQ and DMA3 (DMA5 with
29 * Mitsumi or IDE). If you like to change these, define MAD16_CDSEL with the
32 * CD-ROM port: 0x00=340, 0x40=330, 0x80=360 or 0xc0=320 OPL4 select: 0x20=OPL4,
33 * 0x00=OPL3 CD-ROM irq: 0x00=disabled, 0x04=IRQ5, 0x08=IRQ7, 0x0a=IRQ3,
34 * 0x10=IRQ9, 0x14=IRQ10 and 0x18=IRQ11.
36 * CD-ROM DMA (Sony or Panasonic): 0x00=DMA3, 0x01=DMA2, 0x02=DMA1 or
37 * 0x03=disabled or CD-ROM DMA (Mitsumi or IDE): 0x00=DMA5, 0x01=DMA6,
38 * 0x02=DMA7 or 0x03=disabled
40 * For use with sbpcd, address 0x340, set MAD16_CDSEL to 0x03 or 0x23.
42 * Copyright by Hannu Savolainen 1995
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions are
46 * met: 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer. 2.
48 * Redistributions in binary form must reproduce the above copyright notice,
49 * this list of conditions and the following disclaimer in the documentation
50 * and/or other materials provided with the distribution.
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
53 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
56 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
58 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
59 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 #include <i386/isa/sound/sound_config.h>
68 #if defined(CONFIG_MAD16)
70 static int already_initialized = 0;
79 * The MAD16 occupies I/O ports 0xf8d to 0xf93 (fixed locations). All ports are
80 * inactive by default. They can be activated by writing 0xE2 or 0xE3 to the
81 * password register. The password is valid only until the next I/O read or
85 #define MC1_PORT 0xf8d /* SB address, CDROM interface type, joystick */
86 #define MC2_PORT 0xf8e /* CDROM address, IRQ, DMA, plus OPL4 bit */
87 #define MC3_PORT 0xf8f
88 #define PASSWD_REG 0xf8f
89 #define MC4_PORT 0xf90
90 #define MC5_PORT 0xf91
91 #define MC6_PORT 0xf92
92 #define MC7_PORT 0xf93
94 static int board_type = C928;
96 static sound_os_info *mad16_osp;
110 switch (board_type) { /* Output password */
113 outb(PASSWD_REG, 0xE2);
117 outb(PASSWD_REG, 0xE3);
128 mad_write(int port, int value)
134 switch (board_type) { /* Output password */
137 outb(PASSWD_REG, 0xE2);
141 outb(PASSWD_REG, 0xE3);
145 outb(port, (unsigned char) (value & 0xff));
152 unsigned char tmp, tmp2;
155 * Check that reading a register doesn't return bus float (0xff) when
156 * the card is accessed using password. This may fail in case the
157 * card is in low power mode. Normally at least the power saving mode
160 if ((tmp = mad_read(MC1_PORT)) == 0xff) {
161 DDB(printf("MC1_PORT returned 0xff\n"));
165 * Now check that the gate is closed on first I/O after writing the
166 * password. (This is how a MAD16 compatible card works).
169 if ((tmp2 = inb(MC1_PORT)) == tmp) { /* It didn't close */
170 DDB(printf("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
173 mad_write(MC1_PORT, tmp ^ 0x80); /* Togge a bit */
175 if ((tmp2 = mad_read(MC1_PORT)) != (tmp ^ 0x80)) { /* Compare the bit */
176 mad_write(MC1_PORT, tmp); /* Restore */
177 DDB(printf("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
180 mad_write(MC1_PORT, tmp); /* Restore */
181 return 1; /* Bingo */
186 probe_mad16(struct address_info * hw_config)
189 static int valid_ports[] =
190 {0x530, 0xe80, 0xf40, 0x604};
192 unsigned char cs4231_mode = 0;
196 if (already_initialized)
199 mad16_osp = hw_config->osp;
201 * Check that all ports return 0xff (bus float) when no password is
202 * written to the password register.
205 DDB(printf("--- Detecting MAD16 / Mozart ---\n"));
209 * Then try to detect with the old password
213 DDB(printf("Detect using password = 0xE2\n"));
215 if (!detect_mad16()) { /* No luck. Try different model */
218 DDB(printf("Detect using password = 0xE3\n"));
223 DDB(printf("mad16.c: 82C929 detected\n"));
227 if (((model = mad_read(MC3_PORT)) & 0x03) == 0x03) {
228 DDB(printf("mad16.c: Mozart detected\n"));
231 DDB(printf("mad16.c: 82C928 detected???\n"));
236 for (i = 0xf8d; i <= 0xf93; i++)
237 DDB(printf("port %03x = %03x\n", i, mad_read(i)));
240 * Set the WSS address
243 tmp = 0x80; /* Enable WSS, Disable SB */
245 for (i = 0; i < 5; i++) {
246 if (i > 3) { /* Not a valid port */
247 printf("MAD16/Mozart: Bad WSS base address 0x%x\n", hw_config->io_base);
250 if (valid_ports[i] == hw_config->io_base) {
251 tmp |= i << 4; /* WSS port select bits */
257 * Set optional CD-ROM and joystick settings.
261 tmp |= ((MAD16_CONF) & 0x0f); /* CD-ROM and joystick bits */
263 mad_write(MC1_PORT, tmp);
265 #if defined(MAD16_CONF) && defined(MAD16_CDSEL)
272 tmp |= 0x20; /* Enable OPL4 access */
275 mad_write(MC2_PORT, tmp);
276 mad_write(MC3_PORT, 0xf0); /* Disable SB */
278 if (!ad1848_detect(hw_config->io_base + 4, &ad_flags, mad16_osp))
281 if (ad_flags & (AD_F_CS4231 | AD_F_CS4248))
282 cs4231_mode = 0x02; /* CS4248/CS4231 sync delay switch */
284 if (board_type == C929) {
285 mad_write(MC4_PORT, 0xa2);
286 mad_write(MC5_PORT, 0xA5 | cs4231_mode);
287 mad_write(MC6_PORT, 0x03); /* Disable MPU401 */
289 mad_write(MC4_PORT, 0x02);
290 mad_write(MC5_PORT, 0x30 | cs4231_mode);
293 for (i = 0xf8d; i <= 0xf93; i++)
294 DDB(printf("port %03x after init = %03x\n", i, mad_read(i)));
297 * Verify the WSS parameters
301 printf("MSS: I/O port conflict\n");
305 * Check if the IO port returns valid signature. The original MS
306 * Sound system returns 0x04 while some cards (AudioTriX Pro for
307 * example) return 0x00.
310 if ((inb(hw_config->io_base + 3) & 0x3f) != 0x04 &&
311 (inb(hw_config->io_base + 3) & 0x3f) != 0x00) {
312 DDB(printf("No MSS signature detected on port 0x%x (0x%x)\n",
313 hw_config->io_base, inb(hw_config->io_base + 3)));
316 if (hw_config->irq > 11) {
317 printf("MSS: Bad IRQ %d\n", hw_config->irq);
320 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3) {
321 printf("MSS: Bad DMA %d\n", hw_config->dma);
325 * Check that DMA0 is not in use with a 8 bit board.
328 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80) {
329 printf("MSS: Can't use DMA0 with a 8 bit card/slot\n");
332 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80) {
333 printf("MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
340 attach_mad16(struct address_info * hw_config)
343 static char interrupt_bits[12] =
345 -1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20
349 static char dma_bits[4] =
354 int config_port = hw_config->io_base + 0, version_port = hw_config->io_base + 3;
355 int ad_flags = 0, dma = hw_config->dma, dma2 = hw_config->dma2;
356 unsigned char dma2_bit = 0;
358 already_initialized = 1;
360 if (!ad1848_detect(hw_config->io_base + 4, &ad_flags, mad16_osp))
364 * Set the IRQ and DMA addresses.
367 bits = interrupt_bits[hw_config->irq];
371 outb(config_port, bits | 0x40);
372 if ((inb(version_port) & 0x40) == 0)
373 printf("[IRQ Conflict?]");
376 * Handle the capture DMA channel
379 if (ad_flags & AD_F_CS4231 && dma2 != -1 && dma2 != dma) {
380 if ((dma == 0 && dma2 == 1) ||
381 (dma == 1 && dma2 == 0) ||
382 (dma == 3 && dma2 == 0)) {
383 dma2_bit = 0x04; /* Enable capture DMA */
385 printf("MAD16: Invalid capture DMA\n");
391 outb(config_port, bits | dma_bits[dma] | dma2_bit); /* Write IRQ+DMA setup */
393 ad1848_init("MAD16 WSS", hw_config->io_base + 4,
401 attach_mad16_mpu(struct address_info * hw_config)
403 if (board_type < C929) {/* Early chip. No MPU support. Just SB MIDI */
406 if (mad_read(MC1_PORT) & 0x20)
407 hw_config->io_base = 0x240;
409 hw_config->io_base = 0x220;
411 return mad16_sb_dsp_init(hw_config);
416 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
417 if (!already_initialized)
420 attach_mpu401(hw_config);
425 probe_mad16_mpu(struct address_info * hw_config)
427 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
428 static int mpu_attached = 0;
429 static int valid_ports[] =
430 {0x330, 0x320, 0x310, 0x300};
431 static short valid_irqs[] =
435 int i; /* A variable with secret power */
437 if (!already_initialized) /* The MSS port must be initialized
441 if (mpu_attached) /* Don't let them call this twice */
445 if (board_type < C929) {/* Early chip. No MPU support. Just SB MIDI */
450 tmp = mad_read(MC3_PORT);
453 * MAD16 SB base is defined by the WSS base. It cannot be
454 * changed alone. Ignore configured I/O base. Use the active
458 if (mad_read(MC1_PORT) & 0x20)
459 hw_config->io_base = 0x240;
461 hw_config->io_base = 0x220;
463 switch (hw_config->irq) {
465 tmp = (tmp & 0x3f) | 0x80;
471 tmp = (tmp & 0x3f) | 0x40;
474 printf("mad16/Mozart: Invalid MIDI IRQ\n");
478 mad_write(MC3_PORT, tmp | 0x04);
479 return mad16_sb_dsp_detect(hw_config);
484 tmp = 0x83; /* MPU-401 enable */
487 * Set the MPU base bits
490 for (i = 0; i < 5; i++) {
491 if (i > 3) { /* Out of array bounds */
492 printf("MAD16 / Mozart: Invalid MIDI port 0x%x\n", hw_config->io_base);
495 if (valid_ports[i] == hw_config->io_base) {
502 * Set the MPU IRQ bits
505 for (i = 0; i < 5; i++) {
506 if (i > 3) { /* Out of array bounds */
507 printf("MAD16 / Mozart: Invalid MIDI IRQ %d\n", hw_config->irq);
510 if (valid_irqs[i] == hw_config->irq) {
515 mad_write(MC6_PORT, tmp); /* Write MPU401 config */
517 return probe_mpu401(hw_config);
523 /* That's all folks */