GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / pci / au88x0 / au88x0.c
blob9e34261d89fa38579c37b75f76c400ddcbabb49a
1 /*
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
10 * the ALSA part.
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 :-)
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 <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 int 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)
49 int rc;
50 if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) {
51 printk(KERN_INFO CARD_NAME
52 ": vortex latency is 0xff\n");
53 } else {
54 printk(KERN_WARNING CARD_NAME
55 ": could not set vortex latency: pci error 0x%x\n", rc);
59 static void vortex_fix_agp_bridge(struct pci_dev *via)
61 int rc;
62 u8 value;
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))
71 && ((value & 0x10)
72 || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) {
73 printk(KERN_INFO CARD_NAME
74 ": bridge config is 0x%x\n", value | 0x10);
75 } else {
76 printk(KERN_WARNING CARD_NAME
77 ": could not set vortex latency: pci error 0x%x\n", rc);
81 static void __devinit snd_vortex_workaround(struct pci_dev *vortex, int fix)
83 struct pci_dev *via = NULL;
85 /* autodetect if workarounds are required */
86 if (fix == 255) {
87 /* VIA KT133 */
88 via = pci_get_device(PCI_VENDOR_ID_VIA,
89 PCI_DEVICE_ID_VIA_8365_1, NULL);
90 /* VIA Apollo */
91 if (via == NULL) {
92 via = pci_get_device(PCI_VENDOR_ID_VIA,
93 PCI_DEVICE_ID_VIA_82C598_1, NULL);
94 /* AMD Irongate */
95 if (via == NULL)
96 via = pci_get_device(PCI_VENDOR_ID_AMD,
97 PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL);
99 if (via) {
100 printk(KERN_INFO CARD_NAME ": Activating latency workaround...\n");
101 vortex_fix_latency(vortex);
102 vortex_fix_agp_bridge(via);
104 } else {
105 if (fix & 0x1)
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);
117 pci_dev_put(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);
133 kfree(vortex);
135 return 0;
138 // chip-specific constructor
139 // (see "Management of Cards and Components")
140 static int __devinit
141 snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
143 vortex_t *chip;
144 int err;
145 static struct snd_device_ops ops = {
146 .dev_free = snd_vortex_dev_free,
149 *rchip = NULL;
151 // check PCI availability (DMA).
152 if ((err = pci_enable_device(pci)) < 0)
153 return err;
154 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
155 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
156 printk(KERN_ERR "error to set DMA mask\n");
157 pci_disable_device(pci);
158 return -ENXIO;
161 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
162 if (chip == NULL) {
163 pci_disable_device(pci);
164 return -ENOMEM;
167 chip->card = card;
169 // initialize the stuff
170 chip->pci_dev = pci;
171 chip->io = pci_resource_start(pci, 0);
172 chip->vendor = pci->vendor;
173 chip->device = pci->device;
174 chip->card = card;
175 chip->irq = -1;
177 // (1) PCI resource allocation
178 // Get MMIO area
180 if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0)
181 goto regions_out;
183 chip->mmio = pci_ioremap_bar(pci, 0);
184 if (!chip->mmio) {
185 printk(KERN_ERR "MMIO area remap failed.\n");
186 err = -ENOMEM;
187 goto ioremap_out;
190 /* Init audio core.
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 printk(KERN_ERR "hw core init failed\n");
195 goto core_out;
198 if ((err = request_irq(pci->irq, vortex_interrupt,
199 IRQF_SHARED, CARD_NAME_SHORT,
200 chip)) != 0) {
201 printk(KERN_ERR "cannot grab irq\n");
202 goto irq_out;
204 chip->irq = pci->irq;
206 pci_set_master(pci);
207 // End of PCI setup.
209 // Register alsa root device.
210 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
211 goto alloc_out;
214 snd_card_set_dev(card, &pci->dev);
216 *rchip = chip;
218 return 0;
220 alloc_out:
221 free_irq(chip->irq, chip);
222 irq_out:
223 vortex_core_shutdown(chip);
224 core_out:
225 iounmap(chip->mmio);
226 ioremap_out:
227 pci_release_regions(chip->pci_dev);
228 regions_out:
229 pci_disable_device(chip->pci_dev);
230 vortex_gameport_unregister(chip);
231 kfree(chip);
232 return err;
235 // constructor -- see "Constructor" sub-section
236 static int __devinit
237 snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
239 static int dev;
240 struct snd_card *card;
241 vortex_t *chip;
242 int err;
244 // (1)
245 if (dev >= SNDRV_CARDS)
246 return -ENODEV;
247 if (!enable[dev]) {
248 dev++;
249 return -ENOENT;
251 // (2)
252 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
253 if (err < 0)
254 return err;
256 // (3)
257 if ((err = snd_vortex_create(card, pci, &chip)) < 0) {
258 snd_card_free(card);
259 return err;
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 // ADB pcm.
271 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_ADB)) < 0) {
272 snd_card_free(card);
273 return err;
275 #ifndef CHIP_AU8820
276 // ADB SPDIF
277 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) {
278 snd_card_free(card);
279 return err;
281 // A3D
282 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D)) < 0) {
283 snd_card_free(card);
284 return err;
286 #endif
288 // ADB I2S
289 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) {
290 snd_card_free(card);
291 return err;
294 #ifndef CHIP_AU8810
295 // WT pcm.
296 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) {
297 snd_card_free(card);
298 return err;
300 #endif
301 // snd_ac97_mixer and Vortex mixer.
302 if ((err = snd_vortex_mixer(chip)) < 0) {
303 snd_card_free(card);
304 return err;
306 if ((err = snd_vortex_midi(chip)) < 0) {
307 snd_card_free(card);
308 return err;
311 vortex_gameport_register(chip);
314 // (5)
315 if ((err = pci_read_config_word(pci, PCI_DEVICE_ID,
316 &(chip->device))) < 0) {
317 snd_card_free(card);
318 return err;
320 if ((err = pci_read_config_word(pci, PCI_VENDOR_ID,
321 &(chip->vendor))) < 0) {
322 snd_card_free(card);
323 return err;
325 chip->rev = pci->revision;
326 #ifdef CHIP_AU8830
327 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) {
328 printk(KERN_ALERT
329 "vortex: The revision (%x) of your card has not been seen before.\n",
330 chip->rev);
331 printk(KERN_ALERT
332 "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
333 snd_card_free(card);
334 err = -ENODEV;
335 return err;
337 #endif
339 // (6)
340 if ((err = snd_card_register(card)) < 0) {
341 snd_card_free(card);
342 return err;
344 // (7)
345 pci_set_drvdata(pci, card);
346 dev++;
347 vortex_connect_default(chip, 1);
348 vortex_enable_int(chip);
349 return 0;
352 // destructor -- see "Destructor" sub-section
353 static void __devexit snd_vortex_remove(struct pci_dev *pci)
355 snd_card_free(pci_get_drvdata(pci));
356 pci_set_drvdata(pci, NULL);
359 // pci_driver definition
360 static struct pci_driver driver = {
361 .name = CARD_NAME_SHORT,
362 .id_table = snd_vortex_ids,
363 .probe = snd_vortex_probe,
364 .remove = __devexit_p(snd_vortex_remove),
367 // initialization of the module
368 static int __init alsa_card_vortex_init(void)
370 return pci_register_driver(&driver);
373 // clean up the module
374 static void __exit alsa_card_vortex_exit(void)
376 pci_unregister_driver(&driver);
379 module_init(alsa_card_vortex_init)
380 module_exit(alsa_card_vortex_exit)