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

Cache object: d3b78eb857e63ad6bcaf09c70d64fa4f


[ 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.