topcat.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: topcat.c,v 1.1.2.2 2011/02/08 16:19:21 bouyer Exp $ */
2 1.1.2.2 bouyer /* $OpenBSD: topcat.c,v 1.15 2006/08/11 18:33:13 miod Exp $ */
3 1.1.2.2 bouyer
4 1.1.2.2 bouyer /*
5 1.1.2.2 bouyer * Copyright (c) 2005, Miodrag Vallat.
6 1.1.2.2 bouyer * All rights reserved.
7 1.1.2.2 bouyer *
8 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.1.2.2 bouyer * are met:
11 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.1.2.2 bouyer *
17 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.1.2.2 bouyer * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.1.2.2 bouyer * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 1.1.2.2 bouyer * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.1.2.2 bouyer * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.1.2.2 bouyer * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.1.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 1.1.2.2 bouyer * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 bouyer *
29 1.1.2.2 bouyer */
30 1.1.2.2 bouyer /*-
31 1.1.2.2 bouyer * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
32 1.1.2.2 bouyer * All rights reserved.
33 1.1.2.2 bouyer *
34 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
35 1.1.2.2 bouyer * by Jason R. Thorpe.
36 1.1.2.2 bouyer *
37 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
38 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
39 1.1.2.2 bouyer * are met:
40 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
41 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
42 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
43 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
44 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
45 1.1.2.2 bouyer *
46 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
47 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
48 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
50 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
57 1.1.2.2 bouyer */
58 1.1.2.2 bouyer
59 1.1.2.2 bouyer /*
60 1.1.2.2 bouyer * Copyright (c) 1988 University of Utah.
61 1.1.2.2 bouyer * Copyright (c) 1990, 1993
62 1.1.2.2 bouyer * The Regents of the University of California. All rights reserved.
63 1.1.2.2 bouyer *
64 1.1.2.2 bouyer * This code is derived from software contributed to Berkeley by
65 1.1.2.2 bouyer * the Systems Programming Group of the University of Utah Computer
66 1.1.2.2 bouyer * Science Department.
67 1.1.2.2 bouyer *
68 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
69 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
70 1.1.2.2 bouyer * are met:
71 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
72 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
73 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
74 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
75 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
76 1.1.2.2 bouyer * 3. Neither the name of the University nor the names of its contributors
77 1.1.2.2 bouyer * may be used to endorse or promote products derived from this software
78 1.1.2.2 bouyer * without specific prior written permission.
79 1.1.2.2 bouyer *
80 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
81 1.1.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82 1.1.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83 1.1.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84 1.1.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85 1.1.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
86 1.1.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
87 1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
88 1.1.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
89 1.1.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
90 1.1.2.2 bouyer * SUCH DAMAGE.
91 1.1.2.2 bouyer *
92 1.1.2.2 bouyer * from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
93 1.1.2.2 bouyer *
94 1.1.2.2 bouyer * @(#)grf_tc.c 8.4 (Berkeley) 1/12/94
95 1.1.2.2 bouyer */
96 1.1.2.2 bouyer
97 1.1.2.2 bouyer /*
98 1.1.2.2 bouyer * Graphics routines for TOPCAT, CATSEYE and KATHMANDU frame buffers
99 1.1.2.2 bouyer */
100 1.1.2.2 bouyer
101 1.1.2.2 bouyer #include <sys/param.h>
102 1.1.2.2 bouyer #include <sys/systm.h>
103 1.1.2.2 bouyer #include <sys/conf.h>
104 1.1.2.2 bouyer #include <sys/device.h>
105 1.1.2.2 bouyer #include <sys/proc.h>
106 1.1.2.2 bouyer #include <sys/ioctl.h>
107 1.1.2.2 bouyer #include <sys/bus.h>
108 1.1.2.2 bouyer #include <sys/cpu.h>
109 1.1.2.2 bouyer
110 1.1.2.2 bouyer #include <machine/autoconf.h>
111 1.1.2.2 bouyer
112 1.1.2.2 bouyer #include <hp300/dev/dioreg.h>
113 1.1.2.2 bouyer #include <hp300/dev/diovar.h>
114 1.1.2.2 bouyer #include <hp300/dev/diodevs.h>
115 1.1.2.2 bouyer #include <hp300/dev/intiovar.h>
116 1.1.2.2 bouyer
117 1.1.2.2 bouyer #include <dev/wscons/wsconsio.h>
118 1.1.2.2 bouyer #include <dev/wscons/wsdisplayvar.h>
119 1.1.2.2 bouyer #include <dev/rasops/rasops.h>
120 1.1.2.2 bouyer
121 1.1.2.2 bouyer #include <hp300/dev/diofbreg.h>
122 1.1.2.2 bouyer #include <hp300/dev/diofbvar.h>
123 1.1.2.2 bouyer #include <hp300/dev/topcatreg.h>
124 1.1.2.2 bouyer
125 1.1.2.2 bouyer struct topcat_softc {
126 1.1.2.2 bouyer device_t sc_dev;
127 1.1.2.2 bouyer struct diofb *sc_fb;
128 1.1.2.2 bouyer struct diofb sc_fb_store;
129 1.1.2.2 bouyer int sc_scode;
130 1.1.2.2 bouyer };
131 1.1.2.2 bouyer
132 1.1.2.2 bouyer int topcat_dio_match(device_t, cfdata_t, void *);
133 1.1.2.2 bouyer void topcat_dio_attach(device_t, device_t, void *);
134 1.1.2.2 bouyer int topcat_intio_match(device_t, cfdata_t, void *);
135 1.1.2.2 bouyer void topcat_intio_attach(device_t, device_t, void *);
136 1.1.2.2 bouyer
137 1.1.2.2 bouyer CFATTACH_DECL_NEW(topcat_dio, sizeof(struct topcat_softc),
138 1.1.2.2 bouyer topcat_dio_match, topcat_dio_attach, NULL, NULL);
139 1.1.2.2 bouyer
140 1.1.2.2 bouyer CFATTACH_DECL_NEW(topcat_intio, sizeof(struct topcat_softc),
141 1.1.2.2 bouyer topcat_intio_match, topcat_intio_attach, NULL, NULL);
142 1.1.2.2 bouyer
143 1.1.2.2 bouyer void topcat_end_attach(struct topcat_softc *, u_int8_t);
144 1.1.2.2 bouyer int topcat_reset(struct diofb *, int, struct diofbreg *);
145 1.1.2.2 bouyer void topcat_restore(struct diofb *);
146 1.1.2.2 bouyer int topcat_setcmap(struct diofb *, struct wsdisplay_cmap *);
147 1.1.2.2 bouyer void topcat_setcolor(struct diofb *, u_int);
148 1.1.2.2 bouyer int topcat_windowmove(struct diofb *, u_int16_t, u_int16_t, u_int16_t,
149 1.1.2.2 bouyer u_int16_t, u_int16_t, u_int16_t, int16_t, int16_t);
150 1.1.2.2 bouyer
151 1.1.2.2 bouyer int topcat_ioctl(void *, void *, u_long, void *, int, struct lwp *);
152 1.1.2.2 bouyer
153 1.1.2.2 bouyer struct wsdisplay_accessops topcat_accessops = {
154 1.1.2.2 bouyer topcat_ioctl,
155 1.1.2.2 bouyer diofb_mmap,
156 1.1.2.2 bouyer diofb_alloc_screen,
157 1.1.2.2 bouyer diofb_free_screen,
158 1.1.2.2 bouyer diofb_show_screen,
159 1.1.2.2 bouyer NULL, /* load_font */
160 1.1.2.2 bouyer };
161 1.1.2.2 bouyer
162 1.1.2.2 bouyer /*
163 1.1.2.2 bouyer * Attachment glue
164 1.1.2.2 bouyer */
165 1.1.2.2 bouyer
166 1.1.2.2 bouyer int
167 1.1.2.2 bouyer topcat_intio_match(device_t parent, cfdata_t cf, void *aux)
168 1.1.2.2 bouyer {
169 1.1.2.2 bouyer struct intio_attach_args *ia = aux;
170 1.1.2.2 bouyer struct diofbreg *fbr;
171 1.1.2.2 bouyer
172 1.1.2.2 bouyer if (strcmp("fb", ia->ia_modname) != 0)
173 1.1.2.2 bouyer return 0;
174 1.1.2.2 bouyer
175 1.1.2.2 bouyer fbr = (struct diofbreg *)ia->ia_addr;
176 1.1.2.2 bouyer
177 1.1.2.2 bouyer if (badaddr((void *)fbr))
178 1.1.2.2 bouyer return (0);
179 1.1.2.2 bouyer
180 1.1.2.2 bouyer if (fbr->id == GRFHWID) {
181 1.1.2.2 bouyer switch (fbr->fbid) {
182 1.1.2.2 bouyer case GID_TOPCAT:
183 1.1.2.2 bouyer case GID_LRCATSEYE:
184 1.1.2.2 bouyer case GID_HRCCATSEYE:
185 1.1.2.2 bouyer case GID_HRMCATSEYE:
186 1.1.2.2 bouyer #if 0
187 1.1.2.2 bouyer case GID_XXXCATSEYE:
188 1.1.2.2 bouyer #endif
189 1.1.2.2 bouyer return (1);
190 1.1.2.2 bouyer }
191 1.1.2.2 bouyer }
192 1.1.2.2 bouyer
193 1.1.2.2 bouyer return (0);
194 1.1.2.2 bouyer }
195 1.1.2.2 bouyer
196 1.1.2.2 bouyer void
197 1.1.2.2 bouyer topcat_intio_attach(device_t parent, device_t self, void *aux)
198 1.1.2.2 bouyer {
199 1.1.2.2 bouyer struct topcat_softc *sc = device_private(self);
200 1.1.2.2 bouyer struct intio_attach_args *ia = aux;
201 1.1.2.2 bouyer struct diofbreg *fbr;
202 1.1.2.2 bouyer
203 1.1.2.2 bouyer sc->sc_dev = self;
204 1.1.2.2 bouyer fbr = (struct diofbreg *)ia->ia_addr;
205 1.1.2.2 bouyer sc->sc_scode = CONSCODE_INTERNAL;
206 1.1.2.2 bouyer
207 1.1.2.2 bouyer if (sc->sc_scode == conscode) {
208 1.1.2.2 bouyer sc->sc_fb = &diofb_cn;
209 1.1.2.2 bouyer } else {
210 1.1.2.2 bouyer sc->sc_fb = &sc->sc_fb_store;
211 1.1.2.2 bouyer topcat_reset(sc->sc_fb, sc->sc_scode, fbr);
212 1.1.2.2 bouyer }
213 1.1.2.2 bouyer
214 1.1.2.2 bouyer topcat_end_attach(sc, fbr->fbid);
215 1.1.2.2 bouyer }
216 1.1.2.2 bouyer
217 1.1.2.2 bouyer int
218 1.1.2.2 bouyer topcat_dio_match(device_t parent, cfdata_t cf, void *aux)
219 1.1.2.2 bouyer {
220 1.1.2.2 bouyer struct dio_attach_args *da = aux;
221 1.1.2.2 bouyer
222 1.1.2.2 bouyer if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER) {
223 1.1.2.2 bouyer switch (da->da_secid) {
224 1.1.2.2 bouyer case DIO_DEVICE_SECID_TOPCAT:
225 1.1.2.2 bouyer case DIO_DEVICE_SECID_LRCATSEYE:
226 1.1.2.2 bouyer case DIO_DEVICE_SECID_HRCCATSEYE:
227 1.1.2.2 bouyer case DIO_DEVICE_SECID_HRMCATSEYE:
228 1.1.2.2 bouyer #if 0
229 1.1.2.2 bouyer case DIO_DEVICE_SECID_XXXCATSEYE:
230 1.1.2.2 bouyer #endif
231 1.1.2.2 bouyer return (1);
232 1.1.2.2 bouyer }
233 1.1.2.2 bouyer }
234 1.1.2.2 bouyer
235 1.1.2.2 bouyer return (0);
236 1.1.2.2 bouyer }
237 1.1.2.2 bouyer
238 1.1.2.2 bouyer void
239 1.1.2.2 bouyer topcat_dio_attach(device_t parent, device_t self, void *aux)
240 1.1.2.2 bouyer {
241 1.1.2.2 bouyer struct topcat_softc *sc = device_private(self);
242 1.1.2.2 bouyer struct dio_attach_args *da = aux;
243 1.1.2.2 bouyer bus_space_handle_t bsh;
244 1.1.2.2 bouyer struct diofbreg *fbr;
245 1.1.2.2 bouyer
246 1.1.2.2 bouyer sc->sc_dev = self;
247 1.1.2.2 bouyer sc->sc_scode = da->da_scode;
248 1.1.2.2 bouyer if (sc->sc_scode == conscode) {
249 1.1.2.2 bouyer fbr = (struct diofbreg *)conaddr; /* already mapped */
250 1.1.2.2 bouyer sc->sc_fb = &diofb_cn;
251 1.1.2.2 bouyer } else {
252 1.1.2.2 bouyer sc->sc_fb = &sc->sc_fb_store;
253 1.1.2.2 bouyer if (bus_space_map(da->da_bst, da->da_addr, da->da_size, 0,
254 1.1.2.2 bouyer &bsh)) {
255 1.1.2.2 bouyer aprint_error(": can't map framebuffer\n");
256 1.1.2.2 bouyer return;
257 1.1.2.2 bouyer }
258 1.1.2.2 bouyer fbr = bus_space_vaddr(da->da_bst, bsh);
259 1.1.2.2 bouyer if (topcat_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
260 1.1.2.2 bouyer printf(": can't map framebuffer\n");
261 1.1.2.2 bouyer return;
262 1.1.2.2 bouyer }
263 1.1.2.2 bouyer }
264 1.1.2.2 bouyer
265 1.1.2.2 bouyer topcat_end_attach(sc, fbr->fbid);
266 1.1.2.2 bouyer }
267 1.1.2.2 bouyer
268 1.1.2.2 bouyer void
269 1.1.2.2 bouyer topcat_end_attach(struct topcat_softc *sc, u_int8_t id)
270 1.1.2.2 bouyer {
271 1.1.2.2 bouyer const char *fbname = "unknown";
272 1.1.2.2 bouyer
273 1.1.2.2 bouyer switch (id) {
274 1.1.2.2 bouyer case GID_TOPCAT:
275 1.1.2.2 bouyer switch (sc->sc_fb->planes) {
276 1.1.2.2 bouyer case 1:
277 1.1.2.2 bouyer fbname = "HP98544 topcat";
278 1.1.2.2 bouyer break;
279 1.1.2.2 bouyer case 4:
280 1.1.2.2 bouyer if (sc->sc_fb->dheight == 400)
281 1.1.2.2 bouyer fbname = "HP98543 topcat";
282 1.1.2.2 bouyer else
283 1.1.2.2 bouyer fbname = "HP98545 topcat";
284 1.1.2.2 bouyer break;
285 1.1.2.2 bouyer case 6:
286 1.1.2.2 bouyer fbname = "HP98547 topcat";
287 1.1.2.2 bouyer break;
288 1.1.2.2 bouyer }
289 1.1.2.2 bouyer break;
290 1.1.2.2 bouyer case GID_HRCCATSEYE:
291 1.1.2.2 bouyer fbname = "HP98550 catseye"; /* also A1416 kathmandu */
292 1.1.2.2 bouyer break;
293 1.1.2.2 bouyer case GID_LRCATSEYE:
294 1.1.2.2 bouyer fbname = "HP98549 catseye";
295 1.1.2.2 bouyer break;
296 1.1.2.2 bouyer case GID_HRMCATSEYE:
297 1.1.2.2 bouyer fbname = "HP98548 catseye";
298 1.1.2.2 bouyer break;
299 1.1.2.2 bouyer }
300 1.1.2.2 bouyer
301 1.1.2.2 bouyer diofb_end_attach(sc->sc_dev, &topcat_accessops, sc->sc_fb,
302 1.1.2.2 bouyer sc->sc_scode == conscode, fbname);
303 1.1.2.2 bouyer }
304 1.1.2.2 bouyer
305 1.1.2.2 bouyer /*
306 1.1.2.2 bouyer * Initialize hardware and display routines.
307 1.1.2.2 bouyer */
308 1.1.2.2 bouyer int
309 1.1.2.2 bouyer topcat_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
310 1.1.2.2 bouyer {
311 1.1.2.2 bouyer volatile struct tcboxfb *tc = (struct tcboxfb *)fbr;
312 1.1.2.2 bouyer int rc;
313 1.1.2.2 bouyer u_int i;
314 1.1.2.2 bouyer
315 1.1.2.2 bouyer if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
316 1.1.2.2 bouyer return (rc);
317 1.1.2.2 bouyer
318 1.1.2.2 bouyer /*
319 1.1.2.2 bouyer * If we could not get a valid number of planes, determine it
320 1.1.2.2 bouyer * by writing to the first frame buffer display location,
321 1.1.2.2 bouyer * then reading it back.
322 1.1.2.2 bouyer */
323 1.1.2.2 bouyer if (fb->planes == 0) {
324 1.1.2.2 bouyer volatile u_int8_t *fbp;
325 1.1.2.2 bouyer u_int8_t save;
326 1.1.2.2 bouyer
327 1.1.2.2 bouyer fbp = (u_int8_t *)fb->fbkva;
328 1.1.2.2 bouyer tc->fben = ~0;
329 1.1.2.2 bouyer tc->wen = ~0;
330 1.1.2.2 bouyer tc->ren = ~0;
331 1.1.2.2 bouyer tc->prr = RR_COPY;
332 1.1.2.2 bouyer save = *fbp;
333 1.1.2.2 bouyer *fbp = 0xff;
334 1.1.2.2 bouyer fb->planemask = *fbp;
335 1.1.2.2 bouyer *fbp = save;
336 1.1.2.2 bouyer
337 1.1.2.2 bouyer for (fb->planes = 1; fb->planemask >= (1 << fb->planes);
338 1.1.2.2 bouyer fb->planes++);
339 1.1.2.2 bouyer if (fb->planes > 8)
340 1.1.2.2 bouyer fb->planes = 8;
341 1.1.2.2 bouyer fb->planemask = (1 << fb->planes) - 1;
342 1.1.2.2 bouyer }
343 1.1.2.2 bouyer
344 1.1.2.2 bouyer fb->bmv = topcat_windowmove;
345 1.1.2.2 bouyer topcat_restore(fb);
346 1.1.2.2 bouyer diofb_fbsetup(fb);
347 1.1.2.2 bouyer for (i = 0; i <= fb->planemask; i++)
348 1.1.2.2 bouyer topcat_setcolor(fb, i);
349 1.1.2.2 bouyer
350 1.1.2.2 bouyer return (0);
351 1.1.2.2 bouyer }
352 1.1.2.2 bouyer
353 1.1.2.2 bouyer void
354 1.1.2.2 bouyer topcat_restore(struct diofb *fb)
355 1.1.2.2 bouyer {
356 1.1.2.2 bouyer volatile struct tcboxfb *tc = (struct tcboxfb *)fb->regkva;
357 1.1.2.2 bouyer
358 1.1.2.2 bouyer /*
359 1.1.2.2 bouyer * Catseye looks a lot like a topcat, but not completely.
360 1.1.2.2 bouyer * So, we set some bits to make it work.
361 1.1.2.2 bouyer */
362 1.1.2.2 bouyer if (tc->regs.fbid != GID_TOPCAT) {
363 1.1.2.2 bouyer while ((tc->catseye_status & 1))
364 1.1.2.2 bouyer ;
365 1.1.2.2 bouyer tc->catseye_status = 0x0;
366 1.1.2.2 bouyer tc->vb_select = 0x0;
367 1.1.2.2 bouyer tc->tcntrl = 0x0;
368 1.1.2.2 bouyer tc->acntrl = 0x0;
369 1.1.2.2 bouyer tc->pncntrl = 0x0;
370 1.1.2.2 bouyer tc->rug_cmdstat = 0x90;
371 1.1.2.2 bouyer }
372 1.1.2.2 bouyer
373 1.1.2.2 bouyer /*
374 1.1.2.2 bouyer * Enable reading/writing of all the planes.
375 1.1.2.2 bouyer */
376 1.1.2.2 bouyer tc->fben = fb->planemask;
377 1.1.2.2 bouyer tc->wen = fb->planemask;
378 1.1.2.2 bouyer tc->ren = fb->planemask;
379 1.1.2.2 bouyer tc->prr = RR_COPY;
380 1.1.2.2 bouyer
381 1.1.2.2 bouyer /* Enable display */
382 1.1.2.2 bouyer tc->nblank = 0xff;
383 1.1.2.2 bouyer }
384 1.1.2.2 bouyer
385 1.1.2.2 bouyer int
386 1.1.2.2 bouyer topcat_ioctl(void *v, void *vs, u_long cmd, void *data, int flags,
387 1.1.2.2 bouyer struct lwp *l)
388 1.1.2.2 bouyer {
389 1.1.2.2 bouyer struct diofb *fb = v;
390 1.1.2.2 bouyer struct wsdisplay_fbinfo *wdf;
391 1.1.2.2 bouyer u_int i;
392 1.1.2.2 bouyer
393 1.1.2.2 bouyer switch (cmd) {
394 1.1.2.2 bouyer case WSDISPLAYIO_GTYPE:
395 1.1.2.2 bouyer *(u_int *)data = WSDISPLAY_TYPE_TOPCAT;
396 1.1.2.2 bouyer return 0;
397 1.1.2.2 bouyer case WSDISPLAYIO_SMODE:
398 1.1.2.2 bouyer fb->mapmode = *(u_int *)data;
399 1.1.2.2 bouyer if (fb->mapmode == WSDISPLAYIO_MODE_EMUL) {
400 1.1.2.2 bouyer topcat_restore(fb);
401 1.1.2.2 bouyer for (i = 0; i <= fb->planemask; i++)
402 1.1.2.2 bouyer topcat_setcolor(fb, i);
403 1.1.2.2 bouyer }
404 1.1.2.2 bouyer return 0;
405 1.1.2.2 bouyer case WSDISPLAYIO_GINFO:
406 1.1.2.2 bouyer wdf = (void *)data;
407 1.1.2.2 bouyer wdf->width = fb->ri.ri_width;
408 1.1.2.2 bouyer wdf->height = fb->ri.ri_height;
409 1.1.2.2 bouyer wdf->depth = fb->ri.ri_depth;
410 1.1.2.2 bouyer wdf->cmsize = 1 << fb->planes;
411 1.1.2.2 bouyer return 0;
412 1.1.2.2 bouyer case WSDISPLAYIO_LINEBYTES:
413 1.1.2.2 bouyer *(u_int *)data = fb->ri.ri_stride;
414 1.1.2.2 bouyer return 0;
415 1.1.2.2 bouyer case WSDISPLAYIO_GETCMAP:
416 1.1.2.2 bouyer return (diofb_getcmap(fb, (struct wsdisplay_cmap *)data));
417 1.1.2.2 bouyer case WSDISPLAYIO_PUTCMAP:
418 1.1.2.2 bouyer return (topcat_setcmap(fb, (struct wsdisplay_cmap *)data));
419 1.1.2.2 bouyer case WSDISPLAYIO_GVIDEO:
420 1.1.2.2 bouyer case WSDISPLAYIO_SVIDEO:
421 1.1.2.2 bouyer return EPASSTHROUGH;
422 1.1.2.2 bouyer }
423 1.1.2.2 bouyer
424 1.1.2.2 bouyer return EPASSTHROUGH;
425 1.1.2.2 bouyer }
426 1.1.2.2 bouyer
427 1.1.2.2 bouyer void
428 1.1.2.2 bouyer topcat_setcolor(struct diofb *fb, u_int index)
429 1.1.2.2 bouyer {
430 1.1.2.2 bouyer volatile struct tcboxfb *tc = (struct tcboxfb *)fb->regkva;
431 1.1.2.2 bouyer
432 1.1.2.2 bouyer if (tc->regs.fbid != GID_TOPCAT) {
433 1.1.2.2 bouyer tccm_waitbusy(tc);
434 1.1.2.2 bouyer tc->plane_mask = 0xff;
435 1.1.2.2 bouyer tc->cindex = ~index;
436 1.1.2.2 bouyer tc->rdata = fb->cmap.r[index];
437 1.1.2.2 bouyer tc->gdata = fb->cmap.g[index];
438 1.1.2.2 bouyer tc->bdata = fb->cmap.b[index];
439 1.1.2.2 bouyer tc->strobe = 0xff;
440 1.1.2.2 bouyer
441 1.1.2.2 bouyer tccm_waitbusy(tc);
442 1.1.2.2 bouyer tc->cindex = 0;
443 1.1.2.2 bouyer } else {
444 1.1.2.2 bouyer tccm_waitbusy(tc);
445 1.1.2.2 bouyer tc->plane_mask = 0xff;
446 1.1.2.2 bouyer tc->rdata = fb->cmap.r[index];
447 1.1.2.2 bouyer tc->gdata = fb->cmap.g[index];
448 1.1.2.2 bouyer tc->bdata = fb->cmap.b[index];
449 1.1.2.2 bouyer tc->cindex = ~index;
450 1.1.2.2 bouyer tc->strobe = 0xff;
451 1.1.2.2 bouyer
452 1.1.2.2 bouyer tccm_waitbusy(tc);
453 1.1.2.2 bouyer tc->rdata = 0;
454 1.1.2.2 bouyer tc->gdata = 0;
455 1.1.2.2 bouyer tc->bdata = 0;
456 1.1.2.2 bouyer tc->cindex = 0;
457 1.1.2.2 bouyer }
458 1.1.2.2 bouyer }
459 1.1.2.2 bouyer
460 1.1.2.2 bouyer int
461 1.1.2.2 bouyer topcat_setcmap(struct diofb *fb, struct wsdisplay_cmap *cm)
462 1.1.2.2 bouyer {
463 1.1.2.2 bouyer u_int8_t r[256], g[256], b[256];
464 1.1.2.2 bouyer u_int index = cm->index, count = cm->count;
465 1.1.2.2 bouyer u_int colcount = 1 << fb->planes;
466 1.1.2.2 bouyer int error;
467 1.1.2.2 bouyer
468 1.1.2.2 bouyer if (index >= colcount || count > colcount - index)
469 1.1.2.2 bouyer return (EINVAL);
470 1.1.2.2 bouyer
471 1.1.2.2 bouyer if ((error = copyin(cm->red, r, count)) != 0)
472 1.1.2.2 bouyer return (error);
473 1.1.2.2 bouyer if ((error = copyin(cm->green, g, count)) != 0)
474 1.1.2.2 bouyer return (error);
475 1.1.2.2 bouyer if ((error = copyin(cm->blue, b, count)) != 0)
476 1.1.2.2 bouyer return (error);
477 1.1.2.2 bouyer
478 1.1.2.2 bouyer memcpy(fb->cmap.r + index, r, count);
479 1.1.2.2 bouyer memcpy(fb->cmap.g + index, g, count);
480 1.1.2.2 bouyer memcpy(fb->cmap.b + index, b, count);
481 1.1.2.2 bouyer
482 1.1.2.2 bouyer while (count-- != 0)
483 1.1.2.2 bouyer topcat_setcolor(fb, index++);
484 1.1.2.2 bouyer
485 1.1.2.2 bouyer return (0);
486 1.1.2.2 bouyer }
487 1.1.2.2 bouyer
488 1.1.2.2 bouyer /*
489 1.1.2.2 bouyer * Accelerated routines
490 1.1.2.2 bouyer */
491 1.1.2.2 bouyer
492 1.1.2.2 bouyer int
493 1.1.2.2 bouyer topcat_windowmove(struct diofb *fb, u_int16_t sx, u_int16_t sy,
494 1.1.2.2 bouyer u_int16_t dx, u_int16_t dy, u_int16_t cx, u_int16_t cy, int16_t rop,
495 1.1.2.2 bouyer int16_t planemask)
496 1.1.2.2 bouyer {
497 1.1.2.2 bouyer volatile struct tcboxfb *tc = (struct tcboxfb *)fb->regkva;
498 1.1.2.2 bouyer
499 1.1.2.2 bouyer tc_waitbusy(tc, fb->planemask);
500 1.1.2.2 bouyer
501 1.1.2.2 bouyer tc->wen = planemask;
502 1.1.2.2 bouyer tc->wmrr = rop;
503 1.1.2.2 bouyer if (planemask != 0xff) {
504 1.1.2.2 bouyer tc->wen = planemask ^ 0xff;
505 1.1.2.2 bouyer tc->wmrr = rop ^ 0x0f;
506 1.1.2.2 bouyer tc->wen = fb->planemask;
507 1.1.2.2 bouyer }
508 1.1.2.2 bouyer tc->source_y = sy;
509 1.1.2.2 bouyer tc->source_x = sx;
510 1.1.2.2 bouyer tc->dest_y = dy;
511 1.1.2.2 bouyer tc->dest_x = dx;
512 1.1.2.2 bouyer tc->wheight = cy;
513 1.1.2.2 bouyer tc->wwidth = cx;
514 1.1.2.2 bouyer tc->wmove = fb->planemask;
515 1.1.2.2 bouyer
516 1.1.2.2 bouyer tc_waitbusy(tc, fb->planemask);
517 1.1.2.2 bouyer
518 1.1.2.2 bouyer return (0);
519 1.1.2.2 bouyer }
520 1.1.2.2 bouyer
521 1.1.2.2 bouyer
522 1.1.2.2 bouyer /*
523 1.1.2.2 bouyer * Topcat/catseye console attachment
524 1.1.2.2 bouyer */
525 1.1.2.2 bouyer
526 1.1.2.2 bouyer int
527 1.1.2.2 bouyer topcatcnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
528 1.1.2.2 bouyer {
529 1.1.2.2 bouyer bus_space_handle_t bsh;
530 1.1.2.2 bouyer void *va;
531 1.1.2.2 bouyer struct diofbreg *fbr;
532 1.1.2.2 bouyer struct diofb *fb = &diofb_cn;
533 1.1.2.2 bouyer int size;
534 1.1.2.2 bouyer
535 1.1.2.2 bouyer if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
536 1.1.2.2 bouyer return 1;
537 1.1.2.2 bouyer va = bus_space_vaddr(bst, bsh);
538 1.1.2.2 bouyer fbr = va;
539 1.1.2.2 bouyer
540 1.1.2.2 bouyer if (badaddr(va) || fbr->id != GRFHWID) {
541 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
542 1.1.2.2 bouyer return 1;
543 1.1.2.2 bouyer }
544 1.1.2.2 bouyer
545 1.1.2.2 bouyer switch (fbr->fbid) {
546 1.1.2.2 bouyer case GID_TOPCAT:
547 1.1.2.2 bouyer case GID_LRCATSEYE:
548 1.1.2.2 bouyer case GID_HRCCATSEYE:
549 1.1.2.2 bouyer case GID_HRMCATSEYE:
550 1.1.2.2 bouyer break;
551 1.1.2.2 bouyer
552 1.1.2.2 bouyer default:
553 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
554 1.1.2.2 bouyer return 1;
555 1.1.2.2 bouyer }
556 1.1.2.2 bouyer
557 1.1.2.2 bouyer size = DIO_SIZE(scode, va);
558 1.1.2.2 bouyer
559 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
560 1.1.2.2 bouyer if (bus_space_map(bst, addr, size, 0, &bsh))
561 1.1.2.2 bouyer return 1;
562 1.1.2.2 bouyer va = bus_space_vaddr(bst, bsh);
563 1.1.2.2 bouyer
564 1.1.2.2 bouyer /*
565 1.1.2.2 bouyer * Initialize the framebuffer hardware.
566 1.1.2.2 bouyer */
567 1.1.2.2 bouyer conscode = scode;
568 1.1.2.2 bouyer conaddr = va;
569 1.1.2.2 bouyer topcat_reset(fb, conscode, (struct diofbreg *)conaddr);
570 1.1.2.2 bouyer
571 1.1.2.2 bouyer /*
572 1.1.2.2 bouyer * Initialize the terminal emulator.
573 1.1.2.2 bouyer */
574 1.1.2.2 bouyer diofb_cnattach(fb);
575 1.1.2.2 bouyer return 0;
576 1.1.2.2 bouyer }
577