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>
35 #define VCBITMASK(bitno) (0x0001 << (bitno % 16))
37 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
38 ((AT91PS_PIO) PORT)->PIO_PER = PIN; \
39 ((AT91PS_PIO) PORT)->DDR = PIN; \
40 ((AT91PS_PIO) PORT)->PIO_MDDR = PIN; \
41 if (!I0O1) ((AT91PS_PIO) PORT)->PIO_PPUER = PIN;
43 #define VCXK_SET_PIN(PORT, PIN) ((AT91PS_PIO) PORT)->PIO_SODR = PIN;
44 #define VCXK_CLR_PIN(PORT, PIN) ((AT91PS_PIO) PORT)->PIO_CODR = PIN;
46 #define VCXK_ACKNOWLEDGE \
47 (!(((AT91PS_PIO) CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT)->\
48 PIO_PDSR & CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
50 #elif defined(CONFIG_MCF52x2)
51 #include <asm/m5282.h>
53 #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
56 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
57 if (I0O1) DDR |= PIN; else DDR &= ~PIN;
59 #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
60 #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
62 #define VCXK_ACKNOWLEDGE \
63 (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
64 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
67 #error no vcxk support for selected ARCH
71 VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
73 VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
75 #ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
76 #define VCXK_BWS(x, data) vcxk_bws[x] = data;
77 #define VCXK_BWS_WORD_SET(x, mask) vcxk_bws_word[x] |= mask;
78 #define VCXK_BWS_WORD_CLEAR(x, mask) vcxk_bws_word[x] &= ~mask;
79 #define VCXK_BWS_LONG(x, data) vcxk_bws_long[x] = data;
81 u_char double_bws[16384];
82 u_short *double_bws_word;
83 u_long *double_bws_long;
84 #define VCXK_BWS(x,data) \
85 double_bws[x] = data; vcxk_bws[x] = data;
86 #define VCXK_BWS_WORD_SET(x,mask) \
87 double_bws_word[x] |= mask; \
88 vcxk_bws_word[x] = double_bws_word[x];
89 #define VCXK_BWS_WORD_CLEAR(x,mask) \
90 double_bws_word[x] &= ~mask; \
91 vcxk_bws_word[x] = double_bws_word[x];
92 #define VCXK_BWS_LONG(x,data) \
93 double_bws_long[x] = data; vcxk_bws_long[x] = data;
96 #define VC4K16_Bright1 vcxk_bws_word[0x20004 / 2]
97 #define VC4K16_Bright2 vcxk_bws_word[0x20006 / 2]
98 #define VC2K_Bright vcxk_bws[0x8000]
99 #define VC8K_BrightH vcxk_bws[0xC000]
100 #define VC8K_BrightL vcxk_bws[0xC001]
104 u_long display_width;
105 u_long display_height;
106 u_long display_bwidth;
108 ulong search_vcxk_driver(void);
110 void vcxk_setbrightness(unsigned int side, short brightness);
111 int vcxk_request(void);
112 int vcxk_acknowledge_wait(void);
113 void vcxk_clear(void);
116 ****f* bus_vcxk/vcxk_init
118 * initialalize Video Controller
120 * width visible display width in pixel
121 * height visible display height in pixel
125 int vcxk_init(unsigned long width, unsigned long height)
127 #ifdef CONFIG_SYS_VCXK_RESET_PORT
128 VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
129 CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
130 VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
133 #ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
134 double_bws_word = (u_short *)double_bws;
135 double_bws_long = (u_long *)double_bws;
136 debug("%lx %lx %lx \n", double_bws, double_bws_word, double_bws_long);
138 display_width = width;
139 display_height = height;
140 #if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
141 display_bwidth = ((width + 31) / 8) & ~0x3;
142 #elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
143 display_bwidth = ((width + 15) / 8) & ~0x1;
145 #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
147 debug("linesize ((%d + 15) / 8 & ~0x1) = %d\n",
148 display_width, display_bwidth);
150 #ifdef CONFIG_SYS_VCXK_AUTODETECT
152 vcxk_bws_long[1] = 0x0;
153 vcxk_bws_long[1] = 0x55AAAA55;
154 vcxk_bws_long[5] = 0x0;
155 if (vcxk_bws_long[1] == 0x55AAAA55)
159 debug("No autodetect: use vc4k\n");
162 VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
163 CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
164 VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)
166 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
167 VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
168 CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)
170 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
171 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
172 CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
175 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
176 CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
179 vcxk_cls(); /* clear second/hidden page */
181 vcxk_setbrightness(3, 1000);
187 ****f* bus_vcxk/vcxk_setpixel
189 * set the pixel[x,y] with the given color
193 * color <0x40 off/black
198 void vcxk_setpixel(int x, int y, unsigned long color)
202 if ((x < display_width) && (y < display_height)) {
203 dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
205 color = ((color >> 16) & 0xFF) |
206 ((color >> 8) & 0xFF) | (color & 0xFF);
209 VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
211 VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
217 ****f* bus_vcxk/vcxk_loadimage
219 * copies a binary image to display memory
223 void vcxk_loadimage(ulong source)
226 vcxk_acknowledge_wait();
228 for (cnt = 0; cnt < (16384 / 4); cnt++) {
229 VCXK_BWS_LONG(cnt, (*(ulong *) source));
233 for (cnt = 0; cnt < 16384; cnt++) {
234 VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
242 ****f* bus_vcxk/vcxk_cls
250 vcxk_acknowledge_wait();
256 ****f* bus_vcxk/vcxk_clear(void)
258 * clear the display memory
262 void vcxk_clear(void)
266 for (cnt = 0; cnt < (16384 / 4); cnt++) {
267 VCXK_BWS_LONG(cnt, 0)
272 ****f* bus_vcxk/vcxk_setbrightness
274 * set the display brightness
276 * side 1 set front side brightness
277 * 2 set back side brightness
278 * 3 set brightness for both sides
283 void vcxk_setbrightness(unsigned int side, short brightness)
286 if ((side == 0) || (side & 0x1))
287 VC4K16_Bright1 = brightness + 23;
288 if ((side == 0) || (side & 0x2))
289 VC4K16_Bright2 = brightness + 23;
291 VC2K_Bright = (brightness >> 4) + 2;
292 VC8K_BrightH = (brightness + 23) >> 8;
293 VC8K_BrightL = (brightness + 23) & 0xFF;
298 ****f* bus_vcxk/vcxk_request
300 * requests viewing of display memory
304 int vcxk_request(void)
306 VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
307 CONFIG_SYS_VCXK_REQUEST_PIN)
308 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
309 CONFIG_SYS_VCXK_REQUEST_PIN);
314 ****f* bus_vcxk/vcxk_acknowledge_wait
316 * wait for acknowledge viewing requests
320 int vcxk_acknowledge_wait(void)
322 while (VCXK_ACKNOWLEDGE)
328 ****f* bus_vcxk/vcxk_draw_mono
330 * copies a monochrom bitmap (BMP-Format) from given memory
332 * dataptr pointer to bitmap
333 * x output bitmap @ columne
334 * y output bitmap @ row
338 void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
339 unsigned long cp_width, unsigned long cp_height)
341 unsigned char *lineptr;
342 unsigned long xcnt, ycnt;
344 for (ycnt = cp_height; ycnt > 0; ycnt--) {
346 for (xcnt = 0; xcnt < cp_width; xcnt++) {
347 if ((*lineptr << (xcnt % 8)) & 0x80)
348 vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
350 vcxk_setpixel(xcnt, ycnt-1, 0);
355 dataptr = dataptr + linewidth;
360 ****f* bus_vcxk/vcxk_display_bitmap
362 * copies a bitmap (BMP-Format) to the given position
364 * addr pointer to bitmap
365 * x output bitmap @ columne
366 * y output bitmap @ row
370 int vcxk_display_bitmap(ulong addr, int x, int y)
374 unsigned long height;
376 unsigned long compression;
380 unsigned long c_width;
381 unsigned long c_height;
382 unsigned char *dataptr;
384 bmp = (bmp_image_t *) addr;
385 if ((bmp->header.signature[0] == 'B') &&
386 (bmp->header.signature[1] == 'M')) {
387 compression = le32_to_cpu(bmp->header.compression);
388 width = le32_to_cpu(bmp->header.width);
389 height = le32_to_cpu(bmp->header.height);
390 bpp = le16_to_cpu(bmp->header.bit_count);
392 dataptr = (unsigned char *) bmp +
393 le32_to_cpu(bmp->header.data_offset);
395 if (display_width < (width + x))
396 c_width = display_width - x;
399 if (display_height < (height + y))
400 c_height = display_height - y;
404 lw = (((width + 7) / 8) + 3) & ~0x3;
406 if (c_height < height)
407 dataptr = dataptr + lw * (height - c_height);
410 vcxk_draw_mono(dataptr, lw, c_width, c_height);
413 printf("Error: %ld bit per pixel "
414 "not supported by VCxK\n", bpp);
418 printf("Error: no valid bmp at %lx\n", (ulong) bmp);
425 ****f* bus_vcxk/video_display_bitmap
429 int video_display_bitmap(ulong addr, int x, int y)
431 vcxk_acknowledge_wait();
432 if (vcxk_display_bitmap(addr, x, y)) {