bcm2835_fbd.c revision 239922
154359Sroberto/*- 254359Sroberto * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 354359Sroberto * All rights reserved. 454359Sroberto * 554359Sroberto * Redistribution and use in source and binary forms, with or without 654359Sroberto * modification, are permitted provided that the following conditions 754359Sroberto * are met: 854359Sroberto * 1. Redistributions of source code must retain the above copyright 954359Sroberto * notice, this list of conditions and the following disclaimer. 1054359Sroberto * 2. Redistributions in binary form must reproduce the above copyright 1154359Sroberto * notice, this list of conditions and the following disclaimer in the 1254359Sroberto * documentation and/or other materials provided with the distribution. 1354359Sroberto * 1454359Sroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1554359Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1654359Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1754359Sroberto * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1854359Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1954359Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2054359Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2154359Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2254359Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2354359Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2454359Sroberto * SUCH DAMAGE. 2554359Sroberto * 2654359Sroberto */ 2754359Sroberto#include <sys/cdefs.h> 2854359Sroberto__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_fb.c 239922 2012-08-30 20:59:37Z gonzo $"); 2954359Sroberto 3054359Sroberto#include <sys/param.h> 3154359Sroberto#include <sys/systm.h> 3254359Sroberto#include <sys/bio.h> 3354359Sroberto#include <sys/bus.h> 3454359Sroberto#include <sys/conf.h> 3554359Sroberto#include <sys/endian.h> 3654359Sroberto#include <sys/kernel.h> 3754359Sroberto#include <sys/kthread.h> 3854359Sroberto#include <sys/lock.h> 3954359Sroberto#include <sys/malloc.h> 4054359Sroberto#include <sys/module.h> 4154359Sroberto#include <sys/mutex.h> 4254359Sroberto#include <sys/queue.h> 4354359Sroberto#include <sys/resource.h> 4454359Sroberto#include <sys/rman.h> 4554359Sroberto#include <sys/time.h> 4654359Sroberto#include <sys/timetc.h> 4754359Sroberto#include <sys/fbio.h> 4854359Sroberto#include <sys/consio.h> 4954359Sroberto 5054359Sroberto#include <sys/kdb.h> 5154359Sroberto 5254359Sroberto#include <machine/bus.h> 5354359Sroberto#include <machine/cpu.h> 5454359Sroberto#include <machine/cpufunc.h> 5554359Sroberto#include <machine/resource.h> 5654359Sroberto#include <machine/frame.h> 5754359Sroberto#include <machine/intr.h> 5854359Sroberto 5954359Sroberto#include <dev/fdt/fdt_common.h> 6054359Sroberto#include <dev/ofw/ofw_bus.h> 6154359Sroberto#include <dev/ofw/ofw_bus_subr.h> 6254359Sroberto 6354359Sroberto#include <dev/fb/fbreg.h> 6454359Sroberto#include <dev/syscons/syscons.h> 6554359Sroberto 6656746Sroberto#include <arm/broadcom/bcm2835/bcm2835_mbox.h> 6754359Sroberto#include <arm/broadcom/bcm2835/bcm2835_vcbus.h> 6854359Sroberto 6954359Sroberto#define BCMFB_FONT_HEIGHT 16 7054359Sroberto 7154359Sroberto#define FB_WIDTH 640 7254359Sroberto#define FB_HEIGHT 480 7354359Sroberto 7456746Srobertostruct bcm_fb_config { 7556746Sroberto uint32_t xres; 7654359Sroberto uint32_t yres; 7756746Sroberto uint32_t vxres; 7854359Sroberto uint32_t vyres; 7954359Sroberto uint32_t pitch; 8054359Sroberto uint32_t bpp; 8154359Sroberto uint32_t xoffset; 8254359Sroberto uint32_t yoffset; 8354359Sroberto /* Filled by videocore */ 8454359Sroberto uint32_t base; 8554359Sroberto uint32_t screen_size; 8654359Sroberto}; 8754359Sroberto 8854359Srobertostruct bcmsc_softc { 8954359Sroberto device_t dev; 9054359Sroberto struct cdev * cdev; 9154359Sroberto struct mtx mtx; 9254359Sroberto bus_dma_tag_t dma_tag; 9354359Sroberto bus_dmamap_t dma_map; 9454359Sroberto struct bcm_fb_config* fb_config; 9554359Sroberto bus_addr_t fb_config_phys; 9654359Sroberto struct intr_config_hook init_hook; 9754359Sroberto 9854359Sroberto}; 9956746Sroberto 10054359Srobertostruct video_adapter_softc { 10154359Sroberto /* Videoadpater part */ 10254359Sroberto video_adapter_t va; 10354359Sroberto int console; 10454359Sroberto 10554359Sroberto intptr_t fb_addr; 10654359Sroberto unsigned int fb_size; 10754359Sroberto 10854359Sroberto unsigned int height; 10954359Sroberto unsigned int width; 11054359Sroberto unsigned int stride; 11154359Sroberto 11254359Sroberto unsigned int xmargin; 11354359Sroberto unsigned int ymargin; 11454359Sroberto 11554359Sroberto unsigned char *font; 11654359Sroberto int initialized; 11754359Sroberto}; 11854359Sroberto 11954359Srobertostatic struct bcmsc_softc *bcmsc_softc; 12054359Srobertostatic struct video_adapter_softc va_softc; 12154359Sroberto 12254359Sroberto#define bcm_fb_lock(_sc) mtx_lock(&(_sc)->mtx) 12354359Sroberto#define bcm_fb_unlock(_sc) mtx_unlock(&(_sc)->mtx) 12454359Sroberto#define bcm_fb_lock_assert(sc) mtx_assert(&(_sc)->mtx, MA_OWNED) 12554359Sroberto 12654359Srobertostatic int bcm_fb_probe(device_t); 12754359Srobertostatic int bcm_fb_attach(device_t); 12854359Srobertostatic void bcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err); 12954359Sroberto 13054359Srobertostatic void 13154359Srobertobcm_fb_init(void *arg) 13254359Sroberto{ 13354359Sroberto struct bcmsc_softc *sc = arg; 13454359Sroberto struct video_adapter_softc *va_sc = &va_softc; 13554359Sroberto int err; 13654359Sroberto volatile struct bcm_fb_config* fb_config = sc->fb_config; 13754359Sroberto 13854359Sroberto /* TODO: replace it with FDT stuff */ 13954359Sroberto fb_config->xres = FB_WIDTH; 14054359Sroberto fb_config->yres = FB_HEIGHT; 14154359Sroberto fb_config->vxres = 0; 14254359Sroberto fb_config->vyres = 0; 14354359Sroberto fb_config->xoffset = 0; 14454359Sroberto fb_config->yoffset = 0; 14554359Sroberto fb_config->bpp = 24; 14654359Sroberto fb_config->base = 0; 14756746Sroberto fb_config->pitch = 0; 14856746Sroberto fb_config->screen_size = 0; 14956746Sroberto 15054359Sroberto bus_dmamap_sync(sc->dma_tag, sc->dma_map, 15154359Sroberto BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 15254359Sroberto bcm_mbox_write(BCM2835_MBOX_CHAN_FB, sc->fb_config_phys); 15354359Sroberto bcm_mbox_read(BCM2835_MBOX_CHAN_FB, &err); 15454359Sroberto bus_dmamap_sync(sc->dma_tag, sc->dma_map, 15554359Sroberto BUS_DMASYNC_POSTREAD); 15654359Sroberto 15756746Sroberto if (err == 0) { 15854359Sroberto device_printf(sc->dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", 15956746Sroberto fb_config->xres, fb_config->yres, 16054359Sroberto fb_config->vxres, fb_config->vyres, 16154359Sroberto fb_config->xoffset, fb_config->yoffset, 16254359Sroberto fb_config->bpp); 16354359Sroberto 16454359Sroberto 16554359Sroberto device_printf(sc->dev, "pitch %d, base 0x%08x, screen_size %d\n", 16654359Sroberto fb_config->pitch, fb_config->base, 16754359Sroberto fb_config->screen_size); 16854359Sroberto 16954359Sroberto if (fb_config->base) { 17054359Sroberto va_sc->fb_addr = (intptr_t)pmap_mapdev(fb_config->base, fb_config->screen_size); 17154359Sroberto va_sc->fb_size = fb_config->screen_size; 17254359Sroberto va_sc->stride = fb_config->pitch; 17354359Sroberto } 17454359Sroberto } 17554359Sroberto else 17654359Sroberto device_printf(sc->dev, "Failed to set framebuffer info\n"); 17754359Sroberto 17854359Sroberto config_intrhook_disestablish(&sc->init_hook); 17954359Sroberto} 18054359Sroberto 18154359Srobertostatic int 18254359Srobertobcm_fb_probe(device_t dev) 18354359Sroberto{ 18454359Sroberto int error; 18554359Sroberto 18654359Sroberto if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb")) 18754359Sroberto return (ENXIO); 18854359Sroberto 18954359Sroberto device_set_desc(dev, "BCM2835 framebuffer device"); 19054359Sroberto 19154359Sroberto error = sc_probe_unit(device_get_unit(dev), 19254359Sroberto device_get_flags(dev) | SC_AUTODETECT_KBD); 19354359Sroberto 19454359Sroberto if (error != 0) 19554359Sroberto return (error); 19654359Sroberto 19754359Sroberto return (BUS_PROBE_DEFAULT); 19854359Sroberto} 19954359Sroberto 20054359Srobertostatic int 20154359Srobertobcm_fb_attach(device_t dev) 20254359Sroberto{ 20354359Sroberto struct bcmsc_softc *sc = device_get_softc(dev); 20454359Sroberto int dma_size = sizeof(struct bcm_fb_config); 20554359Sroberto int err; 20654359Sroberto 20754359Sroberto if (bcmsc_softc) 20854359Sroberto return (ENXIO); 20954359Sroberto 21054359Sroberto bcmsc_softc = sc; 21156746Sroberto 21256746Sroberto sc->dev = dev; 21356746Sroberto mtx_init(&sc->mtx, "bcm2835fb", "fb", MTX_DEF); 21456746Sroberto 21556746Sroberto err = bus_dma_tag_create( 21656746Sroberto bus_get_dma_tag(sc->dev), 21754359Sroberto PAGE_SIZE, 0, /* alignment, boundary */ 21856746Sroberto BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 21954359Sroberto BUS_SPACE_MAXADDR, /* highaddr */ 22056746Sroberto NULL, NULL, /* filter, filterarg */ 22156746Sroberto dma_size, 1, /* maxsize, nsegments */ 22254359Sroberto dma_size, 0, /* maxsegsize, flags */ 22354359Sroberto NULL, NULL, /* lockfunc, lockarg */ 22456746Sroberto &sc->dma_tag); 22556746Sroberto 22656746Sroberto err = bus_dmamem_alloc(sc->dma_tag, (void **)&sc->fb_config, 22756746Sroberto 0, &sc->dma_map); 22856746Sroberto if (err) { 22954359Sroberto device_printf(dev, "cannot allocate framebuffer\n"); 23054359Sroberto goto fail; 23156746Sroberto } 23254359Sroberto 23354359Sroberto err = bus_dmamap_load(sc->dma_tag, sc->dma_map, sc->fb_config, 23454359Sroberto dma_size, bcm_fb_dmamap_cb, &sc->fb_config_phys, BUS_DMA_NOWAIT); 23554359Sroberto 23654359Sroberto if (err) { 23754359Sroberto device_printf(dev, "cannot load DMA map\n"); 23854359Sroberto goto fail; 23954359Sroberto } 24054359Sroberto 24154359Sroberto err = (sc_attach_unit(device_get_unit(dev), 24254359Sroberto device_get_flags(dev) | SC_AUTODETECT_KBD)); 24354359Sroberto 24454359Sroberto if (err) { 24554359Sroberto device_printf(dev, "failed to attach syscons\n"); 24654359Sroberto goto fail; 24754359Sroberto } 24856746Sroberto 24954359Sroberto /* 25054359Sroberto * We have to wait until interrupts are enabled. 25154359Sroberto * Mailbox relies on it to get data from VideoCore 25254359Sroberto */ 25354359Sroberto sc->init_hook.ich_func = bcm_fb_init; 25454359Sroberto sc->init_hook.ich_arg = sc; 25554359Sroberto 25656746Sroberto if (config_intrhook_establish(&sc->init_hook) != 0) { 25756746Sroberto device_printf(dev, "failed to establish intrhook\n"); 25856746Sroberto return (ENOMEM); 25956746Sroberto } 26056746Sroberto 26156746Sroberto return (0); 26256746Sroberto 26356746Srobertofail: 26456746Sroberto return (ENXIO); 26556746Sroberto} 26656746Sroberto 26756746Sroberto 26856746Srobertostatic void 26956746Srobertobcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err) 27056746Sroberto{ 27156746Sroberto bus_addr_t *addr; 27256746Sroberto 27356746Sroberto if (err) 27456746Sroberto return; 27556746Sroberto 27656746Sroberto addr = (bus_addr_t*)arg; 27754359Sroberto *addr = PHYS_TO_VCBUS(segs[0].ds_addr); 27854359Sroberto} 27954359Sroberto 28054359Srobertostatic device_method_t bcm_fb_methods[] = { 28154359Sroberto /* Device interface */ 28254359Sroberto DEVMETHOD(device_probe, bcm_fb_probe), 28354359Sroberto DEVMETHOD(device_attach, bcm_fb_attach), 28454359Sroberto 28554359Sroberto { 0, 0 } 28654359Sroberto}; 28754359Sroberto 28854359Srobertostatic devclass_t bcm_fb_devclass; 28954359Sroberto 29054359Srobertostatic driver_t bcm_fb_driver = { 29154359Sroberto "fb", 29254359Sroberto bcm_fb_methods, 29354359Sroberto sizeof(struct bcmsc_softc), 29454359Sroberto}; 29554359Sroberto 29654359SrobertoDRIVER_MODULE(bcm2835fb, simplebus, bcm_fb_driver, bcm_fb_devclass, 0, 0); 29754359Sroberto 29854359Sroberto/* 29954359Sroberto * Video driver routines and glue. 30054359Sroberto */ 30154359Srobertostatic int bcmfb_configure(int); 30254359Srobertostatic vi_probe_t bcmfb_probe; 30354359Srobertostatic vi_init_t bcmfb_init; 30454359Srobertostatic vi_get_info_t bcmfb_get_info; 30554359Srobertostatic vi_query_mode_t bcmfb_query_mode; 30654359Srobertostatic vi_set_mode_t bcmfb_set_mode; 30754359Srobertostatic vi_save_font_t bcmfb_save_font; 30854359Srobertostatic vi_load_font_t bcmfb_load_font; 30954359Srobertostatic vi_show_font_t bcmfb_show_font; 31054359Srobertostatic vi_save_palette_t bcmfb_save_palette; 31154359Srobertostatic vi_load_palette_t bcmfb_load_palette; 31256746Srobertostatic vi_set_border_t bcmfb_set_border; 31354359Srobertostatic vi_save_state_t bcmfb_save_state; 31456746Srobertostatic vi_load_state_t bcmfb_load_state; 31556746Srobertostatic vi_set_win_org_t bcmfb_set_win_org; 31654359Srobertostatic vi_read_hw_cursor_t bcmfb_read_hw_cursor; 31754359Srobertostatic vi_set_hw_cursor_t bcmfb_set_hw_cursor; 31854359Srobertostatic vi_set_hw_cursor_shape_t bcmfb_set_hw_cursor_shape; 31954359Srobertostatic vi_blank_display_t bcmfb_blank_display; 32056746Srobertostatic vi_mmap_t bcmfb_mmap; 32154359Srobertostatic vi_ioctl_t bcmfb_ioctl; 32254359Srobertostatic vi_clear_t bcmfb_clear; 32354359Srobertostatic vi_fill_rect_t bcmfb_fill_rect; 32454359Srobertostatic vi_bitblt_t bcmfb_bitblt; 32556746Srobertostatic vi_diag_t bcmfb_diag; 32656746Srobertostatic vi_save_cursor_palette_t bcmfb_save_cursor_palette; 32754359Srobertostatic vi_load_cursor_palette_t bcmfb_load_cursor_palette; 32854359Srobertostatic vi_copy_t bcmfb_copy; 32954359Srobertostatic vi_putp_t bcmfb_putp; 33054359Srobertostatic vi_putc_t bcmfb_putc; 33154359Srobertostatic vi_puts_t bcmfb_puts; 33256746Srobertostatic vi_putm_t bcmfb_putm; 33356746Sroberto 33454359Srobertostatic video_switch_t bcmfbvidsw = { 33554359Sroberto .probe = bcmfb_probe, 33654359Sroberto .init = bcmfb_init, 33754359Sroberto .get_info = bcmfb_get_info, 33854359Sroberto .query_mode = bcmfb_query_mode, 33954359Sroberto .set_mode = bcmfb_set_mode, 34054359Sroberto .save_font = bcmfb_save_font, 34154359Sroberto .load_font = bcmfb_load_font, 34254359Sroberto .show_font = bcmfb_show_font, 34354359Sroberto .save_palette = bcmfb_save_palette, 34456746Sroberto .load_palette = bcmfb_load_palette, 34556746Sroberto .set_border = bcmfb_set_border, 34656746Sroberto .save_state = bcmfb_save_state, 34754359Sroberto .load_state = bcmfb_load_state, 34854359Sroberto .set_win_org = bcmfb_set_win_org, 34954359Sroberto .read_hw_cursor = bcmfb_read_hw_cursor, 35054359Sroberto .set_hw_cursor = bcmfb_set_hw_cursor, 35154359Sroberto .set_hw_cursor_shape = bcmfb_set_hw_cursor_shape, 35254359Sroberto .blank_display = bcmfb_blank_display, 35354359Sroberto .mmap = bcmfb_mmap, 35454359Sroberto .ioctl = bcmfb_ioctl, 35554359Sroberto .clear = bcmfb_clear, 35654359Sroberto .fill_rect = bcmfb_fill_rect, 35754359Sroberto .bitblt = bcmfb_bitblt, 35854359Sroberto .diag = bcmfb_diag, 35954359Sroberto .save_cursor_palette = bcmfb_save_cursor_palette, 36054359Sroberto .load_cursor_palette = bcmfb_load_cursor_palette, 361 .copy = bcmfb_copy, 362 .putp = bcmfb_putp, 363 .putc = bcmfb_putc, 364 .puts = bcmfb_puts, 365 .putm = bcmfb_putm, 366}; 367 368VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure); 369 370extern sc_rndr_sw_t txtrndrsw; 371RENDERER(bcmfb, 0, txtrndrsw, gfb_set); 372RENDERER_MODULE(bcmfb, gfb_set); 373 374static uint16_t bcmfb_static_window[ROW*COL]; 375extern u_char dflt_font_16[]; 376 377static int 378bcmfb_configure(int flags) 379{ 380 struct video_adapter_softc *sc; 381 382 sc = &va_softc; 383 384 if (sc->initialized) 385 return 0; 386 387 sc->height = FB_HEIGHT; 388 sc->width = FB_WIDTH; 389 390 bcmfb_init(0, &sc->va, 0); 391 392 sc->initialized = 1; 393 394 return (0); 395} 396 397static int 398bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags) 399{ 400 401 return (0); 402} 403 404static int 405bcmfb_init(int unit, video_adapter_t *adp, int flags) 406{ 407 struct video_adapter_softc *sc; 408 video_info_t *vi; 409 410 sc = (struct video_adapter_softc *)adp; 411 vi = &adp->va_info; 412 413 vid_init_struct(adp, "bcmfb", -1, unit); 414 415 sc->font = dflt_font_16; 416 vi->vi_cheight = BCMFB_FONT_HEIGHT; 417 vi->vi_cwidth = 8; 418 vi->vi_width = sc->width/8; 419 vi->vi_height = sc->height/vi->vi_cheight; 420 421 /* 422 * Clamp width/height to syscons maximums 423 */ 424 if (vi->vi_width > COL) 425 vi->vi_width = COL; 426 if (vi->vi_height > ROW) 427 vi->vi_height = ROW; 428 429 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 430 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; 431 432 adp->va_window = (vm_offset_t) bcmfb_static_window; 433 adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; 434 435 vid_register(&sc->va); 436 437 return (0); 438} 439 440static int 441bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) 442{ 443 bcopy(&adp->va_info, info, sizeof(*info)); 444 return (0); 445} 446 447static int 448bcmfb_query_mode(video_adapter_t *adp, video_info_t *info) 449{ 450 return (0); 451} 452 453static int 454bcmfb_set_mode(video_adapter_t *adp, int mode) 455{ 456 return (0); 457} 458 459static int 460bcmfb_save_font(video_adapter_t *adp, int page, int size, int width, 461 u_char *data, int c, int count) 462{ 463 return (0); 464} 465 466static int 467bcmfb_load_font(video_adapter_t *adp, int page, int size, int width, 468 u_char *data, int c, int count) 469{ 470 struct video_adapter_softc *sc = (struct video_adapter_softc *)adp; 471 472 sc->font = data; 473 474 return (0); 475} 476 477static int 478bcmfb_show_font(video_adapter_t *adp, int page) 479{ 480 return (0); 481} 482 483static int 484bcmfb_save_palette(video_adapter_t *adp, u_char *palette) 485{ 486 return (0); 487} 488 489static int 490bcmfb_load_palette(video_adapter_t *adp, u_char *palette) 491{ 492 return (0); 493} 494 495static int 496bcmfb_set_border(video_adapter_t *adp, int border) 497{ 498 return (bcmfb_blank_display(adp, border)); 499} 500 501static int 502bcmfb_save_state(video_adapter_t *adp, void *p, size_t size) 503{ 504 return (0); 505} 506 507static int 508bcmfb_load_state(video_adapter_t *adp, void *p) 509{ 510 return (0); 511} 512 513static int 514bcmfb_set_win_org(video_adapter_t *adp, off_t offset) 515{ 516 return (0); 517} 518 519static int 520bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 521{ 522 *col = *row = 0; 523 524 return (0); 525} 526 527static int 528bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row) 529{ 530 return (0); 531} 532 533static int 534bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 535 int celsize, int blink) 536{ 537 return (0); 538} 539 540static int 541bcmfb_blank_display(video_adapter_t *adp, int mode) 542{ 543 544 return (0); 545} 546 547static int 548bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, 549 int prot, vm_memattr_t *memattr) 550{ 551 struct video_adapter_softc *sc; 552 553 sc = (struct video_adapter_softc *)adp; 554 555 /* 556 * This might be a legacy VGA mem request: if so, just point it at the 557 * framebuffer, since it shouldn't be touched 558 */ 559 if (offset < sc->stride*sc->height) { 560 *paddr = sc->fb_addr + offset; 561 return (0); 562 } 563 564 return (EINVAL); 565} 566 567static int 568bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 569{ 570 571 return (0); 572} 573 574static int 575bcmfb_clear(video_adapter_t *adp) 576{ 577 578 return (bcmfb_blank_display(adp, 0)); 579} 580 581static int 582bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 583{ 584 585 return (0); 586} 587 588static int 589bcmfb_bitblt(video_adapter_t *adp, ...) 590{ 591 592 return (0); 593} 594 595static int 596bcmfb_diag(video_adapter_t *adp, int level) 597{ 598 599 return (0); 600} 601 602static int 603bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) 604{ 605 606 return (0); 607} 608 609static int 610bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) 611{ 612 613 return (0); 614} 615 616static int 617bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 618{ 619 620 return (0); 621} 622 623static int 624bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 625 int size, int bpp, int bit_ltor, int byte_ltor) 626{ 627 628 return (0); 629} 630 631static int 632bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 633{ 634 struct video_adapter_softc *sc; 635 int row; 636 int col; 637 int i, j, k; 638 uint8_t *addr; 639 u_char *p; 640 uint8_t fg, bg, color; 641 642 sc = (struct video_adapter_softc *)adp; 643 644 if (sc->fb_addr == 0) 645 return (0); 646 647 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 648 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 649 p = sc->font + c*BCMFB_FONT_HEIGHT; 650 addr = (uint8_t *)sc->fb_addr 651 + (row + sc->ymargin)*(sc->stride) 652 + 3 * (col + sc->xmargin); 653 654 /* 655 * FIXME: hardcoded 656 */ 657 bg = 0x00; 658 fg = 0x80; 659 660 for (i = 0; i < BCMFB_FONT_HEIGHT; i++) { 661 for (j = 0, k = 7; j < 8; j++, k--) { 662 if ((p[i] & (1 << k)) == 0) 663 color = bg; 664 else 665 color = fg; 666 667 addr[3*j] = color; 668 addr[3*j+1] = color; 669 addr[3*j+2] = color; 670 } 671 672 addr += (sc->stride); 673 } 674 675 return (0); 676} 677 678static int 679bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 680{ 681 int i; 682 683 for (i = 0; i < len; i++) 684 bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 685 686 return (0); 687} 688 689static int 690bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 691 uint32_t pixel_mask, int size, int width) 692{ 693 694 return (0); 695} 696 697/* 698 * Define a stub keyboard driver in case one hasn't been 699 * compiled into the kernel 700 */ 701#include <sys/kbio.h> 702#include <dev/kbd/kbdreg.h> 703 704static int dummy_kbd_configure(int flags); 705 706keyboard_switch_t bcmdummysw; 707 708static int 709dummy_kbd_configure(int flags) 710{ 711 712 return (0); 713} 714KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure); 715