[679] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later
|
---|
| 2 | /*
|
---|
| 3 | * cs5530.c - Initialisation code for Cyrix/NatSemi VSA1 softaudio
|
---|
| 4 | *
|
---|
| 5 | * (C) Copyright 2007 Ash Willis <ashwillis@programmer.net>
|
---|
| 6 | * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk>
|
---|
| 7 | *
|
---|
| 8 | * This driver was ported (shamelessly ripped ;) from oss/kahlua.c but I did
|
---|
| 9 | * mess with it a bit. The chip seems to have to have trouble with full duplex
|
---|
| 10 | * mode. If we're recording in 8bit 8000kHz, say, and we then attempt to
|
---|
| 11 | * simultaneously play back audio at 16bit 44100kHz, the device actually plays
|
---|
| 12 | * back in the same format in which it is capturing. By forcing the chip to
|
---|
| 13 | * always play/capture in 16/44100, we can let alsa-lib convert the samples and
|
---|
| 14 | * that way we can hack up some full duplex audio.
|
---|
| 15 | *
|
---|
| 16 | * XpressAudio(tm) is used on the Cyrix MediaGX (now NatSemi Geode) systems.
|
---|
| 17 | * The older version (VSA1) provides fairly good soundblaster emulation
|
---|
| 18 | * although there are a couple of bugs: large DMA buffers break record,
|
---|
| 19 | * and the MPU event handling seems suspect. VSA2 allows the native driver
|
---|
| 20 | * to control the AC97 audio engine directly and requires a different driver.
|
---|
| 21 | *
|
---|
| 22 | * Thanks to National Semiconductor for providing the needed information
|
---|
| 23 | * on the XpressAudio(tm) internals.
|
---|
| 24 | *
|
---|
| 25 | * TO DO:
|
---|
| 26 | * Investigate whether we can portably support Cognac (5520) in the
|
---|
| 27 | * same manner.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | #ifdef TARGET_OS2
|
---|
| 31 | #define KBUILD_MODNAME "cs5530"
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | #include <linux/delay.h>
|
---|
| 35 | #include <linux/module.h>
|
---|
| 36 | #include <linux/pci.h>
|
---|
| 37 | #include <linux/slab.h>
|
---|
| 38 | #include <sound/core.h>
|
---|
| 39 | #include <sound/sb.h>
|
---|
| 40 | #include <sound/initval.h>
|
---|
| 41 |
|
---|
| 42 | MODULE_AUTHOR("Ash Willis");
|
---|
| 43 | MODULE_DESCRIPTION("CS5530 Audio");
|
---|
| 44 | MODULE_LICENSE("GPL");
|
---|
| 45 |
|
---|
| 46 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
---|
| 47 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
---|
| 48 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
|
---|
| 49 |
|
---|
| 50 | module_param_array(index, int, NULL, 0444);
|
---|
| 51 | MODULE_PARM_DESC(index, "Index value for CS5530 Audio driver.");
|
---|
| 52 | module_param_array(id, charp, NULL, 0444);
|
---|
| 53 | MODULE_PARM_DESC(id, "ID string for CS5530 Audio driver.");
|
---|
| 54 | module_param_array(enable, bool, NULL, 0444);
|
---|
| 55 | MODULE_PARM_DESC(enable, "Enable CS5530 Audio driver.");
|
---|
| 56 |
|
---|
| 57 | struct snd_cs5530 {
|
---|
| 58 | struct snd_card *card;
|
---|
| 59 | struct pci_dev *pci;
|
---|
| 60 | struct snd_sb *sb;
|
---|
| 61 | unsigned long pci_base;
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | static const struct pci_device_id snd_cs5530_ids[] = {
|
---|
| 65 | {PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID,
|
---|
| 66 | PCI_ANY_ID, 0, 0},
|
---|
| 67 | {0,}
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | MODULE_DEVICE_TABLE(pci, snd_cs5530_ids);
|
---|
| 71 |
|
---|
| 72 | static u8 snd_cs5530_mixer_read(unsigned long io, u8 reg)
|
---|
| 73 | {
|
---|
| 74 | outb(reg, io + 4);
|
---|
| 75 | udelay(20);
|
---|
| 76 | reg = inb(io + 5);
|
---|
| 77 | udelay(20);
|
---|
| 78 | return reg;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | static int snd_cs5530_create(struct snd_card *card,
|
---|
[717] | 82 | struct pci_dev *pci)
|
---|
[679] | 83 | {
|
---|
[717] | 84 | struct snd_cs5530 *chip = card->private_data;
|
---|
[679] | 85 | unsigned long sb_base;
|
---|
| 86 | u8 irq, dma8, dma16 = 0;
|
---|
| 87 | u16 map;
|
---|
| 88 | void __iomem *mem;
|
---|
| 89 | int err;
|
---|
| 90 |
|
---|
[717] | 91 | err = pcim_enable_device(pci);
|
---|
[679] | 92 | if (err < 0)
|
---|
| 93 | return err;
|
---|
| 94 |
|
---|
| 95 | chip->card = card;
|
---|
| 96 | chip->pci = pci;
|
---|
| 97 |
|
---|
[717] | 98 | err = pcim_iomap_regions(pci, 1 << 0, "CS5530");
|
---|
| 99 | if (err < 0)
|
---|
[679] | 100 | return err;
|
---|
| 101 | chip->pci_base = pci_resource_start(pci, 0);
|
---|
[717] | 102 | mem = pcim_iomap_table(pci)[0];
|
---|
[679] | 103 | map = readw(mem + 0x18);
|
---|
| 104 |
|
---|
| 105 | /* Map bits
|
---|
| 106 | 0:1 * 0x20 + 0x200 = sb base
|
---|
| 107 | 2 sb enable
|
---|
| 108 | 3 adlib enable
|
---|
| 109 | 5 MPU enable 0x330
|
---|
| 110 | 6 MPU enable 0x300
|
---|
| 111 |
|
---|
| 112 | The other bits may be used internally so must be masked */
|
---|
| 113 |
|
---|
| 114 | sb_base = 0x220 + 0x20 * (map & 3);
|
---|
| 115 |
|
---|
| 116 | if (map & (1<<2))
|
---|
| 117 | dev_info(card->dev, "XpressAudio at 0x%lx\n", sb_base);
|
---|
| 118 | else {
|
---|
| 119 | dev_err(card->dev, "Could not find XpressAudio!\n");
|
---|
| 120 | return -ENODEV;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | if (map & (1<<5))
|
---|
| 124 | dev_info(card->dev, "MPU at 0x300\n");
|
---|
| 125 | else if (map & (1<<6))
|
---|
| 126 | dev_info(card->dev, "MPU at 0x330\n");
|
---|
| 127 |
|
---|
| 128 | irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F;
|
---|
| 129 | dma8 = snd_cs5530_mixer_read(sb_base, 0x81);
|
---|
| 130 |
|
---|
| 131 | if (dma8 & 0x20)
|
---|
| 132 | dma16 = 5;
|
---|
| 133 | else if (dma8 & 0x40)
|
---|
| 134 | dma16 = 6;
|
---|
| 135 | else if (dma8 & 0x80)
|
---|
| 136 | dma16 = 7;
|
---|
| 137 | else {
|
---|
| 138 | dev_err(card->dev, "No 16bit DMA enabled\n");
|
---|
| 139 | return -ENODEV;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | if (dma8 & 0x01)
|
---|
| 143 | dma8 = 0;
|
---|
| 144 | else if (dma8 & 02)
|
---|
| 145 | dma8 = 1;
|
---|
| 146 | else if (dma8 & 0x08)
|
---|
| 147 | dma8 = 3;
|
---|
| 148 | else {
|
---|
| 149 | dev_err(card->dev, "No 8bit DMA enabled\n");
|
---|
| 150 | return -ENODEV;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | if (irq & 1)
|
---|
| 154 | irq = 9;
|
---|
| 155 | else if (irq & 2)
|
---|
| 156 | irq = 5;
|
---|
| 157 | else if (irq & 4)
|
---|
| 158 | irq = 7;
|
---|
| 159 | else if (irq & 8)
|
---|
| 160 | irq = 10;
|
---|
| 161 | else {
|
---|
| 162 | dev_err(card->dev, "SoundBlaster IRQ not set\n");
|
---|
| 163 | return -ENODEV;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | dev_info(card->dev, "IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8, dma16);
|
---|
| 167 |
|
---|
| 168 | err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8,
|
---|
| 169 | dma16, SB_HW_CS5530, &chip->sb);
|
---|
| 170 | if (err < 0) {
|
---|
| 171 | dev_err(card->dev, "Could not create SoundBlaster\n");
|
---|
| 172 | return err;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | err = snd_sb16dsp_pcm(chip->sb, 0);
|
---|
| 176 | if (err < 0) {
|
---|
| 177 | dev_err(card->dev, "Could not create PCM\n");
|
---|
| 178 | return err;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | err = snd_sbmixer_new(chip->sb);
|
---|
| 182 | if (err < 0) {
|
---|
| 183 | dev_err(card->dev, "Could not create Mixer\n");
|
---|
| 184 | return err;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | return 0;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | static int snd_cs5530_probe(struct pci_dev *pci,
|
---|
| 191 | const struct pci_device_id *pci_id)
|
---|
| 192 | {
|
---|
| 193 | static int dev;
|
---|
| 194 | struct snd_card *card;
|
---|
[717] | 195 | struct snd_cs5530 *chip;
|
---|
[679] | 196 | int err;
|
---|
| 197 |
|
---|
| 198 | if (dev >= SNDRV_CARDS)
|
---|
| 199 | return -ENODEV;
|
---|
| 200 | if (!enable[dev]) {
|
---|
| 201 | dev++;
|
---|
| 202 | return -ENOENT;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[717] | 205 | err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
|
---|
| 206 | sizeof(*chip), &card);
|
---|
[679] | 207 | if (err < 0)
|
---|
| 208 | return err;
|
---|
[717] | 209 | chip = card->private_data;
|
---|
[679] | 210 |
|
---|
[717] | 211 | err = snd_cs5530_create(card, pci);
|
---|
| 212 | if (err < 0)
|
---|
[679] | 213 | return err;
|
---|
| 214 |
|
---|
| 215 | strcpy(card->driver, "CS5530");
|
---|
| 216 | strcpy(card->shortname, "CS5530 Audio");
|
---|
| 217 | sprintf(card->longname, "%s at 0x%lx", card->shortname, chip->pci_base);
|
---|
| 218 |
|
---|
| 219 | err = snd_card_register(card);
|
---|
[717] | 220 | if (err < 0)
|
---|
[679] | 221 | return err;
|
---|
| 222 | pci_set_drvdata(pci, card);
|
---|
| 223 | dev++;
|
---|
| 224 | return 0;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | static struct pci_driver cs5530_driver = {
|
---|
| 228 | .name = KBUILD_MODNAME,
|
---|
| 229 | .id_table = snd_cs5530_ids,
|
---|
| 230 | .probe = snd_cs5530_probe,
|
---|
| 231 | };
|
---|
| 232 |
|
---|
| 233 | module_pci_driver(cs5530_driver);
|
---|