1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2005-2009
4 * Jens Scharsig @ BuS Elektronik GmbH & Co. KG, <esw@bus-elektronik.de>
5 */
6
7 #include <common.h>
8 #include <bmp_layout.h>
9 #include <asm/io.h>
10
11 vu_char *vcxk_bws = ((vu_char *) (CONFIG_SYS_VCXK_BASE));
12 vu_short *vcxk_bws_word = ((vu_short *)(CONFIG_SYS_VCXK_BASE));
13 vu_long *vcxk_bws_long = ((vu_long *) (CONFIG_SYS_VCXK_BASE));
14
15 #ifdef CONFIG_AT91RM9200
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/at91_pio.h>
18
19 #ifndef VCBITMASK
20 #define VCBITMASK(bitno) (0x0001 << (bitno % 16))
21 #endif
22 at91_pio_t *pio = (at91_pio_t *) AT91_PIO_BASE;
23 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
24 do { \
25 writel(PIN, &pio->PORT.per); \
26 writel(PIN, &pio->PORT.DDR); \
27 writel(PIN, &pio->PORT.mddr); \
28 if (!I0O1) \
29 writel(PIN, &pio->PORT.puer); \
30 } while (0);
31
32 #define VCXK_SET_PIN(PORT, PIN) writel(PIN, &pio->PORT.sodr);
33 #define VCXK_CLR_PIN(PORT, PIN) writel(PIN, &pio->PORT.codr);
34
35 #define VCXK_ACKNOWLEDGE \
36 (!(readl(&pio->CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT.pdsr) & \
37 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
38 #elif defined(CONFIG_MCF52x2)
39 #include <asm/m5282.h>
40 #ifndef VCBITMASK
41 #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
42 #endif
43
44 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
45 if (I0O1) DDR |= PIN; else DDR &= ~PIN;
46
47 #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
48 #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
49
50 #define VCXK_ACKNOWLEDGE \
51 (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
52 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
53
54 #else
55 #error no vcxk support for selected ARCH
56 #endif
57
58 #define VCXK_DISABLE\
59 VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
60 #define VCXK_ENABLE\
61 VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
62
63 #ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
64 #define VCXK_BWS(x, data) vcxk_bws[x] = data;
65 #define VCXK_BWS_WORD_SET(x, mask) vcxk_bws_word[x] |= mask;
66 #define VCXK_BWS_WORD_CLEAR(x, mask) vcxk_bws_word[x] &= ~mask;
67 #define VCXK_BWS_LONG(x, data) vcxk_bws_long[x] = data;
68 #else
69 u_char double_bws[16384];
70 u_short *double_bws_word;
71 u_long *double_bws_long;
72 #define VCXK_BWS(x,data) \
73 double_bws[x] = data; vcxk_bws[x] = data;
74 #define VCXK_BWS_WORD_SET(x,mask) \
75 double_bws_word[x] |= mask; \
76 vcxk_bws_word[x] = double_bws_word[x];
77 #define VCXK_BWS_WORD_CLEAR(x,mask) \
78 double_bws_word[x] &= ~mask; \
79 vcxk_bws_word[x] = double_bws_word[x];
80 #define VCXK_BWS_LONG(x,data) \
81 double_bws_long[x] = data; vcxk_bws_long[x] = data;
82 #endif
83
84 #define VC4K16_Bright1 vcxk_bws_word[0x20004 / 2]
85 #define VC4K16_Bright2 vcxk_bws_word[0x20006 / 2]
86 #define VC2K_Bright vcxk_bws[0x8000]
87 #define VC8K_BrightH vcxk_bws[0xC000]
88 #define VC8K_BrightL vcxk_bws[0xC001]
89
90 vu_char VC4K16;
91
92 u_long display_width;
93 u_long display_height;
94 u_long display_bwidth;
95
96 ulong search_vcxk_driver(void);
97 void vcxk_cls(void);
98 void vcxk_setbrightness(unsigned int side, short brightness);
99 int vcxk_request(void);
100 int vcxk_acknowledge_wait(void);
101 void vcxk_clear(void);
102
103 /*
104 ****f* bus_vcxk/vcxk_init
105 * FUNCTION
106 * initialalize Video Controller
107 * PARAMETERS
108 * width visible display width in pixel
109 * height visible display height in pixel
110 ***
111 */
112
vcxk_init(unsigned long width,unsigned long height)113 int vcxk_init(unsigned long width, unsigned long height)
114 {
115 #ifdef CONFIG_SYS_VCXK_RESET_PORT
116 VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
117 CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
118 VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
119 #endif
120
121 #ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
122 double_bws_word = (u_short *)double_bws;
123 double_bws_long = (u_long *)double_bws;
124 debug("%px %px %px\n", double_bws, double_bws_word, double_bws_long);
125 #endif
126 display_width = width;
127 display_height = height;
128 #if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
129 display_bwidth = ((width + 31) / 8) & ~0x3;
130 #elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
131 display_bwidth = ((width + 15) / 8) & ~0x1;
132 #else
133 #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
134 #endif
135 debug("linesize ((%ld + 15) / 8 & ~0x1) = %ld\n",
136 display_width, display_bwidth);
137
138 #ifdef CONFIG_SYS_VCXK_AUTODETECT
139 VC4K16 = 0;
140 vcxk_bws_long[1] = 0x0;
141 vcxk_bws_long[1] = 0x55AAAA55;
142 vcxk_bws_long[5] = 0x0;
143 if (vcxk_bws_long[1] == 0x55AAAA55)
144 VC4K16 = 1;
145 #else
146 VC4K16 = 1;
147 debug("No autodetect: use vc4k\n");
148 #endif
149
150 VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
151 CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
152 VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)
153
154 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
155 VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
156 CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)
157
158 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
159 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
160 CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
161
162 VCXK_DISABLE;
163 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
164 CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
165
166 vcxk_cls();
167 vcxk_cls(); /* clear second/hidden page */
168
169 vcxk_setbrightness(3, 1000);
170 VCXK_ENABLE;
171 return 1;
172 }
173
174 /*
175 ****f* bus_vcxk/vcxk_setpixel
176 * FUNCTION
177 * set the pixel[x,y] with the given color
178 * PARAMETER
179 * x pixel colum
180 * y pixel row
181 * color <0x40 off/black
182 * >0x40 on
183 ***
184 */
185
vcxk_setpixel(int x,int y,unsigned long color)186 void vcxk_setpixel(int x, int y, unsigned long color)
187 {
188 vu_short dataptr;
189
190 if ((x < display_width) && (y < display_height)) {
191 dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
192
193 color = ((color >> 16) & 0xFF) |
194 ((color >> 8) & 0xFF) | (color & 0xFF);
195
196 if (color > 0x40) {
197 VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
198 } else {
199 VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
200 }
201 }
202 }
203
204 /*
205 ****f* bus_vcxk/vcxk_loadimage
206 * FUNCTION
207 * copies a binary image to display memory
208 ***
209 */
210
vcxk_loadimage(ulong source)211 void vcxk_loadimage(ulong source)
212 {
213 int cnt;
214 vcxk_acknowledge_wait();
215 if (VC4K16) {
216 for (cnt = 0; cnt < (16384 / 4); cnt++) {
217 VCXK_BWS_LONG(cnt, (*(ulong *) source));
218 source = source + 4;
219 }
220 } else {
221 for (cnt = 0; cnt < 16384; cnt++) {
222 VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
223 source++;
224 }
225 }
226 vcxk_request();
227 }
228
229 /*
230 ****f* bus_vcxk/vcxk_cls
231 * FUNCTION
232 * clear the display
233 ***
234 */
235
vcxk_cls(void)236 void vcxk_cls(void)
237 {
238 vcxk_acknowledge_wait();
239 vcxk_clear();
240 vcxk_request();
241 }
242
243 /*
244 ****f* bus_vcxk/vcxk_clear(void)
245 * FUNCTION
246 * clear the display memory
247 ***
248 */
249
vcxk_clear(void)250 void vcxk_clear(void)
251 {
252 int cnt;
253
254 for (cnt = 0; cnt < (16384 / 4); cnt++) {
255 VCXK_BWS_LONG(cnt, 0)
256 }
257 }
258
259 /*
260 ****f* bus_vcxk/vcxk_setbrightness
261 * FUNCTION
262 * set the display brightness
263 * PARAMETER
264 * side 1 set front side brightness
265 * 2 set back side brightness
266 * 3 set brightness for both sides
267 * brightness 0..1000
268 ***
269 */
270
vcxk_setbrightness(unsigned int side,short brightness)271 void vcxk_setbrightness(unsigned int side, short brightness)
272 {
273 if (VC4K16) {
274 if ((side == 0) || (side & 0x1))
275 VC4K16_Bright1 = brightness + 23;
276 if ((side == 0) || (side & 0x2))
277 VC4K16_Bright2 = brightness + 23;
278 } else {
279 VC2K_Bright = (brightness >> 4) + 2;
280 VC8K_BrightH = (brightness + 23) >> 8;
281 VC8K_BrightL = (brightness + 23) & 0xFF;
282 }
283 }
284
285 /*
286 ****f* bus_vcxk/vcxk_request
287 * FUNCTION
288 * requests viewing of display memory
289 ***
290 */
291
vcxk_request(void)292 int vcxk_request(void)
293 {
294 VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
295 CONFIG_SYS_VCXK_REQUEST_PIN)
296 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
297 CONFIG_SYS_VCXK_REQUEST_PIN);
298 return 1;
299 }
300
301 /*
302 ****f* bus_vcxk/vcxk_acknowledge_wait
303 * FUNCTION
304 * wait for acknowledge viewing requests
305 ***
306 */
307
vcxk_acknowledge_wait(void)308 int vcxk_acknowledge_wait(void)
309 {
310 while (VCXK_ACKNOWLEDGE)
311 ;
312 return 1;
313 }
314
315 /*
316 ****f* bus_vcxk/vcxk_draw_mono
317 * FUNCTION
318 * copies a monochrom bitmap (BMP-Format) from given memory
319 * PARAMETER
320 * dataptr pointer to bitmap
321 * x output bitmap @ columne
322 * y output bitmap @ row
323 ***
324 */
325
vcxk_draw_mono(unsigned char * dataptr,unsigned long linewidth,unsigned long cp_width,unsigned long cp_height)326 void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
327 unsigned long cp_width, unsigned long cp_height)
328 {
329 unsigned char *lineptr;
330 unsigned long xcnt, ycnt;
331
332 for (ycnt = cp_height; ycnt > 0; ycnt--) {
333 lineptr = dataptr;
334 for (xcnt = 0; xcnt < cp_width; xcnt++) {
335 if ((*lineptr << (xcnt % 8)) & 0x80)
336 vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
337 else
338 vcxk_setpixel(xcnt, ycnt-1, 0);
339
340 if ((xcnt % 8) == 7)
341 lineptr++;
342 } /* endfor xcnt */
343 dataptr = dataptr + linewidth;
344 } /* endfor ycnt */
345 }
346
347 /*
348 ****f* bus_vcxk/vcxk_display_bitmap
349 * FUNCTION
350 * copies a bitmap (BMP-Format) to the given position
351 * PARAMETER
352 * addr pointer to bitmap
353 * x output bitmap @ columne
354 * y output bitmap @ row
355 ***
356 */
357
vcxk_display_bitmap(ulong addr,int x,int y)358 int vcxk_display_bitmap(ulong addr, int x, int y)
359 {
360 struct bmp_image *bmp;
361 unsigned long width;
362 unsigned long height;
363 unsigned long bpp;
364
365 unsigned long lw;
366
367 unsigned long c_width;
368 unsigned long c_height;
369 unsigned char *dataptr;
370
371 bmp = (struct bmp_image *)addr;
372 if ((bmp->header.signature[0] == 'B') &&
373 (bmp->header.signature[1] == 'M')) {
374 width = le32_to_cpu(bmp->header.width);
375 height = le32_to_cpu(bmp->header.height);
376 bpp = le16_to_cpu(bmp->header.bit_count);
377
378 dataptr = (unsigned char *) bmp +
379 le32_to_cpu(bmp->header.data_offset);
380
381 if (display_width < (width + x))
382 c_width = display_width - x;
383 else
384 c_width = width;
385 if (display_height < (height + y))
386 c_height = display_height - y;
387 else
388 c_height = height;
389
390 lw = (((width + 7) / 8) + 3) & ~0x3;
391
392 if (c_height < height)
393 dataptr = dataptr + lw * (height - c_height);
394 switch (bpp) {
395 case 1:
396 vcxk_draw_mono(dataptr, lw, c_width, c_height);
397 break;
398 default:
399 printf("Error: %ld bit per pixel "
400 "not supported by VCxK\n", bpp);
401 return 0;
402 }
403 } else {
404 printf("Error: no valid bmp at %lx\n", (ulong) bmp);
405 return 0;
406 }
407 return 1;
408 }
409
410 /*
411 ****f* bus_vcxk/video_display_bitmap
412 ***
413 */
414
video_display_bitmap(ulong addr,int x,int y)415 int video_display_bitmap(ulong addr, int x, int y)
416 {
417 vcxk_acknowledge_wait();
418 if (vcxk_display_bitmap(addr, x, y)) {
419 vcxk_request();
420 return 0;
421 }
422 return 1;
423 }
424
425 /* EOF */
426