xref: /freebsd/sys/arm/ti/am335x/am335x_lcd_syscons.c (revision 076ad2f836d5f49dc1375f1677335a48fe0d4b82)
1 /*-
2  * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28 
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/bus.h>
32 #include <sys/conf.h>
33 #include <sys/endian.h>
34 #include <sys/kernel.h>
35 #include <sys/lock.h>
36 #include <sys/malloc.h>
37 #include <sys/module.h>
38 #include <sys/mutex.h>
39 #include <sys/resource.h>
40 #include <sys/rman.h>
41 #include <sys/fbio.h>
42 #include <sys/consio.h>
43 
44 #include <sys/kdb.h>
45 
46 #include <machine/bus.h>
47 #include <machine/resource.h>
48 #include <machine/intr.h>
49 
50 #include <dev/ofw/ofw_bus.h>
51 #include <dev/ofw/ofw_bus_subr.h>
52 
53 #include <dev/fb/fbreg.h>
54 #include <dev/syscons/syscons.h>
55 
56 #include "am335x_lcd.h"
57 
58 struct video_adapter_softc {
59 	/* Videoadpater part */
60 	video_adapter_t	va;
61 	int		console;
62 
63 	intptr_t	fb_addr;
64 	intptr_t	fb_paddr;
65 	unsigned int	fb_size;
66 
67 	unsigned int	height;
68 	unsigned int	width;
69 	unsigned int	depth;
70 	unsigned int	stride;
71 
72 	unsigned int	xmargin;
73 	unsigned int	ymargin;
74 
75 	unsigned char	*font;
76 	int		initialized;
77 };
78 
79 struct argb {
80 	uint8_t		a;
81 	uint8_t		r;
82 	uint8_t		g;
83 	uint8_t		b;
84 };
85 
86 static struct argb am335x_syscons_palette[16] = {
87 	{0x00, 0x00, 0x00, 0x00},
88 	{0x00, 0x00, 0x00, 0xaa},
89 	{0x00, 0x00, 0xaa, 0x00},
90 	{0x00, 0x00, 0xaa, 0xaa},
91 	{0x00, 0xaa, 0x00, 0x00},
92 	{0x00, 0xaa, 0x00, 0xaa},
93 	{0x00, 0xaa, 0x55, 0x00},
94 	{0x00, 0xaa, 0xaa, 0xaa},
95 	{0x00, 0x55, 0x55, 0x55},
96 	{0x00, 0x55, 0x55, 0xff},
97 	{0x00, 0x55, 0xff, 0x55},
98 	{0x00, 0x55, 0xff, 0xff},
99 	{0x00, 0xff, 0x55, 0x55},
100 	{0x00, 0xff, 0x55, 0xff},
101 	{0x00, 0xff, 0xff, 0x55},
102 	{0x00, 0xff, 0xff, 0xff}
103 };
104 
105 /* mouse pointer from dev/syscons/scgfbrndr.c */
106 static u_char mouse_pointer[16] = {
107         0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
108         0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
109 };
110 
111 #define	AM335X_FONT_HEIGHT	16
112 
113 #define FB_WIDTH		640
114 #define FB_HEIGHT		480
115 #define FB_DEPTH		24
116 
117 static struct video_adapter_softc va_softc;
118 
119 static int am335x_syscons_configure(int flags);
120 
121 /*
122  * Video driver routines and glue.
123  */
124 static vi_probe_t		am335x_syscons_probe;
125 static vi_init_t		am335x_syscons_init;
126 static vi_get_info_t		am335x_syscons_get_info;
127 static vi_query_mode_t		am335x_syscons_query_mode;
128 static vi_set_mode_t		am335x_syscons_set_mode;
129 static vi_save_font_t		am335x_syscons_save_font;
130 static vi_load_font_t		am335x_syscons_load_font;
131 static vi_show_font_t		am335x_syscons_show_font;
132 static vi_save_palette_t	am335x_syscons_save_palette;
133 static vi_load_palette_t	am335x_syscons_load_palette;
134 static vi_set_border_t		am335x_syscons_set_border;
135 static vi_save_state_t		am335x_syscons_save_state;
136 static vi_load_state_t		am335x_syscons_load_state;
137 static vi_set_win_org_t		am335x_syscons_set_win_org;
138 static vi_read_hw_cursor_t	am335x_syscons_read_hw_cursor;
139 static vi_set_hw_cursor_t	am335x_syscons_set_hw_cursor;
140 static vi_set_hw_cursor_shape_t	am335x_syscons_set_hw_cursor_shape;
141 static vi_blank_display_t	am335x_syscons_blank_display;
142 static vi_mmap_t		am335x_syscons_mmap;
143 static vi_ioctl_t		am335x_syscons_ioctl;
144 static vi_clear_t		am335x_syscons_clear;
145 static vi_fill_rect_t		am335x_syscons_fill_rect;
146 static vi_bitblt_t		am335x_syscons_bitblt;
147 static vi_diag_t		am335x_syscons_diag;
148 static vi_save_cursor_palette_t	am335x_syscons_save_cursor_palette;
149 static vi_load_cursor_palette_t	am335x_syscons_load_cursor_palette;
150 static vi_copy_t		am335x_syscons_copy;
151 static vi_putp_t		am335x_syscons_putp;
152 static vi_putc_t		am335x_syscons_putc;
153 static vi_puts_t		am335x_syscons_puts;
154 static vi_putm_t		am335x_syscons_putm;
155 
156 static video_switch_t am335x_sysconsvidsw = {
157 	.probe			= am335x_syscons_probe,
158 	.init			= am335x_syscons_init,
159 	.get_info		= am335x_syscons_get_info,
160 	.query_mode		= am335x_syscons_query_mode,
161 	.set_mode		= am335x_syscons_set_mode,
162 	.save_font		= am335x_syscons_save_font,
163 	.load_font		= am335x_syscons_load_font,
164 	.show_font		= am335x_syscons_show_font,
165 	.save_palette		= am335x_syscons_save_palette,
166 	.load_palette		= am335x_syscons_load_palette,
167 	.set_border		= am335x_syscons_set_border,
168 	.save_state		= am335x_syscons_save_state,
169 	.load_state		= am335x_syscons_load_state,
170 	.set_win_org		= am335x_syscons_set_win_org,
171 	.read_hw_cursor		= am335x_syscons_read_hw_cursor,
172 	.set_hw_cursor		= am335x_syscons_set_hw_cursor,
173 	.set_hw_cursor_shape	= am335x_syscons_set_hw_cursor_shape,
174 	.blank_display		= am335x_syscons_blank_display,
175 	.mmap			= am335x_syscons_mmap,
176 	.ioctl			= am335x_syscons_ioctl,
177 	.clear			= am335x_syscons_clear,
178 	.fill_rect		= am335x_syscons_fill_rect,
179 	.bitblt			= am335x_syscons_bitblt,
180 	.diag			= am335x_syscons_diag,
181 	.save_cursor_palette	= am335x_syscons_save_cursor_palette,
182 	.load_cursor_palette	= am335x_syscons_load_cursor_palette,
183 	.copy			= am335x_syscons_copy,
184 	.putp			= am335x_syscons_putp,
185 	.putc			= am335x_syscons_putc,
186 	.puts			= am335x_syscons_puts,
187 	.putm			= am335x_syscons_putm,
188 };
189 
190 VIDEO_DRIVER(am335x_syscons, am335x_sysconsvidsw, am335x_syscons_configure);
191 
192 static vr_init_t am335x_rend_init;
193 static vr_clear_t am335x_rend_clear;
194 static vr_draw_border_t am335x_rend_draw_border;
195 static vr_draw_t am335x_rend_draw;
196 static vr_set_cursor_t am335x_rend_set_cursor;
197 static vr_draw_cursor_t am335x_rend_draw_cursor;
198 static vr_blink_cursor_t am335x_rend_blink_cursor;
199 static vr_set_mouse_t am335x_rend_set_mouse;
200 static vr_draw_mouse_t am335x_rend_draw_mouse;
201 
202 /*
203  * We use our own renderer; this is because we must emulate a hardware
204  * cursor.
205  */
206 static sc_rndr_sw_t am335x_rend = {
207 	am335x_rend_init,
208 	am335x_rend_clear,
209 	am335x_rend_draw_border,
210 	am335x_rend_draw,
211 	am335x_rend_set_cursor,
212 	am335x_rend_draw_cursor,
213 	am335x_rend_blink_cursor,
214 	am335x_rend_set_mouse,
215 	am335x_rend_draw_mouse
216 };
217 
218 RENDERER(am335x_syscons, 0, am335x_rend, gfb_set);
219 RENDERER_MODULE(am335x_syscons, gfb_set);
220 
221 static void
222 am335x_rend_init(scr_stat* scp)
223 {
224 }
225 
226 static void
227 am335x_rend_clear(scr_stat* scp, int c, int attr)
228 {
229 }
230 
231 static void
232 am335x_rend_draw_border(scr_stat* scp, int color)
233 {
234 }
235 
236 static void
237 am335x_rend_draw(scr_stat* scp, int from, int count, int flip)
238 {
239 	video_adapter_t* adp = scp->sc->adp;
240 	int i, c, a;
241 
242 	if (!flip) {
243 		/* Normal printing */
244 		vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count);
245 	} else {
246 		/* This is for selections and such: invert the color attribute */
247 		for (i = count; i-- > 0; ++from) {
248 			c = sc_vtb_getc(&scp->vtb, from);
249 			a = sc_vtb_geta(&scp->vtb, from) >> 8;
250 			vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4));
251 		}
252 	}
253 }
254 
255 static void
256 am335x_rend_set_cursor(scr_stat* scp, int base, int height, int blink)
257 {
258 }
259 
260 static void
261 am335x_rend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip)
262 {
263 	video_adapter_t* adp = scp->sc->adp;
264 	struct video_adapter_softc *sc;
265 	int row, col;
266 	uint8_t *addr;
267 	int i, j, bytes;
268 
269 	sc = (struct video_adapter_softc *)adp;
270 
271 	if (scp->curs_attr.height <= 0)
272 		return;
273 
274 	if (sc->fb_addr == 0)
275 		return;
276 
277 	if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
278 		return;
279 
280 	/* calculate the coordinates in the video buffer */
281 	row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
282 	col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
283 
284 	addr = (uint8_t *)sc->fb_addr
285 	    + (row + sc->ymargin)*(sc->stride)
286 	    + (sc->depth/8) * (col + sc->xmargin);
287 
288 	bytes = sc->depth/8;
289 
290 	/* our cursor consists of simply inverting the char under it */
291 	for (i = 0; i < adp->va_info.vi_cheight; i++) {
292 		for (j = 0; j < adp->va_info.vi_cwidth; j++) {
293 			switch (sc->depth) {
294 			case 32:
295 			case 24:
296 				addr[bytes*j + 2] ^= 0xff;
297 				/* FALLTHROUGH */
298 			case 16:
299 				addr[bytes*j + 1] ^= 0xff;
300 				addr[bytes*j] ^= 0xff;
301 				break;
302 			default:
303 				break;
304 			}
305 		}
306 
307 		addr += sc->stride;
308 	}
309 }
310 
311 static void
312 am335x_rend_blink_cursor(scr_stat* scp, int at, int flip)
313 {
314 }
315 
316 static void
317 am335x_rend_set_mouse(scr_stat* scp)
318 {
319 }
320 
321 static void
322 am335x_rend_draw_mouse(scr_stat* scp, int x, int y, int on)
323 {
324 	vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8);
325 }
326 
327 static uint16_t am335x_syscons_static_window[ROW*COL];
328 extern u_char dflt_font_16[];
329 
330 /*
331  * Update videoadapter settings after changing resolution
332  */
333 static void
334 am335x_syscons_update_margins(video_adapter_t *adp)
335 {
336 	struct video_adapter_softc *sc;
337 	video_info_t *vi;
338 
339 	sc = (struct video_adapter_softc *)adp;
340 	vi = &adp->va_info;
341 
342 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
343 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
344 }
345 
346 static phandle_t
347 am335x_syscons_find_panel_node(phandle_t start)
348 {
349 	phandle_t child;
350 	phandle_t result;
351 
352 	for (child = OF_child(start); child != 0; child = OF_peer(child)) {
353 		if (ofw_bus_node_is_compatible(child, "ti,am335x-lcd"))
354 			return (child);
355 		if ((result = am335x_syscons_find_panel_node(child)))
356 			return (result);
357 	}
358 
359 	return (0);
360 }
361 
362 static int
363 am335x_syscons_configure(int flags)
364 {
365 	struct video_adapter_softc *va_sc;
366 
367 	va_sc = &va_softc;
368 	phandle_t display, root;
369 	pcell_t cell;
370 
371 	if (va_sc->initialized)
372 		return (0);
373 
374 	va_sc->width = 0;
375 	va_sc->height = 0;
376 
377 	/*
378 	 * It seems there is no way to let syscons framework know
379 	 * that framebuffer resolution has changed. So just try
380 	 * to fetch data from FDT and go with defaults if failed
381 	 */
382 	root = OF_finddevice("/");
383 	if ((root != 0) &&
384 	    (display = am335x_syscons_find_panel_node(root))) {
385 		if ((OF_getencprop(display, "panel_width", &cell,
386 		    sizeof(cell))) > 0)
387 			va_sc->width = cell;
388 
389 		if ((OF_getencprop(display, "panel_height", &cell,
390 		    sizeof(cell))) > 0)
391 			va_sc->height = cell;
392 	}
393 
394 	if (va_sc->width == 0)
395 		va_sc->width = FB_WIDTH;
396 	if (va_sc->height == 0)
397 		va_sc->height = FB_HEIGHT;
398 
399 	am335x_syscons_init(0, &va_sc->va, 0);
400 
401 	va_sc->initialized = 1;
402 
403 	return (0);
404 }
405 
406 static int
407 am335x_syscons_probe(int unit, video_adapter_t **adp, void *arg, int flags)
408 {
409 
410 	return (0);
411 }
412 
413 static int
414 am335x_syscons_init(int unit, video_adapter_t *adp, int flags)
415 {
416 	struct video_adapter_softc *sc;
417 	video_info_t *vi;
418 
419 	sc = (struct video_adapter_softc *)adp;
420 	vi = &adp->va_info;
421 
422 	vid_init_struct(adp, "am335x_syscons", -1, unit);
423 
424 	sc->font = dflt_font_16;
425 	vi->vi_cheight = AM335X_FONT_HEIGHT;
426 	vi->vi_cwidth = 8;
427 
428 	vi->vi_width = sc->width/8;
429 	vi->vi_height = sc->height/vi->vi_cheight;
430 
431 	/*
432 	 * Clamp width/height to syscons maximums
433 	 */
434 	if (vi->vi_width > COL)
435 		vi->vi_width = COL;
436 	if (vi->vi_height > ROW)
437 		vi->vi_height = ROW;
438 
439 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
440 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
441 
442 
443 	adp->va_window = (vm_offset_t) am335x_syscons_static_window;
444 	adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
445 
446 	vid_register(&sc->va);
447 
448 	return (0);
449 }
450 
451 static int
452 am335x_syscons_get_info(video_adapter_t *adp, int mode, video_info_t *info)
453 {
454 	bcopy(&adp->va_info, info, sizeof(*info));
455 	return (0);
456 }
457 
458 static int
459 am335x_syscons_query_mode(video_adapter_t *adp, video_info_t *info)
460 {
461 	return (0);
462 }
463 
464 static int
465 am335x_syscons_set_mode(video_adapter_t *adp, int mode)
466 {
467 	return (0);
468 }
469 
470 static int
471 am335x_syscons_save_font(video_adapter_t *adp, int page, int size, int width,
472     u_char *data, int c, int count)
473 {
474 	return (0);
475 }
476 
477 static int
478 am335x_syscons_load_font(video_adapter_t *adp, int page, int size, int width,
479     u_char *data, int c, int count)
480 {
481 	struct video_adapter_softc *sc = (struct video_adapter_softc *)adp;
482 
483 	sc->font = data;
484 
485 	return (0);
486 }
487 
488 static int
489 am335x_syscons_show_font(video_adapter_t *adp, int page)
490 {
491 	return (0);
492 }
493 
494 static int
495 am335x_syscons_save_palette(video_adapter_t *adp, u_char *palette)
496 {
497 	return (0);
498 }
499 
500 static int
501 am335x_syscons_load_palette(video_adapter_t *adp, u_char *palette)
502 {
503 	return (0);
504 }
505 
506 static int
507 am335x_syscons_set_border(video_adapter_t *adp, int border)
508 {
509 	return (am335x_syscons_blank_display(adp, border));
510 }
511 
512 static int
513 am335x_syscons_save_state(video_adapter_t *adp, void *p, size_t size)
514 {
515 	return (0);
516 }
517 
518 static int
519 am335x_syscons_load_state(video_adapter_t *adp, void *p)
520 {
521 	return (0);
522 }
523 
524 static int
525 am335x_syscons_set_win_org(video_adapter_t *adp, off_t offset)
526 {
527 	return (0);
528 }
529 
530 static int
531 am335x_syscons_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
532 {
533 	*col = *row = 0;
534 
535 	return (0);
536 }
537 
538 static int
539 am335x_syscons_set_hw_cursor(video_adapter_t *adp, int col, int row)
540 {
541 	return (0);
542 }
543 
544 static int
545 am335x_syscons_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
546     int celsize, int blink)
547 {
548 	return (0);
549 }
550 
551 static int
552 am335x_syscons_blank_display(video_adapter_t *adp, int mode)
553 {
554 
555 	struct video_adapter_softc *sc;
556 
557 	sc = (struct video_adapter_softc *)adp;
558 	if (sc && sc->fb_addr)
559 		memset((void*)sc->fb_addr, 0, sc->fb_size);
560 
561 	return (0);
562 }
563 
564 static int
565 am335x_syscons_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
566     int prot, vm_memattr_t *memattr)
567 {
568 	struct video_adapter_softc *sc;
569 
570 	sc = (struct video_adapter_softc *)adp;
571 
572 	/*
573 	 * This might be a legacy VGA mem request: if so, just point it at the
574 	 * framebuffer, since it shouldn't be touched
575 	 */
576 	if (offset < sc->stride*sc->height) {
577 		*paddr = sc->fb_paddr + offset;
578 		return (0);
579 	}
580 
581 	return (EINVAL);
582 }
583 
584 static int
585 am335x_syscons_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
586 {
587 	struct video_adapter_softc *sc;
588 	struct fbtype *fb;
589 
590 	sc = (struct video_adapter_softc *)adp;
591 
592 	switch (cmd) {
593 	case FBIOGTYPE:
594 		fb = (struct fbtype *)data;
595 		fb->fb_type = FBTYPE_PCIMISC;
596 		fb->fb_height = sc->height;
597 		fb->fb_width = sc->width;
598 		fb->fb_depth = sc->depth;
599 		if (sc->depth <= 1 || sc->depth > 8)
600 			fb->fb_cmsize = 0;
601 		else
602 			fb->fb_cmsize = 1 << sc->depth;
603 		fb->fb_size = sc->fb_size;
604 		break;
605 	default:
606 		return (fb_commonioctl(adp, cmd, data));
607 	}
608 
609 	return (0);
610 }
611 
612 static int
613 am335x_syscons_clear(video_adapter_t *adp)
614 {
615 
616 	return (am335x_syscons_blank_display(adp, 0));
617 }
618 
619 static int
620 am335x_syscons_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
621 {
622 
623 	return (0);
624 }
625 
626 static int
627 am335x_syscons_bitblt(video_adapter_t *adp, ...)
628 {
629 
630 	return (0);
631 }
632 
633 static int
634 am335x_syscons_diag(video_adapter_t *adp, int level)
635 {
636 
637 	return (0);
638 }
639 
640 static int
641 am335x_syscons_save_cursor_palette(video_adapter_t *adp, u_char *palette)
642 {
643 
644 	return (0);
645 }
646 
647 static int
648 am335x_syscons_load_cursor_palette(video_adapter_t *adp, u_char *palette)
649 {
650 
651 	return (0);
652 }
653 
654 static int
655 am335x_syscons_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
656 {
657 
658 	return (0);
659 }
660 
661 static int
662 am335x_syscons_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
663     int size, int bpp, int bit_ltor, int byte_ltor)
664 {
665 
666 	return (0);
667 }
668 
669 static int
670 am335x_syscons_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
671 {
672 	struct video_adapter_softc *sc;
673 	int row;
674 	int col;
675 	int i, j, k;
676 	uint8_t *addr;
677 	u_char *p;
678 	uint8_t fg, bg, color;
679 	uint16_t rgb;
680 
681 	sc = (struct video_adapter_softc *)adp;
682 
683 	if (sc->fb_addr == 0)
684 		return (0);
685 
686 	row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
687 	col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
688 	p = sc->font + c*AM335X_FONT_HEIGHT;
689 	addr = (uint8_t *)sc->fb_addr
690 	    + (row + sc->ymargin)*(sc->stride)
691 	    + (sc->depth/8) * (col + sc->xmargin);
692 
693 	fg = a & 0xf ;
694 	bg = (a >> 4) & 0xf;
695 
696 	for (i = 0; i < AM335X_FONT_HEIGHT; i++) {
697 		for (j = 0, k = 7; j < 8; j++, k--) {
698 			if ((p[i] & (1 << k)) == 0)
699 				color = bg;
700 			else
701 				color = fg;
702 
703 			switch (sc->depth) {
704 			case 32:
705 				addr[4*j+0] = am335x_syscons_palette[color].r;
706 				addr[4*j+1] = am335x_syscons_palette[color].g;
707 				addr[4*j+2] = am335x_syscons_palette[color].b;
708 				addr[4*j+3] = am335x_syscons_palette[color].a;
709 				break;
710 			case 24:
711 				addr[3*j] = am335x_syscons_palette[color].r;
712 				addr[3*j+1] = am335x_syscons_palette[color].g;
713 				addr[3*j+2] = am335x_syscons_palette[color].b;
714 				break;
715 			case 16:
716 				rgb = (am335x_syscons_palette[color].r >> 3) << 11;
717 				rgb |= (am335x_syscons_palette[color].g >> 2) << 5;
718 				rgb |= (am335x_syscons_palette[color].b >> 3);
719 				addr[2*j] = rgb & 0xff;
720 				addr[2*j + 1] = (rgb >> 8) & 0xff;
721 			default:
722 				/* Not supported yet */
723 				break;
724 			}
725 		}
726 
727 		addr += (sc->stride);
728 	}
729 
730         return (0);
731 }
732 
733 static int
734 am335x_syscons_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
735 {
736 	int i;
737 
738 	for (i = 0; i < len; i++)
739 		am335x_syscons_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
740 
741 	return (0);
742 }
743 
744 static int
745 am335x_syscons_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
746     uint32_t pixel_mask, int size, int width)
747 {
748 
749 	return (0);
750 }
751 
752 /* Initialization function */
753 int am335x_lcd_syscons_setup(vm_offset_t vaddr, vm_paddr_t paddr,
754     struct panel_info *panel)
755 {
756 	struct video_adapter_softc *va_sc = &va_softc;
757 
758 	va_sc->fb_addr = vaddr;
759 	va_sc->fb_paddr = paddr;
760 	va_sc->depth = panel->bpp;
761 	va_sc->stride = panel->bpp*panel->panel_width/8;
762 
763 	va_sc->width = panel->panel_width;
764 	va_sc->height = panel->panel_height;
765 	va_sc->fb_size = va_sc->width * va_sc->height
766 	    * va_sc->depth/8;
767 	am335x_syscons_update_margins(&va_sc->va);
768 
769 	return (0);
770 }
771 
772 /*
773  * Define a stub keyboard driver in case one hasn't been
774  * compiled into the kernel
775  */
776 #include <sys/kbio.h>
777 #include <dev/kbd/kbdreg.h>
778 
779 static int dummy_kbd_configure(int flags);
780 
781 keyboard_switch_t am335x_dummysw;
782 
783 static int
784 dummy_kbd_configure(int flags)
785 {
786 
787 	return (0);
788 }
789 KEYBOARD_DRIVER(am335x_dummy, am335x_dummysw, dummy_kbd_configure);
790