xref: /netbsd-src/sys/arch/x68k/dev/grf_machdep.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: grf_machdep.c,v 1.33 2021/04/24 23:36:51 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. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
37  *
38  *	@(#)grf_machdep.c	8.2 (Berkeley) 1/12/94
39  */
40 
41 /*
42  * Graphics display driver for the HP300/400 DIO/DIO-II based machines.
43  * This is the hardware-dependent configuration portion of the driver.
44  */
45 
46 #include <sys/cdefs.h>
47 __KERNEL_RCSID(0, "$NetBSD: grf_machdep.c,v 1.33 2021/04/24 23:36:51 thorpej Exp $");
48 
49 #include "locators.h"
50 
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/device.h>
54 
55 #include <machine/autoconf.h>
56 #include <machine/grfioctl.h>
57 #include <x68k/dev/grfvar.h>
58 #include <x68k/x68k/iodevice.h>
59 
60 /* grfbus: is this necessary? */
61 int grfbusprint(void *, const char *);
62 int grfbusmatch(device_t, cfdata_t, void *);
63 void grfbusattach(device_t, device_t, void *);
64 int grfbussearch(device_t, cfdata_t, const int *, void *);
65 
66 /* grf itself */
67 int grfmatch(device_t, cfdata_t, void *);
68 void grfattach(device_t, device_t, void *);
69 int grfprint(void *, const char *);
70 
71 static int grfinit(struct grf_softc *, int);
72 
73 CFATTACH_DECL_NEW(grfbus, 0,
74     grfbusmatch, grfbusattach, NULL, NULL);
75 
76 CFATTACH_DECL_NEW(grf, sizeof(struct grf_softc),
77     grfmatch, grfattach, NULL, NULL);
78 
79 extern struct cfdriver grfbus_cd;
80 
81 int
82 grfbusmatch(device_t parent, cfdata_t cf, void *aux)
83 {
84 	if (strcmp(aux, grfbus_cd.cd_name))
85 		return (0);
86 
87 	return (1);
88 }
89 
90 void
91 grfbusattach(device_t parent, device_t self, void *aux)
92 {
93 
94 	aprint_normal("\n");
95 	config_search(self, NULL,
96 	    CFARG_SEARCH, grfbussearch,
97 	    CFARG_EOL);
98 }
99 
100 int
101 grfbussearch(device_t self, cfdata_t match, const int *ldesc, void *aux)
102 {
103 
104 	config_found(self, &match->cf_loc[GRFBCF_ADDR], grfbusprint, CFARG_EOL);
105 	return (0);
106 }
107 
108 int
109 grfbusprint(void *aux, const char *name)
110 {
111 
112 	if (name == NULL)
113 		return (UNCONF);
114 	return (QUIET);
115 }
116 
117 /*
118  * Normal init routine called by configure() code
119  */
120 int
121 grfmatch(device_t parent, cfdata_t cfp, void *aux)
122 {
123 	int addr;
124 
125 	addr = cfp->cf_loc[GRFBCF_ADDR];
126 	if (addr < 0 || addr > ngrfsw)
127 		return 0;
128 
129 	return 1;
130 }
131 
132 struct grf_softc congrf;
133 
134 void
135 grfattach(device_t parent, device_t self, void *aux)
136 {
137 	struct grf_softc *gp;
138 	struct cfdata *cf;
139 	int addr;
140 
141 	cf = device_cfdata(self);
142 	addr = cf->cf_loc[GRFBCF_ADDR];
143 
144 	gp = device_private(self);
145 	gp->g_device = self;
146 	gp->g_cfaddr = addr;
147 	grfinit(gp, addr);
148 
149 	aprint_normal(": %d x %d ",
150 		gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
151 	if (gp->g_display.gd_colors == 2)
152 		aprint_normal("monochrome");
153 	else
154 		aprint_normal("%d colors", gp->g_display.gd_colors);
155 	aprint_normal(" %s display\n", gp->g_sw->gd_desc);
156 
157 	/*
158 	 * try and attach an ite
159 	 */
160 	config_found(self, gp, grfprint, CFARG_EOL);
161 }
162 
163 int
164 grfprint(void *aux, const char *pnp)
165 {
166 
167 	if (pnp)
168 		aprint_normal("ite at %s", pnp);
169 	return UNCONF;
170 }
171 
172 int
173 grfinit(struct grf_softc *gp, int cfaddr)
174 {
175 	struct grfsw *gsw;
176 	void *addr;
177 
178 	if (cfaddr == 0)
179 		addr = (void *)__UNVOLATILE(IODEVbase->tvram);
180 	else
181 		addr = (void *)__UNVOLATILE(IODEVbase->gvram);
182 
183 	gsw = &grfsw[cfaddr];
184 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
185 		gp->g_sw = gsw;
186 		gp->g_display.gd_id = gsw->gd_swid;
187 		gp->g_flags = GF_ALIVE;
188 		return 1;
189 	}
190 
191 	return 0;
192 }
193 
194 void
195 grf_config_console(void)
196 {
197 	grfinit(&congrf, 0);
198 }
199