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 /************************************************************************/
34 #include <linux/types.h>
36 #if defined(CONFIG_POST)
43 /************************************************************************/
44 /* ** CONFIG STUFF -- should be moved to board config file */
45 /************************************************************************/
46 #define CONFIG_LCD_LOGO
47 #define LCD_INFO /* Display Logo, (C) and system info */
49 #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
50 #undef CONFIG_LCD_LOGO
54 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
55 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
56 /************************************************************************/
58 /************************************************************************/
59 /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
60 /************************************************************************/
62 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
63 #include <bmp_layout.h>
64 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
66 /************************************************************************/
67 /* ** FONT AND LOGO DATA */
68 /************************************************************************/
70 #include <video_font.h> /* Get font data, width and height */
72 #ifdef CONFIG_LCD_LOGO
73 # include <bmp_logo.h> /* Get logo data, width and height */
76 /************************************************************************/
77 /************************************************************************/
80 * Information about displays we are using. This is for configuring
81 * the LCD controller and memory allocation. Someone has to know what
82 * is connected, as we can't autodetect anything.
84 #define CFG_HIGH 0 /* Pins are active high */
85 #define CFG_LOW 1 /* Pins are active low */
87 typedef struct vidinfo {
88 ushort vl_col; /* Number of columns (i.e. 640) */
89 ushort vl_row; /* Number of rows (i.e. 480) */
90 ushort vl_width; /* Width of display area in millimeters */
91 ushort vl_height; /* Height of display area in millimeters */
93 /* LCD configuration register.
95 u_char vl_clkp; /* Clock polarity */
96 u_char vl_oep; /* Output Enable polarity */
97 u_char vl_hsp; /* Horizontal Sync polarity */
98 u_char vl_vsp; /* Vertical Sync polarity */
99 u_char vl_dp; /* Data polarity */
100 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
101 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
102 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
103 u_char vl_clor; /* Color, 0 = mono, 1 = color */
104 u_char vl_tft; /* 0 = passive, 1 = TFT */
106 /* Horizontal control register. Timing from data sheet.
108 ushort vl_wbl; /* Wait between lines */
110 /* Vertical control register.
112 u_char vl_vpw; /* Vertical sync pulse width */
113 u_char vl_lcdac; /* LCD AC timing */
114 u_char vl_wbf; /* Wait between frames */
117 #define LCD_MONOCHROME 0
122 /*----------------------------------------------------------------------*/
123 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
125 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
127 #define LCD_BPP LCD_COLOR4
129 static vidinfo_t panel_info = {
130 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
131 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
132 /* wbl, vpw, lcdac, wbf */
134 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
135 /*----------------------------------------------------------------------*/
137 /*----------------------------------------------------------------------*/
138 #ifdef CONFIG_NEC_NL6648AC33
140 * NEC NL6648AC33-18. Active, color, single scan.
142 static vidinfo_t panel_info = {
143 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
144 3, 0, 0, 1, 1, 144, 2, 0, 33
145 /* wbl, vpw, lcdac, wbf */
147 #endif /* CONFIG_NEC_NL6648AC33 */
148 /*----------------------------------------------------------------------*/
150 #ifdef CONFIG_NEC_NL6648BC20
152 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
154 static vidinfo_t panel_info = {
155 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
156 3, 0, 0, 1, 1, 144, 2, 0, 33
157 /* wbl, vpw, lcdac, wbf */
159 #endif /* CONFIG_NEC_NL6648BC20 */
160 /*----------------------------------------------------------------------*/
162 #ifdef CONFIG_SHARP_LQ104V7DS01
164 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
166 static vidinfo_t panel_info = {
167 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
168 3, 0, 0, 1, 1, 25, 1, 0, 33
169 /* wbl, vpw, lcdac, wbf */
171 #endif /* CONFIG_SHARP_LQ104V7DS01 */
172 /*----------------------------------------------------------------------*/
174 #ifdef CONFIG_SHARP_16x9
176 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
177 * not sure what it is.......
179 static vidinfo_t panel_info = {
180 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
181 3, 0, 0, 1, 1, 15, 4, 0, 3
183 #endif /* CONFIG_SHARP_16x9 */
184 /*----------------------------------------------------------------------*/
186 #ifdef CONFIG_SHARP_LQ057Q3DC02
188 * Sharp LQ057Q3DC02 display. Active, color, single scan.
192 static vidinfo_t panel_info = {
193 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
194 3, 0, 0, 1, 1, 15, 4, 0, 3
195 /* wbl, vpw, lcdac, wbf */
197 #define LCD_INFO_BELOW_LOGO
198 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
199 /*----------------------------------------------------------------------*/
201 #ifdef CONFIG_SHARP_LQ64D341
203 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
205 static vidinfo_t panel_info = {
206 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
207 3, 0, 0, 1, 1, 128, 16, 0, 32
208 /* wbl, vpw, lcdac, wbf */
210 #endif /* CONFIG_SHARP_LQ64D341 */
212 #ifdef CONFIG_SHARP_LQ084V1DG21
214 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
216 static vidinfo_t panel_info = {
217 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
218 3, 0, 0, 1, 1, 160, 3, 0, 48
219 /* wbl, vpw, lcdac, wbf */
221 #endif /* CONFIG_SHARP_LQ084V1DG21 */
223 /*----------------------------------------------------------------------*/
225 #ifdef CONFIG_HLD1045
227 * HLD1045 display, 640x480. Active, color, single scan.
229 static vidinfo_t panel_info = {
230 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
231 3, 0, 0, 1, 1, 160, 3, 0, 48
232 /* wbl, vpw, lcdac, wbf */
234 #endif /* CONFIG_HLD1045 */
235 /*----------------------------------------------------------------------*/
237 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
239 * Prime View V16C6448AC
241 static vidinfo_t panel_info = {
242 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
243 3, 0, 0, 1, 1, 144, 2, 0, 35
244 /* wbl, vpw, lcdac, wbf */
246 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
248 /*----------------------------------------------------------------------*/
250 #ifdef CONFIG_OPTREX_BW
252 * Optrex CBL50840-2 NF-FW 99 22 M5
254 * Hitachi LMG6912RPFC-00T
258 * 320x240. Black & white.
260 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
261 /* 1 - 4 grey levels, 2 bpp */
262 /* 2 - 16 grey levels, 4 bpp */
263 static vidinfo_t panel_info = {
264 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
265 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
267 #endif /* CONFIG_OPTREX_BW */
269 /*-----------------------------------------------------------------*/
270 #ifdef CONFIG_EDT32F10
272 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
274 #define LCD_BPP LCD_MONOCHROME
277 static vidinfo_t panel_info = {
278 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
279 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
282 /*----------------------------------------------------------------------*/
284 #if defined(LCD_INFO_BELOW_LOGO)
285 # define LCD_INFO_X 0
286 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
287 #elif defined(CONFIG_LCD_LOGO)
288 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
289 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
291 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
292 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
296 #define LCD_BPP LCD_COLOR8
302 #define NBITS(bit_code) (1 << (bit_code))
303 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
305 static int lcd_line_length;
307 static int lcd_color_fg;
308 static int lcd_color_bg;
310 static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
313 * Frame buffer memory information
315 static void *lcd_base; /* Start of framebuffer memory */
316 static void *lcd_console_address; /* Start of console buffer */
319 /************************************************************************/
320 /* ** CONSOLE CONSTANTS */
321 /************************************************************************/
323 #if LCD_BPP == LCD_MONOCHROME
326 * Simple color definitions
328 #define CONSOLE_COLOR_BLACK 0
329 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
334 * Simple color definitions
336 #define CONSOLE_COLOR_BLACK 0
337 #define CONSOLE_COLOR_RED 1
338 #define CONSOLE_COLOR_GREEN 2
339 #define CONSOLE_COLOR_YELLOW 3
340 #define CONSOLE_COLOR_BLUE 4
341 #define CONSOLE_COLOR_MAGENTA 5
342 #define CONSOLE_COLOR_CYAN 6
343 #define CONSOLE_COLOR_GREY 14
344 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
348 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
349 #error Default Color Map overlaps with Logo Color Map
352 /************************************************************************/
355 #define PAGE_SIZE 4096
359 /************************************************************************/
360 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
361 /************************************************************************/
363 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
364 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
367 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
369 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
370 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
371 #define CONSOLE_ROW_FIRST (lcd_console_address)
372 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
373 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
375 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
376 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
378 #if LCD_BPP == LCD_MONOCHROME
379 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
380 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
381 #elif LCD_BPP == LCD_COLOR8
382 #define COLOR_MASK(c) (c)
384 #error Unsupported LCD BPP.
387 static short console_col;
388 static short console_row;
390 /************************************************************************/
392 ulong lcd_setmem (ulong addr);
394 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
395 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
396 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
398 static int lcd_init (void *lcdbase);
399 static void lcd_ctrl_init (void *lcdbase);
400 static void lcd_enable (void);
401 static void *lcd_logo (void);
402 #if LCD_BPP == LCD_COLOR8
403 static void lcd_setcolreg (ushort regno,
404 ushort red, ushort green, ushort blue);
406 #if LCD_BPP == LCD_MONOCHROME
407 static void lcd_initcolregs (void);
409 static int lcd_getbgcolor (void);
410 static void lcd_setfgcolor (int color);
411 static void lcd_setbgcolor (int color);
413 #ifdef NOT_USED_SO_FAR
414 static void lcd_disable (void);
415 static void lcd_getcolreg (ushort regno,
416 ushort *red, ushort *green, ushort *blue);
417 static int lcd_getfgcolor (void);
418 #endif /* NOT_USED_SO_FAR */
420 /************************************************************************/
422 /*----------------------------------------------------------------------*/
424 static void console_scrollup (void)
427 /* Copy up rows ignoring the first one */
428 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
430 /* Clear the last one */
431 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
434 * Poor attempt to optimize speed by moving "long"s.
435 * But the code is ugly, and not a bit faster :-(
437 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
438 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
439 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
440 uchar c = lcd_color_bg & 0xFF;
441 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
446 t = (ulong *)CONSOLE_ROW_LAST;
447 l = CONSOLE_ROW_SIZE / sizeof(ulong);
454 /*----------------------------------------------------------------------*/
456 static inline void console_back (void)
458 if (--console_col < 0) {
459 console_col = CONSOLE_COLS-1 ;
460 if (--console_row < 0) {
465 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
466 console_row * VIDEO_FONT_HEIGHT,
470 /*----------------------------------------------------------------------*/
472 static inline void console_newline (void)
477 /* Check if we need to scroll the terminal */
478 if (console_row >= CONSOLE_ROWS) {
479 /* Scroll everything up */
480 console_scrollup () ;
485 /*----------------------------------------------------------------------*/
487 void lcd_putc (const char c)
489 if (!lcd_is_enabled) {
495 case '\r': console_col = 0;
498 case '\n': console_newline();
501 case '\t': /* Tab (8 chars alignment) */
505 if (console_col >= CONSOLE_COLS) {
510 case '\b': console_back();
513 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
514 console_row * VIDEO_FONT_HEIGHT,
516 if (++console_col >= CONSOLE_COLS) {
524 /*----------------------------------------------------------------------*/
526 void lcd_puts (const char *s)
528 if (!lcd_is_enabled) {
538 /************************************************************************/
539 /* ** Low-Level Graphics Routines */
540 /************************************************************************/
542 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
547 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
548 off = x * (1 << LCD_BPP) % 8;
550 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
555 #if LCD_BPP == LCD_MONOCHROME
556 uchar rest = *d & -(1 << (8-off));
559 for (i=0; i<count; ++i) {
563 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
565 #if LCD_BPP == LCD_MONOCHROME
566 sym = (COLOR_MASK(lcd_color_fg) & bits) |
567 (COLOR_MASK(lcd_color_bg) & ~bits);
569 *d++ = rest | (sym >> off);
570 rest = sym << (8-off);
571 #elif LCD_BPP == LCD_COLOR8
572 for (c=0; c<8; ++c) {
573 *d++ = (bits & 0x80) ?
574 lcd_color_fg : lcd_color_bg;
580 #if LCD_BPP == LCD_MONOCHROME
581 *d = rest | (*d & ((1 << (8-off)) - 1));
586 /*----------------------------------------------------------------------*/
588 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
590 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
591 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
593 lcd_drawchars (x, y, s, strlen (s));
597 /*----------------------------------------------------------------------*/
599 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
601 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
602 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
604 lcd_drawchars (x, y, &c, 1);
608 /************************************************************************/
609 /** Small utility to check that you got the colours right */
610 /************************************************************************/
611 #ifdef LCD_TEST_PATTERN
616 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
617 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
618 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
621 static void test_pattern (void)
623 ushort v_max = panel_info.vl_row;
624 ushort h_max = panel_info.vl_col;
625 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
626 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
628 uchar *pix = (uchar *)lcd_base;
630 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
631 h_max, v_max, h_step, v_step);
633 /* WARNING: Code silently assumes 8bit/pixel */
634 for (v=0; v<v_max; ++v) {
635 uchar iy = v / v_step;
636 for (h=0; h<h_max; ++h) {
637 uchar ix = N_BLK_HOR * iy + (h/h_step);
638 *pix++ = test_colors[ix];
642 #endif /* LCD_TEST_PATTERN */
645 /************************************************************************/
646 /* ** GENERIC Initialization Routines */
647 /************************************************************************/
649 int drv_lcd_init (void)
651 DECLARE_GLOBAL_DATA_PTR;
656 lcd_base = (void *)(gd->fb_base);
658 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
660 lcd_init (lcd_base); /* LCD initialization */
662 /* Device initialization */
663 memset (&lcddev, 0, sizeof (lcddev));
665 strcpy (lcddev.name, "lcd");
666 lcddev.ext = 0; /* No extensions */
667 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
668 lcddev.putc = lcd_putc; /* 'putc' function */
669 lcddev.puts = lcd_puts; /* 'puts' function */
671 rc = device_register (&lcddev);
673 return (rc == 0) ? 1 : rc;
676 /*----------------------------------------------------------------------*/
678 static int lcd_init (void *lcdbase)
680 /* Initialize the lcd controller */
681 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
683 lcd_ctrl_init (lcdbase);
685 #if LCD_BPP == LCD_MONOCHROME
686 /* Setting the palette */
689 #elif LCD_BPP == LCD_COLOR8
690 /* Setting the palette */
691 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
692 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
693 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
694 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
695 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
696 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
697 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
698 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
699 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
702 #ifndef CFG_WHITE_ON_BLACK
703 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
704 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
706 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
707 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
708 #endif /* CFG_WHITE_ON_BLACK */
710 #ifdef LCD_TEST_PATTERN
713 /* set framebuffer to background color */
714 memset ((char *)lcd_base,
715 COLOR_MASK(lcd_getbgcolor()),
716 lcd_line_length*panel_info.vl_row);
721 /* Paint the logo and retrieve LCD base address */
722 debug ("[LCD] Drawing the logo...\n");
723 lcd_console_address = lcd_logo ();
725 /* Initialize the console */
727 #ifdef LCD_INFO_BELOW_LOGO
728 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
730 console_row = 1; /* leave 1 blank line below logo */
738 /************************************************************************/
739 /* ** ROM capable initialization part - needed to reserve FB memory */
740 /************************************************************************/
743 * This is called early in the system initialization to grab memory
744 * for the LCD controller.
745 * Returns new address for monitor, after reserving LCD buffer memory
747 * Note that this is running from ROM, so no write access to global data.
749 ulong lcd_setmem (ulong addr)
752 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
754 debug ("LCD panel info: %d x %d, %d bit/pix\n",
755 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
757 size = line_length * panel_info.vl_row;
759 /* Round up to nearest full page */
760 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
762 /* Allocate pages for the frame buffer. */
765 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
771 /************************************************************************/
772 /* ----------------- chipset specific functions ----------------------- */
773 /************************************************************************/
775 static void lcd_ctrl_init (void *lcdbase)
777 volatile immap_t *immr = (immap_t *) CFG_IMMR;
778 volatile lcd823_t *lcdp = &immr->im_lcd;
782 /* Initialize the LCD control register according to the LCD
783 * parameters defined. We do everything here but enable
787 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
788 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
790 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
791 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
792 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
793 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
794 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
795 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
796 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
797 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
798 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
799 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
802 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
803 lccrtmp |= LCCR_EIEN;
806 lcdp->lcd_lccr = lccrtmp;
807 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
809 /* Initialize LCD controller bus priorities.
811 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
813 /* set SHFT/CLOCK division factor 4
814 * This needs to be set based upon display type and processor
815 * speed. The TFT displays run about 20 to 30 MHz.
816 * I was running 64 MHz processor speed.
817 * The value for this divider must be chosen so the result is
818 * an integer of the processor speed (i.e., divide by 3 with
819 * 64 MHz would be bad).
821 immr->im_clkrst.car_sccr &= ~0x1F;
822 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
824 #ifndef CONFIG_EDT32F10
825 /* Enable LCD on port D.
827 immr->im_ioport.iop_pdpar |= 0x1FFF;
828 immr->im_ioport.iop_pddir |= 0x1FFF;
830 /* Enable LCD_A/B/C on port B.
832 immr->im_cpm.cp_pbpar |= 0x00005001;
833 immr->im_cpm.cp_pbdir |= 0x00005001;
835 /* Enable LCD on port D.
837 immr->im_ioport.iop_pdpar |= 0x1DFF;
838 immr->im_ioport.iop_pdpar &= ~0x0200;
839 immr->im_ioport.iop_pddir |= 0x1FFF;
840 immr->im_ioport.iop_pddat |= 0x0200;
843 /* Load the physical address of the linear frame buffer
844 * into the LCD controller.
845 * BIG NOTE: This has to be modified to load A and B depending
846 * upon the split mode of the LCD.
848 lcdp->lcd_lcfaa = (ulong)lcd_base;
849 lcdp->lcd_lcfba = (ulong)lcd_base;
851 /* MORE HACKS...This must be updated according to 823 manual
852 * for different panels.
854 #ifndef CONFIG_EDT32F10
855 lcdp->lcd_lchcr = LCHCR_BO |
856 LCDBIT (LCHCR_AT_BIT, 4) |
857 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
860 lcdp->lcd_lchcr = LCHCR_BO |
861 LCDBIT (LCHCR_AT_BIT, 4) |
862 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
866 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
867 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
868 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
873 /*----------------------------------------------------------------------*/
875 #ifdef NOT_USED_SO_FAR
877 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
879 volatile immap_t *immr = (immap_t *) CFG_IMMR;
880 volatile cpm8xx_t *cp = &(immr->im_cpm);
881 unsigned short colreg, *cmap_ptr;
883 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
886 #ifdef CFG_INVERT_COLORS
890 *red = (colreg >> 8) & 0x0F;
891 *green = (colreg >> 4) & 0x0F;
892 *blue = colreg & 0x0F;
894 #endif /* NOT_USED_SO_FAR */
896 /*----------------------------------------------------------------------*/
898 #if LCD_BPP == LCD_COLOR8
900 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
902 volatile immap_t *immr = (immap_t *) CFG_IMMR;
903 volatile cpm8xx_t *cp = &(immr->im_cpm);
904 unsigned short colreg, *cmap_ptr;
906 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
908 colreg = ((red & 0x0F) << 8) |
909 ((green & 0x0F) << 4) |
911 #ifdef CFG_INVERT_COLORS
916 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
917 regno, &(cp->lcd_cmap[regno * 2]),
919 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
921 #endif /* LCD_COLOR8 */
923 /*----------------------------------------------------------------------*/
925 #if LCD_BPP == LCD_MONOCHROME
927 void lcd_initcolregs (void)
929 volatile immap_t *immr = (immap_t *) CFG_IMMR;
930 volatile cpm8xx_t *cp = &(immr->im_cpm);
933 for (regno = 0; regno < 16; regno++) {
934 cp->lcd_cmap[regno * 2] = 0;
935 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
940 /*----------------------------------------------------------------------*/
942 static void lcd_setfgcolor (int color)
944 lcd_color_fg = color & 0x0F;
947 /*----------------------------------------------------------------------*/
949 static void lcd_setbgcolor (int color)
951 lcd_color_bg = color & 0x0F;
954 /*----------------------------------------------------------------------*/
956 #ifdef NOT_USED_SO_FAR
957 static int lcd_getfgcolor (void)
961 #endif /* NOT_USED_SO_FAR */
963 /*----------------------------------------------------------------------*/
965 static int lcd_getbgcolor (void)
970 /*----------------------------------------------------------------------*/
972 static void lcd_enable (void)
974 volatile immap_t *immr = (immap_t *) CFG_IMMR;
975 volatile lcd823_t *lcdp = &immr->im_lcd;
977 /* Enable the LCD panel */
978 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
979 lcdp->lcd_lccr |= LCCR_PON;
982 /* Turn on display backlight */
983 immr->im_cpm.cp_pbpar |= 0x00008000;
984 immr->im_cpm.cp_pbdir |= 0x00008000;
987 #if defined(CONFIG_LWMON)
988 { uchar c = pic_read (0x60);
989 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
990 c |= 0x04; /* Chip Enable LCD */
992 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
996 #endif /* CONFIG_LWMON */
998 #if defined(CONFIG_R360MPI)
1000 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1002 r360_i2c_lcd_write(0x10, 0x01);
1003 r360_i2c_lcd_write(0x20, 0x01);
1004 r360_i2c_lcd_write(0x3F, 0xFF);
1005 r360_i2c_lcd_write(0x47, 0xFF);
1007 #endif /* CONFIG_R360MPI */
1010 /*----------------------------------------------------------------------*/
1012 #ifdef NOT_USED_SO_FAR
1013 static void lcd_disable (void)
1015 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1016 volatile lcd823_t *lcdp = &immr->im_lcd;
1018 #if defined(CONFIG_LWMON)
1019 { uchar c = pic_read (0x60);
1020 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1021 pic_write (0x60, c);
1023 #elif defined(CONFIG_R360MPI)
1025 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1027 r360_i2c_lcd_write(0x10, 0x00);
1028 r360_i2c_lcd_write(0x20, 0x00);
1029 r360_i2c_lcd_write(0x30, 0x00);
1030 r360_i2c_lcd_write(0x40, 0x00);
1032 #endif /* CONFIG_LWMON */
1033 /* Disable the LCD panel */
1034 lcdp->lcd_lccr &= ~LCCR_PON;
1035 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1037 #endif /* NOT_USED_SO_FAR */
1040 /************************************************************************/
1041 /* ** Chipset depending Bitmap / Logo stuff... */
1042 /************************************************************************/
1045 #ifdef CONFIG_LCD_LOGO
1046 static void bitmap_plot (int x, int y)
1048 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1049 volatile cpm8xx_t *cp = &(immr->im_cpm);
1055 debug ("Logo: width %d height %d colors %d cmap %d\n",
1056 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1057 sizeof(bmp_logo_palette)/(sizeof(ushort))
1060 /* Leave room for default color map */
1061 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1066 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1067 ushort colreg = bmp_logo_palette[i];
1068 #ifdef CFG_INVERT_COLORS
1074 bmap = &bmp_logo_bitmap[0];
1075 fb = (char *)(lcd_base + y * lcd_line_length + x);
1079 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1080 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1081 bmap += BMP_LOGO_WIDTH;
1082 fb += panel_info.vl_col;
1087 #endif /* CONFIG_LCD_LOGO */
1089 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
1091 * Display the BMP file located at address bmp_image.
1094 int lcd_display_bitmap(ulong bmp_image)
1096 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1097 volatile cpm8xx_t *cp = &(immr->im_cpm);
1101 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1104 unsigned long width, height;
1105 unsigned colors,bpix;
1106 unsigned long compression;
1110 if (!((bmp->header.signature[0]=='B') &&
1111 (bmp->header.signature[1]=='M'))) {
1112 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1116 width = le32_to_cpu (bmp->header.width);
1117 height = le32_to_cpu (bmp->header.height);
1118 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1119 compression = le32_to_cpu (bmp->header.compression);
1121 bpix = NBITS(panel_info.vl_bpix);
1123 if ((bpix != 1) && (bpix != 8)) {
1124 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1129 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1130 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1132 le16_to_cpu(bmp->header.bit_count));
1136 if (compression!=BMP_BI_RGB) {
1137 printf ("Error: compression type %ld not supported\n",
1142 debug ("Display-bmp: %d x %d with %d colors\n",
1143 width, height, colors);
1146 /* Fill the entire color map */
1147 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1150 for (i = 0; i < colors; ++i) {
1151 bmp_color_table_entry_t cte = bmp->color_table[i];
1153 ((cte.red>>4) << 8) |
1154 ((cte.green>>4) << 4) |
1156 #ifdef CFG_INVERT_COLORS
1165 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1166 if (width>panel_info.vl_col)
1167 width = panel_info.vl_col;
1168 if (height>panel_info.vl_row)
1169 height = panel_info.vl_row;
1171 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1174 (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
1176 for (i = 0; i < height; ++i) {
1178 for (j = 0; j < width ; j++)
1179 *(fb++)=255-*(bmap++);
1180 bmap += (width - padded_line);
1181 fb -= (width + lcd_line_length);
1186 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
1188 /*----------------------------------------------------------------------*/
1190 static void *lcd_logo (void)
1193 DECLARE_GLOBAL_DATA_PTR;
1197 #endif /* LCD_INFO */
1199 #ifdef CONFIG_SPLASH_SCREEN
1203 if ((s = getenv("splashimage")) != NULL) {
1204 addr = simple_strtoul(s, NULL, 16);
1206 if (lcd_display_bitmap (addr) == 0) {
1207 return ((void *)lcd_base);
1210 #endif /* CONFIG_SPLASH_SCREEN */
1212 #ifdef CONFIG_LCD_LOGO
1214 #endif /* CONFIG_LCD_LOGO */
1218 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1219 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1221 sprintf (info, "(C) 2003 DENX Software Engineering");
1222 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1223 info, strlen(info));
1225 sprintf (info, " Wolfgang DENK, wd@denx.de");
1226 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1227 info, strlen(info));
1228 #ifdef LCD_INFO_BELOW_LOGO
1229 sprintf (info, "MPC823 CPU at %s MHz",
1230 strmhz(temp, gd->cpu_clk));
1231 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1232 info, strlen(info));
1233 sprintf (info, " %ld MB RAM, %ld MB Flash",
1235 gd->bd->bi_flashsize >> 20 );
1236 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1237 info, strlen(info));
1239 /* leave one blank line */
1241 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1242 strmhz(temp, gd->cpu_clk),
1244 gd->bd->bi_flashsize >> 20 );
1245 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1246 info, strlen(info));
1247 #endif /* LCD_INFO_BELOW_LOGO */
1248 #endif /* LCD_INFO */
1250 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1251 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1253 return ((void *)lcd_base);
1254 #endif /* CONFIG_LCD_LOGO */
1257 /************************************************************************/
1258 /************************************************************************/
1260 #endif /* CONFIG_LCD */