1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <common.h>
27
28#include <video_fb.h>
29#include <sed13806.h>
30
31#define readByte(ptrReg) \
32 *(volatile unsigned char *)(sed13806.isaBase + ptrReg)
33
34#define writeByte(ptrReg,value) \
35 *(volatile unsigned char *)(sed13806.isaBase + ptrReg) = value
36
37#ifdef CONFIG_TOTAL5200
38#define writeWord(ptrReg,value) \
39 (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = value)
40#else
41#define writeWord(ptrReg,value) \
42 (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = ((value >> 8 ) & 0xff) | ((value << 8) & 0xff00))
43#endif
44
45GraphicDevice sed13806;
46
47
48
49
50
51static void EpsonSetRegs (void)
52{
53
54 const S1D_REGS *preg = board_get_regs ();
55 while (preg -> Index) {
56 writeByte (preg -> Index, preg -> Value);
57 preg ++;
58 }
59}
60
61
62
63
64
65void *video_hw_init (void)
66{
67 unsigned int *vm, i;
68
69 memset (&sed13806, 0, sizeof (GraphicDevice));
70
71
72
73
74 if ((sed13806.isaBase = board_video_init ()) == 0) {
75 return (NULL);
76 }
77
78 sed13806.frameAdrs = sed13806.isaBase + FRAME_BUFFER_OFFSET;
79 sed13806.winSizeX = board_get_width ();
80 sed13806.winSizeY = board_get_height ();
81
82#if defined(CONFIG_VIDEO_SED13806_8BPP)
83 sed13806.gdfIndex = GDF__8BIT_INDEX;
84 sed13806.gdfBytesPP = 1;
85
86#elif defined(CONFIG_VIDEO_SED13806_16BPP)
87 sed13806.gdfIndex = GDF_16BIT_565RGB;
88 sed13806.gdfBytesPP = 2;
89
90#else
91#error Unsupported SED13806 BPP
92#endif
93
94 sed13806.memSize = sed13806.winSizeX * sed13806.winSizeY * sed13806.gdfBytesPP;
95
96
97 EpsonSetRegs ();
98
99
100 board_validate_screen (sed13806.isaBase);
101
102
103 i = sed13806.memSize/4;
104 vm = (unsigned int *)sed13806.frameAdrs;
105 while(i--)
106 *vm++ = 0;
107
108
109 return (&sed13806);
110}
111
112
113
114
115static void Epson_wait_idle (void)
116{
117 while (readByte (BLT_CTRL0) & 0x80);
118
119
120 *(volatile unsigned short *)(sed13806.isaBase + BLT_REG);
121}
122
123
124
125
126
127void video_hw_bitblt (
128 unsigned int bpp,
129 unsigned int src_x,
130 unsigned int src_y,
131 unsigned int dst_x,
132 unsigned int dst_y,
133 unsigned int dim_x,
134 unsigned int dim_y
135 )
136{
137 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
138 unsigned long srcAddr, dstAddr;
139 unsigned int stride = bpp * pGD -> winSizeX;
140
141 srcAddr = (src_y * stride) + (src_x * bpp);
142 dstAddr = (dst_y * stride) + (dst_x * bpp);
143
144 Epson_wait_idle ();
145
146 writeByte(BLT_ROP,0x0C);
147 writeByte(BLT_OP,0x02);
148 writeWord(BLT_MEM_OFF0, stride / 2);
149 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
150 writeByte(BLT_CTRL1,0x00);
151 }
152 else {
153 writeByte(BLT_CTRL1,0x01);
154 }
155
156 writeWord(BLT_WIDTH0,(dim_x - 1));
157 writeWord(BLT_HEIGHT0,(dim_y - 1));
158
159
160 writeByte(BLT_SRC_ADDR0,srcAddr);
161 writeByte(BLT_SRC_ADDR1,srcAddr>>8);
162 writeByte(BLT_SRC_ADDR2,srcAddr>>16);
163
164 writeByte(BLT_DST_ADDR0,dstAddr);
165 writeByte(BLT_DST_ADDR1,dstAddr>>8);
166 writeByte(BLT_DST_ADDR2,dstAddr>>16);
167
168
169
170 writeByte(BLT_CTRL0,0x80);
171
172
173 Epson_wait_idle ();
174}
175
176
177
178
179void video_hw_rectfill (
180 unsigned int bpp,
181 unsigned int dst_x,
182 unsigned int dst_y,
183 unsigned int dim_x,
184 unsigned int dim_y,
185 unsigned int color
186 )
187{
188 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
189 unsigned long dstAddr;
190 unsigned int stride = bpp * pGD -> winSizeX;
191
192 dstAddr = (dst_y * stride) + (dst_x * bpp);
193
194 Epson_wait_idle ();
195
196
197 writeByte(BLT_DST_ADDR0,dstAddr);
198 writeByte(BLT_DST_ADDR1,dstAddr>>8);
199 writeByte(BLT_DST_ADDR2,dstAddr>>16);
200
201 writeWord(BLT_WIDTH0,(dim_x - 1));
202 writeWord(BLT_HEIGHT0,(dim_y - 1));
203 writeWord(BLT_FGCOLOR0,color);
204
205 writeByte(BLT_OP,0x0C);
206 writeWord(BLT_MEM_OFF0,stride / 2);
207
208 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
209 writeByte(BLT_CTRL1,0x00);
210 }
211 else {
212 writeByte(BLT_CTRL1,0x01);
213 }
214
215
216
217 writeByte(BLT_CTRL0,0x80);
218
219
220 Epson_wait_idle ();
221}
222
223
224
225
226
227void video_set_lut (
228 unsigned int index,
229 unsigned char r,
230 unsigned char g,
231 unsigned char b
232 )
233{
234 writeByte(REG_LUT_ADDR, index );
235 writeByte(REG_LUT_DATA, r);
236 writeByte(REG_LUT_DATA, g);
237 writeByte(REG_LUT_DATA, b);
238}
239#ifdef CONFIG_VIDEO_HW_CURSOR
240
241
242
243
244void video_set_hw_cursor (int x, int y)
245{
246 writeByte (LCD_CURSOR_XL, (x & 0xff));
247 writeByte (LCD_CURSOR_XM, (x >> 8));
248 writeByte (LCD_CURSOR_YL, (y & 0xff));
249 writeByte (LCD_CURSOR_YM, (y >> 8));
250}
251
252
253
254
255
256void video_init_hw_cursor (int font_width, int font_height)
257{
258 volatile unsigned char *ptr;
259 unsigned char pattern;
260 int i;
261
262
263
264
265
266 if ((i = readByte (LCD_CURSOR_START)) == 0) {
267 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - HWCURSORSIZE);
268 }
269 else {
270 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192));
271 }
272
273
274 for (i = 0, pattern = 0; i < 64; i++) {
275 if (i < font_width) {
276
277 pattern |= 0x3;
278
279 }
280 else {
281
282 pattern |= 0x2;
283 }
284 if ((i & 3) == 3) {
285 *ptr = pattern;
286 *(ptr + font_height * 16) = 0xaa;
287 ptr ++;
288 pattern = 0;
289 }
290 pattern <<= 2;
291 }
292
293
294 for (i = 1; i < font_height; i++) {
295 memcpy ((void *)ptr, (void *)(ptr - 16), 16);
296 ptr += 16;
297 }
298
299 for (; i < 64; i++) {
300 memcpy ((void *)(ptr + 16), (void *)ptr, 16);
301 ptr += 16;
302 }
303
304
305 writeByte (LCD_CURSOR_CNTL, 1);
306}
307#endif
308