Deleted Added
sdiff udiff text old ( 29651 ) new ( 30869 )
full compact
1/*
2 * sound/sb_dsp.c
3 *
4 * driver for the SoundBlaster and clones.
5 *
6 * Copyright 1997 Luigi Rizzo.
7 *
8 * Derived from files in the Voxware 3.5 distribution,
9 * Copyright by Hannu Savolainen 1994, under the same copyright
10 * conditions.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met: 1. Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer. 2. Redistributions in binary form must reproduce the
17 * above copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED

--- 78 unchanged lines hidden (view full) ---

107 * directly referenced in the descriptor.
108 */
109
110/*
111 * the probe routine for the SoundBlaster only consists in
112 * resetting the dsp and testing if it is there.
113 * Version detection etc. will be done at attach time.
114 *
115 * Remebber, isa probe routines are supposed to return the
116 * size of io space used.
117 */
118
119static int
120sb_probe(struct isa_device *dev)
121{
122 bzero(&pcm_info[dev->id_unit], sizeof(pcm_info[dev->id_unit]) );
123 if (dev->id_iobase == -1) {

--- 11 unchanged lines hidden (view full) ---

135 return 0;
136}
137
138static int
139sb_attach(struct isa_device *dev)
140{
141 snddev_info *d = &pcm_info[dev->id_unit] ;
142
143 sb_dsp_init(d, dev);
144 return 0 ;
145}
146
147/*
148 * here are the main routines from the switches.
149 */
150

--- 15 unchanged lines hidden (view full) ---

166 }
167
168 d->wsel.si_pid = 0;
169 d->wsel.si_flags = 0;
170
171 d->rsel.si_pid = 0;
172 d->rsel.si_flags = 0;
173
174 d->esel.si_pid = 0;
175 d->esel.si_flags = 0;
176
177 d->flags = 0 ;
178 d->bd_flags &= ~BD_F_HISPEED ;
179
180 switch ( dev & 0xf ) {
181 case SND_DEV_DSP16 :
182 if ((d->audio_fmt & AFMT_S16_LE) == 0) {
183 printf("sorry, 16-bit not supported on SB %d.%02d\n",
184 (d->bd_id >>8) & 0xff, d->bd_id & 0xff);

--- 10 unchanged lines hidden (view full) ---

195 }
196
197 d->flags |= SND_F_BUSY ;
198 d->play_speed = d->rec_speed = DSP_DEFAULT_SPEED ;
199
200 if (flags & O_NONBLOCK)
201 d->flags |= SND_F_NBIO ;
202
203 reset_dbuf(& (d->dbuf_in) );
204 reset_dbuf(& (d->dbuf_out) );
205 sb_reset_dsp(d->io_base);
206 ask_init(d);
207
208 return 0;
209}
210
211static int
212sb_dsp_close(dev_t dev, int flags, int mode, struct proc * p)

--- 69 unchanged lines hidden (view full) ---

