2 * (C) Copyright 2005-2009
3 * Jens Scharsig @ BuS Elektronik GmbH & Co. KG, <esw@bus-elektronik.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <bmp_layout.h>
28 vu_char *vcxk_bws = ((vu_char *) (CONFIG_SYS_VCXK_BASE));
29 vu_short *vcxk_bws_word = ((vu_short *)(CONFIG_SYS_VCXK_BASE));
30 vu_long *vcxk_bws_long = ((vu_long *) (CONFIG_SYS_VCXK_BASE));
32 #ifdef CONFIG_AT91RM9200
33 #include <asm/arch/hardware.h>
34 #include <asm/arch/at91_pio.h>
37 #define VCBITMASK(bitno) (0x0001 << (bitno % 16))
39 #ifndef CONFIG_AT91_LEGACY
40 at91_pio_t *pio = (at91_pio_t *) AT91_PIO_BASE;
41 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
43 writel(PIN, &pio->PORT.per); \
44 writel(PIN, &pio->PORT.DDR); \
45 writel(PIN, &pio->PORT.mddr); \
47 writel(PIN, &pio->PORT.puer); \
50 #define VCXK_SET_PIN(PORT, PIN) writel(PIN, &pio->PORT.sodr);
51 #define VCXK_CLR_PIN(PORT, PIN) writel(PIN, &pio->PORT.codr);
53 #define VCXK_ACKNOWLEDGE \
54 (!(readl(&pio->CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT.pdsr) & \
55 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
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;
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;
66 #define VCXK_ACKNOWLEDGE \
67 (!(((AT91PS_PIO) CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT)->\
68 PIO_PDSR & CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
70 #elif defined(CONFIG_MCF52x2)
71 #include <asm/m5282.h>
73 #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
76 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
77 if (I0O1) DDR |= PIN; else DDR &= ~PIN;
79 #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
80 #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
82 #define VCXK_ACKNOWLEDGE \
83 (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
84 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
87 #error no vcxk support for selected ARCH
91 VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
93 VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
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;
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;
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]
124 u_long display_width;
125 u_long display_height;
126 u_long display_bwidth;
128 ulong search_vcxk_driver(void);
130 void vcxk_setbrightness(unsigned int side, short brightness);
131 int vcxk_request(void);
132 int vcxk_acknowledge_wait(void);
133 void vcxk_clear(void);
136 ****f* bus_vcxk/vcxk_init
138 * initialalize Video Controller
140 * width visible display width in pixel
141 * height visible display height in pixel
145 int vcxk_init(unsigned long width, unsigned long height)
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);
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);
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;
165 #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
167 debug("linesize ((%ld + 15) / 8 & ~0x1) = %ld\n",
168 display_width, display_bwidth);
170 #ifdef CONFIG_SYS_VCXK_AUTODETECT
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)
179 debug("No autodetect: use vc4k\n");
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)
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)
190 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
191 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
192 CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
195 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
196 CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
199 vcxk_cls(); /* clear second/hidden page */
201 vcxk_setbrightness(3, 1000);
207 ****f* bus_vcxk/vcxk_setpixel
209 * set the pixel[x,y] with the given color
213 * color <0x40 off/black
218 void vcxk_setpixel(int x, int y, unsigned long color)
222 if ((x < display_width) && (y < display_height)) {
223 dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
225 color = ((color >> 16) & 0xFF) |
226 ((color >> 8) & 0xFF) | (color & 0xFF);
229 VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
231 VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
237 ****f* bus_vcxk/vcxk_loadimage
239 * copies a binary image to display memory
243 void vcxk_loadimage(ulong source)
246 vcxk_acknowledge_wait();
248 for (cnt = 0; cnt < (16384 / 4); cnt++) {
249 VCXK_BWS_LONG(cnt, (*(ulong *) source));
253 for (cnt = 0; cnt < 16384; cnt++) {
254 VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
262 ****f* bus_vcxk/vcxk_cls
270 vcxk_acknowledge_wait();
276 ****f* bus_vcxk/vcxk_clear(void)
278 * clear the display memory
282 void vcxk_clear(void)
286 for (cnt = 0; cnt < (16384 / 4); cnt++) {
287 VCXK_BWS_LONG(cnt, 0)
292 ****f* bus_vcxk/vcxk_setbrightness
294 * set the display brightness
296 * side 1 set front side brightness
297 * 2 set back side brightness
298 * 3 set brightness for both sides
303 void vcxk_setbrightness(unsigned int side, short brightness)
306 if ((side == 0) || (side & 0x1))
307 VC4K16_Bright1 = brightness + 23;
308 if ((side == 0) || (side & 0x2))
309 VC4K16_Bright2 = brightness + 23;
311 VC2K_Bright = (brightness >> 4) + 2;
312 VC8K_BrightH = (brightness + 23) >> 8;
313 VC8K_BrightL = (brightness + 23) & 0xFF;
318 ****f* bus_vcxk/vcxk_request
320 * requests viewing of display memory
324 int vcxk_request(void)
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);
334 ****f* bus_vcxk/vcxk_acknowledge_wait
336 * wait for acknowledge viewing requests
340 int vcxk_acknowledge_wait(void)
342 while (VCXK_ACKNOWLEDGE)
348 ****f* bus_vcxk/vcxk_draw_mono
350 * copies a monochrom bitmap (BMP-Format) from given memory
352 * dataptr pointer to bitmap
353 * x output bitmap @ columne
354 * y output bitmap @ row
358 void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
359 unsigned long cp_width, unsigned long cp_height)
361 unsigned char *lineptr;
362 unsigned long xcnt, ycnt;
364 for (ycnt = cp_height; ycnt > 0; ycnt--) {
366 for (xcnt = 0; xcnt < cp_width; xcnt++) {
367 if ((*lineptr << (xcnt % 8)) & 0x80)
368 vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
370 vcxk_setpixel(xcnt, ycnt-1, 0);
375 dataptr = dataptr + linewidth;
380 ****f* bus_vcxk/vcxk_display_bitmap
382 * copies a bitmap (BMP-Format) to the given position
384 * addr pointer to bitmap
385 * x output bitmap @ columne
386 * y output bitmap @ row
390 int vcxk_display_bitmap(ulong addr, int x, int y)
394 unsigned long height;
396 unsigned long compression;
400 unsigned long c_width;
401 unsigned long c_height;
402 unsigned char *dataptr;
404 bmp = (bmp_image_t *) addr;
405 if ((bmp->header.signature[0] == 'B') &&
406 (bmp->header.signature[1] == 'M')) {
407 compression = le32_to_cpu(bmp->header.compression);
408 width = le32_to_cpu(bmp->header.width);
409 height = le32_to_cpu(bmp->header.height);
410 bpp = le16_to_cpu(bmp->header.bit_count);
412 dataptr = (unsigned char *) bmp +
413 le32_to_cpu(bmp->header.data_offset);
415 if (display_width < (width + x))
416 c_width = display_width - x;
419 if (display_height < (height + y))
420 c_height = display_height - y;
424 lw = (((width + 7) / 8) + 3) & ~0x3;
426 if (c_height < height)
427 dataptr = dataptr + lw * (height - c_height);
430 vcxk_draw_mono(dataptr, lw, c_width, c_height);
433 printf("Error: %ld bit per pixel "
434 "not supported by VCxK\n", bpp);
438 printf("Error: no valid bmp at %lx\n", (ulong) bmp);
445 ****f* bus_vcxk/video_display_bitmap
449 int video_display_bitmap(ulong addr, int x, int y)
451 vcxk_acknowledge_wait();
452 if (vcxk_display_bitmap(addr, x, y)) {