]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/terasic/mtl/terasic_mtl.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / terasic / mtl / terasic_mtl.h
1 /*-
2  * Copyright (c) 2012 Robert N. M. Watson
3  * All rights reserved.
4  *
5  * This software was developed by SRI International and the University of
6  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7  * ("CTSRD"), as part of the DARPA CRASH research programme.
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  * $FreeBSD$
31  */
32
33 #ifndef _DEV_TERASIC_MTL_H_
34 #define _DEV_TERASIC_MTL_H_
35
36 struct terasic_mtl_softc {
37         /*
38          * syscons requires that its video_adapter_t be at the front of the
39          * softc, so place syscons fields first, which we otherwise would
40          * probably not do.
41          */
42         video_adapter_t  mtl_va;
43
44         /*
45          * Bus-related fields.
46          */
47         device_t         mtl_dev;
48         int              mtl_unit;
49
50         /*
51          * The MTL driver doesn't require a lot of synchronisation; however,
52          * the lock is used to protect read-modify-write operations on MTL
53          * registers.
54          */
55         struct mtx       mtl_lock;
56
57         /*
58          * Control register device -- mappable from userspace.
59          */
60         struct cdev     *mtl_reg_cdev;
61         struct resource *mtl_reg_res;
62         int              mtl_reg_rid;
63
64         /*
65          * Graphics frame buffer device -- mappable form userspace.
66          */
67         struct cdev     *mtl_pixel_cdev;
68         struct resource *mtl_pixel_res;
69         int              mtl_pixel_rid;
70
71         /*
72          * Text frame buffer device -- mappable from userspace, and syscons
73          * hookup.
74          */
75         struct cdev     *mtl_text_cdev;
76         struct resource *mtl_text_res;
77         int              mtl_text_rid;
78         uint16_t        *mtl_text_soft;
79 };
80
81 #define TERASIC_MTL_LOCK(sc)            mtx_lock(&(sc)->mtl_lock)
82 #define TERASIC_MTL_LOCK_ASSERT(sc)     mtx_assert(&(sc)->mtl_lock, MA_OWNED)
83 #define TERASIC_MTL_LOCK_DESTROY(sc)    mtx_destroy(&(sc)->mtl_lock)
84 #define TERASIC_MTL_LOCK_INIT(sc)       mtx_init(&(sc)->mtl_lock,       \
85                                             "terasic_mtl", NULL, MTX_DEF)
86 #define TERASIC_MTL_UNLOCK(sc)          mtx_unlock(&(sc)->mtl_lock)
87
88 /*
89  * Constant properties of the MTL text frame buffer.
90  */
91 #define TERASIC_MTL_COLS        100
92 #define TERASIC_MTL_ROWS        40
93
94 /*
95  * MTL control register offsets.
96  */
97 #define TERASIC_MTL_OFF_BLEND                   0
98 #define TERASIC_MTL_OFF_TEXTCURSOR              4
99 #define TERASIC_MTL_OFF_TEXTFRAMEBUFADDR        8
100 #define TERASIC_MTL_OFF_TOUCHPOINT_X1           12
101 #define TERASIC_MTL_OFF_TOUCHPOINT_Y1           16
102 #define TERASIC_MTL_OFF_TOUCHPOINT_X2           20
103 #define TERASIC_MTL_OFF_TOUCHPOINT_Y2           24
104 #define TERASIC_MTL_OFF_TOUCHGESTURE            28
105
106 /*
107  * Constants to help interpret various control registers.
108  */
109 #define TERASIC_MTL_BLEND_DEFAULT_MASK          0x0f000000
110 #define TERASIC_MTL_BLEND_DEFAULT_SHIFT         24
111 #define TERASIC_MTL_BLEND_PIXEL_MASK            0x00ff0000
112 #define TERASIC_MTL_BLEND_PIXEL_SHIFT           16
113 #define TERASIC_MTL_BLEND_TEXTFG_MASK           0x0000ff00
114 #define TERASIC_MTL_BLEND_TEXTFG_SHIFT          8
115 #define TERASIC_MTL_BLEND_TEXTBG_MASK           0x000000ff
116 #define TERASIC_MTL_BLEND_TEXTBG_SHIFT          0
117 #define TERASIC_MTL_TEXTCURSOR_COL_MASK         0xff00
118 #define TERASIC_MTL_TEXTCURSOR_COL_SHIFT        8
119 #define TERASIC_MTL_TEXTCURSOR_ROW_MASK         0xff
120
121 /*
122  * Colours used both by VGA-like text rendering, and for the default display
123  * colour.
124  */
125 #define TERASIC_MTL_COLOR_BLACK         0
126 #define TERASIC_MTL_COLOR_DARKBLUE      1
127 #define TERASIC_MTL_COLOR_DARKGREEN     2
128 #define TERASIC_MTL_COLOR_DARKCYAN      3
129 #define TERASIC_MTL_COLOR_DARKRED       4
130 #define TERASIC_MTL_COLOR_DARKMAGENTA   5
131 #define TERASIC_MTL_COLOR_BROWN         6
132 #define TERASIC_MTL_COLOR_LIGHTGREY     7
133 #define TERASIC_MTL_COLOR_DARKGREY      8
134 #define TERASIC_MTL_COLOR_LIGHTBLUE     9
135 #define TERASIC_MTL_COLOR_LIGHTGREEN    10
136 #define TERASIC_MTL_COLOR_LIGHTCYAN     11
137 #define TERASIC_MTL_COLOR_LIGHTRED      12
138 #define TERASIC_MTL_COLOR_LIGHTMAGENTA  13
139 #define TERASIC_MTL_COLOR_LIGHTYELLOW   14
140 #define TERASIC_MTL_COLOR_WHITE         15
141 #define TERASIC_MTL_COLORMASK_BLINK     0x80
142
143 /*
144  * Constants to help interpret the text frame buffer.
145  */
146 #define TERASIC_MTL_TEXTFRAMEBUF_EXPECTED_ADDR  0x0177000
147 #define TERASIC_MTL_TEXTFRAMEBUF_CHAR_SHIFT     0
148 #define TERASIC_MTL_TEXTFRAMEBUF_ATTR_SHIFT     8
149
150 /*
151  * Alpha-blending constants.
152  */
153 #define TERASIC_MTL_ALPHA_TRANSPARENT   0
154 #define TERASIC_MTL_ALPHA_OPAQUE        255
155
156 /*
157  * Driver setup routines from the bus attachment/teardown.
158  */
159 int     terasic_mtl_attach(struct terasic_mtl_softc *sc);
160 void    terasic_mtl_detach(struct terasic_mtl_softc *sc);
161
162 extern devclass_t       terasic_mtl_devclass;
163
164 /*
165  * Sub-driver setup routines.
166  */
167 int     terasic_mtl_pixel_attach(struct terasic_mtl_softc *sc);
168 void    terasic_mtl_pixel_detach(struct terasic_mtl_softc *sc);
169 int     terasic_mtl_reg_attach(struct terasic_mtl_softc *sc);
170 void    terasic_mtl_reg_detach(struct terasic_mtl_softc *sc);
171 int     terasic_mtl_syscons_attach(struct terasic_mtl_softc *sc);
172 void    terasic_mtl_syscons_detach(struct terasic_mtl_softc *sc);
173 int     terasic_mtl_text_attach(struct terasic_mtl_softc *sc);
174 void    terasic_mtl_text_detach(struct terasic_mtl_softc *sc);
175
176 /*
177  * Control register I/O routines.
178  */
179 void    terasic_mtl_reg_blank(struct terasic_mtl_softc *sc);
180
181 void    terasic_mtl_reg_blend_get(struct terasic_mtl_softc *sc,
182             uint32_t *blendp);
183 void    terasic_mtl_reg_blend_set(struct terasic_mtl_softc *sc,
184             uint32_t blend);
185 void    terasic_mtl_reg_textcursor_get(struct terasic_mtl_softc *sc,
186             uint8_t *colp, uint8_t *rowp);
187 void    terasic_mtl_reg_textcursor_set(struct terasic_mtl_softc *sc,
188             uint8_t col, uint8_t row);
189 void    terasic_mtl_reg_textframebufaddr_get(struct terasic_mtl_softc *sc,
190             uint32_t *addrp);
191 void    terasic_mtl_reg_textframebufaddr_set(struct terasic_mtl_softc *sc,
192             uint32_t addr);
193
194 /*
195  * Read-modify-write updates of sub-bytes of the blend register.
196  */
197 void    terasic_mtl_blend_default_set(struct terasic_mtl_softc *sc,
198             uint8_t colour);
199 void    terasic_mtl_blend_pixel_set(struct terasic_mtl_softc *sc,
200             uint8_t alpha);
201 void    terasic_mtl_blend_textfg_set(struct terasic_mtl_softc *sc,
202             uint8_t alpha);
203 void    terasic_mtl_blend_textbg_set(struct terasic_mtl_softc *sc,
204             uint8_t alpha);
205
206 /*
207  * Text frame buffer I/O routines.
208  */
209 void    terasic_mtl_text_putc(struct terasic_mtl_softc *sc, u_int x, u_int y,
210             uint8_t c, uint8_t a);
211
212 #endif /* _DEV_TERASIC_MTL_H_ */