The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/versatile/versatile_clcd.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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: releng/11.1/sys/arm/versatile/versatile_clcd.c 281085 2015-04-04 21:34:26Z andrew $");
   29 
   30 #include <sys/param.h>
   31 #include <sys/systm.h>
   32 #include <sys/bus.h>
   33 #include <sys/kernel.h>
   34 #include <sys/module.h>
   35 #include <sys/malloc.h>
   36 #include <sys/rman.h>
   37 #include <sys/fbio.h>
   38 #include <sys/consio.h>
   39 #include <sys/kdb.h>
   40 
   41 #include <machine/bus.h>
   42 #include <machine/cpu.h>
   43 #include <machine/intr.h>
   44 
   45 #include <dev/fdt/fdt_common.h>
   46 #include <dev/ofw/openfirm.h>
   47 #include <dev/ofw/ofw_bus.h>
   48 #include <dev/ofw/ofw_bus_subr.h>
   49 
   50 #include <dev/fb/fbreg.h>
   51 #include <dev/syscons/syscons.h>
   52 
   53 #include <machine/bus.h>
   54 
   55 #define PL110_VENDOR_ARM926PXP  1
   56 
   57 #define MEM_SYS         0
   58 #define MEM_CLCD        1
   59 #define MEM_REGIONS     2
   60 
   61 #define SYS_CLCD                0x00
   62 #define         SYS_CLCD_CLCDID_SHIFT   0x08
   63 #define         SYS_CLCD_CLCDID_MASK    0x1f
   64 #define         SYS_CLCD_PWR3V5VSWITCH  (1 << 4)
   65 #define         SYS_CLCD_VDDPOSSWITCH   (1 << 3)
   66 #define         SYS_CLCD_NLCDIOON       (1 << 2)
   67 #define         SYS_CLCD_LCD_MODE_MASK  0x03
   68 
   69 #define CLCD_MODE_RGB888        0x0
   70 #define CLCD_MODE_RGB555        0x01
   71 #define CLCD_MODE_RBG565        0x02
   72 #define CLCD_MODE_RGB565        0x03
   73 
   74 #define CLCDC_TIMING0           0x00
   75 #define CLCDC_TIMING1           0x04
   76 #define CLCDC_TIMING2           0x08
   77 #define CLCDC_TIMING3           0x0C
   78 #define CLCDC_TIMING3           0x0C
   79 #define CLCDC_UPBASE            0x10
   80 #define CLCDC_LPBASE            0x14
   81 #ifdef PL110_VENDOR_ARM926PXP
   82 #define CLCDC_CONTROL           0x18
   83 #define CLCDC_IMSC              0x1C
   84 #else
   85 #define CLCDC_IMSC              0x18
   86 #define CLCDC_CONTROL           0x1C
   87 #endif
   88 #define         CONTROL_WATERMARK       (1 << 16)
   89 #define         CONTROL_VCOMP_VS        (0 << 12)
   90 #define         CONTROL_VCOMP_BP        (1 << 12)
   91 #define         CONTROL_VCOMP_SAV       (2 << 12)
   92 #define         CONTROL_VCOMP_FP        (3 << 12)
   93 #define         CONTROL_PWR             (1 << 11)
   94 #define         CONTROL_BEPO            (1 << 10)
   95 #define         CONTROL_BEBO            (1 << 9)
   96 #define         CONTROL_BGR             (1 << 8)
   97 #define         CONTROL_DUAL            (1 << 7)
   98 #define         CONTROL_MONO8           (1 << 6)
   99 #define         CONTROL_TFT             (1 << 5)
  100 #define         CONTROL_BW              (1 << 4)
  101 #define         CONTROL_BPP1            (0x00 << 1)
  102 #define         CONTROL_BPP2            (0x01 << 1)
  103 #define         CONTROL_BPP4            (0x02 << 1)
  104 #define         CONTROL_BPP8            (0x03 << 1)
  105 #define         CONTROL_BPP16           (0x04 << 1)
  106 #define         CONTROL_BPP24           (0x05 << 1)
  107 #define         CONTROL_EN      (1 << 0)
  108 #define CLCDC_RIS               0x20
  109 #define CLCDC_MIS               0x24
  110 #define         INTR_MBERR              (1 << 4)
  111 #define         INTR_VCOMP              (1 << 3)
  112 #define         INTR_LNB                (1 << 2)
  113 #define         INTR_FUF                (1 << 1)
  114 #define CLCDC_ICR               0x28
  115 
  116 #ifdef DEBUG
  117 #define dprintf(fmt, args...) do { printf("%s(): ", __func__);   \
  118     printf(fmt,##args); } while (0)
  119 #else
  120 #define dprintf(fmt, args...)
  121 #endif
  122 
  123 #define versatile_clcdc_sys_read_4(sc, reg)     \
  124         bus_read_4((sc)->mem_res[MEM_SYS], (reg))
  125 #define versatile_clcdc_sys_write_4(sc, reg, val)       \
  126         bus_write_4((sc)->mem_res[MEM_SYS], (reg), (val))
  127 
  128 #define versatile_clcdc_read_4(sc, reg) \
  129         bus_read_4((sc)->mem_res[MEM_CLCD], (reg))
  130 #define versatile_clcdc_write_4(sc, reg, val)   \
  131         bus_write_4((sc)->mem_res[MEM_CLCD], (reg), (val))
  132 
  133 struct versatile_clcdc_softc {
  134         struct resource*        mem_res[MEM_REGIONS];
  135 
  136         struct mtx              mtx;
  137 
  138         int                     width;
  139         int                     height;
  140         int                     mode;
  141 
  142         bus_dma_tag_t           dma_tag;
  143         bus_dmamap_t            dma_map;
  144         bus_addr_t              fb_phys;
  145         uint8_t                 *fb_base;
  146 
  147 };
  148 
  149 struct video_adapter_softc {
  150         /* Videoadpater part */
  151         video_adapter_t va;
  152         int             console;
  153 
  154         intptr_t        fb_addr;
  155         unsigned int    fb_size;
  156 
  157         unsigned int    height;
  158         unsigned int    width;
  159         unsigned int    depth;
  160         unsigned int    stride;
  161 
  162         unsigned int    xmargin;
  163         unsigned int    ymargin;
  164 
  165         unsigned char   *font;
  166         int             initialized;
  167 };
  168 
  169 struct argb {
  170         uint8_t         a;
  171         uint8_t         r;
  172         uint8_t         g;
  173         uint8_t         b;
  174 };
  175 
  176 static struct argb versatilefb_palette[16] = {
  177         {0x00, 0x00, 0x00, 0x00},
  178         {0x00, 0x00, 0x00, 0xaa},
  179         {0x00, 0x00, 0xaa, 0x00},
  180         {0x00, 0x00, 0xaa, 0xaa},
  181         {0x00, 0xaa, 0x00, 0x00},
  182         {0x00, 0xaa, 0x00, 0xaa},
  183         {0x00, 0xaa, 0x55, 0x00},
  184         {0x00, 0xaa, 0xaa, 0xaa},
  185         {0x00, 0x55, 0x55, 0x55},
  186         {0x00, 0x55, 0x55, 0xff},
  187         {0x00, 0x55, 0xff, 0x55},
  188         {0x00, 0x55, 0xff, 0xff},
  189         {0x00, 0xff, 0x55, 0x55},
  190         {0x00, 0xff, 0x55, 0xff},
  191         {0x00, 0xff, 0xff, 0x55},
  192         {0x00, 0xff, 0xff, 0xff}
  193 };
  194 
  195 /* mouse pointer from dev/syscons/scgfbrndr.c */
  196 static u_char mouse_pointer[16] = {
  197         0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
  198         0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
  199 };
  200 
  201 #define FB_WIDTH                640
  202 #define FB_HEIGHT               480
  203 #define FB_DEPTH                16
  204 
  205 #define VERSATILE_FONT_HEIGHT   16
  206 
  207 static struct video_adapter_softc va_softc;
  208 
  209 static struct resource_spec versatile_clcdc_mem_spec[] = {
  210         { SYS_RES_MEMORY, 0, RF_ACTIVE },
  211         { SYS_RES_MEMORY, 1, RF_ACTIVE },
  212         { -1, 0, 0 }
  213 };
  214 
  215 static int versatilefb_configure(int);
  216 static void versatilefb_update_margins(video_adapter_t *adp);
  217 
  218 static void
  219 versatile_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err)
  220 {
  221         bus_addr_t *addr;
  222 
  223         if (err)
  224                 return;
  225 
  226         addr = (bus_addr_t*)arg;
  227         *addr = segs[0].ds_addr;
  228 }
  229 
  230 static int
  231 versatile_clcdc_probe(device_t dev)
  232 {
  233 
  234         if (!ofw_bus_status_okay(dev))
  235                 return (ENXIO);
  236 
  237         if (ofw_bus_is_compatible(dev, "arm,pl110")) {
  238                 device_set_desc(dev, "PL110 CLCD controller");
  239                 return (BUS_PROBE_DEFAULT);
  240         }
  241 
  242         return (ENXIO);
  243 }
  244 
  245 static int
  246 versatile_clcdc_attach(device_t dev)
  247 {
  248         struct versatile_clcdc_softc *sc = device_get_softc(dev);
  249         struct video_adapter_softc *va_sc = &va_softc;
  250         int err;
  251         uint32_t reg;
  252         int clcdid;
  253         int dma_size;
  254 
  255         /* Request memory resources */
  256         err = bus_alloc_resources(dev, versatile_clcdc_mem_spec,
  257                 sc->mem_res);
  258         if (err) {
  259                 device_printf(dev, "Error: could not allocate memory resources\n");
  260                 return (ENXIO);
  261         }
  262 
  263         reg = versatile_clcdc_sys_read_4(sc, SYS_CLCD);
  264         clcdid = (reg >> SYS_CLCD_CLCDID_SHIFT) & SYS_CLCD_CLCDID_MASK;
  265         switch (clcdid) {
  266                 case 31:
  267                         device_printf(dev, "QEMU VGA 640x480\n");
  268                         sc->width = 640;
  269                         sc->height = 480;
  270                         break;
  271                 default:
  272                         device_printf(dev, "Unsupported: %d\n", clcdid);
  273                         goto fail;
  274         }
  275 
  276         reg &= ~SYS_CLCD_LCD_MODE_MASK;
  277         reg |= CLCD_MODE_RGB565;
  278         sc->mode = CLCD_MODE_RGB565;
  279         versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
  280         dma_size = sc->width*sc->height*2;
  281 
  282         /*
  283          * Power on LCD
  284          */
  285         reg |= SYS_CLCD_PWR3V5VSWITCH | SYS_CLCD_NLCDIOON;
  286         versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
  287 
  288         /*
  289          * XXX: hardcoded timing for VGA. For other modes/panels
  290          * we need to keep table of timing register values
  291          */
  292         /*
  293          * XXX: set SYS_OSC1 
  294          */
  295         versatile_clcdc_write_4(sc, CLCDC_TIMING0, 0x3F1F3F9C);
  296         versatile_clcdc_write_4(sc, CLCDC_TIMING1, 0x090B61DF);
  297         versatile_clcdc_write_4(sc, CLCDC_TIMING2, 0x067F1800);
  298         /* XXX: timing 3? */
  299 
  300         /*
  301          * Now allocate framebuffer memory
  302          */
  303         err = bus_dma_tag_create(
  304             bus_get_dma_tag(dev),
  305             4, 0,               /* alignment, boundary */
  306             BUS_SPACE_MAXADDR_32BIT,    /* lowaddr */
  307             BUS_SPACE_MAXADDR,          /* highaddr */
  308             NULL, NULL,                 /* filter, filterarg */
  309             dma_size, 1,                /* maxsize, nsegments */
  310             dma_size, 0,                /* maxsegsize, flags */
  311             NULL, NULL,                 /* lockfunc, lockarg */
  312             &sc->dma_tag);
  313 
  314         err = bus_dmamem_alloc(sc->dma_tag, (void **)&sc->fb_base,
  315             0, &sc->dma_map);
  316         if (err) {
  317                 device_printf(dev, "cannot allocate framebuffer\n");
  318                 goto fail;
  319         }
  320 
  321         err = bus_dmamap_load(sc->dma_tag, sc->dma_map, sc->fb_base,
  322             dma_size, versatile_fb_dmamap_cb, &sc->fb_phys, BUS_DMA_NOWAIT);
  323 
  324         if (err) {
  325                 device_printf(dev, "cannot load DMA map\n");
  326                 goto fail;
  327         }
  328 
  329         /* Make sure it's blank */
  330         memset(sc->fb_base, 0x00, dma_size);
  331 
  332         versatile_clcdc_write_4(sc, CLCDC_UPBASE, sc->fb_phys);
  333 
  334         err = (sc_attach_unit(device_get_unit(dev),
  335             device_get_flags(dev) | SC_AUTODETECT_KBD));
  336 
  337         if (err) {
  338                 device_printf(dev, "failed to attach syscons\n");
  339                 goto fail;
  340         }
  341 
  342         /*
  343          * XXX: hardcoded for VGA
  344          */
  345         reg = CONTROL_VCOMP_BP | CONTROL_TFT | CONTROL_BGR | CONTROL_EN;
  346         reg |= CONTROL_BPP16;
  347         versatile_clcdc_write_4(sc, CLCDC_CONTROL, reg);
  348         DELAY(20);
  349         reg |= CONTROL_PWR;
  350         versatile_clcdc_write_4(sc, CLCDC_CONTROL, reg);
  351 
  352         va_sc->fb_addr = (vm_offset_t)sc->fb_base;
  353         va_sc->fb_size = dma_size;
  354         va_sc->width = sc->width;
  355         va_sc->height = sc->height;
  356         va_sc->depth = 16;
  357         va_sc->stride = sc->width * 2;
  358         versatilefb_update_margins(&va_sc->va);
  359 
  360         return (0);
  361 
  362 fail:
  363         if (sc->fb_base)
  364                 bus_dmamem_free(sc->dma_tag, sc->fb_base, sc->dma_map);
  365         if (sc->dma_tag)
  366                 bus_dma_tag_destroy(sc->dma_tag);
  367         return (err);
  368 }
  369 
  370 static device_method_t versatile_clcdc_methods[] = {
  371         DEVMETHOD(device_probe,         versatile_clcdc_probe),
  372         DEVMETHOD(device_attach,        versatile_clcdc_attach),
  373 
  374         DEVMETHOD_END
  375 };
  376 
  377 static driver_t versatile_clcdc_driver = {
  378         "clcdc",
  379         versatile_clcdc_methods,
  380         sizeof(struct versatile_clcdc_softc),
  381 };
  382 
  383 static devclass_t versatile_clcdc_devclass;
  384 
  385 DRIVER_MODULE(versatile_clcdc, simplebus, versatile_clcdc_driver, versatile_clcdc_devclass, 0, 0);
  386 
  387 /*
  388  * Video driver routines and glue.
  389  */
  390 static vi_probe_t               versatilefb_probe;
  391 static vi_init_t                versatilefb_init;
  392 static vi_get_info_t            versatilefb_get_info;
  393 static vi_query_mode_t          versatilefb_query_mode;
  394 static vi_set_mode_t            versatilefb_set_mode;
  395 static vi_save_font_t           versatilefb_save_font;
  396 static vi_load_font_t           versatilefb_load_font;
  397 static vi_show_font_t           versatilefb_show_font;
  398 static vi_save_palette_t        versatilefb_save_palette;
  399 static vi_load_palette_t        versatilefb_load_palette;
  400 static vi_set_border_t          versatilefb_set_border;
  401 static vi_save_state_t          versatilefb_save_state;
  402 static vi_load_state_t          versatilefb_load_state;
  403 static vi_set_win_org_t         versatilefb_set_win_org;
  404 static vi_read_hw_cursor_t      versatilefb_read_hw_cursor;
  405 static vi_set_hw_cursor_t       versatilefb_set_hw_cursor;
  406 static vi_set_hw_cursor_shape_t versatilefb_set_hw_cursor_shape;
  407 static vi_blank_display_t       versatilefb_blank_display;
  408 static vi_mmap_t                versatilefb_mmap;
  409 static vi_ioctl_t               versatilefb_ioctl;
  410 static vi_clear_t               versatilefb_clear;
  411 static vi_fill_rect_t           versatilefb_fill_rect;
  412 static vi_bitblt_t              versatilefb_bitblt;
  413 static vi_diag_t                versatilefb_diag;
  414 static vi_save_cursor_palette_t versatilefb_save_cursor_palette;
  415 static vi_load_cursor_palette_t versatilefb_load_cursor_palette;
  416 static vi_copy_t                versatilefb_copy;
  417 static vi_putp_t                versatilefb_putp;
  418 static vi_putc_t                versatilefb_putc;
  419 static vi_puts_t                versatilefb_puts;
  420 static vi_putm_t                versatilefb_putm;
  421 
  422 static video_switch_t versatilefbvidsw = {
  423         .probe                  = versatilefb_probe,
  424         .init                   = versatilefb_init,
  425         .get_info               = versatilefb_get_info,
  426         .query_mode             = versatilefb_query_mode,
  427         .set_mode               = versatilefb_set_mode,
  428         .save_font              = versatilefb_save_font,
  429         .load_font              = versatilefb_load_font,
  430         .show_font              = versatilefb_show_font,
  431         .save_palette           = versatilefb_save_palette,
  432         .load_palette           = versatilefb_load_palette,
  433         .set_border             = versatilefb_set_border,
  434         .save_state             = versatilefb_save_state,
  435         .load_state             = versatilefb_load_state,
  436         .set_win_org            = versatilefb_set_win_org,
  437         .read_hw_cursor         = versatilefb_read_hw_cursor,
  438         .set_hw_cursor          = versatilefb_set_hw_cursor,
  439         .set_hw_cursor_shape    = versatilefb_set_hw_cursor_shape,
  440         .blank_display          = versatilefb_blank_display,
  441         .mmap                   = versatilefb_mmap,
  442         .ioctl                  = versatilefb_ioctl,
  443         .clear                  = versatilefb_clear,
  444         .fill_rect              = versatilefb_fill_rect,
  445         .bitblt                 = versatilefb_bitblt,
  446         .diag                   = versatilefb_diag,
  447         .save_cursor_palette    = versatilefb_save_cursor_palette,
  448         .load_cursor_palette    = versatilefb_load_cursor_palette,
  449         .copy                   = versatilefb_copy,
  450         .putp                   = versatilefb_putp,
  451         .putc                   = versatilefb_putc,
  452         .puts                   = versatilefb_puts,
  453         .putm                   = versatilefb_putm,
  454 };
  455 
  456 VIDEO_DRIVER(versatilefb, versatilefbvidsw, versatilefb_configure);
  457 
  458 static vr_init_t clcdr_init;
  459 static vr_clear_t clcdr_clear;
  460 static vr_draw_border_t clcdr_draw_border;
  461 static vr_draw_t clcdr_draw;
  462 static vr_set_cursor_t clcdr_set_cursor;
  463 static vr_draw_cursor_t clcdr_draw_cursor;
  464 static vr_blink_cursor_t clcdr_blink_cursor;
  465 static vr_set_mouse_t clcdr_set_mouse;
  466 static vr_draw_mouse_t clcdr_draw_mouse;
  467 
  468 /*
  469  * We use our own renderer; this is because we must emulate a hardware
  470  * cursor.
  471  */
  472 static sc_rndr_sw_t clcdrend = {
  473         clcdr_init,
  474         clcdr_clear,
  475         clcdr_draw_border,
  476         clcdr_draw,
  477         clcdr_set_cursor,
  478         clcdr_draw_cursor,
  479         clcdr_blink_cursor,
  480         clcdr_set_mouse,
  481         clcdr_draw_mouse
  482 };
  483 
  484 RENDERER(versatilefb, 0, clcdrend, gfb_set);
  485 RENDERER_MODULE(versatilefb, gfb_set);
  486 
  487 static void
  488 clcdr_init(scr_stat* scp)
  489 {
  490 }
  491 
  492 static void
  493 clcdr_clear(scr_stat* scp, int c, int attr)
  494 {
  495 }
  496 
  497 static void
  498 clcdr_draw_border(scr_stat* scp, int color)
  499 {
  500 }
  501 
  502 static void
  503 clcdr_draw(scr_stat* scp, int from, int count, int flip)
  504 {
  505         video_adapter_t* adp = scp->sc->adp;
  506         int i, c, a;
  507 
  508         if (!flip) {
  509                 /* Normal printing */
  510                 vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count);
  511         } else {        
  512                 /* This is for selections and such: invert the color attribute */
  513                 for (i = count; i-- > 0; ++from) {
  514                         c = sc_vtb_getc(&scp->vtb, from);
  515                         a = sc_vtb_geta(&scp->vtb, from) >> 8;
  516                         vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4));
  517                 }
  518         }
  519 }
  520 
  521 static void
  522 clcdr_set_cursor(scr_stat* scp, int base, int height, int blink)
  523 {
  524 }
  525 
  526 static void
  527 clcdr_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip)
  528 {
  529         video_adapter_t* adp = scp->sc->adp;
  530         struct video_adapter_softc *sc;
  531         int row, col;
  532         uint8_t *addr;
  533         int i,j;
  534 
  535         sc = (struct video_adapter_softc *)adp;
  536 
  537         if (scp->curs_attr.height <= 0)
  538                 return;
  539 
  540         if (sc->fb_addr == 0)
  541                 return;
  542 
  543         if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
  544                 return;
  545 
  546         /* calculate the coordinates in the video buffer */
  547         row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
  548         col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
  549 
  550         addr = (uint8_t *)sc->fb_addr
  551             + (row + sc->ymargin)*(sc->stride)
  552             + (sc->depth/8) * (col + sc->xmargin);
  553 
  554         /* our cursor consists of simply inverting the char under it */
  555         for (i = 0; i < adp->va_info.vi_cheight; i++) {
  556                 for (j = 0; j < adp->va_info.vi_cwidth; j++) {
  557 
  558                         addr[2*j] ^= 0xff;
  559                         addr[2*j + 1] ^= 0xff;
  560                 }
  561 
  562                 addr += sc->stride;
  563         }
  564 }
  565 
  566 static void
  567 clcdr_blink_cursor(scr_stat* scp, int at, int flip)
  568 {
  569 }
  570 
  571 static void
  572 clcdr_set_mouse(scr_stat* scp)
  573 {
  574 }
  575 
  576 static void
  577 clcdr_draw_mouse(scr_stat* scp, int x, int y, int on)
  578 {
  579         vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8);
  580 
  581 }
  582 
  583 static uint16_t versatilefb_static_window[ROW*COL];
  584 extern u_char dflt_font_16[];
  585 
  586 /*
  587  * Update videoadapter settings after changing resolution
  588  */
  589 static void
  590 versatilefb_update_margins(video_adapter_t *adp)
  591 {
  592         struct video_adapter_softc *sc;
  593         video_info_t *vi;
  594 
  595         sc = (struct video_adapter_softc *)adp;
  596         vi = &adp->va_info;
  597 
  598         sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
  599         sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
  600 }
  601 
  602 static int
  603 versatilefb_configure(int flags)
  604 {
  605         struct video_adapter_softc *va_sc;
  606 
  607         va_sc = &va_softc;
  608 
  609         if (va_sc->initialized)
  610                 return (0);
  611 
  612         va_sc->width = FB_WIDTH;
  613         va_sc->height = FB_HEIGHT;
  614         va_sc->depth = FB_DEPTH;
  615 
  616         versatilefb_init(0, &va_sc->va, 0);
  617 
  618         va_sc->initialized = 1;
  619 
  620         return (0);
  621 }
  622 
  623 static int
  624 versatilefb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
  625 {
  626 
  627         return (0);
  628 }
  629 
  630 static int
  631 versatilefb_init(int unit, video_adapter_t *adp, int flags)
  632 {
  633         struct video_adapter_softc *sc;
  634         video_info_t *vi;
  635 
  636         sc = (struct video_adapter_softc *)adp;
  637         vi = &adp->va_info;
  638 
  639         vid_init_struct(adp, "versatilefb", -1, unit);
  640 
  641         sc->font = dflt_font_16;
  642         vi->vi_cheight = VERSATILE_FONT_HEIGHT;
  643         vi->vi_cwidth = 8;
  644 
  645         vi->vi_width = sc->width/8;
  646         vi->vi_height = sc->height/vi->vi_cheight;
  647 
  648         /*
  649          * Clamp width/height to syscons maximums
  650          */
  651         if (vi->vi_width > COL)
  652                 vi->vi_width = COL;
  653         if (vi->vi_height > ROW)
  654                 vi->vi_height = ROW;
  655 
  656         sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
  657         sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
  658 
  659 
  660         adp->va_window = (vm_offset_t) versatilefb_static_window;
  661         adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
  662 
  663         vid_register(&sc->va);
  664 
  665         return (0);
  666 }
  667 
  668 static int
  669 versatilefb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
  670 {
  671         bcopy(&adp->va_info, info, sizeof(*info));
  672         return (0);
  673 }
  674 
  675 static int
  676 versatilefb_query_mode(video_adapter_t *adp, video_info_t *info)
  677 {
  678         return (0);
  679 }
  680 
  681 static int
  682 versatilefb_set_mode(video_adapter_t *adp, int mode)
  683 {
  684         return (0);
  685 }
  686 
  687 static int
  688 versatilefb_save_font(video_adapter_t *adp, int page, int size, int width,
  689     u_char *data, int c, int count)
  690 {
  691         return (0);
  692 }
  693 
  694 static int
  695 versatilefb_load_font(video_adapter_t *adp, int page, int size, int width,
  696     u_char *data, int c, int count)
  697 {
  698         struct video_adapter_softc *sc = (struct video_adapter_softc *)adp;
  699 
  700         sc->font = data;
  701 
  702         return (0);
  703 }
  704 
  705 static int
  706 versatilefb_show_font(video_adapter_t *adp, int page)
  707 {
  708         return (0);
  709 }
  710 
  711 static int
  712 versatilefb_save_palette(video_adapter_t *adp, u_char *palette)
  713 {
  714         return (0);
  715 }
  716 
  717 static int
  718 versatilefb_load_palette(video_adapter_t *adp, u_char *palette)
  719 {
  720         return (0);
  721 }
  722 
  723 static int
  724 versatilefb_set_border(video_adapter_t *adp, int border)
  725 {
  726         return (versatilefb_blank_display(adp, border));
  727 }
  728 
  729 static int
  730 versatilefb_save_state(video_adapter_t *adp, void *p, size_t size)
  731 {
  732         return (0);
  733 }
  734 
  735 static int
  736 versatilefb_load_state(video_adapter_t *adp, void *p)
  737 {
  738         return (0);
  739 }
  740 
  741 static int
  742 versatilefb_set_win_org(video_adapter_t *adp, off_t offset)
  743 {
  744         return (0);
  745 }
  746 
  747 static int
  748 versatilefb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
  749 {
  750         *col = *row = 0;
  751 
  752         return (0);
  753 }
  754 
  755 static int
  756 versatilefb_set_hw_cursor(video_adapter_t *adp, int col, int row)
  757 {
  758 
  759         return (0);
  760 }
  761 
  762 static int
  763 versatilefb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
  764     int celsize, int blink)
  765 {
  766         return (0);
  767 }
  768 
  769 static int
  770 versatilefb_blank_display(video_adapter_t *adp, int mode)
  771 {
  772 
  773         struct video_adapter_softc *sc;
  774 
  775         sc = (struct video_adapter_softc *)adp;
  776         if (sc && sc->fb_addr)
  777                 memset((void*)sc->fb_addr, 0, sc->fb_size);
  778 
  779         return (0);
  780 }
  781 
  782 static int
  783 versatilefb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
  784     int prot, vm_memattr_t *memattr)
  785 {
  786         struct video_adapter_softc *sc;
  787 
  788         sc = (struct video_adapter_softc *)adp;
  789 
  790         /*
  791          * This might be a legacy VGA mem request: if so, just point it at the
  792          * framebuffer, since it shouldn't be touched
  793          */
  794         if (offset < sc->stride*sc->height) {
  795                 *paddr = sc->fb_addr + offset;
  796                 return (0);
  797         }
  798 
  799         return (EINVAL);
  800 }
  801 
  802 static int
  803 versatilefb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
  804 {
  805 
  806         return (0);
  807 }
  808 
  809 static int
  810 versatilefb_clear(video_adapter_t *adp)
  811 {
  812 
  813         return (versatilefb_blank_display(adp, 0));
  814 }
  815 
  816 static int
  817 versatilefb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
  818 {
  819 
  820         return (0);
  821 }
  822 
  823 static int
  824 versatilefb_bitblt(video_adapter_t *adp, ...)
  825 {
  826 
  827         return (0);
  828 }
  829 
  830 static int
  831 versatilefb_diag(video_adapter_t *adp, int level)
  832 {
  833 
  834         return (0);
  835 }
  836 
  837 static int
  838 versatilefb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
  839 {
  840 
  841         return (0);
  842 }
  843 
  844 static int
  845 versatilefb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
  846 {
  847 
  848         return (0);
  849 }
  850 
  851 static int
  852 versatilefb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
  853 {
  854 
  855         return (0);
  856 }
  857 
  858 static int
  859 versatilefb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
  860     int size, int bpp, int bit_ltor, int byte_ltor)
  861 {
  862 
  863         return (0);
  864 }
  865 
  866 static int
  867 versatilefb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
  868 {
  869         struct video_adapter_softc *sc;
  870         int row;
  871         int col;
  872         int i, j, k;
  873         uint8_t *addr;
  874         u_char *p;
  875         uint8_t fg, bg, color;
  876         uint16_t rgb;
  877 
  878         sc = (struct video_adapter_softc *)adp;
  879 
  880         if (sc->fb_addr == 0)
  881                 return (0);
  882 
  883         if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
  884                 return (0);
  885 
  886         row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
  887         col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
  888         p = sc->font + c*VERSATILE_FONT_HEIGHT;
  889         addr = (uint8_t *)sc->fb_addr
  890             + (row + sc->ymargin)*(sc->stride)
  891             + (sc->depth/8) * (col + sc->xmargin);
  892 
  893         fg = a & 0xf ;
  894         bg = (a >> 4) & 0xf;
  895 
  896         for (i = 0; i < VERSATILE_FONT_HEIGHT; i++) {
  897                 for (j = 0, k = 7; j < 8; j++, k--) {
  898                         if ((p[i] & (1 << k)) == 0)
  899                                 color = bg;
  900                         else
  901                                 color = fg;
  902 
  903                         switch (sc->depth) {
  904                         case 16:
  905                                 rgb = (versatilefb_palette[color].r >> 3) << 11;
  906                                 rgb |= (versatilefb_palette[color].g >> 2) << 5;
  907                                 rgb |= (versatilefb_palette[color].b >> 3);
  908                                 addr[2*j] = rgb & 0xff;
  909                                 addr[2*j + 1] = (rgb >> 8) & 0xff;
  910                         default:
  911                                 /* Not supported yet */
  912                                 break;
  913                         }
  914                 }
  915 
  916                 addr += (sc->stride);
  917         }
  918 
  919         return (0);
  920 }
  921 
  922 static int
  923 versatilefb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
  924 {
  925         int i;
  926 
  927         for (i = 0; i < len; i++) 
  928                 versatilefb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
  929 
  930         return (0);
  931 }
  932 
  933 static int
  934 versatilefb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
  935     uint32_t pixel_mask, int size, int width)
  936 {
  937 
  938         return (0);
  939 }
  940 
  941 /*
  942  * Define a stub keyboard driver in case one hasn't been
  943  * compiled into the kernel
  944  */
  945 #include <sys/kbio.h>
  946 #include <dev/kbd/kbdreg.h>
  947 
  948 static int dummy_kbd_configure(int flags);
  949 
  950 keyboard_switch_t bcmdummysw;
  951 
  952 static int
  953 dummy_kbd_configure(int flags)
  954 {
  955 
  956         return (0);
  957 }
  958 KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure);

Cache object: d8806dd9e976882f316ace4a3a1bba93


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.