1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * cs5530.c - Initialisation code for Cyrix/NatSemi VSA1 softaudio
5 * (C) Copyright 2007 Ash Willis <ashwillis@programmer.net>
6 * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk>
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.
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.
22 * Thanks to National Semiconductor for providing the needed information
23 * on the XpressAudio(tm) internals.
26 * Investigate whether we can portably support Cognac (5520) in the
30 #include <linux/delay.h>
31 #include <linux/module.h>
32 #include <linux/pci.h>
33 #include <linux/slab.h>
34 #include <sound/core.h>
36 #include <sound/initval.h>
38 MODULE_AUTHOR("Ash Willis");
39 MODULE_DESCRIPTION("CS5530 Audio");
40 MODULE_LICENSE("GPL");
42 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
43 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
44 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
46 module_param_array(index
, int, NULL
, 0444);
47 MODULE_PARM_DESC(index
, "Index value for CS5530 Audio driver.");
48 module_param_array(id
, charp
, NULL
, 0444);
49 MODULE_PARM_DESC(id
, "ID string for CS5530 Audio driver.");
50 module_param_array(enable
, bool, NULL
, 0444);
51 MODULE_PARM_DESC(enable
, "Enable CS5530 Audio driver.");
54 struct snd_card
*card
;
57 unsigned long pci_base
;
60 static const struct pci_device_id snd_cs5530_ids
[] = {
61 {PCI_VENDOR_ID_CYRIX
, PCI_DEVICE_ID_CYRIX_5530_AUDIO
, PCI_ANY_ID
,
66 MODULE_DEVICE_TABLE(pci
, snd_cs5530_ids
);
68 static int snd_cs5530_free(struct snd_cs5530
*chip
)
70 pci_release_regions(chip
->pci
);
71 pci_disable_device(chip
->pci
);
76 static int snd_cs5530_dev_free(struct snd_device
*device
)
78 struct snd_cs5530
*chip
= device
->device_data
;
79 return snd_cs5530_free(chip
);
82 static void snd_cs5530_remove(struct pci_dev
*pci
)
84 snd_card_free(pci_get_drvdata(pci
));
87 static u8
snd_cs5530_mixer_read(unsigned long io
, u8 reg
)
96 static int snd_cs5530_create(struct snd_card
*card
,
98 struct snd_cs5530
**rchip
)
100 struct snd_cs5530
*chip
;
101 unsigned long sb_base
;
102 u8 irq
, dma8
, dma16
= 0;
107 static const struct snd_device_ops ops
= {
108 .dev_free
= snd_cs5530_dev_free
,
112 err
= pci_enable_device(pci
);
116 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
118 pci_disable_device(pci
);
125 err
= pci_request_regions(pci
, "CS5530");
128 pci_disable_device(pci
);
131 chip
->pci_base
= pci_resource_start(pci
, 0);
133 mem
= pci_ioremap_bar(pci
, 0);
135 snd_cs5530_free(chip
);
139 map
= readw(mem
+ 0x18);
143 0:1 * 0x20 + 0x200 = sb base
149 The other bits may be used internally so must be masked */
151 sb_base
= 0x220 + 0x20 * (map
& 3);
154 dev_info(card
->dev
, "XpressAudio at 0x%lx\n", sb_base
);
156 dev_err(card
->dev
, "Could not find XpressAudio!\n");
157 snd_cs5530_free(chip
);
162 dev_info(card
->dev
, "MPU at 0x300\n");
163 else if (map
& (1<<6))
164 dev_info(card
->dev
, "MPU at 0x330\n");
166 irq
= snd_cs5530_mixer_read(sb_base
, 0x80) & 0x0F;
167 dma8
= snd_cs5530_mixer_read(sb_base
, 0x81);
171 else if (dma8
& 0x40)
173 else if (dma8
& 0x80)
176 dev_err(card
->dev
, "No 16bit DMA enabled\n");
177 snd_cs5530_free(chip
);
185 else if (dma8
& 0x08)
188 dev_err(card
->dev
, "No 8bit DMA enabled\n");
189 snd_cs5530_free(chip
);
202 dev_err(card
->dev
, "SoundBlaster IRQ not set\n");
203 snd_cs5530_free(chip
);
207 dev_info(card
->dev
, "IRQ: %d DMA8: %d DMA16: %d\n", irq
, dma8
, dma16
);
209 err
= snd_sbdsp_create(card
, sb_base
, irq
, snd_sb16dsp_interrupt
, dma8
,
210 dma16
, SB_HW_CS5530
, &chip
->sb
);
212 dev_err(card
->dev
, "Could not create SoundBlaster\n");
213 snd_cs5530_free(chip
);
217 err
= snd_sb16dsp_pcm(chip
->sb
, 0);
219 dev_err(card
->dev
, "Could not create PCM\n");
220 snd_cs5530_free(chip
);
224 err
= snd_sbmixer_new(chip
->sb
);
226 dev_err(card
->dev
, "Could not create Mixer\n");
227 snd_cs5530_free(chip
);
231 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
233 snd_cs5530_free(chip
);
241 static int snd_cs5530_probe(struct pci_dev
*pci
,
242 const struct pci_device_id
*pci_id
)
245 struct snd_card
*card
;
246 struct snd_cs5530
*chip
= NULL
;
249 if (dev
>= SNDRV_CARDS
)
256 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
262 err
= snd_cs5530_create(card
, pci
, &chip
);
268 strcpy(card
->driver
, "CS5530");
269 strcpy(card
->shortname
, "CS5530 Audio");
270 sprintf(card
->longname
, "%s at 0x%lx", card
->shortname
, chip
->pci_base
);
272 err
= snd_card_register(card
);
277 pci_set_drvdata(pci
, card
);
282 static struct pci_driver cs5530_driver
= {
283 .name
= KBUILD_MODNAME
,
284 .id_table
= snd_cs5530_ids
,
285 .probe
= snd_cs5530_probe
,
286 .remove
= snd_cs5530_remove
,
289 module_pci_driver(cs5530_driver
);