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