Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.4
      1 /*	$NetBSD: wdc_isapnp.c,v 1.4 1998/06/09 07:28:31 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Charles M. Hannum.  All rights reserved.
      5  *
      6  * DMA and multi-sector PIO handling are derived from code contributed by
      7  * Onno van der Linden.
      8  *
      9  * ISA attachment created by Christopher G. Demetriou.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by Charles M. Hannum.
     22  * 4. The name of the author may not be used to endorse or promote products
     23  *    derived from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 
     37 #include <sys/types.h>
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/device.h>
     41 
     42 #include <machine/bus.h>
     43 #include <machine/intr.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 
     51 #include <dev/ic/wdcreg.h>
     52 #include <dev/ic/wdcvar.h>
     53 
     54 struct wdc_isapnp_softc {
     55 	struct	wdc_softc sc_wdcdev;
     56 	struct	wdc_attachment_data sc_ad;
     57 	isa_chipset_tag_t sc_ic;
     58 	void	*sc_ih;
     59 	int	sc_drq;
     60 };
     61 
     62 int	wdc_isapnp_probe 	__P((struct device *, struct cfdata *, void *));
     63 void	wdc_isapnp_attach 	__P((struct device *, struct device *, void *));
     64 
     65 struct cfattach wdc_isapnp_ca = {
     66 	sizeof(struct wdc_isapnp_softc), wdc_isapnp_probe, wdc_isapnp_attach
     67 };
     68 
     69 #ifdef notyet
     70 static void	wdc_isapnp_dma_setup __P((void *));
     71 static void	wdc_isapnp_dma_start __P((void *, void *, size_t, int));
     72 static void	wdc_isapnp_dma_finish __P((void *));
     73 #endif
     74 
     75 int
     76 wdc_isapnp_probe(parent, match, aux)
     77 	struct device *parent;
     78 	struct cfdata *match;
     79 	void *aux;
     80 {
     81 	struct isapnp_attach_args *ipa = aux;
     82 
     83 	if (strcmp(ipa->ipa_devcompat, "PNP0600"))
     84 		return (0);
     85 
     86 	return (1);
     87 }
     88 
     89 void
     90 wdc_isapnp_attach(parent, self, aux)
     91 	struct device *parent, *self;
     92 	void *aux;
     93 {
     94 	struct wdc_isapnp_softc *sc = (void *)self;
     95 	struct isapnp_attach_args *ipa = aux;
     96 
     97 	printf("\n");
     98 
     99 	if (ipa->ipa_nio != 2 ||
    100 	    ipa->ipa_nmem != 0 ||
    101 	    ipa->ipa_nmem32 != 0 ||
    102 	    ipa->ipa_nirq != 1 ||
    103 	    ipa->ipa_ndrq > 1) {
    104 		printf("%s: unexpected configuration\n",
    105 		    sc->sc_wdcdev.sc_dev.dv_xname);
    106 		return;
    107 	}
    108 
    109 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    110 		printf("%s: couldn't map registers\n",
    111 		    sc->sc_wdcdev.sc_dev.dv_xname);
    112 		return;
    113 	}
    114 
    115 	printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
    116 	    ipa->ipa_devclass);
    117 
    118 	sc->sc_ad.iot = ipa->ipa_iot;
    119 	sc->sc_ad.ioh = ipa->ipa_io[0].h;
    120 	sc->sc_ad.auxiot = ipa->ipa_iot;
    121 	sc->sc_ad.auxioh = ipa->ipa_io[1].h;
    122 	sc->sc_ic = ipa->ipa_ic;
    123 
    124 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    125 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, sc);
    126 
    127 #ifdef notyet
    128 	if (ipa->ipa_ndrq > 0) {
    129 		sc->sc_drq = ipa->ipa_drq[0].num;
    130 
    131 		sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
    132 		sc->sc_ad.dma_setup = &wdc_isapnp_dma_setup;
    133 		sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
    134 		sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
    135 	}
    136 #endif
    137 
    138 	wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
    139 }
    140 
    141 #ifdef notyet
    142 static void
    143 wdc_isapnp_dma_setup(scv)
    144 	void *scv;
    145 {
    146 	struct wdc_isapnp_softc *sc = scv;
    147 
    148 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    149 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    150 		printf("%s: can't create map for drq %d\n",
    151 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    152 		sc->sc_ad.cap &= ~WDC_CAPABILITY_DMA;
    153 	}
    154 }
    155 
    156 static void
    157 wdc_isapnp_dma_start(scv, buf, size, read)
    158 	void *scv, *buf;
    159 	size_t size;
    160 	int read;
    161 {
    162 	struct wdc_isapnp_softc *sc = scv;
    163 
    164 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
    165 	    size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
    166 	    BUS_DMA_NOWAIT);
    167 }
    168 
    169 static void
    170 wdc_isapnp_dma_finish(scv)
    171 	void *scv;
    172 {
    173 	struct wdc_isapnp_softc *sc = scv;
    174 
    175 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    176 }
    177 #endif
    178