Home | History | Annotate | Line # | Download | only in ofisa
      1 /*	$NetBSD: wdc_ofisa.c,v 1.41 2022/09/25 17:29:22 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.41 2022/09/25 17:29:22 thorpej Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/device.h>
     45 #include <sys/systm.h>
     46 #include <sys/tty.h>
     47 
     48 #include <sys/intr.h>
     49 #include <sys/bus.h>
     50 
     51 #include <dev/ofw/openfirm.h>
     52 #include <dev/isa/isavar.h>
     53 #include <dev/ofisa/ofisavar.h>
     54 
     55 #include <dev/ic/wdcreg.h>		/* ??? */
     56 #include <dev/ata/atavar.h>
     57 #include <dev/ic/wdcvar.h>
     58 
     59 struct wdc_ofisa_softc {
     60 	struct wdc_softc sc_wdcdev;
     61 	struct ata_channel *sc_chanlist[1];
     62 	struct ata_channel sc_channel;
     63 	struct wdc_regs wdc_regs;
     64 	void	*sc_ih;
     65 };
     66 
     67 static int wdc_ofisa_probe(device_t, cfdata_t, void *);
     68 static void wdc_ofisa_attach(device_t, device_t, void *);
     69 
     70 CFATTACH_DECL_NEW(wdc_ofisa, sizeof(struct wdc_ofisa_softc),
     71     wdc_ofisa_probe, wdc_ofisa_attach, NULL, NULL);
     72 
     73 static const struct device_compatible_entry compat_data[] = {
     74 	{ .compat = "pnpPNP,600" },
     75 	DEVICE_COMPAT_EOL
     76 };
     77 
     78 static int
     79 wdc_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
     80 {
     81 	struct ofisa_attach_args *aa = aux;
     82 	int rv;
     83 
     84 	rv = of_compatible_match(aa->oba.oba_phandle, compat_data) ? 5 : 0;
     85 #ifdef _WDC_OFISA_MD_MATCH
     86 	if (!rv)
     87 		rv = wdc_ofisa_md_match(parent, cf, aux);
     88 #endif
     89 	return (rv);
     90 }
     91 
     92 static void
     93 wdc_ofisa_attach(device_t parent, device_t self, void *aux)
     94 {
     95 	struct wdc_ofisa_softc *sc = device_private(self);
     96 	struct wdc_regs *wdr;
     97 	struct ofisa_attach_args *aa = aux;
     98 	struct ofisa_reg_desc reg[2];
     99 	struct ofisa_intr_desc intr;
    100 	int n;
    101 	bus_space_handle_t ioh;
    102 
    103 	/*
    104 	 * We're living on an ofw.  We have to ask the OFW what our
    105 	 * registers and interrupts properties look like.
    106 	 *
    107 	 * We expect exactly two register regions and one interrupt.
    108 	 */
    109 
    110 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    111 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    112 
    113 	n = ofisa_reg_get(aa->oba.oba_phandle, reg, 2);
    114 #ifdef _WDC_OFISA_MD_REG_FIXUP
    115 	n = wdc_ofisa_md_reg_fixup(parent, self, aux, reg, 2, n);
    116 #endif
    117 	if (n != 2) {
    118 		aprint_error(": error getting register data\n");
    119 		return;
    120 	}
    121 	if (reg[0].len != 8 || reg[1].len != 2) {
    122 		aprint_error(": weird register size (%lu/%lu, expected 8/2)\n",
    123 		    (unsigned long)reg[0].len, (unsigned long)reg[1].len);
    124 		return;
    125 	}
    126 
    127 	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
    128 #ifdef _WDC_OFISA_MD_INTR_FIXUP
    129 	n = wdc_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
    130 #endif
    131 	if (n != 1) {
    132 		aprint_error(": error getting interrupt data\n");
    133 		return;
    134 	}
    135 
    136 	wdr->cmd_iot = (reg[0].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    137 	wdr->ctl_iot = (reg[1].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    138         if (bus_space_map(wdr->cmd_iot, reg[0].addr, 8, 0, &ioh) ||
    139             bus_space_map(wdr->ctl_iot, reg[1].addr, 1, 0,
    140 	      &wdr->ctl_ioh)) {
    141                 aprint_error(": can't map register spaces\n");
    142 		return;
    143         }
    144 	wdr->cmd_baseioh = ioh;
    145 
    146 	for (n = 0; n < WDC_NREG; n++) {
    147 		if (bus_space_subregion(wdr->cmd_iot, ioh, n,
    148 		    n == 0 ? 4 : 1, &wdr->cmd_iohs[n]) != 0) {
    149                 	aprint_error(": can't subregion register space\n");
    150 			return;
    151 		}
    152 	}
    153 
    154 	sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
    155 	    IPL_BIO, wdcintr, &sc->sc_channel);
    156 
    157 	aprint_normal("\n");
    158 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    159 	sc->sc_chanlist[0] = &sc->sc_channel;
    160 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    161 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    162 	sc->sc_wdcdev.wdc_maxdrives = 2;
    163 	sc->sc_channel.ch_channel = 0;
    164 	sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    165 
    166 	wdc_init_shadow_regs(wdr);
    167 
    168 	wdcattach(&sc->sc_channel);
    169 
    170 #if 0
    171 	aprint_verbose_dev(self, "registers: ");
    172 	ofisa_reg_print(reg, 2);
    173 	aprint_verbose("\n");
    174 	aprint_verbose_dev(self, "interrupts: ");
    175 	ofisa_intr_print(&intr, 1);
    176 	aprint_verbose("\n");
    177 #endif
    178 }
    179