Home | History | Annotate | Line # | Download | only in isa
wss_isa.c revision 1.16.2.3
      1  1.16.2.3     skrll /*	$NetBSD: wss_isa.c,v 1.16.2.3 2005/01/17 19:31:11 skrll Exp $	*/
      2       1.1  augustss 
      3       1.1  augustss /*
      4       1.1  augustss  * Copyright (c) 1994 John Brezak
      5       1.1  augustss  * Copyright (c) 1991-1993 Regents of the University of California.
      6       1.1  augustss  * All rights reserved.
      7       1.1  augustss  *
      8       1.1  augustss  * MAD support:
      9       1.1  augustss  * Copyright (c) 1996 Lennart Augustsson
     10       1.1  augustss  * Based on code which is
     11       1.1  augustss  * Copyright (c) 1994 Hannu Savolainen
     12       1.1  augustss  *
     13       1.1  augustss  * Redistribution and use in source and binary forms, with or without
     14       1.1  augustss  * modification, are permitted provided that the following conditions
     15       1.1  augustss  * are met:
     16       1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     17       1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     18       1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     19       1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     20       1.1  augustss  *    documentation and/or other materials provided with the distribution.
     21       1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     22       1.1  augustss  *    must display the following acknowledgement:
     23       1.1  augustss  *	This product includes software developed by the Computer Systems
     24       1.1  augustss  *	Engineering Group at Lawrence Berkeley Laboratory.
     25       1.1  augustss  * 4. Neither the name of the University nor of the Laboratory may be used
     26       1.1  augustss  *    to endorse or promote products derived from this software without
     27       1.1  augustss  *    specific prior written permission.
     28       1.1  augustss  *
     29       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30       1.1  augustss  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31       1.1  augustss  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32       1.1  augustss  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33       1.1  augustss  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34       1.1  augustss  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35       1.1  augustss  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36       1.1  augustss  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37       1.1  augustss  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38       1.1  augustss  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39       1.1  augustss  * SUCH DAMAGE.
     40       1.1  augustss  *
     41       1.1  augustss  */
     42      1.11     lukem 
     43      1.11     lukem #include <sys/cdefs.h>
     44  1.16.2.3     skrll __KERNEL_RCSID(0, "$NetBSD: wss_isa.c,v 1.16.2.3 2005/01/17 19:31:11 skrll Exp $");
     45      1.11     lukem 
     46       1.1  augustss #include <sys/param.h>
     47       1.1  augustss #include <sys/systm.h>
     48       1.5        pk #include <sys/device.h>
     49       1.1  augustss #include <sys/errno.h>
     50       1.1  augustss 
     51       1.1  augustss #include <machine/cpu.h>
     52       1.1  augustss #include <machine/intr.h>
     53       1.1  augustss #include <machine/bus.h>
     54       1.1  augustss 
     55       1.1  augustss #include <sys/audioio.h>
     56       1.1  augustss #include <dev/audio_if.h>
     57       1.1  augustss 
     58       1.1  augustss #include <dev/isa/isavar.h>
     59       1.1  augustss #include <dev/isa/isadmavar.h>
     60       1.1  augustss 
     61       1.1  augustss #include <dev/ic/ad1848reg.h>
     62       1.1  augustss #include <dev/isa/ad1848var.h>
     63       1.1  augustss #include <dev/isa/wssreg.h>
     64       1.1  augustss #include <dev/isa/wssvar.h>
     65       1.1  augustss #include <dev/isa/madreg.h>
     66       1.1  augustss 
     67       1.1  augustss #ifdef AUDIO_DEBUG
     68       1.1  augustss #define DPRINTF(x)	if (wssdebug) printf x
     69       1.1  augustss extern int	wssdebug;
     70       1.1  augustss #else
     71       1.1  augustss #define DPRINTF(x)
     72       1.1  augustss #endif
     73       1.1  augustss 
     74  1.16.2.3     skrll static int	wssfind(struct device *, struct wss_softc *, int,
     75  1.16.2.3     skrll 		    struct isa_attach_args *);
     76       1.1  augustss 
     77  1.16.2.3     skrll static void	madprobe(struct wss_softc *, int);
     78  1.16.2.3     skrll static void	madunmap(struct wss_softc *);
     79  1.16.2.3     skrll static int	detect_mad16(struct wss_softc *, int);
     80       1.1  augustss 
     81  1.16.2.3     skrll int		wss_isa_probe(struct device *, struct cfdata *, void *);
     82  1.16.2.3     skrll void		wss_isa_attach(struct device *, struct device *, void *);
     83       1.1  augustss 
     84      1.15   thorpej CFATTACH_DECL(wss_isa, sizeof(struct wss_softc),
     85      1.15   thorpej     wss_isa_probe, wss_isa_attach, NULL, NULL);
     86       1.1  augustss 
     87       1.1  augustss /*
     88       1.1  augustss  * Probe for the Microsoft Sound System hardware.
     89       1.1  augustss  */
     90       1.1  augustss int
     91  1.16.2.3     skrll wss_isa_probe(struct device *parent, struct cfdata *match, void *aux)
     92       1.1  augustss {
     93  1.16.2.3     skrll 	struct isa_attach_args *ia;
     94  1.16.2.3     skrll 	struct wss_softc probesc, *sc;
     95  1.16.2.3     skrll 	struct ad1848_softc *ac;
     96  1.16.2.3     skrll 
     97  1.16.2.3     skrll 	ia = aux;
     98  1.16.2.3     skrll 	sc = &probesc;
     99  1.16.2.3     skrll 	ac = (struct ad1848_softc *)&sc->sc_ad1848;
    100  1.16.2.3     skrll 	if (ia->ia_nio < 1)
    101  1.16.2.3     skrll 		return 0;
    102  1.16.2.3     skrll 	if (ia->ia_nirq < 1)
    103  1.16.2.3     skrll 		return 0;
    104  1.16.2.3     skrll 	if (ia->ia_ndrq < 1)
    105  1.16.2.3     skrll 		return 0;
    106  1.16.2.3     skrll 
    107  1.16.2.3     skrll 	if (ISA_DIRECT_CONFIG(ia))
    108  1.16.2.3     skrll 		return 0;
    109  1.16.2.3     skrll 
    110  1.16.2.3     skrll 	memset(sc, 0, sizeof *sc);
    111  1.16.2.3     skrll 	ac->sc_dev.dv_cfdata = match;
    112  1.16.2.3     skrll 	if (wssfind(parent, sc, 1, aux)) {
    113  1.16.2.3     skrll 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC);
    114  1.16.2.3     skrll 		ad1848_isa_unmap(&sc->sc_ad1848);
    115  1.16.2.3     skrll 		madunmap(sc);
    116  1.16.2.3     skrll 		return 1;
    117  1.16.2.3     skrll 	} else
    118  1.16.2.3     skrll 		/* Everything is already unmapped */
    119  1.16.2.3     skrll 		return 0;
    120       1.1  augustss }
    121       1.1  augustss 
    122       1.1  augustss static int
    123  1.16.2.3     skrll wssfind(struct device *parent, struct wss_softc *sc, int probing,
    124  1.16.2.3     skrll     struct isa_attach_args *ia)
    125       1.1  augustss {
    126  1.16.2.3     skrll 	static u_char interrupt_bits[12] = {
    127  1.16.2.3     skrll 		-1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20
    128  1.16.2.3     skrll 	};
    129  1.16.2.3     skrll 	static u_char dma_bits[4] = {1, 2, 0, 3};
    130  1.16.2.3     skrll 	struct ad1848_softc *ac;
    131  1.16.2.3     skrll 	int ndrq, playdrq, recdrq;
    132  1.16.2.3     skrll 
    133  1.16.2.3     skrll 	ac = &sc->sc_ad1848.sc_ad1848;
    134  1.16.2.3     skrll 	sc->sc_iot = ia->ia_iot;
    135  1.16.2.3     skrll 	if (ac->sc_dev.dv_cfdata->cf_flags & 1)
    136  1.16.2.3     skrll 		madprobe(sc, ia->ia_io[0].ir_addr);
    137  1.16.2.3     skrll 	else
    138  1.16.2.3     skrll 		sc->mad_chip_type = MAD_NONE;
    139       1.1  augustss 
    140       1.6   mycroft #if 0
    141  1.16.2.3     skrll 	if (!WSS_BASE_VALID(ia->ia_io[0].ir_addr)) {
    142  1.16.2.3     skrll 		DPRINTF(("wss: configured iobase %x invalid\n", ia->ia_iobase));
    143  1.16.2.3     skrll 		goto bad1;
    144  1.16.2.3     skrll 	}
    145       1.6   mycroft #endif
    146       1.1  augustss 
    147  1.16.2.3     skrll 	/* Map the ports upto the AD1848 port */
    148  1.16.2.3     skrll 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, WSS_CODEC,
    149  1.16.2.3     skrll 	    0, &sc->sc_ioh))
    150  1.16.2.3     skrll 		goto bad1;
    151  1.16.2.3     skrll 
    152  1.16.2.3     skrll 	ac->sc_iot = sc->sc_iot;
    153  1.16.2.3     skrll 
    154  1.16.2.3     skrll 	/* Is there an ad1848 chip at (WSS iobase + WSS_CODEC)? */
    155  1.16.2.3     skrll 	if (ad1848_isa_mapprobe(&sc->sc_ad1848,
    156  1.16.2.3     skrll 	    ia->ia_io[0].ir_addr + WSS_CODEC) == 0)
    157  1.16.2.3     skrll 		goto bad;
    158       1.1  augustss 
    159       1.6   mycroft #if 0
    160  1.16.2.3     skrll 	/* Setup WSS interrupt and DMA */
    161  1.16.2.3     skrll 	if (!WSS_DRQ_VALID(ia->ia_drq[0].ir_drq)) {
    162  1.16.2.3     skrll 		DPRINTF(("wss: configured DMA chan %d invalid\n",
    163  1.16.2.3     skrll 		    ia->ia_drq[0].ir_drq));
    164  1.16.2.3     skrll 		goto bad;
    165  1.16.2.3     skrll 	}
    166       1.6   mycroft #endif
    167  1.16.2.3     skrll 	sc->wss_playdrq = ia->ia_drq[0].ir_drq;
    168  1.16.2.3     skrll 	sc->wss_ic      = ia->ia_ic;
    169       1.1  augustss 
    170  1.16.2.3     skrll 	if (sc->wss_playdrq != ISA_UNKNOWN_DRQ &&
    171  1.16.2.3     skrll 	    !isa_drq_isfree(sc->wss_ic, sc->wss_playdrq))
    172  1.16.2.3     skrll 		goto bad;
    173       1.1  augustss 
    174       1.6   mycroft #if 0
    175  1.16.2.3     skrll 	if (!WSS_IRQ_VALID(ia->ia_irq[0].ir_irq)) {
    176  1.16.2.3     skrll 		DPRINTF(("wss: configured interrupt %d invalid\n",
    177  1.16.2.3     skrll 		    ia->ia_irq[0].ir_irq));
    178  1.16.2.3     skrll 		goto bad;
    179  1.16.2.3     skrll 	}
    180       1.6   mycroft #endif
    181       1.1  augustss 
    182  1.16.2.3     skrll 	sc->wss_irq = ia->ia_irq[0].ir_irq;
    183  1.16.2.3     skrll 
    184  1.16.2.3     skrll 	playdrq = ia->ia_drq[0].ir_drq;
    185  1.16.2.3     skrll 	if (ia->ia_ndrq > 1) {
    186  1.16.2.3     skrll 		ndrq = 2;
    187  1.16.2.3     skrll 		recdrq = ia->ia_drq[1].ir_drq;
    188  1.16.2.3     skrll 	} else {
    189  1.16.2.3     skrll 		ndrq = 1;
    190  1.16.2.3     skrll 		recdrq = ISA_UNKNOWN_DRQ;
    191  1.16.2.3     skrll 	}
    192  1.16.2.3     skrll 
    193  1.16.2.3     skrll 	if (ac->mode <= 1)
    194  1.16.2.3     skrll 		ndrq = 1;
    195  1.16.2.3     skrll 	sc->wss_recdrq =
    196  1.16.2.3     skrll 	    ac->mode > 1 && ndrq > 1 &&
    197  1.16.2.3     skrll 	    recdrq != ISA_UNKNOWN_DRQ ? recdrq : playdrq;
    198  1.16.2.3     skrll 	if (sc->wss_recdrq != sc->wss_playdrq && !isa_drq_isfree(sc->wss_ic,
    199  1.16.2.3     skrll 	    sc->wss_recdrq))
    200  1.16.2.3     skrll 		goto bad;
    201  1.16.2.3     skrll 
    202  1.16.2.3     skrll 	if (probing) {
    203  1.16.2.3     skrll 		ia->ia_nio = 1;
    204  1.16.2.3     skrll 		ia->ia_io[0].ir_size = WSS_NPORT;
    205  1.16.2.3     skrll 
    206  1.16.2.3     skrll 		ia->ia_nirq = 1;
    207  1.16.2.3     skrll 
    208  1.16.2.3     skrll 		ia->ia_ndrq = ndrq;
    209  1.16.2.3     skrll 		ia->ia_drq[0].ir_drq = playdrq;
    210  1.16.2.3     skrll 		if (ndrq > 1)
    211  1.16.2.3     skrll 			ia->ia_drq[1].ir_drq = recdrq;
    212      1.12   thorpej 
    213  1.16.2.3     skrll 		ia->ia_niomem = 0;
    214  1.16.2.3     skrll 	}
    215  1.16.2.3     skrll 
    216  1.16.2.3     skrll 	/* XXX recdrq */
    217  1.16.2.3     skrll 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, WSS_CONFIG,
    218  1.16.2.3     skrll 	    (interrupt_bits[ia->ia_irq[0].ir_irq] |
    219  1.16.2.3     skrll 		dma_bits[ia->ia_drq[0].ir_drq]));
    220       1.1  augustss 
    221  1.16.2.3     skrll 	return 1;
    222       1.1  augustss 
    223       1.1  augustss bad:
    224  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC);
    225       1.1  augustss bad1:
    226  1.16.2.3     skrll 	madunmap(sc);
    227  1.16.2.3     skrll 	return 0;
    228       1.1  augustss }
    229       1.1  augustss 
    230       1.1  augustss /*
    231       1.1  augustss  * Attach hardware to driver, attach hardware driver to audio
    232       1.1  augustss  * pseudo-device driver .
    233       1.1  augustss  */
    234       1.1  augustss void
    235  1.16.2.3     skrll wss_isa_attach(struct device *parent, struct device *self, void *aux)
    236       1.1  augustss {
    237  1.16.2.3     skrll 	struct wss_softc *sc;
    238  1.16.2.3     skrll 	struct ad1848_softc *ac;
    239  1.16.2.3     skrll 	struct isa_attach_args *ia;
    240  1.16.2.3     skrll 
    241  1.16.2.3     skrll 	sc = (struct wss_softc *)self;
    242  1.16.2.3     skrll 	ac = (struct ad1848_softc *)&sc->sc_ad1848;
    243  1.16.2.3     skrll 	ia = (struct isa_attach_args *)aux;
    244  1.16.2.3     skrll 	if (!wssfind(parent, sc, 0, ia)) {
    245  1.16.2.3     skrll 		printf("%s: wssfind failed\n", ac->sc_dev.dv_xname);
    246  1.16.2.3     skrll 		return;
    247  1.16.2.3     skrll 	}
    248       1.1  augustss 
    249  1.16.2.3     skrll 	sc->wss_ic = ia->ia_ic;
    250       1.1  augustss 
    251  1.16.2.3     skrll 	wssattach(sc);
    252       1.1  augustss }
    253       1.1  augustss 
    254       1.1  augustss /*
    255       1.1  augustss  * Copyright by Hannu Savolainen 1994
    256       1.1  augustss  *
    257       1.1  augustss  * Redistribution and use in source and binary forms, with or without
    258       1.1  augustss  * modification, are permitted provided that the following conditions are
    259       1.1  augustss  * met: 1. Redistributions of source code must retain the above copyright
    260       1.1  augustss  * notice, this list of conditions and the following disclaimer. 2.
    261       1.1  augustss  * Redistributions in binary form must reproduce the above copyright notice,
    262       1.1  augustss  * this list of conditions and the following disclaimer in the documentation
    263       1.1  augustss  * and/or other materials provided with the distribution.
    264       1.1  augustss  *
    265       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
    266       1.1  augustss  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    267       1.1  augustss  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    268       1.1  augustss  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
    269       1.1  augustss  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    270       1.1  augustss  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    271       1.1  augustss  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    272       1.1  augustss  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    273       1.1  augustss  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    274       1.1  augustss  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    275       1.1  augustss  * SUCH DAMAGE.
    276       1.1  augustss  *
    277       1.1  augustss  */
    278       1.1  augustss 
    279       1.1  augustss /*
    280       1.1  augustss  * Initialization code for OPTi MAD16 compatible audio chips. Including
    281       1.1  augustss  *
    282       1.1  augustss  *      OPTi 82C928     MAD16           (replaced by C929)
    283       1.1  augustss  *      OAK OTI-601D    Mozart
    284       1.1  augustss  *      OPTi 82C929     MAD16 Pro
    285       1.1  augustss  *	OPTi 82C931
    286       1.1  augustss  */
    287       1.1  augustss 
    288       1.1  augustss static int
    289  1.16.2.3     skrll detect_mad16(struct wss_softc *sc, int chip_type)
    290       1.1  augustss {
    291  1.16.2.3     skrll 	unsigned char tmp, tmp2;
    292       1.1  augustss 
    293  1.16.2.3     skrll 	sc->mad_chip_type = chip_type;
    294  1.16.2.3     skrll 	/*
    295  1.16.2.3     skrll 	 * Check that reading a register doesn't return bus float (0xff)
    296  1.16.2.3     skrll 	 * when the card is accessed using password. This may fail in case
    297  1.16.2.3     skrll 	 * the card is in low power mode. Normally at least the power saving mode
    298  1.16.2.3     skrll 	 * bit should be 0.
    299  1.16.2.3     skrll 	 */
    300  1.16.2.3     skrll 	if ((tmp = mad_read(sc, MC1_PORT)) == 0xff) {
    301  1.16.2.3     skrll 		DPRINTF(("MC1_PORT returned 0xff\n"));
    302  1.16.2.3     skrll 		return 0;
    303  1.16.2.3     skrll 	}
    304       1.1  augustss 
    305  1.16.2.3     skrll 	/*
    306  1.16.2.3     skrll 	 * Now check that the gate is closed on first I/O after writing
    307  1.16.2.3     skrll 	 * the password. (This is how a MAD16 compatible card works).
    308  1.16.2.3     skrll 	 */
    309  1.16.2.3     skrll 	if ((tmp2 = bus_space_read_1(sc->sc_iot, sc->mad_ioh, MC1_PORT)) == tmp) {
    310  1.16.2.3     skrll 		DPRINTF(("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
    311  1.16.2.3     skrll 		return 0;
    312  1.16.2.3     skrll 	}
    313       1.1  augustss 
    314  1.16.2.3     skrll 	mad_write(sc, MC1_PORT, tmp ^ 0x80);	/* Toggle a bit */
    315       1.1  augustss 
    316  1.16.2.3     skrll 	/* Compare the bit */
    317  1.16.2.3     skrll 	if ((tmp2 = mad_read(sc, MC1_PORT)) != (tmp ^ 0x80)) {
    318  1.16.2.3     skrll 		mad_write(sc, MC1_PORT, tmp);	/* Restore */
    319  1.16.2.3     skrll 		DPRINTF(("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
    320  1.16.2.3     skrll 		return 0;
    321  1.16.2.3     skrll 	}
    322       1.1  augustss 
    323  1.16.2.3     skrll 	mad_write(sc, MC1_PORT, tmp);	/* Restore */
    324  1.16.2.3     skrll 	return 1;
    325       1.1  augustss }
    326       1.1  augustss 
    327       1.1  augustss static void
    328  1.16.2.3     skrll madprobe(struct wss_softc *sc, int iobase)
    329       1.1  augustss {
    330  1.16.2.3     skrll 	static int valid_ports[M_WSS_NPORTS] =
    331  1.16.2.3     skrll 	    { M_WSS_PORT0, M_WSS_PORT1, M_WSS_PORT2, M_WSS_PORT3 };
    332  1.16.2.3     skrll 	int i;
    333  1.16.2.3     skrll 
    334  1.16.2.3     skrll 	/* Allocate bus space that the MAD chip wants */
    335  1.16.2.3     skrll 	if (bus_space_map(sc->sc_iot, MAD_BASE, MAD_NPORT, 0, &sc->mad_ioh))
    336  1.16.2.3     skrll 		goto bad0;
    337  1.16.2.3     skrll 	if (bus_space_map(sc->sc_iot, MAD_REG1, MAD_LEN1, 0, &sc->mad_ioh1))
    338  1.16.2.3     skrll 		goto bad1;
    339  1.16.2.3     skrll 	if (bus_space_map(sc->sc_iot, MAD_REG2, MAD_LEN2, 0, &sc->mad_ioh2))
    340  1.16.2.3     skrll 		goto bad2;
    341  1.16.2.3     skrll 	if (bus_space_map(sc->sc_iot, MAD_REG3, MAD_LEN3, 0, &sc->sc_opl_ioh))
    342  1.16.2.3     skrll 		goto bad3;
    343  1.16.2.3     skrll 
    344  1.16.2.3     skrll 	DPRINTF(("mad: Detect using password = 0xE2\n"));
    345  1.16.2.3     skrll 	if (!detect_mad16(sc, MAD_82C928)) {
    346  1.16.2.3     skrll 		/* No luck. Try different model */
    347  1.16.2.3     skrll 		DPRINTF(("mad: Detect using password = 0xE3\n"));
    348  1.16.2.3     skrll 		if (!detect_mad16(sc, MAD_82C929))
    349  1.16.2.3     skrll 			goto bad;
    350  1.16.2.3     skrll 		sc->mad_chip_type = MAD_82C929;
    351  1.16.2.3     skrll 		DPRINTF(("mad: 82C929 detected\n"));
    352       1.1  augustss 	} else {
    353  1.16.2.3     skrll 		sc->mad_chip_type = MAD_82C928;
    354  1.16.2.3     skrll 		if ((mad_read(sc, MC3_PORT) & 0x03) == 0x03) {
    355  1.16.2.3     skrll 			DPRINTF(("mad: Mozart detected\n"));
    356  1.16.2.3     skrll 			sc->mad_chip_type = MAD_OTI601D;
    357  1.16.2.3     skrll 		} else {
    358  1.16.2.3     skrll 			DPRINTF(("mad: 82C928 detected?\n"));
    359  1.16.2.3     skrll 			sc->mad_chip_type = MAD_82C928;
    360  1.16.2.3     skrll 		}
    361       1.1  augustss 	}
    362       1.1  augustss 
    363       1.1  augustss #ifdef AUDIO_DEBUG
    364  1.16.2.3     skrll 	if (wssdebug)
    365  1.16.2.3     skrll 		for (i = MC1_PORT; i <= MC7_PORT; i++)
    366  1.16.2.3     skrll 			printf("mad: port %03x = %02x\n", i, mad_read(sc, i));
    367       1.1  augustss #endif
    368       1.1  augustss 
    369  1.16.2.3     skrll 	/* Set the WSS address. */
    370  1.16.2.3     skrll 	for (i = 0; i < M_WSS_NPORTS; i++)
    371  1.16.2.3     skrll 		if (valid_ports[i] == iobase)
    372  1.16.2.3     skrll 			break;
    373  1.16.2.3     skrll 	if (i >= M_WSS_NPORTS) {		/* Not a valid port */
    374  1.16.2.3     skrll 		printf("mad: Bad WSS base address 0x%x\n", iobase);
    375  1.16.2.3     skrll 		goto bad;
    376  1.16.2.3     skrll 	}
    377  1.16.2.3     skrll 	sc->mad_ioindex = i;
    378  1.16.2.3     skrll 	/* enable WSS emulation at the I/O port, no joystick */
    379  1.16.2.3     skrll 	mad_write(sc, MC1_PORT, M_WSS_PORT_SELECT(i) | MC1_JOYDISABLE);
    380  1.16.2.3     skrll 	mad_write(sc, MC2_PORT, 0x03); /* ? */
    381  1.16.2.3     skrll 	mad_write(sc, MC3_PORT, 0xf0); /* Disable SB */
    382  1.16.2.3     skrll 	return;
    383       1.1  augustss 
    384       1.1  augustss bad:
    385  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->sc_opl_ioh, MAD_LEN3);
    386       1.1  augustss bad3:
    387  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->mad_ioh2, MAD_LEN2);
    388       1.1  augustss bad2:
    389  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->mad_ioh1, MAD_LEN1);
    390       1.1  augustss bad1:
    391  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->mad_ioh, MAD_NPORT);
    392       1.1  augustss bad0:
    393  1.16.2.3     skrll 	sc->mad_chip_type = MAD_NONE;
    394       1.1  augustss }
    395       1.1  augustss 
    396       1.1  augustss static void
    397  1.16.2.3     skrll madunmap(struct wss_softc *sc)
    398       1.1  augustss {
    399  1.16.2.3     skrll 
    400  1.16.2.3     skrll 	if (sc->mad_chip_type == MAD_NONE)
    401  1.16.2.3     skrll 		return;
    402  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->mad_ioh, MAD_NPORT);
    403  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->mad_ioh1, MAD_LEN1);
    404  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->mad_ioh2, MAD_LEN2);
    405  1.16.2.3     skrll 	bus_space_unmap(sc->sc_iot, sc->sc_opl_ioh, MAD_LEN3);
    406       1.1  augustss }
    407