blob: cd7fac6f970603f8f111e47d4d06b9a61759fd50 [file] [log] [blame]
wdenka6c7ad22002-12-03 21:28:10 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02003 * Stäubli Faverges - <www.staubli.com>
wdenka6c7ad22002-12-03 21:28:10 +00004 * Pierre AUBERT p.aubert@staubli.com
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenka6c7ad22002-12-03 21:28:10 +00007 */
8/* Video support for Epson SED13806 chipset */
9
10#include <common.h>
11
wdenka6c7ad22002-12-03 21:28:10 +000012#include <video_fb.h>
13#include <sed13806.h>
14
15#define readByte(ptrReg) \
16 *(volatile unsigned char *)(sed13806.isaBase + ptrReg)
17
18#define writeByte(ptrReg,value) \
19 *(volatile unsigned char *)(sed13806.isaBase + ptrReg) = value
20
21#define writeWord(ptrReg,value) \
22 (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = ((value >> 8 ) & 0xff) | ((value << 8) & 0xff00))
wdenka6c7ad22002-12-03 21:28:10 +000023
24GraphicDevice sed13806;
25
26/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +000027 * EpsonSetRegs --
wdenka6c7ad22002-12-03 21:28:10 +000028 *-----------------------------------------------------------------------------
29 */
30static void EpsonSetRegs (void)
31{
32 /* the content of the chipset register depends on the board (clocks, ...)*/
33 const S1D_REGS *preg = board_get_regs ();
34 while (preg -> Index) {
wdenk8bde7f72003-06-27 21:31:46 +000035 writeByte (preg -> Index, preg -> Value);
36 preg ++;
wdenka6c7ad22002-12-03 21:28:10 +000037 }
38}
wdenk8bde7f72003-06-27 21:31:46 +000039
wdenka6c7ad22002-12-03 21:28:10 +000040/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +000041 * video_hw_init --
wdenka6c7ad22002-12-03 21:28:10 +000042 *-----------------------------------------------------------------------------
43 */
44void *video_hw_init (void)
45{
46 unsigned int *vm, i;
47
48 memset (&sed13806, 0, sizeof (GraphicDevice));
49
50 /* Initialization of the access to the graphic chipset
51 Retreive base address of the chipset
52 (see board/RPXClassic/eccx.c) */
53 if ((sed13806.isaBase = board_video_init ()) == 0) {
wdenk8bde7f72003-06-27 21:31:46 +000054 return (NULL);
wdenka6c7ad22002-12-03 21:28:10 +000055 }
56
57 sed13806.frameAdrs = sed13806.isaBase + FRAME_BUFFER_OFFSET;
58 sed13806.winSizeX = board_get_width ();
59 sed13806.winSizeY = board_get_height ();
60
61#if defined(CONFIG_VIDEO_SED13806_8BPP)
62 sed13806.gdfIndex = GDF__8BIT_INDEX;
63 sed13806.gdfBytesPP = 1;
wdenk8bde7f72003-06-27 21:31:46 +000064
wdenka6c7ad22002-12-03 21:28:10 +000065#elif defined(CONFIG_VIDEO_SED13806_16BPP)
66 sed13806.gdfIndex = GDF_16BIT_565RGB;
67 sed13806.gdfBytesPP = 2;
68
69#else
70#error Unsupported SED13806 BPP
71#endif
72
73 sed13806.memSize = sed13806.winSizeX * sed13806.winSizeY * sed13806.gdfBytesPP;
74
75 /* Load SED registers */
76 EpsonSetRegs ();
77
78 /* (see board/RPXClassic/RPXClassic.c) */
79 board_validate_screen (sed13806.isaBase);
80
81 /* Clear video memory */
82 i = sed13806.memSize/4;
83 vm = (unsigned int *)sed13806.frameAdrs;
84 while(i--)
wdenk8bde7f72003-06-27 21:31:46 +000085 *vm++ = 0;
86
87
wdenka6c7ad22002-12-03 21:28:10 +000088 return (&sed13806);
89}
90/*-----------------------------------------------------------------------------
91 * Epson_wait_idle -- Wait for hardware to become idle
92 *-----------------------------------------------------------------------------
93 */
94static void Epson_wait_idle (void)
95{
96 while (readByte (BLT_CTRL0) & 0x80);
97
98 /* Read a word in the BitBLT memory area to shutdown the BitBLT engine */
99 *(volatile unsigned short *)(sed13806.isaBase + BLT_REG);
100}
101
102/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +0000103 * video_hw_bitblt --
wdenka6c7ad22002-12-03 21:28:10 +0000104 *-----------------------------------------------------------------------------
105 */
106void video_hw_bitblt (
107 unsigned int bpp, /* bytes per pixel */
108 unsigned int src_x, /* source pos x */
109 unsigned int src_y, /* source pos y */
110 unsigned int dst_x, /* dest pos x */
111 unsigned int dst_y, /* dest pos y */
112 unsigned int dim_x, /* frame width */
113 unsigned int dim_y /* frame height */
114 )
115{
116 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
117 unsigned long srcAddr, dstAddr;
118 unsigned int stride = bpp * pGD -> winSizeX;
119
120 srcAddr = (src_y * stride) + (src_x * bpp);
121 dstAddr = (dst_y * stride) + (dst_x * bpp);
122
123 Epson_wait_idle ();
wdenk8bde7f72003-06-27 21:31:46 +0000124
125 writeByte(BLT_ROP,0x0C); /* source */
126 writeByte(BLT_OP,0x02);/* move blit in positive direction with ROP */
wdenka6c7ad22002-12-03 21:28:10 +0000127 writeWord(BLT_MEM_OFF0, stride / 2);
128 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
wdenk8bde7f72003-06-27 21:31:46 +0000129 writeByte(BLT_CTRL1,0x00);
wdenka6c7ad22002-12-03 21:28:10 +0000130 }
131 else {
wdenk8bde7f72003-06-27 21:31:46 +0000132 writeByte(BLT_CTRL1,0x01);
wdenka6c7ad22002-12-03 21:28:10 +0000133 }
134
135 writeWord(BLT_WIDTH0,(dim_x - 1));
136 writeWord(BLT_HEIGHT0,(dim_y - 1));
wdenk8bde7f72003-06-27 21:31:46 +0000137
wdenka6c7ad22002-12-03 21:28:10 +0000138 /* set up blit registers */
139 writeByte(BLT_SRC_ADDR0,srcAddr);
wdenk8bde7f72003-06-27 21:31:46 +0000140 writeByte(BLT_SRC_ADDR1,srcAddr>>8);
141 writeByte(BLT_SRC_ADDR2,srcAddr>>16);
142
wdenka6c7ad22002-12-03 21:28:10 +0000143 writeByte(BLT_DST_ADDR0,dstAddr);
wdenk8bde7f72003-06-27 21:31:46 +0000144 writeByte(BLT_DST_ADDR1,dstAddr>>8);
145 writeByte(BLT_DST_ADDR2,dstAddr>>16);
146
wdenka6c7ad22002-12-03 21:28:10 +0000147 /* Engage the blt engine */
148 /* rectangular region for src and dst */
149 writeByte(BLT_CTRL0,0x80);
150
151 /* wait untill current blits finished */
152 Epson_wait_idle ();
153}
154/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +0000155 * video_hw_rectfill --
wdenka6c7ad22002-12-03 21:28:10 +0000156 *-----------------------------------------------------------------------------
157 */
158void video_hw_rectfill (
159 unsigned int bpp, /* bytes per pixel */
160 unsigned int dst_x, /* dest pos x */
161 unsigned int dst_y, /* dest pos y */
162 unsigned int dim_x, /* frame width */
163 unsigned int dim_y, /* frame height */
164 unsigned int color /* fill color */
165 )
166{
167 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
168 unsigned long dstAddr;
169 unsigned int stride = bpp * pGD -> winSizeX;
170
171 dstAddr = (dst_y * stride) + (dst_x * bpp);
172
173 Epson_wait_idle ();
174
175 /* set up blit registers */
176 writeByte(BLT_DST_ADDR0,dstAddr);
wdenk8bde7f72003-06-27 21:31:46 +0000177 writeByte(BLT_DST_ADDR1,dstAddr>>8);
178 writeByte(BLT_DST_ADDR2,dstAddr>>16);
wdenka6c7ad22002-12-03 21:28:10 +0000179
180 writeWord(BLT_WIDTH0,(dim_x - 1));
181 writeWord(BLT_HEIGHT0,(dim_y - 1));
182 writeWord(BLT_FGCOLOR0,color);
183
184 writeByte(BLT_OP,0x0C); /* solid fill */
185 writeWord(BLT_MEM_OFF0,stride / 2);
186
187 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
wdenk8bde7f72003-06-27 21:31:46 +0000188 writeByte(BLT_CTRL1,0x00);
wdenka6c7ad22002-12-03 21:28:10 +0000189 }
190 else {
wdenk8bde7f72003-06-27 21:31:46 +0000191 writeByte(BLT_CTRL1,0x01);
wdenka6c7ad22002-12-03 21:28:10 +0000192 }
wdenk8bde7f72003-06-27 21:31:46 +0000193
wdenka6c7ad22002-12-03 21:28:10 +0000194 /* Engage the blt engine */
195 /* rectangular region for src and dst */
196 writeByte(BLT_CTRL0,0x80);
197
198 /* wait untill current blits finished */
199 Epson_wait_idle ();
200}
201
202/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +0000203 * video_set_lut --
wdenka6c7ad22002-12-03 21:28:10 +0000204 *-----------------------------------------------------------------------------
205 */
206void video_set_lut (
207 unsigned int index, /* color number */
208 unsigned char r, /* red */
209 unsigned char g, /* green */
210 unsigned char b /* blue */
211 )
212{
213 writeByte(REG_LUT_ADDR, index );
214 writeByte(REG_LUT_DATA, r);
215 writeByte(REG_LUT_DATA, g);
216 writeByte(REG_LUT_DATA, b);
217}
218#ifdef CONFIG_VIDEO_HW_CURSOR
219/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +0000220 * video_set_hw_cursor --
wdenka6c7ad22002-12-03 21:28:10 +0000221 *-----------------------------------------------------------------------------
222 */
223void video_set_hw_cursor (int x, int y)
224{
225 writeByte (LCD_CURSOR_XL, (x & 0xff));
226 writeByte (LCD_CURSOR_XM, (x >> 8));
227 writeByte (LCD_CURSOR_YL, (y & 0xff));
228 writeByte (LCD_CURSOR_YM, (y >> 8));
229}
230
231/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +0000232 * video_init_hw_cursor --
wdenka6c7ad22002-12-03 21:28:10 +0000233 *-----------------------------------------------------------------------------
234 */
235void video_init_hw_cursor (int font_width, int font_height)
236{
237 volatile unsigned char *ptr;
238 unsigned char pattern;
239 int i;
wdenk8bde7f72003-06-27 21:31:46 +0000240
wdenka6c7ad22002-12-03 21:28:10 +0000241
242 /* Init cursor content
243 Cursor size is 64x64 pixels
244 Start of the cursor memory depends on panel type (dual panel ...) */
245 if ((i = readByte (LCD_CURSOR_START)) == 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000246 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - HWCURSORSIZE);
wdenka6c7ad22002-12-03 21:28:10 +0000247 }
248 else {
wdenk8bde7f72003-06-27 21:31:46 +0000249 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192));
wdenka6c7ad22002-12-03 21:28:10 +0000250 }
251
252 /* Fill the first line and the first empty line after cursor */
253 for (i = 0, pattern = 0; i < 64; i++) {
wdenk8bde7f72003-06-27 21:31:46 +0000254 if (i < font_width) {
255 /* Invert background */
256 pattern |= 0x3;
257
258 }
259 else {
260 /* Background */
261 pattern |= 0x2;
262 }
263 if ((i & 3) == 3) {
264 *ptr = pattern;
265 *(ptr + font_height * 16) = 0xaa;
266 ptr ++;
267 pattern = 0;
268 }
269 pattern <<= 2;
wdenka6c7ad22002-12-03 21:28:10 +0000270 }
271
272 /* Duplicate this line */
273 for (i = 1; i < font_height; i++) {
wdenk8bde7f72003-06-27 21:31:46 +0000274 memcpy ((void *)ptr, (void *)(ptr - 16), 16);
275 ptr += 16;
wdenka6c7ad22002-12-03 21:28:10 +0000276 }
wdenk8bde7f72003-06-27 21:31:46 +0000277
wdenka6c7ad22002-12-03 21:28:10 +0000278 for (; i < 64; i++) {
wdenk8bde7f72003-06-27 21:31:46 +0000279 memcpy ((void *)(ptr + 16), (void *)ptr, 16);
280 ptr += 16;
wdenka6c7ad22002-12-03 21:28:10 +0000281 }
282
283 /* Select cursor mode */
284 writeByte (LCD_CURSOR_CNTL, 1);
285}
286#endif