1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for SoundBlaster 1.0/2.0/Pro soundcards and compatible
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
7 #include <linux/init.h>
10 #include <linux/ioport.h>
11 #include <linux/module.h>
12 #include <sound/core.h>
14 #include <sound/opl3.h>
15 #include <sound/initval.h>
17 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
18 MODULE_DESCRIPTION("Sound Blaster 1.0/2.0/Pro");
19 MODULE_LICENSE("GPL");
21 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
22 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
23 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
24 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
25 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
26 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3 */
28 module_param_array(index, int, NULL, 0444);
29 MODULE_PARM_DESC(index, "Index value for Sound Blaster soundcard.");
30 module_param_array(id, charp, NULL, 0444);
31 MODULE_PARM_DESC(id, "ID string for Sound Blaster soundcard.");
32 module_param_array(enable, bool, NULL, 0444);
33 MODULE_PARM_DESC(enable, "Enable Sound Blaster soundcard.");
34 module_param_hw_array(port, long, ioport, NULL, 0444);
35 MODULE_PARM_DESC(port, "Port # for SB8 driver.");
36 module_param_hw_array(irq, int, irq, NULL, 0444);
37 MODULE_PARM_DESC(irq, "IRQ # for SB8 driver.");
38 module_param_hw_array(dma8, int, dma, NULL, 0444);
39 MODULE_PARM_DESC(dma8, "8-bit DMA # for SB8 driver.");
42 struct resource *fm_res; /* used to block FM i/o region for legacy cards */
46 static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id)
48 struct snd_sb *chip = dev_id;
50 if (chip->open & SB_OPEN_PCM) {
51 return snd_sb8dsp_interrupt(chip);
53 return snd_sb8dsp_midi_interrupt(chip);
57 static void snd_sb8_free(struct snd_card *card)
59 struct snd_sb8 *acard = card->private_data;
63 release_and_free_resource(acard->fm_res);
66 static int snd_sb8_match(struct device *pdev, unsigned int dev)
70 if (irq[dev] == SNDRV_AUTO_IRQ) {
71 dev_err(pdev, "please specify irq\n");
74 if (dma8[dev] == SNDRV_AUTO_DMA) {
75 dev_err(pdev, "please specify dma8\n");
81 static int snd_sb8_probe(struct device *pdev, unsigned int dev)
84 struct snd_card *card;
85 struct snd_sb8 *acard;
86 struct snd_opl3 *opl3;
89 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
90 sizeof(struct snd_sb8), &card);
93 acard = card->private_data;
94 card->private_free = snd_sb8_free;
97 * Block the 0x388 port to avoid PnP conflicts.
98 * No need to check this value after request_region,
99 * as we never do anything with it.
101 acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
103 if (port[dev] != SNDRV_AUTO_PORT) {
104 if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
112 /* auto-probe legacy ports */
113 static const unsigned long possible_ports[] = {
117 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
118 err = snd_sbdsp_create(card, possible_ports[i],
126 port[dev] = possible_ports[i];
130 if (i >= ARRAY_SIZE(possible_ports)) {
137 if (chip->hardware >= SB_HW_16) {
138 if (chip->hardware == SB_HW_ALS100)
139 snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n",
142 snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
148 if ((err = snd_sb8dsp_pcm(chip, 0)) < 0)
151 if ((err = snd_sbmixer_new(chip)) < 0)
154 if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
155 if ((err = snd_opl3_create(card, chip->port + 8, 0,
158 snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
161 if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
164 snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
165 chip->port, chip->port + 2);
169 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
173 if ((err = snd_sb8dsp_midi(chip, 0)) < 0)
176 strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
177 strcpy(card->shortname, chip->name);
178 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
181 irq[dev], dma8[dev]);
183 if ((err = snd_card_register(card)) < 0)
186 dev_set_drvdata(pdev, card);
194 static void snd_sb8_remove(struct device *pdev, unsigned int dev)
196 snd_card_free(dev_get_drvdata(pdev));
200 static int snd_sb8_suspend(struct device *dev, unsigned int n,
203 struct snd_card *card = dev_get_drvdata(dev);
204 struct snd_sb8 *acard = card->private_data;
205 struct snd_sb *chip = acard->chip;
207 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
208 snd_sbmixer_suspend(chip);
212 static int snd_sb8_resume(struct device *dev, unsigned int n)
214 struct snd_card *card = dev_get_drvdata(dev);
215 struct snd_sb8 *acard = card->private_data;
216 struct snd_sb *chip = acard->chip;
218 snd_sbdsp_reset(chip);
219 snd_sbmixer_resume(chip);
220 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
225 #define DEV_NAME "sb8"
227 static struct isa_driver snd_sb8_driver = {
228 .match = snd_sb8_match,
229 .probe = snd_sb8_probe,
230 .remove = snd_sb8_remove,
232 .suspend = snd_sb8_suspend,
233 .resume = snd_sb8_resume,
240 module_isa_driver(snd_sb8_driver, SNDRV_CARDS);