xref: /netbsd-src/sys/arch/x68k/dev/grf_machdep.c (revision fd5cb0acea84d278e04e640d37ca2398f894991f)
1 /*	$NetBSD: grf_machdep.c,v 1.21 2005/01/18 07:27:20 chs 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.21 2005/01/18 07:27:20 chs Exp $");
86 
87 #include "locators.h"
88 
89 #include <sys/param.h>
90 #include <sys/systm.h>
91 #include <sys/device.h>
92 
93 #include <machine/grfioctl.h>
94 #include <x68k/dev/grfvar.h>
95 #include <x68k/x68k/iodevice.h>
96 
97 /*
98  * false when initing for the console.
99  */
100 extern int x68k_realconfig;
101 extern int x68k_config_found(struct cfdata *, struct device *,
102 			     void *, cfprint_t);
103 
104 /* grfbus: is this necessary? */
105 int grfbusprint(void *auxp, const char *);
106 int grfbusmatch(struct device *, struct cfdata *, void *);
107 void grfbusattach(struct device *, struct device *, void *);
108 int grfbussearch(struct device *, struct cfdata *, void *);
109 
110 /* grf itself */
111 void grfattach(struct device *, struct device *, void *);
112 int grfmatch(struct device *, struct cfdata *, void *);
113 int grfprint(void *, const char *);
114 
115 static int grfinit(void *, int);
116 
117 CFATTACH_DECL(grfbus, sizeof(struct device),
118     grfbusmatch, grfbusattach, NULL, NULL);
119 
120 CFATTACH_DECL(grf, sizeof(struct grf_softc),
121     grfmatch, grfattach, NULL, NULL);
122 
123 /*
124  * only used in console init.
125  */
126 static struct cfdata *cfdata_gbus;
127 static struct cfdata *cfdata_grf;
128 
129 extern struct cfdriver grfbus_cd;
130 
131 int
132 grfbusmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
133 {
134 	if (strcmp(auxp, grfbus_cd.cd_name))
135 		return (0);
136 
137 	if ((x68k_realconfig == 0) || (cfdata_gbus == NULL)) {
138 
139 		/*
140 		 * Probe layers we depend on
141 		 */
142 		if (x68k_realconfig == 0) {
143 			cfdata_gbus = cfp;
144 		}
145 	}
146 	return (1);
147 }
148 
149 void
150 grfbusattach(struct device *pdp, struct device *dp, void *auxp)
151 {
152 	int i;
153 
154 	if (dp == NULL) {
155 		i = 0;
156 		x68k_config_found(cfdata_gbus, NULL, &i, grfbusprint);
157 	} else {
158 		printf("\n");
159 		config_search(grfbussearch, dp, NULL);
160 	}
161 }
162 
163 int
164 grfbussearch(struct device *dp, struct cfdata *match, void *aux)
165 {
166 
167 	config_found(dp, &match->cf_loc[GRFBCF_ADDR], grfbusprint);
168 	return (0);
169 }
170 
171 int
172 grfbusprint(void *auxp, const char *name)
173 {
174 
175 	if (name == NULL)
176 		return (UNCONF);
177 	return (QUIET);
178 }
179 
180 /*
181  * Normal init routine called by configure() code
182  */
183 int
184 grfmatch(struct device *parent, struct cfdata *cfp, void *aux)
185 {
186 	int addr;
187 
188 	addr = cfp->cf_loc[GRFBCF_ADDR];
189 	if (x68k_realconfig == 0) {
190 		if (addr != 0)
191 			return 0;
192 		cfdata_grf = cfp;
193 	}
194 
195 	if (addr < 0 || addr > ngrfsw)
196 		return 0;
197 
198 	return 1;
199 }
200 
201 static struct grf_softc	congrf;
202 
203 void
204 grfattach(struct device *parent, struct device *dp, void *aux)
205 {
206 	struct grf_softc *gp;
207 	struct cfdata *cf;
208 	int addr;
209 
210 	/*
211 	 * Handle exeption case: early console init
212 	 */
213 	if (dp == NULL) {
214 		/* Attach console ite */
215 		grfinit(&congrf, 0);
216 		x68k_config_found(cfdata_grf, NULL, &congrf, grfprint);
217 		return;
218 	}
219 
220 	cf = dp->dv_cfdata;
221 	addr = cf->cf_loc[GRFBCF_ADDR];
222 	grfinit(dp, addr);
223 
224 	gp = (struct grf_softc *)dp;
225 	gp->g_cfaddr = addr;
226 	printf(": %d x %d ", gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
227 	if (gp->g_display.gd_colors == 2)
228 		printf("monochrome");
229 	else
230 		printf("%d colors", gp->g_display.gd_colors);
231 	printf(" %s display\n", gp->g_sw->gd_desc);
232 
233 	/*
234 	 * try and attach an ite
235 	 */
236 	config_found(dp, gp, grfprint);
237 }
238 
239 int
240 grfprint(void *auxp, const char *pnp)
241 {
242 
243 	if (pnp)
244 		aprint_normal("ite at %s", pnp);
245 	return UNCONF;
246 }
247 
248 int
249 grfinit(void *dp, int cfaddr)
250 {
251 	struct grf_softc *gp = dp;
252 	struct grfsw *gsw;
253 	caddr_t addr;
254 
255 	if (cfaddr == 0)
256 		addr = (caddr_t)IODEVbase->tvram;
257 	else
258 		addr = (caddr_t)IODEVbase->gvram;
259 
260 	gsw = &grfsw[cfaddr];
261 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
262 		gp->g_sw = gsw;
263 		gp->g_display.gd_id = gsw->gd_swid;
264 		gp->g_flags = GF_ALIVE;
265 		return 1;
266 	}
267 
268 	return 0;
269 }
270