1 /*- 2 * Copyright (c) 2012 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 */ 27 #include <sys/cdefs.h> 28 __FBSDID("$FreeBSD$"); 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/bus.h> 33 #include <sys/consio.h> 34 #include <sys/fbio.h> 35 #include <sys/kdb.h> 36 #include <sys/kernel.h> 37 #include <sys/malloc.h> 38 #include <sys/module.h> 39 40 #include <vm/vm.h> 41 #include <vm/pmap.h> 42 43 #include <dev/fb/fbreg.h> 44 #include <dev/fdt/fdt_common.h> 45 #include <dev/ofw/ofw_bus.h> 46 #include <dev/ofw/ofw_bus_subr.h> 47 #include <dev/syscons/syscons.h> 48 49 #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h> 50 51 #include "mbox_if.h" 52 53 struct argb { 54 uint8_t a; 55 uint8_t r; 56 uint8_t g; 57 uint8_t b; 58 }; 59 60 static struct argb bcmfb_palette[16] = { 61 {0x00, 0x00, 0x00, 0x00}, 62 {0x00, 0x00, 0x00, 0xaa}, 63 {0x00, 0x00, 0xaa, 0x00}, 64 {0x00, 0x00, 0xaa, 0xaa}, 65 {0x00, 0xaa, 0x00, 0x00}, 66 {0x00, 0xaa, 0x00, 0xaa}, 67 {0x00, 0xaa, 0x55, 0x00}, 68 {0x00, 0xaa, 0xaa, 0xaa}, 69 {0x00, 0x55, 0x55, 0x55}, 70 {0x00, 0x55, 0x55, 0xff}, 71 {0x00, 0x55, 0xff, 0x55}, 72 {0x00, 0x55, 0xff, 0xff}, 73 {0x00, 0xff, 0x55, 0x55}, 74 {0x00, 0xff, 0x55, 0xff}, 75 {0x00, 0xff, 0xff, 0x55}, 76 {0x00, 0xff, 0xff, 0xff} 77 }; 78 79 /* mouse pointer from dev/syscons/scgfbrndr.c */ 80 static u_char mouse_pointer[16] = { 81 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68, 82 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00 83 }; 84 85 #define BCMFB_FONT_HEIGHT 16 86 #define BCMFB_FONT_WIDTH 8 87 #define FB_WIDTH 640 88 #define FB_HEIGHT 480 89 #define FB_DEPTH 24 90 91 struct bcmsc_softc { 92 /* Videoadpater part */ 93 video_adapter_t va; 94 95 intptr_t fb_addr; 96 intptr_t fb_paddr; 97 unsigned int fb_size; 98 99 unsigned int height; 100 unsigned int width; 101 unsigned int depth; 102 unsigned int stride; 103 104 unsigned int xmargin; 105 unsigned int ymargin; 106 107 unsigned char *font; 108 int fbswap; 109 int initialized; 110 }; 111 112 static struct bcmsc_softc bcmsc; 113 114 static int bcm_fb_probe(device_t); 115 static int bcm_fb_attach(device_t); 116 static void bcmfb_update_margins(video_adapter_t *adp); 117 static int bcmfb_configure(int); 118 119 static int 120 bcm_fb_probe(device_t dev) 121 { 122 int error; 123 124 if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb")) 125 return (ENXIO); 126 device_set_desc(dev, "BCM2835 framebuffer device"); 127 error = sc_probe_unit(device_get_unit(dev), 128 device_get_flags(dev) | SC_AUTODETECT_KBD); 129 if (error != 0) 130 return (error); 131 132 return (BUS_PROBE_DEFAULT); 133 } 134 135 static int 136 bcm_fb_attach(device_t dev) 137 { 138 struct bcm2835_fb_config fb; 139 struct bcmsc_softc *sc; 140 141 sc = (struct bcmsc_softc *)vid_get_adapter(vid_find_adapter( 142 "bcmfb", 0)); 143 if (sc != NULL) 144 device_set_softc(dev, sc); 145 else 146 sc = device_get_softc(dev); 147 148 memset(&fb, 0, sizeof(fb)); 149 if (bcm2835_mbox_fb_get_w_h(&fb) != 0) 150 return (ENXIO); 151 fb.bpp = FB_DEPTH; 152 fb.vxres = fb.xres; 153 fb.vyres = fb.yres; 154 fb.xoffset = fb.yoffset = 0; 155 if (bcm2835_mbox_fb_init(&fb) != 0) 156 return (ENXIO); 157 158 sc->fb_addr = (intptr_t)pmap_mapdev(fb.base, fb.size); 159 sc->fb_paddr = fb.base; 160 sc->fb_size = fb.size; 161 sc->depth = fb.bpp; 162 sc->stride = fb.pitch; 163 sc->width = fb.xres; 164 sc->height = fb.yres; 165 bcmfb_update_margins(&sc->va); 166 167 if (sc_attach_unit(device_get_unit(dev), 168 device_get_flags(dev) | SC_AUTODETECT_KBD) != 0) { 169 device_printf(dev, "failed to attach syscons\n"); 170 return (ENXIO); 171 } 172 173 device_printf(dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", fb.xres, fb.yres, 174 fb.vxres, fb.vyres, fb.xoffset, fb.yoffset, fb.bpp); 175 device_printf(dev, 176 "fbswap: %d, pitch %d, base 0x%08x, screen_size %d\n", 177 sc->fbswap, fb.pitch, fb.base, fb.size); 178 179 return (0); 180 } 181 182 static device_method_t bcm_fb_methods[] = { 183 /* Device interface */ 184 DEVMETHOD(device_probe, bcm_fb_probe), 185 DEVMETHOD(device_attach, bcm_fb_attach), 186 187 { 0, 0 } 188 }; 189 190 static devclass_t bcm_fb_devclass; 191 192 static driver_t bcm_fb_driver = { 193 "fb", 194 bcm_fb_methods, 195 sizeof(struct bcmsc_softc), 196 }; 197 198 DRIVER_MODULE(bcm2835fb, ofwbus, bcm_fb_driver, bcm_fb_devclass, 0, 0); 199 200 /* 201 * Video driver routines and glue. 202 */ 203 static vi_probe_t bcmfb_probe; 204 static vi_init_t bcmfb_init; 205 static vi_get_info_t bcmfb_get_info; 206 static vi_query_mode_t bcmfb_query_mode; 207 static vi_set_mode_t bcmfb_set_mode; 208 static vi_save_font_t bcmfb_save_font; 209 static vi_load_font_t bcmfb_load_font; 210 static vi_show_font_t bcmfb_show_font; 211 static vi_save_palette_t bcmfb_save_palette; 212 static vi_load_palette_t bcmfb_load_palette; 213 static vi_set_border_t bcmfb_set_border; 214 static vi_save_state_t bcmfb_save_state; 215 static vi_load_state_t bcmfb_load_state; 216 static vi_set_win_org_t bcmfb_set_win_org; 217 static vi_read_hw_cursor_t bcmfb_read_hw_cursor; 218 static vi_set_hw_cursor_t bcmfb_set_hw_cursor; 219 static vi_set_hw_cursor_shape_t bcmfb_set_hw_cursor_shape; 220 static vi_blank_display_t bcmfb_blank_display; 221 static vi_mmap_t bcmfb_mmap; 222 static vi_ioctl_t bcmfb_ioctl; 223 static vi_clear_t bcmfb_clear; 224 static vi_fill_rect_t bcmfb_fill_rect; 225 static vi_bitblt_t bcmfb_bitblt; 226 static vi_diag_t bcmfb_diag; 227 static vi_save_cursor_palette_t bcmfb_save_cursor_palette; 228 static vi_load_cursor_palette_t bcmfb_load_cursor_palette; 229 static vi_copy_t bcmfb_copy; 230 static vi_putp_t bcmfb_putp; 231 static vi_putc_t bcmfb_putc; 232 static vi_puts_t bcmfb_puts; 233 static vi_putm_t bcmfb_putm; 234 235 static video_switch_t bcmfbvidsw = { 236 .probe = bcmfb_probe, 237 .init = bcmfb_init, 238 .get_info = bcmfb_get_info, 239 .query_mode = bcmfb_query_mode, 240 .set_mode = bcmfb_set_mode, 241 .save_font = bcmfb_save_font, 242 .load_font = bcmfb_load_font, 243 .show_font = bcmfb_show_font, 244 .save_palette = bcmfb_save_palette, 245 .load_palette = bcmfb_load_palette, 246 .set_border = bcmfb_set_border, 247 .save_state = bcmfb_save_state, 248 .load_state = bcmfb_load_state, 249 .set_win_org = bcmfb_set_win_org, 250 .read_hw_cursor = bcmfb_read_hw_cursor, 251 .set_hw_cursor = bcmfb_set_hw_cursor, 252 .set_hw_cursor_shape = bcmfb_set_hw_cursor_shape, 253 .blank_display = bcmfb_blank_display, 254 .mmap = bcmfb_mmap, 255 .ioctl = bcmfb_ioctl, 256 .clear = bcmfb_clear, 257 .fill_rect = bcmfb_fill_rect, 258 .bitblt = bcmfb_bitblt, 259 .diag = bcmfb_diag, 260 .save_cursor_palette = bcmfb_save_cursor_palette, 261 .load_cursor_palette = bcmfb_load_cursor_palette, 262 .copy = bcmfb_copy, 263 .putp = bcmfb_putp, 264 .putc = bcmfb_putc, 265 .puts = bcmfb_puts, 266 .putm = bcmfb_putm, 267 }; 268 269 VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure); 270 271 static vr_init_t bcmrend_init; 272 static vr_clear_t bcmrend_clear; 273 static vr_draw_border_t bcmrend_draw_border; 274 static vr_draw_t bcmrend_draw; 275 static vr_set_cursor_t bcmrend_set_cursor; 276 static vr_draw_cursor_t bcmrend_draw_cursor; 277 static vr_blink_cursor_t bcmrend_blink_cursor; 278 static vr_set_mouse_t bcmrend_set_mouse; 279 static vr_draw_mouse_t bcmrend_draw_mouse; 280 281 /* 282 * We use our own renderer; this is because we must emulate a hardware 283 * cursor. 284 */ 285 static sc_rndr_sw_t bcmrend = { 286 bcmrend_init, 287 bcmrend_clear, 288 bcmrend_draw_border, 289 bcmrend_draw, 290 bcmrend_set_cursor, 291 bcmrend_draw_cursor, 292 bcmrend_blink_cursor, 293 bcmrend_set_mouse, 294 bcmrend_draw_mouse 295 }; 296 297 RENDERER(bcmfb, 0, bcmrend, gfb_set); 298 RENDERER_MODULE(bcmfb, gfb_set); 299 300 static void 301 bcmrend_init(scr_stat* scp) 302 { 303 } 304 305 static void 306 bcmrend_clear(scr_stat* scp, int c, int attr) 307 { 308 } 309 310 static void 311 bcmrend_draw_border(scr_stat* scp, int color) 312 { 313 } 314 315 static void 316 bcmrend_draw(scr_stat* scp, int from, int count, int flip) 317 { 318 video_adapter_t* adp = scp->sc->adp; 319 int i, c, a; 320 321 if (!flip) { 322 /* Normal printing */ 323 vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count); 324 } else { 325 /* This is for selections and such: invert the color attribute */ 326 for (i = count; i-- > 0; ++from) { 327 c = sc_vtb_getc(&scp->vtb, from); 328 a = sc_vtb_geta(&scp->vtb, from) >> 8; 329 vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); 330 } 331 } 332 } 333 334 static void 335 bcmrend_set_cursor(scr_stat* scp, int base, int height, int blink) 336 { 337 } 338 339 static void 340 bcmrend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip) 341 { 342 int bytes, col, i, j, row; 343 struct bcmsc_softc *sc; 344 uint8_t *addr; 345 video_adapter_t *adp; 346 347 adp = scp->sc->adp; 348 sc = (struct bcmsc_softc *)adp; 349 350 if (scp->curs_attr.height <= 0) 351 return; 352 353 if (sc->fb_addr == 0) 354 return; 355 356 if (off >= adp->va_info.vi_width * adp->va_info.vi_height) 357 return; 358 359 /* calculate the coordinates in the video buffer */ 360 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 361 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 362 363 addr = (uint8_t *)sc->fb_addr 364 + (row + sc->ymargin)*(sc->stride) 365 + (sc->depth/8) * (col + sc->xmargin); 366 367 bytes = sc->depth / 8; 368 /* our cursor consists of simply inverting the char under it */ 369 for (i = 0; i < adp->va_info.vi_cheight; i++) { 370 for (j = 0; j < adp->va_info.vi_cwidth; j++) { 371 switch (sc->depth) { 372 case 32: 373 case 24: 374 addr[bytes*j + 2] ^= 0xff; 375 /* FALLTHROUGH */ 376 case 16: 377 addr[bytes*j + 1] ^= 0xff; 378 addr[bytes*j] ^= 0xff; 379 break; 380 default: 381 break; 382 } 383 } 384 385 addr += sc->stride; 386 } 387 } 388 389 static void 390 bcmrend_blink_cursor(scr_stat* scp, int at, int flip) 391 { 392 } 393 394 static void 395 bcmrend_set_mouse(scr_stat* scp) 396 { 397 } 398 399 static void 400 bcmrend_draw_mouse(scr_stat* scp, int x, int y, int on) 401 { 402 vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8); 403 } 404 405 static uint16_t bcmfb_static_window[ROW*COL]; 406 extern u_char dflt_font_16[]; 407 408 /* 409 * Update videoadapter settings after changing resolution 410 */ 411 static void 412 bcmfb_update_margins(video_adapter_t *adp) 413 { 414 struct bcmsc_softc *sc; 415 video_info_t *vi; 416 417 sc = (struct bcmsc_softc *)adp; 418 vi = &adp->va_info; 419 420 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 421 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2; 422 } 423 424 static int 425 bcmfb_configure(int flags) 426 { 427 char bootargs[2048], *n, *p, *v; 428 pcell_t cell; 429 phandle_t chosen, display, root; 430 struct bcmsc_softc *sc; 431 432 sc = &bcmsc; 433 if (sc->initialized) 434 return (0); 435 436 sc->width = 0; 437 sc->height = 0; 438 439 /* 440 * It seems there is no way to let syscons framework know 441 * that framebuffer resolution has changed. So just try 442 * to fetch data from FDT bootargs, FDT display data and 443 * finally go with defaults if everything else has failed. 444 */ 445 chosen = OF_finddevice("/chosen"); 446 if (chosen != 0 && 447 OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) { 448 p = bootargs; 449 while ((v = strsep(&p, " ")) != NULL) { 450 if (*v == '\0') 451 continue; 452 n = strsep(&v, "="); 453 if (strcmp(n, "bcm2708_fb.fbwidth") == 0 && v != NULL) 454 sc->width = (unsigned int)strtol(v, NULL, 0); 455 else if (strcmp(n, "bcm2708_fb.fbheight") == 0 && 456 v != NULL) 457 sc->height = (unsigned int)strtol(v, NULL, 0); 458 else if (strcmp(n, "bcm2708_fb.fbswap") == 0 && 459 v != NULL) 460 if (*v == '1') 461 sc->fbswap = 1; 462 } 463 } 464 465 root = OF_finddevice("/"); 466 if ((root != 0) && 467 (display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) { 468 if (sc->width == 0) { 469 if ((OF_getprop(display, "broadcom,width", 470 &cell, sizeof(cell))) > 0) 471 sc->width = (int)fdt32_to_cpu(cell); 472 } 473 474 if (sc->height == 0) { 475 if ((OF_getprop(display, "broadcom,height", 476 &cell, sizeof(cell))) > 0) 477 sc->height = (int)fdt32_to_cpu(cell); 478 } 479 } 480 481 if (sc->width == 0) 482 sc->width = FB_WIDTH; 483 if (sc->height == 0) 484 sc->height = FB_HEIGHT; 485 486 bcmfb_init(0, &sc->va, 0); 487 sc->initialized = 1; 488 489 return (0); 490 } 491 492 static int 493 bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags) 494 { 495 496 return (0); 497 } 498 499 static int 500 bcmfb_init(int unit, video_adapter_t *adp, int flags) 501 { 502 struct bcmsc_softc *sc; 503 video_info_t *vi; 504 505 sc = (struct bcmsc_softc *)adp; 506 vi = &adp->va_info; 507 508 vid_init_struct(adp, "bcmfb", -1, unit); 509 510 sc->font = dflt_font_16; 511 vi->vi_cheight = BCMFB_FONT_HEIGHT; 512 vi->vi_cwidth = BCMFB_FONT_WIDTH; 513 vi->vi_width = sc->width / vi->vi_cwidth; 514 vi->vi_height = sc->height / vi->vi_cheight; 515 516 /* 517 * Clamp width/height to syscons maximums 518 */ 519 if (vi->vi_width > COL) 520 vi->vi_width = COL; 521 if (vi->vi_height > ROW) 522 vi->vi_height = ROW; 523 524 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 525 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2; 526 527 adp->va_window = (vm_offset_t) bcmfb_static_window; 528 adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; 529 530 vid_register(&sc->va); 531 532 return (0); 533 } 534 535 static int 536 bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) 537 { 538 bcopy(&adp->va_info, info, sizeof(*info)); 539 return (0); 540 } 541 542 static int 543 bcmfb_query_mode(video_adapter_t *adp, video_info_t *info) 544 { 545 return (0); 546 } 547 548 static int 549 bcmfb_set_mode(video_adapter_t *adp, int mode) 550 { 551 return (0); 552 } 553 554 static int 555 bcmfb_save_font(video_adapter_t *adp, int page, int size, int width, 556 u_char *data, int c, int count) 557 { 558 return (0); 559 } 560 561 static int 562 bcmfb_load_font(video_adapter_t *adp, int page, int size, int width, 563 u_char *data, int c, int count) 564 { 565 struct bcmsc_softc *sc; 566 567 sc = (struct bcmsc_softc *)adp; 568 sc->font = data; 569 570 return (0); 571 } 572 573 static int 574 bcmfb_show_font(video_adapter_t *adp, int page) 575 { 576 return (0); 577 } 578 579 static int 580 bcmfb_save_palette(video_adapter_t *adp, u_char *palette) 581 { 582 return (0); 583 } 584 585 static int 586 bcmfb_load_palette(video_adapter_t *adp, u_char *palette) 587 { 588 return (0); 589 } 590 591 static int 592 bcmfb_set_border(video_adapter_t *adp, int border) 593 { 594 return (bcmfb_blank_display(adp, border)); 595 } 596 597 static int 598 bcmfb_save_state(video_adapter_t *adp, void *p, size_t size) 599 { 600 return (0); 601 } 602 603 static int 604 bcmfb_load_state(video_adapter_t *adp, void *p) 605 { 606 return (0); 607 } 608 609 static int 610 bcmfb_set_win_org(video_adapter_t *adp, off_t offset) 611 { 612 return (0); 613 } 614 615 static int 616 bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 617 { 618 *col = *row = 0; 619 620 return (0); 621 } 622 623 static int 624 bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row) 625 { 626 return (0); 627 } 628 629 static int 630 bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 631 int celsize, int blink) 632 { 633 return (0); 634 } 635 636 static int 637 bcmfb_blank_display(video_adapter_t *adp, int mode) 638 { 639 640 struct bcmsc_softc *sc; 641 642 sc = (struct bcmsc_softc *)adp; 643 if (sc && sc->fb_addr) 644 memset((void*)sc->fb_addr, 0, sc->fb_size); 645 646 return (0); 647 } 648 649 static int 650 bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, 651 int prot, vm_memattr_t *memattr) 652 { 653 struct bcmsc_softc *sc; 654 655 sc = (struct bcmsc_softc *)adp; 656 657 /* 658 * This might be a legacy VGA mem request: if so, just point it at the 659 * framebuffer, since it shouldn't be touched 660 */ 661 if (offset < sc->stride*sc->height) { 662 *paddr = sc->fb_paddr + offset; 663 return (0); 664 } 665 666 return (EINVAL); 667 } 668 669 static int 670 bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 671 { 672 struct bcmsc_softc *sc; 673 struct fbtype *fb; 674 675 sc = (struct bcmsc_softc *)adp; 676 677 switch (cmd) { 678 case FBIOGTYPE: 679 fb = (struct fbtype *)data; 680 fb->fb_type = FBTYPE_PCIMISC; 681 fb->fb_height = sc->height; 682 fb->fb_width = sc->width; 683 fb->fb_depth = sc->depth; 684 if (sc->depth <= 1 || sc->depth > 8) 685 fb->fb_cmsize = 0; 686 else 687 fb->fb_cmsize = 1 << sc->depth; 688 fb->fb_size = sc->fb_size; 689 break; 690 default: 691 return (fb_commonioctl(adp, cmd, data)); 692 } 693 694 return (0); 695 } 696 697 static int 698 bcmfb_clear(video_adapter_t *adp) 699 { 700 701 return (bcmfb_blank_display(adp, 0)); 702 } 703 704 static int 705 bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 706 { 707 708 return (0); 709 } 710 711 static int 712 bcmfb_bitblt(video_adapter_t *adp, ...) 713 { 714 715 return (0); 716 } 717 718 static int 719 bcmfb_diag(video_adapter_t *adp, int level) 720 { 721 722 return (0); 723 } 724 725 static int 726 bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) 727 { 728 729 return (0); 730 } 731 732 static int 733 bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) 734 { 735 736 return (0); 737 } 738 739 static int 740 bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 741 { 742 743 return (0); 744 } 745 746 static int 747 bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 748 int size, int bpp, int bit_ltor, int byte_ltor) 749 { 750 751 return (0); 752 } 753 754 static int 755 bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 756 { 757 int bytes, col, i, j, k, row; 758 struct bcmsc_softc *sc; 759 u_char *p; 760 uint8_t *addr, fg, bg, color; 761 uint16_t rgb; 762 763 sc = (struct bcmsc_softc *)adp; 764 765 if (sc->fb_addr == 0) 766 return (0); 767 768 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 769 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 770 p = sc->font + c*BCMFB_FONT_HEIGHT; 771 addr = (uint8_t *)sc->fb_addr 772 + (row + sc->ymargin)*(sc->stride) 773 + (sc->depth/8) * (col + sc->xmargin); 774 775 fg = a & 0xf ; 776 bg = (a >> 4) & 0xf; 777 778 bytes = sc->depth / 8; 779 for (i = 0; i < BCMFB_FONT_HEIGHT; i++) { 780 for (j = 0, k = 7; j < 8; j++, k--) { 781 if ((p[i] & (1 << k)) == 0) 782 color = bg; 783 else 784 color = fg; 785 786 switch (sc->depth) { 787 case 32: 788 case 24: 789 if (sc->fbswap) { 790 addr[bytes * j + 0] = 791 bcmfb_palette[color].b; 792 addr[bytes * j + 1] = 793 bcmfb_palette[color].g; 794 addr[bytes * j + 2] = 795 bcmfb_palette[color].r; 796 } else { 797 addr[bytes * j + 0] = 798 bcmfb_palette[color].r; 799 addr[bytes * j + 1] = 800 bcmfb_palette[color].g; 801 addr[bytes * j + 2] = 802 bcmfb_palette[color].b; 803 } 804 if (sc->depth == 32) 805 addr[bytes * j + 3] = 806 bcmfb_palette[color].a; 807 break; 808 case 16: 809 rgb = (bcmfb_palette[color].r >> 3) << 11; 810 rgb |= (bcmfb_palette[color].g >> 2) << 5; 811 rgb |= (bcmfb_palette[color].b >> 3); 812 addr[bytes * j] = rgb & 0xff; 813 addr[bytes * j + 1] = (rgb >> 8) & 0xff; 814 default: 815 /* Not supported yet */ 816 break; 817 } 818 } 819 820 addr += (sc->stride); 821 } 822 823 return (0); 824 } 825 826 static int 827 bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 828 { 829 int i; 830 831 for (i = 0; i < len; i++) 832 bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 833 834 return (0); 835 } 836 837 static int 838 bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 839 uint32_t pixel_mask, int size, int width) 840 { 841 842 return (0); 843 } 844 845 /* 846 * Define a stub keyboard driver in case one hasn't been 847 * compiled into the kernel 848 */ 849 #include <sys/kbio.h> 850 #include <dev/kbd/kbdreg.h> 851 852 static int dummy_kbd_configure(int flags); 853 854 keyboard_switch_t bcmdummysw; 855 856 static int 857 dummy_kbd_configure(int flags) 858 { 859 860 return (0); 861 } 862 KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure); 863