1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for SoundBlaster 1.0/2.0/Pro soundcards and compatible
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>
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 int snd_sb8_match(struct device *pdev, unsigned int dev)
61 if (irq[dev] == SNDRV_AUTO_IRQ) {
62 dev_err(pdev, "please specify irq\n");
65 if (dma8[dev] == SNDRV_AUTO_DMA) {
66 dev_err(pdev, "please specify dma8\n");
72 static int snd_sb8_probe(struct device *pdev, unsigned int dev)
75 struct snd_card *card;
76 struct snd_sb8 *acard;
77 struct snd_opl3 *opl3;
80 err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
81 sizeof(struct snd_sb8), &card);
84 acard = card->private_data;
87 * Block the 0x388 port to avoid PnP conflicts.
88 * No need to check this value after request_region,
89 * as we never do anything with it.
91 acard->fm_res = devm_request_region(card->dev, 0x388, 4,
94 if (port[dev] != SNDRV_AUTO_PORT) {
95 err = snd_sbdsp_create(card, port[dev], irq[dev],
96 snd_sb8_interrupt, dma8[dev],
97 -1, SB_HW_AUTO, &chip);
101 /* auto-probe legacy ports */
102 static const unsigned long possible_ports[] = {
106 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
107 err = snd_sbdsp_create(card, possible_ports[i],
115 port[dev] = possible_ports[i];
119 if (i >= ARRAY_SIZE(possible_ports))
124 if (chip->hardware >= SB_HW_16) {
125 if (chip->hardware == SB_HW_ALS100)
126 snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n",
129 snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
134 err = snd_sb8dsp_pcm(chip, 0);
138 err = snd_sbmixer_new(chip);
142 if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
143 err = snd_opl3_create(card, chip->port + 8, 0,
144 OPL3_HW_AUTO, 1, &opl3);
146 snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
148 err = snd_opl3_create(card, chip->port, chip->port + 2,
149 OPL3_HW_AUTO, 1, &opl3);
151 snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
152 chip->port, chip->port + 2);
156 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
161 err = snd_sb8dsp_midi(chip, 0);
165 strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
166 strcpy(card->shortname, chip->name);
167 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
170 irq[dev], dma8[dev]);
172 err = snd_card_register(card);
176 dev_set_drvdata(pdev, card);
181 static int snd_sb8_suspend(struct device *dev, unsigned int n,
184 struct snd_card *card = dev_get_drvdata(dev);
185 struct snd_sb8 *acard = card->private_data;
186 struct snd_sb *chip = acard->chip;
188 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
189 snd_sbmixer_suspend(chip);
193 static int snd_sb8_resume(struct device *dev, unsigned int n)
195 struct snd_card *card = dev_get_drvdata(dev);
196 struct snd_sb8 *acard = card->private_data;
197 struct snd_sb *chip = acard->chip;
199 snd_sbdsp_reset(chip);
200 snd_sbmixer_resume(chip);
201 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
206 #define DEV_NAME "sb8"
208 static struct isa_driver snd_sb8_driver = {
209 .match = snd_sb8_match,
210 .probe = snd_sb8_probe,
212 .suspend = snd_sb8_suspend,
213 .resume = snd_sb8_resume,
220 module_isa_driver(snd_sb8_driver, SNDRV_CARDS);