2 * (C) Copyright 2005-2009
3 * Jens Scharsig @ BuS Elektronik GmbH & Co. KG, <esw@bus-elektronik.de>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <bmp_layout.h>
12 vu_char *vcxk_bws = ((vu_char *) (CONFIG_SYS_VCXK_BASE));
13 vu_short *vcxk_bws_word = ((vu_short *)(CONFIG_SYS_VCXK_BASE));
14 vu_long *vcxk_bws_long = ((vu_long *) (CONFIG_SYS_VCXK_BASE));
16 #ifdef CONFIG_AT91RM9200
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/at91_pio.h>
21 #define VCBITMASK(bitno) (0x0001 << (bitno % 16))
23 #ifndef CONFIG_AT91_LEGACY
24 at91_pio_t *pio = (at91_pio_t *) AT91_PIO_BASE;
25 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
27 writel(PIN, &pio->PORT.per); \
28 writel(PIN, &pio->PORT.DDR); \
29 writel(PIN, &pio->PORT.mddr); \
31 writel(PIN, &pio->PORT.puer); \
34 #define VCXK_SET_PIN(PORT, PIN) writel(PIN, &pio->PORT.sodr);
35 #define VCXK_CLR_PIN(PORT, PIN) writel(PIN, &pio->PORT.codr);
37 #define VCXK_ACKNOWLEDGE \
38 (!(readl(&pio->CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT.pdsr) & \
39 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
41 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
42 ((AT91PS_PIO) PORT)->PIO_PER = PIN; \
43 ((AT91PS_PIO) PORT)->DDR = PIN; \
44 ((AT91PS_PIO) PORT)->PIO_MDDR = PIN; \
45 if (!I0O1) ((AT91PS_PIO) PORT)->PIO_PPUER = PIN;
47 #define VCXK_SET_PIN(PORT, PIN) ((AT91PS_PIO) PORT)->PIO_SODR = PIN;
48 #define VCXK_CLR_PIN(PORT, PIN) ((AT91PS_PIO) PORT)->PIO_CODR = PIN;
50 #define VCXK_ACKNOWLEDGE \
51 (!(((AT91PS_PIO) CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT)->\
52 PIO_PDSR & CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
54 #elif defined(CONFIG_MCF52x2)
55 #include <asm/m5282.h>
57 #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
60 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
61 if (I0O1) DDR |= PIN; else DDR &= ~PIN;
63 #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
64 #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
66 #define VCXK_ACKNOWLEDGE \
67 (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
68 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
71 #error no vcxk support for selected ARCH
75 VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
77 VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
79 #ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
80 #define VCXK_BWS(x, data) vcxk_bws[x] = data;
81 #define VCXK_BWS_WORD_SET(x, mask) vcxk_bws_word[x] |= mask;
82 #define VCXK_BWS_WORD_CLEAR(x, mask) vcxk_bws_word[x] &= ~mask;
83 #define VCXK_BWS_LONG(x, data) vcxk_bws_long[x] = data;
85 u_char double_bws[16384];
86 u_short *double_bws_word;
87 u_long *double_bws_long;
88 #define VCXK_BWS(x,data) \
89 double_bws[x] = data; vcxk_bws[x] = data;
90 #define VCXK_BWS_WORD_SET(x,mask) \
91 double_bws_word[x] |= mask; \
92 vcxk_bws_word[x] = double_bws_word[x];
93 #define VCXK_BWS_WORD_CLEAR(x,mask) \
94 double_bws_word[x] &= ~mask; \
95 vcxk_bws_word[x] = double_bws_word[x];
96 #define VCXK_BWS_LONG(x,data) \
97 double_bws_long[x] = data; vcxk_bws_long[x] = data;
100 #define VC4K16_Bright1 vcxk_bws_word[0x20004 / 2]
101 #define VC4K16_Bright2 vcxk_bws_word[0x20006 / 2]
102 #define VC2K_Bright vcxk_bws[0x8000]
103 #define VC8K_BrightH vcxk_bws[0xC000]
104 #define VC8K_BrightL vcxk_bws[0xC001]
108 u_long display_width;
109 u_long display_height;
110 u_long display_bwidth;
112 ulong search_vcxk_driver(void);
114 void vcxk_setbrightness(unsigned int side, short brightness);
115 int vcxk_request(void);
116 int vcxk_acknowledge_wait(void);
117 void vcxk_clear(void);
120 ****f* bus_vcxk/vcxk_init
122 * initialalize Video Controller
124 * width visible display width in pixel
125 * height visible display height in pixel
129 int vcxk_init(unsigned long width, unsigned long height)
131 #ifdef CONFIG_SYS_VCXK_RESET_PORT
132 VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
133 CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
134 VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
137 #ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
138 double_bws_word = (u_short *)double_bws;
139 double_bws_long = (u_long *)double_bws;
140 debug("%px %px %px\n", double_bws, double_bws_word, double_bws_long);
142 display_width = width;
143 display_height = height;
144 #if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
145 display_bwidth = ((width + 31) / 8) & ~0x3;
146 #elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
147 display_bwidth = ((width + 15) / 8) & ~0x1;
149 #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
151 debug("linesize ((%ld + 15) / 8 & ~0x1) = %ld\n",
152 display_width, display_bwidth);
154 #ifdef CONFIG_SYS_VCXK_AUTODETECT
156 vcxk_bws_long[1] = 0x0;
157 vcxk_bws_long[1] = 0x55AAAA55;
158 vcxk_bws_long[5] = 0x0;
159 if (vcxk_bws_long[1] == 0x55AAAA55)
163 debug("No autodetect: use vc4k\n");
166 VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
167 CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
168 VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)
170 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
171 VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
172 CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)
174 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
175 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
176 CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
179 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
180 CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
183 vcxk_cls(); /* clear second/hidden page */
185 vcxk_setbrightness(3, 1000);
191 ****f* bus_vcxk/vcxk_setpixel
193 * set the pixel[x,y] with the given color
197 * color <0x40 off/black
202 void vcxk_setpixel(int x, int y, unsigned long color)
206 if ((x < display_width) && (y < display_height)) {
207 dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
209 color = ((color >> 16) & 0xFF) |
210 ((color >> 8) & 0xFF) | (color & 0xFF);
213 VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
215 VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
221 ****f* bus_vcxk/vcxk_loadimage
223 * copies a binary image to display memory
227 void vcxk_loadimage(ulong source)
230 vcxk_acknowledge_wait();
232 for (cnt = 0; cnt < (16384 / 4); cnt++) {
233 VCXK_BWS_LONG(cnt, (*(ulong *) source));
237 for (cnt = 0; cnt < 16384; cnt++) {
238 VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
246 ****f* bus_vcxk/vcxk_cls
254 vcxk_acknowledge_wait();
260 ****f* bus_vcxk/vcxk_clear(void)
262 * clear the display memory
266 void vcxk_clear(void)
270 for (cnt = 0; cnt < (16384 / 4); cnt++) {
271 VCXK_BWS_LONG(cnt, 0)
276 ****f* bus_vcxk/vcxk_setbrightness
278 * set the display brightness
280 * side 1 set front side brightness
281 * 2 set back side brightness
282 * 3 set brightness for both sides
287 void vcxk_setbrightness(unsigned int side, short brightness)
290 if ((side == 0) || (side & 0x1))
291 VC4K16_Bright1 = brightness + 23;
292 if ((side == 0) || (side & 0x2))
293 VC4K16_Bright2 = brightness + 23;
295 VC2K_Bright = (brightness >> 4) + 2;
296 VC8K_BrightH = (brightness + 23) >> 8;
297 VC8K_BrightL = (brightness + 23) & 0xFF;
302 ****f* bus_vcxk/vcxk_request
304 * requests viewing of display memory
308 int vcxk_request(void)
310 VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
311 CONFIG_SYS_VCXK_REQUEST_PIN)
312 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
313 CONFIG_SYS_VCXK_REQUEST_PIN);
318 ****f* bus_vcxk/vcxk_acknowledge_wait
320 * wait for acknowledge viewing requests
324 int vcxk_acknowledge_wait(void)
326 while (VCXK_ACKNOWLEDGE)
332 ****f* bus_vcxk/vcxk_draw_mono
334 * copies a monochrom bitmap (BMP-Format) from given memory
336 * dataptr pointer to bitmap
337 * x output bitmap @ columne
338 * y output bitmap @ row
342 void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
343 unsigned long cp_width, unsigned long cp_height)
345 unsigned char *lineptr;
346 unsigned long xcnt, ycnt;
348 for (ycnt = cp_height; ycnt > 0; ycnt--) {
350 for (xcnt = 0; xcnt < cp_width; xcnt++) {
351 if ((*lineptr << (xcnt % 8)) & 0x80)
352 vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
354 vcxk_setpixel(xcnt, ycnt-1, 0);
359 dataptr = dataptr + linewidth;
364 ****f* bus_vcxk/vcxk_display_bitmap
366 * copies a bitmap (BMP-Format) to the given position
368 * addr pointer to bitmap
369 * x output bitmap @ columne
370 * y output bitmap @ row
374 int vcxk_display_bitmap(ulong addr, int x, int y)
378 unsigned long height;
383 unsigned long c_width;
384 unsigned long c_height;
385 unsigned char *dataptr;
387 bmp = (bmp_image_t *) addr;
388 if ((bmp->header.signature[0] == 'B') &&
389 (bmp->header.signature[1] == 'M')) {
390 width = le32_to_cpu(bmp->header.width);
391 height = le32_to_cpu(bmp->header.height);
392 bpp = le16_to_cpu(bmp->header.bit_count);
394 dataptr = (unsigned char *) bmp +
395 le32_to_cpu(bmp->header.data_offset);
397 if (display_width < (width + x))
398 c_width = display_width - x;
401 if (display_height < (height + y))
402 c_height = display_height - y;
406 lw = (((width + 7) / 8) + 3) & ~0x3;
408 if (c_height < height)
409 dataptr = dataptr + lw * (height - c_height);
412 vcxk_draw_mono(dataptr, lw, c_width, c_height);
415 printf("Error: %ld bit per pixel "
416 "not supported by VCxK\n", bpp);
420 printf("Error: no valid bmp at %lx\n", (ulong) bmp);
427 ****f* bus_vcxk/video_display_bitmap
431 int video_display_bitmap(ulong addr, int x, int y)
433 vcxk_acknowledge_wait();
434 if (vcxk_display_bitmap(addr, x, y)) {