/*
* 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.
*
*/
/*
* jfw 7/13/97 - The soundblaster code requires the generic bus-space
* structures to be set up properly. Rather than go to the effort of making
* code for a dead line fully generic, properly set up the SB structures and
* leave the rest x86/ISA/default-configuration specific. If you have a
* REAL computer, go buy a REAL sound card.
*/
/*
* Todo:
* - look at other PAS drivers (for PAS native support)
* - use common sb.c once emulation is setup
*/
/*
* jfw 6/21/98 - WARNING: the PAS native IO ports are scattered all around
* IO port space (0x0388, 0x738B, 0xBF88, 0x2789, ...) which will make proper
* reservation a real pain, so I'm not going to do it (while fixing the
* current reservation code to "work"). As a sanity check, I reserve the
* 0x0388 base address, but you probably shouldn't even think of trying this
* driver unless you're certain you have the hardware installed and it doesn't
* conflict with other hardware...
*/
#ifdef AUDIO_DEBUG
#define DPRINTF(x) if (pasdebug) printf x
int pasdebug = 0;
#else
#define DPRINTF(x)
#endif
/*
* Software state, per SoundBlaster card.
* The soundblaster has multiple functionality, which we must demultiplex.
* One approach is to have one major device number for the soundblaster card,
* and use different minor numbers to indicate which hardware function
* we want. This would make for one large driver. Instead our approach
* is to partition the design into a set of drivers that share an underlying
* piece of hardware. Most things are hard to share, for example, the audio
* and midi ports. For audio, we might want to mix two processes' signals,
* and for midi we might want to merge streams (this is hard due to
* running status). Moreover, we should be able to re-use the high-level
* modules with other kinds of hardware. In this module, we only handle the
* most basic communications with the sb card.
*/
struct pas_softc {
struct sbdsp_softc sc_sbdsp; /* base device, &c. */
bus_space_handle_t pas_port_handle; /* the pas-specific port */
/*
* Probe for the soundblaster hardware.
*/
static int
pasfind(cfdata_t match, struct pas_softc *sc,
struct isa_attach_args *ia, int probing)
{
int iobase;
u_char id, t;
int rc;
rc = 0; /* failure */
/* ensure we can set this up as a sound blaster */
if (!SB_BASE_VALID(ia->ia_io[0].ir_addr)) {
printf("pas: configured SB iobase 0x%x invalid\n",
ia->ia_io[0].ir_addr);
return 0;
}
if (bus_space_map(ia->ia_iot, PAS_DEFAULT_BASE, 1, 0,
&sc->pas_port_handle)) {
printf("pas: can't map base register %x in probe\n",
PAS_DEFAULT_BASE);
return 0;
}
/*
* WARNING: Setting an option like W:1 or so that disables
* warm boot reset of the card will screw up this detect code
* something fierce. Adding code to handle this means possibly
* interfering with other cards on the bus if you have something
* on base port 0x388. SO be forewarned.
*/
/* Talk to first board */
outb(MASTER_DECODE, 0xbc);
/* Set base address */
#if 0
/* XXX Need to setup pseudo device */
/* XXX What are good io addrs ? */
if (iobase != PAS_DEFAULT_BASE) {
printf("pas: configured iobase %d invalid\n", iobase);
return 0;
}
#else
/* Start out talking to native PAS */
iobase = PAS_DEFAULT_BASE;
#endif
outb(MASTER_DECODE, iobase >> 2);
/* One wait-state */
paswrite(1, WAIT_STATE);
id = pasread(INTERRUPT_MASK);
if (id == 0xff || id == 0xfe) {
/* sanity */
DPRINTF(("pas: bogus card id\n"));
goto unmap1;
}
/*
* We probably have a PAS-series board, now check for a
* PAS2-series board by trying to change the board revision
* bits. PAS2-series hardware won't let you do this because
* the bits are read-only.
*/
t = id ^ 0xe0;
paswrite(t, INTERRUPT_MASK);
t = inb(INTERRUPT_MASK);
paswrite(id, INTERRUPT_MASK);
if (t != id) {
/* Not a PAS2 */
printf("pas: detected card but PAS2 test failed\n");
goto unmap1;
}
/*XXX*/
t = pasread(OPERATION_MODE_1) & 0xf;
sc->model = O_M_1_to_card[t];
if (sc->model != 0) {
sc->rev = pasread(BOARD_REV_ID);
} else {
DPRINTF(("pas: bogus model id\n"));
goto unmap1;
}
if (sc->model >= 0) {
if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
printf("pas: sb emulation requires known irq\n");
goto unmap1;
}
pasconf(sc->model, ia->ia_io[0].ir_addr,
ia->ia_irq[0].ir_irq, 1);
} else {
DPRINTF(("pas: could not probe pas\n"));
goto unmap1;
}
/* Now a SoundBlaster, so set up proper bus-space hooks
* appropriately
*/
/* Map i/o space [we map 24 ports which is the max of the sb and pro */
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
SBP_NPORT, 0, &sc->sc_sbdsp.sc_ioh)) {
printf("pas: can't map i/o space 0x%x/%d in probe\n",
ia->ia_io[0].ir_addr, SBP_NPORT);
goto unmap1;
}