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