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