1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2005-2009
4 * Jens Scharsig @ BuS Elektronik GmbH & Co. KG, <esw@bus-elektronik.de>
8 #include <bmp_layout.h>
11 vu_char *vcxk_bws = ((vu_char *) (CONFIG_SYS_VCXK_BASE));
12 vu_short *vcxk_bws_word = ((vu_short *)(CONFIG_SYS_VCXK_BASE));
13 vu_long *vcxk_bws_long = ((vu_long *) (CONFIG_SYS_VCXK_BASE));
15 #ifdef CONFIG_AT91RM9200
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/at91_pio.h>
20 #define VCBITMASK(bitno) (0x0001 << (bitno % 16))
22 at91_pio_t *pio = (at91_pio_t *) AT91_PIO_BASE;
23 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
25 writel(PIN, &pio->PORT.per); \
26 writel(PIN, &pio->PORT.DDR); \
27 writel(PIN, &pio->PORT.mddr); \
29 writel(PIN, &pio->PORT.puer); \
32 #define VCXK_SET_PIN(PORT, PIN) writel(PIN, &pio->PORT.sodr);
33 #define VCXK_CLR_PIN(PORT, PIN) writel(PIN, &pio->PORT.codr);
35 #define VCXK_ACKNOWLEDGE \
36 (!(readl(&pio->CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT.pdsr) & \
37 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
38 #elif defined(CONFIG_MCF52x2)
39 #include <asm/m5282.h>
41 #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
44 #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
45 if (I0O1) DDR |= PIN; else DDR &= ~PIN;
47 #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
48 #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
50 #define VCXK_ACKNOWLEDGE \
51 (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
52 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
55 #error no vcxk support for selected ARCH
59 VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
61 VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
63 #ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
64 #define VCXK_BWS(x, data) vcxk_bws[x] = data;
65 #define VCXK_BWS_WORD_SET(x, mask) vcxk_bws_word[x] |= mask;
66 #define VCXK_BWS_WORD_CLEAR(x, mask) vcxk_bws_word[x] &= ~mask;
67 #define VCXK_BWS_LONG(x, data) vcxk_bws_long[x] = data;
69 u_char double_bws[16384];
70 u_short *double_bws_word;
71 u_long *double_bws_long;
72 #define VCXK_BWS(x,data) \
73 double_bws[x] = data; vcxk_bws[x] = data;
74 #define VCXK_BWS_WORD_SET(x,mask) \
75 double_bws_word[x] |= mask; \
76 vcxk_bws_word[x] = double_bws_word[x];
77 #define VCXK_BWS_WORD_CLEAR(x,mask) \
78 double_bws_word[x] &= ~mask; \
79 vcxk_bws_word[x] = double_bws_word[x];
80 #define VCXK_BWS_LONG(x,data) \
81 double_bws_long[x] = data; vcxk_bws_long[x] = data;
84 #define VC4K16_Bright1 vcxk_bws_word[0x20004 / 2]
85 #define VC4K16_Bright2 vcxk_bws_word[0x20006 / 2]
86 #define VC2K_Bright vcxk_bws[0x8000]
87 #define VC8K_BrightH vcxk_bws[0xC000]
88 #define VC8K_BrightL vcxk_bws[0xC001]
93 u_long display_height;
94 u_long display_bwidth;
96 ulong search_vcxk_driver(void);
98 void vcxk_setbrightness(unsigned int side, short brightness);
99 int vcxk_request(void);
100 int vcxk_acknowledge_wait(void);
101 void vcxk_clear(void);
104 ****f* bus_vcxk/vcxk_init
106 * initialalize Video Controller
108 * width visible display width in pixel
109 * height visible display height in pixel
113 int vcxk_init(unsigned long width, unsigned long height)
115 #ifdef CONFIG_SYS_VCXK_RESET_PORT
116 VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
117 CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
118 VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
121 #ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
122 double_bws_word = (u_short *)double_bws;
123 double_bws_long = (u_long *)double_bws;
124 debug("%px %px %px\n", double_bws, double_bws_word, double_bws_long);
126 display_width = width;
127 display_height = height;
128 #if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
129 display_bwidth = ((width + 31) / 8) & ~0x3;
130 #elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
131 display_bwidth = ((width + 15) / 8) & ~0x1;
133 #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
135 debug("linesize ((%ld + 15) / 8 & ~0x1) = %ld\n",
136 display_width, display_bwidth);
138 #ifdef CONFIG_SYS_VCXK_AUTODETECT
140 vcxk_bws_long[1] = 0x0;
141 vcxk_bws_long[1] = 0x55AAAA55;
142 vcxk_bws_long[5] = 0x0;
143 if (vcxk_bws_long[1] == 0x55AAAA55)
147 debug("No autodetect: use vc4k\n");
150 VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
151 CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
152 VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)
154 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
155 VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
156 CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)
158 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
159 CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
160 CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
163 VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
164 CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
167 vcxk_cls(); /* clear second/hidden page */
169 vcxk_setbrightness(3, 1000);
175 ****f* bus_vcxk/vcxk_setpixel
177 * set the pixel[x,y] with the given color
181 * color <0x40 off/black
186 void vcxk_setpixel(int x, int y, unsigned long color)
190 if ((x < display_width) && (y < display_height)) {
191 dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
193 color = ((color >> 16) & 0xFF) |
194 ((color >> 8) & 0xFF) | (color & 0xFF);
197 VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
199 VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
205 ****f* bus_vcxk/vcxk_loadimage
207 * copies a binary image to display memory
211 void vcxk_loadimage(ulong source)
214 vcxk_acknowledge_wait();
216 for (cnt = 0; cnt < (16384 / 4); cnt++) {
217 VCXK_BWS_LONG(cnt, (*(ulong *) source));
221 for (cnt = 0; cnt < 16384; cnt++) {
222 VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
230 ****f* bus_vcxk/vcxk_cls
238 vcxk_acknowledge_wait();
244 ****f* bus_vcxk/vcxk_clear(void)
246 * clear the display memory
250 void vcxk_clear(void)
254 for (cnt = 0; cnt < (16384 / 4); cnt++) {
255 VCXK_BWS_LONG(cnt, 0)
260 ****f* bus_vcxk/vcxk_setbrightness
262 * set the display brightness
264 * side 1 set front side brightness
265 * 2 set back side brightness
266 * 3 set brightness for both sides
271 void vcxk_setbrightness(unsigned int side, short brightness)
274 if ((side == 0) || (side & 0x1))
275 VC4K16_Bright1 = brightness + 23;
276 if ((side == 0) || (side & 0x2))
277 VC4K16_Bright2 = brightness + 23;
279 VC2K_Bright = (brightness >> 4) + 2;
280 VC8K_BrightH = (brightness + 23) >> 8;
281 VC8K_BrightL = (brightness + 23) & 0xFF;
286 ****f* bus_vcxk/vcxk_request
288 * requests viewing of display memory
292 int vcxk_request(void)
294 VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
295 CONFIG_SYS_VCXK_REQUEST_PIN)
296 VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
297 CONFIG_SYS_VCXK_REQUEST_PIN);
302 ****f* bus_vcxk/vcxk_acknowledge_wait
304 * wait for acknowledge viewing requests
308 int vcxk_acknowledge_wait(void)
310 while (VCXK_ACKNOWLEDGE)
316 ****f* bus_vcxk/vcxk_draw_mono
318 * copies a monochrom bitmap (BMP-Format) from given memory
320 * dataptr pointer to bitmap
321 * x output bitmap @ columne
322 * y output bitmap @ row
326 void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
327 unsigned long cp_width, unsigned long cp_height)
329 unsigned char *lineptr;
330 unsigned long xcnt, ycnt;
332 for (ycnt = cp_height; ycnt > 0; ycnt--) {
334 for (xcnt = 0; xcnt < cp_width; xcnt++) {
335 if ((*lineptr << (xcnt % 8)) & 0x80)
336 vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
338 vcxk_setpixel(xcnt, ycnt-1, 0);
343 dataptr = dataptr + linewidth;
348 ****f* bus_vcxk/vcxk_display_bitmap
350 * copies a bitmap (BMP-Format) to the given position
352 * addr pointer to bitmap
353 * x output bitmap @ columne
354 * y output bitmap @ row
358 int vcxk_display_bitmap(ulong addr, int x, int y)
360 struct bmp_image *bmp;
362 unsigned long height;
367 unsigned long c_width;
368 unsigned long c_height;
369 unsigned char *dataptr;
371 bmp = (struct bmp_image *)addr;
372 if ((bmp->header.signature[0] == 'B') &&
373 (bmp->header.signature[1] == 'M')) {
374 width = le32_to_cpu(bmp->header.width);
375 height = le32_to_cpu(bmp->header.height);
376 bpp = le16_to_cpu(bmp->header.bit_count);
378 dataptr = (unsigned char *) bmp +
379 le32_to_cpu(bmp->header.data_offset);
381 if (display_width < (width + x))
382 c_width = display_width - x;
385 if (display_height < (height + y))
386 c_height = display_height - y;
390 lw = (((width + 7) / 8) + 3) & ~0x3;
392 if (c_height < height)
393 dataptr = dataptr + lw * (height - c_height);
396 vcxk_draw_mono(dataptr, lw, c_width, c_height);
399 printf("Error: %ld bit per pixel "
400 "not supported by VCxK\n", bpp);
404 printf("Error: no valid bmp at %lx\n", (ulong) bmp);
411 ****f* bus_vcxk/video_display_bitmap
415 int video_display_bitmap(ulong addr, int x, int y)
417 vcxk_acknowledge_wait();
418 if (vcxk_display_bitmap(addr, x, y)) {