Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.28
      1 /*	$NetBSD: wdc_isapnp.c,v 1.28 2004/08/14 15:08:06 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 2003 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/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: wdc_isapnp.c,v 1.28 2004/08/14 15:08:06 thorpej Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 #include <sys/malloc.h>
     46 
     47 #include <machine/bus.h>
     48 #include <machine/intr.h>
     49 
     50 #include <dev/isa/isavar.h>
     51 #include <dev/isa/isadmavar.h>
     52 
     53 #include <dev/isapnp/isapnpreg.h>
     54 #include <dev/isapnp/isapnpvar.h>
     55 #include <dev/isapnp/isapnpdevs.h>
     56 
     57 #include <dev/ata/atavar.h>
     58 #include <dev/ic/wdcreg.h>
     59 #include <dev/ic/wdcvar.h>
     60 
     61 struct wdc_isapnp_softc {
     62 	struct	wdc_softc sc_wdcdev;
     63 	struct	ata_channel *wdc_chanlist[1];
     64 	struct	ata_channel ata_channel;
     65 	struct	ata_queue wdc_chqueue;
     66 	struct	wdc_regs wdc_regs;
     67 	isa_chipset_tag_t sc_ic;
     68 	void	*sc_ih;
     69 	int	sc_drq;
     70 };
     71 
     72 int	wdc_isapnp_probe 	__P((struct device *, struct cfdata *, void *));
     73 void	wdc_isapnp_attach 	__P((struct device *, struct device *, void *));
     74 
     75 CFATTACH_DECL(wdc_isapnp, sizeof(struct wdc_isapnp_softc),
     76     wdc_isapnp_probe, wdc_isapnp_attach, NULL, NULL);
     77 
     78 #ifdef notyet
     79 static void	wdc_isapnp_dma_setup __P((struct wdc_isapnp_softc *));
     80 static void	wdc_isapnp_dma_start __P((void *, void *, size_t, int));
     81 static void	wdc_isapnp_dma_finish __P((void *));
     82 #endif
     83 
     84 int
     85 wdc_isapnp_probe(parent, match, aux)
     86 	struct device *parent;
     87 	struct cfdata *match;
     88 	void *aux;
     89 {
     90 	int pri, variant;
     91 
     92 	pri = isapnp_devmatch(aux, &isapnp_wdc_devinfo, &variant);
     93 	if (pri && variant > 0)
     94 		pri = 0;
     95 	return (pri);
     96 }
     97 
     98 void
     99 wdc_isapnp_attach(parent, self, aux)
    100 	struct device *parent, *self;
    101 	void *aux;
    102 {
    103 	struct wdc_isapnp_softc *sc = (void *)self;
    104 	struct wdc_regs *wdr;
    105 	struct isapnp_attach_args *ipa = aux;
    106 	int i;
    107 
    108 	if (ipa->ipa_nio != 2 ||
    109 	    ipa->ipa_nmem != 0 ||
    110 	    ipa->ipa_nmem32 != 0 ||
    111 	    ipa->ipa_nirq != 1 ||
    112 	    ipa->ipa_ndrq > 1) {
    113 		printf(": unexpected configuration\n");
    114 		return;
    115 	}
    116 
    117 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    118 		printf(": couldn't map registers\n");
    119 		return;
    120 	}
    121 
    122 	printf(": %s %s\n", ipa->ipa_devident, ipa->ipa_devclass);
    123 
    124 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    125 	wdr->cmd_iot = ipa->ipa_iot;
    126 	wdr->ctl_iot = ipa->ipa_iot;
    127 	/*
    128 	 * An IDE controller can feed us the regions in any order. Pass
    129 	 * them along with the 8-byte region in sc_ad.ioh, and the other
    130 	 * (2 byte) region in auxioh.
    131 	 */
    132 	if (ipa->ipa_io[0].length == 8) {
    133 		wdr->cmd_baseioh = ipa->ipa_io[0].h;
    134 		wdr->ctl_ioh = ipa->ipa_io[1].h;
    135 	} else {
    136 		wdr->cmd_baseioh = ipa->ipa_io[1].h;
    137 		wdr->ctl_ioh = ipa->ipa_io[0].h;
    138 	}
    139 
    140 	for (i = 0; i < WDC_NREG; i++) {
    141 		if (bus_space_subregion(wdr->cmd_iot,
    142 		    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    143 		    &wdr->cmd_iohs[i]) != 0) {
    144 			printf(": couldn't subregion registers\n");
    145 			return;
    146 		}
    147 	}
    148 	wdc_init_shadow_regs(&sc->ata_channel);
    149 	wdr->data32iot = wdr->cmd_iot;
    150 	wdr->data32ioh = wdr->cmd_iohs[0];
    151 
    152 	sc->sc_ic = ipa->ipa_ic;
    153 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    154 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->ata_channel);
    155 
    156 #ifdef notyet
    157 	if (ipa->ipa_ndrq > 0) {
    158 		sc->sc_drq = ipa->ipa_drq[0].num;
    159 
    160 		sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
    161 		sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
    162 		sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
    163 		wdc_isapnp_dma_setup(sc);
    164 	}
    165 #endif
    166 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
    167 	sc->sc_wdcdev.PIO_cap = 0;
    168 	sc->wdc_chanlist[0] = &sc->ata_channel;
    169 	sc->sc_wdcdev.channels = sc->wdc_chanlist;
    170 	sc->sc_wdcdev.nchannels = 1;
    171 	sc->ata_channel.ch_channel = 0;
    172 	sc->ata_channel.ch_wdc = &sc->sc_wdcdev;
    173 	sc->ata_channel.ch_queue = &sc->wdc_chqueue;
    174 
    175 	wdcattach(&sc->ata_channel);
    176 }
    177 
    178 #ifdef notyet
    179 static void
    180 wdc_isapnp_dma_setup(sc)
    181 	struct wdc_isapnp_softc *sc;
    182 {
    183 
    184 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    185 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    186 		printf("%s: can't create map for drq %d\n",
    187 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    188 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
    189 	}
    190 }
    191 
    192 static void
    193 wdc_isapnp_dma_start(scv, buf, size, read)
    194 	void *scv, *buf;
    195 	size_t size;
    196 	int read;
    197 {
    198 	struct wdc_isapnp_softc *sc = scv;
    199 
    200 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf, size, NULL,
    201 	    (read ? DMAMODE_READ : DMAMODE_WRITE) | DMAMODE_DEMAND,
    202 	    BUS_DMA_NOWAIT);
    203 }
    204 
    205 static void
    206 wdc_isapnp_dma_finish(scv)
    207 	void *scv;
    208 {
    209 	struct wdc_isapnp_softc *sc = scv;
    210 
    211 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    212 }
    213 #endif
    214