2 * Driver for SoundBlaster 16/AWE32/AWE64 soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/pnp.h>
27 #include <linux/moduleparam.h>
28 #include <sound/core.h>
30 #include <sound/sb16_csp.h>
31 #include <sound/mpu401.h>
32 #include <sound/opl3.h>
33 #include <sound/emu8000.h>
34 #include <sound/seq_device.h>
35 #define SNDRV_LEGACY_AUTO_PROBE
36 #define SNDRV_LEGACY_FIND_FREE_IRQ
37 #define SNDRV_LEGACY_FIND_FREE_DMA
38 #include <sound/initval.h>
48 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
49 MODULE_LICENSE("GPL");
50 MODULE_CLASSES("{sound}");
52 MODULE_DESCRIPTION("Sound Blaster 16");
53 MODULE_DEVICES("{{Creative Labs,SB 16},"
54 "{Creative Labs,SB Vibra16S},"
55 "{Creative Labs,SB Vibra16C},"
56 "{Creative Labs,SB Vibra16CL},"
57 "{Creative Labs,SB Vibra16X}}");
59 MODULE_DESCRIPTION("Sound Blaster AWE");
60 MODULE_DEVICES("{{Creative Labs,SB AWE 32},"
61 "{Creative Labs,SB AWE 64},"
62 "{Creative Labs,SB AWE 64 Gold}}");
66 #define SNDRV_DEBUG_IRQ
69 #if defined(SNDRV_SBAWE) && (defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)))
70 #define SNDRV_SBAWE_EMU8000
73 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
74 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
75 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
77 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
79 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
80 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x330,0x300 */
81 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
82 #ifdef SNDRV_SBAWE_EMU8000
83 static long awe_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
85 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
86 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
87 static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 5,6,7 */
88 static int mic_agc[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
89 #ifdef CONFIG_SND_SB16_CSP
90 static int csp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
92 #ifdef SNDRV_SBAWE_EMU8000
93 static int seq_ports[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
97 module_param_array(index, int, boot_devs, 0444);
98 MODULE_PARM_DESC(index, "Index value for SoundBlaster 16 soundcard.");
99 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
100 module_param_array(id, charp, boot_devs, 0444);
101 MODULE_PARM_DESC(id, "ID string for SoundBlaster 16 soundcard.");
102 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
103 module_param_array(enable, bool, boot_devs, 0444);
104 MODULE_PARM_DESC(enable, "Enable SoundBlaster 16 soundcard.");
105 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
107 module_param_array(isapnp, bool, boot_devs, 0444);
108 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
109 MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
111 module_param_array(port, long, boot_devs, 0444);
112 MODULE_PARM_DESC(port, "Port # for SB16 driver.");
113 MODULE_PARM_SYNTAX(port, SNDRV_ENABLED ",allows:{{0x220},{0x240},{0x260},{0x280}},dialog:list");
114 module_param_array(mpu_port, long, boot_devs, 0444);
115 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for SB16 driver.");
116 MODULE_PARM_SYNTAX(mpu_port, SNDRV_ENABLED ",allows:{{0x330},{0x300}},dialog:list");
117 module_param_array(fm_port, long, boot_devs, 0444);
118 MODULE_PARM_DESC(fm_port, "FM port # for SB16 PnP driver.");
119 MODULE_PARM_SYNTAX(fm_port, SNDRV_ENABLED ",allows:{{0x388},{0x38c},{0x390},{0x394}},dialog:list");
120 #ifdef SNDRV_SBAWE_EMU8000
121 module_param_array(awe_port, long, boot_devs, 0444);
122 MODULE_PARM_DESC(awe_port, "AWE port # for SB16 PnP driver.");
123 MODULE_PARM_SYNTAX(awe_port, SNDRV_ENABLED ",allows:{{0x620},{0x640},{0x660},{0x680}},dialog:list");
125 module_param_array(irq, int, boot_devs, 0444);
126 MODULE_PARM_DESC(irq, "IRQ # for SB16 driver.");
127 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
128 module_param_array(dma8, int, boot_devs, 0444);
129 MODULE_PARM_DESC(dma8, "8-bit DMA # for SB16 driver.");
130 MODULE_PARM_SYNTAX(dma8, SNDRV_DMA8_DESC);
131 module_param_array(dma16, int, boot_devs, 0444);
132 MODULE_PARM_DESC(dma16, "16-bit DMA # for SB16 driver.");
133 MODULE_PARM_SYNTAX(dma16, SNDRV_DMA16_DESC);
134 module_param_array(mic_agc, int, boot_devs, 0444);
135 MODULE_PARM_DESC(mic_agc, "Mic Auto-Gain-Control switch.");
136 MODULE_PARM_SYNTAX(mic_agc, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC);
137 #ifdef CONFIG_SND_SB16_CSP
138 module_param_array(csp, int, boot_devs, 0444);
139 MODULE_PARM_DESC(csp, "ASP/CSP chip support.");
140 MODULE_PARM_SYNTAX(csp, SNDRV_ENABLED "," SNDRV_ENABLE_DESC);
142 #ifdef SNDRV_SBAWE_EMU8000
143 module_param_array(seq_ports, int, boot_devs, 0444);
144 MODULE_PARM_DESC(seq_ports, "Number of sequencer ports for WaveTable synth.");
145 MODULE_PARM_SYNTAX(seq_ports, SNDRV_ENABLED ",allows:{{0,8}},skill:advanced");
148 struct snd_card_sb16 {
149 struct resource *fm_res; /* used to block FM i/o region for legacy cards */
153 #ifdef SNDRV_SBAWE_EMU8000
154 struct pnp_dev *devwt;
159 static snd_card_t *snd_sb16_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
163 static struct pnp_card_device_id snd_sb16_pnpids[] = {
165 /* Sound Blaster 16 PnP */
166 { .id = "CTL0024", .devs = { { "CTL0031" } } },
167 /* Sound Blaster 16 PnP */
168 { .id = "CTL0025", .devs = { { "CTL0031" } } },
169 /* Sound Blaster 16 PnP */
170 { .id = "CTL0026", .devs = { { "CTL0031" } } },
171 /* Sound Blaster 16 PnP */
172 { .id = "CTL0027", .devs = { { "CTL0031" } } },
173 /* Sound Blaster 16 PnP */
174 { .id = "CTL0028", .devs = { { "CTL0031" } } },
175 /* Sound Blaster 16 PnP */
176 { .id = "CTL0029", .devs = { { "CTL0031" } } },
177 /* Sound Blaster 16 PnP */
178 { .id = "CTL002a", .devs = { { "CTL0031" } } },
179 /* Sound Blaster 16 PnP */
180 /* Note: This card has also a CTL0051:StereoEnhance device!!! */
181 { .id = "CTL002b", .devs = { { "CTL0031" } } },
182 /* Sound Blaster 16 PnP */
183 { .id = "CTL002c", .devs = { { "CTL0031" } } },
184 /* Sound Blaster Vibra16S */
185 { .id = "CTL0051", .devs = { { "CTL0001" } } },
186 /* Sound Blaster Vibra16C */
187 { .id = "CTL0070", .devs = { { "CTL0001" } } },
188 /* Sound Blaster Vibra16CL - added by ctm@ardi.com */
189 { .id = "CTL0080", .devs = { { "CTL0041" } } },
190 /* Sound Blaster 16 'value' PnP. It says model ct4130 on the pcb, */
191 /* but ct4131 on a sticker on the board.. */
192 { .id = "CTL0086", .devs = { { "CTL0041" } } },
193 /* Sound Blaster Vibra16X */
194 { .id = "CTL00f0", .devs = { { "CTL0043" } } },
195 #else /* SNDRV_SBAWE defined */
196 /* Sound Blaster AWE 32 PnP */
197 { .id = "CTL0035", .devs = { { "CTL0031" }, { "CTL0021" } } },
198 /* Sound Blaster AWE 32 PnP */
199 { .id = "CTL0039", .devs = { { "CTL0031" }, { "CTL0021" } } },
200 /* Sound Blaster AWE 32 PnP */
201 { .id = "CTL0042", .devs = { { "CTL0031" }, { "CTL0021" } } },
202 /* Sound Blaster AWE 32 PnP */
203 { .id = "CTL0043", .devs = { { "CTL0031" }, { "CTL0021" } } },
204 /* Sound Blaster AWE 32 PnP */
205 /* Note: This card has also a CTL0051:StereoEnhance device!!! */
206 { .id = "CTL0044", .devs = { { "CTL0031" }, { "CTL0021" } } },
207 /* Sound Blaster AWE 32 PnP */
208 /* Note: This card has also a CTL0051:StereoEnhance device!!! */
209 { .id = "CTL0045", .devs = { { "CTL0031" }, { "CTL0021" } } },
210 /* Sound Blaster AWE 32 PnP */
211 { .id = "CTL0046", .devs = { { "CTL0031" }, { "CTL0021" } } },
212 /* Sound Blaster AWE 32 PnP */
213 { .id = "CTL0047", .devs = { { "CTL0031" }, { "CTL0021" } } },
214 /* Sound Blaster AWE 32 PnP */
215 { .id = "CTL0048", .devs = { { "CTL0031" }, { "CTL0021" } } },
216 /* Sound Blaster AWE 32 PnP */
217 { .id = "CTL0054", .devs = { { "CTL0031" }, { "CTL0021" } } },
218 /* Sound Blaster AWE 32 PnP */
219 { .id = "CTL009a", .devs = { { "CTL0041" }, { "CTL0021" } } },
220 /* Sound Blaster AWE 32 PnP */
221 { .id = "CTL009c", .devs = { { "CTL0041" }, { "CTL0021" } } },
222 /* Sound Blaster 32 PnP */
223 { .id = "CTL009f", .devs = { { "CTL0041" }, { "CTL0021" } } },
224 /* Sound Blaster AWE 64 PnP */
225 { .id = "CTL009d", .devs = { { "CTL0042" }, { "CTL0022" } } },
226 /* Sound Blaster AWE 64 PnP Gold */
227 { .id = "CTL009e", .devs = { { "CTL0044" }, { "CTL0023" } } },
228 /* Sound Blaster AWE 64 PnP Gold */
229 { .id = "CTL00b2", .devs = { { "CTL0044" }, { "CTL0023" } } },
230 /* Sound Blaster AWE 64 PnP */
231 { .id = "CTL00c1", .devs = { { "CTL0042" }, { "CTL0022" } } },
232 /* Sound Blaster AWE 64 PnP */
233 { .id = "CTL00c3", .devs = { { "CTL0045" }, { "CTL0022" } } },
234 /* Sound Blaster AWE 64 PnP */
235 { .id = "CTL00c5", .devs = { { "CTL0045" }, { "CTL0022" } } },
236 /* Sound Blaster AWE 64 PnP */
237 { .id = "CTL00c7", .devs = { { "CTL0045" }, { "CTL0022" } } },
238 /* Sound Blaster AWE 64 PnP */
239 { .id = "CTL00e4", .devs = { { "CTL0045" }, { "CTL0022" } } },
240 /* Sound Blaster AWE 64 PnP */
241 { .id = "CTL00e9", .devs = { { "CTL0045" }, { "CTL0022" } } },
242 /* Sound Blaster 16 PnP (AWE) */
243 { .id = "CTL00ed", .devs = { { "CTL0041" }, { "CTL0070" } } },
244 /* Generic entries */
245 { .id = "CTLXXXX" , .devs = { { "CTL0031" }, { "CTL0021" } } },
246 { .id = "CTLXXXX" , .devs = { { "CTL0041" }, { "CTL0021" } } },
247 { .id = "CTLXXXX" , .devs = { { "CTL0042" }, { "CTL0022" } } },
248 { .id = "CTLXXXX" , .devs = { { "CTL0044" }, { "CTL0023" } } },
249 { .id = "CTLXXXX" , .devs = { { "CTL0045" }, { "CTL0022" } } },
250 #endif /* SNDRV_SBAWE */
251 /* Sound Blaster 16 PnP (Virtual PC 2004)*/
252 { .id = "tBA03b0", .devs = { { "PNPb003" } } },
256 MODULE_DEVICE_TABLE(pnp_card, snd_sb16_pnpids);
258 #endif /* CONFIG_PNP */
260 #ifdef SNDRV_SBAWE_EMU8000
261 #define DRIVER_NAME "snd-card-sbawe"
263 #define DRIVER_NAME "snd-card-sb16"
268 static int __devinit snd_card_sb16_pnp(int dev, struct snd_card_sb16 *acard,
269 struct pnp_card_link *card,
270 const struct pnp_card_device_id *id)
272 struct pnp_dev *pdev;
273 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
278 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
279 if (acard->dev == NULL) {
283 #ifdef SNDRV_SBAWE_EMU8000
284 acard->devwt = pnp_request_card_device(card, id->devs[1].id, acard->dev);
286 /* Audio initialization */
289 pnp_init_resource_table(cfg);
291 /* override resources */
293 if (port[dev] != SNDRV_AUTO_PORT)
294 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
295 if (mpu_port[dev] != SNDRV_AUTO_PORT)
296 pnp_resource_change(&cfg->port_resource[1], mpu_port[dev], 2);
297 if (fm_port[dev] != SNDRV_AUTO_PORT)
298 pnp_resource_change(&cfg->port_resource[2], fm_port[dev], 4);
299 if (dma8[dev] != SNDRV_AUTO_DMA)
300 pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
301 if (dma16[dev] != SNDRV_AUTO_DMA)
302 pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
303 if (irq[dev] != SNDRV_AUTO_IRQ)
304 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
305 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
306 snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
307 err = pnp_activate_dev(pdev);
309 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
313 port[dev] = pnp_port_start(pdev, 0);
314 mpu_port[dev] = pnp_port_start(pdev, 1);
315 fm_port[dev] = pnp_port_start(pdev, 2);
316 dma8[dev] = pnp_dma(pdev, 0);
317 dma16[dev] = pnp_dma(pdev, 1);
318 irq[dev] = pnp_irq(pdev, 0);
319 snd_printdd("pnp SB16: port=0x%lx, mpu port=0x%lx, fm port=0x%lx\n",
320 port[dev], mpu_port[dev], fm_port[dev]);
321 snd_printdd("pnp SB16: dma1=%i, dma2=%i, irq=%i\n",
322 dma8[dev], dma16[dev], irq[dev]);
323 #ifdef SNDRV_SBAWE_EMU8000
324 /* WaveTable initialization */
327 pnp_init_resource_table(cfg);
329 /* override resources */
331 if (awe_port[dev] != SNDRV_AUTO_PORT) {
332 pnp_resource_change(&cfg->port_resource[0], awe_port[dev], 4);
333 pnp_resource_change(&cfg->port_resource[1], awe_port[dev] + 0x400, 4);
334 pnp_resource_change(&cfg->port_resource[2], awe_port[dev] + 0x800, 4);
336 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
337 snd_printk(KERN_ERR PFX "WaveTable the requested resources are invalid, using auto config\n");
338 err = pnp_activate_dev(pdev);
342 awe_port[dev] = pnp_port_start(pdev, 0);
343 snd_printdd("pnp SB16: wavetable port=0x%lx\n", pnp_port_start(pdev, 0));
347 pnp_release_card_device(pdev);
348 snd_printk(KERN_ERR PFX "WaveTable pnp configure failure\n");
358 #endif /* CONFIG_PNP */
360 static void snd_sb16_free(snd_card_t *card)
362 struct snd_card_sb16 *acard = (struct snd_card_sb16 *)card->private_data;
367 release_resource(acard->fm_res);
368 kfree_nocheck(acard->fm_res);
372 static int __init snd_sb16_probe(int dev,
373 struct pnp_card_link *pcard,
374 const struct pnp_card_device_id *pid)
376 static int possible_irqs[] = {5, 9, 10, 7, -1};
377 static int possible_dmas8[] = {1, 3, 0, -1};
378 static int possible_dmas16[] = {5, 6, 7, -1};
379 int xirq, xdma8, xdma16;
382 struct snd_card_sb16 *acard;
384 snd_hwdep_t *synth = NULL;
385 #ifdef CONFIG_SND_SB16_CSP
386 snd_hwdep_t *xcsp = NULL;
391 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
392 sizeof(struct snd_card_sb16));
395 acard = (struct snd_card_sb16 *) card->private_data;
396 card->private_free = snd_sb16_free;
399 if ((err = snd_card_sb16_pnp(dev, acard, pcard, pid))) {
403 snd_card_set_dev(card, &pcard->card->dev);
413 if (xirq == SNDRV_AUTO_IRQ) {
414 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
416 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
420 if (xdma8 == SNDRV_AUTO_DMA) {
421 if ((xdma8 = snd_legacy_find_free_dma(possible_dmas8)) < 0) {
423 snd_printk(KERN_ERR PFX "unable to find a free 8-bit DMA\n");
427 if (xdma16 == SNDRV_AUTO_DMA) {
428 if ((xdma16 = snd_legacy_find_free_dma(possible_dmas16)) < 0) {
430 snd_printk(KERN_ERR PFX "unable to find a free 16-bit DMA\n");
434 /* non-PnP FM port address is hardwired with base port address */
435 fm_port[dev] = port[dev];
436 /* block the 0x388 port to avoid PnP conflicts */
437 acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
438 #ifdef SNDRV_SBAWE_EMU8000
439 /* non-PnP AWE port address is hardwired with base port address */
440 awe_port[dev] = port[dev] + 0x400;
446 if ((err = snd_sbdsp_create(card,
449 snd_sb16dsp_interrupt,
457 if (chip->hardware != SB_HW_16) {
459 snd_printdd("SB 16 chip was not detected at 0x%lx\n", port[dev]);
462 chip->mpu_port = mpu_port[dev];
464 if (!isapnp[dev] && (err = snd_sb16dsp_configure(chip)) < 0) {
466 if ((err = snd_sb16dsp_configure(chip)) < 0) {
471 if ((err = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
477 #ifdef SNDRV_SBAWE_EMU8000
478 awe_port[dev] > 0 ? "SB AWE" :
481 strcpy(card->shortname, chip->name);
482 sprintf(card->longname, "%s at 0x%lx, irq %i, dma ",
487 sprintf(card->longname + strlen(card->longname), "%d", xdma8);
489 sprintf(card->longname + strlen(card->longname), "%s%d",
490 xdma8 >= 0 ? "&" : "", xdma16);
492 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
493 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
495 xirq, 0, &chip->rmidi)) < 0) {
499 chip->rmidi_callback = snd_mpu401_uart_interrupt;
502 #ifdef SNDRV_SBAWE_EMU8000
503 if (awe_port[dev] == SNDRV_AUTO_PORT)
504 awe_port[dev] = 0; /* disable */
507 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
508 if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
510 acard->fm_res != NULL || fm_port[dev] == port[dev],
512 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
513 fm_port[dev], fm_port[dev] + 2);
515 #ifdef SNDRV_SBAWE_EMU8000
516 int seqdev = awe_port[dev] > 0 ? 2 : 1;
520 if ((err = snd_opl3_hwdep_new(opl3, 0, seqdev, &synth)) < 0) {
527 if ((err = snd_sbmixer_new(chip)) < 0) {
532 #ifdef CONFIG_SND_SB16_CSP
533 /* CSP chip on SB16ASP/AWE32 */
534 if ((chip->hardware == SB_HW_16) && csp[dev]) {
535 snd_sb_csp_new(chip, synth != NULL ? 1 : 0, &xcsp);
537 chip->csp = xcsp->private_data;
538 chip->hardware = SB_HW_16CSP;
540 snd_printk(KERN_INFO PFX "warning - CSP chip not detected on soundcard #%i\n", dev + 1);
544 #ifdef SNDRV_SBAWE_EMU8000
545 if (awe_port[dev] > 0) {
546 if (snd_emu8000_new(card, 1, awe_port[dev],
547 seq_ports[dev], NULL) < 0) {
548 snd_printk(KERN_ERR PFX "fatal error - EMU-8000 synthesizer not detected at 0x%lx\n", awe_port[dev]);
556 spin_lock_irqsave(&chip->mixer_lock, flags);
557 snd_sbmixer_write(chip, SB_DSP4_MIC_AGC,
558 (snd_sbmixer_read(chip, SB_DSP4_MIC_AGC) & 0x01) |
559 (mic_agc[dev] ? 0x00 : 0x01));
560 spin_unlock_irqrestore(&chip->mixer_lock, flags);
562 if ((err = snd_card_register(card)) < 0) {
567 pnp_set_card_drvdata(pcard, card);
569 snd_sb16_legacy[dev] = card;
573 static int __init snd_sb16_probe_legacy_port(unsigned long xport)
578 for ( ; dev < SNDRV_CARDS; dev++) {
579 if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
586 res = snd_sb16_probe(dev, NULL, NULL);
588 port[dev] = SNDRV_AUTO_PORT;
596 static int __devinit snd_sb16_pnp_detect(struct pnp_card_link *card,
597 const struct pnp_card_device_id *id)
602 for ( ; dev < SNDRV_CARDS; dev++) {
603 if (!enable[dev] || !isapnp[dev])
605 res = snd_sb16_probe(dev, card, id);
615 static void __devexit snd_sb16_pnp_remove(struct pnp_card_link * pcard)
617 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
619 snd_card_disconnect(card);
620 snd_card_free_in_thread(card);
623 static struct pnp_card_driver sb16_pnpc_driver = {
624 .flags = PNP_DRIVER_RES_DISABLE,
626 .id_table = snd_sb16_pnpids,
627 .probe = snd_sb16_pnp_detect,
628 .remove = __devexit_p(snd_sb16_pnp_remove),
631 #endif /* CONFIG_PNP */
633 static int __init alsa_card_sb16_init(void)
635 int dev, cards = 0, i;
636 static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280, -1};
638 /* legacy non-auto cards at first */
639 for (dev = 0; dev < SNDRV_CARDS; dev++) {
640 if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
646 if (!snd_sb16_probe(dev, NULL, NULL)) {
651 snd_printk(KERN_ERR "Sound Blaster 16+ soundcard #%i not found at 0x%lx or device busy\n", dev, port[dev]);
654 /* legacy auto configured cards */
655 i = snd_legacy_auto_probe(possible_ports, snd_sb16_probe_legacy_port);
660 /* PnP cards at last */
661 i = pnp_register_card_driver(&sb16_pnpc_driver);
668 pnp_unregister_card_driver(&sb16_pnpc_driver);
671 snd_printk(KERN_ERR "Sound Blaster 16 soundcard not found or device busy\n");
672 #ifdef SNDRV_SBAWE_EMU8000
673 snd_printk(KERN_ERR "In case, if you have non-AWE card, try snd-sb16 module\n");
675 snd_printk(KERN_ERR "In case, if you have AWE card, try snd-sbawe module\n");
683 static void __exit alsa_card_sb16_exit(void)
688 /* PnP cards first */
689 pnp_unregister_card_driver(&sb16_pnpc_driver);
691 for (dev = 0; dev < SNDRV_CARDS; dev++)
692 snd_card_free(snd_sb16_legacy[dev]);
695 module_init(alsa_card_sb16_init)
696 module_exit(alsa_card_sb16_exit)