]> git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/video/sed13806.c
libfdt: Sync overlay with upstream
[people/ms/u-boot.git] / drivers / video / sed13806.c
1 /*
2 * (C) Copyright 2002
3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8 /* Video support for Epson SED13806 chipset */
9
10 #include <common.h>
11
12 #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))
23
24 GraphicDevice sed13806;
25
26 /*-----------------------------------------------------------------------------
27 * EpsonSetRegs --
28 *-----------------------------------------------------------------------------
29 */
30 static 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) {
35 writeByte (preg -> Index, preg -> Value);
36 preg ++;
37 }
38 }
39
40 /*-----------------------------------------------------------------------------
41 * video_hw_init --
42 *-----------------------------------------------------------------------------
43 */
44 void *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) {
54 return (NULL);
55 }
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;
64
65 #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--)
85 *vm++ = 0;
86
87
88 return (&sed13806);
89 }
90 /*-----------------------------------------------------------------------------
91 * Epson_wait_idle -- Wait for hardware to become idle
92 *-----------------------------------------------------------------------------
93 */
94 static 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 /*-----------------------------------------------------------------------------
103 * video_hw_bitblt --
104 *-----------------------------------------------------------------------------
105 */
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 */
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 ();
124
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);
130 }
131 else {
132 writeByte(BLT_CTRL1,0x01);
133 }
134
135 writeWord(BLT_WIDTH0,(dim_x - 1));
136 writeWord(BLT_HEIGHT0,(dim_y - 1));
137
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);
142
143 writeByte(BLT_DST_ADDR0,dstAddr);
144 writeByte(BLT_DST_ADDR1,dstAddr>>8);
145 writeByte(BLT_DST_ADDR2,dstAddr>>16);
146
147 /* 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 /*-----------------------------------------------------------------------------
155 * video_hw_rectfill --
156 *-----------------------------------------------------------------------------
157 */
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 */
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);
177 writeByte(BLT_DST_ADDR1,dstAddr>>8);
178 writeByte(BLT_DST_ADDR2,dstAddr>>16);
179
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) {
188 writeByte(BLT_CTRL1,0x00);
189 }
190 else {
191 writeByte(BLT_CTRL1,0x01);
192 }
193
194 /* 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 /*-----------------------------------------------------------------------------
203 * video_set_lut --
204 *-----------------------------------------------------------------------------
205 */
206 void 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 /*-----------------------------------------------------------------------------
220 * video_set_hw_cursor --
221 *-----------------------------------------------------------------------------
222 */
223 void 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 /*-----------------------------------------------------------------------------
232 * video_init_hw_cursor --
233 *-----------------------------------------------------------------------------
234 */
235 void video_init_hw_cursor (int font_width, int font_height)
236 {
237 volatile unsigned char *ptr;
238 unsigned char pattern;
239 int i;
240
241
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);
247 }
248 else {
249 ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192));
250 }
251
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 */
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;
270 }
271
272 /* Duplicate this line */
273 for (i = 1; i < font_height; i++) {
274 memcpy ((void *)ptr, (void *)(ptr - 16), 16);
275 ptr += 16;
276 }
277
278 for (; i < 64; i++) {
279 memcpy ((void *)(ptr + 16), (void *)ptr, 16);
280 ptr += 16;
281 }
282
283 /* Select cursor mode */
284 writeByte (LCD_CURSOR_CNTL, 1);
285 }
286 #endif