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 /************************************************************************/
33 #include <linux/types.h>
39 /************************************************************************/
40 /* ** CONFIG STUFF -- should be moved to board config file */
41 /************************************************************************/
42 #define CONFIG_LCD_LOGO
43 #define LCD_INFO /* Display Logo, (C) and system info */
45 #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
46 #undef CONFIG_LCD_LOGO
50 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
51 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
52 /************************************************************************/
54 /************************************************************************/
55 /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
56 /************************************************************************/
58 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
59 #include <bmp_layout.h>
60 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
62 /************************************************************************/
63 /* ** FONT AND LOGO DATA */
64 /************************************************************************/
66 #include <video_font.h> /* Get font data, width and height */
68 #ifdef CONFIG_LCD_LOGO
69 # include <bmp_logo.h> /* Get logo data, width and height */
72 /************************************************************************/
73 /************************************************************************/
76 * Information about displays we are using. This is for configuring
77 * the LCD controller and memory allocation. Someone has to know what
78 * is connected, as we can't autodetect anything.
80 #define CFG_HIGH 0 /* Pins are active high */
81 #define CFG_LOW 1 /* Pins are active low */
83 typedef struct vidinfo {
84 ushort vl_col; /* Number of columns (i.e. 640) */
85 ushort vl_row; /* Number of rows (i.e. 480) */
86 ushort vl_width; /* Width of display area in millimeters */
87 ushort vl_height; /* Height of display area in millimeters */
89 /* LCD configuration register.
91 u_char vl_clkp; /* Clock polarity */
92 u_char vl_oep; /* Output Enable polarity */
93 u_char vl_hsp; /* Horizontal Sync polarity */
94 u_char vl_vsp; /* Vertical Sync polarity */
95 u_char vl_dp; /* Data polarity */
96 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
97 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
98 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
99 u_char vl_clor; /* Color, 0 = mono, 1 = color */
100 u_char vl_tft; /* 0 = passive, 1 = TFT */
102 /* Horizontal control register. Timing from data sheet.
104 ushort vl_wbl; /* Wait between lines */
106 /* Vertical control register.
108 u_char vl_vpw; /* Vertical sync pulse width */
109 u_char vl_lcdac; /* LCD AC timing */
110 u_char vl_wbf; /* Wait between frames */
113 #define LCD_MONOCHROME 0
118 /*----------------------------------------------------------------------*/
119 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
121 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
123 #define LCD_BPP LCD_COLOR4
125 static vidinfo_t panel_info = {
126 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
127 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
128 /* wbl, vpw, lcdac, wbf */
130 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
131 /*----------------------------------------------------------------------*/
133 /*----------------------------------------------------------------------*/
134 #ifdef CONFIG_NEC_NL6648AC33
136 * NEC NL6648AC33-18. Active, color, single scan.
138 static vidinfo_t panel_info = {
139 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
140 3, 0, 0, 1, 1, 144, 2, 0, 33
141 /* wbl, vpw, lcdac, wbf */
143 #endif /* CONFIG_NEC_NL6648AC33 */
144 /*----------------------------------------------------------------------*/
146 #ifdef CONFIG_NEC_NL6648BC20
148 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
150 static vidinfo_t panel_info = {
151 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
152 3, 0, 0, 1, 1, 144, 2, 0, 33
153 /* wbl, vpw, lcdac, wbf */
155 #endif /* CONFIG_NEC_NL6648BC20 */
156 /*----------------------------------------------------------------------*/
158 #ifdef CONFIG_SHARP_LQ104V7DS01
160 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
162 static vidinfo_t panel_info = {
163 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
164 3, 0, 0, 1, 1, 25, 1, 0, 33
165 /* wbl, vpw, lcdac, wbf */
167 #endif /* CONFIG_SHARP_LQ104V7DS01 */
168 /*----------------------------------------------------------------------*/
170 #ifdef CONFIG_SHARP_16x9
172 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
173 * not sure what it is.......
175 static vidinfo_t panel_info = {
176 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
177 3, 0, 0, 1, 1, 15, 4, 0, 3
179 #endif /* CONFIG_SHARP_16x9 */
180 /*----------------------------------------------------------------------*/
182 #ifdef CONFIG_SHARP_LQ057Q3DC02
184 * Sharp LQ057Q3DC02 display. Active, color, single scan.
188 static vidinfo_t panel_info = {
189 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
190 3, 0, 0, 1, 1, 15, 4, 0, 3
191 /* wbl, vpw, lcdac, wbf */
193 #define LCD_INFO_BELOW_LOGO
194 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
195 /*----------------------------------------------------------------------*/
197 #ifdef CONFIG_SHARP_LQ64D341
199 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
201 static vidinfo_t panel_info = {
202 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
203 3, 0, 0, 1, 1, 128, 16, 0, 32
204 /* wbl, vpw, lcdac, wbf */
206 #endif /* CONFIG_SHARP_LQ64D341 */
208 #ifdef CONFIG_SHARP_LQ084V1DG21
210 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
212 static vidinfo_t panel_info = {
213 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
214 3, 0, 0, 1, 1, 160, 3, 0, 48
215 /* wbl, vpw, lcdac, wbf */
217 #endif /* CONFIG_SHARP_LQ084V1DG21 */
219 /*----------------------------------------------------------------------*/
221 #ifdef CONFIG_HLD1045
223 * HLD1045 display, 640x480. Active, color, single scan.
225 static vidinfo_t panel_info = {
226 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
227 3, 0, 0, 1, 1, 160, 3, 0, 48
228 /* wbl, vpw, lcdac, wbf */
230 #endif /* CONFIG_HLD1045 */
231 /*----------------------------------------------------------------------*/
233 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
235 * Prime View V16C6448AC
237 static vidinfo_t panel_info = {
238 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
239 3, 0, 0, 1, 1, 144, 2, 0, 35
240 /* wbl, vpw, lcdac, wbf */
242 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
244 /*----------------------------------------------------------------------*/
246 #ifdef CONFIG_OPTREX_BW
248 * Optrex CBL50840-2 NF-FW 99 22 M5
250 * Hitachi LMG6912RPFC-00T
254 * 320x240. Black & white.
256 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
257 /* 1 - 4 grey levels, 2 bpp */
258 /* 2 - 16 grey levels, 4 bpp */
259 static vidinfo_t panel_info = {
260 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
261 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
263 #endif /* CONFIG_OPTREX_BW */
265 /*-----------------------------------------------------------------*/
266 #ifdef CONFIG_EDT32F10
268 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
270 #define LCD_BPP LCD_MONOCHROME
273 static vidinfo_t panel_info = {
274 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
275 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
278 /*----------------------------------------------------------------------*/
280 #if defined(LCD_INFO_BELOW_LOGO)
281 # define LCD_INFO_X 0
282 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
283 #elif defined(CONFIG_LCD_LOGO)
284 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
285 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
287 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
288 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
292 #define LCD_BPP LCD_COLOR8
298 #define NBITS(bit_code) (1 << (bit_code))
299 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
301 static int lcd_line_length;
303 static int lcd_color_fg;
304 static int lcd_color_bg;
306 static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
309 * Frame buffer memory information
311 static void *lcd_base; /* Start of framebuffer memory */
312 static void *lcd_console_address; /* Start of console buffer */
315 /************************************************************************/
316 /* ** CONSOLE CONSTANTS */
317 /************************************************************************/
319 #if LCD_BPP == LCD_MONOCHROME
322 * Simple color definitions
324 #define CONSOLE_COLOR_BLACK 0
325 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
330 * Simple color definitions
332 #define CONSOLE_COLOR_BLACK 0
333 #define CONSOLE_COLOR_RED 1
334 #define CONSOLE_COLOR_GREEN 2
335 #define CONSOLE_COLOR_YELLOW 3
336 #define CONSOLE_COLOR_BLUE 4
337 #define CONSOLE_COLOR_MAGENTA 5
338 #define CONSOLE_COLOR_CYAN 6
339 #define CONSOLE_COLOR_GREY 14
340 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
344 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
345 #error Default Color Map overlaps with Logo Color Map
348 /************************************************************************/
351 #define PAGE_SIZE 4096
355 /************************************************************************/
356 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
357 /************************************************************************/
359 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
360 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
363 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
365 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
366 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
367 #define CONSOLE_ROW_FIRST (lcd_console_address)
368 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
369 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
371 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
372 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
374 #if LCD_BPP == LCD_MONOCHROME
375 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
376 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
377 #elif LCD_BPP == LCD_COLOR8
378 #define COLOR_MASK(c) (c)
380 #error Unsupported LCD BPP.
383 static short console_col;
384 static short console_row;
386 /************************************************************************/
388 ulong lcd_setmem (ulong addr);
390 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
391 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
392 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
394 static int lcd_init (void *lcdbase);
395 static void lcd_ctrl_init (void *lcdbase);
396 static void lcd_enable (void);
397 static void *lcd_logo (void);
398 #if LCD_BPP == LCD_COLOR8
399 static void lcd_setcolreg (ushort regno,
400 ushort red, ushort green, ushort blue);
402 #if LCD_BPP == LCD_MONOCHROME
403 static void lcd_initcolregs (void);
405 static int lcd_getbgcolor (void);
406 static void lcd_setfgcolor (int color);
407 static void lcd_setbgcolor (int color);
409 #ifdef NOT_USED_SO_FAR
410 static void lcd_disable (void);
411 static void lcd_getcolreg (ushort regno,
412 ushort *red, ushort *green, ushort *blue);
413 static int lcd_getfgcolor (void);
414 #endif /* NOT_USED_SO_FAR */
416 /************************************************************************/
418 /*----------------------------------------------------------------------*/
420 static void console_scrollup (void)
423 /* Copy up rows ignoring the first one */
424 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
426 /* Clear the last one */
427 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
430 * Poor attempt to optimize speed by moving "long"s.
431 * But the code is ugly, and not a bit faster :-(
433 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
434 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
435 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
436 uchar c = lcd_color_bg & 0xFF;
437 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
442 t = (ulong *)CONSOLE_ROW_LAST;
443 l = CONSOLE_ROW_SIZE / sizeof(ulong);
450 /*----------------------------------------------------------------------*/
452 static inline void console_back (void)
454 if (--console_col < 0) {
455 console_col = CONSOLE_COLS-1 ;
456 if (--console_row < 0) {
461 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
462 console_row * VIDEO_FONT_HEIGHT,
466 /*----------------------------------------------------------------------*/
468 static inline void console_newline (void)
473 /* Check if we need to scroll the terminal */
474 if (console_row >= CONSOLE_ROWS) {
475 /* Scroll everything up */
476 console_scrollup () ;
481 /*----------------------------------------------------------------------*/
483 void lcd_putc (const char c)
485 if (!lcd_is_enabled) {
491 case '\r': console_col = 0;
494 case '\n': console_newline();
497 case '\t': /* Tab (8 chars alignment) */
501 if (console_col >= CONSOLE_COLS) {
506 case '\b': console_back();
509 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
510 console_row * VIDEO_FONT_HEIGHT,
512 if (++console_col >= CONSOLE_COLS) {
520 /*----------------------------------------------------------------------*/
522 void lcd_puts (const char *s)
524 if (!lcd_is_enabled) {
534 /************************************************************************/
535 /* ** Low-Level Graphics Routines */
536 /************************************************************************/
538 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
543 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
544 off = x * (1 << LCD_BPP) % 8;
546 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
551 #if LCD_BPP == LCD_MONOCHROME
552 uchar rest = *d & -(1 << (8-off));
555 for (i=0; i<count; ++i) {
559 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
561 #if LCD_BPP == LCD_MONOCHROME
562 sym = (COLOR_MASK(lcd_color_fg) & bits) |
563 (COLOR_MASK(lcd_color_bg) & ~bits);
565 *d++ = rest | (sym >> off);
566 rest = sym << (8-off);
567 #elif LCD_BPP == LCD_COLOR8
568 for (c=0; c<8; ++c) {
569 *d++ = (bits & 0x80) ?
570 lcd_color_fg : lcd_color_bg;
576 #if LCD_BPP == LCD_MONOCHROME
577 *d = rest | (*d & ((1 << (8-off)) - 1));
582 /*----------------------------------------------------------------------*/
584 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
586 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
587 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
589 lcd_drawchars (x, y, s, strlen (s));
593 /*----------------------------------------------------------------------*/
595 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
597 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
598 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
600 lcd_drawchars (x, y, &c, 1);
604 /************************************************************************/
605 /** Small utility to check that you got the colours right */
606 /************************************************************************/
607 #ifdef LCD_TEST_PATTERN
612 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
613 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
614 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
617 static void test_pattern (void)
619 ushort v_max = panel_info.vl_row;
620 ushort h_max = panel_info.vl_col;
621 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
622 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
624 uchar *pix = (uchar *)lcd_base;
626 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
627 h_max, v_max, h_step, v_step);
629 /* WARNING: Code silently assumes 8bit/pixel */
630 for (v=0; v<v_max; ++v) {
631 uchar iy = v / v_step;
632 for (h=0; h<h_max; ++h) {
633 uchar ix = N_BLK_HOR * iy + (h/h_step);
634 *pix++ = test_colors[ix];
638 #endif /* LCD_TEST_PATTERN */
641 /************************************************************************/
642 /* ** GENERIC Initialization Routines */
643 /************************************************************************/
645 int drv_lcd_init (void)
647 DECLARE_GLOBAL_DATA_PTR;
652 lcd_base = (void *)(gd->fb_base);
654 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
656 lcd_init (lcd_base); /* LCD initialization */
658 /* Device initialization */
659 memset (&lcddev, 0, sizeof (lcddev));
661 strcpy (lcddev.name, "lcd");
662 lcddev.ext = 0; /* No extensions */
663 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
664 lcddev.putc = lcd_putc; /* 'putc' function */
665 lcddev.puts = lcd_puts; /* 'puts' function */
667 rc = device_register (&lcddev);
669 return (rc == 0) ? 1 : rc;
672 /*----------------------------------------------------------------------*/
674 static int lcd_init (void *lcdbase)
676 /* Initialize the lcd controller */
677 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
679 lcd_ctrl_init (lcdbase);
681 #if LCD_BPP == LCD_MONOCHROME
682 /* Setting the palette */
685 #elif LCD_BPP == LCD_COLOR8
686 /* Setting the palette */
687 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
688 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
689 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
690 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
691 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
692 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
693 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
694 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
695 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
698 #ifndef CFG_WHITE_ON_BLACK
699 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
700 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
702 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
703 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
704 #endif /* CFG_WHITE_ON_BLACK */
706 #ifdef LCD_TEST_PATTERN
709 /* set framebuffer to background color */
710 memset ((char *)lcd_base,
711 COLOR_MASK(lcd_getbgcolor()),
712 lcd_line_length*panel_info.vl_row);
717 /* Paint the logo and retrieve LCD base address */
718 debug ("[LCD] Drawing the logo...\n");
719 lcd_console_address = lcd_logo ();
721 /* Initialize the console */
723 #ifdef LCD_INFO_BELOW_LOGO
724 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
726 console_row = 1; /* leave 1 blank line below logo */
734 /************************************************************************/
735 /* ** ROM capable initialization part - needed to reserve FB memory */
736 /************************************************************************/
739 * This is called early in the system initialization to grab memory
740 * for the LCD controller.
741 * Returns new address for monitor, after reserving LCD buffer memory
743 * Note that this is running from ROM, so no write access to global data.
745 ulong lcd_setmem (ulong addr)
748 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
750 debug ("LCD panel info: %d x %d, %d bit/pix\n",
751 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
753 size = line_length * panel_info.vl_row;
755 /* Round up to nearest full page */
756 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
758 /* Allocate pages for the frame buffer. */
761 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
767 /************************************************************************/
768 /* ----------------- chipset specific functions ----------------------- */
769 /************************************************************************/
771 static void lcd_ctrl_init (void *lcdbase)
773 volatile immap_t *immr = (immap_t *) CFG_IMMR;
774 volatile lcd823_t *lcdp = &immr->im_lcd;
778 /* Initialize the LCD control register according to the LCD
779 * parameters defined. We do everything here but enable
783 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
784 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
786 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
787 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
788 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
789 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
790 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
791 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
792 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
793 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
794 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
795 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
798 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
799 lccrtmp |= LCCR_EIEN;
802 lcdp->lcd_lccr = lccrtmp;
803 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
805 /* Initialize LCD controller bus priorities.
807 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
809 /* set SHFT/CLOCK division factor 4
810 * This needs to be set based upon display type and processor
811 * speed. The TFT displays run about 20 to 30 MHz.
812 * I was running 64 MHz processor speed.
813 * The value for this divider must be chosen so the result is
814 * an integer of the processor speed (i.e., divide by 3 with
815 * 64 MHz would be bad).
817 immr->im_clkrst.car_sccr &= ~0x1F;
818 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
820 #ifndef CONFIG_EDT32F10
821 /* Enable LCD on port D.
823 immr->im_ioport.iop_pdpar |= 0x1FFF;
824 immr->im_ioport.iop_pddir |= 0x1FFF;
826 /* Enable LCD_A/B/C on port B.
828 immr->im_cpm.cp_pbpar |= 0x00005001;
829 immr->im_cpm.cp_pbdir |= 0x00005001;
831 /* Enable LCD on port D.
833 immr->im_ioport.iop_pdpar |= 0x1DFF;
834 immr->im_ioport.iop_pdpar &= ~0x0200;
835 immr->im_ioport.iop_pddir |= 0x1FFF;
836 immr->im_ioport.iop_pddat |= 0x0200;
839 /* Load the physical address of the linear frame buffer
840 * into the LCD controller.
841 * BIG NOTE: This has to be modified to load A and B depending
842 * upon the split mode of the LCD.
844 lcdp->lcd_lcfaa = (ulong)lcd_base;
845 lcdp->lcd_lcfba = (ulong)lcd_base;
847 /* MORE HACKS...This must be updated according to 823 manual
848 * for different panels.
850 #ifndef CONFIG_EDT32F10
851 lcdp->lcd_lchcr = LCHCR_BO |
852 LCDBIT (LCHCR_AT_BIT, 4) |
853 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
856 lcdp->lcd_lchcr = LCHCR_BO |
857 LCDBIT (LCHCR_AT_BIT, 4) |
858 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
862 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
863 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
864 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
869 /*----------------------------------------------------------------------*/
871 #ifdef NOT_USED_SO_FAR
873 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
875 volatile immap_t *immr = (immap_t *) CFG_IMMR;
876 volatile cpm8xx_t *cp = &(immr->im_cpm);
877 unsigned short colreg, *cmap_ptr;
879 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
882 #ifdef CFG_INVERT_COLORS
886 *red = (colreg >> 8) & 0x0F;
887 *green = (colreg >> 4) & 0x0F;
888 *blue = colreg & 0x0F;
890 #endif /* NOT_USED_SO_FAR */
892 /*----------------------------------------------------------------------*/
894 #if LCD_BPP == LCD_COLOR8
896 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
898 volatile immap_t *immr = (immap_t *) CFG_IMMR;
899 volatile cpm8xx_t *cp = &(immr->im_cpm);
900 unsigned short colreg, *cmap_ptr;
902 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
904 colreg = ((red & 0x0F) << 8) |
905 ((green & 0x0F) << 4) |
907 #ifdef CFG_INVERT_COLORS
912 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
913 regno, &(cp->lcd_cmap[regno * 2]),
915 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
917 #endif /* LCD_COLOR8 */
919 /*----------------------------------------------------------------------*/
921 #if LCD_BPP == LCD_MONOCHROME
923 void lcd_initcolregs (void)
925 volatile immap_t *immr = (immap_t *) CFG_IMMR;
926 volatile cpm8xx_t *cp = &(immr->im_cpm);
929 for (regno = 0; regno < 16; regno++) {
930 cp->lcd_cmap[regno * 2] = 0;
931 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
936 /*----------------------------------------------------------------------*/
938 static void lcd_setfgcolor (int color)
940 lcd_color_fg = color & 0x0F;
943 /*----------------------------------------------------------------------*/
945 static void lcd_setbgcolor (int color)
947 lcd_color_bg = color & 0x0F;
950 /*----------------------------------------------------------------------*/
952 #ifdef NOT_USED_SO_FAR
953 static int lcd_getfgcolor (void)
957 #endif /* NOT_USED_SO_FAR */
959 /*----------------------------------------------------------------------*/
961 static int lcd_getbgcolor (void)
966 /*----------------------------------------------------------------------*/
968 static void lcd_enable (void)
970 volatile immap_t *immr = (immap_t *) CFG_IMMR;
971 volatile lcd823_t *lcdp = &immr->im_lcd;
973 /* Enable the LCD panel */
974 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
975 lcdp->lcd_lccr |= LCCR_PON;
978 /* Turn on display backlight */
979 immr->im_cpm.cp_pbpar |= 0x00008000;
980 immr->im_cpm.cp_pbdir |= 0x00008000;
983 #if defined(CONFIG_LWMON)
984 { uchar c = pic_read (0x60);
985 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
988 #endif /* CONFIG_LWMON */
990 #if defined(CONFIG_R360MPI)
992 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
994 r360_i2c_lcd_write(0x10, 0x01);
995 r360_i2c_lcd_write(0x20, 0x01);
996 r360_i2c_lcd_write(0x3F, 0xFF);
997 r360_i2c_lcd_write(0x47, 0xFF);
999 #endif /* CONFIG_R360MPI */
1002 /*----------------------------------------------------------------------*/
1004 #ifdef NOT_USED_SO_FAR
1005 static void lcd_disable (void)
1007 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1008 volatile lcd823_t *lcdp = &immr->im_lcd;
1010 #if defined(CONFIG_LWMON)
1011 { uchar c = pic_read (0x60);
1012 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1013 pic_write (0x60, c);
1015 #elif defined(CONFIG_R360MPI)
1017 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1019 r360_i2c_lcd_write(0x10, 0x00);
1020 r360_i2c_lcd_write(0x20, 0x00);
1021 r360_i2c_lcd_write(0x30, 0x00);
1022 r360_i2c_lcd_write(0x40, 0x00);
1024 #endif /* CONFIG_LWMON */
1025 /* Disable the LCD panel */
1026 lcdp->lcd_lccr &= ~LCCR_PON;
1027 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1029 #endif /* NOT_USED_SO_FAR */
1032 /************************************************************************/
1033 /* ** Chipset depending Bitmap / Logo stuff... */
1034 /************************************************************************/
1037 #ifdef CONFIG_LCD_LOGO
1038 static void bitmap_plot (int x, int y)
1040 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1041 volatile cpm8xx_t *cp = &(immr->im_cpm);
1047 debug ("Logo: width %d height %d colors %d cmap %d\n",
1048 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1049 sizeof(bmp_logo_palette)/(sizeof(ushort))
1052 /* Leave room for default color map */
1053 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1056 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1057 ushort colreg = bmp_logo_palette[i];
1058 #ifdef CFG_INVERT_COLORS
1064 bmap = &bmp_logo_bitmap[0];
1065 fb = (char *)(lcd_base + y * lcd_line_length + x);
1067 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1068 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1069 bmap += BMP_LOGO_WIDTH;
1070 fb += panel_info.vl_col;
1073 #endif /* CONFIG_LCD_LOGO */
1075 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
1077 * Display the BMP file located at address bmp_image.
1080 int lcd_display_bitmap(ulong bmp_image)
1082 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1083 volatile cpm8xx_t *cp = &(immr->im_cpm);
1087 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1090 unsigned long width, height;
1091 unsigned colors,bpix;
1092 unsigned long compression;
1094 if (!((bmp->header.signature[0]=='B') &&
1095 (bmp->header.signature[1]=='M'))) {
1096 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1100 width = le32_to_cpu (bmp->header.width);
1101 height = le32_to_cpu (bmp->header.height);
1102 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1103 compression = le32_to_cpu (bmp->header.compression);
1105 bpix = NBITS(panel_info.vl_bpix);
1107 if ((bpix != 1) && (bpix != 8)) {
1108 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1113 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1114 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1116 le16_to_cpu(bmp->header.bit_count));
1120 if (compression!=BMP_BI_RGB) {
1121 printf ("Error: compression type %ld not supported\n",
1126 debug ("Display-bmp: %d x %d with %d colors\n",
1127 width, height, colors);
1130 /* Fill the entire color map */
1131 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1134 for (i = 0; i < colors; ++i) {
1135 bmp_color_table_entry_t cte = bmp->color_table[i];
1137 ((cte.red>>4) << 8) |
1138 ((cte.green>>4) << 4) |
1140 #ifdef CFG_INVERT_COLORS
1147 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1148 if (width>panel_info.vl_col)
1149 width = panel_info.vl_col;
1150 if (height>panel_info.vl_row)
1151 height = panel_info.vl_row;
1153 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1156 (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
1158 for (i = 0; i < height; ++i) {
1159 for (j = 0; j < width ; j++)
1160 *(fb++)=255-*(bmap++);
1161 bmap += (width - padded_line);
1162 fb -= (width + lcd_line_length);
1167 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
1169 /*----------------------------------------------------------------------*/
1171 static void *lcd_logo (void)
1174 DECLARE_GLOBAL_DATA_PTR;
1178 #endif /* LCD_INFO */
1180 #ifdef CONFIG_SPLASH_SCREEN
1184 if ((s = getenv("splashimage")) != NULL) {
1185 addr = simple_strtoul(s, NULL, 16);
1187 if (lcd_display_bitmap (addr) == 0) {
1188 return ((void *)lcd_base);
1191 #endif /* CONFIG_SPLASH_SCREEN */
1193 #ifdef CONFIG_LCD_LOGO
1195 #endif /* CONFIG_LCD_LOGO */
1199 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1200 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1202 sprintf (info, "(C) 2003 DENX Software Engineering");
1203 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1204 info, strlen(info));
1206 sprintf (info, " Wolfgang DENK, wd@denx.de");
1207 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1208 info, strlen(info));
1209 #ifdef LCD_INFO_BELOW_LOGO
1210 sprintf (info, "MPC823 CPU at %s MHz",
1211 strmhz(temp, gd->cpu_clk));
1212 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1213 info, strlen(info));
1214 sprintf (info, " %ld MB RAM, %ld MB Flash",
1216 gd->bd->bi_flashsize >> 20 );
1217 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1218 info, strlen(info));
1220 /* leave one blank line */
1222 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1223 strmhz(temp, gd->cpu_clk),
1225 gd->bd->bi_flashsize >> 20 );
1226 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1227 info, strlen(info));
1228 #endif /* LCD_INFO_BELOW_LOGO */
1229 #endif /* LCD_INFO */
1231 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1232 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1234 return ((void *)lcd_base);
1235 #endif /* CONFIG_LCD_LOGO */
1238 /************************************************************************/
1239 /************************************************************************/
1241 #endif /* CONFIG_LCD */