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)
65 #include <bmp_layout.h>
66 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
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_LQ084V1DG21
229 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
231 static vidinfo_t panel_info = {
232 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
233 3, 0, 0, 1, 1, 160, 3, 0, 48
234 /* wbl, vpw, lcdac, wbf */
236 #endif /* CONFIG_SHARP_LQ084V1DG21 */
238 /*----------------------------------------------------------------------*/
240 #ifdef CONFIG_HLD1045
242 * HLD1045 display, 640x480. Active, color, single scan.
244 static vidinfo_t panel_info = {
245 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
246 3, 0, 0, 1, 1, 160, 3, 0, 48
247 /* wbl, vpw, lcdac, wbf */
249 #endif /* CONFIG_HLD1045 */
250 /*----------------------------------------------------------------------*/
252 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
254 * Prime View V16C6448AC
256 static vidinfo_t panel_info = {
257 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
258 3, 0, 0, 1, 1, 144, 2, 0, 35
259 /* wbl, vpw, lcdac, wbf */
261 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
263 /*----------------------------------------------------------------------*/
265 #ifdef CONFIG_OPTREX_BW
267 * Optrex CBL50840-2 NF-FW 99 22 M5
269 * Hitachi LMG6912RPFC-00T
273 * 320x240. Black & white.
275 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
276 /* 1 - 4 grey levels, 2 bpp */
277 /* 2 - 16 grey levels, 4 bpp */
278 static vidinfo_t panel_info = {
279 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
280 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
282 #endif /* CONFIG_OPTREX_BW */
284 /*-----------------------------------------------------------------*/
285 #ifdef CONFIG_EDT32F10
287 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
289 #define LCD_BPP LCD_MONOCHROME
292 static vidinfo_t panel_info = {
293 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
294 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
297 /*----------------------------------------------------------------------*/
299 #if defined(LCD_INFO_BELOW_LOGO)
300 # define LCD_INFO_X 0
301 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
302 #elif defined(CONFIG_LCD_LOGO)
303 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
304 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
306 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
307 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
311 #define LCD_BPP LCD_COLOR8
317 #define NBITS(bit_code) (1 << (bit_code))
318 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
320 static int lcd_line_length;
322 static int lcd_color_fg;
323 static int lcd_color_bg;
325 char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
328 * Frame buffer memory information
330 static void *lcd_base; /* Start of framebuffer memory */
331 static void *lcd_console_address; /* Start of console buffer */
334 /************************************************************************/
335 /* ** CONSOLE CONSTANTS */
336 /************************************************************************/
338 #if LCD_BPP == LCD_MONOCHROME
341 * Simple color definitions
343 #define CONSOLE_COLOR_BLACK 0
344 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
349 * Simple color definitions
351 #define CONSOLE_COLOR_BLACK 0
352 #define CONSOLE_COLOR_RED 1
353 #define CONSOLE_COLOR_GREEN 2
354 #define CONSOLE_COLOR_YELLOW 3
355 #define CONSOLE_COLOR_BLUE 4
356 #define CONSOLE_COLOR_MAGENTA 5
357 #define CONSOLE_COLOR_CYAN 6
358 #define CONSOLE_COLOR_GREY 14
359 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
363 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
364 #error Default Color Map overlaps with Logo Color Map
367 /************************************************************************/
370 #define PAGE_SIZE 4096
374 /************************************************************************/
375 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
376 /************************************************************************/
378 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
379 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
382 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
384 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
385 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
386 #define CONSOLE_ROW_FIRST (lcd_console_address)
387 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
388 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
390 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
391 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
393 #if LCD_BPP == LCD_MONOCHROME
394 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
395 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
396 #elif LCD_BPP == LCD_COLOR8
397 #define COLOR_MASK(c) (c)
399 #error Unsupported LCD BPP.
402 static short console_col;
403 static short console_row;
405 /************************************************************************/
407 ulong lcd_setmem (ulong addr);
409 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
410 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
411 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
413 int lcd_init (void *lcdbase);
415 static void lcd_ctrl_init (void *lcdbase);
416 static void lcd_enable (void);
417 static void *lcd_logo (void);
418 #if LCD_BPP == LCD_COLOR8
419 static void lcd_setcolreg (ushort regno,
420 ushort red, ushort green, ushort blue);
422 #if LCD_BPP == LCD_MONOCHROME
423 static void lcd_initcolregs (void);
425 static int lcd_getbgcolor (void);
426 static void lcd_setfgcolor (int color);
427 static void lcd_setbgcolor (int color);
429 #if defined(CONFIG_RBC823)
430 void lcd_disable (void);
433 #ifdef NOT_USED_SO_FAR
434 static void lcd_getcolreg (ushort regno,
435 ushort *red, ushort *green, ushort *blue);
436 static int lcd_getfgcolor (void);
437 #endif /* NOT_USED_SO_FAR */
439 /************************************************************************/
441 /*----------------------------------------------------------------------*/
443 static void console_scrollup (void)
446 /* Copy up rows ignoring the first one */
447 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
449 /* Clear the last one */
450 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
453 * Poor attempt to optimize speed by moving "long"s.
454 * But the code is ugly, and not a bit faster :-(
456 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
457 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
458 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
459 uchar c = lcd_color_bg & 0xFF;
460 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
465 t = (ulong *)CONSOLE_ROW_LAST;
466 l = CONSOLE_ROW_SIZE / sizeof(ulong);
473 /*----------------------------------------------------------------------*/
475 static inline void console_back (void)
477 if (--console_col < 0) {
478 console_col = CONSOLE_COLS-1 ;
479 if (--console_row < 0) {
484 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
485 console_row * VIDEO_FONT_HEIGHT,
489 /*----------------------------------------------------------------------*/
491 static inline void console_newline (void)
496 /* Check if we need to scroll the terminal */
497 if (console_row >= CONSOLE_ROWS) {
498 /* Scroll everything up */
499 console_scrollup () ;
504 /*----------------------------------------------------------------------*/
506 void lcd_putc (const char c)
508 if (!lcd_is_enabled) {
514 case '\r': console_col = 0;
517 case '\n': console_newline();
520 case '\t': /* Tab (8 chars alignment) */
524 if (console_col >= CONSOLE_COLS) {
529 case '\b': console_back();
532 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
533 console_row * VIDEO_FONT_HEIGHT,
535 if (++console_col >= CONSOLE_COLS) {
543 /*----------------------------------------------------------------------*/
545 void lcd_puts (const char *s)
547 if (!lcd_is_enabled) {
557 /************************************************************************/
558 /* ** Low-Level Graphics Routines */
559 /************************************************************************/
561 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
566 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
567 off = x * (1 << LCD_BPP) % 8;
569 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
574 #if LCD_BPP == LCD_MONOCHROME
575 uchar rest = *d & -(1 << (8-off));
578 for (i=0; i<count; ++i) {
582 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
584 #if LCD_BPP == LCD_MONOCHROME
585 sym = (COLOR_MASK(lcd_color_fg) & bits) |
586 (COLOR_MASK(lcd_color_bg) & ~bits);
588 *d++ = rest | (sym >> off);
589 rest = sym << (8-off);
590 #elif LCD_BPP == LCD_COLOR8
591 for (c=0; c<8; ++c) {
592 *d++ = (bits & 0x80) ?
593 lcd_color_fg : lcd_color_bg;
599 #if LCD_BPP == LCD_MONOCHROME
600 *d = rest | (*d & ((1 << (8-off)) - 1));
605 /*----------------------------------------------------------------------*/
607 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
609 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
610 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
612 lcd_drawchars (x, y, s, strlen (s));
616 /*----------------------------------------------------------------------*/
618 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
620 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
621 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
623 lcd_drawchars (x, y, &c, 1);
627 /************************************************************************/
628 /** Small utility to check that you got the colours right */
629 /************************************************************************/
630 #ifdef LCD_TEST_PATTERN
635 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
636 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
637 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
640 static void test_pattern (void)
642 ushort v_max = panel_info.vl_row;
643 ushort h_max = panel_info.vl_col;
644 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
645 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
647 uchar *pix = (uchar *)lcd_base;
649 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
650 h_max, v_max, h_step, v_step);
652 /* WARNING: Code silently assumes 8bit/pixel */
653 for (v=0; v<v_max; ++v) {
654 uchar iy = v / v_step;
655 for (h=0; h<h_max; ++h) {
656 uchar ix = N_BLK_HOR * iy + (h/h_step);
657 *pix++ = test_colors[ix];
661 #endif /* LCD_TEST_PATTERN */
664 /************************************************************************/
665 /* ** GENERIC Initialization Routines */
666 /************************************************************************/
668 int drv_lcd_init (void)
670 DECLARE_GLOBAL_DATA_PTR;
675 lcd_base = (void *)(gd->fb_base);
677 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
679 lcd_init (lcd_base); /* LCD initialization */
681 /* Device initialization */
682 memset (&lcddev, 0, sizeof (lcddev));
684 strcpy (lcddev.name, "lcd");
685 lcddev.ext = 0; /* No extensions */
686 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
687 lcddev.putc = lcd_putc; /* 'putc' function */
688 lcddev.puts = lcd_puts; /* 'puts' function */
690 rc = device_register (&lcddev);
692 return (rc == 0) ? 1 : rc;
695 /*----------------------------------------------------------------------*/
697 int lcd_init (void *lcdbase)
699 /* Initialize the lcd controller */
700 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
702 lcd_ctrl_init (lcdbase);
704 #if LCD_BPP == LCD_MONOCHROME
705 /* Setting the palette */
708 #elif LCD_BPP == LCD_COLOR8
709 /* Setting the palette */
710 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
711 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
712 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
713 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
714 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
715 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
716 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
717 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
718 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
721 #ifndef CFG_WHITE_ON_BLACK
722 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
723 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
725 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
726 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
727 #endif /* CFG_WHITE_ON_BLACK */
729 #ifdef LCD_TEST_PATTERN
732 /* set framebuffer to background color */
733 memset ((char *)lcd_base,
734 COLOR_MASK(lcd_getbgcolor()),
735 lcd_line_length*panel_info.vl_row);
740 /* Paint the logo and retrieve LCD base address */
741 debug ("[LCD] Drawing the logo...\n");
742 lcd_console_address = lcd_logo ();
744 /* Initialize the console */
746 #ifdef LCD_INFO_BELOW_LOGO
747 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
749 console_row = 1; /* leave 1 blank line below logo */
757 /************************************************************************/
758 /* ** ROM capable initialization part - needed to reserve FB memory */
759 /************************************************************************/
762 * This is called early in the system initialization to grab memory
763 * for the LCD controller.
764 * Returns new address for monitor, after reserving LCD buffer memory
766 * Note that this is running from ROM, so no write access to global data.
768 ulong lcd_setmem (ulong addr)
771 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
773 debug ("LCD panel info: %d x %d, %d bit/pix\n",
774 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
776 size = line_length * panel_info.vl_row;
778 /* Round up to nearest full page */
779 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
781 /* Allocate pages for the frame buffer. */
784 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
790 /************************************************************************/
791 /* ----------------- chipset specific functions ----------------------- */
792 /************************************************************************/
794 static void lcd_ctrl_init (void *lcdbase)
796 volatile immap_t *immr = (immap_t *) CFG_IMMR;
797 volatile lcd823_t *lcdp = &immr->im_lcd;
802 /* Initialize the LCD control register according to the LCD
803 * parameters defined. We do everything here but enable
807 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
808 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
810 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
811 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
812 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
813 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
814 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
815 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
816 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
817 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
818 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
819 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
822 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
823 lccrtmp |= LCCR_EIEN;
826 lcdp->lcd_lccr = lccrtmp;
827 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
829 /* Initialize LCD controller bus priorities.
832 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
834 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
836 /* set SHFT/CLOCK division factor 4
837 * This needs to be set based upon display type and processor
838 * speed. The TFT displays run about 20 to 30 MHz.
839 * I was running 64 MHz processor speed.
840 * The value for this divider must be chosen so the result is
841 * an integer of the processor speed (i.e., divide by 3 with
842 * 64 MHz would be bad).
844 immr->im_clkrst.car_sccr &= ~0x1F;
845 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
847 #endif /* CONFIG_RBC823 */
849 #if defined(CONFIG_RBC823)
850 /* Enable LCD on port D.
852 immr->im_ioport.iop_pddat &= 0x0300;
853 immr->im_ioport.iop_pdpar |= 0x1CFF;
854 immr->im_ioport.iop_pddir |= 0x1CFF;
856 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
858 immr->im_cpm.cp_pbdat &= ~0x00005001;
859 immr->im_cpm.cp_pbpar &= ~0x00005001;
860 immr->im_cpm.cp_pbdir |= 0x00005001;
861 #elif !defined(CONFIG_EDT32F10)
862 /* Enable LCD on port D.
864 immr->im_ioport.iop_pdpar |= 0x1FFF;
865 immr->im_ioport.iop_pddir |= 0x1FFF;
867 /* Enable LCD_A/B/C on port B.
869 immr->im_cpm.cp_pbpar |= 0x00005001;
870 immr->im_cpm.cp_pbdir |= 0x00005001;
872 /* Enable LCD on port D.
874 immr->im_ioport.iop_pdpar |= 0x1DFF;
875 immr->im_ioport.iop_pdpar &= ~0x0200;
876 immr->im_ioport.iop_pddir |= 0x1FFF;
877 immr->im_ioport.iop_pddat |= 0x0200;
880 /* Load the physical address of the linear frame buffer
881 * into the LCD controller.
882 * BIG NOTE: This has to be modified to load A and B depending
883 * upon the split mode of the LCD.
885 lcdp->lcd_lcfaa = (ulong)lcd_base;
886 lcdp->lcd_lcfba = (ulong)lcd_base;
888 /* MORE HACKS...This must be updated according to 823 manual
889 * for different panels.
890 * Udi Finkelstein - done - see below:
891 * Note: You better not try unsupported combinations such as
892 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
896 (panel_info.vl_tft ? 8 :
897 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
898 /* use << to mult by: single scan = 1, dual scan = 2 */
899 panel_info.vl_splt) *
900 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
902 lcdp->lcd_lchcr = LCHCR_BO |
903 LCDBIT (LCHCR_AT_BIT, 4) |
904 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
907 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
908 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
909 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
914 /*----------------------------------------------------------------------*/
916 #ifdef NOT_USED_SO_FAR
918 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
920 volatile immap_t *immr = (immap_t *) CFG_IMMR;
921 volatile cpm8xx_t *cp = &(immr->im_cpm);
922 unsigned short colreg, *cmap_ptr;
924 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
927 #ifdef CFG_INVERT_COLORS
931 *red = (colreg >> 8) & 0x0F;
932 *green = (colreg >> 4) & 0x0F;
933 *blue = colreg & 0x0F;
935 #endif /* NOT_USED_SO_FAR */
937 /*----------------------------------------------------------------------*/
939 #if LCD_BPP == LCD_COLOR8
941 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
943 volatile immap_t *immr = (immap_t *) CFG_IMMR;
944 volatile cpm8xx_t *cp = &(immr->im_cpm);
945 unsigned short colreg, *cmap_ptr;
947 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
949 colreg = ((red & 0x0F) << 8) |
950 ((green & 0x0F) << 4) |
952 #ifdef CFG_INVERT_COLORS
957 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
958 regno, &(cp->lcd_cmap[regno * 2]),
960 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
962 #endif /* LCD_COLOR8 */
964 /*----------------------------------------------------------------------*/
966 #if LCD_BPP == LCD_MONOCHROME
968 void lcd_initcolregs (void)
970 volatile immap_t *immr = (immap_t *) CFG_IMMR;
971 volatile cpm8xx_t *cp = &(immr->im_cpm);
974 for (regno = 0; regno < 16; regno++) {
975 cp->lcd_cmap[regno * 2] = 0;
976 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
981 /*----------------------------------------------------------------------*/
983 static void lcd_setfgcolor (int color)
985 lcd_color_fg = color & 0x0F;
988 /*----------------------------------------------------------------------*/
990 static void lcd_setbgcolor (int color)
992 lcd_color_bg = color & 0x0F;
995 /*----------------------------------------------------------------------*/
997 #ifdef NOT_USED_SO_FAR
998 static int lcd_getfgcolor (void)
1000 return lcd_color_fg;
1002 #endif /* NOT_USED_SO_FAR */
1004 /*----------------------------------------------------------------------*/
1006 static int lcd_getbgcolor (void)
1008 return lcd_color_bg;
1011 /*----------------------------------------------------------------------*/
1013 static void lcd_enable (void)
1015 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1016 volatile lcd823_t *lcdp = &immr->im_lcd;
1018 /* Enable the LCD panel */
1019 #ifndef CONFIG_RBC823
1020 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
1022 lcdp->lcd_lccr |= LCCR_PON;
1025 /* Turn on display backlight */
1026 immr->im_cpm.cp_pbpar |= 0x00008000;
1027 immr->im_cpm.cp_pbdir |= 0x00008000;
1028 #elif defined(CONFIG_RBC823)
1029 /* Turn on display backlight */
1030 immr->im_cpm.cp_pbdat |= 0x00004000;
1033 #if defined(CONFIG_LWMON)
1034 { uchar c = pic_read (0x60);
1035 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
1036 c |= 0x04; /* Chip Enable LCD */
1038 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
1040 pic_write (0x60, c);
1042 #endif /* CONFIG_LWMON */
1044 #if defined(CONFIG_R360MPI)
1046 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1048 r360_i2c_lcd_write(0x10, 0x01);
1049 r360_i2c_lcd_write(0x20, 0x01);
1050 r360_i2c_lcd_write(0x3F, 0xFF);
1051 r360_i2c_lcd_write(0x47, 0xFF);
1053 #endif /* CONFIG_R360MPI */
1054 #ifdef CONFIG_RBC823
1055 udelay(200000); /* wait 200ms */
1056 /* Turn VEE_ON first */
1057 immr->im_cpm.cp_pbdat |= 0x00000001;
1058 udelay(200000); /* wait 200ms */
1059 /* Now turn on LCD_ON */
1060 immr->im_cpm.cp_pbdat |= 0x00001000;
1062 #ifdef CONFIG_RRVISION
1063 debug ("PC4->Output(1): enable LVDS\n");
1064 debug ("PC5->Output(0): disable PAL clock\n");
1065 immr->im_ioport.iop_pddir |= 0x1000;
1066 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1067 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1068 immr->im_ioport.iop_pcdat |= 0x0800 ;
1069 immr->im_ioport.iop_pcdat &= ~(0x0400);
1070 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1071 immr->im_ioport.iop_pdpar,
1072 immr->im_ioport.iop_pddir,
1073 immr->im_ioport.iop_pddat);
1074 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1075 immr->im_ioport.iop_pcpar,
1076 immr->im_ioport.iop_pcdir,
1077 immr->im_ioport.iop_pcdat);
1081 /*----------------------------------------------------------------------*/
1083 #if defined (CONFIG_RBC823)
1084 void lcd_disable (void)
1086 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1087 volatile lcd823_t *lcdp = &immr->im_lcd;
1089 #if defined(CONFIG_LWMON)
1090 { uchar c = pic_read (0x60);
1091 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1092 pic_write (0x60, c);
1094 #elif defined(CONFIG_R360MPI)
1096 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1098 r360_i2c_lcd_write(0x10, 0x00);
1099 r360_i2c_lcd_write(0x20, 0x00);
1100 r360_i2c_lcd_write(0x30, 0x00);
1101 r360_i2c_lcd_write(0x40, 0x00);
1103 #endif /* CONFIG_LWMON */
1104 /* Disable the LCD panel */
1105 lcdp->lcd_lccr &= ~LCCR_PON;
1106 #ifdef CONFIG_RBC823
1107 /* Turn off display backlight, VEE and LCD_ON */
1108 immr->im_cpm.cp_pbdat &= ~0x00005001;
1110 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1111 #endif /* CONFIG_RBC823 */
1113 #endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
1116 /************************************************************************/
1117 /* ** Chipset depending Bitmap / Logo stuff... */
1118 /************************************************************************/
1121 #ifdef CONFIG_LCD_LOGO
1122 static void bitmap_plot (int x, int y)
1124 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1125 volatile cpm8xx_t *cp = &(immr->im_cpm);
1131 debug ("Logo: width %d height %d colors %d cmap %d\n",
1132 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1133 sizeof(bmp_logo_palette)/(sizeof(ushort))
1136 /* Leave room for default color map */
1137 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1142 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1143 ushort colreg = bmp_logo_palette[i];
1144 #ifdef CFG_INVERT_COLORS
1150 bmap = &bmp_logo_bitmap[0];
1151 fb = (char *)(lcd_base + y * lcd_line_length + x);
1155 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1156 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1157 bmap += BMP_LOGO_WIDTH;
1158 fb += panel_info.vl_col;
1163 #endif /* CONFIG_LCD_LOGO */
1165 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
1167 * Display the BMP file located at address bmp_image.
1170 int lcd_display_bitmap(ulong bmp_image)
1172 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1173 volatile cpm8xx_t *cp = &(immr->im_cpm);
1177 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1180 unsigned long width, height;
1181 unsigned colors,bpix;
1182 unsigned long compression;
1186 if (!((bmp->header.signature[0]=='B') &&
1187 (bmp->header.signature[1]=='M'))) {
1188 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1192 width = le32_to_cpu (bmp->header.width);
1193 height = le32_to_cpu (bmp->header.height);
1194 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1195 compression = le32_to_cpu (bmp->header.compression);
1197 bpix = NBITS(panel_info.vl_bpix);
1199 if ((bpix != 1) && (bpix != 8)) {
1200 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1205 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1206 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1208 le16_to_cpu(bmp->header.bit_count));
1212 if (compression!=BMP_BI_RGB) {
1213 printf ("Error: compression type %ld not supported\n",
1218 debug ("Display-bmp: %d x %d with %d colors\n",
1219 width, height, colors);
1222 /* Fill the entire color map */
1223 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1226 for (i = 0; i < colors; ++i) {
1227 bmp_color_table_entry_t cte = bmp->color_table[i];
1229 ((cte.red>>4) << 8) |
1230 ((cte.green>>4) << 4) |
1232 #ifdef CFG_INVERT_COLORS
1241 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1242 if (width>panel_info.vl_col)
1243 width = panel_info.vl_col;
1244 if (height>panel_info.vl_row)
1245 height = panel_info.vl_row;
1247 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1250 (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
1252 for (i = 0; i < height; ++i) {
1254 for (j = 0; j < width ; j++)
1255 *(fb++)=255-*(bmap++);
1256 bmap += (width - padded_line);
1257 fb -= (width + lcd_line_length);
1262 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
1264 /*----------------------------------------------------------------------*/
1266 static void *lcd_logo (void)
1269 DECLARE_GLOBAL_DATA_PTR;
1273 #endif /* LCD_INFO */
1275 #ifdef CONFIG_SPLASH_SCREEN
1279 if ((s = getenv("splashimage")) != NULL) {
1280 addr = simple_strtoul(s, NULL, 16);
1282 if (lcd_display_bitmap (addr) == 0) {
1283 return ((void *)lcd_base);
1286 #endif /* CONFIG_SPLASH_SCREEN */
1288 #ifdef CONFIG_LCD_LOGO
1290 #endif /* CONFIG_LCD_LOGO */
1294 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1295 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1297 sprintf (info, "(C) 2003 DENX Software Engineering");
1298 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1299 info, strlen(info));
1301 sprintf (info, " Wolfgang DENK, wd@denx.de");
1302 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1303 info, strlen(info));
1304 #ifdef LCD_INFO_BELOW_LOGO
1305 sprintf (info, "MPC823 CPU at %s MHz",
1306 strmhz(temp, gd->cpu_clk));
1307 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1308 info, strlen(info));
1309 sprintf (info, " %ld MB RAM, %ld MB Flash",
1311 gd->bd->bi_flashsize >> 20 );
1312 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1313 info, strlen(info));
1315 /* leave one blank line */
1317 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1318 strmhz(temp, gd->cpu_clk),
1320 gd->bd->bi_flashsize >> 20 );
1321 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1322 info, strlen(info));
1323 #endif /* LCD_INFO_BELOW_LOGO */
1324 #endif /* LCD_INFO */
1326 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1327 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1329 return ((void *)lcd_base);
1330 #endif /* CONFIG_LCD_LOGO */
1333 /************************************************************************/
1334 /************************************************************************/
1336 #endif /* CONFIG_LCD */