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