| 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,
|
|---|
| 82 | struct pci_dev *pci)
|
|---|
| 83 | {
|
|---|
| 84 | struct snd_cs5530 *chip = card->private_data;
|
|---|
| 85 | unsigned long sb_base;
|
|---|
| 86 | u8 irq, dma8, dma16 = 0;
|
|---|
| 87 | u16 map;
|
|---|
| 88 | void __iomem *mem;
|
|---|
| 89 | int err;
|
|---|
| 90 |
|
|---|
| 91 | err = pcim_enable_device(pci);
|
|---|
| 92 | if (err < 0)
|
|---|
| 93 | return err;
|
|---|
| 94 |
|
|---|
| 95 | chip->card = card;
|
|---|
| 96 | chip->pci = pci;
|
|---|
| 97 |
|
|---|
| 98 | err = pcim_iomap_regions(pci, 1 << 0, "CS5530");
|
|---|
| 99 | if (err < 0)
|
|---|
| 100 | return err;
|
|---|
| 101 | chip->pci_base = pci_resource_start(pci, 0);
|
|---|
| 102 | #ifndef TARGET_OS2
|
|---|
| 103 | mem = pcim_iomap_table(pci)[0];
|
|---|
| 104 | #else
|
|---|
| 105 | mem = pci_ioremap_bar(pci, 0);
|
|---|
| 106 | #endif
|
|---|
| 107 | map = readw(mem + 0x18);
|
|---|
| 108 |
|
|---|
| 109 | /* Map bits
|
|---|
| 110 | 0:1 * 0x20 + 0x200 = sb base
|
|---|
| 111 | 2 sb enable
|
|---|
| 112 | 3 adlib enable
|
|---|
| 113 | 5 MPU enable 0x330
|
|---|
| 114 | 6 MPU enable 0x300
|
|---|
| 115 |
|
|---|
| 116 | The other bits may be used internally so must be masked */
|
|---|
| 117 |
|
|---|
| 118 | sb_base = 0x220 + 0x20 * (map & 3);
|
|---|
| 119 |
|
|---|
| 120 | if (map & (1<<2))
|
|---|
| 121 | dev_info(card->dev, "XpressAudio at 0x%lx\n", sb_base);
|
|---|
| 122 | else {
|
|---|
| 123 | dev_err(card->dev, "Could not find XpressAudio!\n");
|
|---|
| 124 | return -ENODEV;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | if (map & (1<<5))
|
|---|
| 128 | dev_info(card->dev, "MPU at 0x300\n");
|
|---|
| 129 | else if (map & (1<<6))
|
|---|
| 130 | dev_info(card->dev, "MPU at 0x330\n");
|
|---|
| 131 |
|
|---|
| 132 | irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F;
|
|---|
| 133 | dma8 = snd_cs5530_mixer_read(sb_base, 0x81);
|
|---|
| 134 |
|
|---|
| 135 | if (dma8 & 0x20)
|
|---|
| 136 | dma16 = 5;
|
|---|
| 137 | else if (dma8 & 0x40)
|
|---|
| 138 | dma16 = 6;
|
|---|
| 139 | else if (dma8 & 0x80)
|
|---|
| 140 | dma16 = 7;
|
|---|
| 141 | else {
|
|---|
| 142 | dev_err(card->dev, "No 16bit DMA enabled\n");
|
|---|
| 143 | return -ENODEV;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | if (dma8 & 0x01)
|
|---|
| 147 | dma8 = 0;
|
|---|
| 148 | else if (dma8 & 02)
|
|---|
| 149 | dma8 = 1;
|
|---|
| 150 | else if (dma8 & 0x08)
|
|---|
| 151 | dma8 = 3;
|
|---|
| 152 | else {
|
|---|
| 153 | dev_err(card->dev, "No 8bit DMA enabled\n");
|
|---|
| 154 | return -ENODEV;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | if (irq & 1)
|
|---|
| 158 | irq = 9;
|
|---|
| 159 | else if (irq & 2)
|
|---|
| 160 | irq = 5;
|
|---|
| 161 | else if (irq & 4)
|
|---|
| 162 | irq = 7;
|
|---|
| 163 | else if (irq & 8)
|
|---|
| 164 | irq = 10;
|
|---|
| 165 | else {
|
|---|
| 166 | dev_err(card->dev, "SoundBlaster IRQ not set\n");
|
|---|
| 167 | return -ENODEV;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | dev_info(card->dev, "IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8, dma16);
|
|---|
| 171 |
|
|---|
| 172 | err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8,
|
|---|
| 173 | dma16, SB_HW_CS5530, &chip->sb);
|
|---|
| 174 | if (err < 0) {
|
|---|
| 175 | dev_err(card->dev, "Could not create SoundBlaster\n");
|
|---|
| 176 | return err;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | err = snd_sb16dsp_pcm(chip->sb, 0);
|
|---|
| 180 | if (err < 0) {
|
|---|
| 181 | dev_err(card->dev, "Could not create PCM\n");
|
|---|
| 182 | return err;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | err = snd_sbmixer_new(chip->sb);
|
|---|
| 186 | if (err < 0) {
|
|---|
| 187 | dev_err(card->dev, "Could not create Mixer\n");
|
|---|
| 188 | return err;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | return 0;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | static int snd_cs5530_probe(struct pci_dev *pci,
|
|---|
| 195 | const struct pci_device_id *pci_id)
|
|---|
| 196 | {
|
|---|
| 197 | static int dev;
|
|---|
| 198 | struct snd_card *card;
|
|---|
| 199 | struct snd_cs5530 *chip;
|
|---|
| 200 | int err;
|
|---|
| 201 |
|
|---|
| 202 | if (dev >= SNDRV_CARDS)
|
|---|
| 203 | return -ENODEV;
|
|---|
| 204 | if (!enable[dev]) {
|
|---|
| 205 | dev++;
|
|---|
| 206 | return -ENOENT;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
|
|---|
| 210 | sizeof(*chip), &card);
|
|---|
| 211 | if (err < 0)
|
|---|
| 212 | return err;
|
|---|
| 213 | chip = card->private_data;
|
|---|
| 214 |
|
|---|
| 215 | err = snd_cs5530_create(card, pci);
|
|---|
| 216 | if (err < 0)
|
|---|
| 217 | return err;
|
|---|
| 218 |
|
|---|
| 219 | strcpy(card->driver, "CS5530");
|
|---|
| 220 | strcpy(card->shortname, "CS5530 Audio");
|
|---|
| 221 | sprintf(card->longname, "%s at 0x%lx", card->shortname, chip->pci_base);
|
|---|
| 222 |
|
|---|
| 223 | err = snd_card_register(card);
|
|---|
| 224 | if (err < 0)
|
|---|
| 225 | return err;
|
|---|
| 226 | pci_set_drvdata(pci, card);
|
|---|
| 227 | dev++;
|
|---|
| 228 | return 0;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | static struct pci_driver cs5530_driver = {
|
|---|
| 232 | .name = KBUILD_MODNAME,
|
|---|
| 233 | .id_table = snd_cs5530_ids,
|
|---|
| 234 | .probe = snd_cs5530_probe,
|
|---|
| 235 | };
|
|---|
| 236 |
|
|---|
| 237 | module_pci_driver(cs5530_driver);
|
|---|