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