1239691Srwatson/*- 2239691Srwatson * Copyright (c) 2012 Robert N. M. Watson 3239691Srwatson * All rights reserved. 4239691Srwatson * 5239691Srwatson * This software was developed by SRI International and the University of 6239691Srwatson * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7239691Srwatson * ("CTSRD"), as part of the DARPA CRASH research programme. 8239691Srwatson * 9239691Srwatson * Redistribution and use in source and binary forms, with or without 10239691Srwatson * modification, are permitted provided that the following conditions 11239691Srwatson * are met: 12239691Srwatson * 1. Redistributions of source code must retain the above copyright 13239691Srwatson * notice, this list of conditions and the following disclaimer. 14239691Srwatson * 2. Redistributions in binary form must reproduce the above copyright 15239691Srwatson * notice, this list of conditions and the following disclaimer in the 16239691Srwatson * documentation and/or other materials provided with the distribution. 17239691Srwatson * 18239691Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19239691Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20239691Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21239691Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22239691Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23239691Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24239691Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25239691Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26239691Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27239691Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28239691Srwatson * SUCH DAMAGE. 29239691Srwatson * 30239691Srwatson * $FreeBSD: releng/10.3/sys/dev/terasic/mtl/terasic_mtl.h 245380 2013-01-13 16:57:11Z rwatson $ 31239691Srwatson */ 32239691Srwatson 33239691Srwatson#ifndef _DEV_TERASIC_MTL_H_ 34239691Srwatson#define _DEV_TERASIC_MTL_H_ 35239691Srwatson 36239691Srwatsonstruct terasic_mtl_softc { 37239691Srwatson /* 38239691Srwatson * syscons requires that its video_adapter_t be at the front of the 39239691Srwatson * softc, so place syscons fields first, which we otherwise would 40239691Srwatson * probably not do. 41239691Srwatson */ 42239691Srwatson video_adapter_t mtl_va; 43239691Srwatson 44239691Srwatson /* 45239691Srwatson * Bus-related fields. 46239691Srwatson */ 47239691Srwatson device_t mtl_dev; 48239691Srwatson int mtl_unit; 49239691Srwatson 50239691Srwatson /* 51239691Srwatson * The MTL driver doesn't require a lot of synchronisation; however, 52239691Srwatson * the lock is used to protect read-modify-write operations on MTL 53239691Srwatson * registers. 54239691Srwatson */ 55239691Srwatson struct mtx mtl_lock; 56239691Srwatson 57239691Srwatson /* 58239691Srwatson * Control register device -- mappable from userspace. 59239691Srwatson */ 60239691Srwatson struct cdev *mtl_reg_cdev; 61239691Srwatson struct resource *mtl_reg_res; 62239691Srwatson int mtl_reg_rid; 63239691Srwatson 64239691Srwatson /* 65239691Srwatson * Graphics frame buffer device -- mappable form userspace. 66239691Srwatson */ 67239691Srwatson struct cdev *mtl_pixel_cdev; 68239691Srwatson struct resource *mtl_pixel_res; 69239691Srwatson int mtl_pixel_rid; 70239691Srwatson 71239691Srwatson /* 72239691Srwatson * Text frame buffer device -- mappable from userspace, and syscons 73239691Srwatson * hookup. 74239691Srwatson */ 75239691Srwatson struct cdev *mtl_text_cdev; 76239691Srwatson struct resource *mtl_text_res; 77239691Srwatson int mtl_text_rid; 78239691Srwatson uint16_t *mtl_text_soft; 79239691Srwatson}; 80239691Srwatson 81239691Srwatson#define TERASIC_MTL_LOCK(sc) mtx_lock(&(sc)->mtl_lock) 82239691Srwatson#define TERASIC_MTL_LOCK_ASSERT(sc) mtx_assert(&(sc)->mtl_lock, MA_OWNED) 83239691Srwatson#define TERASIC_MTL_LOCK_DESTROY(sc) mtx_destroy(&(sc)->mtl_lock) 84239691Srwatson#define TERASIC_MTL_LOCK_INIT(sc) mtx_init(&(sc)->mtl_lock, \ 85239691Srwatson "terasic_mtl", NULL, MTX_DEF) 86239691Srwatson#define TERASIC_MTL_UNLOCK(sc) mtx_unlock(&(sc)->mtl_lock) 87239691Srwatson 88239691Srwatson/* 89239691Srwatson * Constant properties of the MTL text frame buffer. 90239691Srwatson */ 91239691Srwatson#define TERASIC_MTL_COLS 100 92239691Srwatson#define TERASIC_MTL_ROWS 40 93239691Srwatson 94239691Srwatson/* 95239691Srwatson * MTL control register offsets. 96239691Srwatson */ 97239691Srwatson#define TERASIC_MTL_OFF_BLEND 0 98239691Srwatson#define TERASIC_MTL_OFF_TEXTCURSOR 4 99239691Srwatson#define TERASIC_MTL_OFF_TEXTFRAMEBUFADDR 8 100239691Srwatson#define TERASIC_MTL_OFF_TOUCHPOINT_X1 12 101239691Srwatson#define TERASIC_MTL_OFF_TOUCHPOINT_Y1 16 102239691Srwatson#define TERASIC_MTL_OFF_TOUCHPOINT_X2 20 103239691Srwatson#define TERASIC_MTL_OFF_TOUCHPOINT_Y2 24 104239691Srwatson#define TERASIC_MTL_OFF_TOUCHGESTURE 28 105239691Srwatson 106239691Srwatson/* 107239691Srwatson * Constants to help interpret various control registers. 108239691Srwatson */ 109239691Srwatson#define TERASIC_MTL_BLEND_DEFAULT_MASK 0x0f000000 110239691Srwatson#define TERASIC_MTL_BLEND_DEFAULT_SHIFT 24 111239691Srwatson#define TERASIC_MTL_BLEND_PIXEL_MASK 0x00ff0000 112239691Srwatson#define TERASIC_MTL_BLEND_PIXEL_SHIFT 16 113239691Srwatson#define TERASIC_MTL_BLEND_TEXTFG_MASK 0x0000ff00 114239691Srwatson#define TERASIC_MTL_BLEND_TEXTFG_SHIFT 8 115239691Srwatson#define TERASIC_MTL_BLEND_TEXTBG_MASK 0x000000ff 116239691Srwatson#define TERASIC_MTL_BLEND_TEXTBG_SHIFT 0 117239691Srwatson#define TERASIC_MTL_TEXTCURSOR_COL_MASK 0xff00 118239691Srwatson#define TERASIC_MTL_TEXTCURSOR_COL_SHIFT 8 119239691Srwatson#define TERASIC_MTL_TEXTCURSOR_ROW_MASK 0xff 120239691Srwatson 121239691Srwatson/* 122239691Srwatson * Colours used both by VGA-like text rendering, and for the default display 123239691Srwatson * colour. 124239691Srwatson */ 125239691Srwatson#define TERASIC_MTL_COLOR_BLACK 0 126239691Srwatson#define TERASIC_MTL_COLOR_DARKBLUE 1 127239691Srwatson#define TERASIC_MTL_COLOR_DARKGREEN 2 128239691Srwatson#define TERASIC_MTL_COLOR_DARKCYAN 3 129239691Srwatson#define TERASIC_MTL_COLOR_DARKRED 4 130239691Srwatson#define TERASIC_MTL_COLOR_DARKMAGENTA 5 131239691Srwatson#define TERASIC_MTL_COLOR_BROWN 6 132239691Srwatson#define TERASIC_MTL_COLOR_LIGHTGREY 7 133239691Srwatson#define TERASIC_MTL_COLOR_DARKGREY 8 134239691Srwatson#define TERASIC_MTL_COLOR_LIGHTBLUE 9 135239691Srwatson#define TERASIC_MTL_COLOR_LIGHTGREEN 10 136239691Srwatson#define TERASIC_MTL_COLOR_LIGHTCYAN 11 137239691Srwatson#define TERASIC_MTL_COLOR_LIGHTRED 12 138239691Srwatson#define TERASIC_MTL_COLOR_LIGHTMAGENTA 13 139239691Srwatson#define TERASIC_MTL_COLOR_LIGHTYELLOW 14 140239691Srwatson#define TERASIC_MTL_COLOR_WHITE 15 141239691Srwatson#define TERASIC_MTL_COLORMASK_BLINK 0x80 142239691Srwatson 143239691Srwatson/* 144239691Srwatson * Constants to help interpret the text frame buffer. 145239691Srwatson */ 146239691Srwatson#define TERASIC_MTL_TEXTFRAMEBUF_EXPECTED_ADDR 0x0177000 147239691Srwatson#define TERASIC_MTL_TEXTFRAMEBUF_CHAR_SHIFT 0 148239691Srwatson#define TERASIC_MTL_TEXTFRAMEBUF_ATTR_SHIFT 8 149239691Srwatson 150239691Srwatson/* 151239691Srwatson * Alpha-blending constants. 152239691Srwatson */ 153239691Srwatson#define TERASIC_MTL_ALPHA_TRANSPARENT 0 154239691Srwatson#define TERASIC_MTL_ALPHA_OPAQUE 255 155239691Srwatson 156239691Srwatson/* 157239691Srwatson * Driver setup routines from the bus attachment/teardown. 158239691Srwatson */ 159239691Srwatsonint terasic_mtl_attach(struct terasic_mtl_softc *sc); 160239691Srwatsonvoid terasic_mtl_detach(struct terasic_mtl_softc *sc); 161239691Srwatson 162245380Srwatsonextern devclass_t terasic_mtl_devclass; 163245380Srwatson 164239691Srwatson/* 165239691Srwatson * Sub-driver setup routines. 166239691Srwatson */ 167239691Srwatsonint terasic_mtl_pixel_attach(struct terasic_mtl_softc *sc); 168239691Srwatsonvoid terasic_mtl_pixel_detach(struct terasic_mtl_softc *sc); 169239691Srwatsonint terasic_mtl_reg_attach(struct terasic_mtl_softc *sc); 170239691Srwatsonvoid terasic_mtl_reg_detach(struct terasic_mtl_softc *sc); 171239691Srwatsonint terasic_mtl_syscons_attach(struct terasic_mtl_softc *sc); 172239691Srwatsonvoid terasic_mtl_syscons_detach(struct terasic_mtl_softc *sc); 173239691Srwatsonint terasic_mtl_text_attach(struct terasic_mtl_softc *sc); 174239691Srwatsonvoid terasic_mtl_text_detach(struct terasic_mtl_softc *sc); 175239691Srwatson 176239691Srwatson/* 177239691Srwatson * Control register I/O routines. 178239691Srwatson */ 179239691Srwatsonvoid terasic_mtl_reg_blank(struct terasic_mtl_softc *sc); 180239691Srwatson 181239691Srwatsonvoid terasic_mtl_reg_blend_get(struct terasic_mtl_softc *sc, 182239691Srwatson uint32_t *blendp); 183239691Srwatsonvoid terasic_mtl_reg_blend_set(struct terasic_mtl_softc *sc, 184239691Srwatson uint32_t blend); 185239691Srwatsonvoid terasic_mtl_reg_textcursor_get(struct terasic_mtl_softc *sc, 186239691Srwatson uint8_t *colp, uint8_t *rowp); 187239691Srwatsonvoid terasic_mtl_reg_textcursor_set(struct terasic_mtl_softc *sc, 188239691Srwatson uint8_t col, uint8_t row); 189239691Srwatsonvoid terasic_mtl_reg_textframebufaddr_get(struct terasic_mtl_softc *sc, 190239691Srwatson uint32_t *addrp); 191239691Srwatsonvoid terasic_mtl_reg_textframebufaddr_set(struct terasic_mtl_softc *sc, 192239691Srwatson uint32_t addr); 193239691Srwatson 194239691Srwatson/* 195239691Srwatson * Read-modify-write updates of sub-bytes of the blend register. 196239691Srwatson */ 197239691Srwatsonvoid terasic_mtl_blend_default_set(struct terasic_mtl_softc *sc, 198239691Srwatson uint8_t colour); 199239691Srwatsonvoid terasic_mtl_blend_pixel_set(struct terasic_mtl_softc *sc, 200239691Srwatson uint8_t alpha); 201239691Srwatsonvoid terasic_mtl_blend_textfg_set(struct terasic_mtl_softc *sc, 202239691Srwatson uint8_t alpha); 203239691Srwatsonvoid terasic_mtl_blend_textbg_set(struct terasic_mtl_softc *sc, 204239691Srwatson uint8_t alpha); 205239691Srwatson 206239691Srwatson/* 207239691Srwatson * Text frame buffer I/O routines. 208239691Srwatson */ 209239691Srwatsonvoid terasic_mtl_text_putc(struct terasic_mtl_softc *sc, u_int x, u_int y, 210239691Srwatson uint8_t c, uint8_t a); 211239691Srwatson 212239691Srwatson#endif /* _DEV_TERASIC_MTL_H_ */ 213