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