xref: /netbsd-src/sys/arch/x68k/dev/grf_machdep.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: grf_machdep.c,v 1.19 2004/01/25 13:17:00 minoura Exp $	*/
2 
3 /*
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
36  *
37  *	@(#)grf_machdep.c	8.2 (Berkeley) 1/12/94
38  */
39 /*
40  * Copyright (c) 1991 University of Utah.
41  *
42  * This code is derived from software contributed to Berkeley by
43  * the Systems Programming Group of the University of Utah Computer
44  * Science Department.
45  *
46  * Redistribution and use in source and binary forms, with or without
47  * modification, are permitted provided that the following conditions
48  * are met:
49  * 1. Redistributions of source code must retain the above copyright
50  *    notice, this list of conditions and the following disclaimer.
51  * 2. Redistributions in binary form must reproduce the above copyright
52  *    notice, this list of conditions and the following disclaimer in the
53  *    documentation and/or other materials provided with the distribution.
54  * 3. All advertising materials mentioning features or use of this software
55  *    must display the following acknowledgement:
56  *	This product includes software developed by the University of
57  *	California, Berkeley and its contributors.
58  * 4. Neither the name of the University nor the names of its contributors
59  *    may be used to endorse or promote products derived from this software
60  *    without specific prior written permission.
61  *
62  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72  * SUCH DAMAGE.
73  *
74  * from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
75  *
76  *	@(#)grf_machdep.c	8.2 (Berkeley) 1/12/94
77  */
78 
79 /*
80  * Graphics display driver for the HP300/400 DIO/DIO-II based machines.
81  * This is the hardware-dependent configuration portion of the driver.
82  */
83 
84 #include <sys/cdefs.h>
85 __KERNEL_RCSID(0, "$NetBSD: grf_machdep.c,v 1.19 2004/01/25 13:17:00 minoura Exp $");
86 
87 #include <sys/param.h>
88 #include <sys/systm.h>
89 #include <sys/device.h>
90 
91 #include <machine/grfioctl.h>
92 #include <x68k/dev/grfvar.h>
93 #include <x68k/x68k/iodevice.h>
94 
95 /*
96  * false when initing for the console.
97  */
98 extern int x68k_realconfig;
99 extern int x68k_config_found(struct cfdata *, struct device *,
100 			     void *, cfprint_t);
101 
102 /* grfbus: is this necessary? */
103 int grfbusprint(void *auxp, const char *);
104 int grfbusmatch(struct device *, struct cfdata *, void *);
105 void grfbusattach(struct device *, struct device *, void *);
106 int grfbussearch(struct device *, struct cfdata *, void *);
107 
108 /* grf itself */
109 void grfattach(struct device *, struct device *, void *);
110 int grfmatch(struct device *, struct cfdata *, void *);
111 int grfprint(void *, const char *);
112 
113 static int grfinit(void *, int);
114 
115 CFATTACH_DECL(grfbus, sizeof(struct device),
116     grfbusmatch, grfbusattach, NULL, NULL);
117 
118 CFATTACH_DECL(grf, sizeof(struct grf_softc),
119     grfmatch, grfattach, NULL, NULL);
120 
121 /*
122  * only used in console init.
123  */
124 static struct cfdata *cfdata_gbus  = NULL;
125 static struct cfdata *cfdata_grf   = NULL;
126 
127 extern struct cfdriver grfbus_cd;
128 
129 int
130 grfbusmatch(pdp, cfp, auxp)
131 	struct device *pdp;
132 	struct cfdata *cfp;
133 	void *auxp;
134 {
135 	if (strcmp(auxp, grfbus_cd.cd_name))
136 		return(0);
137 
138 	if((x68k_realconfig == 0) || (cfdata_gbus == NULL)) {
139 		/*
140 		 * Probe layers we depend on
141 		 */
142 		if(x68k_realconfig == 0) {
143 			cfdata_gbus = cfp;
144 		}
145 	}
146 	return(1);	/* Always there	*/
147 }
148 
149 void
150 grfbusattach(pdp, dp, auxp)
151 	struct device *pdp, *dp;
152 	void *auxp;
153 {
154 	int i;
155 
156 	if (dp == NULL) {
157 		i = 0;
158 		x68k_config_found(cfdata_gbus, NULL, (void*)&i, grfbusprint);
159 	} else {
160 		printf("\n");
161 		config_search(grfbussearch, dp, NULL);
162 	}
163 }
164 
165 int
166 grfbussearch(dp, match, aux)
167 	struct device *dp;
168 	struct cfdata *match;
169 
170 	void *aux;
171 {
172 	int i = 0;
173 	config_found(dp, (void*)&i, grfbusprint);
174 	return (0);
175 }
176 
177 int
178 grfbusprint(auxp, name)
179 	void *auxp;
180 	const char *name;
181 {
182 	if(name == NULL)
183 		return(UNCONF);
184 	return(QUIET);
185 }
186 
187 /*
188  * Normal init routine called by configure() code
189  */
190 int
191 grfmatch(parent, cfp, aux)
192 	struct device *parent;
193 	struct cfdata *cfp;
194 	void *aux;
195 {
196 	/* XXX console at grf0 */
197 	if (x68k_realconfig == 0) {
198 		if (cfp->cf_unit != 0)
199 			return(0);
200 		cfdata_grf = cfp;
201 	}
202 	return(1);
203 }
204 
205 static struct grf_softc	congrf;
206 
207 void
208 grfattach(parent, dp, aux)
209 	struct device *parent;
210 	struct device *dp;
211 	void *aux;
212 {
213 	struct grf_softc *gp;
214 
215 	/*
216 	 * Handle exeption case: early console init
217 	 */
218 	if(dp == NULL) {
219 		/* Attach console ite */
220 		grfinit(&congrf, 0);
221 		x68k_config_found(cfdata_grf, NULL, &congrf, grfprint);
222 		return;
223 	}
224 
225 	grfinit(dp, dp->dv_unit);
226 
227 	gp = (struct grf_softc *)dp;
228 	printf(": %d x %d ", gp->g_display.gd_dwidth,
229 	    gp->g_display.gd_dheight);
230 	if (gp->g_display.gd_colors == 2)
231 		printf("monochrome");
232 	else
233 		printf("%d colors", gp->g_display.gd_colors);
234 	printf(" %s display\n", gp->g_sw->gd_desc);
235 
236 	/*
237 	 * try and attach an ite
238 	 */
239 	config_found(dp, gp, grfprint);
240 }
241 
242 int
243 grfprint(auxp, pnp)
244 void *auxp;
245 const char *pnp;
246 {
247 	if(pnp)
248 		aprint_normal("ite at %s", pnp);
249 	return UNCONF;
250 }
251 
252 int
253 grfinit(dp, unit)
254 	void *dp;
255 	int unit;
256 {
257 	struct grf_softc *gp = dp;
258 	register struct grfsw *gsw;
259 	caddr_t addr;
260 
261 	if (unit == 0)
262 		addr = (caddr_t)IODEVbase->tvram;
263 	else
264 		addr = (caddr_t)IODEVbase->gvram;
265 
266 	gsw = &grfsw[unit];
267 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
268 		gp->g_sw = gsw;
269 		gp->g_display.gd_id = gsw->gd_swid;
270 		gp->g_flags = GF_ALIVE;
271 		return 1;
272 	}
273 
274 	return 0;
275 }
276