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 at91_pio_t *pio = (at91_pio_t *) AT91_PIO_BASE;
24 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
26 writel(PIN, &pio->PORT.per); \
27 writel(PIN, &pio->PORT.DDR); \
28 writel(PIN, &pio->PORT.mddr); \
30 writel(PIN, &pio->PORT.puer); \
33 #define VCXK_SET_PIN(PORT, PIN) writel(PIN, &pio->PORT.sodr);
34 #define VCXK_CLR_PIN(PORT, PIN) writel(PIN, &pio->PORT.codr);
36 #define VCXK_ACKNOWLEDGE \
37 (!(readl(&pio->CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT.pdsr) & \
38 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
39 #elif defined(CONFIG_MCF52x2)
40 #include <asm/m5282.h>
42 #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
45 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
46 if (I0O1) DDR |= PIN; else DDR &= ~PIN;
48 #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
49 #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
51 #define VCXK_ACKNOWLEDGE \
52 (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
53 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
56 #error no vcxk support for selected ARCH
60 VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
62 VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
64 #ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
65 #define VCXK_BWS(x, data) vcxk_bws[x] = data;
66 #define VCXK_BWS_WORD_SET(x, mask) vcxk_bws_word[x] |= mask;
67 #define VCXK_BWS_WORD_CLEAR(x, mask) vcxk_bws_word[x] &= ~mask;
68 #define VCXK_BWS_LONG(x, data) vcxk_bws_long[x] = data;
70 u_char double_bws[16384];
71 u_short *double_bws_word;
72 u_long *double_bws_long;
73 #define VCXK_BWS(x,data) \
74 double_bws[x] = data; vcxk_bws[x] = data;
75 #define VCXK_BWS_WORD_SET(x,mask) \
76 double_bws_word[x] |= mask; \
77 vcxk_bws_word[x] = double_bws_word[x];
78 #define VCXK_BWS_WORD_CLEAR(x,mask) \
79 double_bws_word[x] &= ~mask; \
80 vcxk_bws_word[x] = double_bws_word[x];
81 #define VCXK_BWS_LONG(x,data) \
82 double_bws_long[x] = data; vcxk_bws_long[x] = data;
85 #define VC4K16_Bright1 vcxk_bws_word[0x20004 / 2]
86 #define VC4K16_Bright2 vcxk_bws_word[0x20006 / 2]
87 #define VC2K_Bright vcxk_bws[0x8000]
88 #define VC8K_BrightH vcxk_bws[0xC000]
89 #define VC8K_BrightL vcxk_bws[0xC001]
94 u_long display_height;
95 u_long display_bwidth;
97 ulong search_vcxk_driver(void);
99 void vcxk_setbrightness(unsigned int side, short brightness);
100 int vcxk_request(void);
101 int vcxk_acknowledge_wait(void);
102 void vcxk_clear(void);
105 ****f* bus_vcxk/vcxk_init
107 * initialalize Video Controller
109 * width visible display width in pixel
110 * height visible display height in pixel
114 int vcxk_init(unsigned long width, unsigned long height)
116 #ifdef CONFIG_SYS_VCXK_RESET_PORT
117 VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
118 CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
119 VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
122 #ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
123 double_bws_word = (u_short *)double_bws;
124 double_bws_long = (u_long *)double_bws;
125 debug("%px %px %px\n", double_bws, double_bws_word, double_bws_long);
127 display_width = width;
128 display_height = height;
129 #if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
130 display_bwidth = ((width + 31) / 8) & ~0x3;
131 #elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
132 display_bwidth = ((width + 15) / 8) & ~0x1;
134 #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
136 debug("linesize ((%ld + 15) / 8 & ~0x1) = %ld\n",
137 display_width, display_bwidth);
139 #ifdef CONFIG_SYS_VCXK_AUTODETECT
141 vcxk_bws_long[1] = 0x0;
142 vcxk_bws_long[1] = 0x55AAAA55;
143 vcxk_bws_long[5] = 0x0;
144 if (vcxk_bws_long[1] == 0x55AAAA55)
148 debug("No autodetect: use vc4k\n");
151 VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
152 CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
153 VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)
155 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
156 VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
157 CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)
159 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
160 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
161 CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
164 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
165 CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
168 vcxk_cls(); /* clear second/hidden page */
170 vcxk_setbrightness(3, 1000);
176 ****f* bus_vcxk/vcxk_setpixel
178 * set the pixel[x,y] with the given color
182 * color <0x40 off/black
187 void vcxk_setpixel(int x, int y, unsigned long color)
191 if ((x < display_width) && (y < display_height)) {
192 dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
194 color = ((color >> 16) & 0xFF) |
195 ((color >> 8) & 0xFF) | (color & 0xFF);
198 VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
200 VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
206 ****f* bus_vcxk/vcxk_loadimage
208 * copies a binary image to display memory
212 void vcxk_loadimage(ulong source)
215 vcxk_acknowledge_wait();
217 for (cnt = 0; cnt < (16384 / 4); cnt++) {
218 VCXK_BWS_LONG(cnt, (*(ulong *) source));
222 for (cnt = 0; cnt < 16384; cnt++) {
223 VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
231 ****f* bus_vcxk/vcxk_cls
239 vcxk_acknowledge_wait();
245 ****f* bus_vcxk/vcxk_clear(void)
247 * clear the display memory
251 void vcxk_clear(void)
255 for (cnt = 0; cnt < (16384 / 4); cnt++) {
256 VCXK_BWS_LONG(cnt, 0)
261 ****f* bus_vcxk/vcxk_setbrightness
263 * set the display brightness
265 * side 1 set front side brightness
266 * 2 set back side brightness
267 * 3 set brightness for both sides
272 void vcxk_setbrightness(unsigned int side, short brightness)
275 if ((side == 0) || (side & 0x1))
276 VC4K16_Bright1 = brightness + 23;
277 if ((side == 0) || (side & 0x2))
278 VC4K16_Bright2 = brightness + 23;
280 VC2K_Bright = (brightness >> 4) + 2;
281 VC8K_BrightH = (brightness + 23) >> 8;
282 VC8K_BrightL = (brightness + 23) & 0xFF;
287 ****f* bus_vcxk/vcxk_request
289 * requests viewing of display memory
293 int vcxk_request(void)
295 VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
296 CONFIG_SYS_VCXK_REQUEST_PIN)
297 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
298 CONFIG_SYS_VCXK_REQUEST_PIN);
303 ****f* bus_vcxk/vcxk_acknowledge_wait
305 * wait for acknowledge viewing requests
309 int vcxk_acknowledge_wait(void)
311 while (VCXK_ACKNOWLEDGE)
317 ****f* bus_vcxk/vcxk_draw_mono
319 * copies a monochrom bitmap (BMP-Format) from given memory
321 * dataptr pointer to bitmap
322 * x output bitmap @ columne
323 * y output bitmap @ row
327 void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
328 unsigned long cp_width, unsigned long cp_height)
330 unsigned char *lineptr;
331 unsigned long xcnt, ycnt;
333 for (ycnt = cp_height; ycnt > 0; ycnt--) {
335 for (xcnt = 0; xcnt < cp_width; xcnt++) {
336 if ((*lineptr << (xcnt % 8)) & 0x80)
337 vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
339 vcxk_setpixel(xcnt, ycnt-1, 0);
344 dataptr = dataptr + linewidth;
349 ****f* bus_vcxk/vcxk_display_bitmap
351 * copies a bitmap (BMP-Format) to the given position
353 * addr pointer to bitmap
354 * x output bitmap @ columne
355 * y output bitmap @ row
359 int vcxk_display_bitmap(ulong addr, int x, int y)
361 struct bmp_image *bmp;
363 unsigned long height;
368 unsigned long c_width;
369 unsigned long c_height;
370 unsigned char *dataptr;
372 bmp = (struct bmp_image *)addr;
373 if ((bmp->header.signature[0] == 'B') &&
374 (bmp->header.signature[1] == 'M')) {
375 width = le32_to_cpu(bmp->header.width);
376 height = le32_to_cpu(bmp->header.height);
377 bpp = le16_to_cpu(bmp->header.bit_count);
379 dataptr = (unsigned char *) bmp +
380 le32_to_cpu(bmp->header.data_offset);
382 if (display_width < (width + x))
383 c_width = display_width - x;
386 if (display_height < (height + y))
387 c_height = display_height - y;
391 lw = (((width + 7) / 8) + 3) & ~0x3;
393 if (c_height < height)
394 dataptr = dataptr + lw * (height - c_height);
397 vcxk_draw_mono(dataptr, lw, c_width, c_height);
400 printf("Error: %ld bit per pixel "
401 "not supported by VCxK\n", bpp);
405 printf("Error: no valid bmp at %lx\n", (ulong) bmp);
412 ****f* bus_vcxk/video_display_bitmap
416 int video_display_bitmap(ulong addr, int x, int y)
418 vcxk_acknowledge_wait();
419 if (vcxk_display_bitmap(addr, x, y)) {