Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Initialisation code for Cyrix/NatSemi VSA1 softaudio |
| 3 | * |
Alan Cox | 2f1e593 | 2008-10-27 15:21:19 +0000 | [diff] [blame] | 4 | * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * XpressAudio(tm) is used on the Cyrix MediaGX (now NatSemi Geode) systems. |
| 7 | * The older version (VSA1) provides fairly good soundblaster emulation |
| 8 | * although there are a couple of bugs: large DMA buffers break record, |
| 9 | * and the MPU event handling seems suspect. VSA2 allows the native driver |
| 10 | * to control the AC97 audio engine directly and requires a different driver. |
| 11 | * |
| 12 | * Thanks to National Semiconductor for providing the needed information |
| 13 | * on the XpressAudio(tm) internals. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms of the GNU General Public License as published by the |
| 17 | * Free Software Foundation; either version 2, or (at your option) any |
| 18 | * later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, but |
| 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | * General Public License for more details. |
| 24 | * |
| 25 | * TO DO: |
| 26 | * Investigate whether we can portably support Cognac (5520) in the |
| 27 | * same manner. |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/pci.h> |
| 34 | |
| 35 | #include "sound_config.h" |
| 36 | |
| 37 | #include "sb.h" |
| 38 | |
| 39 | /* |
| 40 | * Read a soundblaster compatible mixer register. |
| 41 | * In this case we are actually reading an SMI trap |
| 42 | * not real hardware. |
| 43 | */ |
| 44 | |
| 45 | static u8 __devinit mixer_read(unsigned long io, u8 reg) |
| 46 | { |
| 47 | outb(reg, io + 4); |
| 48 | udelay(20); |
| 49 | reg = inb(io + 5); |
| 50 | udelay(20); |
| 51 | return reg; |
| 52 | } |
| 53 | |
| 54 | static int __devinit probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 55 | { |
| 56 | struct address_info *hw_config; |
| 57 | unsigned long base; |
| 58 | void __iomem *mem; |
| 59 | unsigned long io; |
| 60 | u16 map; |
| 61 | u8 irq, dma8, dma16; |
| 62 | int oldquiet; |
| 63 | extern int sb_be_quiet; |
| 64 | |
| 65 | base = pci_resource_start(pdev, 0); |
| 66 | if(base == 0UL) |
| 67 | return 1; |
| 68 | |
| 69 | mem = ioremap(base, 128); |
Harvey Harrison | cb6969e | 2008-05-06 20:42:32 -0700 | [diff] [blame] | 70 | if (!mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return 1; |
| 72 | map = readw(mem + 0x18); /* Read the SMI enables */ |
| 73 | iounmap(mem); |
| 74 | |
| 75 | /* Map bits |
| 76 | 0:1 * 0x20 + 0x200 = sb base |
| 77 | 2 sb enable |
| 78 | 3 adlib enable |
| 79 | 5 MPU enable 0x330 |
| 80 | 6 MPU enable 0x300 |
| 81 | |
| 82 | The other bits may be used internally so must be masked */ |
| 83 | |
| 84 | io = 0x220 + 0x20 * (map & 3); |
| 85 | |
| 86 | if(map & (1<<2)) |
| 87 | printk(KERN_INFO "kahlua: XpressAudio at 0x%lx\n", io); |
| 88 | else |
| 89 | return 1; |
| 90 | |
| 91 | if(map & (1<<5)) |
| 92 | printk(KERN_INFO "kahlua: MPU at 0x300\n"); |
| 93 | else if(map & (1<<6)) |
| 94 | printk(KERN_INFO "kahlua: MPU at 0x330\n"); |
| 95 | |
| 96 | irq = mixer_read(io, 0x80) & 0x0F; |
| 97 | dma8 = mixer_read(io, 0x81); |
| 98 | |
| 99 | // printk("IRQ=%x MAP=%x DMA=%x\n", irq, map, dma8); |
| 100 | |
| 101 | if(dma8 & 0x20) |
| 102 | dma16 = 5; |
| 103 | else if(dma8 & 0x40) |
| 104 | dma16 = 6; |
| 105 | else if(dma8 & 0x80) |
| 106 | dma16 = 7; |
| 107 | else |
| 108 | { |
| 109 | printk(KERN_ERR "kahlua: No 16bit DMA enabled.\n"); |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | if(dma8 & 0x01) |
| 114 | dma8 = 0; |
| 115 | else if(dma8 & 0x02) |
| 116 | dma8 = 1; |
| 117 | else if(dma8 & 0x08) |
| 118 | dma8 = 3; |
| 119 | else |
| 120 | { |
| 121 | printk(KERN_ERR "kahlua: No 8bit DMA enabled.\n"); |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | if(irq & 1) |
| 126 | irq = 9; |
| 127 | else if(irq & 2) |
| 128 | irq = 5; |
| 129 | else if(irq & 4) |
| 130 | irq = 7; |
| 131 | else if(irq & 8) |
| 132 | irq = 10; |
| 133 | else |
| 134 | { |
| 135 | printk(KERN_ERR "kahlua: SB IRQ not set.\n"); |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | printk(KERN_INFO "kahlua: XpressAudio on IRQ %d, DMA %d, %d\n", |
| 140 | irq, dma8, dma16); |
| 141 | |
Robert P. J. Day | 3159f06 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 142 | hw_config = kzalloc(sizeof(struct address_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if(hw_config == NULL) |
| 144 | { |
| 145 | printk(KERN_ERR "kahlua: out of memory.\n"); |
| 146 | return 1; |
| 147 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | pci_set_drvdata(pdev, hw_config); |
| 150 | |
| 151 | hw_config->io_base = io; |
| 152 | hw_config->irq = irq; |
| 153 | hw_config->dma = dma8; |
| 154 | hw_config->dma2 = dma16; |
| 155 | hw_config->name = "Cyrix XpressAudio"; |
| 156 | hw_config->driver_use_1 = SB_NO_MIDI | SB_PCI_IRQ; |
| 157 | |
| 158 | if (!request_region(io, 16, "soundblaster")) |
| 159 | goto err_out_free; |
| 160 | |
| 161 | if(sb_dsp_detect(hw_config, 0, 0, NULL)==0) |
| 162 | { |
| 163 | printk(KERN_ERR "kahlua: audio not responding.\n"); |
| 164 | release_region(io, 16); |
| 165 | goto err_out_free; |
| 166 | } |
| 167 | |
| 168 | oldquiet = sb_be_quiet; |
| 169 | sb_be_quiet = 1; |
| 170 | if(sb_dsp_init(hw_config, THIS_MODULE)) |
| 171 | { |
| 172 | sb_be_quiet = oldquiet; |
| 173 | goto err_out_free; |
| 174 | } |
| 175 | sb_be_quiet = oldquiet; |
| 176 | |
| 177 | return 0; |
| 178 | |
| 179 | err_out_free: |
| 180 | pci_set_drvdata(pdev, NULL); |
| 181 | kfree(hw_config); |
| 182 | return 1; |
| 183 | } |
| 184 | |
| 185 | static void __devexit remove_one(struct pci_dev *pdev) |
| 186 | { |
| 187 | struct address_info *hw_config = pci_get_drvdata(pdev); |
| 188 | sb_dsp_unload(hw_config, 0); |
| 189 | pci_set_drvdata(pdev, NULL); |
| 190 | kfree(hw_config); |
| 191 | } |
| 192 | |
| 193 | MODULE_AUTHOR("Alan Cox"); |
| 194 | MODULE_DESCRIPTION("Kahlua VSA1 PCI Audio"); |
| 195 | MODULE_LICENSE("GPL"); |
| 196 | |
| 197 | /* |
| 198 | * 5530 only. The 5510/5520 decode is different. |
| 199 | */ |
| 200 | |
| 201 | static struct pci_device_id id_tbl[] = { |
| 202 | { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 203 | { } |
| 204 | }; |
| 205 | |
| 206 | MODULE_DEVICE_TABLE(pci, id_tbl); |
| 207 | |
| 208 | static struct pci_driver kahlua_driver = { |
| 209 | .name = "kahlua", |
| 210 | .id_table = id_tbl, |
| 211 | .probe = probe_one, |
| 212 | .remove = __devexit_p(remove_one), |
| 213 | }; |
| 214 | |
| 215 | |
| 216 | static int __init kahlua_init_module(void) |
| 217 | { |
| 218 | printk(KERN_INFO "Cyrix Kahlua VSA1 XpressAudio support (c) Copyright 2003 Red Hat Inc\n"); |
Greg Kroah-Hartman | 4665472 | 2005-12-06 15:33:15 -0800 | [diff] [blame] | 219 | return pci_register_driver(&kahlua_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void __devexit kahlua_cleanup_module(void) |
| 223 | { |
| 224 | pci_unregister_driver(&kahlua_driver); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | module_init(kahlua_init_module); |
| 229 | module_exit(kahlua_cleanup_module); |
| 230 | |