1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include <linux/delay.h>
40#include <linux/module.h>
41#include <linux/pci.h>
42#include <linux/slab.h>
43#include <sound/core.h>
44#include <sound/sb.h>
45#include <sound/initval.h>
46
47MODULE_AUTHOR("Ash Willis");
48MODULE_DESCRIPTION("CS5530 Audio");
49MODULE_LICENSE("GPL");
50
51static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
52static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
53static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
54
55module_param_array(index, int, NULL, 0444);
56MODULE_PARM_DESC(index, "Index value for CS5530 Audio driver.");
57module_param_array(id, charp, NULL, 0444);
58MODULE_PARM_DESC(id, "ID string for CS5530 Audio driver.");
59module_param_array(enable, bool, NULL, 0444);
60MODULE_PARM_DESC(enable, "Enable CS5530 Audio driver.");
61
62struct snd_cs5530 {
63 struct snd_card *card;
64 struct pci_dev *pci;
65 struct snd_sb *sb;
66 unsigned long pci_base;
67};
68
69static DEFINE_PCI_DEVICE_TABLE(snd_cs5530_ids) = {
70 {PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID,
71 PCI_ANY_ID, 0, 0},
72 {0,}
73};
74
75MODULE_DEVICE_TABLE(pci, snd_cs5530_ids);
76
77static int snd_cs5530_free(struct snd_cs5530 *chip)
78{
79 pci_release_regions(chip->pci);
80 pci_disable_device(chip->pci);
81 kfree(chip);
82 return 0;
83}
84
85static int snd_cs5530_dev_free(struct snd_device *device)
86{
87 struct snd_cs5530 *chip = device->device_data;
88 return snd_cs5530_free(chip);
89}
90
91static void snd_cs5530_remove(struct pci_dev *pci)
92{
93 snd_card_free(pci_get_drvdata(pci));
94 pci_set_drvdata(pci, NULL);
95}
96
97static u8 snd_cs5530_mixer_read(unsigned long io, u8 reg)
98{
99 outb(reg, io + 4);
100 udelay(20);
101 reg = inb(io + 5);
102 udelay(20);
103 return reg;
104}
105
106static int snd_cs5530_create(struct snd_card *card,
107 struct pci_dev *pci,
108 struct snd_cs5530 **rchip)
109{
110 struct snd_cs5530 *chip;
111 unsigned long sb_base;
112 u8 irq, dma8, dma16 = 0;
113 u16 map;
114 void __iomem *mem;
115 int err;
116
117 static struct snd_device_ops ops = {
118 .dev_free = snd_cs5530_dev_free,
119 };
120 *rchip = NULL;
121
122 err = pci_enable_device(pci);
123 if (err < 0)
124 return err;
125
126 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
127 if (chip == NULL) {
128 pci_disable_device(pci);
129 return -ENOMEM;
130 }
131
132 chip->card = card;
133 chip->pci = pci;
134
135 err = pci_request_regions(pci, "CS5530");
136 if (err < 0) {
137 kfree(chip);
138 pci_disable_device(pci);
139 return err;
140 }
141 chip->pci_base = pci_resource_start(pci, 0);
142
143 mem = pci_ioremap_bar(pci, 0);
144 if (mem == NULL) {
145 snd_cs5530_free(chip);
146 return -EBUSY;
147 }
148
149 map = readw(mem + 0x18);
150 iounmap(mem);
151
152
153
154
155
156
157
158
159
160
161 sb_base = 0x220 + 0x20 * (map & 3);
162
163 if (map & (1<<2))
164 printk(KERN_INFO "CS5530: XpressAudio at 0x%lx\n", sb_base);
165 else {
166 printk(KERN_ERR "Could not find XpressAudio!\n");
167 snd_cs5530_free(chip);
168 return -ENODEV;
169 }
170
171 if (map & (1<<5))
172 printk(KERN_INFO "CS5530: MPU at 0x300\n");
173 else if (map & (1<<6))
174 printk(KERN_INFO "CS5530: MPU at 0x330\n");
175
176 irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F;
177 dma8 = snd_cs5530_mixer_read(sb_base, 0x81);
178
179 if (dma8 & 0x20)
180 dma16 = 5;
181 else if (dma8 & 0x40)
182 dma16 = 6;
183 else if (dma8 & 0x80)
184 dma16 = 7;
185 else {
186 printk(KERN_ERR "CS5530: No 16bit DMA enabled\n");
187 snd_cs5530_free(chip);
188 return -ENODEV;
189 }
190
191 if (dma8 & 0x01)
192 dma8 = 0;
193 else if (dma8 & 02)
194 dma8 = 1;
195 else if (dma8 & 0x08)
196 dma8 = 3;
197 else {
198 printk(KERN_ERR "CS5530: No 8bit DMA enabled\n");
199 snd_cs5530_free(chip);
200 return -ENODEV;
201 }
202
203 if (irq & 1)
204 irq = 9;
205 else if (irq & 2)
206 irq = 5;
207 else if (irq & 4)
208 irq = 7;
209 else if (irq & 8)
210 irq = 10;
211 else {
212 printk(KERN_ERR "CS5530: SoundBlaster IRQ not set\n");
213 snd_cs5530_free(chip);
214 return -ENODEV;
215 }
216
217 printk(KERN_INFO "CS5530: IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8,
218 dma16);
219
220 err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8,
221 dma16, SB_HW_CS5530, &chip->sb);
222 if (err < 0) {
223 printk(KERN_ERR "CS5530: Could not create SoundBlaster\n");
224 snd_cs5530_free(chip);
225 return err;
226 }
227
228 err = snd_sb16dsp_pcm(chip->sb, 0, &chip->sb->pcm);
229 if (err < 0) {
230 printk(KERN_ERR "CS5530: Could not create PCM\n");
231 snd_cs5530_free(chip);
232 return err;
233 }
234
235 err = snd_sbmixer_new(chip->sb);
236 if (err < 0) {
237 printk(KERN_ERR "CS5530: Could not create Mixer\n");
238 snd_cs5530_free(chip);
239 return err;
240 }
241
242 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
243 if (err < 0) {
244 snd_cs5530_free(chip);
245 return err;
246 }
247
248 snd_card_set_dev(card, &pci->dev);
249 *rchip = chip;
250 return 0;
251}
252
253static int snd_cs5530_probe(struct pci_dev *pci,
254 const struct pci_device_id *pci_id)
255{
256 static int dev;
257 struct snd_card *card;
258 struct snd_cs5530 *chip = NULL;
259 int err;
260
261 if (dev >= SNDRV_CARDS)
262 return -ENODEV;
263 if (!enable[dev]) {
264 dev++;
265 return -ENOENT;
266 }
267
268 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
269
270 if (err < 0)
271 return err;
272
273 err = snd_cs5530_create(card, pci, &chip);
274 if (err < 0) {
275 snd_card_free(card);
276 return err;
277 }
278
279 strcpy(card->driver, "CS5530");
280 strcpy(card->shortname, "CS5530 Audio");
281 sprintf(card->longname, "%s at 0x%lx", card->shortname, chip->pci_base);
282
283 err = snd_card_register(card);
284 if (err < 0) {
285 snd_card_free(card);
286 return err;
287 }
288 pci_set_drvdata(pci, card);
289 dev++;
290 return 0;
291}
292
293static struct pci_driver cs5530_driver = {
294 .name = KBUILD_MODNAME,
295 .id_table = snd_cs5530_ids,
296 .probe = snd_cs5530_probe,
297 .remove = snd_cs5530_remove,
298};
299
300module_pci_driver(cs5530_driver);
301