]>
Commit | Line | Data |
---|---|---|
2a761ace AM |
1 | diff -u linux-2.4.22/drivers/sound/btaudio.c linux/drivers/sound/btaudio.c |
2 | --- linux-2.4.22/drivers/sound/btaudio.c 2003-09-08 17:26:58.000000000 +0200 | |
3 | +++ linux/drivers/sound/btaudio.c 2003-09-08 17:30:22.000000000 +0200 | |
4 | @@ -1,7 +1,7 @@ | |
5 | /* | |
6 | - btaudio - bt878 audio dma driver for linux 2.4.x | |
7 | + btaudio - bt878 audio dma driver for linux 2.4 / 2.5 | |
8 | ||
9 | - (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org> | |
10 | + (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org> | |
11 | ||
12 | This program is free software; you can redistribute it and/or modify | |
13 | it under the terms of the GNU General Public License as published by | |
14 | @@ -19,14 +19,12 @@ | |
15 | ||
16 | */ | |
17 | ||
18 | -#include <linux/version.h> | |
19 | #include <linux/module.h> | |
20 | #include <linux/errno.h> | |
21 | #include <linux/pci.h> | |
22 | #include <linux/sched.h> | |
23 | #include <linux/signal.h> | |
24 | #include <linux/types.h> | |
25 | -#include <linux/wrapper.h> | |
26 | #include <linux/interrupt.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/poll.h> | |
29 | @@ -37,6 +35,9 @@ | |
30 | #include <asm/uaccess.h> | |
31 | #include <asm/io.h> | |
32 | ||
33 | +# define irqreturn_t void | |
34 | +# define IRQ_RETVAL(foobar) | |
35 | +# define strlcpy(dest,src,len) strncpy(dest,src,(len)-1) | |
36 | ||
37 | /* mmio access */ | |
38 | #define btwrite(dat,adr) writel((dat), (bta->mmio+(adr))) | |
39 | @@ -152,15 +153,30 @@ | |
40 | int rate; | |
41 | }; | |
42 | ||
43 | -static struct btaudio *btaudios = NULL; | |
44 | -static unsigned int debug = 0; | |
45 | -static unsigned int irq_debug = 0; | |
46 | +static struct btaudio *btaudios = NULL; | |
47 | +static unsigned int btcount = 0; | |
48 | +static unsigned int debug = 0; | |
49 | +static unsigned int irq_debug = 0; | |
50 | ||
51 | /* -------------------------------------------------------------- */ | |
52 | ||
53 | #define BUF_DEFAULT 128*1024 | |
54 | #define BUF_MIN 8192 | |
55 | ||
56 | +static void free_buffer(struct btaudio *bta) | |
57 | +{ | |
58 | + if (NULL != bta->buf_cpu) { | |
59 | + pci_free_consistent(bta->pci, bta->buf_size, | |
60 | + bta->buf_cpu, bta->buf_dma); | |
61 | + bta->buf_cpu = NULL; | |
62 | + } | |
63 | + if (NULL != bta->risc_cpu) { | |
64 | + pci_free_consistent(bta->pci, bta->risc_size, | |
65 | + bta->risc_cpu, bta->risc_dma); | |
66 | + bta->risc_cpu = NULL; | |
67 | + } | |
68 | +} | |
69 | + | |
70 | static int alloc_buffer(struct btaudio *bta) | |
71 | { | |
72 | if (NULL == bta->buf_cpu) { | |
73 | @@ -172,7 +188,7 @@ | |
74 | break; | |
75 | } | |
76 | if (NULL == bta->buf_cpu) | |
77 | - return -ENOMEM; | |
78 | + goto err; | |
79 | memset(bta->buf_cpu,0,bta->buf_size); | |
80 | } | |
81 | if (NULL == bta->risc_cpu) { | |
82 | @@ -180,23 +196,13 @@ | |
83 | bta->risc_cpu = pci_alloc_consistent | |
84 | (bta->pci, bta->risc_size, &bta->risc_dma); | |
85 | if (NULL == bta->risc_cpu) | |
86 | - return -ENOMEM; | |
87 | + goto err; | |
88 | } | |
89 | return 0; | |
90 | -} | |
91 | ||
92 | -static void free_buffer(struct btaudio *bta) | |
93 | -{ | |
94 | - if (NULL != bta->buf_cpu) { | |
95 | - pci_free_consistent(bta->pci, bta->buf_size, | |
96 | - bta->buf_cpu, bta->buf_dma); | |
97 | - bta->buf_cpu = NULL; | |
98 | - } | |
99 | - if (NULL != bta->risc_cpu) { | |
100 | - pci_free_consistent(bta->pci, bta->risc_size, | |
101 | - bta->risc_cpu, bta->risc_dma); | |
102 | - bta->risc_cpu = NULL; | |
103 | - } | |
104 | + err: | |
105 | + free_buffer(bta); | |
106 | + return -ENOMEM; | |
107 | } | |
108 | ||
109 | static int make_risc(struct btaudio *bta) | |
110 | @@ -330,8 +336,8 @@ | |
111 | if (cmd == SOUND_MIXER_INFO) { | |
112 | mixer_info info; | |
113 | memset(&info,0,sizeof(info)); | |
114 | - strncpy(info.id,"bt878",sizeof(info.id)-1); | |
115 | - strncpy(info.name,"Brooktree Bt878 audio",sizeof(info.name)-1); | |
116 | + strlcpy(info.id,"bt878",sizeof(info.id)); | |
117 | + strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name)); | |
118 | info.modify_counter = bta->mixcount; | |
119 | if (copy_to_user((void *)arg, &info, sizeof(info))) | |
120 | return -EFAULT; | |
121 | @@ -340,8 +346,8 @@ | |
122 | if (cmd == SOUND_OLD_MIXER_INFO) { | |
123 | _old_mixer_info info; | |
124 | memset(&info,0,sizeof(info)); | |
125 | - strncpy(info.id,"bt878",sizeof(info.id)-1); | |
126 | - strncpy(info.name,"Brooktree Bt878 audio",sizeof(info.name)-1); | |
127 | + strlcpy(info.id,"bt878",sizeof(info.id)); | |
128 | + strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name)); | |
129 | if (copy_to_user((void *)arg, &info, sizeof(info))) | |
130 | return -EFAULT; | |
131 | return 0; | |
132 | @@ -426,11 +432,11 @@ | |
133 | } | |
134 | ||
135 | static struct file_operations btaudio_mixer_fops = { | |
136 | - owner: THIS_MODULE, | |
137 | - llseek: no_llseek, | |
138 | - open: btaudio_mixer_open, | |
139 | - release: btaudio_mixer_release, | |
140 | - ioctl: btaudio_mixer_ioctl, | |
141 | + .owner = THIS_MODULE, | |
142 | + .llseek = no_llseek, | |
143 | + .open = btaudio_mixer_open, | |
144 | + .release = btaudio_mixer_release, | |
145 | + .ioctl = btaudio_mixer_ioctl, | |
146 | }; | |
147 | ||
148 | /* -------------------------------------------------------------- */ | |
149 | @@ -791,25 +797,25 @@ | |
150 | } | |
151 | ||
152 | static struct file_operations btaudio_digital_dsp_fops = { | |
153 | - owner: THIS_MODULE, | |
154 | - llseek: no_llseek, | |
155 | - open: btaudio_dsp_open_digital, | |
156 | - release: btaudio_dsp_release, | |
157 | - read: btaudio_dsp_read, | |
158 | - write: btaudio_dsp_write, | |
159 | - ioctl: btaudio_dsp_ioctl, | |
160 | - poll: btaudio_dsp_poll, | |
161 | + .owner = THIS_MODULE, | |
162 | + .llseek = no_llseek, | |
163 | + .open = btaudio_dsp_open_digital, | |
164 | + .release = btaudio_dsp_release, | |
165 | + .read = btaudio_dsp_read, | |
166 | + .write = btaudio_dsp_write, | |
167 | + .ioctl = btaudio_dsp_ioctl, | |
168 | + .poll = btaudio_dsp_poll, | |
169 | }; | |
170 | ||
171 | static struct file_operations btaudio_analog_dsp_fops = { | |
172 | - owner: THIS_MODULE, | |
173 | - llseek: no_llseek, | |
174 | - open: btaudio_dsp_open_analog, | |
175 | - release: btaudio_dsp_release, | |
176 | - read: btaudio_dsp_read, | |
177 | - write: btaudio_dsp_write, | |
178 | - ioctl: btaudio_dsp_ioctl, | |
179 | - poll: btaudio_dsp_poll, | |
180 | + .owner = THIS_MODULE, | |
181 | + .llseek = no_llseek, | |
182 | + .open = btaudio_dsp_open_analog, | |
183 | + .release = btaudio_dsp_release, | |
184 | + .read = btaudio_dsp_read, | |
185 | + .write = btaudio_dsp_write, | |
186 | + .ioctl = btaudio_dsp_ioctl, | |
187 | + .poll = btaudio_dsp_poll, | |
188 | }; | |
189 | ||
190 | /* -------------------------------------------------------------- */ | |
191 | @@ -818,18 +824,20 @@ | |
192 | "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR", | |
193 | "RIPERR", "PABORT", "OCERR", "SCERR" }; | |
194 | ||
195 | -static void btaudio_irq(int irq, void *dev_id, struct pt_regs * regs) | |
196 | +static irqreturn_t btaudio_irq(int irq, void *dev_id, struct pt_regs * regs) | |
197 | { | |
198 | int count = 0; | |
199 | u32 stat,astat; | |
200 | struct btaudio *bta = dev_id; | |
201 | + int handled = 0; | |
202 | ||
203 | for (;;) { | |
204 | count++; | |
205 | stat = btread(REG_INT_STAT); | |
206 | astat = stat & btread(REG_INT_MASK); | |
207 | if (!astat) | |
208 | - return; | |
209 | + break; | |
210 | + handled = 1; | |
211 | btwrite(astat,REG_INT_STAT); | |
212 | ||
213 | if (irq_debug) { | |
214 | @@ -865,29 +873,31 @@ | |
215 | btwrite(0, REG_INT_MASK); | |
216 | } | |
217 | } | |
218 | - return; | |
219 | + return IRQ_RETVAL(handled); | |
220 | } | |
221 | ||
222 | /* -------------------------------------------------------------- */ | |
223 | ||
224 | -static unsigned int dsp1 = -1; | |
225 | -static unsigned int dsp2 = -1; | |
226 | -static unsigned int mixer = -1; | |
227 | +#define BTAUDIO_MAX 16 | |
228 | + | |
229 | +static unsigned int dsp1[BTAUDIO_MAX] = { [ 0 ... BTAUDIO_MAX-1 ] = -1 }; | |
230 | +static unsigned int dsp2[BTAUDIO_MAX] = { [ 0 ... BTAUDIO_MAX-1 ] = -1 }; | |
231 | +static unsigned int mixer[BTAUDIO_MAX] = { [ 0 ... BTAUDIO_MAX-1 ] = -1 }; | |
232 | +static int digital[BTAUDIO_MAX] = { [ 0 ... BTAUDIO_MAX-1 ] = 1 }; | |
233 | +static int analog[BTAUDIO_MAX] = { [ 0 ... BTAUDIO_MAX-1 ] = 1 }; | |
234 | +static int rate[BTAUDIO_MAX] = { [ 0 ... BTAUDIO_MAX-1 ] = 0 }; | |
235 | static int latency = -1; | |
236 | -static int digital = 1; | |
237 | -static int analog = 1; | |
238 | -static int rate = 0; | |
239 | ||
240 | #define BTA_OSPREY200 1 | |
241 | ||
242 | static struct cardinfo cards[] = { | |
243 | [0] = { | |
244 | - name: "default", | |
245 | - rate: 32000, | |
246 | + .name = "default", | |
247 | + .rate = 32000, | |
248 | }, | |
249 | [BTA_OSPREY200] = { | |
250 | - name: "Osprey 200", | |
251 | - rate: 44100, | |
252 | + .name = "Osprey 200", | |
253 | + .rate = 44100, | |
254 | }, | |
255 | }; | |
256 | ||
257 | @@ -899,6 +909,9 @@ | |
258 | unsigned char revision,lat; | |
259 | int rc = -EBUSY; | |
260 | ||
261 | + if (BTAUDIO_MAX == btcount) | |
262 | + return -EBUSY; | |
263 | + | |
264 | if (pci_enable_device(pci_dev)) | |
265 | return -EIO; | |
266 | if (!request_mem_region(pci_resource_start(pci_dev,0), | |
267 | @@ -932,8 +945,8 @@ | |
268 | ||
269 | /* sample rate */ | |
270 | bta->rate = card->rate; | |
271 | - if (rate) | |
272 | - bta->rate = rate; | |
273 | + if (rate[btcount]) | |
274 | + bta->rate = rate[btcount]; | |
275 | ||
276 | init_MUTEX(&bta->lock); | |
277 | init_waitqueue_head(&bta->readq); | |
278 | @@ -955,7 +968,7 @@ | |
279 | /* init hw */ | |
280 | btwrite(0, REG_GPIO_DMA_CTL); | |
281 | btwrite(0, REG_INT_MASK); | |
282 | - btwrite(~0x0UL, REG_INT_STAT); | |
283 | + btwrite(~(u32)0, REG_INT_STAT); | |
284 | pci_set_master(pci_dev); | |
285 | ||
286 | if ((rc = request_irq(bta->irq, btaudio_irq, SA_SHIRQ|SA_INTERRUPT, | |
287 | @@ -966,9 +979,9 @@ | |
288 | } | |
289 | ||
290 | /* register devices */ | |
291 | - if (digital) { | |
292 | + if (digital[btcount]) { | |
293 | rc = bta->dsp_digital = | |
294 | - register_sound_dsp(&btaudio_digital_dsp_fops,dsp1); | |
295 | + register_sound_dsp(&btaudio_digital_dsp_fops,dsp1[btcount]); | |
296 | if (rc < 0) { | |
297 | printk(KERN_WARNING | |
298 | "btaudio: can't register digital dsp (rc=%d)\n",rc); | |
299 | @@ -977,9 +990,9 @@ | |
300 | printk(KERN_INFO "btaudio: registered device dsp%d [digital]\n", | |
301 | bta->dsp_digital >> 4); | |
302 | } | |
303 | - if (analog) { | |
304 | + if (analog[btcount]) { | |
305 | rc = bta->dsp_analog = | |
306 | - register_sound_dsp(&btaudio_analog_dsp_fops,dsp2); | |
307 | + register_sound_dsp(&btaudio_analog_dsp_fops,dsp2[btcount]); | |
308 | if (rc < 0) { | |
309 | printk(KERN_WARNING | |
310 | "btaudio: can't register analog dsp (rc=%d)\n",rc); | |
311 | @@ -987,7 +1000,8 @@ | |
312 | } | |
313 | printk(KERN_INFO "btaudio: registered device dsp%d [analog]\n", | |
314 | bta->dsp_analog >> 4); | |
315 | - rc = bta->mixer_dev = register_sound_mixer(&btaudio_mixer_fops,mixer); | |
316 | + rc = bta->mixer_dev = register_sound_mixer(&btaudio_mixer_fops, | |
317 | + mixer[btcount]); | |
318 | if (rc < 0) { | |
319 | printk(KERN_WARNING | |
320 | "btaudio: can't register mixer (rc=%d)\n",rc); | |
321 | @@ -1000,6 +1014,7 @@ | |
322 | /* hook into linked list */ | |
323 | bta->next = btaudios; | |
324 | btaudios = bta; | |
325 | + btcount++; | |
326 | ||
327 | pci_set_drvdata(pci_dev,bta); | |
328 | return 0; | |
329 | @@ -1027,7 +1042,7 @@ | |
330 | /* turn off all DMA / IRQs */ | |
331 | btand(~15, REG_GPIO_DMA_CTL); | |
332 | btwrite(0, REG_INT_MASK); | |
333 | - btwrite(~0x0UL, REG_INT_STAT); | |
334 | + btwrite(~(u32)0, REG_INT_STAT); | |
335 | ||
336 | /* unregister devices */ | |
337 | if (digital) { | |
338 | @@ -1052,6 +1067,7 @@ | |
339 | ; /* if (NULL == walk->next) BUG(); */ | |
340 | walk->next = bta->next; | |
341 | } | |
342 | + btcount--; | |
343 | ||
344 | pci_set_drvdata(pci_dev, NULL); | |
345 | kfree(bta); | |
346 | @@ -1060,33 +1076,33 @@ | |
347 | ||
348 | /* -------------------------------------------------------------- */ | |
349 | ||
350 | -static struct pci_device_id btaudio_pci_tbl[] __devinitdata = { | |
351 | +static struct pci_device_id btaudio_pci_tbl[] = { | |
352 | { | |
353 | - vendor: PCI_VENDOR_ID_BROOKTREE, | |
354 | - device: 0x0878, | |
355 | - subvendor: 0x0070, | |
356 | - subdevice: 0xff01, | |
357 | - driver_data: BTA_OSPREY200, | |
358 | + .vendor = PCI_VENDOR_ID_BROOKTREE, | |
359 | + .device = 0x0878, | |
360 | + .subvendor = 0x0070, | |
361 | + .subdevice = 0xff01, | |
362 | + .driver_data = BTA_OSPREY200, | |
363 | },{ | |
364 | - vendor: PCI_VENDOR_ID_BROOKTREE, | |
365 | - device: 0x0878, | |
366 | - subvendor: PCI_ANY_ID, | |
367 | - subdevice: PCI_ANY_ID, | |
368 | + .vendor = PCI_VENDOR_ID_BROOKTREE, | |
369 | + .device = 0x0878, | |
370 | + .subvendor = PCI_ANY_ID, | |
371 | + .subdevice = PCI_ANY_ID, | |
372 | },{ | |
373 | - vendor: PCI_VENDOR_ID_BROOKTREE, | |
374 | - device: 0x0878, | |
375 | - subvendor: PCI_ANY_ID, | |
376 | - subdevice: PCI_ANY_ID, | |
377 | + .vendor = PCI_VENDOR_ID_BROOKTREE, | |
378 | + .device = 0x0879, | |
379 | + .subvendor = PCI_ANY_ID, | |
380 | + .subdevice = PCI_ANY_ID, | |
381 | },{ | |
382 | /* --- end of list --- */ | |
383 | } | |
384 | }; | |
385 | ||
386 | static struct pci_driver btaudio_pci_driver = { | |
387 | - name: "btaudio", | |
388 | - id_table: btaudio_pci_tbl, | |
389 | - probe: btaudio_probe, | |
390 | - remove: __devexit_p(btaudio_remove), | |
391 | + .name = "btaudio", | |
392 | + .id_table = btaudio_pci_tbl, | |
393 | + .probe = btaudio_probe, | |
394 | + .remove = __devexit_p(btaudio_remove), | |
395 | }; | |
396 | ||
397 | static int btaudio_init_module(void) | |
398 | @@ -1107,15 +1123,21 @@ | |
399 | module_init(btaudio_init_module); | |
400 | module_exit(btaudio_cleanup_module); | |
401 | ||
402 | -MODULE_PARM(dsp1,"i"); | |
403 | -MODULE_PARM(dsp2,"i"); | |
404 | -MODULE_PARM(mixer,"i"); | |
405 | -MODULE_PARM(debug,"i"); | |
406 | -MODULE_PARM(irq_debug,"i"); | |
407 | -MODULE_PARM(digital,"i"); | |
408 | -MODULE_PARM(analog,"i"); | |
409 | -MODULE_PARM(rate,"i"); | |
410 | -MODULE_PARM(latency,"i"); | |
411 | +MODULE_PARM(dsp1, "1-" __stringify(BTAUDIO_MAX) "i"); | |
412 | +MODULE_PARM_DESC(dsp1,"digital dsp nr"); | |
413 | +MODULE_PARM(dsp2, "1-" __stringify(BTAUDIO_MAX) "i"); | |
414 | +MODULE_PARM_DESC(dsp2,"analog dsp nr"); | |
415 | +MODULE_PARM(mixer, "1-" __stringify(BTAUDIO_MAX) "i"); | |
416 | +MODULE_PARM_DESC(mixer,"mixer nr"); | |
417 | +MODULE_PARM(debug, "i"); | |
418 | +MODULE_PARM(irq_debug, "i"); | |
419 | +MODULE_PARM(digital, "1-" __stringify(BTAUDIO_MAX) "i"); | |
420 | +MODULE_PARM_DESC(digital,"register digital dsp device"); | |
421 | +MODULE_PARM(analog, "1-" __stringify(BTAUDIO_MAX) "i"); | |
422 | +MODULE_PARM_DESC(analog,"register analog dsp device (and mixer)"); | |
423 | +MODULE_PARM(rate, "1-" __stringify(BTAUDIO_MAX) "i"); | |
424 | +MODULE_PARM_DESC(rate,"sample rate supported by the hardware"); | |
425 | +MODULE_PARM(latency, "i"); | |
426 | MODULE_PARM_DESC(latency,"pci latency timer"); | |
427 | ||
428 | MODULE_DEVICE_TABLE(pci, btaudio_pci_tbl); |