blob: 21ce31f636bc55c939970be2bcdbcc9953500680 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Paul Gortmaker65a77212011-07-15 13:13:37 -040022#include <linux/module.h>
Tobias Klauser58da3a22005-12-01 11:14:00 +010023#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <sound/initval.h>
25
26// module parameters (see "Module Parameters")
27static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
28static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
Rusty Russella67ff6a2011-12-15 13:49:36 +103029static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int pcifix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 255 };
31
32module_param_array(index, int, NULL, 0444);
33MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
34module_param_array(id, charp, NULL, 0444);
35MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
36module_param_array(enable, bool, NULL, 0444);
37MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
38module_param_array(pcifix, int, NULL, 0444);
39MODULE_PARM_DESC(pcifix, "Enable VIA-workaround for " CARD_NAME " soundcard.");
40
41MODULE_DESCRIPTION("Aureal vortex");
42MODULE_LICENSE("GPL");
43MODULE_SUPPORTED_DEVICE("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}");
44
45MODULE_DEVICE_TABLE(pci, snd_vortex_ids);
46
47static void vortex_fix_latency(struct pci_dev *vortex)
48{
49 int rc;
50 if (!(rc = pci_write_config_byte(vortex, 0x40, 0xff))) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +053051 pr_info( CARD_NAME
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 ": vortex latency is 0xff\n");
53 } else {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +053054 pr_warn( CARD_NAME
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 ": could not set vortex latency: pci error 0x%x\n", rc);
56 }
57}
58
59static void vortex_fix_agp_bridge(struct pci_dev *via)
60{
61 int rc;
62 u8 value;
63
64 /*
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
68 */
69
70 if (!(rc = pci_read_config_byte(via, 0x42, &value))
71 && ((value & 0x10)
72 || !(rc = pci_write_config_byte(via, 0x42, value | 0x10)))) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +053073 pr_info( CARD_NAME
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 ": bridge config is 0x%x\n", value | 0x10);
75 } else {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +053076 pr_warn( CARD_NAME
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 ": could not set vortex latency: pci error 0x%x\n", rc);
78 }
79}
80
Bill Pembertone23e7a12012-12-06 12:35:10 -050081static void snd_vortex_workaround(struct pci_dev *vortex, int fix)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Jiri Slaby0dd119f2005-09-07 14:28:33 +020083 struct pci_dev *via = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 /* autodetect if workarounds are required */
86 if (fix == 255) {
87 /* VIA KT133 */
Jiri Slaby0dd119f2005-09-07 14:28:33 +020088 via = pci_get_device(PCI_VENDOR_ID_VIA,
89 PCI_DEVICE_ID_VIA_8365_1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* VIA Apollo */
91 if (via == NULL) {
Jiri Slaby0dd119f2005-09-07 14:28:33 +020092 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99 if (via) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530100 pr_info( CARD_NAME ": Activating latency workaround...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 vortex_fix_latency(vortex);
102 vortex_fix_agp_bridge(via);
103 }
104 } else {
105 if (fix & 0x1)
106 vortex_fix_latency(vortex);
Jiri Slaby0dd119f2005-09-07 14:28:33 +0200107 if ((fix & 0x2) && (via = pci_get_device(PCI_VENDOR_ID_VIA,
108 PCI_DEVICE_ID_VIA_8365_1, NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 vortex_fix_agp_bridge(via);
Jiri Slaby0dd119f2005-09-07 14:28:33 +0200110 if ((fix & 0x4) && (via = pci_get_device(PCI_VENDOR_ID_VIA,
111 PCI_DEVICE_ID_VIA_82C598_1, NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 vortex_fix_agp_bridge(via);
Jiri Slaby0dd119f2005-09-07 14:28:33 +0200113 if ((fix & 0x8) && (via = pci_get_device(PCI_VENDOR_ID_AMD,
114 PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 vortex_fix_agp_bridge(via);
116 }
Jiri Slaby0dd119f2005-09-07 14:28:33 +0200117 pci_dev_put(via);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120// component-destructor
121// (see "Management of Cards and Components")
Takashi Iwai2fd16872005-11-17 14:55:19 +0100122static int snd_vortex_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 vortex_t *vortex = device->device_data;
125
126 vortex_gameport_unregister(vortex);
127 vortex_core_shutdown(vortex);
128 // Take down PCI interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 free_irq(vortex->irq, vortex);
Amol Lad8a238c72006-10-06 16:45:19 +0200130 iounmap(vortex->mmio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 pci_release_regions(vortex->pci_dev);
132 pci_disable_device(vortex->pci_dev);
133 kfree(vortex);
134
135 return 0;
136}
137
138// chip-specific constructor
139// (see "Management of Cards and Components")
Bill Pembertone23e7a12012-12-06 12:35:10 -0500140static int
Takashi Iwai2fd16872005-11-17 14:55:19 +0100141snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
143 vortex_t *chip;
144 int err;
Takashi Iwai2fd16872005-11-17 14:55:19 +0100145 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 .dev_free = snd_vortex_dev_free,
147 };
148
149 *rchip = NULL;
150
151 // check PCI availability (DMA).
152 if ((err = pci_enable_device(pci)) < 0)
153 return err;
Yang Hongyang284901a2009-04-06 19:01:15 -0700154 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
155 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530156 pr_err( "error to set DMA mask\n");
Takashi Iwai97c67b62006-01-13 17:16:29 +0100157 pci_disable_device(pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return -ENXIO;
159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200161 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Takashi Iwai97c67b62006-01-13 17:16:29 +0100162 if (chip == NULL) {
163 pci_disable_device(pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return -ENOMEM;
Takashi Iwai97c67b62006-01-13 17:16:29 +0100165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 chip->card = card;
168
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;
176
177 // (1) PCI resource allocation
178 // Get MMIO area
179 //
180 if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0)
181 goto regions_out;
182
Arjan van de Ven2f5ad542008-09-28 16:20:09 -0700183 chip->mmio = pci_ioremap_bar(pci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if (!chip->mmio) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530185 pr_err( "MMIO area remap failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 err = -ENOMEM;
187 goto ioremap_out;
188 }
189
190 /* Init audio core.
191 * This must be done before we do request_irq otherwise we can get spurious
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200192 * interrupts that we do not handle properly and make a mess of things */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if ((err = vortex_core_init(chip)) != 0) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530194 pr_err( "hw core init failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 goto core_out;
196 }
197
198 if ((err = request_irq(pci->irq, vortex_interrupt,
Takashi Iwai934c2b62011-06-10 16:36:37 +0200199 IRQF_SHARED, KBUILD_MODNAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 chip)) != 0) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530201 pr_err( "cannot grab irq\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 goto irq_out;
203 }
204 chip->irq = pci->irq;
205
206 pci_set_master(pci);
207 // End of PCI setup.
208
209 // Register alsa root device.
210 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
211 goto alloc_out;
212 }
213
214 *rchip = chip;
215
216 return 0;
217
218 alloc_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 free_irq(chip->irq, chip);
220 irq_out:
221 vortex_core_shutdown(chip);
222 core_out:
223 iounmap(chip->mmio);
224 ioremap_out:
225 pci_release_regions(chip->pci_dev);
226 regions_out:
227 pci_disable_device(chip->pci_dev);
228 //FIXME: this not the right place to unregister the gameport
229 vortex_gameport_unregister(chip);
Jesper Juhl6ed44ad2007-08-06 14:05:27 +0200230 kfree(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 return err;
232}
233
234// constructor -- see "Constructor" sub-section
Bill Pembertone23e7a12012-12-06 12:35:10 -0500235static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
237{
238 static int dev;
Takashi Iwai2fd16872005-11-17 14:55:19 +0100239 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 vortex_t *chip;
241 int err;
242
243 // (1)
244 if (dev >= SNDRV_CARDS)
245 return -ENODEV;
246 if (!enable[dev]) {
247 dev++;
248 return -ENOENT;
249 }
250 // (2)
Takashi Iwai60c57722014-01-29 14:20:19 +0100251 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
252 0, &card);
Takashi Iwaie58de7b2008-12-28 16:44:30 +0100253 if (err < 0)
254 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 // (3)
257 if ((err = snd_vortex_create(card, pci, &chip)) < 0) {
258 snd_card_free(card);
259 return err;
260 }
261 snd_vortex_workaround(pci, pcifix[dev]);
Alan Horstmann520290e2006-05-03 17:07:29 +0200262
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);
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 // (4) Alloc components.
Raymond Yau7b324862012-01-13 10:30:08 +0800270 err = snd_vortex_mixer(chip);
271 if (err < 0) {
272 snd_card_free(card);
273 return err;
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 // ADB pcm.
Raymond Yau49b9c402012-01-13 10:35:01 +0800276 err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_PCM);
277 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 snd_card_free(card);
279 return err;
280 }
281#ifndef CHIP_AU8820
282 // ADB SPDIF
283 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) {
284 snd_card_free(card);
285 return err;
286 }
287 // A3D
288 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D)) < 0) {
289 snd_card_free(card);
290 return err;
291 }
292#endif
293 /*
294 // ADB I2S
295 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) {
296 snd_card_free(card);
297 return err;
298 }
299 */
300#ifndef CHIP_AU8810
301 // WT pcm.
302 if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) {
303 snd_card_free(card);
304 return err;
305 }
306#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if ((err = snd_vortex_midi(chip)) < 0) {
308 snd_card_free(card);
309 return err;
310 }
311
312 vortex_gameport_register(chip);
313
314#if 0
315 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
316 sizeof(snd_vortex_synth_arg_t), &wave) < 0
317 || wave == NULL) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200318 snd_printk(KERN_ERR "Can't initialize Aureal wavetable synth\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 } else {
320 snd_vortex_synth_arg_t *arg;
321
322 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
323 strcpy(wave->name, "Aureal Synth");
324 arg->hwptr = vortex;
325 arg->index = 1;
326 arg->seq_ports = seq_ports[dev];
327 arg->max_voices = max_synth_voices[dev];
328 }
329#endif
330
331 // (5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if ((err = pci_read_config_word(pci, PCI_DEVICE_ID,
333 &(chip->device))) < 0) {
334 snd_card_free(card);
335 return err;
336 }
337 if ((err = pci_read_config_word(pci, PCI_VENDOR_ID,
338 &(chip->vendor))) < 0) {
339 snd_card_free(card);
340 return err;
341 }
Auke Kok44c10132007-06-08 15:46:36 -0700342 chip->rev = pci->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343#ifdef CHIP_AU8830
344 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) {
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530345 pr_alert(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 "vortex: The revision (%x) of your card has not been seen before.\n",
347 chip->rev);
Sudip Mukherjeee7e69262014-09-08 22:48:03 +0530348 pr_alert(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n");
350 snd_card_free(card);
351 err = -ENODEV;
352 return err;
353 }
354#endif
355
356 // (6)
357 if ((err = snd_card_register(card)) < 0) {
358 snd_card_free(card);
359 return err;
360 }
361 // (7)
362 pci_set_drvdata(pci, card);
363 dev++;
364 vortex_connect_default(chip, 1);
365 vortex_enable_int(chip);
366 return 0;
367}
368
369// destructor -- see "Destructor" sub-section
Bill Pembertone23e7a12012-12-06 12:35:10 -0500370static void snd_vortex_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 snd_card_free(pci_get_drvdata(pci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
375// pci_driver definition
Takashi Iwaie9f66d92012-04-24 12:25:00 +0200376static struct pci_driver vortex_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +0200377 .name = KBUILD_MODNAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .id_table = snd_vortex_ids,
379 .probe = snd_vortex_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -0500380 .remove = snd_vortex_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381};
382
Takashi Iwaie9f66d92012-04-24 12:25:00 +0200383module_pci_driver(vortex_driver);