1993-10-23 10:55:52 +00:00
|
|
|
/*
|
1994-03-11 10:27:25 +00:00
|
|
|
* sound/sb_dsp.c
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1994-10-01 02:17:17 +00:00
|
|
|
* The low level driver for the SoundBlaster DSP chip (SB1.0 to 2.1, SB Pro).
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1994-10-01 02:17:17 +00:00
|
|
|
* Copyright by Hannu Savolainen 1994
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer. 2.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
|
|
|
* Modified: Hunyue Yau Jan 6 1994 Added code to support Sound Galaxy NX
|
|
|
|
* Pro
|
|
|
|
*
|
|
|
|
* JRA Gibson April 1995 Code added for MV ProSonic/Jazz 16 in 16 bit mode
|
1993-10-23 10:55:52 +00:00
|
|
|
*/
|
|
|
|
|
1996-09-10 08:32:01 +00:00
|
|
|
#include <i386/isa/sound/sound_config.h>
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#if (NSB > 0)
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef SM_WAVE
|
|
|
|
#define JAZZ16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <i386/isa/sound/sbcard.h>
|
1996-09-10 08:32:01 +00:00
|
|
|
#include <i386/isa/sound/sb_mixer.h>
|
1997-10-31 17:25:35 +00:00
|
|
|
#include <machine/clock.h>
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
#undef SB_TEST_IRQ
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* XXX note -- only one sb-like device is supported until these
|
|
|
|
* variables are put in a struct sb_unit[] array
|
|
|
|
*/
|
|
|
|
|
1997-11-23 07:35:06 +00:00
|
|
|
|
|
|
|
|
1994-03-11 10:27:25 +00:00
|
|
|
int sbc_base = 0;
|
1998-02-09 06:11:36 +00:00
|
|
|
static int sbc_irq = 0;
|
1994-10-01 02:17:17 +00:00
|
|
|
static int open_mode = 0; /* Read, write or both */
|
1995-07-28 21:40:49 +00:00
|
|
|
int Jazz16_detected = 0;
|
1998-02-12 22:33:33 +00:00
|
|
|
int sb_no_recording = 0;
|
1997-10-31 17:25:35 +00:00
|
|
|
static int dsp_count = 0;
|
|
|
|
static int trigger_bits;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The DSP channel can be used either for input or output. Variable
|
1994-03-11 10:27:25 +00:00
|
|
|
* 'sb_irq_mode' will be set when the program calls read or write first time
|
1993-10-23 10:55:52 +00:00
|
|
|
* after open. Current version doesn't support mode changes without closing
|
|
|
|
* and reopening the device. Support for this feature may be implemented in a
|
|
|
|
* future version of this driver.
|
|
|
|
*/
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
int sb_dsp_ok = 0; /* Set to 1 after successful init */
|
1993-10-23 10:55:52 +00:00
|
|
|
static int midi_disabled = 0;
|
1994-03-11 10:27:25 +00:00
|
|
|
int sb_dsp_highspeed = 0;
|
1997-10-31 17:25:35 +00:00
|
|
|
int sbc_major = 1, sbc_minor = 0; /* DSP version */
|
1994-03-11 10:27:25 +00:00
|
|
|
static int dsp_stereo = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
static int dsp_current_speed = DSP_DEFAULT_SPEED;
|
1994-03-11 10:27:25 +00:00
|
|
|
static int sb16 = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1994-03-11 10:27:25 +00:00
|
|
|
int sb_midi_mode = NORMAL_MIDI;
|
1997-10-31 17:25:35 +00:00
|
|
|
int sb_midi_busy = 0; /* 1 if the process has output to * *
|
|
|
|
* MIDI */
|
1994-03-11 10:27:25 +00:00
|
|
|
int sb_dsp_busy = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
volatile int sb_irq_mode = IMODE_NONE; /* or IMODE_INPUT or IMODE_OUTPUT */
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int dma8 = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef JAZZ16 /* 16 bit support for JAZZ16 */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
static int dsp_16bit = 0;
|
|
|
|
static int dma16 = 5;
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int dsp_set_bits(int arg);
|
|
|
|
static int initialize_ProSonic16(void);
|
|
|
|
#endif /* end of 16 bit support for JAZZ16 */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1994-03-11 10:27:25 +00:00
|
|
|
int sb_duplex_midi = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
static int my_dev = 0;
|
|
|
|
|
1994-03-11 10:27:25 +00:00
|
|
|
volatile int sb_intr_active = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int dsp_speed(int);
|
|
|
|
static int dsp_set_stereo(int mode);
|
|
|
|
static void sb_dsp_reset(int dev);
|
1998-02-12 22:33:33 +00:00
|
|
|
sound_os_info *sb_osp = NULL;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#if defined(CONFIG_MIDI) || defined(CONFIG_AUDIO)
|
1998-02-09 06:11:36 +00:00
|
|
|
static void dsp_speaker(char state);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
/*
|
|
|
|
* Common code for the midi and pcm functions
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1994-03-11 10:27:25 +00:00
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_command(u_char val)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int i;
|
|
|
|
u_long limit;
|
|
|
|
|
|
|
|
limit = get_time() + hz / 10; /* The timeout is 0.1 secods */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note! the i<500000 is an emergency exit. The sb_dsp_command() is
|
|
|
|
* sometimes called while interrupts are disabled. This means that
|
|
|
|
* the timer is disabled also. However the timeout situation is a
|
|
|
|
* abnormal condition. Normally the DSP should be ready to accept
|
|
|
|
* commands after just couple of loops.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 500000 && get_time() < limit; i++) {
|
|
|
|
if ((inb(DSP_STATUS) & 0x80) == 0) {
|
|
|
|
outb(DSP_COMMAND, val);
|
|
|
|
return 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
printf("SoundBlaster: DSP Command(0x%02x) timeout. IRQ conflict ?\n", val);
|
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
sbintr(int irq)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int status;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SBPRO
|
|
|
|
if (sb16) {
|
|
|
|
u_char src = sb_getmixer(IRQ_STAT); /* Interrupt source register */
|
|
|
|
#ifdef CONFIG_SB16
|
|
|
|
if (src & 3)
|
|
|
|
sb16_dsp_interrupt(irq);
|
|
|
|
#ifdef CONFIG_MIDI
|
|
|
|
if (src & 4)
|
|
|
|
sb16midiintr(irq); /* SB MPU401 interrupt */
|
|
|
|
#endif /* CONFIG_MIDI */
|
|
|
|
#endif /* CONFIG_SB16 */
|
|
|
|
if (!(src & 1))
|
|
|
|
return; /* Not a DSP interupt */
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
#endif /* CONFIG_SBPRO */
|
|
|
|
|
|
|
|
status = inb(DSP_DATA_AVAIL); /* Clear interrupt */
|
|
|
|
|
|
|
|
if (sb_intr_active)
|
|
|
|
switch (sb_irq_mode) {
|
|
|
|
case IMODE_OUTPUT:
|
|
|
|
sb_intr_active = 0;
|
|
|
|
DMAbuf_outputintr(my_dev, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMODE_INPUT:
|
|
|
|
sb_intr_active = 0;
|
|
|
|
DMAbuf_inputintr(my_dev);
|
|
|
|
/*
|
|
|
|
* A complete buffer has been input. Let's start new one
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMODE_INIT:
|
|
|
|
sb_intr_active = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMODE_MIDI:
|
|
|
|
#ifdef CONFIG_MIDI
|
|
|
|
sb_midi_interrupt(irq);
|
1994-03-11 10:27:25 +00:00
|
|
|
#endif
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
default:
|
|
|
|
printf("SoundBlaster: Unexpected interrupt\n");
|
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-03-11 10:27:25 +00:00
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_reset_dsp(void)
|
1994-03-11 10:27:25 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int loopc;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
outb(DSP_RESET, 1);
|
|
|
|
DELAY(10);
|
|
|
|
outb(DSP_RESET, 0);
|
|
|
|
DELAY(30);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (loopc = 0; loopc < 100 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++)
|
|
|
|
DELAY(10);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (inb(DSP_READ) != 0xAA) {
|
|
|
|
printf("sb_reset_dsp failed\n");
|
|
|
|
return 0; /* Sorry */
|
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_AUDIO
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_speaker(char state)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
if (state)
|
|
|
|
sb_dsp_command(DSP_CMD_SPKON);
|
|
|
|
else
|
|
|
|
sb_dsp_command(DSP_CMD_SPKOFF);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_speed(int speed)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_char tconst;
|
|
|
|
u_long flags;
|
|
|
|
int max_speed = 44100;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (speed < 4000)
|
|
|
|
speed = 4000;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Older SB models don't support higher speeds than 22050.
|
1997-10-31 17:25:35 +00:00
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major < 2 || (sbc_major == 2 && sbc_minor == 0))
|
|
|
|
max_speed = 22050;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
1995-07-28 21:40:49 +00:00
|
|
|
* SB models earlier than SB Pro have low limit for the input speed.
|
1997-10-31 17:25:35 +00:00
|
|
|
*/
|
|
|
|
if (open_mode != OPEN_WRITE) /* Recording is possible */
|
|
|
|
if (sbc_major < 3) /* Limited input speed with these cards */
|
|
|
|
if (sbc_major == 2 && sbc_minor > 0)
|
|
|
|
max_speed = 15000;
|
|
|
|
else
|
|
|
|
max_speed = 13000;
|
|
|
|
|
|
|
|
if (speed > max_speed)
|
|
|
|
speed = max_speed; /* Invalid speed */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logitech SoundMan Games and Jazz16 cards can support 44.1kHz
|
|
|
|
* stereo
|
|
|
|
*/
|
1995-07-28 21:40:49 +00:00
|
|
|
#if !defined (SM_GAMES)
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Max. stereo speed is 22050
|
|
|
|
*/
|
|
|
|
if (dsp_stereo && speed > 22050 && Jazz16_detected == 0)
|
|
|
|
speed = 22050;
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((speed > 22050) && sb_midi_busy) {
|
|
|
|
printf("SB Warning: High speed DSP not possible simultaneously with MIDI output\n");
|
|
|
|
speed = 22050;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dsp_stereo)
|
|
|
|
speed *= 2;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Now the speed should be valid
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (speed > 22050) { /* High speed mode */
|
|
|
|
int tmp;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
tconst = (u_char) ((65536 - ((256000000 + speed / 2) / speed)) >> 8);
|
|
|
|
sb_dsp_highspeed = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if (sb_dsp_command(DSP_CMD_TCONST))
|
|
|
|
sb_dsp_command(tconst);
|
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
tmp = 65536 - (tconst << 8);
|
|
|
|
speed = (256000000 + tmp / 2) / tmp;
|
|
|
|
} else {
|
|
|
|
int tmp;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_highspeed = 0;
|
|
|
|
tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if (sb_dsp_command(DSP_CMD_TCONST)) /* Set time constant */
|
|
|
|
sb_dsp_command(tconst);
|
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
tmp = 256 - tconst;
|
|
|
|
speed = (1000000 + tmp / 2) / tmp;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dsp_stereo)
|
|
|
|
speed /= 2;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_current_speed = speed;
|
|
|
|
return speed;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_set_stereo(int mode)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_stereo = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifndef CONFIG_SBPRO
|
|
|
|
return 0;
|
1994-03-11 10:27:25 +00:00
|
|
|
#else
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major < 3 || sb16)
|
|
|
|
return 0; /* Sorry no stereo */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mode && sb_midi_busy) {
|
|
|
|
printf("SB Warning: Stereo DSP not possible simultaneously with MIDI output\n");
|
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_stereo = !!mode;
|
|
|
|
return dsp_stereo;
|
1993-10-23 10:55:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_output_block(int dev, u_long buf, int count,
|
|
|
|
int intrflag, int restart_dma)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
|
|
|
|
|
|
|
if (!sb_irq_mode)
|
|
|
|
dsp_speaker(ON);
|
|
|
|
|
|
|
|
DMAbuf_start_dma(dev, buf, count, 1);
|
|
|
|
|
|
|
|
sb_irq_mode = 0;
|
|
|
|
|
|
|
|
if (audio_devs[dev]->dmachan1 > 3)
|
|
|
|
count >>= 1;
|
|
|
|
count--;
|
|
|
|
dsp_count = count;
|
|
|
|
|
|
|
|
sb_irq_mode = IMODE_OUTPUT;
|
|
|
|
if (sb_dsp_highspeed) {
|
|
|
|
flags = splhigh();
|
|
|
|
if (sb_dsp_command(DSP_CMD_HSSIZE)) { /* High speed size */
|
|
|
|
sb_dsp_command((u_char) (dsp_count & 0xff));
|
|
|
|
sb_dsp_command((u_char) ((dsp_count >> 8) & 0xff));
|
|
|
|
sb_dsp_command(DSP_CMD_HSDAC); /* High speed 8 bit DAC */
|
|
|
|
} else
|
|
|
|
printf("SB Error: Unable to start (high speed) DAC\n");
|
|
|
|
splx(flags);
|
|
|
|
} else {
|
|
|
|
flags = splhigh();
|
|
|
|
if (sb_dsp_command(DSP_CMD_DAC8)) { /* 8-bit DAC (DMA) */
|
|
|
|
sb_dsp_command((u_char) (dsp_count & 0xff));
|
|
|
|
sb_dsp_command((u_char) ((dsp_count >> 8) & 0xff));
|
|
|
|
} else
|
|
|
|
printf("SB Error: Unable to start DAC\n");
|
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_intr_active = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_start_input(int dev, u_long buf, int count, int intrflag,
|
|
|
|
int restart_dma)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sb_no_recording) {
|
|
|
|
printf("SB Error: This device doesn't support recording\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Start a DMA input to the buffer pointed by dmaqtail
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!sb_irq_mode)
|
|
|
|
dsp_speaker(OFF);
|
|
|
|
|
|
|
|
DMAbuf_start_dma(dev, buf, count, 0);
|
|
|
|
sb_irq_mode = 0;
|
|
|
|
|
|
|
|
if (audio_devs[dev]->dmachan1 > 3)
|
|
|
|
count >>= 1;
|
|
|
|
count--;
|
|
|
|
dsp_count = count;
|
|
|
|
|
|
|
|
sb_irq_mode = IMODE_INPUT;
|
|
|
|
if (sb_dsp_highspeed) {
|
|
|
|
flags = splhigh();
|
|
|
|
if (sb_dsp_command(DSP_CMD_HSSIZE)) { /* High speed size */
|
|
|
|
sb_dsp_command((u_char) (dsp_count & 0xff));
|
|
|
|
sb_dsp_command((u_char) ((dsp_count >> 8) & 0xff));
|
|
|
|
sb_dsp_command(DSP_CMD_HSADC); /* High speed 8 bit ADC */
|
|
|
|
} else
|
|
|
|
printf("SB Error: Unable to start (high speed) ADC\n");
|
|
|
|
splx(flags);
|
|
|
|
} else {
|
|
|
|
flags = splhigh();
|
|
|
|
if (sb_dsp_command(DSP_CMD_ADC8)) { /* 8-bit ADC (DMA) */
|
|
|
|
sb_dsp_command((u_char) (dsp_count & 0xff));
|
|
|
|
sb_dsp_command((u_char) ((dsp_count >> 8) & 0xff));
|
|
|
|
} else
|
|
|
|
printf("SB Error: Unable to start ADC\n");
|
|
|
|
splx(flags);
|
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_intr_active = 1;
|
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static void
|
|
|
|
sb_dsp_trigger(int dev, int bits)
|
|
|
|
{
|
|
|
|
if (bits == trigger_bits)
|
|
|
|
return;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!bits)
|
|
|
|
sb_dsp_command(0xd0); /* Halt DMA */
|
|
|
|
else if (bits & sb_irq_mode)
|
|
|
|
sb_dsp_command(0xd4); /* Continue DMA */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
trigger_bits = bits;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_cleanup(void)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_intr_active = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_prepare_for_input(int dev, int bsize, int bcount)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-11-23 07:35:06 +00:00
|
|
|
int fudge = -1;
|
|
|
|
struct dma_buffparms *dmap = audio_devs[dev]->dmap_in;
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_cleanup();
|
|
|
|
dsp_speaker(OFF);
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major == 3) { /* SB Pro */
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Select correct dma channel for 16/8 bit acccess
|
|
|
|
*/
|
|
|
|
audio_devs[my_dev]->dmachan1 = dsp_16bit ? dma16 : dma8;
|
|
|
|
if (dsp_stereo)
|
|
|
|
sb_dsp_command(dsp_16bit ? 0xac : 0xa8);
|
|
|
|
else
|
|
|
|
sb_dsp_command(dsp_16bit ? 0xa4 : 0xa0);
|
1995-07-28 21:40:49 +00:00
|
|
|
#else
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* 8 bit only cards use this
|
|
|
|
*/
|
|
|
|
if (dsp_stereo)
|
|
|
|
sb_dsp_command(0xa8);
|
|
|
|
else
|
|
|
|
sb_dsp_command(0xa0);
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_speed(dsp_current_speed); /* Speed must be recalculated
|
|
|
|
* if #channels * changes */
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-11-23 07:35:06 +00:00
|
|
|
|
|
|
|
fudge = audio_devs[my_dev]->dmachan1;
|
|
|
|
if (dmap->dma_chan != fudge ) {
|
|
|
|
isa_dma_release( dmap->dma_chan);
|
|
|
|
isa_dma_acquire(fudge);
|
|
|
|
dmap->dma_chan = fudge;
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
trigger_bits = 0;
|
|
|
|
sb_dsp_command(DSP_CMD_DMAHALT); /* Halt DMA */
|
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_prepare_for_output(int dev, int bsize, int bcount)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-11-23 07:35:06 +00:00
|
|
|
|
|
|
|
int fudge;
|
|
|
|
struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_cleanup();
|
|
|
|
dsp_speaker(ON);
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_SBPRO
|
|
|
|
if (sbc_major == 3) { /* SB Pro */
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* 16 bit specific instructions
|
|
|
|
*/
|
|
|
|
audio_devs[my_dev]->dmachan1 = dsp_16bit ? dma16 : dma8;
|
1997-11-23 07:35:06 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (Jazz16_detected != 2) /* SM Wave */
|
|
|
|
sb_mixer_set_stereo(dsp_stereo);
|
|
|
|
if (dsp_stereo)
|
|
|
|
sb_dsp_command(dsp_16bit ? 0xac : 0xa8);
|
|
|
|
else
|
|
|
|
sb_dsp_command(dsp_16bit ? 0xa4 : 0xa0);
|
1995-07-28 21:40:49 +00:00
|
|
|
#else
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_mixer_set_stereo(dsp_stereo);
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_speed(dsp_current_speed); /* Speed must be recalculated
|
|
|
|
* if #channels * changes */
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
1997-11-23 07:35:06 +00:00
|
|
|
fudge = audio_devs[my_dev]->dmachan1;
|
|
|
|
|
|
|
|
if (dmap->dma_chan != fudge ) {
|
|
|
|
isa_dma_release( dmap->dma_chan);
|
|
|
|
isa_dma_acquire(fudge);
|
|
|
|
dmap->dma_chan = fudge;
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
trigger_bits = 0;
|
|
|
|
sb_dsp_command(DSP_CMD_DMAHALT); /* Halt DMA */
|
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_halt_xfer(int dev)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_open(int dev, int mode)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int retval;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!sb_dsp_ok) {
|
|
|
|
printf("SB Error: SoundBlaster board not installed\n");
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sb_no_recording && mode & OPEN_READ) {
|
|
|
|
printf("SB Warning: Recording not supported by this device\n");
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sb_intr_active || (sb_midi_busy && sb_midi_mode == UART_MIDI)) {
|
|
|
|
printf("SB: PCM not possible during MIDI input\n");
|
|
|
|
return -(EBUSY);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Allocate 8 bit dma
|
|
|
|
*/
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
audio_devs[my_dev]->dmachan1 = dma8;
|
|
|
|
/*
|
|
|
|
* Allocate 16 bit dma
|
|
|
|
*/
|
|
|
|
if (Jazz16_detected != 0)
|
|
|
|
if (dma16 != dma8) {
|
|
|
|
if (0) {
|
|
|
|
return -(EBUSY);
|
|
|
|
}
|
|
|
|
}
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_irq_mode = IMODE_NONE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_busy = 1;
|
|
|
|
open_mode = mode;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-11-23 07:35:06 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_close(int dev)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Release 16 bit dma channel
|
|
|
|
*/
|
|
|
|
if (Jazz16_detected) {
|
|
|
|
audio_devs[my_dev]->dmachan1 = dma8;
|
|
|
|
|
|
|
|
}
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_cleanup();
|
|
|
|
dsp_speaker(OFF);
|
|
|
|
sb_dsp_busy = 0;
|
|
|
|
sb_dsp_highspeed = 0;
|
|
|
|
open_mode = 0;
|
1997-11-23 07:35:06 +00:00
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Function dsp_set_bits() only required for 16 bit cards
|
1995-07-28 21:40:49 +00:00
|
|
|
*/
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
dsp_set_bits(int arg)
|
1995-07-28 21:40:49 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
if (arg)
|
|
|
|
if (Jazz16_detected == 0)
|
|
|
|
dsp_16bit = 0;
|
|
|
|
else
|
|
|
|
switch (arg) {
|
|
|
|
case 8:
|
|
|
|
dsp_16bit = 0;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
dsp_16bit = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dsp_16bit = 0;
|
|
|
|
}
|
|
|
|
return dsp_16bit ? 16 : 8;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#endif /* ifdef JAZZ16 */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_ioctl(int dev, u_int cmd, ioctl_arg arg, int local)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
switch (cmd) {
|
1993-10-23 10:55:52 +00:00
|
|
|
case SOUND_PCM_WRITE_RATE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_speed((int) arg);
|
|
|
|
return *(int *) arg = dsp_speed((*(int *) arg));
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SOUND_PCM_READ_RATE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_current_speed;
|
|
|
|
return *(int *) arg = dsp_current_speed;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SOUND_PCM_WRITE_CHANNELS:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_set_stereo((int) arg - 1) + 1;
|
|
|
|
return *(int *) arg = dsp_set_stereo((*(int *) arg) - 1) + 1;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SOUND_PCM_READ_CHANNELS:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_stereo + 1;
|
|
|
|
return *(int *) arg = dsp_stereo + 1;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_DSP_STEREO:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_set_stereo((int) arg);
|
|
|
|
return *(int *) arg = dsp_set_stereo((*(int *) arg));
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Word size specific cases here.
|
|
|
|
* SNDCTL_DSP_SETFMT=SOUND_PCM_WRITE_BITS
|
|
|
|
*/
|
1995-07-28 21:40:49 +00:00
|
|
|
case SNDCTL_DSP_SETFMT:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_set_bits((int) arg);
|
|
|
|
return *(int *) arg = dsp_set_bits((*(int *) arg));
|
|
|
|
break;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
case SOUND_PCM_READ_BITS:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return dsp_16bit ? 16 : 8;
|
|
|
|
return *(int *) arg = dsp_16bit ? 16 : 8;
|
|
|
|
break;
|
1995-07-28 21:40:49 +00:00
|
|
|
#else
|
1993-10-23 10:55:52 +00:00
|
|
|
case SOUND_PCM_WRITE_BITS:
|
|
|
|
case SOUND_PCM_READ_BITS:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (local)
|
|
|
|
return 8;
|
|
|
|
return *(int *) (int) arg = 8; /* Only 8 bits/sample supported */
|
|
|
|
break;
|
|
|
|
#endif /* ifdef JAZZ16 */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SOUND_PCM_WRITE_FILTER:
|
|
|
|
case SOUND_PCM_READ_FILTER:
|
1997-10-31 17:25:35 +00:00
|
|
|
return -(EINVAL);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
default:;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return -(EINVAL);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_reset(int dev)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_reset_dsp();
|
|
|
|
dsp_speed(dsp_current_speed);
|
|
|
|
dsp_cleanup();
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
#ifdef JAZZ16
|
|
|
|
|
|
|
|
/*
|
1997-10-31 17:25:35 +00:00
|
|
|
* Initialization of a Media Vision ProSonic 16 Soundcard. The function
|
|
|
|
* initializes a ProSonic 16 like PROS.EXE does for DOS. It sets the base
|
|
|
|
* address, the DMA-channels, interrupts and enables the joystickport.
|
|
|
|
*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Also used by Jazz 16 (same card, different name)
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
|
|
|
* written 1994 by Rainer Vranken E-Mail:
|
|
|
|
* rvranken@polaris.informatik.uni-essen.de
|
1995-07-28 21:40:49 +00:00
|
|
|
*/
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
u_int
|
|
|
|
get_sb_byte(void)
|
1995-07-28 21:40:49 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int i;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 1000; i; i--)
|
|
|
|
if (inb(DSP_DATA_AVAIL) & 0x80) {
|
|
|
|
return inb(DSP_READ);
|
|
|
|
}
|
|
|
|
return 0xffff;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SM_WAVE
|
|
|
|
/*
|
|
|
|
* Logitech Soundman Wave detection and initialization by Hannu Savolainen.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1995-07-28 21:40:49 +00:00
|
|
|
* There is a microcontroller (8031) in the SM Wave card for MIDI emulation.
|
|
|
|
* it's located at address MPU_BASE+4. MPU_BASE+7 is a SM Wave specific
|
|
|
|
* control register for MC reset, SCSI, OPL4 and DSP (future expansion)
|
1997-10-31 17:25:35 +00:00
|
|
|
* address decoding. Otherwise the SM Wave is just a ordinary MV Jazz16 based
|
|
|
|
* soundcard.
|
1995-07-28 21:40:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
smw_putmem(int base, int addr, u_char val)
|
1995-07-28 21:40:49 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
outb(base + 1, addr & 0xff); /* Low address bits */
|
|
|
|
outb(base + 2, addr >> 8); /* High address bits */
|
|
|
|
outb(base, val); /* Data */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static u_char
|
|
|
|
smw_getmem(int base, int addr)
|
1995-07-28 21:40:49 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
|
|
|
u_char val;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
outb(base + 1, addr & 0xff); /* Low address bits */
|
|
|
|
outb(base + 2, addr >> 8); /* High address bits */
|
|
|
|
val = inb(base); /* Data */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
|
|
|
return val;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SMW_MIDI0001_INCLUDED
|
1997-10-31 17:25:35 +00:00
|
|
|
#include </sys/i386/isa/sound/smw-midi0001.h>
|
1995-07-28 21:40:49 +00:00
|
|
|
#else
|
1997-10-31 17:25:35 +00:00
|
|
|
u_char *smw_ucode = NULL;
|
|
|
|
int smw_ucodeLen = 0;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int
|
|
|
|
initialize_smw(int mpu_base)
|
|
|
|
{
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
int mp_base = mpu_base + 4; /* Microcontroller base */
|
|
|
|
int i;
|
|
|
|
u_char control;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the microcontroller so that the RAM can be accessed
|
|
|
|
*/
|
|
|
|
|
|
|
|
control = inb(mpu_base + 7);
|
|
|
|
outb(mpu_base + 7, control | 3); /* Set last two bits to 1 (?) */
|
|
|
|
outb(mpu_base + 7, (control & 0xfe) | 2); /* xxxxxxx0 resets the mc */
|
|
|
|
DELAY(3000); /* Wait at least 1ms */
|
|
|
|
|
|
|
|
outb(mpu_base + 7, control & 0xfc); /* xxxxxx00 enables RAM */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect microcontroller by probing the 8k RAM area
|
|
|
|
*/
|
|
|
|
smw_putmem(mp_base, 0, 0x00);
|
|
|
|
smw_putmem(mp_base, 1, 0xff);
|
|
|
|
DELAY(10);
|
|
|
|
|
|
|
|
if (smw_getmem(mp_base, 0) != 0x00 || smw_getmem(mp_base, 1) != 0xff) {
|
|
|
|
printf("\nSM Wave: No microcontroller RAM detected (%02x, %02x)\n",
|
|
|
|
smw_getmem(mp_base, 0), smw_getmem(mp_base, 1));
|
|
|
|
return 0; /* No RAM */
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* There is RAM so assume it's really a SM Wave
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (smw_ucodeLen > 0) {
|
|
|
|
if (smw_ucodeLen != 8192) {
|
|
|
|
printf("\nSM Wave: Invalid microcode (MIDI0001.BIN) length\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Download microcode
|
|
|
|
*/
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < 8192; i++)
|
|
|
|
smw_putmem(mp_base, i, smw_ucode[i]);
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Verify microcode
|
|
|
|
*/
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < 8192; i++)
|
|
|
|
if (smw_getmem(mp_base, i) != smw_ucode[i]) {
|
|
|
|
printf("SM Wave: Microcode verification failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
control = 0;
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef SMW_SCSI_IRQ
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
|
|
|
|
* is disabled by default.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Btw the Zilog 5380 SCSI controller is located at MPU base + 0x10.
|
1997-10-31 17:25:35 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
static u_char scsi_irq_bits[] =
|
|
|
|
{0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0};
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
|
|
|
|
}
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SMW_OPL4_ENABLE
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Make the OPL4 chip visible on the PC bus at 0x380.
|
|
|
|
*
|
|
|
|
* There is no need to enable this feature since VoxWare doesn't support
|
|
|
|
* OPL4 yet. Also there is no RAM in SM Wave so enabling OPL4 is
|
|
|
|
* pretty useless.
|
|
|
|
*/
|
|
|
|
control |= 0x10; /* Uses IRQ12 if bit 0x20 == 0 */
|
|
|
|
/* control |= 0x20; Uncomment this if you want to use IRQ7 */
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
outb(mpu_base + 7, control | 0x03); /* xxxxxx11 restarts */
|
|
|
|
return 1;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
initialize_ProSonic16(void)
|
1995-07-28 21:40:49 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int x;
|
|
|
|
static u_char int_translat[16] =
|
|
|
|
{0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6},
|
|
|
|
dma_translat[8] =
|
|
|
|
{0, 1, 0, 2, 0, 3, 0, 4};
|
|
|
|
|
|
|
|
struct address_info *mpu_config;
|
|
|
|
|
|
|
|
int mpu_base, mpu_irq;
|
|
|
|
|
|
|
|
if ((mpu_config = sound_getconf(SNDCARD_MPU401))) {
|
|
|
|
mpu_base = mpu_config->io_base;
|
|
|
|
mpu_irq = mpu_config->irq;
|
|
|
|
} else {
|
|
|
|
mpu_base = mpu_irq = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
outb(0x201, 0xAF); /* ProSonic/Jazz16 wakeup */
|
|
|
|
DELAY(15000); /* wait at least 10 milliseconds */
|
|
|
|
outb(0x201, 0x50);
|
|
|
|
outb(0x201, (sbc_base & 0x70) | ((mpu_base & 0x30) >> 4));
|
|
|
|
|
|
|
|
if (sb_reset_dsp()) { /* OK. We have at least a SB */
|
|
|
|
|
|
|
|
/* Check the version number of ProSonic (I guess) */
|
|
|
|
|
|
|
|
if (!sb_dsp_command(0xFA))
|
|
|
|
return 1;
|
|
|
|
if (get_sb_byte() != 0x12)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (sb_dsp_command(0xFB) && /* set DMA-channels and Interrupts */
|
|
|
|
sb_dsp_command((dma_translat[JAZZ_DMA16]<<4)|dma_translat[dma8]) &&
|
|
|
|
sb_dsp_command((int_translat[mpu_irq]<<4)|int_translat[sbc_irq])) {
|
|
|
|
Jazz16_detected = 1;
|
|
|
|
if (mpu_base == 0)
|
|
|
|
printf("Jazz16: No MPU401 devices configured - MIDI port not initialized\n");
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef SM_WAVE
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mpu_base != 0)
|
|
|
|
if (initialize_smw(mpu_base))
|
|
|
|
Jazz16_detected = 2;
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_disable_midi();
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
return 1; /* There was at least a SB */
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0; /* No SB or ProSonic16 detected */
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#endif /* ifdef JAZZ16 */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_detect(struct address_info * hw_config)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
sbc_base = hw_config->io_base;
|
|
|
|
sbc_irq = hw_config->irq;
|
|
|
|
sb_osp = hw_config->osp;
|
|
|
|
|
|
|
|
|
|
|
|
if (sb_dsp_ok)
|
|
|
|
return 0; /* Already initialized */
|
|
|
|
dma8 = hw_config->dma;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
#ifdef JAZZ16
|
1997-10-31 17:25:35 +00:00
|
|
|
dma16 = JAZZ_DMA16;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!initialize_ProSonic16())
|
|
|
|
return 0;
|
1995-07-28 21:40:49 +00:00
|
|
|
#else
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!sb_reset_dsp())
|
|
|
|
return 0;
|
1996-11-02 10:41:28 +00:00
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 1; /* Detected */
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_AUDIO
|
1994-04-23 01:50:14 +00:00
|
|
|
static struct audio_operations sb_dsp_operations =
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
"SoundBlaster",
|
|
|
|
NOTHING_SPECIAL,
|
|
|
|
AFMT_U8, /* Just 8 bits. Poor old SB */
|
|
|
|
NULL,
|
|
|
|
sb_dsp_open,
|
|
|
|
sb_dsp_close,
|
|
|
|
sb_dsp_output_block,
|
|
|
|
sb_dsp_start_input,
|
|
|
|
sb_dsp_ioctl,
|
|
|
|
sb_dsp_prepare_for_input,
|
|
|
|
sb_dsp_prepare_for_output,
|
|
|
|
sb_dsp_reset,
|
|
|
|
sb_dsp_halt_xfer,
|
|
|
|
NULL, /* local_qlen */
|
|
|
|
NULL, /* copy_from_user */
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sb_dsp_trigger
|
1993-10-23 10:55:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
void
|
|
|
|
sb_dsp_init(struct address_info * hw_config)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int i;
|
|
|
|
char *fmt = NULL ;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_SBPRO
|
|
|
|
int mixer_type = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sb_osp = hw_config->osp;
|
|
|
|
sbc_major = sbc_minor = 0;
|
|
|
|
sb_dsp_command(DSP_CMD_GETVER); /* Get version */
|
|
|
|
|
|
|
|
for (i = 10000; i; i--) { /* perhaps wait longer on a fast machine ? */
|
|
|
|
if (inb(DSP_DATA_AVAIL) & 0x80) { /* wait for Data Ready */
|
|
|
|
if (sbc_major == 0)
|
|
|
|
sbc_major = inb(DSP_READ);
|
|
|
|
else {
|
|
|
|
sbc_minor = inb(DSP_READ);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
} else
|
|
|
|
DELAY(20);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major == 0) {
|
|
|
|
printf("\n\nFailed to get SB version (%x) - possible I/O conflict\n\n",
|
|
|
|
inb(DSP_DATA_AVAIL));
|
|
|
|
sbc_major = 1;
|
|
|
|
}
|
|
|
|
if (sbc_major == 2 || sbc_major == 3)
|
|
|
|
sb_duplex_midi = 1;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major == 4)
|
|
|
|
sb16 = 1;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major == 3 && sbc_minor == 1) {
|
|
|
|
int ess_major = 0, ess_minor = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Try to detect ESS chips.
|
|
|
|
*/
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_command(DSP_CMD_GETID); /* Return identification bytes. */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 1000; i; i--) {
|
|
|
|
if (inb(DSP_DATA_AVAIL) & 0x80) { /* wait for Data Ready */
|
|
|
|
if (ess_major == 0)
|
|
|
|
ess_major = inb(DSP_READ);
|
|
|
|
else {
|
|
|
|
ess_minor = inb(DSP_READ);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1994-04-23 01:50:14 +00:00
|
|
|
}
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80)
|
|
|
|
printf("Hmm... Could this be an ESS488 based card (rev %d)\n",
|
|
|
|
ess_minor & 0x0f);
|
|
|
|
else if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80)
|
|
|
|
printf("Hmm... Could this be an ESS688 based card (rev %d)\n",
|
|
|
|
ess_minor & 0x0f);
|
1994-04-23 01:50:14 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (snd_set_irq_handler(sbc_irq, sbintr, sb_osp) < 0)
|
|
|
|
printf("sb_dsp: Can't allocate IRQ\n");;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_SBPRO
|
|
|
|
if (sbc_major >= 3)
|
|
|
|
mixer_type = sb_mixer_init(sbc_major);
|
1995-03-05 22:11:57 +00:00
|
|
|
#else
|
1997-10-31 17:25:35 +00:00
|
|
|
if (sbc_major >= 3)
|
|
|
|
printf("\nNOTE! SB Pro support required with your soundcard!\n");
|
1995-03-05 22:11:57 +00:00
|
|
|
#endif
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_AUDIO
|
|
|
|
if (sbc_major >= 3) {
|
|
|
|
if (Jazz16_detected) {
|
|
|
|
if (Jazz16_detected == 2)
|
|
|
|
fmt = "SoundMan Wave %d.%d";
|
|
|
|
else
|
|
|
|
fmt = "MV Jazz16 %d.%d";
|
|
|
|
sb_dsp_operations.format_mask |= AFMT_S16_LE; /* 16 bits */
|
|
|
|
} else
|
|
|
|
#ifdef __SGNXPRO__
|
|
|
|
if (mixer_type == 2)
|
|
|
|
fmt = "Sound Galaxy NX Pro %d.%d" ;
|
|
|
|
else
|
|
|
|
#endif /* __SGNXPRO__ */
|
|
|
|
if (sbc_major == 4)
|
|
|
|
fmt = "SoundBlaster 16 %d.%d";
|
|
|
|
else
|
|
|
|
fmt = "SoundBlaster Pro %d.%d";
|
|
|
|
} else {
|
|
|
|
fmt = "SoundBlaster %d.%d" ;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(sb_dsp_operations.name, fmt, sbc_major, sbc_minor);
|
|
|
|
conf_printf(sb_dsp_operations.name, hw_config);
|
|
|
|
|
|
|
|
#if defined(CONFIG_SB16) && defined(CONFIG_SBPRO)
|
|
|
|
if (!sb16) /* There is a better driver for SB16 */
|
|
|
|
#endif /* CONFIG_SB16 && CONFIG_SBPRO */
|
|
|
|
if (num_audiodevs < MAX_AUDIO_DEV) {
|
|
|
|
audio_devs[my_dev = num_audiodevs++] = &sb_dsp_operations;
|
|
|
|
audio_devs[my_dev]->buffsize = DSP_BUFFSIZE;
|
|
|
|
dma8 = audio_devs[my_dev]->dmachan1 = hw_config->dma;
|
|
|
|
audio_devs[my_dev]->dmachan2 = -1;
|
|
|
|
#ifdef JAZZ16
|
|
|
|
/*
|
|
|
|
* Allocate 16 bit dma
|
|
|
|
*/
|
|
|
|
if (Jazz16_detected != 0)
|
|
|
|
if (dma16 != dma8) {
|
|
|
|
if (0) {
|
|
|
|
printf("Jazz16: Can't allocate 16 bit DMA channel\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* JAZZ16 */
|
|
|
|
} else
|
|
|
|
printf("SB: Too many DSP devices available\n");
|
|
|
|
#else
|
|
|
|
conf_printf("SoundBlaster (configured without audio support)", hw_config);
|
1993-10-23 10:55:52 +00:00
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#ifdef CONFIG_MIDI
|
|
|
|
if (!midi_disabled && !sb16) {
|
|
|
|
/*
|
|
|
|
* Midi don't work in the SB emulation mode of PAS,
|
|
|
|
* SB16 has better midi interface
|
|
|
|
*/
|
|
|
|
sb_midi_init(sbc_major);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MIDI */
|
|
|
|
sb_dsp_ok = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
sb_dsp_disable_midi(void)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_disabled = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
#endif
|