]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/terasic/mtl/terasic_mtl.h
sys/dev: further adoption of SPDX licensing ID tags.
[FreeBSD/FreeBSD.git] / sys / dev / terasic / mtl / terasic_mtl.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2012 Robert N. M. Watson
5  * All rights reserved.
6  *
7  * This software was developed by SRI International and the University of
8  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
9  * ("CTSRD"), as part of the DARPA CRASH research programme.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  */
34
35 #ifndef _DEV_TERASIC_MTL_H_
36 #define _DEV_TERASIC_MTL_H_
37
38 #include "opt_syscons.h"
39
40 struct terasic_mtl_softc {
41 #if defined(DEV_SC)
42         /*
43          * syscons requires that its video_adapter_t be at the front of the
44          * softc, so place syscons fields first, which we otherwise would
45          * probably not do.
46          */
47         video_adapter_t  mtl_va;
48 #endif
49
50         /*
51          * Bus-related fields.
52          */
53         device_t         mtl_dev;
54         int              mtl_unit;
55
56         /*
57          * The MTL driver doesn't require a lot of synchronisation; however,
58          * the lock is used to protect read-modify-write operations on MTL
59          * registers.
60          */
61         struct mtx       mtl_lock;
62
63         /*
64          * Control register device -- mappable from userspace.
65          */
66         struct cdev     *mtl_reg_cdev;
67         struct resource *mtl_reg_res;
68         int              mtl_reg_rid;
69
70         /*
71          * Graphics frame buffer device -- mappable from userspace, and used
72          * by the vt framebuffer interface.
73          */
74         struct cdev     *mtl_pixel_cdev;
75         struct resource *mtl_pixel_res;
76         int              mtl_pixel_rid;
77
78         /*
79          * Text frame buffer device -- mappable from userspace, and syscons
80          * hookup.
81          */
82         struct cdev     *mtl_text_cdev;
83         struct resource *mtl_text_res;
84         int              mtl_text_rid;
85         uint16_t        *mtl_text_soft;
86
87         /*
88          * Framebuffer hookup for vt(4).
89          */
90         struct fb_info   mtl_fb_info;
91 };
92
93 #define TERASIC_MTL_LOCK(sc)            mtx_lock(&(sc)->mtl_lock)
94 #define TERASIC_MTL_LOCK_ASSERT(sc)     mtx_assert(&(sc)->mtl_lock, MA_OWNED)
95 #define TERASIC_MTL_LOCK_DESTROY(sc)    mtx_destroy(&(sc)->mtl_lock)
96 #define TERASIC_MTL_LOCK_INIT(sc)       mtx_init(&(sc)->mtl_lock,       \
97                                             "terasic_mtl", NULL, MTX_DEF)
98 #define TERASIC_MTL_UNLOCK(sc)          mtx_unlock(&(sc)->mtl_lock)
99
100 /*
101  * Constant properties of the MTL text frame buffer.
102  */
103 #define TERASIC_MTL_COLS        100
104 #define TERASIC_MTL_ROWS        40
105
106 /*
107  * MTL control register offsets.
108  */
109 #define TERASIC_MTL_OFF_BLEND                   0
110 #define TERASIC_MTL_OFF_TEXTCURSOR              4
111 #define TERASIC_MTL_OFF_TEXTFRAMEBUFADDR        8
112 #define TERASIC_MTL_OFF_TOUCHPOINT_X1           12
113 #define TERASIC_MTL_OFF_TOUCHPOINT_Y1           16
114 #define TERASIC_MTL_OFF_TOUCHPOINT_X2           20
115 #define TERASIC_MTL_OFF_TOUCHPOINT_Y2           24
116 #define TERASIC_MTL_OFF_TOUCHGESTURE            28
117
118 /*
119  * Constants to help interpret various control registers.
120  */
121 #define TERASIC_MTL_BLEND_PIXEL_ENDIAN_SWAP     0x10000000
122 #define TERASIC_MTL_BLEND_DEFAULT_MASK          0x0f000000
123 #define TERASIC_MTL_BLEND_DEFAULT_SHIFT         24
124 #define TERASIC_MTL_BLEND_PIXEL_MASK            0x00ff0000
125 #define TERASIC_MTL_BLEND_PIXEL_SHIFT           16
126 #define TERASIC_MTL_BLEND_TEXTFG_MASK           0x0000ff00
127 #define TERASIC_MTL_BLEND_TEXTFG_SHIFT          8
128 #define TERASIC_MTL_BLEND_TEXTBG_MASK           0x000000ff
129 #define TERASIC_MTL_BLEND_TEXTBG_SHIFT          0
130 #define TERASIC_MTL_TEXTCURSOR_COL_MASK         0xff00
131 #define TERASIC_MTL_TEXTCURSOR_COL_SHIFT        8
132 #define TERASIC_MTL_TEXTCURSOR_ROW_MASK         0xff
133
134 /*
135  * Colours used both by VGA-like text rendering, and for the default display
136  * colour.
137  */
138 #define TERASIC_MTL_COLOR_BLACK         0
139 #define TERASIC_MTL_COLOR_DARKBLUE      1
140 #define TERASIC_MTL_COLOR_DARKGREEN     2
141 #define TERASIC_MTL_COLOR_DARKCYAN      3
142 #define TERASIC_MTL_COLOR_DARKRED       4
143 #define TERASIC_MTL_COLOR_DARKMAGENTA   5
144 #define TERASIC_MTL_COLOR_BROWN         6
145 #define TERASIC_MTL_COLOR_LIGHTGREY     7
146 #define TERASIC_MTL_COLOR_DARKGREY      8
147 #define TERASIC_MTL_COLOR_LIGHTBLUE     9
148 #define TERASIC_MTL_COLOR_LIGHTGREEN    10
149 #define TERASIC_MTL_COLOR_LIGHTCYAN     11
150 #define TERASIC_MTL_COLOR_LIGHTRED      12
151 #define TERASIC_MTL_COLOR_LIGHTMAGENTA  13
152 #define TERASIC_MTL_COLOR_LIGHTYELLOW   14
153 #define TERASIC_MTL_COLOR_WHITE         15
154 #define TERASIC_MTL_COLORMASK_BLINK     0x80
155
156 /*
157  * Constants to help interpret the text frame buffer.
158  */
159 #define TERASIC_MTL_TEXTFRAMEBUF_EXPECTED_ADDR  0x0177000
160 #define TERASIC_MTL_TEXTFRAMEBUF_CHAR_SHIFT     0
161 #define TERASIC_MTL_TEXTFRAMEBUF_ATTR_SHIFT     8
162
163 /*
164  * Framebuffer constants.
165  */
166 #define TERASIC_MTL_FB_WIDTH            800
167 #define TERASIC_MTL_FB_HEIGHT           640
168
169 /*
170  * Alpha-blending constants.
171  */
172 #define TERASIC_MTL_ALPHA_TRANSPARENT   0
173 #define TERASIC_MTL_ALPHA_OPAQUE        255
174
175 /*
176  * Driver setup routines from the bus attachment/teardown.
177  */
178 int     terasic_mtl_attach(struct terasic_mtl_softc *sc);
179 void    terasic_mtl_detach(struct terasic_mtl_softc *sc);
180
181 extern devclass_t       terasic_mtl_devclass;
182
183 /*
184  * Sub-driver setup routines.
185  */
186 int     terasic_mtl_fbd_attach(struct terasic_mtl_softc *sc);
187 void    terasic_mtl_fbd_detach(struct terasic_mtl_softc *sc);
188 int     terasic_mtl_pixel_attach(struct terasic_mtl_softc *sc);
189 void    terasic_mtl_pixel_detach(struct terasic_mtl_softc *sc);
190 int     terasic_mtl_reg_attach(struct terasic_mtl_softc *sc);
191 void    terasic_mtl_reg_detach(struct terasic_mtl_softc *sc);
192 int     terasic_mtl_syscons_attach(struct terasic_mtl_softc *sc);
193 void    terasic_mtl_syscons_detach(struct terasic_mtl_softc *sc);
194 int     terasic_mtl_text_attach(struct terasic_mtl_softc *sc);
195 void    terasic_mtl_text_detach(struct terasic_mtl_softc *sc);
196
197 /*
198  * Control register I/O routines.
199  */
200 void    terasic_mtl_reg_blank(struct terasic_mtl_softc *sc);
201
202 void    terasic_mtl_reg_blend_get(struct terasic_mtl_softc *sc,
203             uint32_t *blendp);
204 void    terasic_mtl_reg_blend_set(struct terasic_mtl_softc *sc,
205             uint32_t blend);
206 void    terasic_mtl_reg_textcursor_get(struct terasic_mtl_softc *sc,
207             uint8_t *colp, uint8_t *rowp);
208 void    terasic_mtl_reg_textcursor_set(struct terasic_mtl_softc *sc,
209             uint8_t col, uint8_t row);
210 void    terasic_mtl_reg_textframebufaddr_get(struct terasic_mtl_softc *sc,
211             uint32_t *addrp);
212 void    terasic_mtl_reg_textframebufaddr_set(struct terasic_mtl_softc *sc,
213             uint32_t addr);
214
215 /*
216  * Read-modify-write updates of sub-bytes of the blend register.
217  */
218 void    terasic_mtl_blend_default_set(struct terasic_mtl_softc *sc,
219             uint8_t colour);
220 void    terasic_mtl_blend_pixel_set(struct terasic_mtl_softc *sc,
221             uint8_t alpha);
222 void    terasic_mtl_blend_textfg_set(struct terasic_mtl_softc *sc,
223             uint8_t alpha);
224 void    terasic_mtl_blend_textbg_set(struct terasic_mtl_softc *sc,
225             uint8_t alpha);
226 void    terasic_mtl_reg_pixel_endian_set(struct terasic_mtl_softc *sc,
227             int endian_swap);
228
229 /*
230  * Text frame buffer I/O routines.
231  */
232 void    terasic_mtl_text_putc(struct terasic_mtl_softc *sc, u_int x, u_int y,
233             uint8_t c, uint8_t a);
234
235 #endif /* _DEV_TERASIC_MTL_H_ */