Home | History | Annotate | Line # | Download | only in isapnp
gus_isapnp.c revision 1.16
      1 /*	$NetBSD: gus_isapnp.c,v 1.16 2001/10/03 00:04:51 augustss 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 "guspnp.h"
     39 #if NGUSPNP > 0
     40 
     41 #include <sys/param.h>
     42 #include <sys/fcntl.h>
     43 #include <sys/vnode.h>
     44 #include <sys/poll.h>
     45 #include <sys/malloc.h>
     46 #include <sys/select.h>
     47 #include <sys/systm.h>
     48 #include <sys/errno.h>
     49 #include <sys/ioctl.h>
     50 #include <sys/syslog.h>
     51 #include <sys/device.h>
     52 #include <sys/proc.h>
     53 
     54 #include <machine/bus.h>
     55 
     56 #include <sys/audioio.h>
     57 #include <dev/audio_if.h>
     58 #include <dev/audiovar.h>
     59 #include <dev/mulaw.h>
     60 
     61 #include <dev/isa/isavar.h>
     62 #include <dev/isa/isadmavar.h>
     63 #include <i386/isa/icu.h>
     64 
     65 #include <dev/isapnp/isapnpreg.h>
     66 #include <dev/isapnp/isapnpvar.h>
     67 #include <dev/isapnp/isapnpdevs.h>
     68 
     69 
     70 #include <dev/ic/interwavevar.h>
     71 #include <dev/ic/interwavereg.h>
     72 
     73 
     74 int	gus_isapnp_match __P((struct device *, struct cfdata *, void *));
     75 void	gus_isapnp_attach __P((struct device *, struct device *, void *));
     76 static int     gus_isapnp_open __P((void *, int));
     77 
     78 static struct audio_hw_if guspnp_hw_if = {
     79 	gus_isapnp_open,
     80 	iwclose,
     81 	NULL,
     82 
     83 	iw_query_encoding,
     84 	iw_set_params,
     85 
     86 	iw_round_blocksize,
     87 
     88 	iw_commit_settings,
     89 
     90 	iw_init_output,
     91 	iw_init_input,
     92 	iw_start_output,
     93 	iw_start_input,
     94 	iw_halt_output,
     95 	iw_halt_input,
     96 
     97 	iw_speaker_ctl,
     98 
     99 	iw_getdev,
    100 	iw_setfd,
    101 	iw_set_port,
    102 	iw_get_port,
    103 	iw_query_devinfo,
    104 	iw_malloc,
    105 	iw_free,
    106 	iw_round_buffersize,
    107 	iw_mappage,
    108 	iw_get_props,
    109 	NULL,
    110 	NULL,
    111 	NULL,
    112 };
    113 
    114 
    115 
    116 struct cfattach guspnp_ca = {
    117 	sizeof(struct iw_softc), gus_isapnp_match, gus_isapnp_attach
    118 };
    119 
    120 extern struct cfdriver guspnp_cd;
    121 
    122 /*
    123  * Probe / attach routines.
    124  */
    125 
    126 /*
    127  * Probe for the guspnp hardware.
    128  *
    129  * The thing has 5 separate devices on the card
    130  */
    131 
    132 static int gus_0 = 1;		/* XXX what's this */
    133 
    134 int
    135 gus_isapnp_match(parent, match, aux)
    136 	struct device *parent;
    137 	struct cfdata *match;
    138 	void *aux;
    139 {
    140 	int pri, variant;
    141 
    142 	pri = isapnp_devmatch(aux, &isapnp_gus_devinfo, &variant);
    143 	if (pri && variant > 0)
    144 		pri = 0;
    145 	return (pri);
    146 }
    147 
    148 
    149 
    150 /*
    151  * Attach hardware to driver, attach hardware driver to audio
    152  * pseudo-device driver.
    153  */
    154 
    155 void
    156 gus_isapnp_attach(parent, self, aux)
    157 	struct device *parent, *self;
    158 	void *aux;
    159 {
    160         struct iw_softc *sc = (struct iw_softc *)self;
    161 	struct isapnp_attach_args *ipa = aux;
    162 
    163 	printf("\n");
    164 
    165 	if (!gus_0)
    166 		return;
    167 	gus_0 = 0;
    168 
    169 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    170 		printf("%s: error in region allocation\n",
    171 		       sc->sc_dev.dv_xname);
    172 		return;
    173 	}
    174 
    175 	sc->sc_iot = ipa->ipa_iot;
    176 
    177 	/* handle is the region base */
    178 
    179 	sc->dir_h = 0; /* XXXXX */
    180 	sc->p2xr = 0;
    181 	sc->p2xr_h = ipa->ipa_io[0].h;
    182 	sc->sc_p2xr_ic = ipa->ipa_ic;
    183 	sc->p3xr = 0;
    184 	sc->p3xr_h = ipa->ipa_io[1].h;
    185 	sc->sc_p3xr_ic = ipa->ipa_ic;
    186 	sc->codec_index = 0;
    187 	sc->codec_index_h = ipa->ipa_io[2].h;
    188 	sc->sc_irq = ipa->ipa_irq[0].num;
    189 	sc->sc_recdrq = ipa->ipa_drq[0].num;
    190 	sc->sc_playdrq = ipa->ipa_drq[1].num;
    191 
    192 	sc->sc_ic = ipa->ipa_ic;
    193 
    194         /*
    195          * Create our DMA maps.
    196          */
    197         if (sc->sc_playdrq != -1) {
    198 		sc->sc_play_maxsize = isa_dmamaxsize(sc->sc_ic,
    199 		    sc->sc_playdrq);
    200                 if (isa_dmamap_create(sc->sc_ic, sc->sc_playdrq,
    201                     sc->sc_play_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    202                         printf("%s: can't create map for drq %d\n",
    203                             sc->sc_dev.dv_xname, sc->sc_playdrq);
    204                         return;
    205 		      }
    206 	      }
    207         if (sc->sc_recdrq != -1) {
    208 		sc->sc_rec_maxsize = isa_dmamaxsize(sc->sc_ic,
    209 		    sc->sc_recdrq);
    210                 if (isa_dmamap_create(sc->sc_ic, sc->sc_recdrq,
    211                     sc->sc_rec_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    212                         printf("%s: can't create map for drq %d\n",
    213                             sc->sc_dev.dv_xname, sc->sc_recdrq);
    214                         return;
    215 		      }
    216 	      }
    217 
    218         /*
    219          * isapnp is a child if isa, and we need isa for the dma
    220          * routines.
    221          */
    222 	sc->iw_cd = &guspnp_cd;
    223 	sc->iw_hw_if = &guspnp_hw_if;
    224 
    225 	printf("%s: %s %s", sc->sc_dev.dv_xname, ipa->ipa_devident,
    226 	       ipa->ipa_devclass);
    227 
    228 	iwattach(sc);
    229 }
    230 
    231 static
    232 int
    233 gus_isapnp_open(addr, flags)
    234      void *addr;
    235      int flags;
    236 {
    237 	/* open hardware */
    238 	struct iw_softc *sc = (struct iw_softc *)addr;
    239 
    240 	if (!sc)
    241 		return ENXIO;
    242 
    243 	return iwopen(sc,flags);
    244 }
    245 
    246 #endif /* NGUSPNP */
    247