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