2 * Common LCD routines for supported CPUs
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /************************************************************************/
28 /************************************************************************/
37 #include <linux/types.h>
39 #if defined(CONFIG_POST)
45 #if defined(CONFIG_PXA250)
46 #include <asm/byteorder.h>
49 #if defined(CONFIG_MPC823)
56 /************************************************************************/
58 /************************************************************************/
59 #include <video_font.h> /* Get font data, width and height */
61 /************************************************************************/
63 /************************************************************************/
64 #ifdef CONFIG_LCD_LOGO
65 # include <bmp_logo.h> /* Get logo data, width and height */
66 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
67 # error Default Color Map overlaps with Logo Color Map
71 ulong
lcd_setmem (ulong addr
);
73 static void lcd_drawchars (ushort x
, ushort y
, uchar
*str
, int count
);
74 static inline void lcd_puts_xy (ushort x
, ushort y
, uchar
*s
);
75 static inline void lcd_putc_xy (ushort x
, ushort y
, uchar c
);
77 static int lcd_init (void *lcdbase
);
79 static int lcd_clear (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[]);
80 extern void lcd_ctrl_init (void *lcdbase
);
81 extern void lcd_enable (void);
82 static void *lcd_logo (void);
85 #if LCD_BPP == LCD_COLOR8
86 extern void lcd_setcolreg (ushort regno
,
87 ushort red
, ushort green
, ushort blue
);
89 #if LCD_BPP == LCD_MONOCHROME
90 extern void lcd_initcolregs (void);
93 static int lcd_getbgcolor (void);
94 static void lcd_setfgcolor (int color
);
95 static void lcd_setbgcolor (int color
);
97 char lcd_is_enabled
= 0;
98 extern vidinfo_t panel_info
;
100 #ifdef NOT_USED_SO_FAR
101 static void lcd_getcolreg (ushort regno
,
102 ushort
*red
, ushort
*green
, ushort
*blue
);
103 static int lcd_getfgcolor (void);
104 #endif /* NOT_USED_SO_FAR */
106 /************************************************************************/
108 /*----------------------------------------------------------------------*/
110 static void console_scrollup (void)
113 /* Copy up rows ignoring the first one */
114 memcpy (CONSOLE_ROW_FIRST
, CONSOLE_ROW_SECOND
, CONSOLE_SCROLL_SIZE
);
116 /* Clear the last one */
117 memset (CONSOLE_ROW_LAST
, COLOR_MASK(lcd_color_bg
), CONSOLE_ROW_SIZE
);
120 * Poor attempt to optimize speed by moving "long"s.
121 * But the code is ugly, and not a bit faster :-(
123 ulong
*t
= (ulong
*)CONSOLE_ROW_FIRST
;
124 ulong
*s
= (ulong
*)CONSOLE_ROW_SECOND
;
125 ulong l
= CONSOLE_SCROLL_SIZE
/ sizeof(ulong
);
126 uchar c
= lcd_color_bg
& 0xFF;
127 ulong val
= (c
<<24) | (c
<<16) | (c
<<8) | c
;
132 t
= (ulong
*)CONSOLE_ROW_LAST
;
133 l
= CONSOLE_ROW_SIZE
/ sizeof(ulong
);
140 /*----------------------------------------------------------------------*/
142 static inline void console_back (void)
144 if (--console_col
< 0) {
145 console_col
= CONSOLE_COLS
-1 ;
146 if (--console_row
< 0) {
151 lcd_putc_xy (console_col
* VIDEO_FONT_WIDTH
,
152 console_row
* VIDEO_FONT_HEIGHT
,
156 /*----------------------------------------------------------------------*/
158 static inline void console_newline (void)
163 /* Check if we need to scroll the terminal */
164 if (console_row
>= CONSOLE_ROWS
) {
165 /* Scroll everything up */
166 console_scrollup () ;
171 /*----------------------------------------------------------------------*/
173 void lcd_putc (const char c
)
175 if (!lcd_is_enabled
) {
181 case '\r': console_col
= 0;
184 case '\n': console_newline();
187 case '\t': /* Tab (8 chars alignment) */
191 if (console_col
>= CONSOLE_COLS
) {
196 case '\b': console_back();
199 default: lcd_putc_xy (console_col
* VIDEO_FONT_WIDTH
,
200 console_row
* VIDEO_FONT_HEIGHT
,
202 if (++console_col
>= CONSOLE_COLS
) {
210 /*----------------------------------------------------------------------*/
212 void lcd_puts (const char *s
)
214 if (!lcd_is_enabled
) {
224 /************************************************************************/
225 /* ** Low-Level Graphics Routines */
226 /************************************************************************/
228 static void lcd_drawchars (ushort x
, ushort y
, uchar
*str
, int count
)
233 dest
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
* (1 << LCD_BPP
) / 8);
234 off
= x
* (1 << LCD_BPP
) % 8;
236 for (row
=0; row
< VIDEO_FONT_HEIGHT
; ++row
, dest
+= lcd_line_length
) {
241 #if LCD_BPP == LCD_MONOCHROME
242 uchar rest
= *d
& -(1 << (8-off
));
245 for (i
=0; i
<count
; ++i
) {
249 bits
= video_fontdata
[c
* VIDEO_FONT_HEIGHT
+ row
];
251 #if LCD_BPP == LCD_MONOCHROME
252 sym
= (COLOR_MASK(lcd_color_fg
) & bits
) |
253 (COLOR_MASK(lcd_color_bg
) & ~bits
);
255 *d
++ = rest
| (sym
>> off
);
256 rest
= sym
<< (8-off
);
257 #elif LCD_BPP == LCD_COLOR8
258 for (c
=0; c
<8; ++c
) {
259 *d
++ = (bits
& 0x80) ?
260 lcd_color_fg
: lcd_color_bg
;
263 #elif LCD_BPP == LCD_COLOR16
264 for (c
=0; c
<16; ++c
) {
265 *d
++ = (bits
& 0x80) ?
266 lcd_color_fg
: lcd_color_bg
;
271 #if LCD_BPP == LCD_MONOCHROME
272 *d
= rest
| (*d
& ((1 << (8-off
)) - 1));
277 /*----------------------------------------------------------------------*/
279 static inline void lcd_puts_xy (ushort x
, ushort y
, uchar
*s
)
281 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
282 lcd_drawchars (x
, y
+BMP_LOGO_HEIGHT
, s
, strlen ((char *)s
));
284 lcd_drawchars (x
, y
, s
, strlen ((char *)s
));
288 /*----------------------------------------------------------------------*/
290 static inline void lcd_putc_xy (ushort x
, ushort y
, uchar c
)
292 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
293 lcd_drawchars (x
, y
+BMP_LOGO_HEIGHT
, &c
, 1);
295 lcd_drawchars (x
, y
, &c
, 1);
299 /************************************************************************/
300 /** Small utility to check that you got the colours right */
301 /************************************************************************/
302 #ifdef LCD_TEST_PATTERN
307 static int test_colors
[N_BLK_HOR
*N_BLK_VERT
] = {
308 CONSOLE_COLOR_RED
, CONSOLE_COLOR_GREEN
, CONSOLE_COLOR_YELLOW
,
309 CONSOLE_COLOR_BLUE
, CONSOLE_COLOR_MAGENTA
, CONSOLE_COLOR_CYAN
,
312 static void test_pattern (void)
314 ushort v_max
= panel_info
.vl_row
;
315 ushort h_max
= panel_info
.vl_col
;
316 ushort v_step
= (v_max
+ N_BLK_VERT
- 1) / N_BLK_VERT
;
317 ushort h_step
= (h_max
+ N_BLK_HOR
- 1) / N_BLK_HOR
;
319 uchar
*pix
= (uchar
*)lcd_base
;
321 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
322 h_max
, v_max
, h_step
, v_step
);
324 /* WARNING: Code silently assumes 8bit/pixel */
325 for (v
=0; v
<v_max
; ++v
) {
326 uchar iy
= v
/ v_step
;
327 for (h
=0; h
<h_max
; ++h
) {
328 uchar ix
= N_BLK_HOR
* iy
+ (h
/h_step
);
329 *pix
++ = test_colors
[ix
];
333 #endif /* LCD_TEST_PATTERN */
336 /************************************************************************/
337 /* ** GENERIC Initialization Routines */
338 /************************************************************************/
340 int drv_lcd_init (void)
342 DECLARE_GLOBAL_DATA_PTR
;
347 lcd_base
= (void *)(gd
->fb_base
);
349 lcd_line_length
= (panel_info
.vl_col
* NBITS (panel_info
.vl_bpix
)) / 8;
351 lcd_init (lcd_base
); /* LCD initialization */
353 /* Device initialization */
354 memset (&lcddev
, 0, sizeof (lcddev
));
356 strcpy (lcddev
.name
, "lcd");
357 lcddev
.ext
= 0; /* No extensions */
358 lcddev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
359 lcddev
.putc
= lcd_putc
; /* 'putc' function */
360 lcddev
.puts
= lcd_puts
; /* 'puts' function */
362 rc
= device_register (&lcddev
);
364 return (rc
== 0) ? 1 : rc
;
367 /*----------------------------------------------------------------------*/
368 static int lcd_clear (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
370 #if LCD_BPP == LCD_MONOCHROME
371 /* Setting the palette */
374 #elif LCD_BPP == LCD_COLOR8
375 /* Setting the palette */
376 lcd_setcolreg (CONSOLE_COLOR_BLACK
, 0, 0, 0);
377 lcd_setcolreg (CONSOLE_COLOR_RED
, 0xFF, 0, 0);
378 lcd_setcolreg (CONSOLE_COLOR_GREEN
, 0, 0xFF, 0);
379 lcd_setcolreg (CONSOLE_COLOR_YELLOW
, 0xFF, 0xFF, 0);
380 lcd_setcolreg (CONSOLE_COLOR_BLUE
, 0, 0, 0xFF);
381 lcd_setcolreg (CONSOLE_COLOR_MAGENTA
, 0xFF, 0, 0xFF);
382 lcd_setcolreg (CONSOLE_COLOR_CYAN
, 0, 0xFF, 0xFF);
383 lcd_setcolreg (CONSOLE_COLOR_GREY
, 0xAA, 0xAA, 0xAA);
384 lcd_setcolreg (CONSOLE_COLOR_WHITE
, 0xFF, 0xFF, 0xFF);
387 #ifndef CFG_WHITE_ON_BLACK
388 lcd_setfgcolor (CONSOLE_COLOR_BLACK
);
389 lcd_setbgcolor (CONSOLE_COLOR_WHITE
);
391 lcd_setfgcolor (CONSOLE_COLOR_WHITE
);
392 lcd_setbgcolor (CONSOLE_COLOR_BLACK
);
393 #endif /* CFG_WHITE_ON_BLACK */
395 #ifdef LCD_TEST_PATTERN
398 /* set framebuffer to background color */
399 memset ((char *)lcd_base
,
400 COLOR_MASK(lcd_getbgcolor()),
401 lcd_line_length
*panel_info
.vl_row
);
403 /* Paint the logo and retrieve LCD base address */
404 debug ("[LCD] Drawing the logo...\n");
405 lcd_console_address
= lcd_logo ();
414 cls
, 1, 1, lcd_clear
,
415 "cls - clear screen\n",
419 /*----------------------------------------------------------------------*/
421 static int lcd_init (void *lcdbase
)
423 /* Initialize the lcd controller */
424 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase
);
426 lcd_ctrl_init (lcdbase
);
427 lcd_clear (NULL
, 1, 1, NULL
); /* dummy args */
430 /* Initialize the console */
432 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
433 console_row
= 7 + BMP_LOGO_HEIGHT
/ VIDEO_FONT_HEIGHT
;
435 console_row
= 1; /* leave 1 blank line below logo */
443 /************************************************************************/
444 /* ** ROM capable initialization part - needed to reserve FB memory */
445 /************************************************************************/
447 * This is called early in the system initialization to grab memory
448 * for the LCD controller.
449 * Returns new address for monitor, after reserving LCD buffer memory
451 * Note that this is running from ROM, so no write access to global data.
453 ulong
lcd_setmem (ulong addr
)
456 int line_length
= (panel_info
.vl_col
* NBITS (panel_info
.vl_bpix
)) / 8;
458 debug ("LCD panel info: %d x %d, %d bit/pix\n",
459 panel_info
.vl_col
, panel_info
.vl_row
, NBITS (panel_info
.vl_bpix
) );
461 size
= line_length
* panel_info
.vl_row
;
463 /* Round up to nearest full page */
464 size
= (size
+ (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
466 /* Allocate pages for the frame buffer. */
469 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size
>>10, addr
);
474 /*----------------------------------------------------------------------*/
476 static void lcd_setfgcolor (int color
)
478 lcd_color_fg
= color
& 0x0F;
481 /*----------------------------------------------------------------------*/
483 static void lcd_setbgcolor (int color
)
485 lcd_color_bg
= color
& 0x0F;
488 /*----------------------------------------------------------------------*/
490 #ifdef NOT_USED_SO_FAR
491 static int lcd_getfgcolor (void)
495 #endif /* NOT_USED_SO_FAR */
497 /*----------------------------------------------------------------------*/
499 static int lcd_getbgcolor (void)
504 /*----------------------------------------------------------------------*/
506 /************************************************************************/
507 /* ** Chipset depending Bitmap / Logo stuff... */
508 /************************************************************************/
509 #ifdef CONFIG_LCD_LOGO
510 void bitmap_plot (int x
, int y
)
517 #if defined(CONFIG_PXA250)
518 struct pxafb_info
*fbi
= &panel_info
.pxa
;
519 #elif defined(CONFIG_MPC823)
520 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
521 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
524 debug ("Logo: width %d height %d colors %d cmap %d\n",
525 BMP_LOGO_WIDTH
, BMP_LOGO_HEIGHT
, BMP_LOGO_COLORS
,
526 sizeof(bmp_logo_palette
)/(sizeof(ushort
)));
528 bmap
= &bmp_logo_bitmap
[0];
529 fb
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
);
531 if (NBITS(panel_info
.vl_bpix
) < 12) {
532 /* Leave room for default color map */
533 #if defined(CONFIG_PXA250)
534 cmap
= (ushort
*)fbi
->palette
;
535 #elif defined(CONFIG_MPC823)
536 cmap
= (ushort
*)&(cp
->lcd_cmap
[BMP_LOGO_OFFSET
*sizeof(ushort
)]);
542 for (i
=0; i
<(sizeof(bmp_logo_palette
)/(sizeof(ushort
))); ++i
) {
543 ushort colreg
= bmp_logo_palette
[i
];
544 #ifdef CFG_INVERT_COLORS
545 *cmap
++ = 0xffff - colreg
;
553 for (i
=0; i
<BMP_LOGO_HEIGHT
; ++i
) {
554 memcpy (fb
, bmap
, BMP_LOGO_WIDTH
);
555 bmap
+= BMP_LOGO_WIDTH
;
556 fb
+= panel_info
.vl_col
;
559 else { /* true color mode */
560 fb16
= (ushort
*)(lcd_base
+ y
* lcd_line_length
+ x
);
561 for (i
=0; i
<BMP_LOGO_HEIGHT
; ++i
) {
562 for (j
=0; j
<BMP_LOGO_WIDTH
; j
++) {
563 fb16
[j
] = bmp_logo_palette
[(bmap
[j
])];
565 bmap
+= BMP_LOGO_WIDTH
;
566 fb16
+= panel_info
.vl_col
;
572 #endif /* CONFIG_LCD_LOGO */
574 /*----------------------------------------------------------------------*/
575 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
577 * Display the BMP file located at address bmp_image.
580 int lcd_display_bitmap(ulong bmp_image
, int x
, int y
)
585 bmp_image_t
*bmp
=(bmp_image_t
*)bmp_image
;
588 unsigned long width
, height
;
589 unsigned colors
,bpix
;
590 unsigned long compression
;
591 #if defined(CONFIG_PXA250)
592 struct pxafb_info
*fbi
= &panel_info
.pxa
;
593 #elif defined(CONFIG_MPC823)
594 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
595 volatile cpm8xx_t
*cp
= &(immr
->im_cpm
);
598 if (!((bmp
->header
.signature
[0]=='B') &&
599 (bmp
->header
.signature
[1]=='M'))) {
600 printf ("Error: no valid bmp image at %lx\n", bmp_image
);
604 width
= le32_to_cpu (bmp
->header
.width
);
605 height
= le32_to_cpu (bmp
->header
.height
);
606 colors
= 1<<le16_to_cpu (bmp
->header
.bit_count
);
607 compression
= le32_to_cpu (bmp
->header
.compression
);
609 bpix
= NBITS(panel_info
.vl_bpix
);
611 if ((bpix
!= 1) && (bpix
!= 8)) {
612 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
617 if (bpix
!= le16_to_cpu(bmp
->header
.bit_count
)) {
618 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
620 le16_to_cpu(bmp
->header
.bit_count
));
624 debug ("Display-bmp: %d x %d with %d colors\n",
625 (int)width
, (int)height
, (int)colors
);
628 #if defined(CONFIG_PXA250)
629 cmap
= (ushort
*)fbi
->palette
;
630 #elif defined(CONFIG_MPC823)
631 cmap
= (ushort
*)&(cp
->lcd_cmap
[255*sizeof(ushort
)]);
633 # error "Don't know location of color map"
637 for (i
=0; i
<colors
; ++i
) {
638 bmp_color_table_entry_t cte
= bmp
->color_table
[i
];
640 ( ((cte
.red
) << 8) & 0xf800) |
641 ( ((cte
.green
) << 3) & 0x07e0) |
642 ( ((cte
.blue
) >> 3) & 0x001f) ;
643 #ifdef CFG_INVERT_COLORS
644 *cmap
= 0xffff - colreg
;
648 #if defined(CONFIG_PXA250)
650 #elif defined(CONFIG_MPC823)
656 padded_line
= (width
&0x3) ? ((width
&~0x3)+4) : (width
);
657 if ((x
+ width
)>panel_info
.vl_col
)
658 width
= panel_info
.vl_col
- x
;
659 if ((y
+ height
)>panel_info
.vl_row
)
660 height
= panel_info
.vl_row
- y
;
662 bmap
= (uchar
*)bmp
+ le32_to_cpu (bmp
->header
.data_offset
);
663 fb
= (uchar
*) (lcd_base
+
664 (y
+ height
- 1) * lcd_line_length
+ x
);
665 for (i
= 0; i
< height
; ++i
) {
667 for (j
= 0; j
< width
; j
++)
668 #if defined(CONFIG_PXA250)
670 #elif defined(CONFIG_MPC823)
671 *(fb
++)=255-*(bmap
++);
673 bmap
+= (width
- padded_line
);
674 fb
-= (width
+ lcd_line_length
);
679 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
682 static void *lcd_logo (void)
684 #ifdef CONFIG_LCD_INFO
685 DECLARE_GLOBAL_DATA_PTR
;
689 #endif /* CONFIG_LCD_INFO */
691 #ifdef CONFIG_SPLASH_SCREEN
694 static int do_splash
= 1;
696 if (do_splash
&& (s
= getenv("splashimage")) != NULL
) {
697 addr
= simple_strtoul(s
, NULL
, 16);
700 if (lcd_display_bitmap (addr
, 0, 0) == 0) {
701 return ((void *)lcd_base
);
704 #endif /* CONFIG_SPLASH_SCREEN */
706 #ifdef CONFIG_LCD_LOGO
708 #endif /* CONFIG_LCD_LOGO */
711 # ifdef CONFIG_LCD_INFO
712 sprintf (info
, "%s (%s - %s) ", U_BOOT_VERSION
, __DATE__
, __TIME__
);
713 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
, (uchar
*)info
, strlen(info
));
715 sprintf (info
, "(C) 2004 DENX Software Engineering");
716 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
,
717 (uchar
*)info
, strlen(info
));
719 sprintf (info
, " Wolfgang DENK, wd@denx.de");
720 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 2,
721 (uchar
*)info
, strlen(info
));
722 # ifdef CONFIG_LCD_INFO_BELOW_LOGO
723 sprintf (info
, "MPC823 CPU at %s MHz",
724 strmhz(temp
, gd
->cpu_clk
));
725 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 3,
727 sprintf (info
, " %ld MB RAM, %ld MB Flash",
729 gd
->bd
->bi_flashsize
>> 20 );
730 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 4,
733 /* leave one blank line */
735 sprintf (info
, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
736 strmhz(temp
, gd
->cpu_clk
),
738 gd
->bd
->bi_flashsize
>> 20 );
739 lcd_drawchars (LCD_INFO_X
, LCD_INFO_Y
+ VIDEO_FONT_HEIGHT
* 4,
740 (uchar
*)info
, strlen(info
));
742 # endif /* CONFIG_LCD_INFO_BELOW_LOGO */
743 # endif /* CONFIG_LCD_INFO */
744 #endif /* CONFIG_MPC823 */
746 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
747 return ((void *)((ulong
)lcd_base
+ BMP_LOGO_HEIGHT
* lcd_line_length
));
749 return ((void *)lcd_base
);
750 #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
753 /************************************************************************/
754 /************************************************************************/
756 #endif /* CONFIG_LCD */