Home | History | Annotate | Line # | Download | only in isapnp
wss_isapnp.c revision 1.20
      1 /*	$NetBSD: wss_isapnp.c,v 1.20 2006/11/16 01:33:05 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (augustss (at) NetBSD.org).
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: wss_isapnp.c,v 1.20 2006/11/16 01:33:05 christos Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 #include <sys/errno.h>
     46 
     47 #include <machine/bus.h>
     48 
     49 #include <sys/audioio.h>
     50 #include <dev/audio_if.h>
     51 
     52 #include <dev/isa/isavar.h>
     53 #include <dev/isa/isadmavar.h>
     54 
     55 #include <dev/isapnp/isapnpreg.h>
     56 #include <dev/isapnp/isapnpvar.h>
     57 #include <dev/isapnp/isapnpdevs.h>
     58 
     59 #include <dev/isa/ad1848var.h>
     60 #include <dev/isa/madreg.h>
     61 #include <dev/isa/wssreg.h>
     62 #include <dev/isa/wssvar.h>
     63 #include <dev/isa/sbreg.h>
     64 
     65 int	wss_isapnp_match(struct device *, struct cfdata *, void *);
     66 void	wss_isapnp_attach(struct device *, struct device *, void *);
     67 
     68 CFATTACH_DECL(wss_isapnp, sizeof(struct wss_softc),
     69     wss_isapnp_match, wss_isapnp_attach, NULL, NULL);
     70 
     71 /*
     72  * Probe / attach routines.
     73  */
     74 
     75 /*
     76  * Probe for the WSS hardware.
     77  */
     78 int
     79 wss_isapnp_match(struct device *parent, struct cfdata *match,
     80     void *aux)
     81 {
     82 	int pri, variant;
     83 
     84 	pri = isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant);
     85 	if (pri && variant > 1)
     86 		pri = 0;
     87 	return pri;
     88 }
     89 
     90 /*
     91  * Attach hardware to driver, attach hardware driver to audio
     92  * pseudo-device driver.
     93  */
     94 void
     95 wss_isapnp_attach(struct device *parent, struct device *self,
     96     void *aux)
     97 {
     98 	struct wss_softc *sc;
     99 	struct ad1848_softc *ac;
    100 	struct isapnp_attach_args *ipa;
    101 	int variant;
    102 
    103 	sc = device_private(self);
    104 	ac = &sc->sc_ad1848.sc_ad1848;
    105 	ipa = aux;
    106 	printf("\n");
    107 
    108 	if (!isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant)) {
    109 		printf("%s: match failed?\n", self->dv_xname);
    110 		return;
    111 	}
    112 
    113 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    114 		printf("%s: error in region allocation\n", self->dv_xname);
    115 		return;
    116 	}
    117 
    118 	switch (variant) {
    119 	case 1:
    120 		/* We have to put the chip into `WSS mode'. */
    121 		{
    122 			bus_space_tag_t iot;
    123 			bus_space_handle_t ioh;
    124 
    125 			iot = ipa->ipa_iot;
    126 			ioh = ipa->ipa_io[0].h;
    127 
    128 			while (bus_space_read_1(iot, ioh,
    129 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
    130 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, 0x09);
    131 			while (bus_space_read_1(iot, ioh,
    132 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
    133 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, 0x00);
    134 			while (bus_space_read_1(iot, ioh,
    135 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
    136 
    137 			delay(1000);
    138 		}
    139 
    140 		sc->sc_iot = ipa->ipa_iot;
    141 		sc->sc_ioh = ipa->ipa_io[2].h;
    142 		break;
    143 
    144 	default:
    145 		sc->sc_iot = ipa->ipa_iot;
    146 		sc->sc_ioh = ipa->ipa_io[0].h;
    147 		break;
    148 	}
    149 
    150 	sc->mad_chip_type = MAD_NONE;
    151 
    152 	/* Set up AD1848 I/O handle. */
    153 	ac->sc_iot = sc->sc_iot;
    154 	ac->sc_ioh = sc->sc_ioh;
    155 	ac->mode = 2;
    156 
    157 	sc->sc_ad1848.sc_ic = ipa->ipa_ic;
    158 
    159 	sc->wss_ic = ipa->ipa_ic;
    160 	sc->wss_irq = ipa->ipa_irq[0].num;
    161 	sc->wss_playdrq = ipa->ipa_drq[0].num;
    162 	sc->wss_recdrq =
    163 	    ipa->ipa_ndrq > 1 ? ipa->ipa_drq[1].num : ipa->ipa_drq[0].num;
    164 
    165 	if (!ad1848_isa_probe(&sc->sc_ad1848)) {
    166 		printf("%s: ad1848_probe failed\n", self->dv_xname);
    167 		return;
    168 	}
    169 
    170 	printf("%s: %s %s", self->dv_xname, ipa->ipa_devident,
    171 	    ipa->ipa_devclass);
    172 
    173 	wssattach(sc);
    174 
    175 	/* set up OPL I/O handle for ISAPNP boards w/o MAD */
    176 	if (ipa->ipa_nio > 1 && sc->mad_chip_type == MAD_NONE) {
    177 		struct audio_attach_args arg;
    178 
    179 		sc->sc_opl_ioh = ipa->ipa_io[1].h;
    180 
    181 		arg.type = AUDIODEV_TYPE_OPL;
    182 		arg.hwif = 0;
    183 		arg.hdl = 0;
    184 		(void)config_found(&ac->sc_dev, &arg, audioprint);
    185 	}
    186 }
    187