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 Muizelaar 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/module.h>
23 #include <linux/dma-mapping.h>
24 #include <sound/initval.h>
26 // module parameters (see "Module Parameters")
27 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
28 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
29 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
30 static int pcifix
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 255 };
32 module_param_array(index
, int, NULL
, 0444);
33 MODULE_PARM_DESC(index
, "Index value for " CARD_NAME
" soundcard.");
34 module_param_array(id
, charp
, NULL
, 0444);
35 MODULE_PARM_DESC(id
, "ID string for " CARD_NAME
" soundcard.");
36 module_param_array(enable
, bool, NULL
, 0444);
37 MODULE_PARM_DESC(enable
, "Enable " CARD_NAME
" soundcard.");
38 module_param_array(pcifix
, int, NULL
, 0444);
39 MODULE_PARM_DESC(pcifix
, "Enable VIA-workaround for " CARD_NAME
" soundcard.");
41 MODULE_DESCRIPTION("Aureal vortex");
42 MODULE_LICENSE("GPL");
43 MODULE_SUPPORTED_DEVICE("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}");
45 MODULE_DEVICE_TABLE(pci
, snd_vortex_ids
);
47 static void vortex_fix_latency(struct pci_dev
*vortex
)
50 if (!(rc
= pci_write_config_byte(vortex
, 0x40, 0xff))) {
51 dev_info(&vortex
->dev
, "vortex latency is 0xff\n");
53 dev_warn(&vortex
->dev
,
54 "could not set vortex latency: pci error 0x%x\n", rc
);
58 static void vortex_fix_agp_bridge(struct pci_dev
*via
)
64 * only set the bit (Extend PCI#2 Internal Master for
65 * Efficient Handling of Dummy Requests) if the can
66 * read the config and it is not already set
69 if (!(rc
= pci_read_config_byte(via
, 0x42, &value
))
71 || !(rc
= pci_write_config_byte(via
, 0x42, value
| 0x10)))) {
72 dev_info(&via
->dev
, "bridge config is 0x%x\n", value
| 0x10);
75 "could not set vortex latency: pci error 0x%x\n", rc
);
79 static void snd_vortex_workaround(struct pci_dev
*vortex
, int fix
)
81 struct pci_dev
*via
= NULL
;
83 /* autodetect if workarounds are required */
86 via
= pci_get_device(PCI_VENDOR_ID_VIA
,
87 PCI_DEVICE_ID_VIA_8365_1
, NULL
);
90 via
= pci_get_device(PCI_VENDOR_ID_VIA
,
91 PCI_DEVICE_ID_VIA_82C598_1
, NULL
);
94 via
= pci_get_device(PCI_VENDOR_ID_AMD
,
95 PCI_DEVICE_ID_AMD_FE_GATE_7007
, NULL
);
98 dev_info(&vortex
->dev
,
99 "Activating latency workaround...\n");
100 vortex_fix_latency(vortex
);
101 vortex_fix_agp_bridge(via
);
105 vortex_fix_latency(vortex
);
106 if ((fix
& 0x2) && (via
= pci_get_device(PCI_VENDOR_ID_VIA
,
107 PCI_DEVICE_ID_VIA_8365_1
, NULL
)))
108 vortex_fix_agp_bridge(via
);
109 if ((fix
& 0x4) && (via
= pci_get_device(PCI_VENDOR_ID_VIA
,
110 PCI_DEVICE_ID_VIA_82C598_1
, NULL
)))
111 vortex_fix_agp_bridge(via
);
112 if ((fix
& 0x8) && (via
= pci_get_device(PCI_VENDOR_ID_AMD
,
113 PCI_DEVICE_ID_AMD_FE_GATE_7007
, NULL
)))
114 vortex_fix_agp_bridge(via
);
119 // component-destructor
120 // (see "Management of Cards and Components")
121 static int snd_vortex_dev_free(struct snd_device
*device
)
123 vortex_t
*vortex
= device
->device_data
;
125 vortex_gameport_unregister(vortex
);
126 vortex_core_shutdown(vortex
);
127 // Take down PCI interface.
128 free_irq(vortex
->irq
, vortex
);
129 iounmap(vortex
->mmio
);
130 pci_release_regions(vortex
->pci_dev
);
131 pci_disable_device(vortex
->pci_dev
);
137 // chip-specific constructor
138 // (see "Management of Cards and Components")
140 snd_vortex_create(struct snd_card
*card
, struct pci_dev
*pci
, vortex_t
** rchip
)
144 static struct snd_device_ops ops
= {
145 .dev_free
= snd_vortex_dev_free
,
150 // check PCI availability (DMA).
151 if ((err
= pci_enable_device(pci
)) < 0)
153 if (dma_set_mask(&pci
->dev
, DMA_BIT_MASK(32)) < 0 ||
154 dma_set_coherent_mask(&pci
->dev
, DMA_BIT_MASK(32)) < 0) {
155 dev_err(card
->dev
, "error to set DMA mask\n");
156 pci_disable_device(pci
);
160 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
162 pci_disable_device(pci
);
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)
182 chip
->mmio
= pci_ioremap_bar(pci
, 0);
184 dev_err(card
->dev
, "MMIO area remap failed.\n");
190 * This must be done before we do request_irq otherwise we can get spurious
191 * interrupts that we do not handle properly and make a mess of things */
192 if ((err
= vortex_core_init(chip
)) != 0) {
193 dev_err(card
->dev
, "hw core init failed\n");
197 if ((err
= request_irq(pci
->irq
, vortex_interrupt
,
198 IRQF_SHARED
, KBUILD_MODNAME
,
200 dev_err(card
->dev
, "cannot grab irq\n");
203 chip
->irq
= pci
->irq
;
208 // Register alsa root device.
209 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
218 free_irq(chip
->irq
, chip
);
220 vortex_core_shutdown(chip
);
224 pci_release_regions(chip
->pci_dev
);
226 pci_disable_device(chip
->pci_dev
);
227 //FIXME: this not the right place to unregister the gameport
228 vortex_gameport_unregister(chip
);
233 // constructor -- see "Constructor" sub-section
235 snd_vortex_probe(struct pci_dev
*pci
, const struct pci_device_id
*pci_id
)
238 struct snd_card
*card
;
243 if (dev
>= SNDRV_CARDS
)
250 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
256 if ((err
= snd_vortex_create(card
, pci
, &chip
)) < 0) {
260 snd_vortex_workaround(pci
, pcifix
[dev
]);
262 // Card details needed in snd_vortex_midi
263 strcpy(card
->driver
, CARD_NAME_SHORT
);
264 sprintf(card
->shortname
, "Aureal Vortex %s", CARD_NAME_SHORT
);
265 sprintf(card
->longname
, "%s at 0x%lx irq %i",
266 card
->shortname
, chip
->io
, chip
->irq
);
268 // (4) Alloc components.
269 err
= snd_vortex_mixer(chip
);
275 err
= snd_vortex_new_pcm(chip
, VORTEX_PCM_ADB
, NR_PCM
);
282 if ((err
= snd_vortex_new_pcm(chip
, VORTEX_PCM_SPDIF
, 1)) < 0) {
287 if ((err
= snd_vortex_new_pcm(chip
, VORTEX_PCM_A3D
, NR_A3D
)) < 0) {
294 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) {
301 if ((err
= snd_vortex_new_pcm(chip
, VORTEX_PCM_WT
, NR_WT
)) < 0) {
306 if ((err
= snd_vortex_midi(chip
)) < 0) {
311 vortex_gameport_register(chip
);
314 if (snd_seq_device_new(card
, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH
,
315 sizeof(snd_vortex_synth_arg_t
), &wave
) < 0
317 dev_err(card
->dev
, "Can't initialize Aureal wavetable synth\n");
319 snd_vortex_synth_arg_t
*arg
;
321 arg
= SNDRV_SEQ_DEVICE_ARGPTR(wave
);
322 strcpy(wave
->name
, "Aureal Synth");
325 arg
->seq_ports
= seq_ports
[dev
];
326 arg
->max_voices
= max_synth_voices
[dev
];
331 if ((err
= pci_read_config_word(pci
, PCI_DEVICE_ID
,
332 &(chip
->device
))) < 0) {
336 if ((err
= pci_read_config_word(pci
, PCI_VENDOR_ID
,
337 &(chip
->vendor
))) < 0) {
341 chip
->rev
= pci
->revision
;
343 if ((chip
->rev
) != 0xfe && (chip
->rev
) != 0xfa) {
345 "The revision (%x) of your card has not been seen before.\n",
348 "Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
356 if ((err
= snd_card_register(card
)) < 0) {
361 pci_set_drvdata(pci
, card
);
363 vortex_connect_default(chip
, 1);
364 vortex_enable_int(chip
);
368 // destructor -- see "Destructor" sub-section
369 static void snd_vortex_remove(struct pci_dev
*pci
)
371 snd_card_free(pci_get_drvdata(pci
));
374 // pci_driver definition
375 static struct pci_driver vortex_driver
= {
376 .name
= KBUILD_MODNAME
,
377 .id_table
= snd_vortex_ids
,
378 .probe
= snd_vortex_probe
,
379 .remove
= snd_vortex_remove
,
382 module_pci_driver(vortex_driver
);