xref: /netbsd-src/sys/arch/x68k/dev/grf_machdep.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: grf_machdep.c,v 1.5 1996/10/13 03:34:48 christos 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 void grfbusscan __P((struct device *, 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_scan(grfbusscan, dp);
128 	}
129 }
130 
131 void
132 grfbusscan(dp, auxp)
133 	struct device *dp;
134 	void *auxp;
135 {
136 	int i = 0;
137 	config_found(dp, (void*)&i, grfbusprint);
138 }
139 
140 int
141 grfbusprint(auxp, name)
142 	void *auxp;
143 	const char *name;
144 {
145 	if(name == NULL)
146 		return(UNCONF);
147 	return(QUIET);
148 }
149 
150 static struct grf_softc	congrf;
151 /*
152  * XXX called from ite console init routine.
153  * Does just what configure will do later but without printing anything.
154  */
155 void
156 grfconfig(dp)
157 	struct device *dp;
158 {
159 	int unit;
160 	if (!dp)
161 		dp = (void *)&congrf;
162 	unit = dp->dv_unit;
163 
164 	grfinit(dp, unit); /* XXX */
165 }
166 
167 /*
168  * Normal init routine called by configure() code
169  */
170 int
171 grfmatch(parent, match, aux)
172 	struct device *parent;
173 	void *match, *aux;
174 {
175 	struct cfdata *cfp = match;
176 
177 	/* XXX console at grf0 */
178 	if (x68k_realconfig == 0) {
179 		if (cfp->cf_unit != 0)
180 			return(0);
181 		cfdata_grf = cfp;
182 	}
183 	return(1);
184 }
185 
186 void
187 grfattach(parent, dp, aux)
188 	struct device *parent;
189 	struct device *dp;
190 	void *aux;
191 {
192 /*	static struct grf_softc	congrf;*/
193 	struct grf_softc *gp;
194 
195 	grfconfig(dp);
196 	/*
197 	 * Handle exeption case: early console init
198 	 */
199 	if(dp == NULL) {
200 		/* Attach console ite */
201 		x68k_config_found(cfdata_grf, NULL, &congrf, grfprint);
202 		return;
203 	}
204 	gp = (struct grf_softc *)dp;
205 	printf(": %d x %d ", gp->g_display.gd_dwidth,
206 	    gp->g_display.gd_dheight);
207 	if (gp->g_display.gd_colors == 2)
208 		printf("monochrome");
209 	else
210 		printf("%d colors", gp->g_display.gd_colors);
211 	printf(" %s display\n", gp->g_sw->gd_desc);
212 
213 	/*
214 	 * try and attach an ite
215 	 */
216 	config_found(dp, gp, grfprint);
217 }
218 
219 int
220 grfprint(auxp, pnp)
221 void *auxp;
222 const char *pnp;
223 {
224 	if(pnp)
225 		printf("ite at %s", pnp);
226 	return(UNCONF);
227 }
228 
229 int
230 grfinit(dp, unit)
231 	void *dp;
232 	int unit;
233 {
234 	struct grf_softc *gp = dp;
235 	register struct grfsw *gsw;
236 	caddr_t addr = (void *)(unit < 1 ? IODEVbase->tvram : IODEVbase->gvram);
237 
238 	gsw = &grfsw[unit];
239 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
240 		gp->g_sw = gsw;
241 		gp->g_display.gd_id = gsw->gd_swid;
242 		gp->g_flags = GF_ALIVE;
243 		return(1);
244 	}
245 	return(0);
246 }
247