1 /* $NetBSD: rapide.c,v 1.3 2002/05/22 22:43:19 bjh21 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 this structures will utilise 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/param.h> 71 #include <sys/systm.h> 72 #include <sys/conf.h> 73 #include <sys/device.h> 74 #include <sys/malloc.h> 75 76 #include <machine/intr.h> 77 #include <machine/io.h> 78 #include <machine/bus.h> 79 #include <machine/bootconfig.h> 80 #include <arm/iomd/iomdreg.h> 81 #include <arm/iomd/iomdvar.h> 82 #include <acorn32/podulebus/podulebus.h> 83 #include <acorn32/podulebus/rapidereg.h> 84 85 #include <dev/ata/atavar.h> 86 #include <dev/ic/wdcvar.h> 87 #include <dev/podulebus/podules.h> 88 89 90 /* 91 * RapIDE podule device. 92 * 93 * This probes and attaches the top level RapIDE device to the podulebus. 94 * It then configures any children of the RapIDE device. 95 * The attach args specify whether it is configuring the primary or 96 * secondary channel. 97 * The children are expected to be wdc devices using rapide attachments. 98 */ 99 100 /* 101 * RapIDE card softc structure. 102 * 103 * Contains the device node, podule information and global information 104 * required by the driver such as the card version and the interrupt mask. 105 */ 106 107 struct rapide_softc { 108 struct wdc_softc sc_wdcdev; /* common wdc definitions */ 109 struct channel_softc *wdc_chanarray[2]; /* channels definition */ 110 podule_t *sc_podule; /* Our podule info */ 111 int sc_podule_number; /* Our podule number */ 112 int sc_intr_enable_mask; /* Global intr mask */ 113 int sc_version; /* Card version */ 114 bus_space_tag_t sc_ctliot; /* Bus tag */ 115 bus_space_handle_t sc_ctlioh; /* control handler */ 116 struct rapide_channel { 117 struct channel_softc wdc_channel; /* generic part */ 118 irqhandler_t rc_ih; /* interrupt handler */ 119 int rc_irqmask; /* IRQ mask for this channel */ 120 } rapide_channels[2]; 121 }; 122 123 int rapide_probe __P((struct device *, struct cfdata *, void *)); 124 void rapide_attach __P((struct device *, struct device *, void *)); 125 void rapide_shutdown __P((void *arg)); 126 int rapide_intr __P((void *)); 127 128 struct cfattach rapide_ca = { 129 sizeof(struct rapide_softc), rapide_probe, rapide_attach 130 }; 131 132 /* 133 * We have a private bus space tag. 134 * This is created by copying the podulebus tag and then replacing 135 * a couple of the transfer functions. 136 */ 137 138 static struct bus_space rapide_bs_tag; 139 140 bs_rm_4_proto(rapide); 141 bs_wm_4_proto(rapide); 142 143 /* 144 * Create an array of address structures. These define the addresses and 145 * masks needed for the different channels for the card. 146 * 147 * XXX - Needs some work for issue 1 cards. 148 */ 149 150 struct { 151 u_int registers; 152 u_int aux_register; 153 u_int data_register; 154 u_int irq_mask; 155 } rapide_info[] = { 156 { PRIMARY_DRIVE_REGISTERS_OFFSET, PRIMARY_AUX_REGISTER_OFFSET, 157 PRIMARY_DATA_REGISTER_OFFSET, PRIMARY_IRQ_MASK }, 158 { SECONDARY_DRIVE_REGISTERS_OFFSET, SECONDARY_AUX_REGISTER_OFFSET, 159 SECONDARY_DATA_REGISTER_OFFSET, SECONDARY_IRQ_MASK } 160 }; 161 162 163 /* 164 * Card probe function 165 * 166 * Just match the manufacturer and podule ID's 167 */ 168 169 int 170 rapide_probe(parent, cf, aux) 171 struct device *parent; 172 struct cfdata *cf; 173 void *aux; 174 { 175 struct podule_attach_args *pa = (void *)aux; 176 177 return (pa->pa_product == PODULE_RAPIDE); 178 } 179 180 /* 181 * Card attach function 182 * 183 * Identify the card version and configure any children. 184 * Install a shutdown handler to kill interrupts on shutdown 185 */ 186 187 void 188 rapide_attach(parent, self, aux) 189 struct device *parent, *self; 190 void *aux; 191 { 192 struct rapide_softc *sc = (void *)self; 193 struct podule_attach_args *pa = (void *)aux; 194 bus_space_tag_t iot; 195 bus_space_handle_t ctlioh; 196 u_int iobase; 197 int channel; 198 struct rapide_channel *rcp; 199 struct channel_softc *cp; 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_podule_number = pa->pa_podule_number; 207 sc->sc_podule = pa->pa_podule; 208 podules[sc->sc_podule_number].attached = 1; 209 210 set_easi_cycle_type(sc->sc_podule_number, EASI_CYCLE_TYPE_C); 211 212 /* 213 * Duplicate the podule bus space tag and provide alternative 214 * bus_space_read_multi_4() and bus_space_write_multi_4() 215 * functions. 216 */ 217 rapide_bs_tag = *pa->pa_iot; 218 rapide_bs_tag.bs_rm_4 = rapide_bs_rm_4; 219 rapide_bs_tag.bs_wm_4 = rapide_bs_wm_4; 220 sc->sc_ctliot = iot = &rapide_bs_tag; 221 222 if (bus_space_map(iot, pa->pa_podule->easi_base + 223 CONTROL_REGISTERS_OFFSET, CONTROL_REGISTER_SPACE, 0, &ctlioh)) 224 panic("%s: Cannot map control registers\n", self->dv_xname); 225 226 sc->sc_ctlioh = ctlioh; 227 sc->sc_version = bus_space_read_1(iot, ctlioh, VERSION_REGISTER_OFFSET) & VERSION_REGISTER_MASK; 228 /* bus_space_unmap(iot, ctl_ioh, CONTROL_REGISTER_SPACE);*/ 229 230 printf(": Issue %d\n", sc->sc_version + 1); 231 if (sc->sc_version != VERSION_2_ID) 232 return; 233 234 if (shutdownhook_establish(rapide_shutdown, (void *)sc) == NULL) 235 panic("%s: Cannot install shutdown handler", self->dv_xname); 236 237 /* Set the interrupt info for this podule */ 238 sc->sc_podule->irq_addr = pa->pa_podule->easi_base 239 + CONTROL_REGISTERS_OFFSET + IRQ_REQUEST_REGISTER_BYTE_OFFSET; 240 sc->sc_podule->irq_mask = IRQ_MASK; 241 242 iobase = pa->pa_podule->easi_base; 243 244 /* Fill in wdc and channel infos */ 245 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32; 246 sc->sc_wdcdev.PIO_cap = 0; 247 sc->sc_wdcdev.channels = sc->wdc_chanarray; 248 sc->sc_wdcdev.nchannels = 2; 249 for (channel = 0 ; channel < 2; channel++) { 250 rcp = &sc->rapide_channels[channel]; 251 sc->wdc_chanarray[channel] = &rcp->wdc_channel; 252 cp = &rcp->wdc_channel; 253 254 cp->channel = channel; 255 cp->wdc = &sc->sc_wdcdev; 256 cp->ch_queue = malloc(sizeof(struct channel_queue), 257 M_DEVBUF, M_NOWAIT); 258 if (cp->ch_queue == NULL) { 259 printf("%s %s channel: can't allocate memory for " 260 "command queue", self->dv_xname, 261 (channel == 0) ? "primary" : "secondary"); 262 continue; 263 } 264 cp->cmd_iot = iot; 265 cp->ctl_iot = iot; 266 cp->data32iot = iot; 267 268 if (bus_space_map(iot, iobase + rapide_info[channel].registers, 269 DRIVE_REGISTERS_SPACE, 0, &cp->cmd_ioh)) 270 continue; 271 if (bus_space_map(iot, iobase + 272 rapide_info[channel].aux_register, 4, 0, &cp->ctl_ioh)) { 273 bus_space_unmap(iot, cp->cmd_ioh, 274 DRIVE_REGISTERS_SPACE); 275 continue; 276 } 277 if (bus_space_map(iot, iobase + 278 rapide_info[channel].data_register, 4, 0, &cp->data32ioh)) { 279 bus_space_unmap(iot, cp->cmd_ioh, 280 DRIVE_REGISTERS_SPACE); 281 bus_space_unmap(iot, cp->ctl_ioh, 4); 282 continue; 283 } 284 /* Disable interrupts and clear any pending interrupts */ 285 rcp->rc_irqmask = rapide_info[channel].irq_mask; 286 sc->sc_intr_enable_mask &= ~rcp->rc_irqmask; 287 bus_space_write_1(iot, sc->sc_ctlioh, IRQ_MASK_REGISTER_OFFSET, 288 sc->sc_intr_enable_mask); 289 /* XXX - Issue 1 cards will need to clear any pending interrupts */ 290 wdcattach(cp); 291 ihp = &rcp->rc_ih; 292 ihp->ih_func = rapide_intr; 293 ihp->ih_arg = rcp; 294 ihp->ih_level = IPL_BIO; 295 ihp->ih_name = "rapide"; 296 ihp->ih_maskaddr = pa->pa_podule->irq_addr; 297 ihp->ih_maskbits = rcp->rc_irqmask; 298 if (irq_claim(sc->sc_podule->interrupt, ihp)) 299 panic("%s: Cannot claim interrupt %d\n", 300 self->dv_xname, sc->sc_podule->interrupt); 301 /* clear any pending interrupts and enable interrupts */ 302 sc->sc_intr_enable_mask |= rcp->rc_irqmask; 303 bus_space_write_1(iot, sc->sc_ctlioh, 304 IRQ_MASK_REGISTER_OFFSET, sc->sc_intr_enable_mask); 305 /* XXX - Issue 1 cards will need to clear any pending interrupts */ 306 } 307 } 308 309 /* 310 * Card shutdown function 311 * 312 * Called via do_shutdown_hooks() during kernel shutdown. 313 * Clear the cards's interrupt mask to stop any podule interrupts. 314 */ 315 316 void 317 rapide_shutdown(arg) 318 void *arg; 319 { 320 struct rapide_softc *sc = arg; 321 322 /* Disable card interrupts */ 323 bus_space_write_1(sc->sc_ctliot, sc->sc_ctlioh, 324 IRQ_MASK_REGISTER_OFFSET, 0); 325 } 326 327 /* 328 * Podule interrupt handler 329 * 330 * If the interrupt was from our card pass it on to the wdc interrupt handler 331 */ 332 333 int 334 rapide_intr(arg) 335 void *arg; 336 { 337 struct rapide_channel *rcp = arg; 338 irqhandler_t *ihp = &rcp->rc_ih; 339 volatile u_char *intraddr = (volatile u_char *)ihp->ih_maskaddr; 340 341 /* XXX - Issue 1 cards will need to clear the interrupt */ 342 343 /* XXX - not bus space yet - should really be handled by podulebus */ 344 if ((*intraddr) & ihp->ih_maskbits) 345 wdcintr(&rcp->wdc_channel); 346 347 return(0); 348 } 349