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