Home | History | Annotate | Line # | Download | only in ofisa
wdc_ofisa.c revision 1.21
      1 /*	$NetBSD: wdc_ofisa.c,v 1.21 2004/08/14 15:08:06 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright 1997, 1998
      5  * Digital Equipment Corporation. All rights reserved.
      6  *
      7  * This software is furnished under license and may be used and
      8  * copied only in accordance with the following terms and conditions.
      9  * Subject to these conditions, you may download, copy, install,
     10  * use, modify and distribute this software in source and/or binary
     11  * form. No title or ownership is transferred hereby.
     12  *
     13  * 1) Any source code used, modified or distributed must reproduce
     14  *    and retain this copyright notice and list of conditions as
     15  *    they appear in the source file.
     16  *
     17  * 2) No right is granted to use any trade name, trademark, or logo of
     18  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19  *    Corporation" name nor any trademark or logo of Digital Equipment
     20  *    Corporation may be used to endorse or promote products derived
     21  *    from this software without the prior written permission of
     22  *    Digital Equipment Corporation.
     23  *
     24  * 3) This software is provided "AS-IS" and any express or implied
     25  *    warranties, including but not limited to, any implied warranties
     26  *    of merchantability, fitness for a particular purpose, or
     27  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28  *    liable for any damages whatsoever, and in particular, DIGITAL
     29  *    shall not be liable for special, indirect, consequential, or
     30  *    incidental damages or damages for lost profits, loss of
     31  *    revenue or loss of use, whether such damages arise in contract,
     32  *    negligence, tort, under statute, in equity, at law or otherwise,
     33  *    even if advised of the possibility of such damage.
     34  */
     35 
     36 /*
     37  * OFW Attachment for 'wdc' disk controller driver
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: wdc_ofisa.c,v 1.21 2004/08/14 15:08:06 thorpej Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/device.h>
     45 #include <sys/systm.h>
     46 #include <sys/tty.h>
     47 #include <sys/malloc.h>
     48 
     49 #include <machine/intr.h>
     50 #include <machine/bus.h>
     51 
     52 #include <dev/ofw/openfirm.h>
     53 #include <dev/isa/isavar.h>
     54 #include <dev/ofisa/ofisavar.h>
     55 
     56 #include <dev/ic/wdcreg.h>		/* ??? */
     57 #include <dev/ata/atavar.h>
     58 #include <dev/ic/wdcvar.h>
     59 
     60 struct wdc_ofisa_softc {
     61 	struct wdc_softc sc_wdcdev;
     62 	struct ata_channel *sc_chanlist[1];
     63 	struct ata_channel sc_channel;
     64 	struct ata_queue sc_chqueue;
     65 	struct wdc_regs wdc_regs;
     66 	void	*sc_ih;
     67 };
     68 
     69 int wdc_ofisa_probe __P((struct device *, struct cfdata *, void *));
     70 void wdc_ofisa_attach __P((struct device *, struct device *, void *));
     71 
     72 CFATTACH_DECL(wdc_ofisa, sizeof(struct wdc_ofisa_softc),
     73     wdc_ofisa_probe, wdc_ofisa_attach, NULL, NULL);
     74 
     75 int
     76 wdc_ofisa_probe(parent, cf, aux)
     77 	struct device *parent;
     78 	struct cfdata *cf;
     79 	void *aux;
     80 {
     81 	struct ofisa_attach_args *aa = aux;
     82 	static const char *const compatible_strings[] = { "pnpPNP,600", NULL };
     83 	int rv = 0;
     84 
     85 	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
     86 		rv = 5;
     87 #ifdef _WDC_OFISA_MD_MATCH
     88 	if (!rv)
     89 		rv = wdc_ofisa_md_match(parent, cf, aux);
     90 #endif
     91 	return (rv);
     92 }
     93 
     94 void
     95 wdc_ofisa_attach(parent, self, aux)
     96 	struct device *parent, *self;
     97 	void *aux;
     98 {
     99 	struct wdc_ofisa_softc *sc = (void *)self;
    100 	struct wdc_regs *wdr;
    101 	struct ofisa_attach_args *aa = aux;
    102 	struct ofisa_reg_desc reg[2];
    103 	struct ofisa_intr_desc intr;
    104 	int n;
    105 	bus_space_handle_t ioh;
    106 
    107 	/*
    108 	 * We're living on an ofw.  We have to ask the OFW what our
    109 	 * registers and interrupts properties look like.
    110 	 *
    111 	 * We expect exactly two register regions and one interrupt.
    112 	 */
    113 
    114 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    115 
    116 	n = ofisa_reg_get(aa->oba.oba_phandle, reg, 2);
    117 #ifdef _WDC_OFISA_MD_REG_FIXUP
    118 	n = wdc_ofisa_md_reg_fixup(parent, self, aux, reg, 2, n);
    119 #endif
    120 	if (n != 2) {
    121 		printf(": error getting register data\n");
    122 		return;
    123 	}
    124 	if (reg[0].len != 8 || reg[1].len != 2) {
    125 		printf(": weird register size (%lu/%lu, expected 8/2)\n",
    126 		    (unsigned long)reg[0].len, (unsigned long)reg[1].len);
    127 		return;
    128 	}
    129 
    130 	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
    131 #ifdef _WDC_OFISA_MD_INTR_FIXUP
    132 	n = wdc_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
    133 #endif
    134 	if (n != 1) {
    135 		printf(": error getting interrupt data\n");
    136 		return;
    137 	}
    138 
    139 	wdr->cmd_iot = (reg[0].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    140 	wdr->ctl_iot = (reg[1].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    141         if (bus_space_map(wdr->cmd_iot, reg[0].addr, 8, 0, &ioh) ||
    142             bus_space_map(wdr->ctl_iot, reg[1].addr, 1, 0,
    143 	      &wdr->ctl_ioh)) {
    144                 printf(": can't map register spaces\n");
    145 		return;
    146         }
    147 	wdr->cmd_baseioh = ioh;
    148 
    149 	for (n = 0; n < WDC_NREG; n++) {
    150 		if (bus_space_subregion(wdr->cmd_iot, ioh, n,
    151 		    n == 0 ? 4 : 1, &wdr->cmd_iohs[n]) != 0) {
    152                 	printf(": can't subregion register space\n");
    153 			return;
    154 		}
    155 	}
    156 	wdc_init_shadow_regs(&sc->sc_channel);
    157 
    158 	sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
    159 	    IPL_BIO, wdcintr, &sc->sc_channel);
    160 
    161 	printf("\n");
    162 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
    163 	sc->sc_chanlist[0] = &sc->sc_channel;
    164 	sc->sc_wdcdev.channels = sc->sc_chanlist;
    165 	sc->sc_wdcdev.nchannels = 1;
    166 	sc->sc_channel.ch_channel = 0;
    167 	sc->sc_channel.ch_wdc = &sc->sc_wdcdev;
    168 	sc->sc_channel.ch_queue = &sc->sc_chqueue;
    169 
    170 	wdcattach(&sc->sc_channel);
    171 
    172 #if 0
    173 	printf("%s: registers: ", sc->sc_dev.dv_xname);
    174 	ofisa_reg_print(reg, 2);
    175 	printf("\n");
    176 	printf("%s: interrupts: ", sc->sc_dev.dv_xname);
    177 	ofisa_intr_print(&intr, 1);
    178 	printf("\n");
    179 #endif
    180 }
    181