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 int snd_cs5530_free(struct snd_cs5530 *chip)
|
---|
73 | {
|
---|
74 | pci_release_regions(chip->pci);
|
---|
75 | pci_disable_device(chip->pci);
|
---|
76 | kfree(chip);
|
---|
77 | return 0;
|
---|
78 | }
|
---|
79 |
|
---|
80 | static int snd_cs5530_dev_free(struct snd_device *device)
|
---|
81 | {
|
---|
82 | struct snd_cs5530 *chip = device->device_data;
|
---|
83 | return snd_cs5530_free(chip);
|
---|
84 | }
|
---|
85 |
|
---|
86 | static void snd_cs5530_remove(struct pci_dev *pci)
|
---|
87 | {
|
---|
88 | snd_card_free(pci_get_drvdata(pci));
|
---|
89 | }
|
---|
90 |
|
---|
91 | static u8 snd_cs5530_mixer_read(unsigned long io, u8 reg)
|
---|
92 | {
|
---|
93 | outb(reg, io + 4);
|
---|
94 | udelay(20);
|
---|
95 | reg = inb(io + 5);
|
---|
96 | udelay(20);
|
---|
97 | return reg;
|
---|
98 | }
|
---|
99 |
|
---|
100 | static int snd_cs5530_create(struct snd_card *card,
|
---|
101 | struct pci_dev *pci,
|
---|
102 | struct snd_cs5530 **rchip)
|
---|
103 | {
|
---|
104 | struct snd_cs5530 *chip;
|
---|
105 | unsigned long sb_base;
|
---|
106 | u8 irq, dma8, dma16 = 0;
|
---|
107 | u16 map;
|
---|
108 | void __iomem *mem;
|
---|
109 | int err;
|
---|
110 |
|
---|
111 | static const struct snd_device_ops ops = {
|
---|
112 | .dev_free = snd_cs5530_dev_free,
|
---|
113 | };
|
---|
114 | *rchip = NULL;
|
---|
115 |
|
---|
116 | err = pci_enable_device(pci);
|
---|
117 | if (err < 0)
|
---|
118 | return err;
|
---|
119 |
|
---|
120 | chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
---|
121 | if (chip == NULL) {
|
---|
122 | pci_disable_device(pci);
|
---|
123 | return -ENOMEM;
|
---|
124 | }
|
---|
125 |
|
---|
126 | chip->card = card;
|
---|
127 | chip->pci = pci;
|
---|
128 |
|
---|
129 | err = pci_request_regions(pci, "CS5530");
|
---|
130 | if (err < 0) {
|
---|
131 | kfree(chip);
|
---|
132 | pci_disable_device(pci);
|
---|
133 | return err;
|
---|
134 | }
|
---|
135 | chip->pci_base = pci_resource_start(pci, 0);
|
---|
136 |
|
---|
137 | mem = pci_ioremap_bar(pci, 0);
|
---|
138 | if (mem == NULL) {
|
---|
139 | snd_cs5530_free(chip);
|
---|
140 | return -EBUSY;
|
---|
141 | }
|
---|
142 |
|
---|
143 | map = readw(mem + 0x18);
|
---|
144 | iounmap(mem);
|
---|
145 |
|
---|
146 | /* Map bits
|
---|
147 | 0:1 * 0x20 + 0x200 = sb base
|
---|
148 | 2 sb enable
|
---|
149 | 3 adlib enable
|
---|
150 | 5 MPU enable 0x330
|
---|
151 | 6 MPU enable 0x300
|
---|
152 |
|
---|
153 | The other bits may be used internally so must be masked */
|
---|
154 |
|
---|
155 | sb_base = 0x220 + 0x20 * (map & 3);
|
---|
156 |
|
---|
157 | if (map & (1<<2))
|
---|
158 | dev_info(card->dev, "XpressAudio at 0x%lx\n", sb_base);
|
---|
159 | else {
|
---|
160 | dev_err(card->dev, "Could not find XpressAudio!\n");
|
---|
161 | snd_cs5530_free(chip);
|
---|
162 | return -ENODEV;
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (map & (1<<5))
|
---|
166 | dev_info(card->dev, "MPU at 0x300\n");
|
---|
167 | else if (map & (1<<6))
|
---|
168 | dev_info(card->dev, "MPU at 0x330\n");
|
---|
169 |
|
---|
170 | irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F;
|
---|
171 | dma8 = snd_cs5530_mixer_read(sb_base, 0x81);
|
---|
172 |
|
---|
173 | if (dma8 & 0x20)
|
---|
174 | dma16 = 5;
|
---|
175 | else if (dma8 & 0x40)
|
---|
176 | dma16 = 6;
|
---|
177 | else if (dma8 & 0x80)
|
---|
178 | dma16 = 7;
|
---|
179 | else {
|
---|
180 | dev_err(card->dev, "No 16bit DMA enabled\n");
|
---|
181 | snd_cs5530_free(chip);
|
---|
182 | return -ENODEV;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (dma8 & 0x01)
|
---|
186 | dma8 = 0;
|
---|
187 | else if (dma8 & 02)
|
---|
188 | dma8 = 1;
|
---|
189 | else if (dma8 & 0x08)
|
---|
190 | dma8 = 3;
|
---|
191 | else {
|
---|
192 | dev_err(card->dev, "No 8bit DMA enabled\n");
|
---|
193 | snd_cs5530_free(chip);
|
---|
194 | return -ENODEV;
|
---|
195 | }
|
---|
196 |
|
---|
197 | if (irq & 1)
|
---|
198 | irq = 9;
|
---|
199 | else if (irq & 2)
|
---|
200 | irq = 5;
|
---|
201 | else if (irq & 4)
|
---|
202 | irq = 7;
|
---|
203 | else if (irq & 8)
|
---|
204 | irq = 10;
|
---|
205 | else {
|
---|
206 | dev_err(card->dev, "SoundBlaster IRQ not set\n");
|
---|
207 | snd_cs5530_free(chip);
|
---|
208 | return -ENODEV;
|
---|
209 | }
|
---|
210 |
|
---|
211 | dev_info(card->dev, "IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8, dma16);
|
---|
212 |
|
---|
213 | err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8,
|
---|
214 | dma16, SB_HW_CS5530, &chip->sb);
|
---|
215 | if (err < 0) {
|
---|
216 | dev_err(card->dev, "Could not create SoundBlaster\n");
|
---|
217 | snd_cs5530_free(chip);
|
---|
218 | return err;
|
---|
219 | }
|
---|
220 |
|
---|
221 | err = snd_sb16dsp_pcm(chip->sb, 0);
|
---|
222 | if (err < 0) {
|
---|
223 | dev_err(card->dev, "Could not create PCM\n");
|
---|
224 | snd_cs5530_free(chip);
|
---|
225 | return err;
|
---|
226 | }
|
---|
227 |
|
---|
228 | err = snd_sbmixer_new(chip->sb);
|
---|
229 | if (err < 0) {
|
---|
230 | dev_err(card->dev, "Could not create Mixer\n");
|
---|
231 | snd_cs5530_free(chip);
|
---|
232 | return err;
|
---|
233 | }
|
---|
234 |
|
---|
235 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
|
---|
236 | if (err < 0) {
|
---|
237 | snd_cs5530_free(chip);
|
---|
238 | return err;
|
---|
239 | }
|
---|
240 |
|
---|
241 | *rchip = chip;
|
---|
242 | return 0;
|
---|
243 | }
|
---|
244 |
|
---|
245 | static int snd_cs5530_probe(struct pci_dev *pci,
|
---|
246 | const struct pci_device_id *pci_id)
|
---|
247 | {
|
---|
248 | static int dev;
|
---|
249 | struct snd_card *card;
|
---|
250 | struct snd_cs5530 *chip = NULL;
|
---|
251 | int err;
|
---|
252 |
|
---|
253 | if (dev >= SNDRV_CARDS)
|
---|
254 | return -ENODEV;
|
---|
255 | if (!enable[dev]) {
|
---|
256 | dev++;
|
---|
257 | return -ENOENT;
|
---|
258 | }
|
---|
259 |
|
---|
260 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
|
---|
261 | 0, &card);
|
---|
262 |
|
---|
263 | if (err < 0)
|
---|
264 | return err;
|
---|
265 |
|
---|
266 | err = snd_cs5530_create(card, pci, &chip);
|
---|
267 | if (err < 0) {
|
---|
268 | snd_card_free(card);
|
---|
269 | return err;
|
---|
270 | }
|
---|
271 |
|
---|
272 | strcpy(card->driver, "CS5530");
|
---|
273 | strcpy(card->shortname, "CS5530 Audio");
|
---|
274 | sprintf(card->longname, "%s at 0x%lx", card->shortname, chip->pci_base);
|
---|
275 |
|
---|
276 | err = snd_card_register(card);
|
---|
277 | if (err < 0) {
|
---|
278 | snd_card_free(card);
|
---|
279 | return err;
|
---|
280 | }
|
---|
281 | pci_set_drvdata(pci, card);
|
---|
282 | dev++;
|
---|
283 | return 0;
|
---|
284 | }
|
---|
285 |
|
---|
286 | static struct pci_driver cs5530_driver = {
|
---|
287 | .name = KBUILD_MODNAME,
|
---|
288 | .id_table = snd_cs5530_ids,
|
---|
289 | .probe = snd_cs5530_probe,
|
---|
290 | .remove = snd_cs5530_remove,
|
---|
291 | };
|
---|
292 |
|
---|
293 | module_pci_driver(cs5530_driver);
|
---|