2 * cs5530.c - Initialisation code for Cyrix/NatSemi VSA1 softaudio
4 * (C) Copyright 2007 Ash Willis <ashwillis@programmer.net>
5 * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk>
7 * This driver was ported (shamelessly ripped ;) from oss/kahlua.c but I did
8 * mess with it a bit. The chip seems to have to have trouble with full duplex
9 * mode. If we're recording in 8bit 8000kHz, say, and we then attempt to
10 * simultaneously play back audio at 16bit 44100kHz, the device actually plays
11 * back in the same format in which it is capturing. By forcing the chip to
12 * always play/capture in 16/44100, we can let alsa-lib convert the samples and
13 * that way we can hack up some full duplex audio.
15 * XpressAudio(tm) is used on the Cyrix MediaGX (now NatSemi Geode) systems.
16 * The older version (VSA1) provides fairly good soundblaster emulation
17 * although there are a couple of bugs: large DMA buffers break record,
18 * and the MPU event handling seems suspect. VSA2 allows the native driver
19 * to control the AC97 audio engine directly and requires a different driver.
21 * Thanks to National Semiconductor for providing the needed information
22 * on the XpressAudio(tm) internals.
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the
26 * Free Software Foundation; either version 2, or (at your option) any
29 * This program is distributed in the hope that it will be useful, but
30 * WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * General Public License for more details.
35 * Investigate whether we can portably support Cognac (5520) in the
39 #include <linux/delay.h>
40 #include <linux/moduleparam.h>
41 #include <linux/pci.h>
42 #include <linux/slab.h>
43 #include <sound/core.h>
45 #include <sound/initval.h>
47 MODULE_AUTHOR("Ash Willis");
48 MODULE_DESCRIPTION("CS5530 Audio");
49 MODULE_LICENSE("GPL");
51 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
52 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
53 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
56 struct snd_card *card;
59 unsigned long pci_base;
62 static DEFINE_PCI_DEVICE_TABLE(snd_cs5530_ids) = {
63 {PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID,
68 MODULE_DEVICE_TABLE(pci, snd_cs5530_ids);
70 static int snd_cs5530_free(struct snd_cs5530 *chip)
72 pci_release_regions(chip->pci);
73 pci_disable_device(chip->pci);
78 static int snd_cs5530_dev_free(struct snd_device *device)
80 struct snd_cs5530 *chip = device->device_data;
81 return snd_cs5530_free(chip);
84 static void __devexit snd_cs5530_remove(struct pci_dev *pci)
86 snd_card_free(pci_get_drvdata(pci));
87 pci_set_drvdata(pci, NULL);
90 static u8 __devinit snd_cs5530_mixer_read(unsigned long io, u8 reg)
99 static int __devinit snd_cs5530_create(struct snd_card *card,
101 struct snd_cs5530 **rchip)
103 struct snd_cs5530 *chip;
104 unsigned long sb_base;
105 u8 irq, dma8, dma16 = 0;
110 static struct snd_device_ops ops = {
111 .dev_free = snd_cs5530_dev_free,
115 err = pci_enable_device(pci);
119 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
121 pci_disable_device(pci);
128 err = pci_request_regions(pci, "CS5530");
131 pci_disable_device(pci);
134 chip->pci_base = pci_resource_start(pci, 0);
136 mem = pci_ioremap_bar(pci, 0);
139 pci_disable_device(pci);
143 map = readw(mem + 0x18);
147 0:1 * 0x20 + 0x200 = sb base
153 The other bits may be used internally so must be masked */
155 sb_base = 0x220 + 0x20 * (map & 3);
158 printk(KERN_INFO "CS5530: XpressAudio at 0x%lx\n", sb_base);
160 printk(KERN_ERR "Could not find XpressAudio!\n");
161 snd_cs5530_free(chip);
166 printk(KERN_INFO "CS5530: MPU at 0x300\n");
167 else if (map & (1<<6))
168 printk(KERN_INFO "CS5530: MPU at 0x330\n");
170 irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F;
171 dma8 = snd_cs5530_mixer_read(sb_base, 0x81);
175 else if (dma8 & 0x40)
177 else if (dma8 & 0x80)
180 printk(KERN_ERR "CS5530: No 16bit DMA enabled\n");
181 snd_cs5530_free(chip);
189 else if (dma8 & 0x08)
192 printk(KERN_ERR "CS5530: No 8bit DMA enabled\n");
193 snd_cs5530_free(chip);
206 printk(KERN_ERR "CS5530: SoundBlaster IRQ not set\n");
207 snd_cs5530_free(chip);
211 printk(KERN_INFO "CS5530: IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8,
214 err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8,
215 dma16, SB_HW_CS5530, &chip->sb);
217 printk(KERN_ERR "CS5530: Could not create SoundBlaster\n");
218 snd_cs5530_free(chip);
222 err = snd_sb16dsp_pcm(chip->sb, 0, &chip->sb->pcm);
224 printk(KERN_ERR "CS5530: Could not create PCM\n");
225 snd_cs5530_free(chip);
229 err = snd_sbmixer_new(chip->sb);
231 printk(KERN_ERR "CS5530: Could not create Mixer\n");
232 snd_cs5530_free(chip);
236 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
238 snd_cs5530_free(chip);
242 snd_card_set_dev(card, &pci->dev);
247 static int __devinit snd_cs5530_probe(struct pci_dev *pci,
248 const struct pci_device_id *pci_id)
251 struct snd_card *card;
252 struct snd_cs5530 *chip = NULL;
255 if (dev >= SNDRV_CARDS)
262 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
267 err = snd_cs5530_create(card, pci, &chip);
273 strcpy(card->driver, "CS5530");
274 strcpy(card->shortname, "CS5530 Audio");
275 sprintf(card->longname, "%s at 0x%lx", card->shortname, chip->pci_base);
277 err = snd_card_register(card);
282 pci_set_drvdata(pci, card);
287 static struct pci_driver driver = {
288 .name = "CS5530_Audio",
289 .id_table = snd_cs5530_ids,
290 .probe = snd_cs5530_probe,
291 .remove = __devexit_p(snd_cs5530_remove),
294 static int __init alsa_card_cs5530_init(void)
296 return pci_register_driver(&driver);
299 static void __exit alsa_card_cs5530_exit(void)
301 pci_unregister_driver(&driver);
304 module_init(alsa_card_cs5530_init)
305 module_exit(alsa_card_cs5530_exit)