Home | History | Annotate | Line # | Download | only in mainbus
wdc_pioc.c revision 1.11
      1 /*	$NetBSD: wdc_pioc.c,v 1.11 2003/12/02 23:47:20 bjh21 Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997-1998 Mark Brinicombe.
      5  * Copyright (c) 1997 Causality Limited.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Mark Brinicombe
     18  *	for the NetBSD Project.
     19  * 4. The name of the company nor the name of the author may be used to
     20  *    endorse or promote products derived from this software without specific
     21  *    prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: wdc_pioc.c,v 1.11 2003/12/02 23:47:20 bjh21 Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 #include <sys/malloc.h>
     43 
     44 #include <machine/bus.h>
     45 #include <machine/intr.h>
     46 
     47 #include <acorn32/mainbus/piocvar.h>
     48 
     49 #include <dev/ata/atavar.h>
     50 #include <dev/ic/wdcreg.h>
     51 #include <dev/ic/wdcvar.h>
     52 
     53 #include "locators.h"
     54 
     55 #define WDC_PIOC_REG_NPORTS	8
     56 #define WDC_PIOC_AUXREG_OFFSET	(0x206 * 4)
     57 #define WDC_PIOC_AUXREG_NPORTS	1
     58 
     59 struct wdc_pioc_softc {
     60 	struct	wdc_softc sc_wdcdev;
     61 	struct	channel_softc *wdc_chanptr;
     62 	struct	channel_softc wdc_channel;
     63 	void	*sc_ih;
     64 };
     65 
     66 /* prototypes for functions */
     67 static int  wdc_pioc_probe  __P((struct device *, struct cfdata *, void *));
     68 static void wdc_pioc_attach __P((struct device *, struct device *, void *));
     69 
     70 /* device attach structure */
     71 CFATTACH_DECL(wdc_pioc, sizeof(struct wdc_pioc_softc),
     72     wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
     73 
     74 /*
     75  * int wdc_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
     76  *
     77  * Make sure we are trying to attach a wdc device and then
     78  * probe for one.
     79  */
     80 
     81 static int
     82 wdc_pioc_probe(parent, cf, aux)
     83 	struct device *parent;
     84 	struct cfdata *cf;
     85 	void *aux;
     86 {
     87 	struct pioc_attach_args *pa = aux;
     88 	struct channel_softc ch;
     89 	int res, i;
     90 	u_int iobase;
     91 
     92 	if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
     93 		return(0);
     94 
     95 	/* We need an offset */
     96 	if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
     97 		return(0);
     98 
     99 	memset(&ch, 0, sizeof(ch));
    100 
    101 	iobase = pa->pa_iobase + pa->pa_offset;
    102 	ch.cmd_iot = pa->pa_iot;
    103 	ch.ctl_iot = pa->pa_iot;
    104 
    105 	if (bus_space_map(ch.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
    106 	    &ch.cmd_baseioh))
    107 		return(0);
    108 	for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
    109 		if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh, i,
    110 			i == 0 ? 4 : 1, &ch.cmd_iohs[i]) != 0) {
    111 			bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh,
    112 			    WDC_PIOC_REG_NPORTS);
    113 			return 0;
    114 		}
    115 	}
    116 
    117 	if (bus_space_map(ch.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
    118 	    WDC_PIOC_AUXREG_NPORTS, 0, &ch.ctl_ioh)) {
    119 		bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh,
    120 		    WDC_PIOC_REG_NPORTS);
    121 		return(0);
    122 	}
    123 
    124 	res = wdcprobe(&ch);
    125 
    126 	bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
    127 	bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_PIOC_REG_NPORTS);
    128 
    129 	if (res)
    130 		 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
    131 	return(res);
    132 }
    133 
    134 /*
    135  * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux)
    136  *
    137  * attach the wdc device
    138  */
    139 
    140 static void
    141 wdc_pioc_attach(parent, self, aux)
    142 	struct device *parent, *self;
    143 	void *aux;
    144 {
    145 	struct wdc_pioc_softc *sc = (void *)self;
    146 	struct pioc_attach_args *pa = aux;
    147 	u_int iobase;
    148 	int i;
    149 
    150 	printf("\n");
    151 
    152 	iobase = pa->pa_iobase + pa->pa_offset;
    153 	sc->wdc_channel.cmd_iot = pa->pa_iot;
    154 	sc->wdc_channel.ctl_iot = pa->pa_iot;
    155 	if (bus_space_map(sc->wdc_channel.cmd_iot, iobase,
    156 	    WDC_PIOC_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh))
    157 		panic("%s: couldn't map drive registers", self->dv_xname);
    158 	for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
    159 		if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    160 			sc->wdc_channel.cmd_baseioh, i,	i == 0 ? 4 : 1,
    161 			&sc->wdc_channel.cmd_iohs[i]) != 0)
    162 			panic("%s: couldn't submap drive registers",
    163 			    self->dv_xname);
    164 	}
    165 
    166 	if (bus_space_map(sc->wdc_channel.ctl_iot,
    167 	    iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
    168 	    &sc->wdc_channel.ctl_ioh))
    169 		panic("%s: couldn't map aux registers", self->dv_xname);
    170 
    171 	sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc",  wdcintr,
    172 	     &sc->wdc_channel);
    173 	if (!sc->sc_ih)
    174 		panic("%s: Cannot claim IRQ %d", self->dv_xname, pa->pa_irq);
    175 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
    176 	sc->sc_wdcdev.PIO_cap = 0;
    177 	sc->wdc_chanptr = &sc->wdc_channel;
    178 	sc->sc_wdcdev.channels = &sc->wdc_chanptr;
    179 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
    180 	sc->sc_wdcdev.nchannels = 1;
    181 	sc->wdc_channel.channel = 0;
    182 	sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
    183 	    M_DEVBUF, M_NOWAIT);
    184 	if (sc->wdc_channel.ch_queue == NULL) {
    185 		printf("%s: can't allocate memory for command queue",
    186 		    sc->sc_wdcdev.sc_dev.dv_xname);
    187 		return;
    188 	}
    189 
    190 	wdcattach(&sc->wdc_channel);
    191 }
    192 
    193 /* End of wdc_pioc.c */
    194