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
30 #include <i386/isa/sound/sound_config.h>
34 #ifdef INCLUDE_TRIX_BOOT
35 #include <i386/isa/sound/trix_boot.h>
39 extern int sb_no_recording;
42 static int kilroy_was_here = 0; /* Don't detect twice */
43 static int sb_initialized = 0;
45 static sound_os_info *trix_osp = NULL;
50 outb(0x390, (u_char) addr); /* MT-0002-PC ASIC address */
51 return inb(0x391); /* MT-0002-PC ASIC data */
55 trix_write(int addr, int data)
57 outb(0x390, (u_char) addr); /* MT-0002-PC ASIC address */
58 outb(0x391, (u_char) data); /* MT-0002-PC ASIC data */
62 download_boot(int base)
64 #ifdef INCLUDE_TRIX_BOOT
65 int i = 0, n = sizeof(trix_boot);
67 trix_write(0xf8, 0x00); /* ??????? */
68 outb(base + 6, 0x01); /* Clear the internal data pointer */
69 outb(base + 6, 0x00); /* Restart */
72 * Write the boot code to the RAM upload/download register. Each
73 * write increments the internal data pointer.
75 outb(base + 6, 0x01); /* Clear the internal data pointer */
76 outb(0x390, 0x1A); /* Select RAM download/upload port */
78 for (i = 0; i < n; i++)
79 outb(0x391, trix_boot[i]);
80 for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */
82 outb(base + 6, 0x00); /* Reset */
83 outb(0x390, 0x50); /* ?????? */
89 trix_set_wss_port(struct address_info * hw_config)
94 printf("AudioTriX: Config port I/O conflict\n");
97 if (kilroy_was_here) /* Already initialized */
100 if (trix_read(0x15) != 0x71) { /* No asic signature */
101 DDB(printf("No AudioTriX ASIC signature found\n"));
108 * Reset some registers.
115 * Configure the ASIC to place the codec to the proper I/O location
118 switch (hw_config->io_base) {
135 trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits);
140 * Probe and attach routines for the Windows Sound System mode of AudioTriX
145 probe_trix_wss(struct address_info * hw_config)
148 * Check if the IO port returns valid signature. The original MS
149 * Sound system returns 0x04 while some cards (AudioTriX Pro for
150 * example) return 0x00.
154 printf("AudioTriX: MSS I/O port conflict\n");
157 trix_osp = hw_config->osp;
159 if (!trix_set_wss_port(hw_config))
162 if ((inb(hw_config->io_base + 3) & 0x3f) != 0x00) {
163 DDB(printf("No MSS signature detected on port 0x%x\n",
164 hw_config->io_base));
167 if (hw_config->irq > 11) {
168 printf("AudioTriX: Bad WSS IRQ %d\n", hw_config->irq);
171 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3) {
172 printf("AudioTriX: Bad WSS DMA %d\n", hw_config->dma);
175 if (hw_config->dma2 != -1)
176 if (hw_config->dma2 != 0 && hw_config->dma2 != 1 && hw_config->dma2 != 3) {
177 printf("AudioTriX: Bad capture DMA %d\n", hw_config->dma2);
181 * Check that DMA0 is not in use with a 8 bit board.
184 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80) {
185 printf("AudioTriX: Can't use DMA0 with a 8 bit card\n");
188 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80) {
189 printf("AudioTriX: Can't use IRQ%d with a 8 bit card\n", hw_config->irq);
192 return ad1848_detect(hw_config->io_base + 4, NULL, hw_config->osp);
196 attach_trix_wss(struct address_info * hw_config)
198 static u_char interrupt_bits[12] =
199 {-1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20};
202 static u_char dma_bits[4] =
205 int config_port = hw_config->io_base + 0,
206 version_port = hw_config->io_base + 3;
207 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
209 trix_osp = hw_config->osp;
211 if (!kilroy_was_here) {
212 DDB(printf("AudioTriX: Attach called but not probed yet???\n"));
216 * Set the IRQ and DMA addresses.
219 bits = interrupt_bits[hw_config->irq];
221 printf("AudioTriX: Bad IRQ (%d)\n", hw_config->irq);
224 outb(config_port, bits | 0x40);
225 if ((inb(version_port) & 0x40) == 0)
226 printf("[IRQ Conflict?]");
228 if (hw_config->dma2 == -1) { /* Single DMA mode */
229 bits |= dma_bits[dma1];
234 tmp = trix_read(0x13) & ~30;
235 trix_write(0x13, tmp | 0x80 | (dma1 << 4));
237 tmp = trix_read(0x14) & ~30;
238 trix_write(0x14, tmp | 0x80 | (dma2 << 4));
241 outb(config_port, bits);/* Write IRQ+DMA setup */
243 ad1848_init("AudioTriX Pro", hw_config->io_base + 4,
253 probe_trix_sb(struct address_info * hw_config)
257 static char irq_translate[] = {-1, -1, -1, 0, 1, 2, -1, 3};
259 #ifndef INCLUDE_TRIX_BOOT
260 return 0; /* No boot code -> no fun */
262 if (!kilroy_was_here)
263 return 0; /* AudioTriX Pro has not been detected earlier */
268 if ((hw_config->io_base & 0xffffff8f) != 0x200)
271 tmp = hw_config->irq;
274 if (irq_translate[tmp] == -1)
277 tmp = hw_config->dma;
278 if (tmp != 1 && tmp != 3)
281 conf = 0x84; /* DMA and IRQ enable */
282 conf |= hw_config->io_base & 0x70; /* I/O address bits */
283 conf |= irq_translate[hw_config->irq];
284 if (hw_config->dma == 3)
286 trix_write(0x1b, conf);
288 download_boot(hw_config->io_base);
295 attach_trix_sb(struct address_info * hw_config)
298 sb_dsp_disable_midi();
301 conf_printf("AudioTriX (SB)", hw_config);
305 attach_trix_mpu(struct address_info * hw_config)
307 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
308 attach_mpu401(hw_config);
313 probe_trix_mpu(struct address_info * hw_config)
315 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
317 static char irq_bits[] = {-1, -1, -1, 1, 2, 3, -1, 4, -1, 5};
319 if (!kilroy_was_here) {
320 DDB(printf("Trix: WSS and SB modes must be initialized before MPU\n"));
321 return 0; /* AudioTriX Pro has not been detected earlier */
323 if (!sb_initialized) {
324 DDB(printf("Trix: SB mode must be initialized before MPU\n"));
327 if (mpu_initialized) {
328 DDB(printf("Trix: MPU mode already initialized\n"));
331 if (hw_config->irq > 9) {
332 printf("AudioTriX: Bad MPU IRQ %d\n", hw_config->irq);
335 if (irq_bits[hw_config->irq] == -1) {
336 printf("AudioTriX: Bad MPU IRQ %d\n", hw_config->irq);
339 switch (hw_config->io_base) {
353 return 0; /* Invalid port */
356 conf |= irq_bits[hw_config->irq] << 4;
358 trix_write(0x19, (trix_read(0x19) & 0x83) | conf);
362 return probe_mpu401(hw_config);