1 // SPDX-License-Identifier: GPL-2.0-only
3 * ALSA driver for the Aureal Vortex family of soundprocessors.
4 * Author: Manuel Jander (mjander@embedded.cl)
6 * This driver is the result of the OpenVortex Project from Savannah
7 * (savannah.nongnu.org/projects/openvortex). I would like to thank
8 * the developers of OpenVortex, Jeff Muizelaar and Kester Maddock, from
9 * whom i got plenty of help, and their codebase was invaluable.
10 * Thanks to the ALSA developers, they helped a lot working out
12 * Thanks also to Sourceforge for maintaining the old binary drivers,
13 * and the forum, where developers could comunicate.
15 * Now at least i can play Legacy DOOM with MIDI music :-)
19 #include <linux/init.h>
20 #include <linux/pci.h>
21 #include <linux/slab.h>
22 #include <linux/interrupt.h>
23 #include <linux/module.h>
24 #include <linux/dma-mapping.h>
25 #include <sound/initval.h>
27 // module parameters (see "Module Parameters")
28 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
29 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
30 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
31 static int pcifix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 255 };
33 module_param_array(index, int, NULL, 0444);
34 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
35 module_param_array(id, charp, NULL, 0444);
36 MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
37 module_param_array(enable, bool, NULL, 0444);
38 MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
39 module_param_array(pcifix, int, NULL, 0444);
40 MODULE_PARM_DESC(pcifix, "Enable VIA-workaround for " CARD_NAME " soundcard.");
42 MODULE_DESCRIPTION("Aureal vortex");
43 MODULE_LICENSE("GPL");
44 MODULE_SUPPORTED_DEVICE("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}");
46 MODULE_DEVICE_TABLE(pci, snd_vortex_ids);
48 static void vortex_fix_latency(struct pci_dev *vortex)
51 if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) {
52 dev_info(&vortex->dev, "vortex latency is 0xff\n");
54 dev_warn(&vortex->dev,
55 "could not set vortex latency: pci error 0x%x\n", rc);
59 static void vortex_fix_agp_bridge(struct pci_dev *via)
65 * only set the bit (Extend PCI#2 Internal Master for
66 * Efficient Handling of Dummy Requests) if the can
67 * read the config and it is not already set
70 if (!(rc = pci_read_config_byte(via, 0x42, &value))
72 || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) {
73 dev_info(&via->dev, "bridge config is 0x%x\n", value | 0x10);
76 "could not set vortex latency: pci error 0x%x\n", rc);
80 static void snd_vortex_workaround(struct pci_dev *vortex, int fix)
82 struct pci_dev *via = NULL;
84 /* autodetect if workarounds are required */
87 via = pci_get_device(PCI_VENDOR_ID_VIA,
88 PCI_DEVICE_ID_VIA_8365_1, NULL);
91 via = pci_get_device(PCI_VENDOR_ID_VIA,
92 PCI_DEVICE_ID_VIA_82C598_1, NULL);
95 via = pci_get_device(PCI_VENDOR_ID_AMD,
96 PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL);
99 dev_info(&vortex->dev,
100 "Activating latency workaround...\n");
101 vortex_fix_latency(vortex);
102 vortex_fix_agp_bridge(via);
106 vortex_fix_latency(vortex);
107 if ((fix & 0x2) && (via = pci_get_device(PCI_VENDOR_ID_VIA,
108 PCI_DEVICE_ID_VIA_8365_1, NULL)))
109 vortex_fix_agp_bridge(via);
110 if ((fix & 0x4) && (via = pci_get_device(PCI_VENDOR_ID_VIA,
111 PCI_DEVICE_ID_VIA_82C598_1, NULL)))
112 vortex_fix_agp_bridge(via);
113 if ((fix & 0x8) && (via = pci_get_device(PCI_VENDOR_ID_AMD,
114 PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL)))
115 vortex_fix_agp_bridge(via);
120 // component-destructor
121 // (see "Management of Cards and Components")
122 static int snd_vortex_dev_free(struct snd_device *device)
124 vortex_t *vortex = device->device_data;
126 vortex_gameport_unregister(vortex);
127 vortex_core_shutdown(vortex);
128 // Take down PCI interface.
129 free_irq(vortex->irq, vortex);
130 iounmap(vortex->mmio);
131 pci_release_regions(vortex->pci_dev);
132 pci_disable_device(vortex->pci_dev);
138 // chip-specific constructor
139 // (see "Management of Cards and Components")
141 snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
145 static struct snd_device_ops ops = {
146 .dev_free = snd_vortex_dev_free,
151 // check PCI availability (DMA).
152 if ((err = pci_enable_device(pci)) < 0)
154 if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 ||
155 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) {
156 dev_err(card->dev, "error to set DMA mask\n");
157 pci_disable_device(pci);
161 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
163 pci_disable_device(pci);
169 // initialize the stuff
171 chip->io = pci_resource_start(pci, 0);
172 chip->vendor = pci->vendor;
173 chip->device = pci->device;
177 // (1) PCI resource allocation
180 if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0)
183 chip->mmio = pci_ioremap_bar(pci, 0);
185 dev_err(card->dev, "MMIO area remap failed.\n");
191 * This must be done before we do request_irq otherwise we can get spurious
192 * interrupts that we do not handle properly and make a mess of things */
193 if ((err = vortex_core_init(chip)) != 0) {
194 dev_err(card->dev, "hw core init failed\n");
198 if ((err = request_irq(pci->irq, vortex_interrupt,
199 IRQF_SHARED, KBUILD_MODNAME,
201 dev_err(card->dev, "cannot grab irq\n");
204 chip->irq = pci->irq;
209 // Register alsa root device.
210 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
219 free_irq(chip->irq, chip);
221 vortex_core_shutdown(chip);
225 pci_release_regions(chip->pci_dev);
227 pci_disable_device(chip->pci_dev);
228 //FIXME: this not the right place to unregister the gameport
229 vortex_gameport_unregister(chip);
234 // constructor -- see "Constructor" sub-section
236 snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
239 struct snd_card *card;
244 if (dev >= SNDRV_CARDS)
251 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
257 if ((err = snd_vortex_create(card, pci, &chip)) < 0) {
261 snd_vortex_workaround(pci, pcifix[dev]);
263 // Card details needed in snd_vortex_midi
264 strcpy(card->driver, CARD_NAME_SHORT);
265 sprintf(card->shortname, "Aureal Vortex %s", CARD_NAME_SHORT);
266 sprintf(card->longname, "%s at 0x%lx irq %i",
267 card->shortname, chip->io, chip->irq);
269 // (4) Alloc components.
270 err = snd_vortex_mixer(chip);
276 err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_PCM);
283 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) {
288 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D)) < 0) {
295 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) {
302 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) {
307 if ((err = snd_vortex_midi(chip)) < 0) {
312 vortex_gameport_register(chip);
315 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
316 sizeof(snd_vortex_synth_arg_t), &wave) < 0
318 dev_err(card->dev, "Can't initialize Aureal wavetable synth\n");
320 snd_vortex_synth_arg_t *arg;
322 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
323 strcpy(wave->name, "Aureal Synth");
326 arg->seq_ports = seq_ports[dev];
327 arg->max_voices = max_synth_voices[dev];
332 if ((err = pci_read_config_word(pci, PCI_DEVICE_ID,
333 &(chip->device))) < 0) {
337 if ((err = pci_read_config_word(pci, PCI_VENDOR_ID,
338 &(chip->vendor))) < 0) {
342 chip->rev = pci->revision;
344 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) {
346 "The revision (%x) of your card has not been seen before.\n",
349 "Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
357 if ((err = snd_card_register(card)) < 0) {
362 pci_set_drvdata(pci, card);
364 vortex_connect_default(chip, 1);
365 vortex_enable_int(chip);
369 // destructor -- see "Destructor" sub-section
370 static void snd_vortex_remove(struct pci_dev *pci)
372 snd_card_free(pci_get_drvdata(pci));
375 // pci_driver definition
376 static struct pci_driver vortex_driver = {
377 .name = KBUILD_MODNAME,
378 .id_table = snd_vortex_ids,
379 .probe = snd_vortex_probe,
380 .remove = snd_vortex_remove,
383 module_pci_driver(vortex_driver);