1 /* $NetBSD: rapide.c,v 1.32 2017/10/20 07:06:06 jdolecek Exp $ */ 2 3 /* 4 * Copyright (c) 1997-1998 Mark Brinicombe 5 * Copyright (c) 1997-1998 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 author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * Card driver and probe and attach functions to use generic IDE driver 34 * for the RapIDE podule 35 */ 36 37 /* 38 * Thanks to Chris Honey at Raymond Datalink for providing information on 39 * addressing the RapIDE podule. 40 * RapIDE32 is Copyright (C) 1995,1996 Raymond Datalink. RapIDE32 is 41 * manufactured under license by Yellowstone Educational Solutions. 42 */ 43 44 /* 45 * At present this driver only supports the Issue 2 RapIDE podule. 46 */ 47 48 /* 49 * A small amount of work is required for Issue 1 podule support. 50 * The primary differences are the register addresses. 51 * Things are eased by the fact that we can identify the card by register 52 * the same register on both issues of the podule. 53 * Once we kmnow the issue we must change all our addresses accordingly. 54 * All the control registers are mapped the same between cards. 55 * The interrupt handler needs to take note that the issue 1 card needs 56 * the interrupt to be cleared via the interrupt clear register. 57 * This means we share addresses for the mapping of the control block and 58 * thus the card driver does not need to know about the differences. 59 * The differences show up a the controller level. 60 * A structure is used to hold the information about the addressing etc. 61 * An array of these structures holds the information for the primary and 62 * secondary connectors. This needs to be extended to hold this information 63 * for both issues. Then the indexing of these structures will use the 64 * card version number. 65 * 66 * Opps just noticed a mistake. The interrupt request register is different 67 * between cards so the card level attach routine will need to consider this. 68 */ 69 70 #include <sys/cdefs.h> 71 __KERNEL_RCSID(0, "$NetBSD: rapide.c,v 1.32 2017/10/20 07:06:06 jdolecek Exp $"); 72 73 #include <sys/param.h> 74 #include <sys/systm.h> 75 #include <sys/conf.h> 76 #include <sys/device.h> 77 #include <sys/malloc.h> 78 #include <sys/bus.h> 79 80 #include <machine/intr.h> 81 #include <machine/io.h> 82 #include <machine/bootconfig.h> 83 #include <arm/iomd/iomdreg.h> 84 #include <arm/iomd/iomdvar.h> 85 #include <acorn32/podulebus/podulebus.h> 86 #include <acorn32/podulebus/rapidereg.h> 87 88 #include <dev/ata/atavar.h> 89 #include <dev/ic/wdcreg.h> 90 #include <dev/ic/wdcvar.h> 91 #include <dev/podulebus/podules.h> 92 93 94 /* 95 * RapIDE podule device. 96 * 97 * This probes and attaches the top level RapIDE device to the podulebus. 98 * It then configures any children of the RapIDE device. 99 * The attach args specify whether it is configuring the primary or 100 * secondary channel. 101 * The children are expected to be wdc devices using rapide attachments. 102 */ 103 104 /* 105 * RapIDE card softc structure. 106 * 107 * Contains the device node, podule information and global information 108 * required by the driver such as the card version and the interrupt mask. 109 */ 110 111 struct rapide_softc { 112 struct wdc_softc sc_wdcdev; /* common wdc definitions */ 113 struct ata_channel *sc_chanarray[2]; /* channels definition */ 114 podule_t *sc_podule; /* Our podule info */ 115 int sc_podule_number; /* Our podule number */ 116 int sc_intr_enable_mask; /* Global intr mask */ 117 int sc_version; /* Card version */ 118 bus_space_tag_t sc_ctliot; /* Bus tag */ 119 bus_space_handle_t sc_ctlioh; /* control handler */ 120 struct rapide_channel { 121 struct ata_channel rc_channel; /* generic part */ 122 irqhandler_t rc_ih; /* interrupt handler */ 123 int rc_irqmask; /* IRQ mask for this channel */ 124 } rapide_channels[2]; 125 struct wdc_regs sc_wdc_regs[2]; 126 }; 127 128 int rapide_probe (device_t, struct cfdata *, void *); 129 void rapide_attach (device_t, device_t, void *); 130 void rapide_shutdown (void *arg); 131 int rapide_intr (void *); 132 133 CFATTACH_DECL_NEW(rapide, sizeof(struct rapide_softc), 134 rapide_probe, rapide_attach, NULL, NULL); 135 136 /* 137 * We have a private bus space tag. 138 * This is created by copying the podulebus tag and then replacing 139 * a couple of the transfer functions. 140 */ 141 142 static struct bus_space rapide_bs_tag; 143 144 bs_rm_4_proto(rapide); 145 bs_wm_4_proto(rapide); 146 147 /* 148 * Create an array of address structures. These define the addresses and 149 * masks needed for the different channels for the card. 150 * 151 * XXX - Needs some work for issue 1 cards. 152 */ 153 154 struct { 155 u_int registers; 156 u_int aux_register; 157 u_int data_register; 158 u_int irq_mask; 159 } rapide_info[] = { 160 { PRIMARY_DRIVE_REGISTERS_OFFSET, PRIMARY_AUX_REGISTER_OFFSET, 161 PRIMARY_DATA_REGISTER_OFFSET, PRIMARY_IRQ_MASK }, 162 { SECONDARY_DRIVE_REGISTERS_OFFSET, SECONDARY_AUX_REGISTER_OFFSET, 163 SECONDARY_DATA_REGISTER_OFFSET, SECONDARY_IRQ_MASK } 164 }; 165 166 167 /* 168 * Card probe function 169 * 170 * Just match the manufacturer and podule ID's 171 */ 172 173 int 174 rapide_probe(device_t parent, cfdata_t cf, void *aux) 175 { 176 struct podule_attach_args *pa = (void *)aux; 177 178 return (pa->pa_product == PODULE_RAPIDE); 179 } 180 181 /* 182 * Card attach function 183 * 184 * Identify the card version and configure any children. 185 * Install a shutdown handler to kill interrupts on shutdown 186 */ 187 188 void 189 rapide_attach(device_t parent, device_t self, void *aux) 190 { 191 struct rapide_softc *sc = device_private(self); 192 struct podule_attach_args *pa = (void *)aux; 193 bus_space_tag_t iot; 194 bus_space_handle_t ctlioh; 195 u_int iobase; 196 int channel, i; 197 struct rapide_channel *rcp; 198 struct ata_channel *cp; 199 struct wdc_regs *wdr; 200 irqhandler_t *ihp; 201 202 /* Note the podule number and validate */ 203 if (pa->pa_podule_number == -1) 204 panic("Podule has disappeared !"); 205 206 sc->sc_wdcdev.sc_atac.atac_dev = self; 207 sc->sc_podule_number = pa->pa_podule_number; 208 sc->sc_podule = pa->pa_podule; 209 podules[sc->sc_podule_number].attached = 1; 210 211 sc->sc_wdcdev.regs = sc->sc_wdc_regs; 212 213 set_easi_cycle_type(sc->sc_podule_number, EASI_CYCLE_TYPE_C); 214 215 /* 216 * Duplicate the podule bus space tag and provide alternative 217 * bus_space_read_multi_4() and bus_space_write_multi_4() 218 * functions. 219 */ 220 rapide_bs_tag = *pa->pa_iot; 221 rapide_bs_tag.bs_rm_4 = rapide_bs_rm_4; 222 rapide_bs_tag.bs_wm_4 = rapide_bs_wm_4; 223 sc->sc_ctliot = iot = &rapide_bs_tag; 224 225 if (bus_space_map(iot, pa->pa_podule->easi_base + 226 CONTROL_REGISTERS_OFFSET, CONTROL_REGISTER_SPACE, 0, &ctlioh)) 227 panic("%s: Cannot map control registers", device_xname(self)); 228 229 sc->sc_ctlioh = ctlioh; 230 sc->sc_version = bus_space_read_1(iot, ctlioh, VERSION_REGISTER_OFFSET) & VERSION_REGISTER_MASK; 231 /* bus_space_unmap(iot, ctl_ioh, CONTROL_REGISTER_SPACE);*/ 232 233 aprint_normal(": Issue %d\n", sc->sc_version + 1); 234 if (sc->sc_version != VERSION_2_ID) 235 return; 236 237 if (shutdownhook_establish(rapide_shutdown, (void *)sc) == NULL) 238 panic("%s: Cannot install shutdown handler", device_xname(self)); 239 240 /* Set the interrupt info for this podule */ 241 sc->sc_podule->irq_addr = pa->pa_podule->easi_base 242 + CONTROL_REGISTERS_OFFSET + IRQ_REQUEST_REGISTER_BYTE_OFFSET; 243 sc->sc_podule->irq_mask = IRQ_MASK; 244 245 iobase = pa->pa_podule->easi_base; 246 247 /* Fill in wdc and channel infos */ 248 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA32; 249 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0; 250 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanarray; 251 sc->sc_wdcdev.sc_atac.atac_nchannels = 2; 252 sc->sc_wdcdev.wdc_maxdrives = 2; 253 for (channel = 0 ; channel < 2; channel++) { 254 rcp = &sc->rapide_channels[channel]; 255 sc->sc_chanarray[channel] = &rcp->rc_channel; 256 cp = &rcp->rc_channel; 257 wdr = &sc->sc_wdc_regs[channel]; 258 259 cp->ch_channel = channel; 260 cp->ch_atac = &sc->sc_wdcdev.sc_atac; 261 wdr->cmd_iot = iot; 262 wdr->ctl_iot = iot; 263 wdr->data32iot = iot; 264 265 if (bus_space_map(iot, iobase + rapide_info[channel].registers, 266 DRIVE_REGISTERS_SPACE, 0, &wdr->cmd_baseioh)) 267 continue; 268 for (i = 0; i < WDC_NREG; i++) { 269 if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, 270 i, i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) { 271 bus_space_unmap(iot, wdr->cmd_baseioh, 272 DRIVE_REGISTERS_SPACE); 273 continue; 274 } 275 } 276 wdc_init_shadow_regs(wdr); 277 if (bus_space_map(iot, iobase + 278 rapide_info[channel].aux_register, 4, 0, &wdr->ctl_ioh)) { 279 bus_space_unmap(iot, wdr->cmd_baseioh, 280 DRIVE_REGISTERS_SPACE); 281 continue; 282 } 283 if (bus_space_map(iot, iobase + 284 rapide_info[channel].data_register, 4, 0, &wdr->data32ioh)) { 285 bus_space_unmap(iot, wdr->cmd_baseioh, 286 DRIVE_REGISTERS_SPACE); 287 bus_space_unmap(iot, wdr->ctl_ioh, 4); 288 continue; 289 } 290 /* Disable interrupts and clear any pending interrupts */ 291 rcp->rc_irqmask = rapide_info[channel].irq_mask; 292 sc->sc_intr_enable_mask &= ~rcp->rc_irqmask; 293 bus_space_write_1(iot, sc->sc_ctlioh, IRQ_MASK_REGISTER_OFFSET, 294 sc->sc_intr_enable_mask); 295 /* XXX - Issue 1 cards will need to clear any pending interrupts */ 296 ihp = &rcp->rc_ih; 297 ihp->ih_func = rapide_intr; 298 ihp->ih_arg = rcp; 299 ihp->ih_level = IPL_BIO; 300 ihp->ih_name = "rapide"; 301 ihp->ih_maskaddr = pa->pa_podule->irq_addr; 302 ihp->ih_maskbits = rcp->rc_irqmask; 303 if (irq_claim(sc->sc_podule->interrupt, ihp)) 304 panic("%s: Cannot claim interrupt %d", 305 device_xname(self), sc->sc_podule->interrupt); 306 /* clear any pending interrupts and enable interrupts */ 307 sc->sc_intr_enable_mask |= rcp->rc_irqmask; 308 bus_space_write_1(iot, sc->sc_ctlioh, 309 IRQ_MASK_REGISTER_OFFSET, sc->sc_intr_enable_mask); 310 /* XXX - Issue 1 cards will need to clear any pending interrupts */ 311 wdcattach(cp); 312 } 313 } 314 315 /* 316 * Card shutdown function 317 * 318 * Called via do_shutdown_hooks() during kernel shutdown. 319 * Clear the cards's interrupt mask to stop any podule interrupts. 320 */ 321 322 void 323 rapide_shutdown(void *arg) 324 { 325 struct rapide_softc *sc = arg; 326 327 /* Disable card interrupts */ 328 bus_space_write_1(sc->sc_ctliot, sc->sc_ctlioh, 329 IRQ_MASK_REGISTER_OFFSET, 0); 330 } 331 332 /* 333 * Podule interrupt handler 334 * 335 * If the interrupt was from our card pass it on to the wdc interrupt handler 336 */ 337 338 int 339 rapide_intr(void *arg) 340 { 341 struct rapide_channel *rcp = arg; 342 irqhandler_t *ihp = &rcp->rc_ih; 343 volatile u_char *intraddr = (volatile u_char *)ihp->ih_maskaddr; 344 345 /* XXX - Issue 1 cards will need to clear the interrupt */ 346 347 /* XXX - not bus space yet - should really be handled by podulebus */ 348 if ((*intraddr) & ihp->ih_maskbits) 349 wdcintr(&rcp->rc_channel); 350 351 return(0); 352 } 353