hd64461video.c revision 1.18 1 /* $NetBSD: hd64461video.c,v 1.18 2003/07/15 02:29:37 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: hd64461video.c,v 1.18 2003/07/15 02:29:37 lukem Exp $");
41
42 #include "debug_hpcsh.h"
43 // #define HD64461VIDEO_HWACCEL
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/malloc.h>
49
50 #include <sys/conf.h> /* cdev_decl */
51 #include <dev/cons.h> /* consdev */
52
53 /* ioctl */
54 #include <sys/ioctl.h>
55 #include <sys/buf.h>
56 #include <uvm/uvm_extern.h>
57
58 #include <machine/bus.h>
59 #include <machine/intr.h>
60
61 #include <hpcsh/dev/hd64461/hd64461var.h>
62 #include <hpcsh/dev/hd64461/hd64461reg.h>
63 #include <hpcsh/dev/hd64461/hd64461videoreg.h>
64
65 #include <dev/wscons/wsdisplayvar.h>
66 #include <dev/rasops/rasops.h>
67
68 #include <dev/wscons/wsconsio.h>
69 #include <dev/hpc/hpcfbvar.h>
70 #include <dev/hpc/hpcfbio.h>
71 #include <dev/hpc/video_subr.h>
72
73 #include <machine/bootinfo.h>
74
75 #ifdef HD64461VIDEO_DEBUG
76 #define DPRINTF_ENABLE
77 #define DPRINTF_DEBUG hd64461video_debug
78 #endif
79 #include <machine/debug.h>
80
81 struct hd64461video_chip;
82 struct hd64461video_font {
83 struct wsdisplay_font wsfont;
84 int c, cw, cstep;
85 int loaded;
86 };
87
88 struct hd64461video_softc {
89 struct device sc_dev;
90 enum hd64461_module_id sc_module_id;
91 struct hd64461video_chip *sc_vc;
92
93 struct hd64461video_font sc_font;
94 };
95
96 STATIC struct hd64461video_chip {
97 struct video_chip vc;
98 enum hd64461video_display_mode {
99 LCD256_C,
100 LCD64K_C,
101 LCD64_MONO,
102 LCD16_MONO,
103 LCD4_MONO,
104 LCD2_MONO,
105 CRT256_C,
106 LCDCRT
107 };
108 enum hd64461video_display_mode mode;
109 struct hpcfb_dspconf hd;
110 struct hpcfb_fbconf hf;
111 u_int8_t *off_screen_addr;
112 size_t off_screen_size;
113
114 int console;
115 } hd64461video_chip;
116
117 void hd64461video_cnprobe(struct consdev *);
118 void hd64461video_cninit(struct consdev *);
119
120 STATIC int hd64461video_match(struct device *, struct cfdata *, void *);
121 STATIC void hd64461video_attach(struct device *, struct device *, void *);
122
123 STATIC void hd64461video_setup_hpcfbif(struct hd64461video_chip *);
124 STATIC void hd64461video_update_videochip_status(struct hd64461video_chip *);
125 STATIC size_t hd64461video_frame_buffer_size(struct hd64461video_chip *);
126 STATIC void hd64461video_hwaccel_init(struct hd64461video_chip *);
127
128 STATIC void hd64461video_set_clut(struct hd64461video_chip *, int, int,
129 u_int8_t *, u_int8_t *, u_int8_t *);
130 STATIC void hd64461video_get_clut(struct hd64461video_chip *, int, int,
131 u_int8_t *, u_int8_t *, u_int8_t *);
132 #if notyet
133 STATIC void hd64461video_set_display_mode(struct hd64461video_chip *);
134 STATIC void hd64461video_set_display_mode_lcdc(struct hd64461video_chip *);
135 STATIC void hd64461video_set_display_mode_crtc(struct hd64461video_chip *);
136 #endif
137
138 #ifdef HD64461VIDEO_DEBUG
139 STATIC void hd64461video_info(struct hd64461video_softc *);
140 STATIC void hd64461video_dump(void) __attribute__((__unused__));
141 #endif
142
143 CFATTACH_DECL(hd64461video, sizeof(struct hd64461video_softc),
144 hd64461video_match, hd64461video_attach, NULL, NULL);
145
146 int hd64461video_ioctl(void *, u_long, caddr_t, int, struct proc *);
147 paddr_t hd64461video_mmap(void *, off_t, int);
148 void hd64461video_cursor(void *, int, int, int, int, int);
149 void hd64461video_bitblit(void *, int, int, int, int, int, int);
150 void hd64461video_erase(void *, int, int, int, int, int);
151 void hd64461video_putchar(void *, int, int, struct wsdisplay_font *, int, int,
152 u_int, int);
153 void hd64461video_setclut(void *, struct rasops_info *);
154 void hd64461video_font(void *, struct wsdisplay_font *);
155 void hd64461video_iodone(void *);
156
157 struct hpcfb_accessops hd64461video_ha = {
158 .ioctl = hd64461video_ioctl,
159 .mmap = hd64461video_mmap,
160 #ifdef HD64461VIDEO_HWACCEL
161 .cursor = hd64461video_cursor,
162 .bitblit= hd64461video_bitblit,
163 .erase = hd64461video_erase,
164 .putchar= hd64461video_putchar,
165 .setclut= hd64461video_setclut,
166 .font = hd64461video_font,
167 .iodone = hd64461video_iodone
168 #endif /* HD64461VIDEO_HWACCEL */
169 };
170
171 /* font */
172 STATIC void hd64461video_font_load_16bpp(u_int16_t *, u_int8_t *, int, int, int);
173 STATIC void hd64461video_font_load_8bpp(u_int8_t *, u_int8_t *, int, int, int);
174 STATIC void hd64461video_font_set_attr(struct hd64461video_softc *,
175 struct wsdisplay_font *);
176 STATIC void hd64461video_font_load(struct hd64461video_softc *);
177 STATIC vaddr_t hd64461video_font_start_addr(struct hd64461video_softc *, int);
178
179 int
180 hd64461video_match(struct device *parent, struct cfdata *cf, void *aux)
181 {
182 struct hd64461_attach_args *ha = aux;
183
184 return (ha->ha_module_id == HD64461_MODULE_VIDEO);
185 }
186
187 void
188 hd64461video_attach(struct device *parent, struct device *self, void *aux)
189 {
190 struct hd64461_attach_args *ha = aux;
191 struct hd64461video_softc *sc = (struct hd64461video_softc *)self;
192 struct hpcfb_attach_args hfa;
193 struct video_chip *vc = &hd64461video_chip.vc;
194 char pbuf[9];
195 size_t fbsize, on_screen_size;
196
197 sc->sc_module_id = ha->ha_module_id;
198 sc->sc_vc = &hd64461video_chip;
199 printf(": ");
200
201 /* detect frame buffer size */
202 fbsize = hd64461video_frame_buffer_size(&hd64461video_chip);
203 format_bytes(pbuf, sizeof(pbuf), fbsize);
204 printf("frame buffer = %s ", pbuf);
205
206 /* update chip status */
207 hd64461video_update_videochip_status(&hd64461video_chip);
208 // hd64461video_set_display_mode(&hd64461video_chip);
209
210 if (hd64461video_chip.console)
211 printf(", console");
212
213 printf("\n");
214 #ifdef HD64461VIDEO_DEBUG
215 hd64461video_info(sc);
216 hd64461video_dump();
217 #endif
218
219
220 /* setup hpcfb interface */
221 hd64461video_setup_hpcfbif(&hd64461video_chip);
222
223 /* setup off-screen buffer */
224 on_screen_size = (vc->vc_fbwidth * vc->vc_fbheight * vc->vc_fbdepth) /
225 NBBY;
226 hd64461video_chip.off_screen_addr = (u_int8_t *)vc->vc_fbvaddr +
227 on_screen_size;
228 hd64461video_chip.off_screen_size = fbsize - on_screen_size;
229 /* clean up off-screen area */
230 {
231 u_int8_t *p = hd64461video_chip.off_screen_addr;
232 u_int8_t *end = p + hd64461video_chip.off_screen_size;
233 while (p < end)
234 *p++ = 0xff;
235 }
236
237 /* initialize hardware acceralation */
238 hd64461video_hwaccel_init(&hd64461video_chip);
239
240 /* register interface to hpcfb */
241 hfa.ha_console = hd64461video_chip.console;
242 hfa.ha_accessops = &hd64461video_ha;
243 hfa.ha_accessctx = sc;
244 hfa.ha_curfbconf = 0;
245 hfa.ha_nfbconf = 1;
246 hfa.ha_fbconflist = &hd64461video_chip.hf;
247 hfa.ha_curdspconf = 0;
248 hfa.ha_ndspconf = 1;
249 hfa.ha_dspconflist = &hd64461video_chip.hd;
250
251 config_found(self, &hfa, hpcfbprint);
252 }
253
254 /* console support */
255 void
256 hd64461video_cninit(struct consdev *cndev)
257 {
258 hd64461video_chip.console = 1;
259 hd64461video_chip.vc.vc_reverse = video_reverse_color();
260
261 hd64461video_update_videochip_status(&hd64461video_chip);
262 hd64461video_setup_hpcfbif(&hd64461video_chip);
263 hpcfb_cnattach(&hd64461video_chip.hf);
264
265 cn_tab->cn_pri = CN_INTERNAL;
266 }
267
268 void
269 hd64461video_cnprobe(struct consdev *cndev)
270 {
271 #if NWSDISPLAY > 0
272 extern const struct cdevsw wsdisplay_cdevsw;
273 int maj, unit;
274 #endif
275 cndev->cn_dev = NODEV;
276 cndev->cn_pri = CN_NORMAL;
277
278 #if NWSDISPLAY > 0
279 unit = 0;
280 maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
281
282 if (maj != -1) {
283 cndev->cn_pri = CN_INTERNAL;
284 cndev->cn_dev = makedev(maj, unit);
285 }
286 #endif /* NWSDISPLAY > 0 */
287 }
288
289 /* hpcfb support */
290 void
291 hd64461video_setup_hpcfbif(struct hd64461video_chip *hvc)
292 {
293 struct video_chip *vc = &hvc->vc;
294 struct hpcfb_fbconf *fb = &hvc->hf;
295 vaddr_t fbvaddr = vc->vc_fbvaddr;
296 int height = vc->vc_fbheight;
297 int width = vc->vc_fbwidth;
298 int depth = vc->vc_fbdepth;
299
300 memset(fb, 0, sizeof(struct hpcfb_fbconf));
301
302 fb->hf_conf_index = 0; /* configuration index */
303 fb->hf_nconfs = 1; /* how many configurations */
304 strncpy(fb->hf_name, "HD64461 video module", HPCFB_MAXNAMELEN);
305
306 /* frame buffer name */
307 strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN);
308
309 /* configuration name */
310 fb->hf_height = height;
311 fb->hf_width = width;
312 fb->hf_baseaddr = (u_long)fbvaddr;
313 fb->hf_offset = (u_long)fbvaddr -
314 sh3_ptob(sh3_btop(fbvaddr));
315
316 /* frame buffer start offset */
317 fb->hf_bytes_per_line = (width * depth) / NBBY;
318 fb->hf_nplanes = 1;
319 fb->hf_bytes_per_plane = height * fb->hf_bytes_per_line;
320
321 fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
322 fb->hf_access_flags |= HPCFB_ACCESS_WORD;
323 fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
324 if (vc->vc_reverse)
325 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
326
327 switch (depth) {
328 default:
329 panic("%s: not supported color depth", __FUNCTION__);
330 /* NOTREACHED */
331 case 16:
332 fb->hf_class = HPCFB_CLASS_RGBCOLOR;
333 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
334 fb->hf_pack_width = 16;
335 fb->hf_pixels_per_pack = 1;
336 fb->hf_pixel_width = 16;
337
338 fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
339 /* reserved for future use */
340 fb->hf_u.hf_rgb.hf_flags = 0;
341
342 fb->hf_u.hf_rgb.hf_red_width = 5;
343 fb->hf_u.hf_rgb.hf_red_shift = 11;
344 fb->hf_u.hf_rgb.hf_green_width = 6;
345 fb->hf_u.hf_rgb.hf_green_shift = 5;
346 fb->hf_u.hf_rgb.hf_blue_width = 5;
347 fb->hf_u.hf_rgb.hf_blue_shift = 0;
348 fb->hf_u.hf_rgb.hf_alpha_width = 0;
349 fb->hf_u.hf_rgb.hf_alpha_shift = 0;
350 break;
351
352 case 8:
353 fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
354 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
355 fb->hf_pack_width = 8;
356 fb->hf_pixels_per_pack = 1;
357 fb->hf_pixel_width = 8;
358 fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
359 /* reserved for future use */
360 fb->hf_u.hf_indexed.hf_flags = 0;
361 break;
362 }
363 }
364
365 void
366 hd64461video_hwaccel_init(struct hd64461video_chip *hvc)
367 {
368 u_int16_t r;
369
370 r = HD64461_LCDGRCFGR_ACCRESET;
371 switch (hvc->vc.vc_fbdepth) {
372 default:
373 panic("no bitblit acceralation.");
374 case 16:
375 break;
376 case 8:
377 r |= HD64461_LCDGRCFGR_COLORDEPTH_8BPP;
378 break;
379 }
380 hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
381
382 while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
383 HD64461_LCDGRCFGR_ACCSTATUS) != 0)
384 /* busy loop */;
385 r &= ~HD64461_LCDGRCFGR_ACCRESET;
386 hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
387
388 while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
389 HD64461_LCDGRCFGR_ACCSTATUS) != 0)
390 /* busy loop */;
391
392 hd64461_reg_write_2(HD64461_LCDGRDOR_REG16,
393 (hvc->vc.vc_fbwidth - 1) & HD64461_LCDGRDOR_MASK);
394 }
395
396 /* hpcfb ops */
397 int
398 hd64461video_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
399 {
400 struct hd64461video_softc *sc = (struct hd64461video_softc *)v;
401 struct hpcfb_fbconf *hf = &sc->sc_vc->hf;
402 struct hpcfb_fbconf *fbconf;
403 struct hpcfb_dspconf *dspconf;
404 struct wsdisplay_cmap *cmap;
405 u_int8_t *r, *g, *b;
406 int error;
407 size_t idx, cnt;
408
409 switch (cmd) {
410 case WSDISPLAYIO_GETCMAP:
411 cmap = (struct wsdisplay_cmap*)data;
412 cnt = cmap->count;
413 idx = cmap->index;
414
415 if (hf->hf_class != HPCFB_CLASS_INDEXCOLOR ||
416 hf->hf_pack_width != 8 ||
417 !LEGAL_CLUT_INDEX(idx) ||
418 !LEGAL_CLUT_INDEX(idx + cnt -1)) {
419 return (EINVAL);
420 }
421
422 if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
423 !uvm_useracc(cmap->green, cnt, B_WRITE) ||
424 !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
425 return (EFAULT);
426 }
427
428 error = cmap_work_alloc(&r, &g, &b, 0, cnt);
429 if (error != 0) {
430 cmap_work_free(r, g, b, 0);
431 return (ENOMEM);
432 }
433
434 hd64461video_get_clut(sc->sc_vc, idx, cnt, r, g, b);
435 copyout(r, cmap->red, cnt);
436 copyout(g, cmap->green,cnt);
437 copyout(b, cmap->blue, cnt);
438 cmap_work_free(r, g, b, 0);
439
440 return (0);
441
442 case WSDISPLAYIO_PUTCMAP:
443 cmap = (struct wsdisplay_cmap *)data;
444 cnt = cmap->count;
445 idx = cmap->index;
446
447 if (hf->hf_class != HPCFB_CLASS_INDEXCOLOR ||
448 hf->hf_pack_width != 8 ||
449 !LEGAL_CLUT_INDEX(idx) ||
450 !LEGAL_CLUT_INDEX(idx + cnt -1)) {
451 return (EINVAL);
452 }
453
454 if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
455 !uvm_useracc(cmap->green, cnt, B_WRITE) ||
456 !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
457 return (EFAULT);
458 }
459
460 error = cmap_work_alloc(&r, &g, &b, 0, cnt);
461 if (error != 0) {
462 cmap_work_free(r, g, b, 0);
463 return (ENOMEM);
464 }
465
466 copyin(cmap->red, r, cnt);
467 copyin(cmap->green,g, cnt);
468 copyin(cmap->blue, b, cnt);
469 hd64461video_set_clut(sc->sc_vc, idx, cnt, r, g, b);
470 cmap_work_free(r, g, b, 0);
471
472 return (0);
473
474 case HPCFBIO_GCONF:
475 fbconf = (struct hpcfb_fbconf *)data;
476 if (fbconf->hf_conf_index != 0 &&
477 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
478 return (EINVAL);
479 }
480 *fbconf = *hf; /* structure assignment */
481 return (0);
482
483 case HPCFBIO_SCONF:
484 fbconf = (struct hpcfb_fbconf *)data;
485 if (fbconf->hf_conf_index != 0 &&
486 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
487 return (EINVAL);
488 }
489 /*
490 * nothing to do because we have only one configration
491 */
492 return (0);
493
494 case HPCFBIO_GDSPCONF:
495 dspconf = (struct hpcfb_dspconf *)data;
496 if ((dspconf->hd_unit_index != 0 &&
497 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
498 (dspconf->hd_conf_index != 0 &&
499 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
500 return (EINVAL);
501 }
502 *dspconf = sc->sc_vc->hd; /* structure assignment */
503 return (0);
504
505 case HPCFBIO_SDSPCONF:
506 dspconf = (struct hpcfb_dspconf *)data;
507 if ((dspconf->hd_unit_index != 0 &&
508 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
509 (dspconf->hd_conf_index != 0 &&
510 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
511 return (EINVAL);
512 }
513 /*
514 * nothing to do
515 * because we have only one unit and one configration
516 */
517 return (0);
518
519 case HPCFBIO_GOP:
520 case HPCFBIO_SOP:
521 /* XXX not implemented yet */
522 return (EINVAL);
523 }
524
525 return (EPASSTHROUGH);
526 }
527
528 paddr_t
529 hd64461video_mmap(void *ctx, off_t offset, int prot)
530 {
531 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
532 struct hpcfb_fbconf *hf = &sc->sc_vc->hf;
533
534 if (offset < 0 || (hf->hf_bytes_per_plane + hf->hf_offset) < offset)
535 return (-1);
536
537 return (sh3_btop(HD64461_FBBASE + offset));
538 }
539
540 void
541 hd64461video_cursor(void *ctx, int on, int xd, int yd, int w, int h)
542 {
543 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
544 int xw, yh, width, bpp, adr;
545 u_int16_t r;
546
547 width = sc->sc_vc->vc.vc_fbwidth;
548 bpp = sc->sc_vc->vc.vc_fbdepth;
549 xw = w - 1;
550 yh = h - 1;
551
552 /* Wait until previous command done. */
553 hd64461video_iodone(ctx);
554
555 /* Destination addr */
556 adr = width * yd + xd;
557 if (bpp == 16)
558 adr *= 2;
559 hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
560 HD64461_LCDBBTDSARH(adr));
561 hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
562 HD64461_LCDBBTDSARL(adr));
563
564 // Width
565 hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
566 xw & HD64461_LCDBBTDWR_MASK);
567
568 // Height
569 hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
570 yh & HD64461_LCDBBTDHR_MASK);
571
572 // Operation (Destination Invert)
573 hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
574 HD64461_LCDC_BITBLT_DSTINVERT);
575
576 // BitBLT mode (Destination Invert)
577 hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16, 0);
578
579 // Kick.
580 r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
581 r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
582 r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
583 hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
584 }
585
586 void
587 hd64461video_bitblit(void *ctx, int xs, int ys, int xd, int yd, int h, int w)
588 {
589 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
590 int xw, yh, width, bpp, condition_a, adr;
591 u_int16_t r;
592
593 xw = w - 1;
594 yh = h - 1;
595 width = sc->sc_vc->vc.vc_fbwidth;
596 bpp = sc->sc_vc->vc.vc_fbdepth;
597 condition_a = ((ys == yd) && (xs <= xd)) || (ys < yd);
598
599 hd64461video_iodone(ctx);
600
601 // Source addr
602 if (condition_a)
603 adr = (width * (ys + yh)) + (xs + xw);
604 else
605 adr = width * ys + xs;
606 if (bpp == 16)
607 adr *= 2;
608
609 hd64461_reg_write_2(HD64461_LCDBBTSSARH_REG16,
610 HD64461_LCDBBTSSARH(adr));
611 hd64461_reg_write_2(HD64461_LCDBBTSSARL_REG16,
612 HD64461_LCDBBTSSARL(adr));
613
614 // Destination addr
615 if (condition_a)
616 adr = (width * (yd + yh)) + (xd + xw);
617 else
618 adr = width * yd + xd;
619 if (bpp == 16)
620 adr *= 2;
621
622 hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
623 HD64461_LCDBBTDSARH(adr));
624 hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
625 HD64461_LCDBBTDSARL(adr));
626
627 // Width
628 hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
629 xw & HD64461_LCDBBTDWR_MASK);
630
631 // Height
632 hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
633 yh & HD64461_LCDBBTDHR_MASK);
634
635 // Operation (source copy)
636 hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
637 HD64461_LCDC_BITBLT_SRCCOPY);
638
639 // BitBLT mode (on screen to on screen)
640 r = HD64461_LCDBBTMDR_SET(0,
641 HD64461_LCDBBTMDR_ON_SCREEN_TO_ON_SCREEN);
642 if (condition_a) /* reverse direction */
643 r |= HD64461_LCDBBTMDR_SCANDRCT_RL_BT;
644 hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16, r);
645
646 // Kick.
647 r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
648 r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
649 r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
650 hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
651 }
652
653 void
654 hd64461video_erase(void *ctx, int xd, int yd, int h, int w, int attr)
655 {
656 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
657 int xw, yh, width, bpp, adr;
658 u_int16_t r;
659
660 width = sc->sc_vc->vc.vc_fbwidth;
661 bpp = sc->sc_vc->vc.vc_fbdepth;
662 xw = w - 1;
663 yh = h - 1;
664
665 /* Wait until previous command done. */
666 hd64461video_iodone(ctx);
667
668 /* Destination addr */
669 adr = width * yd + xd;
670 if (bpp == 16)
671 adr *= 2;
672 hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
673 HD64461_LCDBBTDSARH(adr));
674 hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
675 HD64461_LCDBBTDSARL(adr));
676
677 // Width
678 hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
679 xw & HD64461_LCDBBTDWR_MASK);
680
681 // Height
682 hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
683 yh & HD64461_LCDBBTDHR_MASK);
684
685 // Color
686 hd64461_reg_write_2(HD64461_LCDGRSCR_REG16, 0); //XXX black only
687
688 // Operation (Solid Color Fill)
689 hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
690 HD64461_LCDC_BITBLT_PATCOPY);
691
692 // BitBLT mode (Solid Color)
693 hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16,
694 HD64461_LCDBBTMDR_PATSELECT_SOLIDCOLOR);
695
696 // Kick.
697 r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
698 r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
699 r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
700 hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
701 }
702
703 void
704 hd64461video_putchar(void *ctx, int row, int col, struct wsdisplay_font *font,
705 int fclr, int uclr, u_int uc, int attr)
706 {
707 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
708 int w, h, cw;
709
710 w = font->fontwidth;
711 h = font->fontheight;
712 cw = sc->sc_font.cw;
713 hd64461video_bitblit(ctx, (uc % cw) * w,
714 sc->sc_vc->vc.vc_fbheight + (uc / cw) * h, row, col, h, w);
715 }
716
717 void
718 hd64461video_setclut(void *ctx, struct rasops_info *info)
719 {
720 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
721
722 if (sc->sc_vc->vc.vc_fbdepth != 8)
723 return;
724 }
725
726 void
727 hd64461video_font(void *ctx, struct wsdisplay_font *font)
728 {
729 struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
730
731 hd64461video_font_set_attr(sc, font);
732 hd64461video_font_load(sc);
733 }
734
735 void
736 hd64461video_iodone(void *ctx)
737 {
738 while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
739 HD64461_LCDGRCFGR_ACCSTATUS) != 0)
740 /* busy loop */;
741 }
742
743 /* internal */
744 void
745 hd64461video_font_load_16bpp(u_int16_t *d, u_int8_t *s, int w, int h, int step)
746 {
747 int i, j, n;
748 n = step / sizeof(u_int16_t);
749
750 for (i = 0; i < h; i++, d += n) {
751 for (j = 0; j < w; j++) {
752 d[j] = *s & (1 << (w - j - 1)) ? 0xffff : 0x0000;
753 }
754 s++;
755 }
756 }
757
758 void
759 hd64461video_font_load_8bpp(u_int8_t *d, u_int8_t *s, int w, int h, int step)
760 {
761 int i, j, n;
762 n = step / sizeof(u_int8_t);
763
764 for (i = 0; i < h; i++, d += n) {
765 for (j = 0; j < w; j++) {
766 d[j] = *s & (1 << (w - j - 1)) ? 0xff : 0x00;
767 }
768 s++;
769 }
770 }
771
772 void
773 hd64461video_font_set_attr(struct hd64461video_softc *sc,
774 struct wsdisplay_font *f)
775 {
776 struct hd64461video_chip *hvc = sc->sc_vc;
777 struct wsdisplay_font *font = (struct wsdisplay_font *)&sc->sc_font;
778 int w, h, bpp;
779
780 w = f->fontwidth;
781 h = f->fontheight;
782 bpp = hvc->vc.vc_fbdepth;
783
784 *font = *f;
785 sc->sc_font.c = (w * bpp) / NBBY;
786 sc->sc_font.cw = hvc->hf.hf_width / w;
787 sc->sc_font.cstep = ((w * h * bpp) / NBBY) * sc->sc_font.cw;
788
789 DPRINTF("c = %d cw = %d cstep = %d\n", sc->sc_font.c,
790 sc->sc_font.cw, sc->sc_font.cstep);
791
792 }
793
794 /* return frame buffer virtual address of charcter #n */
795 vaddr_t
796 hd64461video_font_start_addr(struct hd64461video_softc *sc, int n)
797 {
798 struct hd64461video_chip *hvc = sc->sc_vc;
799 struct hd64461video_font *font = &sc->sc_font;
800 vaddr_t base;
801
802 base = (vaddr_t)hvc->off_screen_addr;
803 base += (n / font->cw) * font->cstep + font->c * (n % font->cw);
804
805 return base;
806 }
807
808 void
809 hd64461video_font_load(struct hd64461video_softc *sc)
810 {
811 struct hd64461video_chip *hvc = sc->sc_vc;
812 struct wsdisplay_font *font = (struct wsdisplay_font *)&sc->sc_font;
813 u_int8_t *q;
814 int w, h, step, i, n;
815
816 if (sc->sc_font.loaded) {
817 printf("reload font\n");
818 }
819
820 w = font->fontwidth;
821 h = font->fontheight;
822 step = sc->sc_font.cw * sc->sc_font.c;
823 n = (w * h) / NBBY;
824 q = font->data;
825
826 DPRINTF("%s (%dx%d) %d+%d\n", font->name, w, h, font->firstchar,
827 font->numchars);
828 DPRINTF("bitorder %d byteorder %d stride %d\n", font->bitorder,
829 font->byteorder, font->stride);
830
831 switch (hvc->vc.vc_fbdepth) {
832 case 8:
833 for (i = font->firstchar; i < font->numchars; i++) {
834 hd64461video_font_load_8bpp
835 ((u_int8_t *)hd64461video_font_start_addr(sc, i),
836 q, w, h, step);
837 q += n;
838 }
839 break;
840 case 16:
841 for (i = font->firstchar; i < font->numchars; i++) {
842 hd64461video_font_load_16bpp
843 ((u_int16_t *)hd64461video_font_start_addr(sc, i),
844 q, w, h, step);
845 q += n;
846 }
847 break;
848 }
849
850 sc->sc_font.loaded = TRUE;
851 }
852
853 void
854 hd64461video_update_videochip_status(struct hd64461video_chip *hvc)
855 {
856 struct video_chip *vc = &hvc->vc;
857 u_int16_t r;
858 int i;
859 int depth, width, height;
860
861 /* display mode */
862 r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
863 i = HD64461_LCDLDR3_CG(r);
864 switch (i) {
865 case HD64461_LCDLDR3_CG_COLOR16:
866 depth = 16;
867 hvc->mode = LCD64K_C;
868 break;
869 case HD64461_LCDLDR3_CG_COLOR8:
870 depth = 8;
871 hvc->mode = LCD256_C;
872 break;
873 case HD64461_LCDLDR3_CG_GRAY6:
874 depth = 6;
875 hvc->mode = LCD64_MONO;
876 break;
877 case HD64461_LCDLDR3_CG_GRAY4:
878 depth = 4;
879 hvc->mode = LCD16_MONO;
880 break;
881 case HD64461_LCDLDR3_CG_GRAY2:
882 depth = 2;
883 hvc->mode = LCD4_MONO;
884 break;
885 case HD64461_LCDLDR3_CG_GRAY1:
886 depth = 1;
887 hvc->mode = LCD2_MONO;
888 break;
889 }
890
891 r = hd64461_reg_read_2(HD64461_LCDCCR_REG16);
892 i = HD64461_LCDCCR_DSPSEL(i);
893 switch (i) {
894 case HD64461_LCDCCR_DSPSEL_LCD_CRT:
895 depth = 8;
896 hvc->mode = LCDCRT;
897 break;
898 case HD64461_LCDCCR_DSPSEL_CRT:
899 depth = 8;
900 hvc->mode = CRT256_C;
901 break;
902 case HD64461_LCDCCR_DSPSEL_LCD:
903 /* nothing to do */
904 break;
905 }
906
907 width = bootinfo->fb_width;
908 height = bootinfo->fb_height;
909
910 vc->vc_fbvaddr = HD64461_FBBASE;
911 vc->vc_fbpaddr = HD64461_FBBASE;
912 vc->vc_fbdepth = depth;
913 vc->vc_fbsize = (width * height * depth) / NBBY;
914 vc->vc_fbwidth = width;
915 vc->vc_fbheight = height;
916 }
917
918 #if notyet
919 void
920 hd64461video_set_display_mode(struct hd64461video_chip *hvc)
921 {
922
923 if (hvc->mode == LCDCRT || hvc->mode == CRT256_C)
924 hd64461video_set_display_mode_crtc(hvc);
925
926 hd64461video_set_display_mode_lcdc(hvc);
927 }
928
929 void
930 hd64461video_set_display_mode_lcdc(struct hd64461video_chip *hvc)
931 {
932 struct {
933 u_int16_t clor; /* display size 640 x 240 */
934 u_int16_t ldr3;
935 const char *name;
936 } disp_conf[] = {
937 [LCD256_C] = { 0x280 , HD64461_LCDLDR3_CG_COLOR8 ,
938 "8bit color" },
939 [LCD64K_C] = { 0x500 , HD64461_LCDLDR3_CG_COLOR16 ,
940 "16bit color" },
941 [LCD64_MONO] = { 0x280 , HD64461_LCDLDR3_CG_GRAY6 ,
942 "6bit gray scale" },
943 [LCD16_MONO] = { 0x140 , HD64461_LCDLDR3_CG_GRAY4 ,
944 "4bit gray scale" },
945 [LCD4_MONO] = { 0x0a0 , HD64461_LCDLDR3_CG_GRAY2 ,
946 "2bit gray scale" },
947 [LCD2_MONO] = { 0x050 , HD64461_LCDLDR3_CG_GRAY1 ,
948 "mono chrome" },
949 }, *conf;
950 u_int16_t r;
951 int omode;
952
953 conf = &disp_conf[hvc->mode];
954
955 hd64461_reg_write_2(HD64461_LCDCLOR_REG16, conf->clor);
956 r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
957 omode = HD64461_LCDLDR3_CG(r);
958 r = HD64461_LCDLDR3_CG_CLR(r);
959 r = HD64461_LCDLDR3_CG_SET(r, conf->ldr3);
960 hd64461_reg_write_2(HD64461_LCDLDR3_REG16, r);
961
962 printf("%s ", conf->name);
963 }
964
965 void
966 hd64461video_set_display_mode_crtc(struct hd64461video_chip *hvc)
967 {
968 /* not yet */
969 }
970 #endif /* notyet */
971
972 size_t
973 hd64461video_frame_buffer_size(struct hd64461video_chip *hvc)
974 {
975 vaddr_t page, startaddr, endaddr;
976 int x;
977
978 startaddr = HD64461_FBBASE;
979 endaddr = startaddr + HD64461_FBSIZE - 1;
980
981 page = startaddr;
982
983 x = random();
984 *(volatile int *)(page + 0) = x;
985 *(volatile int *)(page + 4) = ~x;
986
987 if (*(volatile int *)(page + 0) != x ||
988 *(volatile int *)(page + 4) != ~x)
989 return (0);
990
991 for (page += HD64461_FBPAGESIZE; page < endaddr;
992 page += HD64461_FBPAGESIZE) {
993 if (*(volatile int *)(page + 0) == x &&
994 *(volatile int *)(page + 4) == ~x)
995 goto fbend_found;
996 }
997
998 page -= HD64461_FBPAGESIZE;
999 *(volatile int *)(page + 0) = x;
1000 *(volatile int *)(page + 4) = ~x;
1001
1002 if (*(volatile int *)(page + 0) != x ||
1003 *(volatile int *)(page + 4) != ~x)
1004 return (0);
1005
1006 fbend_found:
1007 return (page - startaddr);
1008 }
1009
1010 void
1011 hd64461video_set_clut(struct hd64461video_chip *vc, int idx, int cnt,
1012 u_int8_t *r, u_int8_t *g, u_int8_t *b)
1013 {
1014 KASSERT(r && g && b);
1015
1016 /* index pallete */
1017 hd64461_reg_write_2(HD64461_LCDCPTWAR_REG16,
1018 HD64461_LCDCPTWAR_SET(0, idx));
1019 /* set data */
1020 while (cnt && LEGAL_CLUT_INDEX(idx)) {
1021 u_int16_t v;
1022 #define HD64461VIDEO_SET_CLUT(x) \
1023 v = (x >> 2) & 0x3f; \
1024 hd64461_reg_write_2(HD64461_LCDCPTWDR_REG16, v)
1025 HD64461VIDEO_SET_CLUT(*r);
1026 HD64461VIDEO_SET_CLUT(*g);
1027 HD64461VIDEO_SET_CLUT(*b);
1028 #undef HD64461VIDEO_SET_CLUT
1029 r++, g++, b++;
1030 idx++, cnt--;
1031 }
1032 }
1033
1034 void
1035 hd64461video_get_clut(struct hd64461video_chip *vc, int idx, int cnt,
1036 u_int8_t *r, u_int8_t *g, u_int8_t *b)
1037 {
1038 KASSERT(r && g && b);
1039
1040 /* index pallete */
1041 hd64461_reg_write_2(HD64461_LCDCPTRAR_REG16,
1042 HD64461_LCDCPTRAR_SET(0, idx));
1043
1044 /* get data */
1045 while (cnt && LEGAL_CLUT_INDEX(idx)) {
1046 u_int16_t v;
1047 #define HD64461VIDEO_GET_CLUT(x) \
1048 v = hd64461_reg_read_2(HD64461_LCDCPTWDR_REG16); \
1049 x = HD64461_LCDCPTRDR(v); \
1050 x <<= 2
1051 HD64461VIDEO_GET_CLUT(*r);
1052 HD64461VIDEO_GET_CLUT(*g);
1053 HD64461VIDEO_GET_CLUT(*b);
1054 #undef HD64461VIDEO_GET_CLUT
1055 r++, g++, b++;
1056 idx++, cnt--;
1057 }
1058 }
1059
1060 #ifdef HD64461VIDEO_DEBUG
1061 void
1062 hd64461video_info(struct hd64461video_softc *sc)
1063 {
1064 u_int16_t r;
1065 int color;
1066 int i;
1067
1068 dbg_banner_function();
1069 printf("---[LCD]---\n");
1070 /* Base Address Register */
1071 r = hd64461_reg_read_2(HD64461_LCDCBAR_REG16);
1072 printf("LCDCBAR Frame buffer base address (4k Byte align): 0x%08x\n",
1073 HD64461_LCDCBAR_BASEADDR(r));
1074
1075 /* Line Address Offset Register */
1076 r = hd64461_reg_read_2(HD64461_LCDCLOR_REG16);
1077 printf("LCDCLOR Line address offset: %d\n", HD64461_LCDCLOR(r));
1078
1079 /* LCDC Control Register */
1080 r = hd64461_reg_read_2(HD64461_LCDCCR_REG16);
1081 i = HD64461_LCDCCR_DSPSEL(r);
1082 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_LCDCCR_##m, #m)
1083 printf("LCDCCR (LCD Control Register)\n");
1084 DBG_BITMASK_PRINT(r, STBAK);
1085 DBG_BITMASK_PRINT(r, STREQ);
1086 DBG_BITMASK_PRINT(r, MOFF);
1087 DBG_BITMASK_PRINT(r, REFSEL);
1088 DBG_BITMASK_PRINT(r, EPON);
1089 DBG_BITMASK_PRINT(r, SPON);
1090 printf("\n");
1091 #undef DBG_BITMASK_PRINT
1092 printf("LCDCCR Display selct LCD[%c] CRT[%c]\n",
1093 i == HD64461_LCDCCR_DSPSEL_LCD_CRT ||
1094 i == HD64461_LCDCCR_DSPSEL_LCD ? 'x' : '_',
1095 i == HD64461_LCDCCR_DSPSEL_LCD_CRT ||
1096 i == HD64461_LCDCCR_DSPSEL_CRT ? 'x' : '_');
1097
1098 /* LCD Display Register */
1099 /* 1 */
1100 r = hd64461_reg_read_2(HD64461_LCDLDR1_REG16);
1101 printf("(LCD Display Register)\n");
1102 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_LCDLDR1_##m, #m)
1103 printf("LCDLDR1: ");
1104 DBG_BITMASK_PRINT(r, DINV);
1105 DBG_BITMASK_PRINT(r, DON);
1106 printf("\n");
1107 #undef DBG_BITMASK_PRINT
1108 /* 2 */
1109 r = hd64461_reg_read_2(HD64461_LCDLDR2_REG16);
1110 i = HD64461_LCDLDR2_LM(r);
1111 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_LCDLDR2_##m, #m)
1112 printf("LCDLDR2: ");
1113 DBG_BITMASK_PRINT(r, CC1);
1114 DBG_BITMASK_PRINT(r, CC2);
1115 #undef DBG_BITMASK_PRINT
1116 color = 0;
1117 switch (i) {
1118 default:
1119 panic("unknown unknown LCD interface.");
1120 break;
1121 case HD64461_LCDLDR2_LM_COLOR:
1122 color = 1;
1123 printf("Color");
1124 break;
1125 case HD64461_LCDLDR2_LM_GRAY8:
1126 printf("8-bit grayscale");
1127 break;
1128 case HD64461_LCDLDR2_LM_GRAY4:
1129 printf("8-bit grayscale");
1130 break;
1131 }
1132 printf(" LCD interface\n");
1133 /* 3 */
1134 printf("LCDLDR3: ");
1135 r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
1136 i = HD64461_LCDLDR3_CS(r);
1137 printf("CS ");
1138 switch (i) {
1139 case 0:
1140 printf("15");
1141 break;
1142 case 1:
1143 printf("2.5");
1144 break;
1145 case 2:
1146 printf("3.75");
1147 break;
1148 case 4:
1149 printf("5");
1150 break;
1151 case 8:
1152 printf("7.5");
1153 break;
1154 case 16:
1155 printf("10");
1156 break;
1157 }
1158 printf("%s MHz ", color ? "" : "/2");
1159 i = HD64461_LCDLDR3_CG(r);
1160 switch (i) {
1161 case HD64461_LCDLDR3_CG_COLOR16:
1162 printf("Color 64K colors\n");
1163 break;
1164 case HD64461_LCDLDR3_CG_COLOR8:
1165 printf("Color 256 colors\n");
1166 break;
1167 case HD64461_LCDLDR3_CG_GRAY6:
1168 printf("6-bit Grayscale\n");
1169 break;
1170 case HD64461_LCDLDR3_CG_GRAY4:
1171 printf("4-bit Grayscale\n");
1172 break;
1173 case HD64461_LCDLDR3_CG_GRAY2:
1174 printf("2-bit Grayscale\n");
1175 break;
1176 case HD64461_LCDLDR3_CG_GRAY1:
1177 printf("1-bit Grayscale\n");
1178 break;
1179 }
1180
1181 /* LCD Number of Characters in Horizontal Register */
1182 r = hd64461_reg_read_2(HD64461_LCDLDHNCR_REG16);
1183 printf("LDHNCR: NHD %d NHT %d (# of horizontal characters)\n",
1184 HD64461_LCDLDHNCR_NHD(r), HD64461_LCDLDHNCR_NHT(r));
1185
1186 /* Start Position of Horizontal Register */
1187 r = hd64461_reg_read_2(HD64461_LCDLDHNSR_REG16);
1188 printf("LDHNSR: HSW %d HSP %d (start position of horizontal)\n",
1189 HD64461_LCDLDHNSR_HSW(r), HD64461_LCDLDHNSR_HSP(r));
1190
1191 /* Total Vertical Lines Register */
1192 r = hd64461_reg_read_2(HD64461_LCDLDVNTR_REG16);
1193 printf("LDVNTR: %d (total vertical lines)\n",
1194 HD64461_LCDLDVNTR_VTL(r));
1195
1196 /* Display Vertical Lines Register */
1197 r = hd64461_reg_read_2(HD64461_LCDLDVNDR_REG16);
1198 printf("LDVNDR: %d (display vertical lines)\n",
1199 HD64461_LCDLDVSPR_VSP(r));
1200
1201 /* Vertical Synchronization Position Register */
1202 r = hd64461_reg_read_2(HD64461_LCDLDVSPR_REG16);
1203 printf("LDVSPR: %d (vertical synchronization position)\n",
1204 HD64461_LCDLDVSPR_VSP(r));
1205
1206 /*
1207 * CRT Control Register
1208 */
1209 printf("---[CRT]---\n");
1210 r = hd64461_reg_read_2(HD64461_LCDCRTVTR_REG16);
1211 printf("CRTVTR: %d (CRTC total vertical lines)\n",
1212 HD64461_LCDCRTVTR(r));
1213 r = hd64461_reg_read_2(HD64461_LCDCRTVRSR_REG16);
1214 printf("CRTVRSR: %d (CRTC vertical retrace start line)\n",
1215 HD64461_LCDCRTVRSR(r));
1216 r = hd64461_reg_read_2(HD64461_LCDCRTVRER_REG16);
1217 printf("CRTVRER: %d (CRTC vertical retrace end line)\n",
1218 HD64461_LCDCRTVRER(r));
1219
1220 }
1221
1222 void
1223 hd64461video_dump()
1224 {
1225 u_int16_t r;
1226 printf("---[Display Mode Setting]---\n");
1227 #define DUMPREG(x) \
1228 r = hd64461_reg_read_2(HD64461_LCD ## x ## _REG16); \
1229 __dbg_bit_print(r, sizeof(u_int16_t), 0, 0, #x, DBG_BIT_PRINT_COUNT)
1230 DUMPREG(CBAR);
1231 DUMPREG(CLOR);
1232 DUMPREG(CCR);
1233 DUMPREG(LDR1);
1234 DUMPREG(LDR2);
1235 DUMPREG(LDHNCR);
1236 DUMPREG(LDHNSR);
1237 DUMPREG(LDVNTR);
1238 DUMPREG(LDVNDR);
1239 DUMPREG(LDVSPR);
1240 DUMPREG(LDR3);
1241 DUMPREG(CRTVTR);
1242 DUMPREG(CRTVRSR);
1243 DUMPREG(CRTVRER);
1244 #undef DUMPREG
1245 dbg_banner_line();
1246 }
1247
1248 #endif /* HD64461VIDEO_DEBUG */
1249