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>
35 #if defined(CONFIG_POST)
42 /************************************************************************/
43 /* ** CONFIG STUFF -- should be moved to board config file */
44 /************************************************************************/
45 #define CONFIG_LCD_LOGO
46 #define LCD_INFO /* Display Logo, (C) and system info */
48 #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
49 #undef CONFIG_LCD_LOGO
53 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
54 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
55 /************************************************************************/
57 /************************************************************************/
58 /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
59 /************************************************************************/
61 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
62 #include <bmp_layout.h>
63 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
65 /************************************************************************/
66 /* ** FONT AND LOGO DATA */
67 /************************************************************************/
69 #include <video_font.h> /* Get font data, width and height */
71 #ifdef CONFIG_LCD_LOGO
72 # include <bmp_logo.h> /* Get logo data, width and height */
75 /************************************************************************/
76 /************************************************************************/
79 * Information about displays we are using. This is for configuring
80 * the LCD controller and memory allocation. Someone has to know what
81 * is connected, as we can't autodetect anything.
83 #define CFG_HIGH 0 /* Pins are active high */
84 #define CFG_LOW 1 /* Pins are active low */
86 typedef struct vidinfo
{
87 ushort vl_col
; /* Number of columns (i.e. 640) */
88 ushort vl_row
; /* Number of rows (i.e. 480) */
89 ushort vl_width
; /* Width of display area in millimeters */
90 ushort vl_height
; /* Height of display area in millimeters */
92 /* LCD configuration register.
94 u_char vl_clkp
; /* Clock polarity */
95 u_char vl_oep
; /* Output Enable polarity */
96 u_char vl_hsp
; /* Horizontal Sync polarity */
97 u_char vl_vsp
; /* Vertical Sync polarity */
98 u_char vl_dp
; /* Data polarity */
99 u_char vl_bpix
; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
100 u_char vl_lbw
; /* LCD Bus width, 0 = 4, 1 = 8 */
101 u_char vl_splt
; /* Split display, 0 = single-scan, 1 = dual-scan */
102 u_char vl_clor
; /* Color, 0 = mono, 1 = color */
103 u_char vl_tft
; /* 0 = passive, 1 = TFT */
105 /* Horizontal control register. Timing from data sheet.
107 ushort vl_wbl
; /* Wait between lines */
109 /* Vertical control register.
111 u_char vl_vpw
; /* Vertical sync pulse width */
112 u_char vl_lcdac
; /* LCD AC timing */
113 u_char vl_wbf
; /* Wait between frames */
116 #define LCD_MONOCHROME 0
121 /*----------------------------------------------------------------------*/
122 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
124 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
126 #define LCD_BPP LCD_COLOR4
128 static vidinfo_t panel_info
= {
129 640, 480, 132, 99, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
,
130 LCD_BPP
, 1, 0, 1, 0, 5, 0, 0, 0
131 /* wbl, vpw, lcdac, wbf */
133 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
134 /*----------------------------------------------------------------------*/
136 /*----------------------------------------------------------------------*/
137 #ifdef CONFIG_NEC_NL6648AC33
139 * NEC NL6648AC33-18. Active, color, single scan.
141 static vidinfo_t panel_info
= {
142 640, 480, 132, 99, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_HIGH
,
143 3, 0, 0, 1, 1, 144, 2, 0, 33
144 /* wbl, vpw, lcdac, wbf */
146 #endif /* CONFIG_NEC_NL6648AC33 */
147 /*----------------------------------------------------------------------*/
149 #ifdef CONFIG_NEC_NL6648BC20
151 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
153 static vidinfo_t panel_info
= {
154 640, 480, 132, 99, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_HIGH
,
155 3, 0, 0, 1, 1, 144, 2, 0, 33
156 /* wbl, vpw, lcdac, wbf */
158 #endif /* CONFIG_NEC_NL6648BC20 */
159 /*----------------------------------------------------------------------*/
161 #ifdef CONFIG_SHARP_LQ104V7DS01
163 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
165 static vidinfo_t panel_info
= {
166 640, 480, 132, 99, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_LOW
,
167 3, 0, 0, 1, 1, 25, 1, 0, 33
168 /* wbl, vpw, lcdac, wbf */
170 #endif /* CONFIG_SHARP_LQ104V7DS01 */
171 /*----------------------------------------------------------------------*/
173 #ifdef CONFIG_SHARP_16x9
175 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
176 * not sure what it is.......
178 static vidinfo_t panel_info
= {
179 320, 240, 0, 0, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
,
180 3, 0, 0, 1, 1, 15, 4, 0, 3
182 #endif /* CONFIG_SHARP_16x9 */
183 /*----------------------------------------------------------------------*/
185 #ifdef CONFIG_SHARP_LQ057Q3DC02
187 * Sharp LQ057Q3DC02 display. Active, color, single scan.
191 static vidinfo_t panel_info
= {
192 320, 240, 0, 0, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_HIGH
,
193 3, 0, 0, 1, 1, 15, 4, 0, 3
194 /* wbl, vpw, lcdac, wbf */
196 #define LCD_INFO_BELOW_LOGO
197 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
198 /*----------------------------------------------------------------------*/
200 #ifdef CONFIG_SHARP_LQ64D341
202 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
204 static vidinfo_t panel_info
= {
205 640, 480, 0, 0, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_HIGH
,
206 3, 0, 0, 1, 1, 128, 16, 0, 32
207 /* wbl, vpw, lcdac, wbf */
209 #endif /* CONFIG_SHARP_LQ64D341 */
211 #ifdef CONFIG_SHARP_LQ084V1DG21
213 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
215 static vidinfo_t panel_info
= {
216 640, 480, 171, 129, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_LOW
,
217 3, 0, 0, 1, 1, 160, 3, 0, 48
218 /* wbl, vpw, lcdac, wbf */
220 #endif /* CONFIG_SHARP_LQ084V1DG21 */
222 /*----------------------------------------------------------------------*/
224 #ifdef CONFIG_HLD1045
226 * HLD1045 display, 640x480. Active, color, single scan.
228 static vidinfo_t panel_info
= {
229 640, 480, 0, 0, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_HIGH
,
230 3, 0, 0, 1, 1, 160, 3, 0, 48
231 /* wbl, vpw, lcdac, wbf */
233 #endif /* CONFIG_HLD1045 */
234 /*----------------------------------------------------------------------*/
236 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
238 * Prime View V16C6448AC
240 static vidinfo_t panel_info
= {
241 640, 480, 130, 98, CFG_HIGH
, CFG_HIGH
, CFG_LOW
, CFG_LOW
, CFG_HIGH
,
242 3, 0, 0, 1, 1, 144, 2, 0, 35
243 /* wbl, vpw, lcdac, wbf */
245 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
247 /*----------------------------------------------------------------------*/
249 #ifdef CONFIG_OPTREX_BW
251 * Optrex CBL50840-2 NF-FW 99 22 M5
253 * Hitachi LMG6912RPFC-00T
257 * 320x240. Black & white.
259 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
260 /* 1 - 4 grey levels, 2 bpp */
261 /* 2 - 16 grey levels, 4 bpp */
262 static vidinfo_t panel_info
= {
263 320, 240, 0, 0, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_LOW
,
264 OPTREX_BPP
, 0, 0, 0, 0, 0, 0, 0, 0, 4
266 #endif /* CONFIG_OPTREX_BW */
268 /*-----------------------------------------------------------------*/
269 #ifdef CONFIG_EDT32F10
271 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
273 #define LCD_BPP LCD_MONOCHROME
276 static vidinfo_t panel_info
= {
277 320, 240, 0, 0, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_HIGH
, CFG_LOW
,
278 LCD_BPP
, 0, 0, 0, 0, 33, 0, 0, 0
281 /*----------------------------------------------------------------------*/
283 #if defined(LCD_INFO_BELOW_LOGO)
284 # define LCD_INFO_X 0
285 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
286 #elif defined(CONFIG_LCD_LOGO)
287 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
288 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
290 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
291 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
295 #define LCD_BPP LCD_COLOR8
301 #define NBITS(bit_code) (1 << (bit_code))
302 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
304 static int lcd_line_length
;
306 static int lcd_color_fg
;
307 static int lcd_color_bg
;
309 static char lcd_is_enabled
= 0; /* Indicate that LCD is enabled */
312 * Frame buffer memory information
314 static void *lcd_base
; /* Start of framebuffer memory */
315 static void *lcd_console_address
; /* Start of console buffer */
318 /************************************************************************/
319 /* ** CONSOLE CONSTANTS */
320 /************************************************************************/
322 #if LCD_BPP == LCD_MONOCHROME
325 * Simple color definitions
327 #define CONSOLE_COLOR_BLACK 0
328 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
333 * Simple color definitions
335 #define CONSOLE_COLOR_BLACK 0
336 #define CONSOLE_COLOR_RED 1
337 #define CONSOLE_COLOR_GREEN 2
338 #define CONSOLE_COLOR_YELLOW 3
339 #define CONSOLE_COLOR_BLUE 4
340 #define CONSOLE_COLOR_MAGENTA 5
341 #define CONSOLE_COLOR_CYAN 6
342 #define CONSOLE_COLOR_GREY 14
343 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
347 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
348 #error Default Color Map overlaps with Logo Color Map
351 /************************************************************************/
354 #define PAGE_SIZE 4096
358 /************************************************************************/
359 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
360 /************************************************************************/
362 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
363 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
366 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
368 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
369 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
370 #define CONSOLE_ROW_FIRST (lcd_console_address)
371 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
372 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
374 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
375 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
377 #if LCD_BPP == LCD_MONOCHROME
378 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
379 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
380 #elif LCD_BPP == LCD_COLOR8
381 #define COLOR_MASK(c) (c)
383 #error Unsupported LCD BPP.
386 static short console_col
;
387 static short console_row
;
389 /************************************************************************/
391 ulong
lcd_setmem (ulong addr
);
393 static void lcd_drawchars (ushort x
, ushort y
, uchar
*str
, int count
);
394 static inline void lcd_puts_xy (ushort x
, ushort y
, uchar
*s
);
395 static inline void lcd_putc_xy (ushort x
, ushort y
, uchar c
);
397 static int lcd_init (void *lcdbase
);
398 static void lcd_ctrl_init (void *lcdbase
);
399 static void lcd_enable (void);
400 static void *lcd_logo (void);
401 #if LCD_BPP == LCD_COLOR8
402 static void lcd_setcolreg (ushort regno
,
403 ushort red
, ushort green
, ushort blue
);
405 #if LCD_BPP == LCD_MONOCHROME
406 static void lcd_initcolregs (void);
408 static int lcd_getbgcolor (void);
409 static void lcd_setfgcolor (int color
);
410 static void lcd_setbgcolor (int color
);
412 #ifdef NOT_USED_SO_FAR
413 static void lcd_disable (void);
414 static void lcd_getcolreg (ushort regno
,
415 ushort
*red
, ushort
*green
, ushort
*blue
);
416 static int lcd_getfgcolor (void);
417 #endif /* NOT_USED_SO_FAR */
419 /************************************************************************/
421 /*----------------------------------------------------------------------*/
423 static void console_scrollup (void)
426 /* Copy up rows ignoring the first one */
427 memcpy (CONSOLE_ROW_FIRST
, CONSOLE_ROW_SECOND
, CONSOLE_SCROLL_SIZE
);
429 /* Clear the last one */
430 memset (CONSOLE_ROW_LAST
, COLOR_MASK(lcd_color_bg
), CONSOLE_ROW_SIZE
);
433 * Poor attempt to optimize speed by moving "long"s.
434 * But the code is ugly, and not a bit faster :-(
436 ulong
*t
= (ulong
*)CONSOLE_ROW_FIRST
;
437 ulong
*s
= (ulong
*)CONSOLE_ROW_SECOND
;
438 ulong l
= CONSOLE_SCROLL_SIZE
/ sizeof(ulong
);
439 uchar c
= lcd_color_bg
& 0xFF;
440 ulong val
= (c
<<24) | (c
<<16) | (c
<<8) | c
;
445 t
= (ulong
*)CONSOLE_ROW_LAST
;
446 l
= CONSOLE_ROW_SIZE
/ sizeof(ulong
);
453 /*----------------------------------------------------------------------*/
455 static inline void console_back (void)
457 if (--console_col
< 0) {
458 console_col
= CONSOLE_COLS
-1 ;
459 if (--console_row
< 0) {
464 lcd_putc_xy (console_col
* VIDEO_FONT_WIDTH
,
465 console_row
* VIDEO_FONT_HEIGHT
,
469 /*----------------------------------------------------------------------*/
471 static inline void console_newline (void)
476 /* Check if we need to scroll the terminal */
477 if (console_row
>= CONSOLE_ROWS
) {
478 /* Scroll everything up */
479 console_scrollup () ;
484 /*----------------------------------------------------------------------*/
486 void lcd_putc (const char c
)
488 if (!lcd_is_enabled
) {
494 case '\r': console_col
= 0;
497 case '\n': console_newline();
500 case '\t': /* Tab (8 chars alignment) */
504 if (console_col
>= CONSOLE_COLS
) {
509 case '\b': console_back();
512 default: lcd_putc_xy (console_col
* VIDEO_FONT_WIDTH
,
513 console_row
* VIDEO_FONT_HEIGHT
,
515 if (++console_col
>= CONSOLE_COLS
) {
523 /*----------------------------------------------------------------------*/
525 void lcd_puts (const char *s
)
527 if (!lcd_is_enabled
) {
537 /************************************************************************/
538 /* ** Low-Level Graphics Routines */
539 /************************************************************************/
541 static void lcd_drawchars (ushort x
, ushort y
, uchar
*str
, int count
)
546 dest
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
* (1 << LCD_BPP
) / 8);
547 off
= x
* (1 << LCD_BPP
) % 8;
549 for (row
=0; row
< VIDEO_FONT_HEIGHT
; ++row
, dest
+= lcd_line_length
) {
554 #if LCD_BPP == LCD_MONOCHROME
555 uchar rest
= *d
& -(1 << (8-off
));
558 for (i
=0; i
<count
; ++i
) {
562 bits
= video_fontdata
[c
* VIDEO_FONT_HEIGHT
+ row
];
564 #if LCD_BPP == LCD_MONOCHROME
565 sym
= (COLOR_MASK(lcd_color_fg
) & bits
) |
566 (COLOR_MASK(lcd_color_bg
) & ~bits
);
568 *d
++ = rest
| (sym
>> off
);
569 rest
= sym
<< (8-off
);
570 #elif LCD_BPP == LCD_COLOR8
571 for (c
=0; c
<8; ++c
) {
572 *d
++ = (bits
& 0x80) ?
573 lcd_color_fg
: lcd_color_bg
;
579 #if LCD_BPP == LCD_MONOCHROME
580 *d
= rest
| (*d
& ((1 << (8-off
)) - 1));
585 /*----------------------------------------------------------------------*/
587 static inline void lcd_puts_xy (ushort x
, ushort y
, uchar
*s
)
589 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
590 lcd_drawchars (x
, y
+BMP_LOGO_HEIGHT
, s
, strlen (s
));
592 lcd_drawchars (x
, y
, s
, strlen (s
));
596 /*----------------------------------------------------------------------*/
598 static inline void lcd_putc_xy (ushort x
, ushort y
, uchar c
)
600 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
601 lcd_drawchars (x
, y
+BMP_LOGO_HEIGHT
, &c
, 1);
603 lcd_drawchars (x
, y
, &c
, 1);
607 /************************************************************************/
608 /** Small utility to check that you got the colours right */
609 /************************************************************************/
610 #ifdef LCD_TEST_PATTERN
615 static int test_colors
[N_BLK_HOR
*N_BLK_VERT
] = {
616 CONSOLE_COLOR_RED
, CONSOLE_COLOR_GREEN
, CONSOLE_COLOR_YELLOW
,
617 CONSOLE_COLOR_BLUE
, CONSOLE_COLOR_MAGENTA
, CONSOLE_COLOR_CYAN
,
620 static void test_pattern (void)
622 ushort v_max
= panel_info
.vl_row
;
623 ushort h_max
= panel_info
.vl_col
;
624 ushort v_step
= (v_max
+ N_BLK_VERT
- 1) / N_BLK_VERT
;
625 ushort h_step
= (h_max
+ N_BLK_HOR
- 1) / N_BLK_HOR
;
627 uchar
*pix
= (uchar
*)lcd_base
;
629 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
630 h_max
, v_max
, h_step
, v_step
);
632 /* WARNING: Code silently assumes 8bit/pixel */
633 for (v
=0; v
<v_max
; ++v
) {
634 uchar iy
= v
/ v_step
;
635 for (h
=0; h
<h_max
; ++h
) {
636 uchar ix
= N_BLK_HOR
* iy
+ (h
/h_step
);
637 *pix
++ = test_colors
[ix
];
641 #endif /* LCD_TEST_PATTERN */
644 /************************************************************************/
645 /* ** GENERIC Initialization Routines */
646 /************************************************************************/
648 int drv_lcd_init (void)
650 DECLARE_GLOBAL_DATA_PTR
;
655 lcd_base
= (void *)(gd
->fb_base
);
657 lcd_line_length
= (panel_info
.vl_col
* NBITS (panel_info
.vl_bpix
)) / 8;
659 lcd_init (lcd_base
); /* LCD initialization */
661 /* Device initialization */
662 memset (&lcddev
, 0, sizeof (lcddev
));
664 strcpy (lcddev
.name
, "lcd");
665 lcddev
.ext
= 0; /* No extensions */
666 lcddev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
667 lcddev
.putc
= lcd_putc
; /* 'putc' function */
668 lcddev
.puts
= lcd_puts
; /* 'puts' function */
670 rc
= device_register (&lcddev
);
672 return (rc
== 0) ? 1 : rc
;
675 /*----------------------------------------------------------------------*/
677 static int lcd_init (void *lcdbase
)
679 /* Initialize the lcd controller */
680 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase
);
682 lcd_ctrl_init (lcdbase
);
684 #if LCD_BPP == LCD_MONOCHROME
685 /* Setting the palette */
688 #elif LCD_BPP == LCD_COLOR8
689 /* Setting the palette */
690 lcd_setcolreg (CONSOLE_COLOR_BLACK
, 0, 0, 0);
691 lcd_setcolreg (CONSOLE_COLOR_RED
, 0xFF, 0, 0);
692 lcd_setcolreg (CONSOLE_COLOR_GREEN
, 0, 0xFF, 0);
693 lcd_setcolreg (CONSOLE_COLOR_YELLOW
, 0xFF, 0xFF, 0);
694 lcd_setcolreg (CONSOLE_COLOR_BLUE
, 0, 0, 0xFF);
695 lcd_setcolreg (CONSOLE_COLOR_MAGENTA
, 0xFF, 0, 0xFF);
696 lcd_setcolreg (CONSOLE_COLOR_CYAN
, 0, 0xFF, 0xFF);
697 lcd_setcolreg (CONSOLE_COLOR_GREY
, 0xAA, 0xAA, 0xAA);
698 lcd_setcolreg (CONSOLE_COLOR_WHITE
, 0xFF, 0xFF, 0xFF);
701 #ifndef CFG_WHITE_ON_BLACK
702 lcd_setfgcolor (CONSOLE_COLOR_BLACK
);
703 lcd_setbgcolor (CONSOLE_COLOR_WHITE
);
705 lcd_setfgcolor (CONSOLE_COLOR_WHITE
);
706 lcd_setbgcolor (CONSOLE_COLOR_BLACK
);
707 #endif /* CFG_WHITE_ON_BLACK */
709 #ifdef LCD_TEST_PATTERN
712 /* set framebuffer to background color */
713 memset ((char *)lcd_base
,
714 COLOR_MASK(lcd_getbgcolor()),
715 lcd_line_length
*panel_info
.vl_row
);
720 /* Paint the logo and retrieve LCD base address */
721 debug ("[LCD] Drawing the logo...\n");
722 lcd_console_address
= lcd_logo ();
724 /* Initialize the console */
726 #ifdef LCD_INFO_BELOW_LOGO
727 console_row
= 7 + BMP_LOGO_HEIGHT
/ VIDEO_FONT_HEIGHT
;
729 console_row
= 1; /* leave 1 blank line below logo */
737 /************************************************************************/
738 /* ** ROM capable initialization part - needed to reserve FB memory */
739 /************************************************************************/
742 * This is called early in the system initialization to grab memory
743 * for the LCD controller.
744 * Returns new address for monitor, after reserving LCD buffer memory
746 * Note that this is running from ROM, so no write access to global data.
748 ulong
lcd_setmem (ulong addr
)
751 int line_length
= (panel_info
.vl_col
* NBITS (panel_info
.vl_bpix
)) / 8;
753 debug ("LCD panel info: %d x %d, %d bit/pix\n",
754 panel_info
.vl_col
, panel_info
.vl_row
, NBITS (panel_info
.vl_bpix
) );
756 size
= line_length
* panel_info
.vl_row
;
758 /* Round up to nearest full page */
759 size
= (size
+ (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
761 /* Allocate pages for the frame buffer. */
764 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size
>>10, addr
);
770 /************************************************************************/
771 /* ----------------- chipset specific functions ----------------------- */
772 /************************************************************************/
774 static void lcd_ctrl_init (void *lcdbase
)
776 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
777 volatile lcd823_t
*lcdp
= &immr
->im_lcd
;
781 /* Initialize the LCD control register according to the LCD
782 * parameters defined. We do everything here but enable
786 lccrtmp
= LCDBIT (LCCR_BNUM_BIT
,
787 (((panel_info
.vl_row
* panel_info
.vl_col
) * (1 << LCD_BPP
)) / 128));
789 lccrtmp
|= LCDBIT (LCCR_CLKP_BIT
, panel_info
.vl_clkp
) |
790 LCDBIT (LCCR_OEP_BIT
, panel_info
.vl_oep
) |
791 LCDBIT (LCCR_HSP_BIT
, panel_info
.vl_hsp
) |
792 LCDBIT (LCCR_VSP_BIT
, panel_info
.vl_vsp
) |
793 LCDBIT (LCCR_DP_BIT
, panel_info
.vl_dp
) |
794 LCDBIT (LCCR_BPIX_BIT
, panel_info
.vl_bpix
) |
795 LCDBIT (LCCR_LBW_BIT
, panel_info
.vl_lbw
) |
796 LCDBIT (LCCR_SPLT_BIT
, panel_info
.vl_splt
) |
797 LCDBIT (LCCR_CLOR_BIT
, panel_info
.vl_clor
) |
798 LCDBIT (LCCR_TFT_BIT
, panel_info
.vl_tft
);
801 lccrtmp
|= ((SIU_LEVEL5
/ 2) << 12);
802 lccrtmp
|= LCCR_EIEN
;
805 lcdp
->lcd_lccr
= lccrtmp
;
806 lcdp
->lcd_lcsr
= 0xFF; /* Clear pending interrupts */
808 /* Initialize LCD controller bus priorities.
810 immr
->im_siu_conf
.sc_sdcr
&= ~0x0f; /* RAID = LAID = 0 */
812 /* set SHFT/CLOCK division factor 4
813 * This needs to be set based upon display type and processor
814 * speed. The TFT displays run about 20 to 30 MHz.
815 * I was running 64 MHz processor speed.
816 * The value for this divider must be chosen so the result is
817 * an integer of the processor speed (i.e., divide by 3 with
818 * 64 MHz would be bad).
820 immr
->im_clkrst
.car_sccr
&= ~0x1F;
821 immr
->im_clkrst
.car_sccr
|= LCD_DF
; /* was 8 */
823 #ifndef CONFIG_EDT32F10
824 /* Enable LCD on port D.
826 immr
->im_ioport
.iop_pdpar
|= 0x1FFF;
827 immr
->im_ioport
.iop_pddir
|= 0x1FFF;
829 /* Enable LCD_A/B/C on port B.
831 immr
->im_cpm
.cp_pbpar
|= 0x00005001;
832 immr
->im_cpm
.cp_pbdir
|= 0x00005001;
834 /* Enable LCD on port D.
836 immr
->im_ioport
.iop_pdpar
|= 0x1DFF;
837 immr
->im_ioport
.iop_pdpar
&= ~0x0200;
838 immr
->im_ioport
.iop_pddir
|= 0x1FFF;
839 immr
->im_ioport
.iop_pddat
|= 0x0200;
842 /* Load the physical address of the linear frame buffer
843 * into the LCD controller.
844 * BIG NOTE: This has to be modified to load A and B depending
845 * upon the split mode of the LCD.
847 lcdp
->lcd_lcfaa
= (ulong
)lcd_base
;
848 lcdp
->lcd_lcfba
= (ulong
)lcd_base
;
850 /* MORE HACKS...This must be updated according to 823 manual
851 * for different panels.
853 #ifndef CONFIG_EDT32F10
854 lcdp
->lcd_lchcr
= LCHCR_BO
|
855 LCDBIT (LCHCR_AT_BIT
, 4) |
856 LCDBIT (LCHCR_HPC_BIT
, panel_info
.vl_col
) |
859 lcdp
->lcd_lchcr
= LCHCR_BO
|
860 LCDBIT (LCHCR_AT_BIT
, 4) |
861 LCDBIT (LCHCR_HPC_BIT
, panel_info
.vl_col
/4) |
865 lcdp
->lcd_lcvcr
= LCDBIT (LCVCR_VPW_BIT
, panel_info
.vl_vpw
) |
866 LCDBIT (LCVCR_LCD_AC_BIT
, panel_info
.vl_lcdac
) |
867 LCDBIT (LCVCR_VPC_BIT
, panel_info
.vl_row
) |
872 /*----------------------------------------------------------------------*/
874 #ifdef NOT_USED_SO_FAR
876 lcd_getcolreg (ushort regno
, ushort
*red
, ushort
*green
, ushort
*blue
)
878 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
879 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
880 unsigned short colreg
, *cmap_ptr
;
882 cmap_ptr
= (unsigned short *)&cp
->lcd_cmap
[regno
* 2];
885 #ifdef CFG_INVERT_COLORS
889 *red
= (colreg
>> 8) & 0x0F;
890 *green
= (colreg
>> 4) & 0x0F;
891 *blue
= colreg
& 0x0F;
893 #endif /* NOT_USED_SO_FAR */
895 /*----------------------------------------------------------------------*/
897 #if LCD_BPP == LCD_COLOR8
899 lcd_setcolreg (ushort regno
, ushort red
, ushort green
, ushort blue
)
901 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
902 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
903 unsigned short colreg
, *cmap_ptr
;
905 cmap_ptr
= (unsigned short *)&cp
->lcd_cmap
[regno
* 2];
907 colreg
= ((red
& 0x0F) << 8) |
908 ((green
& 0x0F) << 4) |
910 #ifdef CFG_INVERT_COLORS
915 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
916 regno
, &(cp
->lcd_cmap
[regno
* 2]),
918 cp
->lcd_cmap
[ regno
* 2 ], cp
->lcd_cmap
[(regno
* 2) + 1]);
920 #endif /* LCD_COLOR8 */
922 /*----------------------------------------------------------------------*/
924 #if LCD_BPP == LCD_MONOCHROME
926 void lcd_initcolregs (void)
928 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
929 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
932 for (regno
= 0; regno
< 16; regno
++) {
933 cp
->lcd_cmap
[regno
* 2] = 0;
934 cp
->lcd_cmap
[(regno
* 2) + 1] = regno
& 0x0f;
939 /*----------------------------------------------------------------------*/
941 static void lcd_setfgcolor (int color
)
943 lcd_color_fg
= color
& 0x0F;
946 /*----------------------------------------------------------------------*/
948 static void lcd_setbgcolor (int color
)
950 lcd_color_bg
= color
& 0x0F;
953 /*----------------------------------------------------------------------*/
955 #ifdef NOT_USED_SO_FAR
956 static int lcd_getfgcolor (void)
960 #endif /* NOT_USED_SO_FAR */
962 /*----------------------------------------------------------------------*/
964 static int lcd_getbgcolor (void)
969 /*----------------------------------------------------------------------*/
971 static void lcd_enable (void)
973 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
974 volatile lcd823_t
*lcdp
= &immr
->im_lcd
;
976 /* Enable the LCD panel */
977 immr
->im_siu_conf
.sc_sdcr
|= (1 << (31 - 25)); /* LAM = 1 */
978 lcdp
->lcd_lccr
|= LCCR_PON
;
981 /* Turn on display backlight */
982 immr
->im_cpm
.cp_pbpar
|= 0x00008000;
983 immr
->im_cpm
.cp_pbdir
|= 0x00008000;
986 #if defined(CONFIG_LWMON)
987 { uchar c
= pic_read (0x60);
988 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
989 c
|= 0x04; /* Chip Enable LCD */
991 c
|= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
995 #endif /* CONFIG_LWMON */
997 #if defined(CONFIG_R360MPI)
999 extern void r360_i2c_lcd_write (uchar data0
, uchar data1
);
1001 r360_i2c_lcd_write(0x10, 0x01);
1002 r360_i2c_lcd_write(0x20, 0x01);
1003 r360_i2c_lcd_write(0x3F, 0xFF);
1004 r360_i2c_lcd_write(0x47, 0xFF);
1006 #endif /* CONFIG_R360MPI */
1009 /*----------------------------------------------------------------------*/
1011 #ifdef NOT_USED_SO_FAR
1012 static void lcd_disable (void)
1014 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
1015 volatile lcd823_t
*lcdp
= &immr
->im_lcd
;
1017 #if defined(CONFIG_LWMON)
1018 { uchar c
= pic_read (0x60);
1019 c
&= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1020 pic_write (0x60, c
);
1022 #elif defined(CONFIG_R360MPI)
1024 extern void r360_i2c_lcd_write (uchar data0
, uchar data1
);
1026 r360_i2c_lcd_write(0x10, 0x00);
1027 r360_i2c_lcd_write(0x20, 0x00);
1028 r360_i2c_lcd_write(0x30, 0x00);
1029 r360_i2c_lcd_write(0x40, 0x00);
1031 #endif /* CONFIG_LWMON */
1032 /* Disable the LCD panel */
1033 lcdp
->lcd_lccr
&= ~LCCR_PON
;
1034 immr
->im_siu_conf
.sc_sdcr
&= ~(1 << (31 - 25)); /* LAM = 0 */
1036 #endif /* NOT_USED_SO_FAR */
1039 /************************************************************************/
1040 /* ** Chipset depending Bitmap / Logo stuff... */
1041 /************************************************************************/
1044 #ifdef CONFIG_LCD_LOGO
1045 static void bitmap_plot (int x
, int y
)
1047 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
1048 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
1054 debug ("Logo: width %d height %d colors %d cmap %d\n",
1055 BMP_LOGO_WIDTH
, BMP_LOGO_HEIGHT
, BMP_LOGO_COLORS
,
1056 sizeof(bmp_logo_palette
)/(sizeof(ushort
))
1059 /* Leave room for default color map */
1060 cmap
= (ushort
*)&(cp
->lcd_cmap
[BMP_LOGO_OFFSET
*sizeof(ushort
)]);
1063 for (i
=0; i
<(sizeof(bmp_logo_palette
)/(sizeof(ushort
))); ++i
) {
1064 ushort colreg
= bmp_logo_palette
[i
];
1065 #ifdef CFG_INVERT_COLORS
1071 bmap
= &bmp_logo_bitmap
[0];
1072 fb
= (char *)(lcd_base
+ y
* lcd_line_length
+ x
);
1074 for (i
=0; i
<BMP_LOGO_HEIGHT
; ++i
) {
1075 memcpy (fb
, bmap
, BMP_LOGO_WIDTH
);
1076 bmap
+= BMP_LOGO_WIDTH
;
1077 fb
+= panel_info
.vl_col
;
1080 #endif /* CONFIG_LCD_LOGO */
1082 #if (CONFIG_COMMANDS & CFG_CMD_BMP)
1084 * Display the BMP file located at address bmp_image.
1087 int lcd_display_bitmap(ulong bmp_image
)
1089 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
1090 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
1094 bmp_image_t
*bmp
=(bmp_image_t
*)bmp_image
;
1097 unsigned long width
, height
;
1098 unsigned colors
,bpix
;
1099 unsigned long compression
;
1101 if (!((bmp
->header
.signature
[0]=='B') &&
1102 (bmp
->header
.signature
[1]=='M'))) {
1103 printf ("Error: no valid bmp image at %lx\n", bmp_image
);
1107 width
= le32_to_cpu (bmp
->header
.width
);
1108 height
= le32_to_cpu (bmp
->header
.height
);
1109 colors
= 1<<le16_to_cpu (bmp
->header
.bit_count
);
1110 compression
= le32_to_cpu (bmp
->header
.compression
);
1112 bpix
= NBITS(panel_info
.vl_bpix
);
1114 if ((bpix
!= 1) && (bpix
!= 8)) {
1115 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1120 if (bpix
!= le16_to_cpu(bmp
->header
.bit_count
)) {
1121 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1123 le16_to_cpu(bmp
->header
.bit_count
));
1127 if (compression
!=BMP_BI_RGB
) {
1128 printf ("Error: compression type %ld not supported\n",
1133 debug ("Display-bmp: %d x %d with %d colors\n",
1134 width
, height
, colors
);
1137 /* Fill the entire color map */
1138 cmap
= (ushort
*)&(cp
->lcd_cmap
[255*sizeof(ushort
)]);
1141 for (i
= 0; i
< colors
; ++i
) {
1142 bmp_color_table_entry_t cte
= bmp
->color_table
[i
];
1144 ((cte
.red
>>4) << 8) |
1145 ((cte
.green
>>4) << 4) |
1147 #ifdef CFG_INVERT_COLORS
1154 padded_line
= (width
&0x3) ? ((width
&~0x3)+4) : (width
);
1155 if (width
>panel_info
.vl_col
)
1156 width
= panel_info
.vl_col
;
1157 if (height
>panel_info
.vl_row
)
1158 height
= panel_info
.vl_row
;
1160 bmap
= (uchar
*)bmp
+ le32_to_cpu (bmp
->header
.data_offset
);
1163 (((height
>=panel_info
.vl_row
) ? panel_info
.vl_row
: height
)-1)
1165 for (i
= 0; i
< height
; ++i
) {
1166 for (j
= 0; j
< width
; j
++)
1167 *(fb
++)=255-*(bmap
++);
1168 bmap
+= (width
- padded_line
);
1169 fb
-= (width
+ lcd_line_length
);
1174 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
1176 /*----------------------------------------------------------------------*/
1178 static void *lcd_logo (void)
1181 DECLARE_GLOBAL_DATA_PTR
;
1185 #endif /* LCD_INFO */
1187 #ifdef CONFIG_SPLASH_SCREEN
1191 if ((s
= getenv("splashimage")) != NULL
) {
1192 addr
= simple_strtoul(s
, NULL
, 16);
1194 if (lcd_display_bitmap (addr
) == 0) {
1195 return ((void *)lcd_base
);
1198 #endif /* CONFIG_SPLASH_SCREEN */
1200 #ifdef CONFIG_LCD_LOGO
1202 #endif /* CONFIG_LCD_LOGO */
1206 sprintf (info
, "%s (%s - %s) ", U_BOOT_VERSION
, __DATE__
, __TIME__
);
1207 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
, info
, strlen(info
));
1209 sprintf (info
, "(C) 2003 DENX Software Engineering");
1210 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
,
1211 info
, strlen(info
));
1213 sprintf (info
, " Wolfgang DENK, wd@denx.de");
1214 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 2,
1215 info
, strlen(info
));
1216 #ifdef LCD_INFO_BELOW_LOGO
1217 sprintf (info
, "MPC823 CPU at %s MHz",
1218 strmhz(temp
, gd
->cpu_clk
));
1219 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 3,
1220 info
, strlen(info
));
1221 sprintf (info
, " %ld MB RAM, %ld MB Flash",
1223 gd
->bd
->bi_flashsize
>> 20 );
1224 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 4,
1225 info
, strlen(info
));
1227 /* leave one blank line */
1229 sprintf (info
, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1230 strmhz(temp
, gd
->cpu_clk
),
1232 gd
->bd
->bi_flashsize
>> 20 );
1233 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 4,
1234 info
, strlen(info
));
1235 #endif /* LCD_INFO_BELOW_LOGO */
1236 #endif /* LCD_INFO */
1238 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1239 return ((void *)((ulong
)lcd_base
+ BMP_LOGO_HEIGHT
* lcd_line_length
));
1241 return ((void *)lcd_base
);
1242 #endif /* CONFIG_LCD_LOGO */
1245 /************************************************************************/
1246 /************************************************************************/
1248 #endif /* CONFIG_LCD */