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