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 /************************************************************************/
37 #include <linux/types.h>
39 #if defined(CONFIG_POST)
46 /************************************************************************/
47 /* ** CONFIG STUFF -- should be moved to board config file */
48 /************************************************************************/
49 #define CONFIG_LCD_LOGO
50 #define LCD_INFO /* Display Logo, (C) and system info */
52 #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
53 #undef CONFIG_LCD_LOGO
57 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
58 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
59 /************************************************************************/
61 /************************************************************************/
62 /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
63 /************************************************************************/
65 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
66 #include <bmp_layout.h>
67 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
69 /************************************************************************/
70 /* ** FONT AND LOGO DATA */
71 /************************************************************************/
73 #include <video_font.h> /* Get font data, width and height */
75 #ifdef CONFIG_LCD_LOGO
76 # include <bmp_logo.h> /* Get logo data, width and height */
79 /************************************************************************/
80 /************************************************************************/
83 * Information about displays we are using. This is for configuring
84 * the LCD controller and memory allocation. Someone has to know what
85 * is connected, as we can't autodetect anything.
87 #define CFG_HIGH 0 /* Pins are active high */
88 #define CFG_LOW 1 /* Pins are active low */
90 typedef struct vidinfo {
91 ushort vl_col; /* Number of columns (i.e. 640) */
92 ushort vl_row; /* Number of rows (i.e. 480) */
93 ushort vl_width; /* Width of display area in millimeters */
94 ushort vl_height; /* Height of display area in millimeters */
96 /* LCD configuration register.
98 u_char vl_clkp; /* Clock polarity */
99 u_char vl_oep; /* Output Enable polarity */
100 u_char vl_hsp; /* Horizontal Sync polarity */
101 u_char vl_vsp; /* Vertical Sync polarity */
102 u_char vl_dp; /* Data polarity */
103 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
104 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
105 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
106 u_char vl_clor; /* Color, 0 = mono, 1 = color */
107 u_char vl_tft; /* 0 = passive, 1 = TFT */
109 /* Horizontal control register. Timing from data sheet.
111 ushort vl_wbl; /* Wait between lines */
113 /* Vertical control register.
115 u_char vl_vpw; /* Vertical sync pulse width */
116 u_char vl_lcdac; /* LCD AC timing */
117 u_char vl_wbf; /* Wait between frames */
120 #define LCD_MONOCHROME 0
125 /*----------------------------------------------------------------------*/
126 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
128 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
130 #define LCD_BPP LCD_COLOR4
132 static vidinfo_t panel_info = {
133 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
134 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
135 /* wbl, vpw, lcdac, wbf */
137 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
138 /*----------------------------------------------------------------------*/
140 /*----------------------------------------------------------------------*/
141 #ifdef CONFIG_HITACHI_SP19X001_Z1A
143 * Hitachi SP19X001-. Active, color, single scan.
145 static vidinfo_t panel_info = {
146 640, 480, 154, 116, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
147 LCD_COLOR8, 1, 0, 1, 0, 0, 0, 0, 0
148 /* wbl, vpw, lcdac, wbf */
150 #endif /* CONFIG_HITACHI_SP19X001_Z1A */
151 /*----------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------*/
154 #ifdef CONFIG_NEC_NL6448AC33
156 * NEC NL6448AC33-18. Active, color, single scan.
158 static vidinfo_t panel_info = {
159 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
160 3, 0, 0, 1, 1, 144, 2, 0, 33
161 /* wbl, vpw, lcdac, wbf */
163 #endif /* CONFIG_NEC_NL6448AC33 */
164 /*----------------------------------------------------------------------*/
166 #ifdef CONFIG_NEC_NL6448BC20
168 * NEC NL6448BC20-08. 6.5", 640x480. Active, color, single scan.
170 static vidinfo_t panel_info = {
171 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
172 3, 0, 0, 1, 1, 144, 2, 0, 33
173 /* wbl, vpw, lcdac, wbf */
175 #endif /* CONFIG_NEC_NL6448BC20 */
176 /*----------------------------------------------------------------------*/
178 #ifdef CONFIG_NEC_NL6448BC33_54
180 * NEC NL6448BC33-54. 10.4", 640x480. Active, color, single scan.
182 static vidinfo_t panel_info = {
183 640, 480, 212, 158, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
184 3, 0, 0, 1, 1, 144, 2, 0, 33
185 /* wbl, vpw, lcdac, wbf */
187 #endif /* CONFIG_NEC_NL6448BC33_54 */
188 /*----------------------------------------------------------------------*/
190 #ifdef CONFIG_SHARP_LQ104V7DS01
192 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
194 static vidinfo_t panel_info = {
195 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
196 3, 0, 0, 1, 1, 25, 1, 0, 33
197 /* wbl, vpw, lcdac, wbf */
199 #endif /* CONFIG_SHARP_LQ104V7DS01 */
200 /*----------------------------------------------------------------------*/
202 #ifdef CONFIG_SHARP_16x9
204 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
205 * not sure what it is.......
207 static vidinfo_t panel_info = {
208 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
209 3, 0, 0, 1, 1, 15, 4, 0, 3
211 #endif /* CONFIG_SHARP_16x9 */
212 /*----------------------------------------------------------------------*/
214 #ifdef CONFIG_SHARP_LQ057Q3DC02
216 * Sharp LQ057Q3DC02 display. Active, color, single scan.
220 static vidinfo_t panel_info = {
221 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
222 3, 0, 0, 1, 1, 15, 4, 0, 3
223 /* wbl, vpw, lcdac, wbf */
225 #define LCD_INFO_BELOW_LOGO
226 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
227 /*----------------------------------------------------------------------*/
229 #ifdef CONFIG_SHARP_LQ64D341
231 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
233 static vidinfo_t panel_info = {
234 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
235 3, 0, 0, 1, 1, 128, 16, 0, 32
236 /* wbl, vpw, lcdac, wbf */
238 #endif /* CONFIG_SHARP_LQ64D341 */
240 #ifdef CONFIG_SHARP_LQ065T9DR51U
242 * Sharp LQ065T9DR51U display, 400x240. Active, color, single scan.
244 static vidinfo_t panel_info = {
245 400, 240, 143, 79, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
246 3, 0, 0, 1, 1, 248, 4, 0, 35
247 /* wbl, vpw, lcdac, wbf */
249 #define LCD_INFO_BELOW_LOGO
250 #endif /* CONFIG_SHARP_LQ065T9DR51U */
252 #ifdef CONFIG_SHARP_LQ084V1DG21
254 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
256 static vidinfo_t panel_info = {
257 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
258 3, 0, 0, 1, 1, 160, 3, 0, 48
259 /* wbl, vpw, lcdac, wbf */
261 #endif /* CONFIG_SHARP_LQ084V1DG21 */
263 /*----------------------------------------------------------------------*/
265 #ifdef CONFIG_HLD1045
267 * HLD1045 display, 640x480. Active, color, single scan.
269 static vidinfo_t panel_info = {
270 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
271 3, 0, 0, 1, 1, 160, 3, 0, 48
272 /* wbl, vpw, lcdac, wbf */
274 #endif /* CONFIG_HLD1045 */
275 /*----------------------------------------------------------------------*/
277 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
279 * Prime View V16C6448AC
281 static vidinfo_t panel_info = {
282 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
283 3, 0, 0, 1, 1, 144, 2, 0, 35
284 /* wbl, vpw, lcdac, wbf */
286 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
288 /*----------------------------------------------------------------------*/
290 #ifdef CONFIG_OPTREX_BW
292 * Optrex CBL50840-2 NF-FW 99 22 M5
294 * Hitachi LMG6912RPFC-00T
298 * 320x240. Black & white.
300 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
301 /* 1 - 4 grey levels, 2 bpp */
302 /* 2 - 16 grey levels, 4 bpp */
303 static vidinfo_t panel_info = {
304 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
305 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
307 #endif /* CONFIG_OPTREX_BW */
309 /*-----------------------------------------------------------------*/
310 #ifdef CONFIG_EDT32F10
312 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
314 #define LCD_BPP LCD_MONOCHROME
317 static vidinfo_t panel_info = {
318 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
319 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
322 /*----------------------------------------------------------------------*/
324 #if defined(LCD_INFO_BELOW_LOGO)
325 # define LCD_INFO_X 0
326 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
327 #elif defined(CONFIG_LCD_LOGO)
328 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
329 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
331 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
332 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
336 #define LCD_BPP LCD_COLOR8
342 #define NBITS(bit_code) (1 << (bit_code))
343 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
345 static int lcd_line_length;
347 static int lcd_color_fg;
348 static int lcd_color_bg;
350 char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
353 * Frame buffer memory information
355 static void *lcd_base; /* Start of framebuffer memory */
356 static void *lcd_console_address; /* Start of console buffer */
359 /************************************************************************/
360 /* ** CONSOLE CONSTANTS */
361 /************************************************************************/
363 #if LCD_BPP == LCD_MONOCHROME
366 * Simple color definitions
368 #define CONSOLE_COLOR_BLACK 0
369 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
374 * Simple color definitions
376 #define CONSOLE_COLOR_BLACK 0
377 #define CONSOLE_COLOR_RED 1
378 #define CONSOLE_COLOR_GREEN 2
379 #define CONSOLE_COLOR_YELLOW 3
380 #define CONSOLE_COLOR_BLUE 4
381 #define CONSOLE_COLOR_MAGENTA 5
382 #define CONSOLE_COLOR_CYAN 6
383 #define CONSOLE_COLOR_GREY 14
384 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
388 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
389 #error Default Color Map overlaps with Logo Color Map
392 /************************************************************************/
395 #define PAGE_SIZE 4096
399 /************************************************************************/
400 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
401 /************************************************************************/
403 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
404 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
407 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
409 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
410 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
411 #define CONSOLE_ROW_FIRST (lcd_console_address)
412 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
413 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
415 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
416 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
418 #if LCD_BPP == LCD_MONOCHROME
419 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
420 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
421 #elif LCD_BPP == LCD_COLOR8
422 #define COLOR_MASK(c) (c)
424 #error Unsupported LCD BPP.
427 static short console_col;
428 static short console_row;
430 /************************************************************************/
432 ulong lcd_setmem (ulong addr);
434 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
435 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
436 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
438 static int lcd_init (void *lcdbase);
440 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
441 static void lcd_ctrl_init (void *lcdbase);
442 static void lcd_enable (void);
443 static void *lcd_logo (void);
444 #if LCD_BPP == LCD_COLOR8
445 static void lcd_setcolreg (ushort regno,
446 ushort red, ushort green, ushort blue);
448 #if LCD_BPP == LCD_MONOCHROME
449 static void lcd_initcolregs (void);
451 static int lcd_getbgcolor (void);
452 static void lcd_setfgcolor (int color);
453 static void lcd_setbgcolor (int color);
455 #if defined(CONFIG_RBC823)
456 void lcd_disable (void);
459 #ifdef NOT_USED_SO_FAR
460 static void lcd_getcolreg (ushort regno,
461 ushort *red, ushort *green, ushort *blue);
462 static int lcd_getfgcolor (void);
463 #endif /* NOT_USED_SO_FAR */
465 /************************************************************************/
467 /*----------------------------------------------------------------------*/
469 static void console_scrollup (void)
472 /* Copy up rows ignoring the first one */
473 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
475 /* Clear the last one */
476 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
479 * Poor attempt to optimize speed by moving "long"s.
480 * But the code is ugly, and not a bit faster :-(
482 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
483 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
484 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
485 uchar c = lcd_color_bg & 0xFF;
486 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
491 t = (ulong *)CONSOLE_ROW_LAST;
492 l = CONSOLE_ROW_SIZE / sizeof(ulong);
499 /*----------------------------------------------------------------------*/
501 static inline void console_back (void)
503 if (--console_col < 0) {
504 console_col = CONSOLE_COLS-1 ;
505 if (--console_row < 0) {
510 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
511 console_row * VIDEO_FONT_HEIGHT,
515 /*----------------------------------------------------------------------*/
517 static inline void console_newline (void)
522 /* Check if we need to scroll the terminal */
523 if (console_row >= CONSOLE_ROWS) {
524 /* Scroll everything up */
525 console_scrollup () ;
530 /*----------------------------------------------------------------------*/
532 void lcd_putc (const char c)
534 if (!lcd_is_enabled) {
540 case '\r': console_col = 0;
543 case '\n': console_newline();
546 case '\t': /* Tab (8 chars alignment) */
550 if (console_col >= CONSOLE_COLS) {
555 case '\b': console_back();
558 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
559 console_row * VIDEO_FONT_HEIGHT,
561 if (++console_col >= CONSOLE_COLS) {
569 /*----------------------------------------------------------------------*/
571 void lcd_puts (const char *s)
573 if (!lcd_is_enabled) {
583 /************************************************************************/
584 /* ** Low-Level Graphics Routines */
585 /************************************************************************/
587 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
592 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
593 off = x * (1 << LCD_BPP) % 8;
595 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
600 #if LCD_BPP == LCD_MONOCHROME
601 uchar rest = *d & -(1 << (8-off));
604 for (i=0; i<count; ++i) {
608 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
610 #if LCD_BPP == LCD_MONOCHROME
611 sym = (COLOR_MASK(lcd_color_fg) & bits) |
612 (COLOR_MASK(lcd_color_bg) & ~bits);
614 *d++ = rest | (sym >> off);
615 rest = sym << (8-off);
616 #elif LCD_BPP == LCD_COLOR8
617 for (c=0; c<8; ++c) {
618 *d++ = (bits & 0x80) ?
619 lcd_color_fg : lcd_color_bg;
625 #if LCD_BPP == LCD_MONOCHROME
626 *d = rest | (*d & ((1 << (8-off)) - 1));
631 /*----------------------------------------------------------------------*/
633 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
635 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
636 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
638 lcd_drawchars (x, y, s, strlen (s));
642 /*----------------------------------------------------------------------*/
644 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
646 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
647 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
649 lcd_drawchars (x, y, &c, 1);
653 /************************************************************************/
654 /** Small utility to check that you got the colours right */
655 /************************************************************************/
656 #ifdef LCD_TEST_PATTERN
661 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
662 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
663 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
666 static void test_pattern (void)
668 ushort v_max = panel_info.vl_row;
669 ushort h_max = panel_info.vl_col;
670 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
671 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
673 uchar *pix = (uchar *)lcd_base;
675 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
676 h_max, v_max, h_step, v_step);
678 /* WARNING: Code silently assumes 8bit/pixel */
679 for (v=0; v<v_max; ++v) {
680 uchar iy = v / v_step;
681 for (h=0; h<h_max; ++h) {
682 uchar ix = N_BLK_HOR * iy + (h/h_step);
683 *pix++ = test_colors[ix];
687 #endif /* LCD_TEST_PATTERN */
690 /************************************************************************/
691 /* ** GENERIC Initialization Routines */
692 /************************************************************************/
694 int drv_lcd_init (void)
696 DECLARE_GLOBAL_DATA_PTR;
701 lcd_base = (void *)(gd->fb_base);
703 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
705 lcd_init (lcd_base); /* LCD initialization */
707 /* Device initialization */
708 memset (&lcddev, 0, sizeof (lcddev));
710 strcpy (lcddev.name, "lcd");
711 lcddev.ext = 0; /* No extensions */
712 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
713 lcddev.putc = lcd_putc; /* 'putc' function */
714 lcddev.puts = lcd_puts; /* 'puts' function */
716 rc = device_register (&lcddev);
718 return (rc == 0) ? 1 : rc;
721 /*----------------------------------------------------------------------*/
723 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
725 #if LCD_BPP == LCD_MONOCHROME
726 /* Setting the palette */
729 #elif LCD_BPP == LCD_COLOR8
730 /* Setting the palette */
731 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
732 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
733 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
734 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
735 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
736 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
737 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
738 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
739 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
742 #ifndef CFG_WHITE_ON_BLACK
743 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
744 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
746 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
747 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
748 #endif /* CFG_WHITE_ON_BLACK */
750 #ifdef LCD_TEST_PATTERN
753 /* set framebuffer to background color */
754 memset ((char *)lcd_base,
755 COLOR_MASK(lcd_getbgcolor()),
756 lcd_line_length*panel_info.vl_row);
758 /* Paint the logo and retrieve LCD base address */
759 debug ("[LCD] Drawing the logo...\n");
760 lcd_console_address = lcd_logo ();
769 cls, 1, 1, lcd_clear,
770 "cls - clear screen\n",
774 /*----------------------------------------------------------------------*/
776 static int lcd_init (void *lcdbase)
778 /* Initialize the lcd controller */
779 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
781 lcd_ctrl_init (lcdbase);
782 lcd_clear (NULL, 1, 1, NULL); /* dummy args */
785 /* Initialize the console */
787 #ifdef LCD_INFO_BELOW_LOGO
788 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
790 console_row = 1; /* leave 1 blank line below logo */
798 /************************************************************************/
799 /* ** ROM capable initialization part - needed to reserve FB memory */
800 /************************************************************************/
803 * This is called early in the system initialization to grab memory
804 * for the LCD controller.
805 * Returns new address for monitor, after reserving LCD buffer memory
807 * Note that this is running from ROM, so no write access to global data.
809 ulong lcd_setmem (ulong addr)
812 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
814 debug ("LCD panel info: %d x %d, %d bit/pix\n",
815 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
817 size = line_length * panel_info.vl_row;
819 /* Round up to nearest full page */
820 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
822 /* Allocate pages for the frame buffer. */
825 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
831 /************************************************************************/
832 /* ----------------- chipset specific functions ----------------------- */
833 /************************************************************************/
835 static void lcd_ctrl_init (void *lcdbase)
837 volatile immap_t *immr = (immap_t *) CFG_IMMR;
838 volatile lcd823_t *lcdp = &immr->im_lcd;
843 /* Initialize the LCD control register according to the LCD
844 * parameters defined. We do everything here but enable
848 #ifdef CONFIG_RPXLITE
849 /* This is special for RPXlite_DW Software Development Platform **[Sam]** */
850 panel_info.vl_dp = CFG_LOW;
853 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
854 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
856 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
857 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
858 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
859 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
860 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
861 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
862 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
863 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
864 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
865 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
868 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
869 lccrtmp |= LCCR_EIEN;
872 lcdp->lcd_lccr = lccrtmp;
873 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
875 /* Initialize LCD controller bus priorities.
878 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
880 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
882 /* set SHFT/CLOCK division factor 4
883 * This needs to be set based upon display type and processor
884 * speed. The TFT displays run about 20 to 30 MHz.
885 * I was running 64 MHz processor speed.
886 * The value for this divider must be chosen so the result is
887 * an integer of the processor speed (i.e., divide by 3 with
888 * 64 MHz would be bad).
890 immr->im_clkrst.car_sccr &= ~0x1F;
891 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
893 #endif /* CONFIG_RBC823 */
895 #if defined(CONFIG_RBC823)
896 /* Enable LCD on port D.
898 immr->im_ioport.iop_pddat &= 0x0300;
899 immr->im_ioport.iop_pdpar |= 0x1CFF;
900 immr->im_ioport.iop_pddir |= 0x1CFF;
902 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
904 immr->im_cpm.cp_pbdat &= ~0x00005001;
905 immr->im_cpm.cp_pbpar &= ~0x00005001;
906 immr->im_cpm.cp_pbdir |= 0x00005001;
907 #elif !defined(CONFIG_EDT32F10)
908 /* Enable LCD on port D.
910 immr->im_ioport.iop_pdpar |= 0x1FFF;
911 immr->im_ioport.iop_pddir |= 0x1FFF;
913 /* Enable LCD_A/B/C on port B.
915 immr->im_cpm.cp_pbpar |= 0x00005001;
916 immr->im_cpm.cp_pbdir |= 0x00005001;
918 /* Enable LCD on port D.
920 immr->im_ioport.iop_pdpar |= 0x1DFF;
921 immr->im_ioport.iop_pdpar &= ~0x0200;
922 immr->im_ioport.iop_pddir |= 0x1FFF;
923 immr->im_ioport.iop_pddat |= 0x0200;
926 /* Load the physical address of the linear frame buffer
927 * into the LCD controller.
928 * BIG NOTE: This has to be modified to load A and B depending
929 * upon the split mode of the LCD.
931 lcdp->lcd_lcfaa = (ulong)lcd_base;
932 lcdp->lcd_lcfba = (ulong)lcd_base;
934 /* MORE HACKS...This must be updated according to 823 manual
935 * for different panels.
936 * Udi Finkelstein - done - see below:
937 * Note: You better not try unsupported combinations such as
938 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
942 (panel_info.vl_tft ? 8 :
943 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
944 /* use << to mult by: single scan = 1, dual scan = 2 */
945 panel_info.vl_splt) *
946 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
948 lcdp->lcd_lchcr = LCHCR_BO |
949 LCDBIT (LCHCR_AT_BIT, 4) |
950 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
953 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
954 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
955 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
960 /*----------------------------------------------------------------------*/
962 #ifdef NOT_USED_SO_FAR
964 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
966 volatile immap_t *immr = (immap_t *) CFG_IMMR;
967 volatile cpm8xx_t *cp = &(immr->im_cpm);
968 unsigned short colreg, *cmap_ptr;
970 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
973 #ifdef CFG_INVERT_COLORS
977 *red = (colreg >> 8) & 0x0F;
978 *green = (colreg >> 4) & 0x0F;
979 *blue = colreg & 0x0F;
981 #endif /* NOT_USED_SO_FAR */
983 /*----------------------------------------------------------------------*/
985 #if LCD_BPP == LCD_COLOR8
987 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
989 volatile immap_t *immr = (immap_t *) CFG_IMMR;
990 volatile cpm8xx_t *cp = &(immr->im_cpm);
991 unsigned short colreg, *cmap_ptr;
993 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
995 colreg = ((red & 0x0F) << 8) |
996 ((green & 0x0F) << 4) |
998 #ifdef CFG_INVERT_COLORS
1003 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
1004 regno, &(cp->lcd_cmap[regno * 2]),
1006 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
1008 #endif /* LCD_COLOR8 */
1010 /*----------------------------------------------------------------------*/
1012 #if LCD_BPP == LCD_MONOCHROME
1014 void lcd_initcolregs (void)
1016 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1017 volatile cpm8xx_t *cp = &(immr->im_cpm);
1020 for (regno = 0; regno < 16; regno++) {
1021 cp->lcd_cmap[regno * 2] = 0;
1022 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
1027 /*----------------------------------------------------------------------*/
1029 static void lcd_setfgcolor (int color)
1031 lcd_color_fg = color & 0x0F;
1034 /*----------------------------------------------------------------------*/
1036 static void lcd_setbgcolor (int color)
1038 lcd_color_bg = color & 0x0F;
1041 /*----------------------------------------------------------------------*/
1043 #ifdef NOT_USED_SO_FAR
1044 static int lcd_getfgcolor (void)
1046 return lcd_color_fg;
1048 #endif /* NOT_USED_SO_FAR */
1050 /*----------------------------------------------------------------------*/
1052 static int lcd_getbgcolor (void)
1054 return lcd_color_bg;
1057 /*----------------------------------------------------------------------*/
1059 static void lcd_enable (void)
1061 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1062 volatile lcd823_t *lcdp = &immr->im_lcd;
1064 /* Enable the LCD panel */
1065 #ifndef CONFIG_RBC823
1066 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
1068 lcdp->lcd_lccr |= LCCR_PON;
1071 /* Turn on display backlight */
1072 immr->im_cpm.cp_pbpar |= 0x00008000;
1073 immr->im_cpm.cp_pbdir |= 0x00008000;
1074 #elif defined(CONFIG_RBC823)
1075 /* Turn on display backlight */
1076 immr->im_cpm.cp_pbdat |= 0x00004000;
1079 #if defined(CONFIG_LWMON)
1080 { uchar c = pic_read (0x60);
1081 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
1082 /* Enable LCD later in sysmon test, only if temperature is OK */
1084 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
1086 pic_write (0x60, c);
1088 #endif /* CONFIG_LWMON */
1090 #if defined(CONFIG_R360MPI)
1092 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1093 unsigned long bgi, ctr;
1096 if ((p = getenv("lcdbgi")) != NULL) {
1097 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1102 if ((p = getenv("lcdctr")) != NULL) {
1103 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1108 r360_i2c_lcd_write(0x10, 0x01);
1109 r360_i2c_lcd_write(0x20, 0x01);
1110 r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1111 r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
1113 #endif /* CONFIG_R360MPI */
1114 #ifdef CONFIG_RBC823
1115 udelay(200000); /* wait 200ms */
1116 /* Turn VEE_ON first */
1117 immr->im_cpm.cp_pbdat |= 0x00000001;
1118 udelay(200000); /* wait 200ms */
1119 /* Now turn on LCD_ON */
1120 immr->im_cpm.cp_pbdat |= 0x00001000;
1122 #ifdef CONFIG_RRVISION
1123 debug ("PC4->Output(1): enable LVDS\n");
1124 debug ("PC5->Output(0): disable PAL clock\n");
1125 immr->im_ioport.iop_pddir |= 0x1000;
1126 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1127 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1128 immr->im_ioport.iop_pcdat |= 0x0800 ;
1129 immr->im_ioport.iop_pcdat &= ~(0x0400);
1130 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1131 immr->im_ioport.iop_pdpar,
1132 immr->im_ioport.iop_pddir,
1133 immr->im_ioport.iop_pddat);
1134 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1135 immr->im_ioport.iop_pcpar,
1136 immr->im_ioport.iop_pcdir,
1137 immr->im_ioport.iop_pcdat);
1141 /*----------------------------------------------------------------------*/
1143 #if defined (CONFIG_RBC823)
1144 void lcd_disable (void)
1146 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1147 volatile lcd823_t *lcdp = &immr->im_lcd;
1149 #if defined(CONFIG_LWMON)
1150 { uchar c = pic_read (0x60);
1151 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1152 pic_write (0x60, c);
1154 #elif defined(CONFIG_R360MPI)
1156 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1158 r360_i2c_lcd_write(0x10, 0x00);
1159 r360_i2c_lcd_write(0x20, 0x00);
1160 r360_i2c_lcd_write(0x30, 0x00);
1161 r360_i2c_lcd_write(0x40, 0x00);
1163 #endif /* CONFIG_LWMON */
1164 /* Disable the LCD panel */
1165 lcdp->lcd_lccr &= ~LCCR_PON;
1166 #ifdef CONFIG_RBC823
1167 /* Turn off display backlight, VEE and LCD_ON */
1168 immr->im_cpm.cp_pbdat &= ~0x00005001;
1170 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1171 #endif /* CONFIG_RBC823 */
1173 #endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
1176 /************************************************************************/
1177 /* ** Chipset depending Bitmap / Logo stuff... */
1178 /************************************************************************/
1181 #ifdef CONFIG_LCD_LOGO
1182 static void bitmap_plot (int x, int y)
1184 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1185 volatile cpm8xx_t *cp = &(immr->im_cpm);
1191 debug ("Logo: width %d height %d colors %d cmap %d\n",
1192 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1193 sizeof(bmp_logo_palette)/(sizeof(ushort))
1196 /* Leave room for default color map */
1197 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1202 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1203 ushort colreg = bmp_logo_palette[i];
1204 #ifdef CFG_INVERT_COLORS
1210 bmap = &bmp_logo_bitmap[0];
1211 fb = (char *)(lcd_base + y * lcd_line_length + x);
1215 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1216 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1217 bmap += BMP_LOGO_WIDTH;
1218 fb += panel_info.vl_col;
1223 #endif /* CONFIG_LCD_LOGO */
1225 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1227 * Display the BMP file located at address bmp_image.
1230 int lcd_display_bitmap(ulong bmp_image, int x, int y)
1232 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1233 volatile cpm8xx_t *cp = &(immr->im_cpm);
1237 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1240 unsigned long width, height;
1241 unsigned colors,bpix;
1242 unsigned long compression;
1246 if (!((bmp->header.signature[0]=='B') &&
1247 (bmp->header.signature[1]=='M'))) {
1248 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1252 width = le32_to_cpu (bmp->header.width);
1253 height = le32_to_cpu (bmp->header.height);
1254 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1255 compression = le32_to_cpu (bmp->header.compression);
1257 bpix = NBITS(panel_info.vl_bpix);
1259 if ((bpix != 1) && (bpix != 8)) {
1260 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1265 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1266 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1268 le16_to_cpu(bmp->header.bit_count));
1272 if (compression!=BMP_BI_RGB) {
1273 printf ("Error: compression type %ld not supported\n",
1278 debug ("Display-bmp: %d x %d with %d colors\n",
1279 width, height, colors);
1282 /* Fill the entire color map */
1283 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1286 for (i = 0; i < colors; ++i) {
1287 bmp_color_table_entry_t cte = bmp->color_table[i];
1289 ((cte.red>>4) << 8) |
1290 ((cte.green>>4) << 4) |
1292 #ifdef CFG_INVERT_COLORS
1301 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1302 if ((x + width)>panel_info.vl_col)
1303 width = panel_info.vl_col - x;
1304 if ((y + height)>panel_info.vl_row)
1305 height = panel_info.vl_row - y;
1307 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1308 fb = (uchar *) (lcd_base +
1309 (y + height - 1) * lcd_line_length + x);
1310 for (i = 0; i < height; ++i) {
1312 for (j = 0; j < width ; j++)
1313 *(fb++)=255-*(bmap++);
1314 bmap += (width - padded_line);
1315 fb -= (width + lcd_line_length);
1320 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
1322 /*----------------------------------------------------------------------*/
1324 static void *lcd_logo (void)
1327 DECLARE_GLOBAL_DATA_PTR;
1331 #endif /* LCD_INFO */
1333 #ifdef CONFIG_SPLASH_SCREEN
1336 static int do_splash = 1;
1338 if (do_splash && (s = getenv("splashimage")) != NULL) {
1339 addr = simple_strtoul(s, NULL, 16);
1342 if (lcd_display_bitmap (addr, 0, 0) == 0) {
1343 return ((void *)lcd_base);
1346 #endif /* CONFIG_SPLASH_SCREEN */
1348 #ifdef CONFIG_LCD_LOGO
1350 #endif /* CONFIG_LCD_LOGO */
1354 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1355 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1357 sprintf (info, "(C) 2003 DENX Software Engineering");
1358 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1359 info, strlen(info));
1361 sprintf (info, " Wolfgang DENK, wd@denx.de");
1362 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1363 info, strlen(info));
1364 #ifdef LCD_INFO_BELOW_LOGO
1365 sprintf (info, "MPC823 CPU at %s MHz",
1366 strmhz(temp, gd->cpu_clk));
1367 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1368 info, strlen(info));
1369 sprintf (info, " %ld MB RAM, %ld MB Flash",
1371 gd->bd->bi_flashsize >> 20 );
1372 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1373 info, strlen(info));
1375 /* leave one blank line */
1377 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1378 strmhz(temp, gd->cpu_clk),
1380 gd->bd->bi_flashsize >> 20 );
1381 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1382 info, strlen(info));
1383 #endif /* LCD_INFO_BELOW_LOGO */
1384 #endif /* LCD_INFO */
1386 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1387 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1389 return ((void *)lcd_base);
1390 #endif /* CONFIG_LCD_LOGO */
1393 /************************************************************************/
1394 /************************************************************************/
1396 #endif /* CONFIG_LCD */