1 | /*
|
---|
2 | * ALSA driver for the Aureal Vortex family of soundprocessors.
|
---|
3 | * Author: Manuel Jander (mjander@embedded.cl)
|
---|
4 | *
|
---|
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
|
---|
10 | * the ALSA part.
|
---|
11 | * Thanks also to Sourceforge for maintaining the old binary drivers,
|
---|
12 | * and the forum, where developers could comunicate.
|
---|
13 | *
|
---|
14 | * Now at least i can play Legacy DOOM with MIDI music :-)
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include "au88x0.h"
|
---|
18 | #include <linux/init.h>
|
---|
19 | #include <linux/pci.h>
|
---|
20 | #include <linux/slab.h>
|
---|
21 | #include <linux/interrupt.h>
|
---|
22 | #define SNDRV_GET_ID
|
---|
23 | #include <sound/initval.h>
|
---|
24 |
|
---|
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 |
|
---|
30 | MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
31 | MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
|
---|
32 | MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
|
---|
33 | MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
---|
34 | MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
|
---|
35 | MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
|
---|
36 | MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
37 | MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
|
---|
38 | MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
|
---|
39 |
|
---|
40 | MODULE_DESCRIPTION("Aureal vortex");
|
---|
41 | MODULE_CLASSES("{sound}");
|
---|
42 | MODULE_LICENSE("GPL");
|
---|
43 | MODULE_DEVICES("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}");
|
---|
44 |
|
---|
45 | static struct pci_device_id snd_vortex_ids[] = {
|
---|
46 | {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1,},
|
---|
47 | {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
|
---|
48 | {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
|
---|
49 | {0,}
|
---|
50 | };
|
---|
51 |
|
---|
52 | #ifndef MODULE
|
---|
53 | /* format is: snd-mychip=enable,index,id */
|
---|
54 | static int __init alsa_card_vortex_setup(char *str) {
|
---|
55 | static unsigned __initdata nr_dev = 0;
|
---|
56 |
|
---|
57 | if (nr_dev >= SNDRV_CARDS)
|
---|
58 | return 0;
|
---|
59 | (void) (get_option(&str, &enable[nr_dev]) == 2 &&
|
---|
60 | get_option(&str, &index[nr_dev]) == 2 &&
|
---|
61 | get_id(&str, &id[nr_dev]) == 2);
|
---|
62 | nr_dev++;
|
---|
63 | return 1;
|
---|
64 | }
|
---|
65 | __setup("snd-au88x0=", alsa_card_vortex_setup);
|
---|
66 | #endif /* ifndef MODULE */
|
---|
67 |
|
---|
68 |
|
---|
69 | MODULE_DEVICE_TABLE(pci, snd_vortex_ids);
|
---|
70 | #define PCI_DEVICE_ID_VIA_8365_1 0x8305
|
---|
71 | #define PCI_VENDOR_ID_VIA 0x1106
|
---|
72 | static void __devinit snd_vortex_workaround(struct pci_dev *vortex, int fix) {
|
---|
73 | struct pci_dev *via=NULL;
|
---|
74 | int rc;
|
---|
75 | /* autodetect if workarounds are required */
|
---|
76 | while( (via = pci_find_device(PCI_VENDOR_ID_VIA,
|
---|
77 | PCI_DEVICE_ID_VIA_8365_1, via)) ) {
|
---|
78 | if(fix == 255) {
|
---|
79 | printk("detected VIA KT133/KM133. activating workaround...\n");
|
---|
80 | fix = 3; // do latency and via bridge workaround
|
---|
81 | }
|
---|
82 | break;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* fix vortex latency */
|
---|
86 | if(fix & 0x01) {
|
---|
87 | if( !(rc = pci_write_config_byte(vortex, 0x40, 0xff)) ) {
|
---|
88 | printk("vortex latency is 0xff\n");
|
---|
89 | }
|
---|
90 | else {
|
---|
91 | printk("could not set vortex latency: pci error 0x%x\n", rc);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | /* fix via agp bridge */
|
---|
96 | if(via && (fix & 0x02)) {
|
---|
97 | u8 value;
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * only set the bit (Extend PCI#2 Internal Master for
|
---|
101 | * Efficient Handling of Dummy Requests) if the can
|
---|
102 | * read the config and it is not already set
|
---|
103 | */
|
---|
104 |
|
---|
105 | if( !(rc = pci_read_config_byte(via, 0x42, &value)) && (
|
---|
106 | (value & 0x10) ||
|
---|
107 | !(rc=pci_write_config_byte(via, 0x42, value|0x10)) ) ) {
|
---|
108 |
|
---|
109 | printk("bridge config is 0x%x\n", value|0x10);
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | printk("could not set vortex latency: pci error 0x%x\n", rc);
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | // component-destructor
|
---|
118 | // (see "Management of Cards and Components")
|
---|
119 | static int snd_vortex_dev_free(snd_device_t *device) {
|
---|
120 | vortex_t *vortex = snd_magic_cast(vortex_t, device->device_data,
|
---|
121 | return -ENXIO);
|
---|
122 |
|
---|
123 | #if defined(CONFIG_GAMEPORT)
|
---|
124 | vortex_gameport_unregister(vortex);
|
---|
125 | #endif
|
---|
126 | vortex_core_shutdown(vortex);
|
---|
127 | // Take down PCI interface.
|
---|
128 | synchronize_irq(vortex->irq);
|
---|
129 | free_irq(vortex->irq, vortex);
|
---|
130 | // pci_release_regions(vortex->pci_dev);
|
---|
131 | // pci_disable_device(vortex->pci_dev);
|
---|
132 | snd_magic_kfree(vortex);
|
---|
133 |
|
---|
134 | return 0;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // chip-specific constructor
|
---|
138 | // (see "Management of Cards and Components")
|
---|
139 | static int __devinit
|
---|
140 | snd_vortex_create(snd_card_t *card, struct pci_dev *pci, vortex_t **rchip) {
|
---|
141 | vortex_t *chip;
|
---|
142 | int err;
|
---|
143 | struct resource * reg_temp;
|
---|
144 | unsigned long res;
|
---|
145 | static snd_device_ops_t ops = {
|
---|
146 | snd_vortex_dev_free,0,0,0
|
---|
147 | };
|
---|
148 |
|
---|
149 | *rchip = NULL;
|
---|
150 |
|
---|
151 | // check PCI availability (DMA).
|
---|
152 | if ((err = pci_enable_device(pci)) < 0)
|
---|
153 | return err;
|
---|
154 | if (!pci_dma_supported(pci, VORTEX_DMA_MASK)) {
|
---|
155 | printk(KERN_ERR "error to set DMA mask\n");
|
---|
156 | return -ENXIO;
|
---|
157 | }
|
---|
158 | pci_set_dma_mask(pci, VORTEX_DMA_MASK);
|
---|
159 |
|
---|
160 | chip = snd_magic_kcalloc(vortex_t, 0, GFP_KERNEL);
|
---|
161 | if (chip == NULL)
|
---|
162 | return -ENOMEM;
|
---|
163 |
|
---|
164 | chip->card = card;
|
---|
165 |
|
---|
166 | // initialize the stuff
|
---|
167 | chip->pci_dev = pci;
|
---|
168 | chip->io = pci_resource_start(pci, 0);
|
---|
169 | chip->vendor = pci->vendor;
|
---|
170 | chip->device = pci->device;
|
---|
171 | chip->card = card;
|
---|
172 | chip->irq = -1;
|
---|
173 | spin_lock_init(&chip->lock);
|
---|
174 |
|
---|
175 | // (1) PCI resource allocation
|
---|
176 | // Get MMIO area
|
---|
177 | //
|
---|
178 | // if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0)
|
---|
179 | // goto regions_out;
|
---|
180 | res = pci_resource_start(pci, 0);
|
---|
181 | if ((reg_temp = request_region(res, pci_resource_len(pci, 0), CARD_NAME_SHORT)) == NULL) {
|
---|
182 | snd_printk("unable to grab VORTEX I/O memory \n");
|
---|
183 | return -EBUSY;
|
---|
184 | }
|
---|
185 |
|
---|
186 | res = pci_resource_start(pci, 1);
|
---|
187 | if ((reg_temp = request_region(res, pci_resource_len(pci, 1), CARD_NAME_SHORT)) == NULL) {
|
---|
188 | snd_printk("unable to grab VORTEX I/O memory \n");
|
---|
189 | return -EBUSY;
|
---|
190 | }
|
---|
191 |
|
---|
192 | res = pci_resource_start(pci, 2);
|
---|
193 |
|
---|
194 | if ((reg_temp = request_mem_region(res, pci_resource_len(pci, 2), CARD_NAME_SHORT)) == NULL) {
|
---|
195 | snd_printk("unable to grab I/O memory 0x%lx-0x%lx\n", res, res+pci_resource_len(pci, 2));
|
---|
196 | return -EBUSY;
|
---|
197 | }
|
---|
198 |
|
---|
199 | chip->mmio = ioremap_nocache(res, pci_resource_len(pci, 2));
|
---|
200 | #ifdef DEBUG
|
---|
201 | dprintf(("got MMIO: %x, IO: %x",chip->mmio, res));
|
---|
202 | #endif
|
---|
203 | if (!chip->mmio) {
|
---|
204 | printk(KERN_ERR "MMIO area remap failed.\n");
|
---|
205 | err = -ENOMEM;
|
---|
206 | goto ioremap_out;
|
---|
207 | }
|
---|
208 |
|
---|
209 | //by Eleph
|
---|
210 | //pci_set_latency_time(pci, 0x40);
|
---|
211 |
|
---|
212 | // pci_write_config_byte(pci, 0x40,0xFF); // Vortex specific patch
|
---|
213 | /* Init audio core.
|
---|
214 | * This must be done before we do request_irq otherwise we can get spurious
|
---|
215 | * interupts that we do not handle properly and make a mess of things */
|
---|
216 | if ((err = vortex_core_init(chip)) != 0) {
|
---|
217 | printk(KERN_ERR "hw core init failed\n");
|
---|
218 | goto core_out;
|
---|
219 | }
|
---|
220 |
|
---|
221 | if ((err = request_irq(pci->irq, vortex_interrupt, SA_INTERRUPT | SA_SHIRQ,
|
---|
222 | CARD_NAME_SHORT, (void *) chip)) != 0) {
|
---|
223 | printk(KERN_ERR "cannot grab irq\n");
|
---|
224 | goto irq_out;
|
---|
225 | }
|
---|
226 | chip->irq = pci->irq;
|
---|
227 |
|
---|
228 | pci_set_master(pci);
|
---|
229 | // End of PCI setup.
|
---|
230 |
|
---|
231 |
|
---|
232 | // Register alsa root device.
|
---|
233 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
|
---|
234 | goto alloc_out;
|
---|
235 | }
|
---|
236 |
|
---|
237 | *rchip = chip;
|
---|
238 |
|
---|
239 | return 0;
|
---|
240 |
|
---|
241 | alloc_out:
|
---|
242 | synchronize_irq(chip->irq);
|
---|
243 | free_irq(chip->irq, chip);
|
---|
244 | irq_out:
|
---|
245 | vortex_core_shutdown(chip);
|
---|
246 | core_out:
|
---|
247 | //FIXME: the type of chip->mmio might need to be changed??
|
---|
248 | iounmap((void*)chip->mmio);
|
---|
249 | ioremap_out:
|
---|
250 | // pci_release_regions(chip->pci_dev);
|
---|
251 | regions_out:
|
---|
252 | // pci_disable_device(chip->pci_dev);
|
---|
253 | //FIXME: this not the right place to unregister the gameport
|
---|
254 | #if defined(CONFIG_GAMEPORT)
|
---|
255 | vortex_gameport_unregister(chip);
|
---|
256 | #endif
|
---|
257 | return err;
|
---|
258 | }
|
---|
259 |
|
---|
260 | // constructor -- see "Constructor" sub-section
|
---|
261 | static int __devinit
|
---|
262 | snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) {
|
---|
263 | static int dev;
|
---|
264 | snd_card_t *card;
|
---|
265 | vortex_t *chip;
|
---|
266 | int err;
|
---|
267 |
|
---|
268 | // (1)
|
---|
269 | #ifdef DEBUG
|
---|
270 | dprintf(("snd_vortex_probe"));
|
---|
271 | #endif
|
---|
272 | if (dev >= SNDRV_CARDS)
|
---|
273 | return -ENODEV;
|
---|
274 | if (!enable[dev]) {
|
---|
275 | dev++;
|
---|
276 | return -ENOENT;
|
---|
277 | }
|
---|
278 | // (2)
|
---|
279 | #ifdef DEBUG
|
---|
280 | dprintf(("snd_vortex_probe 2"));
|
---|
281 | #endif
|
---|
282 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
|
---|
283 | if (card == NULL)
|
---|
284 | return -ENOMEM;
|
---|
285 |
|
---|
286 | // (3)
|
---|
287 | #ifdef DEBUG
|
---|
288 | dprintf(("snd_vortex_probe 3"));
|
---|
289 | #endif
|
---|
290 | if ((err = snd_vortex_create(card, pci, &chip)) < 0) {
|
---|
291 | snd_card_free(card);
|
---|
292 | return err;
|
---|
293 | }
|
---|
294 |
|
---|
295 | snd_vortex_workaround(pci, 255);
|
---|
296 |
|
---|
297 | // (4) Alloc components.
|
---|
298 | // ADB pcm.
|
---|
299 | #ifdef DEBUG
|
---|
300 | dprintf(("snd_vortex_probe 4"));
|
---|
301 | #endif
|
---|
302 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_ADB)) < 0) {
|
---|
303 | snd_card_free(card);
|
---|
304 | return err;
|
---|
305 | }
|
---|
306 | #ifndef CHIP_AU8820
|
---|
307 | #ifdef DEBUG
|
---|
308 | dprintf(("snd_vortex_probe 4/1"));
|
---|
309 | #endif
|
---|
310 | // ADB SPDIF
|
---|
311 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) {
|
---|
312 | snd_card_free(card);
|
---|
313 | return err;
|
---|
314 | }
|
---|
315 | #endif
|
---|
316 | /*
|
---|
317 | // ADB I2S
|
---|
318 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) {
|
---|
319 | snd_card_free(card);
|
---|
320 | return err;
|
---|
321 | }
|
---|
322 | */
|
---|
323 | #ifndef CHIP_AU8810
|
---|
324 | // WT pcm.
|
---|
325 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) {
|
---|
326 | snd_card_free(card);
|
---|
327 | return err;
|
---|
328 | }
|
---|
329 | #endif
|
---|
330 | // snd_ac97_mixer and Vortex mixer.
|
---|
331 | #ifdef DEBUG
|
---|
332 | dprintf(("snd_vortex_probe.mixer init"));
|
---|
333 | #endif
|
---|
334 | if ((err = snd_vortex_mixer(chip)) < 0) {
|
---|
335 | snd_card_free(card);
|
---|
336 | return err;
|
---|
337 | }
|
---|
338 | #ifdef DEBUG
|
---|
339 | dprintf(("snd_vortex_probe. midi init"));
|
---|
340 | #endif
|
---|
341 | if ((err = snd_vortex_midi(chip)) < 0) {
|
---|
342 | snd_card_free(card);
|
---|
343 | return err;
|
---|
344 | }
|
---|
345 | #if defined(CONFIG_GAMEPORT)
|
---|
346 | if ((err = vortex_gameport_register(chip)) < 0) {
|
---|
347 | snd_card_free(card);
|
---|
348 | return err;
|
---|
349 | }
|
---|
350 | #endif
|
---|
351 | #if 0
|
---|
352 | if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
|
---|
353 | sizeof(snd_vortex_synth_arg_t), &wave) < 0
|
---|
354 | || wave == NULL) {
|
---|
355 | snd_printk("Can't initialize Aureal wavetable synth\n");
|
---|
356 | } else {
|
---|
357 | snd_vortex_synth_arg_t *arg;
|
---|
358 |
|
---|
359 | arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
|
---|
360 | strcpy(wave->name, "Aureal Synth");
|
---|
361 | arg->hwptr = vortex;
|
---|
362 | arg->index = 1;
|
---|
363 | arg->seq_ports = seq_ports[dev];
|
---|
364 | arg->max_voices = max_synth_voices[dev];
|
---|
365 | }
|
---|
366 | #endif
|
---|
367 |
|
---|
368 | // (5)
|
---|
369 | strcpy(card->driver, "Aureal Vortex");
|
---|
370 | strcpy(card->shortname, CARD_NAME_SHORT);
|
---|
371 | sprintf(card->longname, "%s at 0x%lx irq %i",
|
---|
372 | card->shortname, chip->io, chip->irq);
|
---|
373 |
|
---|
374 | #ifdef CHIP_AU8830
|
---|
375 | {
|
---|
376 | unsigned char revision;
|
---|
377 | if ((err = pci_read_config_byte(pci, PCI_REVISION_ID, &revision)) < 0) {
|
---|
378 | snd_card_free(card);
|
---|
379 | return err;
|
---|
380 | }
|
---|
381 |
|
---|
382 | if (revision != 0xfe && revision != 0xfa) {
|
---|
383 | printk(KERN_ALERT "vortex: The revision (%x) of your card has not been seen before.\n", revision);
|
---|
384 | printk(KERN_ALERT "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
|
---|
385 | snd_card_free(card);
|
---|
386 | err = -ENODEV;
|
---|
387 | return err;
|
---|
388 | }
|
---|
389 | }
|
---|
390 | #endif
|
---|
391 | // (6)
|
---|
392 | #ifdef DEBUG
|
---|
393 | dprintf(("snd_vortex_probe 6"));
|
---|
394 | #endif
|
---|
395 | if ((err = snd_card_register(card)) < 0) {
|
---|
396 | snd_card_free(card);
|
---|
397 | return err;
|
---|
398 | }
|
---|
399 | // (7)
|
---|
400 | #ifdef DEBUG
|
---|
401 | dprintf(("snd_vortex_probe 7"));
|
---|
402 | #endif
|
---|
403 | pci_set_drvdata(pci, chip);
|
---|
404 | dev++;
|
---|
405 | vortex_connect_default(chip, 1);
|
---|
406 | vortex_enable_int(chip);
|
---|
407 | return 0;
|
---|
408 | }
|
---|
409 |
|
---|
410 | // destructor -- see "Destructor" sub-section
|
---|
411 | static void __devexit snd_vortex_remove(struct pci_dev *pci) {
|
---|
412 | vortex_t *vortex = snd_magic_cast(vortex_t,
|
---|
413 | pci_get_drvdata(pci), return);
|
---|
414 |
|
---|
415 | if (vortex) {
|
---|
416 | // Release ALSA stuff.
|
---|
417 | snd_card_free(vortex->card);
|
---|
418 | // Free Vortex struct.
|
---|
419 | pci_set_drvdata(pci, NULL);
|
---|
420 | } else
|
---|
421 | printk("snd_vortex_remove called more than one time!\n");
|
---|
422 | }
|
---|
423 |
|
---|
424 | // pci_driver definition
|
---|
425 | static struct pci_driver driver = {
|
---|
426 | 0,0,0,CARD_NAME_SHORT,
|
---|
427 | snd_vortex_ids,
|
---|
428 | snd_vortex_probe,
|
---|
429 | snd_vortex_remove,0,0
|
---|
430 | };
|
---|
431 |
|
---|
432 | // initialization of the module
|
---|
433 | static int __init alsa_card_vortex_init(void) {
|
---|
434 | int err;
|
---|
435 |
|
---|
436 | if ((err = pci_module_init(&driver)) < 0) {
|
---|
437 | //#ifdef MODULE
|
---|
438 | // printk(KERN_ERR "Aureal soundcard not found " "or device busy\n");
|
---|
439 | //#endif
|
---|
440 | return err;
|
---|
441 | }
|
---|
442 | return 0;
|
---|
443 | }
|
---|
444 |
|
---|
445 | // clean up the module
|
---|
446 | static void __exit alsa_card_vortex_exit(void) {
|
---|
447 | pci_unregister_driver(&driver);
|
---|
448 | }
|
---|
449 |
|
---|
450 | module_init(alsa_card_vortex_init)
|
---|
451 | module_exit(alsa_card_vortex_exit)
|
---|