Home | History | Annotate | Line # | Download | only in isapnp
wss_isapnp.c revision 1.21.16.1
      1 /*	$NetBSD: wss_isapnp.c,v 1.21.16.1 2008/06/02 13:23:33 mjf 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: wss_isapnp.c,v 1.21.16.1 2008/06/02 13:23:33 mjf Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 #include <sys/errno.h>
     39 
     40 #include <sys/bus.h>
     41 
     42 #include <sys/audioio.h>
     43 #include <dev/audio_if.h>
     44 
     45 #include <dev/isa/isavar.h>
     46 #include <dev/isa/isadmavar.h>
     47 
     48 #include <dev/isapnp/isapnpreg.h>
     49 #include <dev/isapnp/isapnpvar.h>
     50 #include <dev/isapnp/isapnpdevs.h>
     51 
     52 #include <dev/isa/ad1848var.h>
     53 #include <dev/isa/madreg.h>
     54 #include <dev/isa/wssreg.h>
     55 #include <dev/isa/wssvar.h>
     56 #include <dev/isa/sbreg.h>
     57 
     58 int	wss_isapnp_match(struct device *, struct cfdata *, void *);
     59 void	wss_isapnp_attach(struct device *, struct device *, void *);
     60 
     61 CFATTACH_DECL(wss_isapnp, sizeof(struct wss_softc),
     62     wss_isapnp_match, wss_isapnp_attach, NULL, NULL);
     63 
     64 /*
     65  * Probe / attach routines.
     66  */
     67 
     68 /*
     69  * Probe for the WSS hardware.
     70  */
     71 int
     72 wss_isapnp_match(struct device *parent, struct cfdata *match,
     73     void *aux)
     74 {
     75 	int pri, variant;
     76 
     77 	pri = isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant);
     78 	if (pri && variant > 1)
     79 		pri = 0;
     80 	return pri;
     81 }
     82 
     83 /*
     84  * Attach hardware to driver, attach hardware driver to audio
     85  * pseudo-device driver.
     86  */
     87 void
     88 wss_isapnp_attach(struct device *parent, struct device *self,
     89     void *aux)
     90 {
     91 	struct wss_softc *sc;
     92 	struct ad1848_softc *ac;
     93 	struct isapnp_attach_args *ipa;
     94 	int variant;
     95 
     96 	sc = device_private(self);
     97 	ac = &sc->sc_ad1848.sc_ad1848;
     98 	ipa = aux;
     99 	printf("\n");
    100 
    101 	if (!isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant)) {
    102 		aprint_error_dev(self, "match failed?\n");
    103 		return;
    104 	}
    105 
    106 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    107 		aprint_error_dev(self, "error in region allocation\n");
    108 		return;
    109 	}
    110 
    111 	switch (variant) {
    112 	case 1:
    113 		/* We have to put the chip into `WSS mode'. */
    114 		{
    115 			bus_space_tag_t iot;
    116 			bus_space_handle_t ioh;
    117 
    118 			iot = ipa->ipa_iot;
    119 			ioh = ipa->ipa_io[0].h;
    120 
    121 			while (bus_space_read_1(iot, ioh,
    122 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
    123 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, 0x09);
    124 			while (bus_space_read_1(iot, ioh,
    125 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
    126 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, 0x00);
    127 			while (bus_space_read_1(iot, ioh,
    128 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
    129 
    130 			delay(1000);
    131 		}
    132 
    133 		sc->sc_iot = ipa->ipa_iot;
    134 		sc->sc_ioh = ipa->ipa_io[2].h;
    135 		break;
    136 
    137 	default:
    138 		sc->sc_iot = ipa->ipa_iot;
    139 		sc->sc_ioh = ipa->ipa_io[0].h;
    140 		break;
    141 	}
    142 
    143 	sc->mad_chip_type = MAD_NONE;
    144 
    145 	/* Set up AD1848 I/O handle. */
    146 	ac->sc_iot = sc->sc_iot;
    147 	ac->sc_ioh = sc->sc_ioh;
    148 	ac->mode = 2;
    149 
    150 	sc->sc_ad1848.sc_ic = ipa->ipa_ic;
    151 
    152 	sc->wss_ic = ipa->ipa_ic;
    153 	sc->wss_irq = ipa->ipa_irq[0].num;
    154 	sc->wss_playdrq = ipa->ipa_drq[0].num;
    155 	sc->wss_recdrq =
    156 	    ipa->ipa_ndrq > 1 ? ipa->ipa_drq[1].num : ipa->ipa_drq[0].num;
    157 
    158 	if (!ad1848_isa_probe(&sc->sc_ad1848)) {
    159 		aprint_error_dev(self, "ad1848_probe failed\n");
    160 		return;
    161 	}
    162 
    163 	aprint_error_dev(self, "%s %s", ipa->ipa_devident,
    164 	    ipa->ipa_devclass);
    165 
    166 	wssattach(sc);
    167 
    168 	/* set up OPL I/O handle for ISAPNP boards w/o MAD */
    169 	if (ipa->ipa_nio > 1 && sc->mad_chip_type == MAD_NONE) {
    170 		struct audio_attach_args arg;
    171 
    172 		sc->sc_opl_ioh = ipa->ipa_io[1].h;
    173 
    174 		arg.type = AUDIODEV_TYPE_OPL;
    175 		arg.hwif = 0;
    176 		arg.hdl = 0;
    177 		(void)config_found(&ac->sc_dev, &arg, audioprint);
    178 	}
    179 }
    180