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)
55 /************************************************************************/
57 /************************************************************************/
58 #include <video_font.h> /* Get font data, width and height */
60 /************************************************************************/
62 /************************************************************************/
63 #ifdef CONFIG_LCD_LOGO
64 # include <bmp_logo.h> /* Get logo data, width and height */
65 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
66 # error Default Color Map overlaps with Logo Color Map
70 DECLARE_GLOBAL_DATA_PTR;
72 ulong lcd_setmem (ulong addr);
74 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
75 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
76 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
78 static int lcd_init (void *lcdbase);
80 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
81 extern void lcd_ctrl_init (void *lcdbase);
82 extern void lcd_enable (void);
83 static void *lcd_logo (void);
86 #if LCD_BPP == LCD_COLOR8
87 extern void lcd_setcolreg (ushort regno,
88 ushort red, ushort green, ushort blue);
90 #if LCD_BPP == LCD_MONOCHROME
91 extern void lcd_initcolregs (void);
94 static int lcd_getbgcolor (void);
95 static void lcd_setfgcolor (int color);
96 static void lcd_setbgcolor (int color);
98 char lcd_is_enabled = 0;
99 extern vidinfo_t panel_info;
101 #ifdef NOT_USED_SO_FAR
102 static void lcd_getcolreg (ushort regno,
103 ushort *red, ushort *green, ushort *blue);
104 static int lcd_getfgcolor (void);
105 #endif /* NOT_USED_SO_FAR */
107 /************************************************************************/
109 /*----------------------------------------------------------------------*/
111 static void console_scrollup (void)
114 /* Copy up rows ignoring the first one */
115 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
117 /* Clear the last one */
118 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
121 * Poor attempt to optimize speed by moving "long"s.
122 * But the code is ugly, and not a bit faster :-(
124 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
125 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
126 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
127 uchar c = lcd_color_bg & 0xFF;
128 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
133 t = (ulong *)CONSOLE_ROW_LAST;
134 l = CONSOLE_ROW_SIZE / sizeof(ulong);
141 /*----------------------------------------------------------------------*/
143 static inline void console_back (void)
145 if (--console_col < 0) {
146 console_col = CONSOLE_COLS-1 ;
147 if (--console_row < 0) {
152 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
153 console_row * VIDEO_FONT_HEIGHT,
157 /*----------------------------------------------------------------------*/
159 static inline void console_newline (void)
164 /* Check if we need to scroll the terminal */
165 if (console_row >= CONSOLE_ROWS) {
166 /* Scroll everything up */
167 console_scrollup () ;
172 /*----------------------------------------------------------------------*/
174 void lcd_putc (const char c)
176 if (!lcd_is_enabled) {
182 case '\r': console_col = 0;
185 case '\n': console_newline();
188 case '\t': /* Tab (8 chars alignment) */
192 if (console_col >= CONSOLE_COLS) {
197 case '\b': console_back();
200 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
201 console_row * VIDEO_FONT_HEIGHT,
203 if (++console_col >= CONSOLE_COLS) {
211 /*----------------------------------------------------------------------*/
213 void lcd_puts (const char *s)
215 if (!lcd_is_enabled) {
225 /************************************************************************/
226 /* ** Low-Level Graphics Routines */
227 /************************************************************************/
229 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
234 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
235 off = x * (1 << LCD_BPP) % 8;
237 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
242 #if LCD_BPP == LCD_MONOCHROME
243 uchar rest = *d & -(1 << (8-off));
246 for (i=0; i<count; ++i) {
250 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
252 #if LCD_BPP == LCD_MONOCHROME
253 sym = (COLOR_MASK(lcd_color_fg) & bits) |
254 (COLOR_MASK(lcd_color_bg) & ~bits);
256 *d++ = rest | (sym >> off);
257 rest = sym << (8-off);
258 #elif LCD_BPP == LCD_COLOR8
259 for (c=0; c<8; ++c) {
260 *d++ = (bits & 0x80) ?
261 lcd_color_fg : lcd_color_bg;
264 #elif LCD_BPP == LCD_COLOR16
265 for (c=0; c<16; ++c) {
266 *d++ = (bits & 0x80) ?
267 lcd_color_fg : lcd_color_bg;
272 #if LCD_BPP == LCD_MONOCHROME
273 *d = rest | (*d & ((1 << (8-off)) - 1));
278 /*----------------------------------------------------------------------*/
280 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
282 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
283 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen ((char *)s));
285 lcd_drawchars (x, y, s, strlen ((char *)s));
289 /*----------------------------------------------------------------------*/
291 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
293 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
294 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
296 lcd_drawchars (x, y, &c, 1);
300 /************************************************************************/
301 /** Small utility to check that you got the colours right */
302 /************************************************************************/
303 #ifdef LCD_TEST_PATTERN
308 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
309 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
310 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
313 static void test_pattern (void)
315 ushort v_max = panel_info.vl_row;
316 ushort h_max = panel_info.vl_col;
317 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
318 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
320 uchar *pix = (uchar *)lcd_base;
322 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
323 h_max, v_max, h_step, v_step);
325 /* WARNING: Code silently assumes 8bit/pixel */
326 for (v=0; v<v_max; ++v) {
327 uchar iy = v / v_step;
328 for (h=0; h<h_max; ++h) {
329 uchar ix = N_BLK_HOR * iy + (h/h_step);
330 *pix++ = test_colors[ix];
334 #endif /* LCD_TEST_PATTERN */
337 /************************************************************************/
338 /* ** GENERIC Initialization Routines */
339 /************************************************************************/
341 int drv_lcd_init (void)
346 lcd_base = (void *)(gd->fb_base);
348 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
350 lcd_init (lcd_base); /* LCD initialization */
352 /* Device initialization */
353 memset (&lcddev, 0, sizeof (lcddev));
355 strcpy (lcddev.name, "lcd");
356 lcddev.ext = 0; /* No extensions */
357 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
358 lcddev.putc = lcd_putc; /* 'putc' function */
359 lcddev.puts = lcd_puts; /* 'puts' function */
361 rc = device_register (&lcddev);
363 return (rc == 0) ? 1 : rc;
366 /*----------------------------------------------------------------------*/
367 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
369 #if LCD_BPP == LCD_MONOCHROME
370 /* Setting the palette */
373 #elif LCD_BPP == LCD_COLOR8
374 /* Setting the palette */
375 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
376 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
377 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
378 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
379 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
380 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
381 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
382 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
383 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
386 #ifndef CFG_WHITE_ON_BLACK
387 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
388 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
390 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
391 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
392 #endif /* CFG_WHITE_ON_BLACK */
394 #ifdef LCD_TEST_PATTERN
397 /* set framebuffer to background color */
398 memset ((char *)lcd_base,
399 COLOR_MASK(lcd_getbgcolor()),
400 lcd_line_length*panel_info.vl_row);
402 /* Paint the logo and retrieve LCD base address */
403 debug ("[LCD] Drawing the logo...\n");
404 lcd_console_address = lcd_logo ();
413 cls, 1, 1, lcd_clear,
414 "cls - clear screen\n",
418 /*----------------------------------------------------------------------*/
420 static int lcd_init (void *lcdbase)
422 /* Initialize the lcd controller */
423 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
425 lcd_ctrl_init (lcdbase);
426 lcd_clear (NULL, 1, 1, NULL); /* dummy args */
429 /* Initialize the console */
431 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
432 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
434 console_row = 1; /* leave 1 blank line below logo */
442 /************************************************************************/
443 /* ** ROM capable initialization part - needed to reserve FB memory */
444 /************************************************************************/
446 * This is called early in the system initialization to grab memory
447 * for the LCD controller.
448 * Returns new address for monitor, after reserving LCD buffer memory
450 * Note that this is running from ROM, so no write access to global data.
452 ulong lcd_setmem (ulong addr)
455 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
457 debug ("LCD panel info: %d x %d, %d bit/pix\n",
458 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
460 size = line_length * panel_info.vl_row;
462 /* Round up to nearest full page */
463 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
465 /* Allocate pages for the frame buffer. */
468 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
473 /*----------------------------------------------------------------------*/
475 static void lcd_setfgcolor (int color)
477 lcd_color_fg = color & 0x0F;
480 /*----------------------------------------------------------------------*/
482 static void lcd_setbgcolor (int color)
484 lcd_color_bg = color & 0x0F;
487 /*----------------------------------------------------------------------*/
489 #ifdef NOT_USED_SO_FAR
490 static int lcd_getfgcolor (void)
494 #endif /* NOT_USED_SO_FAR */
496 /*----------------------------------------------------------------------*/
498 static int lcd_getbgcolor (void)
503 /*----------------------------------------------------------------------*/
505 /************************************************************************/
506 /* ** Chipset depending Bitmap / Logo stuff... */
507 /************************************************************************/
508 #ifdef CONFIG_LCD_LOGO
509 void bitmap_plot (int x, int y)
516 #if defined(CONFIG_PXA250)
517 struct pxafb_info *fbi = &panel_info.pxa;
518 #elif defined(CONFIG_MPC823)
519 volatile immap_t *immr = (immap_t *) CFG_IMMR;
520 volatile cpm8xx_t *cp = &(immr->im_cpm);
523 debug ("Logo: width %d height %d colors %d cmap %d\n",
524 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
525 sizeof(bmp_logo_palette)/(sizeof(ushort)));
527 bmap = &bmp_logo_bitmap[0];
528 fb = (uchar *)(lcd_base + y * lcd_line_length + x);
530 if (NBITS(panel_info.vl_bpix) < 12) {
531 /* Leave room for default color map */
532 #if defined(CONFIG_PXA250)
533 cmap = (ushort *)fbi->palette;
534 #elif defined(CONFIG_MPC823)
535 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
541 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
542 ushort colreg = bmp_logo_palette[i];
543 #ifdef CFG_INVERT_COLORS
544 *cmap++ = 0xffff - colreg;
552 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
553 memcpy (fb, bmap, BMP_LOGO_WIDTH);
554 bmap += BMP_LOGO_WIDTH;
555 fb += panel_info.vl_col;
558 else { /* true color mode */
559 fb16 = (ushort *)(lcd_base + y * lcd_line_length + x);
560 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
561 for (j=0; j<BMP_LOGO_WIDTH; j++) {
562 fb16[j] = bmp_logo_palette[(bmap[j])];
564 bmap += BMP_LOGO_WIDTH;
565 fb16 += panel_info.vl_col;
571 #endif /* CONFIG_LCD_LOGO */
573 /*----------------------------------------------------------------------*/
574 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
576 * Display the BMP file located at address bmp_image.
579 int lcd_display_bitmap(ulong bmp_image, int x, int y)
581 #if !defined(CONFIG_MCC200)
586 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
589 unsigned long width, height;
590 unsigned long pwidth = panel_info.vl_col;
591 unsigned colors,bpix;
592 unsigned long compression;
593 #if defined(CONFIG_PXA250)
594 struct pxafb_info *fbi = &panel_info.pxa;
595 #elif defined(CONFIG_MPC823)
596 volatile immap_t *immr = (immap_t *) CFG_IMMR;
597 volatile cpm8xx_t *cp = &(immr->im_cpm);
600 if (!((bmp->header.signature[0]=='B') &&
601 (bmp->header.signature[1]=='M'))) {
602 printf ("Error: no valid bmp image at %lx\n", bmp_image);
606 width = le32_to_cpu (bmp->header.width);
607 height = le32_to_cpu (bmp->header.height);
608 colors = 1<<le16_to_cpu (bmp->header.bit_count);
609 compression = le32_to_cpu (bmp->header.compression);
611 bpix = NBITS(panel_info.vl_bpix);
613 if ((bpix != 1) && (bpix != 8)) {
614 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
619 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
620 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
622 le16_to_cpu(bmp->header.bit_count));
626 debug ("Display-bmp: %d x %d with %d colors\n",
627 (int)width, (int)height, (int)colors);
629 #if !defined(CONFIG_MCC200)
630 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
632 #if defined(CONFIG_PXA250)
633 cmap = (ushort *)fbi->palette;
634 #elif defined(CONFIG_MPC823)
635 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
637 # error "Don't know location of color map"
641 for (i=0; i<colors; ++i) {
642 bmp_color_table_entry_t cte = bmp->color_table[i];
644 ( ((cte.red) << 8) & 0xf800) |
645 ( ((cte.green) << 3) & 0x07e0) |
646 ( ((cte.blue) >> 3) & 0x001f) ;
647 #ifdef CFG_INVERT_COLORS
648 *cmap = 0xffff - colreg;
652 #if defined(CONFIG_PXA250)
654 #elif defined(CONFIG_MPC823)
662 * BMP format for Monochrome assumes that the state of a
663 * pixel is described on a per Bit basis, not per Byte.
664 * So, in case of Monochrome BMP we should align widths
665 * on a byte boundary and convert them from Bit to Byte
667 * Probably, PXA250 and MPC823 process 1bpp BMP images in
668 * their own ways, so make the converting to be MCC200
671 #if defined(CONFIG_MCC200)
674 width = ((width + 7) & ~7) >> 3;
675 x = ((x + 7) & ~7) >> 3;
676 pwidth= ((pwidth + 7) & ~7) >> 3;
680 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
681 if ((x + width)>pwidth)
683 if ((y + height)>panel_info.vl_row)
684 height = panel_info.vl_row - y;
686 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
687 fb = (uchar *) (lcd_base +
688 (y + height - 1) * lcd_line_length + x);
689 for (i = 0; i < height; ++i) {
691 for (j = 0; j < width ; j++)
692 #if defined(CONFIG_PXA250)
694 #elif defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
695 *(fb++)=255-*(bmap++);
697 bmap += (width - padded_line);
698 fb -= (width + lcd_line_length);
706 static void *lcd_logo (void)
708 #ifdef CONFIG_LCD_INFO
711 #endif /* CONFIG_LCD_INFO */
713 #ifdef CONFIG_SPLASH_SCREEN
716 static int do_splash = 1;
718 if (do_splash && (s = getenv("splashimage")) != NULL) {
719 addr = simple_strtoul(s, NULL, 16);
722 if (lcd_display_bitmap (addr, 0, 0) == 0) {
723 return ((void *)lcd_base);
726 #endif /* CONFIG_SPLASH_SCREEN */
728 #ifdef CONFIG_LCD_LOGO
730 #endif /* CONFIG_LCD_LOGO */
733 # ifdef CONFIG_LCD_INFO
734 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
735 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, (uchar *)info, strlen(info));
737 sprintf (info, "(C) 2004 DENX Software Engineering");
738 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
739 (uchar *)info, strlen(info));
741 sprintf (info, " Wolfgang DENK, wd@denx.de");
742 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
743 (uchar *)info, strlen(info));
744 # ifdef CONFIG_LCD_INFO_BELOW_LOGO
745 sprintf (info, "MPC823 CPU at %s MHz",
746 strmhz(temp, gd->cpu_clk));
747 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
749 sprintf (info, " %ld MB RAM, %ld MB Flash",
751 gd->bd->bi_flashsize >> 20 );
752 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
755 /* leave one blank line */
757 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
758 strmhz(temp, gd->cpu_clk),
760 gd->bd->bi_flashsize >> 20 );
761 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
762 (uchar *)info, strlen(info));
764 # endif /* CONFIG_LCD_INFO_BELOW_LOGO */
765 # endif /* CONFIG_LCD_INFO */
766 #endif /* CONFIG_MPC823 */
768 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
769 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
771 return ((void *)lcd_base);
772 #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
775 /************************************************************************/
776 /************************************************************************/
778 #endif /* CONFIG_LCD */