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