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