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