wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Common LCD routines for supported CPUs |
| 3 | * |
| 4 | * (C) Copyright 2001-2002 |
| 5 | * Wolfgang Denk, DENX Software Engineering -- wd@denx.de |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | /************************************************************************/ |
| 27 | /* ** HEADER FILES */ |
| 28 | /************************************************************************/ |
| 29 | |
| 30 | /* #define DEBUG */ |
| 31 | |
| 32 | #include <config.h> |
| 33 | #include <common.h> |
| 34 | #include <command.h> |
| 35 | #include <version.h> |
| 36 | #include <stdarg.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <devices.h> |
| 39 | #if defined(CONFIG_POST) |
| 40 | #include <post.h> |
| 41 | #endif |
| 42 | #include <lcd.h> |
wdenk | bc3202a | 2005-04-03 23:11:38 +0000 | [diff] [blame] | 43 | #include <watchdog.h> |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 44 | |
| 45 | #if defined(CONFIG_PXA250) |
| 46 | #include <asm/byteorder.h> |
| 47 | #endif |
| 48 | |
| 49 | #if defined(CONFIG_MPC823) |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 50 | #include <lcdvideo.h> |
| 51 | #endif |
| 52 | |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_LCD |
| 54 | |
| 55 | /************************************************************************/ |
| 56 | /* ** FONT DATA */ |
| 57 | /************************************************************************/ |
| 58 | #include <video_font.h> /* Get font data, width and height */ |
| 59 | |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 60 | /************************************************************************/ |
| 61 | /* ** LOGO DATA */ |
| 62 | /************************************************************************/ |
| 63 | #ifdef CONFIG_LCD_LOGO |
| 64 | # include <bmp_logo.h> /* Get logo data, width and height */ |
| 65 | # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) |
| 66 | # error Default Color Map overlaps with Logo Color Map |
| 67 | # endif |
| 68 | #endif |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 69 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 70 | DECLARE_GLOBAL_DATA_PTR; |
| 71 | |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 72 | ulong lcd_setmem (ulong addr); |
| 73 | |
| 74 | static void lcd_drawchars (ushort x, ushort y, uchar *str, int count); |
| 75 | static inline void lcd_puts_xy (ushort x, ushort y, uchar *s); |
| 76 | static inline void lcd_putc_xy (ushort x, ushort y, uchar c); |
| 77 | |
| 78 | static int lcd_init (void *lcdbase); |
| 79 | |
| 80 | static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]); |
| 81 | extern void lcd_ctrl_init (void *lcdbase); |
| 82 | extern void lcd_enable (void); |
| 83 | static void *lcd_logo (void); |
| 84 | |
| 85 | |
| 86 | #if LCD_BPP == LCD_COLOR8 |
| 87 | extern void lcd_setcolreg (ushort regno, |
| 88 | ushort red, ushort green, ushort blue); |
| 89 | #endif |
| 90 | #if LCD_BPP == LCD_MONOCHROME |
| 91 | extern void lcd_initcolregs (void); |
| 92 | #endif |
| 93 | |
| 94 | static int lcd_getbgcolor (void); |
| 95 | static void lcd_setfgcolor (int color); |
| 96 | static void lcd_setbgcolor (int color); |
| 97 | |
| 98 | char lcd_is_enabled = 0; |
| 99 | extern vidinfo_t panel_info; |
| 100 | |
| 101 | #ifdef NOT_USED_SO_FAR |
| 102 | static void lcd_getcolreg (ushort regno, |
| 103 | ushort *red, ushort *green, ushort *blue); |
| 104 | static int lcd_getfgcolor (void); |
| 105 | #endif /* NOT_USED_SO_FAR */ |
| 106 | |
| 107 | /************************************************************************/ |
| 108 | |
| 109 | /*----------------------------------------------------------------------*/ |
| 110 | |
| 111 | static void console_scrollup (void) |
| 112 | { |
| 113 | #if 1 |
| 114 | /* Copy up rows ignoring the first one */ |
| 115 | memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE); |
| 116 | |
| 117 | /* Clear the last one */ |
| 118 | memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE); |
| 119 | #else |
| 120 | /* |
| 121 | * Poor attempt to optimize speed by moving "long"s. |
| 122 | * But the code is ugly, and not a bit faster :-( |
| 123 | */ |
| 124 | ulong *t = (ulong *)CONSOLE_ROW_FIRST; |
| 125 | ulong *s = (ulong *)CONSOLE_ROW_SECOND; |
| 126 | ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong); |
| 127 | uchar c = lcd_color_bg & 0xFF; |
| 128 | ulong val= (c<<24) | (c<<16) | (c<<8) | c; |
| 129 | |
| 130 | while (l--) |
| 131 | *t++ = *s++; |
| 132 | |
| 133 | t = (ulong *)CONSOLE_ROW_LAST; |
| 134 | l = CONSOLE_ROW_SIZE / sizeof(ulong); |
| 135 | |
| 136 | while (l-- > 0) |
| 137 | *t++ = val; |
| 138 | #endif |
| 139 | } |
| 140 | |
| 141 | /*----------------------------------------------------------------------*/ |
| 142 | |
| 143 | static inline void console_back (void) |
| 144 | { |
| 145 | if (--console_col < 0) { |
| 146 | console_col = CONSOLE_COLS-1 ; |
| 147 | if (--console_row < 0) { |
| 148 | console_row = 0; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | lcd_putc_xy (console_col * VIDEO_FONT_WIDTH, |
| 153 | console_row * VIDEO_FONT_HEIGHT, |
| 154 | ' '); |
| 155 | } |
| 156 | |
| 157 | /*----------------------------------------------------------------------*/ |
| 158 | |
| 159 | static inline void console_newline (void) |
| 160 | { |
| 161 | ++console_row; |
| 162 | console_col = 0; |
| 163 | |
| 164 | /* Check if we need to scroll the terminal */ |
| 165 | if (console_row >= CONSOLE_ROWS) { |
| 166 | /* Scroll everything up */ |
| 167 | console_scrollup () ; |
| 168 | --console_row; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /*----------------------------------------------------------------------*/ |
| 173 | |
| 174 | void lcd_putc (const char c) |
| 175 | { |
| 176 | if (!lcd_is_enabled) { |
| 177 | serial_putc(c); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | switch (c) { |
| 182 | case '\r': console_col = 0; |
| 183 | return; |
| 184 | |
| 185 | case '\n': console_newline(); |
| 186 | return; |
| 187 | |
| 188 | case '\t': /* Tab (8 chars alignment) */ |
| 189 | console_col |= 8; |
| 190 | console_col &= ~7; |
| 191 | |
| 192 | if (console_col >= CONSOLE_COLS) { |
| 193 | console_newline(); |
| 194 | } |
| 195 | return; |
| 196 | |
| 197 | case '\b': console_back(); |
| 198 | return; |
| 199 | |
| 200 | default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH, |
| 201 | console_row * VIDEO_FONT_HEIGHT, |
| 202 | c); |
| 203 | if (++console_col >= CONSOLE_COLS) { |
| 204 | console_newline(); |
| 205 | } |
| 206 | return; |
| 207 | } |
| 208 | /* NOTREACHED */ |
| 209 | } |
| 210 | |
| 211 | /*----------------------------------------------------------------------*/ |
| 212 | |
| 213 | void lcd_puts (const char *s) |
| 214 | { |
| 215 | if (!lcd_is_enabled) { |
| 216 | serial_puts (s); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | while (*s) { |
| 221 | lcd_putc (*s++); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /************************************************************************/ |
| 226 | /* ** Low-Level Graphics Routines */ |
| 227 | /************************************************************************/ |
| 228 | |
| 229 | static void lcd_drawchars (ushort x, ushort y, uchar *str, int count) |
| 230 | { |
| 231 | uchar *dest; |
| 232 | ushort off, row; |
| 233 | |
| 234 | dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8); |
| 235 | off = x * (1 << LCD_BPP) % 8; |
| 236 | |
| 237 | for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { |
| 238 | uchar *s = str; |
| 239 | uchar *d = dest; |
| 240 | int i; |
| 241 | |
| 242 | #if LCD_BPP == LCD_MONOCHROME |
| 243 | uchar rest = *d & -(1 << (8-off)); |
| 244 | uchar sym; |
| 245 | #endif |
| 246 | for (i=0; i<count; ++i) { |
| 247 | uchar c, bits; |
| 248 | |
| 249 | c = *s++; |
| 250 | bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; |
| 251 | |
| 252 | #if LCD_BPP == LCD_MONOCHROME |
| 253 | sym = (COLOR_MASK(lcd_color_fg) & bits) | |
| 254 | (COLOR_MASK(lcd_color_bg) & ~bits); |
| 255 | |
| 256 | *d++ = rest | (sym >> off); |
| 257 | rest = sym << (8-off); |
| 258 | #elif LCD_BPP == LCD_COLOR8 |
| 259 | for (c=0; c<8; ++c) { |
| 260 | *d++ = (bits & 0x80) ? |
| 261 | lcd_color_fg : lcd_color_bg; |
| 262 | bits <<= 1; |
| 263 | } |
| 264 | #elif LCD_BPP == LCD_COLOR16 |
| 265 | for (c=0; c<16; ++c) { |
| 266 | *d++ = (bits & 0x80) ? |
| 267 | lcd_color_fg : lcd_color_bg; |
| 268 | bits <<= 1; |
| 269 | } |
| 270 | #endif |
| 271 | } |
| 272 | #if LCD_BPP == LCD_MONOCHROME |
| 273 | *d = rest | (*d & ((1 << (8-off)) - 1)); |
| 274 | #endif |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /*----------------------------------------------------------------------*/ |
| 279 | |
| 280 | static inline void lcd_puts_xy (ushort x, ushort y, uchar *s) |
| 281 | { |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 282 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 283 | lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen ((char *)s)); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 284 | #else |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 285 | lcd_drawchars (x, y, s, strlen ((char *)s)); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 286 | #endif |
| 287 | } |
| 288 | |
| 289 | /*----------------------------------------------------------------------*/ |
| 290 | |
| 291 | static inline void lcd_putc_xy (ushort x, ushort y, uchar c) |
| 292 | { |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 293 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 294 | lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1); |
| 295 | #else |
| 296 | lcd_drawchars (x, y, &c, 1); |
| 297 | #endif |
| 298 | } |
| 299 | |
| 300 | /************************************************************************/ |
| 301 | /** Small utility to check that you got the colours right */ |
| 302 | /************************************************************************/ |
| 303 | #ifdef LCD_TEST_PATTERN |
| 304 | |
| 305 | #define N_BLK_VERT 2 |
| 306 | #define N_BLK_HOR 3 |
| 307 | |
| 308 | static int test_colors[N_BLK_HOR*N_BLK_VERT] = { |
| 309 | CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, |
| 310 | CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, |
| 311 | }; |
| 312 | |
| 313 | static void test_pattern (void) |
| 314 | { |
| 315 | ushort v_max = panel_info.vl_row; |
| 316 | ushort h_max = panel_info.vl_col; |
| 317 | ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; |
| 318 | ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; |
| 319 | ushort v, h; |
| 320 | uchar *pix = (uchar *)lcd_base; |
| 321 | |
| 322 | printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n", |
| 323 | h_max, v_max, h_step, v_step); |
| 324 | |
| 325 | /* WARNING: Code silently assumes 8bit/pixel */ |
| 326 | for (v=0; v<v_max; ++v) { |
| 327 | uchar iy = v / v_step; |
| 328 | for (h=0; h<h_max; ++h) { |
| 329 | uchar ix = N_BLK_HOR * iy + (h/h_step); |
| 330 | *pix++ = test_colors[ix]; |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | #endif /* LCD_TEST_PATTERN */ |
| 335 | |
| 336 | |
| 337 | /************************************************************************/ |
| 338 | /* ** GENERIC Initialization Routines */ |
| 339 | /************************************************************************/ |
| 340 | |
| 341 | int drv_lcd_init (void) |
| 342 | { |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 343 | device_t lcddev; |
| 344 | int rc; |
| 345 | |
| 346 | lcd_base = (void *)(gd->fb_base); |
| 347 | |
| 348 | lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8; |
| 349 | |
| 350 | lcd_init (lcd_base); /* LCD initialization */ |
| 351 | |
| 352 | /* Device initialization */ |
| 353 | memset (&lcddev, 0, sizeof (lcddev)); |
| 354 | |
| 355 | strcpy (lcddev.name, "lcd"); |
| 356 | lcddev.ext = 0; /* No extensions */ |
| 357 | lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
| 358 | lcddev.putc = lcd_putc; /* 'putc' function */ |
| 359 | lcddev.puts = lcd_puts; /* 'puts' function */ |
| 360 | |
| 361 | rc = device_register (&lcddev); |
| 362 | |
| 363 | return (rc == 0) ? 1 : rc; |
| 364 | } |
| 365 | |
| 366 | /*----------------------------------------------------------------------*/ |
| 367 | static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 368 | { |
| 369 | #if LCD_BPP == LCD_MONOCHROME |
| 370 | /* Setting the palette */ |
| 371 | lcd_initcolregs(); |
| 372 | |
| 373 | #elif LCD_BPP == LCD_COLOR8 |
| 374 | /* Setting the palette */ |
| 375 | lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0); |
| 376 | lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0); |
| 377 | lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0); |
| 378 | lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); |
| 379 | lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF); |
| 380 | lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); |
| 381 | lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); |
| 382 | lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); |
| 383 | lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); |
| 384 | #endif |
| 385 | |
| 386 | #ifndef CFG_WHITE_ON_BLACK |
| 387 | lcd_setfgcolor (CONSOLE_COLOR_BLACK); |
| 388 | lcd_setbgcolor (CONSOLE_COLOR_WHITE); |
| 389 | #else |
| 390 | lcd_setfgcolor (CONSOLE_COLOR_WHITE); |
| 391 | lcd_setbgcolor (CONSOLE_COLOR_BLACK); |
| 392 | #endif /* CFG_WHITE_ON_BLACK */ |
| 393 | |
| 394 | #ifdef LCD_TEST_PATTERN |
| 395 | test_pattern(); |
| 396 | #else |
| 397 | /* set framebuffer to background color */ |
| 398 | memset ((char *)lcd_base, |
| 399 | COLOR_MASK(lcd_getbgcolor()), |
| 400 | lcd_line_length*panel_info.vl_row); |
| 401 | #endif |
| 402 | /* Paint the logo and retrieve LCD base address */ |
| 403 | debug ("[LCD] Drawing the logo...\n"); |
| 404 | lcd_console_address = lcd_logo (); |
| 405 | |
| 406 | console_col = 0; |
| 407 | console_row = 0; |
| 408 | |
| 409 | return (0); |
| 410 | } |
| 411 | |
| 412 | U_BOOT_CMD( |
| 413 | cls, 1, 1, lcd_clear, |
| 414 | "cls - clear screen\n", |
| 415 | NULL |
| 416 | ); |
| 417 | |
| 418 | /*----------------------------------------------------------------------*/ |
| 419 | |
| 420 | static int lcd_init (void *lcdbase) |
| 421 | { |
| 422 | /* Initialize the lcd controller */ |
| 423 | debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase); |
| 424 | |
| 425 | lcd_ctrl_init (lcdbase); |
| 426 | lcd_clear (NULL, 1, 1, NULL); /* dummy args */ |
| 427 | lcd_enable (); |
| 428 | |
| 429 | /* Initialize the console */ |
| 430 | console_col = 0; |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 431 | #ifdef CONFIG_LCD_INFO_BELOW_LOGO |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 432 | console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; |
| 433 | #else |
| 434 | console_row = 1; /* leave 1 blank line below logo */ |
| 435 | #endif |
| 436 | lcd_is_enabled = 1; |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | |
| 442 | /************************************************************************/ |
| 443 | /* ** ROM capable initialization part - needed to reserve FB memory */ |
| 444 | /************************************************************************/ |
| 445 | /* |
| 446 | * This is called early in the system initialization to grab memory |
| 447 | * for the LCD controller. |
| 448 | * Returns new address for monitor, after reserving LCD buffer memory |
| 449 | * |
| 450 | * Note that this is running from ROM, so no write access to global data. |
| 451 | */ |
| 452 | ulong lcd_setmem (ulong addr) |
| 453 | { |
| 454 | ulong size; |
| 455 | int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8; |
| 456 | |
| 457 | debug ("LCD panel info: %d x %d, %d bit/pix\n", |
| 458 | panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) ); |
| 459 | |
| 460 | size = line_length * panel_info.vl_row; |
| 461 | |
| 462 | /* Round up to nearest full page */ |
| 463 | size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 464 | |
| 465 | /* Allocate pages for the frame buffer. */ |
| 466 | addr -= size; |
| 467 | |
| 468 | debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr); |
| 469 | |
| 470 | return (addr); |
| 471 | } |
| 472 | |
| 473 | /*----------------------------------------------------------------------*/ |
| 474 | |
| 475 | static void lcd_setfgcolor (int color) |
| 476 | { |
| 477 | lcd_color_fg = color & 0x0F; |
| 478 | } |
| 479 | |
| 480 | /*----------------------------------------------------------------------*/ |
| 481 | |
| 482 | static void lcd_setbgcolor (int color) |
| 483 | { |
| 484 | lcd_color_bg = color & 0x0F; |
| 485 | } |
| 486 | |
| 487 | /*----------------------------------------------------------------------*/ |
| 488 | |
| 489 | #ifdef NOT_USED_SO_FAR |
| 490 | static int lcd_getfgcolor (void) |
| 491 | { |
| 492 | return lcd_color_fg; |
| 493 | } |
| 494 | #endif /* NOT_USED_SO_FAR */ |
| 495 | |
| 496 | /*----------------------------------------------------------------------*/ |
| 497 | |
| 498 | static int lcd_getbgcolor (void) |
| 499 | { |
| 500 | return lcd_color_bg; |
| 501 | } |
| 502 | |
| 503 | /*----------------------------------------------------------------------*/ |
| 504 | |
| 505 | /************************************************************************/ |
| 506 | /* ** Chipset depending Bitmap / Logo stuff... */ |
| 507 | /************************************************************************/ |
| 508 | #ifdef CONFIG_LCD_LOGO |
| 509 | void bitmap_plot (int x, int y) |
| 510 | { |
| 511 | ushort *cmap; |
| 512 | ushort i, j; |
| 513 | uchar *bmap; |
| 514 | uchar *fb; |
| 515 | ushort *fb16; |
| 516 | #if defined(CONFIG_PXA250) |
| 517 | struct pxafb_info *fbi = &panel_info.pxa; |
| 518 | #elif defined(CONFIG_MPC823) |
| 519 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 520 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 521 | #endif |
| 522 | |
| 523 | debug ("Logo: width %d height %d colors %d cmap %d\n", |
| 524 | BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS, |
| 525 | sizeof(bmp_logo_palette)/(sizeof(ushort))); |
| 526 | |
| 527 | bmap = &bmp_logo_bitmap[0]; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 528 | fb = (uchar *)(lcd_base + y * lcd_line_length + x); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 529 | |
| 530 | if (NBITS(panel_info.vl_bpix) < 12) { |
| 531 | /* Leave room for default color map */ |
| 532 | #if defined(CONFIG_PXA250) |
| 533 | cmap = (ushort *)fbi->palette; |
| 534 | #elif defined(CONFIG_MPC823) |
| 535 | cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]); |
| 536 | #endif |
| 537 | |
| 538 | WATCHDOG_RESET(); |
| 539 | |
| 540 | /* Set color map */ |
| 541 | for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) { |
| 542 | ushort colreg = bmp_logo_palette[i]; |
| 543 | #ifdef CFG_INVERT_COLORS |
| 544 | *cmap++ = 0xffff - colreg; |
| 545 | #else |
| 546 | *cmap++ = colreg; |
| 547 | #endif |
| 548 | } |
| 549 | |
| 550 | WATCHDOG_RESET(); |
| 551 | |
| 552 | for (i=0; i<BMP_LOGO_HEIGHT; ++i) { |
| 553 | memcpy (fb, bmap, BMP_LOGO_WIDTH); |
| 554 | bmap += BMP_LOGO_WIDTH; |
| 555 | fb += panel_info.vl_col; |
| 556 | } |
| 557 | } |
| 558 | else { /* true color mode */ |
| 559 | fb16 = (ushort *)(lcd_base + y * lcd_line_length + x); |
| 560 | for (i=0; i<BMP_LOGO_HEIGHT; ++i) { |
| 561 | for (j=0; j<BMP_LOGO_WIDTH; j++) { |
| 562 | fb16[j] = bmp_logo_palette[(bmap[j])]; |
| 563 | } |
| 564 | bmap += BMP_LOGO_WIDTH; |
| 565 | fb16 += panel_info.vl_col; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | WATCHDOG_RESET(); |
| 570 | } |
| 571 | #endif /* CONFIG_LCD_LOGO */ |
| 572 | |
| 573 | /*----------------------------------------------------------------------*/ |
| 574 | #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
| 575 | /* |
| 576 | * Display the BMP file located at address bmp_image. |
| 577 | * Only uncompressed. |
| 578 | */ |
| 579 | int lcd_display_bitmap(ulong bmp_image, int x, int y) |
| 580 | { |
| 581 | ushort *cmap; |
| 582 | ushort i, j; |
| 583 | uchar *fb; |
| 584 | bmp_image_t *bmp=(bmp_image_t *)bmp_image; |
| 585 | uchar *bmap; |
| 586 | ushort padded_line; |
| 587 | unsigned long width, height; |
| 588 | unsigned colors,bpix; |
| 589 | unsigned long compression; |
| 590 | #if defined(CONFIG_PXA250) |
| 591 | struct pxafb_info *fbi = &panel_info.pxa; |
| 592 | #elif defined(CONFIG_MPC823) |
| 593 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 594 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 595 | #endif |
| 596 | |
| 597 | if (!((bmp->header.signature[0]=='B') && |
| 598 | (bmp->header.signature[1]=='M'))) { |
| 599 | printf ("Error: no valid bmp image at %lx\n", bmp_image); |
| 600 | return 1; |
| 601 | } |
| 602 | |
| 603 | width = le32_to_cpu (bmp->header.width); |
| 604 | height = le32_to_cpu (bmp->header.height); |
| 605 | colors = 1<<le16_to_cpu (bmp->header.bit_count); |
| 606 | compression = le32_to_cpu (bmp->header.compression); |
| 607 | |
| 608 | bpix = NBITS(panel_info.vl_bpix); |
| 609 | |
| 610 | if ((bpix != 1) && (bpix != 8)) { |
| 611 | printf ("Error: %d bit/pixel mode not supported by U-Boot\n", |
| 612 | bpix); |
| 613 | return 1; |
| 614 | } |
| 615 | |
| 616 | if (bpix != le16_to_cpu(bmp->header.bit_count)) { |
| 617 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 618 | bpix, |
| 619 | le16_to_cpu(bmp->header.bit_count)); |
| 620 | return 1; |
| 621 | } |
| 622 | |
| 623 | debug ("Display-bmp: %d x %d with %d colors\n", |
| 624 | (int)width, (int)height, (int)colors); |
| 625 | |
| 626 | if (bpix==8) { |
| 627 | #if defined(CONFIG_PXA250) |
| 628 | cmap = (ushort *)fbi->palette; |
| 629 | #elif defined(CONFIG_MPC823) |
| 630 | cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]); |
wdenk | b3a4a70 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 631 | #else |
| 632 | # error "Don't know location of color map" |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 633 | #endif |
| 634 | |
| 635 | /* Set color map */ |
| 636 | for (i=0; i<colors; ++i) { |
| 637 | bmp_color_table_entry_t cte = bmp->color_table[i]; |
| 638 | ushort colreg = |
| 639 | ( ((cte.red) << 8) & 0xf800) | |
Wolfgang Denk | c4df5a4 | 2005-09-21 15:24:52 +0200 | [diff] [blame] | 640 | ( ((cte.green) << 3) & 0x07e0) | |
| 641 | ( ((cte.blue) >> 3) & 0x001f) ; |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 642 | #ifdef CFG_INVERT_COLORS |
wdenk | b3a4a70 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 643 | *cmap = 0xffff - colreg; |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 644 | #else |
wdenk | b3a4a70 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 645 | *cmap = colreg; |
| 646 | #endif |
| 647 | #if defined(CONFIG_PXA250) |
| 648 | cmap++; |
| 649 | #elif defined(CONFIG_MPC823) |
| 650 | cmap--; |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 651 | #endif |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | padded_line = (width&0x3) ? ((width&~0x3)+4) : (width); |
| 656 | if ((x + width)>panel_info.vl_col) |
| 657 | width = panel_info.vl_col - x; |
| 658 | if ((y + height)>panel_info.vl_row) |
| 659 | height = panel_info.vl_row - y; |
| 660 | |
| 661 | bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset); |
| 662 | fb = (uchar *) (lcd_base + |
| 663 | (y + height - 1) * lcd_line_length + x); |
| 664 | for (i = 0; i < height; ++i) { |
wdenk | 5ceea26 | 2005-06-05 20:30:43 +0000 | [diff] [blame] | 665 | WATCHDOG_RESET(); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 666 | for (j = 0; j < width ; j++) |
| 667 | #if defined(CONFIG_PXA250) |
| 668 | *(fb++)=*(bmap++); |
| 669 | #elif defined(CONFIG_MPC823) |
| 670 | *(fb++)=255-*(bmap++); |
| 671 | #endif |
| 672 | bmap += (width - padded_line); |
| 673 | fb -= (width + lcd_line_length); |
| 674 | } |
| 675 | |
| 676 | return (0); |
| 677 | } |
| 678 | #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */ |
| 679 | |
| 680 | |
| 681 | static void *lcd_logo (void) |
| 682 | { |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 683 | #ifdef CONFIG_LCD_INFO |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 684 | char info[80]; |
| 685 | char temp[32]; |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 686 | #endif /* CONFIG_LCD_INFO */ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 687 | |
| 688 | #ifdef CONFIG_SPLASH_SCREEN |
| 689 | char *s; |
| 690 | ulong addr; |
| 691 | static int do_splash = 1; |
| 692 | |
| 693 | if (do_splash && (s = getenv("splashimage")) != NULL) { |
| 694 | addr = simple_strtoul(s, NULL, 16); |
| 695 | do_splash = 0; |
| 696 | |
| 697 | if (lcd_display_bitmap (addr, 0, 0) == 0) { |
| 698 | return ((void *)lcd_base); |
| 699 | } |
| 700 | } |
| 701 | #endif /* CONFIG_SPLASH_SCREEN */ |
| 702 | |
| 703 | #ifdef CONFIG_LCD_LOGO |
| 704 | bitmap_plot (0, 0); |
| 705 | #endif /* CONFIG_LCD_LOGO */ |
| 706 | |
| 707 | #ifdef CONFIG_MPC823 |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 708 | # ifdef CONFIG_LCD_INFO |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 709 | sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 710 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, (uchar *)info, strlen(info)); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 711 | |
| 712 | sprintf (info, "(C) 2004 DENX Software Engineering"); |
| 713 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT, |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 714 | (uchar *)info, strlen(info)); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 715 | |
| 716 | sprintf (info, " Wolfgang DENK, wd@denx.de"); |
| 717 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2, |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 718 | (uchar *)info, strlen(info)); |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 719 | # ifdef CONFIG_LCD_INFO_BELOW_LOGO |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 720 | sprintf (info, "MPC823 CPU at %s MHz", |
| 721 | strmhz(temp, gd->cpu_clk)); |
| 722 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3, |
| 723 | info, strlen(info)); |
| 724 | sprintf (info, " %ld MB RAM, %ld MB Flash", |
| 725 | gd->ram_size >> 20, |
| 726 | gd->bd->bi_flashsize >> 20 ); |
| 727 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4, |
| 728 | info, strlen(info)); |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 729 | # else |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 730 | /* leave one blank line */ |
| 731 | |
| 732 | sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash", |
| 733 | strmhz(temp, gd->cpu_clk), |
| 734 | gd->ram_size >> 20, |
| 735 | gd->bd->bi_flashsize >> 20 ); |
| 736 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4, |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 737 | (uchar *)info, strlen(info)); |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 738 | |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 739 | # endif /* CONFIG_LCD_INFO_BELOW_LOGO */ |
| 740 | # endif /* CONFIG_LCD_INFO */ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 741 | #endif /* CONFIG_MPC823 */ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 742 | |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 743 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 744 | return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length)); |
| 745 | #else |
| 746 | return ((void *)lcd_base); |
wdenk | 2b9d186 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 747 | #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /************************************************************************/ |
| 751 | /************************************************************************/ |
| 752 | |
| 753 | #endif /* CONFIG_LCD */ |