2 * (C) Copyright 2001-2002
3 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 /************************************************************************/
26 /************************************************************************/
36 #include <linux/types.h>
38 #if defined(CONFIG_POST)
45 /************************************************************************/
46 /* ** CONFIG STUFF -- should be moved to board config file */
47 /************************************************************************/
48 #define CONFIG_LCD_LOGO
49 #define LCD_INFO /* Display Logo, (C) and system info */
51 #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
52 #undef CONFIG_LCD_LOGO
56 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
57 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
58 /************************************************************************/
60 /************************************************************************/
61 /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
62 /************************************************************************/
64 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
65 #include <bmp_layout.h>
66 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
68 /************************************************************************/
69 /* ** FONT AND LOGO DATA */
70 /************************************************************************/
72 #include <video_font.h> /* Get font data, width and height */
74 #ifdef CONFIG_LCD_LOGO
75 # include <bmp_logo.h> /* Get logo data, width and height */
78 /************************************************************************/
79 /************************************************************************/
82 * Information about displays we are using. This is for configuring
83 * the LCD controller and memory allocation. Someone has to know what
84 * is connected, as we can't autodetect anything.
86 #define CFG_HIGH 0 /* Pins are active high */
87 #define CFG_LOW 1 /* Pins are active low */
89 typedef struct vidinfo {
90 ushort vl_col; /* Number of columns (i.e. 640) */
91 ushort vl_row; /* Number of rows (i.e. 480) */
92 ushort vl_width; /* Width of display area in millimeters */
93 ushort vl_height; /* Height of display area in millimeters */
95 /* LCD configuration register.
97 u_char vl_clkp; /* Clock polarity */
98 u_char vl_oep; /* Output Enable polarity */
99 u_char vl_hsp; /* Horizontal Sync polarity */
100 u_char vl_vsp; /* Vertical Sync polarity */
101 u_char vl_dp; /* Data polarity */
102 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
103 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
104 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
105 u_char vl_clor; /* Color, 0 = mono, 1 = color */
106 u_char vl_tft; /* 0 = passive, 1 = TFT */
108 /* Horizontal control register. Timing from data sheet.
110 ushort vl_wbl; /* Wait between lines */
112 /* Vertical control register.
114 u_char vl_vpw; /* Vertical sync pulse width */
115 u_char vl_lcdac; /* LCD AC timing */
116 u_char vl_wbf; /* Wait between frames */
119 #define LCD_MONOCHROME 0
124 /*----------------------------------------------------------------------*/
125 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
127 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
129 #define LCD_BPP LCD_COLOR4
131 static vidinfo_t panel_info = {
132 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
133 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
134 /* wbl, vpw, lcdac, wbf */
136 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
137 /*----------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------*/
140 #ifdef CONFIG_HITACHI_SP19X001_Z1A
142 * Hitachi SP19X001-. Active, color, single scan.
144 static vidinfo_t panel_info = {
145 640, 480, 154, 116, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
146 LCD_COLOR8, 1, 0, 1, 0, 0, 0, 0, 0
147 /* wbl, vpw, lcdac, wbf */
149 #endif /* CONFIG_HITACHI_SP19X001_Z1A */
150 /*----------------------------------------------------------------------*/
152 /*----------------------------------------------------------------------*/
153 #ifdef CONFIG_NEC_NL6648AC33
155 * NEC NL6648AC33-18. Active, color, single scan.
157 static vidinfo_t panel_info = {
158 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
159 3, 0, 0, 1, 1, 144, 2, 0, 33
160 /* wbl, vpw, lcdac, wbf */
162 #endif /* CONFIG_NEC_NL6648AC33 */
163 /*----------------------------------------------------------------------*/
165 #ifdef CONFIG_NEC_NL6648BC20
167 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
169 static vidinfo_t panel_info = {
170 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
171 3, 0, 0, 1, 1, 144, 2, 0, 33
172 /* wbl, vpw, lcdac, wbf */
174 #endif /* CONFIG_NEC_NL6648BC20 */
175 /*----------------------------------------------------------------------*/
177 #ifdef CONFIG_SHARP_LQ104V7DS01
179 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
181 static vidinfo_t panel_info = {
182 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
183 3, 0, 0, 1, 1, 25, 1, 0, 33
184 /* wbl, vpw, lcdac, wbf */
186 #endif /* CONFIG_SHARP_LQ104V7DS01 */
187 /*----------------------------------------------------------------------*/
189 #ifdef CONFIG_SHARP_16x9
191 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
192 * not sure what it is.......
194 static vidinfo_t panel_info = {
195 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
196 3, 0, 0, 1, 1, 15, 4, 0, 3
198 #endif /* CONFIG_SHARP_16x9 */
199 /*----------------------------------------------------------------------*/
201 #ifdef CONFIG_SHARP_LQ057Q3DC02
203 * Sharp LQ057Q3DC02 display. Active, color, single scan.
207 static vidinfo_t panel_info = {
208 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
209 3, 0, 0, 1, 1, 15, 4, 0, 3
210 /* wbl, vpw, lcdac, wbf */
212 #define LCD_INFO_BELOW_LOGO
213 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
214 /*----------------------------------------------------------------------*/
216 #ifdef CONFIG_SHARP_LQ64D341
218 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
220 static vidinfo_t panel_info = {
221 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
222 3, 0, 0, 1, 1, 128, 16, 0, 32
223 /* wbl, vpw, lcdac, wbf */
225 #endif /* CONFIG_SHARP_LQ64D341 */
227 #ifdef CONFIG_SHARP_LQ065T9DR51U
229 * Sharp LQ065T9DR51U display, 400x240. Active, color, single scan.
231 static vidinfo_t panel_info = {
232 400, 240, 143, 79, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
233 3, 0, 0, 1, 1, 248, 4, 0, 35
234 /* wbl, vpw, lcdac, wbf */
236 #define LCD_INFO_BELOW_LOGO
237 #endif /* CONFIG_SHARP_LQ065T9DR51U */
239 #ifdef CONFIG_SHARP_LQ084V1DG21
241 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
243 static vidinfo_t panel_info = {
244 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
245 3, 0, 0, 1, 1, 160, 3, 0, 48
246 /* wbl, vpw, lcdac, wbf */
248 #endif /* CONFIG_SHARP_LQ084V1DG21 */
250 /*----------------------------------------------------------------------*/
252 #ifdef CONFIG_HLD1045
254 * HLD1045 display, 640x480. Active, color, single scan.
256 static vidinfo_t panel_info = {
257 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
258 3, 0, 0, 1, 1, 160, 3, 0, 48
259 /* wbl, vpw, lcdac, wbf */
261 #endif /* CONFIG_HLD1045 */
262 /*----------------------------------------------------------------------*/
264 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
266 * Prime View V16C6448AC
268 static vidinfo_t panel_info = {
269 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
270 3, 0, 0, 1, 1, 144, 2, 0, 35
271 /* wbl, vpw, lcdac, wbf */
273 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
275 /*----------------------------------------------------------------------*/
277 #ifdef CONFIG_OPTREX_BW
279 * Optrex CBL50840-2 NF-FW 99 22 M5
281 * Hitachi LMG6912RPFC-00T
285 * 320x240. Black & white.
287 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
288 /* 1 - 4 grey levels, 2 bpp */
289 /* 2 - 16 grey levels, 4 bpp */
290 static vidinfo_t panel_info = {
291 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
292 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
294 #endif /* CONFIG_OPTREX_BW */
296 /*-----------------------------------------------------------------*/
297 #ifdef CONFIG_EDT32F10
299 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
301 #define LCD_BPP LCD_MONOCHROME
304 static vidinfo_t panel_info = {
305 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
306 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
309 /*----------------------------------------------------------------------*/
311 #if defined(LCD_INFO_BELOW_LOGO)
312 # define LCD_INFO_X 0
313 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
314 #elif defined(CONFIG_LCD_LOGO)
315 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
316 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
318 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
319 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
323 #define LCD_BPP LCD_COLOR8
329 #define NBITS(bit_code) (1 << (bit_code))
330 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
332 static int lcd_line_length;
334 static int lcd_color_fg;
335 static int lcd_color_bg;
337 char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
340 * Frame buffer memory information
342 static void *lcd_base; /* Start of framebuffer memory */
343 static void *lcd_console_address; /* Start of console buffer */
346 /************************************************************************/
347 /* ** CONSOLE CONSTANTS */
348 /************************************************************************/
350 #if LCD_BPP == LCD_MONOCHROME
353 * Simple color definitions
355 #define CONSOLE_COLOR_BLACK 0
356 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
361 * Simple color definitions
363 #define CONSOLE_COLOR_BLACK 0
364 #define CONSOLE_COLOR_RED 1
365 #define CONSOLE_COLOR_GREEN 2
366 #define CONSOLE_COLOR_YELLOW 3
367 #define CONSOLE_COLOR_BLUE 4
368 #define CONSOLE_COLOR_MAGENTA 5
369 #define CONSOLE_COLOR_CYAN 6
370 #define CONSOLE_COLOR_GREY 14
371 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
375 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
376 #error Default Color Map overlaps with Logo Color Map
379 /************************************************************************/
382 #define PAGE_SIZE 4096
386 /************************************************************************/
387 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
388 /************************************************************************/
390 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
391 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
394 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
396 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
397 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
398 #define CONSOLE_ROW_FIRST (lcd_console_address)
399 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
400 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
402 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
403 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
405 #if LCD_BPP == LCD_MONOCHROME
406 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
407 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
408 #elif LCD_BPP == LCD_COLOR8
409 #define COLOR_MASK(c) (c)
411 #error Unsupported LCD BPP.
414 static short console_col;
415 static short console_row;
417 /************************************************************************/
419 ulong lcd_setmem (ulong addr);
421 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
422 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
423 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
425 int lcd_init (void *lcdbase);
427 static void lcd_ctrl_init (void *lcdbase);
428 static void lcd_enable (void);
429 static void *lcd_logo (void);
430 #if LCD_BPP == LCD_COLOR8
431 static void lcd_setcolreg (ushort regno,
432 ushort red, ushort green, ushort blue);
434 #if LCD_BPP == LCD_MONOCHROME
435 static void lcd_initcolregs (void);
437 static int lcd_getbgcolor (void);
438 static void lcd_setfgcolor (int color);
439 static void lcd_setbgcolor (int color);
441 #if defined(CONFIG_RBC823)
442 void lcd_disable (void);
445 #ifdef NOT_USED_SO_FAR
446 static void lcd_getcolreg (ushort regno,
447 ushort *red, ushort *green, ushort *blue);
448 static int lcd_getfgcolor (void);
449 #endif /* NOT_USED_SO_FAR */
451 /************************************************************************/
453 /*----------------------------------------------------------------------*/
455 static void console_scrollup (void)
458 /* Copy up rows ignoring the first one */
459 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
461 /* Clear the last one */
462 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
465 * Poor attempt to optimize speed by moving "long"s.
466 * But the code is ugly, and not a bit faster :-(
468 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
469 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
470 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
471 uchar c = lcd_color_bg & 0xFF;
472 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
477 t = (ulong *)CONSOLE_ROW_LAST;
478 l = CONSOLE_ROW_SIZE / sizeof(ulong);
485 /*----------------------------------------------------------------------*/
487 static inline void console_back (void)
489 if (--console_col < 0) {
490 console_col = CONSOLE_COLS-1 ;
491 if (--console_row < 0) {
496 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
497 console_row * VIDEO_FONT_HEIGHT,
501 /*----------------------------------------------------------------------*/
503 static inline void console_newline (void)
508 /* Check if we need to scroll the terminal */
509 if (console_row >= CONSOLE_ROWS) {
510 /* Scroll everything up */
511 console_scrollup () ;
516 /*----------------------------------------------------------------------*/
518 void lcd_putc (const char c)
520 if (!lcd_is_enabled) {
526 case '\r': console_col = 0;
529 case '\n': console_newline();
532 case '\t': /* Tab (8 chars alignment) */
536 if (console_col >= CONSOLE_COLS) {
541 case '\b': console_back();
544 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
545 console_row * VIDEO_FONT_HEIGHT,
547 if (++console_col >= CONSOLE_COLS) {
555 /*----------------------------------------------------------------------*/
557 void lcd_puts (const char *s)
559 if (!lcd_is_enabled) {
569 /************************************************************************/
570 /* ** Low-Level Graphics Routines */
571 /************************************************************************/
573 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
578 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
579 off = x * (1 << LCD_BPP) % 8;
581 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
586 #if LCD_BPP == LCD_MONOCHROME
587 uchar rest = *d & -(1 << (8-off));
590 for (i=0; i<count; ++i) {
594 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
596 #if LCD_BPP == LCD_MONOCHROME
597 sym = (COLOR_MASK(lcd_color_fg) & bits) |
598 (COLOR_MASK(lcd_color_bg) & ~bits);
600 *d++ = rest | (sym >> off);
601 rest = sym << (8-off);
602 #elif LCD_BPP == LCD_COLOR8
603 for (c=0; c<8; ++c) {
604 *d++ = (bits & 0x80) ?
605 lcd_color_fg : lcd_color_bg;
611 #if LCD_BPP == LCD_MONOCHROME
612 *d = rest | (*d & ((1 << (8-off)) - 1));
617 /*----------------------------------------------------------------------*/
619 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
621 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
622 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
624 lcd_drawchars (x, y, s, strlen (s));
628 /*----------------------------------------------------------------------*/
630 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
632 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
633 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
635 lcd_drawchars (x, y, &c, 1);
639 /************************************************************************/
640 /** Small utility to check that you got the colours right */
641 /************************************************************************/
642 #ifdef LCD_TEST_PATTERN
647 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
648 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
649 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
652 static void test_pattern (void)
654 ushort v_max = panel_info.vl_row;
655 ushort h_max = panel_info.vl_col;
656 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
657 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
659 uchar *pix = (uchar *)lcd_base;
661 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
662 h_max, v_max, h_step, v_step);
664 /* WARNING: Code silently assumes 8bit/pixel */
665 for (v=0; v<v_max; ++v) {
666 uchar iy = v / v_step;
667 for (h=0; h<h_max; ++h) {
668 uchar ix = N_BLK_HOR * iy + (h/h_step);
669 *pix++ = test_colors[ix];
673 #endif /* LCD_TEST_PATTERN */
676 /************************************************************************/
677 /* ** GENERIC Initialization Routines */
678 /************************************************************************/
680 int drv_lcd_init (void)
682 DECLARE_GLOBAL_DATA_PTR;
687 lcd_base = (void *)(gd->fb_base);
689 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
691 lcd_init (lcd_base); /* LCD initialization */
693 /* Device initialization */
694 memset (&lcddev, 0, sizeof (lcddev));
696 strcpy (lcddev.name, "lcd");
697 lcddev.ext = 0; /* No extensions */
698 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
699 lcddev.putc = lcd_putc; /* 'putc' function */
700 lcddev.puts = lcd_puts; /* 'puts' function */
702 rc = device_register (&lcddev);
704 return (rc == 0) ? 1 : rc;
707 /*----------------------------------------------------------------------*/
709 int lcd_init (void *lcdbase)
711 /* Initialize the lcd controller */
712 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
714 lcd_ctrl_init (lcdbase);
716 #if LCD_BPP == LCD_MONOCHROME
717 /* Setting the palette */
720 #elif LCD_BPP == LCD_COLOR8
721 /* Setting the palette */
722 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
723 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
724 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
725 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
726 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
727 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
728 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
729 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
730 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
733 #ifndef CFG_WHITE_ON_BLACK
734 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
735 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
737 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
738 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
739 #endif /* CFG_WHITE_ON_BLACK */
741 #ifdef LCD_TEST_PATTERN
744 /* set framebuffer to background color */
745 memset ((char *)lcd_base,
746 COLOR_MASK(lcd_getbgcolor()),
747 lcd_line_length*panel_info.vl_row);
752 /* Paint the logo and retrieve LCD base address */
753 debug ("[LCD] Drawing the logo...\n");
754 lcd_console_address = lcd_logo ();
756 /* Initialize the console */
758 #ifdef LCD_INFO_BELOW_LOGO
759 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
761 console_row = 1; /* leave 1 blank line below logo */
769 /************************************************************************/
770 /* ** ROM capable initialization part - needed to reserve FB memory */
771 /************************************************************************/
774 * This is called early in the system initialization to grab memory
775 * for the LCD controller.
776 * Returns new address for monitor, after reserving LCD buffer memory
778 * Note that this is running from ROM, so no write access to global data.
780 ulong lcd_setmem (ulong addr)
783 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
785 debug ("LCD panel info: %d x %d, %d bit/pix\n",
786 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
788 size = line_length * panel_info.vl_row;
790 /* Round up to nearest full page */
791 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
793 /* Allocate pages for the frame buffer. */
796 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
802 /************************************************************************/
803 /* ----------------- chipset specific functions ----------------------- */
804 /************************************************************************/
806 static void lcd_ctrl_init (void *lcdbase)
808 volatile immap_t *immr = (immap_t *) CFG_IMMR;
809 volatile lcd823_t *lcdp = &immr->im_lcd;
814 /* Initialize the LCD control register according to the LCD
815 * parameters defined. We do everything here but enable
819 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
820 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
822 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
823 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
824 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
825 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
826 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
827 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
828 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
829 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
830 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
831 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
834 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
835 lccrtmp |= LCCR_EIEN;
838 lcdp->lcd_lccr = lccrtmp;
839 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
841 /* Initialize LCD controller bus priorities.
844 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
846 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
848 /* set SHFT/CLOCK division factor 4
849 * This needs to be set based upon display type and processor
850 * speed. The TFT displays run about 20 to 30 MHz.
851 * I was running 64 MHz processor speed.
852 * The value for this divider must be chosen so the result is
853 * an integer of the processor speed (i.e., divide by 3 with
854 * 64 MHz would be bad).
856 immr->im_clkrst.car_sccr &= ~0x1F;
857 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
859 #endif /* CONFIG_RBC823 */
861 #if defined(CONFIG_RBC823)
862 /* Enable LCD on port D.
864 immr->im_ioport.iop_pddat &= 0x0300;
865 immr->im_ioport.iop_pdpar |= 0x1CFF;
866 immr->im_ioport.iop_pddir |= 0x1CFF;
868 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
870 immr->im_cpm.cp_pbdat &= ~0x00005001;
871 immr->im_cpm.cp_pbpar &= ~0x00005001;
872 immr->im_cpm.cp_pbdir |= 0x00005001;
873 #elif !defined(CONFIG_EDT32F10)
874 /* Enable LCD on port D.
876 immr->im_ioport.iop_pdpar |= 0x1FFF;
877 immr->im_ioport.iop_pddir |= 0x1FFF;
879 /* Enable LCD_A/B/C on port B.
881 immr->im_cpm.cp_pbpar |= 0x00005001;
882 immr->im_cpm.cp_pbdir |= 0x00005001;
884 /* Enable LCD on port D.
886 immr->im_ioport.iop_pdpar |= 0x1DFF;
887 immr->im_ioport.iop_pdpar &= ~0x0200;
888 immr->im_ioport.iop_pddir |= 0x1FFF;
889 immr->im_ioport.iop_pddat |= 0x0200;
892 /* Load the physical address of the linear frame buffer
893 * into the LCD controller.
894 * BIG NOTE: This has to be modified to load A and B depending
895 * upon the split mode of the LCD.
897 lcdp->lcd_lcfaa = (ulong)lcd_base;
898 lcdp->lcd_lcfba = (ulong)lcd_base;
900 /* MORE HACKS...This must be updated according to 823 manual
901 * for different panels.
902 * Udi Finkelstein - done - see below:
903 * Note: You better not try unsupported combinations such as
904 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
908 (panel_info.vl_tft ? 8 :
909 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
910 /* use << to mult by: single scan = 1, dual scan = 2 */
911 panel_info.vl_splt) *
912 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
914 lcdp->lcd_lchcr = LCHCR_BO |
915 LCDBIT (LCHCR_AT_BIT, 4) |
916 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
919 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
920 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
921 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
926 /*----------------------------------------------------------------------*/
928 #ifdef NOT_USED_SO_FAR
930 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
932 volatile immap_t *immr = (immap_t *) CFG_IMMR;
933 volatile cpm8xx_t *cp = &(immr->im_cpm);
934 unsigned short colreg, *cmap_ptr;
936 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
939 #ifdef CFG_INVERT_COLORS
943 *red = (colreg >> 8) & 0x0F;
944 *green = (colreg >> 4) & 0x0F;
945 *blue = colreg & 0x0F;
947 #endif /* NOT_USED_SO_FAR */
949 /*----------------------------------------------------------------------*/
951 #if LCD_BPP == LCD_COLOR8
953 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
955 volatile immap_t *immr = (immap_t *) CFG_IMMR;
956 volatile cpm8xx_t *cp = &(immr->im_cpm);
957 unsigned short colreg, *cmap_ptr;
959 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
961 colreg = ((red & 0x0F) << 8) |
962 ((green & 0x0F) << 4) |
964 #ifdef CFG_INVERT_COLORS
969 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
970 regno, &(cp->lcd_cmap[regno * 2]),
972 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
974 #endif /* LCD_COLOR8 */
976 /*----------------------------------------------------------------------*/
978 #if LCD_BPP == LCD_MONOCHROME
980 void lcd_initcolregs (void)
982 volatile immap_t *immr = (immap_t *) CFG_IMMR;
983 volatile cpm8xx_t *cp = &(immr->im_cpm);
986 for (regno = 0; regno < 16; regno++) {
987 cp->lcd_cmap[regno * 2] = 0;
988 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
993 /*----------------------------------------------------------------------*/
995 static void lcd_setfgcolor (int color)
997 lcd_color_fg = color & 0x0F;
1000 /*----------------------------------------------------------------------*/
1002 static void lcd_setbgcolor (int color)
1004 lcd_color_bg = color & 0x0F;
1007 /*----------------------------------------------------------------------*/
1009 #ifdef NOT_USED_SO_FAR
1010 static int lcd_getfgcolor (void)
1012 return lcd_color_fg;
1014 #endif /* NOT_USED_SO_FAR */
1016 /*----------------------------------------------------------------------*/
1018 static int lcd_getbgcolor (void)
1020 return lcd_color_bg;
1023 /*----------------------------------------------------------------------*/
1025 static void lcd_enable (void)
1027 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1028 volatile lcd823_t *lcdp = &immr->im_lcd;
1030 /* Enable the LCD panel */
1031 #ifndef CONFIG_RBC823
1032 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
1034 lcdp->lcd_lccr |= LCCR_PON;
1037 /* Turn on display backlight */
1038 immr->im_cpm.cp_pbpar |= 0x00008000;
1039 immr->im_cpm.cp_pbdir |= 0x00008000;
1040 #elif defined(CONFIG_RBC823)
1041 /* Turn on display backlight */
1042 immr->im_cpm.cp_pbdat |= 0x00004000;
1045 #if defined(CONFIG_LWMON)
1046 { uchar c = pic_read (0x60);
1047 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
1048 c |= 0x04; /* Chip Enable LCD */
1050 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
1052 pic_write (0x60, c);
1054 #endif /* CONFIG_LWMON */
1056 #if defined(CONFIG_R360MPI)
1058 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1059 unsigned long bgi, ctr;
1062 if ((p = getenv("lcdbgi")) != NULL) {
1063 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1068 if ((p = getenv("lcdctr")) != NULL) {
1069 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1074 r360_i2c_lcd_write(0x10, 0x01);
1075 r360_i2c_lcd_write(0x20, 0x01);
1076 r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1077 r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
1079 #endif /* CONFIG_R360MPI */
1080 #ifdef CONFIG_RBC823
1081 udelay(200000); /* wait 200ms */
1082 /* Turn VEE_ON first */
1083 immr->im_cpm.cp_pbdat |= 0x00000001;
1084 udelay(200000); /* wait 200ms */
1085 /* Now turn on LCD_ON */
1086 immr->im_cpm.cp_pbdat |= 0x00001000;
1088 #ifdef CONFIG_RRVISION
1089 debug ("PC4->Output(1): enable LVDS\n");
1090 debug ("PC5->Output(0): disable PAL clock\n");
1091 immr->im_ioport.iop_pddir |= 0x1000;
1092 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1093 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1094 immr->im_ioport.iop_pcdat |= 0x0800 ;
1095 immr->im_ioport.iop_pcdat &= ~(0x0400);
1096 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1097 immr->im_ioport.iop_pdpar,
1098 immr->im_ioport.iop_pddir,
1099 immr->im_ioport.iop_pddat);
1100 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1101 immr->im_ioport.iop_pcpar,
1102 immr->im_ioport.iop_pcdir,
1103 immr->im_ioport.iop_pcdat);
1107 /*----------------------------------------------------------------------*/
1109 #if defined (CONFIG_RBC823)
1110 void lcd_disable (void)
1112 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1113 volatile lcd823_t *lcdp = &immr->im_lcd;
1115 #if defined(CONFIG_LWMON)
1116 { uchar c = pic_read (0x60);
1117 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1118 pic_write (0x60, c);
1120 #elif defined(CONFIG_R360MPI)
1122 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1124 r360_i2c_lcd_write(0x10, 0x00);
1125 r360_i2c_lcd_write(0x20, 0x00);
1126 r360_i2c_lcd_write(0x30, 0x00);
1127 r360_i2c_lcd_write(0x40, 0x00);
1129 #endif /* CONFIG_LWMON */
1130 /* Disable the LCD panel */
1131 lcdp->lcd_lccr &= ~LCCR_PON;
1132 #ifdef CONFIG_RBC823
1133 /* Turn off display backlight, VEE and LCD_ON */
1134 immr->im_cpm.cp_pbdat &= ~0x00005001;
1136 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1137 #endif /* CONFIG_RBC823 */
1139 #endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
1142 /************************************************************************/
1143 /* ** Chipset depending Bitmap / Logo stuff... */
1144 /************************************************************************/
1147 #ifdef CONFIG_LCD_LOGO
1148 static void bitmap_plot (int x, int y)
1150 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1151 volatile cpm8xx_t *cp = &(immr->im_cpm);
1157 debug ("Logo: width %d height %d colors %d cmap %d\n",
1158 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1159 sizeof(bmp_logo_palette)/(sizeof(ushort))
1162 /* Leave room for default color map */
1163 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1168 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1169 ushort colreg = bmp_logo_palette[i];
1170 #ifdef CFG_INVERT_COLORS
1176 bmap = &bmp_logo_bitmap[0];
1177 fb = (char *)(lcd_base + y * lcd_line_length + x);
1181 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1182 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1183 bmap += BMP_LOGO_WIDTH;
1184 fb += panel_info.vl_col;
1189 #endif /* CONFIG_LCD_LOGO */
1191 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1193 * Display the BMP file located at address bmp_image.
1196 int lcd_display_bitmap(ulong bmp_image)
1198 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1199 volatile cpm8xx_t *cp = &(immr->im_cpm);
1203 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1206 unsigned long width, height;
1207 unsigned colors,bpix;
1208 unsigned long compression;
1212 if (!((bmp->header.signature[0]=='B') &&
1213 (bmp->header.signature[1]=='M'))) {
1214 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1218 width = le32_to_cpu (bmp->header.width);
1219 height = le32_to_cpu (bmp->header.height);
1220 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1221 compression = le32_to_cpu (bmp->header.compression);
1223 bpix = NBITS(panel_info.vl_bpix);
1225 if ((bpix != 1) && (bpix != 8)) {
1226 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1231 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1232 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1234 le16_to_cpu(bmp->header.bit_count));
1238 if (compression!=BMP_BI_RGB) {
1239 printf ("Error: compression type %ld not supported\n",
1244 debug ("Display-bmp: %d x %d with %d colors\n",
1245 width, height, colors);
1248 /* Fill the entire color map */
1249 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1252 for (i = 0; i < colors; ++i) {
1253 bmp_color_table_entry_t cte = bmp->color_table[i];
1255 ((cte.red>>4) << 8) |
1256 ((cte.green>>4) << 4) |
1258 #ifdef CFG_INVERT_COLORS
1267 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1268 if (width>panel_info.vl_col)
1269 width = panel_info.vl_col;
1270 if (height>panel_info.vl_row)
1271 height = panel_info.vl_row;
1273 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1276 (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
1278 for (i = 0; i < height; ++i) {
1280 for (j = 0; j < width ; j++)
1281 *(fb++)=255-*(bmap++);
1282 bmap += (width - padded_line);
1283 fb -= (width + lcd_line_length);
1288 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
1290 /*----------------------------------------------------------------------*/
1292 static void *lcd_logo (void)
1295 DECLARE_GLOBAL_DATA_PTR;
1299 #endif /* LCD_INFO */
1301 #ifdef CONFIG_SPLASH_SCREEN
1305 if ((s = getenv("splashimage")) != NULL) {
1306 addr = simple_strtoul(s, NULL, 16);
1308 if (lcd_display_bitmap (addr) == 0) {
1309 return ((void *)lcd_base);
1312 #endif /* CONFIG_SPLASH_SCREEN */
1314 #ifdef CONFIG_LCD_LOGO
1316 #endif /* CONFIG_LCD_LOGO */
1320 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1321 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1323 sprintf (info, "(C) 2003 DENX Software Engineering");
1324 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1325 info, strlen(info));
1327 sprintf (info, " Wolfgang DENK, wd@denx.de");
1328 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1329 info, strlen(info));
1330 #ifdef LCD_INFO_BELOW_LOGO
1331 sprintf (info, "MPC823 CPU at %s MHz",
1332 strmhz(temp, gd->cpu_clk));
1333 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1334 info, strlen(info));
1335 sprintf (info, " %ld MB RAM, %ld MB Flash",
1337 gd->bd->bi_flashsize >> 20 );
1338 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1339 info, strlen(info));
1341 /* leave one blank line */
1343 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1344 strmhz(temp, gd->cpu_clk),
1346 gd->bd->bi_flashsize >> 20 );
1347 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1348 info, strlen(info));
1349 #endif /* LCD_INFO_BELOW_LOGO */
1350 #endif /* LCD_INFO */
1352 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1353 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1355 return ((void *)lcd_base);
1356 #endif /* CONFIG_LCD_LOGO */
1359 /************************************************************************/
1360 /************************************************************************/
1362 #endif /* CONFIG_LCD */