Home | History | Annotate | Line # | Download | only in eisa
      1  1.24   thorpej /*	$NetBSD: dpt_eisa.c,v 1.24 2021/01/27 04:35:15 thorpej Exp $	*/
      2   1.1        ad 
      3   1.1        ad /*
      4  1.11    keihan  * Copyright (c) 1999, 2000, 2001 Andrew Doran <ad (at) NetBSD.org>
      5   1.1        ad  * All rights reserved.
      6   1.1        ad  *
      7   1.1        ad  * Redistribution and use in source and binary forms, with or without
      8   1.1        ad  * modification, are permitted provided that the following conditions
      9   1.1        ad  * are met:
     10   1.1        ad  * 1. Redistributions of source code must retain the above copyright
     11   1.1        ad  *    notice, this list of conditions and the following disclaimer.
     12   1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     14   1.1        ad  *    documentation and/or other materials provided with the distribution.
     15   1.1        ad  *
     16   1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17   1.1        ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18   1.1        ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19   1.1        ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20   1.1        ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21   1.1        ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22   1.1        ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23   1.1        ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24   1.1        ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1        ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1        ad  * SUCH DAMAGE.
     27   1.1        ad  *
     28   1.1        ad  */
     29   1.1        ad 
     30   1.1        ad /*
     31   1.1        ad  * EISA front-end for DPT EATA SCSI driver.
     32   1.1        ad  */
     33   1.6     lukem 
     34   1.6     lukem #include <sys/cdefs.h>
     35  1.24   thorpej __KERNEL_RCSID(0, "$NetBSD: dpt_eisa.c,v 1.24 2021/01/27 04:35:15 thorpej Exp $");
     36   1.1        ad 
     37   1.1        ad #include <sys/param.h>
     38   1.1        ad #include <sys/systm.h>
     39   1.1        ad #include <sys/device.h>
     40   1.5    bouyer #include <sys/queue.h>
     41   1.1        ad 
     42  1.17        ad #include <sys/bus.h>
     43  1.17        ad #include <sys/intr.h>
     44   1.1        ad 
     45   1.1        ad #include <dev/scsipi/scsipi_all.h>
     46   1.1        ad #include <dev/scsipi/scsiconf.h>
     47   1.1        ad 
     48   1.1        ad #include <dev/eisa/eisavar.h>
     49   1.1        ad 
     50   1.1        ad #include <dev/ic/dptreg.h>
     51   1.1        ad #include <dev/ic/dptvar.h>
     52   1.1        ad 
     53  1.10        ad #include <dev/i2o/dptivar.h>
     54  1.10        ad 
     55   1.1        ad #define DPT_EISA_SLOT_OFFSET		0x0c00
     56   1.1        ad #define DPT_EISA_IOSIZE			0x0100
     57   1.1        ad #define DPT_EISA_IOCONF			0x90
     58   1.1        ad #define DPT_EISA_EATA_REG_OFFSET	0x88
     59   1.1        ad 
     60  1.20    cegger static void	dpt_eisa_attach(device_t, device_t, void *);
     61   1.5    bouyer static int	dpt_eisa_irq(bus_space_tag_t, bus_space_handle_t, int *);
     62  1.20    cegger static int	dpt_eisa_match(device_t, cfdata_t, void *);
     63   1.1        ad 
     64  1.21       chs CFATTACH_DECL_NEW(dpt_eisa, sizeof(struct dpt_softc),
     65   1.9   thorpej     dpt_eisa_match, dpt_eisa_attach, NULL, NULL);
     66   1.1        ad 
     67  1.24   thorpej static const struct device_compatible_entry compat_data[] = {
     68  1.24   thorpej 	{ .compat = "DPT2402" },
     69  1.24   thorpej 	{ .compat = "DPTA401" },
     70  1.24   thorpej 	{ .compat = "DPTA402" },
     71  1.24   thorpej 	{ .compat = "DPTA410" },
     72  1.24   thorpej 	{ .compat = "DPTA411" },
     73  1.24   thorpej 	{ .compat = "DPTA412" },
     74  1.24   thorpej 	{ .compat = "DPTA420" },
     75  1.24   thorpej 	{ .compat = "DPTA501" },
     76  1.24   thorpej 	{ .compat = "DPTA502" },
     77  1.24   thorpej 	{ .compat = "DPTA701" },
     78  1.24   thorpej 	{ .compat = "DPTBC01" },
     79  1.24   thorpej 	{ .compat = "NEC8200" },	/* OEM */
     80  1.24   thorpej 	{ .compat = "ATT2408" },	/* OEM */
     81  1.24   thorpej 	DEVICE_COMPAT_EOL
     82  1.12     perry };
     83   1.1        ad 
     84   1.5    bouyer static int
     85   1.5    bouyer dpt_eisa_irq(bus_space_tag_t iot, bus_space_handle_t ioh, int *irq)
     86   1.1        ad {
     87   1.1        ad 
     88   1.1        ad 	switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
     89   1.1        ad 	case 0x08:
     90   1.1        ad 		*irq = 11;
     91   1.1        ad 		break;
     92   1.1        ad 	case 0x10:
     93   1.1        ad 		*irq = 15;
     94   1.1        ad 		break;
     95   1.1        ad 	case 0x20:
     96   1.1        ad 		*irq = 14;
     97   1.1        ad 		break;
     98   1.1        ad 	default:
     99   1.1        ad 		return (-1);
    100   1.1        ad 	}
    101   1.1        ad 
    102   1.1        ad 	return (0);
    103   1.1        ad }
    104   1.1        ad 
    105   1.5    bouyer static int
    106  1.21       chs dpt_eisa_match(device_t parent, cfdata_t match, void *aux)
    107   1.1        ad {
    108  1.24   thorpej 	struct eisa_attach_args *ea = aux;
    109   1.1        ad 
    110  1.24   thorpej 	return eisa_compatible_match(ea, compat_data);
    111   1.1        ad }
    112   1.1        ad 
    113   1.5    bouyer static void
    114  1.20    cegger dpt_eisa_attach(device_t parent, device_t self, void *aux)
    115   1.1        ad {
    116   1.1        ad 	struct eisa_attach_args *ea;
    117   1.1        ad 	bus_space_handle_t ioh;
    118   1.1        ad 	eisa_chipset_tag_t ec;
    119   1.1        ad 	eisa_intr_handle_t ih;
    120   1.1        ad 	struct dpt_softc *sc;
    121   1.1        ad 	bus_space_tag_t iot;
    122   1.1        ad 	const char *intrstr;
    123   1.1        ad 	int irq;
    124  1.22  christos 	char intrbuf[EISA_INTRSTR_LEN];
    125  1.12     perry 
    126   1.1        ad 	ea = aux;
    127  1.14   thorpej 	sc = device_private(self);
    128  1.21       chs 	sc->sc_dev = self;
    129   1.1        ad 	iot = ea->ea_iot;
    130   1.1        ad 	ec = ea->ea_ec;
    131  1.12     perry 
    132   1.1        ad 	printf(": ");
    133   1.1        ad 
    134   1.1        ad 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    135   1.2        ad 	    DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
    136  1.23   msaitoh 		aprint_error("can't map i/o space\n");
    137   1.2        ad 		return;
    138   1.2        ad 	}
    139   1.1        ad 
    140   1.1        ad 	sc->sc_iot = iot;
    141   1.1        ad 	sc->sc_ioh = ioh;
    142   1.1        ad 	sc->sc_dmat = ea->ea_dmat;
    143   1.1        ad 
    144   1.1        ad 	/* Map and establish the interrupt. */
    145   1.2        ad 	if (dpt_eisa_irq(iot, ioh, &irq)) {
    146  1.23   msaitoh 		aprint_error("HBA on invalid IRQ\n");
    147   1.2        ad 		return;
    148   1.2        ad 	}
    149   1.1        ad 
    150   1.1        ad 	if (eisa_intr_map(ec, irq, &ih)) {
    151  1.23   msaitoh 		aprint_error("can't map interrupt (%d)\n", irq);
    152   1.1        ad 		return;
    153   1.1        ad 	}
    154  1.12     perry 
    155  1.22  christos 	intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
    156   1.1        ad 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    157   1.1        ad 	    dpt_intr, sc);
    158   1.1        ad 	if (sc->sc_ih == NULL) {
    159  1.23   msaitoh 		aprint_error("can't establish interrupt");
    160   1.1        ad 		if (intrstr != NULL)
    161  1.23   msaitoh 			aprint_error(" at %s", intrstr);
    162  1.23   msaitoh 		aprint_error("\n");
    163   1.1        ad 		return;
    164   1.1        ad 	}
    165   1.1        ad 
    166   1.5    bouyer 	/* Read the EATA configuration. */
    167   1.1        ad 	if (dpt_readcfg(sc)) {
    168  1.21       chs 		aprint_error_dev(sc->sc_dev, "readcfg failed - see dpt(4)\n");
    169  1.12     perry 		return;
    170   1.1        ad 	}
    171  1.10        ad 
    172  1.10        ad 	sc->sc_bustype = SI_EISA_BUS;
    173  1.10        ad 	sc->sc_isaport =  EISA_SLOT_ADDR(ea->ea_slot) + DPT_EISA_SLOT_OFFSET;
    174  1.10        ad 	sc->sc_isairq = irq;
    175   1.1        ad 
    176   1.5    bouyer 	/* Now attach to the bus-independent code. */
    177   1.1        ad 	dpt_init(sc, intrstr);
    178   1.1        ad }
    179