Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Tobias Klauser | 58da3a2 | 2005-12-01 11:14:00 +0100 | [diff] [blame] | 23 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <sound/initval.h> |
| 25 | |
| 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 }; |
| 31 | |
| 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."); |
| 40 | |
| 41 | MODULE_DESCRIPTION("Aureal vortex"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | MODULE_SUPPORTED_DEVICE("{{Aureal Semiconductor Inc., Aureal Vortex Sound Processor}}"); |
| 44 | |
| 45 | MODULE_DEVICE_TABLE(pci, snd_vortex_ids); |
| 46 | |
| 47 | static void vortex_fix_latency(struct pci_dev *vortex) |
| 48 | { |
| 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); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | static 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)))) { |
| 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); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | static void __devinit snd_vortex_workaround(struct pci_dev *vortex, int fix) |
| 82 | { |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 83 | struct pci_dev *via = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | /* autodetect if workarounds are required */ |
| 86 | if (fix == 255) { |
| 87 | /* VIA KT133 */ |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 88 | via = pci_get_device(PCI_VENDOR_ID_VIA, |
| 89 | PCI_DEVICE_ID_VIA_8365_1, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* VIA Apollo */ |
| 91 | if (via == NULL) { |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | if (via) { |
| 100 | printk(KERN_INFO CARD_NAME ": Activating latency workaround...\n"); |
| 101 | vortex_fix_latency(vortex); |
| 102 | vortex_fix_agp_bridge(via); |
| 103 | } |
| 104 | } else { |
| 105 | if (fix & 0x1) |
| 106 | vortex_fix_latency(vortex); |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 107 | if ((fix & 0x2) && (via = pci_get_device(PCI_VENDOR_ID_VIA, |
| 108 | PCI_DEVICE_ID_VIA_8365_1, NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | vortex_fix_agp_bridge(via); |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 110 | if ((fix & 0x4) && (via = pci_get_device(PCI_VENDOR_ID_VIA, |
| 111 | PCI_DEVICE_ID_VIA_82C598_1, NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | vortex_fix_agp_bridge(via); |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 113 | if ((fix & 0x8) && (via = pci_get_device(PCI_VENDOR_ID_AMD, |
| 114 | PCI_DEVICE_ID_AMD_FE_GATE_7007, NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | vortex_fix_agp_bridge(via); |
| 116 | } |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 117 | pci_dev_put(via); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // component-destructor |
| 121 | // (see "Management of Cards and Components") |
Takashi Iwai | 2fd1687 | 2005-11-17 14:55:19 +0100 | [diff] [blame] | 122 | static int snd_vortex_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | vortex_t *vortex = device->device_data; |
| 125 | |
| 126 | vortex_gameport_unregister(vortex); |
| 127 | vortex_core_shutdown(vortex); |
| 128 | // Take down PCI interface. |
| 129 | synchronize_irq(vortex->irq); |
| 130 | free_irq(vortex->irq, vortex); |
Amol Lad | 8a238c7 | 2006-10-06 16:45:19 +0200 | [diff] [blame] | 131 | iounmap(vortex->mmio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | pci_release_regions(vortex->pci_dev); |
| 133 | pci_disable_device(vortex->pci_dev); |
| 134 | kfree(vortex); |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | // chip-specific constructor |
| 140 | // (see "Management of Cards and Components") |
| 141 | static int __devinit |
Takashi Iwai | 2fd1687 | 2005-11-17 14:55:19 +0100 | [diff] [blame] | 142 | snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | vortex_t *chip; |
| 145 | int err; |
Takashi Iwai | 2fd1687 | 2005-11-17 14:55:19 +0100 | [diff] [blame] | 146 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | .dev_free = snd_vortex_dev_free, |
| 148 | }; |
| 149 | |
| 150 | *rchip = NULL; |
| 151 | |
| 152 | // check PCI availability (DMA). |
| 153 | if ((err = pci_enable_device(pci)) < 0) |
| 154 | return err; |
Takashi Iwai | 97c67b6 | 2006-01-13 17:16:29 +0100 | [diff] [blame] | 155 | if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 || |
| 156 | pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | printk(KERN_ERR "error to set DMA mask\n"); |
Takashi Iwai | 97c67b6 | 2006-01-13 17:16:29 +0100 | [diff] [blame] | 158 | pci_disable_device(pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return -ENXIO; |
| 160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 162 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Takashi Iwai | 97c67b6 | 2006-01-13 17:16:29 +0100 | [diff] [blame] | 163 | if (chip == NULL) { |
| 164 | pci_disable_device(pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | return -ENOMEM; |
Takashi Iwai | 97c67b6 | 2006-01-13 17:16:29 +0100 | [diff] [blame] | 166 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | chip->card = card; |
| 169 | |
| 170 | // initialize the stuff |
| 171 | chip->pci_dev = pci; |
| 172 | chip->io = pci_resource_start(pci, 0); |
| 173 | chip->vendor = pci->vendor; |
| 174 | chip->device = pci->device; |
| 175 | chip->card = card; |
| 176 | chip->irq = -1; |
| 177 | |
| 178 | // (1) PCI resource allocation |
| 179 | // Get MMIO area |
| 180 | // |
| 181 | if ((err = pci_request_regions(pci, CARD_NAME_SHORT)) != 0) |
| 182 | goto regions_out; |
| 183 | |
| 184 | chip->mmio = ioremap_nocache(pci_resource_start(pci, 0), |
| 185 | pci_resource_len(pci, 0)); |
| 186 | if (!chip->mmio) { |
| 187 | printk(KERN_ERR "MMIO area remap failed.\n"); |
| 188 | err = -ENOMEM; |
| 189 | goto ioremap_out; |
| 190 | } |
| 191 | |
| 192 | /* Init audio core. |
| 193 | * This must be done before we do request_irq otherwise we can get spurious |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 194 | * interrupts that we do not handle properly and make a mess of things */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if ((err = vortex_core_init(chip)) != 0) { |
| 196 | printk(KERN_ERR "hw core init failed\n"); |
| 197 | goto core_out; |
| 198 | } |
| 199 | |
| 200 | if ((err = request_irq(pci->irq, vortex_interrupt, |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 201 | IRQF_SHARED, CARD_NAME_SHORT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | chip)) != 0) { |
| 203 | printk(KERN_ERR "cannot grab irq\n"); |
| 204 | goto irq_out; |
| 205 | } |
| 206 | chip->irq = pci->irq; |
| 207 | |
| 208 | pci_set_master(pci); |
| 209 | // End of PCI setup. |
| 210 | |
| 211 | // Register alsa root device. |
| 212 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
| 213 | goto alloc_out; |
| 214 | } |
| 215 | |
Takashi Iwai | 97c67b6 | 2006-01-13 17:16:29 +0100 | [diff] [blame] | 216 | snd_card_set_dev(card, &pci->dev); |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | *rchip = chip; |
| 219 | |
| 220 | return 0; |
| 221 | |
| 222 | alloc_out: |
| 223 | synchronize_irq(chip->irq); |
| 224 | free_irq(chip->irq, chip); |
| 225 | irq_out: |
| 226 | vortex_core_shutdown(chip); |
| 227 | core_out: |
| 228 | iounmap(chip->mmio); |
| 229 | ioremap_out: |
| 230 | pci_release_regions(chip->pci_dev); |
| 231 | regions_out: |
| 232 | pci_disable_device(chip->pci_dev); |
| 233 | //FIXME: this not the right place to unregister the gameport |
| 234 | vortex_gameport_unregister(chip); |
Jesper Juhl | 6ed44ad | 2007-08-06 14:05:27 +0200 | [diff] [blame] | 235 | kfree(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return err; |
| 237 | } |
| 238 | |
| 239 | // constructor -- see "Constructor" sub-section |
| 240 | static int __devinit |
| 241 | snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) |
| 242 | { |
| 243 | static int dev; |
Takashi Iwai | 2fd1687 | 2005-11-17 14:55:19 +0100 | [diff] [blame] | 244 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | vortex_t *chip; |
| 246 | int err; |
| 247 | |
| 248 | // (1) |
| 249 | if (dev >= SNDRV_CARDS) |
| 250 | return -ENODEV; |
| 251 | if (!enable[dev]) { |
| 252 | dev++; |
| 253 | return -ENOENT; |
| 254 | } |
| 255 | // (2) |
| 256 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); |
| 257 | if (card == NULL) |
| 258 | return -ENOMEM; |
| 259 | |
| 260 | // (3) |
| 261 | if ((err = snd_vortex_create(card, pci, &chip)) < 0) { |
| 262 | snd_card_free(card); |
| 263 | return err; |
| 264 | } |
| 265 | snd_vortex_workaround(pci, pcifix[dev]); |
Alan Horstmann | 520290e | 2006-05-03 17:07:29 +0200 | [diff] [blame] | 266 | |
| 267 | // Card details needed in snd_vortex_midi |
| 268 | strcpy(card->driver, CARD_NAME_SHORT); |
| 269 | sprintf(card->shortname, "Aureal Vortex %s", CARD_NAME_SHORT); |
| 270 | sprintf(card->longname, "%s at 0x%lx irq %i", |
| 271 | card->shortname, chip->io, chip->irq); |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | // (4) Alloc components. |
| 274 | // ADB pcm. |
| 275 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_ADB)) < 0) { |
| 276 | snd_card_free(card); |
| 277 | return err; |
| 278 | } |
| 279 | #ifndef CHIP_AU8820 |
| 280 | // ADB SPDIF |
| 281 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1)) < 0) { |
| 282 | snd_card_free(card); |
| 283 | return err; |
| 284 | } |
| 285 | // A3D |
| 286 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D)) < 0) { |
| 287 | snd_card_free(card); |
| 288 | return err; |
| 289 | } |
| 290 | #endif |
| 291 | /* |
| 292 | // ADB I2S |
| 293 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) { |
| 294 | snd_card_free(card); |
| 295 | return err; |
| 296 | } |
| 297 | */ |
| 298 | #ifndef CHIP_AU8810 |
| 299 | // WT pcm. |
| 300 | if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT)) < 0) { |
| 301 | snd_card_free(card); |
| 302 | return err; |
| 303 | } |
| 304 | #endif |
| 305 | // snd_ac97_mixer and Vortex mixer. |
| 306 | if ((err = snd_vortex_mixer(chip)) < 0) { |
| 307 | snd_card_free(card); |
| 308 | return err; |
| 309 | } |
| 310 | if ((err = snd_vortex_midi(chip)) < 0) { |
| 311 | snd_card_free(card); |
| 312 | return err; |
| 313 | } |
| 314 | |
| 315 | vortex_gameport_register(chip); |
| 316 | |
| 317 | #if 0 |
| 318 | if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH, |
| 319 | sizeof(snd_vortex_synth_arg_t), &wave) < 0 |
| 320 | || wave == NULL) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 321 | snd_printk(KERN_ERR "Can't initialize Aureal wavetable synth\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } else { |
| 323 | snd_vortex_synth_arg_t *arg; |
| 324 | |
| 325 | arg = SNDRV_SEQ_DEVICE_ARGPTR(wave); |
| 326 | strcpy(wave->name, "Aureal Synth"); |
| 327 | arg->hwptr = vortex; |
| 328 | arg->index = 1; |
| 329 | arg->seq_ports = seq_ports[dev]; |
| 330 | arg->max_voices = max_synth_voices[dev]; |
| 331 | } |
| 332 | #endif |
| 333 | |
| 334 | // (5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | if ((err = pci_read_config_word(pci, PCI_DEVICE_ID, |
| 336 | &(chip->device))) < 0) { |
| 337 | snd_card_free(card); |
| 338 | return err; |
| 339 | } |
| 340 | if ((err = pci_read_config_word(pci, PCI_VENDOR_ID, |
| 341 | &(chip->vendor))) < 0) { |
| 342 | snd_card_free(card); |
| 343 | return err; |
| 344 | } |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 345 | chip->rev = pci->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | #ifdef CHIP_AU8830 |
| 347 | if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) { |
| 348 | printk(KERN_ALERT |
| 349 | "vortex: The revision (%x) of your card has not been seen before.\n", |
| 350 | chip->rev); |
| 351 | printk(KERN_ALERT |
| 352 | "vortex: Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n"); |
| 353 | snd_card_free(card); |
| 354 | err = -ENODEV; |
| 355 | return err; |
| 356 | } |
| 357 | #endif |
| 358 | |
| 359 | // (6) |
| 360 | if ((err = snd_card_register(card)) < 0) { |
| 361 | snd_card_free(card); |
| 362 | return err; |
| 363 | } |
| 364 | // (7) |
| 365 | pci_set_drvdata(pci, card); |
| 366 | dev++; |
| 367 | vortex_connect_default(chip, 1); |
| 368 | vortex_enable_int(chip); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | // destructor -- see "Destructor" sub-section |
| 373 | static void __devexit snd_vortex_remove(struct pci_dev *pci) |
| 374 | { |
| 375 | snd_card_free(pci_get_drvdata(pci)); |
| 376 | pci_set_drvdata(pci, NULL); |
| 377 | } |
| 378 | |
| 379 | // pci_driver definition |
| 380 | static struct pci_driver driver = { |
| 381 | .name = CARD_NAME_SHORT, |
| 382 | .id_table = snd_vortex_ids, |
| 383 | .probe = snd_vortex_probe, |
| 384 | .remove = __devexit_p(snd_vortex_remove), |
| 385 | }; |
| 386 | |
| 387 | // initialization of the module |
| 388 | static int __init alsa_card_vortex_init(void) |
| 389 | { |
Takashi Iwai | 01d25d4 | 2005-04-11 16:58:24 +0200 | [diff] [blame] | 390 | return pci_register_driver(&driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // clean up the module |
| 394 | static void __exit alsa_card_vortex_exit(void) |
| 395 | { |
| 396 | pci_unregister_driver(&driver); |
| 397 | } |
| 398 | |
| 399 | module_init(alsa_card_vortex_init) |
| 400 | module_exit(alsa_card_vortex_exit) |