4 * Detection routine for the ISA Sound Blaster and compatable sound
7 * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this
9 * software for more info.
11 * This is a complete rewrite of the detection routines. This was
12 * prompted by the PnP API change during v2.5 and the ugly state the
15 * Copyright (C) by Paul Laufer 2002. Based on code originally by
16 * Hannu Savolainen which was modified by many others over the
17 * years. Authors specifically mentioned in the previous version were:
18 * Daniel Stone, Alessandro Zummo, Jeff Garzik, Arnaldo Carvalho de
19 * Melo, Daniel Church, and myself.
21 * 02-05-2003 Original Release, Paul Laufer <paul@laufernet.com>
22 * 02-07-2003 Bug made it into first release. Take two.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
30 #include <linux/mca.h>
31 #endif /* CONFIG_MCA */
32 #include "sound_config.h"
36 #include <linux/pnp.h>
37 #endif /* CONFIG_PNP */
40 MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
41 MODULE_LICENSE("GPL");
43 extern void *smw_free;
45 static int __initdata mpu_io = 0;
46 static int __initdata io = -1;
47 static int __initdata irq = -1;
48 static int __initdata dma = -1;
49 static int __initdata dma16 = -1;
50 static int __initdata type = 0; /* Can set this to a specific card type */
51 static int __initdata esstype = 0; /* ESS chip type */
52 static int __initdata acer = 0; /* Do acer notebook init? */
53 static int __initdata sm_games = 0; /* Logitech soundman games? */
55 struct sb_card_config *legacy = NULL;
58 static int __initdata pnp = 1;
60 static int __initdata uart401 = 0;
63 static int __initdata pnp = 0;
66 module_param(io, int, 000);
67 MODULE_PARM_DESC(io, "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
68 module_param(irq, int, 000);
69 MODULE_PARM_DESC(irq, "IRQ (5,7,9,10)");
70 module_param(dma, int, 000);
71 MODULE_PARM_DESC(dma, "8-bit DMA channel (0,1,3)");
72 module_param(dma16, int, 000);
73 MODULE_PARM_DESC(dma16, "16-bit DMA channel (5,6,7)");
74 module_param(mpu_io, int, 000);
75 MODULE_PARM_DESC(mpu_io, "MPU base address");
76 module_param(type, int, 000);
77 MODULE_PARM_DESC(type, "You can set this to specific card type (doesn't " \
79 module_param(sm_games, int, 000);
80 MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
81 "(doesn't work with pnp)");
82 module_param(esstype, int, 000);
83 MODULE_PARM_DESC(esstype, "ESS chip type (doesn't work with pnp)");
84 module_param(acer, int, 000);
85 MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
86 "(doesn't work with pnp)");
89 module_param(pnp, int, 000);
90 MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
92 /* Not done yet.... */
94 module_param(uart401, int, 000);
95 MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
96 "the mpu on some clones");
98 #endif /* CONFIG_PNP */
100 /* OSS subsystem card registration shared by PnP and legacy routines */
101 static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
103 if(!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
104 printk(KERN_ERR "sb: Failed DSP Detect.\n");
108 if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
109 printk(KERN_ERR "sb: Failed DSP init.\n");
113 if(scc->mpucnf.io_base > 0) {
115 printk(KERN_INFO "sb: Turning on MPU\n");
116 if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
123 static void sb_unload(struct sb_card_config *scc)
125 sb_dsp_unload(&scc->conf, 0);
127 unload_sbmpu(&scc->mpucnf);
131 /* Register legacy card with OSS subsystem */
132 static int sb_init_legacy(void)
134 struct sb_module_options sbmo = {0};
136 if((legacy = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
137 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
140 memset(legacy, 0, sizeof(struct sb_card_config));
142 legacy->conf.io_base = io;
143 legacy->conf.irq = irq;
144 legacy->conf.dma = dma;
145 legacy->conf.dma2 = dma16;
146 legacy->conf.card_subtype = type;
148 legacy->mpucnf.io_base = mpu_io;
149 legacy->mpucnf.irq = -1;
150 legacy->mpucnf.dma = -1;
151 legacy->mpucnf.dma2 = -1;
153 sbmo.esstype = esstype;
154 sbmo.sm_games = sm_games;
157 return sb_register_oss(legacy, &sbmo);
162 /* Populate the OSS subsystem structures with information from PnP */
163 static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
165 scc->conf.io_base = -1;
169 scc->mpucnf.io_base = -1;
170 scc->mpucnf.irq = -1;
171 scc->mpucnf.dma = -1;
172 scc->mpucnf.dma2 = -1;
174 /* All clones layout their PnP tables differently and some use
175 different logical devices for the MPU */
176 if(!strncmp("CTL",scc->card_id,3)) {
177 scc->conf.io_base = pnp_port_start(dev,0);
178 scc->conf.irq = pnp_irq(dev,0);
179 scc->conf.dma = pnp_dma(dev,0);
180 scc->conf.dma2 = pnp_dma(dev,1);
181 scc->mpucnf.io_base = pnp_port_start(dev,1);
184 if(!strncmp("tBA",scc->card_id,3)) {
185 scc->conf.io_base = pnp_port_start(dev,0);
186 scc->conf.irq = pnp_irq(dev,0);
187 scc->conf.dma = pnp_dma(dev,0);
188 scc->conf.dma2 = pnp_dma(dev,1);
191 if(!strncmp("ESS",scc->card_id,3)) {
192 scc->conf.io_base = pnp_port_start(dev,0);
193 scc->conf.irq = pnp_irq(dev,0);
194 scc->conf.dma = pnp_dma(dev,0);
195 scc->conf.dma2 = pnp_dma(dev,1);
196 scc->mpucnf.io_base = pnp_port_start(dev,2);
199 if(!strncmp("CMI",scc->card_id,3)) {
200 scc->conf.io_base = pnp_port_start(dev,0);
201 scc->conf.irq = pnp_irq(dev,0);
202 scc->conf.dma = pnp_dma(dev,0);
203 scc->conf.dma2 = pnp_dma(dev,1);
206 if(!strncmp("RWB",scc->card_id,3)) {
207 scc->conf.io_base = pnp_port_start(dev,0);
208 scc->conf.irq = pnp_irq(dev,0);
209 scc->conf.dma = pnp_dma(dev,0);
212 if(!strncmp("ALS",scc->card_id,3)) {
213 if(!strncmp("ALS0007",scc->card_id,7)) {
214 scc->conf.io_base = pnp_port_start(dev,0);
215 scc->conf.irq = pnp_irq(dev,0);
216 scc->conf.dma = pnp_dma(dev,0);
218 scc->conf.io_base = pnp_port_start(dev,0);
219 scc->conf.irq = pnp_irq(dev,0);
220 scc->conf.dma = pnp_dma(dev,1);
221 scc->conf.dma2 = pnp_dma(dev,0);
225 if(!strncmp("RTL",scc->card_id,3)) {
226 scc->conf.io_base = pnp_port_start(dev,0);
227 scc->conf.irq = pnp_irq(dev,0);
228 scc->conf.dma = pnp_dma(dev,1);
229 scc->conf.dma2 = pnp_dma(dev,0);
233 /* Probe callback function for the PnP API */
234 static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
236 struct sb_card_config *scc;
237 struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
238 struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
244 if((scc = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
245 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
248 memset(scc, 0, sizeof(struct sb_card_config));
250 printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
251 "%s, Device PnP id = %s\n", card->card->name, card_id->id,
254 scc->card_id = card_id->id;
255 scc->dev_id = dev->id->id;
256 sb_dev2cfg(dev, scc);
258 printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
259 "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
260 scc->conf.dma, scc->conf.dma2);
262 pnp_set_card_drvdata(card, scc);
264 return sb_register_oss(scc, &sbmo);
267 static void sb_pnp_remove(struct pnp_card_link *card)
269 struct sb_card_config *scc = pnp_get_card_drvdata(card);
274 printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
279 static struct pnp_card_driver sb_pnp_driver = {
280 .name = "OSS SndBlstr", /* 16 character limit */
281 .id_table = sb_pnp_card_table,
282 .probe = sb_pnp_probe,
283 .remove = sb_pnp_remove,
285 #endif /* CONFIG_PNP */
287 static int __init sb_init(void)
292 printk(KERN_INFO "sb: Init: Starting Probe...\n");
294 if(io != -1 && irq != -1 && dma != -1) {
295 printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
296 "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
297 lres = sb_init_legacy();
298 } else if((io != -1 || irq != -1 || dma != -1) ||
299 (!pnp && (io == -1 && irq == -1 && dma == -1)))
300 printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
301 "must be set for legacy cards.\n");
305 pres = pnp_register_card_driver(&sb_pnp_driver);
308 printk(KERN_INFO "sb: Init: Done\n");
310 /* If either PnP or Legacy registered a card then return
312 return (pres > 0 || lres > 0) ? 0 : -ENODEV;
315 static void __exit sb_exit(void)
317 printk(KERN_INFO "sb: Unloading...\n");
319 /* Unload legacy card */
321 printk (KERN_INFO "sb: Unloading legacy card\n");
326 pnp_unregister_card_driver(&sb_pnp_driver);
335 module_init(sb_init);
336 module_exit(sb_exit);