p9100.c revision 1.59 1 1.59 chs /* $NetBSD: p9100.c,v 1.59 2012/10/27 17:18:37 chs Exp $ */
2 1.1 pk
3 1.1 pk /*-
4 1.27 macallan * Copyright (c) 1998, 2005, 2006 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Matt Thomas.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk *
19 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pk */
31 1.1 pk
32 1.1 pk /*
33 1.1 pk * color display (p9100) driver.
34 1.1 pk *
35 1.1 pk * Does not handle interrupts, even though they can occur.
36 1.1 pk *
37 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
38 1.1 pk */
39 1.5 lukem
40 1.5 lukem #include <sys/cdefs.h>
41 1.59 chs __KERNEL_RCSID(0, "$NetBSD: p9100.c,v 1.59 2012/10/27 17:18:37 chs Exp $");
42 1.1 pk
43 1.1 pk #include <sys/param.h>
44 1.1 pk #include <sys/systm.h>
45 1.1 pk #include <sys/buf.h>
46 1.1 pk #include <sys/device.h>
47 1.1 pk #include <sys/ioctl.h>
48 1.1 pk #include <sys/malloc.h>
49 1.1 pk #include <sys/mman.h>
50 1.1 pk #include <sys/tty.h>
51 1.1 pk #include <sys/conf.h>
52 1.1 pk
53 1.36 ad #include <sys/bus.h>
54 1.1 pk #include <machine/autoconf.h>
55 1.1 pk
56 1.1 pk #include <dev/sun/fbio.h>
57 1.1 pk #include <dev/sun/fbvar.h>
58 1.1 pk #include <dev/sun/btreg.h>
59 1.1 pk #include <dev/sun/btvar.h>
60 1.21 macallan
61 1.1 pk #include <dev/sbus/p9100reg.h>
62 1.1 pk
63 1.1 pk #include <dev/sbus/sbusvar.h>
64 1.1 pk
65 1.44 macallan #include <dev/wscons/wsdisplayvar.h>
66 1.21 macallan #include <dev/wscons/wsconsio.h>
67 1.21 macallan #include <dev/wsfont/wsfont.h>
68 1.21 macallan #include <dev/rasops/rasops.h>
69 1.21 macallan
70 1.27 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
71 1.57 macallan #include <dev/wscons/wsdisplay_glyphcachevar.h>
72 1.27 macallan
73 1.21 macallan #include "opt_wsemul.h"
74 1.22 macallan #include "rasops_glue.h"
75 1.45 macallan #include "opt_pnozz.h"
76 1.21 macallan
77 1.49 tsutsui #include "ioconf.h"
78 1.49 tsutsui
79 1.1 pk #include "tctrl.h"
80 1.1 pk #if NTCTRL > 0
81 1.1 pk #include <machine/tctrl.h>
82 1.45 macallan #include <sparc/dev/tctrlvar.h> /*XXX*/
83 1.1 pk #endif
84 1.1 pk
85 1.44 macallan #ifdef PNOZZ_DEBUG
86 1.44 macallan #define DPRINTF aprint_normal
87 1.44 macallan #else
88 1.44 macallan #define DPRINTF while (0) aprint_normal
89 1.44 macallan #endif
90 1.44 macallan
91 1.24 macallan struct pnozz_cursor {
92 1.24 macallan short pc_enable; /* cursor is enabled */
93 1.24 macallan struct fbcurpos pc_pos; /* position */
94 1.24 macallan struct fbcurpos pc_hot; /* hot-spot */
95 1.24 macallan struct fbcurpos pc_size; /* size of mask & image fields */
96 1.24 macallan uint32_t pc_bits[0x100]; /* space for mask & image bits */
97 1.24 macallan unsigned char red[3], green[3];
98 1.24 macallan unsigned char blue[3]; /* cursor palette */
99 1.24 macallan };
100 1.24 macallan
101 1.1 pk /* per-display variables */
102 1.1 pk struct p9100_softc {
103 1.44 macallan device_t sc_dev; /* base device */
104 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
105 1.24 macallan
106 1.1 pk bus_space_tag_t sc_bustag;
107 1.8 pk
108 1.8 pk bus_addr_t sc_ctl_paddr; /* phys address description */
109 1.1 pk bus_size_t sc_ctl_psize; /* for device mmap() */
110 1.1 pk bus_space_handle_t sc_ctl_memh; /* bus space handle */
111 1.8 pk
112 1.8 pk bus_addr_t sc_fb_paddr; /* phys address description */
113 1.1 pk bus_size_t sc_fb_psize; /* for device mmap() */
114 1.54 macallan #ifdef PNOZZ_USE_LATCH
115 1.1 pk bus_space_handle_t sc_fb_memh; /* bus space handle */
116 1.54 macallan #endif
117 1.27 macallan volatile uint32_t sc_junk;
118 1.45 macallan uint32_t sc_mono_width; /* for setup_mono */
119 1.33 blymn
120 1.44 macallan uint32_t sc_width;
121 1.44 macallan uint32_t sc_height; /* panel width / height */
122 1.44 macallan uint32_t sc_stride;
123 1.44 macallan uint32_t sc_depth;
124 1.44 macallan int sc_depthshift; /* blitter works on bytes not pixels */
125 1.44 macallan
126 1.21 macallan union bt_cmap sc_cmap; /* Brooktree color map */
127 1.21 macallan
128 1.24 macallan struct pnozz_cursor sc_cursor;
129 1.24 macallan
130 1.45 macallan int sc_mode;
131 1.45 macallan int sc_video, sc_powerstate;
132 1.45 macallan uint32_t sc_bg;
133 1.27 macallan volatile uint32_t sc_last_offset;
134 1.27 macallan struct vcons_data vd;
135 1.45 macallan uint8_t sc_dac_power;
136 1.57 macallan glyphcache sc_gc;
137 1.21 macallan };
138 1.21 macallan
139 1.21 macallan
140 1.27 macallan static struct vcons_screen p9100_console_screen;
141 1.21 macallan
142 1.21 macallan extern const u_char rasops_cmap[768];
143 1.21 macallan
144 1.21 macallan struct wsscreen_descr p9100_defscreendesc = {
145 1.21 macallan "default",
146 1.21 macallan 0, 0,
147 1.21 macallan NULL,
148 1.21 macallan 8, 16,
149 1.21 macallan WSSCREEN_WSCOLORS,
150 1.21 macallan };
151 1.1 pk
152 1.21 macallan const struct wsscreen_descr *_p9100_scrlist[] = {
153 1.21 macallan &p9100_defscreendesc,
154 1.21 macallan /* XXX other formats, graphics screen? */
155 1.1 pk };
156 1.1 pk
157 1.21 macallan struct wsscreen_list p9100_screenlist = {
158 1.45 macallan sizeof(_p9100_scrlist) / sizeof(struct wsscreen_descr *),
159 1.45 macallan _p9100_scrlist
160 1.21 macallan };
161 1.1 pk
162 1.1 pk /* autoconfiguration driver */
163 1.43 cegger static int p9100_sbus_match(device_t, cfdata_t, void *);
164 1.43 cegger static void p9100_sbus_attach(device_t, device_t, void *);
165 1.1 pk
166 1.43 cegger static void p9100unblank(device_t);
167 1.1 pk
168 1.44 macallan CFATTACH_DECL_NEW(pnozz, sizeof(struct p9100_softc),
169 1.13 thorpej p9100_sbus_match, p9100_sbus_attach, NULL, NULL);
170 1.1 pk
171 1.27 macallan static dev_type_open(p9100open);
172 1.57 macallan static dev_type_close(p9100close);
173 1.27 macallan static dev_type_ioctl(p9100ioctl);
174 1.27 macallan static dev_type_mmap(p9100mmap);
175 1.10 gehenna
176 1.10 gehenna const struct cdevsw pnozz_cdevsw = {
177 1.10 gehenna p9100open, nullclose, noread, nowrite, p9100ioctl,
178 1.14 jdolecek nostop, notty, nopoll, p9100mmap, nokqfilter,
179 1.10 gehenna };
180 1.10 gehenna
181 1.1 pk /* frame buffer generic driver */
182 1.1 pk static struct fbdriver p9100fbdriver = {
183 1.57 macallan p9100unblank, p9100open, p9100close, p9100ioctl, nopoll,
184 1.14 jdolecek p9100mmap, nokqfilter
185 1.1 pk };
186 1.1 pk
187 1.21 macallan static void p9100loadcmap(struct p9100_softc *, int, int);
188 1.21 macallan static void p9100_set_video(struct p9100_softc *, int);
189 1.21 macallan static int p9100_get_video(struct p9100_softc *);
190 1.1 pk static uint32_t p9100_ctl_read_4(struct p9100_softc *, bus_size_t);
191 1.21 macallan static void p9100_ctl_write_4(struct p9100_softc *, bus_size_t, uint32_t);
192 1.27 macallan static uint8_t p9100_ramdac_read(struct p9100_softc *, bus_size_t);
193 1.27 macallan static void p9100_ramdac_write(struct p9100_softc *, bus_size_t, uint8_t);
194 1.27 macallan
195 1.27 macallan static uint8_t p9100_ramdac_read_ctl(struct p9100_softc *, int);
196 1.27 macallan static void p9100_ramdac_write_ctl(struct p9100_softc *, int, uint8_t);
197 1.21 macallan
198 1.27 macallan static void p9100_init_engine(struct p9100_softc *);
199 1.44 macallan static int p9100_set_depth(struct p9100_softc *, int);
200 1.28 macallan
201 1.28 macallan #if NWSDISPLAY > 0
202 1.21 macallan static void p9100_sync(struct p9100_softc *);
203 1.57 macallan static void p9100_bitblt(void *, int, int, int, int, int, int, int);
204 1.27 macallan static void p9100_rectfill(void *, int, int, int, int, uint32_t);
205 1.28 macallan static void p9100_clearscreen(struct p9100_softc *);
206 1.28 macallan
207 1.33 blymn static void p9100_setup_mono(struct p9100_softc *, int, int, int, int,
208 1.33 blymn uint32_t, uint32_t);
209 1.27 macallan static void p9100_feed_line(struct p9100_softc *, int, uint8_t *);
210 1.21 macallan static void p9100_set_color_reg(struct p9100_softc *, int, int32_t);
211 1.21 macallan
212 1.27 macallan static void p9100_copycols(void *, int, int, int, int);
213 1.27 macallan static void p9100_erasecols(void *, int, int, int, long);
214 1.27 macallan static void p9100_copyrows(void *, int, int, int);
215 1.27 macallan static void p9100_eraserows(void *, int, int, long);
216 1.27 macallan /*static int p9100_mapchar(void *, int, u_int *);*/
217 1.27 macallan static void p9100_putchar(void *, int, int, u_int, long);
218 1.57 macallan static void p9100_putchar_aa(void *, int, int, u_int, long);
219 1.27 macallan static void p9100_cursor(void *, int, int, int);
220 1.27 macallan
221 1.27 macallan static int p9100_putcmap(struct p9100_softc *, struct wsdisplay_cmap *);
222 1.27 macallan static int p9100_getcmap(struct p9100_softc *, struct wsdisplay_cmap *);
223 1.35 christos static int p9100_ioctl(void *, void *, u_long, void *, int, struct lwp *);
224 1.31 jmmv static paddr_t p9100_mmap(void *, void *, off_t, int);
225 1.33 blymn
226 1.27 macallan /*static int p9100_load_font(void *, void *, struct wsdisplay_font *);*/
227 1.21 macallan
228 1.33 blymn static void p9100_init_screen(void *, struct vcons_screen *, int,
229 1.45 macallan long *);
230 1.28 macallan #endif
231 1.28 macallan
232 1.27 macallan static void p9100_init_cursor(struct p9100_softc *);
233 1.28 macallan
234 1.27 macallan static void p9100_set_fbcursor(struct p9100_softc *);
235 1.27 macallan static void p9100_setcursorcmap(struct p9100_softc *);
236 1.27 macallan static void p9100_loadcursor(struct p9100_softc *);
237 1.27 macallan
238 1.44 macallan #if 0
239 1.27 macallan static int p9100_intr(void *);
240 1.44 macallan #endif
241 1.21 macallan
242 1.27 macallan /* power management stuff */
243 1.52 dyoung static bool p9100_suspend(device_t, const pmf_qual_t *);
244 1.52 dyoung static bool p9100_resume(device_t, const pmf_qual_t *);
245 1.27 macallan
246 1.40 he #if NTCTRL > 0
247 1.27 macallan static void p9100_set_extvga(void *, int);
248 1.40 he #endif
249 1.21 macallan
250 1.28 macallan #if NWSDISPLAY > 0
251 1.21 macallan struct wsdisplay_accessops p9100_accessops = {
252 1.21 macallan p9100_ioctl,
253 1.21 macallan p9100_mmap,
254 1.27 macallan NULL, /* vcons_alloc_screen */
255 1.27 macallan NULL, /* vcons_free_screen */
256 1.27 macallan NULL, /* vcons_show_screen */
257 1.21 macallan NULL, /* load_font */
258 1.21 macallan NULL, /* polls */
259 1.21 macallan NULL, /* scroll */
260 1.21 macallan };
261 1.28 macallan #endif
262 1.1 pk
263 1.54 macallan #ifdef PNOZZ_USE_LATCH
264 1.53 macallan #define PNOZZ_LATCH(sc, off) if(sc->sc_last_offset != (off & 0xffffff80)) { \
265 1.27 macallan sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, \
266 1.27 macallan off); \
267 1.27 macallan sc->sc_last_offset = off & 0xffffff80; }
268 1.54 macallan #else
269 1.54 macallan #define PNOZZ_LATCH(a, b)
270 1.54 macallan #endif
271 1.27 macallan
272 1.1 pk /*
273 1.1 pk * Match a p9100.
274 1.1 pk */
275 1.1 pk static int
276 1.43 cegger p9100_sbus_match(device_t parent, cfdata_t cf, void *aux)
277 1.1 pk {
278 1.1 pk struct sbus_attach_args *sa = aux;
279 1.1 pk
280 1.44 macallan if (strcmp("p9100", sa->sa_name) == 0)
281 1.44 macallan return 100;
282 1.44 macallan return 0;
283 1.1 pk }
284 1.1 pk
285 1.1 pk
286 1.1 pk /*
287 1.1 pk * Attach a display. We need to notice if it is the console, too.
288 1.1 pk */
289 1.1 pk static void
290 1.43 cegger p9100_sbus_attach(device_t parent, device_t self, void *args)
291 1.1 pk {
292 1.39 drochner struct p9100_softc *sc = device_private(self);
293 1.1 pk struct sbus_attach_args *sa = args;
294 1.1 pk struct fbdevice *fb = &sc->sc_fb;
295 1.1 pk int isconsole;
296 1.44 macallan int node = sa->sa_node;
297 1.21 macallan int i, j;
298 1.57 macallan uint8_t ver, cmap[768];
299 1.21 macallan
300 1.21 macallan #if NWSDISPLAY > 0
301 1.21 macallan struct wsemuldisplaydev_attach_args aa;
302 1.21 macallan struct rasops_info *ri;
303 1.21 macallan unsigned long defattr;
304 1.21 macallan #endif
305 1.1 pk
306 1.27 macallan sc->sc_last_offset = 0xffffffff;
307 1.44 macallan sc->sc_dev = self;
308 1.44 macallan
309 1.44 macallan /*
310 1.44 macallan * When the ROM has mapped in a p9100 display, the address
311 1.44 macallan * maps only the video RAM, so in any case we have to map the
312 1.45 macallan * registers ourselves.
313 1.44 macallan */
314 1.44 macallan
315 1.44 macallan if (sa->sa_npromvaddrs != 0)
316 1.44 macallan fb->fb_pixels = (void *)sa->sa_promvaddrs[0];
317 1.27 macallan
318 1.1 pk /* Remember cookies for p9100_mmap() */
319 1.1 pk sc->sc_bustag = sa->sa_bustag;
320 1.44 macallan
321 1.20 perry sc->sc_ctl_paddr = sbus_bus_addr(sa->sa_bustag,
322 1.9 thorpej sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base);
323 1.21 macallan sc->sc_ctl_psize = 0x8000;/*(bus_size_t)sa->sa_reg[0].oa_size;*/
324 1.3 eeh
325 1.20 perry sc->sc_fb_paddr = sbus_bus_addr(sa->sa_bustag,
326 1.9 thorpej sa->sa_reg[2].oa_space, sa->sa_reg[2].oa_base);
327 1.9 thorpej sc->sc_fb_psize = (bus_size_t)sa->sa_reg[2].oa_size;
328 1.1 pk
329 1.44 macallan if (sbus_bus_map(sc->sc_bustag,
330 1.44 macallan sa->sa_reg[0].oa_space,
331 1.44 macallan sa->sa_reg[0].oa_base,
332 1.44 macallan /*
333 1.44 macallan * XXX for some reason the SBus resources don't cover
334 1.44 macallan * all registers, so we just map what we need
335 1.44 macallan */
336 1.44 macallan 0x8000,
337 1.44 macallan 0, &sc->sc_ctl_memh) != 0) {
338 1.44 macallan printf("%s: cannot map control registers\n",
339 1.59 chs device_xname(self));
340 1.44 macallan return;
341 1.44 macallan }
342 1.44 macallan
343 1.45 macallan /*
344 1.45 macallan * we need to map the framebuffer even though we never write to it,
345 1.45 macallan * thanks to some weirdness in the SPARCbook's SBus glue for the
346 1.45 macallan * P9100 - all register accesses need to be 'latched in' whenever we
347 1.45 macallan * go to another 0x80 aligned 'page' by reading the framebuffer at the
348 1.45 macallan * same offset
349 1.54 macallan * XXX apparently the latter isn't true - my SP3GX works fine without
350 1.45 macallan */
351 1.54 macallan #ifdef PNOZZ_USE_LATCH
352 1.44 macallan if (fb->fb_pixels == NULL) {
353 1.44 macallan if (sbus_bus_map(sc->sc_bustag,
354 1.44 macallan sa->sa_reg[2].oa_space,
355 1.44 macallan sa->sa_reg[2].oa_base,
356 1.44 macallan sc->sc_fb_psize,
357 1.45 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
358 1.45 macallan &sc->sc_fb_memh) != 0) {
359 1.44 macallan printf("%s: cannot map framebuffer\n",
360 1.59 chs device_xname(self));
361 1.44 macallan return;
362 1.44 macallan }
363 1.44 macallan fb->fb_pixels = (char *)sc->sc_fb_memh;
364 1.44 macallan } else {
365 1.44 macallan sc->sc_fb_memh = (bus_space_handle_t) fb->fb_pixels;
366 1.44 macallan }
367 1.54 macallan #endif
368 1.44 macallan sc->sc_width = prom_getpropint(node, "width", 800);
369 1.44 macallan sc->sc_height = prom_getpropint(node, "height", 600);
370 1.44 macallan sc->sc_depth = prom_getpropint(node, "depth", 8) >> 3;
371 1.44 macallan
372 1.44 macallan sc->sc_stride = prom_getpropint(node, "linebytes",
373 1.44 macallan sc->sc_width * sc->sc_depth);
374 1.44 macallan
375 1.1 pk fb->fb_driver = &p9100fbdriver;
376 1.44 macallan fb->fb_device = sc->sc_dev;
377 1.44 macallan fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK;
378 1.21 macallan #ifdef PNOZZ_EMUL_CG3
379 1.1 pk fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
380 1.21 macallan #else
381 1.21 macallan fb->fb_type.fb_type = FBTYPE_P9100;
382 1.21 macallan #endif
383 1.7 cyber fb->fb_pixels = NULL;
384 1.33 blymn
385 1.21 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
386 1.1 pk
387 1.7 cyber isconsole = fb_is_console(node);
388 1.44 macallan #if 0
389 1.7 cyber if (!isconsole) {
390 1.37 cegger aprint_normal("\n");
391 1.37 cegger aprint_error_dev(self, "fatal error: PROM didn't configure device\n");
392 1.7 cyber return;
393 1.7 cyber }
394 1.44 macallan #endif
395 1.1 pk
396 1.44 macallan fb->fb_type.fb_depth = 8;
397 1.44 macallan sc->sc_depth = 1;
398 1.44 macallan sc->sc_depthshift = 0;
399 1.21 macallan
400 1.27 macallan /* check the RAMDAC */
401 1.27 macallan ver = p9100_ramdac_read_ctl(sc, DAC_VERSION);
402 1.33 blymn
403 1.21 macallan p9100_init_engine(sc);
404 1.44 macallan p9100_set_depth(sc, 8);
405 1.44 macallan
406 1.33 blymn fb_setsize_obp(fb, fb->fb_type.fb_depth, sc->sc_width, sc->sc_height,
407 1.21 macallan node);
408 1.1 pk
409 1.44 macallan #if 0
410 1.27 macallan bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
411 1.27 macallan p9100_intr, sc);
412 1.44 macallan #endif
413 1.1 pk
414 1.19 pk fb->fb_type.fb_cmsize = prom_getpropint(node, "cmsize", 256);
415 1.1 pk if ((1 << fb->fb_type.fb_depth) != fb->fb_type.fb_cmsize)
416 1.1 pk printf(", %d entry colormap", fb->fb_type.fb_cmsize);
417 1.1 pk
418 1.1 pk /* make sure we are not blanked */
419 1.7 cyber if (isconsole)
420 1.7 cyber p9100_set_video(sc, 1);
421 1.1 pk
422 1.45 macallan /* register with power management */
423 1.45 macallan sc->sc_video = 1;
424 1.45 macallan sc->sc_powerstate = PWR_RESUME;
425 1.45 macallan if (!pmf_device_register(self, p9100_suspend, p9100_resume)) {
426 1.45 macallan panic("%s: could not register with PMF",
427 1.44 macallan device_xname(sc->sc_dev));
428 1.1 pk }
429 1.1 pk
430 1.1 pk if (isconsole) {
431 1.1 pk printf(" (console)\n");
432 1.1 pk #ifdef RASTERCONSOLE
433 1.21 macallan /*p9100loadcmap(sc, 255, 1);*/
434 1.1 pk fbrcons_init(fb);
435 1.1 pk #endif
436 1.1 pk } else
437 1.1 pk printf("\n");
438 1.33 blymn
439 1.21 macallan #if NWSDISPLAY > 0
440 1.21 macallan wsfont_init();
441 1.33 blymn
442 1.57 macallan #ifdef PNOZZ_DEBUG
443 1.57 macallan /* make the glyph cache visible */
444 1.57 macallan sc->sc_height -= 100;
445 1.57 macallan #endif
446 1.57 macallan
447 1.57 macallan sc->sc_gc.gc_bitblt = p9100_bitblt;
448 1.57 macallan sc->sc_gc.gc_blitcookie = sc;
449 1.57 macallan sc->sc_gc.gc_rop = ROP_SRC;
450 1.57 macallan
451 1.27 macallan vcons_init(&sc->vd, sc, &p9100_defscreendesc, &p9100_accessops);
452 1.27 macallan sc->vd.init_screen = p9100_init_screen;
453 1.33 blymn
454 1.27 macallan vcons_init_screen(&sc->vd, &p9100_console_screen, 1, &defattr);
455 1.27 macallan p9100_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
456 1.21 macallan
457 1.57 macallan /* Initialize the default color map. */
458 1.57 macallan rasops_get_cmap(&p9100_console_screen.scr_ri, cmap, 768);
459 1.57 macallan
460 1.57 macallan j = 0;
461 1.57 macallan for (i = 0; i < 256; i++) {
462 1.57 macallan sc->sc_cmap.cm_map[i][0] = cmap[j];
463 1.57 macallan j++;
464 1.57 macallan sc->sc_cmap.cm_map[i][1] = cmap[j];
465 1.57 macallan j++;
466 1.57 macallan sc->sc_cmap.cm_map[i][2] = cmap[j];
467 1.57 macallan j++;
468 1.57 macallan }
469 1.57 macallan p9100loadcmap(sc, 0, 256);
470 1.57 macallan
471 1.27 macallan sc->sc_bg = (defattr >> 16) & 0xff;
472 1.27 macallan p9100_clearscreen(sc);
473 1.33 blymn
474 1.27 macallan ri = &p9100_console_screen.scr_ri;
475 1.21 macallan
476 1.21 macallan p9100_defscreendesc.nrows = ri->ri_rows;
477 1.21 macallan p9100_defscreendesc.ncols = ri->ri_cols;
478 1.21 macallan p9100_defscreendesc.textops = &ri->ri_ops;
479 1.21 macallan p9100_defscreendesc.capabilities = ri->ri_caps;
480 1.33 blymn
481 1.57 macallan glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
482 1.57 macallan (0x200000 / sc->sc_stride) - sc->sc_height - 5,
483 1.57 macallan sc->sc_width,
484 1.57 macallan ri->ri_font->fontwidth,
485 1.57 macallan ri->ri_font->fontheight,
486 1.57 macallan defattr);
487 1.57 macallan
488 1.21 macallan if(isconsole) {
489 1.21 macallan wsdisplay_cnattach(&p9100_defscreendesc, ri, 0, 0, defattr);
490 1.47 macallan vcons_replay_msgbuf(&p9100_console_screen);
491 1.21 macallan }
492 1.21 macallan
493 1.21 macallan aa.console = isconsole;
494 1.21 macallan aa.scrdata = &p9100_screenlist;
495 1.21 macallan aa.accessops = &p9100_accessops;
496 1.27 macallan aa.accesscookie = &sc->vd;
497 1.1 pk
498 1.21 macallan config_found(self, &aa, wsemuldisplaydevprint);
499 1.21 macallan #endif
500 1.44 macallan fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
501 1.45 macallan printf("%s: rev %d / %x, %dx%d, depth %d mem %x\n",
502 1.45 macallan device_xname(self),
503 1.45 macallan (i & 7), ver, fb->fb_type.fb_width, fb->fb_type.fb_height,
504 1.45 macallan fb->fb_type.fb_depth, (unsigned int)sc->sc_fb_psize);
505 1.28 macallan /* cursor sprite handling */
506 1.28 macallan p9100_init_cursor(sc);
507 1.28 macallan
508 1.21 macallan /* attach the fb */
509 1.1 pk fb_attach(fb, isconsole);
510 1.28 macallan
511 1.27 macallan #if NTCTRL > 0
512 1.27 macallan /* register callback for external monitor status change */
513 1.27 macallan tadpole_register_callback(p9100_set_extvga, sc);
514 1.21 macallan #endif
515 1.1 pk }
516 1.1 pk
517 1.1 pk int
518 1.25 christos p9100open(dev_t dev, int flags, int mode, struct lwp *l)
519 1.1 pk {
520 1.1 pk int unit = minor(dev);
521 1.1 pk
522 1.39 drochner if (device_lookup(&pnozz_cd, unit) == NULL)
523 1.1 pk return (ENXIO);
524 1.1 pk return (0);
525 1.1 pk }
526 1.1 pk
527 1.1 pk int
528 1.57 macallan p9100close(dev_t dev, int flags, int mode, struct lwp *l)
529 1.57 macallan {
530 1.57 macallan struct p9100_softc *sc = device_lookup_private(&pnozz_cd, minor(dev));
531 1.57 macallan
532 1.57 macallan #if NWSDISPLAY > 0
533 1.57 macallan p9100_init_engine(sc);
534 1.57 macallan p9100_set_depth(sc, 8);
535 1.57 macallan p9100loadcmap(sc, 0, 256);
536 1.57 macallan p9100_clearscreen(sc);
537 1.57 macallan glyphcache_wipe(&sc->sc_gc);
538 1.57 macallan vcons_redraw_screen(sc->vd.active);
539 1.57 macallan #endif
540 1.57 macallan return 0;
541 1.57 macallan }
542 1.57 macallan
543 1.57 macallan int
544 1.35 christos p9100ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
545 1.1 pk {
546 1.39 drochner struct p9100_softc *sc = device_lookup_private(&pnozz_cd, minor(dev));
547 1.1 pk struct fbgattr *fba;
548 1.24 macallan int error, v;
549 1.1 pk
550 1.1 pk switch (cmd) {
551 1.1 pk
552 1.1 pk case FBIOGTYPE:
553 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
554 1.1 pk break;
555 1.1 pk
556 1.1 pk case FBIOGATTR:
557 1.1 pk fba = (struct fbgattr *)data;
558 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
559 1.1 pk fba->owner = 0; /* XXX ??? */
560 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
561 1.1 pk fba->sattr.flags = 0;
562 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
563 1.1 pk fba->sattr.dev_specific[0] = -1;
564 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
565 1.1 pk fba->emu_types[1] = -1;
566 1.1 pk break;
567 1.1 pk
568 1.1 pk case FBIOGETCMAP:
569 1.1 pk #define p ((struct fbcmap *)data)
570 1.1 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
571 1.1 pk
572 1.1 pk case FBIOPUTCMAP:
573 1.1 pk /* copy to software map */
574 1.1 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
575 1.1 pk if (error)
576 1.1 pk return (error);
577 1.1 pk /* now blast them into the chip */
578 1.1 pk /* XXX should use retrace interrupt */
579 1.1 pk p9100loadcmap(sc, p->index, p->count);
580 1.1 pk #undef p
581 1.1 pk break;
582 1.1 pk
583 1.1 pk case FBIOGVIDEO:
584 1.1 pk *(int *)data = p9100_get_video(sc);
585 1.1 pk break;
586 1.1 pk
587 1.1 pk case FBIOSVIDEO:
588 1.1 pk p9100_set_video(sc, *(int *)data);
589 1.1 pk break;
590 1.1 pk
591 1.24 macallan /* these are for both FBIOSCURSOR and FBIOGCURSOR */
592 1.24 macallan #define p ((struct fbcursor *)data)
593 1.24 macallan #define pc (&sc->sc_cursor)
594 1.24 macallan
595 1.24 macallan case FBIOGCURSOR:
596 1.24 macallan p->set = FB_CUR_SETALL; /* close enough, anyway */
597 1.24 macallan p->enable = pc->pc_enable;
598 1.24 macallan p->pos = pc->pc_pos;
599 1.24 macallan p->hot = pc->pc_hot;
600 1.24 macallan p->size = pc->pc_size;
601 1.24 macallan
602 1.24 macallan if (p->image != NULL) {
603 1.24 macallan error = copyout(pc->pc_bits, p->image, 0x200);
604 1.24 macallan if (error)
605 1.24 macallan return error;
606 1.24 macallan error = copyout(&pc->pc_bits[0x80], p->mask, 0x200);
607 1.24 macallan if (error)
608 1.24 macallan return error;
609 1.24 macallan }
610 1.33 blymn
611 1.24 macallan p->cmap.index = 0;
612 1.24 macallan p->cmap.count = 3;
613 1.24 macallan if (p->cmap.red != NULL) {
614 1.24 macallan copyout(pc->red, p->cmap.red, 3);
615 1.24 macallan copyout(pc->green, p->cmap.green, 3);
616 1.24 macallan copyout(pc->blue, p->cmap.blue, 3);
617 1.24 macallan }
618 1.24 macallan break;
619 1.24 macallan
620 1.24 macallan case FBIOSCURSOR:
621 1.24 macallan {
622 1.24 macallan int count;
623 1.24 macallan uint32_t image[0x80], mask[0x80];
624 1.24 macallan uint8_t red[3], green[3], blue[3];
625 1.33 blymn
626 1.24 macallan v = p->set;
627 1.24 macallan if (v & FB_CUR_SETCMAP) {
628 1.24 macallan error = copyin(p->cmap.red, red, 3);
629 1.24 macallan error |= copyin(p->cmap.green, green, 3);
630 1.24 macallan error |= copyin(p->cmap.blue, blue, 3);
631 1.24 macallan if (error)
632 1.24 macallan return error;
633 1.24 macallan }
634 1.24 macallan if (v & FB_CUR_SETSHAPE) {
635 1.24 macallan if (p->size.x > 64 || p->size.y > 64)
636 1.24 macallan return EINVAL;
637 1.24 macallan memset(&mask, 0, 0x200);
638 1.24 macallan memset(&image, 0, 0x200);
639 1.24 macallan count = p->size.y * 8;
640 1.24 macallan error = copyin(p->image, image, count);
641 1.24 macallan if (error)
642 1.24 macallan return error;
643 1.24 macallan error = copyin(p->mask, mask, count);
644 1.24 macallan if (error)
645 1.24 macallan return error;
646 1.24 macallan }
647 1.24 macallan
648 1.24 macallan /* parameters are OK; do it */
649 1.24 macallan if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
650 1.24 macallan if (v & FB_CUR_SETCUR)
651 1.24 macallan pc->pc_enable = p->enable;
652 1.24 macallan if (v & FB_CUR_SETPOS)
653 1.24 macallan pc->pc_pos = p->pos;
654 1.24 macallan if (v & FB_CUR_SETHOT)
655 1.24 macallan pc->pc_hot = p->hot;
656 1.24 macallan p9100_set_fbcursor(sc);
657 1.24 macallan }
658 1.33 blymn
659 1.24 macallan if (v & FB_CUR_SETCMAP) {
660 1.24 macallan memcpy(pc->red, red, 3);
661 1.24 macallan memcpy(pc->green, green, 3);
662 1.24 macallan memcpy(pc->blue, blue, 3);
663 1.24 macallan p9100_setcursorcmap(sc);
664 1.24 macallan }
665 1.33 blymn
666 1.24 macallan if (v & FB_CUR_SETSHAPE) {
667 1.24 macallan memcpy(pc->pc_bits, image, 0x200);
668 1.24 macallan memcpy(&pc->pc_bits[0x80], mask, 0x200);
669 1.24 macallan p9100_loadcursor(sc);
670 1.24 macallan }
671 1.24 macallan }
672 1.24 macallan break;
673 1.24 macallan
674 1.24 macallan #undef p
675 1.24 macallan #undef cc
676 1.24 macallan
677 1.24 macallan case FBIOGCURPOS:
678 1.24 macallan *(struct fbcurpos *)data = sc->sc_cursor.pc_pos;
679 1.24 macallan break;
680 1.24 macallan
681 1.24 macallan case FBIOSCURPOS:
682 1.24 macallan sc->sc_cursor.pc_pos = *(struct fbcurpos *)data;
683 1.24 macallan p9100_set_fbcursor(sc);
684 1.24 macallan break;
685 1.24 macallan
686 1.24 macallan case FBIOGCURMAX:
687 1.24 macallan /* max cursor size is 64x64 */
688 1.24 macallan ((struct fbcurpos *)data)->x = 64;
689 1.24 macallan ((struct fbcurpos *)data)->y = 64;
690 1.24 macallan break;
691 1.24 macallan
692 1.1 pk default:
693 1.1 pk return (ENOTTY);
694 1.1 pk }
695 1.1 pk return (0);
696 1.1 pk }
697 1.1 pk
698 1.1 pk static uint32_t
699 1.1 pk p9100_ctl_read_4(struct p9100_softc *sc, bus_size_t off)
700 1.1 pk {
701 1.27 macallan
702 1.27 macallan PNOZZ_LATCH(sc, off);
703 1.1 pk return bus_space_read_4(sc->sc_bustag, sc->sc_ctl_memh, off);
704 1.1 pk }
705 1.1 pk
706 1.1 pk static void
707 1.1 pk p9100_ctl_write_4(struct p9100_softc *sc, bus_size_t off, uint32_t v)
708 1.1 pk {
709 1.27 macallan
710 1.27 macallan PNOZZ_LATCH(sc, off);
711 1.1 pk bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off, v);
712 1.1 pk }
713 1.1 pk
714 1.28 macallan /* initialize the drawing engine */
715 1.28 macallan static void
716 1.28 macallan p9100_init_engine(struct p9100_softc *sc)
717 1.28 macallan {
718 1.28 macallan /* reset clipping rectangles */
719 1.33 blymn uint32_t rmax = ((sc->sc_width & 0x3fff) << 16) |
720 1.28 macallan (sc->sc_height & 0x3fff);
721 1.28 macallan
722 1.28 macallan sc->sc_last_offset = 0xffffffff;
723 1.28 macallan
724 1.28 macallan p9100_ctl_write_4(sc, WINDOW_OFFSET, 0);
725 1.28 macallan p9100_ctl_write_4(sc, WINDOW_MIN, 0);
726 1.28 macallan p9100_ctl_write_4(sc, WINDOW_MAX, rmax);
727 1.28 macallan p9100_ctl_write_4(sc, BYTE_CLIP_MIN, 0);
728 1.57 macallan p9100_ctl_write_4(sc, BYTE_CLIP_MAX, 0x3fff3fff);
729 1.28 macallan p9100_ctl_write_4(sc, DRAW_MODE, 0);
730 1.33 blymn p9100_ctl_write_4(sc, PLANE_MASK, 0xffffffff);
731 1.33 blymn p9100_ctl_write_4(sc, PATTERN0, 0xffffffff);
732 1.33 blymn p9100_ctl_write_4(sc, PATTERN1, 0xffffffff);
733 1.33 blymn p9100_ctl_write_4(sc, PATTERN2, 0xffffffff);
734 1.33 blymn p9100_ctl_write_4(sc, PATTERN3, 0xffffffff);
735 1.44 macallan
736 1.28 macallan }
737 1.28 macallan
738 1.28 macallan /* we only need these in the wsdisplay case */
739 1.28 macallan #if NWSDISPLAY > 0
740 1.28 macallan
741 1.21 macallan /* wait until the engine is idle */
742 1.21 macallan static void
743 1.21 macallan p9100_sync(struct p9100_softc *sc)
744 1.21 macallan {
745 1.33 blymn while((p9100_ctl_read_4(sc, ENGINE_STATUS) &
746 1.21 macallan (ENGINE_BUSY | BLITTER_BUSY)) != 0);
747 1.21 macallan }
748 1.21 macallan
749 1.33 blymn static void
750 1.21 macallan p9100_set_color_reg(struct p9100_softc *sc, int reg, int32_t col)
751 1.21 macallan {
752 1.21 macallan uint32_t out;
753 1.33 blymn
754 1.21 macallan switch(sc->sc_depth)
755 1.21 macallan {
756 1.21 macallan case 1: /* 8 bit */
757 1.21 macallan out = (col << 8) | col;
758 1.33 blymn out |= out << 16;
759 1.21 macallan break;
760 1.21 macallan case 2: /* 16 bit */
761 1.33 blymn out = col | (col << 16);
762 1.21 macallan break;
763 1.21 macallan default:
764 1.21 macallan out = col;
765 1.21 macallan }
766 1.21 macallan p9100_ctl_write_4(sc, reg, out);
767 1.21 macallan }
768 1.21 macallan
769 1.21 macallan /* screen-to-screen blit */
770 1.33 blymn static void
771 1.27 macallan p9100_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
772 1.57 macallan int he, int rop)
773 1.21 macallan {
774 1.27 macallan struct p9100_softc *sc = cookie;
775 1.27 macallan uint32_t src, dst, srcw, dstw;
776 1.27 macallan
777 1.27 macallan sc->sc_last_offset = 0xffffffff;
778 1.27 macallan
779 1.21 macallan src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
780 1.21 macallan dst = ((xd & 0x3fff) << 16) | (yd & 0x3fff);
781 1.21 macallan srcw = (((xs + wi - 1) & 0x3fff) << 16) | ((ys + he - 1) & 0x3fff);
782 1.21 macallan dstw = (((xd + wi - 1) & 0x3fff) << 16) | ((yd + he - 1) & 0x3fff);
783 1.44 macallan
784 1.21 macallan p9100_sync(sc);
785 1.44 macallan
786 1.21 macallan p9100_ctl_write_4(sc, RASTER_OP, rop);
787 1.57 macallan p9100_ctl_write_4(sc, BYTE_CLIP_MAX, 0x3fff3fff);
788 1.33 blymn
789 1.44 macallan p9100_ctl_write_4(sc, ABS_XY0, src << sc->sc_depthshift);
790 1.44 macallan p9100_ctl_write_4(sc, ABS_XY1, srcw << sc->sc_depthshift);
791 1.44 macallan p9100_ctl_write_4(sc, ABS_XY2, dst << sc->sc_depthshift);
792 1.44 macallan p9100_ctl_write_4(sc, ABS_XY3, dstw << sc->sc_depthshift);
793 1.33 blymn
794 1.27 macallan sc->sc_junk = p9100_ctl_read_4(sc, COMMAND_BLIT);
795 1.21 macallan }
796 1.21 macallan
797 1.21 macallan /* solid rectangle fill */
798 1.33 blymn static void
799 1.27 macallan p9100_rectfill(void *cookie, int xs, int ys, int wi, int he, uint32_t col)
800 1.21 macallan {
801 1.27 macallan struct p9100_softc *sc = cookie;
802 1.27 macallan uint32_t src, srcw;
803 1.27 macallan
804 1.27 macallan sc->sc_last_offset = 0xffffffff;
805 1.27 macallan
806 1.21 macallan src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
807 1.21 macallan srcw = (((xs + wi) & 0x3fff) << 16) | ((ys + he) & 0x3fff);
808 1.21 macallan p9100_sync(sc);
809 1.57 macallan p9100_ctl_write_4(sc, BYTE_CLIP_MAX, 0x3fff3fff);
810 1.21 macallan p9100_set_color_reg(sc, FOREGROUND_COLOR, col);
811 1.21 macallan p9100_set_color_reg(sc, BACKGROUND_COLOR, col);
812 1.21 macallan p9100_ctl_write_4(sc, RASTER_OP, ROP_PAT);
813 1.21 macallan p9100_ctl_write_4(sc, COORD_INDEX, 0);
814 1.21 macallan p9100_ctl_write_4(sc, RECT_RTW_XY, src);
815 1.21 macallan p9100_ctl_write_4(sc, RECT_RTW_XY, srcw);
816 1.27 macallan sc->sc_junk = p9100_ctl_read_4(sc, COMMAND_QUAD);
817 1.21 macallan }
818 1.21 macallan
819 1.21 macallan /* setup for mono->colour expansion */
820 1.33 blymn static void
821 1.33 blymn p9100_setup_mono(struct p9100_softc *sc, int x, int y, int wi, int he,
822 1.33 blymn uint32_t fg, uint32_t bg)
823 1.21 macallan {
824 1.27 macallan
825 1.27 macallan sc->sc_last_offset = 0xffffffff;
826 1.27 macallan
827 1.21 macallan p9100_sync(sc);
828 1.33 blymn /*
829 1.21 macallan * this doesn't make any sense to me either, but for some reason the
830 1.33 blymn * chip applies the foreground colour to 0 pixels
831 1.21 macallan */
832 1.33 blymn
833 1.21 macallan p9100_set_color_reg(sc,FOREGROUND_COLOR,bg);
834 1.21 macallan p9100_set_color_reg(sc,BACKGROUND_COLOR,fg);
835 1.21 macallan
836 1.57 macallan p9100_ctl_write_4(sc, BYTE_CLIP_MAX, 0x3fff3fff);
837 1.21 macallan p9100_ctl_write_4(sc, RASTER_OP, ROP_SRC);
838 1.21 macallan p9100_ctl_write_4(sc, ABS_X0, x);
839 1.21 macallan p9100_ctl_write_4(sc, ABS_XY1, (x << 16) | (y & 0xFFFFL));
840 1.21 macallan p9100_ctl_write_4(sc, ABS_X2, (x + wi));
841 1.21 macallan p9100_ctl_write_4(sc, ABS_Y3, he);
842 1.21 macallan /* now feed the data into the chip */
843 1.21 macallan sc->sc_mono_width = wi;
844 1.21 macallan }
845 1.21 macallan
846 1.21 macallan /* write monochrome data to the screen through the blitter */
847 1.33 blymn static void
848 1.21 macallan p9100_feed_line(struct p9100_softc *sc, int count, uint8_t *data)
849 1.21 macallan {
850 1.21 macallan int i;
851 1.21 macallan uint32_t latch = 0, bork;
852 1.21 macallan int shift = 24;
853 1.21 macallan int to_go = sc->sc_mono_width;
854 1.27 macallan
855 1.27 macallan PNOZZ_LATCH(sc, PIXEL_1);
856 1.27 macallan
857 1.21 macallan for (i = 0; i < count; i++) {
858 1.21 macallan bork = data[i];
859 1.21 macallan latch |= (bork << shift);
860 1.21 macallan if (shift == 0) {
861 1.21 macallan /* check how many bits are significant */
862 1.21 macallan if (to_go > 31) {
863 1.44 macallan bus_space_write_4(sc->sc_bustag,
864 1.44 macallan sc->sc_ctl_memh,
865 1.27 macallan (PIXEL_1 + (31 << 2)), latch);
866 1.21 macallan to_go -= 32;
867 1.21 macallan } else
868 1.21 macallan {
869 1.44 macallan bus_space_write_4(sc->sc_bustag,
870 1.44 macallan sc->sc_ctl_memh,
871 1.27 macallan (PIXEL_1 + ((to_go - 1) << 2)), latch);
872 1.21 macallan to_go = 0;
873 1.21 macallan }
874 1.21 macallan latch = 0;
875 1.21 macallan shift = 24;
876 1.21 macallan } else
877 1.21 macallan shift -= 8;
878 1.21 macallan }
879 1.21 macallan if (shift != 24)
880 1.21 macallan p9100_ctl_write_4(sc, (PIXEL_1 + ((to_go - 1) << 2)), latch);
881 1.33 blymn }
882 1.21 macallan
883 1.27 macallan static void
884 1.21 macallan p9100_clearscreen(struct p9100_softc *sc)
885 1.21 macallan {
886 1.33 blymn
887 1.21 macallan p9100_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
888 1.21 macallan }
889 1.28 macallan #endif /* NWSDISPLAY > 0 */
890 1.21 macallan
891 1.27 macallan static uint8_t
892 1.1 pk p9100_ramdac_read(struct p9100_softc *sc, bus_size_t off)
893 1.1 pk {
894 1.27 macallan
895 1.1 pk sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
896 1.33 blymn return ((bus_space_read_4(sc->sc_bustag,
897 1.21 macallan sc->sc_ctl_memh, off) >> 16) & 0xff);
898 1.1 pk }
899 1.1 pk
900 1.27 macallan static void
901 1.1 pk p9100_ramdac_write(struct p9100_softc *sc, bus_size_t off, uint8_t v)
902 1.1 pk {
903 1.27 macallan
904 1.1 pk sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
905 1.33 blymn bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off,
906 1.21 macallan ((uint32_t)v) << 16);
907 1.1 pk }
908 1.1 pk
909 1.27 macallan static uint8_t
910 1.27 macallan p9100_ramdac_read_ctl(struct p9100_softc *sc, int off)
911 1.27 macallan {
912 1.27 macallan p9100_ramdac_write(sc, DAC_INDX_LO, off & 0xff);
913 1.27 macallan p9100_ramdac_write(sc, DAC_INDX_HI, (off & 0xff00) >> 8);
914 1.27 macallan return p9100_ramdac_read(sc, DAC_INDX_DATA);
915 1.27 macallan }
916 1.27 macallan
917 1.27 macallan static void
918 1.27 macallan p9100_ramdac_write_ctl(struct p9100_softc *sc, int off, uint8_t val)
919 1.27 macallan {
920 1.27 macallan p9100_ramdac_write(sc, DAC_INDX_LO, off & 0xff);
921 1.27 macallan p9100_ramdac_write(sc, DAC_INDX_HI, (off & 0xff00) >> 8);
922 1.27 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, val);
923 1.27 macallan }
924 1.27 macallan
925 1.1 pk /*
926 1.1 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
927 1.1 pk */
928 1.1 pk static void
929 1.43 cegger p9100unblank(device_t dev)
930 1.1 pk {
931 1.39 drochner struct p9100_softc *sc = device_private(dev);
932 1.33 blymn
933 1.45 macallan p9100_set_video(sc, 1);
934 1.33 blymn
935 1.33 blymn /*
936 1.27 macallan * Check if we're in terminal mode. If not force the console screen
937 1.27 macallan * to front so we can see ddb, panic messages and so on
938 1.27 macallan */
939 1.27 macallan if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) {
940 1.27 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
941 1.27 macallan if (sc->vd.active != &p9100_console_screen) {
942 1.27 macallan SCREEN_INVISIBLE(sc->vd.active);
943 1.27 macallan sc->vd.active = &p9100_console_screen;
944 1.27 macallan SCREEN_VISIBLE(&p9100_console_screen);
945 1.27 macallan }
946 1.44 macallan p9100_init_engine(sc);
947 1.44 macallan p9100_set_depth(sc, 8);
948 1.27 macallan vcons_redraw_screen(&p9100_console_screen);
949 1.27 macallan }
950 1.1 pk }
951 1.1 pk
952 1.1 pk static void
953 1.1 pk p9100_set_video(struct p9100_softc *sc, int enable)
954 1.1 pk {
955 1.50 tsutsui uint32_t v = p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1);
956 1.33 blymn
957 1.1 pk if (enable)
958 1.1 pk v |= VIDEO_ENABLED;
959 1.1 pk else
960 1.1 pk v &= ~VIDEO_ENABLED;
961 1.1 pk p9100_ctl_write_4(sc, SCRN_RPNT_CTL_1, v);
962 1.1 pk #if NTCTRL > 0
963 1.1 pk /* Turn On/Off the TFT if we know how.
964 1.1 pk */
965 1.1 pk tadpole_set_video(enable);
966 1.1 pk #endif
967 1.1 pk }
968 1.1 pk
969 1.1 pk static int
970 1.1 pk p9100_get_video(struct p9100_softc *sc)
971 1.1 pk {
972 1.1 pk return (p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1) & VIDEO_ENABLED) != 0;
973 1.1 pk }
974 1.1 pk
975 1.45 macallan static bool
976 1.52 dyoung p9100_suspend(device_t dev, const pmf_qual_t *qual)
977 1.45 macallan {
978 1.45 macallan struct p9100_softc *sc = device_private(dev);
979 1.45 macallan
980 1.45 macallan if (sc->sc_powerstate == PWR_SUSPEND)
981 1.45 macallan return TRUE;
982 1.45 macallan
983 1.45 macallan sc->sc_video = p9100_get_video(sc);
984 1.45 macallan sc->sc_dac_power = p9100_ramdac_read_ctl(sc, DAC_POWER_MGT);
985 1.45 macallan p9100_ramdac_write_ctl(sc, DAC_POWER_MGT,
986 1.45 macallan DAC_POWER_SCLK_DISABLE |
987 1.45 macallan DAC_POWER_DDOT_DISABLE |
988 1.45 macallan DAC_POWER_SYNC_DISABLE |
989 1.45 macallan DAC_POWER_ICLK_DISABLE |
990 1.45 macallan DAC_POWER_IPWR_DISABLE);
991 1.45 macallan p9100_set_video(sc, 0);
992 1.45 macallan sc->sc_powerstate = PWR_SUSPEND;
993 1.45 macallan return TRUE;
994 1.45 macallan }
995 1.45 macallan
996 1.45 macallan static bool
997 1.52 dyoung p9100_resume(device_t dev, const pmf_qual_t *qual)
998 1.27 macallan {
999 1.45 macallan struct p9100_softc *sc = device_private(dev);
1000 1.45 macallan
1001 1.45 macallan if (sc->sc_powerstate == PWR_RESUME)
1002 1.45 macallan return TRUE;
1003 1.33 blymn
1004 1.45 macallan p9100_ramdac_write_ctl(sc, DAC_POWER_MGT, sc->sc_dac_power);
1005 1.45 macallan p9100_set_video(sc, sc->sc_video);
1006 1.33 blymn
1007 1.45 macallan sc->sc_powerstate = PWR_RESUME;
1008 1.45 macallan return TRUE;
1009 1.27 macallan }
1010 1.27 macallan
1011 1.1 pk /*
1012 1.1 pk * Load a subset of the current (new) colormap into the IBM RAMDAC.
1013 1.1 pk */
1014 1.1 pk static void
1015 1.1 pk p9100loadcmap(struct p9100_softc *sc, int start, int ncolors)
1016 1.1 pk {
1017 1.21 macallan int i;
1018 1.27 macallan sc->sc_last_offset = 0xffffffff;
1019 1.27 macallan
1020 1.1 pk p9100_ramdac_write(sc, DAC_CMAP_WRIDX, start);
1021 1.1 pk
1022 1.21 macallan for (i=0;i<ncolors;i++) {
1023 1.33 blymn p9100_ramdac_write(sc, DAC_CMAP_DATA,
1024 1.21 macallan sc->sc_cmap.cm_map[i + start][0]);
1025 1.33 blymn p9100_ramdac_write(sc, DAC_CMAP_DATA,
1026 1.21 macallan sc->sc_cmap.cm_map[i + start][1]);
1027 1.33 blymn p9100_ramdac_write(sc, DAC_CMAP_DATA,
1028 1.21 macallan sc->sc_cmap.cm_map[i + start][2]);
1029 1.1 pk }
1030 1.1 pk }
1031 1.1 pk
1032 1.1 pk /*
1033 1.1 pk * Return the address that would map the given device at the given
1034 1.1 pk * offset, allowing for the given protection, or return -1 for error.
1035 1.1 pk */
1036 1.27 macallan static paddr_t
1037 1.1 pk p9100mmap(dev_t dev, off_t off, int prot)
1038 1.1 pk {
1039 1.39 drochner struct p9100_softc *sc = device_lookup_private(&pnozz_cd, minor(dev));
1040 1.1 pk
1041 1.1 pk if (off & PGOFSET)
1042 1.1 pk panic("p9100mmap");
1043 1.1 pk if (off < 0)
1044 1.1 pk return (-1);
1045 1.1 pk
1046 1.21 macallan #ifdef PNOZZ_EMUL_CG3
1047 1.1 pk #define CG3_MMAP_OFFSET 0x04000000
1048 1.1 pk /* Make Xsun think we are a CG3 (SUN3COLOR)
1049 1.1 pk */
1050 1.1 pk if (off >= CG3_MMAP_OFFSET && off < CG3_MMAP_OFFSET + sc->sc_fb_psize) {
1051 1.1 pk off -= CG3_MMAP_OFFSET;
1052 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
1053 1.3 eeh sc->sc_fb_paddr,
1054 1.3 eeh off,
1055 1.3 eeh prot,
1056 1.3 eeh BUS_SPACE_MAP_LINEAR));
1057 1.1 pk }
1058 1.21 macallan #endif
1059 1.1 pk
1060 1.44 macallan if (off >= sc->sc_fb_psize + sc->sc_ctl_psize/* + sc->sc_cmd_psize*/)
1061 1.1 pk return (-1);
1062 1.1 pk
1063 1.1 pk if (off < sc->sc_fb_psize) {
1064 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
1065 1.3 eeh sc->sc_fb_paddr,
1066 1.3 eeh off,
1067 1.3 eeh prot,
1068 1.3 eeh BUS_SPACE_MAP_LINEAR));
1069 1.1 pk }
1070 1.44 macallan
1071 1.1 pk off -= sc->sc_fb_psize;
1072 1.1 pk if (off < sc->sc_ctl_psize) {
1073 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
1074 1.3 eeh sc->sc_ctl_paddr,
1075 1.3 eeh off,
1076 1.3 eeh prot,
1077 1.3 eeh BUS_SPACE_MAP_LINEAR));
1078 1.1 pk }
1079 1.1 pk
1080 1.44 macallan return EINVAL;
1081 1.1 pk }
1082 1.21 macallan
1083 1.21 macallan /* wscons stuff */
1084 1.28 macallan #if NWSDISPLAY > 0
1085 1.21 macallan
1086 1.27 macallan static void
1087 1.21 macallan p9100_cursor(void *cookie, int on, int row, int col)
1088 1.21 macallan {
1089 1.21 macallan struct rasops_info *ri = cookie;
1090 1.27 macallan struct vcons_screen *scr = ri->ri_hw;
1091 1.27 macallan struct p9100_softc *sc = scr->scr_cookie;
1092 1.21 macallan int x, y, wi,he;
1093 1.33 blymn
1094 1.21 macallan wi = ri->ri_font->fontwidth;
1095 1.21 macallan he = ri->ri_font->fontheight;
1096 1.33 blymn
1097 1.27 macallan if (ri->ri_flg & RI_CURSOR) {
1098 1.27 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
1099 1.27 macallan y = ri->ri_crow * he + ri->ri_yorigin;
1100 1.27 macallan p9100_bitblt(sc, x, y, x, y, wi, he, ROP_SRC ^ 0xff);
1101 1.27 macallan ri->ri_flg &= ~RI_CURSOR;
1102 1.27 macallan }
1103 1.44 macallan
1104 1.27 macallan ri->ri_crow = row;
1105 1.27 macallan ri->ri_ccol = col;
1106 1.44 macallan
1107 1.27 macallan if (on)
1108 1.27 macallan {
1109 1.27 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
1110 1.27 macallan y = ri->ri_crow * he + ri->ri_yorigin;
1111 1.27 macallan p9100_bitblt(sc, x, y, x, y, wi, he, ROP_SRC ^ 0xff);
1112 1.27 macallan ri->ri_flg |= RI_CURSOR;
1113 1.21 macallan }
1114 1.21 macallan }
1115 1.21 macallan
1116 1.21 macallan #if 0
1117 1.27 macallan static int
1118 1.21 macallan p9100_mapchar(void *cookie, int uni, u_int *index)
1119 1.21 macallan {
1120 1.21 macallan return 0;
1121 1.21 macallan }
1122 1.21 macallan #endif
1123 1.21 macallan
1124 1.27 macallan static void
1125 1.21 macallan p9100_putchar(void *cookie, int row, int col, u_int c, long attr)
1126 1.21 macallan {
1127 1.21 macallan struct rasops_info *ri = cookie;
1128 1.55 macallan struct wsdisplay_font *font = PICK_FONT(ri, c);
1129 1.27 macallan struct vcons_screen *scr = ri->ri_hw;
1130 1.27 macallan struct p9100_softc *sc = scr->scr_cookie;
1131 1.33 blymn
1132 1.57 macallan int fg, bg, i;
1133 1.27 macallan uint8_t *data;
1134 1.47 macallan int x, y, wi, he;
1135 1.33 blymn
1136 1.55 macallan wi = font->fontwidth;
1137 1.55 macallan he = font->fontheight;
1138 1.33 blymn
1139 1.55 macallan if (!CHAR_IN_FONT(c, font))
1140 1.27 macallan return;
1141 1.44 macallan
1142 1.27 macallan bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
1143 1.27 macallan fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xff];
1144 1.27 macallan x = ri->ri_xorigin + col * wi;
1145 1.27 macallan y = ri->ri_yorigin + row * he;
1146 1.44 macallan
1147 1.27 macallan if (c == 0x20) {
1148 1.27 macallan p9100_rectfill(sc, x, y, wi, he, bg);
1149 1.27 macallan } else {
1150 1.57 macallan data = WSFONT_GLYPH(c, font);
1151 1.27 macallan
1152 1.33 blymn p9100_setup_mono(sc, x, y, wi, 1, fg, bg);
1153 1.27 macallan for (i = 0; i < he; i++) {
1154 1.55 macallan p9100_feed_line(sc, font->stride,
1155 1.27 macallan data);
1156 1.55 macallan data += font->stride;
1157 1.21 macallan }
1158 1.21 macallan }
1159 1.21 macallan }
1160 1.21 macallan
1161 1.57 macallan static void
1162 1.57 macallan p9100_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
1163 1.57 macallan {
1164 1.57 macallan struct rasops_info *ri = cookie;
1165 1.57 macallan struct wsdisplay_font *font = PICK_FONT(ri, c);
1166 1.57 macallan struct vcons_screen *scr = ri->ri_hw;
1167 1.57 macallan struct p9100_softc *sc = scr->scr_cookie;
1168 1.57 macallan uint32_t bg, latch = 0, bg8, fg8, pixel;
1169 1.57 macallan int i, j, x, y, wi, he, r, g, b, aval, rwi;
1170 1.57 macallan int r1, g1, b1, r0, g0, b0, fgo, bgo;
1171 1.57 macallan uint8_t *data8;
1172 1.57 macallan int rv;
1173 1.57 macallan
1174 1.57 macallan if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
1175 1.57 macallan return;
1176 1.57 macallan
1177 1.57 macallan if (!CHAR_IN_FONT(c, font))
1178 1.57 macallan return;
1179 1.57 macallan
1180 1.57 macallan wi = font->fontwidth;
1181 1.57 macallan rwi = (wi + 3) & ~3;
1182 1.57 macallan he = font->fontheight;
1183 1.57 macallan
1184 1.57 macallan bg = ri->ri_devcmap[(attr >> 16) & 0xf];
1185 1.57 macallan x = ri->ri_xorigin + col * wi;
1186 1.57 macallan y = ri->ri_yorigin + row * he;
1187 1.57 macallan
1188 1.57 macallan if (c == 0x20) {
1189 1.57 macallan p9100_rectfill(sc, x, y, wi, he, bg);
1190 1.57 macallan return;
1191 1.57 macallan }
1192 1.57 macallan
1193 1.57 macallan rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
1194 1.57 macallan if (rv == GC_OK)
1195 1.57 macallan return;
1196 1.57 macallan
1197 1.57 macallan data8 = WSFONT_GLYPH(c, font);
1198 1.57 macallan
1199 1.57 macallan p9100_sync(sc);
1200 1.57 macallan
1201 1.57 macallan p9100_ctl_write_4(sc, RASTER_OP, ROP_SRC);
1202 1.57 macallan p9100_ctl_write_4(sc, ABS_X0, x);
1203 1.57 macallan p9100_ctl_write_4(sc, ABS_XY1, (x << 16) | (y & 0xFFFFL));
1204 1.57 macallan p9100_ctl_write_4(sc, ABS_X2, (x + rwi));
1205 1.57 macallan p9100_ctl_write_4(sc, ABS_Y3, 1);
1206 1.57 macallan p9100_ctl_write_4(sc, BYTE_CLIP_MAX, ((x + wi - 1) << 16) | 0x3fff);
1207 1.57 macallan
1208 1.57 macallan /*
1209 1.57 macallan * we need the RGB colours here, so get offsets into rasops_cmap
1210 1.57 macallan */
1211 1.57 macallan fgo = ((attr >> 24) & 0xf) * 3;
1212 1.57 macallan bgo = ((attr >> 16) & 0xf) * 3;
1213 1.57 macallan
1214 1.57 macallan r0 = rasops_cmap[bgo];
1215 1.57 macallan r1 = rasops_cmap[fgo];
1216 1.57 macallan g0 = rasops_cmap[bgo + 1];
1217 1.57 macallan g1 = rasops_cmap[fgo + 1];
1218 1.57 macallan b0 = rasops_cmap[bgo + 2];
1219 1.57 macallan b1 = rasops_cmap[fgo + 2];
1220 1.57 macallan #define R3G3B2(r, g, b) ((r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6))
1221 1.57 macallan bg8 = R3G3B2(r0, g0, b0);
1222 1.57 macallan fg8 = R3G3B2(r1, g1, b1);
1223 1.57 macallan
1224 1.57 macallan //r128fb_wait(sc, 16);
1225 1.57 macallan
1226 1.57 macallan for (i = 0; i < he; i++) {
1227 1.57 macallan for (j = 0; j < wi; j++) {
1228 1.57 macallan aval = *data8;
1229 1.57 macallan if (aval == 0) {
1230 1.57 macallan pixel = bg8;
1231 1.57 macallan } else if (aval == 255) {
1232 1.57 macallan pixel = fg8;
1233 1.57 macallan } else {
1234 1.57 macallan r = aval * r1 + (255 - aval) * r0;
1235 1.57 macallan g = aval * g1 + (255 - aval) * g0;
1236 1.57 macallan b = aval * b1 + (255 - aval) * b0;
1237 1.57 macallan pixel = ((r & 0xe000) >> 8) |
1238 1.57 macallan ((g & 0xe000) >> 11) |
1239 1.57 macallan ((b & 0xc000) >> 14);
1240 1.57 macallan }
1241 1.57 macallan latch = (latch << 8) | pixel;
1242 1.57 macallan /* write in 32bit chunks */
1243 1.57 macallan if ((j & 3) == 3) {
1244 1.57 macallan bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
1245 1.57 macallan COMMAND_PIXEL8, latch);
1246 1.57 macallan latch = 0;
1247 1.57 macallan }
1248 1.57 macallan data8++;
1249 1.57 macallan }
1250 1.57 macallan /* if we have pixels left in latch write them out */
1251 1.57 macallan if ((j & 3) != 0) {
1252 1.57 macallan latch = latch << ((4 - (j & 3)) << 3);
1253 1.57 macallan bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
1254 1.57 macallan COMMAND_PIXEL8, latch);
1255 1.57 macallan }
1256 1.57 macallan }
1257 1.57 macallan if (rv == GC_ADD) {
1258 1.57 macallan glyphcache_add(&sc->sc_gc, c, x, y);
1259 1.57 macallan }
1260 1.57 macallan }
1261 1.57 macallan
1262 1.21 macallan /*
1263 1.21 macallan * wsdisplay_accessops
1264 1.21 macallan */
1265 1.21 macallan
1266 1.21 macallan int
1267 1.35 christos p9100_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
1268 1.31 jmmv struct lwp *l)
1269 1.21 macallan {
1270 1.27 macallan struct vcons_data *vd = v;
1271 1.27 macallan struct p9100_softc *sc = vd->cookie;
1272 1.21 macallan struct wsdisplay_fbinfo *wdf;
1273 1.27 macallan struct vcons_screen *ms = vd->active;
1274 1.21 macallan
1275 1.21 macallan switch (cmd) {
1276 1.21 macallan case WSDISPLAYIO_GTYPE:
1277 1.21 macallan *(u_int *)data = WSDISPLAY_TYPE_SB_P9100;
1278 1.21 macallan return 0;
1279 1.33 blymn
1280 1.21 macallan case FBIOGVIDEO:
1281 1.21 macallan case WSDISPLAYIO_GVIDEO:
1282 1.21 macallan *(int *)data = p9100_get_video(sc);
1283 1.21 macallan return 0;
1284 1.33 blymn
1285 1.21 macallan case WSDISPLAYIO_SVIDEO:
1286 1.21 macallan case FBIOSVIDEO:
1287 1.21 macallan p9100_set_video(sc, *(int *)data);
1288 1.21 macallan return 0;
1289 1.21 macallan
1290 1.21 macallan case WSDISPLAYIO_GINFO:
1291 1.21 macallan wdf = (void *)data;
1292 1.27 macallan wdf->height = ms->scr_ri.ri_height;
1293 1.27 macallan wdf->width = ms->scr_ri.ri_width;
1294 1.27 macallan wdf->depth = ms->scr_ri.ri_depth;
1295 1.21 macallan wdf->cmsize = 256;
1296 1.21 macallan return 0;
1297 1.21 macallan
1298 1.21 macallan case WSDISPLAYIO_GETCMAP:
1299 1.21 macallan return p9100_getcmap(sc, (struct wsdisplay_cmap *)data);
1300 1.21 macallan
1301 1.21 macallan case WSDISPLAYIO_PUTCMAP:
1302 1.21 macallan return p9100_putcmap(sc, (struct wsdisplay_cmap *)data);
1303 1.21 macallan
1304 1.21 macallan case WSDISPLAYIO_SMODE:
1305 1.21 macallan {
1306 1.21 macallan int new_mode = *(int*)data;
1307 1.21 macallan if (new_mode != sc->sc_mode)
1308 1.21 macallan {
1309 1.21 macallan sc->sc_mode = new_mode;
1310 1.21 macallan if (new_mode == WSDISPLAYIO_MODE_EMUL)
1311 1.21 macallan {
1312 1.33 blymn p9100_init_engine(sc);
1313 1.44 macallan p9100_set_depth(sc, 8);
1314 1.27 macallan p9100loadcmap(sc, 0, 256);
1315 1.27 macallan p9100_clearscreen(sc);
1316 1.57 macallan glyphcache_wipe(&sc->sc_gc);
1317 1.27 macallan vcons_redraw_screen(ms);
1318 1.21 macallan }
1319 1.21 macallan }
1320 1.21 macallan }
1321 1.21 macallan }
1322 1.21 macallan return EPASSTHROUGH;
1323 1.21 macallan }
1324 1.21 macallan
1325 1.27 macallan static paddr_t
1326 1.31 jmmv p9100_mmap(void *v, void *vs, off_t offset, int prot)
1327 1.21 macallan {
1328 1.27 macallan struct vcons_data *vd = v;
1329 1.33 blymn struct p9100_softc *sc = vd->cookie;
1330 1.21 macallan paddr_t pa;
1331 1.33 blymn
1332 1.21 macallan /* 'regular' framebuffer mmap()ing */
1333 1.21 macallan if (offset < sc->sc_fb_psize) {
1334 1.33 blymn pa = bus_space_mmap(sc->sc_bustag, sc->sc_fb_paddr + offset, 0,
1335 1.33 blymn prot, BUS_SPACE_MAP_LINEAR);
1336 1.21 macallan return pa;
1337 1.21 macallan }
1338 1.21 macallan
1339 1.33 blymn if ((offset >= sc->sc_fb_paddr) && (offset < (sc->sc_fb_paddr +
1340 1.21 macallan sc->sc_fb_psize))) {
1341 1.33 blymn pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
1342 1.33 blymn BUS_SPACE_MAP_LINEAR);
1343 1.21 macallan return pa;
1344 1.21 macallan }
1345 1.21 macallan
1346 1.33 blymn if ((offset >= sc->sc_ctl_paddr) && (offset < (sc->sc_ctl_paddr +
1347 1.21 macallan sc->sc_ctl_psize))) {
1348 1.33 blymn pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
1349 1.33 blymn BUS_SPACE_MAP_LINEAR);
1350 1.21 macallan return pa;
1351 1.21 macallan }
1352 1.21 macallan
1353 1.21 macallan return -1;
1354 1.21 macallan }
1355 1.21 macallan
1356 1.27 macallan static void
1357 1.27 macallan p9100_init_screen(void *cookie, struct vcons_screen *scr,
1358 1.21 macallan int existing, long *defattr)
1359 1.21 macallan {
1360 1.27 macallan struct p9100_softc *sc = cookie;
1361 1.27 macallan struct rasops_info *ri = &scr->scr_ri;
1362 1.33 blymn
1363 1.21 macallan ri->ri_depth = sc->sc_depth << 3;
1364 1.21 macallan ri->ri_width = sc->sc_width;
1365 1.21 macallan ri->ri_height = sc->sc_height;
1366 1.21 macallan ri->ri_stride = sc->sc_stride;
1367 1.27 macallan ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
1368 1.57 macallan if (ri->ri_depth == 8)
1369 1.57 macallan ri->ri_flg |= RI_8BIT_IS_RGB | RI_ENABLE_ALPHA;
1370 1.21 macallan
1371 1.54 macallan #ifdef PNOZZ_USE_LATCH
1372 1.21 macallan ri->ri_bits = bus_space_vaddr(sc->sc_bustag, sc->sc_fb_memh);
1373 1.44 macallan DPRINTF("addr: %08lx\n",(ulong)ri->ri_bits);
1374 1.54 macallan #endif
1375 1.44 macallan
1376 1.56 macallan rasops_init(ri, 0, 0);
1377 1.21 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
1378 1.21 macallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
1379 1.21 macallan sc->sc_width / ri->ri_font->fontwidth);
1380 1.21 macallan
1381 1.21 macallan /* enable acceleration */
1382 1.27 macallan ri->ri_ops.cursor = p9100_cursor;
1383 1.27 macallan ri->ri_ops.copyrows = p9100_copyrows;
1384 1.21 macallan ri->ri_ops.eraserows = p9100_eraserows;
1385 1.27 macallan ri->ri_ops.copycols = p9100_copycols;
1386 1.21 macallan ri->ri_ops.erasecols = p9100_erasecols;
1387 1.57 macallan if (FONT_IS_ALPHA(ri->ri_font)) {
1388 1.57 macallan ri->ri_ops.putchar = p9100_putchar_aa;
1389 1.57 macallan } else
1390 1.57 macallan ri->ri_ops.putchar = p9100_putchar;
1391 1.21 macallan }
1392 1.21 macallan
1393 1.27 macallan static int
1394 1.21 macallan p9100_putcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
1395 1.21 macallan {
1396 1.21 macallan u_int index = cm->index;
1397 1.21 macallan u_int count = cm->count;
1398 1.21 macallan int i, error;
1399 1.21 macallan u_char rbuf[256], gbuf[256], bbuf[256];
1400 1.21 macallan u_char *r, *g, *b;
1401 1.21 macallan
1402 1.21 macallan if (cm->index >= 256 || cm->count > 256 ||
1403 1.21 macallan (cm->index + cm->count) > 256)
1404 1.21 macallan return EINVAL;
1405 1.21 macallan error = copyin(cm->red, &rbuf[index], count);
1406 1.21 macallan if (error)
1407 1.21 macallan return error;
1408 1.21 macallan error = copyin(cm->green, &gbuf[index], count);
1409 1.21 macallan if (error)
1410 1.21 macallan return error;
1411 1.21 macallan error = copyin(cm->blue, &bbuf[index], count);
1412 1.21 macallan if (error)
1413 1.21 macallan return error;
1414 1.21 macallan
1415 1.21 macallan r = &rbuf[index];
1416 1.21 macallan g = &gbuf[index];
1417 1.21 macallan b = &bbuf[index];
1418 1.21 macallan
1419 1.21 macallan for (i = 0; i < count; i++) {
1420 1.21 macallan sc->sc_cmap.cm_map[index][0] = *r;
1421 1.21 macallan sc->sc_cmap.cm_map[index][1] = *g;
1422 1.21 macallan sc->sc_cmap.cm_map[index][2] = *b;
1423 1.21 macallan index++;
1424 1.21 macallan r++, g++, b++;
1425 1.21 macallan }
1426 1.21 macallan p9100loadcmap(sc, 0, 256);
1427 1.21 macallan return 0;
1428 1.21 macallan }
1429 1.21 macallan
1430 1.27 macallan static int
1431 1.21 macallan p9100_getcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
1432 1.21 macallan {
1433 1.21 macallan u_int index = cm->index;
1434 1.21 macallan u_int count = cm->count;
1435 1.21 macallan int error, i;
1436 1.27 macallan uint8_t red[256], green[256], blue[256];
1437 1.21 macallan
1438 1.21 macallan if (index >= 255 || count > 256 || index + count > 256)
1439 1.21 macallan return EINVAL;
1440 1.21 macallan
1441 1.21 macallan i = index;
1442 1.21 macallan while (i < (index + count)) {
1443 1.21 macallan red[i] = sc->sc_cmap.cm_map[i][0];
1444 1.21 macallan green[i] = sc->sc_cmap.cm_map[i][1];
1445 1.21 macallan blue[i] = sc->sc_cmap.cm_map[i][2];
1446 1.21 macallan i++;
1447 1.21 macallan }
1448 1.21 macallan error = copyout(&red[index], cm->red, count);
1449 1.21 macallan if (error)
1450 1.21 macallan return error;
1451 1.21 macallan error = copyout(&green[index], cm->green, count);
1452 1.21 macallan if (error)
1453 1.21 macallan return error;
1454 1.21 macallan error = copyout(&blue[index], cm->blue, count);
1455 1.21 macallan if (error)
1456 1.21 macallan return error;
1457 1.21 macallan
1458 1.21 macallan return 0;
1459 1.21 macallan }
1460 1.21 macallan
1461 1.27 macallan static void
1462 1.27 macallan p9100_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1463 1.27 macallan {
1464 1.27 macallan struct rasops_info *ri = cookie;
1465 1.27 macallan struct vcons_screen *scr = ri->ri_hw;
1466 1.27 macallan int32_t xs, xd, y, width, height;
1467 1.33 blymn
1468 1.27 macallan xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1469 1.27 macallan xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1470 1.27 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1471 1.27 macallan width = ri->ri_font->fontwidth * ncols;
1472 1.27 macallan height = ri->ri_font->fontheight;
1473 1.27 macallan p9100_bitblt(scr->scr_cookie, xs, y, xd, y, width, height, ROP_SRC);
1474 1.27 macallan }
1475 1.27 macallan
1476 1.27 macallan static void
1477 1.27 macallan p9100_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
1478 1.27 macallan {
1479 1.27 macallan struct rasops_info *ri = cookie;
1480 1.27 macallan struct vcons_screen *scr = ri->ri_hw;
1481 1.27 macallan int32_t x, y, width, height, bg;
1482 1.33 blymn
1483 1.27 macallan x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1484 1.27 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1485 1.27 macallan width = ri->ri_font->fontwidth * ncols;
1486 1.33 blymn height = ri->ri_font->fontheight;
1487 1.27 macallan bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
1488 1.27 macallan p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
1489 1.27 macallan }
1490 1.27 macallan
1491 1.27 macallan static void
1492 1.27 macallan p9100_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1493 1.27 macallan {
1494 1.27 macallan struct rasops_info *ri = cookie;
1495 1.27 macallan struct vcons_screen *scr = ri->ri_hw;
1496 1.27 macallan int32_t x, ys, yd, width, height;
1497 1.27 macallan
1498 1.27 macallan x = ri->ri_xorigin;
1499 1.27 macallan ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1500 1.27 macallan yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1501 1.27 macallan width = ri->ri_emuwidth;
1502 1.33 blymn height = ri->ri_font->fontheight * nrows;
1503 1.27 macallan p9100_bitblt(scr->scr_cookie, x, ys, x, yd, width, height, ROP_SRC);
1504 1.27 macallan }
1505 1.27 macallan
1506 1.27 macallan static void
1507 1.27 macallan p9100_eraserows(void *cookie, int row, int nrows, long fillattr)
1508 1.27 macallan {
1509 1.27 macallan struct rasops_info *ri = cookie;
1510 1.27 macallan struct vcons_screen *scr = ri->ri_hw;
1511 1.27 macallan int32_t x, y, width, height, bg;
1512 1.33 blymn
1513 1.27 macallan if ((row == 0) && (nrows == ri->ri_rows)) {
1514 1.27 macallan x = y = 0;
1515 1.27 macallan width = ri->ri_width;
1516 1.27 macallan height = ri->ri_height;
1517 1.27 macallan } else {
1518 1.27 macallan x = ri->ri_xorigin;
1519 1.27 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1520 1.27 macallan width = ri->ri_emuwidth;
1521 1.27 macallan height = ri->ri_font->fontheight * nrows;
1522 1.27 macallan }
1523 1.27 macallan bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
1524 1.27 macallan p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
1525 1.27 macallan }
1526 1.27 macallan
1527 1.57 macallan #if 0
1528 1.27 macallan static int
1529 1.21 macallan p9100_load_font(void *v, void *cookie, struct wsdisplay_font *data)
1530 1.21 macallan {
1531 1.21 macallan
1532 1.21 macallan return 0;
1533 1.21 macallan }
1534 1.21 macallan #endif
1535 1.21 macallan
1536 1.28 macallan #endif /* NWSDISPLAY > 0 */
1537 1.28 macallan
1538 1.44 macallan #if 0
1539 1.27 macallan static int
1540 1.21 macallan p9100_intr(void *arg)
1541 1.21 macallan {
1542 1.44 macallan /*p9100_softc *sc=arg;*/
1543 1.44 macallan DPRINTF(".");
1544 1.21 macallan return 1;
1545 1.21 macallan }
1546 1.44 macallan #endif
1547 1.24 macallan
1548 1.27 macallan static void
1549 1.24 macallan p9100_init_cursor(struct p9100_softc *sc)
1550 1.24 macallan {
1551 1.33 blymn
1552 1.24 macallan memset(&sc->sc_cursor, 0, sizeof(struct pnozz_cursor));
1553 1.24 macallan sc->sc_cursor.pc_size.x = 64;
1554 1.24 macallan sc->sc_cursor.pc_size.y = 64;
1555 1.24 macallan
1556 1.24 macallan }
1557 1.24 macallan
1558 1.27 macallan static void
1559 1.24 macallan p9100_set_fbcursor(struct p9100_softc *sc)
1560 1.24 macallan {
1561 1.24 macallan #ifdef PNOZZ_PARANOID
1562 1.24 macallan int s;
1563 1.33 blymn
1564 1.24 macallan s = splhigh(); /* just in case... */
1565 1.24 macallan #endif
1566 1.27 macallan sc->sc_last_offset = 0xffffffff;
1567 1.27 macallan
1568 1.24 macallan /* set position and hotspot */
1569 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
1570 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_HI, 0);
1571 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_CTL);
1572 1.24 macallan if (sc->sc_cursor.pc_enable) {
1573 1.33 blymn p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_X11 |
1574 1.24 macallan DAC_CURSOR_64);
1575 1.24 macallan } else
1576 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_OFF);
1577 1.24 macallan /* next two registers - x low, high, y low, high */
1578 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.x & 0xff);
1579 1.33 blymn p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.x >> 8) &
1580 1.24 macallan 0xff);
1581 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.y & 0xff);
1582 1.33 blymn p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.y >> 8) &
1583 1.24 macallan 0xff);
1584 1.24 macallan /* hotspot */
1585 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.x & 0xff);
1586 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.y & 0xff);
1587 1.33 blymn
1588 1.24 macallan #ifdef PNOZZ_PARANOID
1589 1.24 macallan splx(s);
1590 1.24 macallan #endif
1591 1.24 macallan
1592 1.24 macallan }
1593 1.24 macallan
1594 1.27 macallan static void
1595 1.24 macallan p9100_setcursorcmap(struct p9100_softc *sc)
1596 1.24 macallan {
1597 1.24 macallan int i;
1598 1.33 blymn
1599 1.24 macallan #ifdef PNOZZ_PARANOID
1600 1.24 macallan int s;
1601 1.24 macallan s = splhigh(); /* just in case... */
1602 1.24 macallan #endif
1603 1.27 macallan sc->sc_last_offset = 0xffffffff;
1604 1.33 blymn
1605 1.24 macallan /* set cursor colours */
1606 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
1607 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_HI, 0);
1608 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_COL_1);
1609 1.24 macallan
1610 1.24 macallan for (i = 0; i < 3; i++) {
1611 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.red[i]);
1612 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.green[i]);
1613 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.blue[i]);
1614 1.24 macallan }
1615 1.33 blymn
1616 1.24 macallan #ifdef PNOZZ_PARANOID
1617 1.24 macallan splx(s);
1618 1.24 macallan #endif
1619 1.24 macallan }
1620 1.24 macallan
1621 1.27 macallan static void
1622 1.24 macallan p9100_loadcursor(struct p9100_softc *sc)
1623 1.24 macallan {
1624 1.24 macallan uint32_t *image, *mask;
1625 1.24 macallan uint32_t bit, bbit, im, ma;
1626 1.24 macallan int i, j, k;
1627 1.24 macallan uint8_t latch1, latch2;
1628 1.33 blymn
1629 1.24 macallan #ifdef PNOZZ_PARANOID
1630 1.24 macallan int s;
1631 1.24 macallan s = splhigh(); /* just in case... */
1632 1.24 macallan #endif
1633 1.27 macallan sc->sc_last_offset = 0xffffffff;
1634 1.27 macallan
1635 1.24 macallan /* set cursor shape */
1636 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
1637 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_HI, 1);
1638 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_LO, 0);
1639 1.24 macallan
1640 1.24 macallan image = sc->sc_cursor.pc_bits;
1641 1.24 macallan mask = &sc->sc_cursor.pc_bits[0x80];
1642 1.24 macallan
1643 1.24 macallan for (i = 0; i < 0x80; i++) {
1644 1.24 macallan bit = 0x80000000;
1645 1.24 macallan im = image[i];
1646 1.24 macallan ma = mask[i];
1647 1.24 macallan for (k = 0; k < 4; k++) {
1648 1.24 macallan bbit = 0x1;
1649 1.24 macallan latch1 = 0;
1650 1.24 macallan for (j = 0; j < 4; j++) {
1651 1.24 macallan if (im & bit)
1652 1.24 macallan latch1 |= bbit;
1653 1.24 macallan bbit <<= 1;
1654 1.24 macallan if (ma & bit)
1655 1.24 macallan latch1 |= bbit;
1656 1.24 macallan bbit <<= 1;
1657 1.24 macallan bit >>= 1;
1658 1.24 macallan }
1659 1.24 macallan bbit = 0x1;
1660 1.24 macallan latch2 = 0;
1661 1.24 macallan for (j = 0; j < 4; j++) {
1662 1.24 macallan if (im & bit)
1663 1.24 macallan latch2 |= bbit;
1664 1.24 macallan bbit <<= 1;
1665 1.24 macallan if (ma & bit)
1666 1.24 macallan latch2 |= bbit;
1667 1.24 macallan bbit <<= 1;
1668 1.24 macallan bit >>= 1;
1669 1.24 macallan }
1670 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, latch1);
1671 1.24 macallan p9100_ramdac_write(sc, DAC_INDX_DATA, latch2);
1672 1.24 macallan }
1673 1.24 macallan }
1674 1.44 macallan #ifdef PNOZZ_DEBUG_CURSOR
1675 1.24 macallan printf("image:\n");
1676 1.24 macallan for (i=0;i<0x80;i+=2)
1677 1.24 macallan printf("%08x %08x\n", image[i], image[i+1]);
1678 1.24 macallan printf("mask:\n");
1679 1.24 macallan for (i=0;i<0x80;i+=2)
1680 1.24 macallan printf("%08x %08x\n", mask[i], mask[i+1]);
1681 1.24 macallan #endif
1682 1.24 macallan #ifdef PNOZZ_PARANOID
1683 1.24 macallan splx(s);
1684 1.24 macallan #endif
1685 1.24 macallan }
1686 1.27 macallan
1687 1.40 he #if NTCTRL > 0
1688 1.27 macallan static void
1689 1.27 macallan p9100_set_extvga(void *cookie, int status)
1690 1.27 macallan {
1691 1.27 macallan struct p9100_softc *sc = cookie;
1692 1.27 macallan #ifdef PNOZZ_PARANOID
1693 1.27 macallan int s;
1694 1.27 macallan
1695 1.27 macallan s = splhigh();
1696 1.27 macallan #endif
1697 1.44 macallan
1698 1.44 macallan #ifdef PNOZZ_DEBUG
1699 1.44 macallan printf("%s: external VGA %s\n", device_xname(sc->sc_dev),
1700 1.27 macallan status ? "on" : "off");
1701 1.27 macallan #endif
1702 1.44 macallan
1703 1.27 macallan sc->sc_last_offset = 0xffffffff;
1704 1.27 macallan
1705 1.27 macallan if (status) {
1706 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_POWER_MGT,
1707 1.44 macallan p9100_ramdac_read_ctl(sc, DAC_POWER_MGT) &
1708 1.27 macallan ~DAC_POWER_IPWR_DISABLE);
1709 1.27 macallan } else {
1710 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_POWER_MGT,
1711 1.44 macallan p9100_ramdac_read_ctl(sc, DAC_POWER_MGT) |
1712 1.27 macallan DAC_POWER_IPWR_DISABLE);
1713 1.27 macallan }
1714 1.27 macallan #ifdef PNOZZ_PARANOID
1715 1.27 macallan splx(s);
1716 1.27 macallan #endif
1717 1.27 macallan }
1718 1.40 he #endif /* NTCTRL > 0 */
1719 1.44 macallan
1720 1.44 macallan static int
1721 1.44 macallan upper_bit(uint32_t b)
1722 1.44 macallan {
1723 1.44 macallan uint32_t mask=0x80000000;
1724 1.44 macallan int cnt = 31;
1725 1.44 macallan if (b == 0)
1726 1.44 macallan return -1;
1727 1.44 macallan while ((mask != 0) && ((b & mask) == 0)) {
1728 1.44 macallan mask = mask >> 1;
1729 1.44 macallan cnt--;
1730 1.44 macallan }
1731 1.44 macallan return cnt;
1732 1.44 macallan }
1733 1.44 macallan
1734 1.44 macallan static int
1735 1.44 macallan p9100_set_depth(struct p9100_softc *sc, int depth)
1736 1.44 macallan {
1737 1.44 macallan int new_sls;
1738 1.44 macallan uint32_t bits, scr, memctl, mem;
1739 1.44 macallan int s0, s1, s2, s3, ps, crtcline;
1740 1.44 macallan uint8_t pf, mc3, es;
1741 1.44 macallan
1742 1.44 macallan switch (depth) {
1743 1.44 macallan case 8:
1744 1.44 macallan sc->sc_depthshift = 0;
1745 1.44 macallan ps = 2;
1746 1.44 macallan pf = 3;
1747 1.44 macallan mc3 = 0;
1748 1.44 macallan es = 0; /* no swapping */
1749 1.44 macallan memctl = 3;
1750 1.44 macallan break;
1751 1.44 macallan case 16:
1752 1.44 macallan sc->sc_depthshift = 1;
1753 1.44 macallan ps = 3;
1754 1.44 macallan pf = 4;
1755 1.44 macallan mc3 = 0;
1756 1.44 macallan es = 2; /* swap bytes in 16bit words */
1757 1.44 macallan memctl = 2;
1758 1.44 macallan break;
1759 1.44 macallan case 24:
1760 1.44 macallan /* boo */
1761 1.44 macallan printf("We don't DO 24bit pixels dammit!\n");
1762 1.44 macallan return 0;
1763 1.44 macallan case 32:
1764 1.44 macallan sc->sc_depthshift = 2;
1765 1.44 macallan ps = 5;
1766 1.44 macallan pf = 6;
1767 1.44 macallan mc3 = 0;
1768 1.44 macallan es = 6; /* swap both half-words and bytes */
1769 1.44 macallan memctl = 1; /* 0 */
1770 1.44 macallan break;
1771 1.44 macallan default:
1772 1.44 macallan aprint_error("%s: bogus colour depth (%d)\n",
1773 1.44 macallan __func__, depth);
1774 1.44 macallan return FALSE;
1775 1.44 macallan }
1776 1.44 macallan /*
1777 1.44 macallan * this could be done a lot shorter and faster but then nobody would
1778 1.44 macallan * understand what the hell we're doing here without getting a major
1779 1.44 macallan * headache. Scanline size is encoded as 4 shift values, 3 of them 3 bits
1780 1.44 macallan * wide, 16 << n for n>0, one 2 bits, 512 << n for n>0. n==0 means 0
1781 1.44 macallan */
1782 1.44 macallan new_sls = sc->sc_width << sc->sc_depthshift;
1783 1.44 macallan sc->sc_stride = new_sls;
1784 1.44 macallan bits = new_sls;
1785 1.44 macallan s3 = upper_bit(bits);
1786 1.44 macallan if (s3 > 9) {
1787 1.44 macallan bits &= ~(1 << s3);
1788 1.44 macallan s3 -= 9;
1789 1.44 macallan } else
1790 1.44 macallan s3 = 0;
1791 1.44 macallan s2 = upper_bit(bits);
1792 1.44 macallan if (s2 > 0) {
1793 1.44 macallan bits &= ~(1 << s2);
1794 1.44 macallan s2 -= 4;
1795 1.44 macallan } else
1796 1.44 macallan s2 = 0;
1797 1.44 macallan s1 = upper_bit(bits);
1798 1.44 macallan if (s1 > 0) {
1799 1.44 macallan bits &= ~(1 << s1);
1800 1.44 macallan s1 -= 4;
1801 1.44 macallan } else
1802 1.44 macallan s1 = 0;
1803 1.44 macallan s0 = upper_bit(bits);
1804 1.44 macallan if (s0 > 0) {
1805 1.44 macallan bits &= ~(1 << s0);
1806 1.44 macallan s0 -= 4;
1807 1.44 macallan } else
1808 1.44 macallan s0 = 0;
1809 1.44 macallan
1810 1.44 macallan
1811 1.44 macallan DPRINTF("sls: %x sh: %d %d %d %d leftover: %x\n", new_sls, s0, s1,
1812 1.44 macallan s2, s3, bits);
1813 1.44 macallan
1814 1.44 macallan /*
1815 1.44 macallan * now let's put these values into the System Config Register. No need to
1816 1.44 macallan * read it here since we (hopefully) just saved the content
1817 1.44 macallan */
1818 1.44 macallan scr = p9100_ctl_read_4(sc, SYS_CONF);
1819 1.44 macallan scr = (s0 << SHIFT_0) | (s1 << SHIFT_1) | (s2 << SHIFT_2) |
1820 1.44 macallan (s3 << SHIFT_3) | (ps << PIXEL_SHIFT) | (es << SWAP_SHIFT);
1821 1.44 macallan
1822 1.44 macallan DPRINTF("new scr: %x DAC %x %x\n", scr, pf, mc3);
1823 1.44 macallan
1824 1.44 macallan mem = p9100_ctl_read_4(sc, VID_MEM_CONFIG);
1825 1.44 macallan
1826 1.44 macallan DPRINTF("old memctl: %08x\n", mem);
1827 1.44 macallan
1828 1.44 macallan /* set shift and crtc clock */
1829 1.44 macallan mem &= ~(0x0000fc00);
1830 1.44 macallan mem |= (memctl << 10) | (memctl << 13);
1831 1.44 macallan p9100_ctl_write_4(sc, VID_MEM_CONFIG, mem);
1832 1.44 macallan
1833 1.44 macallan DPRINTF("new memctl: %08x\n", mem);
1834 1.44 macallan
1835 1.44 macallan /* whack the engine... */
1836 1.44 macallan p9100_ctl_write_4(sc, SYS_CONF, scr);
1837 1.44 macallan
1838 1.44 macallan /* ok, whack the DAC */
1839 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_MISC_1, 0x11);
1840 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_MISC_2, 0x45);
1841 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_MISC_3, mc3);
1842 1.44 macallan /*
1843 1.44 macallan * despite the 3GX manual saying otherwise we don't need to mess with
1844 1.44 macallan * any clock dividers here
1845 1.44 macallan */
1846 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_MISC_CLK, 1);
1847 1.44 macallan p9100_ramdac_write_ctl(sc, 3, 0);
1848 1.44 macallan p9100_ramdac_write_ctl(sc, 4, 0);
1849 1.44 macallan
1850 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_POWER_MGT, 0);
1851 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_OPERATION, 0);
1852 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_PALETTE_CTRL, 0);
1853 1.44 macallan
1854 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_PIXEL_FMT, pf);
1855 1.44 macallan
1856 1.44 macallan /* TODO: distinguish between 15 and 16 bit */
1857 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_8BIT_CTRL, 0);
1858 1.44 macallan /* direct colour, linear, 565 */
1859 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_16BIT_CTRL, 0xc6);
1860 1.44 macallan /* direct colour */
1861 1.44 macallan p9100_ramdac_write_ctl(sc, DAC_32BIT_CTRL, 3);
1862 1.44 macallan
1863 1.44 macallan /* From the 3GX manual. Needs magic number reduction */
1864 1.44 macallan p9100_ramdac_write_ctl(sc, 0x10, 2);
1865 1.44 macallan p9100_ramdac_write_ctl(sc, 0x11, 0);
1866 1.44 macallan p9100_ramdac_write_ctl(sc, 0x14, 5);
1867 1.44 macallan p9100_ramdac_write_ctl(sc, 0x08, 1);
1868 1.44 macallan p9100_ramdac_write_ctl(sc, 0x15, 5);
1869 1.44 macallan p9100_ramdac_write_ctl(sc, 0x16, 0x63);
1870 1.44 macallan
1871 1.44 macallan /* whack the CRTC */
1872 1.44 macallan /* we always transfer 64bit in one go */
1873 1.44 macallan crtcline = sc->sc_stride >> 3;
1874 1.44 macallan
1875 1.44 macallan DPRINTF("crtcline: %d\n", crtcline);
1876 1.44 macallan
1877 1.44 macallan p9100_ctl_write_4(sc, VID_HTOTAL, (24 << sc->sc_depthshift) + crtcline);
1878 1.44 macallan p9100_ctl_write_4(sc, VID_HSRE, 8 << sc->sc_depthshift);
1879 1.44 macallan p9100_ctl_write_4(sc, VID_HBRE, 18 << sc->sc_depthshift);
1880 1.44 macallan p9100_ctl_write_4(sc, VID_HBFE, (18 << sc->sc_depthshift) + crtcline);
1881 1.44 macallan
1882 1.44 macallan #ifdef PNOZZ_DEBUG
1883 1.44 macallan {
1884 1.44 macallan uint32_t sscr;
1885 1.44 macallan sscr = p9100_ctl_read_4(sc, SYS_CONF);
1886 1.44 macallan printf("scr: %x\n", sscr);
1887 1.44 macallan }
1888 1.44 macallan #endif
1889 1.44 macallan return TRUE;
1890 1.44 macallan }
1891