lcg.c revision 1.12 1 1.12 riastrad /* $NetBSD: lcg.c,v 1.12 2025/02/27 15:31:06 riastradh Exp $ */
2 1.1 jklos /*
3 1.1 jklos * LCG accelerated framebuffer driver
4 1.1 jklos * Copyright (c) 2003, 2004 Blaz Antonic
5 1.1 jklos * All rights reserved.
6 1.1 jklos *
7 1.1 jklos * Redistribution and use in source and binary forms, with or without
8 1.1 jklos * modification, are permitted provided that the following conditions
9 1.1 jklos * are met:
10 1.1 jklos * 1. Redistributions of source code must retain the above copyright
11 1.1 jklos * notice, this list of conditions and the following disclaimer.
12 1.1 jklos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jklos * notice, this list of conditions and the following disclaimer in the
14 1.1 jklos * documentation and/or other materials provided with the distribution.
15 1.1 jklos * 3. All advertising materials mentioning features or use of this software
16 1.1 jklos * must display the abovementioned copyrights
17 1.1 jklos * 4. The name of the author may not be used to endorse or promote products
18 1.1 jklos * derived from this software without specific prior written permission
19 1.1 jklos *
20 1.1 jklos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 jklos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 jklos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 jklos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 jklos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 jklos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 jklos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 jklos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 jklos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 jklos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 jklos */
31 1.1 jklos /*
32 1.1 jklos * Resurrection and dumb framebuffer mode by Bjrn Johannesson
33 1.1 jklos * rherdware (at) yahoo.com in December 2014
34 1.1 jklos */
35 1.1 jklos
36 1.1 jklos #include <sys/cdefs.h>
37 1.12 riastrad __KERNEL_RCSID(0, "$NetBSD: lcg.c,v 1.12 2025/02/27 15:31:06 riastradh Exp $");
38 1.1 jklos
39 1.1 jklos #define LCG_NO_ACCEL
40 1.1 jklos
41 1.1 jklos #include <sys/param.h>
42 1.1 jklos #include <sys/device.h>
43 1.1 jklos #include <sys/systm.h>
44 1.1 jklos #include <sys/callout.h>
45 1.1 jklos #include <sys/time.h>
46 1.5 thorpej #include <sys/kmem.h>
47 1.1 jklos #include <sys/conf.h>
48 1.1 jklos #include <sys/kernel.h>
49 1.1 jklos #include <sys/systm.h>
50 1.1 jklos
51 1.1 jklos #include <machine/vsbus.h>
52 1.1 jklos #include <machine/sid.h>
53 1.1 jklos #include <machine/cpu.h>
54 1.1 jklos #include <machine/lcgreg.h>
55 1.1 jklos
56 1.1 jklos #include <dev/cons.h>
57 1.1 jklos
58 1.1 jklos #include <dev/dec/dzreg.h>
59 1.1 jklos #include <dev/dec/dzvar.h>
60 1.1 jklos #include <dev/dec/dzkbdvar.h>
61 1.1 jklos
62 1.1 jklos #include <dev/wscons/wsdisplayvar.h>
63 1.1 jklos #include <dev/wscons/wsconsio.h>
64 1.1 jklos #include <dev/wscons/wscons_callbacks.h>
65 1.1 jklos #include <dev/wsfont/wsfont.h>
66 1.1 jklos
67 1.1 jklos #include "machine/scb.h"
68 1.1 jklos
69 1.1 jklos #include "dzkbd.h"
70 1.1 jklos
71 1.1 jklos /* Screen hardware defs */
72 1.1 jklos
73 1.1 jklos #define LCG_FB_ADDR 0x21801000 /* Frame buffer */
74 1.1 jklos
75 1.1 jklos /* FIFO defines */
76 1.1 jklos #define LCG_FIFO_SIZE 0x10000 /* 64 KB */
77 1.1 jklos #define LCG_FIFO_WIN_ADDR 0x20180000
78 1.1 jklos #define LCG_FIFO_WIN_SIZE VAX_NBPG
79 1.1 jklos #define LCG_FIFO_ALIGN 0x10000
80 1.1 jklos
81 1.1 jklos /* font rendering defines */
82 1.1 jklos #define LCG_FONT_ADDR (LCG_FB_ADDR + lcg_fb_size)
83 1.3 dholland #define LCG_FONT_STORAGE_SIZE 0x40000 /* 16 KB, enough to accommodate 16x32 font bitmaps */
84 1.1 jklos
85 1.1 jklos /* register space defines */
86 1.1 jklos #define LCG_REG_ADDR 0x20100000 /* LCG registers */
87 1.1 jklos #define LCG_REG_SIZE 0x4000 /* 16384 bytes */
88 1.1 jklos #define LCG_REG(reg) regaddr[(reg / 4)]
89 1.1 jklos
90 1.1 jklos /* LUT defines */
91 1.1 jklos #define LCG_LUT_ADDR 0x21800800 /* LUT right before onscreen FB */
92 1.1 jklos #define LCG_LUT_OFFSET 0x00000800
93 1.1 jklos #define LCG_LUT_SIZE 0x800 /* 2048 bytes */
94 1.1 jklos
95 1.1 jklos #define LCG_BG_COLOR WSCOL_BLACK
96 1.1 jklos #define LCG_FG_COLOR WSCOL_WHITE
97 1.1 jklos
98 1.1 jklos #define LCG_CONFIG 0x200f0010 /* LCG model information */
99 1.1 jklos
100 1.1 jklos /* implement sanity checks at certain points to ensure safer operation */
101 1.1 jklos #define LCG_SAFE
102 1.1 jklos //#define LCG_DEBUG
103 1.1 jklos
104 1.1 jklos static int lcg_match(struct device *, struct cfdata *, void *);
105 1.1 jklos static void lcg_attach(struct device *, struct device *, void *);
106 1.1 jklos
107 1.1 jklos struct lcg_softc {
108 1.1 jklos bus_dmamap_t sc_dm;
109 1.1 jklos };
110 1.1 jklos
111 1.1 jklos CFATTACH_DECL_NEW(lcg, sizeof(struct lcg_softc),
112 1.1 jklos lcg_match, lcg_attach, NULL, NULL);
113 1.1 jklos
114 1.1 jklos static void lcg_cursor(void *, int, int, int);
115 1.1 jklos static int lcg_mapchar(void *, int, unsigned int *);
116 1.1 jklos static void lcg_putchar(void *, int, int, u_int, long);
117 1.1 jklos static void lcg_copycols(void *, int, int, int,int);
118 1.1 jklos static void lcg_erasecols(void *, int, int, int, long);
119 1.1 jklos static void lcg_copyrows(void *, int, int, int);
120 1.1 jklos static void lcg_eraserows(void *, int, int, long);
121 1.1 jklos static int lcg_allocattr(void *, int, int, int, long *);
122 1.1 jklos static int lcg_get_cmap(struct wsdisplay_cmap *);
123 1.1 jklos static int lcg_set_cmap(struct wsdisplay_cmap *);
124 1.1 jklos static void lcg_init_common(struct device *, struct vsbus_attach_args *);
125 1.1 jklos
126 1.1 jklos const struct wsdisplay_emulops lcg_emulops = {
127 1.1 jklos lcg_cursor,
128 1.1 jklos lcg_mapchar,
129 1.1 jklos lcg_putchar,
130 1.1 jklos lcg_copycols,
131 1.1 jklos lcg_erasecols,
132 1.1 jklos lcg_copyrows,
133 1.1 jklos lcg_eraserows,
134 1.1 jklos lcg_allocattr
135 1.1 jklos };
136 1.1 jklos
137 1.1 jklos static char lcg_stdscreen_name[10] = "160x68";
138 1.1 jklos struct wsscreen_descr lcg_stdscreen = {
139 1.1 jklos lcg_stdscreen_name, 160, 68, /* dynamically set */
140 1.1 jklos &lcg_emulops,
141 1.1 jklos 8, 15, /* dynamically set */
142 1.1 jklos WSSCREEN_UNDERLINE|WSSCREEN_REVERSE|WSSCREEN_WSCOLORS,
143 1.1 jklos };
144 1.1 jklos
145 1.1 jklos const struct wsscreen_descr *_lcg_scrlist[] = {
146 1.1 jklos &lcg_stdscreen,
147 1.1 jklos };
148 1.1 jklos
149 1.1 jklos const struct wsscreen_list lcg_screenlist = {
150 1.1 jklos sizeof(_lcg_scrlist) / sizeof(struct wsscreen_descr *),
151 1.1 jklos _lcg_scrlist,
152 1.1 jklos };
153 1.1 jklos
154 1.1 jklos static char *lcgaddr;
155 1.1 jklos static char *lutaddr;
156 1.1 jklos static volatile long *regaddr;
157 1.1 jklos static volatile long *fifoaddr;
158 1.1 jklos #ifndef LCG_NO_ACCEL
159 1.1 jklos static char *fontaddr;
160 1.1 jklos #endif
161 1.1 jklos
162 1.1 jklos static int lcg_xsize;
163 1.1 jklos static int lcg_ysize;
164 1.1 jklos static int lcg_depth;
165 1.1 jklos static int lcg_cols;
166 1.1 jklos static int lcg_rows;
167 1.1 jklos static int lcg_onerow;
168 1.1 jklos static int lcg_fb_size;
169 1.1 jklos static int lcg_glyph_size; /* bitmap size in bits */
170 1.1 jklos
171 1.1 jklos static char *cursor;
172 1.1 jklos
173 1.1 jklos static int cur_on;
174 1.1 jklos
175 1.1 jklos static int cur_fg, cur_bg;
176 1.1 jklos
177 1.1 jklos
178 1.1 jklos /* Our current hardware colormap */
179 1.1 jklos static struct hwcmap256 {
180 1.1 jklos #define CMAP_SIZE 256 /* 256 R/G/B entries */
181 1.1 jklos u_int8_t r[CMAP_SIZE];
182 1.1 jklos u_int8_t g[CMAP_SIZE];
183 1.1 jklos u_int8_t b[CMAP_SIZE];
184 1.1 jklos } lcg_cmap;
185 1.1 jklos
186 1.1 jklos /* The default colormap */
187 1.1 jklos static struct {
188 1.1 jklos u_int8_t r[8];
189 1.1 jklos u_int8_t g[8];
190 1.1 jklos u_int8_t b[8];
191 1.1 jklos } lcg_default_cmap = {
192 1.1 jklos { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
193 1.1 jklos { 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff },
194 1.1 jklos { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff }
195 1.1 jklos };
196 1.1 jklos
197 1.1 jklos struct wsdisplay_font lcg_font;
198 1.1 jklos static u_char *qf;
199 1.1 jklos static u_short *qf2;
200 1.1 jklos
201 1.1 jklos #define QCHAR(c) (c < lcg_font.firstchar ? 0 : \
202 1.1 jklos (c >= (lcg_font.firstchar + lcg_font.numchars) ? 0 : c - lcg_font.firstchar))
203 1.1 jklos #define QFONT(c,line) ((lcg_font.stride == 2 ? \
204 1.1 jklos qf2[QCHAR(c) * lcg_font.fontheight + line] : \
205 1.1 jklos qf[QCHAR(c) * lcg_font.fontheight + line]))
206 1.1 jklos #define LCG_ADDR(row, col, line, dot) \
207 1.1 jklos lcgaddr[((col) * lcg_font.fontwidth) + ((row) * lcg_font.fontheight * lcg_xsize) + \
208 1.1 jklos (line) * lcg_xsize + dot]
209 1.1 jklos
210 1.1 jklos
211 1.1 jklos static int lcg_ioctl(void *, void *, u_long, void *, int, struct lwp *);
212 1.1 jklos static paddr_t lcg_mmap(void *, void *, off_t, int);
213 1.1 jklos static int lcg_alloc_screen(void *, const struct wsscreen_descr *,
214 1.1 jklos void **, int *, int *, long *);
215 1.1 jklos static void lcg_free_screen(void *, void *);
216 1.1 jklos static int lcg_show_screen(void *, void *, int,
217 1.1 jklos void (*) (void *, int, int), void *);
218 1.1 jklos static void lcg_crsr_blink(void *);
219 1.1 jklos
220 1.1 jklos /* LCG HW accel functions */
221 1.1 jklos #ifndef LCG_NO_ACCEL
222 1.1 jklos static void fifo_put(long data);
223 1.1 jklos static int fifo_fill(int iterations);
224 1.1 jklos static u_char fifo_counter = 0;
225 1.1 jklos
226 1.1 jklos static void blkcpy(long source, long dest, int xdim, int ydim);
227 1.1 jklos static void blkset(long dest, int xdim, int ydim, char color);
228 1.1 jklos static void renderchar(long source, long dest, int xdim, int ydim, char fg, char bg);
229 1.1 jklos #endif /* LCG_NO_ACCEL */
230 1.1 jklos
231 1.1 jklos const struct wsdisplay_accessops lcg_accessops = {
232 1.1 jklos lcg_ioctl,
233 1.1 jklos lcg_mmap,
234 1.1 jklos lcg_alloc_screen,
235 1.1 jklos lcg_free_screen,
236 1.1 jklos lcg_show_screen,
237 1.1 jklos 0 /* load_font */
238 1.1 jklos };
239 1.1 jklos
240 1.1 jklos /* TODO allocate ss_image dynamically for consoles beyond first one */
241 1.1 jklos struct lcg_screen {
242 1.1 jklos int ss_curx;
243 1.1 jklos int ss_cury;
244 1.1 jklos int ss_cur_fg;
245 1.1 jklos int ss_cur_bg;
246 1.1 jklos struct {
247 1.1 jklos u_char data; /* Image character */
248 1.1 jklos u_char attr; /* Attribute: 80/70/08/07 */
249 1.1 jklos } ss_image[160 * 128]; /* allow for maximum possible cell matrix */
250 1.1 jklos };
251 1.1 jklos #define LCG_ATTR_UNDERLINE 0x80
252 1.1 jklos #define LCG_BG_MASK 0x70
253 1.1 jklos #define LCG_ATTR_REVERSE 0x08
254 1.1 jklos #define LCG_FG_MASK 0x07
255 1.1 jklos
256 1.1 jklos static struct lcg_screen lcg_conscreen;
257 1.1 jklos static struct lcg_screen *curscr;
258 1.1 jklos static struct lcg_screen *savescr;
259 1.1 jklos
260 1.1 jklos static callout_t lcg_cursor_ch;
261 1.1 jklos
262 1.1 jklos #ifndef LCG_NO_ACCEL
263 1.1 jklos void fifo_put(long data)
264 1.1 jklos {
265 1.1 jklos fifo_counter &= 0x3;
266 1.1 jklos fifoaddr[fifo_counter] = data;
267 1.1 jklos fifo_counter++;
268 1.1 jklos }
269 1.1 jklos
270 1.1 jklos int fifo_fill(int iterations)
271 1.1 jklos {
272 1.1 jklos long status;
273 1.4 maya int counter = 0;
274 1.1 jklos
275 1.1 jklos while (fifo_counter % 4)
276 1.1 jklos fifo_put(0);
277 1.1 jklos
278 1.1 jklos #ifdef LCG_SAFE
279 1.1 jklos status = LCG_REG(LCG_REG_GRAPHICS_SUB_STATUS);
280 1.1 jklos while ((counter < iterations) && ((status & 0x80000000) == 0x80000000)) {
281 1.1 jklos delay(1000);
282 1.1 jklos status = LCG_REG(LCG_REG_GRAPHICS_SUB_STATUS);
283 1.1 jklos counter++;
284 1.1 jklos }
285 1.1 jklos #endif
286 1.1 jklos
287 1.1 jklos if (counter == 0)
288 1.1 jklos return 0;
289 1.1 jklos else
290 1.1 jklos return 1;
291 1.1 jklos }
292 1.1 jklos
293 1.1 jklos void blkcpy(long source, long dest, int xdim, int ydim)
294 1.1 jklos {
295 1.1 jklos int err;
296 1.1 jklos
297 1.1 jklos #ifdef LCG_SAFE
298 1.1 jklos if ((source < LCG_FB_ADDR) || (source > LCG_FB_ADDR + lcg_fb_size)) {
299 1.1 jklos printf("lcg: blkcpy: invalid source 0x%lx\n", source);
300 1.1 jklos return;
301 1.1 jklos }
302 1.1 jklos if ((dest < LCG_FB_ADDR) || (dest > LCG_FB_ADDR + lcg_fb_size)) {
303 1.1 jklos printf("lcg: blkcpy: invalid destination 0x%lx\n", dest);
304 1.1 jklos return;
305 1.1 jklos }
306 1.1 jklos #endif
307 1.1 jklos
308 1.1 jklos #ifdef LCG_SAFE
309 1.1 jklos fifo_put(0x0c010000 | (cur_fg & 0xff));
310 1.1 jklos #endif
311 1.1 jklos fifo_put(0x01020006);
312 1.1 jklos
313 1.1 jklos fifo_put(0x06800000);
314 1.1 jklos fifo_put(source);
315 1.1 jklos fifo_put(lcg_xsize);
316 1.1 jklos
317 1.1 jklos fifo_put(0x05800000);
318 1.1 jklos fifo_put(dest);
319 1.1 jklos fifo_put(lcg_xsize);
320 1.1 jklos
321 1.1 jklos fifo_put(0x03400000);
322 1.1 jklos fifo_put(0xff);
323 1.1 jklos
324 1.1 jklos fifo_put(0x02000003);
325 1.1 jklos
326 1.1 jklos #ifdef LCG_SAFE
327 1.1 jklos fifo_put(0x04c00000);
328 1.1 jklos fifo_put(0);
329 1.1 jklos fifo_put(lcg_xsize);
330 1.1 jklos fifo_put(lcg_fb_size - (dest - LCG_FB_ADDR));
331 1.1 jklos #endif
332 1.1 jklos
333 1.1 jklos fifo_put(0x09c00000);
334 1.1 jklos fifo_put(((ydim & 0xffff) << 16) | xdim);
335 1.1 jklos fifo_put(0);
336 1.1 jklos fifo_put(0);
337 1.1 jklos
338 1.1 jklos err = fifo_fill(200);
339 1.1 jklos if (err)
340 1.1 jklos printf("lcg: AG still busy after 200 msec\n");
341 1.1 jklos }
342 1.1 jklos
343 1.1 jklos void blkset(long dest, int xdim, int ydim, char color)
344 1.1 jklos {
345 1.1 jklos int err;
346 1.1 jklos
347 1.1 jklos #ifdef LCG_SAFE
348 1.1 jklos if ((dest < LCG_FB_ADDR) || (dest > LCG_FB_ADDR + lcg_fb_size)) {
349 1.1 jklos printf("lcg: blkset: invalid destination 0x%lx\n", dest);
350 1.1 jklos return;
351 1.1 jklos }
352 1.1 jklos #endif
353 1.1 jklos
354 1.1 jklos fifo_put(0x0c010000 | (color & 0xff));
355 1.1 jklos
356 1.1 jklos fifo_put(0x01000000);
357 1.1 jklos
358 1.1 jklos fifo_put(0x05800000);
359 1.1 jklos fifo_put(dest);
360 1.1 jklos fifo_put(lcg_xsize);
361 1.1 jklos
362 1.1 jklos fifo_put(0x03400000);
363 1.1 jklos fifo_put(0xff);
364 1.1 jklos
365 1.1 jklos fifo_put(0x02000003);
366 1.1 jklos
367 1.1 jklos #ifdef LCG_SAFE
368 1.1 jklos fifo_put(0x04c00000);
369 1.1 jklos fifo_put(0);
370 1.1 jklos fifo_put(lcg_xsize);
371 1.1 jklos fifo_put(lcg_fb_size - (dest - LCG_FB_ADDR));
372 1.1 jklos #endif
373 1.1 jklos
374 1.1 jklos fifo_put(0x09c00000);
375 1.1 jklos fifo_put(((ydim & 0xffff) << 16) | xdim);
376 1.1 jklos fifo_put(0);
377 1.1 jklos fifo_put(0);
378 1.1 jklos
379 1.1 jklos err = fifo_fill(200);
380 1.1 jklos if (err)
381 1.1 jklos printf("lcg: AG still busy after 200 msec\n");
382 1.1 jklos }
383 1.1 jklos
384 1.1 jklos void renderchar(long source, long dest, int xdim, int ydim, char fg, char bg)
385 1.1 jklos {
386 1.1 jklos int err;
387 1.1 jklos #ifdef LCG_SAFE
388 1.1 jklos if ((dest < LCG_FB_ADDR) || (dest > LCG_FB_ADDR + lcg_fb_size)) {
389 1.1 jklos printf("lcg: blkset: invalid destination 0x%lx\n", dest);
390 1.1 jklos return;
391 1.1 jklos }
392 1.1 jklos #endif
393 1.1 jklos
394 1.1 jklos fifo_put(0x0c050000 | (bg & 0xff));
395 1.1 jklos fifo_put(0x0c010000 | (fg & 0xff));
396 1.1 jklos
397 1.1 jklos fifo_put(0x01030008);
398 1.1 jklos
399 1.1 jklos fifo_put(0x06800000);
400 1.1 jklos fifo_put(source);
401 1.1 jklos //fifo_put(lcg_xsize);
402 1.1 jklos fifo_put(lcg_font.stride);
403 1.1 jklos
404 1.1 jklos fifo_put(0x05800000);
405 1.1 jklos fifo_put(dest);
406 1.1 jklos fifo_put(lcg_xsize);
407 1.1 jklos
408 1.1 jklos fifo_put(0x03400000);
409 1.1 jklos fifo_put(0xff);
410 1.1 jklos
411 1.1 jklos fifo_put(0x02000003);
412 1.1 jklos
413 1.1 jklos #ifdef LCG_SAFE
414 1.1 jklos fifo_put(0x04c00000);
415 1.1 jklos fifo_put(0);
416 1.1 jklos fifo_put(lcg_xsize);
417 1.1 jklos fifo_put(lcg_fb_size - (dest - LCG_FB_ADDR));
418 1.1 jklos #endif
419 1.1 jklos
420 1.1 jklos fifo_put(0x09c00000);
421 1.1 jklos fifo_put(((ydim & 0xffff) << 16) | (xdim & 0xffff));
422 1.1 jklos fifo_put(0);
423 1.1 jklos fifo_put(0);
424 1.1 jklos
425 1.1 jklos err = fifo_fill(200);
426 1.1 jklos if (err)
427 1.1 jklos printf("lcg: AG still busy after 200 msec\n");
428 1.1 jklos }
429 1.1 jklos #endif /* LCG_NO_ACCEL */
430 1.1 jklos
431 1.1 jklos int
432 1.1 jklos lcg_match(struct device *parent, struct cfdata *match, void *aux)
433 1.1 jklos {
434 1.1 jklos struct vsbus_softc *sc = device_private(parent);
435 1.1 jklos struct vsbus_attach_args *va = aux;
436 1.11 jakllsch volatile char * const ch = (char *)va->va_addr;
437 1.1 jklos
438 1.1 jklos if ((vax_boardtype != VAX_BTYP_46) && (vax_boardtype != VAX_BTYP_48))
439 1.1 jklos return 0;
440 1.1 jklos
441 1.1 jklos *ch = 1;
442 1.1 jklos if ((*ch & 1) == 0)
443 1.1 jklos return 0;
444 1.1 jklos *ch = 0;
445 1.1 jklos if ((*ch & 1) != 0)
446 1.1 jklos return 0;
447 1.1 jklos
448 1.1 jklos /* XXX use vertical interrupt? */
449 1.1 jklos sc->sc_mask = 0x04; /* XXX - should be generated */
450 1.1 jklos scb_fake(0x120, 0x15);
451 1.1 jklos return 20;
452 1.1 jklos }
453 1.1 jklos
454 1.1 jklos void
455 1.1 jklos lcg_attach(struct device *parent, struct device *self, void *aux)
456 1.1 jklos {
457 1.1 jklos struct vsbus_attach_args *va = aux;
458 1.1 jklos struct wsemuldisplaydev_attach_args aa;
459 1.1 jklos
460 1.1 jklos printf("\n");
461 1.1 jklos aa.console = lcgaddr != NULL;
462 1.1 jklos
463 1.1 jklos lcg_init_common(self, va);
464 1.1 jklos
465 1.1 jklos curscr = &lcg_conscreen;
466 1.1 jklos
467 1.1 jklos aa.scrdata = &lcg_screenlist;
468 1.1 jklos aa.accessops = &lcg_accessops;
469 1.1 jklos
470 1.1 jklos /* enable software cursor */
471 1.1 jklos callout_init(&lcg_cursor_ch, 0);
472 1.1 jklos callout_reset(&lcg_cursor_ch, hz / 2, lcg_crsr_blink, NULL);
473 1.1 jklos
474 1.7 thorpej config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE);
475 1.1 jklos }
476 1.1 jklos
477 1.1 jklos static void
478 1.1 jklos lcg_crsr_blink(void *arg)
479 1.1 jklos {
480 1.1 jklos int dot;
481 1.1 jklos
482 1.1 jklos if (cur_on && curscr != NULL)
483 1.1 jklos for (dot = 0; dot < lcg_font.fontwidth; dot++)
484 1.1 jklos cursor[dot] = ((cursor[dot] & 0x0f) == cur_fg) ? cur_bg : cur_fg;
485 1.1 jklos
486 1.1 jklos callout_reset(&lcg_cursor_ch, hz / 2, lcg_crsr_blink, NULL);
487 1.1 jklos }
488 1.1 jklos
489 1.1 jklos void
490 1.1 jklos lcg_cursor(void *id, int on, int row, int col)
491 1.1 jklos {
492 1.1 jklos struct lcg_screen *ss = id;
493 1.1 jklos int dot, attr;
494 1.1 jklos
495 1.1 jklos attr = ss->ss_image[row * lcg_cols + col].attr;
496 1.1 jklos if (ss == curscr) {
497 1.1 jklos if (cursor != NULL) {
498 1.1 jklos int ch = QFONT(ss->ss_image[ss->ss_cury * lcg_cols +
499 1.1 jklos ss->ss_curx].data, lcg_font.fontheight - 1);
500 1.1 jklos attr = ss->ss_image[ss->ss_cury * lcg_cols +
501 1.1 jklos ss->ss_curx].attr;
502 1.1 jklos
503 1.1 jklos if (attr & LCG_ATTR_REVERSE) {
504 1.1 jklos cur_bg = attr & LCG_FG_MASK;
505 1.1 jklos cur_fg = (attr & LCG_BG_MASK) >> 4;
506 1.1 jklos } else {
507 1.1 jklos cur_fg = attr & LCG_FG_MASK;
508 1.1 jklos cur_bg = (attr & LCG_BG_MASK) >> 4;
509 1.1 jklos }
510 1.1 jklos for (dot = 0; dot < lcg_font.fontwidth; dot++)
511 1.1 jklos cursor[dot] = (ch & (1 << dot)) ?
512 1.1 jklos cur_fg : cur_bg;
513 1.1 jklos }
514 1.1 jklos
515 1.1 jklos cursor = &LCG_ADDR(row, col, lcg_font.fontheight - 1, 0);
516 1.1 jklos cur_on = on;
517 1.1 jklos if (attr & LCG_ATTR_REVERSE) {
518 1.1 jklos cur_bg = attr & LCG_FG_MASK;
519 1.1 jklos cur_fg = (attr & LCG_BG_MASK) >> 4;
520 1.1 jklos } else {
521 1.1 jklos cur_fg = attr & LCG_FG_MASK;
522 1.1 jklos cur_bg = (attr & LCG_BG_MASK) >> 4;
523 1.1 jklos }
524 1.1 jklos }
525 1.1 jklos ss->ss_curx = col;
526 1.1 jklos ss->ss_cury = row;
527 1.1 jklos if (attr & LCG_ATTR_REVERSE) {
528 1.1 jklos ss->ss_cur_bg = attr & LCG_FG_MASK;
529 1.1 jklos ss->ss_cur_fg = (attr & LCG_BG_MASK) >> 4;
530 1.1 jklos } else {
531 1.1 jklos ss->ss_cur_fg = attr & LCG_FG_MASK;
532 1.1 jklos ss->ss_cur_bg = (attr & LCG_BG_MASK) >> 4;
533 1.1 jklos }
534 1.1 jklos }
535 1.1 jklos
536 1.1 jklos int
537 1.1 jklos lcg_mapchar(void *id, int uni, unsigned int *index)
538 1.1 jklos {
539 1.1 jklos if (uni < 256) {
540 1.1 jklos *index = uni;
541 1.1 jklos return (5);
542 1.1 jklos }
543 1.1 jklos *index = ' ';
544 1.1 jklos return (0);
545 1.1 jklos }
546 1.1 jklos
547 1.1 jklos static void
548 1.1 jklos lcg_putchar(void *id, int row, int col, u_int c, long attr)
549 1.1 jklos {
550 1.1 jklos struct lcg_screen *ss = id;
551 1.1 jklos int i;
552 1.1 jklos char dot_fg, dot_bg;
553 1.1 jklos
554 1.1 jklos c &= 0xff;
555 1.1 jklos
556 1.1 jklos ss->ss_image[row * lcg_cols + col].data = c;
557 1.1 jklos ss->ss_image[row * lcg_cols + col].attr = attr;
558 1.1 jklos if (ss != curscr)
559 1.1 jklos return;
560 1.1 jklos
561 1.1 jklos dot_fg = attr & LCG_FG_MASK;
562 1.1 jklos dot_bg = (attr & LCG_BG_MASK) >> 4;
563 1.1 jklos if (attr & LCG_ATTR_REVERSE) {
564 1.1 jklos dot_fg = (attr & LCG_BG_MASK) >> 4;
565 1.1 jklos dot_bg = attr & LCG_FG_MASK;
566 1.1 jklos }
567 1.1 jklos
568 1.1 jklos #ifndef LCG_NO_ACCEL
569 1.1 jklos renderchar(LCG_FONT_ADDR + (c * lcg_glyph_size),
570 1.1 jklos LCG_FB_ADDR + (row * lcg_onerow) + (col * lcg_font.fontwidth),
571 1.1 jklos lcg_font.fontwidth, lcg_font.fontheight, dot_fg, dot_bg);
572 1.1 jklos #else
573 1.1 jklos for (i = 0; i < lcg_font.fontheight; i++) {
574 1.1 jklos unsigned char ch = QFONT(c,i);
575 1.1 jklos for (int j = 0; j < lcg_font.fontwidth; j++) {
576 1.1 jklos LCG_ADDR(row, col, i, j) = ((ch >> j) & 1) ? dot_fg : dot_bg;
577 1.1 jklos }
578 1.1 jklos }
579 1.1 jklos #endif /* LCG_NO_ACCEL */
580 1.1 jklos if (attr & LCG_ATTR_UNDERLINE) {
581 1.1 jklos char *p = &LCG_ADDR(row, col, lcg_font.fontheight - 1, 0);
582 1.1 jklos for (i = 0; i < lcg_font.fontwidth; i++)
583 1.1 jklos p[i] = ~p[i];
584 1.1 jklos }
585 1.1 jklos }
586 1.1 jklos
587 1.1 jklos
588 1.1 jklos
589 1.1 jklos /*
590 1.1 jklos * copies columns inside a row.
591 1.1 jklos */
592 1.1 jklos static void
593 1.1 jklos lcg_copycols(void *id, int row, int srccol, int dstcol, int ncols)
594 1.1 jklos {
595 1.1 jklos struct lcg_screen *ss = id;
596 1.1 jklos #ifdef LCG_NO_ACCEL
597 1.1 jklos int i = 0;
598 1.1 jklos #endif
599 1.1 jklos
600 1.1 jklos bcopy(&ss->ss_image[row * lcg_cols + srccol], &ss->ss_image[row *
601 1.1 jklos lcg_cols + dstcol], ncols * sizeof(ss->ss_image[0]));
602 1.1 jklos if (ss != curscr)
603 1.1 jklos return;
604 1.1 jklos #ifdef LCG_NO_ACCEL
605 1.1 jklos for (i = 0; i < lcg_font.fontheight; i++)
606 1.1 jklos memcpy(&LCG_ADDR(row, dstcol, i, 0),
607 1.1 jklos &LCG_ADDR(row,srccol, i, 0), ncols * lcg_font.fontwidth);
608 1.1 jklos
609 1.1 jklos #else
610 1.1 jklos blkcpy(LCG_FB_ADDR + (row * lcg_onerow) + (srccol * lcg_font.fontwidth),
611 1.1 jklos LCG_FB_ADDR + (row * lcg_onerow) + (dstcol * lcg_font.fontwidth),
612 1.1 jklos (ncols * lcg_font.fontwidth), lcg_font.fontheight);
613 1.1 jklos #endif
614 1.1 jklos }
615 1.1 jklos
616 1.1 jklos /*
617 1.1 jklos * Erases a bunch of chars inside one row.
618 1.1 jklos */
619 1.1 jklos static void
620 1.1 jklos lcg_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
621 1.1 jklos {
622 1.1 jklos struct lcg_screen *ss = id;
623 1.1 jklos int i;
624 1.1 jklos
625 1.1 jklos bzero(&ss->ss_image[row * lcg_cols + startcol], ncols * sizeof(ss->ss_image[0]));
626 1.1 jklos for (i = row * lcg_cols + startcol; i < row * lcg_cols + startcol + ncols; ++i)
627 1.1 jklos ss->ss_image[i].attr = fillattr;
628 1.1 jklos if (ss != curscr)
629 1.1 jklos return;
630 1.1 jklos #ifdef LCG_NO_ACCEL
631 1.1 jklos for (i = 0; i < lcg_font.fontheight; i++)
632 1.1 jklos memset(&LCG_ADDR(row, startcol, i, 0), 0, ncols * lcg_font.fontwidth);
633 1.1 jklos #else
634 1.1 jklos blkset(LCG_FB_ADDR + (row * lcg_onerow) + (startcol * lcg_font.fontwidth),
635 1.1 jklos (ncols * lcg_font.fontwidth), lcg_font.fontheight, (fillattr & LCG_BG_MASK) >> 4);
636 1.1 jklos #endif
637 1.1 jklos }
638 1.1 jklos
639 1.1 jklos static void
640 1.1 jklos lcg_copyrows(void *id, int srcrow, int dstrow, int nrows)
641 1.1 jklos {
642 1.1 jklos struct lcg_screen *ss = id;
643 1.1 jklos
644 1.1 jklos bcopy(&ss->ss_image[srcrow * lcg_cols], &ss->ss_image[dstrow * lcg_cols],
645 1.1 jklos nrows * lcg_cols * sizeof(ss->ss_image[0]));
646 1.1 jklos if (ss != curscr)
647 1.1 jklos return;
648 1.1 jklos #ifdef LCG_NO_ACCEL
649 1.1 jklos memcpy(&lcgaddr[dstrow * lcg_onerow],
650 1.1 jklos &lcgaddr[srcrow * lcg_onerow], nrows * lcg_onerow);
651 1.1 jklos #else
652 1.1 jklos blkcpy(LCG_FB_ADDR + (srcrow * lcg_onerow), LCG_FB_ADDR + (dstrow * lcg_onerow),
653 1.1 jklos (lcg_cols * lcg_font.fontwidth), (nrows * lcg_font.fontheight));
654 1.1 jklos #endif
655 1.1 jklos }
656 1.1 jklos
657 1.1 jklos static void
658 1.1 jklos lcg_eraserows(void *id, int startrow, int nrows, long fillattr)
659 1.1 jklos {
660 1.1 jklos struct lcg_screen *ss = id;
661 1.1 jklos int i;
662 1.1 jklos
663 1.1 jklos bzero(&ss->ss_image[startrow * lcg_cols], nrows * lcg_cols *
664 1.1 jklos sizeof(ss->ss_image[0]));
665 1.1 jklos for (i = startrow * lcg_cols; i < (startrow + nrows) * lcg_cols; ++i)
666 1.1 jklos ss->ss_image[i].attr = fillattr;
667 1.1 jklos if (ss != curscr)
668 1.1 jklos return;
669 1.1 jklos #ifdef LCG_NO_ACCEL
670 1.1 jklos memset(&lcgaddr[startrow * lcg_onerow], 0, nrows * lcg_onerow);
671 1.1 jklos #else
672 1.1 jklos blkset(LCG_FB_ADDR + (startrow * lcg_onerow), (lcg_cols * lcg_font.fontwidth),
673 1.1 jklos (nrows * lcg_font.fontheight), (fillattr & LCG_BG_MASK) >> 4);
674 1.1 jklos #endif
675 1.1 jklos }
676 1.1 jklos
677 1.1 jklos static int
678 1.1 jklos lcg_allocattr(void *id, int fg, int bg, int flags, long *attrp)
679 1.1 jklos {
680 1.1 jklos long myattr;
681 1.1 jklos
682 1.1 jklos if (flags & WSATTR_WSCOLORS)
683 1.1 jklos myattr = (fg & LCG_FG_MASK) | ((bg << 4) & LCG_BG_MASK);
684 1.1 jklos else
685 1.1 jklos myattr = WSCOL_WHITE << 4; /* XXXX */
686 1.1 jklos if (flags & WSATTR_REVERSE)
687 1.1 jklos myattr |= LCG_ATTR_REVERSE;
688 1.1 jklos if (flags & WSATTR_UNDERLINE)
689 1.1 jklos myattr |= LCG_ATTR_UNDERLINE;
690 1.1 jklos *attrp = myattr;
691 1.1 jklos return 0;
692 1.1 jklos }
693 1.1 jklos
694 1.1 jklos static int
695 1.1 jklos lcg_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
696 1.1 jklos {
697 1.1 jklos struct wsdisplay_fbinfo *fb = (void *)data;
698 1.1 jklos int i;
699 1.1 jklos
700 1.1 jklos switch (cmd) {
701 1.1 jklos case WSDISPLAYIO_GTYPE:
702 1.1 jklos *(u_int *)data = WSDISPLAY_TYPE_LCG;
703 1.1 jklos break;
704 1.1 jklos
705 1.1 jklos case WSDISPLAYIO_GINFO:
706 1.1 jklos fb->height = lcg_ysize;
707 1.1 jklos fb->width = lcg_xsize;
708 1.1 jklos fb->depth = lcg_depth;
709 1.1 jklos fb->cmsize = 1 << lcg_depth;
710 1.1 jklos break;
711 1.1 jklos
712 1.2 jklos case WSDISPLAYIO_LINEBYTES:
713 1.2 jklos *(u_int *)data = lcg_xsize;
714 1.2 jklos break;
715 1.2 jklos
716 1.1 jklos case WSDISPLAYIO_GETCMAP:
717 1.1 jklos return lcg_get_cmap((struct wsdisplay_cmap *)data);
718 1.1 jklos
719 1.1 jklos case WSDISPLAYIO_PUTCMAP:
720 1.1 jklos return lcg_set_cmap((struct wsdisplay_cmap *)data);
721 1.1 jklos
722 1.1 jklos case WSDISPLAYIO_GMODE:
723 1.1 jklos return EPASSTHROUGH;
724 1.1 jklos
725 1.1 jklos case WSDISPLAYIO_SMODE:
726 1.1 jklos /* if setting WSDISPLAYIO_MODE_EMUL, restore console cmap, current screen */
727 1.1 jklos if (*(u_int *)data == WSDISPLAYIO_MODE_EMUL) {
728 1.1 jklos /* FIXME: if this is meant to reset palette LUT reload has to be triggered too */
729 1.1 jklos bzero(lutaddr, LCG_LUT_SIZE);
730 1.1 jklos for (i = 0; i < 8; ++i) {
731 1.1 jklos lcg_cmap.r[i] = lcg_default_cmap.r[i];
732 1.1 jklos lcg_cmap.g[i] = lcg_default_cmap.g[i];
733 1.1 jklos lcg_cmap.b[i] = lcg_default_cmap.b[i];
734 1.1 jklos lutaddr[i * 8 + 1] = i;
735 1.1 jklos lutaddr[i * 8 + 2] = 1;
736 1.1 jklos lutaddr[i * 8 + 3] = lcg_cmap.r[i] >> (lcg_depth & 7);
737 1.1 jklos lutaddr[i * 8 + 4] = 1;
738 1.1 jklos lutaddr[i * 8 + 5] = lcg_cmap.g[i] >> (lcg_depth & 7);
739 1.1 jklos lutaddr[i * 8 + 6] = 1;
740 1.1 jklos lutaddr[i * 8 + 7] = lcg_cmap.b[i] >> (lcg_depth & 7);
741 1.1 jklos }
742 1.1 jklos if (savescr != NULL)
743 1.1 jklos lcg_show_screen(NULL, savescr, 0, NULL, NULL);
744 1.1 jklos savescr = NULL;
745 1.1 jklos } else { /* WSDISPLAYIO_MODE_MAPPED */
746 1.1 jklos savescr = curscr;
747 1.1 jklos curscr = NULL;
748 1.1 jklos /* clear screen? */
749 1.1 jklos }
750 1.1 jklos
751 1.1 jklos return EPASSTHROUGH;
752 1.1 jklos #if 0
753 1.1 jklos case WSDISPLAYIO_SVIDEO:
754 1.1 jklos if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
755 1.1 jklos curcmd = curc;
756 1.1 jklos } else {
757 1.1 jklos curc = curcmd;
758 1.1 jklos curcmd &= ~(CUR_CMD_FOPA|CUR_CMD_ENPA);
759 1.1 jklos curcmd |= CUR_CMD_FOPB;
760 1.1 jklos }
761 1.1 jklos WRITECUR(CUR_CMD, curcmd);
762 1.1 jklos break;
763 1.1 jklos
764 1.1 jklos case WSDISPLAYIO_GVIDEO:
765 1.1 jklos *(u_int *)data = (curcmd & CUR_CMD_FOPB ?
766 1.1 jklos WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON);
767 1.1 jklos break;
768 1.1 jklos
769 1.1 jklos #endif
770 1.1 jklos default:
771 1.1 jklos return EPASSTHROUGH;
772 1.1 jklos }
773 1.1 jklos return 0;
774 1.1 jklos }
775 1.1 jklos
776 1.1 jklos static paddr_t
777 1.1 jklos lcg_mmap(void *v, void *vs, off_t offset, int prot)
778 1.1 jklos {
779 1.1 jklos if (offset >= lcg_fb_size || offset < 0)
780 1.1 jklos return -1;
781 1.1 jklos return (LCG_FB_ADDR + offset) >> PGSHIFT;
782 1.1 jklos }
783 1.1 jklos
784 1.1 jklos int
785 1.1 jklos lcg_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
786 1.1 jklos int *curxp, int *curyp, long *defattrp)
787 1.1 jklos {
788 1.1 jklos int i;
789 1.1 jklos struct lcg_screen *ss;
790 1.1 jklos
791 1.5 thorpej *cookiep = kmem_alloc(sizeof(struct lcg_screen), KM_SLEEP);
792 1.1 jklos bzero(*cookiep, sizeof(struct lcg_screen));
793 1.1 jklos *curxp = *curyp = 0;
794 1.1 jklos *defattrp = (LCG_BG_COLOR << 4) | LCG_FG_COLOR;
795 1.1 jklos ss = *cookiep;
796 1.1 jklos for (i = 0; i < lcg_cols * lcg_rows; ++i)
797 1.1 jklos ss->ss_image[i].attr = (LCG_BG_COLOR << 4) | LCG_FG_COLOR;
798 1.1 jklos return 0;
799 1.1 jklos }
800 1.1 jklos
801 1.1 jklos void
802 1.1 jklos lcg_free_screen(void *v, void *cookie)
803 1.1 jklos {
804 1.1 jklos }
805 1.1 jklos
806 1.1 jklos int
807 1.1 jklos lcg_show_screen(void *v, void *cookie, int waitok,
808 1.1 jklos void (*cb)(void *, int, int), void *cbarg)
809 1.1 jklos {
810 1.1 jklos struct lcg_screen *ss = cookie;
811 1.1 jklos int row, col, dot_fg, dot_bg, j, attr;
812 1.1 jklos #ifdef LCG_NO_ACCEL
813 1.1 jklos int iter, jter;
814 1.1 jklos unsigned char ch;
815 1.1 jklos #endif
816 1.1 jklos
817 1.1 jklos if (ss == curscr)
818 1.1 jklos return (0);
819 1.1 jklos #ifdef LCG_NO_ACCEL
820 1.1 jklos memset(lcgaddr, LCG_BG_COLOR, lcg_xsize * lcg_ysize);
821 1.1 jklos #endif
822 1.1 jklos
823 1.1 jklos for (row = 0; row < lcg_rows; row++)
824 1.1 jklos for (col = 0; col < lcg_cols; col++) {
825 1.1 jklos attr = ss->ss_image[row * lcg_cols + col].attr;
826 1.1 jklos if (attr & LCG_ATTR_REVERSE) {
827 1.1 jklos dot_fg = (attr & LCG_BG_MASK) >> 4;
828 1.1 jklos dot_bg = attr & LCG_FG_MASK;
829 1.1 jklos } else {
830 1.1 jklos dot_fg = attr & LCG_FG_MASK;
831 1.1 jklos dot_bg = (attr & LCG_BG_MASK) >> 4;
832 1.1 jklos }
833 1.1 jklos u_char c = ss->ss_image[row * lcg_cols + col].data;
834 1.1 jklos
835 1.1 jklos if (c < 32)
836 1.1 jklos c = 32;
837 1.1 jklos #ifndef LCG_NO_ACCEL
838 1.1 jklos renderchar(LCG_FONT_ADDR + (c * lcg_glyph_size),
839 1.1 jklos LCG_FB_ADDR + (row * lcg_onerow) + (col * lcg_font.fontwidth),
840 1.1 jklos lcg_font.fontwidth, lcg_font.fontheight, dot_fg, dot_bg);
841 1.1 jklos #else
842 1.1 jklos for (iter = 0; iter < lcg_font.fontheight; iter++) {
843 1.1 jklos ch = QFONT(c,iter);
844 1.1 jklos for (jter = 0; jter < lcg_font.fontwidth; jter++) {
845 1.1 jklos LCG_ADDR(row, col, iter, jter) = ((ch >> jter) & 1) ? dot_fg : dot_bg;
846 1.1 jklos }
847 1.1 jklos }
848 1.1 jklos #endif
849 1.1 jklos if (attr & LCG_ATTR_UNDERLINE)
850 1.1 jklos for (j = 0; j < lcg_font.fontwidth; j++)
851 1.1 jklos LCG_ADDR(row, col,
852 1.1 jklos lcg_font.fontheight - 1, j) = dot_fg;
853 1.1 jklos }
854 1.1 jklos
855 1.1 jklos cursor = &lcgaddr[(ss->ss_cury * lcg_onerow) +
856 1.1 jklos ((lcg_font.fontheight - 1) * lcg_xsize) +
857 1.1 jklos (ss->ss_curx * lcg_font.fontwidth)];
858 1.1 jklos cur_fg = ss->ss_cur_fg;
859 1.1 jklos cur_bg = ss->ss_cur_bg;
860 1.1 jklos
861 1.1 jklos curscr = ss;
862 1.1 jklos return (0);
863 1.1 jklos }
864 1.1 jklos
865 1.1 jklos static int
866 1.1 jklos lcg_get_cmap(struct wsdisplay_cmap *p)
867 1.1 jklos {
868 1.1 jklos u_int index = p->index, count = p->count;
869 1.1 jklos int error;
870 1.1 jklos
871 1.1 jklos if (index >= (1 << lcg_depth) || count > (1 << lcg_depth) - index)
872 1.1 jklos return (EINVAL);
873 1.1 jklos
874 1.1 jklos error = copyout(&lcg_cmap.r[index], p->red, count);
875 1.1 jklos if (error)
876 1.1 jklos return error;
877 1.1 jklos error = copyout(&lcg_cmap.g[index], p->green, count);
878 1.1 jklos if (error)
879 1.1 jklos return error;
880 1.1 jklos error = copyout(&lcg_cmap.b[index], p->blue, count);
881 1.1 jklos return error;
882 1.1 jklos }
883 1.1 jklos
884 1.1 jklos static int
885 1.1 jklos lcg_set_cmap(struct wsdisplay_cmap *p)
886 1.1 jklos {
887 1.1 jklos u_int index = p->index, count = p->count;
888 1.1 jklos int error, s;
889 1.1 jklos
890 1.1 jklos if (index >= (1 << lcg_depth) || count > (1 << lcg_depth) - index)
891 1.1 jklos return (EINVAL);
892 1.1 jklos
893 1.1 jklos error = copyin(p->red, &lcg_cmap.r[index], count);
894 1.1 jklos if (error)
895 1.1 jklos return error;
896 1.1 jklos error = copyin(p->green, &lcg_cmap.g[index], count);
897 1.1 jklos if (error)
898 1.1 jklos return error;
899 1.1 jklos error = copyin(p->blue, &lcg_cmap.b[index], count);
900 1.1 jklos if (error)
901 1.1 jklos return error;
902 1.1 jklos
903 1.1 jklos s = spltty();
904 1.1 jklos /* FIXME: if this is meant to set palette LUT reload has to be triggered too */
905 1.1 jklos while (count-- > 0) {
906 1.1 jklos lutaddr[index * 8 + 0] = 0;
907 1.1 jklos lutaddr[index * 8 + 1] = index;
908 1.1 jklos lutaddr[index * 8 + 2] = 1;
909 1.1 jklos lutaddr[index * 8 + 3] = lcg_cmap.r[index] >> (lcg_depth & 7);
910 1.1 jklos lutaddr[index * 8 + 4] = 1;
911 1.1 jklos lutaddr[index * 8 + 5] = lcg_cmap.g[index] >> (lcg_depth & 7);
912 1.1 jklos lutaddr[index * 8 + 6] = 1;
913 1.1 jklos lutaddr[index * 8 + 7] = lcg_cmap.b[index] >> (lcg_depth & 7);
914 1.1 jklos ++index;
915 1.1 jklos }
916 1.1 jklos splx(s);
917 1.1 jklos return (0);
918 1.1 jklos }
919 1.1 jklos
920 1.1 jklos cons_decl(lcg);
921 1.1 jklos
922 1.1 jklos void
923 1.1 jklos lcgcninit(struct consdev *cndev)
924 1.1 jklos {
925 1.1 jklos int i;
926 1.1 jklos /* Clear screen */
927 1.1 jklos memset(lcgaddr, LCG_BG_COLOR, lcg_xsize * lcg_ysize);
928 1.1 jklos
929 1.1 jklos curscr = &lcg_conscreen;
930 1.1 jklos for (i = 0; i < lcg_cols * lcg_rows; ++i)
931 1.1 jklos lcg_conscreen.ss_image[i].attr =
932 1.1 jklos (LCG_BG_COLOR << 4) | LCG_FG_COLOR;
933 1.1 jklos wsdisplay_cnattach(&lcg_stdscreen, &lcg_conscreen, 0, 0,
934 1.1 jklos (LCG_BG_COLOR << 4) | LCG_FG_COLOR);
935 1.1 jklos cn_tab->cn_pri = CN_INTERNAL;
936 1.1 jklos
937 1.1 jklos
938 1.1 jklos #if NDZKBD > 0
939 1.1 jklos dzkbd_cnattach(0); /* Connect keyboard and screen together */
940 1.1 jklos #endif
941 1.1 jklos }
942 1.1 jklos
943 1.1 jklos /*
944 1.1 jklos * Called very early to setup the glass tty as console.
945 1.1 jklos * Because it's called before the VM system is inited, virtual memory
946 1.1 jklos * for the framebuffer can be stolen directly without disturbing anything.
947 1.1 jklos */
948 1.1 jklos void
949 1.1 jklos lcgcnprobe(struct consdev *cndev)
950 1.1 jklos {
951 1.1 jklos extern const struct cdevsw wsdisplay_cdevsw;
952 1.1 jklos
953 1.1 jklos if ((vax_boardtype != VAX_BTYP_46) && (vax_boardtype != VAX_BTYP_48))
954 1.1 jklos return; /* Only for VS 4000/60 and VLC */
955 1.1 jklos
956 1.1 jklos if (vax_confdata & 0x100)
957 1.1 jklos return; /* Diagnostic console */
958 1.1 jklos
959 1.1 jklos lcg_init_common(NULL, NULL);
960 1.1 jklos
961 1.1 jklos /* Set up default LUT */
962 1.1 jklos
963 1.1 jklos cndev->cn_pri = CN_INTERNAL;
964 1.1 jklos cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw), 0);
965 1.1 jklos }
966 1.1 jklos
967 1.1 jklos void
968 1.1 jklos lcg_init_common(struct device *self, struct vsbus_attach_args *va)
969 1.1 jklos {
970 1.1 jklos u_int magic, *lcg_config;
971 1.1 jklos int i;
972 1.1 jklos extern vaddr_t virtual_avail;
973 1.1 jklos long video_conf;
974 1.1 jklos int cookie;
975 1.1 jklos struct wsdisplay_font *wf;
976 1.1 jklos
977 1.12 riastrad struct lcg_softc *sc = device_private(self);
978 1.1 jklos bus_dma_segment_t seg;
979 1.1 jklos int rseg, err;
980 1.1 jklos void *fifo_mem_vaddr;
981 1.1 jklos #ifndef LCG_NO_ACCEL
982 1.1 jklos u_char line;
983 1.1 jklos u_int ch, temp;
984 1.1 jklos #endif
985 1.1 jklos
986 1.1 jklos if (regaddr != NULL)
987 1.1 jklos return;
988 1.1 jklos
989 1.1 jklos /* map LCG registers first */
990 1.1 jklos if (self != NULL) {
991 1.1 jklos regaddr = (long*)vax_map_physmem(LCG_REG_ADDR, (LCG_REG_SIZE/VAX_NBPG));
992 1.1 jklos if (regaddr == 0) {
993 1.8 riastrad device_printf(self,
994 1.8 riastrad "Couldn't allocate register memory.\n");
995 1.1 jklos return;
996 1.1 jklos }
997 1.1 jklos } else {
998 1.1 jklos regaddr = (long*)virtual_avail;
999 1.1 jklos virtual_avail += LCG_REG_SIZE;
1000 1.1 jklos ioaccess((vaddr_t)regaddr, LCG_REG_ADDR, (LCG_REG_SIZE/VAX_NBPG));
1001 1.1 jklos }
1002 1.1 jklos
1003 1.1 jklos /*
1004 1.1 jklos * v = *0x200f0010 & VLC ? 0x07 : 0xf0;
1005 1.1 jklos * switch(v) {
1006 1.1 jklos * 0x05: 1280x1024
1007 1.1 jklos * 0x06: conf & 0x80 ? 1024x768 : 640x480
1008 1.1 jklos * 0x07: conf & 0x80 ? 1024x768 ? 1024x864
1009 1.1 jklos * 0x20: 1024x864
1010 1.1 jklos * 0x40: 1024x768
1011 1.1 jklos * 0x60: 1024x864
1012 1.1 jklos * 0x80: 1280x1024 4BPN
1013 1.1 jklos * 0x90: 1280x1024 8BPN
1014 1.1 jklos * 0xb0: 1280x1024 8BPN 2HD
1015 1.1 jklos */
1016 1.1 jklos if (self != NULL) {
1017 1.1 jklos lcg_config = (u_int *)vax_map_physmem(LCG_CONFIG, 1);
1018 1.1 jklos } else {
1019 1.1 jklos lcg_config = (u_int *)virtual_avail;
1020 1.1 jklos ioaccess((vaddr_t)lcg_config, LCG_CONFIG, 1);
1021 1.1 jklos }
1022 1.1 jklos magic = *lcg_config & (vax_boardtype == VAX_BTYP_46 ? 0xf0 : 0x07);
1023 1.1 jklos if (self != NULL) {
1024 1.1 jklos vax_unmap_physmem((vaddr_t)lcg_config, 1);
1025 1.1 jklos } else {
1026 1.1 jklos iounaccess((vaddr_t)lcg_config, 1);
1027 1.1 jklos }
1028 1.1 jklos lcg_depth = 8;
1029 1.1 jklos switch(magic) {
1030 1.1 jklos case 0x80: /* KA46 HR 1280x1024 4BPLN */
1031 1.1 jklos lcg_depth = 4;
1032 1.1 jklos case 0x05: /* KA48 HR 1280x1024 8BPLN */
1033 1.1 jklos case 0x90: /* KA46 HR 1280x1024 8BPLN */
1034 1.1 jklos case 0xb0: /* KA46 HR 1280x1024 8BPLN 2HD */
1035 1.1 jklos lcg_xsize = 1280;
1036 1.1 jklos lcg_ysize = 1024;
1037 1.1 jklos break;
1038 1.1 jklos case 0x06: /* KA48 1024x768 or 640x480 */
1039 1.1 jklos if (vax_confdata & 0x80) {
1040 1.1 jklos lcg_xsize = 1024;
1041 1.1 jklos lcg_ysize = 768;
1042 1.1 jklos } else {
1043 1.1 jklos lcg_xsize = 640;
1044 1.1 jklos lcg_ysize = 480;
1045 1.1 jklos }
1046 1.1 jklos break;
1047 1.1 jklos case 0x07: /* KA48 1024x768 or 1024x864 */
1048 1.1 jklos lcg_xsize = 1024;
1049 1.1 jklos lcg_ysize = (vax_confdata & 0x80) ? 768 : 864;
1050 1.1 jklos break;
1051 1.1 jklos case 0x20: /* KA46 1024x864 */
1052 1.1 jklos case 0x60: /* KA46 1024x864 */
1053 1.1 jklos lcg_xsize = 1024;
1054 1.1 jklos lcg_ysize = 864;
1055 1.1 jklos break;
1056 1.1 jklos case 0x40: /* KA46 1024x768 */
1057 1.1 jklos lcg_xsize = 1024;
1058 1.1 jklos lcg_ysize = 768;
1059 1.1 jklos break;
1060 1.1 jklos default:
1061 1.1 jklos panic("LCG model not supported");
1062 1.1 jklos }
1063 1.1 jklos if (self != NULL)
1064 1.8 riastrad aprint_normal_dev(self,
1065 1.8 riastrad "framebuffer size %dx%d, depth %d (magic 0x%x)\n",
1066 1.8 riastrad lcg_xsize, lcg_ysize, lcg_depth, magic);
1067 1.1 jklos
1068 1.1 jklos wsfont_init();
1069 1.1 jklos cookie = wsfont_find(NULL, 12, 22, 0, WSDISPLAY_FONTORDER_R2L,
1070 1.1 jklos WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP);
1071 1.1 jklos if (cookie == -1)
1072 1.1 jklos cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L, 0,
1073 1.1 jklos WSFONT_FIND_BITMAP);
1074 1.1 jklos if (cookie == -1)
1075 1.1 jklos cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L,
1076 1.1 jklos WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP);
1077 1.1 jklos if (cookie == -1 || wsfont_lock(cookie, &wf))
1078 1.1 jklos panic("lcg_common_init: can't load console font");
1079 1.1 jklos lcg_font = *wf;
1080 1.1 jklos lcg_cols = lcg_xsize / lcg_font.fontwidth;
1081 1.1 jklos lcg_rows = lcg_ysize / lcg_font.fontheight;
1082 1.1 jklos if (self != NULL) {
1083 1.8 riastrad aprint_normal_dev(self, "using font %s (%dx%d), ",
1084 1.8 riastrad lcg_font.name,
1085 1.8 riastrad lcg_font.fontwidth, lcg_font.fontheight);
1086 1.1 jklos aprint_normal("console size: %dx%d\n", lcg_cols, lcg_rows);
1087 1.1 jklos }
1088 1.1 jklos lcg_onerow = lcg_xsize * lcg_font.fontheight;
1089 1.1 jklos lcg_fb_size = lcg_xsize * lcg_ysize;
1090 1.1 jklos lcg_stdscreen.ncols = lcg_cols;
1091 1.1 jklos lcg_stdscreen.nrows = lcg_rows;
1092 1.1 jklos lcg_stdscreen.fontwidth = lcg_font.fontwidth;
1093 1.1 jklos lcg_stdscreen.fontheight = lcg_font.fontheight;
1094 1.1 jklos lcg_glyph_size = lcg_font.stride * lcg_font.fontheight;
1095 1.1 jklos snprintf(lcg_stdscreen_name, sizeof(lcg_stdscreen_name), "%dx%d", lcg_cols, lcg_rows);
1096 1.1 jklos qf = lcg_font.data;
1097 1.1 jklos qf2 = (u_short *)lcg_font.data;
1098 1.1 jklos
1099 1.1 jklos if (self != NULL) {
1100 1.1 jklos lcgaddr = (void *)vax_map_physmem(va->va_paddr,
1101 1.1 jklos ((lcg_fb_size + LCG_FONT_STORAGE_SIZE)/VAX_NBPG));
1102 1.1 jklos if (lcgaddr == 0) {
1103 1.8 riastrad device_printf(self,
1104 1.8 riastrad "unable to allocate framebuffer memory.\n");
1105 1.1 jklos return;
1106 1.1 jklos }
1107 1.1 jklos #ifndef LCG_NO_ACCEL
1108 1.1 jklos fontaddr = lcgaddr + lcg_fb_size;
1109 1.1 jklos
1110 1.1 jklos /* copy font bitmaps */
1111 1.1 jklos for (ch = 0; ch < 256; ch++)
1112 1.1 jklos for (line = 0; line < lcg_font.fontheight; line++) {
1113 1.1 jklos temp = QFONT(ch, line);
1114 1.1 jklos if (lcg_font.stride == 1)
1115 1.1 jklos fontaddr[(ch * lcg_font.fontheight) + line] = temp;
1116 1.1 jklos else {
1117 1.1 jklos /* stride == 2 */
1118 1.1 jklos fontaddr[(ch * lcg_font.stride * lcg_font.fontheight) + line] = temp & 0xff;
1119 1.1 jklos fontaddr[(ch * lcg_font.stride * lcg_font.fontheight) + line + 1] = (temp >> 16) & 0xff;
1120 1.1 jklos }
1121 1.1 jklos }
1122 1.1 jklos #endif
1123 1.1 jklos
1124 1.1 jklos lutaddr = (void *)vax_map_physmem(LCG_LUT_ADDR, (LCG_LUT_SIZE/VAX_NBPG));
1125 1.1 jklos if (lutaddr == 0) {
1126 1.8 riastrad device_printf(self,
1127 1.8 riastrad "unable to allocate LUT memory.\n");
1128 1.1 jklos return;
1129 1.1 jklos }
1130 1.1 jklos fifoaddr = (long*)vax_map_physmem(LCG_FIFO_WIN_ADDR, (LCG_FIFO_WIN_SIZE/VAX_NBPG));
1131 1.1 jklos if (regaddr == 0) {
1132 1.8 riastrad device_printf(self, "unable to map FIFO window\n");
1133 1.1 jklos return;
1134 1.1 jklos }
1135 1.1 jklos
1136 1.1 jklos /* allocate contiguous physical memory block for FIFO */
1137 1.1 jklos err = bus_dmamem_alloc(va->va_dmat, LCG_FIFO_SIZE,
1138 1.1 jklos LCG_FIFO_ALIGN, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT);
1139 1.1 jklos if (err) {
1140 1.8 riastrad device_printf(self,
1141 1.8 riastrad "unable to allocate FIFO memory block, err = %d\n",
1142 1.8 riastrad err);
1143 1.1 jklos return;
1144 1.1 jklos }
1145 1.1 jklos
1146 1.1 jklos err = bus_dmamem_map(va->va_dmat, &seg, rseg, LCG_FIFO_SIZE,
1147 1.1 jklos &fifo_mem_vaddr, BUS_DMA_NOWAIT);
1148 1.1 jklos if (err) {
1149 1.8 riastrad device_printf(self,
1150 1.8 riastrad "unable to map FIFO memory block, err = %d\n",
1151 1.8 riastrad err);
1152 1.1 jklos bus_dmamem_free(va->va_dmat, &seg, rseg);
1153 1.1 jklos return;
1154 1.1 jklos }
1155 1.1 jklos
1156 1.1 jklos err = bus_dmamap_create(va->va_dmat, LCG_FIFO_SIZE, rseg,
1157 1.1 jklos LCG_FIFO_SIZE, 0, BUS_DMA_NOWAIT, &sc->sc_dm);
1158 1.1 jklos if (err) {
1159 1.8 riastrad device_printf(self,
1160 1.8 riastrad "unable to create DMA map, err = %d\n",
1161 1.8 riastrad err);
1162 1.1 jklos bus_dmamem_unmap(va->va_dmat, fifo_mem_vaddr, LCG_FIFO_SIZE);
1163 1.1 jklos bus_dmamem_free(va->va_dmat, &seg, rseg);
1164 1.1 jklos return;
1165 1.1 jklos }
1166 1.1 jklos
1167 1.1 jklos err = bus_dmamap_load(va->va_dmat, sc->sc_dm, fifo_mem_vaddr,
1168 1.1 jklos LCG_FIFO_SIZE, NULL, BUS_DMA_NOWAIT);
1169 1.1 jklos if (err) {
1170 1.8 riastrad device_printf(self,
1171 1.8 riastrad "unable to load DMA map, err = %d\n",
1172 1.8 riastrad err);
1173 1.1 jklos bus_dmamap_destroy(va->va_dmat, sc->sc_dm);
1174 1.1 jklos bus_dmamem_unmap(va->va_dmat, fifo_mem_vaddr, LCG_FIFO_SIZE);
1175 1.1 jklos bus_dmamem_free(va->va_dmat, &seg, rseg);
1176 1.1 jklos return;
1177 1.1 jklos }
1178 1.1 jklos
1179 1.1 jklos /* initialize LCG hardware */
1180 1.1 jklos LCG_REG(LCG_REG_GRAPHICS_CONTROL) = 0xd8000000; /* gfx reset, FIFO and AG enable */
1181 1.1 jklos // LCG_REG(LCG_REG_WRITE_PROTECT_LOW_HIGH) = (((LCG_FB_ADDR + lcg_fb_size) & 0xffff0000) | (LCG_FB_ADDR >> 16));
1182 1.1 jklos LCG_REG(LCG_REG_WRITE_PROTECT_LOW_HIGH) = 0xffff0000;
1183 1.1 jklos LCG_REG(LCG_REG_FIFO_BASE) = sc->sc_dm->dm_segs[0].ds_addr;
1184 1.1 jklos LCG_REG(LCG_REG_FIFO_BASE2) = sc->sc_dm->dm_segs[0].ds_addr;
1185 1.1 jklos LCG_REG(LCG_REG_FIFO_MASKS) = 0xffff;
1186 1.1 jklos LCG_REG(LCG_REG_FIFO_SAVE_HEAD_OFFSET) = sc->sc_dm->dm_segs[0].ds_addr;
1187 1.1 jklos // LCG_REG(LCG_REG_GRAPHICS_INT_STATUS) = 0;
1188 1.1 jklos // LCG_REG(LCG_REG_GRAPHICS_CONTROL) = 0x50000000; /* FIFO and AG enable */
1189 1.1 jklos LCG_REG(LCG_REG_GRAPHICS_INT_STATUS) = 0xffffffff;
1190 1.1 jklos LCG_REG(LCG_REG_GRAPHICS_INT_SET_ENABLE) = 0;
1191 1.1 jklos LCG_REG(LCG_REG_GRAPHICS_INT_CLR_ENABLE) = 0xffffffff;
1192 1.1 jklos LCG_REG(LCG_REG_LCG_GO) = 3; /* FIFO and AG go */
1193 1.1 jklos // LCG_REG(LCG_REG_BREAKPT_ADDRESS) = 0x2fffffff;
1194 1.1 jklos
1195 1.1 jklos } else {
1196 1.1 jklos lcgaddr = (void *)virtual_avail;
1197 1.1 jklos virtual_avail += lcg_fb_size + LCG_FONT_STORAGE_SIZE;
1198 1.1 jklos ioaccess((vaddr_t)lcgaddr, LCG_FB_ADDR, (lcg_fb_size/VAX_NBPG));
1199 1.1 jklos
1200 1.1 jklos lutaddr = (void *)virtual_avail;
1201 1.1 jklos virtual_avail += LCG_LUT_SIZE;
1202 1.1 jklos ioaccess((vaddr_t)lutaddr, LCG_LUT_ADDR, (LCG_LUT_SIZE/VAX_NBPG));
1203 1.1 jklos
1204 1.1 jklos fifoaddr = (long*)virtual_avail;
1205 1.1 jklos virtual_avail += LCG_FIFO_WIN_SIZE;
1206 1.1 jklos ioaccess((vaddr_t)fifoaddr, LCG_FIFO_WIN_ADDR, (LCG_FIFO_WIN_SIZE/VAX_NBPG));
1207 1.1 jklos }
1208 1.1 jklos
1209 1.1 jklos bzero(lutaddr, LCG_LUT_SIZE);
1210 1.1 jklos for (i = 0; i < 8; ++i) {
1211 1.1 jklos lcg_cmap.r[i] = lcg_default_cmap.r[i];
1212 1.1 jklos lcg_cmap.g[i] = lcg_default_cmap.g[i];
1213 1.1 jklos lcg_cmap.b[i] = lcg_default_cmap.b[i];
1214 1.1 jklos lutaddr[i * 8 + 1] = i;
1215 1.1 jklos lutaddr[i * 8 + 2] = 1;
1216 1.1 jklos lutaddr[i * 8 + 3] = lcg_cmap.r[i] >> (lcg_depth & 7);
1217 1.1 jklos lutaddr[i * 8 + 4] = 1;
1218 1.1 jklos lutaddr[i * 8 + 5] = lcg_cmap.g[i] >> (lcg_depth & 7);
1219 1.1 jklos lutaddr[i * 8 + 6] = 1;
1220 1.1 jklos lutaddr[i * 8 + 7] = lcg_cmap.b[i] >> (lcg_depth & 7);
1221 1.1 jklos }
1222 1.1 jklos
1223 1.1 jklos /*
1224 1.1 jklos * 0xf100165b 4000/60
1225 1.1 jklos * 1111 0001 0000 0000 0001 0110 0101 1011
1226 1.1 jklos * vvvv vvvv vvvv vvvv vvvv vvvv vvvv vvvv
1227 1.1 jklos * 3322 2222 2222 1111 1111 11
1228 1.1 jklos * 1098 7654 3210 9876 5432 1098 7654 3210
1229 1.1 jklos *
1230 1.1 jklos * 0xf1001d7b 4000/VLC
1231 1.1 jklos * 1111 0001 0000 0000 0001 1101 0111 1011
1232 1.1 jklos * vvvv vvvv vvvv vvvv vvvv vvvv vvvv vvvv
1233 1.1 jklos * 3322 2222 2222 1111 1111 11
1234 1.1 jklos * 1098 7654 3210 9876 5432 1098 7654 3210
1235 1.1 jklos *
1236 1.1 jklos * 31-30 11 Vertical state
1237 1.1 jklos * 29-38 11 Horizontal state
1238 1.1 jklos * 27-26 00
1239 1.1 jklos * 25 0 console LUT select
1240 1.1 jklos * 24 1 control LUT select
1241 1.1 jklos * 23 0
1242 1.1 jklos * 22 0 cursor active
1243 1.1 jklos * 21-16 000000
1244 1.1 jklos * 15 0 video subsystem reset
1245 1.1 jklos * 14 0
1246 1.1 jklos * 13 0 LUT load size 2KB
1247 1.1 jklos * 12 1 enable H sync
1248 1.1 jklos * 11 0 Full LUT load 1
1249 1.1 jklos * 10 1 video clock select
1250 1.1 jklos * 9- 8 10 memory refresh rate 01
1251 1.1 jklos * 7- 6 01 video refresh rate
1252 1.1 jklos * 5 0 load select 1
1253 1.1 jklos * 4 1 read cursor output
1254 1.1 jklos * 3 1 LUT load enable
1255 1.1 jklos * 2 0 cursor enable
1256 1.1 jklos * 1 1 video enable
1257 1.1 jklos * 0 1 refresh clock enable
1258 1.1 jklos */
1259 1.10 andvar /* prepare video_config reg for LUT reload */
1260 1.1 jklos video_conf
1261 1.1 jklos = (3 << 30) /* vertical state */
1262 1.1 jklos | (3 << 28) /* horizontal state */
1263 1.1 jklos | (0 << 26) /* unused */
1264 1.1 jklos | (0 << 25) /* console LUT select */
1265 1.1 jklos | (0 << 24) /* control LUT select */
1266 1.1 jklos | (0 << 23) /* unused */
1267 1.1 jklos | (0 << 22) /* cursor active */
1268 1.1 jklos | (0 << 16) /* current cursor scanline showing */
1269 1.1 jklos | (0 << 15) /* video subsystem reset */
1270 1.1 jklos | (0 << 14) /* unused */
1271 1.1 jklos | (1 << 13) /* LUT load size 2 KB */
1272 1.1 jklos | (1 << 12) /* enable horizontal sync */
1273 1.1 jklos | (1 << 10) /* video clock select */
1274 1.1 jklos | (1 << 6) /* video refresh select */
1275 1.10 andvar | (1 << 4) /* read cursor output */
1276 1.1 jklos | (1 << 3) /* LUT load enable */
1277 1.1 jklos | (0 << 2) /* cursor enable */
1278 1.1 jklos | (1 << 1) /* video enable */
1279 1.1 jklos | (1 << 0); /* refresh clock enable */
1280 1.1 jklos /* FIXME needs updating for all supported models */
1281 1.1 jklos if (lcg_xsize == 1280) { /* 4000/60 HR 4PLN */
1282 1.1 jklos video_conf |= (0 << 11); /* split LUT load */
1283 1.1 jklos video_conf |= (2 << 8); /* memory refresh select */
1284 1.1 jklos video_conf |= (0 << 5); /* split shift register load */
1285 1.1 jklos } else { /* 4000/VLC LR 8PLN */
1286 1.1 jklos video_conf |= (1 << 11); /* Full LUT load */
1287 1.1 jklos video_conf |= (1 << 8); /* memory refresh select */
1288 1.1 jklos video_conf |= (1 << 5); /* split shift register load */
1289 1.1 jklos }
1290 1.1 jklos
1291 1.1 jklos LCG_REG(LCG_REG_VIDEO_CONFIG) = video_conf;
1292 1.1 jklos /* vital !!! */
1293 1.1 jklos LCG_REG(LCG_REG_LUT_CONSOLE_SEL) = 1;
1294 1.1 jklos LCG_REG(LCG_REG_LUT_COLOR_BASE_W) = LCG_LUT_OFFSET;
1295 1.1 jklos
1296 1.1 jklos delay(1000);
1297 1.1 jklos LCG_REG(LCG_REG_LUT_CONSOLE_SEL) = 0;
1298 1.1 jklos
1299 1.1 jklos #ifdef LCG_DEBUG
1300 1.1 jklos if (self != NULL)
1301 1.8 riastrad device_printf(self, "video config register set 0x%08lx\n",
1302 1.8 riastrad video_conf);
1303 1.1 jklos #endif
1304 1.1 jklos }
1305