282 }
283 if ( c & 2 ) { /* 16-bit dma */
284 if (d->dma1 >= 4)
285 reason |= 1;
286 if (d->dma2 >= 4)
287 reason |= 2;
288 }
289 }
290 if ( c & 2 )
291 inb(DSP_DATA_AVL16); /* 16-bit int ack */
292 if (c & 1)
293 inb(DSP_DATA_AVAIL); /* 8-bit int ack */
294
295DEB(printf("sbintr, flags 0x%08lx reason %d\n", d->flags, reason));
296 if ( (d->flags & SND_F_WR_DMA) && (reason & 1) )
297 dsp_wrintr(d);
298 if ( (d->flags & SND_F_RD_DMA) && (reason & 2) )
299 dsp_rdintr(d);
300
301 /*
302 * the sb16 might have multiple sources etc.
303 */
304 if (d->bd_flags & BD_F_SB16 && (c & 3) )
305 goto again;
306}
307
308/*

--- 6 unchanged lines hidden (view full) ---

315 * the changes at the next convenient time (typically, at the
316 * start of operations). For full duplex devices, in some cases the
317 * init requires both channels to be idle.
318 */
319static int
320sb_callback(snddev_info *d, int reason)
321{
322 int rd = reason & SND_CB_RD ;
323 int l = (rd) ? d->dbuf_in.dl0 : d->dbuf_out.dl0 ;
324
325 switch (reason & SND_CB_REASON_MASK) {
326 case SND_CB_INIT : /* called with int enabled and no pending io */
327 dsp_speed(d);
328 snd_set_blocksize(d);
329 if (d->play_fmt & AFMT_MU_LAW)
330 d->flags |= SND_F_XLAT8 ;
331 else
332 d->flags &= ~SND_F_XLAT8 ;
333 return 1;
334 break ;
335
336 case SND_CB_START : /* called with int disabled */
337 sb_cmd(d->io_base, rd ? DSP_CMD_SPKOFF : DSP_CMD_SPKON);
338 d->flags &= ~SND_F_INIT ;
339 if (d->bd_flags & BD_F_SB16) {
340 /* the SB16 can do full duplex using one 16-bit channel
341 * and one 8-bit channel. It needs to be programmed to
342 * use split format though.
343 */
344 int b16 ;
345 int swap = 0 ;
346
347 b16 = (rd) ? d->rec_fmt : d->play_fmt ;
348 b16 = (b16 == AFMT_S16_LE) ? 1 : 0;
349 /*
350 * check if I have to swap dma channels. Swap if
351 * - !rd, dma1 <4, b16
352 * - !rd, dma1 >=4, !b16
353 * - rd, dma2 <4, b16
354 * - rd, dma2 >=4, !b16
355 */
356 if (!rd) {
357 if ( (d->dma1 <4 && b16) || (d->dma1 >=4 && !b16) ) swap = 1;
358 } else {
359 if ( (d->dma2 <4 && b16) || (d->dma2 >=4 && !b16) ) swap = 1;
360 }
361 /*
362 * before swapping should make sure that there is no
363 * pending DMA on the other channel...
364 */
365 if (swap) {
366 int c = d->dma2 ;
367 d->dma2 = d->dma1;
368 d->dma1 = c ;
369 }
370 DEB(printf("sb_init: play %ld rec %ld dma1 %d dma2 %d\n",
371 d->play_fmt, d->rec_fmt, d->dma1, d->dma2));
372 }
373 /* fallthrough */
374 case SND_CB_RESTART:
375 if (d->bd_flags & BD_F_SB16) {
376 u_char c, c1 ;
377 /*
378 * SB16 support still not completely working!!!
379 *
380 * in principle, on the SB16, I could support simultaneous
381 * play & rec.
382 * However, there is no way to ask explicitly for 8 or
383 * 16 bit transfer. As a consequence, if we do 8-bit,
384 * we need to use the 8-bit channel, and if we do 16-bit,
385 * we need to use the other one. The only way I find to
386 * do this is to swap d->dma1 and d->dma2 ...
387 *
388 */
389
390 if (rd) {
391 c = ((d->dma2 > 3) ? DSP_DMA16 : DSP_DMA8) |
392 DSP_F16_FIFO_ON | DSP_F16_ADC ;
393 c1 = (d->play_fmt == AFMT_U8) ? 0 : DSP_F16_SIGNED ;
394 if (d->play_fmt == AFMT_MU_LAW) c1 = 0 ;
395 if (d->rec_fmt == AFMT_S16_LE)
396 l /= 2 ;
397 } else {
398 c = ((d->dma1 > 3) ? DSP_DMA16 : DSP_DMA8) |
399 DSP_F16_FIFO_ON | DSP_F16_DAC ;
400 c1 = (d->rec_fmt == AFMT_U8) ? 0 : DSP_F16_SIGNED ;
401 if (d->play_fmt == AFMT_MU_LAW) c1 = 0 ;
402 if (d->play_fmt == AFMT_S16_LE)
403 l /= 2 ;
404 }
405
406 if (d->flags & SND_F_STEREO)
407 c1 |= DSP_F16_STEREO ;
408
409 sb_cmd(d->io_base, c );
410 sb_cmd3(d->io_base, c1 , l - 1) ;
411 } else {
412 u_char c ;
413 if (d->bd_flags & BD_F_HISPEED)
414 c = (rd) ? DSP_CMD_HSADC : DSP_CMD_HSDAC ;
415 else
416 c = (rd) ? DSP_CMD_ADC8 : DSP_CMD_DAC8 ;
417 sb_cmd3(d->io_base, c , l - 1) ;
418 }
419 break;
420
421 case SND_CB_STOP :
422 /* XXX ??? sb_cmd(d->io_base, DSP_CMD_SPKOFF);*/ /* speaker off */
423 break ;
424
425 }
426 return 0 ;
427}
428
429/*
430 * The second part of the file contains all functions specific to

--- 7 unchanged lines hidden (view full) ---

438
439 outb(DSP_RESET, 1);
440 DELAY(100);
441 outb(DSP_RESET, 0);
442 for (loopc = 0; loopc<100 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++)
443 DELAY(30);
444
445 if (inb(DSP_READ) != 0xAA) {
446 DEB(printf("sb_reset_dsp failed\n"));
447 return 0; /* Sorry */
448 }
449 return 1;
450}
451
452/*
453 * only used in sb_attach from here.
454 */

--- 293 unchanged lines hidden (view full) ---

748
749 if (d->flags & SND_F_STEREO)
750 speed *= 2;
751
752 /*
753 * Now the speed should be valid. Compute the value to be
754 * programmed into the board.
755 *
756 * XXX check this code...
757 */
758
759 if (speed > 22050) { /* High speed mode on 2.01/3.xx */
760 int tmp;
761
762 tconst = (u_char) ((65536 - ((256000000 + speed / 2) / speed)) >> 8);
763 d->bd_flags |= BD_F_HISPEED ;
764
765 flags = spltty();
766 sb_cmd2(d->io_base, DSP_CMD_TCONST, tconst);
767 splx(flags);
768
769 tmp = 65536 - (tconst << 8);
770 speed = (256000000 + tmp / 2) / tmp;

--- 246 unchanged lines hidden (view full) ---

1017 &tty_imask /* imask */
1018};
1019DATA_SET (pnpdevice_set, sb16pnp);
1020
1021static char *
1022sb16pnp_probe(u_long csn, u_long vend_id)
1023{
1024 char *s = NULL ;
1025 if (vend_id == 0x01009305)
1026 s = "Avance Asound 100" ;
1027 if (vend_id == 0x2b008c0e)
1028 s = "SB16 Value PnP" ;
1029 /*
1030 * The SB16/AWE64 cards seem to differ in the fourth byte of
1031 * the vendor id, so I have just masked it for the time being...
1032 * Reported values are:
1033 * SB16 Value PnP: 0x2b008c0e
1034 * SB AWE64 PnP: 0x39008c0e 0x9d008c0e 0xc3008c0e
1035 */
1036 if ( (vend_id & 0xffffff) == (0x9d008c0e & 0xffffff) )
1037 s = "SB AWE64 PnP";
1038 if (s) {
1039 struct pnp_cinfo d;
1040 read_pnp_parms(&d, 0);
1041 if (d.enable == 0) {
1042 printf("This is a %s, but LDN 0 is disabled\n", s);
1043 return NULL ;
1044 }
1045 return s ;

--- 33 unchanged lines hidden ---