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