Home | History | Annotate | Line # | Download | only in isapnp
gus_isapnp.c revision 1.20
      1 /*	$NetBSD: gus_isapnp.c,v 1.20 2002/10/02 16:33:58 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author: Kari Mettinen
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *        This product includes software developed by the NetBSD
     20  *        Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: gus_isapnp.c,v 1.20 2002/10/02 16:33:58 thorpej Exp $");
     40 
     41 #include "guspnp.h"
     42 #if NGUSPNP > 0
     43 
     44 #include <sys/param.h>
     45 #include <sys/fcntl.h>
     46 #include <sys/vnode.h>
     47 #include <sys/poll.h>
     48 #include <sys/malloc.h>
     49 #include <sys/select.h>
     50 #include <sys/systm.h>
     51 #include <sys/errno.h>
     52 #include <sys/ioctl.h>
     53 #include <sys/syslog.h>
     54 #include <sys/device.h>
     55 #include <sys/proc.h>
     56 
     57 #include <machine/bus.h>
     58 
     59 #include <sys/audioio.h>
     60 #include <dev/audio_if.h>
     61 #include <dev/audiovar.h>
     62 #include <dev/mulaw.h>
     63 
     64 #include <dev/isa/isavar.h>
     65 #include <dev/isa/isadmavar.h>
     66 #include <i386/isa/icu.h>
     67 
     68 #include <dev/isapnp/isapnpreg.h>
     69 #include <dev/isapnp/isapnpvar.h>
     70 #include <dev/isapnp/isapnpdevs.h>
     71 
     72 
     73 #include <dev/ic/interwavevar.h>
     74 #include <dev/ic/interwavereg.h>
     75 
     76 
     77 int	gus_isapnp_match __P((struct device *, struct cfdata *, void *));
     78 void	gus_isapnp_attach __P((struct device *, struct device *, void *));
     79 static int     gus_isapnp_open __P((void *, int));
     80 
     81 static struct audio_hw_if guspnp_hw_if = {
     82 	gus_isapnp_open,
     83 	iwclose,
     84 	NULL,
     85 
     86 	iw_query_encoding,
     87 	iw_set_params,
     88 
     89 	iw_round_blocksize,
     90 
     91 	iw_commit_settings,
     92 
     93 	iw_init_output,
     94 	iw_init_input,
     95 	iw_start_output,
     96 	iw_start_input,
     97 	iw_halt_output,
     98 	iw_halt_input,
     99 
    100 	iw_speaker_ctl,
    101 
    102 	iw_getdev,
    103 	iw_setfd,
    104 	iw_set_port,
    105 	iw_get_port,
    106 	iw_query_devinfo,
    107 	iw_malloc,
    108 	iw_free,
    109 	iw_round_buffersize,
    110 	iw_mappage,
    111 	iw_get_props,
    112 	NULL,
    113 	NULL,
    114 	NULL,
    115 };
    116 
    117 
    118 
    119 CFATTACH_DECL(guspnp, sizeof(struct iw_softc),
    120     gus_isapnp_match, gus_isapnp_attach, NULL, NULL);
    121 
    122 extern struct cfdriver guspnp_cd;
    123 
    124 /*
    125  * Probe / attach routines.
    126  */
    127 
    128 /*
    129  * Probe for the guspnp hardware.
    130  *
    131  * The thing has 5 separate devices on the card
    132  */
    133 
    134 static int gus_0 = 1;		/* XXX what's this */
    135 
    136 int
    137 gus_isapnp_match(parent, match, aux)
    138 	struct device *parent;
    139 	struct cfdata *match;
    140 	void *aux;
    141 {
    142 	int pri, variant;
    143 
    144 	pri = isapnp_devmatch(aux, &isapnp_gus_devinfo, &variant);
    145 	if (pri && variant > 0)
    146 		pri = 0;
    147 	return (pri);
    148 }
    149 
    150 
    151 
    152 /*
    153  * Attach hardware to driver, attach hardware driver to audio
    154  * pseudo-device driver.
    155  */
    156 
    157 void
    158 gus_isapnp_attach(parent, self, aux)
    159 	struct device *parent, *self;
    160 	void *aux;
    161 {
    162         struct iw_softc *sc = (struct iw_softc *)self;
    163 	struct isapnp_attach_args *ipa = aux;
    164 
    165 	printf("\n");
    166 
    167 	if (!gus_0)
    168 		return;
    169 	gus_0 = 0;
    170 
    171 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    172 		printf("%s: error in region allocation\n",
    173 		       sc->sc_dev.dv_xname);
    174 		return;
    175 	}
    176 
    177 	sc->sc_iot = ipa->ipa_iot;
    178 
    179 	/* handle is the region base */
    180 
    181 	sc->dir_h = 0; /* XXXXX */
    182 	sc->p2xr = 0;
    183 	sc->p2xr_h = ipa->ipa_io[0].h;
    184 	sc->sc_p2xr_ic = ipa->ipa_ic;
    185 	sc->p3xr = 0;
    186 	sc->p3xr_h = ipa->ipa_io[1].h;
    187 	sc->sc_p3xr_ic = ipa->ipa_ic;
    188 	sc->codec_index = 0;
    189 	sc->codec_index_h = ipa->ipa_io[2].h;
    190 	sc->sc_irq = ipa->ipa_irq[0].num;
    191 	sc->sc_recdrq = ipa->ipa_drq[0].num;
    192 	sc->sc_playdrq = ipa->ipa_drq[1].num;
    193 
    194 	sc->sc_ic = ipa->ipa_ic;
    195 
    196         /*
    197          * Create our DMA maps.
    198          */
    199         if (sc->sc_playdrq != -1) {
    200 		sc->sc_play_maxsize = isa_dmamaxsize(sc->sc_ic,
    201 		    sc->sc_playdrq);
    202                 if (isa_dmamap_create(sc->sc_ic, sc->sc_playdrq,
    203                     sc->sc_play_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    204                         printf("%s: can't create map for drq %d\n",
    205                             sc->sc_dev.dv_xname, sc->sc_playdrq);
    206                         return;
    207 		      }
    208 	      }
    209         if (sc->sc_recdrq != -1) {
    210 		sc->sc_rec_maxsize = isa_dmamaxsize(sc->sc_ic,
    211 		    sc->sc_recdrq);
    212                 if (isa_dmamap_create(sc->sc_ic, sc->sc_recdrq,
    213                     sc->sc_rec_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    214                         printf("%s: can't create map for drq %d\n",
    215                             sc->sc_dev.dv_xname, sc->sc_recdrq);
    216                         return;
    217 		      }
    218 	      }
    219 
    220         /*
    221          * isapnp is a child if isa, and we need isa for the dma
    222          * routines.
    223          */
    224 	sc->iw_cd = &guspnp_cd;
    225 	sc->iw_hw_if = &guspnp_hw_if;
    226 
    227 	printf("%s: %s %s", sc->sc_dev.dv_xname, ipa->ipa_devident,
    228 	       ipa->ipa_devclass);
    229 
    230 	iwattach(sc);
    231 }
    232 
    233 static
    234 int
    235 gus_isapnp_open(addr, flags)
    236      void *addr;
    237      int flags;
    238 {
    239 	/* open hardware */
    240 	struct iw_softc *sc = (struct iw_softc *)addr;
    241 
    242 	if (!sc)
    243 		return ENXIO;
    244 
    245 	return iwopen(sc,flags);
    246 }
    247 
    248 #endif /* NGUSPNP */
    249