Home | History | Annotate | Line # | Download | only in eisa
dpt_eisa.c revision 1.1.2.1
      1  1.1.2.1  wrstuden /*	$NetBSD: dpt_eisa.c,v 1.1.2.1 1999/12/27 18:34:41 wrstuden Exp $	*/
      2      1.1        ad 
      3      1.1        ad /*
      4      1.1        ad  * Copyright (c) 1999 Andy 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.1        ad 
     34      1.1        ad #include <sys/cdefs.h>
     35  1.1.2.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: dpt_eisa.c,v 1.1.2.1 1999/12/27 18:34:41 wrstuden Exp $");
     36      1.1        ad 
     37      1.1        ad #include <sys/types.h>
     38      1.1        ad #include <sys/param.h>
     39      1.1        ad #include <sys/systm.h>
     40      1.1        ad #include <sys/device.h>
     41      1.1        ad 
     42      1.1        ad #include <machine/bus.h>
     43      1.1        ad #include <machine/intr.h>
     44      1.1        ad 
     45      1.1        ad #include <dev/scsipi/scsi_all.h>
     46      1.1        ad #include <dev/scsipi/scsipi_all.h>
     47      1.1        ad #include <dev/scsipi/scsiconf.h>
     48      1.1        ad 
     49      1.1        ad #include <dev/eisa/eisavar.h>
     50      1.1        ad #include <dev/eisa/eisadevs.h>
     51      1.1        ad 
     52      1.1        ad #include <dev/ic/dptreg.h>
     53      1.1        ad #include <dev/ic/dptvar.h>
     54      1.1        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.1        ad int	dpt_eisa_irq __P((bus_space_tag_t, bus_space_handle_t, int *));
     61      1.1        ad int	dpt_eisa_match __P((struct device *, struct cfdata *, void *));
     62      1.1        ad void	dpt_eisa_attach __P((struct device *, struct device *, void *));
     63      1.1        ad 
     64      1.1        ad struct cfattach dpt_eisa_ca = {
     65      1.1        ad 	sizeof(struct dpt_softc), dpt_eisa_match, dpt_eisa_attach
     66      1.1        ad };
     67      1.1        ad 
     68      1.1        ad const char *dpt_eisa_boards[] = {
     69      1.1        ad 	"DPT2402",
     70      1.1        ad 	"DPTA401",
     71      1.1        ad 	"DPTA402",
     72      1.1        ad 	"DPTA410",
     73      1.1        ad 	"DPTA411",
     74      1.1        ad 	"DPTA412",
     75      1.1        ad 	"DPTA420",
     76      1.1        ad 	"DPTA501",
     77      1.1        ad 	"DPTA502",
     78      1.1        ad 	"DPTA701",
     79      1.1        ad 	"DPTBC01",
     80      1.1        ad 	"NEC8200",	/* OEM */
     81      1.1        ad 	"ATT2408",	/* OEM */
     82      1.1        ad 	NULL
     83      1.1        ad };
     84      1.1        ad 
     85      1.1        ad int
     86      1.1        ad dpt_eisa_irq(iot, ioh, irq)
     87      1.1        ad 	bus_space_tag_t iot;
     88      1.1        ad 	bus_space_handle_t ioh;
     89      1.1        ad 	int *irq;
     90      1.1        ad {
     91      1.1        ad 
     92      1.1        ad 	switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
     93      1.1        ad 	case 0x08:
     94      1.1        ad 		*irq = 11;
     95      1.1        ad 		break;
     96      1.1        ad 	case 0x10:
     97      1.1        ad 		*irq = 15;
     98      1.1        ad 		break;
     99      1.1        ad 	case 0x20:
    100      1.1        ad 		*irq = 14;
    101      1.1        ad 		break;
    102      1.1        ad 	default:
    103      1.1        ad 		return (-1);
    104      1.1        ad 	}
    105      1.1        ad 
    106      1.1        ad 	return (0);
    107      1.1        ad }
    108      1.1        ad 
    109      1.1        ad int
    110      1.1        ad dpt_eisa_match(parent, match, aux)
    111      1.1        ad 	struct device *parent;
    112      1.1        ad 	struct cfdata *match;
    113      1.1        ad 	void *aux;
    114      1.1        ad {
    115      1.1        ad 	struct eisa_attach_args *ea;
    116      1.1        ad 	int i;
    117      1.1        ad 
    118      1.1        ad 	ea = aux;
    119      1.1        ad 
    120      1.1        ad 	for (i = 0; dpt_eisa_boards[i] != NULL; i++)
    121      1.1        ad 		if (strcmp(ea->ea_idstring, dpt_eisa_boards[i]) == 0)
    122      1.1        ad 			break;
    123      1.1        ad 
    124      1.1        ad 	return (dpt_eisa_boards[i] != NULL);
    125      1.1        ad }
    126      1.1        ad 
    127      1.1        ad void
    128      1.1        ad dpt_eisa_attach(parent, self, aux)
    129      1.1        ad 	struct device *parent, *self;
    130      1.1        ad 	void *aux;
    131      1.1        ad {
    132      1.1        ad 	struct eisa_attach_args *ea;
    133      1.1        ad 	bus_space_handle_t ioh;
    134      1.1        ad 	eisa_chipset_tag_t ec;
    135      1.1        ad 	eisa_intr_handle_t ih;
    136      1.1        ad 	struct dpt_softc *sc;
    137      1.1        ad 	bus_space_tag_t iot;
    138      1.1        ad 	const char *intrstr;
    139      1.1        ad 	int irq;
    140      1.1        ad 
    141      1.1        ad 	ea = aux;
    142      1.1        ad 	sc = (struct dpt_softc *)self;
    143      1.1        ad 	iot = ea->ea_iot;
    144      1.1        ad 	ec = ea->ea_ec;
    145      1.1        ad 
    146      1.1        ad 	printf(": ");
    147      1.1        ad 
    148      1.1        ad 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    149  1.1.2.1  wrstuden 	    DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
    150  1.1.2.1  wrstuden 		printf("can't map i/o space\n");
    151  1.1.2.1  wrstuden 		return;
    152  1.1.2.1  wrstuden 	}
    153      1.1        ad 
    154      1.1        ad 	sc->sc_iot = iot;
    155      1.1        ad 	sc->sc_ioh = ioh;
    156      1.1        ad 	sc->sc_dmat = ea->ea_dmat;
    157      1.1        ad 
    158      1.1        ad 	/* Map and establish the interrupt. */
    159  1.1.2.1  wrstuden 	if (dpt_eisa_irq(iot, ioh, &irq)) {
    160  1.1.2.1  wrstuden 		printf("HBA on invalid IRQ (%d)\n", irq);
    161  1.1.2.1  wrstuden 		return;
    162  1.1.2.1  wrstuden 	}
    163      1.1        ad 
    164      1.1        ad 	if (eisa_intr_map(ec, irq, &ih)) {
    165      1.1        ad 		printf("can't map interrupt (%d)\n", irq);
    166      1.1        ad 		return;
    167      1.1        ad 	}
    168      1.1        ad 
    169      1.1        ad 	intrstr = eisa_intr_string(ec, ih);
    170      1.1        ad 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    171      1.1        ad 	    dpt_intr, sc);
    172      1.1        ad 	if (sc->sc_ih == NULL) {
    173      1.1        ad 		printf("can't establish interrupt");
    174      1.1        ad 		if (intrstr != NULL)
    175      1.1        ad 			printf(" at %s", intrstr);
    176      1.1        ad 		printf("\n");
    177      1.1        ad 		return;
    178      1.1        ad 	}
    179      1.1        ad 
    180      1.1        ad 	/* Read the EATA configuration */
    181      1.1        ad 	if (dpt_readcfg(sc)) {
    182      1.1        ad 		printf("%s: readcfg failed - see dpt(4)\n",
    183      1.1        ad 		    sc->sc_dv.dv_xname);
    184      1.1        ad 		return;
    185      1.1        ad 	}
    186      1.1        ad 
    187      1.1        ad 	/* Now attach to the bus-independant code */
    188      1.1        ad 	dpt_init(sc, intrstr);
    189      1.1        ad }
    190