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.
180 static vidinfo_t panel_info = {
181 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
182 3, 0, 0, 1, 1, 15, 4, 0, 3
183 /* wbl, vpw, lcdac, wbf */
185 #define LCD_INFO_BELOW_LOGO
186 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
187 /*----------------------------------------------------------------------*/
189 #ifdef CONFIG_SHARP_LQ64D341
191 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
193 static vidinfo_t panel_info = {
194 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
195 3, 0, 0, 1, 1, 128, 16, 0, 32
196 /* wbl, vpw, lcdac, wbf */
198 #endif /* CONFIG_SHARP_LQ64D341 */
200 #ifdef CONFIG_SHARP_LQ084V1DG21
202 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
204 static vidinfo_t panel_info = {
205 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
206 3, 0, 0, 1, 1, 160, 3, 0, 48
207 /* wbl, vpw, lcdac, wbf */
209 #endif /* CONFIG_SHARP_LQ084V1DG21 */
211 /*----------------------------------------------------------------------*/
213 #ifdef CONFIG_HLD1045
215 * HLD1045 display, 640x480. Active, color, single scan.
217 static vidinfo_t panel_info = {
218 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
219 3, 0, 0, 1, 1, 160, 3, 0, 48
220 /* wbl, vpw, lcdac, wbf */
222 #endif /* CONFIG_HLD1045 */
223 /*----------------------------------------------------------------------*/
225 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
227 * Prime View V16C6448AC
229 static vidinfo_t panel_info = {
230 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
231 3, 0, 0, 1, 1, 144, 2, 0, 35
232 /* wbl, vpw, lcdac, wbf */
234 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
236 /*----------------------------------------------------------------------*/
238 #ifdef CONFIG_OPTREX_BW
240 * Optrex CBL50840-2 NF-FW 99 22 M5
242 * Hitachi LMG6912RPFC-00T
246 * 320x240. Black & white.
248 #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
249 /* 1 - 4 grey levels, 2 bpp */
250 /* 2 - 16 grey levels, 4 bpp */
251 static vidinfo_t panel_info = {
252 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
253 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
255 #endif /* CONFIG_OPTREX_BW */
257 /*-----------------------------------------------------------------*/
258 #ifdef CONFIG_EDT32F10
260 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
262 #define LCD_BPP LCD_MONOCHROME
265 static vidinfo_t panel_info = {
266 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
267 LCD_BPP, 0, 0, 0, 0, 0, 15, 0, 0
270 /*----------------------------------------------------------------------*/
272 #if defined(LCD_INFO_BELOW_LOGO)
273 # define LCD_INFO_X 0
274 # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
275 #elif defined(CONFIG_LCD_LOGO)
276 # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
277 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
279 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
280 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
284 #define LCD_BPP LCD_COLOR8
290 #define NBITS(bit_code) (1 << (bit_code))
291 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
293 static int lcd_line_length;
295 static int lcd_color_fg;
296 static int lcd_color_bg;
298 static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
301 * Frame buffer memory information
303 static void *lcd_base; /* Start of framebuffer memory */
304 static void *lcd_console_address; /* Start of console buffer */
307 /************************************************************************/
308 /* ** CONSOLE CONSTANTS */
309 /************************************************************************/
311 #if LCD_BPP == LCD_MONOCHROME
314 * Simple color definitions
316 #define CONSOLE_COLOR_BLACK 0
317 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
322 * Simple color definitions
324 #define CONSOLE_COLOR_BLACK 0
325 #define CONSOLE_COLOR_RED 1
326 #define CONSOLE_COLOR_GREEN 2
327 #define CONSOLE_COLOR_YELLOW 3
328 #define CONSOLE_COLOR_BLUE 4
329 #define CONSOLE_COLOR_MAGENTA 5
330 #define CONSOLE_COLOR_CYAN 6
331 #define CONSOLE_COLOR_GREY 14
332 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
336 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
337 #error Default Color Map overlaps with Logo Color Map
340 /************************************************************************/
343 #define PAGE_SIZE 4096
347 /************************************************************************/
348 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
349 /************************************************************************/
351 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
352 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
355 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
357 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
358 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
359 #define CONSOLE_ROW_FIRST (lcd_console_address)
360 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
361 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
363 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
364 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
366 #if LCD_BPP == LCD_MONOCHROME
367 #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
368 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
369 #elif LCD_BPP == LCD_COLOR8
370 #define COLOR_MASK(c) (c)
372 #error Unsupported LCD BPP.
375 static short console_col;
376 static short console_row;
378 /************************************************************************/
380 ulong lcd_setmem (ulong addr);
382 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
383 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
384 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
386 static int lcd_init (void *lcdbase);
387 static void lcd_ctrl_init (void *lcdbase);
388 static void lcd_enable (void);
389 static void *lcd_logo (void);
390 #if LCD_BPP == LCD_COLOR8
391 static void lcd_setcolreg (ushort regno,
392 ushort red, ushort green, ushort blue);
394 #if LCD_BPP == LCD_MONOCHROME
395 static void lcd_initcolregs (void);
397 static int lcd_getbgcolor (void);
398 static void lcd_setfgcolor (int color);
399 static void lcd_setbgcolor (int color);
401 #ifdef NOT_USED_SO_FAR
402 static void lcd_disable (void);
403 static void lcd_getcolreg (ushort regno,
404 ushort *red, ushort *green, ushort *blue);
405 static int lcd_getfgcolor (void);
406 #endif /* NOT_USED_SO_FAR */
408 /************************************************************************/
410 /*----------------------------------------------------------------------*/
412 static void console_scrollup (void)
415 /* Copy up rows ignoring the first one */
416 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
418 /* Clear the last one */
419 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
422 * Poor attempt to optimize speed by moving "long"s.
423 * But the code is ugly, and not a bit faster :-(
425 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
426 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
427 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
428 uchar c = lcd_color_bg & 0xFF;
429 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
434 t = (ulong *)CONSOLE_ROW_LAST;
435 l = CONSOLE_ROW_SIZE / sizeof(ulong);
442 /*----------------------------------------------------------------------*/
444 static inline void console_back (void)
446 if (--console_col < 0) {
447 console_col = CONSOLE_COLS-1 ;
448 if (--console_row < 0) {
453 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
454 console_row * VIDEO_FONT_HEIGHT,
458 /*----------------------------------------------------------------------*/
460 static inline void console_newline (void)
465 /* Check if we need to scroll the terminal */
466 if (console_row >= CONSOLE_ROWS) {
467 /* Scroll everything up */
468 console_scrollup () ;
473 /*----------------------------------------------------------------------*/
475 void lcd_putc (const char c)
477 if (!lcd_is_enabled) {
483 case '\r': console_col = 0;
486 case '\n': console_newline();
489 case '\t': /* Tab (8 chars alignment) */
493 if (console_col >= CONSOLE_COLS) {
498 case '\b': console_back();
501 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
502 console_row * VIDEO_FONT_HEIGHT,
504 if (++console_col >= CONSOLE_COLS) {
512 /*----------------------------------------------------------------------*/
514 void lcd_puts (const char *s)
516 if (!lcd_is_enabled) {
526 /************************************************************************/
527 /* ** Low-Level Graphics Routines */
528 /************************************************************************/
530 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
535 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
536 off = x * (1 << LCD_BPP) % 8;
538 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
543 #if LCD_BPP == LCD_MONOCHROME
544 uchar rest = *d & -(1 << (8-off));
547 for (i=0; i<count; ++i) {
551 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
553 #if LCD_BPP == LCD_MONOCHROME
554 sym = (COLOR_MASK(lcd_color_fg) & bits) |
555 (COLOR_MASK(lcd_color_bg) & ~bits);
557 *d++ = rest | (sym >> off);
558 rest = sym << (8-off);
559 #elif LCD_BPP == LCD_COLOR8
560 for (c=0; c<8; ++c) {
561 *d++ = (bits & 0x80) ?
562 lcd_color_fg : lcd_color_bg;
568 #if LCD_BPP == LCD_MONOCHROME
569 *d = rest | (*d & ((1 << (8-off)) - 1));
574 /*----------------------------------------------------------------------*/
576 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
578 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
579 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
581 lcd_drawchars (x, y, s, strlen (s));
585 /*----------------------------------------------------------------------*/
587 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
589 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
590 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
592 lcd_drawchars (x, y, &c, 1);
596 /************************************************************************/
597 /** Small utility to check that you got the colours right */
598 /************************************************************************/
599 #ifdef LCD_TEST_PATTERN
604 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
605 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
606 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
609 static void test_pattern (void)
611 ushort v_max = panel_info.vl_row;
612 ushort h_max = panel_info.vl_col;
613 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
614 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
616 uchar *pix = (uchar *)lcd_base;
618 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
619 h_max, v_max, h_step, v_step);
621 /* WARNING: Code silently assumes 8bit/pixel */
622 for (v=0; v<v_max; ++v) {
623 uchar iy = v / v_step;
624 for (h=0; h<h_max; ++h) {
625 uchar ix = N_BLK_HOR * iy + (h/h_step);
626 *pix++ = test_colors[ix];
630 #endif /* LCD_TEST_PATTERN */
633 /************************************************************************/
634 /* ** GENERIC Initialization Routines */
635 /************************************************************************/
637 int drv_lcd_init (void)
639 DECLARE_GLOBAL_DATA_PTR;
644 lcd_base = (void *)(gd->fb_base);
646 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
648 lcd_init (lcd_base); /* LCD initialization */
650 /* Device initialization */
651 memset (&lcddev, 0, sizeof (lcddev));
653 strcpy (lcddev.name, "lcd");
654 lcddev.ext = 0; /* No extensions */
655 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
656 lcddev.putc = lcd_putc; /* 'putc' function */
657 lcddev.puts = lcd_puts; /* 'puts' function */
659 rc = device_register (&lcddev);
661 return (rc == 0) ? 1 : rc;
664 /*----------------------------------------------------------------------*/
666 static int lcd_init (void *lcdbase)
668 /* Initialize the lcd controller */
669 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
671 lcd_ctrl_init (lcdbase);
673 #if LCD_BPP == LCD_MONOCHROME
674 /* Setting the palette */
677 #elif LCD_BPP == LCD_COLOR8
678 /* Setting the palette */
679 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
680 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
681 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
682 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
683 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
684 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
685 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
686 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
687 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
690 #ifndef CFG_WHITE_ON_BLACK
691 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
692 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
694 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
695 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
696 #endif /* CFG_WHITE_ON_BLACK */
698 #ifdef LCD_TEST_PATTERN
701 /* set framebuffer to background color */
702 memset ((char *)lcd_base,
703 COLOR_MASK(lcd_getbgcolor()),
704 lcd_line_length*panel_info.vl_row);
709 /* Paint the logo and retrieve LCD base address */
710 debug ("[LCD] Drawing the logo...\n");
711 lcd_console_address = lcd_logo ();
713 /* Initialize the console */
715 #ifdef LCD_INFO_BELOW_LOGO
716 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
718 console_row = 1; /* leave 1 blank line below logo */
726 /************************************************************************/
727 /* ** ROM capable initialization part - needed to reserve FB memory */
728 /************************************************************************/
731 * This is called early in the system initialization to grab memory
732 * for the LCD controller.
733 * Returns new address for monitor, after reserving LCD buffer memory
735 * Note that this is running from ROM, so no write access to global data.
737 ulong lcd_setmem (ulong addr)
740 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
742 debug ("LCD panel info: %d x %d, %d bit/pix\n",
743 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
745 size = line_length * panel_info.vl_row;
747 /* Round up to nearest full page */
748 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
750 /* Allocate pages for the frame buffer. */
753 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
759 /************************************************************************/
760 /* ----------------- chipset specific functions ----------------------- */
761 /************************************************************************/
763 static void lcd_ctrl_init (void *lcdbase)
765 volatile immap_t *immr = (immap_t *) CFG_IMMR;
766 volatile lcd823_t *lcdp = &immr->im_lcd;
770 /* Initialize the LCD control register according to the LCD
771 * parameters defined. We do everything here but enable
775 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
776 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
778 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
779 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
780 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
781 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
782 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
783 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
784 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
785 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
786 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
787 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
790 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
791 lccrtmp |= LCCR_EIEN;
794 lcdp->lcd_lccr = lccrtmp;
795 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
797 /* Initialize LCD controller bus priorities.
799 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
801 /* set SHFT/CLOCK division factor 4
802 * This needs to be set based upon display type and processor
803 * speed. The TFT displays run about 20 to 30 MHz.
804 * I was running 64 MHz processor speed.
805 * The value for this divider must be chosen so the result is
806 * an integer of the processor speed (i.e., divide by 3 with
807 * 64 MHz would be bad).
809 immr->im_clkrst.car_sccr &= ~0x1F;
810 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
812 #ifndef CONFIG_EDT32F10
813 /* Enable LCD on port D.
815 immr->im_ioport.iop_pdpar |= 0x1FFF;
816 immr->im_ioport.iop_pddir |= 0x1FFF;
818 /* Enable LCD_A/B/C on port B.
820 immr->im_cpm.cp_pbpar |= 0x00005001;
821 immr->im_cpm.cp_pbdir |= 0x00005001;
823 /* Enable LCD on port D.
825 immr->im_ioport.iop_pdpar |= 0x1DFF;
826 immr->im_ioport.iop_pdpar &= ~0x0200;
827 immr->im_ioport.iop_pddir |= 0x1FFF;
828 immr->im_ioport.iop_pddat |= 0x0200;
831 /* Load the physical address of the linear frame buffer
832 * into the LCD controller.
833 * BIG NOTE: This has to be modified to load A and B depending
834 * upon the split mode of the LCD.
836 lcdp->lcd_lcfaa = (ulong)lcd_base;
837 lcdp->lcd_lcfba = (ulong)lcd_base;
839 /* MORE HACKS...This must be updated according to 823 manual
840 * for different panels.
842 #ifndef CONFIG_EDT32F10
843 lcdp->lcd_lchcr = LCHCR_BO |
844 LCDBIT (LCHCR_AT_BIT, 4) |
845 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
848 lcdp->lcd_lchcr = LCHCR_BO |
849 LCDBIT (LCHCR_AT_BIT, 4) |
850 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
854 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
855 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
856 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
861 /*----------------------------------------------------------------------*/
863 #ifdef NOT_USED_SO_FAR
865 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
867 volatile immap_t *immr = (immap_t *) CFG_IMMR;
868 volatile cpm8xx_t *cp = &(immr->im_cpm);
869 unsigned short colreg, *cmap_ptr;
871 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
874 #ifdef CFG_INVERT_COLORS
878 *red = (colreg >> 8) & 0x0F;
879 *green = (colreg >> 4) & 0x0F;
880 *blue = colreg & 0x0F;
882 #endif /* NOT_USED_SO_FAR */
884 /*----------------------------------------------------------------------*/
886 #if LCD_BPP == LCD_COLOR8
888 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
890 volatile immap_t *immr = (immap_t *) CFG_IMMR;
891 volatile cpm8xx_t *cp = &(immr->im_cpm);
892 unsigned short colreg, *cmap_ptr;
894 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
896 colreg = ((red & 0x0F) << 8) |
897 ((green & 0x0F) << 4) |
899 #ifdef CFG_INVERT_COLORS
904 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
905 regno, &(cp->lcd_cmap[regno * 2]),
907 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
909 #endif /* LCD_COLOR8 */
911 /*----------------------------------------------------------------------*/
913 #if LCD_BPP == LCD_MONOCHROME
915 void lcd_initcolregs (void)
917 volatile immap_t *immr = (immap_t *) CFG_IMMR;
918 volatile cpm8xx_t *cp = &(immr->im_cpm);
921 for (regno = 0; regno < 16; regno++) {
922 cp->lcd_cmap[regno * 2] = 0;
923 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
928 /*----------------------------------------------------------------------*/
930 static void lcd_setfgcolor (int color)
932 lcd_color_fg = color & 0x0F;
935 /*----------------------------------------------------------------------*/
937 static void lcd_setbgcolor (int color)
939 lcd_color_bg = color & 0x0F;
942 /*----------------------------------------------------------------------*/
944 #ifdef NOT_USED_SO_FAR
945 static int lcd_getfgcolor (void)
949 #endif /* NOT_USED_SO_FAR */
951 /*----------------------------------------------------------------------*/
953 static int lcd_getbgcolor (void)
958 /*----------------------------------------------------------------------*/
960 static void lcd_enable (void)
962 volatile immap_t *immr = (immap_t *) CFG_IMMR;
963 volatile lcd823_t *lcdp = &immr->im_lcd;
965 /* Enable the LCD panel */
966 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
967 lcdp->lcd_lccr |= LCCR_PON;
970 /* Turn on display backlight */
971 immr->im_cpm.cp_pbpar |= 0x00008000;
972 immr->im_cpm.cp_pbdir |= 0x00008000;
975 #if defined(CONFIG_LWMON)
976 { uchar c = pic_read (0x60);
977 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
980 #elif defined(CONFIG_R360MPI)
982 extern void r360_pwm_write (uchar reg, uchar val);
984 r360_pwm_write(8, 1);
985 r360_pwm_write(0, 4);
986 r360_pwm_write(1, 6);
988 #endif /* CONFIG_LWMON */
991 /*----------------------------------------------------------------------*/
993 #ifdef NOT_USED_SO_FAR
994 static void lcd_disable (void)
996 volatile immap_t *immr = (immap_t *) CFG_IMMR;
997 volatile lcd823_t *lcdp = &immr->im_lcd;
999 #if defined(CONFIG_LWMON)
1000 { uchar c = pic_read (0x60);
1001 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1002 pic_write (0x60, c);
1004 #elif defined(CONFIG_R360MPI)
1006 extern void r360_pwm_write (uchar reg, uchar val);
1008 r360_pwm_write(0, 0);
1009 r360_pwm_write(1, 0);
1011 #endif /* CONFIG_LWMON */
1012 /* Disable the LCD panel */
1013 lcdp->lcd_lccr &= ~LCCR_PON;
1014 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1016 #endif /* NOT_USED_SO_FAR */
1019 /************************************************************************/
1020 /* ** Chipset depending Bitmap / Logo stuff... */
1021 /************************************************************************/
1024 #ifdef CONFIG_LCD_LOGO
1025 static void bitmap_plot (int x, int y)
1027 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1028 volatile cpm8xx_t *cp = &(immr->im_cpm);
1034 debug ("Logo: width %d height %d colors %d cmap %d\n",
1035 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1036 sizeof(bmp_logo_palette)/(sizeof(ushort))
1039 /* Leave room for default color map */
1040 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1043 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1044 ushort colreg = bmp_logo_palette[i];
1045 #ifdef CFG_INVERT_COLORS
1051 bmap = &bmp_logo_bitmap[0];
1052 fb = (char *)(lcd_base + y * lcd_line_length + x);
1054 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1055 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1056 bmap += BMP_LOGO_WIDTH;
1057 fb += panel_info.vl_col;
1060 #endif /* CONFIG_LCD_LOGO */
1062 /*----------------------------------------------------------------------*/
1064 static void *lcd_logo (void)
1067 DECLARE_GLOBAL_DATA_PTR;
1071 #endif /* LCD_INFO */
1073 #ifdef CONFIG_LCD_LOGO
1075 #endif /* CONFIG_LCD_LOGO */
1079 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1080 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1082 sprintf (info, "(C) 2002 DENX Software Engineering");
1083 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1084 info, strlen(info));
1086 sprintf (info, " Wolfgang DENK, wd@denx.de");
1087 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1088 info, strlen(info));
1089 #ifdef LCD_INFO_BELOW_LOGO
1090 sprintf (info, "MPC823 CPU at %s MHz",
1091 strmhz(temp, gd->cpu_clk));
1092 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1093 info, strlen(info));
1094 sprintf (info, " %ld MB RAM, %ld MB Flash",
1096 gd->bd->bi_flashsize >> 20 );
1097 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1098 info, strlen(info));
1100 /* leave one blank line */
1102 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1103 strmhz(temp, gd->cpu_clk),
1105 gd->bd->bi_flashsize >> 20 );
1106 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1107 info, strlen(info));
1108 #endif /* LCD_INFO_BELOW_LOGO */
1109 #endif /* LCD_INFO */
1111 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1112 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1114 return ((void *)lcd_base);
1115 #endif /* CONFIG_LCD_LOGO */
1118 /************************************************************************/
1119 /************************************************************************/
1121 #endif /* CONFIG_LCD */