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