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_NL6448AC33
155 * NEC NL6448AC33-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_NL6448AC33 */
163 /*----------------------------------------------------------------------*/
165 #ifdef CONFIG_NEC_NL6448BC20
167 * NEC NL6448BC20-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_NL6448BC20 */
175 /*----------------------------------------------------------------------*/
177 #ifdef CONFIG_NEC_NL6448BC33_54
179 * NEC NL6448BC33-54. 10.4", 640x480. Active, color, single scan.
181 static vidinfo_t panel_info = {
182 640, 480, 212, 158, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
183 3, 0, 0, 1, 1, 144, 2, 0, 33
184 /* wbl, vpw, lcdac, wbf */
186 #endif /* CONFIG_NEC_NL6448BC33_54 */
187 /*----------------------------------------------------------------------*/
189 #ifdef CONFIG_SHARP_LQ104V7DS01
191 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
193 static vidinfo_t panel_info = {
194 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
195 3, 0, 0, 1, 1, 25, 1, 0, 33
196 /* wbl, vpw, lcdac, wbf */
198 #endif /* CONFIG_SHARP_LQ104V7DS01 */
199 /*----------------------------------------------------------------------*/
201 #ifdef CONFIG_SHARP_16x9
203 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
204 * not sure what it is.......
206 static vidinfo_t panel_info = {
207 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
208 3, 0, 0, 1, 1, 15, 4, 0, 3
210 #endif /* CONFIG_SHARP_16x9 */
211 /*----------------------------------------------------------------------*/
213 #ifdef CONFIG_SHARP_LQ057Q3DC02
215 * Sharp LQ057Q3DC02 display. Active, color, single scan.
219 static vidinfo_t panel_info = {
220 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
221 3, 0, 0, 1, 1, 15, 4, 0, 3
222 /* wbl, vpw, lcdac, wbf */
224 #define LCD_INFO_BELOW_LOGO
225 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
226 /*----------------------------------------------------------------------*/
228 #ifdef CONFIG_SHARP_LQ64D341
230 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
232 static vidinfo_t panel_info = {
233 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
234 3, 0, 0, 1, 1, 128, 16, 0, 32
235 /* wbl, vpw, lcdac, wbf */
237 #endif /* CONFIG_SHARP_LQ64D341 */
239 #ifdef CONFIG_SHARP_LQ065T9DR51U
241 * Sharp LQ065T9DR51U display, 400x240. Active, color, single scan.
243 static vidinfo_t panel_info = {
244 400, 240, 143, 79, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
245 3, 0, 0, 1, 1, 248, 4, 0, 35
246 /* wbl, vpw, lcdac, wbf */
248 #define LCD_INFO_BELOW_LOGO
249 #endif /* CONFIG_SHARP_LQ065T9DR51U */
251 #ifdef CONFIG_SHARP_LQ084V1DG21
253 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
255 static vidinfo_t panel_info = {
256 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
257 3, 0, 0, 1, 1, 160, 3, 0, 48
258 /* wbl, vpw, lcdac, wbf */
260 #endif /* CONFIG_SHARP_LQ084V1DG21 */
262 /*----------------------------------------------------------------------*/
264 #ifdef CONFIG_HLD1045
266 * HLD1045 display, 640x480. Active, color, single scan.
268 static vidinfo_t panel_info = {
269 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
270 3, 0, 0, 1, 1, 160, 3, 0, 48
271 /* wbl, vpw, lcdac, wbf */
273 #endif /* CONFIG_HLD1045 */
274 /*----------------------------------------------------------------------*/
276 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
278 * Prime View V16C6448AC
280 static vidinfo_t panel_info = {
281 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
282 3, 0, 0, 1, 1, 144, 2, 0, 35
283 /* wbl, vpw, lcdac, wbf */
285 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
287 /*----------------------------------------------------------------------*/
289 #ifdef CONFIG_OPTREX_BW
291 * Optrex CBL50840-2 NF-FW 99 22 M5
293 * Hitachi LMG6912RPFC-00T
297 * 320x240. Black & white.
299 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
300 /* 1 - 4 grey levels, 2 bpp */
301 /* 2 - 16 grey levels, 4 bpp */
302 static vidinfo_t panel_info = {
303 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
304 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
306 #endif /* CONFIG_OPTREX_BW */
308 /*-----------------------------------------------------------------*/
309 #ifdef CONFIG_EDT32F10
311 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
313 #define LCD_BPP LCD_MONOCHROME
316 static vidinfo_t panel_info = {
317 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
318 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
321 /*----------------------------------------------------------------------*/
323 #if defined(LCD_INFO_BELOW_LOGO)
324 # define LCD_INFO_X 0
325 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
326 #elif defined(CONFIG_LCD_LOGO)
327 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
328 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
330 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
331 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
335 #define LCD_BPP LCD_COLOR8
341 #define NBITS(bit_code) (1 << (bit_code))
342 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
344 static int lcd_line_length;
346 static int lcd_color_fg;
347 static int lcd_color_bg;
349 char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
352 * Frame buffer memory information
354 static void *lcd_base; /* Start of framebuffer memory */
355 static void *lcd_console_address; /* Start of console buffer */
358 /************************************************************************/
359 /* ** CONSOLE CONSTANTS */
360 /************************************************************************/
362 #if LCD_BPP == LCD_MONOCHROME
365 * Simple color definitions
367 #define CONSOLE_COLOR_BLACK 0
368 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
373 * Simple color definitions
375 #define CONSOLE_COLOR_BLACK 0
376 #define CONSOLE_COLOR_RED 1
377 #define CONSOLE_COLOR_GREEN 2
378 #define CONSOLE_COLOR_YELLOW 3
379 #define CONSOLE_COLOR_BLUE 4
380 #define CONSOLE_COLOR_MAGENTA 5
381 #define CONSOLE_COLOR_CYAN 6
382 #define CONSOLE_COLOR_GREY 14
383 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
387 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
388 #error Default Color Map overlaps with Logo Color Map
391 /************************************************************************/
394 #define PAGE_SIZE 4096
398 /************************************************************************/
399 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
400 /************************************************************************/
402 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
403 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
406 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
408 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
409 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
410 #define CONSOLE_ROW_FIRST (lcd_console_address)
411 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
412 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
414 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
415 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
417 #if LCD_BPP == LCD_MONOCHROME
418 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
419 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
420 #elif LCD_BPP == LCD_COLOR8
421 #define COLOR_MASK(c) (c)
423 #error Unsupported LCD BPP.
426 static short console_col;
427 static short console_row;
429 /************************************************************************/
431 ulong lcd_setmem (ulong addr);
433 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
434 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
435 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
437 int lcd_init (void *lcdbase);
439 static void lcd_ctrl_init (void *lcdbase);
440 static void lcd_enable (void);
441 static void *lcd_logo (void);
442 #if LCD_BPP == LCD_COLOR8
443 static void lcd_setcolreg (ushort regno,
444 ushort red, ushort green, ushort blue);
446 #if LCD_BPP == LCD_MONOCHROME
447 static void lcd_initcolregs (void);
449 static int lcd_getbgcolor (void);
450 static void lcd_setfgcolor (int color);
451 static void lcd_setbgcolor (int color);
453 #if defined(CONFIG_RBC823)
454 void lcd_disable (void);
457 #ifdef NOT_USED_SO_FAR
458 static void lcd_getcolreg (ushort regno,
459 ushort *red, ushort *green, ushort *blue);
460 static int lcd_getfgcolor (void);
461 #endif /* NOT_USED_SO_FAR */
463 /************************************************************************/
465 /*----------------------------------------------------------------------*/
467 static void console_scrollup (void)
470 /* Copy up rows ignoring the first one */
471 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
473 /* Clear the last one */
474 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
477 * Poor attempt to optimize speed by moving "long"s.
478 * But the code is ugly, and not a bit faster :-(
480 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
481 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
482 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
483 uchar c = lcd_color_bg & 0xFF;
484 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
489 t = (ulong *)CONSOLE_ROW_LAST;
490 l = CONSOLE_ROW_SIZE / sizeof(ulong);
497 /*----------------------------------------------------------------------*/
499 static inline void console_back (void)
501 if (--console_col < 0) {
502 console_col = CONSOLE_COLS-1 ;
503 if (--console_row < 0) {
508 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
509 console_row * VIDEO_FONT_HEIGHT,
513 /*----------------------------------------------------------------------*/
515 static inline void console_newline (void)
520 /* Check if we need to scroll the terminal */
521 if (console_row >= CONSOLE_ROWS) {
522 /* Scroll everything up */
523 console_scrollup () ;
528 /*----------------------------------------------------------------------*/
530 void lcd_putc (const char c)
532 if (!lcd_is_enabled) {
538 case '\r': console_col = 0;
541 case '\n': console_newline();
544 case '\t': /* Tab (8 chars alignment) */
548 if (console_col >= CONSOLE_COLS) {
553 case '\b': console_back();
556 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
557 console_row * VIDEO_FONT_HEIGHT,
559 if (++console_col >= CONSOLE_COLS) {
567 /*----------------------------------------------------------------------*/
569 void lcd_puts (const char *s)
571 if (!lcd_is_enabled) {
581 /************************************************************************/
582 /* ** Low-Level Graphics Routines */
583 /************************************************************************/
585 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
590 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
591 off = x * (1 << LCD_BPP) % 8;
593 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
598 #if LCD_BPP == LCD_MONOCHROME
599 uchar rest = *d & -(1 << (8-off));
602 for (i=0; i<count; ++i) {
606 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
608 #if LCD_BPP == LCD_MONOCHROME
609 sym = (COLOR_MASK(lcd_color_fg) & bits) |
610 (COLOR_MASK(lcd_color_bg) & ~bits);
612 *d++ = rest | (sym >> off);
613 rest = sym << (8-off);
614 #elif LCD_BPP == LCD_COLOR8
615 for (c=0; c<8; ++c) {
616 *d++ = (bits & 0x80) ?
617 lcd_color_fg : lcd_color_bg;
623 #if LCD_BPP == LCD_MONOCHROME
624 *d = rest | (*d & ((1 << (8-off)) - 1));
629 /*----------------------------------------------------------------------*/
631 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
633 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
634 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
636 lcd_drawchars (x, y, s, strlen (s));
640 /*----------------------------------------------------------------------*/
642 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
644 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
645 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
647 lcd_drawchars (x, y, &c, 1);
651 /************************************************************************/
652 /** Small utility to check that you got the colours right */
653 /************************************************************************/
654 #ifdef LCD_TEST_PATTERN
659 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
660 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
661 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
664 static void test_pattern (void)
666 ushort v_max = panel_info.vl_row;
667 ushort h_max = panel_info.vl_col;
668 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
669 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
671 uchar *pix = (uchar *)lcd_base;
673 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
674 h_max, v_max, h_step, v_step);
676 /* WARNING: Code silently assumes 8bit/pixel */
677 for (v=0; v<v_max; ++v) {
678 uchar iy = v / v_step;
679 for (h=0; h<h_max; ++h) {
680 uchar ix = N_BLK_HOR * iy + (h/h_step);
681 *pix++ = test_colors[ix];
685 #endif /* LCD_TEST_PATTERN */
688 /************************************************************************/
689 /* ** GENERIC Initialization Routines */
690 /************************************************************************/
692 int drv_lcd_init (void)
694 DECLARE_GLOBAL_DATA_PTR;
699 lcd_base = (void *)(gd->fb_base);
701 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
703 lcd_init (lcd_base); /* LCD initialization */
705 /* Device initialization */
706 memset (&lcddev, 0, sizeof (lcddev));
708 strcpy (lcddev.name, "lcd");
709 lcddev.ext = 0; /* No extensions */
710 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
711 lcddev.putc = lcd_putc; /* 'putc' function */
712 lcddev.puts = lcd_puts; /* 'puts' function */
714 rc = device_register (&lcddev);
716 return (rc == 0) ? 1 : rc;
719 /*----------------------------------------------------------------------*/
721 int lcd_init (void *lcdbase)
723 /* Initialize the lcd controller */
724 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
726 lcd_ctrl_init (lcdbase);
728 #if LCD_BPP == LCD_MONOCHROME
729 /* Setting the palette */
732 #elif LCD_BPP == LCD_COLOR8
733 /* Setting the palette */
734 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
735 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
736 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
737 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
738 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
739 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
740 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
741 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
742 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
745 #ifndef CFG_WHITE_ON_BLACK
746 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
747 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
749 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
750 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
751 #endif /* CFG_WHITE_ON_BLACK */
753 #ifdef LCD_TEST_PATTERN
756 /* set framebuffer to background color */
757 memset ((char *)lcd_base,
758 COLOR_MASK(lcd_getbgcolor()),
759 lcd_line_length*panel_info.vl_row);
764 /* Paint the logo and retrieve LCD base address */
765 debug ("[LCD] Drawing the logo...\n");
766 lcd_console_address = lcd_logo ();
768 /* Initialize the console */
770 #ifdef LCD_INFO_BELOW_LOGO
771 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
773 console_row = 1; /* leave 1 blank line below logo */
781 /************************************************************************/
782 /* ** ROM capable initialization part - needed to reserve FB memory */
783 /************************************************************************/
786 * This is called early in the system initialization to grab memory
787 * for the LCD controller.
788 * Returns new address for monitor, after reserving LCD buffer memory
790 * Note that this is running from ROM, so no write access to global data.
792 ulong lcd_setmem (ulong addr)
795 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
797 debug ("LCD panel info: %d x %d, %d bit/pix\n",
798 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
800 size = line_length * panel_info.vl_row;
802 /* Round up to nearest full page */
803 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
805 /* Allocate pages for the frame buffer. */
808 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
814 /************************************************************************/
815 /* ----------------- chipset specific functions ----------------------- */
816 /************************************************************************/
818 static void lcd_ctrl_init (void *lcdbase)
820 volatile immap_t *immr = (immap_t *) CFG_IMMR;
821 volatile lcd823_t *lcdp = &immr->im_lcd;
826 /* Initialize the LCD control register according to the LCD
827 * parameters defined. We do everything here but enable
831 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
832 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
834 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
835 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
836 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
837 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
838 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
839 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
840 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
841 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
842 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
843 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
846 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
847 lccrtmp |= LCCR_EIEN;
850 lcdp->lcd_lccr = lccrtmp;
851 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
853 /* Initialize LCD controller bus priorities.
856 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
858 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
860 /* set SHFT/CLOCK division factor 4
861 * This needs to be set based upon display type and processor
862 * speed. The TFT displays run about 20 to 30 MHz.
863 * I was running 64 MHz processor speed.
864 * The value for this divider must be chosen so the result is
865 * an integer of the processor speed (i.e., divide by 3 with
866 * 64 MHz would be bad).
868 immr->im_clkrst.car_sccr &= ~0x1F;
869 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
871 #endif /* CONFIG_RBC823 */
873 #if defined(CONFIG_RBC823)
874 /* Enable LCD on port D.
876 immr->im_ioport.iop_pddat &= 0x0300;
877 immr->im_ioport.iop_pdpar |= 0x1CFF;
878 immr->im_ioport.iop_pddir |= 0x1CFF;
880 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
882 immr->im_cpm.cp_pbdat &= ~0x00005001;
883 immr->im_cpm.cp_pbpar &= ~0x00005001;
884 immr->im_cpm.cp_pbdir |= 0x00005001;
885 #elif !defined(CONFIG_EDT32F10)
886 /* Enable LCD on port D.
888 immr->im_ioport.iop_pdpar |= 0x1FFF;
889 immr->im_ioport.iop_pddir |= 0x1FFF;
891 /* Enable LCD_A/B/C on port B.
893 immr->im_cpm.cp_pbpar |= 0x00005001;
894 immr->im_cpm.cp_pbdir |= 0x00005001;
896 /* Enable LCD on port D.
898 immr->im_ioport.iop_pdpar |= 0x1DFF;
899 immr->im_ioport.iop_pdpar &= ~0x0200;
900 immr->im_ioport.iop_pddir |= 0x1FFF;
901 immr->im_ioport.iop_pddat |= 0x0200;
904 /* Load the physical address of the linear frame buffer
905 * into the LCD controller.
906 * BIG NOTE: This has to be modified to load A and B depending
907 * upon the split mode of the LCD.
909 lcdp->lcd_lcfaa = (ulong)lcd_base;
910 lcdp->lcd_lcfba = (ulong)lcd_base;
912 /* MORE HACKS...This must be updated according to 823 manual
913 * for different panels.
914 * Udi Finkelstein - done - see below:
915 * Note: You better not try unsupported combinations such as
916 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
920 (panel_info.vl_tft ? 8 :
921 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
922 /* use << to mult by: single scan = 1, dual scan = 2 */
923 panel_info.vl_splt) *
924 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
926 lcdp->lcd_lchcr = LCHCR_BO |
927 LCDBIT (LCHCR_AT_BIT, 4) |
928 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
931 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
932 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
933 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
938 /*----------------------------------------------------------------------*/
940 #ifdef NOT_USED_SO_FAR
942 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
944 volatile immap_t *immr = (immap_t *) CFG_IMMR;
945 volatile cpm8xx_t *cp = &(immr->im_cpm);
946 unsigned short colreg, *cmap_ptr;
948 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
951 #ifdef CFG_INVERT_COLORS
955 *red = (colreg >> 8) & 0x0F;
956 *green = (colreg >> 4) & 0x0F;
957 *blue = colreg & 0x0F;
959 #endif /* NOT_USED_SO_FAR */
961 /*----------------------------------------------------------------------*/
963 #if LCD_BPP == LCD_COLOR8
965 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
967 volatile immap_t *immr = (immap_t *) CFG_IMMR;
968 volatile cpm8xx_t *cp = &(immr->im_cpm);
969 unsigned short colreg, *cmap_ptr;
971 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
973 colreg = ((red & 0x0F) << 8) |
974 ((green & 0x0F) << 4) |
976 #ifdef CFG_INVERT_COLORS
981 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
982 regno, &(cp->lcd_cmap[regno * 2]),
984 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
986 #endif /* LCD_COLOR8 */
988 /*----------------------------------------------------------------------*/
990 #if LCD_BPP == LCD_MONOCHROME
992 void lcd_initcolregs (void)
994 volatile immap_t *immr = (immap_t *) CFG_IMMR;
995 volatile cpm8xx_t *cp = &(immr->im_cpm);
998 for (regno = 0; regno < 16; regno++) {
999 cp->lcd_cmap[regno * 2] = 0;
1000 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
1005 /*----------------------------------------------------------------------*/
1007 static void lcd_setfgcolor (int color)
1009 lcd_color_fg = color & 0x0F;
1012 /*----------------------------------------------------------------------*/
1014 static void lcd_setbgcolor (int color)
1016 lcd_color_bg = color & 0x0F;
1019 /*----------------------------------------------------------------------*/
1021 #ifdef NOT_USED_SO_FAR
1022 static int lcd_getfgcolor (void)
1024 return lcd_color_fg;
1026 #endif /* NOT_USED_SO_FAR */
1028 /*----------------------------------------------------------------------*/
1030 static int lcd_getbgcolor (void)
1032 return lcd_color_bg;
1035 /*----------------------------------------------------------------------*/
1037 static void lcd_enable (void)
1039 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1040 volatile lcd823_t *lcdp = &immr->im_lcd;
1042 /* Enable the LCD panel */
1043 #ifndef CONFIG_RBC823
1044 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
1046 lcdp->lcd_lccr |= LCCR_PON;
1049 /* Turn on display backlight */
1050 immr->im_cpm.cp_pbpar |= 0x00008000;
1051 immr->im_cpm.cp_pbdir |= 0x00008000;
1052 #elif defined(CONFIG_RBC823)
1053 /* Turn on display backlight */
1054 immr->im_cpm.cp_pbdat |= 0x00004000;
1057 #if defined(CONFIG_LWMON)
1058 { uchar c = pic_read (0x60);
1059 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
1060 c |= 0x04; /* Chip Enable LCD */
1062 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
1064 pic_write (0x60, c);
1066 #endif /* CONFIG_LWMON */
1068 #if defined(CONFIG_R360MPI)
1070 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1071 unsigned long bgi, ctr;
1074 if ((p = getenv("lcdbgi")) != NULL) {
1075 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1080 if ((p = getenv("lcdctr")) != NULL) {
1081 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1086 r360_i2c_lcd_write(0x10, 0x01);
1087 r360_i2c_lcd_write(0x20, 0x01);
1088 r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1089 r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
1091 #endif /* CONFIG_R360MPI */
1092 #ifdef CONFIG_RBC823
1093 udelay(200000); /* wait 200ms */
1094 /* Turn VEE_ON first */
1095 immr->im_cpm.cp_pbdat |= 0x00000001;
1096 udelay(200000); /* wait 200ms */
1097 /* Now turn on LCD_ON */
1098 immr->im_cpm.cp_pbdat |= 0x00001000;
1100 #ifdef CONFIG_RRVISION
1101 debug ("PC4->Output(1): enable LVDS\n");
1102 debug ("PC5->Output(0): disable PAL clock\n");
1103 immr->im_ioport.iop_pddir |= 0x1000;
1104 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1105 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1106 immr->im_ioport.iop_pcdat |= 0x0800 ;
1107 immr->im_ioport.iop_pcdat &= ~(0x0400);
1108 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1109 immr->im_ioport.iop_pdpar,
1110 immr->im_ioport.iop_pddir,
1111 immr->im_ioport.iop_pddat);
1112 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1113 immr->im_ioport.iop_pcpar,
1114 immr->im_ioport.iop_pcdir,
1115 immr->im_ioport.iop_pcdat);
1119 /*----------------------------------------------------------------------*/
1121 #if defined (CONFIG_RBC823)
1122 void lcd_disable (void)
1124 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1125 volatile lcd823_t *lcdp = &immr->im_lcd;
1127 #if defined(CONFIG_LWMON)
1128 { uchar c = pic_read (0x60);
1129 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1130 pic_write (0x60, c);
1132 #elif defined(CONFIG_R360MPI)
1134 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1136 r360_i2c_lcd_write(0x10, 0x00);
1137 r360_i2c_lcd_write(0x20, 0x00);
1138 r360_i2c_lcd_write(0x30, 0x00);
1139 r360_i2c_lcd_write(0x40, 0x00);
1141 #endif /* CONFIG_LWMON */
1142 /* Disable the LCD panel */
1143 lcdp->lcd_lccr &= ~LCCR_PON;
1144 #ifdef CONFIG_RBC823
1145 /* Turn off display backlight, VEE and LCD_ON */
1146 immr->im_cpm.cp_pbdat &= ~0x00005001;
1148 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1149 #endif /* CONFIG_RBC823 */
1151 #endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
1154 /************************************************************************/
1155 /* ** Chipset depending Bitmap / Logo stuff... */
1156 /************************************************************************/
1159 #ifdef CONFIG_LCD_LOGO
1160 static void bitmap_plot (int x, int y)
1162 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1163 volatile cpm8xx_t *cp = &(immr->im_cpm);
1169 debug ("Logo: width %d height %d colors %d cmap %d\n",
1170 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1171 sizeof(bmp_logo_palette)/(sizeof(ushort))
1174 /* Leave room for default color map */
1175 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1180 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1181 ushort colreg = bmp_logo_palette[i];
1182 #ifdef CFG_INVERT_COLORS
1188 bmap = &bmp_logo_bitmap[0];
1189 fb = (char *)(lcd_base + y * lcd_line_length + x);
1193 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1194 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1195 bmap += BMP_LOGO_WIDTH;
1196 fb += panel_info.vl_col;
1201 #endif /* CONFIG_LCD_LOGO */
1203 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1205 * Display the BMP file located at address bmp_image.
1208 int lcd_display_bitmap(ulong bmp_image, int x, int y)
1210 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1211 volatile cpm8xx_t *cp = &(immr->im_cpm);
1215 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1218 unsigned long width, height;
1219 unsigned colors,bpix;
1220 unsigned long compression;
1224 if (!((bmp->header.signature[0]=='B') &&
1225 (bmp->header.signature[1]=='M'))) {
1226 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1230 width = le32_to_cpu (bmp->header.width);
1231 height = le32_to_cpu (bmp->header.height);
1232 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1233 compression = le32_to_cpu (bmp->header.compression);
1235 bpix = NBITS(panel_info.vl_bpix);
1237 if ((bpix != 1) && (bpix != 8)) {
1238 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1243 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1244 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1246 le16_to_cpu(bmp->header.bit_count));
1250 if (compression!=BMP_BI_RGB) {
1251 printf ("Error: compression type %ld not supported\n",
1256 debug ("Display-bmp: %d x %d with %d colors\n",
1257 width, height, colors);
1260 /* Fill the entire color map */
1261 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1264 for (i = 0; i < colors; ++i) {
1265 bmp_color_table_entry_t cte = bmp->color_table[i];
1267 ((cte.red>>4) << 8) |
1268 ((cte.green>>4) << 4) |
1270 #ifdef CFG_INVERT_COLORS
1279 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1280 if ((x + width)>panel_info.vl_col)
1281 width = panel_info.vl_col - x;
1282 if ((y + height)>panel_info.vl_row)
1283 height = panel_info.vl_row - y;
1285 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1286 fb = (uchar *) (lcd_base +
1287 (y + height - 1) * lcd_line_length + x);
1288 for (i = 0; i < height; ++i) {
1290 for (j = 0; j < width ; j++)
1291 *(fb++)=255-*(bmap++);
1292 bmap += (width - padded_line);
1293 fb -= (width + lcd_line_length);
1298 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
1300 /*----------------------------------------------------------------------*/
1302 static void *lcd_logo (void)
1305 DECLARE_GLOBAL_DATA_PTR;
1309 #endif /* LCD_INFO */
1311 #ifdef CONFIG_SPLASH_SCREEN
1315 if ((s = getenv("splashimage")) != NULL) {
1316 addr = simple_strtoul(s, NULL, 16);
1318 if (lcd_display_bitmap (addr, 0, 0) == 0) {
1319 return ((void *)lcd_base);
1322 #endif /* CONFIG_SPLASH_SCREEN */
1324 #ifdef CONFIG_LCD_LOGO
1326 #endif /* CONFIG_LCD_LOGO */
1330 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1331 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1333 sprintf (info, "(C) 2003 DENX Software Engineering");
1334 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1335 info, strlen(info));
1337 sprintf (info, " Wolfgang DENK, wd@denx.de");
1338 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1339 info, strlen(info));
1340 #ifdef LCD_INFO_BELOW_LOGO
1341 sprintf (info, "MPC823 CPU at %s MHz",
1342 strmhz(temp, gd->cpu_clk));
1343 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1344 info, strlen(info));
1345 sprintf (info, " %ld MB RAM, %ld MB Flash",
1347 gd->bd->bi_flashsize >> 20 );
1348 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1349 info, strlen(info));
1351 /* leave one blank line */
1353 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1354 strmhz(temp, gd->cpu_clk),
1356 gd->bd->bi_flashsize >> 20 );
1357 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1358 info, strlen(info));
1359 #endif /* LCD_INFO_BELOW_LOGO */
1360 #endif /* LCD_INFO */
1362 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1363 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1365 return ((void *)lcd_base);
1366 #endif /* CONFIG_LCD_LOGO */
1369 /************************************************************************/
1370 /************************************************************************/
1372 #endif /* CONFIG_LCD */