2 * ALSA driver for the Aureal Vortex family of soundprocessors.
3 * Author: Manuel Jander (mjander@embedded.cl)
5 * This driver is the result of the OpenVortex Project from Savannah
6 * (savannah.nongnu.org/projects/openvortex). I would like to thank
7 * the developers of OpenVortex, Jeff Muizelar and Kester Maddock, from
8 * whom i got plenty of help, and their codebase was invaluable.
9 * Thanks to the ALSA developers, they helped a lot working out
11 * Thanks also to Sourceforge for maintaining the old binary drivers,
12 * and the forum, where developers could comunicate.
14 * Now at least i can play Legacy DOOM with MIDI music :-)
18 #include <linux/init.h>
19 #include <linux/pci.h>
20 #include <linux/slab.h>
21 #include <linux/interrupt.h>
22 #include <linux/moduleparam.h>
23 #include <sound/initval.h>
25 // module parameters (see "Module Parameters")
26 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
27 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
28 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
29 static int pcifix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 255 };
32 module_param_array(index, int, boot_devs, 0444);
33 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
34 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
35 module_param_array(id, charp, boot_devs, 0444);
36 MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
37 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
38 module_param_array(enable, bool, boot_devs, 0444);
39 MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
40 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
41 module_param_array(pcifix, int, boot_devs, 0444);
42 MODULE_PARM_DESC(pcifix, "Enable VIA-workaround for " CARD_NAME " soundcard.");
43 MODULE_PARM_SYNTAX(pcifix,
45 ",allows:{{0,Disabled},{1,Latency},{2,Bridge},{3,Both},{255,Auto}},default:4,dialog:check");
47 MODULE_DESCRIPTION("Aureal vortex");
48 MODULE_CLASSES("{sound}");
49 MODULE_LICENSE("GPL");
50 MODULE_DEVICES("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}");
52 MODULE_DEVICE_TABLE(pci, snd_vortex_ids);
54 static void vortex_fix_latency(struct pci_dev *vortex)
57 if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) {
58 printk(KERN_INFO CARD_NAME
59 ": vortex latency is 0xff\n");
61 printk(KERN_WARNING CARD_NAME
62 ": could not set vortex latency: pci error 0x%x\n", rc);
66 static void vortex_fix_agp_bridge(struct pci_dev *via)
72 * only set the bit (Extend PCI#2 Internal Master for
73 * Efficient Handling of Dummy Requests) if the can
74 * read the config and it is not already set
77 if (!(rc = pci_read_config_byte(via, 0x42, &value))
79 || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) {
80 printk(KERN_INFO CARD_NAME
81 ": bridge config is 0x%x\n", value | 0x10);
83 printk(KERN_WARNING CARD_NAME
84 ": could not set vortex latency: pci error 0x%x\n", rc);
88 static void __devinit snd_vortex_workaround(struct pci_dev *vortex, int fix)
92 /* autodetect if workarounds are required */
95 via = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8365_1, NULL);
98 via = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C598_1, NULL);
102 via = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL);
105 printk(KERN_INFO CARD_NAME ": Activating latency workaround...\n");
106 vortex_fix_latency(vortex);
107 vortex_fix_agp_bridge(via);
111 vortex_fix_latency(vortex);
112 if ((fix & 0x2) && (via = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8365_1, NULL)))
113 vortex_fix_agp_bridge(via);
114 if ((fix & 0x4) && (via = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C598_1, NULL)))
115 vortex_fix_agp_bridge(via);
116 if ((fix & 0x8) && (via = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL)))
117 vortex_fix_agp_bridge(via);
121 // component-destructor
122 // (see "Management of Cards and Components")
123 static int snd_vortex_dev_free(snd_device_t * device)
125 vortex_t *vortex = snd_magic_cast(vortex_t, device->device_data,
128 vortex_gameport_unregister(vortex);
129 vortex_core_shutdown(vortex);
130 // Take down PCI interface.
131 synchronize_irq(vortex->irq);
132 free_irq(vortex->irq, vortex);
133 pci_release_regions(vortex->pci_dev);
134 pci_disable_device(vortex->pci_dev);
135 snd_magic_kfree(vortex);
140 // chip-specific constructor
141 // (see "Management of Cards and Components")
143 snd_vortex_create(snd_card_t * card, struct pci_dev *pci, vortex_t ** rchip)
147 static snd_device_ops_t ops = {
148 .dev_free = snd_vortex_dev_free,
153 // check PCI availability (DMA).
154 if ((err = pci_enable_device(pci)) < 0)
156 if (!pci_dma_supported(pci, VORTEX_DMA_MASK)) {
157 printk(KERN_ERR "error to set DMA mask\n");
160 pci_set_dma_mask(pci, VORTEX_DMA_MASK);
162 chip = snd_magic_kcalloc(vortex_t, 0, GFP_KERNEL);
168 // initialize the stuff
170 chip->io = pci_resource_start(pci, 0);
171 chip->vendor = pci->vendor;
172 chip->device = pci->device;
176 // (1) PCI resource allocation
179 if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0)
183 ioremap_nocache(pci_resource_start(pci, 0),
184 pci_resource_len(pci, 0));
186 printk(KERN_ERR "MMIO area remap failed.\n");
192 * This must be done before we do request_irq otherwise we can get spurious
193 * interupts that we do not handle properly and make a mess of things */
194 if ((err = vortex_core_init(chip)) != 0) {
195 printk(KERN_ERR "hw core init failed\n");
200 request_irq(pci->irq, vortex_interrupt,
201 SA_INTERRUPT | SA_SHIRQ, CARD_NAME_SHORT,
202 (void *)chip)) != 0) {
203 printk(KERN_ERR "cannot grab irq\n");
206 chip->irq = pci->irq;
211 // Register alsa root device.
212 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
221 synchronize_irq(chip->irq);
222 free_irq(chip->irq, chip);
224 vortex_core_shutdown(chip);
226 //FIXME: the type of chip->mmio might need to be changed??
227 iounmap((void *)chip->mmio);
229 pci_release_regions(chip->pci_dev);
231 pci_disable_device(chip->pci_dev);
232 //FIXME: this not the right place to unregister the gameport
233 vortex_gameport_unregister(chip);
237 // constructor -- see "Constructor" sub-section
239 snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
247 if (dev >= SNDRV_CARDS)
254 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
259 if ((err = snd_vortex_create(card, pci, &chip)) < 0) {
263 snd_vortex_workaround(pci, pcifix[dev]);
264 // (4) Alloc components.
266 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_ADB)) < 0) {
272 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) {
277 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D)) < 0) {
284 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) {
291 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) {
296 // snd_ac97_mixer and Vortex mixer.
297 if ((err = snd_vortex_mixer(chip)) < 0) {
301 if ((err = snd_vortex_midi(chip)) < 0) {
305 if ((err = vortex_gameport_register(chip)) < 0) {
310 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
311 sizeof(snd_vortex_synth_arg_t), &wave) < 0
313 snd_printk("Can't initialize Aureal wavetable synth\n");
315 snd_vortex_synth_arg_t *arg;
317 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
318 strcpy(wave->name, "Aureal Synth");
321 arg->seq_ports = seq_ports[dev];
322 arg->max_voices = max_synth_voices[dev];
327 strcpy(card->driver, "Aureal Vortex");
328 strcpy(card->shortname, CARD_NAME_SHORT);
329 sprintf(card->longname, "%s at 0x%lx irq %i",
330 card->shortname, chip->io, chip->irq);
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 if ((err = pci_read_config_byte(pci, PCI_REVISION_ID,
343 &(chip->rev))) < 0) {
348 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) {
350 "vortex: The revision (%x) of your card has not been seen before.\n",
353 "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
361 if ((err = snd_card_register(card)) < 0) {
366 pci_set_drvdata(pci, card);
368 vortex_connect_default(chip, 1);
369 vortex_enable_int(chip);
373 // destructor -- see "Destructor" sub-section
374 static void __devexit snd_vortex_remove(struct pci_dev *pci)
376 snd_card_free(pci_get_drvdata(pci));
377 pci_set_drvdata(pci, NULL);
380 // pci_driver definition
381 static struct pci_driver driver = {
382 .name = CARD_NAME_SHORT,
383 .id_table = snd_vortex_ids,
384 .probe = snd_vortex_probe,
385 .remove = __devexit_p(snd_vortex_remove),
388 // initialization of the module
389 static int __init alsa_card_vortex_init(void)
391 return pci_module_init(&driver);
394 // clean up the module
395 static void __exit alsa_card_vortex_exit(void)
397 pci_unregister_driver(&driver);
400 module_init(alsa_card_vortex_init)
401 module_exit(alsa_card_vortex_exit)