1251018Sgonzo/*- 2251018Sgonzo * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo@freebsd.org> 3251018Sgonzo * All rights reserved. 4251018Sgonzo * 5251018Sgonzo * Redistribution and use in source and binary forms, with or without 6251018Sgonzo * modification, are permitted provided that the following conditions 7251018Sgonzo * are met: 8251018Sgonzo * 1. Redistributions of source code must retain the above copyright 9251018Sgonzo * notice, this list of conditions and the following disclaimer. 10251018Sgonzo * 2. Redistributions in binary form must reproduce the above copyright 11251018Sgonzo * notice, this list of conditions and the following disclaimer in the 12251018Sgonzo * documentation and/or other materials provided with the distribution. 13251018Sgonzo * 14251018Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15251018Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16251018Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17251018Sgonzo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18251018Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19251018Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20251018Sgonzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21251018Sgonzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22251018Sgonzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23251018Sgonzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24251018Sgonzo * SUCH DAMAGE. 25251018Sgonzo */ 26251018Sgonzo#include <sys/cdefs.h> 27251018Sgonzo__FBSDID("$FreeBSD$"); 28251018Sgonzo 29251018Sgonzo#include <sys/param.h> 30251018Sgonzo#include <sys/systm.h> 31251018Sgonzo#include <sys/bus.h> 32251018Sgonzo#include <sys/conf.h> 33251018Sgonzo#include <sys/endian.h> 34251018Sgonzo#include <sys/kernel.h> 35251018Sgonzo#include <sys/lock.h> 36251018Sgonzo#include <sys/malloc.h> 37251018Sgonzo#include <sys/module.h> 38251018Sgonzo#include <sys/mutex.h> 39251018Sgonzo#include <sys/resource.h> 40251018Sgonzo#include <sys/rman.h> 41251018Sgonzo#include <sys/fbio.h> 42251018Sgonzo#include <sys/consio.h> 43251018Sgonzo 44251018Sgonzo#include <sys/kdb.h> 45251018Sgonzo 46251018Sgonzo#include <machine/bus.h> 47251018Sgonzo#include <machine/cpu.h> 48251018Sgonzo#include <machine/cpufunc.h> 49251018Sgonzo#include <machine/resource.h> 50251018Sgonzo#include <machine/intr.h> 51251018Sgonzo 52251018Sgonzo#include <dev/fdt/fdt_common.h> 53251018Sgonzo#include <dev/ofw/ofw_bus.h> 54251018Sgonzo#include <dev/ofw/ofw_bus_subr.h> 55251018Sgonzo 56251018Sgonzo#include <dev/fb/fbreg.h> 57251018Sgonzo#include <dev/syscons/syscons.h> 58251018Sgonzo 59251018Sgonzo#include "am335x_lcd.h" 60251018Sgonzo 61251018Sgonzostruct video_adapter_softc { 62251018Sgonzo /* Videoadpater part */ 63251018Sgonzo video_adapter_t va; 64251018Sgonzo int console; 65251018Sgonzo 66251018Sgonzo intptr_t fb_addr; 67251018Sgonzo intptr_t fb_paddr; 68251018Sgonzo unsigned int fb_size; 69251018Sgonzo 70251018Sgonzo unsigned int height; 71251018Sgonzo unsigned int width; 72251018Sgonzo unsigned int depth; 73251018Sgonzo unsigned int stride; 74251018Sgonzo 75251018Sgonzo unsigned int xmargin; 76251018Sgonzo unsigned int ymargin; 77251018Sgonzo 78251018Sgonzo unsigned char *font; 79251018Sgonzo int initialized; 80251018Sgonzo}; 81251018Sgonzo 82251018Sgonzostruct argb { 83251018Sgonzo uint8_t a; 84251018Sgonzo uint8_t r; 85251018Sgonzo uint8_t g; 86251018Sgonzo uint8_t b; 87251018Sgonzo}; 88251018Sgonzo 89251018Sgonzostatic struct argb am335x_syscons_palette[16] = { 90251018Sgonzo {0x00, 0x00, 0x00, 0x00}, 91251018Sgonzo {0x00, 0x00, 0x00, 0xaa}, 92251018Sgonzo {0x00, 0x00, 0xaa, 0x00}, 93251018Sgonzo {0x00, 0x00, 0xaa, 0xaa}, 94251018Sgonzo {0x00, 0xaa, 0x00, 0x00}, 95251018Sgonzo {0x00, 0xaa, 0x00, 0xaa}, 96251018Sgonzo {0x00, 0xaa, 0x55, 0x00}, 97251018Sgonzo {0x00, 0xaa, 0xaa, 0xaa}, 98251018Sgonzo {0x00, 0x55, 0x55, 0x55}, 99251018Sgonzo {0x00, 0x55, 0x55, 0xff}, 100251018Sgonzo {0x00, 0x55, 0xff, 0x55}, 101251018Sgonzo {0x00, 0x55, 0xff, 0xff}, 102251018Sgonzo {0x00, 0xff, 0x55, 0x55}, 103251018Sgonzo {0x00, 0xff, 0x55, 0xff}, 104251018Sgonzo {0x00, 0xff, 0xff, 0x55}, 105251018Sgonzo {0x00, 0xff, 0xff, 0xff} 106251018Sgonzo}; 107251018Sgonzo 108251018Sgonzo/* mouse pointer from dev/syscons/scgfbrndr.c */ 109251018Sgonzostatic u_char mouse_pointer[16] = { 110251018Sgonzo 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68, 111251018Sgonzo 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00 112251018Sgonzo}; 113251018Sgonzo 114251018Sgonzo#define AM335X_FONT_HEIGHT 16 115251018Sgonzo 116251018Sgonzo#define FB_WIDTH 640 117251018Sgonzo#define FB_HEIGHT 480 118251018Sgonzo#define FB_DEPTH 24 119251018Sgonzo 120251018Sgonzostatic struct video_adapter_softc va_softc; 121251018Sgonzo 122251018Sgonzostatic int am335x_syscons_configure(int flags); 123251018Sgonzo 124251018Sgonzo/* 125251018Sgonzo * Video driver routines and glue. 126251018Sgonzo */ 127251018Sgonzostatic vi_probe_t am335x_syscons_probe; 128251018Sgonzostatic vi_init_t am335x_syscons_init; 129251018Sgonzostatic vi_get_info_t am335x_syscons_get_info; 130251018Sgonzostatic vi_query_mode_t am335x_syscons_query_mode; 131251018Sgonzostatic vi_set_mode_t am335x_syscons_set_mode; 132251018Sgonzostatic vi_save_font_t am335x_syscons_save_font; 133251018Sgonzostatic vi_load_font_t am335x_syscons_load_font; 134251018Sgonzostatic vi_show_font_t am335x_syscons_show_font; 135251018Sgonzostatic vi_save_palette_t am335x_syscons_save_palette; 136251018Sgonzostatic vi_load_palette_t am335x_syscons_load_palette; 137251018Sgonzostatic vi_set_border_t am335x_syscons_set_border; 138251018Sgonzostatic vi_save_state_t am335x_syscons_save_state; 139251018Sgonzostatic vi_load_state_t am335x_syscons_load_state; 140251018Sgonzostatic vi_set_win_org_t am335x_syscons_set_win_org; 141251018Sgonzostatic vi_read_hw_cursor_t am335x_syscons_read_hw_cursor; 142251018Sgonzostatic vi_set_hw_cursor_t am335x_syscons_set_hw_cursor; 143251018Sgonzostatic vi_set_hw_cursor_shape_t am335x_syscons_set_hw_cursor_shape; 144251018Sgonzostatic vi_blank_display_t am335x_syscons_blank_display; 145251018Sgonzostatic vi_mmap_t am335x_syscons_mmap; 146251018Sgonzostatic vi_ioctl_t am335x_syscons_ioctl; 147251018Sgonzostatic vi_clear_t am335x_syscons_clear; 148251018Sgonzostatic vi_fill_rect_t am335x_syscons_fill_rect; 149251018Sgonzostatic vi_bitblt_t am335x_syscons_bitblt; 150251018Sgonzostatic vi_diag_t am335x_syscons_diag; 151251018Sgonzostatic vi_save_cursor_palette_t am335x_syscons_save_cursor_palette; 152251018Sgonzostatic vi_load_cursor_palette_t am335x_syscons_load_cursor_palette; 153251018Sgonzostatic vi_copy_t am335x_syscons_copy; 154251018Sgonzostatic vi_putp_t am335x_syscons_putp; 155251018Sgonzostatic vi_putc_t am335x_syscons_putc; 156251018Sgonzostatic vi_puts_t am335x_syscons_puts; 157251018Sgonzostatic vi_putm_t am335x_syscons_putm; 158251018Sgonzo 159251018Sgonzostatic video_switch_t am335x_sysconsvidsw = { 160251018Sgonzo .probe = am335x_syscons_probe, 161251018Sgonzo .init = am335x_syscons_init, 162251018Sgonzo .get_info = am335x_syscons_get_info, 163251018Sgonzo .query_mode = am335x_syscons_query_mode, 164251018Sgonzo .set_mode = am335x_syscons_set_mode, 165251018Sgonzo .save_font = am335x_syscons_save_font, 166251018Sgonzo .load_font = am335x_syscons_load_font, 167251018Sgonzo .show_font = am335x_syscons_show_font, 168251018Sgonzo .save_palette = am335x_syscons_save_palette, 169251018Sgonzo .load_palette = am335x_syscons_load_palette, 170251018Sgonzo .set_border = am335x_syscons_set_border, 171251018Sgonzo .save_state = am335x_syscons_save_state, 172251018Sgonzo .load_state = am335x_syscons_load_state, 173251018Sgonzo .set_win_org = am335x_syscons_set_win_org, 174251018Sgonzo .read_hw_cursor = am335x_syscons_read_hw_cursor, 175251018Sgonzo .set_hw_cursor = am335x_syscons_set_hw_cursor, 176251018Sgonzo .set_hw_cursor_shape = am335x_syscons_set_hw_cursor_shape, 177251018Sgonzo .blank_display = am335x_syscons_blank_display, 178251018Sgonzo .mmap = am335x_syscons_mmap, 179251018Sgonzo .ioctl = am335x_syscons_ioctl, 180251018Sgonzo .clear = am335x_syscons_clear, 181251018Sgonzo .fill_rect = am335x_syscons_fill_rect, 182251018Sgonzo .bitblt = am335x_syscons_bitblt, 183251018Sgonzo .diag = am335x_syscons_diag, 184251018Sgonzo .save_cursor_palette = am335x_syscons_save_cursor_palette, 185251018Sgonzo .load_cursor_palette = am335x_syscons_load_cursor_palette, 186251018Sgonzo .copy = am335x_syscons_copy, 187251018Sgonzo .putp = am335x_syscons_putp, 188251018Sgonzo .putc = am335x_syscons_putc, 189251018Sgonzo .puts = am335x_syscons_puts, 190251018Sgonzo .putm = am335x_syscons_putm, 191251018Sgonzo}; 192251018Sgonzo 193251018SgonzoVIDEO_DRIVER(am335x_syscons, am335x_sysconsvidsw, am335x_syscons_configure); 194251018Sgonzo 195251018Sgonzostatic vr_init_t am335x_rend_init; 196251018Sgonzostatic vr_clear_t am335x_rend_clear; 197251018Sgonzostatic vr_draw_border_t am335x_rend_draw_border; 198251018Sgonzostatic vr_draw_t am335x_rend_draw; 199251018Sgonzostatic vr_set_cursor_t am335x_rend_set_cursor; 200251018Sgonzostatic vr_draw_cursor_t am335x_rend_draw_cursor; 201251018Sgonzostatic vr_blink_cursor_t am335x_rend_blink_cursor; 202251018Sgonzostatic vr_set_mouse_t am335x_rend_set_mouse; 203251018Sgonzostatic vr_draw_mouse_t am335x_rend_draw_mouse; 204251018Sgonzo 205251018Sgonzo/* 206251018Sgonzo * We use our own renderer; this is because we must emulate a hardware 207251018Sgonzo * cursor. 208251018Sgonzo */ 209251018Sgonzostatic sc_rndr_sw_t am335x_rend = { 210251018Sgonzo am335x_rend_init, 211251018Sgonzo am335x_rend_clear, 212251018Sgonzo am335x_rend_draw_border, 213251018Sgonzo am335x_rend_draw, 214251018Sgonzo am335x_rend_set_cursor, 215251018Sgonzo am335x_rend_draw_cursor, 216251018Sgonzo am335x_rend_blink_cursor, 217251018Sgonzo am335x_rend_set_mouse, 218251018Sgonzo am335x_rend_draw_mouse 219251018Sgonzo}; 220251018Sgonzo 221251018SgonzoRENDERER(am335x_syscons, 0, am335x_rend, gfb_set); 222251018SgonzoRENDERER_MODULE(am335x_syscons, gfb_set); 223251018Sgonzo 224251018Sgonzostatic void 225251018Sgonzoam335x_rend_init(scr_stat* scp) 226251018Sgonzo{ 227251018Sgonzo} 228251018Sgonzo 229251018Sgonzostatic void 230251018Sgonzoam335x_rend_clear(scr_stat* scp, int c, int attr) 231251018Sgonzo{ 232251018Sgonzo} 233251018Sgonzo 234251018Sgonzostatic void 235251018Sgonzoam335x_rend_draw_border(scr_stat* scp, int color) 236251018Sgonzo{ 237251018Sgonzo} 238251018Sgonzo 239251018Sgonzostatic void 240251018Sgonzoam335x_rend_draw(scr_stat* scp, int from, int count, int flip) 241251018Sgonzo{ 242251018Sgonzo video_adapter_t* adp = scp->sc->adp; 243251018Sgonzo int i, c, a; 244251018Sgonzo 245251018Sgonzo if (!flip) { 246251018Sgonzo /* Normal printing */ 247251018Sgonzo vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count); 248251018Sgonzo } else { 249251018Sgonzo /* This is for selections and such: invert the color attribute */ 250251018Sgonzo for (i = count; i-- > 0; ++from) { 251251018Sgonzo c = sc_vtb_getc(&scp->vtb, from); 252251018Sgonzo a = sc_vtb_geta(&scp->vtb, from) >> 8; 253251018Sgonzo vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); 254251018Sgonzo } 255251018Sgonzo } 256251018Sgonzo} 257251018Sgonzo 258251018Sgonzostatic void 259251018Sgonzoam335x_rend_set_cursor(scr_stat* scp, int base, int height, int blink) 260251018Sgonzo{ 261251018Sgonzo} 262251018Sgonzo 263251018Sgonzostatic void 264251018Sgonzoam335x_rend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip) 265251018Sgonzo{ 266251018Sgonzo video_adapter_t* adp = scp->sc->adp; 267251018Sgonzo struct video_adapter_softc *sc; 268251018Sgonzo int row, col; 269251018Sgonzo uint8_t *addr; 270251018Sgonzo int i, j, bytes; 271251018Sgonzo 272251018Sgonzo sc = (struct video_adapter_softc *)adp; 273251018Sgonzo 274251018Sgonzo if (scp->curs_attr.height <= 0) 275251018Sgonzo return; 276251018Sgonzo 277251018Sgonzo if (sc->fb_addr == 0) 278251018Sgonzo return; 279251018Sgonzo 280251018Sgonzo if (off >= adp->va_info.vi_width * adp->va_info.vi_height) 281251018Sgonzo return; 282251018Sgonzo 283251018Sgonzo /* calculate the coordinates in the video buffer */ 284251018Sgonzo row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 285251018Sgonzo col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 286251018Sgonzo 287251018Sgonzo addr = (uint8_t *)sc->fb_addr 288251018Sgonzo + (row + sc->ymargin)*(sc->stride) 289251018Sgonzo + (sc->depth/8) * (col + sc->xmargin); 290251018Sgonzo 291251018Sgonzo bytes = sc->depth/8; 292251018Sgonzo 293251018Sgonzo /* our cursor consists of simply inverting the char under it */ 294251018Sgonzo for (i = 0; i < adp->va_info.vi_cheight; i++) { 295251018Sgonzo for (j = 0; j < adp->va_info.vi_cwidth; j++) { 296251018Sgonzo switch (sc->depth) { 297251018Sgonzo case 32: 298251018Sgonzo case 24: 299251018Sgonzo addr[bytes*j + 2] ^= 0xff; 300251018Sgonzo /* FALLTHROUGH */ 301251018Sgonzo case 16: 302251018Sgonzo addr[bytes*j + 1] ^= 0xff; 303251018Sgonzo addr[bytes*j] ^= 0xff; 304251018Sgonzo break; 305251018Sgonzo default: 306251018Sgonzo break; 307251018Sgonzo } 308251018Sgonzo } 309251018Sgonzo 310251018Sgonzo addr += sc->stride; 311251018Sgonzo } 312251018Sgonzo} 313251018Sgonzo 314251018Sgonzostatic void 315251018Sgonzoam335x_rend_blink_cursor(scr_stat* scp, int at, int flip) 316251018Sgonzo{ 317251018Sgonzo} 318251018Sgonzo 319251018Sgonzostatic void 320251018Sgonzoam335x_rend_set_mouse(scr_stat* scp) 321251018Sgonzo{ 322251018Sgonzo} 323251018Sgonzo 324251018Sgonzostatic void 325251018Sgonzoam335x_rend_draw_mouse(scr_stat* scp, int x, int y, int on) 326251018Sgonzo{ 327251018Sgonzo vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8); 328251018Sgonzo} 329251018Sgonzo 330251018Sgonzostatic uint16_t am335x_syscons_static_window[ROW*COL]; 331251018Sgonzoextern u_char dflt_font_16[]; 332251018Sgonzo 333251018Sgonzo/* 334251018Sgonzo * Update videoadapter settings after changing resolution 335251018Sgonzo */ 336251018Sgonzostatic void 337251018Sgonzoam335x_syscons_update_margins(video_adapter_t *adp) 338251018Sgonzo{ 339251018Sgonzo struct video_adapter_softc *sc; 340251018Sgonzo video_info_t *vi; 341251018Sgonzo 342251018Sgonzo sc = (struct video_adapter_softc *)adp; 343251018Sgonzo vi = &adp->va_info; 344251018Sgonzo 345251018Sgonzo sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 346251018Sgonzo sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; 347251018Sgonzo} 348251018Sgonzo 349251018Sgonzostatic phandle_t 350251018Sgonzoam335x_syscons_find_panel_node(phandle_t start) 351251018Sgonzo{ 352251018Sgonzo phandle_t child; 353251018Sgonzo phandle_t result; 354251018Sgonzo 355251018Sgonzo for (child = OF_child(start); child != 0; child = OF_peer(child)) { 356251018Sgonzo if (fdt_is_compatible(child, "ti,am335x-lcd")) 357251018Sgonzo return (child); 358251018Sgonzo if ((result = am335x_syscons_find_panel_node(child))) 359251018Sgonzo return (result); 360251018Sgonzo } 361251018Sgonzo 362251018Sgonzo return (0); 363251018Sgonzo} 364251018Sgonzo 365251018Sgonzostatic int 366251018Sgonzoam335x_syscons_configure(int flags) 367251018Sgonzo{ 368251018Sgonzo struct video_adapter_softc *va_sc; 369251018Sgonzo 370251018Sgonzo va_sc = &va_softc; 371251018Sgonzo phandle_t display, root; 372251018Sgonzo pcell_t cell; 373251018Sgonzo 374251018Sgonzo if (va_sc->initialized) 375251018Sgonzo return (0); 376251018Sgonzo 377251018Sgonzo va_sc->width = 0; 378251018Sgonzo va_sc->height = 0; 379251018Sgonzo 380251018Sgonzo /* 381251018Sgonzo * It seems there is no way to let syscons framework know 382251018Sgonzo * that framebuffer resolution has changed. So just try 383251018Sgonzo * to fetch data from FDT and go with defaults if failed 384251018Sgonzo */ 385251018Sgonzo root = OF_finddevice("/"); 386251018Sgonzo if ((root != 0) && 387251018Sgonzo (display = am335x_syscons_find_panel_node(root))) { 388251018Sgonzo if ((OF_getprop(display, "panel_width", 389251018Sgonzo &cell, sizeof(cell))) > 0) 390251018Sgonzo va_sc->width = (int)fdt32_to_cpu(cell); 391251018Sgonzo 392251018Sgonzo if ((OF_getprop(display, "panel_height", 393251018Sgonzo &cell, sizeof(cell))) > 0) 394251018Sgonzo va_sc->height = (int)fdt32_to_cpu(cell); 395251018Sgonzo } 396251018Sgonzo 397251018Sgonzo if (va_sc->width == 0) 398251018Sgonzo va_sc->width = FB_WIDTH; 399251018Sgonzo if (va_sc->height == 0) 400251018Sgonzo va_sc->height = FB_HEIGHT; 401251018Sgonzo 402251018Sgonzo am335x_syscons_init(0, &va_sc->va, 0); 403251018Sgonzo 404251018Sgonzo va_sc->initialized = 1; 405251018Sgonzo 406251018Sgonzo return (0); 407251018Sgonzo} 408251018Sgonzo 409251018Sgonzostatic int 410251018Sgonzoam335x_syscons_probe(int unit, video_adapter_t **adp, void *arg, int flags) 411251018Sgonzo{ 412251018Sgonzo 413251018Sgonzo return (0); 414251018Sgonzo} 415251018Sgonzo 416251018Sgonzostatic int 417251018Sgonzoam335x_syscons_init(int unit, video_adapter_t *adp, int flags) 418251018Sgonzo{ 419251018Sgonzo struct video_adapter_softc *sc; 420251018Sgonzo video_info_t *vi; 421251018Sgonzo 422251018Sgonzo sc = (struct video_adapter_softc *)adp; 423251018Sgonzo vi = &adp->va_info; 424251018Sgonzo 425251018Sgonzo vid_init_struct(adp, "am335x_syscons", -1, unit); 426251018Sgonzo 427251018Sgonzo sc->font = dflt_font_16; 428251018Sgonzo vi->vi_cheight = AM335X_FONT_HEIGHT; 429251018Sgonzo vi->vi_cwidth = 8; 430251018Sgonzo 431251018Sgonzo vi->vi_width = sc->width/8; 432251018Sgonzo vi->vi_height = sc->height/vi->vi_cheight; 433251018Sgonzo 434251018Sgonzo /* 435251018Sgonzo * Clamp width/height to syscons maximums 436251018Sgonzo */ 437251018Sgonzo if (vi->vi_width > COL) 438251018Sgonzo vi->vi_width = COL; 439251018Sgonzo if (vi->vi_height > ROW) 440251018Sgonzo vi->vi_height = ROW; 441251018Sgonzo 442251018Sgonzo sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 443251018Sgonzo sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; 444251018Sgonzo 445251018Sgonzo 446251018Sgonzo adp->va_window = (vm_offset_t) am335x_syscons_static_window; 447251018Sgonzo adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; 448251018Sgonzo 449251018Sgonzo vid_register(&sc->va); 450251018Sgonzo 451251018Sgonzo return (0); 452251018Sgonzo} 453251018Sgonzo 454251018Sgonzostatic int 455251018Sgonzoam335x_syscons_get_info(video_adapter_t *adp, int mode, video_info_t *info) 456251018Sgonzo{ 457251018Sgonzo bcopy(&adp->va_info, info, sizeof(*info)); 458251018Sgonzo return (0); 459251018Sgonzo} 460251018Sgonzo 461251018Sgonzostatic int 462251018Sgonzoam335x_syscons_query_mode(video_adapter_t *adp, video_info_t *info) 463251018Sgonzo{ 464251018Sgonzo return (0); 465251018Sgonzo} 466251018Sgonzo 467251018Sgonzostatic int 468251018Sgonzoam335x_syscons_set_mode(video_adapter_t *adp, int mode) 469251018Sgonzo{ 470251018Sgonzo return (0); 471251018Sgonzo} 472251018Sgonzo 473251018Sgonzostatic int 474251018Sgonzoam335x_syscons_save_font(video_adapter_t *adp, int page, int size, int width, 475251018Sgonzo u_char *data, int c, int count) 476251018Sgonzo{ 477251018Sgonzo return (0); 478251018Sgonzo} 479251018Sgonzo 480251018Sgonzostatic int 481251018Sgonzoam335x_syscons_load_font(video_adapter_t *adp, int page, int size, int width, 482251018Sgonzo u_char *data, int c, int count) 483251018Sgonzo{ 484251018Sgonzo struct video_adapter_softc *sc = (struct video_adapter_softc *)adp; 485251018Sgonzo 486251018Sgonzo sc->font = data; 487251018Sgonzo 488251018Sgonzo return (0); 489251018Sgonzo} 490251018Sgonzo 491251018Sgonzostatic int 492251018Sgonzoam335x_syscons_show_font(video_adapter_t *adp, int page) 493251018Sgonzo{ 494251018Sgonzo return (0); 495251018Sgonzo} 496251018Sgonzo 497251018Sgonzostatic int 498251018Sgonzoam335x_syscons_save_palette(video_adapter_t *adp, u_char *palette) 499251018Sgonzo{ 500251018Sgonzo return (0); 501251018Sgonzo} 502251018Sgonzo 503251018Sgonzostatic int 504251018Sgonzoam335x_syscons_load_palette(video_adapter_t *adp, u_char *palette) 505251018Sgonzo{ 506251018Sgonzo return (0); 507251018Sgonzo} 508251018Sgonzo 509251018Sgonzostatic int 510251018Sgonzoam335x_syscons_set_border(video_adapter_t *adp, int border) 511251018Sgonzo{ 512251018Sgonzo return (am335x_syscons_blank_display(adp, border)); 513251018Sgonzo} 514251018Sgonzo 515251018Sgonzostatic int 516251018Sgonzoam335x_syscons_save_state(video_adapter_t *adp, void *p, size_t size) 517251018Sgonzo{ 518251018Sgonzo return (0); 519251018Sgonzo} 520251018Sgonzo 521251018Sgonzostatic int 522251018Sgonzoam335x_syscons_load_state(video_adapter_t *adp, void *p) 523251018Sgonzo{ 524251018Sgonzo return (0); 525251018Sgonzo} 526251018Sgonzo 527251018Sgonzostatic int 528251018Sgonzoam335x_syscons_set_win_org(video_adapter_t *adp, off_t offset) 529251018Sgonzo{ 530251018Sgonzo return (0); 531251018Sgonzo} 532251018Sgonzo 533251018Sgonzostatic int 534251018Sgonzoam335x_syscons_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 535251018Sgonzo{ 536251018Sgonzo *col = *row = 0; 537251018Sgonzo 538251018Sgonzo return (0); 539251018Sgonzo} 540251018Sgonzo 541251018Sgonzostatic int 542251018Sgonzoam335x_syscons_set_hw_cursor(video_adapter_t *adp, int col, int row) 543251018Sgonzo{ 544251018Sgonzo return (0); 545251018Sgonzo} 546251018Sgonzo 547251018Sgonzostatic int 548251018Sgonzoam335x_syscons_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 549251018Sgonzo int celsize, int blink) 550251018Sgonzo{ 551251018Sgonzo return (0); 552251018Sgonzo} 553251018Sgonzo 554251018Sgonzostatic int 555251018Sgonzoam335x_syscons_blank_display(video_adapter_t *adp, int mode) 556251018Sgonzo{ 557251018Sgonzo 558251018Sgonzo struct video_adapter_softc *sc; 559251018Sgonzo 560251018Sgonzo sc = (struct video_adapter_softc *)adp; 561251018Sgonzo if (sc && sc->fb_addr) 562251018Sgonzo memset((void*)sc->fb_addr, 0, sc->fb_size); 563251018Sgonzo 564251018Sgonzo return (0); 565251018Sgonzo} 566251018Sgonzo 567251018Sgonzostatic int 568251018Sgonzoam335x_syscons_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, 569251018Sgonzo int prot, vm_memattr_t *memattr) 570251018Sgonzo{ 571251018Sgonzo struct video_adapter_softc *sc; 572251018Sgonzo 573251018Sgonzo sc = (struct video_adapter_softc *)adp; 574251018Sgonzo 575251018Sgonzo /* 576251018Sgonzo * This might be a legacy VGA mem request: if so, just point it at the 577251018Sgonzo * framebuffer, since it shouldn't be touched 578251018Sgonzo */ 579251018Sgonzo if (offset < sc->stride*sc->height) { 580251018Sgonzo *paddr = sc->fb_paddr + offset; 581251018Sgonzo return (0); 582251018Sgonzo } 583251018Sgonzo 584251018Sgonzo return (EINVAL); 585251018Sgonzo} 586251018Sgonzo 587251018Sgonzostatic int 588251018Sgonzoam335x_syscons_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 589251018Sgonzo{ 590251018Sgonzo struct video_adapter_softc *sc; 591251018Sgonzo struct fbtype *fb; 592251018Sgonzo 593251018Sgonzo sc = (struct video_adapter_softc *)adp; 594251018Sgonzo 595251018Sgonzo switch (cmd) { 596251018Sgonzo case FBIOGTYPE: 597251018Sgonzo fb = (struct fbtype *)data; 598251018Sgonzo fb->fb_type = FBTYPE_PCIMISC; 599251018Sgonzo fb->fb_height = sc->height; 600251018Sgonzo fb->fb_width = sc->width; 601251018Sgonzo fb->fb_depth = sc->depth; 602251018Sgonzo if (sc->depth <= 1 || sc->depth > 8) 603251018Sgonzo fb->fb_cmsize = 0; 604251018Sgonzo else 605251018Sgonzo fb->fb_cmsize = 1 << sc->depth; 606251018Sgonzo fb->fb_size = sc->fb_size; 607251018Sgonzo break; 608251018Sgonzo default: 609251018Sgonzo return (fb_commonioctl(adp, cmd, data)); 610251018Sgonzo } 611251018Sgonzo 612251018Sgonzo return (0); 613251018Sgonzo} 614251018Sgonzo 615251018Sgonzostatic int 616251018Sgonzoam335x_syscons_clear(video_adapter_t *adp) 617251018Sgonzo{ 618251018Sgonzo 619251018Sgonzo return (am335x_syscons_blank_display(adp, 0)); 620251018Sgonzo} 621251018Sgonzo 622251018Sgonzostatic int 623251018Sgonzoam335x_syscons_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 624251018Sgonzo{ 625251018Sgonzo 626251018Sgonzo return (0); 627251018Sgonzo} 628251018Sgonzo 629251018Sgonzostatic int 630251018Sgonzoam335x_syscons_bitblt(video_adapter_t *adp, ...) 631251018Sgonzo{ 632251018Sgonzo 633251018Sgonzo return (0); 634251018Sgonzo} 635251018Sgonzo 636251018Sgonzostatic int 637251018Sgonzoam335x_syscons_diag(video_adapter_t *adp, int level) 638251018Sgonzo{ 639251018Sgonzo 640251018Sgonzo return (0); 641251018Sgonzo} 642251018Sgonzo 643251018Sgonzostatic int 644251018Sgonzoam335x_syscons_save_cursor_palette(video_adapter_t *adp, u_char *palette) 645251018Sgonzo{ 646251018Sgonzo 647251018Sgonzo return (0); 648251018Sgonzo} 649251018Sgonzo 650251018Sgonzostatic int 651251018Sgonzoam335x_syscons_load_cursor_palette(video_adapter_t *adp, u_char *palette) 652251018Sgonzo{ 653251018Sgonzo 654251018Sgonzo return (0); 655251018Sgonzo} 656251018Sgonzo 657251018Sgonzostatic int 658251018Sgonzoam335x_syscons_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 659251018Sgonzo{ 660251018Sgonzo 661251018Sgonzo return (0); 662251018Sgonzo} 663251018Sgonzo 664251018Sgonzostatic int 665251018Sgonzoam335x_syscons_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 666251018Sgonzo int size, int bpp, int bit_ltor, int byte_ltor) 667251018Sgonzo{ 668251018Sgonzo 669251018Sgonzo return (0); 670251018Sgonzo} 671251018Sgonzo 672251018Sgonzostatic int 673251018Sgonzoam335x_syscons_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 674251018Sgonzo{ 675251018Sgonzo struct video_adapter_softc *sc; 676251018Sgonzo int row; 677251018Sgonzo int col; 678251018Sgonzo int i, j, k; 679251018Sgonzo uint8_t *addr; 680251018Sgonzo u_char *p; 681251018Sgonzo uint8_t fg, bg, color; 682251018Sgonzo uint16_t rgb; 683251018Sgonzo 684251018Sgonzo sc = (struct video_adapter_softc *)adp; 685251018Sgonzo 686251018Sgonzo if (sc->fb_addr == 0) 687251018Sgonzo return (0); 688251018Sgonzo 689251018Sgonzo row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 690251018Sgonzo col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 691251018Sgonzo p = sc->font + c*AM335X_FONT_HEIGHT; 692251018Sgonzo addr = (uint8_t *)sc->fb_addr 693251018Sgonzo + (row + sc->ymargin)*(sc->stride) 694251018Sgonzo + (sc->depth/8) * (col + sc->xmargin); 695251018Sgonzo 696251018Sgonzo fg = a & 0xf ; 697251018Sgonzo bg = (a >> 4) & 0xf; 698251018Sgonzo 699251018Sgonzo for (i = 0; i < AM335X_FONT_HEIGHT; i++) { 700251018Sgonzo for (j = 0, k = 7; j < 8; j++, k--) { 701251018Sgonzo if ((p[i] & (1 << k)) == 0) 702251018Sgonzo color = bg; 703251018Sgonzo else 704251018Sgonzo color = fg; 705251018Sgonzo 706251018Sgonzo switch (sc->depth) { 707251018Sgonzo case 32: 708251018Sgonzo addr[4*j+0] = am335x_syscons_palette[color].r; 709251018Sgonzo addr[4*j+1] = am335x_syscons_palette[color].g; 710251018Sgonzo addr[4*j+2] = am335x_syscons_palette[color].b; 711251018Sgonzo addr[4*j+3] = am335x_syscons_palette[color].a; 712251018Sgonzo break; 713251018Sgonzo case 24: 714251018Sgonzo addr[3*j] = am335x_syscons_palette[color].r; 715251018Sgonzo addr[3*j+1] = am335x_syscons_palette[color].g; 716251018Sgonzo addr[3*j+2] = am335x_syscons_palette[color].b; 717251018Sgonzo break; 718251018Sgonzo case 16: 719251018Sgonzo rgb = (am335x_syscons_palette[color].r >> 3) << 11; 720251018Sgonzo rgb |= (am335x_syscons_palette[color].g >> 2) << 5; 721251018Sgonzo rgb |= (am335x_syscons_palette[color].b >> 3); 722251018Sgonzo addr[2*j] = rgb & 0xff; 723251018Sgonzo addr[2*j + 1] = (rgb >> 8) & 0xff; 724251018Sgonzo default: 725251018Sgonzo /* Not supported yet */ 726251018Sgonzo break; 727251018Sgonzo } 728251018Sgonzo } 729251018Sgonzo 730251018Sgonzo addr += (sc->stride); 731251018Sgonzo } 732251018Sgonzo 733251018Sgonzo return (0); 734251018Sgonzo} 735251018Sgonzo 736251018Sgonzostatic int 737251018Sgonzoam335x_syscons_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 738251018Sgonzo{ 739251018Sgonzo int i; 740251018Sgonzo 741251018Sgonzo for (i = 0; i < len; i++) 742251018Sgonzo am335x_syscons_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 743251018Sgonzo 744251018Sgonzo return (0); 745251018Sgonzo} 746251018Sgonzo 747251018Sgonzostatic int 748251018Sgonzoam335x_syscons_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 749251018Sgonzo uint32_t pixel_mask, int size, int width) 750251018Sgonzo{ 751251018Sgonzo 752251018Sgonzo return (0); 753251018Sgonzo} 754251018Sgonzo 755251018Sgonzo/* Initialization function */ 756251018Sgonzoint am335x_lcd_syscons_setup(vm_offset_t vaddr, vm_paddr_t paddr, 757251018Sgonzo struct panel_info *panel) 758251018Sgonzo{ 759251018Sgonzo struct video_adapter_softc *va_sc = &va_softc; 760251018Sgonzo 761251018Sgonzo va_sc->fb_addr = vaddr; 762251018Sgonzo va_sc->fb_paddr = paddr; 763251018Sgonzo va_sc->depth = panel->bpp; 764251018Sgonzo va_sc->stride = panel->bpp*panel->panel_width/8; 765251018Sgonzo 766251018Sgonzo va_sc->width = panel->panel_width; 767251018Sgonzo va_sc->height = panel->panel_height; 768251018Sgonzo va_sc->fb_size = va_sc->width * va_sc->height 769251018Sgonzo * va_sc->depth/8; 770251018Sgonzo am335x_syscons_update_margins(&va_sc->va); 771251018Sgonzo 772251018Sgonzo return (0); 773251018Sgonzo} 774251018Sgonzo 775251018Sgonzo/* 776251018Sgonzo * Define a stub keyboard driver in case one hasn't been 777251018Sgonzo * compiled into the kernel 778251018Sgonzo */ 779251018Sgonzo#include <sys/kbio.h> 780251018Sgonzo#include <dev/kbd/kbdreg.h> 781251018Sgonzo 782251018Sgonzostatic int dummy_kbd_configure(int flags); 783251018Sgonzo 784251018Sgonzokeyboard_switch_t am335x_dummysw; 785251018Sgonzo 786251018Sgonzostatic int 787251018Sgonzodummy_kbd_configure(int flags) 788251018Sgonzo{ 789251018Sgonzo 790251018Sgonzo return (0); 791251018Sgonzo} 792251018SgonzoKEYBOARD_DRIVER(am335x_dummy, am335x_dummysw, dummy_kbd_configure); 793