blob: dcd8d6d2f56f39b6b821f12e503bce389996ccf4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * linux/sound/oss/soundcard.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Sound card driver for Linux
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * integrated sound_switch.c
16 * Stefan Reinauer : integrated /proc/sound (equals to /dev/sndstat,
17 * which should disappear in the near future)
18 * Eric Dumas : devfs support (22-Jan-98) <dumas@linux.eu.org> with
19 * fixups by C. Scott Ananian <cananian@alumni.princeton.edu>
20 * Richard Gooch : moved common (non OSS-specific) devices to sound_core.c
21 * Rob Riggs : Added persistent DMA buffers support (1998/10/17)
22 * Christoph Hellwig : Some cleanup work (2000/03/01)
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "sound_config.h"
27#include <linux/init.h>
28#include <linux/types.h>
29#include <linux/errno.h>
30#include <linux/signal.h>
31#include <linux/fcntl.h>
32#include <linux/ctype.h>
33#include <linux/stddef.h>
34#include <linux/kmod.h>
Ahmed S. Darwishb322f402007-02-12 00:52:07 -080035#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/dma.h>
37#include <asm/io.h>
38#include <linux/wait.h>
39#include <linux/slab.h>
40#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/major.h>
42#include <linux/delay.h>
43#include <linux/proc_fs.h>
44#include <linux/smp_lock.h>
45#include <linux/module.h>
Al Virof23f6e02006-10-20 15:17:02 -040046#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
49 * This ought to be moved into include/asm/dma.h
50 */
51#ifndef valid_dma
52#define valid_dma(n) ((n) >= 0 && (n) < MAX_DMA_CHANNELS && (n) != 4)
53#endif
54
55/*
56 * Table for permanently allocated memory (used when unloading the module)
57 */
58void * sound_mem_blocks[1024];
59int sound_nblocks = 0;
60
61/* Persistent DMA buffers */
62#ifdef CONFIG_SOUND_DMAP
63int sound_dmap_flag = 1;
64#else
65int sound_dmap_flag = 0;
66#endif
67
68static char dma_alloc_map[MAX_DMA_CHANNELS];
69
70#define DMA_MAP_UNAVAIL 0
71#define DMA_MAP_FREE 1
72#define DMA_MAP_BUSY 2
73
74
75unsigned long seq_time = 0; /* Time for /dev/sequencer */
gregkh@suse.de619e6662005-03-23 09:51:41 -080076extern struct class *sound_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/*
79 * Table for configurable mixer volume handling
80 */
81static mixer_vol_table mixer_vols[MAX_MIXER_DEV];
82static int num_mixer_volumes;
83
84int *load_mixer_volumes(char *name, int *levels, int present)
85{
86 int i, n;
87
88 for (i = 0; i < num_mixer_volumes; i++) {
89 if (strcmp(name, mixer_vols[i].name) == 0) {
90 if (present)
91 mixer_vols[i].num = i;
92 return mixer_vols[i].levels;
93 }
94 }
95 if (num_mixer_volumes >= MAX_MIXER_DEV) {
96 printk(KERN_ERR "Sound: Too many mixers (%s)\n", name);
97 return levels;
98 }
99 n = num_mixer_volumes++;
100
101 strcpy(mixer_vols[n].name, name);
102
103 if (present)
104 mixer_vols[n].num = n;
105 else
106 mixer_vols[n].num = -1;
107
108 for (i = 0; i < 32; i++)
109 mixer_vols[n].levels[i] = levels[i];
110 return mixer_vols[n].levels;
111}
Adrian Bunkece7f772006-10-04 02:17:31 -0700112EXPORT_SYMBOL(load_mixer_volumes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int set_mixer_levels(void __user * arg)
115{
116 /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */
117 mixer_vol_table buf;
118
119 if (__copy_from_user(&buf, arg, sizeof(buf)))
120 return -EFAULT;
121 load_mixer_volumes(buf.name, buf.levels, 0);
122 if (__copy_to_user(arg, &buf, sizeof(buf)))
123 return -EFAULT;
124 return 0;
125}
126
127static int get_mixer_levels(void __user * arg)
128{
129 int n;
130
131 if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num))))
132 return -EFAULT;
133 if (n < 0 || n >= num_mixer_volumes)
134 return -EINVAL;
135 if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table)))
136 return -EFAULT;
137 return 0;
138}
139
140/* 4K page size but our output routines use some slack for overruns */
141#define PROC_BLOCK_SIZE (3*1024)
142
143static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
144{
Josef Sipek7bc56322006-12-08 02:37:40 -0800145 int dev = iminor(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 int ret = -EINVAL;
147
148 /*
149 * The OSS drivers aren't remotely happy without this locking,
150 * and unless someone fixes them when they are about to bite the
151 * big one anyway, we might as well bandage here..
152 */
153
154 lock_kernel();
155
156 DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count));
157 switch (dev & 0x0f) {
158 case SND_DEV_DSP:
159 case SND_DEV_DSP16:
160 case SND_DEV_AUDIO:
161 ret = audio_read(dev, file, buf, count);
162 break;
163
164 case SND_DEV_SEQ:
165 case SND_DEV_SEQ2:
166 ret = sequencer_read(dev, file, buf, count);
167 break;
168
169 case SND_DEV_MIDIN:
170 ret = MIDIbuf_read(dev, file, buf, count);
171 }
172 unlock_kernel();
173 return ret;
174}
175
176static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
177{
Josef Sipek7bc56322006-12-08 02:37:40 -0800178 int dev = iminor(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 int ret = -EINVAL;
180
181 lock_kernel();
182 DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count));
183 switch (dev & 0x0f) {
184 case SND_DEV_SEQ:
185 case SND_DEV_SEQ2:
186 ret = sequencer_write(dev, file, buf, count);
187 break;
188
189 case SND_DEV_DSP:
190 case SND_DEV_DSP16:
191 case SND_DEV_AUDIO:
192 ret = audio_write(dev, file, buf, count);
193 break;
194
195 case SND_DEV_MIDIN:
196 ret = MIDIbuf_write(dev, file, buf, count);
197 break;
198 }
199 unlock_kernel();
200 return ret;
201}
202
203static int sound_open(struct inode *inode, struct file *file)
204{
205 int dev = iminor(inode);
206 int retval;
207
208 DEB(printk("sound_open(dev=%d)\n", dev));
209 if ((dev >= SND_NDEVS) || (dev < 0)) {
210 printk(KERN_ERR "Invalid minor device %d\n", dev);
211 return -ENXIO;
212 }
213 switch (dev & 0x0f) {
214 case SND_DEV_CTL:
215 dev >>= 4;
216 if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) {
217 request_module("mixer%d", dev);
218 }
219 if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
220 return -ENXIO;
221
222 if (!try_module_get(mixer_devs[dev]->owner))
223 return -ENXIO;
224 break;
225
226 case SND_DEV_SEQ:
227 case SND_DEV_SEQ2:
228 if ((retval = sequencer_open(dev, file)) < 0)
229 return retval;
230 break;
231
232 case SND_DEV_MIDIN:
233 if ((retval = MIDIbuf_open(dev, file)) < 0)
234 return retval;
235 break;
236
237 case SND_DEV_DSP:
238 case SND_DEV_DSP16:
239 case SND_DEV_AUDIO:
240 if ((retval = audio_open(dev, file)) < 0)
241 return retval;
242 break;
243
244 default:
245 printk(KERN_ERR "Invalid minor device %d\n", dev);
246 return -ENXIO;
247 }
248
249 return 0;
250}
251
252static int sound_release(struct inode *inode, struct file *file)
253{
254 int dev = iminor(inode);
255
256 lock_kernel();
257 DEB(printk("sound_release(dev=%d)\n", dev));
258 switch (dev & 0x0f) {
259 case SND_DEV_CTL:
260 module_put(mixer_devs[dev >> 4]->owner);
261 break;
262
263 case SND_DEV_SEQ:
264 case SND_DEV_SEQ2:
265 sequencer_release(dev, file);
266 break;
267
268 case SND_DEV_MIDIN:
269 MIDIbuf_release(dev, file);
270 break;
271
272 case SND_DEV_DSP:
273 case SND_DEV_DSP16:
274 case SND_DEV_AUDIO:
275 audio_release(dev, file);
276 break;
277
278 default:
279 printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev);
280 }
281 unlock_kernel();
282
283 return 0;
284}
285
286static int get_mixer_info(int dev, void __user *arg)
287{
288 mixer_info info;
289 memset(&info, 0, sizeof(info));
290 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
291 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
292 info.modify_counter = mixer_devs[dev]->modify_counter;
293 if (__copy_to_user(arg, &info, sizeof(info)))
294 return -EFAULT;
295 return 0;
296}
297
298static int get_old_mixer_info(int dev, void __user *arg)
299{
300 _old_mixer_info info;
301 memset(&info, 0, sizeof(info));
302 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
303 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
304 if (copy_to_user(arg, &info, sizeof(info)))
305 return -EFAULT;
306 return 0;
307}
308
309static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg)
310{
311 if (mixdev < 0 || mixdev >= MAX_MIXER_DEV)
312 return -ENXIO;
313 /* Try to load the mixer... */
314 if (mixer_devs[mixdev] == NULL) {
315 request_module("mixer%d", mixdev);
316 }
317 if (mixdev >= num_mixers || !mixer_devs[mixdev])
318 return -ENXIO;
319 if (cmd == SOUND_MIXER_INFO)
320 return get_mixer_info(mixdev, arg);
321 if (cmd == SOUND_OLD_MIXER_INFO)
322 return get_old_mixer_info(mixdev, arg);
323 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
324 mixer_devs[mixdev]->modify_counter++;
325 if (!mixer_devs[mixdev]->ioctl)
326 return -EINVAL;
327 return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
328}
329
330static int sound_ioctl(struct inode *inode, struct file *file,
331 unsigned int cmd, unsigned long arg)
332{
333 int len = 0, dtype;
334 int dev = iminor(inode);
335 void __user *p = (void __user *)arg;
336
337 if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) {
338 /*
339 * Have to validate the address given by the process.
340 */
341 len = _SIOC_SIZE(cmd);
342 if (len < 1 || len > 65536 || !p)
343 return -EFAULT;
344 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
345 if (!access_ok(VERIFY_READ, p, len))
346 return -EFAULT;
347 if (_SIOC_DIR(cmd) & _SIOC_READ)
348 if (!access_ok(VERIFY_WRITE, p, len))
349 return -EFAULT;
350 }
351 DEB(printk("sound_ioctl(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
352 if (cmd == OSS_GETVERSION)
353 return __put_user(SOUND_VERSION, (int __user *)p);
354
355 if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */
356 (dev & 0x0f) != SND_DEV_CTL) {
357 dtype = dev & 0x0f;
358 switch (dtype) {
359 case SND_DEV_DSP:
360 case SND_DEV_DSP16:
361 case SND_DEV_AUDIO:
362 return sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
363 cmd, p);
364
365 default:
366 return sound_mixer_ioctl(dev >> 4, cmd, p);
367 }
368 }
369 switch (dev & 0x0f) {
370 case SND_DEV_CTL:
371 if (cmd == SOUND_MIXER_GETLEVELS)
372 return get_mixer_levels(p);
373 if (cmd == SOUND_MIXER_SETLEVELS)
374 return set_mixer_levels(p);
375 return sound_mixer_ioctl(dev >> 4, cmd, p);
376
377 case SND_DEV_SEQ:
378 case SND_DEV_SEQ2:
379 return sequencer_ioctl(dev, file, cmd, p);
380
381 case SND_DEV_DSP:
382 case SND_DEV_DSP16:
383 case SND_DEV_AUDIO:
384 return audio_ioctl(dev, file, cmd, p);
385 break;
386
387 case SND_DEV_MIDIN:
388 return MIDIbuf_ioctl(dev, file, cmd, p);
389 break;
390
391 }
392 return -EINVAL;
393}
394
395static unsigned int sound_poll(struct file *file, poll_table * wait)
396{
Josef Sipek7bc56322006-12-08 02:37:40 -0800397 struct inode *inode = file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 int dev = iminor(inode);
399
400 DEB(printk("sound_poll(dev=%d)\n", dev));
401 switch (dev & 0x0f) {
402 case SND_DEV_SEQ:
403 case SND_DEV_SEQ2:
404 return sequencer_poll(dev, file, wait);
405
406 case SND_DEV_MIDIN:
407 return MIDIbuf_poll(dev, file, wait);
408
409 case SND_DEV_DSP:
410 case SND_DEV_DSP16:
411 case SND_DEV_AUDIO:
412 return DMAbuf_poll(file, dev >> 4, wait);
413 }
414 return 0;
415}
416
417static int sound_mmap(struct file *file, struct vm_area_struct *vma)
418{
419 int dev_class;
420 unsigned long size;
421 struct dma_buffparms *dmap = NULL;
Josef Sipek7bc56322006-12-08 02:37:40 -0800422 int dev = iminor(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 dev_class = dev & 0x0f;
425 dev >>= 4;
426
427 if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
428 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
429 return -EINVAL;
430 }
431 lock_kernel();
432 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
433 dmap = audio_devs[dev]->dmap_out;
434 else if (vma->vm_flags & VM_READ)
435 dmap = audio_devs[dev]->dmap_in;
436 else {
437 printk(KERN_ERR "Sound: Undefined mmap() access\n");
438 unlock_kernel();
439 return -EINVAL;
440 }
441
442 if (dmap == NULL) {
443 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
444 unlock_kernel();
445 return -EIO;
446 }
447 if (dmap->raw_buf == NULL) {
448 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
449 unlock_kernel();
450 return -EIO;
451 }
452 if (dmap->mapping_flags) {
453 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
454 unlock_kernel();
455 return -EIO;
456 }
457 if (vma->vm_pgoff != 0) {
458 printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
459 unlock_kernel();
460 return -EINVAL;
461 }
462 size = vma->vm_end - vma->vm_start;
463
464 if (size != dmap->bytes_in_use) {
465 printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
466 }
467 if (remap_pfn_range(vma, vma->vm_start,
468 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
469 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
470 unlock_kernel();
471 return -EAGAIN;
472 }
473
474 dmap->mapping_flags |= DMA_MAP_MAPPED;
475
476 if( audio_devs[dev]->d->mmap)
477 audio_devs[dev]->d->mmap(dev);
478
479 memset(dmap->raw_buf,
480 dmap->neutral_byte,
481 dmap->bytes_in_use);
482 unlock_kernel();
483 return 0;
484}
485
Arjan van de Ven9c2e08c2007-02-12 00:55:37 -0800486const struct file_operations oss_sound_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .owner = THIS_MODULE,
488 .llseek = no_llseek,
489 .read = sound_read,
490 .write = sound_write,
491 .poll = sound_poll,
492 .ioctl = sound_ioctl,
493 .mmap = sound_mmap,
494 .open = sound_open,
495 .release = sound_release,
496};
497
498/*
499 * Create the required special subdevices
500 */
501
502static int create_special_devices(void)
503{
504 int seq1,seq2;
505 seq1=register_sound_special(&oss_sound_fops, 1);
506 if(seq1==-1)
507 goto bad;
508 seq2=register_sound_special(&oss_sound_fops, 8);
509 if(seq2!=-1)
510 return 0;
511 unregister_sound_special(1);
512bad:
513 return -1;
514}
515
516
517/* These device names follow the official Linux device list,
518 * Documentation/devices.txt. Let us know if there are other
519 * common names we should support for compatibility.
520 * Only those devices not created by the generic code in sound_core.c are
521 * registered here.
522 */
523static const struct {
524 unsigned short minor;
525 char *name;
526 umode_t mode;
527 int *num;
528} dev_list[] = { /* list of minor devices */
529/* seems to be some confusion here -- this device is not in the device list */
530 {SND_DEV_DSP16, "dspW", S_IWUGO | S_IRUSR | S_IRGRP,
531 &num_audiodevs},
532 {SND_DEV_AUDIO, "audio", S_IWUGO | S_IRUSR | S_IRGRP,
533 &num_audiodevs},
534};
535
536static int dmabuf;
537static int dmabug;
538
539module_param(dmabuf, int, 0444);
540module_param(dmabug, int, 0444);
541
542static int __init oss_init(void)
543{
544 int err;
545 int i, j;
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#ifdef CONFIG_PCI
548 if(dmabug)
549 isa_dma_bridge_buggy = dmabug;
550#endif
551
552 err = create_special_devices();
553 if (err) {
554 printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
555 return err;
556 }
557
558 /* Protecting the innocent */
559 sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
560
Ahmed S. Darwishb322f402007-02-12 00:52:07 -0800561 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
Greg Kroah-Hartmand80f19f2006-08-07 22:19:37 -0700562 device_create(sound_class, NULL,
563 MKDEV(SOUND_MAJOR, dev_list[i].minor),
564 "%s", dev_list[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 if (!dev_list[i].num)
567 continue;
568
Greg Kroah-Hartman0936f262005-06-20 21:15:16 -0700569 for (j = 1; j < *dev_list[i].num; j++)
Greg Kroah-Hartmand80f19f2006-08-07 22:19:37 -0700570 device_create(sound_class, NULL,
571 MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)),
572 "%s%d", dev_list[i].name, j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 }
574
575 if (sound_nblocks >= 1024)
576 printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
577
578 return 0;
579}
580
581static void __exit oss_cleanup(void)
582{
583 int i, j;
584
Ahmed S. Darwishb322f402007-02-12 00:52:07 -0800585 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
Greg Kroah-Hartmand80f19f2006-08-07 22:19:37 -0700586 device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (!dev_list[i].num)
588 continue;
Greg Kroah-Hartman0936f262005-06-20 21:15:16 -0700589 for (j = 1; j < *dev_list[i].num; j++)
Greg Kroah-Hartmand80f19f2006-08-07 22:19:37 -0700590 device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
592
593 unregister_sound_special(1);
594 unregister_sound_special(8);
595
596 sound_stop_timer();
597
598 sequencer_unload();
599
600 for (i = 0; i < MAX_DMA_CHANNELS; i++)
601 if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) {
602 printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i);
603 sound_free_dma(i);
604 }
605
606 for (i = 0; i < sound_nblocks; i++)
607 vfree(sound_mem_blocks[i]);
608
609}
610
611module_init(oss_init);
612module_exit(oss_cleanup);
613MODULE_LICENSE("GPL");
Adrian Bunkece7f772006-10-04 02:17:31 -0700614MODULE_DESCRIPTION("OSS Sound subsystem");
615MODULE_AUTHOR("Hannu Savolainen, et al.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617
618int sound_alloc_dma(int chn, char *deviceID)
619{
620 int err;
621
622 if ((err = request_dma(chn, deviceID)) != 0)
623 return err;
624
625 dma_alloc_map[chn] = DMA_MAP_FREE;
626
627 return 0;
628}
Adrian Bunkece7f772006-10-04 02:17:31 -0700629EXPORT_SYMBOL(sound_alloc_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631int sound_open_dma(int chn, char *deviceID)
632{
633 if (!valid_dma(chn)) {
634 printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn);
635 return 1;
636 }
637
638 if (dma_alloc_map[chn] != DMA_MAP_FREE) {
639 printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]);
640 return 1;
641 }
642 dma_alloc_map[chn] = DMA_MAP_BUSY;
643 return 0;
644}
Adrian Bunkece7f772006-10-04 02:17:31 -0700645EXPORT_SYMBOL(sound_open_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647void sound_free_dma(int chn)
648{
649 if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) {
650 /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */
651 return;
652 }
653 free_dma(chn);
654 dma_alloc_map[chn] = DMA_MAP_UNAVAIL;
655}
Adrian Bunkece7f772006-10-04 02:17:31 -0700656EXPORT_SYMBOL(sound_free_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658void sound_close_dma(int chn)
659{
660 if (dma_alloc_map[chn] != DMA_MAP_BUSY) {
661 printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn);
662 return;
663 }
664 dma_alloc_map[chn] = DMA_MAP_FREE;
665}
Adrian Bunkece7f772006-10-04 02:17:31 -0700666EXPORT_SYMBOL(sound_close_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668static void do_sequencer_timer(unsigned long dummy)
669{
670 sequencer_timer(0);
671}
672
673
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700674static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676void request_sound_timer(int count)
677{
678 extern unsigned long seq_time;
679
680 if (count < 0) {
681 seq_timer.expires = (-count) + jiffies;
682 add_timer(&seq_timer);
683 return;
684 }
685 count += seq_time;
686
687 count -= jiffies;
688
689 if (count < 1)
690 count = 1;
691
692 seq_timer.expires = (count) + jiffies;
693 add_timer(&seq_timer);
694}
695
696void sound_stop_timer(void)
697{
698 del_timer(&seq_timer);
699}
700
701void conf_printf(char *name, struct address_info *hw_config)
702{
703#ifndef CONFIG_SOUND_TRACEINIT
704 return;
705#else
706 printk("<%s> at 0x%03x", name, hw_config->io_base);
707
708 if (hw_config->irq)
709 printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq);
710
711 if (hw_config->dma != -1 || hw_config->dma2 != -1)
712 {
713 printk(" dma %d", hw_config->dma);
714 if (hw_config->dma2 != -1)
715 printk(",%d", hw_config->dma2);
716 }
717 printk("\n");
718#endif
719}
Adrian Bunkece7f772006-10-04 02:17:31 -0700720EXPORT_SYMBOL(conf_printf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722void conf_printf2(char *name, int base, int irq, int dma, int dma2)
723{
724#ifndef CONFIG_SOUND_TRACEINIT
725 return;
726#else
727 printk("<%s> at 0x%03x", name, base);
728
729 if (irq)
730 printk(" irq %d", (irq > 0) ? irq : -irq);
731
732 if (dma != -1 || dma2 != -1)
733 {
734 printk(" dma %d", dma);
735 if (dma2 != -1)
736 printk(",%d", dma2);
737 }
738 printk("\n");
739#endif
740}
Adrian Bunkece7f772006-10-04 02:17:31 -0700741EXPORT_SYMBOL(conf_printf2);
742