4 * Low level driver for the MediaTriX AudioTriX Pro (MT-0002-PC Control Chip)
6 * Copyright by Hannu Savolainen 1995
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $DragonFly: src/sys/dev/sound/isa/i386/trix/Attic/trix.c,v 1.2 2003/08/07 21:17:13 dillon Exp $
31 #include <i386/isa/sound/sound_config.h>
35 #ifdef INCLUDE_TRIX_BOOT
36 #include "trix_boot.h"
40 extern int sb_no_recording;
43 static int kilroy_was_here = 0; /* Don't detect twice */
44 static int sb_initialized = 0;
46 static sound_os_info *trix_osp = NULL;
51 outb(0x390, (u_char) addr); /* MT-0002-PC ASIC address */
52 return inb(0x391); /* MT-0002-PC ASIC data */
56 trix_write(int addr, int data)
58 outb(0x390, (u_char) addr); /* MT-0002-PC ASIC address */
59 outb(0x391, (u_char) data); /* MT-0002-PC ASIC data */
63 download_boot(int base)
65 #ifdef INCLUDE_TRIX_BOOT
66 int i = 0, n = sizeof(trix_boot);
68 trix_write(0xf8, 0x00); /* ??????? */
69 outb(base + 6, 0x01); /* Clear the internal data pointer */
70 outb(base + 6, 0x00); /* Restart */
73 * Write the boot code to the RAM upload/download register. Each
74 * write increments the internal data pointer.
76 outb(base + 6, 0x01); /* Clear the internal data pointer */
77 outb(0x390, 0x1A); /* Select RAM download/upload port */
79 for (i = 0; i < n; i++)
80 outb(0x391, trix_boot[i]);
81 for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */
83 outb(base + 6, 0x00); /* Reset */
84 outb(0x390, 0x50); /* ?????? */
90 trix_set_wss_port(struct address_info * hw_config)
95 printf("AudioTriX: Config port I/O conflict\n");
98 if (kilroy_was_here) /* Already initialized */
101 if (trix_read(0x15) != 0x71) { /* No asic signature */
102 DDB(printf("No AudioTriX ASIC signature found\n"));
109 * Reset some registers.
116 * Configure the ASIC to place the codec to the proper I/O location
119 switch (hw_config->io_base) {
136 trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits);
141 * Probe and attach routines for the Windows Sound System mode of AudioTriX
146 probe_trix_wss(struct address_info * hw_config)
149 * Check if the IO port returns valid signature. The original MS
150 * Sound system returns 0x04 while some cards (AudioTriX Pro for
151 * example) return 0x00.
155 printf("AudioTriX: MSS I/O port conflict\n");
158 trix_osp = hw_config->osp;
160 if (!trix_set_wss_port(hw_config))
163 if ((inb(hw_config->io_base + 3) & 0x3f) != 0x00) {
164 DDB(printf("No MSS signature detected on port 0x%x\n",
165 hw_config->io_base));
168 if (hw_config->irq > 11) {
169 printf("AudioTriX: Bad WSS IRQ %d\n", hw_config->irq);
172 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3) {
173 printf("AudioTriX: Bad WSS DMA %d\n", hw_config->dma);
176 if (hw_config->dma2 != -1)
177 if (hw_config->dma2 != 0 && hw_config->dma2 != 1 && hw_config->dma2 != 3) {
178 printf("AudioTriX: Bad capture DMA %d\n", hw_config->dma2);
182 * Check that DMA0 is not in use with a 8 bit board.
185 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80) {
186 printf("AudioTriX: Can't use DMA0 with a 8 bit card\n");
189 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80) {
190 printf("AudioTriX: Can't use IRQ%d with a 8 bit card\n", hw_config->irq);
193 return ad1848_detect(hw_config->io_base + 4, NULL, hw_config->osp);
197 attach_trix_wss(struct address_info * hw_config)
199 static u_char interrupt_bits[12] =
200 {-1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20};
203 static u_char dma_bits[4] =
206 int config_port = hw_config->io_base + 0,
207 version_port = hw_config->io_base + 3;
208 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
210 trix_osp = hw_config->osp;
212 if (!kilroy_was_here) {
213 DDB(printf("AudioTriX: Attach called but not probed yet???\n"));
217 * Set the IRQ and DMA addresses.
220 bits = interrupt_bits[hw_config->irq];
222 printf("AudioTriX: Bad IRQ (%d)\n", hw_config->irq);
225 outb(config_port, bits | 0x40);
226 if ((inb(version_port) & 0x40) == 0)
227 printf("[IRQ Conflict?]");
229 if (hw_config->dma2 == -1) { /* Single DMA mode */
230 bits |= dma_bits[dma1];
235 tmp = trix_read(0x13) & ~30;
236 trix_write(0x13, tmp | 0x80 | (dma1 << 4));
238 tmp = trix_read(0x14) & ~30;
239 trix_write(0x14, tmp | 0x80 | (dma2 << 4));
242 outb(config_port, bits);/* Write IRQ+DMA setup */
244 ad1848_init("AudioTriX Pro", hw_config->io_base + 4,
254 probe_trix_sb(struct address_info * hw_config)
258 static char irq_translate[] = {-1, -1, -1, 0, 1, 2, -1, 3};
260 #ifndef INCLUDE_TRIX_BOOT
261 return 0; /* No boot code -> no fun */
263 if (!kilroy_was_here)
264 return 0; /* AudioTriX Pro has not been detected earlier */
269 if ((hw_config->io_base & 0xffffff8f) != 0x200)
272 tmp = hw_config->irq;
275 if (irq_translate[tmp] == -1)
278 tmp = hw_config->dma;
279 if (tmp != 1 && tmp != 3)
282 conf = 0x84; /* DMA and IRQ enable */
283 conf |= hw_config->io_base & 0x70; /* I/O address bits */
284 conf |= irq_translate[hw_config->irq];
285 if (hw_config->dma == 3)
287 trix_write(0x1b, conf);
289 download_boot(hw_config->io_base);
296 attach_trix_sb(struct address_info * hw_config)
299 sb_dsp_disable_midi();
302 conf_printf("AudioTriX (SB)", hw_config);
306 attach_trix_mpu(struct address_info * hw_config)
308 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
309 attach_mpu401(hw_config);
314 probe_trix_mpu(struct address_info * hw_config)
316 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
318 static char irq_bits[] = {-1, -1, -1, 1, 2, 3, -1, 4, -1, 5};
320 if (!kilroy_was_here) {
321 DDB(printf("Trix: WSS and SB modes must be initialized before MPU\n"));
322 return 0; /* AudioTriX Pro has not been detected earlier */
324 if (!sb_initialized) {
325 DDB(printf("Trix: SB mode must be initialized before MPU\n"));
328 if (mpu_initialized) {
329 DDB(printf("Trix: MPU mode already initialized\n"));
332 if (hw_config->irq > 9) {
333 printf("AudioTriX: Bad MPU IRQ %d\n", hw_config->irq);
336 if (irq_bits[hw_config->irq] == -1) {
337 printf("AudioTriX: Bad MPU IRQ %d\n", hw_config->irq);
340 switch (hw_config->io_base) {
354 return 0; /* Invalid port */
357 conf |= irq_bits[hw_config->irq] << 4;
359 trix_write(0x19, (trix_read(0x19) & 0x83) | conf);
363 return probe_mpu401(hw_config);