2 * linux/sound/oss/dmasound/dmasound_core.c
5 * OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for
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
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
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
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
66 * - Buffer size is now a kernel runtime option
67 * - Implemented fsync() & several minor improvements
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
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
83 * - /dev/sndstat shows now the real hardware frequency
84 * - The lowpass filter is disabled by default now
86 * 1996/9/25 Geert Uytterhoeven:
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
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
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
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
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
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
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);
206 static unsigned int numReadBufs = DEFAULT_N_BUFFERS;
207 module_param(numReadBufs, int, 0);
208 static unsigned int readBufSize = DEFAULT_BUFF_SIZE; /* in bytes */
209 module_param(readBufSize, int, 0);
212 MODULE_LICENSE("GPL");
215 static int sq_unit = -1;
216 static int mixer_unit = -1;
217 static int state_unit = -1;
218 static int irq_installed;
221 /* software implemented recording volume! */
222 uint software_input_volume = SW_INPUT_VOLUME_SCALE * SW_INPUT_VOLUME_DEFAULT;
223 EXPORT_SYMBOL(software_input_volume);
225 /* control over who can modify resources shared between play/record */
226 static mode_t shared_resource_owner;
227 static int shared_resources_initialised;
233 struct sound_settings dmasound = { .lock = SPIN_LOCK_UNLOCKED };
235 static inline void sound_silence(void)
237 dmasound.mach.silence(); /* _MUST_ stop DMA */
240 static inline int sound_set_format(int format)
242 return dmasound.mach.setFormat(format);
246 static int sound_set_speed(int speed)
249 return dmasound.soft.speed;
251 /* trap out-of-range speed settings.
252 at present we allow (arbitrarily) low rates - using soft
253 up-conversion - but we can't allow > max because there is
254 no soft down-conversion.
256 if (dmasound.mach.max_dsp_speed &&
257 (speed > dmasound.mach.max_dsp_speed))
258 speed = dmasound.mach.max_dsp_speed ;
260 dmasound.soft.speed = speed;
262 if (dmasound.minDev == SND_DEV_DSP)
263 dmasound.dsp.speed = dmasound.soft.speed;
265 return dmasound.soft.speed;
268 static int sound_set_stereo(int stereo)
271 return dmasound.soft.stereo;
273 stereo = !!stereo; /* should be 0 or 1 now */
275 dmasound.soft.stereo = stereo;
276 if (dmasound.minDev == SND_DEV_DSP)
277 dmasound.dsp.stereo = stereo;
282 static ssize_t sound_copy_translate(TRANS *trans, const u_char __user *userPtr,
283 size_t userCount, u_char frame[],
284 ssize_t *frameUsed, ssize_t frameLeft)
286 ssize_t (*ct_func)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
288 switch (dmasound.soft.format) {
290 ct_func = trans->ct_ulaw;
293 ct_func = trans->ct_alaw;
296 ct_func = trans->ct_s8;
299 ct_func = trans->ct_u8;
302 ct_func = trans->ct_s16be;
305 ct_func = trans->ct_u16be;
308 ct_func = trans->ct_s16le;
311 ct_func = trans->ct_u16le;
316 /* if the user has requested a non-existent translation don't try
317 to call it but just return 0 bytes moved
320 return ct_func(userPtr, userCount, frame, frameUsed, frameLeft);
325 * /dev/mixer abstraction
333 static int mixer_open(struct inode *inode, struct file *file)
335 if (!try_module_get(dmasound.mach.owner))
341 static int mixer_release(struct inode *inode, struct file *file)
345 module_put(dmasound.mach.owner);
349 static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
352 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
353 mixer.modify_counter++;
356 return IOCTL_OUT(arg, SOUND_VERSION);
357 case SOUND_MIXER_INFO:
360 memset(&info, 0, sizeof(info));
361 strlcpy(info.id, dmasound.mach.name2, sizeof(info.id));
362 strlcpy(info.name, dmasound.mach.name2, sizeof(info.name));
363 info.modify_counter = mixer.modify_counter;
364 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
369 if (dmasound.mach.mixer_ioctl)
370 return dmasound.mach.mixer_ioctl(cmd, arg);
374 static const struct file_operations mixer_fops =
376 .owner = THIS_MODULE,
378 .ioctl = mixer_ioctl,
380 .release = mixer_release,
383 static void mixer_init(void)
388 mixer_unit = register_sound_mixer(&mixer_fops, -1);
395 if (dmasound.mach.mixer_init)
396 dmasound.mach.mixer_init();
401 * Sound queue stuff, the heart of the driver
404 struct sound_queue dmasound_write_sq;
405 static void sq_reset_output(void) ;
407 struct sound_queue dmasound_read_sq;
408 static void sq_reset_input(void) ;
411 static int sq_allocate_buffers(struct sound_queue *sq, int num, int size)
419 sq->buffers = kmalloc (num * sizeof(char *), GFP_KERNEL);
422 for (i = 0; i < num; i++) {
423 sq->buffers[i] = dmasound.mach.dma_alloc(size, GFP_KERNEL);
424 if (!sq->buffers[i]) {
426 dmasound.mach.dma_free(sq->buffers[i], size);
435 static void sq_release_buffers(struct sound_queue *sq)
440 for (i = 0; i < sq->numBufs; i++)
441 dmasound.mach.dma_free(sq->buffers[i], sq->bufSize);
448 static int sq_setup(struct sound_queue *sq)
450 int (*setup_func)(void) = NULL;
453 if (sq->locked) { /* are we already set? - and not changeable */
454 #ifdef DEBUG_DMASOUND
455 printk("dmasound_core: tried to sq_setup a locked queue\n") ;
459 sq->locked = 1 ; /* don't think we have a race prob. here _check_ */
461 /* make sure that the parameters are set up
462 This should have been done already...
465 dmasound.mach.init();
467 /* OK. If the user has set fragment parameters explicitly, then we
468 should leave them alone... as long as they are valid.
469 Invalid user fragment params can occur if we allow the whole buffer
470 to be used when the user requests the fragments sizes (with no soft
471 x-lation) and then the user subsequently sets a soft x-lation that
472 requires increased internal buffering.
474 Othwerwise (if the user did not set them) OSS says that we should
475 select frag params on the basis of 0.5 s output & 0.1 s input
476 latency. (TODO. For now we will copy in the defaults.)
479 if (sq->user_frags <= 0) {
480 sq->max_count = sq->numBufs ;
481 sq->max_active = sq->numBufs ;
482 sq->block_size = sq->bufSize;
483 /* set up the user info */
484 sq->user_frags = sq->numBufs ;
485 sq->user_frag_size = sq->bufSize ;
486 sq->user_frag_size *=
487 (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
488 sq->user_frag_size /=
489 (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
491 /* work out requested block size */
492 sq->block_size = sq->user_frag_size ;
494 (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
496 (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
497 /* the user wants to write frag-size chunks */
498 sq->block_size *= dmasound.hard.speed ;
499 sq->block_size /= dmasound.soft.speed ;
500 /* this only works for size values which are powers of 2 */
502 (dmasound.hard.size * (dmasound.hard.stereo+1))/8 ;
503 sq->block_size += (hard_frame - 1) ;
504 sq->block_size &= ~(hard_frame - 1) ; /* make sure we are aligned */
505 /* let's just check for obvious mistakes */
506 if ( sq->block_size <= 0 || sq->block_size > sq->bufSize) {
507 #ifdef DEBUG_DMASOUND
508 printk("dmasound_core: invalid frag size (user set %d)\n", sq->user_frag_size) ;
510 sq->block_size = sq->bufSize ;
512 if ( sq->user_frags <= sq->numBufs ) {
513 sq->max_count = sq->user_frags ;
514 /* if user has set max_active - then use it */
515 sq->max_active = (sq->max_active <= sq->max_count) ?
516 sq->max_active : sq->max_count ;
518 #ifdef DEBUG_DMASOUND
519 printk("dmasound_core: invalid frag count (user set %d)\n", sq->user_frags) ;
522 sq->max_active = sq->numBufs ;
525 sq->front = sq->count = sq->rear_size = 0;
529 if (sq == &write_sq) {
531 setup_func = dmasound.mach.write_sq_setup;
536 setup_func = dmasound.mach.read_sq_setup;
544 static inline void sq_play(void)
546 dmasound.mach.play();
549 static ssize_t sq_write(struct file *file, const char __user *src, size_t uLeft,
552 ssize_t uWritten = 0;
554 ssize_t uUsed = 0, bUsed, bLeft;
555 unsigned long flags ;
557 /* ++TeSche: Is something like this necessary?
558 * Hey, that's an honest question! Or does any other part of the
559 * filesystem already checks this situation? I really don't know.
564 /* implement any changes we have made to the soft/hard params.
565 this is not satisfactory really, all we have done up to now is to
566 say what we would like - there hasn't been any real checking of capability
569 if (shared_resources_initialised == 0) {
570 dmasound.mach.init() ;
571 shared_resources_initialised = 1 ;
574 /* set up the sq if it is not already done. This may seem a dumb place
575 to do it - but it is what OSS requires. It means that write() can
576 return memory allocation errors. To avoid this possibility use the
577 GETBLKSIZE or GETOSPACE ioctls (after you've fiddled with all the
578 params you want to change) - these ioctls also force the setup.
581 if (write_sq.locked == 0) {
582 if ((uWritten = sq_setup(&write_sq)) < 0) return uWritten ;
586 /* FIXME: I think that this may be the wrong behaviour when we get strapped
587 for time and the cpu is close to being (or actually) behind in sending data.
588 - because we've lost the time that the N samples, already in the buffer,
589 would have given us to get here with the next lot from the user.
591 /* The interrupt doesn't start to play the last, incomplete frame.
592 * Thus we can append to it without disabling the interrupts! (Note
593 * also that write_sq.rear isn't affected by the interrupt.)
596 /* as of 1.6 this behaviour changes if SNDCTL_DSP_POST has been issued:
597 this will mimic the behaviour of syncing and allow the sq_play() to
598 queue a partial fragment. Since sq_play() may/will be called from
599 the IRQ handler - at least on Pmac we have to deal with it.
600 The strategy - possibly not optimum - is to kill _POST status if we
601 get here. This seems, at least, reasonable - in the sense that POST
602 is supposed to indicate that we might not write before the queue
603 is drained - and if we get here in time then it does not apply.
606 spin_lock_irqsave(&dmasound.lock, flags);
607 write_sq.syncing &= ~2 ; /* take out POST status */
608 spin_unlock_irqrestore(&dmasound.lock, flags);
610 if (write_sq.count > 0 &&
611 (bLeft = write_sq.block_size-write_sq.rear_size) > 0) {
612 dest = write_sq.buffers[write_sq.rear];
613 bUsed = write_sq.rear_size;
614 uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
615 dest, &bUsed, bLeft);
620 uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
621 write_sq.rear_size = bUsed;
625 while (write_sq.count >= write_sq.max_active) {
627 if (write_sq.open_mode & O_NONBLOCK)
628 return uWritten > 0 ? uWritten : -EAGAIN;
629 SLEEP(write_sq.action_queue);
630 if (signal_pending(current))
631 return uWritten > 0 ? uWritten : -EINTR;
634 /* Here, we can avoid disabling the interrupt by first
635 * copying and translating the data, and then updating
636 * the write_sq variables. Until this is done, the interrupt
637 * won't see the new frame and we can work on it
641 dest = write_sq.buffers[(write_sq.rear+1) % write_sq.max_count];
643 bLeft = write_sq.block_size;
644 uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
645 dest, &bUsed, bLeft);
650 uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
652 write_sq.rear = (write_sq.rear+1) % write_sq.max_count;
653 write_sq.rear_size = bUsed;
656 } /* uUsed may have been 0 */
660 return uUsed < 0? uUsed: uWritten;
663 static unsigned int sq_poll(struct file *file, struct poll_table_struct *wait)
665 unsigned int mask = 0;
668 if (write_sq.locked == 0) {
669 if ((retVal = sq_setup(&write_sq)) < 0)
673 if (file->f_mode & FMODE_WRITE )
674 poll_wait(file, &write_sq.action_queue, wait);
676 if (file->f_mode & FMODE_READ)
677 poll_wait(file, &read_sq.action_queue, wait);
678 if (file->f_mode & FMODE_READ)
679 if (read_sq.block_size - read_sq.rear_size > 0)
680 mask |= POLLIN | POLLRDNORM;
682 if (file->f_mode & FMODE_WRITE)
683 if (write_sq.count < write_sq.max_active || write_sq.block_size - write_sq.rear_size > 0)
684 mask |= POLLOUT | POLLWRNORM;
691 * Here is how the values are used for reading.
692 * The value 'active' simply indicates the DMA is running. This is done
693 * so the driver semantics are DMA starts when the first read is posted.
694 * The value 'front' indicates the buffer we should next send to the user.
695 * The value 'rear' indicates the buffer the DMA is currently filling.
696 * When 'front' == 'rear' the buffer "ring" is empty (we always have an
697 * empty available). The 'rear_size' is used to track partial offsets
698 * into the buffer we are currently returning to the user.
700 * This level (> [1.5]) doesn't care what strategy the LL driver uses with
701 * DMA on over-run. It can leave it running (and keep active == 1) or it
702 * can kill it and set active == 0 in which case this routine will spot
703 * it and restart the DMA.
706 static ssize_t sq_read(struct file *file, char __user *dst, size_t uLeft,
710 ssize_t uRead, bLeft, bUsed, uUsed;
715 /* cater for the compatibility mode - record compiled in but no LL */
716 if (dmasound.mach.record == NULL)
719 /* see comment in sq_write()
722 if( shared_resources_initialised == 0) {
723 dmasound.mach.init() ;
724 shared_resources_initialised = 1 ;
727 /* set up the sq if it is not already done. see comments in sq_write().
730 if (read_sq.locked == 0) {
731 if ((uRead = sq_setup(&read_sq)) < 0)
737 /* Move what the user requests, depending upon other options.
741 /* we happened to get behind and the LL driver killed DMA
742 then we should set it going again. This also sets it
743 going the first time through.
745 if ( !read_sq.active )
746 dmasound.mach.record();
748 /* When front == rear, the DMA is not done yet.
750 while (read_sq.front == read_sq.rear) {
751 if (read_sq.open_mode & O_NONBLOCK) {
752 return uRead > 0 ? uRead : -EAGAIN;
754 SLEEP(read_sq.action_queue);
755 if (signal_pending(current))
756 return uRead > 0 ? uRead : -EINTR;
759 /* The amount we move is either what is left in the
760 * current buffer or what the user wants.
762 bLeft = read_sq.block_size - read_sq.rear_size;
763 bUsed = read_sq.rear_size;
764 uUsed = sound_copy_translate(dmasound.trans_read, dst, uLeft,
765 read_sq.buffers[read_sq.front],
772 read_sq.rear_size += bUsed;
773 if (read_sq.rear_size >= read_sq.block_size) {
774 read_sq.rear_size = 0;
776 if (read_sq.front >= read_sq.max_active)
782 #endif /* HAS_RECORD */
784 static inline void sq_init_waitqueue(struct sound_queue *sq)
786 init_waitqueue_head(&sq->action_queue);
787 init_waitqueue_head(&sq->open_queue);
788 init_waitqueue_head(&sq->sync_queue);
792 #if 0 /* blocking open() */
793 static inline void sq_wake_up(struct sound_queue *sq, struct file *file,
796 if (file->f_mode & mode) {
797 sq->busy = 0; /* CHECK: IS THIS OK??? */
798 WAKE_UP(sq->open_queue);
803 static int sq_open2(struct sound_queue *sq, struct file *file, mode_t mode,
804 int numbufs, int bufsize)
808 if (file->f_mode & mode) {
810 #if 0 /* blocking open() */
812 if (file->f_flags & O_NONBLOCK)
816 SLEEP(sq->open_queue);
817 if (signal_pending(current))
822 /* OSS manual says we will return EBUSY regardless
828 sq->busy = 1; /* Let's play spot-the-race-condition */
830 /* allocate the default number & size of buffers.
831 (i.e. specified in _setup() or as module params)
832 can't be changed at the moment - but _could_ be perhaps
833 in the setfragments ioctl.
835 if (( rc = sq_allocate_buffers(sq, numbufs, bufsize))) {
836 #if 0 /* blocking open() */
837 sq_wake_up(sq, file, mode);
844 sq->open_mode = file->f_mode;
849 #define write_sq_init_waitqueue() sq_init_waitqueue(&write_sq)
850 #if 0 /* blocking open() */
851 #define write_sq_wake_up(file) sq_wake_up(&write_sq, file, FMODE_WRITE)
853 #define write_sq_release_buffers() sq_release_buffers(&write_sq)
854 #define write_sq_open(file) \
855 sq_open2(&write_sq, file, FMODE_WRITE, numWriteBufs, writeBufSize )
858 #define read_sq_init_waitqueue() sq_init_waitqueue(&read_sq)
859 #if 0 /* blocking open() */
860 #define read_sq_wake_up(file) sq_wake_up(&read_sq, file, FMODE_READ)
862 #define read_sq_release_buffers() sq_release_buffers(&read_sq)
863 #define read_sq_open(file) \
864 sq_open2(&read_sq, file, FMODE_READ, numReadBufs, readBufSize )
866 #define read_sq_init_waitqueue() do {} while (0)
867 #if 0 /* blocking open() */
868 #define read_sq_wake_up(file) do {} while (0)
870 #define read_sq_release_buffers() do {} while (0)
871 #define sq_reset_input() do {} while (0)
874 static int sq_open(struct inode *inode, struct file *file)
878 if (!try_module_get(dmasound.mach.owner))
881 rc = write_sq_open(file); /* checks the f_mode */
885 if (dmasound.mach.record) {
886 rc = read_sq_open(file); /* checks the f_mode */
889 } else { /* no record function installed; in compat mode */
890 if (file->f_mode & FMODE_READ) {
891 /* TODO: if O_RDWR, release any resources grabbed by write part */
896 #else /* !HAS_RECORD */
897 if (file->f_mode & FMODE_READ) {
898 /* TODO: if O_RDWR, release any resources grabbed by write part */
899 rc = -ENXIO ; /* I think this is what is required by open(2) */
902 #endif /* HAS_RECORD */
904 if (dmasound.mach.sq_open)
905 dmasound.mach.sq_open(file->f_mode);
907 /* CHECK whether this is sensible - in the case that dsp0 could be opened
908 O_RDONLY and dsp1 could be opened O_WRONLY
911 dmasound.minDev = iminor(inode) & 0x0f;
913 /* OK. - we should make some attempt at consistency. At least the H'ware
914 options should be set with a valid mode. We will make it that the LL
915 driver must supply defaults for hard & soft params.
918 if (shared_resource_owner == 0) {
919 /* you can make this AFMT_U8/mono/8K if you want to mimic old
920 OSS behaviour - while we still have soft translations ;-) */
921 dmasound.soft = dmasound.mach.default_soft ;
922 dmasound.dsp = dmasound.mach.default_soft ;
923 dmasound.hard = dmasound.mach.default_hard ;
926 #ifndef DMASOUND_STRICT_OSS_COMPLIANCE
927 /* none of the current LL drivers can actually do this "native" at the moment
928 OSS does not really require us to supply /dev/audio if we can't do it.
930 if (dmasound.minDev == SND_DEV_AUDIO) {
931 sound_set_speed(8000);
933 sound_set_format(AFMT_MU_LAW);
939 module_put(dmasound.mach.owner);
943 static void sq_reset_output(void)
945 sound_silence(); /* this _must_ stop DMA, we might be about to lose the buffers */
948 write_sq.rear_size = 0;
949 /* write_sq.front = (write_sq.rear+1) % write_sq.max_count;*/
951 write_sq.rear = -1 ; /* same as for set-up */
953 /* OK - we can unlock the parameters and fragment settings */
954 write_sq.locked = 0 ;
955 write_sq.user_frags = 0 ;
956 write_sq.user_frag_size = 0 ;
961 static void sq_reset_input(void)
963 if (dmasound.mach.record && read_sq.active) {
964 if (dmasound.mach.abort_read) { /* this routine must really be present */
965 read_sq.syncing = 1 ;
966 /* this can use the read_sq.sync_queue to sleep if
967 necessary - it should not return until DMA
968 is really stopped - because we might deallocate
969 the buffers as the next action...
971 dmasound.mach.abort_read() ;
974 "dmasound_core: %s has no abort_read()!! all bets are off\n",
975 dmasound.mach.name) ;
984 /* OK - we can unlock the parameters and fragment settings */
986 read_sq.user_frags = 0 ;
987 read_sq.user_frag_size = 0 ;
992 static void sq_reset(void)
996 /* we could consider resetting the shared_resources_owner here... but I
997 think it is probably still rather non-obvious to application writer
1000 /* we release everything else though */
1001 shared_resources_initialised = 0 ;
1004 static int sq_fsync(struct file *filp, struct dentry *dentry)
1009 write_sq.syncing |= 1;
1010 sq_play(); /* there may be an incomplete frame waiting */
1012 while (write_sq.active) {
1013 SLEEP(write_sq.sync_queue);
1014 if (signal_pending(current)) {
1015 /* While waiting for audio output to drain, an
1016 * interrupt occurred. Stop audio output immediately
1017 * and clear the queue. */
1023 printk(KERN_WARNING "dmasound: Timeout draining output\n");
1030 /* flag no sync regardless of whether we had a DSP_POST or not */
1031 write_sq.syncing = 0 ;
1035 static int sq_release(struct inode *inode, struct file *file)
1042 /* probably best to do the read side first - so that time taken to do it
1043 overlaps with playing any remaining output samples.
1045 if (file->f_mode & FMODE_READ) {
1046 sq_reset_input() ; /* make sure dma is stopped and all is quiet */
1047 read_sq_release_buffers();
1052 if (file->f_mode & FMODE_WRITE) {
1054 rc = sq_fsync(file, file->f_path.dentry);
1056 sq_reset_output() ; /* make sure dma is stopped and all is quiet */
1057 write_sq_release_buffers();
1061 if (file->f_mode & shared_resource_owner) { /* it's us that has them */
1062 shared_resource_owner = 0 ;
1063 shared_resources_initialised = 0 ;
1064 dmasound.hard = dmasound.mach.default_hard ;
1067 module_put(dmasound.mach.owner);
1069 #if 0 /* blocking open() */
1070 /* Wake up a process waiting for the queue being released.
1071 * Note: There may be several processes waiting for a call
1072 * to open() returning. */
1074 /* Iain: hmm I don't understand this next comment ... */
1075 /* There is probably a DOS atack here. They change the mode flag. */
1076 /* XXX add check here,*/
1077 read_sq_wake_up(file); /* checks f_mode */
1078 write_sq_wake_up(file); /* checks f_mode */
1079 #endif /* blocking open() */
1086 /* here we see if we have a right to modify format, channels, size and so on
1087 if no-one else has claimed it already then we do...
1089 TODO: We might change this to mask O_RDWR such that only one or the other channel
1090 is the owner - if we have problems.
1093 static int shared_resources_are_mine(mode_t md)
1095 if (shared_resource_owner)
1096 return (shared_resource_owner & md ) ;
1098 shared_resource_owner = md ;
1103 /* if either queue is locked we must deny the right to change shared params
1106 static int queues_are_quiescent(void)
1109 if (dmasound.mach.record)
1113 if (write_sq.locked)
1118 /* check and set a queue's fragments per user's wishes...
1119 we will check against the pre-defined literals and the actual sizes.
1120 This is a bit fraught - because soft translations can mess with our
1121 buffer requirements *after* this call - OSS says "call setfrags first"
1124 /* It is possible to replace all the -EINVAL returns with an override that
1125 just puts the allowable value in. This may be what many OSS apps require
1128 static int set_queue_frags(struct sound_queue *sq, int bufs, int size)
1131 #ifdef DEBUG_DMASOUND
1132 printk("dmasound_core: tried to set_queue_frags on a locked queue\n") ;
1137 if ((size < MIN_FRAG_SIZE) || (size > MAX_FRAG_SIZE))
1139 size = (1<<size) ; /* now in bytes */
1140 if (size > sq->bufSize)
1141 return -EINVAL ; /* this might still not work */
1145 if (bufs > sq->numBufs) /* the user is allowed say "don't care" with 0x7fff */
1146 bufs = sq->numBufs ;
1148 /* there is, currently, no way to specify max_active separately
1149 from max_count. This could be a LL driver issue - I guess
1150 if there is a requirement for these values to be different then
1151 we will have to pass that info. up to this level.
1154 sq->max_active = bufs ;
1155 sq->user_frag_size = size ;
1160 static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
1167 audio_buf_info info;
1170 case SNDCTL_DSP_RESET:
1174 case SNDCTL_DSP_GETFMTS:
1175 fmt = dmasound.mach.hardware_afmts ; /* this is what OSS says.. */
1176 return IOCTL_OUT(arg, fmt);
1178 case SNDCTL_DSP_GETBLKSIZE:
1179 /* this should tell the caller about bytes that the app can
1180 read/write - the app doesn't care about our internal buffers.
1181 We force sq_setup() here as per OSS 1.1 (which should
1182 compute the values necessary).
1183 Since there is no mechanism to specify read/write separately, for
1184 fds opened O_RDWR, the write_sq values will, arbitrarily, overwrite
1189 if (dmasound.mach.record && (file->f_mode & FMODE_READ)) {
1190 if ( !read_sq.locked )
1191 sq_setup(&read_sq) ; /* set params */
1192 size = read_sq.user_frag_size ;
1195 if (file->f_mode & FMODE_WRITE) {
1196 if ( !write_sq.locked )
1197 sq_setup(&write_sq) ;
1198 size = write_sq.user_frag_size ;
1200 return IOCTL_OUT(arg, size);
1202 case SNDCTL_DSP_POST:
1203 /* all we are going to do is to tell the LL that any
1204 partial frags can be queued for output.
1205 The LL will have to clear this flag when last output
1208 write_sq.syncing |= 0x2 ;
1211 case SNDCTL_DSP_SYNC:
1212 /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET
1213 except that it waits for output to finish before resetting
1214 everything - read, however, is killed imediately.
1217 if ((file->f_mode & FMODE_READ) && dmasound.mach.record)
1219 if (file->f_mode & FMODE_WRITE) {
1220 result = sq_fsync(file, file->f_path.dentry);
1223 /* if we are the shared resource owner then release them */
1224 if (file->f_mode & shared_resource_owner)
1225 shared_resources_initialised = 0 ;
1228 case SOUND_PCM_READ_RATE:
1229 return IOCTL_OUT(arg, dmasound.soft.speed);
1230 case SNDCTL_DSP_SPEED:
1231 /* changing this on the fly will have weird effects on the sound.
1232 Where there are rate conversions implemented in soft form - it
1233 will cause the _ctx_xxx() functions to be substituted.
1234 However, there doesn't appear to be any reason to dis-allow it from
1237 if (shared_resources_are_mine(file->f_mode)) {
1238 IOCTL_IN(arg, data);
1239 data = sound_set_speed(data) ;
1240 shared_resources_initialised = 0 ;
1241 return IOCTL_OUT(arg, data);
1245 /* OSS says these next 4 actions are undefined when the device is
1246 busy/active - we will just return -EINVAL.
1247 To be allowed to change one - (a) you have to own the right
1248 (b) the queue(s) must be quiescent
1250 case SNDCTL_DSP_STEREO:
1251 if (shared_resources_are_mine(file->f_mode) &&
1252 queues_are_quiescent()) {
1253 IOCTL_IN(arg, data);
1254 shared_resources_initialised = 0 ;
1255 return IOCTL_OUT(arg, sound_set_stereo(data));
1259 case SOUND_PCM_WRITE_CHANNELS:
1260 if (shared_resources_are_mine(file->f_mode) &&
1261 queues_are_quiescent()) {
1262 IOCTL_IN(arg, data);
1263 /* the user might ask for 20 channels, we will return 1 or 2 */
1264 shared_resources_initialised = 0 ;
1265 return IOCTL_OUT(arg, sound_set_stereo(data-1)+1);
1269 case SNDCTL_DSP_SETFMT:
1270 if (shared_resources_are_mine(file->f_mode) &&
1271 queues_are_quiescent()) {
1273 IOCTL_IN(arg, data);
1274 shared_resources_initialised = 0 ;
1275 format = sound_set_format(data);
1276 result = IOCTL_OUT(arg, format);
1279 if (format != data && data != AFMT_QUERY)
1284 case SNDCTL_DSP_SUBDIVIDE:
1286 case SNDCTL_DSP_SETFRAGMENT:
1287 /* we can do this independently for the two queues - with the
1288 proviso that for fds opened O_RDWR we cannot separate the
1289 actions and both queues will be set per the last call.
1290 NOTE: this does *NOT* actually set the queue up - merely
1291 registers our intentions.
1293 IOCTL_IN(arg, data);
1295 nbufs = (data >> 16) & 0x7fff ; /* 0x7fff is 'use maximum' */
1296 size = data & 0xffff;
1298 if ((file->f_mode & FMODE_READ) && dmasound.mach.record) {
1299 result = set_queue_frags(&read_sq, nbufs, size) ;
1304 if (file->f_mode & FMODE_WRITE) {
1305 result = set_queue_frags(&write_sq, nbufs, size) ;
1309 /* NOTE: this return value is irrelevant - OSS specifically says that
1310 the value is 'random' and that the user _must_ check the actual
1311 frags values using SNDCTL_DSP_GETBLKSIZE or similar */
1312 return IOCTL_OUT(arg, data);
1314 case SNDCTL_DSP_GETOSPACE:
1317 if (file->f_mode & FMODE_WRITE) {
1318 if ( !write_sq.locked )
1319 sq_setup(&write_sq) ;
1320 info.fragments = write_sq.max_active - write_sq.count;
1321 info.fragstotal = write_sq.max_active;
1322 info.fragsize = write_sq.user_frag_size;
1323 info.bytes = info.fragments * info.fragsize;
1324 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1330 case SNDCTL_DSP_GETCAPS:
1331 val = dmasound.mach.capabilities & 0xffffff00;
1332 return IOCTL_OUT(arg,val);
1335 return mixer_ioctl(inode, file, cmd, arg);
1340 static const struct file_operations sq_fops =
1342 .owner = THIS_MODULE,
1343 .llseek = no_llseek,
1348 .release = sq_release,
1352 static const struct file_operations sq_fops_record =
1354 .owner = THIS_MODULE,
1355 .llseek = no_llseek,
1360 .release = sq_release,
1365 static int sq_init(void)
1367 const struct file_operations *fops = &sq_fops;
1373 if (dmasound.mach.record)
1374 fops = &sq_fops_record;
1376 sq_unit = register_sound_dsp(fops, -1);
1378 printk(KERN_ERR "dmasound_core: couldn't register fops\n") ;
1382 write_sq_init_waitqueue();
1383 read_sq_init_waitqueue();
1385 /* These parameters will be restored for every clean open()
1386 * in the case of multiple open()s (e.g. dsp0 & dsp1) they
1387 * will be set so long as the shared resources have no owner.
1390 if (shared_resource_owner == 0) {
1391 dmasound.soft = dmasound.mach.default_soft ;
1392 dmasound.hard = dmasound.mach.default_hard ;
1393 dmasound.dsp = dmasound.mach.default_soft ;
1394 shared_resources_initialised = 0 ;
1404 /* we allow more space for record-enabled because there are extra output lines.
1405 the number here must include the amount we are prepared to give to the low-level
1410 #define STAT_BUFF_LEN 1024
1412 #define STAT_BUFF_LEN 768
1415 /* this is how much space we will allow the low-level driver to use
1416 in the stat buffer. Currently, 2 * (80 character line + <NL>).
1417 We do not police this (it is up to the ll driver to be honest).
1420 #define LOW_LEVEL_STAT_ALLOC 162
1424 char buf[STAT_BUFF_LEN]; /* state.buf should not overflow! */
1428 /* publish this function for use by low-level code, if required */
1430 char *get_afmt_string(int afmt)
1440 return "unsigned 8 bit";
1443 return "signed 8 bit";
1446 return "signed 16 bit BE";
1449 return "unsigned 16 bit BE";
1452 return "signed 16 bit LE";
1455 return "unsigned 16 bit LE";
1458 return "format not set" ;
1463 return "ERROR: Unsupported AFMT_XXXX code" ;
1466 static int state_open(struct inode *inode, struct file *file)
1468 char *buffer = state.buf;
1474 if (!try_module_get(dmasound.mach.owner))
1479 len += sprintf(buffer+len, "%sDMA sound driver rev %03d :\n",
1480 dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
1481 ((dmasound.mach.version>>8) & 0x0f));
1482 len += sprintf(buffer+len,
1483 "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
1484 DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
1485 (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
1487 /* call the low-level module to fill in any stat info. that it has
1488 if present. Maximum buffer usage is specified.
1491 if (dmasound.mach.state_info)
1492 len += dmasound.mach.state_info(buffer+len,
1493 (size_t) LOW_LEVEL_STAT_ALLOC) ;
1495 /* make usage of the state buffer as deterministic as poss.
1496 exceptional conditions could cause overrun - and this is flagged as
1500 /* formats and settings */
1502 len += sprintf(buffer+len,"\t\t === Formats & settings ===\n") ;
1503 len += sprintf(buffer+len,"Parameter %20s%20s\n","soft","hard") ;
1504 len += sprintf(buffer+len,"Format :%20s%20s\n",
1505 get_afmt_string(dmasound.soft.format),
1506 get_afmt_string(dmasound.hard.format));
1508 len += sprintf(buffer+len,"Samp Rate:%14d s/sec%14d s/sec\n",
1509 dmasound.soft.speed, dmasound.hard.speed);
1511 len += sprintf(buffer+len,"Channels :%20s%20s\n",
1512 dmasound.soft.stereo ? "stereo" : "mono",
1513 dmasound.hard.stereo ? "stereo" : "mono" );
1515 /* sound queue status */
1517 len += sprintf(buffer+len,"\t\t === Sound Queue status ===\n");
1518 len += sprintf(buffer+len,"Allocated:%8s%6s\n","Buffers","Size") ;
1519 len += sprintf(buffer+len,"%9s:%8d%6d\n",
1520 "write", write_sq.numBufs, write_sq.bufSize) ;
1522 if (dmasound.mach.record)
1523 len += sprintf(buffer+len,"%9s:%8d%6d\n",
1524 "read", read_sq.numBufs, read_sq.bufSize) ;
1526 len += sprintf(buffer+len,
1527 "Current : MaxFrg FragSiz MaxAct Frnt Rear "
1528 "Cnt RrSize A B S L xruns\n") ;
1529 len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
1530 "write", write_sq.max_count, write_sq.block_size,
1531 write_sq.max_active, write_sq.front, write_sq.rear,
1532 write_sq.count, write_sq.rear_size, write_sq.active,
1533 write_sq.busy, write_sq.syncing, write_sq.locked, write_sq.xruns) ;
1535 if (dmasound.mach.record)
1536 len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
1537 "read", read_sq.max_count, read_sq.block_size,
1538 read_sq.max_active, read_sq.front, read_sq.rear,
1539 read_sq.count, read_sq.rear_size, read_sq.active,
1540 read_sq.busy, read_sq.syncing, read_sq.locked, read_sq.xruns) ;
1542 #ifdef DEBUG_DMASOUND
1543 printk("dmasound: stat buffer used %d bytes\n", len) ;
1546 if (len >= STAT_BUFF_LEN)
1547 printk(KERN_ERR "dmasound_core: stat buffer overflowed!\n");
1553 static int state_release(struct inode *inode, struct file *file)
1557 module_put(dmasound.mach.owner);
1562 static ssize_t state_read(struct file *file, char __user *buf, size_t count,
1565 int n = state.len - state.ptr;
1570 if (copy_to_user(buf, &state.buf[state.ptr], n))
1576 static const struct file_operations state_fops = {
1577 .owner = THIS_MODULE,
1578 .llseek = no_llseek,
1581 .release = state_release,
1584 static int state_init(void)
1589 state_unit = register_sound_special(&state_fops, SND_DEV_STATUS);
1600 * This function is called by _one_ chipset-specific driver
1603 int dmasound_init(void)
1611 /* Set up sound queue, /dev/audio and /dev/dsp. */
1613 /* Set default settings. */
1614 if ((res = sq_init()) < 0)
1617 /* Set up /dev/sndstat. */
1618 if ((res = state_init()) < 0)
1621 /* Set up /dev/mixer. */
1624 if (!dmasound.mach.irqinit()) {
1625 printk(KERN_ERR "DMA sound driver: Interrupt initialization failed\n");
1632 printk(KERN_INFO "%s DMA sound driver rev %03d installed\n",
1633 dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
1634 ((dmasound.mach.version>>8) & 0x0f));
1636 "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
1637 DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
1638 (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
1639 printk(KERN_INFO "Write will use %4d fragments of %7d bytes as default\n",
1640 numWriteBufs, writeBufSize) ;
1642 if (dmasound.mach.record)
1644 "Read will use %4d fragments of %7d bytes as default\n",
1645 numReadBufs, readBufSize) ;
1653 void dmasound_deinit(void)
1655 if (irq_installed) {
1657 dmasound.mach.irqcleanup();
1661 write_sq_release_buffers();
1662 read_sq_release_buffers();
1664 if (mixer_unit >= 0)
1665 unregister_sound_mixer(mixer_unit);
1666 if (state_unit >= 0)
1667 unregister_sound_special(state_unit);
1669 unregister_sound_dsp(sq_unit);
1674 static int dmasound_setup(char *str)
1678 str = get_options(str, ARRAY_SIZE(ints), ints);
1680 /* check the bootstrap parameter for "dmasound=" */
1682 /* FIXME: other than in the most naive of cases there is no sense in these
1683 * buffers being other than powers of two. This is not checked yet.
1689 if ((ints[5] < 0) || (ints[5] > MAX_CATCH_RADIUS))
1690 printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
1692 catchRadius = ints[5];
1695 if (ints[4] < MIN_BUFFERS)
1696 printk("dmasound_setup: invalid number of read buffers, using default = %d\n",
1699 numReadBufs = ints[4];
1702 if ((size = ints[3]) < 256) /* check for small buffer specs */
1704 if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
1705 printk("dmasound_setup: invalid read buffer size, using default = %d\n", readBufSize);
1711 if ((ints[3] < 0) || (ints[3] > MAX_CATCH_RADIUS))
1712 printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
1714 catchRadius = ints[3];
1718 if (ints[1] < MIN_BUFFERS)
1719 printk("dmasound_setup: invalid number of buffers, using default = %d\n", numWriteBufs);
1721 numWriteBufs = ints[1];
1724 if ((size = ints[2]) < 256) /* check for small buffer specs */
1726 if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
1727 printk("dmasound_setup: invalid write buffer size, using default = %d\n", writeBufSize);
1729 writeBufSize = size;
1733 printk("dmasound_setup: invalid number of arguments\n");
1739 __setup("dmasound=", dmasound_setup);
1741 #endif /* !MODULE */
1747 #ifdef HAS_8BIT_TABLES
1750 char dmasound_ulaw2dma8[] = {
1751 -126, -122, -118, -114, -110, -106, -102, -98,
1752 -94, -90, -86, -82, -78, -74, -70, -66,
1753 -63, -61, -59, -57, -55, -53, -51, -49,
1754 -47, -45, -43, -41, -39, -37, -35, -33,
1755 -31, -30, -29, -28, -27, -26, -25, -24,
1756 -23, -22, -21, -20, -19, -18, -17, -16,
1757 -16, -15, -15, -14, -14, -13, -13, -12,
1758 -12, -11, -11, -10, -10, -9, -9, -8,
1759 -8, -8, -7, -7, -7, -7, -6, -6,
1760 -6, -6, -5, -5, -5, -5, -4, -4,
1761 -4, -4, -4, -4, -3, -3, -3, -3,
1762 -3, -3, -3, -3, -2, -2, -2, -2,
1763 -2, -2, -2, -2, -2, -2, -2, -2,
1764 -1, -1, -1, -1, -1, -1, -1, -1,
1765 -1, -1, -1, -1, -1, -1, -1, -1,
1766 -1, -1, -1, -1, -1, -1, -1, 0,
1767 125, 121, 117, 113, 109, 105, 101, 97,
1768 93, 89, 85, 81, 77, 73, 69, 65,
1769 62, 60, 58, 56, 54, 52, 50, 48,
1770 46, 44, 42, 40, 38, 36, 34, 32,
1771 30, 29, 28, 27, 26, 25, 24, 23,
1772 22, 21, 20, 19, 18, 17, 16, 15,
1773 15, 14, 14, 13, 13, 12, 12, 11,
1774 11, 10, 10, 9, 9, 8, 8, 7,
1775 7, 7, 6, 6, 6, 6, 5, 5,
1776 5, 5, 4, 4, 4, 4, 3, 3,
1777 3, 3, 3, 3, 2, 2, 2, 2,
1778 2, 2, 2, 2, 1, 1, 1, 1,
1779 1, 1, 1, 1, 1, 1, 1, 1,
1780 0, 0, 0, 0, 0, 0, 0, 0,
1781 0, 0, 0, 0, 0, 0, 0, 0,
1782 0, 0, 0, 0, 0, 0, 0, 0
1787 char dmasound_alaw2dma8[] = {
1788 -22, -21, -24, -23, -18, -17, -20, -19,
1789 -30, -29, -32, -31, -26, -25, -28, -27,
1790 -11, -11, -12, -12, -9, -9, -10, -10,
1791 -15, -15, -16, -16, -13, -13, -14, -14,
1792 -86, -82, -94, -90, -70, -66, -78, -74,
1793 -118, -114, -126, -122, -102, -98, -110, -106,
1794 -43, -41, -47, -45, -35, -33, -39, -37,
1795 -59, -57, -63, -61, -51, -49, -55, -53,
1796 -2, -2, -2, -2, -2, -2, -2, -2,
1797 -2, -2, -2, -2, -2, -2, -2, -2,
1798 -1, -1, -1, -1, -1, -1, -1, -1,
1799 -1, -1, -1, -1, -1, -1, -1, -1,
1800 -6, -6, -6, -6, -5, -5, -5, -5,
1801 -8, -8, -8, -8, -7, -7, -7, -7,
1802 -3, -3, -3, -3, -3, -3, -3, -3,
1803 -4, -4, -4, -4, -4, -4, -4, -4,
1804 21, 20, 23, 22, 17, 16, 19, 18,
1805 29, 28, 31, 30, 25, 24, 27, 26,
1806 10, 10, 11, 11, 8, 8, 9, 9,
1807 14, 14, 15, 15, 12, 12, 13, 13,
1808 86, 82, 94, 90, 70, 66, 78, 74,
1809 118, 114, 126, 122, 102, 98, 110, 106,
1810 43, 41, 47, 45, 35, 33, 39, 37,
1811 59, 57, 63, 61, 51, 49, 55, 53,
1812 1, 1, 1, 1, 1, 1, 1, 1,
1813 1, 1, 1, 1, 1, 1, 1, 1,
1814 0, 0, 0, 0, 0, 0, 0, 0,
1815 0, 0, 0, 0, 0, 0, 0, 0,
1816 5, 5, 5, 5, 4, 4, 4, 4,
1817 7, 7, 7, 7, 6, 6, 6, 6,
1818 2, 2, 2, 2, 2, 2, 2, 2,
1819 3, 3, 3, 3, 3, 3, 3, 3
1821 #endif /* HAS_8BIT_TABLES */
1824 * Visible symbols for modules
1827 EXPORT_SYMBOL(dmasound);
1828 EXPORT_SYMBOL(dmasound_init);
1830 EXPORT_SYMBOL(dmasound_deinit);
1832 EXPORT_SYMBOL(dmasound_write_sq);
1834 EXPORT_SYMBOL(dmasound_read_sq);
1836 EXPORT_SYMBOL(dmasound_catchRadius);
1837 #ifdef HAS_8BIT_TABLES
1838 EXPORT_SYMBOL(dmasound_ulaw2dma8);
1839 EXPORT_SYMBOL(dmasound_alaw2dma8);
1841 EXPORT_SYMBOL(get_afmt_string) ;