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 */
62 ulong lcd_setmem (ulong addr);
64 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
65 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
66 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
68 static int lcd_init (void *lcdbase);
70 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
71 extern void lcd_ctrl_init (void *lcdbase);
72 extern void lcd_enable (void);
73 static void *lcd_logo (void);
76 #if LCD_BPP == LCD_COLOR8
77 extern void lcd_setcolreg (ushort regno,
78 ushort red, ushort green, ushort blue);
80 #if LCD_BPP == LCD_MONOCHROME
81 extern void lcd_initcolregs (void);
84 static int lcd_getbgcolor (void);
85 static void lcd_setfgcolor (int color);
86 static void lcd_setbgcolor (int color);
88 char lcd_is_enabled = 0;
89 extern vidinfo_t panel_info;
91 #ifdef NOT_USED_SO_FAR
92 static void lcd_getcolreg (ushort regno,
93 ushort *red, ushort *green, ushort *blue);
94 static int lcd_getfgcolor (void);
95 #endif /* NOT_USED_SO_FAR */
97 /************************************************************************/
99 /*----------------------------------------------------------------------*/
101 static void console_scrollup (void)
104 /* Copy up rows ignoring the first one */
105 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
107 /* Clear the last one */
108 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
111 * Poor attempt to optimize speed by moving "long"s.
112 * But the code is ugly, and not a bit faster :-(
114 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
115 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
116 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
117 uchar c = lcd_color_bg & 0xFF;
118 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
123 t = (ulong *)CONSOLE_ROW_LAST;
124 l = CONSOLE_ROW_SIZE / sizeof(ulong);
131 /*----------------------------------------------------------------------*/
133 static inline void console_back (void)
135 if (--console_col < 0) {
136 console_col = CONSOLE_COLS-1 ;
137 if (--console_row < 0) {
142 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
143 console_row * VIDEO_FONT_HEIGHT,
147 /*----------------------------------------------------------------------*/
149 static inline void console_newline (void)
154 /* Check if we need to scroll the terminal */
155 if (console_row >= CONSOLE_ROWS) {
156 /* Scroll everything up */
157 console_scrollup () ;
162 /*----------------------------------------------------------------------*/
164 void lcd_putc (const char c)
166 if (!lcd_is_enabled) {
172 case '\r': console_col = 0;
175 case '\n': console_newline();
178 case '\t': /* Tab (8 chars alignment) */
182 if (console_col >= CONSOLE_COLS) {
187 case '\b': console_back();
190 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
191 console_row * VIDEO_FONT_HEIGHT,
193 if (++console_col >= CONSOLE_COLS) {
201 /*----------------------------------------------------------------------*/
203 void lcd_puts (const char *s)
205 if (!lcd_is_enabled) {
215 /************************************************************************/
216 /* ** Low-Level Graphics Routines */
217 /************************************************************************/
219 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
224 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
225 off = x * (1 << LCD_BPP) % 8;
227 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
232 #if LCD_BPP == LCD_MONOCHROME
233 uchar rest = *d & -(1 << (8-off));
236 for (i=0; i<count; ++i) {
240 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
242 #if LCD_BPP == LCD_MONOCHROME
243 sym = (COLOR_MASK(lcd_color_fg) & bits) |
244 (COLOR_MASK(lcd_color_bg) & ~bits);
246 *d++ = rest | (sym >> off);
247 rest = sym << (8-off);
248 #elif LCD_BPP == LCD_COLOR8
249 for (c=0; c<8; ++c) {
250 *d++ = (bits & 0x80) ?
251 lcd_color_fg : lcd_color_bg;
254 #elif LCD_BPP == LCD_COLOR16
255 for (c=0; c<16; ++c) {
256 *d++ = (bits & 0x80) ?
257 lcd_color_fg : lcd_color_bg;
262 #if LCD_BPP == LCD_MONOCHROME
263 *d = rest | (*d & ((1 << (8-off)) - 1));
268 /*----------------------------------------------------------------------*/
270 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
272 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
273 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
275 lcd_drawchars (x, y, s, strlen (s));
279 /*----------------------------------------------------------------------*/
281 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
283 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
284 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
286 lcd_drawchars (x, y, &c, 1);
290 /************************************************************************/
291 /** Small utility to check that you got the colours right */
292 /************************************************************************/
293 #ifdef LCD_TEST_PATTERN
298 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
299 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
300 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
303 static void test_pattern (void)
305 ushort v_max = panel_info.vl_row;
306 ushort h_max = panel_info.vl_col;
307 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
308 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
310 uchar *pix = (uchar *)lcd_base;
312 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
313 h_max, v_max, h_step, v_step);
315 /* WARNING: Code silently assumes 8bit/pixel */
316 for (v=0; v<v_max; ++v) {
317 uchar iy = v / v_step;
318 for (h=0; h<h_max; ++h) {
319 uchar ix = N_BLK_HOR * iy + (h/h_step);
320 *pix++ = test_colors[ix];
324 #endif /* LCD_TEST_PATTERN */
327 /************************************************************************/
328 /* ** GENERIC Initialization Routines */
329 /************************************************************************/
331 int drv_lcd_init (void)
333 DECLARE_GLOBAL_DATA_PTR;
338 lcd_base = (void *)(gd->fb_base);
340 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
342 lcd_init (lcd_base); /* LCD initialization */
344 /* Device initialization */
345 memset (&lcddev, 0, sizeof (lcddev));
347 strcpy (lcddev.name, "lcd");
348 lcddev.ext = 0; /* No extensions */
349 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
350 lcddev.putc = lcd_putc; /* 'putc' function */
351 lcddev.puts = lcd_puts; /* 'puts' function */
353 rc = device_register (&lcddev);
355 return (rc == 0) ? 1 : rc;
358 /*----------------------------------------------------------------------*/
359 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
361 #if LCD_BPP == LCD_MONOCHROME
362 /* Setting the palette */
365 #elif LCD_BPP == LCD_COLOR8
366 /* Setting the palette */
367 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
368 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
369 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
370 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
371 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
372 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
373 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
374 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
375 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
378 #ifndef CFG_WHITE_ON_BLACK
379 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
380 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
382 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
383 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
384 #endif /* CFG_WHITE_ON_BLACK */
386 #ifdef LCD_TEST_PATTERN
389 /* set framebuffer to background color */
390 memset ((char *)lcd_base,
391 COLOR_MASK(lcd_getbgcolor()),
392 lcd_line_length*panel_info.vl_row);
394 /* Paint the logo and retrieve LCD base address */
395 debug ("[LCD] Drawing the logo...\n");
396 lcd_console_address = lcd_logo ();
405 cls, 1, 1, lcd_clear,
406 "cls - clear screen\n",
410 /*----------------------------------------------------------------------*/
412 static int lcd_init (void *lcdbase)
414 /* Initialize the lcd controller */
415 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
417 lcd_ctrl_init (lcdbase);
418 lcd_clear (NULL, 1, 1, NULL); /* dummy args */
421 /* Initialize the console */
423 #ifdef LCD_INFO_BELOW_LOGO
424 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
426 console_row = 1; /* leave 1 blank line below logo */
434 /************************************************************************/
435 /* ** ROM capable initialization part - needed to reserve FB memory */
436 /************************************************************************/
438 * This is called early in the system initialization to grab memory
439 * for the LCD controller.
440 * Returns new address for monitor, after reserving LCD buffer memory
442 * Note that this is running from ROM, so no write access to global data.
444 ulong lcd_setmem (ulong addr)
447 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
449 debug ("LCD panel info: %d x %d, %d bit/pix\n",
450 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
452 size = line_length * panel_info.vl_row;
454 /* Round up to nearest full page */
455 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
457 /* Allocate pages for the frame buffer. */
460 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
465 /*----------------------------------------------------------------------*/
467 static void lcd_setfgcolor (int color)
469 lcd_color_fg = color & 0x0F;
472 /*----------------------------------------------------------------------*/
474 static void lcd_setbgcolor (int color)
476 lcd_color_bg = color & 0x0F;
479 /*----------------------------------------------------------------------*/
481 #ifdef NOT_USED_SO_FAR
482 static int lcd_getfgcolor (void)
486 #endif /* NOT_USED_SO_FAR */
488 /*----------------------------------------------------------------------*/
490 static int lcd_getbgcolor (void)
495 /*----------------------------------------------------------------------*/
497 /************************************************************************/
498 /* ** Chipset depending Bitmap / Logo stuff... */
499 /************************************************************************/
500 #ifdef CONFIG_LCD_LOGO
501 void bitmap_plot (int x, int y)
508 #if defined(CONFIG_PXA250)
509 struct pxafb_info *fbi = &panel_info.pxa;
510 #elif defined(CONFIG_MPC823)
511 volatile immap_t *immr = (immap_t *) CFG_IMMR;
512 volatile cpm8xx_t *cp = &(immr->im_cpm);
515 debug ("Logo: width %d height %d colors %d cmap %d\n",
516 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
517 sizeof(bmp_logo_palette)/(sizeof(ushort)));
519 bmap = &bmp_logo_bitmap[0];
520 fb = (char *)(lcd_base + y * lcd_line_length + x);
522 if (NBITS(panel_info.vl_bpix) < 12) {
523 /* Leave room for default color map */
524 #if defined(CONFIG_PXA250)
525 cmap = (ushort *)fbi->palette;
526 #elif defined(CONFIG_MPC823)
527 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
533 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
534 ushort colreg = bmp_logo_palette[i];
535 #ifdef CFG_INVERT_COLORS
536 *cmap++ = 0xffff - colreg;
544 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
545 memcpy (fb, bmap, BMP_LOGO_WIDTH);
546 bmap += BMP_LOGO_WIDTH;
547 fb += panel_info.vl_col;
550 else { /* true color mode */
551 fb16 = (ushort *)(lcd_base + y * lcd_line_length + x);
552 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
553 for (j=0; j<BMP_LOGO_WIDTH; j++) {
554 fb16[j] = bmp_logo_palette[(bmap[j])];
556 bmap += BMP_LOGO_WIDTH;
557 fb16 += panel_info.vl_col;
563 #endif /* CONFIG_LCD_LOGO */
565 /*----------------------------------------------------------------------*/
566 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
568 * Display the BMP file located at address bmp_image.
571 int lcd_display_bitmap(ulong bmp_image, int x, int y)
576 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
579 unsigned long width, height;
580 unsigned colors,bpix;
581 unsigned long compression;
582 #if defined(CONFIG_PXA250)
583 struct pxafb_info *fbi = &panel_info.pxa;
584 #elif defined(CONFIG_MPC823)
585 volatile immap_t *immr = (immap_t *) CFG_IMMR;
586 volatile cpm8xx_t *cp = &(immr->im_cpm);
589 if (!((bmp->header.signature[0]=='B') &&
590 (bmp->header.signature[1]=='M'))) {
591 printf ("Error: no valid bmp image at %lx\n", bmp_image);
595 width = le32_to_cpu (bmp->header.width);
596 height = le32_to_cpu (bmp->header.height);
597 colors = 1<<le16_to_cpu (bmp->header.bit_count);
598 compression = le32_to_cpu (bmp->header.compression);
600 bpix = NBITS(panel_info.vl_bpix);
602 if ((bpix != 1) && (bpix != 8)) {
603 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
608 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
609 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
611 le16_to_cpu(bmp->header.bit_count));
615 debug ("Display-bmp: %d x %d with %d colors\n",
616 (int)width, (int)height, (int)colors);
619 #if defined(CONFIG_PXA250)
620 cmap = (ushort *)fbi->palette;
621 #elif defined(CONFIG_MPC823)
622 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
624 # error "Don't know location of color map"
628 for (i=0; i<colors; ++i) {
629 bmp_color_table_entry_t cte = bmp->color_table[i];
631 ( ((cte.red) << 8) & 0xf800) |
632 ( ((cte.green) << 4) & 0x07e0) |
633 ( (cte.blue) & 0x001f) ;
635 #ifdef CFG_INVERT_COLORS
636 *cmap = 0xffff - colreg;
640 #if defined(CONFIG_PXA250)
642 #elif defined(CONFIG_MPC823)
648 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
649 if ((x + width)>panel_info.vl_col)
650 width = panel_info.vl_col - x;
651 if ((y + height)>panel_info.vl_row)
652 height = panel_info.vl_row - y;
654 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
655 fb = (uchar *) (lcd_base +
656 (y + height - 1) * lcd_line_length + x);
657 for (i = 0; i < height; ++i) {
659 for (j = 0; j < width ; j++)
660 #if defined(CONFIG_PXA250)
662 #elif defined(CONFIG_MPC823)
663 *(fb++)=255-*(bmap++);
665 bmap += (width - padded_line);
666 fb -= (width + lcd_line_length);
671 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
674 static void *lcd_logo (void)
677 DECLARE_GLOBAL_DATA_PTR;
681 #endif /* LCD_INFO */
683 #ifdef CONFIG_SPLASH_SCREEN
686 static int do_splash = 1;
688 if (do_splash && (s = getenv("splashimage")) != NULL) {
689 addr = simple_strtoul(s, NULL, 16);
692 if (lcd_display_bitmap (addr, 0, 0) == 0) {
693 return ((void *)lcd_base);
696 #endif /* CONFIG_SPLASH_SCREEN */
698 #ifdef CONFIG_LCD_LOGO
700 #endif /* CONFIG_LCD_LOGO */
704 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
705 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
707 sprintf (info, "(C) 2004 DENX Software Engineering");
708 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
711 sprintf (info, " Wolfgang DENK, wd@denx.de");
712 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
714 #ifdef LCD_INFO_BELOW_LOGO
715 sprintf (info, "MPC823 CPU at %s MHz",
716 strmhz(temp, gd->cpu_clk));
717 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
719 sprintf (info, " %ld MB RAM, %ld MB Flash",
721 gd->bd->bi_flashsize >> 20 );
722 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
725 /* leave one blank line */
727 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
728 strmhz(temp, gd->cpu_clk),
730 gd->bd->bi_flashsize >> 20 );
731 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
734 #endif /* CONFIG_MPC823 */
735 #endif /* LCD_INFO_BELOW_LOGO */
736 #endif /* LCD_INFO */
738 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
739 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
741 return ((void *)lcd_base);
742 #endif /* CONFIG_LCD_LOGO */
745 /************************************************************************/
746 /************************************************************************/
748 #endif /* CONFIG_LCD */