intio.c revision 1.29 1 1.29 tsutsui /* $NetBSD: intio.c,v 1.29 2010/12/31 22:41:55 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.7 gmcgarry * Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.3 jtc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.3 jtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1 thorpej */
31 1.1 thorpej
32 1.1 thorpej /*
33 1.1 thorpej * Autoconfiguration support for hp300 internal i/o space.
34 1.1 thorpej */
35 1.1 thorpej
36 1.8 gmcgarry #include <sys/cdefs.h>
37 1.29 tsutsui __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.29 2010/12/31 22:41:55 tsutsui Exp $");
38 1.8 gmcgarry
39 1.1 thorpej #include <sys/param.h>
40 1.1 thorpej #include <sys/systm.h>
41 1.18 tsutsui #include <sys/device.h>
42 1.7 gmcgarry
43 1.7 gmcgarry #include <machine/hp300spu.h>
44 1.7 gmcgarry
45 1.18 tsutsui #include <hp300/dev/intioreg.h>
46 1.1 thorpej #include <hp300/dev/intiovar.h>
47 1.1 thorpej
48 1.17 tsutsui struct intio_softc {
49 1.27 tsutsui device_t sc_dev;
50 1.17 tsutsui struct bus_space_tag sc_tag;
51 1.17 tsutsui };
52 1.17 tsutsui
53 1.27 tsutsui static int intiomatch(device_t, cfdata_t, void *);
54 1.27 tsutsui static void intioattach(device_t, device_t, void *);
55 1.19 thorpej static int intioprint(void *, const char *);
56 1.1 thorpej
57 1.27 tsutsui CFATTACH_DECL_NEW(intio, sizeof(struct intio_softc),
58 1.12 thorpej intiomatch, intioattach, NULL, NULL);
59 1.1 thorpej
60 1.7 gmcgarry #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
61 1.7 gmcgarry defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
62 1.7 gmcgarry defined(HP380) || defined(HP385)
63 1.19 thorpej static const struct intio_builtins intio_3xx_builtins[] = {
64 1.22 tsutsui { "rtc", RTC_BASE, -1},
65 1.22 tsutsui { "hil", HIL_BASE, 1},
66 1.22 tsutsui { "hpib", HPIB_BASE, 3},
67 1.22 tsutsui { "dma", DMA_BASE, 1},
68 1.22 tsutsui { "fb", FB_BASE, -1},
69 1.7 gmcgarry };
70 1.21 tsutsui #define nintio_3xx_builtins __arraycount(intio_3xx_builtins)
71 1.7 gmcgarry #endif
72 1.7 gmcgarry
73 1.29 tsutsui #if defined(HP362)
74 1.29 tsutsui static const struct intio_builtins intio_362_builtins[] = {
75 1.29 tsutsui { "rtc", RTC_BASE, -1},
76 1.29 tsutsui { "hil", HIL_BASE, 1},
77 1.29 tsutsui { "hpib", HPIB_BASE, 3},
78 1.29 tsutsui { "dma", DMA_BASE, 1},
79 1.29 tsutsui };
80 1.29 tsutsui #define nintio_362_builtins __arraycount(intio_362_builtins)
81 1.29 tsutsui #endif
82 1.29 tsutsui
83 1.29 tsutsui #if defined(HP382)
84 1.29 tsutsui static const struct intio_builtins intio_382_builtins[] = {
85 1.25 tsutsui { "rtc", RTC_BASE, -1},
86 1.25 tsutsui { "frodo", FRODO_BASE, 5},
87 1.25 tsutsui { "hil", HIL_BASE, 1},
88 1.25 tsutsui { "hpib", HPIB_BASE, 3},
89 1.25 tsutsui { "dma", DMA_BASE, 1},
90 1.25 tsutsui };
91 1.29 tsutsui #define nintio_382_builtins __arraycount(intio_382_builtins)
92 1.25 tsutsui #endif
93 1.25 tsutsui
94 1.7 gmcgarry #if defined(HP400) || defined(HP425) || defined(HP433)
95 1.19 thorpej static const struct intio_builtins intio_4xx_builtins[] = {
96 1.22 tsutsui { "rtc", RTC_BASE, -1},
97 1.22 tsutsui { "frodo", FRODO_BASE, 5},
98 1.22 tsutsui { "hil", HIL_BASE, 1},
99 1.22 tsutsui { "hpib", HPIB_BASE, 3},
100 1.22 tsutsui { "dma", DMA_BASE, 1},
101 1.7 gmcgarry };
102 1.21 tsutsui #define nintio_4xx_builtins __arraycount(intio_4xx_builtins)
103 1.7 gmcgarry #endif
104 1.7 gmcgarry
105 1.7 gmcgarry static int intio_matched = 0;
106 1.26 christos extern void *internalhpib;
107 1.7 gmcgarry
108 1.19 thorpej static int
109 1.27 tsutsui intiomatch(device_t parent, cfdata_t cf, void *aux)
110 1.1 thorpej {
111 1.27 tsutsui
112 1.1 thorpej /* Allow only one instance. */
113 1.1 thorpej if (intio_matched)
114 1.21 tsutsui return 0;
115 1.1 thorpej
116 1.1 thorpej intio_matched = 1;
117 1.21 tsutsui return 1;
118 1.1 thorpej }
119 1.1 thorpej
120 1.19 thorpej static void
121 1.27 tsutsui intioattach(device_t parent, device_t self, void *aux)
122 1.1 thorpej {
123 1.27 tsutsui struct intio_softc *sc = device_private(self);
124 1.7 gmcgarry struct intio_attach_args ia;
125 1.7 gmcgarry const struct intio_builtins *ib;
126 1.17 tsutsui bus_space_tag_t bst = &sc->sc_tag;
127 1.7 gmcgarry int ndevs;
128 1.7 gmcgarry int i;
129 1.1 thorpej
130 1.27 tsutsui sc->sc_dev = self;
131 1.27 tsutsui aprint_normal("\n");
132 1.1 thorpej
133 1.17 tsutsui memset(bst, 0, sizeof(struct bus_space_tag));
134 1.17 tsutsui bst->bustype = HP300_BUS_SPACE_INTIO;
135 1.17 tsutsui
136 1.7 gmcgarry switch (machineid) {
137 1.7 gmcgarry #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
138 1.7 gmcgarry defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
139 1.7 gmcgarry defined(HP380) || defined(HP385)
140 1.7 gmcgarry case HP_320:
141 1.7 gmcgarry case HP_330:
142 1.7 gmcgarry case HP_340:
143 1.7 gmcgarry case HP_345:
144 1.7 gmcgarry case HP_350:
145 1.7 gmcgarry case HP_360:
146 1.7 gmcgarry case HP_370:
147 1.7 gmcgarry case HP_375:
148 1.7 gmcgarry case HP_380:
149 1.7 gmcgarry case HP_385:
150 1.7 gmcgarry ib = intio_3xx_builtins;
151 1.7 gmcgarry ndevs = nintio_3xx_builtins;
152 1.7 gmcgarry break;
153 1.7 gmcgarry #endif
154 1.29 tsutsui #if defined(HP362)
155 1.25 tsutsui case HP_362:
156 1.29 tsutsui ib = intio_362_builtins;
157 1.29 tsutsui ndevs = nintio_362_builtins;
158 1.29 tsutsui break;
159 1.29 tsutsui #endif
160 1.29 tsutsui #if defined(HP382)
161 1.25 tsutsui case HP_382:
162 1.29 tsutsui ib = intio_382_builtins;
163 1.29 tsutsui ndevs = nintio_382_builtins;
164 1.25 tsutsui break;
165 1.25 tsutsui #endif
166 1.7 gmcgarry #if defined(HP400) || defined(HP425) || defined(HP433)
167 1.7 gmcgarry case HP_400:
168 1.7 gmcgarry case HP_425:
169 1.7 gmcgarry case HP_433:
170 1.7 gmcgarry ib = intio_4xx_builtins;
171 1.7 gmcgarry ndevs = nintio_4xx_builtins;
172 1.7 gmcgarry break;
173 1.7 gmcgarry #endif
174 1.7 gmcgarry default:
175 1.7 gmcgarry return;
176 1.7 gmcgarry }
177 1.7 gmcgarry
178 1.7 gmcgarry memset(&ia, 0, sizeof(ia));
179 1.7 gmcgarry
180 1.16 tsutsui for (i = 0; i < ndevs; i++) {
181 1.15 gmcgarry
182 1.15 gmcgarry /*
183 1.15 gmcgarry * Internal HP-IB doesn't always return a device ID,
184 1.15 gmcgarry * so we rely on the sysflags.
185 1.15 gmcgarry */
186 1.22 tsutsui if (ib[i].ib_offset == HPIB_BASE && !internalhpib)
187 1.15 gmcgarry continue;
188 1.15 gmcgarry
189 1.23 tsutsui strlcpy(ia.ia_modname, ib[i].ib_modname,
190 1.24 tsutsui sizeof(ia.ia_modname));
191 1.17 tsutsui ia.ia_bst = bst;
192 1.7 gmcgarry ia.ia_iobase = ib[i].ib_offset;
193 1.7 gmcgarry ia.ia_addr = (bus_addr_t)(intiobase + ib[i].ib_offset);
194 1.7 gmcgarry ia.ia_ipl = ib[i].ib_ipl;
195 1.7 gmcgarry config_found(self, &ia, intioprint);
196 1.7 gmcgarry }
197 1.1 thorpej }
198 1.1 thorpej
199 1.19 thorpej static int
200 1.19 thorpej intioprint(void *aux, const char *pnp)
201 1.1 thorpej {
202 1.1 thorpej struct intio_attach_args *ia = aux;
203 1.1 thorpej
204 1.9 gmcgarry if (pnp != NULL)
205 1.14 thorpej aprint_normal("%s at %s", ia->ia_modname, pnp);
206 1.15 gmcgarry if (ia->ia_iobase != 0 && pnp == NULL) {
207 1.15 gmcgarry aprint_normal(" addr 0x%lx", INTIOBASE + ia->ia_iobase);
208 1.15 gmcgarry if (ia->ia_ipl != -1)
209 1.14 thorpej aprint_normal(" ipl %d", ia->ia_ipl);
210 1.7 gmcgarry }
211 1.21 tsutsui return UNCONF;
212 1.1 thorpej }
213