Home | History | Annotate | Line # | Download | only in isa
wdc_isa.c revision 1.9
      1 /*	$NetBSD: wdc_isa.c,v 1.9 1998/08/15 10:10:52 mycroft 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/ic/wdcvar.h>
     51 
     52 #define	WDC_ISA_REG_NPORTS	8
     53 #define	WDC_ISA_AUXREG_OFFSET	0x206
     54 #define	WDC_ISA_AUXREG_NPORTS	1 /* XXX "fdc" owns ports 0x3f7/0x377 */
     55 
     56 /*
     57  * XXX This code currently doesn't even try to allow 32-bit data port use.
     58  */
     59 
     60 struct wdc_isa_softc {
     61 	struct wdc_softc sc_wdcdev;
     62 	struct wdc_attachment_data sc_ad;
     63 	isa_chipset_tag_t sc_ic;
     64 	void	*sc_ih;
     65 	int	sc_drq;
     66 };
     67 
     68 int	wdc_isa_probe	__P((struct device *, struct cfdata *, void *));
     69 void	wdc_isa_attach	__P((struct device *, struct device *, void *));
     70 
     71 struct cfattach wdc_isa_ca = {
     72 	sizeof(struct wdc_isa_softc), wdc_isa_probe, wdc_isa_attach
     73 };
     74 
     75 static void	wdc_isa_dma_setup __P((void *));
     76 static void	wdc_isa_dma_start __P((void *, void *, size_t, int));
     77 static void	wdc_isa_dma_finish __P((void *));
     78 
     79 int
     80 wdc_isa_probe(parent, match, aux)
     81 	struct device *parent;
     82 	struct cfdata *match;
     83 	void *aux;
     84 {
     85 #if 0 /* XXX memset */
     86 	struct wdc_attachment_data ad = { 0 };
     87 #else /* XXX memset */
     88 	struct wdc_attachment_data ad;
     89 #endif /* XXX memset */
     90 	struct isa_attach_args *ia = aux;
     91 	int result = 0;
     92 
     93 #if 0 /* XXX memset */
     94 #else /* XXX memset */
     95 	bzero(&ad, sizeof ad);
     96 #endif /* XXX memset */
     97 	ad.iot = ia->ia_iot;
     98 	if (bus_space_map(ad.iot, ia->ia_iobase, WDC_ISA_REG_NPORTS, 0,
     99 	    &ad.ioh))
    100 		goto out;
    101 
    102 	ad.auxiot = ia->ia_iot;
    103 	if (bus_space_map(ad.auxiot, ia->ia_iobase + WDC_ISA_AUXREG_OFFSET,
    104 	    WDC_ISA_AUXREG_NPORTS, 0, &ad.auxioh))
    105 		goto outunmap;
    106 
    107 	result = wdcprobe(&ad);
    108 	if (result) {
    109 		ia->ia_iosize = WDC_ISA_REG_NPORTS;
    110 		ia->ia_msize = 0;
    111 	}
    112 
    113 	bus_space_unmap(ad.auxiot, ad.auxioh, WDC_ISA_AUXREG_NPORTS);
    114 outunmap:
    115 	bus_space_unmap(ad.iot, ad.ioh, WDC_ISA_REG_NPORTS);
    116 out:
    117 	return (result);
    118 }
    119 
    120 void
    121 wdc_isa_attach(parent, self, aux)
    122 	struct device *parent, *self;
    123 	void *aux;
    124 {
    125 	struct wdc_isa_softc *sc = (void *)self;
    126 	struct isa_attach_args *ia = aux;
    127 
    128 	printf("\n");
    129 
    130 	sc->sc_ad.iot = ia->ia_iot;
    131 	sc->sc_ad.auxiot = ia->ia_iot;
    132 	sc->sc_ic = ia->ia_ic;
    133 	if (bus_space_map(sc->sc_ad.iot, ia->ia_iobase, WDC_ISA_REG_NPORTS, 0,
    134 	      &sc->sc_ad.ioh) ||
    135 	    bus_space_map(sc->sc_ad.auxiot,
    136 	      ia->ia_iobase + WDC_ISA_AUXREG_OFFSET, WDC_ISA_AUXREG_NPORTS,
    137 	      0, &sc->sc_ad.auxioh)) {
    138 		printf("%s: couldn't map registers\n",
    139 		    sc->sc_wdcdev.sc_dev.dv_xname);
    140 	}
    141 
    142 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    143 	    IPL_BIO, wdcintr, sc);
    144 
    145 	if (ia->ia_drq != DRQUNK) {
    146 		sc->sc_drq = ia->ia_drq;
    147 
    148 		sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
    149 		sc->sc_ad.dma_arg = sc;
    150 		sc->sc_ad.dma_setup = &wdc_isa_dma_setup;
    151 		sc->sc_ad.dma_start = &wdc_isa_dma_start;
    152 		sc->sc_ad.dma_finish = &wdc_isa_dma_finish;
    153 	}
    154 
    155 	wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
    156 }
    157 
    158 static void
    159 wdc_isa_dma_setup(scv)
    160 	void *scv;
    161 {
    162 	struct wdc_isa_softc *sc = scv;
    163 
    164 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    165 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    166 		printf("%s: can't create map for drq %d\n",
    167 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    168 		sc->sc_ad.cap &= ~WDC_CAPABILITY_DMA;
    169 	}
    170 }
    171 
    172 static void
    173 wdc_isa_dma_start(scv, buf, size, read)
    174 	void *scv, *buf;
    175 	size_t size;
    176 	int read;
    177 {
    178 	struct wdc_isa_softc *sc = scv;
    179 
    180 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
    181 	    size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
    182 	    BUS_DMA_NOWAIT);
    183 }
    184 
    185 static void
    186 wdc_isa_dma_finish(scv)
    187 	void *scv;
    188 {
    189 	struct wdc_isa_softc *sc = scv;
    190 
    191 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    192 }
    193