Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 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 | |
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 | #include <linux/moduleparam.h> | |
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 | static int pcifix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 255 }; | |
30 | ||
31 | module_param_array(index, int, NULL, 0444); | |
32 | MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); | |
33 | module_param_array(id, charp, NULL, 0444); | |
34 | MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); | |
35 | module_param_array(enable, bool, NULL, 0444); | |
36 | MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard."); | |
37 | module_param_array(pcifix, int, NULL, 0444); | |
38 | MODULE_PARM_DESC(pcifix, "Enable VIA-workaround for " CARD_NAME " soundcard."); | |
39 | ||
40 | MODULE_DESCRIPTION("Aureal vortex"); | |
41 | MODULE_LICENSE("GPL"); | |
42 | MODULE_SUPPORTED_DEVICE("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}"); | |
43 | ||
44 | MODULE_DEVICE_TABLE(pci, snd_vortex_ids); | |
45 | ||
46 | static void vortex_fix_latency(struct pci_dev *vortex) | |
47 | { | |
48 | int rc; | |
49 | if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) { | |
50 | printk(KERN_INFO CARD_NAME | |
51 | ": vortex latency is 0xff\n"); | |
52 | } else { | |
53 | printk(KERN_WARNING CARD_NAME | |
54 | ": could not set vortex latency: pci error 0x%x\n", rc); | |
55 | } | |
56 | } | |
57 | ||
58 | static void vortex_fix_agp_bridge(struct pci_dev *via) | |
59 | { | |
60 | int rc; | |
61 | u8 value; | |
62 | ||
63 | /* | |
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 | |
67 | */ | |
68 | ||
69 | if (!(rc = pci_read_config_byte(via, 0x42, &value)) | |
70 | && ((value & 0x10) | |
71 | || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) { | |
72 | printk(KERN_INFO CARD_NAME | |
73 | ": bridge config is 0x%x\n", value | 0x10); | |
74 | } else { | |
75 | printk(KERN_WARNING CARD_NAME | |
76 | ": could not set vortex latency: pci error 0x%x\n", rc); | |
77 | } | |
78 | } | |
79 | ||
80 | static void __devinit snd_vortex_workaround(struct pci_dev *vortex, int fix) | |
81 | { | |
0dd119f7 | 82 | struct pci_dev *via = NULL; |
1da177e4 LT |
83 | |
84 | /* autodetect if workarounds are required */ | |
85 | if (fix == 255) { | |
86 | /* VIA KT133 */ | |
0dd119f7 JS |
87 | via = pci_get_device(PCI_VENDOR_ID_VIA, |
88 | PCI_DEVICE_ID_VIA_8365_1, NULL); | |
1da177e4 LT |
89 | /* VIA Apollo */ |
90 | if (via == NULL) { | |
0dd119f7 JS |
91 | via = pci_get_device(PCI_VENDOR_ID_VIA, |
92 | PCI_DEVICE_ID_VIA_82C598_1, NULL); | |
93 | /* AMD Irongate */ | |
94 | if (via == NULL) | |
95 | via = pci_get_device(PCI_VENDOR_ID_AMD, | |
96 | PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL); | |
1da177e4 LT |
97 | } |
98 | if (via) { | |
99 | printk(KERN_INFO CARD_NAME ": Activating latency workaround...\n"); | |
100 | vortex_fix_latency(vortex); | |
101 | vortex_fix_agp_bridge(via); | |
102 | } | |
103 | } else { | |
104 | if (fix & 0x1) | |
105 | vortex_fix_latency(vortex); | |
0dd119f7 JS |
106 | if ((fix & 0x2) && (via = pci_get_device(PCI_VENDOR_ID_VIA, |
107 | PCI_DEVICE_ID_VIA_8365_1, NULL))) | |
1da177e4 | 108 | vortex_fix_agp_bridge(via); |
0dd119f7 JS |
109 | if ((fix & 0x4) && (via = pci_get_device(PCI_VENDOR_ID_VIA, |
110 | PCI_DEVICE_ID_VIA_82C598_1, NULL))) | |
1da177e4 | 111 | vortex_fix_agp_bridge(via); |
0dd119f7 JS |
112 | if ((fix & 0x8) && (via = pci_get_device(PCI_VENDOR_ID_AMD, |
113 | PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL))) | |
1da177e4 LT |
114 | vortex_fix_agp_bridge(via); |
115 | } | |
0dd119f7 | 116 | pci_dev_put(via); |
1da177e4 LT |
117 | } |
118 | ||
119 | // component-destructor | |
120 | // (see "Management of Cards and Components") | |
121 | static int snd_vortex_dev_free(snd_device_t * device) | |
122 | { | |
123 | vortex_t *vortex = device->device_data; | |
124 | ||
125 | vortex_gameport_unregister(vortex); | |
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 | 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 | { | |
142 | vortex_t *chip; | |
143 | int err; | |
144 | static snd_device_ops_t ops = { | |
145 | .dev_free = snd_vortex_dev_free, | |
146 | }; | |
147 | ||
148 | *rchip = NULL; | |
149 | ||
150 | // check PCI availability (DMA). | |
151 | if ((err = pci_enable_device(pci)) < 0) | |
152 | return err; | |
153 | if (!pci_dma_supported(pci, VORTEX_DMA_MASK)) { | |
154 | printk(KERN_ERR "error to set DMA mask\n"); | |
155 | return -ENXIO; | |
156 | } | |
157 | pci_set_dma_mask(pci, VORTEX_DMA_MASK); | |
158 | ||
e560d8d8 | 159 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
1da177e4 LT |
160 | if (chip == NULL) |
161 | return -ENOMEM; | |
162 | ||
163 | chip->card = card; | |
164 | ||
165 | // initialize the stuff | |
166 | chip->pci_dev = pci; | |
167 | chip->io = pci_resource_start(pci, 0); | |
168 | chip->vendor = pci->vendor; | |
169 | chip->device = pci->device; | |
170 | chip->card = card; | |
171 | chip->irq = -1; | |
172 | ||
173 | // (1) PCI resource allocation | |
174 | // Get MMIO area | |
175 | // | |
176 | if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0) | |
177 | goto regions_out; | |
178 | ||
179 | chip->mmio = ioremap_nocache(pci_resource_start(pci, 0), | |
180 | pci_resource_len(pci, 0)); | |
181 | if (!chip->mmio) { | |
182 | printk(KERN_ERR "MMIO area remap failed.\n"); | |
183 | err = -ENOMEM; | |
184 | goto ioremap_out; | |
185 | } | |
186 | ||
187 | /* Init audio core. | |
188 | * This must be done before we do request_irq otherwise we can get spurious | |
189 | * interupts that we do not handle properly and make a mess of things */ | |
190 | if ((err = vortex_core_init(chip)) != 0) { | |
191 | printk(KERN_ERR "hw core init failed\n"); | |
192 | goto core_out; | |
193 | } | |
194 | ||
195 | if ((err = request_irq(pci->irq, vortex_interrupt, | |
196 | SA_INTERRUPT | SA_SHIRQ, CARD_NAME_SHORT, | |
197 | chip)) != 0) { | |
198 | printk(KERN_ERR "cannot grab irq\n"); | |
199 | goto irq_out; | |
200 | } | |
201 | chip->irq = pci->irq; | |
202 | ||
203 | pci_set_master(pci); | |
204 | // End of PCI setup. | |
205 | ||
206 | // Register alsa root device. | |
207 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { | |
208 | goto alloc_out; | |
209 | } | |
210 | ||
211 | *rchip = chip; | |
212 | ||
213 | return 0; | |
214 | ||
215 | alloc_out: | |
216 | synchronize_irq(chip->irq); | |
217 | free_irq(chip->irq, chip); | |
218 | irq_out: | |
219 | vortex_core_shutdown(chip); | |
220 | core_out: | |
221 | iounmap(chip->mmio); | |
222 | ioremap_out: | |
223 | pci_release_regions(chip->pci_dev); | |
224 | regions_out: | |
225 | pci_disable_device(chip->pci_dev); | |
226 | //FIXME: this not the right place to unregister the gameport | |
227 | vortex_gameport_unregister(chip); | |
228 | return err; | |
229 | } | |
230 | ||
231 | // constructor -- see "Constructor" sub-section | |
232 | static int __devinit | |
233 | snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) | |
234 | { | |
235 | static int dev; | |
236 | snd_card_t *card; | |
237 | vortex_t *chip; | |
238 | int err; | |
239 | ||
240 | // (1) | |
241 | if (dev >= SNDRV_CARDS) | |
242 | return -ENODEV; | |
243 | if (!enable[dev]) { | |
244 | dev++; | |
245 | return -ENOENT; | |
246 | } | |
247 | // (2) | |
248 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | |
249 | if (card == NULL) | |
250 | return -ENOMEM; | |
251 | ||
252 | // (3) | |
253 | if ((err = snd_vortex_create(card, pci, &chip)) < 0) { | |
254 | snd_card_free(card); | |
255 | return err; | |
256 | } | |
257 | snd_vortex_workaround(pci, pcifix[dev]); | |
258 | // (4) Alloc components. | |
259 | // ADB pcm. | |
260 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_ADB)) < 0) { | |
261 | snd_card_free(card); | |
262 | return err; | |
263 | } | |
264 | #ifndef CHIP_AU8820 | |
265 | // ADB SPDIF | |
266 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) { | |
267 | snd_card_free(card); | |
268 | return err; | |
269 | } | |
270 | // A3D | |
271 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D)) < 0) { | |
272 | snd_card_free(card); | |
273 | return err; | |
274 | } | |
275 | #endif | |
276 | /* | |
277 | // ADB I2S | |
278 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) { | |
279 | snd_card_free(card); | |
280 | return err; | |
281 | } | |
282 | */ | |
283 | #ifndef CHIP_AU8810 | |
284 | // WT pcm. | |
285 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) { | |
286 | snd_card_free(card); | |
287 | return err; | |
288 | } | |
289 | #endif | |
290 | // snd_ac97_mixer and Vortex mixer. | |
291 | if ((err = snd_vortex_mixer(chip)) < 0) { | |
292 | snd_card_free(card); | |
293 | return err; | |
294 | } | |
295 | if ((err = snd_vortex_midi(chip)) < 0) { | |
296 | snd_card_free(card); | |
297 | return err; | |
298 | } | |
299 | ||
300 | vortex_gameport_register(chip); | |
301 | ||
302 | #if 0 | |
303 | if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH, | |
304 | sizeof(snd_vortex_synth_arg_t), &wave) < 0 | |
305 | || wave == NULL) { | |
306 | snd_printk("Can't initialize Aureal wavetable synth\n"); | |
307 | } else { | |
308 | snd_vortex_synth_arg_t *arg; | |
309 | ||
310 | arg = SNDRV_SEQ_DEVICE_ARGPTR(wave); | |
311 | strcpy(wave->name, "Aureal Synth"); | |
312 | arg->hwptr = vortex; | |
313 | arg->index = 1; | |
314 | arg->seq_ports = seq_ports[dev]; | |
315 | arg->max_voices = max_synth_voices[dev]; | |
316 | } | |
317 | #endif | |
318 | ||
319 | // (5) | |
320 | strcpy(card->driver, CARD_NAME_SHORT); | |
321 | strcpy(card->shortname, CARD_NAME_SHORT); | |
322 | sprintf(card->longname, "%s at 0x%lx irq %i", | |
323 | card->shortname, chip->io, chip->irq); | |
324 | ||
325 | if ((err = pci_read_config_word(pci, PCI_DEVICE_ID, | |
326 | &(chip->device))) < 0) { | |
327 | snd_card_free(card); | |
328 | return err; | |
329 | } | |
330 | if ((err = pci_read_config_word(pci, PCI_VENDOR_ID, | |
331 | &(chip->vendor))) < 0) { | |
332 | snd_card_free(card); | |
333 | return err; | |
334 | } | |
335 | if ((err = pci_read_config_byte(pci, PCI_REVISION_ID, | |
336 | &(chip->rev))) < 0) { | |
337 | snd_card_free(card); | |
338 | return err; | |
339 | } | |
340 | #ifdef CHIP_AU8830 | |
341 | if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) { | |
342 | printk(KERN_ALERT | |
343 | "vortex: The revision (%x) of your card has not been seen before.\n", | |
344 | chip->rev); | |
345 | printk(KERN_ALERT | |
346 | "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n"); | |
347 | snd_card_free(card); | |
348 | err = -ENODEV; | |
349 | return err; | |
350 | } | |
351 | #endif | |
352 | ||
353 | // (6) | |
354 | if ((err = snd_card_register(card)) < 0) { | |
355 | snd_card_free(card); | |
356 | return err; | |
357 | } | |
358 | // (7) | |
359 | pci_set_drvdata(pci, card); | |
360 | dev++; | |
361 | vortex_connect_default(chip, 1); | |
362 | vortex_enable_int(chip); | |
363 | return 0; | |
364 | } | |
365 | ||
366 | // destructor -- see "Destructor" sub-section | |
367 | static void __devexit snd_vortex_remove(struct pci_dev *pci) | |
368 | { | |
369 | snd_card_free(pci_get_drvdata(pci)); | |
370 | pci_set_drvdata(pci, NULL); | |
371 | } | |
372 | ||
373 | // pci_driver definition | |
374 | static struct pci_driver driver = { | |
375 | .name = CARD_NAME_SHORT, | |
376 | .id_table = snd_vortex_ids, | |
377 | .probe = snd_vortex_probe, | |
378 | .remove = __devexit_p(snd_vortex_remove), | |
379 | }; | |
380 | ||
381 | // initialization of the module | |
382 | static int __init alsa_card_vortex_init(void) | |
383 | { | |
01d25d46 | 384 | return pci_register_driver(&driver); |
1da177e4 LT |
385 | } |
386 | ||
387 | // clean up the module | |
388 | static void __exit alsa_card_vortex_exit(void) | |
389 | { | |
390 | pci_unregister_driver(&driver); | |
391 | } | |
392 | ||
393 | module_init(alsa_card_vortex_init) | |
394 | module_exit(alsa_card_vortex_exit) |