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