1 /* $NetBSD: wdc_pioc.c,v 1.6 2002/10/02 03:31:59 thorpej 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/param.h> 37 #include <sys/systm.h> 38 #include <sys/device.h> 39 #include <sys/malloc.h> 40 41 #include <machine/bus.h> 42 #include <machine/intr.h> 43 44 #include <acorn32/mainbus/piocvar.h> 45 46 #include <dev/ata/atavar.h> 47 #include <dev/ic/wdcvar.h> 48 49 #include "locators.h" 50 51 #define WDC_PIOC_REG_NPORTS 8 52 #define WDC_PIOC_AUXREG_OFFSET (0x206 * 4) 53 #define WDC_PIOC_AUXREG_NPORTS 1 54 55 struct wdc_pioc_softc { 56 struct wdc_softc sc_wdcdev; 57 struct channel_softc *wdc_chanptr; 58 struct channel_softc wdc_channel; 59 void *sc_ih; 60 }; 61 62 /* prototypes for functions */ 63 static int wdc_pioc_probe __P((struct device *, struct cfdata *, void *)); 64 static void wdc_pioc_attach __P((struct device *, struct device *, void *)); 65 66 /* device attach structure */ 67 CFATTACH_DECL(wdc_pioc, sizeof(struct wdc_pioc_softc), 68 wdc_pioc_probe, wdc_pioc_attach, NULL, NULL); 69 70 /* 71 * int wdc_pioc_probe(struct device *parent, struct cfdata *cf, void *aux) 72 * 73 * Make sure we are trying to attach a wdc device and then 74 * probe for one. 75 */ 76 77 static int 78 wdc_pioc_probe(parent, cf, aux) 79 struct device *parent; 80 struct cfdata *cf; 81 void *aux; 82 { 83 struct pioc_attach_args *pa = aux; 84 struct channel_softc ch; 85 int res; 86 u_int iobase; 87 88 if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0) 89 return(0); 90 91 /* We need an offset */ 92 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT) 93 return(0); 94 95 memset(&ch, 0, sizeof(ch)); 96 97 iobase = pa->pa_iobase + pa->pa_offset; 98 ch.cmd_iot = pa->pa_iot; 99 ch.ctl_iot = pa->pa_iot; 100 101 if (bus_space_map(ch.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0, 102 &ch.cmd_ioh)) 103 return(0); 104 if (bus_space_map(ch.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET, 105 WDC_PIOC_AUXREG_NPORTS, 0, &ch.ctl_ioh)) { 106 bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_PIOC_REG_NPORTS); 107 return(0); 108 } 109 110 res = wdcprobe(&ch); 111 112 bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_PIOC_AUXREG_NPORTS); 113 bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_PIOC_REG_NPORTS); 114 115 if (res) 116 pa->pa_iosize = WDC_PIOC_REG_NPORTS; 117 return(res); 118 } 119 120 /* 121 * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux) 122 * 123 * attach the wdc device 124 */ 125 126 static void 127 wdc_pioc_attach(parent, self, aux) 128 struct device *parent, *self; 129 void *aux; 130 { 131 struct wdc_pioc_softc *sc = (void *)self; 132 struct pioc_attach_args *pa = aux; 133 u_int iobase; 134 135 printf("\n"); 136 137 iobase = pa->pa_iobase + pa->pa_offset; 138 sc->wdc_channel.cmd_iot = pa->pa_iot; 139 sc->wdc_channel.ctl_iot = pa->pa_iot; 140 if (bus_space_map(sc->wdc_channel.cmd_iot, iobase, 141 WDC_PIOC_REG_NPORTS, 0, &sc->wdc_channel.cmd_ioh)) 142 panic("%s: couldn't map drive registers", self->dv_xname); 143 144 if (bus_space_map(sc->wdc_channel.ctl_iot, 145 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0, 146 &sc->wdc_channel.ctl_ioh)) 147 panic("%s: couldn't map aux registers", self->dv_xname); 148 149 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr, 150 &sc->wdc_channel); 151 if (!sc->sc_ih) 152 panic("%s: Cannot claim IRQ %d", self->dv_xname, pa->pa_irq); 153 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16; 154 sc->sc_wdcdev.PIO_cap = 0; 155 sc->wdc_chanptr = &sc->wdc_channel; 156 sc->sc_wdcdev.channels = &sc->wdc_chanptr; 157 sc->wdc_channel.wdc = &sc->sc_wdcdev; 158 sc->sc_wdcdev.nchannels = 1; 159 sc->wdc_channel.channel = 0; 160 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue), 161 M_DEVBUF, M_NOWAIT); 162 if (sc->wdc_channel.ch_queue == NULL) { 163 printf("%s: can't allocate memory for command queue", 164 sc->sc_wdcdev.sc_dev.dv_xname); 165 return; 166 } 167 wdcattach(&sc->wdc_channel); 168 } 169 170 /* End of wdc_pioc.c */ 171