fb_elb.c revision 1.18 1 1.17 rin /* $NetBSD: fb_elb.c,v 1.18 2021/03/07 10:33:07 rin Exp $ */
2 1.1 hannken
3 1.1 hannken /*-
4 1.1 hannken * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 1.1 hannken * All rights reserved.
6 1.1 hannken *
7 1.1 hannken * This code is derived from software contributed to The NetBSD Foundation
8 1.1 hannken * by Juergen Hannken-Illjes.
9 1.1 hannken *
10 1.1 hannken * Redistribution and use in source and binary forms, with or without
11 1.1 hannken * modification, are permitted provided that the following conditions
12 1.1 hannken * are met:
13 1.1 hannken * 1. Redistributions of source code must retain the above copyright
14 1.1 hannken * notice, this list of conditions and the following disclaimer.
15 1.1 hannken * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 hannken * notice, this list of conditions and the following disclaimer in the
17 1.1 hannken * documentation and/or other materials provided with the distribution.
18 1.1 hannken *
19 1.1 hannken * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 hannken * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 hannken * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 hannken * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 hannken * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 hannken * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 hannken * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 hannken * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 hannken * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 hannken * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 hannken * POSSIBILITY OF SUCH DAMAGE.
30 1.1 hannken */
31 1.3 lukem
32 1.3 lukem #include <sys/cdefs.h>
33 1.17 rin __KERNEL_RCSID(0, "$NetBSD: fb_elb.c,v 1.18 2021/03/07 10:33:07 rin Exp $");
34 1.1 hannken
35 1.1 hannken #include <sys/param.h>
36 1.1 hannken #include <sys/conf.h>
37 1.1 hannken #include <sys/device.h>
38 1.1 hannken #include <sys/ioctl.h>
39 1.14 thorpej #include <sys/kmem.h>
40 1.1 hannken #include <sys/systm.h>
41 1.1 hannken
42 1.1 hannken #include <dev/wscons/wsconsio.h>
43 1.1 hannken #include <dev/wscons/wsdisplayvar.h>
44 1.1 hannken #include <dev/rasops/rasops.h>
45 1.1 hannken
46 1.1 hannken #include <machine/explora.h>
47 1.13 dyoung #include <sys/bus.h>
48 1.1 hannken
49 1.1 hannken #include <evbppc/explora/dev/elbvar.h>
50 1.1 hannken
51 1.1 hannken #define FB_NPORTS 65536
52 1.17 rin #define CMAP_SIZE 256
53 1.1 hannken
54 1.1 hannken struct fb_dev {
55 1.1 hannken void *fb_vram;
56 1.1 hannken bus_space_tag_t fb_iot;
57 1.1 hannken bus_space_handle_t fb_ioh;
58 1.1 hannken struct rasops_info fb_ri;
59 1.1 hannken };
60 1.1 hannken
61 1.18 rin struct fb_cmap {
62 1.18 rin uint8_t r;
63 1.18 rin uint8_t g;
64 1.18 rin uint8_t b;
65 1.18 rin };
66 1.18 rin
67 1.1 hannken struct fb_elb_softc {
68 1.12 matt device_t sc_dev;
69 1.1 hannken struct fb_dev *sc_fb;
70 1.18 rin bus_addr_t sc_fbbase;
71 1.18 rin bus_size_t sc_fbsize;
72 1.1 hannken int sc_nscreens;
73 1.18 rin int sc_mode;
74 1.18 rin struct fb_cmap sc_cmap[CMAP_SIZE];
75 1.1 hannken };
76 1.1 hannken
77 1.18 rin /*
78 1.18 rin * We assume that rasops_cmap is compatible to sc_cmap.
79 1.18 rin */
80 1.18 rin CTASSERT(sizeof(rasops_cmap) == CMAP_SIZE * 3);
81 1.18 rin
82 1.17 rin void fb_cnattach(bus_space_tag_t, bus_addr_t, void *);
83 1.17 rin
84 1.12 matt static int fb_elb_probe(device_t, cfdata_t, void *);
85 1.12 matt static void fb_elb_attach(device_t, device_t, void *);
86 1.17 rin
87 1.18 rin static void fb_init(struct fb_dev *, int, int);
88 1.18 rin static void fb_initcmap(struct fb_elb_softc *);
89 1.18 rin
90 1.18 rin static int fb_getcmap(struct fb_elb_softc *, struct wsdisplay_cmap *);
91 1.18 rin static int fb_putcmap(struct fb_elb_softc *,
92 1.18 rin const struct wsdisplay_cmap *);
93 1.17 rin
94 1.8 christos static int fb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
95 1.7 hannken static paddr_t fb_mmap(void *, void *, off_t, int);
96 1.1 hannken static int fb_alloc_screen(void *, const struct wsscreen_descr *, void **,
97 1.1 hannken int *, int *, long *);
98 1.1 hannken static void fb_free_screen(void *, void *);
99 1.1 hannken static int fb_show_screen(void *, void *, int, void (*)(void *, int, int),
100 1.1 hannken void *);
101 1.1 hannken
102 1.2 hannken static void fb_eraserows(void *, int, int, long);
103 1.2 hannken static void fb_erasecols(void *, int, int, int, long);
104 1.2 hannken static void fb_copyrows(void *, int, int, int);
105 1.2 hannken static void fb_copycols(void *, int, int, int, int);
106 1.2 hannken
107 1.18 rin static void s3_getgeometry(struct fb_dev *, int *, int *);
108 1.18 rin static void s3_putcmap(struct fb_dev *, const struct fb_cmap *);
109 1.2 hannken static void s3_copy(struct fb_dev *, int, int, int, int, int, int, int);
110 1.2 hannken static void s3_fill(struct fb_dev *, int, int, int, int, int, int);
111 1.1 hannken
112 1.1 hannken static struct fb_dev console_dev;
113 1.1 hannken
114 1.1 hannken static struct wsdisplay_accessops accessops = {
115 1.1 hannken fb_ioctl,
116 1.1 hannken fb_mmap,
117 1.1 hannken fb_alloc_screen,
118 1.1 hannken fb_free_screen,
119 1.1 hannken fb_show_screen,
120 1.1 hannken NULL
121 1.1 hannken };
122 1.1 hannken
123 1.1 hannken static struct wsscreen_descr stdscreen = {
124 1.1 hannken "std",
125 1.1 hannken 0, 0,
126 1.1 hannken 0,
127 1.1 hannken 0, 0,
128 1.1 hannken 0
129 1.1 hannken };
130 1.1 hannken
131 1.1 hannken static const struct wsscreen_descr *scrlist[] = {
132 1.1 hannken &stdscreen
133 1.1 hannken };
134 1.1 hannken
135 1.1 hannken static struct wsscreen_list screenlist = {
136 1.12 matt __arraycount(scrlist), scrlist
137 1.1 hannken };
138 1.1 hannken
139 1.17 rin void
140 1.17 rin fb_cnattach(bus_space_tag_t iot, bus_addr_t iobase, void *vram)
141 1.17 rin {
142 1.17 rin struct rasops_info *ri = &console_dev.fb_ri;
143 1.17 rin long defattr;
144 1.18 rin int width, height;
145 1.17 rin
146 1.17 rin console_dev.fb_iot = iot;
147 1.17 rin console_dev.fb_ioh = iobase;
148 1.17 rin console_dev.fb_vram = vram;
149 1.17 rin
150 1.18 rin s3_getgeometry(&console_dev, &width, &height);
151 1.18 rin
152 1.18 rin fb_init(&console_dev, width, height);
153 1.18 rin
154 1.18 rin s3_putcmap(&console_dev, (const struct fb_cmap*)rasops_cmap);
155 1.17 rin
156 1.17 rin (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
157 1.17 rin
158 1.17 rin wsdisplay_cnattach(&stdscreen, ri, 0, 0, defattr);
159 1.17 rin }
160 1.17 rin
161 1.12 matt CFATTACH_DECL_NEW(fb_elb, sizeof(struct fb_elb_softc),
162 1.1 hannken fb_elb_probe, fb_elb_attach, NULL, NULL);
163 1.1 hannken
164 1.1 hannken static int
165 1.12 matt fb_elb_probe(device_t parent, cfdata_t cf, void *aux)
166 1.1 hannken {
167 1.1 hannken struct elb_attach_args *oaa = aux;
168 1.1 hannken
169 1.1 hannken if (strcmp(oaa->elb_name, cf->cf_name) != 0)
170 1.1 hannken return 0;
171 1.1 hannken
172 1.17 rin return 1;
173 1.1 hannken }
174 1.1 hannken
175 1.1 hannken static void
176 1.12 matt fb_elb_attach(device_t parent, device_t self, void *aux)
177 1.1 hannken {
178 1.12 matt struct fb_elb_softc *sc = device_private(self);
179 1.1 hannken struct elb_attach_args *eaa = aux;
180 1.1 hannken struct wsemuldisplaydev_attach_args waa;
181 1.1 hannken bus_space_handle_t ioh;
182 1.18 rin int is_console, width, height;
183 1.1 hannken
184 1.12 matt sc->sc_dev = self;
185 1.12 matt
186 1.1 hannken is_console = ((void *)eaa->elb_base == console_dev.fb_vram);
187 1.1 hannken
188 1.18 rin if (is_console)
189 1.1 hannken sc->sc_fb = &console_dev;
190 1.18 rin else
191 1.14 thorpej sc->sc_fb = kmem_zalloc(sizeof(struct fb_dev), KM_SLEEP);
192 1.1 hannken
193 1.1 hannken sc->sc_fb->fb_iot = eaa->elb_bt;
194 1.18 rin bus_space_map(sc->sc_fb->fb_iot, eaa->elb_base2, FB_NPORTS,
195 1.18 rin 0, &sc->sc_fb->fb_ioh);
196 1.18 rin
197 1.18 rin s3_getgeometry(sc->sc_fb, &width, &height);
198 1.18 rin
199 1.18 rin sc->sc_fbbase = eaa->elb_base;
200 1.18 rin sc->sc_fbsize = width * height;
201 1.18 rin bus_space_map(sc->sc_fb->fb_iot, sc->sc_fbbase, sc->sc_fbsize,
202 1.1 hannken BUS_SPACE_MAP_LINEAR, &ioh);
203 1.1 hannken sc->sc_fb->fb_vram = bus_space_vaddr(sc->sc_fb->fb_iot, ioh);
204 1.1 hannken
205 1.15 rin if (!is_console)
206 1.18 rin fb_init(sc->sc_fb, width, height);
207 1.18 rin fb_initcmap(sc);
208 1.1 hannken
209 1.18 rin printf(": %dx%d 8bpp\n", width, height);
210 1.1 hannken
211 1.18 rin sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
212 1.1 hannken waa.console = is_console;
213 1.1 hannken waa.scrdata = &screenlist;
214 1.1 hannken waa.accessops = &accessops;
215 1.1 hannken waa.accesscookie = sc;
216 1.1 hannken
217 1.5 drochner config_found(self, &waa, wsemuldisplaydevprint);
218 1.1 hannken }
219 1.1 hannken
220 1.1 hannken static void
221 1.18 rin fb_init(struct fb_dev *fb, int width, int height)
222 1.1 hannken {
223 1.1 hannken struct rasops_info *ri = &fb->fb_ri;
224 1.1 hannken
225 1.18 rin ri->ri_width = width;
226 1.18 rin ri->ri_height = height;
227 1.15 rin ri->ri_depth = 8;
228 1.15 rin ri->ri_stride = ri->ri_width;
229 1.15 rin ri->ri_bits = fb->fb_vram;
230 1.15 rin ri->ri_flg = RI_CENTER | RI_CLEAR;
231 1.15 rin if (ri == &console_dev.fb_ri)
232 1.15 rin ri->ri_flg |= RI_NO_AUTO;
233 1.1 hannken
234 1.15 rin rasops_init(ri, 500, 500);
235 1.1 hannken
236 1.2 hannken /* Replace the copy/erase ops. */
237 1.2 hannken ri->ri_hw = fb;
238 1.2 hannken ri->ri_ops.eraserows = fb_eraserows;
239 1.2 hannken ri->ri_ops.erasecols = fb_erasecols;
240 1.2 hannken ri->ri_ops.copyrows = fb_copyrows;
241 1.2 hannken ri->ri_ops.copycols = fb_copycols;
242 1.2 hannken
243 1.1 hannken stdscreen.nrows = ri->ri_rows;
244 1.1 hannken stdscreen.ncols = ri->ri_cols;
245 1.1 hannken stdscreen.textops = &ri->ri_ops;
246 1.1 hannken stdscreen.capabilities = ri->ri_caps;
247 1.1 hannken }
248 1.1 hannken
249 1.18 rin static void
250 1.18 rin fb_initcmap(struct fb_elb_softc *sc)
251 1.18 rin {
252 1.18 rin
253 1.18 rin memcpy(&sc->sc_cmap, rasops_cmap, sizeof(sc->sc_cmap));
254 1.18 rin s3_putcmap(sc->sc_fb, sc->sc_cmap);
255 1.18 rin }
256 1.18 rin
257 1.18 rin static int
258 1.18 rin fb_getcmap(struct fb_elb_softc *sc, struct wsdisplay_cmap *p)
259 1.18 rin {
260 1.18 rin u_int index = p->index, count = p->count;
261 1.18 rin uint8_t buf[CMAP_SIZE * 3];
262 1.18 rin int error, i;
263 1.18 rin
264 1.18 rin if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
265 1.18 rin return EINVAL;
266 1.18 rin
267 1.18 rin for (i = 0; i < count; i++) {
268 1.18 rin buf[i] = sc->sc_cmap[index + i].r;
269 1.18 rin buf[i + count] = sc->sc_cmap[index + i].g;
270 1.18 rin buf[i + 2 * count] = sc->sc_cmap[index + i].b;
271 1.18 rin }
272 1.18 rin
273 1.18 rin if ((error = copyout(&buf[0], p->red, count)) != 0 ||
274 1.18 rin (error = copyout(&buf[count], p->green, count)) != 0 ||
275 1.18 rin (error = copyout(&buf[2 * count], p->blue, count)) != 0)
276 1.18 rin return error;
277 1.18 rin
278 1.18 rin return 0;
279 1.18 rin }
280 1.18 rin
281 1.18 rin static int
282 1.18 rin fb_putcmap(struct fb_elb_softc *sc, const struct wsdisplay_cmap *p)
283 1.18 rin {
284 1.18 rin u_int index = p->index, count = p->count;
285 1.18 rin uint8_t buf[CMAP_SIZE * 3];
286 1.18 rin int error, i;
287 1.18 rin
288 1.18 rin if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
289 1.18 rin return EINVAL;
290 1.18 rin
291 1.18 rin if ((error = copyin(p->red, &buf[0], count)) != 0 ||
292 1.18 rin (error = copyin(p->green, &buf[count], count)) != 0 ||
293 1.18 rin (error = copyin(p->blue, &buf[2 * count], count)) != 0)
294 1.18 rin return error;
295 1.18 rin
296 1.18 rin for (i = 0; i < count; i++) {
297 1.18 rin sc->sc_cmap[index + i].r = buf[i];
298 1.18 rin sc->sc_cmap[index + i].g = buf[i + count];
299 1.18 rin sc->sc_cmap[index + i].b = buf[i + 2 * count];
300 1.18 rin }
301 1.18 rin
302 1.18 rin s3_putcmap(sc->sc_fb, sc->sc_cmap);
303 1.18 rin
304 1.18 rin return 0;
305 1.18 rin }
306 1.18 rin
307 1.1 hannken static int
308 1.8 christos fb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
309 1.1 hannken {
310 1.1 hannken struct fb_elb_softc *sc = v;
311 1.1 hannken struct rasops_info *ri = &sc->sc_fb->fb_ri;
312 1.1 hannken struct wsdisplay_fbinfo *wdf;
313 1.18 rin int new_mode;
314 1.1 hannken
315 1.1 hannken switch (cmd) {
316 1.1 hannken case WSDISPLAYIO_GTYPE:
317 1.1 hannken *(int *)data = WSDISPLAY_TYPE_UNKNOWN; /* XXX */
318 1.17 rin return 0;
319 1.1 hannken
320 1.1 hannken case WSDISPLAYIO_GINFO:
321 1.1 hannken wdf = (void *)data;
322 1.1 hannken wdf->height = ri->ri_height;
323 1.1 hannken wdf->width = ri->ri_width;
324 1.1 hannken wdf->depth = ri->ri_depth;
325 1.18 rin wdf->cmsize = CMAP_SIZE;
326 1.18 rin return 0;
327 1.18 rin
328 1.18 rin case WSDISPLAYIO_LINEBYTES:
329 1.18 rin *(u_int *)data = ri->ri_stride;
330 1.17 rin return 0;
331 1.1 hannken
332 1.1 hannken case WSDISPLAYIO_GETCMAP:
333 1.18 rin return fb_getcmap(sc, (struct wsdisplay_cmap *)data);
334 1.18 rin
335 1.1 hannken case WSDISPLAYIO_PUTCMAP:
336 1.18 rin return fb_putcmap(sc, (struct wsdisplay_cmap *)data);
337 1.18 rin
338 1.18 rin case WSDISPLAYIO_SMODE:
339 1.18 rin new_mode = *(int *)data;
340 1.18 rin if (new_mode != sc->sc_mode) {
341 1.18 rin sc->sc_mode = new_mode;
342 1.18 rin if (new_mode == WSDISPLAYIO_MODE_EMUL) {
343 1.18 rin /* XXX */
344 1.18 rin memset(sc->sc_fb->fb_vram, 0, sc->sc_fbsize);
345 1.18 rin
346 1.18 rin fb_initcmap(sc);
347 1.18 rin }
348 1.18 rin }
349 1.18 rin return 0;
350 1.18 rin
351 1.18 rin default:
352 1.1 hannken break;
353 1.1 hannken }
354 1.1 hannken
355 1.17 rin return EPASSTHROUGH;
356 1.1 hannken }
357 1.1 hannken
358 1.1 hannken static paddr_t
359 1.7 hannken fb_mmap(void *v, void *vs, off_t offset, int prot)
360 1.1 hannken {
361 1.4 hannken struct fb_elb_softc *sc = v;
362 1.4 hannken
363 1.18 rin if (offset < 0 || offset >= sc->sc_fbsize)
364 1.4 hannken return -1;
365 1.4 hannken
366 1.18 rin return bus_space_mmap(sc->sc_fb->fb_iot, sc->sc_fbbase, offset, prot,
367 1.4 hannken BUS_SPACE_MAP_LINEAR);
368 1.1 hannken }
369 1.1 hannken
370 1.1 hannken static int
371 1.1 hannken fb_alloc_screen(void *v, const struct wsscreen_descr *scrdesc, void **cookiep,
372 1.1 hannken int *ccolp, int *crowp, long *attrp)
373 1.1 hannken {
374 1.1 hannken struct fb_elb_softc *sc = v;
375 1.1 hannken struct rasops_info *ri = &sc->sc_fb->fb_ri;
376 1.1 hannken
377 1.1 hannken if (sc->sc_nscreens > 0)
378 1.1 hannken return ENOMEM;
379 1.1 hannken
380 1.1 hannken *cookiep = ri;
381 1.1 hannken *ccolp = *crowp = 0;
382 1.1 hannken (*ri->ri_ops.allocattr)(ri, 0, 0, 0, attrp);
383 1.1 hannken sc->sc_nscreens++;
384 1.1 hannken
385 1.17 rin return 0;
386 1.1 hannken }
387 1.1 hannken
388 1.1 hannken static void
389 1.1 hannken fb_free_screen(void *v, void *cookie)
390 1.1 hannken {
391 1.1 hannken struct fb_elb_softc *sc = v;
392 1.1 hannken
393 1.1 hannken if (sc->sc_fb == &console_dev)
394 1.1 hannken panic("fb_free_screen: freeing console");
395 1.1 hannken
396 1.1 hannken sc->sc_nscreens--;
397 1.1 hannken }
398 1.1 hannken
399 1.1 hannken static int
400 1.1 hannken fb_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int),
401 1.1 hannken void *cbarg)
402 1.1 hannken {
403 1.1 hannken
404 1.17 rin return 0;
405 1.1 hannken }
406 1.1 hannken
407 1.2 hannken static void
408 1.2 hannken fb_eraserows(void *v, int row, int nrows, long attr)
409 1.2 hannken {
410 1.2 hannken struct rasops_info *ri = v;
411 1.2 hannken struct fb_dev *fb = ri->ri_hw;
412 1.2 hannken
413 1.2 hannken row *= ri->ri_font->fontheight;
414 1.2 hannken nrows *= ri->ri_font->fontheight;
415 1.2 hannken
416 1.2 hannken s3_fill(fb, 0, row, ri->ri_stride, nrows, (attr >> 16)&0x0f, 0x0f);
417 1.2 hannken }
418 1.2 hannken
419 1.2 hannken static void
420 1.2 hannken fb_erasecols(void *v, int row, int startcol, int ncols, long attr)
421 1.2 hannken {
422 1.2 hannken struct rasops_info *ri = v;
423 1.2 hannken struct fb_dev *fb = ri->ri_hw;
424 1.2 hannken
425 1.2 hannken row *= ri->ri_font->fontheight;
426 1.2 hannken startcol *= ri->ri_font->fontwidth;
427 1.2 hannken ncols *= ri->ri_font->fontwidth;
428 1.2 hannken
429 1.2 hannken s3_fill(fb, startcol, row, ncols, ri->ri_font->fontheight,
430 1.2 hannken (attr >> 16)&0x0f, 0x0f);
431 1.2 hannken }
432 1.2 hannken
433 1.2 hannken static void
434 1.2 hannken fb_copyrows(void *v, int srcrow, int dstrow, int nrows)
435 1.2 hannken {
436 1.2 hannken struct rasops_info *ri = v;
437 1.2 hannken struct fb_dev *fb = ri->ri_hw;
438 1.2 hannken
439 1.2 hannken srcrow *= ri->ri_font->fontheight;
440 1.2 hannken dstrow *= ri->ri_font->fontheight;
441 1.2 hannken nrows *= ri->ri_font->fontheight;
442 1.2 hannken
443 1.2 hannken s3_copy(fb, 0, srcrow, 0, dstrow, ri->ri_stride, nrows, 0x0f);
444 1.2 hannken }
445 1.2 hannken
446 1.2 hannken static void
447 1.2 hannken fb_copycols(void *v, int row, int srccol, int dstcol, int ncols)
448 1.2 hannken {
449 1.2 hannken struct rasops_info *ri = v;
450 1.2 hannken struct fb_dev *fb = ri->ri_hw;
451 1.2 hannken
452 1.2 hannken row *= ri->ri_font->fontheight;
453 1.2 hannken srccol *= ri->ri_font->fontwidth;
454 1.2 hannken dstcol *= ri->ri_font->fontwidth;
455 1.2 hannken ncols *= ri->ri_font->fontwidth;
456 1.2 hannken
457 1.2 hannken s3_copy(fb, srccol, row, dstcol, row,
458 1.2 hannken ncols, ri->ri_font->fontheight, 0x0f);
459 1.2 hannken }
460 1.2 hannken
461 1.1 hannken /*
462 1.1 hannken * S3 support routines
463 1.1 hannken */
464 1.1 hannken
465 1.1 hannken #define S3_CRTC_INDEX 0x83d4
466 1.1 hannken #define S3_CRTC_DATA 0x83d5
467 1.1 hannken
468 1.1 hannken #define S3_DAC_RD_INDEX 0x83c7
469 1.1 hannken #define S3_DAC_WR_INDEX 0x83c8
470 1.1 hannken #define S3_DAC_DATA 0x83c9
471 1.1 hannken
472 1.2 hannken #define S3_CUR_Y 0x82e8
473 1.2 hannken #define S3_CUR_X 0x86e8
474 1.2 hannken #define S3_DESTY_AXSTP 0x8ae8
475 1.2 hannken #define S3_DESTX_DIASTP 0x8ee8
476 1.2 hannken #define S3_MAJ_AXIS_PCNT 0x96e8
477 1.2 hannken #define S3_GP_STAT 0x9ae8
478 1.2 hannken #define S3_CMD 0x9ae8
479 1.2 hannken #define S3_BKGD_COLOR 0xa2e8
480 1.2 hannken #define S3_FRGD_COLOR 0xa6e8
481 1.2 hannken #define S3_WRT_MASK 0xaae8
482 1.2 hannken #define S3_RD_MASK 0xaee8
483 1.2 hannken #define S3_BKGD_MIX 0xb6e8
484 1.2 hannken #define S3_FRGD_MIX 0xbae8
485 1.2 hannken #define S3_MULTIFUNC_CNTL 0xbee8
486 1.2 hannken
487 1.2 hannken #define S3_GP_STAT_FIFO_1 0x0080
488 1.2 hannken #define S3_GP_STAT_BSY 0x0200
489 1.2 hannken
490 1.2 hannken #define S3_CMD_BITBLT 0xc001
491 1.2 hannken #define S3_CMD_RECT 0x4001
492 1.2 hannken #define S3_INC_Y 0x0080
493 1.2 hannken #define S3_INC_X 0x0020
494 1.2 hannken #define S3_DRAW 0x0010
495 1.2 hannken #define S3_MULTI 0x0002
496 1.2 hannken
497 1.2 hannken #define S3_CSRC_BKGDCOL 0x0000
498 1.2 hannken #define S3_CSRC_FRGDCOL 0x0020
499 1.2 hannken #define S3_CSRC_DISPMEM 0x0060
500 1.2 hannken #define S3_MIX_NEW 0x0007
501 1.2 hannken
502 1.1 hannken static void
503 1.18 rin s3_getgeometry(struct fb_dev *fb, int *width, int *height)
504 1.1 hannken {
505 1.1 hannken bus_space_tag_t iot = fb->fb_iot;
506 1.1 hannken bus_space_handle_t ioh = fb->fb_ioh;
507 1.18 rin int w, h, i;
508 1.1 hannken
509 1.1 hannken bus_space_write_1(iot, ioh, S3_CRTC_INDEX, 1);
510 1.1 hannken w = bus_space_read_1(iot, ioh, S3_CRTC_DATA);
511 1.1 hannken
512 1.1 hannken bus_space_write_1(iot, ioh, S3_CRTC_INDEX, 18);
513 1.1 hannken h = bus_space_read_1(iot, ioh, S3_CRTC_DATA);
514 1.1 hannken
515 1.1 hannken bus_space_write_1(iot, ioh, S3_CRTC_INDEX, 7);
516 1.1 hannken i = bus_space_read_1(iot, ioh, S3_CRTC_DATA);
517 1.1 hannken
518 1.1 hannken h += (i << 7) & 0x100;
519 1.1 hannken h += (i << 3) & 0x200;
520 1.1 hannken
521 1.1 hannken *width = (w+1) << 3;
522 1.1 hannken *height = h+1;
523 1.2 hannken }
524 1.2 hannken
525 1.2 hannken static void
526 1.18 rin s3_putcmap(struct fb_dev *fb, const struct fb_cmap *cmap)
527 1.18 rin {
528 1.18 rin bus_space_tag_t iot = fb->fb_iot;
529 1.18 rin bus_space_handle_t ioh = fb->fb_ioh;
530 1.18 rin int i;
531 1.18 rin
532 1.18 rin bus_space_write_1(iot, ioh, S3_DAC_WR_INDEX, 0);
533 1.18 rin for (i = 0; i < CMAP_SIZE; i++) {
534 1.18 rin bus_space_write_1(iot, ioh, S3_DAC_DATA, cmap[i].r >> 2);
535 1.18 rin bus_space_write_1(iot, ioh, S3_DAC_DATA, cmap[i].g >> 2);
536 1.18 rin bus_space_write_1(iot, ioh, S3_DAC_DATA, cmap[i].b >> 2);
537 1.18 rin }
538 1.18 rin }
539 1.18 rin
540 1.18 rin static void
541 1.2 hannken s3_copy(struct fb_dev *fb, int src_x, int src_y, int dest_x, int dest_y,
542 1.2 hannken int width, int height, int mask)
543 1.2 hannken {
544 1.2 hannken bus_space_tag_t iot = fb->fb_iot;
545 1.2 hannken bus_space_handle_t ioh = fb->fb_ioh;
546 1.2 hannken u_int16_t cmd = S3_CMD_BITBLT | S3_DRAW;
547 1.2 hannken
548 1.2 hannken if (src_x > dest_x)
549 1.2 hannken cmd |= S3_INC_X;
550 1.2 hannken else {
551 1.2 hannken src_x += width-1;
552 1.2 hannken dest_x += width-1;
553 1.2 hannken }
554 1.2 hannken
555 1.2 hannken if (src_y > dest_y)
556 1.2 hannken cmd |= S3_INC_Y;
557 1.2 hannken else {
558 1.2 hannken src_y += height-1;
559 1.2 hannken dest_y += height-1;
560 1.2 hannken }
561 1.2 hannken
562 1.2 hannken while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_FIFO_1)
563 1.2 hannken ;
564 1.2 hannken
565 1.2 hannken bus_space_write_2(iot, ioh, S3_FRGD_MIX, S3_CSRC_DISPMEM | S3_MIX_NEW);
566 1.2 hannken bus_space_write_2(iot, ioh, S3_WRT_MASK, mask);
567 1.2 hannken bus_space_write_2(iot, ioh, S3_CUR_X, src_x);
568 1.2 hannken bus_space_write_2(iot, ioh, S3_CUR_Y, src_y);
569 1.2 hannken bus_space_write_2(iot, ioh, S3_DESTX_DIASTP, dest_x);
570 1.2 hannken bus_space_write_2(iot, ioh, S3_DESTY_AXSTP, dest_y);
571 1.2 hannken bus_space_write_2(iot, ioh, S3_MULTIFUNC_CNTL, height-1);
572 1.2 hannken bus_space_write_2(iot, ioh, S3_MAJ_AXIS_PCNT, width-1);
573 1.2 hannken bus_space_write_2(iot, ioh, S3_CMD, cmd);
574 1.2 hannken
575 1.2 hannken while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_BSY)
576 1.2 hannken ;
577 1.2 hannken }
578 1.2 hannken
579 1.2 hannken static void
580 1.2 hannken s3_fill(struct fb_dev *fb, int x, int y, int width, int height,
581 1.2 hannken int color, int mask)
582 1.2 hannken {
583 1.2 hannken bus_space_tag_t iot = fb->fb_iot;
584 1.2 hannken bus_space_handle_t ioh = fb->fb_ioh;
585 1.2 hannken u_int16_t cmd = S3_CMD_RECT | S3_INC_X | S3_INC_Y | S3_DRAW;
586 1.2 hannken
587 1.2 hannken while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_FIFO_1)
588 1.2 hannken ;
589 1.2 hannken
590 1.2 hannken bus_space_write_2(iot, ioh, S3_FRGD_MIX, S3_CSRC_FRGDCOL | S3_MIX_NEW);
591 1.2 hannken bus_space_write_2(iot, ioh, S3_FRGD_COLOR, color);
592 1.2 hannken bus_space_write_2(iot, ioh, S3_WRT_MASK, mask);
593 1.2 hannken bus_space_write_2(iot, ioh, S3_CUR_X, x);
594 1.2 hannken bus_space_write_2(iot, ioh, S3_CUR_Y, y);
595 1.2 hannken bus_space_write_2(iot, ioh, S3_MULTIFUNC_CNTL, height-1);
596 1.2 hannken bus_space_write_2(iot, ioh, S3_MAJ_AXIS_PCNT, width-1);
597 1.2 hannken bus_space_write_2(iot, ioh, S3_CMD, cmd);
598 1.2 hannken
599 1.2 hannken while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_BSY)
600 1.2 hannken ;
601 1.1 hannken }
602