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 */
46 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
47 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
48 /************************************************************************/
50 /************************************************************************/
51 /* ** FONT AND LOGO DATA */
52 /************************************************************************/
54 #include <video_font.h> /* Get font data, width and height */
56 #ifdef CONFIG_LCD_LOGO
57 # include <bmp_logo.h> /* Get logo data, width and height */
60 /************************************************************************/
61 /************************************************************************/
64 * Information about displays we are using. This is for configuring
65 * the LCD controller and memory allocation. Someone has to know what
66 * is connected, as we can't autodetect anything.
68 #define CFG_HIGH 0 /* Pins are active high */
69 #define CFG_LOW 1 /* Pins are active low */
71 typedef struct vidinfo {
72 ushort vl_col; /* Number of columns (i.e. 640) */
73 ushort vl_row; /* Number of rows (i.e. 480) */
74 ushort vl_width; /* Width of display area in millimeters */
75 ushort vl_height; /* Height of display area in millimeters */
77 /* LCD configuration register.
79 u_char vl_clkp; /* Clock polarity */
80 u_char vl_oep; /* Output Enable polarity */
81 u_char vl_hsp; /* Horizontal Sync polarity */
82 u_char vl_vsp; /* Vertical Sync polarity */
83 u_char vl_dp; /* Data polarity */
84 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
85 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
86 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
87 u_char vl_clor; /* Color, 0 = mono, 1 = color */
88 u_char vl_tft; /* 0 = passive, 1 = TFT */
90 /* Horizontal control register. Timing from data sheet.
92 ushort vl_wbl; /* Wait between lines */
94 /* Vertical control register.
96 u_char vl_vpw; /* Vertical sync pulse width */
97 u_char vl_lcdac; /* LCD AC timing */
98 u_char vl_wbf; /* Wait between frames */
101 #define LCD_MONOCHROME 0
106 /*----------------------------------------------------------------------*/
107 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
109 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
111 #define LCD_BPP LCD_COLOR4
113 static vidinfo_t panel_info = {
114 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
115 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
116 /* wbl, vpw, lcdac, wbf */
118 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
119 /*----------------------------------------------------------------------*/
121 /*----------------------------------------------------------------------*/
122 #ifdef CONFIG_NEC_NL6648AC33
124 * NEC NL6648AC33-18. Active, color, single scan.
126 static vidinfo_t panel_info = {
127 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
128 3, 0, 0, 1, 1, 144, 2, 0, 33
129 /* wbl, vpw, lcdac, wbf */
131 #endif /* CONFIG_NEC_NL6648AC33 */
132 /*----------------------------------------------------------------------*/
134 #ifdef CONFIG_NEC_NL6648BC20
136 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
138 static vidinfo_t panel_info = {
139 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
140 3, 0, 0, 1, 1, 144, 2, 0, 33
141 /* wbl, vpw, lcdac, wbf */
143 #endif /* CONFIG_NEC_NL6648BC20 */
144 /*----------------------------------------------------------------------*/
146 #ifdef CONFIG_SHARP_LQ104V7DS01
148 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
150 static vidinfo_t panel_info = {
151 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
152 3, 0, 0, 1, 1, 25, 1, 0, 33
153 /* wbl, vpw, lcdac, wbf */
155 #endif /* CONFIG_SHARP_LQ104V7DS01 */
156 /*----------------------------------------------------------------------*/
158 #ifdef CONFIG_SHARP_16x9
160 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
161 * not sure what it is.......
163 static vidinfo_t panel_info = {
164 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
165 3, 0, 0, 1, 1, 15, 4, 0, 3
167 #endif /* CONFIG_SHARP_16x9 */
168 /*----------------------------------------------------------------------*/
170 #ifdef CONFIG_SHARP_LQ057Q3DC02
172 * Sharp LQ057Q3DC02 display. Active, color, single scan.
174 static vidinfo_t panel_info = {
175 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
176 3, 0, 0, 1, 1, 15, 4, 0, 3
177 /* wbl, vpw, lcdac, wbf */
179 #define LCD_INFO_BELOW_LOGO
180 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
181 /*----------------------------------------------------------------------*/
183 #ifdef CONFIG_SHARP_LQ64D341
185 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
187 static vidinfo_t panel_info = {
188 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
189 3, 0, 0, 1, 1, 128, 16, 0, 32
190 /* wbl, vpw, lcdac, wbf */
192 #endif /* CONFIG_SHARP_LQ64D341 */
193 /*----------------------------------------------------------------------*/
195 #ifdef CONFIG_HLD1045
197 * HLD1045 display, 640x480. Active, color, single scan.
199 static vidinfo_t panel_info = {
200 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
201 3, 0, 0, 1, 1, 160, 3, 0, 48
202 /* wbl, vpw, lcdac, wbf */
204 #endif /* CONFIG_HLD1045 */
205 /*----------------------------------------------------------------------*/
207 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
209 * Prime View V16C6448AC
211 static vidinfo_t panel_info = {
212 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
213 3, 0, 0, 1, 1, 144, 2, 0, 35
214 /* wbl, vpw, lcdac, wbf */
216 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
218 /*----------------------------------------------------------------------*/
220 #ifdef CONFIG_OPTREX_BW
222 * Optrex CBL50840-2 NF-FW 99 22 M5
224 * Hitachi LMG6912RPFC-00T
228 * 320x240. Black & white.
230 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
231 /* 1 - 4 grey levels, 2 bpp */
232 /* 2 - 16 grey levels, 4 bpp */
233 static vidinfo_t panel_info = {
234 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
235 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
237 #endif /* CONFIG_OPTREX_BW */
239 /*-----------------------------------------------------------------*/
240 #ifdef CONFIG_EDT32F10
242 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
244 #define LCD_BPP LCD_MONOCHROME
247 static vidinfo_t panel_info = {
248 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
249 LCD_BPP, 0, 0, 0, 0, 0, 15, 0, 0
252 /*----------------------------------------------------------------------*/
254 #if defined(LCD_INFO_BELOW_LOGO)
255 # define LCD_INFO_X 0
256 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
257 #elif defined(CONFIG_LCD_LOGO)
258 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
259 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
261 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
262 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
266 #define LCD_BPP LCD_COLOR8
272 #define NBITS(bit_code) (1 << (bit_code))
273 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
275 static int lcd_line_length;
277 static int lcd_color_fg;
278 static int lcd_color_bg;
280 static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
283 * Frame buffer memory information
285 static void *lcd_base; /* Start of framebuffer memory */
286 static void *lcd_console_address; /* Start of console buffer */
289 /************************************************************************/
290 /* ** CONSOLE CONSTANTS */
291 /************************************************************************/
293 #if LCD_BPP == LCD_MONOCHROME
296 * Simple color definitions
298 #define CONSOLE_COLOR_BLACK 0
299 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
304 * Simple color definitions
306 #define CONSOLE_COLOR_BLACK 0
307 #define CONSOLE_COLOR_RED 1
308 #define CONSOLE_COLOR_GREEN 2
309 #define CONSOLE_COLOR_YELLOW 3
310 #define CONSOLE_COLOR_BLUE 4
311 #define CONSOLE_COLOR_MAGENTA 5
312 #define CONSOLE_COLOR_CYAN 6
313 #define CONSOLE_COLOR_GREY 14
314 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
318 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
319 #error Default Color Map overlaps with Logo Color Map
322 /************************************************************************/
325 #define PAGE_SIZE 4096
329 /************************************************************************/
330 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
331 /************************************************************************/
333 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
334 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
337 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
339 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
340 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
341 #define CONSOLE_ROW_FIRST (lcd_console_address)
342 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
343 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
345 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
346 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
348 #if LCD_BPP == LCD_MONOCHROME
349 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
350 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
351 #elif LCD_BPP == LCD_COLOR8
352 #define COLOR_MASK(c) (c)
354 #error Unsupported LCD BPP.
357 static short console_col;
358 static short console_row;
360 /************************************************************************/
362 ulong lcd_setmem (ulong addr);
364 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
365 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
366 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
368 static int lcd_init (void *lcdbase);
369 static void lcd_ctrl_init (void *lcdbase);
370 static void lcd_enable (void);
371 static void *lcd_logo (void);
372 #if LCD_BPP == LCD_COLOR8
373 static void lcd_setcolreg (ushort regno,
374 ushort red, ushort green, ushort blue);
376 #if LCD_BPP == LCD_MONOCHROME
377 static void lcd_initcolregs (void);
379 static int lcd_getbgcolor (void);
380 static void lcd_setfgcolor (int color);
381 static void lcd_setbgcolor (int color);
383 #ifdef NOT_USED_SO_FAR
384 static void lcd_disable (void);
385 static void lcd_getcolreg (ushort regno,
386 ushort *red, ushort *green, ushort *blue);
387 static int lcd_getfgcolor (void);
388 #endif /* NOT_USED_SO_FAR */
390 /************************************************************************/
392 /*----------------------------------------------------------------------*/
394 static void console_scrollup (void)
397 /* Copy up rows ignoring the first one */
398 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
400 /* Clear the last one */
401 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
404 * Poor attempt to optimize speed by moving "long"s.
405 * But the code is ugly, and not a bit faster :-(
407 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
408 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
409 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
410 uchar c = lcd_color_bg & 0xFF;
411 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
416 t = (ulong *)CONSOLE_ROW_LAST;
417 l = CONSOLE_ROW_SIZE / sizeof(ulong);
424 /*----------------------------------------------------------------------*/
426 static inline void console_back (void)
428 if (--console_col < 0) {
429 console_col = CONSOLE_COLS-1 ;
430 if (--console_row < 0) {
435 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
436 console_row * VIDEO_FONT_HEIGHT,
440 /*----------------------------------------------------------------------*/
442 static inline void console_newline (void)
447 /* Check if we need to scroll the terminal */
448 if (console_row >= CONSOLE_ROWS) {
449 /* Scroll everything up */
450 console_scrollup () ;
455 /*----------------------------------------------------------------------*/
457 void lcd_putc (const char c)
459 if (!lcd_is_enabled) {
465 case '\r': console_col = 0;
468 case '\n': console_newline();
471 case '\t': /* Tab (8 chars alignment) */
475 if (console_col >= CONSOLE_COLS) {
480 case '\b': console_back();
483 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
484 console_row * VIDEO_FONT_HEIGHT,
486 if (++console_col >= CONSOLE_COLS) {
494 /*----------------------------------------------------------------------*/
496 void lcd_puts (const char *s)
498 if (!lcd_is_enabled) {
508 /************************************************************************/
509 /* ** Low-Level Graphics Routines */
510 /************************************************************************/
512 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
517 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
518 off = x * (1 << LCD_BPP) % 8;
520 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
525 #if LCD_BPP == LCD_MONOCHROME
526 uchar rest = *d & -(1 << (8-off));
529 for (i=0; i<count; ++i) {
533 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
535 #if LCD_BPP == LCD_MONOCHROME
536 sym = (COLOR_MASK(lcd_color_fg) & bits) |
537 (COLOR_MASK(lcd_color_bg) & ~bits);
539 *d++ = rest | (sym >> off);
540 rest = sym << (8-off);
541 #elif LCD_BPP == LCD_COLOR8
542 for (c=0; c<8; ++c) {
543 *d++ = (bits & 0x80) ?
544 lcd_color_fg : lcd_color_bg;
550 #if LCD_BPP == LCD_MONOCHROME
551 *d = rest | (*d & ((1 << (8-off)) - 1));
556 /*----------------------------------------------------------------------*/
558 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
560 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
561 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
563 lcd_drawchars (x, y, s, strlen (s));
567 /*----------------------------------------------------------------------*/
569 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
571 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
572 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
574 lcd_drawchars (x, y, &c, 1);
578 /************************************************************************/
579 /** Small utility to check that you got the colours right */
580 /************************************************************************/
581 #ifdef LCD_TEST_PATTERN
586 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
587 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
588 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
591 static void test_pattern (void)
593 ushort v_max = panel_info.vl_row;
594 ushort h_max = panel_info.vl_col;
595 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
596 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
598 uchar *pix = (uchar *)lcd_base;
600 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
601 h_max, v_max, h_step, v_step);
603 /* WARNING: Code silently assumes 8bit/pixel */
604 for (v=0; v<v_max; ++v) {
605 uchar iy = v / v_step;
606 for (h=0; h<h_max; ++h) {
607 uchar ix = N_BLK_HOR * iy + (h/h_step);
608 *pix++ = test_colors[ix];
612 #endif /* LCD_TEST_PATTERN */
615 /************************************************************************/
616 /* ** GENERIC Initialization Routines */
617 /************************************************************************/
619 int drv_lcd_init (void)
621 DECLARE_GLOBAL_DATA_PTR;
626 lcd_base = (void *)(gd->fb_base);
628 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
630 lcd_init (lcd_base); /* LCD initialization */
632 /* Device initialization */
633 memset (&lcddev, 0, sizeof (lcddev));
635 strcpy (lcddev.name, "lcd");
636 lcddev.ext = 0; /* No extensions */
637 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
638 lcddev.putc = lcd_putc; /* 'putc' function */
639 lcddev.puts = lcd_puts; /* 'puts' function */
641 rc = device_register (&lcddev);
643 return (rc == 0) ? 1 : rc;
646 /*----------------------------------------------------------------------*/
648 static int lcd_init (void *lcdbase)
650 /* Initialize the lcd controller */
651 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
653 lcd_ctrl_init (lcdbase);
655 #if LCD_BPP == LCD_MONOCHROME
656 /* Setting the palette */
659 #elif LCD_BPP == LCD_COLOR8
660 /* Setting the palette */
661 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
662 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
663 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
664 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
665 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
666 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
667 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
668 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
669 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
672 #ifndef CFG_WHITE_ON_BLACK
673 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
674 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
676 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
677 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
678 #endif /* CFG_WHITE_ON_BLACK */
680 #ifdef LCD_TEST_PATTERN
683 /* set framebuffer to background color */
684 memset ((char *)lcd_base,
685 COLOR_MASK(lcd_getbgcolor()),
686 lcd_line_length*panel_info.vl_row);
691 /* Paint the logo and retrieve LCD base address */
692 debug ("[LCD] Drawing the logo...\n");
693 lcd_console_address = lcd_logo ();
695 /* Initialize the console */
697 #ifdef LCD_INFO_BELOW_LOGO
698 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
700 console_row = 1; /* leave 1 blank line below logo */
708 /************************************************************************/
709 /* ** ROM capable initialization part - needed to reserve FB memory */
710 /************************************************************************/
713 * This is called early in the system initialization to grab memory
714 * for the LCD controller.
715 * Returns new address for monitor, after reserving LCD buffer memory
717 * Note that this is running from ROM, so no write access to global data.
719 ulong lcd_setmem (ulong addr)
722 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
724 debug ("LCD panel info: %d x %d, %d bit/pix\n",
725 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
727 size = line_length * panel_info.vl_row;
729 /* Round up to nearest full page */
730 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
732 /* Allocate pages for the frame buffer. */
735 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
741 /************************************************************************/
742 /* ----------------- chipset specific functions ----------------------- */
743 /************************************************************************/
745 static void lcd_ctrl_init (void *lcdbase)
747 volatile immap_t *immr = (immap_t *) CFG_IMMR;
748 volatile lcd823_t *lcdp = &immr->im_lcd;
752 /* Initialize the LCD control register according to the LCD
753 * parameters defined. We do everything here but enable
757 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
758 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
760 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
761 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
762 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
763 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
764 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
765 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
766 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
767 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
768 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
769 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
772 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
773 lccrtmp |= LCCR_EIEN;
776 lcdp->lcd_lccr = lccrtmp;
777 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
779 /* Initialize LCD controller bus priorities.
781 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
783 /* set SHFT/CLOCK division factor 4
784 * This needs to be set based upon display type and processor
785 * speed. The TFT displays run about 20 to 30 MHz.
786 * I was running 64 MHz processor speed.
787 * The value for this divider must be chosen so the result is
788 * an integer of the processor speed (i.e., divide by 3 with
789 * 64 MHz would be bad).
791 immr->im_clkrst.car_sccr &= ~0x1F;
792 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
794 #ifndef CONFIG_EDT32F10
795 /* Enable LCD on port D.
797 immr->im_ioport.iop_pdpar |= 0x1FFF;
798 immr->im_ioport.iop_pddir |= 0x1FFF;
800 /* Enable LCD_A/B/C on port B.
802 immr->im_cpm.cp_pbpar |= 0x00005001;
803 immr->im_cpm.cp_pbdir |= 0x00005001;
805 /* Enable LCD on port D.
807 immr->im_ioport.iop_pdpar |= 0x1DFF;
808 immr->im_ioport.iop_pdpar &= ~0x0200;
809 immr->im_ioport.iop_pddir |= 0x1FFF;
810 immr->im_ioport.iop_pddat |= 0x0200;
813 /* Load the physical address of the linear frame buffer
814 * into the LCD controller.
815 * BIG NOTE: This has to be modified to load A and B depending
816 * upon the split mode of the LCD.
818 lcdp->lcd_lcfaa = (ulong)lcd_base;
819 lcdp->lcd_lcfba = (ulong)lcd_base;
821 /* MORE HACKS...This must be updated according to 823 manual
822 * for different panels.
824 #ifndef CONFIG_EDT32F10
825 lcdp->lcd_lchcr = LCHCR_BO |
826 LCDBIT (LCHCR_AT_BIT, 4) |
827 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
830 lcdp->lcd_lchcr = LCHCR_BO |
831 LCDBIT (LCHCR_AT_BIT, 4) |
832 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
836 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
837 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
838 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
843 /*----------------------------------------------------------------------*/
845 #ifdef NOT_USED_SO_FAR
847 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
849 volatile immap_t *immr = (immap_t *) CFG_IMMR;
850 volatile cpm8xx_t *cp = &(immr->im_cpm);
851 unsigned short colreg, *cmap_ptr;
853 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
856 #ifdef CFG_INVERT_COLORS
860 *red = (colreg >> 8) & 0x0F;
861 *green = (colreg >> 4) & 0x0F;
862 *blue = colreg & 0x0F;
864 #endif /* NOT_USED_SO_FAR */
866 /*----------------------------------------------------------------------*/
868 #if LCD_BPP == LCD_COLOR8
870 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
872 volatile immap_t *immr = (immap_t *) CFG_IMMR;
873 volatile cpm8xx_t *cp = &(immr->im_cpm);
874 unsigned short colreg, *cmap_ptr;
876 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
878 colreg = ((red & 0x0F) << 8) |
879 ((green & 0x0F) << 4) |
881 #ifdef CFG_INVERT_COLORS
886 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
887 regno, &(cp->lcd_cmap[regno * 2]),
889 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
891 #endif /* LCD_COLOR8 */
893 /*----------------------------------------------------------------------*/
895 #if LCD_BPP == LCD_MONOCHROME
897 void lcd_initcolregs (void)
899 volatile immap_t *immr = (immap_t *) CFG_IMMR;
900 volatile cpm8xx_t *cp = &(immr->im_cpm);
903 for (regno = 0; regno < 16; regno++) {
904 cp->lcd_cmap[regno * 2] = 0;
905 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
910 /*----------------------------------------------------------------------*/
912 static void lcd_setfgcolor (int color)
914 lcd_color_fg = color & 0x0F;
917 /*----------------------------------------------------------------------*/
919 static void lcd_setbgcolor (int color)
921 lcd_color_bg = color & 0x0F;
924 /*----------------------------------------------------------------------*/
926 #ifdef NOT_USED_SO_FAR
927 static int lcd_getfgcolor (void)
931 #endif /* NOT_USED_SO_FAR */
933 /*----------------------------------------------------------------------*/
935 static int lcd_getbgcolor (void)
940 /*----------------------------------------------------------------------*/
942 static void lcd_enable (void)
944 volatile immap_t *immr = (immap_t *) CFG_IMMR;
945 volatile lcd823_t *lcdp = &immr->im_lcd;
947 /* Enable the LCD panel */
948 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
949 lcdp->lcd_lccr |= LCCR_PON;
950 #if defined(CONFIG_LWMON)
951 { uchar c = pic_read (0x60);
952 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
955 #elif defined(CONFIG_R360MPI)
957 extern void r360_pwm_write (uchar reg, uchar val);
959 r360_pwm_write(8, 1);
960 r360_pwm_write(0, 4);
961 r360_pwm_write(1, 6);
963 #endif /* CONFIG_LWMON */
966 /*----------------------------------------------------------------------*/
968 #ifdef NOT_USED_SO_FAR
969 static void lcd_disable (void)
971 volatile immap_t *immr = (immap_t *) CFG_IMMR;
972 volatile lcd823_t *lcdp = &immr->im_lcd;
974 #if defined(CONFIG_LWMON)
975 { uchar c = pic_read (0x60);
976 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
979 #elif defined(CONFIG_R360MPI)
981 extern void r360_pwm_write (uchar reg, uchar val);
983 r360_pwm_write(0, 0);
984 r360_pwm_write(1, 0);
986 #endif /* CONFIG_LWMON */
987 /* Disable the LCD panel */
988 lcdp->lcd_lccr &= ~LCCR_PON;
989 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
991 #endif /* NOT_USED_SO_FAR */
994 /************************************************************************/
995 /* ** Chipset depending Bitmap / Logo stuff... */
996 /************************************************************************/
999 #ifdef CONFIG_LCD_LOGO
1000 static void bitmap_plot (int x, int y)
1002 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1003 volatile cpm8xx_t *cp = &(immr->im_cpm);
1009 debug ("Logo: width %d height %d colors %d cmap %d\n",
1010 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1011 sizeof(bmp_logo_palette)/(sizeof(ushort))
1014 /* Leave room for default color map */
1015 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1018 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1019 ushort colreg = bmp_logo_palette[i];
1020 #ifdef CFG_INVERT_COLORS
1026 bmap = &bmp_logo_bitmap[0];
1027 fb = (char *)(lcd_base + y * lcd_line_length + x);
1029 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1030 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1031 bmap += BMP_LOGO_WIDTH;
1032 fb += panel_info.vl_col;
1035 #endif /* CONFIG_LCD_LOGO */
1037 /*----------------------------------------------------------------------*/
1039 static void *lcd_logo (void)
1042 DECLARE_GLOBAL_DATA_PTR;
1046 #endif /* LCD_INFO */
1048 #ifdef CONFIG_LCD_LOGO
1050 #endif /* CONFIG_LCD_LOGO */
1054 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1055 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1057 sprintf (info, "(C) 2002 DENX Software Engineering");
1058 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1059 info, strlen(info));
1061 sprintf (info, " Wolfgang DENK, wd@denx.de");
1062 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1063 info, strlen(info));
1064 #ifdef LCD_INFO_BELOW_LOGO
1065 sprintf (info, "MPC823 CPU at %s MHz",
1066 strmhz(temp, gd->cpu_clk));
1067 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1068 info, strlen(info));
1069 sprintf (info, " %ld MB RAM, %ld MB Flash",
1071 gd->bd->bi_flashsize >> 20 );
1072 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1073 info, strlen(info));
1075 /* leave one blank line */
1077 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1078 strmhz(temp, gd->cpu_clk),
1080 gd->bd->bi_flashsize >> 20 );
1081 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1082 info, strlen(info));
1083 #endif /* LCD_INFO_BELOW_LOGO */
1084 #endif /* LCD_INFO */
1086 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1087 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1089 return ((void *)lcd_base);
1090 #endif /* CONFIG_LCD_LOGO */
1093 /************************************************************************/
1094 /************************************************************************/
1096 #endif /* CONFIG_LCD */