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