xref: /netbsd-src/sys/arch/hp300/dev/intio.c (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: intio.c,v 1.15 2003/05/24 06:21:22 gmcgarry 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Autoconfiguration support for hp300 internal i/o space.
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.15 2003/05/24 06:21:22 gmcgarry Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/device.h>
49 
50 #include <machine/hp300spu.h>
51 
52 #include <hp300/dev/intioreg.h>
53 #include <hp300/dev/intiovar.h>
54 
55 int	intiomatch(struct device *, struct cfdata *, void *);
56 void	intioattach(struct device *, struct device *, void *);
57 int	intioprint(void *, const char *);
58 
59 CFATTACH_DECL(intio, sizeof(struct device),
60     intiomatch, intioattach, NULL, NULL);
61 
62 #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
63     defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
64     defined(HP380) || defined(HP385)
65 const struct intio_builtins intio_3xx_builtins[] = {
66 	{ "rtc",	0x020000,	-1},
67 	{ "hil",	0x028000,	1},
68 	{ "hpib",	0x078000,	3},
69 	{ "dma",	0x100000,	1},
70 	{ "fb",		0x160000,	-1},
71 };
72 #define nintio_3xx_builtins \
73 	(sizeof(intio_3xx_builtins) / sizeof(intio_3xx_builtins[0]))
74 #endif
75 
76 #if defined(HP400) || defined(HP425) || defined(HP433)
77 const struct intio_builtins intio_4xx_builtins[] = {
78 	{ "rtc",	0x020000,	-1},
79 	{ "frodo",	0x01c000,	5},
80 	{ "hil",	0x028000,	1},
81 	{ "hpib",	0x078000,	3},
82 	{ "dma",	0x100000,	1},
83 };
84 #define nintio_4xx_builtins \
85 	(sizeof(intio_4xx_builtins) / sizeof(intio_4xx_builtins[0]))
86 #endif
87 
88 static int intio_matched = 0;
89 extern caddr_t internalhpib;
90 
91 int
92 intiomatch(parent, match, aux)
93 	struct device *parent;
94 	struct cfdata *match;
95 	void *aux;
96 {
97 	/* Allow only one instance. */
98 	if (intio_matched)
99 		return (0);
100 
101 	intio_matched = 1;
102 	return (1);
103 }
104 
105 void
106 intioattach(parent, self, aux)
107 	struct device *parent, *self;
108 	void *aux;
109 {
110 	struct intio_attach_args ia;
111 	const struct intio_builtins *ib;
112 	int ndevs;
113 	int i;
114 
115 	printf("\n");
116 
117 	switch (machineid) {
118 #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
119     defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
120     defined(HP380) || defined(HP385)
121 	case HP_320:
122 	case HP_330:
123 	case HP_340:
124 	case HP_345:
125 	case HP_350:
126 	case HP_360:
127 	case HP_370:
128 	case HP_375:
129 	case HP_380:
130 	case HP_385:
131 		ib = intio_3xx_builtins;
132 		ndevs = nintio_3xx_builtins;
133 		break;
134 #endif
135 #if defined(HP400) || defined(HP425) || defined(HP433)
136 	case HP_400:
137 	case HP_425:
138 	case HP_433:
139 		ib = intio_4xx_builtins;
140 		ndevs = nintio_4xx_builtins;
141 		break;
142 #endif
143 	default:
144 		return;
145 	}
146 
147 	memset(&ia, 0, sizeof(ia));
148 
149 	for (i=0; i<ndevs; i++) {
150 
151 		/*
152 		 * Internal HP-IB doesn't always return a device ID,
153 		 * so we rely on the sysflags.
154 		 */
155 		if (ib[i].ib_offset == 0x078000 && !internalhpib)
156 			continue;
157 
158 		strncpy(ia.ia_modname, ib[i].ib_modname, INTIO_MOD_LEN);
159 		ia.ia_modname[INTIO_MOD_LEN] = '\0';
160 		ia.ia_bst = HP300_BUS_SPACE_INTIO;
161 		ia.ia_iobase = ib[i].ib_offset;
162 		ia.ia_addr = (bus_addr_t)(intiobase + ib[i].ib_offset);
163 		ia.ia_ipl = ib[i].ib_ipl;
164 		config_found(self, &ia, intioprint);
165 	}
166 }
167 
168 int
169 intioprint(aux, pnp)
170 	void *aux;
171 	const char *pnp;
172 {
173 	struct intio_attach_args *ia = aux;
174 
175 	if (pnp != NULL)
176 		aprint_normal("%s at %s", ia->ia_modname, pnp);
177 	if (ia->ia_iobase != 0 && pnp == NULL) {
178 		aprint_normal(" addr 0x%lx", INTIOBASE + ia->ia_iobase);
179 		if (ia->ia_ipl != -1)
180 			aprint_normal(" ipl %d", ia->ia_ipl);
181 	}
182 	return (UNCONF);
183 }
184