wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering -- wd@denx.de |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /************************************************************************/ |
| 25 | /* ** HEADER FILES */ |
| 26 | /************************************************************************/ |
| 27 | |
| 28 | #include <config.h> |
| 29 | #include <common.h> |
| 30 | #include <version.h> |
| 31 | #include <stdarg.h> |
| 32 | #include <lcdvideo.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <devices.h> |
| 35 | |
| 36 | |
| 37 | #ifdef CONFIG_LCD |
| 38 | |
| 39 | /************************************************************************/ |
| 40 | /* ** CONFIG STUFF -- should be moved to board config file */ |
| 41 | /************************************************************************/ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 42 | #define CONFIG_LCD_LOGO |
| 43 | #define LCD_INFO /* Display Logo, (C) and system info */ |
wdenk | 608c914 | 2003-01-13 23:54:46 +0000 | [diff] [blame] | 44 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame^] | 45 | #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10) |
wdenk | 608c914 | 2003-01-13 23:54:46 +0000 | [diff] [blame] | 46 | #undef CONFIG_LCD_LOGO |
| 47 | #undef LCD_INFO |
| 48 | #endif |
| 49 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 50 | /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */ |
| 51 | /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */ |
| 52 | /************************************************************************/ |
| 53 | |
| 54 | /************************************************************************/ |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame^] | 55 | /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */ |
| 56 | /************************************************************************/ |
| 57 | |
| 58 | #if (CONFIG_COMMANDS & CFG_CMD_BMP) |
| 59 | #include <bmp_layout.h> |
| 60 | #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */ |
| 61 | |
| 62 | /************************************************************************/ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 63 | /* ** FONT AND LOGO DATA */ |
| 64 | /************************************************************************/ |
| 65 | |
| 66 | #include <video_font.h> /* Get font data, width and height */ |
| 67 | |
| 68 | #ifdef CONFIG_LCD_LOGO |
| 69 | # include <bmp_logo.h> /* Get logo data, width and height */ |
| 70 | #endif |
| 71 | |
| 72 | /************************************************************************/ |
| 73 | /************************************************************************/ |
| 74 | |
| 75 | /* |
| 76 | * Information about displays we are using. This is for configuring |
| 77 | * the LCD controller and memory allocation. Someone has to know what |
| 78 | * is connected, as we can't autodetect anything. |
| 79 | */ |
| 80 | #define CFG_HIGH 0 /* Pins are active high */ |
| 81 | #define CFG_LOW 1 /* Pins are active low */ |
| 82 | |
| 83 | typedef struct vidinfo { |
| 84 | ushort vl_col; /* Number of columns (i.e. 640) */ |
| 85 | ushort vl_row; /* Number of rows (i.e. 480) */ |
| 86 | ushort vl_width; /* Width of display area in millimeters */ |
| 87 | ushort vl_height; /* Height of display area in millimeters */ |
| 88 | |
| 89 | /* LCD configuration register. |
| 90 | */ |
| 91 | u_char vl_clkp; /* Clock polarity */ |
| 92 | u_char vl_oep; /* Output Enable polarity */ |
| 93 | u_char vl_hsp; /* Horizontal Sync polarity */ |
| 94 | u_char vl_vsp; /* Vertical Sync polarity */ |
| 95 | u_char vl_dp; /* Data polarity */ |
| 96 | u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */ |
| 97 | u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */ |
| 98 | u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */ |
| 99 | u_char vl_clor; /* Color, 0 = mono, 1 = color */ |
| 100 | u_char vl_tft; /* 0 = passive, 1 = TFT */ |
| 101 | |
| 102 | /* Horizontal control register. Timing from data sheet. |
| 103 | */ |
| 104 | ushort vl_wbl; /* Wait between lines */ |
| 105 | |
| 106 | /* Vertical control register. |
| 107 | */ |
| 108 | u_char vl_vpw; /* Vertical sync pulse width */ |
| 109 | u_char vl_lcdac; /* LCD AC timing */ |
| 110 | u_char vl_wbf; /* Wait between frames */ |
| 111 | } vidinfo_t; |
| 112 | |
| 113 | #define LCD_MONOCHROME 0 |
| 114 | #define LCD_COLOR2 1 |
| 115 | #define LCD_COLOR4 2 |
| 116 | #define LCD_COLOR8 3 |
| 117 | |
| 118 | /*----------------------------------------------------------------------*/ |
| 119 | #ifdef CONFIG_KYOCERA_KCS057QV1AJ |
| 120 | /* |
| 121 | * Kyocera KCS057QV1AJ-G23. Passive, color, single scan. |
| 122 | */ |
| 123 | #define LCD_BPP LCD_COLOR4 |
| 124 | |
| 125 | static vidinfo_t panel_info = { |
| 126 | 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, |
| 127 | LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0 |
| 128 | /* wbl, vpw, lcdac, wbf */ |
| 129 | }; |
| 130 | #endif /* CONFIG_KYOCERA_KCS057QV1AJ */ |
| 131 | /*----------------------------------------------------------------------*/ |
| 132 | |
| 133 | /*----------------------------------------------------------------------*/ |
| 134 | #ifdef CONFIG_NEC_NL6648AC33 |
| 135 | /* |
| 136 | * NEC NL6648AC33-18. Active, color, single scan. |
| 137 | */ |
| 138 | static vidinfo_t panel_info = { |
| 139 | 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH, |
| 140 | 3, 0, 0, 1, 1, 144, 2, 0, 33 |
| 141 | /* wbl, vpw, lcdac, wbf */ |
| 142 | }; |
| 143 | #endif /* CONFIG_NEC_NL6648AC33 */ |
| 144 | /*----------------------------------------------------------------------*/ |
| 145 | |
| 146 | #ifdef CONFIG_NEC_NL6648BC20 |
| 147 | /* |
| 148 | * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan. |
| 149 | */ |
| 150 | static vidinfo_t panel_info = { |
| 151 | 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH, |
| 152 | 3, 0, 0, 1, 1, 144, 2, 0, 33 |
| 153 | /* wbl, vpw, lcdac, wbf */ |
| 154 | }; |
| 155 | #endif /* CONFIG_NEC_NL6648BC20 */ |
| 156 | /*----------------------------------------------------------------------*/ |
| 157 | |
| 158 | #ifdef CONFIG_SHARP_LQ104V7DS01 |
| 159 | /* |
| 160 | * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan. |
| 161 | */ |
| 162 | static vidinfo_t panel_info = { |
| 163 | 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW, |
| 164 | 3, 0, 0, 1, 1, 25, 1, 0, 33 |
| 165 | /* wbl, vpw, lcdac, wbf */ |
| 166 | }; |
| 167 | #endif /* CONFIG_SHARP_LQ104V7DS01 */ |
| 168 | /*----------------------------------------------------------------------*/ |
| 169 | |
| 170 | #ifdef CONFIG_SHARP_16x9 |
| 171 | /* |
| 172 | * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am |
| 173 | * not sure what it is....... |
| 174 | */ |
| 175 | static vidinfo_t panel_info = { |
| 176 | 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, |
| 177 | 3, 0, 0, 1, 1, 15, 4, 0, 3 |
| 178 | }; |
| 179 | #endif /* CONFIG_SHARP_16x9 */ |
| 180 | /*----------------------------------------------------------------------*/ |
| 181 | |
| 182 | #ifdef CONFIG_SHARP_LQ057Q3DC02 |
| 183 | /* |
| 184 | * Sharp LQ057Q3DC02 display. Active, color, single scan. |
| 185 | */ |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 186 | #define LCD_DF 12 |
| 187 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 188 | static vidinfo_t panel_info = { |
| 189 | 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH, |
| 190 | 3, 0, 0, 1, 1, 15, 4, 0, 3 |
| 191 | /* wbl, vpw, lcdac, wbf */ |
| 192 | }; |
| 193 | #define LCD_INFO_BELOW_LOGO |
| 194 | #endif /* CONFIG_SHARP_LQ057Q3DC02 */ |
| 195 | /*----------------------------------------------------------------------*/ |
| 196 | |
| 197 | #ifdef CONFIG_SHARP_LQ64D341 |
| 198 | /* |
| 199 | * Sharp LQ64D341 display, 640x480. Active, color, single scan. |
| 200 | */ |
| 201 | static vidinfo_t panel_info = { |
| 202 | 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH, |
| 203 | 3, 0, 0, 1, 1, 128, 16, 0, 32 |
| 204 | /* wbl, vpw, lcdac, wbf */ |
| 205 | }; |
| 206 | #endif /* CONFIG_SHARP_LQ64D341 */ |
wdenk | 608c914 | 2003-01-13 23:54:46 +0000 | [diff] [blame] | 207 | |
| 208 | #ifdef CONFIG_SHARP_LQ084V1DG21 |
| 209 | /* |
| 210 | * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan. |
| 211 | */ |
| 212 | static vidinfo_t panel_info = { |
| 213 | 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW, |
| 214 | 3, 0, 0, 1, 1, 160, 3, 0, 48 |
| 215 | /* wbl, vpw, lcdac, wbf */ |
| 216 | }; |
| 217 | #endif /* CONFIG_SHARP_LQ084V1DG21 */ |
| 218 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 219 | /*----------------------------------------------------------------------*/ |
| 220 | |
| 221 | #ifdef CONFIG_HLD1045 |
| 222 | /* |
| 223 | * HLD1045 display, 640x480. Active, color, single scan. |
| 224 | */ |
| 225 | static vidinfo_t panel_info = { |
| 226 | 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH, |
| 227 | 3, 0, 0, 1, 1, 160, 3, 0, 48 |
| 228 | /* wbl, vpw, lcdac, wbf */ |
| 229 | }; |
| 230 | #endif /* CONFIG_HLD1045 */ |
| 231 | /*----------------------------------------------------------------------*/ |
| 232 | |
| 233 | #ifdef CONFIG_PRIMEVIEW_V16C6448AC |
| 234 | /* |
| 235 | * Prime View V16C6448AC |
| 236 | */ |
| 237 | static vidinfo_t panel_info = { |
| 238 | 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH, |
| 239 | 3, 0, 0, 1, 1, 144, 2, 0, 35 |
| 240 | /* wbl, vpw, lcdac, wbf */ |
| 241 | }; |
| 242 | #endif /* CONFIG_PRIMEVIEW_V16C6448AC */ |
| 243 | |
| 244 | /*----------------------------------------------------------------------*/ |
| 245 | |
| 246 | #ifdef CONFIG_OPTREX_BW |
| 247 | /* |
| 248 | * Optrex CBL50840-2 NF-FW 99 22 M5 |
| 249 | * or |
| 250 | * Hitachi LMG6912RPFC-00T |
| 251 | * or |
| 252 | * Hitachi SP14Q002 |
| 253 | * |
| 254 | * 320x240. Black & white. |
| 255 | */ |
| 256 | #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */ |
| 257 | /* 1 - 4 grey levels, 2 bpp */ |
| 258 | /* 2 - 16 grey levels, 4 bpp */ |
| 259 | static vidinfo_t panel_info = { |
| 260 | 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW, |
| 261 | OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4 |
| 262 | }; |
| 263 | #endif /* CONFIG_OPTREX_BW */ |
| 264 | |
| 265 | /*-----------------------------------------------------------------*/ |
| 266 | #ifdef CONFIG_EDT32F10 |
| 267 | /* |
| 268 | * Emerging Display Technologies 320x240. Passive, monochrome, single scan. |
| 269 | */ |
| 270 | #define LCD_BPP LCD_MONOCHROME |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 271 | #define LCD_DF 10 |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 272 | |
| 273 | static vidinfo_t panel_info = { |
| 274 | 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW, |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 275 | LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0 |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 276 | }; |
| 277 | #endif |
| 278 | /*----------------------------------------------------------------------*/ |
| 279 | |
| 280 | #if defined(LCD_INFO_BELOW_LOGO) |
| 281 | # define LCD_INFO_X 0 |
| 282 | # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT) |
| 283 | #elif defined(CONFIG_LCD_LOGO) |
| 284 | # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH) |
| 285 | # define LCD_INFO_Y (VIDEO_FONT_HEIGHT) |
| 286 | #else |
| 287 | # define LCD_INFO_X (VIDEO_FONT_WIDTH) |
| 288 | # define LCD_INFO_Y (VIDEO_FONT_HEIGHT) |
| 289 | #endif |
| 290 | |
| 291 | #ifndef LCD_BPP |
| 292 | #define LCD_BPP LCD_COLOR8 |
| 293 | #endif |
| 294 | #ifndef LCD_DF |
| 295 | #define LCD_DF 1 |
| 296 | #endif |
| 297 | |
| 298 | #define NBITS(bit_code) (1 << (bit_code)) |
| 299 | #define NCOLORS(bit_code) (1 << NBITS(bit_code)) |
| 300 | |
| 301 | static int lcd_line_length; |
| 302 | |
| 303 | static int lcd_color_fg; |
| 304 | static int lcd_color_bg; |
| 305 | |
| 306 | static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */ |
| 307 | |
| 308 | /* |
| 309 | * Frame buffer memory information |
| 310 | */ |
| 311 | static void *lcd_base; /* Start of framebuffer memory */ |
| 312 | static void *lcd_console_address; /* Start of console buffer */ |
| 313 | |
| 314 | |
| 315 | /************************************************************************/ |
| 316 | /* ** CONSOLE CONSTANTS */ |
| 317 | /************************************************************************/ |
| 318 | |
| 319 | #if LCD_BPP == LCD_MONOCHROME |
| 320 | |
| 321 | /* |
| 322 | * Simple color definitions |
| 323 | */ |
| 324 | #define CONSOLE_COLOR_BLACK 0 |
| 325 | #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */ |
| 326 | |
| 327 | #else |
| 328 | |
| 329 | /* |
| 330 | * Simple color definitions |
| 331 | */ |
| 332 | #define CONSOLE_COLOR_BLACK 0 |
| 333 | #define CONSOLE_COLOR_RED 1 |
| 334 | #define CONSOLE_COLOR_GREEN 2 |
| 335 | #define CONSOLE_COLOR_YELLOW 3 |
| 336 | #define CONSOLE_COLOR_BLUE 4 |
| 337 | #define CONSOLE_COLOR_MAGENTA 5 |
| 338 | #define CONSOLE_COLOR_CYAN 6 |
| 339 | #define CONSOLE_COLOR_GREY 14 |
| 340 | #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */ |
| 341 | |
| 342 | #endif |
| 343 | |
| 344 | #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) |
| 345 | #error Default Color Map overlaps with Logo Color Map |
| 346 | #endif |
| 347 | |
| 348 | /************************************************************************/ |
| 349 | |
| 350 | #ifndef PAGE_SIZE |
| 351 | #define PAGE_SIZE 4096 |
| 352 | #endif |
| 353 | |
| 354 | |
| 355 | /************************************************************************/ |
| 356 | /* ** CONSOLE DEFINITIONS & FUNCTIONS */ |
| 357 | /************************************************************************/ |
| 358 | |
| 359 | #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO) |
| 360 | #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \ |
| 361 | / VIDEO_FONT_HEIGHT) |
| 362 | #else |
| 363 | #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT) |
| 364 | #endif |
| 365 | #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH) |
| 366 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) |
| 367 | #define CONSOLE_ROW_FIRST (lcd_console_address) |
| 368 | #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) |
| 369 | #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ |
| 370 | - CONSOLE_ROW_SIZE) |
| 371 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) |
| 372 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) |
| 373 | |
| 374 | #if LCD_BPP == LCD_MONOCHROME |
| 375 | #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \ |
| 376 | (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7) |
| 377 | #elif LCD_BPP == LCD_COLOR8 |
| 378 | #define COLOR_MASK(c) (c) |
| 379 | #else |
| 380 | #error Unsupported LCD BPP. |
| 381 | #endif |
| 382 | |
| 383 | static short console_col; |
| 384 | static short console_row; |
| 385 | |
| 386 | /************************************************************************/ |
| 387 | |
| 388 | ulong lcd_setmem (ulong addr); |
| 389 | |
| 390 | static void lcd_drawchars (ushort x, ushort y, uchar *str, int count); |
| 391 | static inline void lcd_puts_xy (ushort x, ushort y, uchar *s); |
| 392 | static inline void lcd_putc_xy (ushort x, ushort y, uchar c); |
| 393 | |
| 394 | static int lcd_init (void *lcdbase); |
| 395 | static void lcd_ctrl_init (void *lcdbase); |
| 396 | static void lcd_enable (void); |
| 397 | static void *lcd_logo (void); |
| 398 | #if LCD_BPP == LCD_COLOR8 |
| 399 | static void lcd_setcolreg (ushort regno, |
| 400 | ushort red, ushort green, ushort blue); |
| 401 | #endif |
| 402 | #if LCD_BPP == LCD_MONOCHROME |
| 403 | static void lcd_initcolregs (void); |
| 404 | #endif |
| 405 | static int lcd_getbgcolor (void); |
| 406 | static void lcd_setfgcolor (int color); |
| 407 | static void lcd_setbgcolor (int color); |
| 408 | |
| 409 | #ifdef NOT_USED_SO_FAR |
| 410 | static void lcd_disable (void); |
| 411 | static void lcd_getcolreg (ushort regno, |
| 412 | ushort *red, ushort *green, ushort *blue); |
| 413 | static int lcd_getfgcolor (void); |
| 414 | #endif /* NOT_USED_SO_FAR */ |
| 415 | |
| 416 | /************************************************************************/ |
| 417 | |
| 418 | /*----------------------------------------------------------------------*/ |
| 419 | |
| 420 | static void console_scrollup (void) |
| 421 | { |
| 422 | #if 1 |
| 423 | /* Copy up rows ignoring the first one */ |
| 424 | memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE); |
| 425 | |
| 426 | /* Clear the last one */ |
| 427 | memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE); |
| 428 | #else |
| 429 | /* |
| 430 | * Poor attempt to optimize speed by moving "long"s. |
| 431 | * But the code is ugly, and not a bit faster :-( |
| 432 | */ |
| 433 | ulong *t = (ulong *)CONSOLE_ROW_FIRST; |
| 434 | ulong *s = (ulong *)CONSOLE_ROW_SECOND; |
| 435 | ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong); |
| 436 | uchar c = lcd_color_bg & 0xFF; |
| 437 | ulong val= (c<<24) | (c<<16) | (c<<8) | c; |
| 438 | |
| 439 | while (l--) |
| 440 | *t++ = *s++; |
| 441 | |
| 442 | t = (ulong *)CONSOLE_ROW_LAST; |
| 443 | l = CONSOLE_ROW_SIZE / sizeof(ulong); |
| 444 | |
| 445 | while (l-- > 0) |
| 446 | *t++ = val; |
| 447 | #endif |
| 448 | } |
| 449 | |
| 450 | /*----------------------------------------------------------------------*/ |
| 451 | |
| 452 | static inline void console_back (void) |
| 453 | { |
| 454 | if (--console_col < 0) { |
| 455 | console_col = CONSOLE_COLS-1 ; |
| 456 | if (--console_row < 0) { |
| 457 | console_row = 0; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | lcd_putc_xy (console_col * VIDEO_FONT_WIDTH, |
| 462 | console_row * VIDEO_FONT_HEIGHT, |
| 463 | ' '); |
| 464 | } |
| 465 | |
| 466 | /*----------------------------------------------------------------------*/ |
| 467 | |
| 468 | static inline void console_newline (void) |
| 469 | { |
| 470 | ++console_row; |
| 471 | console_col = 0; |
| 472 | |
| 473 | /* Check if we need to scroll the terminal */ |
| 474 | if (console_row >= CONSOLE_ROWS) { |
| 475 | /* Scroll everything up */ |
| 476 | console_scrollup () ; |
| 477 | --console_row; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /*----------------------------------------------------------------------*/ |
| 482 | |
| 483 | void lcd_putc (const char c) |
| 484 | { |
| 485 | if (!lcd_is_enabled) { |
| 486 | serial_putc(c); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | switch (c) { |
| 491 | case '\r': console_col = 0; |
| 492 | return; |
| 493 | |
| 494 | case '\n': console_newline(); |
| 495 | return; |
| 496 | |
| 497 | case '\t': /* Tab (8 chars alignment) */ |
| 498 | console_col |= 8; |
| 499 | console_col &= ~7; |
| 500 | |
| 501 | if (console_col >= CONSOLE_COLS) { |
| 502 | console_newline(); |
| 503 | } |
| 504 | return; |
| 505 | |
| 506 | case '\b': console_back(); |
| 507 | return; |
| 508 | |
| 509 | default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH, |
| 510 | console_row * VIDEO_FONT_HEIGHT, |
| 511 | c); |
| 512 | if (++console_col >= CONSOLE_COLS) { |
| 513 | console_newline(); |
| 514 | } |
| 515 | return; |
| 516 | } |
| 517 | /* NOTREACHED */ |
| 518 | } |
| 519 | |
| 520 | /*----------------------------------------------------------------------*/ |
| 521 | |
| 522 | void lcd_puts (const char *s) |
| 523 | { |
| 524 | if (!lcd_is_enabled) { |
| 525 | serial_puts (s); |
| 526 | return; |
| 527 | } |
| 528 | |
| 529 | while (*s) { |
| 530 | lcd_putc (*s++); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /************************************************************************/ |
| 535 | /* ** Low-Level Graphics Routines */ |
| 536 | /************************************************************************/ |
| 537 | |
| 538 | static void lcd_drawchars (ushort x, ushort y, uchar *str, int count) |
| 539 | { |
| 540 | uchar *dest; |
| 541 | ushort off, row; |
| 542 | |
| 543 | dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8); |
| 544 | off = x * (1 << LCD_BPP) % 8; |
| 545 | |
| 546 | for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { |
| 547 | uchar *s = str; |
| 548 | uchar *d = dest; |
| 549 | int i; |
| 550 | |
| 551 | #if LCD_BPP == LCD_MONOCHROME |
| 552 | uchar rest = *d & -(1 << (8-off)); |
| 553 | uchar sym; |
| 554 | #endif |
| 555 | for (i=0; i<count; ++i) { |
| 556 | uchar c, bits; |
| 557 | |
| 558 | c = *s++; |
| 559 | bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; |
| 560 | |
| 561 | #if LCD_BPP == LCD_MONOCHROME |
| 562 | sym = (COLOR_MASK(lcd_color_fg) & bits) | |
| 563 | (COLOR_MASK(lcd_color_bg) & ~bits); |
| 564 | |
| 565 | *d++ = rest | (sym >> off); |
| 566 | rest = sym << (8-off); |
| 567 | #elif LCD_BPP == LCD_COLOR8 |
| 568 | for (c=0; c<8; ++c) { |
| 569 | *d++ = (bits & 0x80) ? |
| 570 | lcd_color_fg : lcd_color_bg; |
| 571 | bits <<= 1; |
| 572 | } |
| 573 | #endif |
| 574 | } |
| 575 | |
| 576 | #if LCD_BPP == LCD_MONOCHROME |
| 577 | *d = rest | (*d & ((1 << (8-off)) - 1)); |
| 578 | #endif |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | /*----------------------------------------------------------------------*/ |
| 583 | |
| 584 | static inline void lcd_puts_xy (ushort x, ushort y, uchar *s) |
| 585 | { |
| 586 | #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO) |
| 587 | lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s)); |
| 588 | #else |
| 589 | lcd_drawchars (x, y, s, strlen (s)); |
| 590 | #endif |
| 591 | } |
| 592 | |
| 593 | /*----------------------------------------------------------------------*/ |
| 594 | |
| 595 | static inline void lcd_putc_xy (ushort x, ushort y, uchar c) |
| 596 | { |
| 597 | #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO) |
| 598 | lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1); |
| 599 | #else |
| 600 | lcd_drawchars (x, y, &c, 1); |
| 601 | #endif |
| 602 | } |
| 603 | |
| 604 | /************************************************************************/ |
| 605 | /** Small utility to check that you got the colours right */ |
| 606 | /************************************************************************/ |
| 607 | #ifdef LCD_TEST_PATTERN |
| 608 | |
| 609 | #define N_BLK_VERT 2 |
| 610 | #define N_BLK_HOR 3 |
| 611 | |
| 612 | static int test_colors[N_BLK_HOR*N_BLK_VERT] = { |
| 613 | CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, |
| 614 | CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, |
| 615 | }; |
| 616 | |
| 617 | static void test_pattern (void) |
| 618 | { |
| 619 | ushort v_max = panel_info.vl_row; |
| 620 | ushort h_max = panel_info.vl_col; |
| 621 | ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; |
| 622 | ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; |
| 623 | ushort v, h; |
| 624 | uchar *pix = (uchar *)lcd_base; |
| 625 | |
| 626 | printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n", |
| 627 | h_max, v_max, h_step, v_step); |
| 628 | |
| 629 | /* WARNING: Code silently assumes 8bit/pixel */ |
| 630 | for (v=0; v<v_max; ++v) { |
| 631 | uchar iy = v / v_step; |
| 632 | for (h=0; h<h_max; ++h) { |
| 633 | uchar ix = N_BLK_HOR * iy + (h/h_step); |
| 634 | *pix++ = test_colors[ix]; |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | #endif /* LCD_TEST_PATTERN */ |
| 639 | |
| 640 | |
| 641 | /************************************************************************/ |
| 642 | /* ** GENERIC Initialization Routines */ |
| 643 | /************************************************************************/ |
| 644 | |
| 645 | int drv_lcd_init (void) |
| 646 | { |
| 647 | DECLARE_GLOBAL_DATA_PTR; |
| 648 | |
| 649 | device_t lcddev; |
| 650 | int rc; |
| 651 | |
| 652 | lcd_base = (void *)(gd->fb_base); |
| 653 | |
| 654 | lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8; |
| 655 | |
| 656 | lcd_init (lcd_base); /* LCD initialization */ |
| 657 | |
| 658 | /* Device initialization */ |
| 659 | memset (&lcddev, 0, sizeof (lcddev)); |
| 660 | |
| 661 | strcpy (lcddev.name, "lcd"); |
| 662 | lcddev.ext = 0; /* No extensions */ |
| 663 | lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
| 664 | lcddev.putc = lcd_putc; /* 'putc' function */ |
| 665 | lcddev.puts = lcd_puts; /* 'puts' function */ |
| 666 | |
| 667 | rc = device_register (&lcddev); |
| 668 | |
| 669 | return (rc == 0) ? 1 : rc; |
| 670 | } |
| 671 | |
| 672 | /*----------------------------------------------------------------------*/ |
| 673 | |
| 674 | static int lcd_init (void *lcdbase) |
| 675 | { |
| 676 | /* Initialize the lcd controller */ |
| 677 | debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase); |
| 678 | |
| 679 | lcd_ctrl_init (lcdbase); |
| 680 | |
| 681 | #if LCD_BPP == LCD_MONOCHROME |
| 682 | /* Setting the palette */ |
| 683 | lcd_initcolregs(); |
| 684 | |
| 685 | #elif LCD_BPP == LCD_COLOR8 |
| 686 | /* Setting the palette */ |
| 687 | lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0); |
| 688 | lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0); |
| 689 | lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0); |
| 690 | lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); |
| 691 | lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF); |
| 692 | lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); |
| 693 | lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); |
| 694 | lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); |
| 695 | lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); |
| 696 | #endif |
| 697 | |
| 698 | #ifndef CFG_WHITE_ON_BLACK |
| 699 | lcd_setfgcolor (CONSOLE_COLOR_BLACK); |
| 700 | lcd_setbgcolor (CONSOLE_COLOR_WHITE); |
| 701 | #else |
| 702 | lcd_setfgcolor (CONSOLE_COLOR_WHITE); |
| 703 | lcd_setbgcolor (CONSOLE_COLOR_BLACK); |
| 704 | #endif /* CFG_WHITE_ON_BLACK */ |
| 705 | |
| 706 | #ifdef LCD_TEST_PATTERN |
| 707 | test_pattern(); |
| 708 | #else |
| 709 | /* set framebuffer to background color */ |
| 710 | memset ((char *)lcd_base, |
| 711 | COLOR_MASK(lcd_getbgcolor()), |
| 712 | lcd_line_length*panel_info.vl_row); |
| 713 | #endif |
| 714 | |
| 715 | lcd_enable (); |
| 716 | |
| 717 | /* Paint the logo and retrieve LCD base address */ |
| 718 | debug ("[LCD] Drawing the logo...\n"); |
| 719 | lcd_console_address = lcd_logo (); |
| 720 | |
| 721 | /* Initialize the console */ |
| 722 | console_col = 0; |
| 723 | #ifdef LCD_INFO_BELOW_LOGO |
| 724 | console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; |
| 725 | #else |
| 726 | console_row = 1; /* leave 1 blank line below logo */ |
| 727 | #endif |
| 728 | lcd_is_enabled = 1; |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | /************************************************************************/ |
| 735 | /* ** ROM capable initialization part - needed to reserve FB memory */ |
| 736 | /************************************************************************/ |
| 737 | |
| 738 | /* |
| 739 | * This is called early in the system initialization to grab memory |
| 740 | * for the LCD controller. |
| 741 | * Returns new address for monitor, after reserving LCD buffer memory |
| 742 | * |
| 743 | * Note that this is running from ROM, so no write access to global data. |
| 744 | */ |
| 745 | ulong lcd_setmem (ulong addr) |
| 746 | { |
| 747 | ulong size; |
| 748 | int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8; |
| 749 | |
| 750 | debug ("LCD panel info: %d x %d, %d bit/pix\n", |
| 751 | panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) ); |
| 752 | |
| 753 | size = line_length * panel_info.vl_row; |
| 754 | |
| 755 | /* Round up to nearest full page */ |
| 756 | size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 757 | |
| 758 | /* Allocate pages for the frame buffer. */ |
| 759 | addr -= size; |
| 760 | |
| 761 | debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr); |
| 762 | |
| 763 | return (addr); |
| 764 | } |
| 765 | |
| 766 | |
| 767 | /************************************************************************/ |
| 768 | /* ----------------- chipset specific functions ----------------------- */ |
| 769 | /************************************************************************/ |
| 770 | |
| 771 | static void lcd_ctrl_init (void *lcdbase) |
| 772 | { |
| 773 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 774 | volatile lcd823_t *lcdp = &immr->im_lcd; |
| 775 | |
| 776 | uint lccrtmp; |
| 777 | |
| 778 | /* Initialize the LCD control register according to the LCD |
| 779 | * parameters defined. We do everything here but enable |
| 780 | * the controller. |
| 781 | */ |
| 782 | |
| 783 | lccrtmp = LCDBIT (LCCR_BNUM_BIT, |
| 784 | (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128)); |
| 785 | |
| 786 | lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) | |
| 787 | LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) | |
| 788 | LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) | |
| 789 | LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) | |
| 790 | LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) | |
| 791 | LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) | |
| 792 | LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) | |
| 793 | LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) | |
| 794 | LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) | |
| 795 | LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft); |
| 796 | |
| 797 | #if 0 |
| 798 | lccrtmp |= ((SIU_LEVEL5 / 2) << 12); |
| 799 | lccrtmp |= LCCR_EIEN; |
| 800 | #endif |
| 801 | |
| 802 | lcdp->lcd_lccr = lccrtmp; |
| 803 | lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */ |
| 804 | |
| 805 | /* Initialize LCD controller bus priorities. |
| 806 | */ |
| 807 | immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */ |
| 808 | |
| 809 | /* set SHFT/CLOCK division factor 4 |
| 810 | * This needs to be set based upon display type and processor |
| 811 | * speed. The TFT displays run about 20 to 30 MHz. |
| 812 | * I was running 64 MHz processor speed. |
| 813 | * The value for this divider must be chosen so the result is |
| 814 | * an integer of the processor speed (i.e., divide by 3 with |
| 815 | * 64 MHz would be bad). |
| 816 | */ |
| 817 | immr->im_clkrst.car_sccr &= ~0x1F; |
| 818 | immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */ |
| 819 | |
| 820 | #ifndef CONFIG_EDT32F10 |
| 821 | /* Enable LCD on port D. |
| 822 | */ |
| 823 | immr->im_ioport.iop_pdpar |= 0x1FFF; |
| 824 | immr->im_ioport.iop_pddir |= 0x1FFF; |
| 825 | |
| 826 | /* Enable LCD_A/B/C on port B. |
| 827 | */ |
| 828 | immr->im_cpm.cp_pbpar |= 0x00005001; |
| 829 | immr->im_cpm.cp_pbdir |= 0x00005001; |
| 830 | #else |
| 831 | /* Enable LCD on port D. |
| 832 | */ |
| 833 | immr->im_ioport.iop_pdpar |= 0x1DFF; |
| 834 | immr->im_ioport.iop_pdpar &= ~0x0200; |
| 835 | immr->im_ioport.iop_pddir |= 0x1FFF; |
| 836 | immr->im_ioport.iop_pddat |= 0x0200; |
| 837 | #endif |
| 838 | |
| 839 | /* Load the physical address of the linear frame buffer |
| 840 | * into the LCD controller. |
| 841 | * BIG NOTE: This has to be modified to load A and B depending |
| 842 | * upon the split mode of the LCD. |
| 843 | */ |
| 844 | lcdp->lcd_lcfaa = (ulong)lcd_base; |
| 845 | lcdp->lcd_lcfba = (ulong)lcd_base; |
| 846 | |
| 847 | /* MORE HACKS...This must be updated according to 823 manual |
| 848 | * for different panels. |
| 849 | */ |
| 850 | #ifndef CONFIG_EDT32F10 |
| 851 | lcdp->lcd_lchcr = LCHCR_BO | |
| 852 | LCDBIT (LCHCR_AT_BIT, 4) | |
| 853 | LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) | |
| 854 | panel_info.vl_wbl; |
| 855 | #else |
| 856 | lcdp->lcd_lchcr = LCHCR_BO | |
| 857 | LCDBIT (LCHCR_AT_BIT, 4) | |
| 858 | LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) | |
| 859 | panel_info.vl_wbl; |
| 860 | #endif |
| 861 | |
| 862 | lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) | |
| 863 | LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) | |
| 864 | LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) | |
| 865 | panel_info.vl_wbf; |
| 866 | |
| 867 | } |
| 868 | |
| 869 | /*----------------------------------------------------------------------*/ |
| 870 | |
| 871 | #ifdef NOT_USED_SO_FAR |
| 872 | static void |
| 873 | lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue) |
| 874 | { |
| 875 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 876 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 877 | unsigned short colreg, *cmap_ptr; |
| 878 | |
| 879 | cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2]; |
| 880 | |
| 881 | colreg = *cmap_ptr; |
| 882 | #ifdef CFG_INVERT_COLORS |
| 883 | colreg ^= 0x0FFF; |
| 884 | #endif |
| 885 | |
| 886 | *red = (colreg >> 8) & 0x0F; |
| 887 | *green = (colreg >> 4) & 0x0F; |
| 888 | *blue = colreg & 0x0F; |
| 889 | } |
| 890 | #endif /* NOT_USED_SO_FAR */ |
| 891 | |
| 892 | /*----------------------------------------------------------------------*/ |
| 893 | |
| 894 | #if LCD_BPP == LCD_COLOR8 |
| 895 | static void |
| 896 | lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue) |
| 897 | { |
| 898 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 899 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 900 | unsigned short colreg, *cmap_ptr; |
| 901 | |
| 902 | cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2]; |
| 903 | |
| 904 | colreg = ((red & 0x0F) << 8) | |
| 905 | ((green & 0x0F) << 4) | |
| 906 | (blue & 0x0F) ; |
| 907 | #ifdef CFG_INVERT_COLORS |
| 908 | colreg ^= 0x0FFF; |
| 909 | #endif |
| 910 | *cmap_ptr = colreg; |
| 911 | |
| 912 | debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n", |
| 913 | regno, &(cp->lcd_cmap[regno * 2]), |
| 914 | red, green, blue, |
| 915 | cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]); |
| 916 | } |
| 917 | #endif /* LCD_COLOR8 */ |
| 918 | |
| 919 | /*----------------------------------------------------------------------*/ |
| 920 | |
| 921 | #if LCD_BPP == LCD_MONOCHROME |
| 922 | static |
| 923 | void lcd_initcolregs (void) |
| 924 | { |
| 925 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 926 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 927 | ushort regno; |
| 928 | |
| 929 | for (regno = 0; regno < 16; regno++) { |
| 930 | cp->lcd_cmap[regno * 2] = 0; |
| 931 | cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f; |
| 932 | } |
| 933 | } |
| 934 | #endif |
| 935 | |
| 936 | /*----------------------------------------------------------------------*/ |
| 937 | |
| 938 | static void lcd_setfgcolor (int color) |
| 939 | { |
| 940 | lcd_color_fg = color & 0x0F; |
| 941 | } |
| 942 | |
| 943 | /*----------------------------------------------------------------------*/ |
| 944 | |
| 945 | static void lcd_setbgcolor (int color) |
| 946 | { |
| 947 | lcd_color_bg = color & 0x0F; |
| 948 | } |
| 949 | |
| 950 | /*----------------------------------------------------------------------*/ |
| 951 | |
| 952 | #ifdef NOT_USED_SO_FAR |
| 953 | static int lcd_getfgcolor (void) |
| 954 | { |
| 955 | return lcd_color_fg; |
| 956 | } |
| 957 | #endif /* NOT_USED_SO_FAR */ |
| 958 | |
| 959 | /*----------------------------------------------------------------------*/ |
| 960 | |
| 961 | static int lcd_getbgcolor (void) |
| 962 | { |
| 963 | return lcd_color_bg; |
| 964 | } |
| 965 | |
| 966 | /*----------------------------------------------------------------------*/ |
| 967 | |
| 968 | static void lcd_enable (void) |
| 969 | { |
| 970 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 971 | volatile lcd823_t *lcdp = &immr->im_lcd; |
| 972 | |
| 973 | /* Enable the LCD panel */ |
| 974 | immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */ |
| 975 | lcdp->lcd_lccr |= LCCR_PON; |
wdenk | 608c914 | 2003-01-13 23:54:46 +0000 | [diff] [blame] | 976 | |
| 977 | #ifdef CONFIG_V37 |
| 978 | /* Turn on display backlight */ |
| 979 | immr->im_cpm.cp_pbpar |= 0x00008000; |
| 980 | immr->im_cpm.cp_pbdir |= 0x00008000; |
| 981 | #endif |
| 982 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 983 | #if defined(CONFIG_LWMON) |
| 984 | { uchar c = pic_read (0x60); |
| 985 | c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */ |
| 986 | pic_write (0x60, c); |
| 987 | } |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 988 | #endif /* CONFIG_LWMON */ |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 989 | |
| 990 | #if defined(CONFIG_R360MPI) |
| 991 | { |
| 992 | extern void r360_i2c_lcd_write (uchar data0, uchar data1); |
| 993 | |
| 994 | r360_i2c_lcd_write(0x10, 0x01); |
| 995 | r360_i2c_lcd_write(0x20, 0x01); |
| 996 | r360_i2c_lcd_write(0x3F, 0xFF); |
| 997 | r360_i2c_lcd_write(0x47, 0xFF); |
| 998 | } |
| 999 | #endif /* CONFIG_R360MPI */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | /*----------------------------------------------------------------------*/ |
| 1003 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame^] | 1004 | #if (CONFIG_COMMANDS & CFG_CMD_BMP) |
| 1005 | /* |
| 1006 | Display the BMP file located at address bmp_image. |
| 1007 | Only uncompressed |
| 1008 | */ |
| 1009 | int lcd_display_bitmap(ulong bmp_image) |
| 1010 | { |
| 1011 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 1012 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 1013 | ushort *cmap; |
| 1014 | ushort i, j; |
| 1015 | uchar *fb; |
| 1016 | bmp_image_t *bmp=(bmp_image_t *)bmp_image; |
| 1017 | uchar *bmap; |
| 1018 | ushort padded_line; |
| 1019 | unsigned long width, height; |
| 1020 | unsigned colors,bpix; |
| 1021 | unsigned long compression; |
| 1022 | |
| 1023 | if (!((bmp->header.signature[0]=='B') && |
| 1024 | (bmp->header.signature[1]=='M'))) { |
| 1025 | printf ("Error: no valid bmp image at %lx\n", bmp_image); |
| 1026 | return 1; |
| 1027 | } |
| 1028 | |
| 1029 | width = le32_to_cpu (bmp->header.width); |
| 1030 | height = le32_to_cpu (bmp->header.height); |
| 1031 | colors = 1<<le16_to_cpu (bmp->header.bit_count); |
| 1032 | compression = le32_to_cpu (bmp->header.compression); |
| 1033 | |
| 1034 | bpix = NBITS(panel_info.vl_bpix); |
| 1035 | |
| 1036 | if ((bpix != 1) && (bpix != 8)) { |
| 1037 | printf ("Error: %d bit/pixel mode not supported by U-Boot\n", |
| 1038 | bpix); |
| 1039 | return 1; |
| 1040 | } |
| 1041 | |
| 1042 | if (bpix != le16_to_cpu(bmp->header.bit_count)) { |
| 1043 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 1044 | bpix, |
| 1045 | le16_to_cpu(bmp->header.bit_count)); |
| 1046 | return 1; |
| 1047 | } |
| 1048 | |
| 1049 | if (compression!=BMP_BI_RGB) { |
| 1050 | printf ("Error: compression type %ld not supported\n", |
| 1051 | compression); |
| 1052 | return 1; |
| 1053 | } |
| 1054 | |
| 1055 | debug ("Display-bmp: %d x %d with %d colors\n", |
| 1056 | width, height, colors); |
| 1057 | |
| 1058 | if (bpix==8) { |
| 1059 | /* Fill the entire color map */ |
| 1060 | cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]); |
| 1061 | |
| 1062 | /* Set color map */ |
| 1063 | for (i = 0; i < colors; ++i) { |
| 1064 | bmp_color_table_entry_t cte = bmp->color_table[i]; |
| 1065 | ushort colreg = |
| 1066 | ((cte.red>>4) << 8) | |
| 1067 | ((cte.green>>4) << 4) | |
| 1068 | (cte.blue>>4) ; |
| 1069 | #ifdef CFG_INVERT_COLORS |
| 1070 | colreg ^= 0xFFF; |
| 1071 | #endif |
| 1072 | *cmap-- = colreg; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | padded_line = (width&0x3) ? ((width&~0x3)+4) : (width); |
| 1077 | if (width>panel_info.vl_col) |
| 1078 | width = panel_info.vl_col; |
| 1079 | if (height>panel_info.vl_row) |
| 1080 | height = panel_info.vl_row; |
| 1081 | |
| 1082 | bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset); |
| 1083 | fb = (uchar *) |
| 1084 | (lcd_base + |
| 1085 | (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1) |
| 1086 | * lcd_line_length); |
| 1087 | for (i = 0; i < height; ++i) { |
| 1088 | for (j = 0; j < width ; j++) |
| 1089 | *(fb++)=255-*(bmap++); |
| 1090 | bmap += (width - padded_line); |
| 1091 | fb -= (width + lcd_line_length); |
| 1092 | } |
| 1093 | |
| 1094 | return (0); |
| 1095 | } |
| 1096 | #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */ |
| 1097 | |
| 1098 | /*----------------------------------------------------------------------*/ |
| 1099 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1100 | #ifdef NOT_USED_SO_FAR |
| 1101 | static void lcd_disable (void) |
| 1102 | { |
| 1103 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 1104 | volatile lcd823_t *lcdp = &immr->im_lcd; |
| 1105 | |
| 1106 | #if defined(CONFIG_LWMON) |
| 1107 | { uchar c = pic_read (0x60); |
| 1108 | c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */ |
| 1109 | pic_write (0x60, c); |
| 1110 | } |
| 1111 | #elif defined(CONFIG_R360MPI) |
| 1112 | { |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 1113 | extern void r360_i2c_lcd_write (uchar data0, uchar data1); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1114 | |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 1115 | r360_i2c_lcd_write(0x10, 0x00); |
| 1116 | r360_i2c_lcd_write(0x20, 0x00); |
| 1117 | r360_i2c_lcd_write(0x30, 0x00); |
| 1118 | r360_i2c_lcd_write(0x40, 0x00); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1119 | } |
| 1120 | #endif /* CONFIG_LWMON */ |
| 1121 | /* Disable the LCD panel */ |
| 1122 | lcdp->lcd_lccr &= ~LCCR_PON; |
| 1123 | immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */ |
| 1124 | } |
| 1125 | #endif /* NOT_USED_SO_FAR */ |
| 1126 | |
| 1127 | |
| 1128 | /************************************************************************/ |
| 1129 | /* ** Chipset depending Bitmap / Logo stuff... */ |
| 1130 | /************************************************************************/ |
| 1131 | |
| 1132 | |
| 1133 | #ifdef CONFIG_LCD_LOGO |
| 1134 | static void bitmap_plot (int x, int y) |
| 1135 | { |
| 1136 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 1137 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 1138 | ushort *cmap; |
| 1139 | ushort i; |
| 1140 | uchar *bmap; |
| 1141 | uchar *fb; |
| 1142 | |
| 1143 | debug ("Logo: width %d height %d colors %d cmap %d\n", |
| 1144 | BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS, |
| 1145 | sizeof(bmp_logo_palette)/(sizeof(ushort)) |
| 1146 | ); |
| 1147 | |
| 1148 | /* Leave room for default color map */ |
| 1149 | cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]); |
| 1150 | |
| 1151 | /* Set color map */ |
| 1152 | for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) { |
| 1153 | ushort colreg = bmp_logo_palette[i]; |
| 1154 | #ifdef CFG_INVERT_COLORS |
| 1155 | colreg ^= 0xFFF; |
| 1156 | #endif |
| 1157 | *cmap++ = colreg; |
| 1158 | } |
| 1159 | |
| 1160 | bmap = &bmp_logo_bitmap[0]; |
| 1161 | fb = (char *)(lcd_base + y * lcd_line_length + x); |
| 1162 | |
| 1163 | for (i=0; i<BMP_LOGO_HEIGHT; ++i) { |
| 1164 | memcpy (fb, bmap, BMP_LOGO_WIDTH); |
| 1165 | bmap += BMP_LOGO_WIDTH; |
| 1166 | fb += panel_info.vl_col; |
| 1167 | } |
| 1168 | } |
| 1169 | #endif /* CONFIG_LCD_LOGO */ |
| 1170 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame^] | 1171 | #if (CONFIG_COMMANDS & CFG_CMD_BMP) |
| 1172 | /* |
| 1173 | Display the BMP file located at address bmp_image. |
| 1174 | Only uncompressed |
| 1175 | */ |
| 1176 | int lcd_display_bitmap(ulong bmp_image) |
| 1177 | { |
| 1178 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 1179 | volatile cpm8xx_t *cp = &(immr->im_cpm); |
| 1180 | ushort *cmap; |
| 1181 | ushort i, j; |
| 1182 | uchar *fb; |
| 1183 | bmp_image_t *bmp=(bmp_image_t *)bmp_image; |
| 1184 | uchar *bmap; |
| 1185 | ushort padded_line; |
| 1186 | unsigned long width, height; |
| 1187 | unsigned colors,bpix; |
| 1188 | unsigned long compression; |
| 1189 | |
| 1190 | if (!((bmp->header.signature[0]=='B') && |
| 1191 | (bmp->header.signature[1]=='M'))) { |
| 1192 | printf ("Error: no valid bmp image at %lx\n", bmp_image); |
| 1193 | return 1; |
| 1194 | } |
| 1195 | |
| 1196 | width = le32_to_cpu (bmp->header.width); |
| 1197 | height = le32_to_cpu (bmp->header.height); |
| 1198 | colors = 1<<le16_to_cpu (bmp->header.bit_count); |
| 1199 | compression = le32_to_cpu (bmp->header.compression); |
| 1200 | |
| 1201 | bpix = NBITS(panel_info.vl_bpix); |
| 1202 | |
| 1203 | if ((bpix != 1) && (bpix != 8)) { |
| 1204 | printf ("Error: %d bit/pixel mode not supported by U-Boot\n", |
| 1205 | bpix); |
| 1206 | return 1; |
| 1207 | } |
| 1208 | |
| 1209 | if (bpix != le16_to_cpu(bmp->header.bit_count)) { |
| 1210 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 1211 | bpix, |
| 1212 | le16_to_cpu(bmp->header.bit_count)); |
| 1213 | return 1; |
| 1214 | } |
| 1215 | |
| 1216 | if (compression!=BMP_BI_RGB) { |
| 1217 | printf ("Error: compression type %ld not supported\n", |
| 1218 | compression); |
| 1219 | return 1; |
| 1220 | } |
| 1221 | |
| 1222 | debug ("Display-bmp: %d x %d with %d colors\n", |
| 1223 | width, height, colors); |
| 1224 | |
| 1225 | if (bpix==8) { |
| 1226 | /* Fill the entire color map */ |
| 1227 | cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]); |
| 1228 | |
| 1229 | /* Set color map */ |
| 1230 | for (i = 0; i < colors; ++i) { |
| 1231 | bmp_color_table_entry_t cte = bmp->color_table[i]; |
| 1232 | ushort colreg = |
| 1233 | ((cte.red>>4) << 8) | |
| 1234 | ((cte.green>>4) << 4) | |
| 1235 | (cte.blue>>4) ; |
| 1236 | #ifdef CFG_INVERT_COLORS |
| 1237 | colreg ^= 0xFFF; |
| 1238 | #endif |
| 1239 | *cmap-- = colreg; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | padded_line = (width&0x3) ? ((width&~0x3)+4) : (width); |
| 1244 | if (width>panel_info.vl_col) |
| 1245 | width = panel_info.vl_col; |
| 1246 | if (height>panel_info.vl_row) |
| 1247 | height = panel_info.vl_row; |
| 1248 | |
| 1249 | bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset); |
| 1250 | fb = (uchar *) |
| 1251 | (lcd_base + |
| 1252 | (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1) |
| 1253 | * lcd_line_length); |
| 1254 | for (i = 0; i < height; ++i) { |
| 1255 | for (j = 0; j < width ; j++) |
| 1256 | *(fb++)=255-*(bmap++); |
| 1257 | bmap += (width - padded_line); |
| 1258 | fb -= (width + lcd_line_length); |
| 1259 | } |
| 1260 | |
| 1261 | return (0); |
| 1262 | } |
| 1263 | #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */ |
| 1264 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1265 | /*----------------------------------------------------------------------*/ |
| 1266 | |
| 1267 | static void *lcd_logo (void) |
| 1268 | { |
| 1269 | #ifdef LCD_INFO |
| 1270 | DECLARE_GLOBAL_DATA_PTR; |
| 1271 | |
| 1272 | char info[80]; |
| 1273 | char temp[32]; |
| 1274 | #endif /* LCD_INFO */ |
| 1275 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame^] | 1276 | #ifdef CONFIG_SPLASH_SCREEN |
| 1277 | char *s; |
| 1278 | ulong addr; |
| 1279 | |
| 1280 | if ((s = getenv("splashimage")) != NULL) { |
| 1281 | addr = simple_strtoul(s, NULL, 16); |
| 1282 | |
| 1283 | if (lcd_display_bitmap (addr) == 0) { |
| 1284 | return ((void *)lcd_base); |
| 1285 | } |
| 1286 | } |
| 1287 | #endif /* CONFIG_SPLASH_SCREEN */ |
| 1288 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1289 | #ifdef CONFIG_LCD_LOGO |
| 1290 | bitmap_plot (0, 0); |
| 1291 | #endif /* CONFIG_LCD_LOGO */ |
| 1292 | |
| 1293 | |
| 1294 | #ifdef LCD_INFO |
| 1295 | sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__); |
| 1296 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info)); |
| 1297 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame^] | 1298 | sprintf (info, "(C) 2003 DENX Software Engineering"); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1299 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT, |
| 1300 | info, strlen(info)); |
| 1301 | |
| 1302 | sprintf (info, " Wolfgang DENK, wd@denx.de"); |
| 1303 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2, |
| 1304 | info, strlen(info)); |
| 1305 | #ifdef LCD_INFO_BELOW_LOGO |
| 1306 | sprintf (info, "MPC823 CPU at %s MHz", |
| 1307 | strmhz(temp, gd->cpu_clk)); |
| 1308 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3, |
| 1309 | info, strlen(info)); |
| 1310 | sprintf (info, " %ld MB RAM, %ld MB Flash", |
| 1311 | gd->ram_size >> 20, |
| 1312 | gd->bd->bi_flashsize >> 20 ); |
| 1313 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4, |
| 1314 | info, strlen(info)); |
| 1315 | #else |
| 1316 | /* leave one blank line */ |
| 1317 | |
| 1318 | sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash", |
| 1319 | strmhz(temp, gd->cpu_clk), |
| 1320 | gd->ram_size >> 20, |
| 1321 | gd->bd->bi_flashsize >> 20 ); |
| 1322 | lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4, |
| 1323 | info, strlen(info)); |
| 1324 | #endif /* LCD_INFO_BELOW_LOGO */ |
| 1325 | #endif /* LCD_INFO */ |
| 1326 | |
| 1327 | #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO) |
| 1328 | return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length)); |
| 1329 | #else |
| 1330 | return ((void *)lcd_base); |
| 1331 | #endif /* CONFIG_LCD_LOGO */ |
| 1332 | } |
| 1333 | |
| 1334 | /************************************************************************/ |
| 1335 | /************************************************************************/ |
| 1336 | |
| 1337 | #endif /* CONFIG_LCD */ |