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