4 * Low level driver for the MediaTrix AudioTrix Pro
5 * (MT-0002-PC Control Chip)
8 * Copyright (C) by Hannu Savolainen 1993-1997
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
15 * Alan Cox Modularisation, cleanup.
16 * Christoph Hellwig Adapted to module_init/module_exit
17 * Arnaldo C. de Melo Got rid of attach_uart401
20 #include <linux/init.h>
21 #include <linux/module.h>
23 #include "sound_config.h"
25 #include "sound_firmware.h"
30 #include "trix_boot.h"
36 static unsigned char trix_read(int addr)
38 outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
39 return inb(0x391); /* MT-0002-PC ASIC data */
42 static void trix_write(int addr, int data)
44 outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
45 outb(((unsigned char) data), 0x391); /* MT-0002-PC ASIC data */
48 static void download_boot(int base)
50 int i = 0, n = trix_boot_len;
52 if (trix_boot_len == 0)
55 trix_write(0xf8, 0x00); /* ??????? */
56 outb((0x01), base + 6); /* Clear the internal data pointer */
57 outb((0x00), base + 6); /* Restart */
60 * Write the boot code to the RAM upload/download register.
61 * Each write increments the internal data pointer.
63 outb((0x01), base + 6); /* Clear the internal data pointer */
64 outb((0x1A), 0x390); /* Select RAM download/upload port */
66 for (i = 0; i < n; i++)
67 outb((trix_boot[i]), 0x391);
68 for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */
70 outb((0x00), base + 6); /* Reset */
71 outb((0x50), 0x390); /* ?????? */
75 static int trix_set_wss_port(struct address_info *hw_config)
77 unsigned char addr_bits;
79 if (trix_read(0x15) != 0x71) /* No ASIC signature */
81 MDB(printk(KERN_ERR "No AudioTrix ASIC signature found\n"));
86 * Reset some registers.
93 * Configure the ASIC to place the codec to the proper I/O location
96 switch (hw_config->io_base)
114 trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits);
119 * Probe and attach routines for the Windows Sound System mode of
123 static int __init init_trix_wss(struct address_info *hw_config)
125 static unsigned char dma_bits[4] = {
128 struct resource *ports;
129 int config_port = hw_config->io_base + 0;
130 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
131 int old_num_mixers = num_mixers;
135 switch(hw_config->irq) {
149 printk(KERN_ERR "AudioTrix: Bad WSS IRQ %d\n", hw_config->irq);
159 printk(KERN_ERR "AudioTrix: Bad WSS DMA %d\n", dma1);
170 printk(KERN_ERR "AudioTrix: Bad capture DMA %d\n", dma2);
175 * Check if the IO port returns valid signature. The original MS Sound
176 * system returns 0x04 while some cards (AudioTrix Pro for example)
179 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
181 printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
185 if (!request_region(hw_config->io_base, 4, "MSS config")) {
186 printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
187 release_region(hw_config->io_base + 4, 4);
191 if (!trix_set_wss_port(hw_config))
194 config = inb(hw_config->io_base + 3);
196 if ((config & 0x3f) != 0x00)
198 MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x\n", hw_config->io_base));
203 * Check that DMA0 is not in use with a 8 bit board.
206 if (dma1 == 0 && config & 0x80)
208 printk(KERN_ERR "AudioTrix: Can't use DMA0 with a 8 bit card slot\n");
211 if (hw_config->irq > 9 && config & 0x80)
213 printk(KERN_ERR "AudioTrix: Can't use IRQ%d with a 8 bit card slot\n", hw_config->irq);
217 ret = ad1848_detect(ports, NULL, hw_config->osp);
222 trix_write(0x15, 0x80);
225 * Set the IRQ and DMA addresses.
228 outb((bits | 0x40), config_port);
230 if (dma2 == -1 || dma2 == dma1)
232 bits |= dma_bits[dma1];
239 tmp = trix_read(0x13) & ~30;
240 trix_write(0x13, tmp | 0x80 | (dma1 << 4));
242 tmp = trix_read(0x14) & ~30;
243 trix_write(0x14, tmp | 0x80 | (dma2 << 4));
246 outb((bits), config_port); /* Write IRQ+DMA setup */
248 hw_config->slots[0] = ad1848_init("AudioTrix Pro", ports,
256 if (num_mixers > old_num_mixers) /* Mixer got installed */
258 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE); /* Line in */
259 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
260 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* OPL4 */
261 AD1848_REROUTE(SOUND_MIXER_SPEAKER, SOUND_MIXER_ALTPCM); /* SB */
266 release_region(hw_config->io_base, 4);
267 release_region(hw_config->io_base + 4, 4);
271 static int __init probe_trix_sb(struct address_info *hw_config)
276 extern int sb_be_quiet;
278 static signed char irq_translate[] = {
279 -1, -1, -1, 0, 1, 2, -1, 3
282 if (trix_boot_len == 0)
283 return 0; /* No boot code -> no fun */
285 if ((hw_config->io_base & 0xffffff8f) != 0x200)
288 tmp = hw_config->irq;
291 if (irq_translate[tmp] == -1)
294 tmp = hw_config->dma;
295 if (tmp != 1 && tmp != 3)
298 if (!request_region(hw_config->io_base, 16, "soundblaster")) {
299 printk(KERN_ERR "AudioTrix: SB I/O port conflict (%x)\n", hw_config->io_base);
303 conf = 0x84; /* DMA and IRQ enable */
304 conf |= hw_config->io_base & 0x70; /* I/O address bits */
305 conf |= irq_translate[hw_config->irq];
306 if (hw_config->dma == 3)
308 trix_write(0x1b, conf);
310 download_boot(hw_config->io_base);
312 hw_config->name = "AudioTrix SB";
313 if (!sb_dsp_detect(hw_config, 0, 0, NULL)) {
314 release_region(hw_config->io_base, 16);
318 hw_config->driver_use_1 = SB_NO_MIDI | SB_NO_MIXER | SB_NO_RECORDING;
320 /* Prevent false alarms */
321 old_quiet = sb_be_quiet;
324 sb_dsp_init(hw_config, THIS_MODULE);
326 sb_be_quiet = old_quiet;
330 static int __init probe_trix_mpu(struct address_info *hw_config)
333 static int irq_bits[] = {
334 -1, -1, -1, 1, 2, 3, -1, 4, -1, 5
337 if (hw_config->irq > 9)
339 printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
342 if (irq_bits[hw_config->irq] == -1)
344 printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
347 switch (hw_config->io_base)
362 return 0; /* Invalid port */
365 conf |= irq_bits[hw_config->irq] << 4;
366 trix_write(0x19, (trix_read(0x19) & 0x83) | conf);
367 hw_config->name = "AudioTrix Pro";
368 return probe_uart401(hw_config, THIS_MODULE);
371 static void __exit unload_trix_wss(struct address_info *hw_config)
373 int dma2 = hw_config->dma2;
376 dma2 = hw_config->dma;
378 release_region(0x390, 2);
379 release_region(hw_config->io_base, 4);
381 ad1848_unload(hw_config->io_base + 4,
386 sound_unload_audiodev(hw_config->slots[0]);
389 static inline void __exit unload_trix_mpu(struct address_info *hw_config)
391 unload_uart401(hw_config);
394 static inline void __exit unload_trix_sb(struct address_info *hw_config)
396 sb_dsp_unload(hw_config, mpu);
399 static struct address_info cfg;
400 static struct address_info cfg2;
401 static struct address_info cfg_mpu;
406 static int __initdata io = -1;
407 static int __initdata irq = -1;
408 static int __initdata dma = -1;
409 static int __initdata dma2 = -1; /* Set this for modules that need it */
410 static int __initdata sb_io = -1;
411 static int __initdata sb_dma = -1;
412 static int __initdata sb_irq = -1;
413 static int __initdata mpu_io = -1;
414 static int __initdata mpu_irq = -1;
416 module_param(io, int, 0);
417 module_param(irq, int, 0);
418 module_param(dma, int, 0);
419 module_param(dma2, int, 0);
420 module_param(sb_io, int, 0);
421 module_param(sb_dma, int, 0);
422 module_param(sb_irq, int, 0);
423 module_param(mpu_io, int, 0);
424 module_param(mpu_irq, int, 0);
425 module_param(joystick, bool, 0);
427 static int __init init_trix(void)
429 printk(KERN_INFO "MediaTrix audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
436 cfg2.io_base = sb_io;
440 cfg_mpu.io_base = mpu_io;
441 cfg_mpu.irq = mpu_irq;
443 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
444 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
448 if (cfg2.io_base != -1 && (cfg2.irq == -1 || cfg2.dma == -1)) {
449 printk(KERN_INFO "CONFIG_SB_IRQ and CONFIG_SB_DMA must be specified if SB_IO is set.\n");
452 if (cfg_mpu.io_base != -1 && cfg_mpu.irq == -1) {
453 printk(KERN_INFO "CONFIG_MPU_IRQ must be specified if MPU_IO is set.\n");
459 trix_boot_len = mod_firmware_load("/etc/sound/trxpro.bin",
460 (char **) &trix_boot);
463 if (!request_region(0x390, 2, "AudioTrix")) {
464 printk(KERN_ERR "AudioTrix: Config port I/O conflict\n");
468 if (!init_trix_wss(&cfg)) {
469 release_region(0x390, 2);
474 * We must attach in the right order to get the firmware
478 if (cfg2.io_base != -1) {
479 sb = probe_trix_sb(&cfg2);
482 if (cfg_mpu.io_base != -1)
483 mpu = probe_trix_mpu(&cfg_mpu);
488 static void __exit cleanup_trix(void)
493 unload_trix_sb(&cfg2);
495 unload_trix_mpu(&cfg_mpu);
496 unload_trix_wss(&cfg);
499 module_init(init_trix);
500 module_exit(cleanup_trix);
503 static int __init setup_trix (char *str)
505 /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, mpu_io, mpu_irq */
508 str = get_options(str, ARRAY_SIZE(ints), ints);
523 __setup("trix=", setup_trix);
525 MODULE_LICENSE("GPL");