4 * Audio routines for Sound Blaster compatible cards.
7 * Copyright (C) by Hannu Savolainen 1993-1997
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
14 * Alan Cox : Formatting and clean ups
17 * Mostly working. Weird uart bug causing irq storms
19 * Daniel J. Rodriksson: Changes to make sb16 work full duplex.
20 * Maybe other 16 bit cards in this code could behave
22 * Chris Rankin: Use spinlocks instead of CLI/STI
25 #include <linux/spinlock.h>
27 #include "sound_config.h"
34 int sb_audio_open(int dev
, int mode
)
36 sb_devc
*devc
= audio_devs
[dev
]->devc
;
41 printk(KERN_ERR
"Sound Blaster: incomplete initialization.\n");
44 if (devc
->caps
& SB_NO_RECORDING
&& mode
& OPEN_READ
)
46 if (mode
== OPEN_READ
)
49 spin_lock_irqsave(&devc
->lock
, flags
);
52 spin_unlock_irqrestore(&devc
->lock
, flags
);
55 if (devc
->dma16
!= -1 && devc
->dma16
!= devc
->dma8
&& !devc
->duplex
)
57 if (sound_open_dma(devc
->dma16
, "Sound Blaster 16 bit"))
59 spin_unlock_irqrestore(&devc
->lock
, flags
);
64 spin_unlock_irqrestore(&devc
->lock
, flags
);
66 devc
->irq_mode
= IMODE_NONE
;
67 devc
->irq_mode_16
= IMODE_NONE
;
68 devc
->fullduplex
= devc
->duplex
&&
69 ((mode
& OPEN_READ
) && (mode
& OPEN_WRITE
));
72 /* At first glance this check isn't enough, some ESS chips might not
73 * have a RECLEV. However if they don't common_mixer_set will refuse
74 * cause devc->iomap has no register mapping for RECLEV
76 if (devc
->model
== MDL_ESS
) ess_mixer_reload (devc
, SOUND_MIXER_RECLEV
);
78 /* The ALS007 seems to require that the DSP be removed from the output */
79 /* in order for recording to be activated properly. This is done by */
80 /* setting the appropriate bits of the output control register 4ch to */
81 /* zero. This code assumes that the output control registers are not */
82 /* used anywhere else and therefore the DSP bits are *always* ON for */
83 /* output and OFF for sampling. */
85 if (devc
->submodel
== SUBMDL_ALS007
)
88 sb_setmixer(devc
,ALS007_OUTPUT_CTRL2
,
89 sb_getmixer(devc
,ALS007_OUTPUT_CTRL2
) & 0xf9);
91 sb_setmixer(devc
,ALS007_OUTPUT_CTRL2
,
92 sb_getmixer(devc
,ALS007_OUTPUT_CTRL2
) | 0x06);
97 void sb_audio_close(int dev
)
99 sb_devc
*devc
= audio_devs
[dev
]->devc
;
101 /* fix things if mmap turned off fullduplex */
104 && (devc
->opened
& OPEN_READ
) && (devc
->opened
& OPEN_WRITE
))
106 struct dma_buffparms
*dmap_temp
;
107 dmap_temp
= audio_devs
[dev
]->dmap_out
;
108 audio_devs
[dev
]->dmap_out
= audio_devs
[dev
]->dmap_in
;
109 audio_devs
[dev
]->dmap_in
= dmap_temp
;
111 audio_devs
[dev
]->dmap_out
->dma
= devc
->dma8
;
112 audio_devs
[dev
]->dmap_in
->dma
= ( devc
->duplex
) ?
113 devc
->dma16
: devc
->dma8
;
115 if (devc
->dma16
!= -1 && devc
->dma16
!= devc
->dma8
&& !devc
->duplex
)
116 sound_close_dma(devc
->dma16
);
118 /* For ALS007, turn DSP output back on if closing the device for read */
120 if ((devc
->submodel
== SUBMDL_ALS007
) && (devc
->opened
& OPEN_READ
))
122 sb_setmixer(devc
,ALS007_OUTPUT_CTRL2
,
123 sb_getmixer(devc
,ALS007_OUTPUT_CTRL2
) | 0x06);
128 static void sb_set_output_parms(int dev
, unsigned long buf
, int nr_bytes
,
131 sb_devc
*devc
= audio_devs
[dev
]->devc
;
133 if (!devc
->fullduplex
|| devc
->bits
== AFMT_S16_LE
)
136 devc
->trg_bytes
= nr_bytes
;
137 devc
->trg_intrflag
= intrflag
;
138 devc
->irq_mode
= IMODE_OUTPUT
;
142 devc
->trg_buf_16
= buf
;
143 devc
->trg_bytes_16
= nr_bytes
;
144 devc
->trg_intrflag_16
= intrflag
;
145 devc
->irq_mode_16
= IMODE_OUTPUT
;
149 static void sb_set_input_parms(int dev
, unsigned long buf
, int count
, int intrflag
)
151 sb_devc
*devc
= audio_devs
[dev
]->devc
;
153 if (!devc
->fullduplex
|| devc
->bits
!= AFMT_S16_LE
)
156 devc
->trg_bytes
= count
;
157 devc
->trg_intrflag
= intrflag
;
158 devc
->irq_mode
= IMODE_INPUT
;
162 devc
->trg_buf_16
= buf
;
163 devc
->trg_bytes_16
= count
;
164 devc
->trg_intrflag_16
= intrflag
;
165 devc
->irq_mode_16
= IMODE_INPUT
;
170 * SB1.x compatible routines
173 static void sb1_audio_output_block(int dev
, unsigned long buf
, int nr_bytes
, int intrflag
)
176 int count
= nr_bytes
;
177 sb_devc
*devc
= audio_devs
[dev
]->devc
;
179 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
181 if (audio_devs
[dev
]->dmap_out
->dma
> 3)
185 devc
->irq_mode
= IMODE_OUTPUT
;
187 spin_lock_irqsave(&devc
->lock
, flags
);
188 if (sb_dsp_command(devc
, 0x14)) /* 8 bit DAC using DMA */
190 sb_dsp_command(devc
, (unsigned char) (count
& 0xff));
191 sb_dsp_command(devc
, (unsigned char) ((count
>> 8) & 0xff));
194 printk(KERN_WARNING
"Sound Blaster: unable to start DAC.\n");
195 spin_unlock_irqrestore(&devc
->lock
, flags
);
196 devc
->intr_active
= 1;
199 static void sb1_audio_start_input(int dev
, unsigned long buf
, int nr_bytes
, int intrflag
)
202 int count
= nr_bytes
;
203 sb_devc
*devc
= audio_devs
[dev
]->devc
;
206 * Start a DMA input to the buffer pointed by dmaqtail
209 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
211 if (audio_devs
[dev
]->dmap_out
->dma
> 3)
215 devc
->irq_mode
= IMODE_INPUT
;
217 spin_lock_irqsave(&devc
->lock
, flags
);
218 if (sb_dsp_command(devc
, 0x24)) /* 8 bit ADC using DMA */
220 sb_dsp_command(devc
, (unsigned char) (count
& 0xff));
221 sb_dsp_command(devc
, (unsigned char) ((count
>> 8) & 0xff));
224 printk(KERN_ERR
"Sound Blaster: unable to start ADC.\n");
225 spin_unlock_irqrestore(&devc
->lock
, flags
);
227 devc
->intr_active
= 1;
230 static void sb1_audio_trigger(int dev
, int bits
)
232 sb_devc
*devc
= audio_devs
[dev
]->devc
;
234 bits
&= devc
->irq_mode
;
237 sb_dsp_command(devc
, 0xd0); /* Halt DMA */
240 switch (devc
->irq_mode
)
243 sb1_audio_start_input(dev
, devc
->trg_buf
, devc
->trg_bytes
,
248 sb1_audio_output_block(dev
, devc
->trg_buf
, devc
->trg_bytes
,
253 devc
->trigger_bits
= bits
;
256 static int sb1_audio_prepare_for_input(int dev
, int bsize
, int bcount
)
258 sb_devc
*devc
= audio_devs
[dev
]->devc
;
261 spin_lock_irqsave(&devc
->lock
, flags
);
262 if (sb_dsp_command(devc
, 0x40))
263 sb_dsp_command(devc
, devc
->tconst
);
264 sb_dsp_command(devc
, DSP_CMD_SPKOFF
);
265 spin_unlock_irqrestore(&devc
->lock
, flags
);
267 devc
->trigger_bits
= 0;
271 static int sb1_audio_prepare_for_output(int dev
, int bsize
, int bcount
)
273 sb_devc
*devc
= audio_devs
[dev
]->devc
;
276 spin_lock_irqsave(&devc
->lock
, flags
);
277 if (sb_dsp_command(devc
, 0x40))
278 sb_dsp_command(devc
, devc
->tconst
);
279 sb_dsp_command(devc
, DSP_CMD_SPKON
);
280 spin_unlock_irqrestore(&devc
->lock
, flags
);
281 devc
->trigger_bits
= 0;
285 static int sb1_audio_set_speed(int dev
, int speed
)
287 int max_speed
= 23000;
288 sb_devc
*devc
= audio_devs
[dev
]->devc
;
291 if (devc
->opened
& OPEN_READ
)
299 if (speed
> max_speed
)
302 devc
->tconst
= (256 - ((1000000 + speed
/ 2) / speed
)) & 0xff;
303 tmp
= 256 - devc
->tconst
;
304 speed
= (1000000 + tmp
/ 2) / tmp
;
311 static short sb1_audio_set_channels(int dev
, short channels
)
313 sb_devc
*devc
= audio_devs
[dev
]->devc
;
314 return devc
->channels
= 1;
317 static unsigned int sb1_audio_set_bits(int dev
, unsigned int bits
)
319 sb_devc
*devc
= audio_devs
[dev
]->devc
;
320 return devc
->bits
= 8;
323 static void sb1_audio_halt_xfer(int dev
)
326 sb_devc
*devc
= audio_devs
[dev
]->devc
;
328 spin_lock_irqsave(&devc
->lock
, flags
);
330 spin_unlock_irqrestore(&devc
->lock
, flags
);
334 * SB 2.0 and SB 2.01 compatible routines
337 static void sb20_audio_output_block(int dev
, unsigned long buf
, int nr_bytes
,
341 int count
= nr_bytes
;
342 sb_devc
*devc
= audio_devs
[dev
]->devc
;
345 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
347 if (audio_devs
[dev
]->dmap_out
->dma
> 3)
351 devc
->irq_mode
= IMODE_OUTPUT
;
353 spin_lock_irqsave(&devc
->lock
, flags
);
354 if (sb_dsp_command(devc
, 0x48)) /* DSP Block size */
356 sb_dsp_command(devc
, (unsigned char) (count
& 0xff));
357 sb_dsp_command(devc
, (unsigned char) ((count
>> 8) & 0xff));
359 if (devc
->speed
* devc
->channels
<= 23000)
360 cmd
= 0x1c; /* 8 bit PCM output */
362 cmd
= 0x90; /* 8 bit high speed PCM output (SB2.01/Pro) */
364 if (!sb_dsp_command(devc
, cmd
))
365 printk(KERN_ERR
"Sound Blaster: unable to start DAC.\n");
368 printk(KERN_ERR
"Sound Blaster: unable to start DAC.\n");
369 spin_unlock_irqrestore(&devc
->lock
, flags
);
370 devc
->intr_active
= 1;
373 static void sb20_audio_start_input(int dev
, unsigned long buf
, int nr_bytes
, int intrflag
)
376 int count
= nr_bytes
;
377 sb_devc
*devc
= audio_devs
[dev
]->devc
;
381 * Start a DMA input to the buffer pointed by dmaqtail
384 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
386 if (audio_devs
[dev
]->dmap_out
->dma
> 3)
390 devc
->irq_mode
= IMODE_INPUT
;
392 spin_lock_irqsave(&devc
->lock
, flags
);
393 if (sb_dsp_command(devc
, 0x48)) /* DSP Block size */
395 sb_dsp_command(devc
, (unsigned char) (count
& 0xff));
396 sb_dsp_command(devc
, (unsigned char) ((count
>> 8) & 0xff));
398 if (devc
->speed
* devc
->channels
<= (devc
->major
== 3 ? 23000 : 13000))
399 cmd
= 0x2c; /* 8 bit PCM input */
401 cmd
= 0x98; /* 8 bit high speed PCM input (SB2.01/Pro) */
403 if (!sb_dsp_command(devc
, cmd
))
404 printk(KERN_ERR
"Sound Blaster: unable to start ADC.\n");
407 printk(KERN_ERR
"Sound Blaster: unable to start ADC.\n");
408 spin_unlock_irqrestore(&devc
->lock
, flags
);
409 devc
->intr_active
= 1;
412 static void sb20_audio_trigger(int dev
, int bits
)
414 sb_devc
*devc
= audio_devs
[dev
]->devc
;
415 bits
&= devc
->irq_mode
;
418 sb_dsp_command(devc
, 0xd0); /* Halt DMA */
421 switch (devc
->irq_mode
)
424 sb20_audio_start_input(dev
, devc
->trg_buf
, devc
->trg_bytes
,
429 sb20_audio_output_block(dev
, devc
->trg_buf
, devc
->trg_bytes
,
434 devc
->trigger_bits
= bits
;
438 * SB2.01 specific speed setup
441 static int sb201_audio_set_speed(int dev
, int speed
)
443 sb_devc
*devc
= audio_devs
[dev
]->devc
;
453 if (devc
->opened
& OPEN_READ
&& speed
> 15000)
455 s
= speed
* devc
->channels
;
456 devc
->tconst
= (256 - ((1000000 + s
/ 2) / s
)) & 0xff;
457 tmp
= 256 - devc
->tconst
;
458 speed
= ((1000000 + tmp
/ 2) / tmp
) / devc
->channels
;
466 * SB Pro specific routines
469 static int sbpro_audio_prepare_for_input(int dev
, int bsize
, int bcount
)
470 { /* For SB Pro and Jazz16 */
471 sb_devc
*devc
= audio_devs
[dev
]->devc
;
473 unsigned char bits
= 0;
475 if (devc
->dma16
>= 0 && devc
->dma16
!= devc
->dma8
)
476 audio_devs
[dev
]->dmap_out
->dma
= audio_devs
[dev
]->dmap_in
->dma
=
477 devc
->bits
== 16 ? devc
->dma16
: devc
->dma8
;
479 if (devc
->model
== MDL_JAZZ
|| devc
->model
== MDL_SMW
)
480 if (devc
->bits
== AFMT_S16_LE
)
481 bits
= 0x04; /* 16 bit mode */
483 spin_lock_irqsave(&devc
->lock
, flags
);
484 if (sb_dsp_command(devc
, 0x40))
485 sb_dsp_command(devc
, devc
->tconst
);
486 sb_dsp_command(devc
, DSP_CMD_SPKOFF
);
487 if (devc
->channels
== 1)
488 sb_dsp_command(devc
, 0xa0 | bits
); /* Mono input */
490 sb_dsp_command(devc
, 0xa8 | bits
); /* Stereo input */
491 spin_unlock_irqrestore(&devc
->lock
, flags
);
493 devc
->trigger_bits
= 0;
497 static int sbpro_audio_prepare_for_output(int dev
, int bsize
, int bcount
)
498 { /* For SB Pro and Jazz16 */
499 sb_devc
*devc
= audio_devs
[dev
]->devc
;
502 unsigned char bits
= 0;
504 if (devc
->dma16
>= 0 && devc
->dma16
!= devc
->dma8
)
505 audio_devs
[dev
]->dmap_out
->dma
= audio_devs
[dev
]->dmap_in
->dma
= devc
->bits
== 16 ? devc
->dma16
: devc
->dma8
;
506 if (devc
->model
== MDL_SBPRO
)
507 sb_mixer_set_stereo(devc
, devc
->channels
== 2);
509 spin_lock_irqsave(&devc
->lock
, flags
);
510 if (sb_dsp_command(devc
, 0x40))
511 sb_dsp_command(devc
, devc
->tconst
);
512 sb_dsp_command(devc
, DSP_CMD_SPKON
);
514 if (devc
->model
== MDL_JAZZ
|| devc
->model
== MDL_SMW
)
516 if (devc
->bits
== AFMT_S16_LE
)
517 bits
= 0x04; /* 16 bit mode */
519 if (devc
->channels
== 1)
520 sb_dsp_command(devc
, 0xa0 | bits
); /* Mono output */
522 sb_dsp_command(devc
, 0xa8 | bits
); /* Stereo output */
523 spin_unlock_irqrestore(&devc
->lock
, flags
);
527 spin_unlock_irqrestore(&devc
->lock
, flags
);
528 tmp
= sb_getmixer(devc
, 0x0e);
529 if (devc
->channels
== 1)
533 sb_setmixer(devc
, 0x0e, tmp
);
535 devc
->trigger_bits
= 0;
539 static int sbpro_audio_set_speed(int dev
, int speed
)
541 sb_devc
*devc
= audio_devs
[dev
]->devc
;
549 if (devc
->channels
> 1 && speed
> 22050)
551 sb201_audio_set_speed(dev
, speed
);
556 static short sbpro_audio_set_channels(int dev
, short channels
)
558 sb_devc
*devc
= audio_devs
[dev
]->devc
;
560 if (channels
== 1 || channels
== 2)
562 if (channels
!= devc
->channels
)
564 devc
->channels
= channels
;
565 if (devc
->model
== MDL_SBPRO
&& devc
->channels
== 2)
566 sbpro_audio_set_speed(dev
, devc
->speed
);
569 return devc
->channels
;
572 static int jazz16_audio_set_speed(int dev
, int speed
)
574 sb_devc
*devc
= audio_devs
[dev
]->devc
;
586 s
= speed
* devc
->channels
;
588 devc
->tconst
= (256 - ((1000000 + s
/ 2) / s
)) & 0xff;
590 tmp
= 256 - devc
->tconst
;
591 speed
= ((1000000 + tmp
/ 2) / tmp
) / devc
->channels
;
599 * SB16 specific routines
602 static int sb16_audio_set_speed(int dev
, int speed
)
604 sb_devc
*devc
= audio_devs
[dev
]->devc
;
605 int max_speed
= devc
->submodel
== SUBMDL_ALS100
? 48000 : 44100;
612 if (speed
> max_speed
)
620 static unsigned int sb16_audio_set_bits(int dev
, unsigned int bits
)
622 sb_devc
*devc
= audio_devs
[dev
]->devc
;
626 if (bits
== AFMT_U8
|| bits
== AFMT_S16_LE
)
629 devc
->bits
= AFMT_U8
;
635 static int sb16_audio_prepare_for_input(int dev
, int bsize
, int bcount
)
637 sb_devc
*devc
= audio_devs
[dev
]->devc
;
639 if (!devc
->fullduplex
)
641 audio_devs
[dev
]->dmap_out
->dma
=
642 audio_devs
[dev
]->dmap_in
->dma
=
643 devc
->bits
== AFMT_S16_LE
?
644 devc
->dma16
: devc
->dma8
;
646 else if (devc
->bits
== AFMT_S16_LE
)
648 audio_devs
[dev
]->dmap_out
->dma
= devc
->dma8
;
649 audio_devs
[dev
]->dmap_in
->dma
= devc
->dma16
;
653 audio_devs
[dev
]->dmap_out
->dma
= devc
->dma16
;
654 audio_devs
[dev
]->dmap_in
->dma
= devc
->dma8
;
657 devc
->trigger_bits
= 0;
661 static int sb16_audio_prepare_for_output(int dev
, int bsize
, int bcount
)
663 sb_devc
*devc
= audio_devs
[dev
]->devc
;
665 if (!devc
->fullduplex
)
667 audio_devs
[dev
]->dmap_out
->dma
=
668 audio_devs
[dev
]->dmap_in
->dma
=
669 devc
->bits
== AFMT_S16_LE
?
670 devc
->dma16
: devc
->dma8
;
672 else if (devc
->bits
== AFMT_S16_LE
)
674 audio_devs
[dev
]->dmap_out
->dma
= devc
->dma8
;
675 audio_devs
[dev
]->dmap_in
->dma
= devc
->dma16
;
679 audio_devs
[dev
]->dmap_out
->dma
= devc
->dma16
;
680 audio_devs
[dev
]->dmap_in
->dma
= devc
->dma8
;
683 devc
->trigger_bits
= 0;
687 static void sb16_audio_output_block(int dev
, unsigned long buf
, int count
,
690 unsigned long flags
, cnt
;
691 sb_devc
*devc
= audio_devs
[dev
]->devc
;
694 if (!devc
->fullduplex
|| devc
->bits
== AFMT_S16_LE
)
696 devc
->irq_mode
= IMODE_OUTPUT
;
697 devc
->intr_active
= 1;
701 devc
->irq_mode_16
= IMODE_OUTPUT
;
702 devc
->intr_active_16
= 1;
706 spin_lock_irqsave(&devc
->lock
, flags
);
708 if (devc
->fullduplex
)
709 devc
->bits
= (devc
->bits
== AFMT_S16_LE
) ?
710 AFMT_U8
: AFMT_S16_LE
;
711 spin_unlock_irqrestore(&devc
->lock
, flags
);
714 if (devc
->bits
== AFMT_S16_LE
)
718 spin_lock_irqsave(&devc
->lock
, flags
);
720 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
722 sb_dsp_command(devc
, 0x41);
723 sb_dsp_command(devc
, (unsigned char) ((devc
->speed
>> 8) & 0xff));
724 sb_dsp_command(devc
, (unsigned char) (devc
->speed
& 0xff));
726 sb_dsp_command(devc
, (devc
->bits
== AFMT_S16_LE
? 0xb6 : 0xc6));
727 sb_dsp_command(devc
, ((devc
->channels
== 2 ? 0x20 : 0) +
728 (devc
->bits
== AFMT_S16_LE
? 0x10 : 0)));
729 sb_dsp_command(devc
, (unsigned char) (cnt
& 0xff));
730 sb_dsp_command(devc
, (unsigned char) (cnt
>> 8));
732 /* restore real value after all programming */
734 spin_unlock_irqrestore(&devc
->lock
, flags
);
739 * This fails on the Cyrix MediaGX. If you don't have the DMA enabled
740 * before the first sample arrives it locks up. However even if you
741 * do enable the DMA in time you just get DMA timeouts and missing
742 * interrupts and stuff, so for now I've not bothered fixing this either.
745 static void sb16_audio_start_input(int dev
, unsigned long buf
, int count
, int intrflag
)
747 unsigned long flags
, cnt
;
748 sb_devc
*devc
= audio_devs
[dev
]->devc
;
750 if (!devc
->fullduplex
|| devc
->bits
!= AFMT_S16_LE
)
752 devc
->irq_mode
= IMODE_INPUT
;
753 devc
->intr_active
= 1;
757 devc
->irq_mode_16
= IMODE_INPUT
;
758 devc
->intr_active_16
= 1;
762 if (devc
->bits
== AFMT_S16_LE
)
766 spin_lock_irqsave(&devc
->lock
, flags
);
768 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
770 sb_dsp_command(devc
, 0x42);
771 sb_dsp_command(devc
, (unsigned char) ((devc
->speed
>> 8) & 0xff));
772 sb_dsp_command(devc
, (unsigned char) (devc
->speed
& 0xff));
774 sb_dsp_command(devc
, (devc
->bits
== AFMT_S16_LE
? 0xbe : 0xce));
775 sb_dsp_command(devc
, ((devc
->channels
== 2 ? 0x20 : 0) +
776 (devc
->bits
== AFMT_S16_LE
? 0x10 : 0)));
777 sb_dsp_command(devc
, (unsigned char) (cnt
& 0xff));
778 sb_dsp_command(devc
, (unsigned char) (cnt
>> 8));
780 spin_unlock_irqrestore(&devc
->lock
, flags
);
783 static void sb16_audio_trigger(int dev
, int bits
)
785 sb_devc
*devc
= audio_devs
[dev
]->devc
;
787 int bits_16
= bits
& devc
->irq_mode_16
;
788 bits
&= devc
->irq_mode
;
790 if (!bits
&& !bits_16
)
791 sb_dsp_command(devc
, 0xd0); /* Halt DMA */
796 switch (devc
->irq_mode
)
799 sb16_audio_start_input(dev
,
806 sb16_audio_output_block(dev
,
815 switch (devc
->irq_mode_16
)
818 sb16_audio_start_input(dev
,
821 devc
->trg_intrflag_16
);
825 sb16_audio_output_block(dev
,
828 devc
->trg_intrflag_16
);
834 devc
->trigger_bits
= bits
| bits_16
;
837 static unsigned char lbuf8
[2048];
838 static signed short *lbuf16
= (signed short *)lbuf8
;
839 #define LBUFCOPYSIZE 1024
841 sb16_copy_from_user(int dev
,
842 char *localbuf
, int localoffs
,
843 const char __user
*userbuf
, int useroffs
,
844 int max_in
, int max_out
,
845 int *used
, int *returned
,
848 sb_devc
*devc
= audio_devs
[dev
]->devc
;
849 int i
, c
, p
, locallen
;
853 /* if not duplex no conversion */
854 if (!devc
->fullduplex
)
856 if (copy_from_user(localbuf
+ localoffs
,
857 userbuf
+ useroffs
, len
))
862 else if (devc
->bits
== AFMT_S16_LE
)
865 /* max_in >> 1, max number of samples in ( 16 bits ) */
866 /* max_out, max number of samples out ( 8 bits ) */
867 /* len, number of samples that will be taken ( 16 bits )*/
868 /* c, count of samples remaining in buffer ( 16 bits )*/
869 /* p, count of samples already processed ( 16 bits )*/
870 len
= ( (max_in
>> 1) > max_out
) ? max_out
: (max_in
>> 1);
873 buf8
= (unsigned char *)(localbuf
+ localoffs
);
876 locallen
= (c
>= LBUFCOPYSIZE
? LBUFCOPYSIZE
: c
);
877 /* << 1 in order to get 16 bit samples */
878 if (copy_from_user(lbuf16
,
879 userbuf
+ useroffs
+ (p
<< 1),
882 for (i
= 0; i
< locallen
; i
++)
884 buf8
[p
+i
] = ~((lbuf16
[i
] >> 8) & 0xff) ^ 0x80;
886 c
-= locallen
; p
+= locallen
;
888 /* used = ( samples * 16 bits size ) */
889 *used
= max_in
> ( max_out
<< 1) ? (max_out
<< 1) : max_in
;
890 /* returned = ( samples * 8 bits size ) */
896 /* max_in, max number of samples in ( 8 bits ) */
897 /* max_out >> 1, max number of samples out ( 16 bits ) */
898 /* len, number of samples that will be taken ( 8 bits )*/
899 /* c, count of samples remaining in buffer ( 8 bits )*/
900 /* p, count of samples already processed ( 8 bits )*/
901 len
= max_in
> (max_out
>> 1) ? (max_out
>> 1) : max_in
;
904 buf16
= (signed short *)(localbuf
+ localoffs
);
907 locallen
= (c
>= LBUFCOPYSIZE
? LBUFCOPYSIZE
: c
);
908 if (copy_from_user(lbuf8
,
909 userbuf
+useroffs
+ p
,
912 for (i
= 0; i
< locallen
; i
++)
914 buf16
[p
+i
] = (~lbuf8
[i
] ^ 0x80) << 8;
916 c
-= locallen
; p
+= locallen
;
918 /* used = ( samples * 8 bits size ) */
920 /* returned = ( samples * 16 bits size ) */
921 *returned
= len
<< 1;
926 sb16_audio_mmap(int dev
)
928 sb_devc
*devc
= audio_devs
[dev
]->devc
;
929 devc
->fullduplex
= 0;
932 static struct audio_driver sb1_audio_driver
= /* SB1.x */
934 .owner
= THIS_MODULE
,
935 .open
= sb_audio_open
,
936 .close
= sb_audio_close
,
937 .output_block
= sb_set_output_parms
,
938 .start_input
= sb_set_input_parms
,
939 .prepare_for_input
= sb1_audio_prepare_for_input
,
940 .prepare_for_output
= sb1_audio_prepare_for_output
,
941 .halt_io
= sb1_audio_halt_xfer
,
942 .trigger
= sb1_audio_trigger
,
943 .set_speed
= sb1_audio_set_speed
,
944 .set_bits
= sb1_audio_set_bits
,
945 .set_channels
= sb1_audio_set_channels
948 static struct audio_driver sb20_audio_driver
= /* SB2.0 */
950 .owner
= THIS_MODULE
,
951 .open
= sb_audio_open
,
952 .close
= sb_audio_close
,
953 .output_block
= sb_set_output_parms
,
954 .start_input
= sb_set_input_parms
,
955 .prepare_for_input
= sb1_audio_prepare_for_input
,
956 .prepare_for_output
= sb1_audio_prepare_for_output
,
957 .halt_io
= sb1_audio_halt_xfer
,
958 .trigger
= sb20_audio_trigger
,
959 .set_speed
= sb1_audio_set_speed
,
960 .set_bits
= sb1_audio_set_bits
,
961 .set_channels
= sb1_audio_set_channels
964 static struct audio_driver sb201_audio_driver
= /* SB2.01 */
966 .owner
= THIS_MODULE
,
967 .open
= sb_audio_open
,
968 .close
= sb_audio_close
,
969 .output_block
= sb_set_output_parms
,
970 .start_input
= sb_set_input_parms
,
971 .prepare_for_input
= sb1_audio_prepare_for_input
,
972 .prepare_for_output
= sb1_audio_prepare_for_output
,
973 .halt_io
= sb1_audio_halt_xfer
,
974 .trigger
= sb20_audio_trigger
,
975 .set_speed
= sb201_audio_set_speed
,
976 .set_bits
= sb1_audio_set_bits
,
977 .set_channels
= sb1_audio_set_channels
980 static struct audio_driver sbpro_audio_driver
= /* SB Pro */
982 .owner
= THIS_MODULE
,
983 .open
= sb_audio_open
,
984 .close
= sb_audio_close
,
985 .output_block
= sb_set_output_parms
,
986 .start_input
= sb_set_input_parms
,
987 .prepare_for_input
= sbpro_audio_prepare_for_input
,
988 .prepare_for_output
= sbpro_audio_prepare_for_output
,
989 .halt_io
= sb1_audio_halt_xfer
,
990 .trigger
= sb20_audio_trigger
,
991 .set_speed
= sbpro_audio_set_speed
,
992 .set_bits
= sb1_audio_set_bits
,
993 .set_channels
= sbpro_audio_set_channels
996 static struct audio_driver jazz16_audio_driver
= /* Jazz16 and SM Wave */
998 .owner
= THIS_MODULE
,
999 .open
= sb_audio_open
,
1000 .close
= sb_audio_close
,
1001 .output_block
= sb_set_output_parms
,
1002 .start_input
= sb_set_input_parms
,
1003 .prepare_for_input
= sbpro_audio_prepare_for_input
,
1004 .prepare_for_output
= sbpro_audio_prepare_for_output
,
1005 .halt_io
= sb1_audio_halt_xfer
,
1006 .trigger
= sb20_audio_trigger
,
1007 .set_speed
= jazz16_audio_set_speed
,
1008 .set_bits
= sb16_audio_set_bits
,
1009 .set_channels
= sbpro_audio_set_channels
1012 static struct audio_driver sb16_audio_driver
= /* SB16 */
1014 .owner
= THIS_MODULE
,
1015 .open
= sb_audio_open
,
1016 .close
= sb_audio_close
,
1017 .output_block
= sb_set_output_parms
,
1018 .start_input
= sb_set_input_parms
,
1019 .prepare_for_input
= sb16_audio_prepare_for_input
,
1020 .prepare_for_output
= sb16_audio_prepare_for_output
,
1021 .halt_io
= sb1_audio_halt_xfer
,
1022 .copy_user
= sb16_copy_from_user
,
1023 .trigger
= sb16_audio_trigger
,
1024 .set_speed
= sb16_audio_set_speed
,
1025 .set_bits
= sb16_audio_set_bits
,
1026 .set_channels
= sbpro_audio_set_channels
,
1027 .mmap
= sb16_audio_mmap
1030 void sb_audio_init(sb_devc
* devc
, char *name
, struct module
*owner
)
1032 int audio_flags
= 0;
1033 int format_mask
= AFMT_U8
;
1035 struct audio_driver
*driver
= &sb1_audio_driver
;
1037 switch (devc
->model
)
1039 case MDL_SB1
: /* SB1.0 or SB 1.5 */
1040 DDB(printk("Will use standard SB1.x driver\n"));
1041 audio_flags
= DMA_HARDSTOP
;
1045 DDB(printk("Will use SB2.0 driver\n"));
1046 audio_flags
= DMA_AUTOMODE
;
1047 driver
= &sb20_audio_driver
;
1051 DDB(printk("Will use SB2.01 (high speed) driver\n"));
1052 audio_flags
= DMA_AUTOMODE
;
1053 driver
= &sb201_audio_driver
;
1058 DDB(printk("Will use Jazz16 driver\n"));
1059 audio_flags
= DMA_AUTOMODE
;
1060 format_mask
|= AFMT_S16_LE
;
1061 driver
= &jazz16_audio_driver
;
1065 DDB(printk("Will use ESS ES688/1688 driver\n"));
1066 driver
= ess_audio_init (devc
, &audio_flags
, &format_mask
);
1070 DDB(printk("Will use SB16 driver\n"));
1071 audio_flags
= DMA_AUTOMODE
;
1072 format_mask
|= AFMT_S16_LE
;
1073 if (devc
->dma8
!= devc
->dma16
&& devc
->dma16
!= -1)
1075 audio_flags
|= DMA_DUPLEX
;
1078 driver
= &sb16_audio_driver
;
1082 DDB(printk("Will use SB Pro driver\n"));
1083 audio_flags
= DMA_AUTOMODE
;
1084 driver
= &sbpro_audio_driver
;
1088 driver
->owner
= owner
;
1090 if ((devc
->dev
= sound_install_audiodrv(AUDIO_DRIVER_VERSION
,
1091 name
,driver
, sizeof(struct audio_driver
),
1092 audio_flags
, format_mask
, devc
,
1094 devc
->duplex
? devc
->dma16
: devc
->dma8
)) < 0)
1096 printk(KERN_ERR
"Sound Blaster: unable to install audio.\n");
1099 audio_devs
[devc
->dev
]->mixer_dev
= devc
->my_mixerdev
;
1100 audio_devs
[devc
->dev
]->min_fragment
= 5;