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