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 #ifndef CONFIG_EDT32F10
43 #define CONFIG_LCD_LOGO
44 #define LCD_INFO /* Display Logo, (C) and system info */
48 #undef CONFIG_LCD_LOGO
52 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
53 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
54 /************************************************************************/
56 /************************************************************************/
57 /* ** FONT AND LOGO DATA */
58 /************************************************************************/
60 #include <video_font.h> /* Get font data, width and height */
62 #ifdef CONFIG_LCD_LOGO
63 # include <bmp_logo.h> /* Get logo data, width and height */
66 /************************************************************************/
67 /************************************************************************/
70 * Information about displays we are using. This is for configuring
71 * the LCD controller and memory allocation. Someone has to know what
72 * is connected, as we can't autodetect anything.
74 #define CFG_HIGH 0 /* Pins are active high */
75 #define CFG_LOW 1 /* Pins are active low */
77 typedef struct vidinfo {
78 ushort vl_col; /* Number of columns (i.e. 640) */
79 ushort vl_row; /* Number of rows (i.e. 480) */
80 ushort vl_width; /* Width of display area in millimeters */
81 ushort vl_height; /* Height of display area in millimeters */
83 /* LCD configuration register.
85 u_char vl_clkp; /* Clock polarity */
86 u_char vl_oep; /* Output Enable polarity */
87 u_char vl_hsp; /* Horizontal Sync polarity */
88 u_char vl_vsp; /* Vertical Sync polarity */
89 u_char vl_dp; /* Data polarity */
90 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
91 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
92 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
93 u_char vl_clor; /* Color, 0 = mono, 1 = color */
94 u_char vl_tft; /* 0 = passive, 1 = TFT */
96 /* Horizontal control register. Timing from data sheet.
98 ushort vl_wbl; /* Wait between lines */
100 /* Vertical control register.
102 u_char vl_vpw; /* Vertical sync pulse width */
103 u_char vl_lcdac; /* LCD AC timing */
104 u_char vl_wbf; /* Wait between frames */
107 #define LCD_MONOCHROME 0
112 /*----------------------------------------------------------------------*/
113 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
115 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
117 #define LCD_BPP LCD_COLOR4
119 static vidinfo_t panel_info = {
120 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
121 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
122 /* wbl, vpw, lcdac, wbf */
124 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
125 /*----------------------------------------------------------------------*/
127 /*----------------------------------------------------------------------*/
128 #ifdef CONFIG_NEC_NL6648AC33
130 * NEC NL6648AC33-18. Active, color, single scan.
132 static vidinfo_t panel_info = {
133 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
134 3, 0, 0, 1, 1, 144, 2, 0, 33
135 /* wbl, vpw, lcdac, wbf */
137 #endif /* CONFIG_NEC_NL6648AC33 */
138 /*----------------------------------------------------------------------*/
140 #ifdef CONFIG_NEC_NL6648BC20
142 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
144 static vidinfo_t panel_info = {
145 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
146 3, 0, 0, 1, 1, 144, 2, 0, 33
147 /* wbl, vpw, lcdac, wbf */
149 #endif /* CONFIG_NEC_NL6648BC20 */
150 /*----------------------------------------------------------------------*/
152 #ifdef CONFIG_SHARP_LQ104V7DS01
154 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
156 static vidinfo_t panel_info = {
157 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
158 3, 0, 0, 1, 1, 25, 1, 0, 33
159 /* wbl, vpw, lcdac, wbf */
161 #endif /* CONFIG_SHARP_LQ104V7DS01 */
162 /*----------------------------------------------------------------------*/
164 #ifdef CONFIG_SHARP_16x9
166 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
167 * not sure what it is.......
169 static vidinfo_t panel_info = {
170 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
171 3, 0, 0, 1, 1, 15, 4, 0, 3
173 #endif /* CONFIG_SHARP_16x9 */
174 /*----------------------------------------------------------------------*/
176 #ifdef CONFIG_SHARP_LQ057Q3DC02
178 * Sharp LQ057Q3DC02 display. Active, color, single scan.
182 static vidinfo_t panel_info = {
183 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
184 3, 0, 0, 1, 1, 15, 4, 0, 3
185 /* wbl, vpw, lcdac, wbf */
187 #define LCD_INFO_BELOW_LOGO
188 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
189 /*----------------------------------------------------------------------*/
191 #ifdef CONFIG_SHARP_LQ64D341
193 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
195 static vidinfo_t panel_info = {
196 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
197 3, 0, 0, 1, 1, 128, 16, 0, 32
198 /* wbl, vpw, lcdac, wbf */
200 #endif /* CONFIG_SHARP_LQ64D341 */
202 #ifdef CONFIG_SHARP_LQ084V1DG21
204 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
206 static vidinfo_t panel_info = {
207 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
208 3, 0, 0, 1, 1, 160, 3, 0, 48
209 /* wbl, vpw, lcdac, wbf */
211 #endif /* CONFIG_SHARP_LQ084V1DG21 */
213 /*----------------------------------------------------------------------*/
215 #ifdef CONFIG_HLD1045
217 * HLD1045 display, 640x480. Active, color, single scan.
219 static vidinfo_t panel_info = {
220 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
221 3, 0, 0, 1, 1, 160, 3, 0, 48
222 /* wbl, vpw, lcdac, wbf */
224 #endif /* CONFIG_HLD1045 */
225 /*----------------------------------------------------------------------*/
227 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
229 * Prime View V16C6448AC
231 static vidinfo_t panel_info = {
232 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
233 3, 0, 0, 1, 1, 144, 2, 0, 35
234 /* wbl, vpw, lcdac, wbf */
236 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
238 /*----------------------------------------------------------------------*/
240 #ifdef CONFIG_OPTREX_BW
242 * Optrex CBL50840-2 NF-FW 99 22 M5
244 * Hitachi LMG6912RPFC-00T
248 * 320x240. Black & white.
250 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
251 /* 1 - 4 grey levels, 2 bpp */
252 /* 2 - 16 grey levels, 4 bpp */
253 static vidinfo_t panel_info = {
254 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
255 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
257 #endif /* CONFIG_OPTREX_BW */
259 /*-----------------------------------------------------------------*/
260 #ifdef CONFIG_EDT32F10
262 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
264 #define LCD_BPP LCD_MONOCHROME
267 static vidinfo_t panel_info = {
268 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
269 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
272 /*----------------------------------------------------------------------*/
274 #if defined(LCD_INFO_BELOW_LOGO)
275 # define LCD_INFO_X 0
276 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
277 #elif defined(CONFIG_LCD_LOGO)
278 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
279 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
281 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
282 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
286 #define LCD_BPP LCD_COLOR8
292 #define NBITS(bit_code) (1 << (bit_code))
293 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
295 static int lcd_line_length;
297 static int lcd_color_fg;
298 static int lcd_color_bg;
300 static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
303 * Frame buffer memory information
305 static void *lcd_base; /* Start of framebuffer memory */
306 static void *lcd_console_address; /* Start of console buffer */
309 /************************************************************************/
310 /* ** CONSOLE CONSTANTS */
311 /************************************************************************/
313 #if LCD_BPP == LCD_MONOCHROME
316 * Simple color definitions
318 #define CONSOLE_COLOR_BLACK 0
319 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
324 * Simple color definitions
326 #define CONSOLE_COLOR_BLACK 0
327 #define CONSOLE_COLOR_RED 1
328 #define CONSOLE_COLOR_GREEN 2
329 #define CONSOLE_COLOR_YELLOW 3
330 #define CONSOLE_COLOR_BLUE 4
331 #define CONSOLE_COLOR_MAGENTA 5
332 #define CONSOLE_COLOR_CYAN 6
333 #define CONSOLE_COLOR_GREY 14
334 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
338 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
339 #error Default Color Map overlaps with Logo Color Map
342 /************************************************************************/
345 #define PAGE_SIZE 4096
349 /************************************************************************/
350 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
351 /************************************************************************/
353 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
354 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
357 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
359 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
360 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
361 #define CONSOLE_ROW_FIRST (lcd_console_address)
362 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
363 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
365 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
366 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
368 #if LCD_BPP == LCD_MONOCHROME
369 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
370 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
371 #elif LCD_BPP == LCD_COLOR8
372 #define COLOR_MASK(c) (c)
374 #error Unsupported LCD BPP.
377 static short console_col;
378 static short console_row;
380 /************************************************************************/
382 ulong lcd_setmem (ulong addr);
384 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
385 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
386 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
388 static int lcd_init (void *lcdbase);
389 static void lcd_ctrl_init (void *lcdbase);
390 static void lcd_enable (void);
391 static void *lcd_logo (void);
392 #if LCD_BPP == LCD_COLOR8
393 static void lcd_setcolreg (ushort regno,
394 ushort red, ushort green, ushort blue);
396 #if LCD_BPP == LCD_MONOCHROME
397 static void lcd_initcolregs (void);
399 static int lcd_getbgcolor (void);
400 static void lcd_setfgcolor (int color);
401 static void lcd_setbgcolor (int color);
403 #ifdef NOT_USED_SO_FAR
404 static void lcd_disable (void);
405 static void lcd_getcolreg (ushort regno,
406 ushort *red, ushort *green, ushort *blue);
407 static int lcd_getfgcolor (void);
408 #endif /* NOT_USED_SO_FAR */
410 /************************************************************************/
412 /*----------------------------------------------------------------------*/
414 static void console_scrollup (void)
417 /* Copy up rows ignoring the first one */
418 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
420 /* Clear the last one */
421 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
424 * Poor attempt to optimize speed by moving "long"s.
425 * But the code is ugly, and not a bit faster :-(
427 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
428 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
429 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
430 uchar c = lcd_color_bg & 0xFF;
431 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
436 t = (ulong *)CONSOLE_ROW_LAST;
437 l = CONSOLE_ROW_SIZE / sizeof(ulong);
444 /*----------------------------------------------------------------------*/
446 static inline void console_back (void)
448 if (--console_col < 0) {
449 console_col = CONSOLE_COLS-1 ;
450 if (--console_row < 0) {
455 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
456 console_row * VIDEO_FONT_HEIGHT,
460 /*----------------------------------------------------------------------*/
462 static inline void console_newline (void)
467 /* Check if we need to scroll the terminal */
468 if (console_row >= CONSOLE_ROWS) {
469 /* Scroll everything up */
470 console_scrollup () ;
475 /*----------------------------------------------------------------------*/
477 void lcd_putc (const char c)
479 if (!lcd_is_enabled) {
485 case '\r': console_col = 0;
488 case '\n': console_newline();
491 case '\t': /* Tab (8 chars alignment) */
495 if (console_col >= CONSOLE_COLS) {
500 case '\b': console_back();
503 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
504 console_row * VIDEO_FONT_HEIGHT,
506 if (++console_col >= CONSOLE_COLS) {
514 /*----------------------------------------------------------------------*/
516 void lcd_puts (const char *s)
518 if (!lcd_is_enabled) {
528 /************************************************************************/
529 /* ** Low-Level Graphics Routines */
530 /************************************************************************/
532 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
537 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
538 off = x * (1 << LCD_BPP) % 8;
540 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
545 #if LCD_BPP == LCD_MONOCHROME
546 uchar rest = *d & -(1 << (8-off));
549 for (i=0; i<count; ++i) {
553 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
555 #if LCD_BPP == LCD_MONOCHROME
556 sym = (COLOR_MASK(lcd_color_fg) & bits) |
557 (COLOR_MASK(lcd_color_bg) & ~bits);
559 *d++ = rest | (sym >> off);
560 rest = sym << (8-off);
561 #elif LCD_BPP == LCD_COLOR8
562 for (c=0; c<8; ++c) {
563 *d++ = (bits & 0x80) ?
564 lcd_color_fg : lcd_color_bg;
570 #if LCD_BPP == LCD_MONOCHROME
571 *d = rest | (*d & ((1 << (8-off)) - 1));
576 /*----------------------------------------------------------------------*/
578 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
580 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
581 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
583 lcd_drawchars (x, y, s, strlen (s));
587 /*----------------------------------------------------------------------*/
589 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
591 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
592 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
594 lcd_drawchars (x, y, &c, 1);
598 /************************************************************************/
599 /** Small utility to check that you got the colours right */
600 /************************************************************************/
601 #ifdef LCD_TEST_PATTERN
606 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
607 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
608 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
611 static void test_pattern (void)
613 ushort v_max = panel_info.vl_row;
614 ushort h_max = panel_info.vl_col;
615 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
616 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
618 uchar *pix = (uchar *)lcd_base;
620 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
621 h_max, v_max, h_step, v_step);
623 /* WARNING: Code silently assumes 8bit/pixel */
624 for (v=0; v<v_max; ++v) {
625 uchar iy = v / v_step;
626 for (h=0; h<h_max; ++h) {
627 uchar ix = N_BLK_HOR * iy + (h/h_step);
628 *pix++ = test_colors[ix];
632 #endif /* LCD_TEST_PATTERN */
635 /************************************************************************/
636 /* ** GENERIC Initialization Routines */
637 /************************************************************************/
639 int drv_lcd_init (void)
641 DECLARE_GLOBAL_DATA_PTR;
646 lcd_base = (void *)(gd->fb_base);
648 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
650 lcd_init (lcd_base); /* LCD initialization */
652 /* Device initialization */
653 memset (&lcddev, 0, sizeof (lcddev));
655 strcpy (lcddev.name, "lcd");
656 lcddev.ext = 0; /* No extensions */
657 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
658 lcddev.putc = lcd_putc; /* 'putc' function */
659 lcddev.puts = lcd_puts; /* 'puts' function */
661 rc = device_register (&lcddev);
663 return (rc == 0) ? 1 : rc;
666 /*----------------------------------------------------------------------*/
668 static int lcd_init (void *lcdbase)
670 /* Initialize the lcd controller */
671 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
673 lcd_ctrl_init (lcdbase);
675 #if LCD_BPP == LCD_MONOCHROME
676 /* Setting the palette */
679 #elif LCD_BPP == LCD_COLOR8
680 /* Setting the palette */
681 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
682 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
683 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
684 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
685 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
686 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
687 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
688 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
689 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
692 #ifndef CFG_WHITE_ON_BLACK
693 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
694 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
696 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
697 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
698 #endif /* CFG_WHITE_ON_BLACK */
700 #ifdef LCD_TEST_PATTERN
703 /* set framebuffer to background color */
704 memset ((char *)lcd_base,
705 COLOR_MASK(lcd_getbgcolor()),
706 lcd_line_length*panel_info.vl_row);
711 /* Paint the logo and retrieve LCD base address */
712 debug ("[LCD] Drawing the logo...\n");
713 lcd_console_address = lcd_logo ();
715 /* Initialize the console */
717 #ifdef LCD_INFO_BELOW_LOGO
718 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
720 console_row = 1; /* leave 1 blank line below logo */
728 /************************************************************************/
729 /* ** ROM capable initialization part - needed to reserve FB memory */
730 /************************************************************************/
733 * This is called early in the system initialization to grab memory
734 * for the LCD controller.
735 * Returns new address for monitor, after reserving LCD buffer memory
737 * Note that this is running from ROM, so no write access to global data.
739 ulong lcd_setmem (ulong addr)
742 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
744 debug ("LCD panel info: %d x %d, %d bit/pix\n",
745 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
747 size = line_length * panel_info.vl_row;
749 /* Round up to nearest full page */
750 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
752 /* Allocate pages for the frame buffer. */
755 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
761 /************************************************************************/
762 /* ----------------- chipset specific functions ----------------------- */
763 /************************************************************************/
765 static void lcd_ctrl_init (void *lcdbase)
767 volatile immap_t *immr = (immap_t *) CFG_IMMR;
768 volatile lcd823_t *lcdp = &immr->im_lcd;
772 /* Initialize the LCD control register according to the LCD
773 * parameters defined. We do everything here but enable
777 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
778 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
780 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
781 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
782 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
783 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
784 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
785 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
786 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
787 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
788 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
789 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
792 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
793 lccrtmp |= LCCR_EIEN;
796 lcdp->lcd_lccr = lccrtmp;
797 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
799 /* Initialize LCD controller bus priorities.
801 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
803 /* set SHFT/CLOCK division factor 4
804 * This needs to be set based upon display type and processor
805 * speed. The TFT displays run about 20 to 30 MHz.
806 * I was running 64 MHz processor speed.
807 * The value for this divider must be chosen so the result is
808 * an integer of the processor speed (i.e., divide by 3 with
809 * 64 MHz would be bad).
811 immr->im_clkrst.car_sccr &= ~0x1F;
812 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
814 #ifndef CONFIG_EDT32F10
815 /* Enable LCD on port D.
817 immr->im_ioport.iop_pdpar |= 0x1FFF;
818 immr->im_ioport.iop_pddir |= 0x1FFF;
820 /* Enable LCD_A/B/C on port B.
822 immr->im_cpm.cp_pbpar |= 0x00005001;
823 immr->im_cpm.cp_pbdir |= 0x00005001;
825 /* Enable LCD on port D.
827 immr->im_ioport.iop_pdpar |= 0x1DFF;
828 immr->im_ioport.iop_pdpar &= ~0x0200;
829 immr->im_ioport.iop_pddir |= 0x1FFF;
830 immr->im_ioport.iop_pddat |= 0x0200;
833 /* Load the physical address of the linear frame buffer
834 * into the LCD controller.
835 * BIG NOTE: This has to be modified to load A and B depending
836 * upon the split mode of the LCD.
838 lcdp->lcd_lcfaa = (ulong)lcd_base;
839 lcdp->lcd_lcfba = (ulong)lcd_base;
841 /* MORE HACKS...This must be updated according to 823 manual
842 * for different panels.
844 #ifndef CONFIG_EDT32F10
845 lcdp->lcd_lchcr = LCHCR_BO |
846 LCDBIT (LCHCR_AT_BIT, 4) |
847 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
850 lcdp->lcd_lchcr = LCHCR_BO |
851 LCDBIT (LCHCR_AT_BIT, 4) |
852 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
856 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
857 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
858 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
863 /*----------------------------------------------------------------------*/
865 #ifdef NOT_USED_SO_FAR
867 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
869 volatile immap_t *immr = (immap_t *) CFG_IMMR;
870 volatile cpm8xx_t *cp = &(immr->im_cpm);
871 unsigned short colreg, *cmap_ptr;
873 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
876 #ifdef CFG_INVERT_COLORS
880 *red = (colreg >> 8) & 0x0F;
881 *green = (colreg >> 4) & 0x0F;
882 *blue = colreg & 0x0F;
884 #endif /* NOT_USED_SO_FAR */
886 /*----------------------------------------------------------------------*/
888 #if LCD_BPP == LCD_COLOR8
890 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
892 volatile immap_t *immr = (immap_t *) CFG_IMMR;
893 volatile cpm8xx_t *cp = &(immr->im_cpm);
894 unsigned short colreg, *cmap_ptr;
896 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
898 colreg = ((red & 0x0F) << 8) |
899 ((green & 0x0F) << 4) |
901 #ifdef CFG_INVERT_COLORS
906 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
907 regno, &(cp->lcd_cmap[regno * 2]),
909 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
911 #endif /* LCD_COLOR8 */
913 /*----------------------------------------------------------------------*/
915 #if LCD_BPP == LCD_MONOCHROME
917 void lcd_initcolregs (void)
919 volatile immap_t *immr = (immap_t *) CFG_IMMR;
920 volatile cpm8xx_t *cp = &(immr->im_cpm);
923 for (regno = 0; regno < 16; regno++) {
924 cp->lcd_cmap[regno * 2] = 0;
925 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
930 /*----------------------------------------------------------------------*/
932 static void lcd_setfgcolor (int color)
934 lcd_color_fg = color & 0x0F;
937 /*----------------------------------------------------------------------*/
939 static void lcd_setbgcolor (int color)
941 lcd_color_bg = color & 0x0F;
944 /*----------------------------------------------------------------------*/
946 #ifdef NOT_USED_SO_FAR
947 static int lcd_getfgcolor (void)
951 #endif /* NOT_USED_SO_FAR */
953 /*----------------------------------------------------------------------*/
955 static int lcd_getbgcolor (void)
960 /*----------------------------------------------------------------------*/
962 static void lcd_enable (void)
964 volatile immap_t *immr = (immap_t *) CFG_IMMR;
965 volatile lcd823_t *lcdp = &immr->im_lcd;
967 /* Enable the LCD panel */
968 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
969 lcdp->lcd_lccr |= LCCR_PON;
972 /* Turn on display backlight */
973 immr->im_cpm.cp_pbpar |= 0x00008000;
974 immr->im_cpm.cp_pbdir |= 0x00008000;
977 #if defined(CONFIG_LWMON)
978 { uchar c = pic_read (0x60);
979 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
982 #endif /* CONFIG_LWMON */
984 #if defined(CONFIG_R360MPI)
986 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
988 r360_i2c_lcd_write(0x10, 0x01);
989 r360_i2c_lcd_write(0x20, 0x01);
990 r360_i2c_lcd_write(0x3F, 0xFF);
991 r360_i2c_lcd_write(0x47, 0xFF);
993 #endif /* CONFIG_R360MPI */
996 /*----------------------------------------------------------------------*/
998 #ifdef NOT_USED_SO_FAR
999 static void lcd_disable (void)
1001 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1002 volatile lcd823_t *lcdp = &immr->im_lcd;
1004 #if defined(CONFIG_LWMON)
1005 { uchar c = pic_read (0x60);
1006 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1007 pic_write (0x60, c);
1009 #elif defined(CONFIG_R360MPI)
1011 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1013 r360_i2c_lcd_write(0x10, 0x00);
1014 r360_i2c_lcd_write(0x20, 0x00);
1015 r360_i2c_lcd_write(0x30, 0x00);
1016 r360_i2c_lcd_write(0x40, 0x00);
1018 #endif /* CONFIG_LWMON */
1019 /* Disable the LCD panel */
1020 lcdp->lcd_lccr &= ~LCCR_PON;
1021 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1023 #endif /* NOT_USED_SO_FAR */
1026 /************************************************************************/
1027 /* ** Chipset depending Bitmap / Logo stuff... */
1028 /************************************************************************/
1031 #ifdef CONFIG_LCD_LOGO
1032 static void bitmap_plot (int x, int y)
1034 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1035 volatile cpm8xx_t *cp = &(immr->im_cpm);
1041 debug ("Logo: width %d height %d colors %d cmap %d\n",
1042 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1043 sizeof(bmp_logo_palette)/(sizeof(ushort))
1046 /* Leave room for default color map */
1047 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1050 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1051 ushort colreg = bmp_logo_palette[i];
1052 #ifdef CFG_INVERT_COLORS
1058 bmap = &bmp_logo_bitmap[0];
1059 fb = (char *)(lcd_base + y * lcd_line_length + x);
1061 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1062 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1063 bmap += BMP_LOGO_WIDTH;
1064 fb += panel_info.vl_col;
1067 #endif /* CONFIG_LCD_LOGO */
1069 /*----------------------------------------------------------------------*/
1071 static void *lcd_logo (void)
1074 DECLARE_GLOBAL_DATA_PTR;
1078 #endif /* LCD_INFO */
1080 #ifdef CONFIG_LCD_LOGO
1082 #endif /* CONFIG_LCD_LOGO */
1086 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1087 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1089 sprintf (info, "(C) 2002 DENX Software Engineering");
1090 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1091 info, strlen(info));
1093 sprintf (info, " Wolfgang DENK, wd@denx.de");
1094 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1095 info, strlen(info));
1096 #ifdef LCD_INFO_BELOW_LOGO
1097 sprintf (info, "MPC823 CPU at %s MHz",
1098 strmhz(temp, gd->cpu_clk));
1099 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1100 info, strlen(info));
1101 sprintf (info, " %ld MB RAM, %ld MB Flash",
1103 gd->bd->bi_flashsize >> 20 );
1104 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1105 info, strlen(info));
1107 /* leave one blank line */
1109 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1110 strmhz(temp, gd->cpu_clk),
1112 gd->bd->bi_flashsize >> 20 );
1113 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1114 info, strlen(info));
1115 #endif /* LCD_INFO_BELOW_LOGO */
1116 #endif /* LCD_INFO */
1118 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1119 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1121 return ((void *)lcd_base);
1122 #endif /* CONFIG_LCD_LOGO */
1125 /************************************************************************/
1126 /************************************************************************/
1128 #endif /* CONFIG_LCD */