3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
6 * SPDX-License-Identifier: GPL-2.0+
8 /* Video support for Epson SED13806 chipset */
15 #define readByte(ptrReg) \
16 *(volatile unsigned char *)(sed13806.isaBase + ptrReg)
18 #define writeByte(ptrReg,value) \
19 *(volatile unsigned char *)(sed13806.isaBase + ptrReg) = value
21 #define writeWord(ptrReg,value) \
22 (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = ((value >> 8 ) & 0xff) | ((value << 8) & 0xff00))
24 GraphicDevice sed13806;
26 /*-----------------------------------------------------------------------------
28 *-----------------------------------------------------------------------------
30 static void EpsonSetRegs (void)
32 /* the content of the chipset register depends on the board (clocks, ...)*/
33 const S1D_REGS *preg = board_get_regs ();
34 while (preg -> Index) {
35 writeByte (preg -> Index, preg -> Value);
40 /*-----------------------------------------------------------------------------
42 *-----------------------------------------------------------------------------
44 void *video_hw_init (void)
48 memset (&sed13806, 0, sizeof (GraphicDevice));
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) {
57 sed13806.frameAdrs = sed13806.isaBase + FRAME_BUFFER_OFFSET;
58 sed13806.winSizeX = board_get_width ();
59 sed13806.winSizeY = board_get_height ();
61 #if defined(CONFIG_VIDEO_SED13806_8BPP)
62 sed13806.gdfIndex = GDF__8BIT_INDEX;
63 sed13806.gdfBytesPP = 1;
65 #elif defined(CONFIG_VIDEO_SED13806_16BPP)
66 sed13806.gdfIndex = GDF_16BIT_565RGB;
67 sed13806.gdfBytesPP = 2;
70 #error Unsupported SED13806 BPP
73 sed13806.memSize = sed13806.winSizeX * sed13806.winSizeY * sed13806.gdfBytesPP;
75 /* Load SED registers */
78 /* (see board/RPXClassic/RPXClassic.c) */
79 board_validate_screen (sed13806.isaBase);
81 /* Clear video memory */
82 i = sed13806.memSize/4;
83 vm = (unsigned int *)sed13806.frameAdrs;
90 /*-----------------------------------------------------------------------------
91 * Epson_wait_idle -- Wait for hardware to become idle
92 *-----------------------------------------------------------------------------
94 static void Epson_wait_idle (void)
96 while (readByte (BLT_CTRL0) & 0x80);
98 /* Read a word in the BitBLT memory area to shutdown the BitBLT engine */
99 *(volatile unsigned short *)(sed13806.isaBase + BLT_REG);
102 /*-----------------------------------------------------------------------------
104 *-----------------------------------------------------------------------------
106 void 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 */
116 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
117 unsigned long srcAddr, dstAddr;
118 unsigned int stride = bpp * pGD -> winSizeX;
120 srcAddr = (src_y * stride) + (src_x * bpp);
121 dstAddr = (dst_y * stride) + (dst_x * bpp);
125 writeByte(BLT_ROP,0x0C); /* source */
126 writeByte(BLT_OP,0x02);/* move blit in positive direction with ROP */
127 writeWord(BLT_MEM_OFF0, stride / 2);
128 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
129 writeByte(BLT_CTRL1,0x00);
132 writeByte(BLT_CTRL1,0x01);
135 writeWord(BLT_WIDTH0,(dim_x - 1));
136 writeWord(BLT_HEIGHT0,(dim_y - 1));
138 /* set up blit registers */
139 writeByte(BLT_SRC_ADDR0,srcAddr);
140 writeByte(BLT_SRC_ADDR1,srcAddr>>8);
141 writeByte(BLT_SRC_ADDR2,srcAddr>>16);
143 writeByte(BLT_DST_ADDR0,dstAddr);
144 writeByte(BLT_DST_ADDR1,dstAddr>>8);
145 writeByte(BLT_DST_ADDR2,dstAddr>>16);
147 /* Engage the blt engine */
148 /* rectangular region for src and dst */
149 writeByte(BLT_CTRL0,0x80);
151 /* wait untill current blits finished */
154 /*-----------------------------------------------------------------------------
155 * video_hw_rectfill --
156 *-----------------------------------------------------------------------------
158 void 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 */
167 register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
168 unsigned long dstAddr;
169 unsigned int stride = bpp * pGD -> winSizeX;
171 dstAddr = (dst_y * stride) + (dst_x * bpp);
175 /* set up blit registers */
176 writeByte(BLT_DST_ADDR0,dstAddr);
177 writeByte(BLT_DST_ADDR1,dstAddr>>8);
178 writeByte(BLT_DST_ADDR2,dstAddr>>16);
180 writeWord(BLT_WIDTH0,(dim_x - 1));
181 writeWord(BLT_HEIGHT0,(dim_y - 1));
182 writeWord(BLT_FGCOLOR0,color);
184 writeByte(BLT_OP,0x0C); /* solid fill */
185 writeWord(BLT_MEM_OFF0,stride / 2);
187 if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
188 writeByte(BLT_CTRL1,0x00);
191 writeByte(BLT_CTRL1,0x01);
194 /* Engage the blt engine */
195 /* rectangular region for src and dst */
196 writeByte(BLT_CTRL0,0x80);
198 /* wait untill current blits finished */
202 /*-----------------------------------------------------------------------------
204 *-----------------------------------------------------------------------------
207 unsigned int index, /* color number */
208 unsigned char r, /* red */
209 unsigned char g, /* green */
210 unsigned char b /* blue */
213 writeByte(REG_LUT_ADDR, index );
214 writeByte(REG_LUT_DATA, r);
215 writeByte(REG_LUT_DATA, g);
216 writeByte(REG_LUT_DATA, b);
218 #ifdef CONFIG_VIDEO_HW_CURSOR
219 /*-----------------------------------------------------------------------------
220 * video_set_hw_cursor --
221 *-----------------------------------------------------------------------------
223 void video_set_hw_cursor (int x, int y)
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));
231 /*-----------------------------------------------------------------------------
232 * video_init_hw_cursor --
233 *-----------------------------------------------------------------------------
235 void video_init_hw_cursor (int font_width, int font_height)
237 volatile unsigned char *ptr;
238 unsigned char pattern;
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) {
246 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - HWCURSORSIZE);
249 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192));
252 /* Fill the first line and the first empty line after cursor */
253 for (i = 0, pattern = 0; i < 64; i++) {
254 if (i < font_width) {
255 /* Invert background */
265 *(ptr + font_height * 16) = 0xaa;
272 /* Duplicate this line */
273 for (i = 1; i < font_height; i++) {
274 memcpy ((void *)ptr, (void *)(ptr - 16), 16);
278 for (; i < 64; i++) {
279 memcpy ((void *)(ptr + 16), (void *)ptr, 16);
283 /* Select cursor mode */
284 writeByte (LCD_CURSOR_CNTL, 1);