Home | History | Annotate | Line # | Download | only in ofisa
wdc_ofisa.c revision 1.40
      1  1.40   thorpej /*	$NetBSD: wdc_ofisa.c,v 1.40 2021/01/27 03:10:21 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.40   thorpej __KERNEL_RCSID(0, "$NetBSD: wdc_ofisa.c,v 1.40 2021/01/27 03:10:21 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.29        ad #include <sys/intr.h>
     50  1.29        ad #include <sys/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.25     perry 	struct ata_channel *sc_chanlist[1];
     63  1.21   thorpej 	struct ata_channel sc_channel;
     64  1.21   thorpej 	struct wdc_regs wdc_regs;
     65   1.1       cgd 	void	*sc_ih;
     66   1.1       cgd };
     67   1.1       cgd 
     68  1.30      cube static int wdc_ofisa_probe(device_t, cfdata_t, void *);
     69  1.30      cube static void wdc_ofisa_attach(device_t, device_t, void *);
     70   1.1       cgd 
     71  1.30      cube CFATTACH_DECL_NEW(wdc_ofisa, sizeof(struct wdc_ofisa_softc),
     72  1.11   thorpej     wdc_ofisa_probe, wdc_ofisa_attach, NULL, NULL);
     73   1.1       cgd 
     74  1.37   thorpej static const struct device_compatible_entry compat_data[] = {
     75  1.37   thorpej 	{ .compat = "pnpPNP,600" },
     76  1.39   thorpej 	DEVICE_COMPAT_EOL
     77  1.37   thorpej };
     78  1.37   thorpej 
     79  1.22   thorpej static int
     80  1.30      cube wdc_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
     81   1.1       cgd {
     82   1.1       cgd 	struct ofisa_attach_args *aa = aux;
     83  1.37   thorpej 	int rv;
     84   1.1       cgd 
     85  1.40   thorpej 	rv = of_compatible_match(aa->oba.oba_phandle, compat_data) ? 5 : 0;
     86   1.1       cgd #ifdef _WDC_OFISA_MD_MATCH
     87   1.1       cgd 	if (!rv)
     88   1.1       cgd 		rv = wdc_ofisa_md_match(parent, cf, aux);
     89   1.1       cgd #endif
     90   1.1       cgd 	return (rv);
     91   1.1       cgd }
     92   1.1       cgd 
     93  1.22   thorpej static void
     94  1.30      cube wdc_ofisa_attach(device_t parent, device_t self, void *aux)
     95   1.1       cgd {
     96  1.28   thorpej 	struct wdc_ofisa_softc *sc = device_private(self);
     97  1.21   thorpej 	struct wdc_regs *wdr;
     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.16      fvdl 	bus_space_handle_t ioh;
    103   1.1       cgd 
    104   1.1       cgd 	/*
    105   1.1       cgd 	 * We're living on an ofw.  We have to ask the OFW what our
    106   1.1       cgd 	 * registers and interrupts properties look like.
    107   1.1       cgd 	 *
    108   1.1       cgd 	 * We expect exactly two register regions and one interrupt.
    109   1.1       cgd 	 */
    110   1.1       cgd 
    111  1.30      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    112  1.21   thorpej 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    113  1.21   thorpej 
    114   1.2       cgd 	n = ofisa_reg_get(aa->oba.oba_phandle, reg, 2);
    115   1.1       cgd #ifdef _WDC_OFISA_MD_REG_FIXUP
    116   1.1       cgd 	n = wdc_ofisa_md_reg_fixup(parent, self, aux, reg, 2, n);
    117   1.1       cgd #endif
    118   1.1       cgd 	if (n != 2) {
    119  1.30      cube 		aprint_error(": error getting register data\n");
    120   1.1       cgd 		return;
    121   1.1       cgd 	}
    122   1.1       cgd 	if (reg[0].len != 8 || reg[1].len != 2) {
    123  1.30      cube 		aprint_error(": weird register size (%lu/%lu, expected 8/2)\n",
    124   1.2       cgd 		    (unsigned long)reg[0].len, (unsigned long)reg[1].len);
    125   1.1       cgd 		return;
    126   1.1       cgd 	}
    127   1.1       cgd 
    128   1.2       cgd 	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
    129   1.1       cgd #ifdef _WDC_OFISA_MD_INTR_FIXUP
    130   1.1       cgd 	n = wdc_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
    131   1.1       cgd #endif
    132   1.1       cgd 	if (n != 1) {
    133  1.30      cube 		aprint_error(": error getting interrupt data\n");
    134   1.1       cgd 		return;
    135   1.1       cgd 	}
    136   1.1       cgd 
    137  1.21   thorpej 	wdr->cmd_iot = (reg[0].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    138  1.21   thorpej 	wdr->ctl_iot = (reg[1].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    139  1.21   thorpej         if (bus_space_map(wdr->cmd_iot, reg[0].addr, 8, 0, &ioh) ||
    140  1.21   thorpej             bus_space_map(wdr->ctl_iot, reg[1].addr, 1, 0,
    141  1.21   thorpej 	      &wdr->ctl_ioh)) {
    142  1.30      cube                 aprint_error(": can't map register spaces\n");
    143   1.1       cgd 		return;
    144   1.1       cgd         }
    145  1.21   thorpej 	wdr->cmd_baseioh = ioh;
    146  1.16      fvdl 
    147  1.16      fvdl 	for (n = 0; n < WDC_NREG; n++) {
    148  1.21   thorpej 		if (bus_space_subregion(wdr->cmd_iot, ioh, n,
    149  1.21   thorpej 		    n == 0 ? 4 : 1, &wdr->cmd_iohs[n]) != 0) {
    150  1.30      cube                 	aprint_error(": can't subregion register space\n");
    151  1.16      fvdl 			return;
    152  1.16      fvdl 		}
    153  1.16      fvdl 	}
    154   1.1       cgd 
    155   1.3    bouyer 	sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
    156  1.21   thorpej 	    IPL_BIO, wdcintr, &sc->sc_channel);
    157   1.1       cgd 
    158  1.30      cube 	aprint_normal("\n");
    159  1.23   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    160  1.21   thorpej 	sc->sc_chanlist[0] = &sc->sc_channel;
    161  1.23   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    162  1.23   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    163  1.33    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    164  1.21   thorpej 	sc->sc_channel.ch_channel = 0;
    165  1.23   thorpej 	sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    166  1.36  jdolecek 
    167  1.35  jdolecek 	wdc_init_shadow_regs(wdr);
    168  1.24   reinoud 
    169  1.21   thorpej 	wdcattach(&sc->sc_channel);
    170   1.1       cgd 
    171   1.1       cgd #if 0
    172  1.30      cube 	aprint_verbose_dev(self, "registers: ");
    173   1.1       cgd 	ofisa_reg_print(reg, 2);
    174  1.30      cube 	aprint_verbose("\n");
    175  1.30      cube 	aprint_verbose_dev(self, "interrupts: ");
    176   1.1       cgd 	ofisa_intr_print(&intr, 1);
    177  1.30      cube 	aprint_verbose("\n");
    178   1.1       cgd #endif
    179   1.1       cgd }
    180