]>
Commit | Line | Data |
---|---|---|
8655b6f8 WD |
1 | /* |
2 | * Common LCD routines for supported CPUs | |
3 | * | |
4 | * (C) Copyright 2001-2002 | |
5 | * Wolfgang Denk, DENX Software Engineering -- wd@denx.de | |
6 | * | |
3765b3e7 | 7 | * SPDX-License-Identifier: GPL-2.0+ |
8655b6f8 WD |
8 | */ |
9 | ||
10 | /************************************************************************/ | |
11 | /* ** HEADER FILES */ | |
12 | /************************************************************************/ | |
13 | ||
14 | /* #define DEBUG */ | |
15 | ||
16 | #include <config.h> | |
17 | #include <common.h> | |
18 | #include <command.h> | |
8655b6f8 | 19 | #include <stdarg.h> |
c0880485 NK |
20 | #include <search.h> |
21 | #include <env_callback.h> | |
8655b6f8 | 22 | #include <linux/types.h> |
52cb4d4f | 23 | #include <stdio_dev.h> |
8655b6f8 WD |
24 | #if defined(CONFIG_POST) |
25 | #include <post.h> | |
26 | #endif | |
27 | #include <lcd.h> | |
8b0bfc68 | 28 | #include <watchdog.h> |
dca2a1c1 | 29 | #include <asm/unaligned.h> |
dd4425e8 | 30 | #include <splash.h> |
7d95f2a3 SG |
31 | #include <asm/io.h> |
32 | #include <asm/unaligned.h> | |
dd4425e8 | 33 | |
abc20aba MV |
34 | #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \ |
35 | defined(CONFIG_CPU_MONAHANS) | |
36 | #define CONFIG_CPU_PXA | |
8655b6f8 WD |
37 | #include <asm/byteorder.h> |
38 | #endif | |
39 | ||
40 | #if defined(CONFIG_MPC823) | |
8655b6f8 WD |
41 | #include <lcdvideo.h> |
42 | #endif | |
43 | ||
39cf4804 SP |
44 | #if defined(CONFIG_ATMEL_LCD) |
45 | #include <atmel_lcdc.h> | |
39cf4804 SP |
46 | #endif |
47 | ||
6a195d2d SW |
48 | #if defined(CONFIG_LCD_DT_SIMPLEFB) |
49 | #include <libfdt.h> | |
50 | #endif | |
51 | ||
8655b6f8 WD |
52 | /************************************************************************/ |
53 | /* ** FONT DATA */ | |
54 | /************************************************************************/ | |
55 | #include <video_font.h> /* Get font data, width and height */ | |
56 | ||
88804d19 WD |
57 | /************************************************************************/ |
58 | /* ** LOGO DATA */ | |
59 | /************************************************************************/ | |
60 | #ifdef CONFIG_LCD_LOGO | |
61 | # include <bmp_logo.h> /* Get logo data, width and height */ | |
c270730f | 62 | # include <bmp_logo_data.h> |
acb13868 | 63 | # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16) |
88804d19 WD |
64 | # error Default Color Map overlaps with Logo Color Map |
65 | # endif | |
66 | #endif | |
8655b6f8 | 67 | |
7d95f2a3 SG |
68 | #ifdef CONFIG_SANDBOX |
69 | #include <asm/sdl.h> | |
70 | #endif | |
71 | ||
676d319e SG |
72 | #ifndef CONFIG_LCD_ALIGNMENT |
73 | #define CONFIG_LCD_ALIGNMENT PAGE_SIZE | |
74 | #endif | |
75 | ||
0d89efef SG |
76 | /* By default we scroll by a single line */ |
77 | #ifndef CONFIG_CONSOLE_SCROLL_LINES | |
78 | #define CONFIG_CONSOLE_SCROLL_LINES 1 | |
79 | #endif | |
80 | ||
a5796c51 JH |
81 | /************************************************************************/ |
82 | /* ** CONSOLE DEFINITIONS & FUNCTIONS */ | |
83 | /************************************************************************/ | |
84 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) | |
85 | # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \ | |
86 | / VIDEO_FONT_HEIGHT) | |
87 | #else | |
88 | # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT) | |
89 | #endif | |
90 | ||
91 | #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH) | |
92 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) | |
93 | #define CONSOLE_ROW_FIRST lcd_console_address | |
94 | #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) | |
95 | #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ | |
96 | - CONSOLE_ROW_SIZE) | |
97 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) | |
98 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
d87080b7 | 99 | |
a5796c51 JH |
100 | #if LCD_BPP == LCD_MONOCHROME |
101 | # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \ | |
102 | (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7) | |
57d76a89 HP |
103 | #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ |
104 | (LCD_BPP == LCD_COLOR32) | |
a5796c51 JH |
105 | # define COLOR_MASK(c) (c) |
106 | #else | |
107 | # error Unsupported LCD BPP. | |
108 | #endif | |
109 | ||
d87080b7 | 110 | DECLARE_GLOBAL_DATA_PTR; |
8655b6f8 | 111 | |
8f47d917 | 112 | static void lcd_drawchars(ushort x, ushort y, uchar *str, int count); |
8f47d917 | 113 | static inline void lcd_putc_xy(ushort x, ushort y, uchar c); |
8655b6f8 | 114 | |
8f47d917 | 115 | static int lcd_init(void *lcdbase); |
8655b6f8 | 116 | |
6b035141 | 117 | static void *lcd_logo(void); |
8655b6f8 | 118 | |
8f47d917 NK |
119 | static void lcd_setfgcolor(int color); |
120 | static void lcd_setbgcolor(int color); | |
8655b6f8 | 121 | |
46d1d5dd WD |
122 | static int lcd_color_fg; |
123 | static int lcd_color_bg; | |
f1d205a1 | 124 | int lcd_line_length; |
46d1d5dd | 125 | |
8655b6f8 | 126 | char lcd_is_enabled = 0; |
8655b6f8 | 127 | |
f1d205a1 JH |
128 | static short console_col; |
129 | static short console_row; | |
9a8efc46 | 130 | |
f1d205a1 | 131 | static void *lcd_console_address; |
00a0ca59 | 132 | static void *lcd_base; /* Start of framebuffer memory */ |
9a8efc46 | 133 | |
9a8efc46 | 134 | static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */ |
8655b6f8 WD |
135 | |
136 | /************************************************************************/ | |
137 | ||
9a8efc46 SG |
138 | /* Flush LCD activity to the caches */ |
139 | void lcd_sync(void) | |
140 | { | |
141 | /* | |
142 | * flush_dcache_range() is declared in common.h but it seems that some | |
143 | * architectures do not actually implement it. Is there a way to find | |
144 | * out whether it exists? For now, ARM is safe. | |
145 | */ | |
146 | #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF) | |
147 | int line_length; | |
148 | ||
149 | if (lcd_flush_dcache) | |
150 | flush_dcache_range((u32)lcd_base, | |
151 | (u32)(lcd_base + lcd_get_size(&line_length))); | |
7d95f2a3 SG |
152 | #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL) |
153 | static ulong last_sync; | |
154 | ||
155 | if (get_timer(last_sync) > 10) { | |
156 | sandbox_sdl_sync(lcd_base); | |
157 | last_sync = get_timer(0); | |
158 | } | |
9a8efc46 SG |
159 | #endif |
160 | } | |
161 | ||
162 | void lcd_set_flush_dcache(int flush) | |
163 | { | |
164 | lcd_flush_dcache = (flush != 0); | |
165 | } | |
166 | ||
8655b6f8 WD |
167 | /*----------------------------------------------------------------------*/ |
168 | ||
8f47d917 | 169 | static void console_scrollup(void) |
8655b6f8 | 170 | { |
0d89efef SG |
171 | const int rows = CONFIG_CONSOLE_SCROLL_LINES; |
172 | ||
173 | /* Copy up rows ignoring those that will be overwritten */ | |
174 | memcpy(CONSOLE_ROW_FIRST, | |
175 | lcd_console_address + CONSOLE_ROW_SIZE * rows, | |
176 | CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); | |
177 | ||
178 | /* Clear the last rows */ | |
57d76a89 | 179 | #if (LCD_BPP != LCD_COLOR32) |
0d89efef SG |
180 | memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, |
181 | COLOR_MASK(lcd_color_bg), | |
6b035141 | 182 | CONSOLE_ROW_SIZE * rows); |
57d76a89 HP |
183 | #else |
184 | u32 *ppix = lcd_console_address + | |
185 | CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; | |
186 | u32 i; | |
187 | for (i = 0; | |
188 | i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); | |
189 | i++) { | |
190 | *ppix++ = COLOR_MASK(lcd_color_bg); | |
191 | } | |
192 | #endif | |
9a8efc46 | 193 | lcd_sync(); |
0d89efef | 194 | console_row -= rows; |
8655b6f8 WD |
195 | } |
196 | ||
197 | /*----------------------------------------------------------------------*/ | |
198 | ||
8f47d917 | 199 | static inline void console_back(void) |
8655b6f8 WD |
200 | { |
201 | if (--console_col < 0) { | |
202 | console_col = CONSOLE_COLS-1 ; | |
6b035141 | 203 | if (--console_row < 0) |
8655b6f8 | 204 | console_row = 0; |
8655b6f8 WD |
205 | } |
206 | ||
8f47d917 NK |
207 | lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, |
208 | console_row * VIDEO_FONT_HEIGHT, ' '); | |
8655b6f8 WD |
209 | } |
210 | ||
211 | /*----------------------------------------------------------------------*/ | |
212 | ||
8f47d917 | 213 | static inline void console_newline(void) |
8655b6f8 | 214 | { |
8655b6f8 WD |
215 | console_col = 0; |
216 | ||
217 | /* Check if we need to scroll the terminal */ | |
6b035141 | 218 | if (++console_row >= CONSOLE_ROWS) |
8f47d917 | 219 | console_scrollup(); |
6b035141 | 220 | else |
9a8efc46 | 221 | lcd_sync(); |
8655b6f8 WD |
222 | } |
223 | ||
224 | /*----------------------------------------------------------------------*/ | |
225 | ||
709ea543 SG |
226 | static void lcd_stub_putc(struct stdio_dev *dev, const char c) |
227 | { | |
228 | lcd_putc(c); | |
229 | } | |
230 | ||
8f47d917 | 231 | void lcd_putc(const char c) |
8655b6f8 WD |
232 | { |
233 | if (!lcd_is_enabled) { | |
234 | serial_putc(c); | |
8f47d917 | 235 | |
8655b6f8 WD |
236 | return; |
237 | } | |
238 | ||
239 | switch (c) { | |
8f47d917 NK |
240 | case '\r': |
241 | console_col = 0; | |
8655b6f8 | 242 | |
8f47d917 NK |
243 | return; |
244 | case '\n': | |
245 | console_newline(); | |
8655b6f8 | 246 | |
8f47d917 | 247 | return; |
8655b6f8 | 248 | case '\t': /* Tab (8 chars alignment) */ |
8f47d917 NK |
249 | console_col += 8; |
250 | console_col &= ~7; | |
8655b6f8 | 251 | |
8f47d917 NK |
252 | if (console_col >= CONSOLE_COLS) |
253 | console_newline(); | |
8655b6f8 | 254 | |
8f47d917 NK |
255 | return; |
256 | case '\b': | |
257 | console_back(); | |
8655b6f8 | 258 | |
8f47d917 NK |
259 | return; |
260 | default: | |
261 | lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, | |
262 | console_row * VIDEO_FONT_HEIGHT, c); | |
263 | if (++console_col >= CONSOLE_COLS) | |
264 | console_newline(); | |
8655b6f8 | 265 | } |
8655b6f8 WD |
266 | } |
267 | ||
268 | /*----------------------------------------------------------------------*/ | |
269 | ||
709ea543 SG |
270 | static void lcd_stub_puts(struct stdio_dev *dev, const char *s) |
271 | { | |
272 | lcd_puts(s); | |
273 | } | |
274 | ||
8f47d917 | 275 | void lcd_puts(const char *s) |
8655b6f8 WD |
276 | { |
277 | if (!lcd_is_enabled) { | |
8f47d917 NK |
278 | serial_puts(s); |
279 | ||
8655b6f8 WD |
280 | return; |
281 | } | |
282 | ||
6b035141 | 283 | while (*s) |
8f47d917 | 284 | lcd_putc(*s++); |
6b035141 | 285 | |
9a8efc46 | 286 | lcd_sync(); |
8655b6f8 WD |
287 | } |
288 | ||
15b17ab5 HS |
289 | /*----------------------------------------------------------------------*/ |
290 | ||
291 | void lcd_printf(const char *fmt, ...) | |
292 | { | |
293 | va_list args; | |
294 | char buf[CONFIG_SYS_PBSIZE]; | |
295 | ||
296 | va_start(args, fmt); | |
297 | vsprintf(buf, fmt, args); | |
298 | va_end(args); | |
299 | ||
300 | lcd_puts(buf); | |
301 | } | |
302 | ||
8655b6f8 WD |
303 | /************************************************************************/ |
304 | /* ** Low-Level Graphics Routines */ | |
305 | /************************************************************************/ | |
306 | ||
8f47d917 | 307 | static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) |
8655b6f8 WD |
308 | { |
309 | uchar *dest; | |
be547c6d MV |
310 | ushort row; |
311 | ||
0f999c49 AG |
312 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
313 | y += BMP_LOGO_HEIGHT; | |
314 | #endif | |
315 | ||
be547c6d MV |
316 | #if LCD_BPP == LCD_MONOCHROME |
317 | ushort off = x * (1 << LCD_BPP) % 8; | |
318 | #endif | |
8655b6f8 | 319 | |
57d76a89 | 320 | dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8); |
8655b6f8 | 321 | |
8f47d917 | 322 | for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { |
8655b6f8 | 323 | uchar *s = str; |
8655b6f8 | 324 | int i; |
acb13868 AR |
325 | #if LCD_BPP == LCD_COLOR16 |
326 | ushort *d = (ushort *)dest; | |
57d76a89 HP |
327 | #elif LCD_BPP == LCD_COLOR32 |
328 | u32 *d = (u32 *)dest; | |
acb13868 AR |
329 | #else |
330 | uchar *d = dest; | |
331 | #endif | |
8655b6f8 WD |
332 | |
333 | #if LCD_BPP == LCD_MONOCHROME | |
6b035141 | 334 | uchar rest = *d & -(1 << (8 - off)); |
8655b6f8 WD |
335 | uchar sym; |
336 | #endif | |
8f47d917 | 337 | for (i = 0; i < count; ++i) { |
8655b6f8 WD |
338 | uchar c, bits; |
339 | ||
340 | c = *s++; | |
341 | bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; | |
342 | ||
343 | #if LCD_BPP == LCD_MONOCHROME | |
344 | sym = (COLOR_MASK(lcd_color_fg) & bits) | | |
8f47d917 | 345 | (COLOR_MASK(lcd_color_bg) & ~bits); |
8655b6f8 WD |
346 | |
347 | *d++ = rest | (sym >> off); | |
348 | rest = sym << (8-off); | |
349 | #elif LCD_BPP == LCD_COLOR8 | |
8f47d917 | 350 | for (c = 0; c < 8; ++c) { |
8655b6f8 WD |
351 | *d++ = (bits & 0x80) ? |
352 | lcd_color_fg : lcd_color_bg; | |
353 | bits <<= 1; | |
354 | } | |
355 | #elif LCD_BPP == LCD_COLOR16 | |
8f47d917 | 356 | for (c = 0; c < 8; ++c) { |
8655b6f8 WD |
357 | *d++ = (bits & 0x80) ? |
358 | lcd_color_fg : lcd_color_bg; | |
359 | bits <<= 1; | |
360 | } | |
57d76a89 HP |
361 | #elif LCD_BPP == LCD_COLOR32 |
362 | for (c = 0; c < 8; ++c) { | |
363 | *d++ = (bits & 0x80) ? | |
364 | lcd_color_fg : lcd_color_bg; | |
365 | bits <<= 1; | |
366 | } | |
8655b6f8 WD |
367 | #endif |
368 | } | |
369 | #if LCD_BPP == LCD_MONOCHROME | |
6b035141 | 370 | *d = rest | (*d & ((1 << (8 - off)) - 1)); |
8655b6f8 WD |
371 | #endif |
372 | } | |
373 | } | |
374 | ||
8f47d917 | 375 | static inline void lcd_putc_xy(ushort x, ushort y, uchar c) |
8655b6f8 | 376 | { |
0f999c49 | 377 | lcd_drawchars(x, y, &c, 1); |
8655b6f8 WD |
378 | } |
379 | ||
380 | /************************************************************************/ | |
381 | /** Small utility to check that you got the colours right */ | |
382 | /************************************************************************/ | |
383 | #ifdef LCD_TEST_PATTERN | |
384 | ||
385 | #define N_BLK_VERT 2 | |
386 | #define N_BLK_HOR 3 | |
387 | ||
6b035141 | 388 | static int test_colors[N_BLK_HOR * N_BLK_VERT] = { |
8655b6f8 WD |
389 | CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, |
390 | CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, | |
391 | }; | |
392 | ||
8f47d917 | 393 | static void test_pattern(void) |
8655b6f8 WD |
394 | { |
395 | ushort v_max = panel_info.vl_row; | |
396 | ushort h_max = panel_info.vl_col; | |
397 | ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; | |
398 | ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; | |
399 | ushort v, h; | |
400 | uchar *pix = (uchar *)lcd_base; | |
401 | ||
8f47d917 | 402 | printf("[LCD] Test Pattern: %d x %d [%d x %d]\n", |
8655b6f8 WD |
403 | h_max, v_max, h_step, v_step); |
404 | ||
405 | /* WARNING: Code silently assumes 8bit/pixel */ | |
8f47d917 | 406 | for (v = 0; v < v_max; ++v) { |
8655b6f8 | 407 | uchar iy = v / v_step; |
8f47d917 | 408 | for (h = 0; h < h_max; ++h) { |
6b035141 | 409 | uchar ix = N_BLK_HOR * iy + h / h_step; |
8655b6f8 WD |
410 | *pix++ = test_colors[ix]; |
411 | } | |
412 | } | |
413 | } | |
414 | #endif /* LCD_TEST_PATTERN */ | |
415 | ||
416 | ||
417 | /************************************************************************/ | |
418 | /* ** GENERIC Initialization Routines */ | |
419 | /************************************************************************/ | |
cefa4717 AG |
420 | /* |
421 | * With most lcd drivers the line length is set up | |
422 | * by calculating it from panel_info parameters. Some | |
423 | * drivers need to calculate the line length differently, | |
424 | * so make the function weak to allow overriding it. | |
425 | */ | |
426 | __weak int lcd_get_size(int *line_length) | |
676d319e SG |
427 | { |
428 | *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; | |
429 | return *line_length * panel_info.vl_row; | |
430 | } | |
431 | ||
6b035141 | 432 | int drv_lcd_init(void) |
8655b6f8 | 433 | { |
52cb4d4f | 434 | struct stdio_dev lcddev; |
8655b6f8 WD |
435 | int rc; |
436 | ||
7d95f2a3 | 437 | lcd_base = map_sysmem(gd->fb_base, 0); |
8655b6f8 | 438 | |
8f47d917 | 439 | lcd_init(lcd_base); /* LCD initialization */ |
8655b6f8 WD |
440 | |
441 | /* Device initialization */ | |
8f47d917 | 442 | memset(&lcddev, 0, sizeof(lcddev)); |
8655b6f8 | 443 | |
8f47d917 | 444 | strcpy(lcddev.name, "lcd"); |
8655b6f8 WD |
445 | lcddev.ext = 0; /* No extensions */ |
446 | lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ | |
709ea543 SG |
447 | lcddev.putc = lcd_stub_putc; /* 'putc' function */ |
448 | lcddev.puts = lcd_stub_puts; /* 'puts' function */ | |
8655b6f8 | 449 | |
6b035141 | 450 | rc = stdio_register(&lcddev); |
8655b6f8 WD |
451 | |
452 | return (rc == 0) ? 1 : rc; | |
453 | } | |
454 | ||
455 | /*----------------------------------------------------------------------*/ | |
02110903 | 456 | void lcd_clear(void) |
8655b6f8 WD |
457 | { |
458 | #if LCD_BPP == LCD_MONOCHROME | |
459 | /* Setting the palette */ | |
460 | lcd_initcolregs(); | |
461 | ||
462 | #elif LCD_BPP == LCD_COLOR8 | |
463 | /* Setting the palette */ | |
8f47d917 NK |
464 | lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); |
465 | lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); | |
466 | lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0); | |
467 | lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); | |
468 | lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF); | |
469 | lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); | |
470 | lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); | |
471 | lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); | |
472 | lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); | |
8655b6f8 WD |
473 | #endif |
474 | ||
6d0f6bcf | 475 | #ifndef CONFIG_SYS_WHITE_ON_BLACK |
8f47d917 NK |
476 | lcd_setfgcolor(CONSOLE_COLOR_BLACK); |
477 | lcd_setbgcolor(CONSOLE_COLOR_WHITE); | |
8655b6f8 | 478 | #else |
8f47d917 NK |
479 | lcd_setfgcolor(CONSOLE_COLOR_WHITE); |
480 | lcd_setbgcolor(CONSOLE_COLOR_BLACK); | |
6d0f6bcf | 481 | #endif /* CONFIG_SYS_WHITE_ON_BLACK */ |
8655b6f8 WD |
482 | |
483 | #ifdef LCD_TEST_PATTERN | |
484 | test_pattern(); | |
485 | #else | |
486 | /* set framebuffer to background color */ | |
57d76a89 | 487 | #if (LCD_BPP != LCD_COLOR32) |
8f47d917 | 488 | memset((char *)lcd_base, |
8d9eaafd | 489 | COLOR_MASK(lcd_color_bg), |
6b035141 | 490 | lcd_line_length * panel_info.vl_row); |
57d76a89 HP |
491 | #else |
492 | u32 *ppix = lcd_base; | |
493 | u32 i; | |
494 | for (i = 0; | |
495 | i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix); | |
496 | i++) { | |
497 | *ppix++ = COLOR_MASK(lcd_color_bg); | |
498 | } | |
499 | #endif | |
8655b6f8 WD |
500 | #endif |
501 | /* Paint the logo and retrieve LCD base address */ | |
8f47d917 | 502 | debug("[LCD] Drawing the logo...\n"); |
6b035141 | 503 | lcd_console_address = lcd_logo(); |
8655b6f8 WD |
504 | |
505 | console_col = 0; | |
506 | console_row = 0; | |
9a8efc46 SG |
507 | lcd_sync(); |
508 | } | |
509 | ||
510 | static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc, | |
511 | char *const argv[]) | |
512 | { | |
513 | lcd_clear(); | |
514 | return 0; | |
8655b6f8 WD |
515 | } |
516 | ||
517 | U_BOOT_CMD( | |
02110903 | 518 | cls, 1, 1, do_lcd_clear, |
2fb2604d | 519 | "clear screen", |
a89c33db | 520 | "" |
8655b6f8 WD |
521 | ); |
522 | ||
523 | /*----------------------------------------------------------------------*/ | |
524 | ||
8f47d917 | 525 | static int lcd_init(void *lcdbase) |
8655b6f8 WD |
526 | { |
527 | /* Initialize the lcd controller */ | |
8f47d917 | 528 | debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase); |
8655b6f8 | 529 | |
8f47d917 | 530 | lcd_ctrl_init(lcdbase); |
1d3dea12 AG |
531 | |
532 | /* | |
533 | * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores | |
534 | * the 'lcdbase' argument and uses custom lcd base address | |
535 | * by setting up gd->fb_base. Check for this condition and fixup | |
536 | * 'lcd_base' address. | |
537 | */ | |
7d95f2a3 SG |
538 | if (map_to_sysmem(lcdbase) != gd->fb_base) |
539 | lcd_base = map_sysmem(gd->fb_base, 0); | |
1d3dea12 AG |
540 | |
541 | debug("[LCD] Using LCD frambuffer at %p\n", lcd_base); | |
542 | ||
6d330719 | 543 | lcd_get_size(&lcd_line_length); |
6f93d2b8 | 544 | lcd_is_enabled = 1; |
02110903 | 545 | lcd_clear(); |
6b035141 | 546 | lcd_enable(); |
8655b6f8 WD |
547 | |
548 | /* Initialize the console */ | |
549 | console_col = 0; | |
88804d19 | 550 | #ifdef CONFIG_LCD_INFO_BELOW_LOGO |
8655b6f8 WD |
551 | console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; |
552 | #else | |
553 | console_row = 1; /* leave 1 blank line below logo */ | |
554 | #endif | |
8655b6f8 WD |
555 | |
556 | return 0; | |
557 | } | |
558 | ||
559 | ||
560 | /************************************************************************/ | |
561 | /* ** ROM capable initialization part - needed to reserve FB memory */ | |
562 | /************************************************************************/ | |
563 | /* | |
564 | * This is called early in the system initialization to grab memory | |
565 | * for the LCD controller. | |
566 | * Returns new address for monitor, after reserving LCD buffer memory | |
567 | * | |
568 | * Note that this is running from ROM, so no write access to global data. | |
569 | */ | |
8f47d917 | 570 | ulong lcd_setmem(ulong addr) |
8655b6f8 WD |
571 | { |
572 | ulong size; | |
676d319e | 573 | int line_length; |
8655b6f8 | 574 | |
8f47d917 NK |
575 | debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col, |
576 | panel_info.vl_row, NBITS(panel_info.vl_bpix)); | |
8655b6f8 | 577 | |
676d319e | 578 | size = lcd_get_size(&line_length); |
8655b6f8 | 579 | |
676d319e SG |
580 | /* Round up to nearest full page, or MMU section if defined */ |
581 | size = ALIGN(size, CONFIG_LCD_ALIGNMENT); | |
582 | addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT); | |
8655b6f8 WD |
583 | |
584 | /* Allocate pages for the frame buffer. */ | |
585 | addr -= size; | |
586 | ||
6b035141 JH |
587 | debug("Reserving %ldk for LCD Framebuffer at: %08lx\n", |
588 | size >> 10, addr); | |
8655b6f8 | 589 | |
8f47d917 | 590 | return addr; |
8655b6f8 WD |
591 | } |
592 | ||
593 | /*----------------------------------------------------------------------*/ | |
594 | ||
8f47d917 | 595 | static void lcd_setfgcolor(int color) |
8655b6f8 | 596 | { |
39cf4804 | 597 | lcd_color_fg = color; |
8655b6f8 WD |
598 | } |
599 | ||
600 | /*----------------------------------------------------------------------*/ | |
601 | ||
8f47d917 | 602 | static void lcd_setbgcolor(int color) |
8655b6f8 | 603 | { |
39cf4804 | 604 | lcd_color_bg = color; |
8655b6f8 WD |
605 | } |
606 | ||
8655b6f8 WD |
607 | /************************************************************************/ |
608 | /* ** Chipset depending Bitmap / Logo stuff... */ | |
609 | /************************************************************************/ | |
203c37b8 NK |
610 | static inline ushort *configuration_get_cmap(void) |
611 | { | |
612 | #if defined CONFIG_CPU_PXA | |
613 | struct pxafb_info *fbi = &panel_info.pxa; | |
614 | return (ushort *)fbi->palette; | |
615 | #elif defined(CONFIG_MPC823) | |
616 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; | |
617 | cpm8xx_t *cp = &(immr->im_cpm); | |
618 | return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]); | |
619 | #elif defined(CONFIG_ATMEL_LCD) | |
620 | return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0)); | |
d23019f3 AG |
621 | #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB) |
622 | return panel_info.cmap; | |
6b035141 | 623 | #elif defined(CONFIG_LCD_LOGO) |
d23019f3 AG |
624 | return bmp_logo_palette; |
625 | #else | |
626 | return NULL; | |
627 | #endif | |
203c37b8 NK |
628 | } |
629 | ||
8655b6f8 | 630 | #ifdef CONFIG_LCD_LOGO |
8f47d917 | 631 | void bitmap_plot(int x, int y) |
8655b6f8 | 632 | { |
39cf4804 | 633 | #ifdef CONFIG_ATMEL_LCD |
203c37b8 | 634 | uint *cmap = (uint *)bmp_logo_palette; |
39cf4804 | 635 | #else |
203c37b8 | 636 | ushort *cmap = (ushort *)bmp_logo_palette; |
39cf4804 | 637 | #endif |
8655b6f8 WD |
638 | ushort i, j; |
639 | uchar *bmap; | |
640 | uchar *fb; | |
641 | ushort *fb16; | |
203c37b8 NK |
642 | #if defined(CONFIG_MPC823) |
643 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; | |
644 | cpm8xx_t *cp = &(immr->im_cpm); | |
8655b6f8 | 645 | #endif |
317461c1 | 646 | unsigned bpix = NBITS(panel_info.vl_bpix); |
8655b6f8 | 647 | |
8f47d917 | 648 | debug("Logo: width %d height %d colors %d cmap %d\n", |
8655b6f8 | 649 | BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS, |
095407da | 650 | ARRAY_SIZE(bmp_logo_palette)); |
8655b6f8 WD |
651 | |
652 | bmap = &bmp_logo_bitmap[0]; | |
317461c1 | 653 | fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8); |
8655b6f8 | 654 | |
317461c1 | 655 | if (bpix < 12) { |
203c37b8 NK |
656 | /* Leave room for default color map |
657 | * default case: generic system with no cmap (most likely 16bpp) | |
658 | * cmap was set to the source palette, so no change is done. | |
659 | * This avoids even more ifdefs in the next stanza | |
660 | */ | |
661 | #if defined(CONFIG_MPC823) | |
8f47d917 | 662 | cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]); |
39cf4804 | 663 | #elif defined(CONFIG_ATMEL_LCD) |
203c37b8 | 664 | cmap = (uint *)configuration_get_cmap(); |
acb13868 | 665 | #else |
203c37b8 | 666 | cmap = configuration_get_cmap(); |
8655b6f8 WD |
667 | #endif |
668 | ||
669 | WATCHDOG_RESET(); | |
670 | ||
671 | /* Set color map */ | |
095407da | 672 | for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) { |
8655b6f8 | 673 | ushort colreg = bmp_logo_palette[i]; |
39cf4804 SP |
674 | #ifdef CONFIG_ATMEL_LCD |
675 | uint lut_entry; | |
676 | #ifdef CONFIG_ATMEL_LCD_BGR555 | |
677 | lut_entry = ((colreg & 0x000F) << 11) | | |
8f47d917 NK |
678 | ((colreg & 0x00F0) << 2) | |
679 | ((colreg & 0x0F00) >> 7); | |
39cf4804 SP |
680 | #else /* CONFIG_ATMEL_LCD_RGB565 */ |
681 | lut_entry = ((colreg & 0x000F) << 1) | | |
8f47d917 NK |
682 | ((colreg & 0x00F0) << 3) | |
683 | ((colreg & 0x0F00) << 4); | |
39cf4804 SP |
684 | #endif |
685 | *(cmap + BMP_LOGO_OFFSET) = lut_entry; | |
686 | cmap++; | |
687 | #else /* !CONFIG_ATMEL_LCD */ | |
6d0f6bcf | 688 | #ifdef CONFIG_SYS_INVERT_COLORS |
8655b6f8 WD |
689 | *cmap++ = 0xffff - colreg; |
690 | #else | |
691 | *cmap++ = colreg; | |
692 | #endif | |
39cf4804 | 693 | #endif /* CONFIG_ATMEL_LCD */ |
8655b6f8 WD |
694 | } |
695 | ||
696 | WATCHDOG_RESET(); | |
697 | ||
8f47d917 NK |
698 | for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { |
699 | memcpy(fb, bmap, BMP_LOGO_WIDTH); | |
8655b6f8 | 700 | bmap += BMP_LOGO_WIDTH; |
6b035141 | 701 | fb += panel_info.vl_col; |
8655b6f8 WD |
702 | } |
703 | } | |
704 | else { /* true color mode */ | |
acb13868 | 705 | u16 col16; |
317461c1 | 706 | fb16 = (ushort *)fb; |
8f47d917 NK |
707 | for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { |
708 | for (j = 0; j < BMP_LOGO_WIDTH; j++) { | |
acb13868 AR |
709 | col16 = bmp_logo_palette[(bmap[j]-16)]; |
710 | fb16[j] = | |
711 | ((col16 & 0x000F) << 1) | | |
712 | ((col16 & 0x00F0) << 3) | | |
713 | ((col16 & 0x0F00) << 4); | |
8655b6f8 WD |
714 | } |
715 | bmap += BMP_LOGO_WIDTH; | |
716 | fb16 += panel_info.vl_col; | |
717 | } | |
718 | } | |
719 | ||
720 | WATCHDOG_RESET(); | |
9a8efc46 | 721 | lcd_sync(); |
8655b6f8 | 722 | } |
2b5cb3d3 AG |
723 | #else |
724 | static inline void bitmap_plot(int x, int y) {} | |
8655b6f8 WD |
725 | #endif /* CONFIG_LCD_LOGO */ |
726 | ||
727 | /*----------------------------------------------------------------------*/ | |
c3517f91 | 728 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
8655b6f8 WD |
729 | /* |
730 | * Display the BMP file located at address bmp_image. | |
731 | * Only uncompressed. | |
732 | */ | |
1ca298ce MW |
733 | |
734 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN | |
735 | #define BMP_ALIGN_CENTER 0x7FFF | |
7c7e280a NK |
736 | |
737 | static void splash_align_axis(int *axis, unsigned long panel_size, | |
738 | unsigned long picture_size) | |
739 | { | |
740 | unsigned long panel_picture_delta = panel_size - picture_size; | |
741 | unsigned long axis_alignment; | |
742 | ||
743 | if (*axis == BMP_ALIGN_CENTER) | |
744 | axis_alignment = panel_picture_delta / 2; | |
745 | else if (*axis < 0) | |
746 | axis_alignment = panel_picture_delta + *axis + 1; | |
747 | else | |
748 | return; | |
749 | ||
750 | *axis = max(0, axis_alignment); | |
751 | } | |
1ca298ce MW |
752 | #endif |
753 | ||
45d7f525 TWHT |
754 | |
755 | #ifdef CONFIG_LCD_BMP_RLE8 | |
756 | ||
757 | #define BMP_RLE8_ESCAPE 0 | |
758 | #define BMP_RLE8_EOL 0 | |
759 | #define BMP_RLE8_EOBMP 1 | |
760 | #define BMP_RLE8_DELTA 2 | |
761 | ||
762 | static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap, | |
763 | int cnt) | |
764 | { | |
765 | while (cnt > 0) { | |
766 | *(*fbp)++ = cmap[*bmap++]; | |
767 | cnt--; | |
768 | } | |
769 | } | |
770 | ||
771 | static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt) | |
772 | { | |
773 | ushort *fb = *fbp; | |
774 | int cnt_8copy = cnt >> 3; | |
775 | ||
776 | cnt -= cnt_8copy << 3; | |
777 | while (cnt_8copy > 0) { | |
778 | *fb++ = c; | |
779 | *fb++ = c; | |
780 | *fb++ = c; | |
781 | *fb++ = c; | |
782 | *fb++ = c; | |
783 | *fb++ = c; | |
784 | *fb++ = c; | |
785 | *fb++ = c; | |
786 | cnt_8copy--; | |
787 | } | |
788 | while (cnt > 0) { | |
789 | *fb++ = c; | |
790 | cnt--; | |
791 | } | |
6b035141 | 792 | *fbp = fb; |
45d7f525 TWHT |
793 | } |
794 | ||
795 | /* | |
6b035141 | 796 | * Do not call this function directly, must be called from lcd_display_bitmap. |
45d7f525 TWHT |
797 | */ |
798 | static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb, | |
799 | int x_off, int y_off) | |
800 | { | |
801 | uchar *bmap; | |
802 | ulong width, height; | |
803 | ulong cnt, runlen; | |
804 | int x, y; | |
805 | int decode = 1; | |
806 | ||
dca2a1c1 PM |
807 | width = get_unaligned_le32(&bmp->header.width); |
808 | height = get_unaligned_le32(&bmp->header.height); | |
809 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); | |
45d7f525 TWHT |
810 | |
811 | x = 0; | |
812 | y = height - 1; | |
813 | ||
814 | while (decode) { | |
815 | if (bmap[0] == BMP_RLE8_ESCAPE) { | |
816 | switch (bmap[1]) { | |
817 | case BMP_RLE8_EOL: | |
818 | /* end of line */ | |
819 | bmap += 2; | |
820 | x = 0; | |
821 | y--; | |
822 | /* 16bpix, 2-byte per pixel, width should *2 */ | |
823 | fb -= (width * 2 + lcd_line_length); | |
824 | break; | |
825 | case BMP_RLE8_EOBMP: | |
826 | /* end of bitmap */ | |
827 | decode = 0; | |
828 | break; | |
829 | case BMP_RLE8_DELTA: | |
830 | /* delta run */ | |
831 | x += bmap[2]; | |
832 | y -= bmap[3]; | |
833 | /* 16bpix, 2-byte per pixel, x should *2 */ | |
834 | fb = (uchar *) (lcd_base + (y + y_off - 1) | |
835 | * lcd_line_length + (x + x_off) * 2); | |
836 | bmap += 4; | |
837 | break; | |
838 | default: | |
839 | /* unencoded run */ | |
840 | runlen = bmap[1]; | |
841 | bmap += 2; | |
842 | if (y < height) { | |
843 | if (x < width) { | |
844 | if (x + runlen > width) | |
845 | cnt = width - x; | |
846 | else | |
847 | cnt = runlen; | |
848 | draw_unencoded_bitmap( | |
849 | (ushort **)&fb, | |
850 | bmap, cmap, cnt); | |
851 | } | |
852 | x += runlen; | |
853 | } | |
854 | bmap += runlen; | |
855 | if (runlen & 1) | |
856 | bmap++; | |
857 | } | |
858 | } else { | |
859 | /* encoded run */ | |
860 | if (y < height) { | |
861 | runlen = bmap[0]; | |
862 | if (x < width) { | |
863 | /* aggregate the same code */ | |
864 | while (bmap[0] == 0xff && | |
865 | bmap[2] != BMP_RLE8_ESCAPE && | |
866 | bmap[1] == bmap[3]) { | |
867 | runlen += bmap[2]; | |
868 | bmap += 2; | |
869 | } | |
870 | if (x + runlen > width) | |
871 | cnt = width - x; | |
872 | else | |
873 | cnt = runlen; | |
874 | draw_encoded_bitmap((ushort **)&fb, | |
875 | cmap[bmap[1]], cnt); | |
876 | } | |
877 | x += runlen; | |
878 | } | |
879 | bmap += 2; | |
880 | } | |
881 | } | |
882 | } | |
883 | #endif | |
884 | ||
d23019f3 | 885 | #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200) |
bfdcc65e | 886 | #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++) |
d23019f3 AG |
887 | #else |
888 | #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++ | |
bfdcc65e NK |
889 | #endif |
890 | ||
891 | #if defined(CONFIG_BMP_16BPP) | |
892 | #if defined(CONFIG_ATMEL_LCD_BGR555) | |
893 | static inline void fb_put_word(uchar **fb, uchar **from) | |
894 | { | |
895 | *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03); | |
896 | *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2); | |
897 | *from += 2; | |
898 | } | |
899 | #else | |
900 | static inline void fb_put_word(uchar **fb, uchar **from) | |
901 | { | |
902 | *(*fb)++ = *(*from)++; | |
903 | *(*fb)++ = *(*from)++; | |
904 | } | |
905 | #endif | |
906 | #endif /* CONFIG_BMP_16BPP */ | |
907 | ||
8655b6f8 WD |
908 | int lcd_display_bitmap(ulong bmp_image, int x, int y) |
909 | { | |
00cc5595 AG |
910 | #if !defined(CONFIG_MCC200) |
911 | ushort *cmap = NULL; | |
912 | #endif | |
913 | ushort *cmap_base = NULL; | |
8655b6f8 WD |
914 | ushort i, j; |
915 | uchar *fb; | |
7d95f2a3 | 916 | bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0); |
8655b6f8 | 917 | uchar *bmap; |
fecac46c | 918 | ushort padded_width; |
b245e65e | 919 | unsigned long width, height, byte_width; |
e8143e72 | 920 | unsigned long pwidth = panel_info.vl_col; |
b245e65e | 921 | unsigned colors, bpix, bmp_bpix; |
8655b6f8 | 922 | |
6b035141 JH |
923 | if (!bmp || !(bmp->header.signature[0] == 'B' && |
924 | bmp->header.signature[1] == 'M')) { | |
8f47d917 NK |
925 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
926 | ||
8655b6f8 | 927 | return 1; |
b245e65e | 928 | } |
8655b6f8 | 929 | |
dca2a1c1 PM |
930 | width = get_unaligned_le32(&bmp->header.width); |
931 | height = get_unaligned_le32(&bmp->header.height); | |
932 | bmp_bpix = get_unaligned_le16(&bmp->header.bit_count); | |
933 | ||
b245e65e | 934 | colors = 1 << bmp_bpix; |
8655b6f8 WD |
935 | |
936 | bpix = NBITS(panel_info.vl_bpix); | |
937 | ||
6b035141 | 938 | if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
b245e65e GL |
939 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
940 | bpix, bmp_bpix); | |
8f47d917 | 941 | |
8655b6f8 WD |
942 | return 1; |
943 | } | |
944 | ||
b245e65e | 945 | /* We support displaying 8bpp BMPs on 16bpp LCDs */ |
dad631cc | 946 | if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) { |
8655b6f8 | 947 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
dca2a1c1 | 948 | bpix, get_unaligned_le16(&bmp->header.bit_count)); |
8655b6f8 WD |
949 | return 1; |
950 | } | |
951 | ||
8f47d917 | 952 | debug("Display-bmp: %d x %d with %d colors\n", |
8655b6f8 WD |
953 | (int)width, (int)height, (int)colors); |
954 | ||
f6414714 WD |
955 | #if !defined(CONFIG_MCC200) |
956 | /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */ | |
b245e65e | 957 | if (bmp_bpix == 8) { |
203c37b8 | 958 | cmap = configuration_get_cmap(); |
b245e65e GL |
959 | cmap_base = cmap; |
960 | ||
8655b6f8 | 961 | /* Set color map */ |
8f47d917 | 962 | for (i = 0; i < colors; ++i) { |
8655b6f8 | 963 | bmp_color_table_entry_t cte = bmp->color_table[i]; |
1464eff7 | 964 | #if !defined(CONFIG_ATMEL_LCD) |
8655b6f8 WD |
965 | ushort colreg = |
966 | ( ((cte.red) << 8) & 0xf800) | | |
59d80bf1 WD |
967 | ( ((cte.green) << 3) & 0x07e0) | |
968 | ( ((cte.blue) >> 3) & 0x001f) ; | |
6d0f6bcf | 969 | #ifdef CONFIG_SYS_INVERT_COLORS |
25d6712a | 970 | *cmap = 0xffff - colreg; |
8655b6f8 | 971 | #else |
25d6712a WD |
972 | *cmap = colreg; |
973 | #endif | |
b245e65e | 974 | #if defined(CONFIG_MPC823) |
25d6712a | 975 | cmap--; |
b245e65e GL |
976 | #else |
977 | cmap++; | |
1464eff7 MJ |
978 | #endif |
979 | #else /* CONFIG_ATMEL_LCD */ | |
980 | lcd_setcolreg(i, cte.red, cte.green, cte.blue); | |
8655b6f8 WD |
981 | #endif |
982 | } | |
983 | } | |
f6414714 | 984 | #endif |
e8143e72 WD |
985 | /* |
986 | * BMP format for Monochrome assumes that the state of a | |
987 | * pixel is described on a per Bit basis, not per Byte. | |
988 | * So, in case of Monochrome BMP we should align widths | |
989 | * on a byte boundary and convert them from Bit to Byte | |
990 | * units. | |
511d0c72 WD |
991 | * Probably, PXA250 and MPC823 process 1bpp BMP images in |
992 | * their own ways, so make the converting to be MCC200 | |
e8143e72 WD |
993 | * specific. |
994 | */ | |
995 | #if defined(CONFIG_MCC200) | |
8f47d917 | 996 | if (bpix == 1) { |
e8143e72 WD |
997 | width = ((width + 7) & ~7) >> 3; |
998 | x = ((x + 7) & ~7) >> 3; | |
999 | pwidth= ((pwidth + 7) & ~7) >> 3; | |
1000 | } | |
1001 | #endif | |
1002 | ||
6b035141 | 1003 | padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
1ca298ce MW |
1004 | |
1005 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN | |
7c7e280a NK |
1006 | splash_align_axis(&x, pwidth, width); |
1007 | splash_align_axis(&y, panel_info.vl_row, height); | |
1ca298ce MW |
1008 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
1009 | ||
8f47d917 | 1010 | if ((x + width) > pwidth) |
e8143e72 | 1011 | width = pwidth - x; |
8f47d917 | 1012 | if ((y + height) > panel_info.vl_row) |
8655b6f8 WD |
1013 | height = panel_info.vl_row - y; |
1014 | ||
dca2a1c1 PM |
1015 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
1016 | fb = (uchar *)(lcd_base + | |
8d46d5b1 | 1017 | (y + height - 1) * lcd_line_length + x * bpix / 8); |
a303dfb0 | 1018 | |
b245e65e | 1019 | switch (bmp_bpix) { |
a303dfb0 MJ |
1020 | case 1: /* pass through */ |
1021 | case 8: | |
45d7f525 | 1022 | #ifdef CONFIG_LCD_BMP_RLE8 |
dca2a1c1 PM |
1023 | u32 compression = get_unaligned_le32(&bmp->header.compression); |
1024 | if (compression == BMP_BI_RLE8) { | |
45d7f525 TWHT |
1025 | if (bpix != 16) { |
1026 | /* TODO implement render code for bpix != 16 */ | |
1027 | printf("Error: only support 16 bpix"); | |
1028 | return 1; | |
1029 | } | |
1030 | lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y); | |
1031 | break; | |
1032 | } | |
1033 | #endif | |
1034 | ||
b245e65e GL |
1035 | if (bpix != 16) |
1036 | byte_width = width; | |
1037 | else | |
1038 | byte_width = width * 2; | |
1039 | ||
a303dfb0 MJ |
1040 | for (i = 0; i < height; ++i) { |
1041 | WATCHDOG_RESET(); | |
b245e65e GL |
1042 | for (j = 0; j < width; j++) { |
1043 | if (bpix != 16) { | |
bfdcc65e | 1044 | FB_PUT_BYTE(fb, bmap); |
b245e65e GL |
1045 | } else { |
1046 | *(uint16_t *)fb = cmap_base[*(bmap++)]; | |
1047 | fb += sizeof(uint16_t) / sizeof(*fb); | |
1048 | } | |
1049 | } | |
fecac46c | 1050 | bmap += (padded_width - width); |
6b035141 | 1051 | fb -= byte_width + lcd_line_length; |
a303dfb0 MJ |
1052 | } |
1053 | break; | |
1054 | ||
1055 | #if defined(CONFIG_BMP_16BPP) | |
1056 | case 16: | |
1057 | for (i = 0; i < height; ++i) { | |
1058 | WATCHDOG_RESET(); | |
bfdcc65e NK |
1059 | for (j = 0; j < width; j++) |
1060 | fb_put_word(&fb, &bmap); | |
1061 | ||
fecac46c | 1062 | bmap += (padded_width - width) * 2; |
6b035141 | 1063 | fb -= width * 2 + lcd_line_length; |
a303dfb0 MJ |
1064 | } |
1065 | break; | |
1066 | #endif /* CONFIG_BMP_16BPP */ | |
1067 | ||
fb6a9aab DL |
1068 | #if defined(CONFIG_BMP_32BPP) |
1069 | case 32: | |
1070 | for (i = 0; i < height; ++i) { | |
1071 | for (j = 0; j < width; j++) { | |
1072 | *(fb++) = *(bmap++); | |
1073 | *(fb++) = *(bmap++); | |
1074 | *(fb++) = *(bmap++); | |
1075 | *(fb++) = *(bmap++); | |
1076 | } | |
6b035141 | 1077 | fb -= lcd_line_length + width * (bpix / 8); |
fb6a9aab DL |
1078 | } |
1079 | break; | |
1080 | #endif /* CONFIG_BMP_32BPP */ | |
a303dfb0 MJ |
1081 | default: |
1082 | break; | |
1083 | }; | |
8655b6f8 | 1084 | |
9a8efc46 | 1085 | lcd_sync(); |
8f47d917 | 1086 | return 0; |
8655b6f8 | 1087 | } |
c3517f91 | 1088 | #endif |
8655b6f8 | 1089 | |
8f47d917 | 1090 | static void *lcd_logo(void) |
8655b6f8 | 1091 | { |
8655b6f8 WD |
1092 | #ifdef CONFIG_SPLASH_SCREEN |
1093 | char *s; | |
1094 | ulong addr; | |
1095 | static int do_splash = 1; | |
1096 | ||
1097 | if (do_splash && (s = getenv("splashimage")) != NULL) { | |
1ca298ce | 1098 | int x = 0, y = 0; |
8655b6f8 WD |
1099 | do_splash = 0; |
1100 | ||
581bb419 | 1101 | if (splash_screen_prepare()) |
dd4425e8 | 1102 | return (void *)lcd_base; |
581bb419 | 1103 | |
1ca298ce | 1104 | addr = simple_strtoul (s, NULL, 16); |
ff8fb56b AG |
1105 | |
1106 | splash_get_pos(&x, &y); | |
1ca298ce | 1107 | |
d3a555ed | 1108 | if (bmp_display(addr, x, y) == 0) |
8f47d917 | 1109 | return (void *)lcd_base; |
8655b6f8 WD |
1110 | } |
1111 | #endif /* CONFIG_SPLASH_SCREEN */ | |
1112 | ||
2b5cb3d3 | 1113 | bitmap_plot(0, 0); |
8655b6f8 | 1114 | |
6b59e03e HS |
1115 | #ifdef CONFIG_LCD_INFO |
1116 | console_col = LCD_INFO_X / VIDEO_FONT_WIDTH; | |
1117 | console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; | |
1118 | lcd_show_board_info(); | |
1119 | #endif /* CONFIG_LCD_INFO */ | |
39cf4804 | 1120 | |
88804d19 | 1121 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
8f47d917 | 1122 | return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length); |
8655b6f8 | 1123 | #else |
8f47d917 | 1124 | return (void *)lcd_base; |
6b035141 | 1125 | #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */ |
8655b6f8 WD |
1126 | } |
1127 | ||
c0880485 NK |
1128 | #ifdef CONFIG_SPLASHIMAGE_GUARD |
1129 | static int on_splashimage(const char *name, const char *value, enum env_op op, | |
1130 | int flags) | |
1131 | { | |
1132 | ulong addr; | |
1133 | int aligned; | |
1134 | ||
1135 | if (op == env_op_delete) | |
1136 | return 0; | |
1137 | ||
1138 | addr = simple_strtoul(value, NULL, 16); | |
1139 | /* See README.displaying-bmps */ | |
1140 | aligned = (addr % 4 == 2); | |
1141 | if (!aligned) { | |
1142 | printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n"); | |
1143 | return -1; | |
1144 | } | |
1145 | ||
1146 | return 0; | |
1147 | } | |
1148 | ||
1149 | U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); | |
1150 | #endif | |
1151 | ||
395166cf VB |
1152 | void lcd_position_cursor(unsigned col, unsigned row) |
1153 | { | |
1154 | console_col = min(col, CONSOLE_COLS - 1); | |
1155 | console_row = min(row, CONSOLE_ROWS - 1); | |
1156 | } | |
1157 | ||
1158 | int lcd_get_pixel_width(void) | |
1159 | { | |
1160 | return panel_info.vl_col; | |
1161 | } | |
1162 | ||
1163 | int lcd_get_pixel_height(void) | |
1164 | { | |
1165 | return panel_info.vl_row; | |
1166 | } | |
1167 | ||
1168 | int lcd_get_screen_rows(void) | |
1169 | { | |
1170 | return CONSOLE_ROWS; | |
1171 | } | |
1172 | ||
1173 | int lcd_get_screen_columns(void) | |
1174 | { | |
1175 | return CONSOLE_COLS; | |
1176 | } | |
6a195d2d SW |
1177 | |
1178 | #if defined(CONFIG_LCD_DT_SIMPLEFB) | |
1179 | static int lcd_dt_simplefb_configure_node(void *blob, int off) | |
1180 | { | |
1181 | u32 stride; | |
1182 | fdt32_t cells[2]; | |
1183 | int ret; | |
5af7d0f0 | 1184 | static const char format[] = |
6a195d2d SW |
1185 | #if LCD_BPP == LCD_COLOR16 |
1186 | "r5g6b5"; | |
1187 | #else | |
1188 | ""; | |
1189 | #endif | |
1190 | ||
1191 | if (!format[0]) | |
1192 | return -1; | |
1193 | ||
1194 | stride = panel_info.vl_col * 2; | |
1195 | ||
1196 | cells[0] = cpu_to_fdt32(gd->fb_base); | |
1197 | cells[1] = cpu_to_fdt32(stride * panel_info.vl_row); | |
1198 | ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2); | |
1199 | if (ret < 0) | |
1200 | return -1; | |
1201 | ||
1202 | cells[0] = cpu_to_fdt32(panel_info.vl_col); | |
1203 | ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0])); | |
1204 | if (ret < 0) | |
1205 | return -1; | |
1206 | ||
1207 | cells[0] = cpu_to_fdt32(panel_info.vl_row); | |
1208 | ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0])); | |
1209 | if (ret < 0) | |
1210 | return -1; | |
1211 | ||
1212 | cells[0] = cpu_to_fdt32(stride); | |
1213 | ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0])); | |
1214 | if (ret < 0) | |
1215 | return -1; | |
1216 | ||
1217 | ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1); | |
1218 | if (ret < 0) | |
1219 | return -1; | |
1220 | ||
1221 | ret = fdt_delprop(blob, off, "status"); | |
1222 | if (ret < 0) | |
1223 | return -1; | |
1224 | ||
1225 | return 0; | |
1226 | } | |
1227 | ||
1228 | int lcd_dt_simplefb_add_node(void *blob) | |
1229 | { | |
5af7d0f0 SW |
1230 | static const char compat[] = "simple-framebuffer"; |
1231 | static const char disabled[] = "disabled"; | |
6a195d2d SW |
1232 | int off, ret; |
1233 | ||
1234 | off = fdt_add_subnode(blob, 0, "framebuffer"); | |
1235 | if (off < 0) | |
1236 | return -1; | |
1237 | ||
1238 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); | |
1239 | if (ret < 0) | |
1240 | return -1; | |
1241 | ||
1242 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); | |
1243 | if (ret < 0) | |
1244 | return -1; | |
1245 | ||
1246 | return lcd_dt_simplefb_configure_node(blob, off); | |
1247 | } | |
1248 | ||
1249 | int lcd_dt_simplefb_enable_existing_node(void *blob) | |
1250 | { | |
1251 | int off; | |
1252 | ||
1253 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); | |
1254 | if (off < 0) | |
1255 | return -1; | |
1256 | ||
1257 | return lcd_dt_simplefb_configure_node(blob, off); | |
1258 | } | |
1259 | #endif |