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