blob: 6996ca805ebf9ad6164c2881f5952857fd85cc8c [file] [log] [blame]
wdenk9dd2b882002-12-03 21:28:10 +00001/*
2 * (C) Copyright 2002
3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24/* Video support for Epson SED13806 chipset */
25
26#include <common.h>
27
28#ifdef CONFIG_VIDEO_SED13806
29
30#include <video_fb.h>
31#include <sed13806.h>
32
33#define readByte(ptrReg) \
34 *(volatile unsigned char *)(sed13806.isaBase + ptrReg)
35
36#define writeByte(ptrReg,value) \
37 *(volatile unsigned char *)(sed13806.isaBase + ptrReg) = value
38
wdenkda54bc92004-08-04 21:56:49 +000039#ifdef CONFIG_TOTAL5200
40#define writeWord(ptrReg,value) \
41 (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = value)
42#else
wdenk9dd2b882002-12-03 21:28:10 +000043#define writeWord(ptrReg,value) \
44 (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = ((value >> 8 ) & 0xff) | ((value << 8) & 0xff00))
wdenkda54bc92004-08-04 21:56:49 +000045#endif
wdenk9dd2b882002-12-03 21:28:10 +000046
47GraphicDevice sed13806;
48
49/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000050 * EpsonSetRegs --
wdenk9dd2b882002-12-03 21:28:10 +000051 *-----------------------------------------------------------------------------
52 */
53static void EpsonSetRegs (void)
54{
55 /* the content of the chipset register depends on the board (clocks, ...)*/
56 const S1D_REGS *preg = board_get_regs ();
57 while (preg -> Index) {
wdenk57b2d802003-06-27 21:31:46 +000058 writeByte (preg -> Index, preg -> Value);
59 preg ++;
wdenk9dd2b882002-12-03 21:28:10 +000060 }
61}
wdenk57b2d802003-06-27 21:31:46 +000062
wdenk9dd2b882002-12-03 21:28:10 +000063/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000064 * video_hw_init --
wdenk9dd2b882002-12-03 21:28:10 +000065 *-----------------------------------------------------------------------------
66 */
67void *video_hw_init (void)
68{
69 unsigned int *vm, i;
70
71 memset (&sed13806, 0, sizeof (GraphicDevice));
72
73 /* Initialization of the access to the graphic chipset
74 Retreive base address of the chipset
75 (see board/RPXClassic/eccx.c) */
76 if ((sed13806.isaBase = board_video_init ()) == 0) {
wdenk57b2d802003-06-27 21:31:46 +000077 return (NULL);
wdenk9dd2b882002-12-03 21:28:10 +000078 }
79
80 sed13806.frameAdrs = sed13806.isaBase + FRAME_BUFFER_OFFSET;
81 sed13806.winSizeX = board_get_width ();
82 sed13806.winSizeY = board_get_height ();
83
84#if defined(CONFIG_VIDEO_SED13806_8BPP)
85 sed13806.gdfIndex = GDF__8BIT_INDEX;
86 sed13806.gdfBytesPP = 1;
wdenk57b2d802003-06-27 21:31:46 +000087
wdenk9dd2b882002-12-03 21:28:10 +000088#elif defined(CONFIG_VIDEO_SED13806_16BPP)
89 sed13806.gdfIndex = GDF_16BIT_565RGB;
90 sed13806.gdfBytesPP = 2;
91
92#else
93#error Unsupported SED13806 BPP
94#endif
95
96 sed13806.memSize = sed13806.winSizeX * sed13806.winSizeY * sed13806.gdfBytesPP;
97
98 /* Load SED registers */
99 EpsonSetRegs ();
100
101 /* (see board/RPXClassic/RPXClassic.c) */
102 board_validate_screen (sed13806.isaBase);
103
104 /* Clear video memory */
105 i = sed13806.memSize/4;
106 vm = (unsigned int *)sed13806.frameAdrs;
107 while(i--)
wdenk57b2d802003-06-27 21:31:46 +0000108 *vm++ = 0;
109
110
wdenk9dd2b882002-12-03 21:28:10 +0000111 return (&sed13806);
112}
113/*-----------------------------------------------------------------------------
114 * Epson_wait_idle -- Wait for hardware to become idle
115 *-----------------------------------------------------------------------------
116 */
117static void Epson_wait_idle (void)
118{
119 while (readByte (BLT_CTRL0) & 0x80);
120
121 /* Read a word in the BitBLT memory area to shutdown the BitBLT engine */
122 *(volatile unsigned short *)(sed13806.isaBase + BLT_REG);
123}
124
125/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000126 * video_hw_bitblt --
wdenk9dd2b882002-12-03 21:28:10 +0000127 *-----------------------------------------------------------------------------
128 */
129void video_hw_bitblt (
130 unsigned int bpp, /* bytes per pixel */
131 unsigned int src_x, /* source pos x */
132 unsigned int src_y, /* source pos y */
133 unsigned int dst_x, /* dest pos x */
134 unsigned int dst_y, /* dest pos y */
135 unsigned int dim_x, /* frame width */
136 unsigned int dim_y /* frame height */
137 )
138{
139 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
140 unsigned long srcAddr, dstAddr;
141 unsigned int stride = bpp * pGD -> winSizeX;
142
143 srcAddr = (src_y * stride) + (src_x * bpp);
144 dstAddr = (dst_y * stride) + (dst_x * bpp);
145
146 Epson_wait_idle ();
wdenk57b2d802003-06-27 21:31:46 +0000147
148 writeByte(BLT_ROP,0x0C); /* source */
149 writeByte(BLT_OP,0x02);/* move blit in positive direction with ROP */
wdenk9dd2b882002-12-03 21:28:10 +0000150 writeWord(BLT_MEM_OFF0, stride / 2);
151 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
wdenk57b2d802003-06-27 21:31:46 +0000152 writeByte(BLT_CTRL1,0x00);
wdenk9dd2b882002-12-03 21:28:10 +0000153 }
154 else {
wdenk57b2d802003-06-27 21:31:46 +0000155 writeByte(BLT_CTRL1,0x01);
wdenk9dd2b882002-12-03 21:28:10 +0000156 }
157
158 writeWord(BLT_WIDTH0,(dim_x - 1));
159 writeWord(BLT_HEIGHT0,(dim_y - 1));
wdenk57b2d802003-06-27 21:31:46 +0000160
wdenk9dd2b882002-12-03 21:28:10 +0000161 /* set up blit registers */
162 writeByte(BLT_SRC_ADDR0,srcAddr);
wdenk57b2d802003-06-27 21:31:46 +0000163 writeByte(BLT_SRC_ADDR1,srcAddr>>8);
164 writeByte(BLT_SRC_ADDR2,srcAddr>>16);
165
wdenk9dd2b882002-12-03 21:28:10 +0000166 writeByte(BLT_DST_ADDR0,dstAddr);
wdenk57b2d802003-06-27 21:31:46 +0000167 writeByte(BLT_DST_ADDR1,dstAddr>>8);
168 writeByte(BLT_DST_ADDR2,dstAddr>>16);
169
wdenk9dd2b882002-12-03 21:28:10 +0000170 /* Engage the blt engine */
171 /* rectangular region for src and dst */
172 writeByte(BLT_CTRL0,0x80);
173
174 /* wait untill current blits finished */
175 Epson_wait_idle ();
176}
177/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000178 * video_hw_rectfill --
wdenk9dd2b882002-12-03 21:28:10 +0000179 *-----------------------------------------------------------------------------
180 */
181void video_hw_rectfill (
182 unsigned int bpp, /* bytes per pixel */
183 unsigned int dst_x, /* dest pos x */
184 unsigned int dst_y, /* dest pos y */
185 unsigned int dim_x, /* frame width */
186 unsigned int dim_y, /* frame height */
187 unsigned int color /* fill color */
188 )
189{
190 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
191 unsigned long dstAddr;
192 unsigned int stride = bpp * pGD -> winSizeX;
193
194 dstAddr = (dst_y * stride) + (dst_x * bpp);
195
196 Epson_wait_idle ();
197
198 /* set up blit registers */
199 writeByte(BLT_DST_ADDR0,dstAddr);
wdenk57b2d802003-06-27 21:31:46 +0000200 writeByte(BLT_DST_ADDR1,dstAddr>>8);
201 writeByte(BLT_DST_ADDR2,dstAddr>>16);
wdenk9dd2b882002-12-03 21:28:10 +0000202
203 writeWord(BLT_WIDTH0,(dim_x - 1));
204 writeWord(BLT_HEIGHT0,(dim_y - 1));
205 writeWord(BLT_FGCOLOR0,color);
206
207 writeByte(BLT_OP,0x0C); /* solid fill */
208 writeWord(BLT_MEM_OFF0,stride / 2);
209
210 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
wdenk57b2d802003-06-27 21:31:46 +0000211 writeByte(BLT_CTRL1,0x00);
wdenk9dd2b882002-12-03 21:28:10 +0000212 }
213 else {
wdenk57b2d802003-06-27 21:31:46 +0000214 writeByte(BLT_CTRL1,0x01);
wdenk9dd2b882002-12-03 21:28:10 +0000215 }
wdenk57b2d802003-06-27 21:31:46 +0000216
wdenk9dd2b882002-12-03 21:28:10 +0000217 /* Engage the blt engine */
218 /* rectangular region for src and dst */
219 writeByte(BLT_CTRL0,0x80);
220
221 /* wait untill current blits finished */
222 Epson_wait_idle ();
223}
224
225/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000226 * video_set_lut --
wdenk9dd2b882002-12-03 21:28:10 +0000227 *-----------------------------------------------------------------------------
228 */
229void video_set_lut (
230 unsigned int index, /* color number */
231 unsigned char r, /* red */
232 unsigned char g, /* green */
233 unsigned char b /* blue */
234 )
235{
236 writeByte(REG_LUT_ADDR, index );
237 writeByte(REG_LUT_DATA, r);
238 writeByte(REG_LUT_DATA, g);
239 writeByte(REG_LUT_DATA, b);
240}
241#ifdef CONFIG_VIDEO_HW_CURSOR
242/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000243 * video_set_hw_cursor --
wdenk9dd2b882002-12-03 21:28:10 +0000244 *-----------------------------------------------------------------------------
245 */
246void video_set_hw_cursor (int x, int y)
247{
248 writeByte (LCD_CURSOR_XL, (x & 0xff));
249 writeByte (LCD_CURSOR_XM, (x >> 8));
250 writeByte (LCD_CURSOR_YL, (y & 0xff));
251 writeByte (LCD_CURSOR_YM, (y >> 8));
252}
253
254/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000255 * video_init_hw_cursor --
wdenk9dd2b882002-12-03 21:28:10 +0000256 *-----------------------------------------------------------------------------
257 */
258void video_init_hw_cursor (int font_width, int font_height)
259{
260 volatile unsigned char *ptr;
261 unsigned char pattern;
262 int i;
wdenk57b2d802003-06-27 21:31:46 +0000263
wdenk9dd2b882002-12-03 21:28:10 +0000264
265 /* Init cursor content
266 Cursor size is 64x64 pixels
267 Start of the cursor memory depends on panel type (dual panel ...) */
268 if ((i = readByte (LCD_CURSOR_START)) == 0) {
wdenk57b2d802003-06-27 21:31:46 +0000269 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - HWCURSORSIZE);
wdenk9dd2b882002-12-03 21:28:10 +0000270 }
271 else {
wdenk57b2d802003-06-27 21:31:46 +0000272 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192));
wdenk9dd2b882002-12-03 21:28:10 +0000273 }
274
275 /* Fill the first line and the first empty line after cursor */
276 for (i = 0, pattern = 0; i < 64; i++) {
wdenk57b2d802003-06-27 21:31:46 +0000277 if (i < font_width) {
278 /* Invert background */
279 pattern |= 0x3;
280
281 }
282 else {
283 /* Background */
284 pattern |= 0x2;
285 }
286 if ((i & 3) == 3) {
287 *ptr = pattern;
288 *(ptr + font_height * 16) = 0xaa;
289 ptr ++;
290 pattern = 0;
291 }
292 pattern <<= 2;
wdenk9dd2b882002-12-03 21:28:10 +0000293 }
294
295 /* Duplicate this line */
296 for (i = 1; i < font_height; i++) {
wdenk57b2d802003-06-27 21:31:46 +0000297 memcpy ((void *)ptr, (void *)(ptr - 16), 16);
298 ptr += 16;
wdenk9dd2b882002-12-03 21:28:10 +0000299 }
wdenk57b2d802003-06-27 21:31:46 +0000300
wdenk9dd2b882002-12-03 21:28:10 +0000301 for (; i < 64; i++) {
wdenk57b2d802003-06-27 21:31:46 +0000302 memcpy ((void *)(ptr + 16), (void *)ptr, 16);
303 ptr += 16;
wdenk9dd2b882002-12-03 21:28:10 +0000304 }
305
306 /* Select cursor mode */
307 writeByte (LCD_CURSOR_CNTL, 1);
308}
309#endif
310#endif