GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / oss / dmasound / dmasound_core.c
blobfb05a5322b0c4b05b3777ddb4f05f575f7b37bde
1 /*
2 * linux/sound/oss/dmasound/dmasound_core.c
5 * OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for
6 * Linux/m68k
7 * Extended to support Power Macintosh for Linux/ppc by Paul Mackerras
9 * (c) 1995 by Michael Schlueter & Michael Marte
11 * Michael Schlueter (michael@duck.syd.de) did the basic structure of the VFS
12 * interface and the u-law to signed byte conversion.
14 * Michael Marte (marte@informatik.uni-muenchen.de) did the sound queue,
15 * /dev/mixer, /dev/sndstat and complemented the VFS interface. He would like
16 * to thank:
17 * - Michael Schlueter for initial ideas and documentation on the MFP and
18 * the DMA sound hardware.
19 * - Therapy? for their CD 'Troublegum' which really made me rock.
21 * /dev/sndstat is based on code by Hannu Savolainen, the author of the
22 * VoxWare family of drivers.
24 * This file is subject to the terms and conditions of the GNU General Public
25 * License. See the file COPYING in the main directory of this archive
26 * for more details.
28 * History:
30 * 1995/8/25 First release
32 * 1995/9/02 Roman Hodek:
33 * - Fixed atari_stram_alloc() call, the timer
34 * programming and several race conditions
35 * 1995/9/14 Roman Hodek:
36 * - After some discussion with Michael Schlueter,
37 * revised the interrupt disabling
38 * - Slightly speeded up U8->S8 translation by using
39 * long operations where possible
40 * - Added 4:3 interpolation for /dev/audio
42 * 1995/9/20 Torsten Scherer:
43 * - Fixed a bug in sq_write and changed /dev/audio
44 * converting to play at 12517Hz instead of 6258Hz.
46 * 1995/9/23 Torsten Scherer:
47 * - Changed sq_interrupt() and sq_play() to pre-program
48 * the DMA for another frame while there's still one
49 * running. This allows the IRQ response to be
50 * arbitrarily delayed and playing will still continue.
52 * 1995/10/14 Guenther Kelleter, Torsten Scherer:
53 * - Better support for Falcon audio (the Falcon doesn't
54 * raise an IRQ at the end of a frame, but at the
55 * beginning instead!). uses 'if (codec_dma)' in lots
56 * of places to simply switch between Falcon and TT
57 * code.
59 * 1995/11/06 Torsten Scherer:
60 * - Started introducing a hardware abstraction scheme
61 * (may perhaps also serve for Amigas?)
62 * - Can now play samples at almost all frequencies by
63 * means of a more generalized expand routine
64 * - Takes a good deal of care to cut data only at
65 * sample sizes
66 * - Buffer size is now a kernel runtime option
67 * - Implemented fsync() & several minor improvements
68 * Guenther Kelleter:
69 * - Useful hints and bug fixes
70 * - Cross-checked it for Falcons
72 * 1996/3/9 Geert Uytterhoeven:
73 * - Support added for Amiga, A-law, 16-bit little
74 * endian.
75 * - Unification to drivers/sound/dmasound.c.
77 * 1996/4/6 Martin Mitchell:
78 * - Updated to 1.3 kernel.
80 * 1996/6/13 Topi Kanerva:
81 * - Fixed things that were broken (mainly the amiga
82 * 14-bit routines)
83 * - /dev/sndstat shows now the real hardware frequency
84 * - The lowpass filter is disabled by default now
86 * 1996/9/25 Geert Uytterhoeven:
87 * - Modularization
89 * 1998/6/10 Andreas Schwab:
90 * - Converted to use sound_core
92 * 1999/12/28 Richard Zidlicky:
93 * - Added support for Q40
95 * 2000/2/27 Geert Uytterhoeven:
96 * - Clean up and split the code into 4 parts:
97 * o dmasound_core: machine-independent code
98 * o dmasound_atari: Atari TT and Falcon support
99 * o dmasound_awacs: Apple PowerMac support
100 * o dmasound_paula: Amiga support
102 * 2000/3/25 Geert Uytterhoeven:
103 * - Integration of dmasound_q40
104 * - Small clean ups
106 * 2001/01/26 [1.0] Iain Sandoe
107 * - make /dev/sndstat show revision & edition info.
108 * - since dmasound.mach.sq_setup() can fail on pmac
109 * its type has been changed to int and the returns
110 * are checked.
111 * [1.1] - stop missing translations from being called.
112 * 2001/02/08 [1.2] - remove unused translation tables & move machine-
113 * specific tables to low-level.
114 * - return correct info. for SNDCTL_DSP_GETFMTS.
115 * [1.3] - implement SNDCTL_DSP_GETCAPS fully.
116 * [1.4] - make /dev/sndstat text length usage deterministic.
117 * - make /dev/sndstat call to low-level
118 * dmasound.mach.state_info() pass max space to ll driver.
119 * - tidy startup banners and output info.
120 * [1.5] - tidy up a little (removed some unused #defines in
121 * dmasound.h)
122 * - fix up HAS_RECORD conditionalisation.
123 * - add record code in places it is missing...
124 * - change buf-sizes to bytes to allow < 1kb for pmac
125 * if user param entry is < 256 the value is taken to
126 * be in kb > 256 is taken to be in bytes.
127 * - make default buff/frag params conditional on
128 * machine to allow smaller values for pmac.
129 * - made the ioctls, read & write comply with the OSS
130 * rules on setting params.
131 * - added parsing of _setup() params for record.
132 * 2001/04/04 [1.6] - fix bug where sample rates higher than maximum were
133 * being reported as OK.
134 * - fix open() to return -EBUSY as per OSS doc. when
135 * audio is in use - this is independent of O_NOBLOCK.
136 * - fix bug where SNDCTL_DSP_POST was blocking.
139 /* Record capability notes 30/01/2001:
140 * At present these observations apply only to pmac LL driver (the only one
141 * that can do record, at present). However, if other LL drivers for machines
142 * with record are added they may apply.
144 * The fragment parameters for the record and play channels are separate.
145 * However, if the driver is opened O_RDWR there is no way (in the current OSS
146 * API) to specify their values independently for the record and playback
147 * channels. Since the only common factor between the input & output is the
148 * sample rate (on pmac) it should be possible to open /dev/dspX O_WRONLY and
149 * /dev/dspY O_RDONLY. The input & output channels could then have different
150 * characteristics (other than the first that sets sample rate claiming the
151 * right to set it for ever). As it stands, the format, channels, number of
152 * bits & sample rate are assumed to be common. In the future perhaps these
153 * should be the responsibility of the LL driver - and then if a card really
154 * does not share items between record & playback they can be specified
155 * separately.
158 /* Thread-safeness of shared_resources notes: 31/01/2001
159 * If the user opens O_RDWR and then splits record & play between two threads
160 * both of which inherit the fd - and then starts changing things from both
161 * - we will have difficulty telling.
163 * It's bad application coding - but ...
164 * TODO: think about how to sort this out... without bogging everything down in
165 * semaphores.
167 * Similarly, the OSS spec says "all changes to parameters must be between
168 * open() and the first read() or write(). - and a bit later on (by
169 * implication) "between SNDCTL_DSP_RESET and the first read() or write() after
170 * it". If the app is multi-threaded and this rule is broken between threads
171 * we will have trouble spotting it - and the fault will be rather obscure :-(
173 * We will try and put out at least a kmsg if we see it happen... but I think
174 * it will be quite hard to trap it with an -EXXX return... because we can't
175 * see the fault until after the damage is done.
178 #include <linux/module.h>
179 #include <linux/slab.h>
180 #include <linux/sound.h>
181 #include <linux/init.h>
182 #include <linux/soundcard.h>
183 #include <linux/poll.h>
184 #include <linux/smp_lock.h>
186 #include <asm/uaccess.h>
188 #include "dmasound.h"
190 #define DMASOUND_CORE_REVISION 1
191 #define DMASOUND_CORE_EDITION 6
194 * Declarations
197 int dmasound_catchRadius = 0;
198 module_param(dmasound_catchRadius, int, 0);
200 static unsigned int numWriteBufs = DEFAULT_N_BUFFERS;
201 module_param(numWriteBufs, int, 0);
202 static unsigned int writeBufSize = DEFAULT_BUFF_SIZE ; /* in bytes */
203 module_param(writeBufSize, int, 0);
205 MODULE_LICENSE("GPL");
207 #ifdef MODULE
208 static int sq_unit = -1;
209 static int mixer_unit = -1;
210 static int state_unit = -1;
211 static int irq_installed;
212 #endif /* MODULE */
214 /* control over who can modify resources shared between play/record */
215 static fmode_t shared_resource_owner;
216 static int shared_resources_initialised;
219 * Mid level stuff
222 struct sound_settings dmasound = {
223 .lock = __SPIN_LOCK_UNLOCKED(dmasound.lock)
226 static inline void sound_silence(void)
228 dmasound.mach.silence(); /* _MUST_ stop DMA */
231 static inline int sound_set_format(int format)
233 return dmasound.mach.setFormat(format);
237 static int sound_set_speed(int speed)
239 if (speed < 0)
240 return dmasound.soft.speed;
242 /* trap out-of-range speed settings.
243 at present we allow (arbitrarily) low rates - using soft
244 up-conversion - but we can't allow > max because there is
245 no soft down-conversion.
247 if (dmasound.mach.max_dsp_speed &&
248 (speed > dmasound.mach.max_dsp_speed))
249 speed = dmasound.mach.max_dsp_speed ;
251 dmasound.soft.speed = speed;
253 if (dmasound.minDev == SND_DEV_DSP)
254 dmasound.dsp.speed = dmasound.soft.speed;
256 return dmasound.soft.speed;
259 static int sound_set_stereo(int stereo)
261 if (stereo < 0)
262 return dmasound.soft.stereo;
264 stereo = !!stereo; /* should be 0 or 1 now */
266 dmasound.soft.stereo = stereo;
267 if (dmasound.minDev == SND_DEV_DSP)
268 dmasound.dsp.stereo = stereo;
270 return stereo;
273 static ssize_t sound_copy_translate(TRANS *trans, const u_char __user *userPtr,
274 size_t userCount, u_char frame[],
275 ssize_t *frameUsed, ssize_t frameLeft)
277 ssize_t (*ct_func)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
279 switch (dmasound.soft.format) {
280 case AFMT_MU_LAW:
281 ct_func = trans->ct_ulaw;
282 break;
283 case AFMT_A_LAW:
284 ct_func = trans->ct_alaw;
285 break;
286 case AFMT_S8:
287 ct_func = trans->ct_s8;
288 break;
289 case AFMT_U8:
290 ct_func = trans->ct_u8;
291 break;
292 case AFMT_S16_BE:
293 ct_func = trans->ct_s16be;
294 break;
295 case AFMT_U16_BE:
296 ct_func = trans->ct_u16be;
297 break;
298 case AFMT_S16_LE:
299 ct_func = trans->ct_s16le;
300 break;
301 case AFMT_U16_LE:
302 ct_func = trans->ct_u16le;
303 break;
304 default:
305 return 0;
307 /* if the user has requested a non-existent translation don't try
308 to call it but just return 0 bytes moved
310 if (ct_func)
311 return ct_func(userPtr, userCount, frame, frameUsed, frameLeft);
312 return 0;
316 * /dev/mixer abstraction
319 static struct {
320 int busy;
321 int modify_counter;
322 } mixer;
324 static int mixer_open(struct inode *inode, struct file *file)
326 lock_kernel();
327 if (!try_module_get(dmasound.mach.owner)) {
328 unlock_kernel();
329 return -ENODEV;
331 mixer.busy = 1;
332 unlock_kernel();
333 return 0;
336 static int mixer_release(struct inode *inode, struct file *file)
338 lock_kernel();
339 mixer.busy = 0;
340 module_put(dmasound.mach.owner);
341 unlock_kernel();
342 return 0;
345 static int mixer_ioctl(struct file *file, u_int cmd, u_long arg)
347 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
348 mixer.modify_counter++;
349 switch (cmd) {
350 case OSS_GETVERSION:
351 return IOCTL_OUT(arg, SOUND_VERSION);
352 case SOUND_MIXER_INFO:
354 mixer_info info;
355 memset(&info, 0, sizeof(info));
356 strlcpy(info.id, dmasound.mach.name2, sizeof(info.id));
357 strlcpy(info.name, dmasound.mach.name2, sizeof(info.name));
358 info.modify_counter = mixer.modify_counter;
359 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
360 return -EFAULT;
361 return 0;
364 if (dmasound.mach.mixer_ioctl)
365 return dmasound.mach.mixer_ioctl(cmd, arg);
366 return -EINVAL;
369 static long mixer_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
371 int ret;
373 lock_kernel();
374 ret = mixer_ioctl(file, cmd, arg);
375 unlock_kernel();
377 return ret;
380 static const struct file_operations mixer_fops =
382 .owner = THIS_MODULE,
383 .llseek = no_llseek,
384 .unlocked_ioctl = mixer_unlocked_ioctl,
385 .open = mixer_open,
386 .release = mixer_release,
389 static void mixer_init(void)
391 #ifndef MODULE
392 int mixer_unit;
393 #endif
394 mixer_unit = register_sound_mixer(&mixer_fops, -1);
395 if (mixer_unit < 0)
396 return;
398 mixer.busy = 0;
399 dmasound.treble = 0;
400 dmasound.bass = 0;
401 if (dmasound.mach.mixer_init)
402 dmasound.mach.mixer_init();
407 * Sound queue stuff, the heart of the driver
410 struct sound_queue dmasound_write_sq;
411 static void sq_reset_output(void) ;
413 static int sq_allocate_buffers(struct sound_queue *sq, int num, int size)
415 int i;
417 if (sq->buffers)
418 return 0;
419 sq->numBufs = num;
420 sq->bufSize = size;
421 sq->buffers = kmalloc (num * sizeof(char *), GFP_KERNEL);
422 if (!sq->buffers)
423 return -ENOMEM;
424 for (i = 0; i < num; i++) {
425 sq->buffers[i] = dmasound.mach.dma_alloc(size, GFP_KERNEL);
426 if (!sq->buffers[i]) {
427 while (i--)
428 dmasound.mach.dma_free(sq->buffers[i], size);
429 kfree(sq->buffers);
430 sq->buffers = NULL;
431 return -ENOMEM;
434 return 0;
437 static void sq_release_buffers(struct sound_queue *sq)
439 int i;
441 if (sq->buffers) {
442 for (i = 0; i < sq->numBufs; i++)
443 dmasound.mach.dma_free(sq->buffers[i], sq->bufSize);
444 kfree(sq->buffers);
445 sq->buffers = NULL;
450 static int sq_setup(struct sound_queue *sq)
452 int (*setup_func)(void) = NULL;
453 int hard_frame ;
455 if (sq->locked) { /* are we already set? - and not changeable */
456 #ifdef DEBUG_DMASOUND
457 printk("dmasound_core: tried to sq_setup a locked queue\n") ;
458 #endif
459 return -EINVAL ;
461 sq->locked = 1 ; /* don't think we have a race prob. here _check_ */
463 /* make sure that the parameters are set up
464 This should have been done already...
467 dmasound.mach.init();
469 /* OK. If the user has set fragment parameters explicitly, then we
470 should leave them alone... as long as they are valid.
471 Invalid user fragment params can occur if we allow the whole buffer
472 to be used when the user requests the fragments sizes (with no soft
473 x-lation) and then the user subsequently sets a soft x-lation that
474 requires increased internal buffering.
476 Othwerwise (if the user did not set them) OSS says that we should
477 select frag params on the basis of 0.5 s output & 0.1 s input
478 latency. (TODO. For now we will copy in the defaults.)
481 if (sq->user_frags <= 0) {
482 sq->max_count = sq->numBufs ;
483 sq->max_active = sq->numBufs ;
484 sq->block_size = sq->bufSize;
485 /* set up the user info */
486 sq->user_frags = sq->numBufs ;
487 sq->user_frag_size = sq->bufSize ;
488 sq->user_frag_size *=
489 (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
490 sq->user_frag_size /=
491 (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
492 } else {
493 /* work out requested block size */
494 sq->block_size = sq->user_frag_size ;
495 sq->block_size *=
496 (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
497 sq->block_size /=
498 (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
499 /* the user wants to write frag-size chunks */
500 sq->block_size *= dmasound.hard.speed ;
501 sq->block_size /= dmasound.soft.speed ;
502 /* this only works for size values which are powers of 2 */
503 hard_frame =
504 (dmasound.hard.size * (dmasound.hard.stereo+1))/8 ;
505 sq->block_size += (hard_frame - 1) ;
506 sq->block_size &= ~(hard_frame - 1) ; /* make sure we are aligned */
507 /* let's just check for obvious mistakes */
508 if ( sq->block_size <= 0 || sq->block_size > sq->bufSize) {
509 #ifdef DEBUG_DMASOUND
510 printk("dmasound_core: invalid frag size (user set %d)\n", sq->user_frag_size) ;
511 #endif
512 sq->block_size = sq->bufSize ;
514 if ( sq->user_frags <= sq->numBufs ) {
515 sq->max_count = sq->user_frags ;
516 /* if user has set max_active - then use it */
517 sq->max_active = (sq->max_active <= sq->max_count) ?
518 sq->max_active : sq->max_count ;
519 } else {
520 #ifdef DEBUG_DMASOUND
521 printk("dmasound_core: invalid frag count (user set %d)\n", sq->user_frags) ;
522 #endif
523 sq->max_count =
524 sq->max_active = sq->numBufs ;
527 sq->front = sq->count = sq->rear_size = 0;
528 sq->syncing = 0;
529 sq->active = 0;
531 if (sq == &write_sq) {
532 sq->rear = -1;
533 setup_func = dmasound.mach.write_sq_setup;
535 if (setup_func)
536 return setup_func();
537 return 0 ;
540 static inline void sq_play(void)
542 dmasound.mach.play();
545 static ssize_t sq_write(struct file *file, const char __user *src, size_t uLeft,
546 loff_t *ppos)
548 ssize_t uWritten = 0;
549 u_char *dest;
550 ssize_t uUsed = 0, bUsed, bLeft;
551 unsigned long flags ;
553 /* ++TeSche: Is something like this necessary?
554 * Hey, that's an honest question! Or does any other part of the
555 * filesystem already checks this situation? I really don't know.
557 if (uLeft == 0)
558 return 0;
560 /* implement any changes we have made to the soft/hard params.
561 this is not satisfactory really, all we have done up to now is to
562 say what we would like - there hasn't been any real checking of capability
565 if (shared_resources_initialised == 0) {
566 dmasound.mach.init() ;
567 shared_resources_initialised = 1 ;
570 /* set up the sq if it is not already done. This may seem a dumb place
571 to do it - but it is what OSS requires. It means that write() can
572 return memory allocation errors. To avoid this possibility use the
573 GETBLKSIZE or GETOSPACE ioctls (after you've fiddled with all the
574 params you want to change) - these ioctls also force the setup.
577 if (write_sq.locked == 0) {
578 if ((uWritten = sq_setup(&write_sq)) < 0) return uWritten ;
579 uWritten = 0 ;
582 /* The interrupt doesn't start to play the last, incomplete frame.
583 * Thus we can append to it without disabling the interrupts! (Note
584 * also that write_sq.rear isn't affected by the interrupt.)
587 /* as of 1.6 this behaviour changes if SNDCTL_DSP_POST has been issued:
588 this will mimic the behaviour of syncing and allow the sq_play() to
589 queue a partial fragment. Since sq_play() may/will be called from
590 the IRQ handler - at least on Pmac we have to deal with it.
591 The strategy - possibly not optimum - is to kill _POST status if we
592 get here. This seems, at least, reasonable - in the sense that POST
593 is supposed to indicate that we might not write before the queue
594 is drained - and if we get here in time then it does not apply.
597 spin_lock_irqsave(&dmasound.lock, flags);
598 write_sq.syncing &= ~2 ; /* take out POST status */
599 spin_unlock_irqrestore(&dmasound.lock, flags);
601 if (write_sq.count > 0 &&
602 (bLeft = write_sq.block_size-write_sq.rear_size) > 0) {
603 dest = write_sq.buffers[write_sq.rear];
604 bUsed = write_sq.rear_size;
605 uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
606 dest, &bUsed, bLeft);
607 if (uUsed <= 0)
608 return uUsed;
609 src += uUsed;
610 uWritten += uUsed;
611 uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
612 write_sq.rear_size = bUsed;
615 while (uLeft) {
616 while (write_sq.count >= write_sq.max_active) {
617 sq_play();
618 if (write_sq.non_blocking)
619 return uWritten > 0 ? uWritten : -EAGAIN;
620 SLEEP(write_sq.action_queue);
621 if (signal_pending(current))
622 return uWritten > 0 ? uWritten : -EINTR;
625 /* Here, we can avoid disabling the interrupt by first
626 * copying and translating the data, and then updating
627 * the write_sq variables. Until this is done, the interrupt
628 * won't see the new frame and we can work on it
629 * undisturbed.
632 dest = write_sq.buffers[(write_sq.rear+1) % write_sq.max_count];
633 bUsed = 0;
634 bLeft = write_sq.block_size;
635 uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
636 dest, &bUsed, bLeft);
637 if (uUsed <= 0)
638 break;
639 src += uUsed;
640 uWritten += uUsed;
641 uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
642 if (bUsed) {
643 write_sq.rear = (write_sq.rear+1) % write_sq.max_count;
644 write_sq.rear_size = bUsed;
645 write_sq.count++;
647 } /* uUsed may have been 0 */
649 sq_play();
651 return uUsed < 0? uUsed: uWritten;
654 static unsigned int sq_poll(struct file *file, struct poll_table_struct *wait)
656 unsigned int mask = 0;
657 int retVal;
659 if (write_sq.locked == 0) {
660 if ((retVal = sq_setup(&write_sq)) < 0)
661 return retVal;
662 return 0;
664 if (file->f_mode & FMODE_WRITE )
665 poll_wait(file, &write_sq.action_queue, wait);
666 if (file->f_mode & FMODE_WRITE)
667 if (write_sq.count < write_sq.max_active || write_sq.block_size - write_sq.rear_size > 0)
668 mask |= POLLOUT | POLLWRNORM;
669 return mask;
673 static inline void sq_init_waitqueue(struct sound_queue *sq)
675 init_waitqueue_head(&sq->action_queue);
676 init_waitqueue_head(&sq->open_queue);
677 init_waitqueue_head(&sq->sync_queue);
678 sq->busy = 0;
682 static int sq_open2(struct sound_queue *sq, struct file *file, fmode_t mode,
683 int numbufs, int bufsize)
685 int rc = 0;
687 if (file->f_mode & mode) {
688 if (sq->busy) {
689 /* OSS manual says we will return EBUSY regardless
690 of O_NOBLOCK.
692 return -EBUSY ;
694 sq->busy = 1; /* Let's play spot-the-race-condition */
696 /* allocate the default number & size of buffers.
697 (i.e. specified in _setup() or as module params)
698 can't be changed at the moment - but _could_ be perhaps
699 in the setfragments ioctl.
701 if (( rc = sq_allocate_buffers(sq, numbufs, bufsize))) {
702 sq->busy = 0 ;
703 return rc;
706 sq->non_blocking = file->f_flags & O_NONBLOCK;
708 return rc;
711 #define write_sq_init_waitqueue() sq_init_waitqueue(&write_sq)
712 #define write_sq_release_buffers() sq_release_buffers(&write_sq)
713 #define write_sq_open(file) \
714 sq_open2(&write_sq, file, FMODE_WRITE, numWriteBufs, writeBufSize )
716 static int sq_open(struct inode *inode, struct file *file)
718 int rc;
720 lock_kernel();
721 if (!try_module_get(dmasound.mach.owner)) {
722 unlock_kernel();
723 return -ENODEV;
726 rc = write_sq_open(file); /* checks the f_mode */
727 if (rc)
728 goto out;
729 if (file->f_mode & FMODE_READ) {
730 /* TODO: if O_RDWR, release any resources grabbed by write part */
731 rc = -ENXIO ; /* I think this is what is required by open(2) */
732 goto out;
735 if (dmasound.mach.sq_open)
736 dmasound.mach.sq_open(file->f_mode);
738 /* CHECK whether this is sensible - in the case that dsp0 could be opened
739 O_RDONLY and dsp1 could be opened O_WRONLY
742 dmasound.minDev = iminor(inode) & 0x0f;
744 /* OK. - we should make some attempt at consistency. At least the H'ware
745 options should be set with a valid mode. We will make it that the LL
746 driver must supply defaults for hard & soft params.
749 if (shared_resource_owner == 0) {
750 /* you can make this AFMT_U8/mono/8K if you want to mimic old
751 OSS behaviour - while we still have soft translations ;-) */
752 dmasound.soft = dmasound.mach.default_soft ;
753 dmasound.dsp = dmasound.mach.default_soft ;
754 dmasound.hard = dmasound.mach.default_hard ;
757 #ifndef DMASOUND_STRICT_OSS_COMPLIANCE
758 /* none of the current LL drivers can actually do this "native" at the moment
759 OSS does not really require us to supply /dev/audio if we can't do it.
761 if (dmasound.minDev == SND_DEV_AUDIO) {
762 sound_set_speed(8000);
763 sound_set_stereo(0);
764 sound_set_format(AFMT_MU_LAW);
766 #endif
767 unlock_kernel();
768 return 0;
769 out:
770 module_put(dmasound.mach.owner);
771 unlock_kernel();
772 return rc;
775 static void sq_reset_output(void)
777 sound_silence(); /* this _must_ stop DMA, we might be about to lose the buffers */
778 write_sq.active = 0;
779 write_sq.count = 0;
780 write_sq.rear_size = 0;
781 /* write_sq.front = (write_sq.rear+1) % write_sq.max_count;*/
782 write_sq.front = 0 ;
783 write_sq.rear = -1 ; /* same as for set-up */
785 /* OK - we can unlock the parameters and fragment settings */
786 write_sq.locked = 0 ;
787 write_sq.user_frags = 0 ;
788 write_sq.user_frag_size = 0 ;
791 static void sq_reset(void)
793 sq_reset_output() ;
794 /* we could consider resetting the shared_resources_owner here... but I
795 think it is probably still rather non-obvious to application writer
798 /* we release everything else though */
799 shared_resources_initialised = 0 ;
802 static int sq_fsync(struct file *filp, struct dentry *dentry)
804 int rc = 0;
805 int timeout = 5;
807 write_sq.syncing |= 1;
808 sq_play(); /* there may be an incomplete frame waiting */
810 while (write_sq.active) {
811 SLEEP(write_sq.sync_queue);
812 if (signal_pending(current)) {
813 /* While waiting for audio output to drain, an
814 * interrupt occurred. Stop audio output immediately
815 * and clear the queue. */
816 sq_reset_output();
817 rc = -EINTR;
818 break;
820 if (!--timeout) {
821 printk(KERN_WARNING "dmasound: Timeout draining output\n");
822 sq_reset_output();
823 rc = -EIO;
824 break;
828 /* flag no sync regardless of whether we had a DSP_POST or not */
829 write_sq.syncing = 0 ;
830 return rc;
833 static int sq_release(struct inode *inode, struct file *file)
835 int rc = 0;
837 lock_kernel();
839 if (file->f_mode & FMODE_WRITE) {
840 if (write_sq.busy)
841 rc = sq_fsync(file, file->f_path.dentry);
843 sq_reset_output() ; /* make sure dma is stopped and all is quiet */
844 write_sq_release_buffers();
845 write_sq.busy = 0;
848 if (file->f_mode & shared_resource_owner) { /* it's us that has them */
849 shared_resource_owner = 0 ;
850 shared_resources_initialised = 0 ;
851 dmasound.hard = dmasound.mach.default_hard ;
854 module_put(dmasound.mach.owner);
857 unlock_kernel();
859 return rc;
862 /* here we see if we have a right to modify format, channels, size and so on
863 if no-one else has claimed it already then we do...
865 TODO: We might change this to mask O_RDWR such that only one or the other channel
866 is the owner - if we have problems.
869 static int shared_resources_are_mine(fmode_t md)
871 if (shared_resource_owner)
872 return (shared_resource_owner & md) != 0;
873 else {
874 shared_resource_owner = md ;
875 return 1 ;
879 /* if either queue is locked we must deny the right to change shared params
882 static int queues_are_quiescent(void)
884 if (write_sq.locked)
885 return 0 ;
886 return 1 ;
889 /* check and set a queue's fragments per user's wishes...
890 we will check against the pre-defined literals and the actual sizes.
891 This is a bit fraught - because soft translations can mess with our
892 buffer requirements *after* this call - OSS says "call setfrags first"
895 /* It is possible to replace all the -EINVAL returns with an override that
896 just puts the allowable value in. This may be what many OSS apps require
899 static int set_queue_frags(struct sound_queue *sq, int bufs, int size)
901 if (sq->locked) {
902 #ifdef DEBUG_DMASOUND
903 printk("dmasound_core: tried to set_queue_frags on a locked queue\n") ;
904 #endif
905 return -EINVAL ;
908 if ((size < MIN_FRAG_SIZE) || (size > MAX_FRAG_SIZE))
909 return -EINVAL ;
910 size = (1<<size) ; /* now in bytes */
911 if (size > sq->bufSize)
912 return -EINVAL ; /* this might still not work */
914 if (bufs <= 0)
915 return -EINVAL ;
916 if (bufs > sq->numBufs) /* the user is allowed say "don't care" with 0x7fff */
917 bufs = sq->numBufs ;
919 /* there is, currently, no way to specify max_active separately
920 from max_count. This could be a LL driver issue - I guess
921 if there is a requirement for these values to be different then
922 we will have to pass that info. up to this level.
924 sq->user_frags =
925 sq->max_active = bufs ;
926 sq->user_frag_size = size ;
928 return 0 ;
931 static int sq_ioctl(struct file *file, u_int cmd, u_long arg)
933 int val, result;
934 u_long fmt;
935 int data;
936 int size, nbufs;
937 audio_buf_info info;
939 switch (cmd) {
940 case SNDCTL_DSP_RESET:
941 sq_reset();
942 return 0;
943 break ;
944 case SNDCTL_DSP_GETFMTS:
945 fmt = dmasound.mach.hardware_afmts ; /* this is what OSS says.. */
946 return IOCTL_OUT(arg, fmt);
947 break ;
948 case SNDCTL_DSP_GETBLKSIZE:
949 /* this should tell the caller about bytes that the app can
950 read/write - the app doesn't care about our internal buffers.
951 We force sq_setup() here as per OSS 1.1 (which should
952 compute the values necessary).
953 Since there is no mechanism to specify read/write separately, for
954 fds opened O_RDWR, the write_sq values will, arbitrarily, overwrite
955 the read_sq ones.
957 size = 0 ;
958 if (file->f_mode & FMODE_WRITE) {
959 if ( !write_sq.locked )
960 sq_setup(&write_sq) ;
961 size = write_sq.user_frag_size ;
963 return IOCTL_OUT(arg, size);
964 break ;
965 case SNDCTL_DSP_POST:
966 /* all we are going to do is to tell the LL that any
967 partial frags can be queued for output.
968 The LL will have to clear this flag when last output
969 is queued.
971 write_sq.syncing |= 0x2 ;
972 sq_play() ;
973 return 0 ;
974 case SNDCTL_DSP_SYNC:
975 /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET
976 except that it waits for output to finish before resetting
977 everything - read, however, is killed imediately.
979 result = 0 ;
980 if (file->f_mode & FMODE_WRITE) {
981 result = sq_fsync(file, file->f_path.dentry);
982 sq_reset_output() ;
984 /* if we are the shared resource owner then release them */
985 if (file->f_mode & shared_resource_owner)
986 shared_resources_initialised = 0 ;
987 return result ;
988 break ;
989 case SOUND_PCM_READ_RATE:
990 return IOCTL_OUT(arg, dmasound.soft.speed);
991 case SNDCTL_DSP_SPEED:
992 /* changing this on the fly will have weird effects on the sound.
993 Where there are rate conversions implemented in soft form - it
994 will cause the _ctx_xxx() functions to be substituted.
995 However, there doesn't appear to be any reason to dis-allow it from
996 a driver pov.
998 if (shared_resources_are_mine(file->f_mode)) {
999 IOCTL_IN(arg, data);
1000 data = sound_set_speed(data) ;
1001 shared_resources_initialised = 0 ;
1002 return IOCTL_OUT(arg, data);
1003 } else
1004 return -EINVAL ;
1005 break ;
1006 /* OSS says these next 4 actions are undefined when the device is
1007 busy/active - we will just return -EINVAL.
1008 To be allowed to change one - (a) you have to own the right
1009 (b) the queue(s) must be quiescent
1011 case SNDCTL_DSP_STEREO:
1012 if (shared_resources_are_mine(file->f_mode) &&
1013 queues_are_quiescent()) {
1014 IOCTL_IN(arg, data);
1015 shared_resources_initialised = 0 ;
1016 return IOCTL_OUT(arg, sound_set_stereo(data));
1017 } else
1018 return -EINVAL ;
1019 break ;
1020 case SOUND_PCM_WRITE_CHANNELS:
1021 if (shared_resources_are_mine(file->f_mode) &&
1022 queues_are_quiescent()) {
1023 IOCTL_IN(arg, data);
1024 /* the user might ask for 20 channels, we will return 1 or 2 */
1025 shared_resources_initialised = 0 ;
1026 return IOCTL_OUT(arg, sound_set_stereo(data-1)+1);
1027 } else
1028 return -EINVAL ;
1029 break ;
1030 case SNDCTL_DSP_SETFMT:
1031 if (shared_resources_are_mine(file->f_mode) &&
1032 queues_are_quiescent()) {
1033 int format;
1034 IOCTL_IN(arg, data);
1035 shared_resources_initialised = 0 ;
1036 format = sound_set_format(data);
1037 result = IOCTL_OUT(arg, format);
1038 if (result < 0)
1039 return result;
1040 if (format != data && data != AFMT_QUERY)
1041 return -EINVAL;
1042 return 0;
1043 } else
1044 return -EINVAL ;
1045 case SNDCTL_DSP_SUBDIVIDE:
1046 return -EINVAL ;
1047 case SNDCTL_DSP_SETFRAGMENT:
1048 /* we can do this independently for the two queues - with the
1049 proviso that for fds opened O_RDWR we cannot separate the
1050 actions and both queues will be set per the last call.
1051 NOTE: this does *NOT* actually set the queue up - merely
1052 registers our intentions.
1054 IOCTL_IN(arg, data);
1055 result = 0 ;
1056 nbufs = (data >> 16) & 0x7fff ; /* 0x7fff is 'use maximum' */
1057 size = data & 0xffff;
1058 if (file->f_mode & FMODE_WRITE) {
1059 result = set_queue_frags(&write_sq, nbufs, size) ;
1060 if (result)
1061 return result ;
1063 /* NOTE: this return value is irrelevant - OSS specifically says that
1064 the value is 'random' and that the user _must_ check the actual
1065 frags values using SNDCTL_DSP_GETBLKSIZE or similar */
1066 return IOCTL_OUT(arg, data);
1067 break ;
1068 case SNDCTL_DSP_GETOSPACE:
1071 if (file->f_mode & FMODE_WRITE) {
1072 if ( !write_sq.locked )
1073 sq_setup(&write_sq) ;
1074 info.fragments = write_sq.max_active - write_sq.count;
1075 info.fragstotal = write_sq.max_active;
1076 info.fragsize = write_sq.user_frag_size;
1077 info.bytes = info.fragments * info.fragsize;
1078 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1079 return -EFAULT;
1080 return 0;
1081 } else
1082 return -EINVAL ;
1083 break ;
1084 case SNDCTL_DSP_GETCAPS:
1085 val = dmasound.mach.capabilities & 0xffffff00;
1086 return IOCTL_OUT(arg,val);
1088 default:
1089 return mixer_ioctl(file, cmd, arg);
1091 return -EINVAL;
1094 static long sq_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
1096 int ret;
1098 lock_kernel();
1099 ret = sq_ioctl(file, cmd, arg);
1100 unlock_kernel();
1102 return ret;
1105 static const struct file_operations sq_fops =
1107 .owner = THIS_MODULE,
1108 .llseek = no_llseek,
1109 .write = sq_write,
1110 .poll = sq_poll,
1111 .unlocked_ioctl = sq_unlocked_ioctl,
1112 .open = sq_open,
1113 .release = sq_release,
1116 static int sq_init(void)
1118 const struct file_operations *fops = &sq_fops;
1119 #ifndef MODULE
1120 int sq_unit;
1121 #endif
1123 sq_unit = register_sound_dsp(fops, -1);
1124 if (sq_unit < 0) {
1125 printk(KERN_ERR "dmasound_core: couldn't register fops\n") ;
1126 return sq_unit ;
1129 write_sq_init_waitqueue();
1131 /* These parameters will be restored for every clean open()
1132 * in the case of multiple open()s (e.g. dsp0 & dsp1) they
1133 * will be set so long as the shared resources have no owner.
1136 if (shared_resource_owner == 0) {
1137 dmasound.soft = dmasound.mach.default_soft ;
1138 dmasound.hard = dmasound.mach.default_hard ;
1139 dmasound.dsp = dmasound.mach.default_soft ;
1140 shared_resources_initialised = 0 ;
1142 return 0 ;
1147 * /dev/sndstat
1150 /* we allow more space for record-enabled because there are extra output lines.
1151 the number here must include the amount we are prepared to give to the low-level
1152 driver.
1155 #define STAT_BUFF_LEN 768
1157 /* this is how much space we will allow the low-level driver to use
1158 in the stat buffer. Currently, 2 * (80 character line + <NL>).
1159 We do not police this (it is up to the ll driver to be honest).
1162 #define LOW_LEVEL_STAT_ALLOC 162
1164 static struct {
1165 int busy;
1166 char buf[STAT_BUFF_LEN]; /* state.buf should not overflow! */
1167 int len, ptr;
1168 } state;
1170 /* publish this function for use by low-level code, if required */
1172 static char *get_afmt_string(int afmt)
1174 switch(afmt) {
1175 case AFMT_MU_LAW:
1176 return "mu-law";
1177 break;
1178 case AFMT_A_LAW:
1179 return "A-law";
1180 break;
1181 case AFMT_U8:
1182 return "unsigned 8 bit";
1183 break;
1184 case AFMT_S8:
1185 return "signed 8 bit";
1186 break;
1187 case AFMT_S16_BE:
1188 return "signed 16 bit BE";
1189 break;
1190 case AFMT_U16_BE:
1191 return "unsigned 16 bit BE";
1192 break;
1193 case AFMT_S16_LE:
1194 return "signed 16 bit LE";
1195 break;
1196 case AFMT_U16_LE:
1197 return "unsigned 16 bit LE";
1198 break;
1199 case 0:
1200 return "format not set" ;
1201 break ;
1202 default:
1203 break ;
1205 return "ERROR: Unsupported AFMT_XXXX code" ;
1208 static int state_open(struct inode *inode, struct file *file)
1210 char *buffer = state.buf;
1211 int len = 0;
1212 int ret;
1214 lock_kernel();
1215 ret = -EBUSY;
1216 if (state.busy)
1217 goto out;
1219 ret = -ENODEV;
1220 if (!try_module_get(dmasound.mach.owner))
1221 goto out;
1223 state.ptr = 0;
1224 state.busy = 1;
1226 len += sprintf(buffer+len, "%sDMA sound driver rev %03d :\n",
1227 dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
1228 ((dmasound.mach.version>>8) & 0x0f));
1229 len += sprintf(buffer+len,
1230 "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
1231 DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
1232 (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
1234 /* call the low-level module to fill in any stat info. that it has
1235 if present. Maximum buffer usage is specified.
1238 if (dmasound.mach.state_info)
1239 len += dmasound.mach.state_info(buffer+len,
1240 (size_t) LOW_LEVEL_STAT_ALLOC) ;
1242 /* make usage of the state buffer as deterministic as poss.
1243 exceptional conditions could cause overrun - and this is flagged as
1244 a kernel error.
1247 /* formats and settings */
1249 len += sprintf(buffer+len,"\t\t === Formats & settings ===\n") ;
1250 len += sprintf(buffer+len,"Parameter %20s%20s\n","soft","hard") ;
1251 len += sprintf(buffer+len,"Format :%20s%20s\n",
1252 get_afmt_string(dmasound.soft.format),
1253 get_afmt_string(dmasound.hard.format));
1255 len += sprintf(buffer+len,"Samp Rate:%14d s/sec%14d s/sec\n",
1256 dmasound.soft.speed, dmasound.hard.speed);
1258 len += sprintf(buffer+len,"Channels :%20s%20s\n",
1259 dmasound.soft.stereo ? "stereo" : "mono",
1260 dmasound.hard.stereo ? "stereo" : "mono" );
1262 /* sound queue status */
1264 len += sprintf(buffer+len,"\t\t === Sound Queue status ===\n");
1265 len += sprintf(buffer+len,"Allocated:%8s%6s\n","Buffers","Size") ;
1266 len += sprintf(buffer+len,"%9s:%8d%6d\n",
1267 "write", write_sq.numBufs, write_sq.bufSize) ;
1268 len += sprintf(buffer+len,
1269 "Current : MaxFrg FragSiz MaxAct Frnt Rear "
1270 "Cnt RrSize A B S L xruns\n") ;
1271 len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
1272 "write", write_sq.max_count, write_sq.block_size,
1273 write_sq.max_active, write_sq.front, write_sq.rear,
1274 write_sq.count, write_sq.rear_size, write_sq.active,
1275 write_sq.busy, write_sq.syncing, write_sq.locked, write_sq.xruns) ;
1276 #ifdef DEBUG_DMASOUND
1277 printk("dmasound: stat buffer used %d bytes\n", len) ;
1278 #endif
1280 if (len >= STAT_BUFF_LEN)
1281 printk(KERN_ERR "dmasound_core: stat buffer overflowed!\n");
1283 state.len = len;
1284 ret = 0;
1285 out:
1286 unlock_kernel();
1287 return ret;
1290 static int state_release(struct inode *inode, struct file *file)
1292 lock_kernel();
1293 state.busy = 0;
1294 module_put(dmasound.mach.owner);
1295 unlock_kernel();
1296 return 0;
1299 static ssize_t state_read(struct file *file, char __user *buf, size_t count,
1300 loff_t *ppos)
1302 int n = state.len - state.ptr;
1303 if (n > count)
1304 n = count;
1305 if (n <= 0)
1306 return 0;
1307 if (copy_to_user(buf, &state.buf[state.ptr], n))
1308 return -EFAULT;
1309 state.ptr += n;
1310 return n;
1313 static const struct file_operations state_fops = {
1314 .owner = THIS_MODULE,
1315 .llseek = no_llseek,
1316 .read = state_read,
1317 .open = state_open,
1318 .release = state_release,
1321 static int state_init(void)
1323 #ifndef MODULE
1324 int state_unit;
1325 #endif
1326 state_unit = register_sound_special(&state_fops, SND_DEV_STATUS);
1327 if (state_unit < 0)
1328 return state_unit ;
1329 state.busy = 0;
1330 return 0 ;
1335 * Config & Setup
1337 * This function is called by _one_ chipset-specific driver
1340 int dmasound_init(void)
1342 int res ;
1343 #ifdef MODULE
1344 if (irq_installed)
1345 return -EBUSY;
1346 #endif
1348 /* Set up sound queue, /dev/audio and /dev/dsp. */
1350 /* Set default settings. */
1351 if ((res = sq_init()) < 0)
1352 return res ;
1354 /* Set up /dev/sndstat. */
1355 if ((res = state_init()) < 0)
1356 return res ;
1358 /* Set up /dev/mixer. */
1359 mixer_init();
1361 if (!dmasound.mach.irqinit()) {
1362 printk(KERN_ERR "DMA sound driver: Interrupt initialization failed\n");
1363 return -ENODEV;
1365 #ifdef MODULE
1366 irq_installed = 1;
1367 #endif
1369 printk(KERN_INFO "%s DMA sound driver rev %03d installed\n",
1370 dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
1371 ((dmasound.mach.version>>8) & 0x0f));
1372 printk(KERN_INFO
1373 "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
1374 DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
1375 (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
1376 printk(KERN_INFO "Write will use %4d fragments of %7d bytes as default\n",
1377 numWriteBufs, writeBufSize) ;
1378 return 0;
1381 #ifdef MODULE
1383 void dmasound_deinit(void)
1385 if (irq_installed) {
1386 sound_silence();
1387 dmasound.mach.irqcleanup();
1388 irq_installed = 0;
1391 write_sq_release_buffers();
1393 if (mixer_unit >= 0)
1394 unregister_sound_mixer(mixer_unit);
1395 if (state_unit >= 0)
1396 unregister_sound_special(state_unit);
1397 if (sq_unit >= 0)
1398 unregister_sound_dsp(sq_unit);
1401 #else /* !MODULE */
1403 static int dmasound_setup(char *str)
1405 int ints[6], size;
1407 str = get_options(str, ARRAY_SIZE(ints), ints);
1409 /* check the bootstrap parameter for "dmasound=" */
1412 switch (ints[0]) {
1413 case 3:
1414 if ((ints[3] < 0) || (ints[3] > MAX_CATCH_RADIUS))
1415 printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
1416 else
1417 catchRadius = ints[3];
1418 /* fall through */
1419 case 2:
1420 if (ints[1] < MIN_BUFFERS)
1421 printk("dmasound_setup: invalid number of buffers, using default = %d\n", numWriteBufs);
1422 else
1423 numWriteBufs = ints[1];
1424 /* fall through */
1425 case 1:
1426 if ((size = ints[2]) < 256) /* check for small buffer specs */
1427 size <<= 10 ;
1428 if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
1429 printk("dmasound_setup: invalid write buffer size, using default = %d\n", writeBufSize);
1430 else
1431 writeBufSize = size;
1432 case 0:
1433 break;
1434 default:
1435 printk("dmasound_setup: invalid number of arguments\n");
1436 return 0;
1438 return 1;
1441 __setup("dmasound=", dmasound_setup);
1443 #endif /* !MODULE */
1446 * Conversion tables
1449 #ifdef HAS_8BIT_TABLES
1450 /* 8 bit mu-law */
1452 char dmasound_ulaw2dma8[] = {
1453 -126, -122, -118, -114, -110, -106, -102, -98,
1454 -94, -90, -86, -82, -78, -74, -70, -66,
1455 -63, -61, -59, -57, -55, -53, -51, -49,
1456 -47, -45, -43, -41, -39, -37, -35, -33,
1457 -31, -30, -29, -28, -27, -26, -25, -24,
1458 -23, -22, -21, -20, -19, -18, -17, -16,
1459 -16, -15, -15, -14, -14, -13, -13, -12,
1460 -12, -11, -11, -10, -10, -9, -9, -8,
1461 -8, -8, -7, -7, -7, -7, -6, -6,
1462 -6, -6, -5, -5, -5, -5, -4, -4,
1463 -4, -4, -4, -4, -3, -3, -3, -3,
1464 -3, -3, -3, -3, -2, -2, -2, -2,
1465 -2, -2, -2, -2, -2, -2, -2, -2,
1466 -1, -1, -1, -1, -1, -1, -1, -1,
1467 -1, -1, -1, -1, -1, -1, -1, -1,
1468 -1, -1, -1, -1, -1, -1, -1, 0,
1469 125, 121, 117, 113, 109, 105, 101, 97,
1470 93, 89, 85, 81, 77, 73, 69, 65,
1471 62, 60, 58, 56, 54, 52, 50, 48,
1472 46, 44, 42, 40, 38, 36, 34, 32,
1473 30, 29, 28, 27, 26, 25, 24, 23,
1474 22, 21, 20, 19, 18, 17, 16, 15,
1475 15, 14, 14, 13, 13, 12, 12, 11,
1476 11, 10, 10, 9, 9, 8, 8, 7,
1477 7, 7, 6, 6, 6, 6, 5, 5,
1478 5, 5, 4, 4, 4, 4, 3, 3,
1479 3, 3, 3, 3, 2, 2, 2, 2,
1480 2, 2, 2, 2, 1, 1, 1, 1,
1481 1, 1, 1, 1, 1, 1, 1, 1,
1482 0, 0, 0, 0, 0, 0, 0, 0,
1483 0, 0, 0, 0, 0, 0, 0, 0,
1484 0, 0, 0, 0, 0, 0, 0, 0
1487 /* 8 bit A-law */
1489 char dmasound_alaw2dma8[] = {
1490 -22, -21, -24, -23, -18, -17, -20, -19,
1491 -30, -29, -32, -31, -26, -25, -28, -27,
1492 -11, -11, -12, -12, -9, -9, -10, -10,
1493 -15, -15, -16, -16, -13, -13, -14, -14,
1494 -86, -82, -94, -90, -70, -66, -78, -74,
1495 -118, -114, -126, -122, -102, -98, -110, -106,
1496 -43, -41, -47, -45, -35, -33, -39, -37,
1497 -59, -57, -63, -61, -51, -49, -55, -53,
1498 -2, -2, -2, -2, -2, -2, -2, -2,
1499 -2, -2, -2, -2, -2, -2, -2, -2,
1500 -1, -1, -1, -1, -1, -1, -1, -1,
1501 -1, -1, -1, -1, -1, -1, -1, -1,
1502 -6, -6, -6, -6, -5, -5, -5, -5,
1503 -8, -8, -8, -8, -7, -7, -7, -7,
1504 -3, -3, -3, -3, -3, -3, -3, -3,
1505 -4, -4, -4, -4, -4, -4, -4, -4,
1506 21, 20, 23, 22, 17, 16, 19, 18,
1507 29, 28, 31, 30, 25, 24, 27, 26,
1508 10, 10, 11, 11, 8, 8, 9, 9,
1509 14, 14, 15, 15, 12, 12, 13, 13,
1510 86, 82, 94, 90, 70, 66, 78, 74,
1511 118, 114, 126, 122, 102, 98, 110, 106,
1512 43, 41, 47, 45, 35, 33, 39, 37,
1513 59, 57, 63, 61, 51, 49, 55, 53,
1514 1, 1, 1, 1, 1, 1, 1, 1,
1515 1, 1, 1, 1, 1, 1, 1, 1,
1516 0, 0, 0, 0, 0, 0, 0, 0,
1517 0, 0, 0, 0, 0, 0, 0, 0,
1518 5, 5, 5, 5, 4, 4, 4, 4,
1519 7, 7, 7, 7, 6, 6, 6, 6,
1520 2, 2, 2, 2, 2, 2, 2, 2,
1521 3, 3, 3, 3, 3, 3, 3, 3
1523 #endif /* HAS_8BIT_TABLES */
1526 * Visible symbols for modules
1529 EXPORT_SYMBOL(dmasound);
1530 EXPORT_SYMBOL(dmasound_init);
1531 #ifdef MODULE
1532 EXPORT_SYMBOL(dmasound_deinit);
1533 #endif
1534 EXPORT_SYMBOL(dmasound_write_sq);
1535 EXPORT_SYMBOL(dmasound_catchRadius);
1536 #ifdef HAS_8BIT_TABLES
1537 EXPORT_SYMBOL(dmasound_ulaw2dma8);
1538 EXPORT_SYMBOL(dmasound_alaw2dma8);
1539 #endif