1997-04-02 07:58:25 +04:00
|
|
|
/* $NetBSD: sb.c,v 1.44 1997/04/02 03:58:25 mycroft Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1994-01-09 22:35:00 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1991-1993 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the Computer Systems
|
|
|
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
|
|
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
1995-02-21 05:28:06 +03:00
|
|
|
*
|
1994-01-09 22:35:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/syslog.h>
|
1994-03-29 08:35:37 +04:00
|
|
|
#include <sys/device.h>
|
1995-02-21 05:28:06 +03:00
|
|
|
#include <sys/proc.h>
|
1994-01-09 22:35:00 +03:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
1996-05-13 03:51:23 +04:00
|
|
|
#include <machine/intr.h>
|
1994-01-09 22:35:00 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
|
1995-02-21 05:28:06 +03:00
|
|
|
#include <sys/audioio.h>
|
|
|
|
#include <dev/audio_if.h>
|
1995-07-19 23:58:09 +04:00
|
|
|
#include <dev/mulaw.h>
|
1995-02-21 05:28:06 +03:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
1994-01-09 22:35:00 +03:00
|
|
|
|
1995-04-17 19:48:20 +04:00
|
|
|
#include <dev/isa/sbreg.h>
|
1997-01-17 00:03:30 +03:00
|
|
|
#include <dev/isa/sbvar.h>
|
|
|
|
#include <dev/isa/sbdspvar.h>
|
1994-01-09 22:35:00 +03:00
|
|
|
|
|
|
|
struct sb_softc {
|
1995-02-21 05:28:06 +03:00
|
|
|
struct device sc_dev; /* base device */
|
|
|
|
struct isadev sc_id; /* ISA device */
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih; /* interrupt vectoring */
|
1994-03-29 08:35:37 +04:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
struct sbdsp_softc sc_sbdsp;
|
1994-01-09 22:35:00 +03:00
|
|
|
};
|
|
|
|
|
1996-03-17 03:43:52 +03:00
|
|
|
struct cfdriver sb_cd = {
|
|
|
|
NULL, "sb", DV_DULL
|
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_device sb_device = {
|
|
|
|
"SoundBlaster",
|
|
|
|
"x",
|
|
|
|
"sb"
|
1995-02-21 05:28:06 +03:00
|
|
|
};
|
1994-01-09 22:35:00 +03:00
|
|
|
|
1995-02-21 05:28:06 +03:00
|
|
|
int sbopen __P((dev_t, int));
|
1995-03-25 03:00:53 +03:00
|
|
|
int sb_getdev __P((void *, struct audio_device *));
|
1994-01-09 22:35:00 +03:00
|
|
|
|
1995-02-21 05:28:06 +03:00
|
|
|
/*
|
|
|
|
* Define our interface to the higher level audio driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct audio_hw_if sb_hw_if = {
|
|
|
|
sbopen,
|
|
|
|
sbdsp_close,
|
|
|
|
NULL,
|
|
|
|
sbdsp_set_in_sr,
|
|
|
|
sbdsp_get_in_sr,
|
|
|
|
sbdsp_set_out_sr,
|
|
|
|
sbdsp_get_out_sr,
|
|
|
|
sbdsp_query_encoding,
|
1997-03-20 09:48:48 +03:00
|
|
|
sbdsp_set_format,
|
1995-02-21 05:28:06 +03:00
|
|
|
sbdsp_get_encoding,
|
|
|
|
sbdsp_get_precision,
|
|
|
|
sbdsp_set_channels,
|
|
|
|
sbdsp_get_channels,
|
|
|
|
sbdsp_round_blocksize,
|
|
|
|
sbdsp_set_out_port,
|
|
|
|
sbdsp_get_out_port,
|
|
|
|
sbdsp_set_in_port,
|
|
|
|
sbdsp_get_in_port,
|
|
|
|
sbdsp_commit_settings,
|
1995-07-19 23:58:09 +04:00
|
|
|
mulaw_expand,
|
|
|
|
mulaw_compress,
|
1995-02-21 05:28:06 +03:00
|
|
|
sbdsp_dma_output,
|
|
|
|
sbdsp_dma_input,
|
|
|
|
sbdsp_haltdma,
|
|
|
|
sbdsp_haltdma,
|
|
|
|
sbdsp_contdma,
|
|
|
|
sbdsp_contdma,
|
|
|
|
sbdsp_speaker_ctl,
|
|
|
|
sb_getdev,
|
|
|
|
sbdsp_setfd,
|
|
|
|
sbdsp_mixer_set_port,
|
|
|
|
sbdsp_mixer_get_port,
|
|
|
|
sbdsp_mixer_query_devinfo,
|
|
|
|
0, /* not full-duplex */
|
|
|
|
0
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1994-01-09 22:35:00 +03:00
|
|
|
|
1995-02-21 05:28:06 +03:00
|
|
|
/*
|
|
|
|
* Probe / attach routines.
|
|
|
|
*/
|
|
|
|
|
1997-01-17 00:03:30 +03:00
|
|
|
|
1994-01-09 22:35:00 +03:00
|
|
|
int
|
1997-01-17 00:03:30 +03:00
|
|
|
sbmatch(sc)
|
|
|
|
struct sbdsp_softc *sc;
|
1994-01-09 22:35:00 +03:00
|
|
|
{
|
1997-03-20 14:03:10 +03:00
|
|
|
static u_char drq_conf[8] = {
|
|
|
|
0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
|
1995-11-10 08:01:05 +03:00
|
|
|
};
|
1997-01-17 00:03:30 +03:00
|
|
|
|
1995-03-08 21:27:35 +03:00
|
|
|
static u_char irq_conf[11] = {
|
1995-11-10 08:01:05 +03:00
|
|
|
-1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
|
1995-03-08 21:27:35 +03:00
|
|
|
};
|
1994-01-09 22:35:00 +03:00
|
|
|
|
1997-04-02 07:58:25 +04:00
|
|
|
if (sbdsp_probe(sc) == 0)
|
1994-03-29 08:35:37 +04:00
|
|
|
return 0;
|
1997-03-20 14:03:10 +03:00
|
|
|
|
1994-01-09 22:35:00 +03:00
|
|
|
/*
|
|
|
|
* Cannot auto-discover DMA channel.
|
|
|
|
*/
|
1995-07-07 06:19:48 +04:00
|
|
|
if (ISSBPROCLASS(sc)) {
|
1997-03-20 14:03:10 +03:00
|
|
|
if (!SBP_DRQ_VALID(sc->sc_drq8)) {
|
1997-01-17 00:03:30 +03:00
|
|
|
printf("%s: configured dma chan %d invalid\n",
|
1997-03-20 14:03:10 +03:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_drq8);
|
1995-02-21 05:28:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1997-03-20 14:03:10 +03:00
|
|
|
} else {
|
|
|
|
if (!SB_DRQ_VALID(sc->sc_drq8)) {
|
1997-01-17 00:03:30 +03:00
|
|
|
printf("%s: configured dma chan %d invalid\n",
|
1997-03-20 14:03:10 +03:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_drq8);
|
1995-02-21 05:28:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-03-20 14:03:10 +03:00
|
|
|
if (ISSB16CLASS(sc)) {
|
|
|
|
if (sc->sc_drq16 == -1)
|
|
|
|
sc->sc_drq16 = sc->sc_drq8;
|
|
|
|
if (!SB16_DRQ_VALID(sc->sc_drq16)) {
|
|
|
|
printf("%s: configured dma chan %d invalid\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_drq16);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sc->sc_drq16 = sc->sc_drq8;
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
#ifdef NEWCONFIG
|
1994-01-09 22:35:00 +03:00
|
|
|
/*
|
|
|
|
* If the IRQ wasn't compiled in, auto-detect it.
|
|
|
|
*/
|
1997-01-17 00:03:30 +03:00
|
|
|
if (sc->sc_irq == IRQUNK) {
|
|
|
|
sc->sc_irq = isa_discoverintr(sbforceintr, sc);
|
1995-07-07 06:19:48 +04:00
|
|
|
sbdsp_reset(sc);
|
|
|
|
if (ISSBPROCLASS(sc)) {
|
1997-01-17 00:03:30 +03:00
|
|
|
if (!SBP_IRQ_VALID(sc->sc_irq)) {
|
|
|
|
printf("%s: couldn't auto-detect interrupt\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1995-02-21 05:28:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1997-01-17 00:03:30 +03:00
|
|
|
if (!SB_IRQ_VALID(sc->sc_irq)) {
|
|
|
|
printf("%s: couldn't auto-detect interrupt\n");
|
|
|
|
sc->sc_dev.dv_xname);
|
1995-02-21 05:28:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1994-01-09 22:35:00 +03:00
|
|
|
}
|
1994-03-29 08:35:37 +04:00
|
|
|
} else
|
|
|
|
#endif
|
1995-07-07 06:19:48 +04:00
|
|
|
if (ISSBPROCLASS(sc)) {
|
1997-01-17 00:03:30 +03:00
|
|
|
if (!SBP_IRQ_VALID(sc->sc_irq)) {
|
|
|
|
printf("%s: configured irq %d invalid\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_irq);
|
1995-02-21 05:28:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1997-03-20 14:03:10 +03:00
|
|
|
} else {
|
1997-01-17 00:03:30 +03:00
|
|
|
if (!SB_IRQ_VALID(sc->sc_irq)) {
|
|
|
|
printf("%s: configured irq %d invalid\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_irq);
|
1995-02-21 05:28:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1994-01-09 22:35:00 +03:00
|
|
|
}
|
1997-03-20 14:03:10 +03:00
|
|
|
|
|
|
|
if (ISSB16CLASS(sc)) {
|
|
|
|
#if 0
|
|
|
|
printf("%s: old drq conf %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
sbdsp_mix_read(sc, SBP_SET_DRQ));
|
|
|
|
printf("%s: try drq conf %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
|
|
|
|
#endif
|
|
|
|
sbdsp_mix_write(sc, SBP_SET_DRQ,
|
|
|
|
drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
|
|
|
|
#if 0
|
|
|
|
printf("%s: new drq conf %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
sbdsp_mix_read(sc, SBP_SET_DRQ));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("%s: old irq conf %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
sbdsp_mix_read(sc, SBP_SET_IRQ));
|
|
|
|
printf("%s: try irq conf %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
irq_conf[sc->sc_irq]);
|
|
|
|
#endif
|
|
|
|
sbdsp_mix_write(sc, SBP_SET_IRQ,
|
|
|
|
irq_conf[sc->sc_irq]);
|
|
|
|
#if 0
|
|
|
|
printf("%s: new irq conf %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
sbdsp_mix_read(sc, SBP_SET_IRQ));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
return 1;
|
1994-01-09 22:35:00 +03:00
|
|
|
}
|
|
|
|
|
1997-01-17 00:03:30 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
sbattach(sc)
|
|
|
|
struct sbdsp_softc *sc;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc->sc_ih = isa_intr_establish(sc->sc_ic, sc->sc_irq, IST_EDGE,
|
|
|
|
IPL_AUDIO, sbdsp_intr, sc);
|
|
|
|
|
|
|
|
sbdsp_attach(sc);
|
|
|
|
|
|
|
|
if ((error = audio_hardware_attach(&sb_hw_if, sc)) != 0)
|
|
|
|
printf("%s: could not attach to audio device driver (%d)\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
#ifdef NEWCONFIG
|
1994-01-09 22:35:00 +03:00
|
|
|
void
|
1994-03-29 08:35:37 +04:00
|
|
|
sbforceintr(aux)
|
|
|
|
void *aux;
|
1994-01-09 22:35:00 +03:00
|
|
|
{
|
|
|
|
static char dmabuf;
|
1997-01-17 00:03:30 +03:00
|
|
|
struct sbdsp_softc *sc = aux;
|
1994-03-29 08:35:37 +04:00
|
|
|
|
1994-01-09 22:35:00 +03:00
|
|
|
/*
|
|
|
|
* Set up a DMA read of one byte.
|
|
|
|
* XXX Note that at this point we haven't called
|
|
|
|
* at_setup_dmachan(). This is okay because it just
|
|
|
|
* allocates a buffer in case it needs to make a copy,
|
|
|
|
* and it won't need to make a copy for a 1 byte buffer.
|
|
|
|
* (I think that calling at_setup_dmachan() should be optional;
|
|
|
|
* if you don't call it, it will be called the first time
|
|
|
|
* it is needed (and you pay the latency). Also, you might
|
|
|
|
* never need the buffer anyway.)
|
|
|
|
*/
|
1997-03-20 14:03:10 +03:00
|
|
|
at_dma(DMAMODE_READ, &dmabuf, 1, sc->sc_drq8);
|
1997-01-17 00:03:30 +03:00
|
|
|
if (sbdsp_wdsp(sc, SB_DSP_RDMA) == 0) {
|
|
|
|
(void)sbdsp_wdsp(sc, 0);
|
|
|
|
(void)sbdsp_wdsp(sc, 0);
|
1994-01-09 22:35:00 +03:00
|
|
|
}
|
|
|
|
}
|
1994-03-29 08:35:37 +04:00
|
|
|
#endif
|
1994-01-09 22:35:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-02-21 05:28:06 +03:00
|
|
|
* Various routines to interface to higher level audio driver
|
1994-01-09 22:35:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1995-02-21 05:28:06 +03:00
|
|
|
sbopen(dev, flags)
|
|
|
|
dev_t dev;
|
|
|
|
int flags;
|
1994-01-09 22:35:00 +03:00
|
|
|
{
|
1995-07-07 06:19:48 +04:00
|
|
|
struct sbdsp_softc *sc;
|
1995-02-21 05:28:06 +03:00
|
|
|
int unit = AUDIOUNIT(dev);
|
|
|
|
|
1996-03-17 03:43:52 +03:00
|
|
|
if (unit >= sb_cd.cd_ndevs)
|
1995-02-21 05:28:06 +03:00
|
|
|
return ENODEV;
|
|
|
|
|
1996-03-17 03:43:52 +03:00
|
|
|
sc = sb_cd.cd_devs[unit];
|
1995-02-21 05:28:06 +03:00
|
|
|
if (!sc)
|
|
|
|
return ENXIO;
|
|
|
|
|
1995-07-07 06:19:48 +04:00
|
|
|
return sbdsp_open(sc, dev, flags);
|
1994-01-09 22:35:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-02-21 05:28:06 +03:00
|
|
|
sb_getdev(addr, retp)
|
1995-03-25 03:00:53 +03:00
|
|
|
void *addr;
|
1995-02-21 05:28:06 +03:00
|
|
|
struct audio_device *retp;
|
1994-01-09 22:35:00 +03:00
|
|
|
{
|
1996-03-16 07:00:09 +03:00
|
|
|
struct sbdsp_softc *sc = addr;
|
|
|
|
|
|
|
|
if (sc->sc_model & MODEL_JAZZ16)
|
|
|
|
strncpy(retp->name, "MV Jazz16", sizeof(retp->name));
|
|
|
|
else
|
|
|
|
strncpy(retp->name, "SoundBlaster", sizeof(retp->name));
|
1997-03-12 10:06:19 +03:00
|
|
|
sprintf(retp->version, "%d.%02d",
|
1996-03-16 07:00:09 +03:00
|
|
|
SBVER_MAJOR(sc->sc_model),
|
|
|
|
SBVER_MINOR(sc->sc_model));
|
|
|
|
strncpy(retp->config, "sb", sizeof(retp->config));
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
return 0;
|
1994-01-09 22:35:00 +03:00
|
|
|
}
|