4 * Low level driver for Yamaha YMF701B aka OPL3-SA 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
16 * Christoph Hellwig Adapted to module_init/module_exit
17 * Arnaldo C. de Melo got rid of attach_uart401
20 * Check for install of mpu etc is wrong, should check result of the mss stuff
23 #include <linux/init.h>
24 #include <linux/module.h>
28 #include "sound_config.h"
35 static int sb_initialized = 0;
38 static int kilroy_was_here = 0; /* Don't detect twice */
39 static int mpu_initialized = 0;
41 static int *opl3sa_osp = NULL;
43 static unsigned char opl3sa_read(int addr)
50 outb((0x1d), 0xf86); /* password */
51 outb(((unsigned char) addr), 0xf86); /* address */
52 tmp = inb(0xf87); /* data */
58 static void opl3sa_write(int addr, int data)
64 outb((0x1d), 0xf86); /* password */
65 outb(((unsigned char) addr), 0xf86); /* address */
66 outb(((unsigned char) data), 0xf87); /* data */
70 static int __init opl3sa_detect(void)
74 if (((tmp = opl3sa_read(0x01)) & 0xc4) != 0x04)
76 DDB(printk("OPL3-SA detect error 1 (%x)\n", opl3sa_read(0x01)));
81 * Check that the password feature has any effect
84 if (inb(0xf87) == tmp)
86 DDB(printk("OPL3-SA detect failed 2 (%x/%x)\n", tmp, inb(0xf87)));
89 tmp = (opl3sa_read(0x04) & 0xe0) >> 5;
91 if (tmp != 0 && tmp != 1)
93 DDB(printk("OPL3-SA detect failed 3 (%d)\n", tmp));
96 DDB(printk("OPL3-SA mode %x detected\n", tmp));
98 opl3sa_write(0x01, 0x00); /* Disable MSS */
99 opl3sa_write(0x02, 0x00); /* Disable SB */
100 opl3sa_write(0x03, 0x00); /* Disable MPU */
106 * Probe and attach routines for the Windows Sound System mode of
110 static int __init probe_opl3sa_wss(struct address_info *hw_config)
113 unsigned char tmp = 0x24; /* WSS enable */
115 if (check_region(0xf86, 2)) /* Control port is busy */
118 * Check if the IO port returns valid signature. The original MS Sound
119 * system returns 0x04 while some cards (OPL3-SA for example)
123 if (check_region(hw_config->io_base, 8))
125 printk(KERN_ERR "OPL3-SA: MSS I/O port conflict (%x)\n", hw_config->io_base);
128 opl3sa_osp = hw_config->osp;
130 if (!opl3sa_detect())
132 printk(KERN_ERR "OSS: OPL3-SA chip not found\n");
136 switch (hw_config->io_base)
151 printk(KERN_ERR "OSS: Unsupported OPL3-SA/WSS base %x\n", hw_config->io_base);
155 opl3sa_write(0x01, tmp); /* WSS setup register */
158 ret = probe_ms_sound(hw_config);
160 request_region(0xf86, 2, "OPL3-SA");
165 static void __init attach_opl3sa_wss(struct address_info *hw_config)
170 attach_ms_sound(hw_config, THIS_MODULE);
171 if (num_mixers > nm) /* A mixer was installed */
173 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
174 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
175 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
180 static int __init probe_opl3sa_mpu(struct address_info *hw_config)
183 static signed char irq_bits[] = {
184 -1, -1, -1, -1, -1, 1, -1, 2, -1, 3, 4
187 if (!kilroy_was_here)
188 return 0; /* OPL3-SA has not been detected earlier */
192 DDB(printk("OPL3-SA: MPU mode already initialized\n"));
195 if (hw_config->irq > 10)
197 printk(KERN_ERR "OPL3-SA: Bad MPU IRQ %d\n", hw_config->irq);
200 if (irq_bits[hw_config->irq] == -1)
202 printk(KERN_ERR "OPL3-SA: Bad MPU IRQ %d\n", hw_config->irq);
205 switch (hw_config->io_base)
220 return 0; /* Invalid port */
223 conf |= 0x83; /* MPU & OPL3 (synth) & game port enable */
224 conf |= irq_bits[hw_config->irq] << 2;
226 opl3sa_write(0x03, conf);
229 hw_config->name = "OPL3-SA (MPU401)";
231 return probe_uart401(hw_config, THIS_MODULE);
234 static void __exit unload_opl3sa_wss(struct address_info *hw_config)
236 int dma2 = hw_config->dma2;
239 dma2 = hw_config->dma;
241 release_region(0xf86, 2);
242 release_region(hw_config->io_base, 4);
244 ad1848_unload(hw_config->io_base + 4,
249 sound_unload_audiodev(hw_config->slots[0]);
252 static inline void __exit unload_opl3sa_mpu(struct address_info *hw_config)
254 unload_uart401(hw_config);
258 static inline void __exit unload_opl3sa_sb(struct address_info *hw_config)
260 sb_dsp_unload(hw_config);
264 static int found_mpu;
266 static struct address_info cfg;
267 static struct address_info cfg_mpu;
269 static int __initdata io = -1;
270 static int __initdata irq = -1;
271 static int __initdata dma = -1;
272 static int __initdata dma2 = -1;
273 static int __initdata mpu_io = -1;
274 static int __initdata mpu_irq = -1;
277 MODULE_PARM(irq,"i");
278 MODULE_PARM(dma,"i");
279 MODULE_PARM(dma2,"i");
280 MODULE_PARM(mpu_io,"i");
281 MODULE_PARM(mpu_irq,"i");
283 static int __init init_opl3sa(void)
285 if (io == -1 || irq == -1 || dma == -1) {
286 printk(KERN_ERR "opl3sa: dma, irq and io must be set.\n");
295 cfg_mpu.io_base = mpu_io;
296 cfg_mpu.irq = mpu_irq;
298 if (probe_opl3sa_wss(&cfg) == 0)
301 found_mpu=probe_opl3sa_mpu(&cfg_mpu);
303 attach_opl3sa_wss(&cfg);
307 static void __exit cleanup_opl3sa(void)
310 unload_opl3sa_mpu(&cfg_mpu);
311 unload_opl3sa_wss(&cfg);
314 module_init(init_opl3sa);
315 module_exit(cleanup_opl3sa);
318 static int __init setup_opl3sa(char *str)
320 /* io, irq, dma, dma2, mpu_io, mpu_irq */
323 str = get_options(str, ARRAY_SIZE(ints), ints);
335 __setup("opl3sa=", setup_opl3sa);
337 MODULE_LICENSE("GPL");