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>
25 #include <linux/spinlock.h>
29 #include "sound_config.h"
36 static int sb_initialized;
39 static int kilroy_was_here; /* Don't detect twice */
40 static int mpu_initialized;
41 static spinlock_t lock=SPIN_LOCK_UNLOCKED;
42 static int *opl3sa_osp;
44 static unsigned char opl3sa_read(int addr)
49 spin_lock_irqsave(&lock,flags);
50 outb((0x1d), 0xf86); /* password */
51 outb(((unsigned char) addr), 0xf86); /* address */
52 tmp = inb(0xf87); /* data */
53 spin_unlock_irqrestore(&lock,flags);
58 static void opl3sa_write(int addr, int data)
62 spin_lock_irqsave(&lock,flags);
63 outb((0x1d), 0xf86); /* password */
64 outb(((unsigned char) addr), 0xf86); /* address */
65 outb(((unsigned char) data), 0xf87); /* data */
66 spin_unlock_irqrestore(&lock,flags);
69 static int __init opl3sa_detect(void)
73 if (((tmp = opl3sa_read(0x01)) & 0xc4) != 0x04)
75 DDB(printk("OPL3-SA detect error 1 (%x)\n", opl3sa_read(0x01)));
80 * Check that the password feature has any effect
83 if (inb(0xf87) == tmp)
85 DDB(printk("OPL3-SA detect failed 2 (%x/%x)\n", tmp, inb(0xf87)));
88 tmp = (opl3sa_read(0x04) & 0xe0) >> 5;
90 if (tmp != 0 && tmp != 1)
92 DDB(printk("OPL3-SA detect failed 3 (%d)\n", tmp));
95 DDB(printk("OPL3-SA mode %x detected\n", tmp));
97 opl3sa_write(0x01, 0x00); /* Disable MSS */
98 opl3sa_write(0x02, 0x00); /* Disable SB */
99 opl3sa_write(0x03, 0x00); /* Disable MPU */
105 * Probe and attach routines for the Windows Sound System mode of
109 static int __init probe_opl3sa_wss(struct address_info *hw_config)
112 unsigned char tmp = 0x24; /* WSS enable */
114 if (check_region(0xf86, 2)) /* Control port is busy */
117 * Check if the IO port returns valid signature. The original MS Sound
118 * system returns 0x04 while some cards (OPL3-SA for example)
122 if (check_region(hw_config->io_base, 8))
124 printk(KERN_ERR "OPL3-SA: MSS I/O port conflict (%x)\n", hw_config->io_base);
127 opl3sa_osp = hw_config->osp;
129 if (!opl3sa_detect())
131 printk(KERN_ERR "OSS: OPL3-SA chip not found\n");
135 switch (hw_config->io_base)
150 printk(KERN_ERR "OSS: Unsupported OPL3-SA/WSS base %x\n", hw_config->io_base);
154 opl3sa_write(0x01, tmp); /* WSS setup register */
157 ret = probe_ms_sound(hw_config);
159 request_region(0xf86, 2, "OPL3-SA");
164 static void __init attach_opl3sa_wss(struct address_info *hw_config)
169 attach_ms_sound(hw_config, THIS_MODULE);
170 if (num_mixers > nm) /* A mixer was installed */
172 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
173 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
174 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
179 static int __init probe_opl3sa_mpu(struct address_info *hw_config)
182 static signed char irq_bits[] = {
183 -1, -1, -1, -1, -1, 1, -1, 2, -1, 3, 4
186 if (!kilroy_was_here)
187 return 0; /* OPL3-SA has not been detected earlier */
191 DDB(printk("OPL3-SA: MPU mode already initialized\n"));
194 if (hw_config->irq > 10)
196 printk(KERN_ERR "OPL3-SA: Bad MPU IRQ %d\n", hw_config->irq);
199 if (irq_bits[hw_config->irq] == -1)
201 printk(KERN_ERR "OPL3-SA: Bad MPU IRQ %d\n", hw_config->irq);
204 switch (hw_config->io_base)
219 return 0; /* Invalid port */
222 conf |= 0x83; /* MPU & OPL3 (synth) & game port enable */
223 conf |= irq_bits[hw_config->irq] << 2;
225 opl3sa_write(0x03, conf);
228 hw_config->name = "OPL3-SA (MPU401)";
230 return probe_uart401(hw_config, THIS_MODULE);
233 static void __exit unload_opl3sa_wss(struct address_info *hw_config)
235 int dma2 = hw_config->dma2;
238 dma2 = hw_config->dma;
240 release_region(0xf86, 2);
241 release_region(hw_config->io_base, 4);
243 ad1848_unload(hw_config->io_base + 4,
248 sound_unload_audiodev(hw_config->slots[0]);
251 static inline void __exit unload_opl3sa_mpu(struct address_info *hw_config)
253 unload_uart401(hw_config);
257 static inline void __exit unload_opl3sa_sb(struct address_info *hw_config)
259 sb_dsp_unload(hw_config);
263 static int found_mpu;
265 static struct address_info cfg;
266 static struct address_info cfg_mpu;
268 static int __initdata io = -1;
269 static int __initdata irq = -1;
270 static int __initdata dma = -1;
271 static int __initdata dma2 = -1;
272 static int __initdata mpu_io = -1;
273 static int __initdata mpu_irq = -1;
276 MODULE_PARM(irq,"i");
277 MODULE_PARM(dma,"i");
278 MODULE_PARM(dma2,"i");
279 MODULE_PARM(mpu_io,"i");
280 MODULE_PARM(mpu_irq,"i");
282 static int __init init_opl3sa(void)
284 if (io == -1 || irq == -1 || dma == -1) {
285 printk(KERN_ERR "opl3sa: dma, irq and io must be set.\n");
294 cfg_mpu.io_base = mpu_io;
295 cfg_mpu.irq = mpu_irq;
297 if (probe_opl3sa_wss(&cfg) == 0)
300 found_mpu=probe_opl3sa_mpu(&cfg_mpu);
302 attach_opl3sa_wss(&cfg);
306 static void __exit cleanup_opl3sa(void)
309 unload_opl3sa_mpu(&cfg_mpu);
310 unload_opl3sa_wss(&cfg);
313 module_init(init_opl3sa);
314 module_exit(cleanup_opl3sa);
317 static int __init setup_opl3sa(char *str)
319 /* io, irq, dma, dma2, mpu_io, mpu_irq */
322 str = get_options(str, ARRAY_SIZE(ints), ints);
334 __setup("opl3sa=", setup_opl3sa);
336 MODULE_LICENSE("GPL");