xref: /netbsd/sys/arch/x68k/dev/grf_machdep.c (revision c4a72b64)
1 /*	$NetBSD: grf_machdep.c,v 1.15 2002/10/02 16:02:39 thorpej 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 <machine/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 int x68k_config_found __P((struct cfdata *, struct device *,
63 			   void *, cfprint_t));
64 
65 int grfbusprint __P((void *auxp, const char *));
66 int grfbusmatch __P((struct device *, struct cfdata *, void *));
67 void grfbusattach __P((struct device *, struct device *, void *));
68 int grfbussearch __P((struct device *, struct cfdata *, void *));
69 
70 void grfattach __P((struct device *, struct device *, void *));
71 int grfmatch __P((struct device *, struct cfdata *, void *));
72 int grfprint __P((void *, const char *));
73 
74 void grfconfig __P((struct device *));
75 int grfinit __P((void *, int));
76 
77 CFATTACH_DECL(grfbus, sizeof(struct device),
78     grfbusmatch, grfbusattach, NULL, NULL);
79 
80 CFATTACH_DECL(grf, sizeof(struct grf_softc),
81     grfmatch, grfattach, NULL, NULL);
82 
83 /*
84  * only used in console init.
85  */
86 static struct cfdata *cfdata_gbus  = NULL;
87 static struct cfdata *cfdata_grf   = NULL;
88 
89 extern struct cfdriver grfbus_cd;
90 
91 int
92 grfbusmatch(pdp, cfp, auxp)
93 	struct device *pdp;
94 	struct cfdata *cfp;
95 	void *auxp;
96 {
97 	if (strcmp(auxp, grfbus_cd.cd_name))
98 		return(0);
99 
100 	if((x68k_realconfig == 0) || (cfdata_gbus == NULL)) {
101 		/*
102 		 * Probe layers we depend on
103 		 */
104 		if(x68k_realconfig == 0) {
105 			cfdata_gbus = cfp;
106 		}
107 	}
108 	return(1);	/* Always there	*/
109 }
110 
111 void
112 grfbusattach(pdp, dp, auxp)
113 	struct device *pdp, *dp;
114 	void *auxp;
115 {
116 	int i;
117 
118 	if (dp == NULL) {
119 		i = 0;
120 		x68k_config_found(cfdata_gbus, NULL, (void*)&i, grfbusprint);
121 	} else {
122 		printf("\n");
123 		config_search(grfbussearch, dp, NULL);
124 	}
125 }
126 
127 int
128 grfbussearch(dp, match, aux)
129 	struct device *dp;
130 	struct cfdata *match;
131 
132 	void *aux;
133 {
134 	int i = 0;
135 	config_found(dp, (void*)&i, grfbusprint);
136 	return (0);
137 }
138 
139 int
140 grfbusprint(auxp, name)
141 	void *auxp;
142 	const char *name;
143 {
144 	if(name == NULL)
145 		return(UNCONF);
146 	return(QUIET);
147 }
148 
149 static struct grf_softc	congrf;
150 /*
151  * XXX called from ite console init routine.
152  * Does just what configure will do later but without printing anything.
153  */
154 void
155 grfconfig(dp)
156 	struct device *dp;
157 {
158 	int unit;
159 	if (!dp)
160 		dp = (void *)&congrf;
161 	unit = dp->dv_unit;
162 
163 	grfinit(dp, unit); /* XXX */
164 }
165 
166 /*
167  * Normal init routine called by configure() code
168  */
169 int
170 grfmatch(parent, cfp, aux)
171 	struct device *parent;
172 	struct cfdata *cfp;
173 	void *aux;
174 {
175 	/* XXX console at grf0 */
176 	if (x68k_realconfig == 0) {
177 		if (cfp->cf_unit != 0)
178 			return(0);
179 		cfdata_grf = cfp;
180 	}
181 	return(1);
182 }
183 
184 void
185 grfattach(parent, dp, aux)
186 	struct device *parent;
187 	struct device *dp;
188 	void *aux;
189 {
190 /*	static struct grf_softc	congrf;*/
191 	struct grf_softc *gp;
192 
193 	grfconfig(dp);
194 	/*
195 	 * Handle exeption case: early console init
196 	 */
197 	if(dp == NULL) {
198 		/* Attach console ite */
199 		x68k_config_found(cfdata_grf, NULL, &congrf, grfprint);
200 		return;
201 	}
202 	gp = (struct grf_softc *)dp;
203 	printf(": %d x %d ", gp->g_display.gd_dwidth,
204 	    gp->g_display.gd_dheight);
205 	if (gp->g_display.gd_colors == 2)
206 		printf("monochrome");
207 	else
208 		printf("%d colors", gp->g_display.gd_colors);
209 	printf(" %s display\n", gp->g_sw->gd_desc);
210 
211 	/*
212 	 * try and attach an ite
213 	 */
214 	config_found(dp, gp, grfprint);
215 }
216 
217 int
218 grfprint(auxp, pnp)
219 void *auxp;
220 const char *pnp;
221 {
222 	if(pnp)
223 		printf("ite at %s", pnp);
224 	return(UNCONF);
225 }
226 
227 int
228 grfinit(dp, unit)
229 	void *dp;
230 	int unit;
231 {
232 	struct grf_softc *gp = dp;
233 	register struct grfsw *gsw;
234 	caddr_t addr;
235 
236 	if (unit == 0)
237 		addr = (caddr_t)IODEVbase->tvram;
238 	else
239 		addr = (caddr_t)IODEVbase->gvram;
240 
241 	gsw = &grfsw[unit];
242 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
243 		gp->g_sw = gsw;
244 		gp->g_display.gd_id = gsw->gd_swid;
245 		gp->g_flags = GF_ALIVE;
246 		return(1);
247 	}
248 	return(0);
249 }
250