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