1/*- 2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * Copyright (c) 2012, 2013 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Oleksandr Rybalko 7 * under sponsorship from the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 */ 31#include <sys/cdefs.h> 32__FBSDID("$FreeBSD: stable/11/sys/arm/freescale/imx/imx51_ipuv3.c 356110 2019-12-27 03:00:18Z kevans $"); 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/bio.h> 37#include <sys/bus.h> 38#include <sys/conf.h> 39#include <sys/endian.h> 40#include <sys/kernel.h> 41#include <sys/kthread.h> 42#include <sys/lock.h> 43#include <sys/malloc.h> 44#include <sys/module.h> 45#include <sys/mutex.h> 46#include <sys/queue.h> 47#include <sys/resource.h> 48#include <sys/rman.h> 49#include <sys/time.h> 50#include <sys/timetc.h> 51#include <sys/fbio.h> 52#include <sys/consio.h> 53 54#include <sys/kdb.h> 55 56#include <vm/vm.h> 57#include <vm/pmap.h> 58 59#include <machine/bus.h> 60#include <machine/fdt.h> 61#include <machine/resource.h> 62#include <machine/intr.h> 63 64#include <dev/ofw/ofw_bus.h> 65#include <dev/ofw/ofw_bus_subr.h> 66 67#include <dev/fb/fbreg.h> 68#include <dev/syscons/syscons.h> 69 70#include <arm/freescale/imx/imx51_ccmvar.h> 71 72#include <arm/freescale/imx/imx51_ipuv3reg.h> 73 74#define IMX51_IPU_HSP_CLOCK 665000000 75#define IPU3FB_FONT_HEIGHT 16 76 77struct ipu3sc_softc { 78 device_t dev; 79 bus_addr_t pbase; 80 bus_addr_t vbase; 81 82 bus_space_tag_t iot; 83 bus_space_handle_t ioh; 84 bus_space_handle_t cm_ioh; 85 bus_space_handle_t dp_ioh; 86 bus_space_handle_t di0_ioh; 87 bus_space_handle_t di1_ioh; 88 bus_space_handle_t dctmpl_ioh; 89 bus_space_handle_t dc_ioh; 90 bus_space_handle_t dmfc_ioh; 91 bus_space_handle_t idmac_ioh; 92 bus_space_handle_t cpmem_ioh; 93}; 94 95struct video_adapter_softc { 96 /* Videoadpater part */ 97 video_adapter_t va; 98 99 intptr_t fb_addr; 100 intptr_t fb_paddr; 101 unsigned int fb_size; 102 103 int bpp; 104 int depth; 105 unsigned int height; 106 unsigned int width; 107 unsigned int stride; 108 109 unsigned int xmargin; 110 unsigned int ymargin; 111 112 unsigned char *font; 113 int initialized; 114}; 115 116static struct ipu3sc_softc *ipu3sc_softc; 117static struct video_adapter_softc va_softc; 118 119/* FIXME: not only 2 bytes color supported */ 120static uint16_t colors[16] = { 121 0x0000, /* black */ 122 0x001f, /* blue */ 123 0x07e0, /* green */ 124 0x07ff, /* cyan */ 125 0xf800, /* red */ 126 0xf81f, /* magenta */ 127 0x3800, /* brown */ 128 0xc618, /* light grey */ 129 0xc618, /* XXX: dark grey */ 130 0x001f, /* XXX: light blue */ 131 0x07e0, /* XXX: light green */ 132 0x07ff, /* XXX: light cyan */ 133 0xf800, /* XXX: light red */ 134 0xf81f, /* XXX: light magenta */ 135 0xffe0, /* yellow */ 136 0xffff, /* white */ 137}; 138static uint32_t colors_24[16] = { 139 0x000000,/* Black */ 140 0x000080,/* Blue */ 141 0x008000,/* Green */ 142 0x008080,/* Cyan */ 143 0x800000,/* Red */ 144 0x800080,/* Magenta */ 145 0xcc6600,/* brown */ 146 0xC0C0C0,/* Silver */ 147 0x808080,/* Gray */ 148 0x0000FF,/* Light Blue */ 149 0x00FF00,/* Light Green */ 150 0x00FFFF,/* Light Cyan */ 151 0xFF0000,/* Light Red */ 152 0xFF00FF,/* Light Magenta */ 153 0xFFFF00,/* Yellow */ 154 0xFFFFFF,/* White */ 155 156 157}; 158 159#define IPUV3_READ(ipuv3, module, reg) \ 160 bus_space_read_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg)) 161#define IPUV3_WRITE(ipuv3, module, reg, val) \ 162 bus_space_write_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg), (val)) 163 164#define CPMEM_CHANNEL_OFFSET(_c) ((_c) * 0x40) 165#define CPMEM_WORD_OFFSET(_w) ((_w) * 0x20) 166#define CPMEM_DP_OFFSET(_d) ((_d) * 0x10000) 167#define IMX_IPU_DP0 0 168#define IMX_IPU_DP1 1 169#define CPMEM_CHANNEL(_dp, _ch, _w) \ 170 (CPMEM_DP_OFFSET(_dp) + CPMEM_CHANNEL_OFFSET(_ch) + \ 171 CPMEM_WORD_OFFSET(_w)) 172#define CPMEM_OFFSET(_dp, _ch, _w, _o) \ 173 (CPMEM_CHANNEL((_dp), (_ch), (_w)) + (_o)) 174 175#define IPUV3_DEBUG 100 176 177#ifdef IPUV3_DEBUG 178#define SUBMOD_DUMP_REG(_sc, _m, _l) \ 179 { \ 180 int i; \ 181 printf("*** " #_m " ***\n"); \ 182 for (i = 0; i <= (_l); i += 4) { \ 183 if ((i % 32) == 0) \ 184 printf("%04x: ", i & 0xffff); \ 185 printf("0x%08x%c", IPUV3_READ((_sc), _m, i), \ 186 ((i + 4) % 32)?' ':'\n'); \ 187 } \ 188 printf("\n"); \ 189 } 190#endif 191 192#ifdef IPUV3_DEBUG 193int ipuv3_debug = IPUV3_DEBUG; 194#define DPRINTFN(n,x) if (ipuv3_debug>(n)) printf x; else 195#else 196#define DPRINTFN(n,x) 197#endif 198 199static int ipu3_fb_probe(device_t); 200static int ipu3_fb_attach(device_t); 201 202static int 203ipu3_fb_malloc(struct ipu3sc_softc *sc, size_t size) 204{ 205 206 sc->vbase = (uint32_t)contigmalloc(size, M_DEVBUF, M_ZERO, 0, ~0, 207 PAGE_SIZE, 0); 208 sc->pbase = vtophys(sc->vbase); 209 210 return (0); 211} 212 213static void 214ipu3_fb_init(void *arg) 215{ 216 struct ipu3sc_softc *sc = arg; 217 struct video_adapter_softc *va_sc = &va_softc; 218 uint64_t w0sh96; 219 uint32_t w1sh96; 220 221 /* FW W0[137:125] - 96 = [41:29] */ 222 /* FH W0[149:138] - 96 = [53:42] */ 223 w0sh96 = IPUV3_READ(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 0, 16)); 224 w0sh96 <<= 32; 225 w0sh96 |= IPUV3_READ(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 0, 12)); 226 227 va_sc->width = ((w0sh96 >> 29) & 0x1fff) + 1; 228 va_sc->height = ((w0sh96 >> 42) & 0x0fff) + 1; 229 230 /* SLY W1[115:102] - 96 = [19:6] */ 231 w1sh96 = IPUV3_READ(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 1, 12)); 232 va_sc->stride = ((w1sh96 >> 6) & 0x3fff) + 1; 233 234 printf("%dx%d [%d]\n", va_sc->width, va_sc->height, va_sc->stride); 235 va_sc->fb_size = va_sc->height * va_sc->stride; 236 237 ipu3_fb_malloc(sc, va_sc->fb_size); 238 239 /* DP1 + config_ch_23 + word_2 */ 240 IPUV3_WRITE(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 1, 0), 241 ((sc->pbase >> 3) | ((sc->pbase >> 3) << 29)) & 0xffffffff); 242 243 IPUV3_WRITE(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 1, 4), 244 ((sc->pbase >> 3) >> 3) & 0xffffffff); 245 246 va_sc->fb_addr = (intptr_t)sc->vbase; 247 va_sc->fb_paddr = (intptr_t)sc->pbase; 248 va_sc->bpp = va_sc->stride / va_sc->width; 249 va_sc->depth = va_sc->bpp * 8; 250} 251 252static int 253ipu3_fb_probe(device_t dev) 254{ 255 int error; 256 257 if (!ofw_bus_status_okay(dev)) 258 return (ENXIO); 259 260 if (!ofw_bus_is_compatible(dev, "fsl,ipu3")) 261 return (ENXIO); 262 263 device_set_desc(dev, "i.MX5x Image Processing Unit v3 (FB)"); 264 265 error = sc_probe_unit(device_get_unit(dev), 266 device_get_flags(dev) | SC_AUTODETECT_KBD); 267 268 if (error != 0) 269 return (error); 270 271 return (BUS_PROBE_DEFAULT); 272} 273 274static int 275ipu3_fb_attach(device_t dev) 276{ 277 struct ipu3sc_softc *sc = device_get_softc(dev); 278 bus_space_tag_t iot; 279 bus_space_handle_t ioh; 280 phandle_t node; 281 pcell_t reg; 282 int err; 283 uintptr_t base; 284 285 if (ipu3sc_softc) 286 return (ENXIO); 287 288 ipu3sc_softc = sc; 289 290 if (bootverbose) 291 device_printf(dev, "clock gate status is %d\n", 292 imx51_get_clk_gating(IMX51CLK_IPU_HSP_CLK_ROOT)); 293 294 sc->dev = dev; 295 296 err = (sc_attach_unit(device_get_unit(dev), 297 device_get_flags(dev) | SC_AUTODETECT_KBD)); 298 299 if (err) { 300 device_printf(dev, "failed to attach syscons\n"); 301 goto fail; 302 } 303 304 sc = device_get_softc(dev); 305 sc->iot = iot = fdtbus_bs_tag; 306 307 /* 308 * Retrieve the device address based on the start address in the 309 * DTS. The DTS for i.MX51 specifies 0x5e000000 as the first register 310 * address, so we just subtract IPU_CM_BASE to get the offset at which 311 * the IPU device was memory mapped. 312 * On i.MX53, the offset is 0. 313 */ 314 node = ofw_bus_get_node(dev); 315 if ((OF_getencprop(node, "reg", ®, sizeof(reg))) <= 0) 316 base = 0; 317 else 318 base = reg - IPU_CM_BASE(0); 319 /* map controller registers */ 320 err = bus_space_map(iot, IPU_CM_BASE(base), IPU_CM_SIZE, 0, &ioh); 321 if (err) 322 goto fail_retarn_cm; 323 sc->cm_ioh = ioh; 324 325 /* map Display Multi FIFO Controller registers */ 326 err = bus_space_map(iot, IPU_DMFC_BASE(base), IPU_DMFC_SIZE, 0, &ioh); 327 if (err) 328 goto fail_retarn_dmfc; 329 sc->dmfc_ioh = ioh; 330 331 /* map Display Interface 0 registers */ 332 err = bus_space_map(iot, IPU_DI0_BASE(base), IPU_DI0_SIZE, 0, &ioh); 333 if (err) 334 goto fail_retarn_di0; 335 sc->di0_ioh = ioh; 336 337 /* map Display Interface 1 registers */ 338 err = bus_space_map(iot, IPU_DI1_BASE(base), IPU_DI0_SIZE, 0, &ioh); 339 if (err) 340 goto fail_retarn_di1; 341 sc->di1_ioh = ioh; 342 343 /* map Display Processor registers */ 344 err = bus_space_map(iot, IPU_DP_BASE(base), IPU_DP_SIZE, 0, &ioh); 345 if (err) 346 goto fail_retarn_dp; 347 sc->dp_ioh = ioh; 348 349 /* map Display Controller registers */ 350 err = bus_space_map(iot, IPU_DC_BASE(base), IPU_DC_SIZE, 0, &ioh); 351 if (err) 352 goto fail_retarn_dc; 353 sc->dc_ioh = ioh; 354 355 /* map Image DMA Controller registers */ 356 err = bus_space_map(iot, IPU_IDMAC_BASE(base), IPU_IDMAC_SIZE, 0, 357 &ioh); 358 if (err) 359 goto fail_retarn_idmac; 360 sc->idmac_ioh = ioh; 361 362 /* map CPMEM registers */ 363 err = bus_space_map(iot, IPU_CPMEM_BASE(base), IPU_CPMEM_SIZE, 0, 364 &ioh); 365 if (err) 366 goto fail_retarn_cpmem; 367 sc->cpmem_ioh = ioh; 368 369 /* map DCTEMPL registers */ 370 err = bus_space_map(iot, IPU_DCTMPL_BASE(base), IPU_DCTMPL_SIZE, 0, 371 &ioh); 372 if (err) 373 goto fail_retarn_dctmpl; 374 sc->dctmpl_ioh = ioh; 375 376#ifdef notyet 377 sc->ih = imx51_ipuv3_intr_establish(IMX51_INT_IPUV3, IPL_BIO, 378 ipuv3intr, sc); 379 if (sc->ih == NULL) { 380 device_printf(sc->dev, 381 "unable to establish interrupt at irq %d\n", 382 IMX51_INT_IPUV3); 383 return (ENXIO); 384 } 385#endif 386 387 /* 388 * We have to wait until interrupts are enabled. 389 * Mailbox relies on it to get data from VideoCore 390 */ 391 ipu3_fb_init(sc); 392 393 return (0); 394 395fail: 396 return (ENXIO); 397fail_retarn_dctmpl: 398 bus_space_unmap(sc->iot, sc->cpmem_ioh, IPU_CPMEM_SIZE); 399fail_retarn_cpmem: 400 bus_space_unmap(sc->iot, sc->idmac_ioh, IPU_IDMAC_SIZE); 401fail_retarn_idmac: 402 bus_space_unmap(sc->iot, sc->dc_ioh, IPU_DC_SIZE); 403fail_retarn_dp: 404 bus_space_unmap(sc->iot, sc->dp_ioh, IPU_DP_SIZE); 405fail_retarn_dc: 406 bus_space_unmap(sc->iot, sc->di1_ioh, IPU_DI1_SIZE); 407fail_retarn_di1: 408 bus_space_unmap(sc->iot, sc->di0_ioh, IPU_DI0_SIZE); 409fail_retarn_di0: 410 bus_space_unmap(sc->iot, sc->dmfc_ioh, IPU_DMFC_SIZE); 411fail_retarn_dmfc: 412 bus_space_unmap(sc->iot, sc->dc_ioh, IPU_CM_SIZE); 413fail_retarn_cm: 414 device_printf(sc->dev, 415 "failed to map registers (errno=%d)\n", err); 416 return (err); 417} 418 419static device_method_t ipu3_fb_methods[] = { 420 /* Device interface */ 421 DEVMETHOD(device_probe, ipu3_fb_probe), 422 DEVMETHOD(device_attach, ipu3_fb_attach), 423 424 { 0, 0 } 425}; 426 427static devclass_t ipu3_fb_devclass; 428 429static driver_t ipu3_fb_driver = { 430 "fb", 431 ipu3_fb_methods, 432 sizeof(struct ipu3sc_softc), 433}; 434 435DRIVER_MODULE(ipu3fb, simplebus, ipu3_fb_driver, ipu3_fb_devclass, 0, 0); 436 437/* 438 * Video driver routines and glue. 439 */ 440static int ipu3fb_configure(int); 441static vi_probe_t ipu3fb_probe; 442static vi_init_t ipu3fb_init; 443static vi_get_info_t ipu3fb_get_info; 444static vi_query_mode_t ipu3fb_query_mode; 445static vi_set_mode_t ipu3fb_set_mode; 446static vi_save_font_t ipu3fb_save_font; 447static vi_load_font_t ipu3fb_load_font; 448static vi_show_font_t ipu3fb_show_font; 449static vi_save_palette_t ipu3fb_save_palette; 450static vi_load_palette_t ipu3fb_load_palette; 451static vi_set_border_t ipu3fb_set_border; 452static vi_save_state_t ipu3fb_save_state; 453static vi_load_state_t ipu3fb_load_state; 454static vi_set_win_org_t ipu3fb_set_win_org; 455static vi_read_hw_cursor_t ipu3fb_read_hw_cursor; 456static vi_set_hw_cursor_t ipu3fb_set_hw_cursor; 457static vi_set_hw_cursor_shape_t ipu3fb_set_hw_cursor_shape; 458static vi_blank_display_t ipu3fb_blank_display; 459static vi_mmap_t ipu3fb_mmap; 460static vi_ioctl_t ipu3fb_ioctl; 461static vi_clear_t ipu3fb_clear; 462static vi_fill_rect_t ipu3fb_fill_rect; 463static vi_bitblt_t ipu3fb_bitblt; 464static vi_diag_t ipu3fb_diag; 465static vi_save_cursor_palette_t ipu3fb_save_cursor_palette; 466static vi_load_cursor_palette_t ipu3fb_load_cursor_palette; 467static vi_copy_t ipu3fb_copy; 468static vi_putp_t ipu3fb_putp; 469static vi_putc_t ipu3fb_putc; 470static vi_puts_t ipu3fb_puts; 471static vi_putm_t ipu3fb_putm; 472 473static video_switch_t ipu3fbvidsw = { 474 .probe = ipu3fb_probe, 475 .init = ipu3fb_init, 476 .get_info = ipu3fb_get_info, 477 .query_mode = ipu3fb_query_mode, 478 .set_mode = ipu3fb_set_mode, 479 .save_font = ipu3fb_save_font, 480 .load_font = ipu3fb_load_font, 481 .show_font = ipu3fb_show_font, 482 .save_palette = ipu3fb_save_palette, 483 .load_palette = ipu3fb_load_palette, 484 .set_border = ipu3fb_set_border, 485 .save_state = ipu3fb_save_state, 486 .load_state = ipu3fb_load_state, 487 .set_win_org = ipu3fb_set_win_org, 488 .read_hw_cursor = ipu3fb_read_hw_cursor, 489 .set_hw_cursor = ipu3fb_set_hw_cursor, 490 .set_hw_cursor_shape = ipu3fb_set_hw_cursor_shape, 491 .blank_display = ipu3fb_blank_display, 492 .mmap = ipu3fb_mmap, 493 .ioctl = ipu3fb_ioctl, 494 .clear = ipu3fb_clear, 495 .fill_rect = ipu3fb_fill_rect, 496 .bitblt = ipu3fb_bitblt, 497 .diag = ipu3fb_diag, 498 .save_cursor_palette = ipu3fb_save_cursor_palette, 499 .load_cursor_palette = ipu3fb_load_cursor_palette, 500 .copy = ipu3fb_copy, 501 .putp = ipu3fb_putp, 502 .putc = ipu3fb_putc, 503 .puts = ipu3fb_puts, 504 .putm = ipu3fb_putm, 505}; 506 507VIDEO_DRIVER(ipu3fb, ipu3fbvidsw, ipu3fb_configure); 508 509extern sc_rndr_sw_t txtrndrsw; 510RENDERER(ipu3fb, 0, txtrndrsw, gfb_set); 511RENDERER_MODULE(ipu3fb, gfb_set); 512 513static uint16_t ipu3fb_static_window[ROW*COL]; 514extern u_char dflt_font_16[]; 515 516static int 517ipu3fb_configure(int flags) 518{ 519 struct video_adapter_softc *sc; 520 521 sc = &va_softc; 522 523 if (sc->initialized) 524 return 0; 525 526 sc->width = 640; 527 sc->height = 480; 528 sc->bpp = 2; 529 sc->stride = sc->width * sc->bpp; 530 531 ipu3fb_init(0, &sc->va, 0); 532 533 sc->initialized = 1; 534 535 return (0); 536} 537 538static int 539ipu3fb_probe(int unit, video_adapter_t **adp, void *arg, int flags) 540{ 541 542 return (0); 543} 544 545static int 546ipu3fb_init(int unit, video_adapter_t *adp, int flags) 547{ 548 struct video_adapter_softc *sc; 549 video_info_t *vi; 550 551 sc = (struct video_adapter_softc *)adp; 552 vi = &adp->va_info; 553 554 vid_init_struct(adp, "ipu3fb", -1, unit); 555 556 sc->font = dflt_font_16; 557 vi->vi_cheight = IPU3FB_FONT_HEIGHT; 558 vi->vi_cwidth = 8; 559 vi->vi_width = sc->width/8; 560 vi->vi_height = sc->height/vi->vi_cheight; 561 562 /* 563 * Clamp width/height to syscons maximums 564 */ 565 if (vi->vi_width > COL) 566 vi->vi_width = COL; 567 if (vi->vi_height > ROW) 568 vi->vi_height = ROW; 569 570 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 571 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; 572 573 adp->va_window = (vm_offset_t) ipu3fb_static_window; 574 adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; 575 adp->va_line_width = sc->stride; 576 adp->va_buffer_size = sc->fb_size; 577 578 vid_register(&sc->va); 579 580 return (0); 581} 582 583static int 584ipu3fb_get_info(video_adapter_t *adp, int mode, video_info_t *info) 585{ 586 587 bcopy(&adp->va_info, info, sizeof(*info)); 588 return (0); 589} 590 591static int 592ipu3fb_query_mode(video_adapter_t *adp, video_info_t *info) 593{ 594 595 return (0); 596} 597 598static int 599ipu3fb_set_mode(video_adapter_t *adp, int mode) 600{ 601 602 return (0); 603} 604 605static int 606ipu3fb_save_font(video_adapter_t *adp, int page, int size, int width, 607 u_char *data, int c, int count) 608{ 609 610 return (0); 611} 612 613static int 614ipu3fb_load_font(video_adapter_t *adp, int page, int size, int width, 615 u_char *data, int c, int count) 616{ 617 struct video_adapter_softc *sc; 618 619 sc = (struct video_adapter_softc *)adp; 620 sc->font = data; 621 622 return (0); 623} 624 625static int 626ipu3fb_show_font(video_adapter_t *adp, int page) 627{ 628 629 return (0); 630} 631 632static int 633ipu3fb_save_palette(video_adapter_t *adp, u_char *palette) 634{ 635 636 return (0); 637} 638 639static int 640ipu3fb_load_palette(video_adapter_t *adp, u_char *palette) 641{ 642 643 return (0); 644} 645 646static int 647ipu3fb_set_border(video_adapter_t *adp, int border) 648{ 649 650 return (ipu3fb_blank_display(adp, border)); 651} 652 653static int 654ipu3fb_save_state(video_adapter_t *adp, void *p, size_t size) 655{ 656 657 return (0); 658} 659 660static int 661ipu3fb_load_state(video_adapter_t *adp, void *p) 662{ 663 664 return (0); 665} 666 667static int 668ipu3fb_set_win_org(video_adapter_t *adp, off_t offset) 669{ 670 671 return (0); 672} 673 674static int 675ipu3fb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 676{ 677 678 *col = *row = 0; 679 return (0); 680} 681 682static int 683ipu3fb_set_hw_cursor(video_adapter_t *adp, int col, int row) 684{ 685 686 return (0); 687} 688 689static int 690ipu3fb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 691 int celsize, int blink) 692{ 693 694 return (0); 695} 696 697static int 698ipu3fb_blank_display(video_adapter_t *adp, int mode) 699{ 700 701 return (0); 702} 703 704static int 705ipu3fb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, 706 int prot, vm_memattr_t *memattr) 707{ 708 struct video_adapter_softc *sc; 709 710 sc = (struct video_adapter_softc *)adp; 711 712 /* 713 * This might be a legacy VGA mem request: if so, just point it at the 714 * framebuffer, since it shouldn't be touched 715 */ 716 if (offset < sc->stride * sc->height) { 717 *paddr = sc->fb_paddr + offset; 718 return (0); 719 } 720 721 return (EINVAL); 722} 723 724static int 725ipu3fb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 726{ 727 struct video_adapter_softc *sc; 728 struct fbtype *fb; 729 730 sc = (struct video_adapter_softc *)adp; 731 732 switch (cmd) { 733 case FBIOGTYPE: 734 fb = (struct fbtype *)data; 735 fb->fb_type = FBTYPE_PCIMISC; 736 fb->fb_height = sc->height; 737 fb->fb_width = sc->width; 738 fb->fb_depth = sc->depth; 739 if (sc->depth <= 1 || sc->depth > 8) 740 fb->fb_cmsize = 0; 741 else 742 fb->fb_cmsize = 1 << sc->depth; 743 fb->fb_size = sc->fb_size; 744 break; 745 case FBIOSCURSOR: 746 return (ENODEV); 747 default: 748 return (fb_commonioctl(adp, cmd, data)); 749 } 750 751 return (0); 752} 753 754static int 755ipu3fb_clear(video_adapter_t *adp) 756{ 757 758 return (ipu3fb_blank_display(adp, 0)); 759} 760 761static int 762ipu3fb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 763{ 764 765 return (0); 766} 767 768static int 769ipu3fb_bitblt(video_adapter_t *adp, ...) 770{ 771 772 return (0); 773} 774 775static int 776ipu3fb_diag(video_adapter_t *adp, int level) 777{ 778 779 return (0); 780} 781 782static int 783ipu3fb_save_cursor_palette(video_adapter_t *adp, u_char *palette) 784{ 785 786 return (0); 787} 788 789static int 790ipu3fb_load_cursor_palette(video_adapter_t *adp, u_char *palette) 791{ 792 793 return (0); 794} 795 796static int 797ipu3fb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 798{ 799 800 return (0); 801} 802 803static int 804ipu3fb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 805 int size, int bpp, int bit_ltor, int byte_ltor) 806{ 807 808 return (0); 809} 810 811static int 812ipu3fb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 813{ 814 struct video_adapter_softc *sc; 815 int col, row, bpp; 816 int b, i, j, k; 817 uint8_t *addr; 818 u_char *p; 819 uint32_t fg, bg, color; 820 821 sc = (struct video_adapter_softc *)adp; 822 bpp = sc->bpp; 823 824 if (sc->fb_addr == 0) 825 return (0); 826 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 827 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 828 p = sc->font + c * IPU3FB_FONT_HEIGHT; 829 addr = (uint8_t *)sc->fb_addr 830 + (row + sc->ymargin) * (sc->stride) 831 + bpp * (col + sc->xmargin); 832 833 if (bpp == 2) { 834 bg = colors[(a >> 4) & 0x0f]; 835 fg = colors[a & 0x0f]; 836 } else if (bpp == 3) { 837 bg = colors_24[(a >> 4) & 0x0f]; 838 fg = colors_24[a & 0x0f]; 839 } else { 840 return (ENXIO); 841 } 842 843 for (i = 0; i < IPU3FB_FONT_HEIGHT; i++) { 844 for (j = 0, k = 7; j < 8; j++, k--) { 845 if ((p[i] & (1 << k)) == 0) 846 color = bg; 847 else 848 color = fg; 849 /* FIXME: BPP maybe different */ 850 for (b = 0; b < bpp; b ++) 851 addr[bpp * j + b] = 852 (color >> (b << 3)) & 0xff; 853 } 854 855 addr += (sc->stride); 856 } 857 858 return (0); 859} 860 861static int 862ipu3fb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 863{ 864 int i; 865 866 for (i = 0; i < len; i++) 867 ipu3fb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 868 869 return (0); 870} 871 872static int 873ipu3fb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 874 uint32_t pixel_mask, int size, int width) 875{ 876 877 return (0); 878} 879