/* * sound/oss/trix.c * * Low level driver for the MediaTrix AudioTrix Pro * (MT-0002-PC Control Chip) * * * Copyright (C) by Hannu Savolainen 1993-1997 * * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL) * Version 2 (June 1991). See the "COPYING" file distributed with this software * for more info. * * Changes * Alan Cox Modularisation, cleanup. * Christoph Hellwig Adapted to module_init/module_exit * Arnaldo C. de Melo Got rid of attach_uart401 */ #include #include #include "sound_config.h" #include "sb.h" #include "sound_firmware.h" #include "ad1848.h" #include "mpu401.h" #include "trix_boot.h" static int mpu; static bool joystick; static unsigned char trix_read(int addr) { outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */ return inb(0x391); /* MT-0002-PC ASIC data */ } static void trix_write(int addr, int data) { outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */ outb(((unsigned char) data), 0x391); /* MT-0002-PC ASIC data */ } static void download_boot(int base) { int i = 0, n = trix_boot_len; if (trix_boot_len == 0) return; trix_write(0xf8, 0x00); /* ??????? */ outb((0x01), base + 6); /* Clear the internal data pointer */ outb((0x00), base + 6); /* Restart */ /* * Write the boot code to the RAM upload/download register. * Each write increments the internal data pointer. */ outb((0x01), base + 6); /* Clear the internal data pointer */ outb((0x1A), 0x390); /* Select RAM download/upload port */ for (i = 0; i < n; i++) outb((trix_boot[i]), 0x391); for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */ outb((0x00), 0x391); outb((0x00), base + 6); /* Reset */ outb((0x50), 0x390); /* ?????? */ } static int trix_set_wss_port(struct address_info *hw_config) { unsigned char addr_bits; if (trix_read(0x15) != 0x71) /* No ASIC signature */ { MDB(printk(KERN_ERR "No AudioTrix ASIC signature found\n")); return 0; } /* * Reset some registers. */ trix_write(0x13, 0); trix_write(0x14, 0); /* * Configure the ASIC to place the codec to the proper I/O location */ switch (hw_config->io_base) { case 0x530: addr_bits = 0; break; case 0x604: addr_bits = 1; break; case 0xE80: addr_bits = 2; break; case 0xF40: addr_bits = 3; break; default: return 0; } trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits); return 1; } /* * Probe and attach routines for the Windows Sound System mode of * AudioTrix Pro */ static int __init init_trix_wss(struct address_info *hw_config) { static unsigned char dma_bits[4] = { 1, 2, 0, 3 }; struct resource *ports; int config_port = hw_config->io_base + 0; int dma1 = hw_config->dma, dma2 = hw_config->dma2; int old_num_mixers = num_mixers; u8 config, bits; int ret; switch(hw_config->irq) { case 7: bits = 8; break; case 9: bits = 0x10; break; case 10: bits = 0x18; break; case 11: bits = 0x20; break; default: printk(KERN_ERR "AudioTrix: Bad WSS IRQ %d\n", hw_config->irq); return 0; } switch (dma1) { case 0: case 1: case 3: break; default: printk(KERN_ERR "AudioTrix: Bad WSS DMA %d\n", dma1); return 0; } switch (dma2) { case -1: case 0: case 1: case 3: break; default: printk(KERN_ERR "AudioTrix: Bad capture DMA %d\n", dma2); return 0; } /* * Check if the IO port returns valid signature. The original MS Sound * system returns 0x04 while some cards (AudioTrix Pro for example) * return 0x00. */ ports = request_region(hw_config->io_base + 4, 4, "ad1848"); if (!ports) { printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base); return 0; } if (!request_region(hw_config->io_base, 4, "MSS config")) { printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base); release_region(hw_config->io_base + 4, 4); return 0; } if (!trix_set_wss_port(hw_config)) goto fail; config = inb(hw_config->io_base + 3); if ((config & 0x3f) != 0x00) { MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x\n", hw_config->io_base)); goto fail; } /* * Check that DMA0 is not in use with a 8 bit board. */ if (dma1 == 0 && config & 0x80) { printk(KERN_ERR "AudioTrix: Can't use DMA0 with a 8 bit card slot\n"); goto fail; } if (hw_config->irq > 9 && config & 0x80) { printk(KERN_ERR "AudioTrix: Can't use IRQ%d with a 8 bit card slot\n", hw_config->irq); goto fail; } ret = ad1848_detect(ports, NULL, hw_config->osp); if (!ret) goto fail; if (joystick==1) trix_write(0x15, 0x80); /* * Set the IRQ and DMA addresses. */ outb((bits | 0x40), config_port); if (dma2 == -1 || dma2 == dma1) { bits |= dma_bits[dma1]; dma2 = dma1; } else { unsigned char tmp; tmp = trix_read(0x13) & ~30; trix_write(0x13, tmp | 0x80 | (dma1 << 4)); tmp = trix_read(0x14) & ~30; trix_write(0x14, tmp | 0x80 | (dma2 << 4)); } outb((bits), config_port); /* Write IRQ+DMA setup */ hw_config->slots[0] = ad1848_init("AudioTrix Pro", ports, hw_config->irq, dma1, dma2, 0, hw_config->osp, THIS_MODULE); if (num_mixers > old_num_mixers) /* Mixer got installed */ { AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE); /* Line in */ AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD); AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* OPL4 */ AD1848_REROUTE(SOUND_MIXER_SPEAKER, SOUND_MIXER_ALTPCM); /* SB */ } return 1; fail: releas