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