blob: f2e404c4b971e4f023c10c6ca3b9aef3b7962dd6 [file] [log] [blame]
wdenk5b1d7132002-11-03 00:07:02 +00001/*
2 * (C) Copyright 2001-2002
3 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24/************************************************************************/
25/* ** HEADER FILES */
26/************************************************************************/
27
wdenk8564acf2003-07-14 22:13:32 +000028/* #define DEBUG */
29
wdenk5b1d7132002-11-03 00:07:02 +000030#include <config.h>
31#include <common.h>
wdenk7aa78612003-05-03 15:50:43 +000032#include <watchdog.h>
wdenk5b1d7132002-11-03 00:07:02 +000033#include <version.h>
34#include <stdarg.h>
35#include <lcdvideo.h>
36#include <linux/types.h>
37#include <devices.h>
wdenk4532cb62003-04-27 22:52:51 +000038#if defined(CONFIG_POST)
39#include <post.h>
40#endif
wdenk682011f2003-06-03 23:54:09 +000041#include <lcd.h>
wdenk5b1d7132002-11-03 00:07:02 +000042
43#ifdef CONFIG_LCD
44
45/************************************************************************/
46/* ** CONFIG STUFF -- should be moved to board config file */
47/************************************************************************/
wdenk5b1d7132002-11-03 00:07:02 +000048#define CONFIG_LCD_LOGO
49#define LCD_INFO /* Display Logo, (C) and system info */
wdenk608c9142003-01-13 23:54:46 +000050
wdenkd791b1d2003-04-20 14:04:18 +000051#if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
wdenk608c9142003-01-13 23:54:46 +000052#undef CONFIG_LCD_LOGO
53#undef LCD_INFO
54#endif
55
wdenk5b1d7132002-11-03 00:07:02 +000056/* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
57/* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
58/************************************************************************/
59
60/************************************************************************/
wdenkd791b1d2003-04-20 14:04:18 +000061/* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
62/************************************************************************/
63
wdenk27b207f2003-07-24 23:38:38 +000064#if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenkd791b1d2003-04-20 14:04:18 +000065#include <bmp_layout.h>
wdenk27b207f2003-07-24 23:38:38 +000066#endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
wdenkd791b1d2003-04-20 14:04:18 +000067
68/************************************************************************/
wdenk5b1d7132002-11-03 00:07:02 +000069/* ** FONT AND LOGO DATA */
70/************************************************************************/
71
72#include <video_font.h> /* Get font data, width and height */
73
74#ifdef CONFIG_LCD_LOGO
75# include <bmp_logo.h> /* Get logo data, width and height */
76#endif
77
78/************************************************************************/
79/************************************************************************/
80
81/*
82 * Information about displays we are using. This is for configuring
83 * the LCD controller and memory allocation. Someone has to know what
84 * is connected, as we can't autodetect anything.
85 */
86#define CFG_HIGH 0 /* Pins are active high */
87#define CFG_LOW 1 /* Pins are active low */
88
89typedef struct vidinfo {
90 ushort vl_col; /* Number of columns (i.e. 640) */
91 ushort vl_row; /* Number of rows (i.e. 480) */
92 ushort vl_width; /* Width of display area in millimeters */
93 ushort vl_height; /* Height of display area in millimeters */
94
95 /* LCD configuration register.
96 */
97 u_char vl_clkp; /* Clock polarity */
98 u_char vl_oep; /* Output Enable polarity */
99 u_char vl_hsp; /* Horizontal Sync polarity */
100 u_char vl_vsp; /* Vertical Sync polarity */
101 u_char vl_dp; /* Data polarity */
102 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
103 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
104 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
105 u_char vl_clor; /* Color, 0 = mono, 1 = color */
106 u_char vl_tft; /* 0 = passive, 1 = TFT */
107
108 /* Horizontal control register. Timing from data sheet.
109 */
110 ushort vl_wbl; /* Wait between lines */
111
112 /* Vertical control register.
113 */
114 u_char vl_vpw; /* Vertical sync pulse width */
115 u_char vl_lcdac; /* LCD AC timing */
116 u_char vl_wbf; /* Wait between frames */
117} vidinfo_t;
118
119#define LCD_MONOCHROME 0
120#define LCD_COLOR2 1
121#define LCD_COLOR4 2
122#define LCD_COLOR8 3
123
124/*----------------------------------------------------------------------*/
125#ifdef CONFIG_KYOCERA_KCS057QV1AJ
126/*
127 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
128 */
129#define LCD_BPP LCD_COLOR4
130
131static vidinfo_t panel_info = {
132 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
133 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
134 /* wbl, vpw, lcdac, wbf */
135};
136#endif /* CONFIG_KYOCERA_KCS057QV1AJ */
137/*----------------------------------------------------------------------*/
138
139/*----------------------------------------------------------------------*/
wdenk682011f2003-06-03 23:54:09 +0000140#ifdef CONFIG_HITACHI_SP19X001_Z1A
141/*
142 * Hitachi SP19X001-. Active, color, single scan.
143 */
144static vidinfo_t panel_info = {
145 640, 480, 154, 116, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
146 LCD_COLOR8, 1, 0, 1, 0, 0, 0, 0, 0
147 /* wbl, vpw, lcdac, wbf */
148};
149#endif /* CONFIG_HITACHI_SP19X001_Z1A */
150/*----------------------------------------------------------------------*/
151
152/*----------------------------------------------------------------------*/
wdenk5b1d7132002-11-03 00:07:02 +0000153#ifdef CONFIG_NEC_NL6648AC33
154/*
155 * NEC NL6648AC33-18. Active, color, single scan.
156 */
157static vidinfo_t panel_info = {
158 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
159 3, 0, 0, 1, 1, 144, 2, 0, 33
160 /* wbl, vpw, lcdac, wbf */
161};
162#endif /* CONFIG_NEC_NL6648AC33 */
163/*----------------------------------------------------------------------*/
164
165#ifdef CONFIG_NEC_NL6648BC20
166/*
167 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
168 */
169static vidinfo_t panel_info = {
170 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
171 3, 0, 0, 1, 1, 144, 2, 0, 33
172 /* wbl, vpw, lcdac, wbf */
173};
174#endif /* CONFIG_NEC_NL6648BC20 */
175/*----------------------------------------------------------------------*/
176
177#ifdef CONFIG_SHARP_LQ104V7DS01
178/*
179 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
180 */
181static vidinfo_t panel_info = {
182 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
183 3, 0, 0, 1, 1, 25, 1, 0, 33
184 /* wbl, vpw, lcdac, wbf */
185};
186#endif /* CONFIG_SHARP_LQ104V7DS01 */
187/*----------------------------------------------------------------------*/
188
189#ifdef CONFIG_SHARP_16x9
190/*
191 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
192 * not sure what it is.......
193 */
194static vidinfo_t panel_info = {
195 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
196 3, 0, 0, 1, 1, 15, 4, 0, 3
197};
198#endif /* CONFIG_SHARP_16x9 */
199/*----------------------------------------------------------------------*/
200
201#ifdef CONFIG_SHARP_LQ057Q3DC02
202/*
203 * Sharp LQ057Q3DC02 display. Active, color, single scan.
204 */
wdenk4a6fd342003-04-12 23:38:12 +0000205#define LCD_DF 12
206
wdenk5b1d7132002-11-03 00:07:02 +0000207static vidinfo_t panel_info = {
208 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
209 3, 0, 0, 1, 1, 15, 4, 0, 3
210 /* wbl, vpw, lcdac, wbf */
211};
212#define LCD_INFO_BELOW_LOGO
213#endif /* CONFIG_SHARP_LQ057Q3DC02 */
214/*----------------------------------------------------------------------*/
215
216#ifdef CONFIG_SHARP_LQ64D341
217/*
218 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
219 */
220static vidinfo_t panel_info = {
221 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
222 3, 0, 0, 1, 1, 128, 16, 0, 32
223 /* wbl, vpw, lcdac, wbf */
224};
225#endif /* CONFIG_SHARP_LQ64D341 */
wdenk608c9142003-01-13 23:54:46 +0000226
227#ifdef CONFIG_SHARP_LQ084V1DG21
228/*
229 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
230 */
231static vidinfo_t panel_info = {
232 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
233 3, 0, 0, 1, 1, 160, 3, 0, 48
234 /* wbl, vpw, lcdac, wbf */
235};
236#endif /* CONFIG_SHARP_LQ084V1DG21 */
237
wdenk5b1d7132002-11-03 00:07:02 +0000238/*----------------------------------------------------------------------*/
239
240#ifdef CONFIG_HLD1045
241/*
242 * HLD1045 display, 640x480. Active, color, single scan.
243 */
244static vidinfo_t panel_info = {
245 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
246 3, 0, 0, 1, 1, 160, 3, 0, 48
247 /* wbl, vpw, lcdac, wbf */
248};
249#endif /* CONFIG_HLD1045 */
250/*----------------------------------------------------------------------*/
251
252#ifdef CONFIG_PRIMEVIEW_V16C6448AC
253/*
254 * Prime View V16C6448AC
255 */
256static vidinfo_t panel_info = {
257 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
258 3, 0, 0, 1, 1, 144, 2, 0, 35
259 /* wbl, vpw, lcdac, wbf */
260};
261#endif /* CONFIG_PRIMEVIEW_V16C6448AC */
262
263/*----------------------------------------------------------------------*/
264
265#ifdef CONFIG_OPTREX_BW
266/*
267 * Optrex CBL50840-2 NF-FW 99 22 M5
268 * or
269 * Hitachi LMG6912RPFC-00T
270 * or
271 * Hitachi SP14Q002
272 *
273 * 320x240. Black & white.
274 */
275#define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
276 /* 1 - 4 grey levels, 2 bpp */
277 /* 2 - 16 grey levels, 4 bpp */
278static vidinfo_t panel_info = {
279 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
280 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
281};
282#endif /* CONFIG_OPTREX_BW */
283
284/*-----------------------------------------------------------------*/
285#ifdef CONFIG_EDT32F10
286/*
287 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
288 */
289#define LCD_BPP LCD_MONOCHROME
wdenk4a6fd342003-04-12 23:38:12 +0000290#define LCD_DF 10
wdenk5b1d7132002-11-03 00:07:02 +0000291
292static vidinfo_t panel_info = {
293 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
wdenk4a6fd342003-04-12 23:38:12 +0000294 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
wdenk5b1d7132002-11-03 00:07:02 +0000295};
296#endif
297/*----------------------------------------------------------------------*/
298
299#if defined(LCD_INFO_BELOW_LOGO)
300# define LCD_INFO_X 0
301# define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
302#elif defined(CONFIG_LCD_LOGO)
303# define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
304# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
305#else
306# define LCD_INFO_X (VIDEO_FONT_WIDTH)
307# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
308#endif
309
310#ifndef LCD_BPP
311#define LCD_BPP LCD_COLOR8
312#endif
313#ifndef LCD_DF
314#define LCD_DF 1
315#endif
316
317#define NBITS(bit_code) (1 << (bit_code))
318#define NCOLORS(bit_code) (1 << NBITS(bit_code))
319
320static int lcd_line_length;
321
322static int lcd_color_fg;
323static int lcd_color_bg;
324
wdenk682011f2003-06-03 23:54:09 +0000325char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
wdenk5b1d7132002-11-03 00:07:02 +0000326
327/*
328 * Frame buffer memory information
329 */
330static void *lcd_base; /* Start of framebuffer memory */
331static void *lcd_console_address; /* Start of console buffer */
332
333
334/************************************************************************/
335/* ** CONSOLE CONSTANTS */
336/************************************************************************/
337
338#if LCD_BPP == LCD_MONOCHROME
339
340/*
341 * Simple color definitions
342 */
343#define CONSOLE_COLOR_BLACK 0
344#define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
345
346#else
347
348/*
349 * Simple color definitions
350 */
351#define CONSOLE_COLOR_BLACK 0
352#define CONSOLE_COLOR_RED 1
353#define CONSOLE_COLOR_GREEN 2
354#define CONSOLE_COLOR_YELLOW 3
355#define CONSOLE_COLOR_BLUE 4
356#define CONSOLE_COLOR_MAGENTA 5
357#define CONSOLE_COLOR_CYAN 6
358#define CONSOLE_COLOR_GREY 14
359#define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
360
361#endif
362
363#if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
364#error Default Color Map overlaps with Logo Color Map
365#endif
366
367/************************************************************************/
368
369#ifndef PAGE_SIZE
370#define PAGE_SIZE 4096
371#endif
372
373
374/************************************************************************/
375/* ** CONSOLE DEFINITIONS & FUNCTIONS */
376/************************************************************************/
377
378#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
379#define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
380 / VIDEO_FONT_HEIGHT)
381#else
382#define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
383#endif
384#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
385#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
386#define CONSOLE_ROW_FIRST (lcd_console_address)
387#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
388#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
389 - CONSOLE_ROW_SIZE)
390#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
391#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
392
393#if LCD_BPP == LCD_MONOCHROME
394#define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
395 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
396#elif LCD_BPP == LCD_COLOR8
397#define COLOR_MASK(c) (c)
398#else
399#error Unsupported LCD BPP.
400#endif
401
402static short console_col;
403static short console_row;
404
405/************************************************************************/
406
407ulong lcd_setmem (ulong addr);
408
409static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
410static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
411static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
412
wdenk682011f2003-06-03 23:54:09 +0000413int lcd_init (void *lcdbase);
414
wdenk5b1d7132002-11-03 00:07:02 +0000415static void lcd_ctrl_init (void *lcdbase);
416static void lcd_enable (void);
417static void *lcd_logo (void);
418#if LCD_BPP == LCD_COLOR8
419static void lcd_setcolreg (ushort regno,
420 ushort red, ushort green, ushort blue);
421#endif
422#if LCD_BPP == LCD_MONOCHROME
423static void lcd_initcolregs (void);
424#endif
425static int lcd_getbgcolor (void);
426static void lcd_setfgcolor (int color);
427static void lcd_setbgcolor (int color);
428
wdenk682011f2003-06-03 23:54:09 +0000429#if defined(CONFIG_RBC823)
430void lcd_disable (void);
431#endif
432
wdenk5b1d7132002-11-03 00:07:02 +0000433#ifdef NOT_USED_SO_FAR
wdenk5b1d7132002-11-03 00:07:02 +0000434static void lcd_getcolreg (ushort regno,
435 ushort *red, ushort *green, ushort *blue);
436static int lcd_getfgcolor (void);
437#endif /* NOT_USED_SO_FAR */
438
439/************************************************************************/
440
441/*----------------------------------------------------------------------*/
442
443static void console_scrollup (void)
444{
445#if 1
446 /* Copy up rows ignoring the first one */
447 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
448
449 /* Clear the last one */
450 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
451#else
452 /*
453 * Poor attempt to optimize speed by moving "long"s.
454 * But the code is ugly, and not a bit faster :-(
455 */
456 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
457 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
458 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
459 uchar c = lcd_color_bg & 0xFF;
460 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
461
462 while (l--)
463 *t++ = *s++;
464
465 t = (ulong *)CONSOLE_ROW_LAST;
466 l = CONSOLE_ROW_SIZE / sizeof(ulong);
467
468 while (l-- > 0)
469 *t++ = val;
470#endif
471}
472
473/*----------------------------------------------------------------------*/
474
475static inline void console_back (void)
476{
477 if (--console_col < 0) {
478 console_col = CONSOLE_COLS-1 ;
479 if (--console_row < 0) {
480 console_row = 0;
481 }
482 }
483
484 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
485 console_row * VIDEO_FONT_HEIGHT,
486 ' ');
487}
488
489/*----------------------------------------------------------------------*/
490
491static inline void console_newline (void)
492{
493 ++console_row;
494 console_col = 0;
495
496 /* Check if we need to scroll the terminal */
497 if (console_row >= CONSOLE_ROWS) {
498 /* Scroll everything up */
499 console_scrollup () ;
500 --console_row;
501 }
502}
503
504/*----------------------------------------------------------------------*/
505
506void lcd_putc (const char c)
507{
508 if (!lcd_is_enabled) {
509 serial_putc(c);
510 return;
511 }
512
513 switch (c) {
514 case '\r': console_col = 0;
515 return;
516
517 case '\n': console_newline();
518 return;
519
520 case '\t': /* Tab (8 chars alignment) */
521 console_col |= 8;
522 console_col &= ~7;
523
524 if (console_col >= CONSOLE_COLS) {
525 console_newline();
526 }
527 return;
528
529 case '\b': console_back();
530 return;
531
532 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
533 console_row * VIDEO_FONT_HEIGHT,
534 c);
535 if (++console_col >= CONSOLE_COLS) {
536 console_newline();
537 }
538 return;
539 }
540 /* NOTREACHED */
541}
542
543/*----------------------------------------------------------------------*/
544
545void lcd_puts (const char *s)
546{
547 if (!lcd_is_enabled) {
548 serial_puts (s);
549 return;
550 }
551
552 while (*s) {
553 lcd_putc (*s++);
554 }
555}
556
557/************************************************************************/
558/* ** Low-Level Graphics Routines */
559/************************************************************************/
560
561static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
562{
563 uchar *dest;
564 ushort off, row;
565
566 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
567 off = x * (1 << LCD_BPP) % 8;
568
569 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
570 uchar *s = str;
571 uchar *d = dest;
572 int i;
573
574#if LCD_BPP == LCD_MONOCHROME
575 uchar rest = *d & -(1 << (8-off));
576 uchar sym;
577#endif
578 for (i=0; i<count; ++i) {
579 uchar c, bits;
580
581 c = *s++;
582 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
583
584#if LCD_BPP == LCD_MONOCHROME
585 sym = (COLOR_MASK(lcd_color_fg) & bits) |
586 (COLOR_MASK(lcd_color_bg) & ~bits);
587
588 *d++ = rest | (sym >> off);
589 rest = sym << (8-off);
590#elif LCD_BPP == LCD_COLOR8
591 for (c=0; c<8; ++c) {
592 *d++ = (bits & 0x80) ?
593 lcd_color_fg : lcd_color_bg;
594 bits <<= 1;
595 }
596#endif
597 }
598
599#if LCD_BPP == LCD_MONOCHROME
600 *d = rest | (*d & ((1 << (8-off)) - 1));
601#endif
602 }
603}
604
605/*----------------------------------------------------------------------*/
606
607static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
608{
609#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
610 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
611#else
612 lcd_drawchars (x, y, s, strlen (s));
613#endif
614}
615
616/*----------------------------------------------------------------------*/
617
618static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
619{
620#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
621 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
622#else
623 lcd_drawchars (x, y, &c, 1);
624#endif
625}
626
627/************************************************************************/
628/** Small utility to check that you got the colours right */
629/************************************************************************/
630#ifdef LCD_TEST_PATTERN
631
632#define N_BLK_VERT 2
633#define N_BLK_HOR 3
634
635static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
636 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
637 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
638};
639
640static void test_pattern (void)
641{
642 ushort v_max = panel_info.vl_row;
643 ushort h_max = panel_info.vl_col;
644 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
645 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
646 ushort v, h;
647 uchar *pix = (uchar *)lcd_base;
648
649 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
650 h_max, v_max, h_step, v_step);
651
652 /* WARNING: Code silently assumes 8bit/pixel */
653 for (v=0; v<v_max; ++v) {
654 uchar iy = v / v_step;
655 for (h=0; h<h_max; ++h) {
656 uchar ix = N_BLK_HOR * iy + (h/h_step);
657 *pix++ = test_colors[ix];
658 }
659 }
660}
661#endif /* LCD_TEST_PATTERN */
662
663
664/************************************************************************/
665/* ** GENERIC Initialization Routines */
666/************************************************************************/
667
668int drv_lcd_init (void)
669{
670 DECLARE_GLOBAL_DATA_PTR;
671
672 device_t lcddev;
673 int rc;
674
675 lcd_base = (void *)(gd->fb_base);
676
677 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
678
679 lcd_init (lcd_base); /* LCD initialization */
680
681 /* Device initialization */
682 memset (&lcddev, 0, sizeof (lcddev));
683
684 strcpy (lcddev.name, "lcd");
685 lcddev.ext = 0; /* No extensions */
686 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
687 lcddev.putc = lcd_putc; /* 'putc' function */
688 lcddev.puts = lcd_puts; /* 'puts' function */
689
690 rc = device_register (&lcddev);
691
692 return (rc == 0) ? 1 : rc;
693}
694
695/*----------------------------------------------------------------------*/
696
wdenk682011f2003-06-03 23:54:09 +0000697int lcd_init (void *lcdbase)
wdenk5b1d7132002-11-03 00:07:02 +0000698{
699 /* Initialize the lcd controller */
700 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
701
702 lcd_ctrl_init (lcdbase);
703
704#if LCD_BPP == LCD_MONOCHROME
705 /* Setting the palette */
706 lcd_initcolregs();
707
708#elif LCD_BPP == LCD_COLOR8
709 /* Setting the palette */
710 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
711 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
712 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
713 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
714 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
715 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
716 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
717 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
718 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
719#endif
720
721#ifndef CFG_WHITE_ON_BLACK
722 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
723 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
724#else
725 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
726 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
727#endif /* CFG_WHITE_ON_BLACK */
728
729#ifdef LCD_TEST_PATTERN
730 test_pattern();
731#else
732 /* set framebuffer to background color */
733 memset ((char *)lcd_base,
734 COLOR_MASK(lcd_getbgcolor()),
735 lcd_line_length*panel_info.vl_row);
736#endif
737
738 lcd_enable ();
739
740 /* Paint the logo and retrieve LCD base address */
741 debug ("[LCD] Drawing the logo...\n");
742 lcd_console_address = lcd_logo ();
743
744 /* Initialize the console */
745 console_col = 0;
746#ifdef LCD_INFO_BELOW_LOGO
747 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
748#else
749 console_row = 1; /* leave 1 blank line below logo */
750#endif
751 lcd_is_enabled = 1;
752
753 return 0;
754}
755
756
757/************************************************************************/
758/* ** ROM capable initialization part - needed to reserve FB memory */
759/************************************************************************/
760
761/*
762 * This is called early in the system initialization to grab memory
763 * for the LCD controller.
764 * Returns new address for monitor, after reserving LCD buffer memory
765 *
766 * Note that this is running from ROM, so no write access to global data.
767 */
768ulong lcd_setmem (ulong addr)
769{
770 ulong size;
771 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
772
773 debug ("LCD panel info: %d x %d, %d bit/pix\n",
774 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
775
776 size = line_length * panel_info.vl_row;
777
778 /* Round up to nearest full page */
779 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
780
781 /* Allocate pages for the frame buffer. */
782 addr -= size;
783
784 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
785
786 return (addr);
787}
788
789
790/************************************************************************/
791/* ----------------- chipset specific functions ----------------------- */
792/************************************************************************/
793
794static void lcd_ctrl_init (void *lcdbase)
795{
796 volatile immap_t *immr = (immap_t *) CFG_IMMR;
797 volatile lcd823_t *lcdp = &immr->im_lcd;
798
799 uint lccrtmp;
wdenk682011f2003-06-03 23:54:09 +0000800 uint lchcr_hpc_tmp;
wdenk5b1d7132002-11-03 00:07:02 +0000801
802 /* Initialize the LCD control register according to the LCD
803 * parameters defined. We do everything here but enable
804 * the controller.
805 */
806
807 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
808 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
809
810 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
811 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
812 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
813 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
814 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
815 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
816 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
817 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
818 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
819 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
820
821#if 0
822 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
823 lccrtmp |= LCCR_EIEN;
824#endif
825
826 lcdp->lcd_lccr = lccrtmp;
827 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
828
829 /* Initialize LCD controller bus priorities.
830 */
wdenk682011f2003-06-03 23:54:09 +0000831#ifdef CONFIG_RBC823
832 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
833#else
wdenk5b1d7132002-11-03 00:07:02 +0000834 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
835
836 /* set SHFT/CLOCK division factor 4
837 * This needs to be set based upon display type and processor
838 * speed. The TFT displays run about 20 to 30 MHz.
839 * I was running 64 MHz processor speed.
840 * The value for this divider must be chosen so the result is
841 * an integer of the processor speed (i.e., divide by 3 with
842 * 64 MHz would be bad).
843 */
844 immr->im_clkrst.car_sccr &= ~0x1F;
845 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
846
wdenk682011f2003-06-03 23:54:09 +0000847#endif /* CONFIG_RBC823 */
848
849#if defined(CONFIG_RBC823)
850 /* Enable LCD on port D.
851 */
852 immr->im_ioport.iop_pddat &= 0x0300;
853 immr->im_ioport.iop_pdpar |= 0x1CFF;
854 immr->im_ioport.iop_pddir |= 0x1CFF;
855
856 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
857 */
858 immr->im_cpm.cp_pbdat &= ~0x00005001;
859 immr->im_cpm.cp_pbpar &= ~0x00005001;
860 immr->im_cpm.cp_pbdir |= 0x00005001;
861#elif !defined(CONFIG_EDT32F10)
wdenk5b1d7132002-11-03 00:07:02 +0000862 /* Enable LCD on port D.
863 */
864 immr->im_ioport.iop_pdpar |= 0x1FFF;
865 immr->im_ioport.iop_pddir |= 0x1FFF;
866
867 /* Enable LCD_A/B/C on port B.
868 */
869 immr->im_cpm.cp_pbpar |= 0x00005001;
870 immr->im_cpm.cp_pbdir |= 0x00005001;
871#else
872 /* Enable LCD on port D.
873 */
874 immr->im_ioport.iop_pdpar |= 0x1DFF;
875 immr->im_ioport.iop_pdpar &= ~0x0200;
876 immr->im_ioport.iop_pddir |= 0x1FFF;
877 immr->im_ioport.iop_pddat |= 0x0200;
878#endif
879
880 /* Load the physical address of the linear frame buffer
881 * into the LCD controller.
882 * BIG NOTE: This has to be modified to load A and B depending
883 * upon the split mode of the LCD.
884 */
885 lcdp->lcd_lcfaa = (ulong)lcd_base;
886 lcdp->lcd_lcfba = (ulong)lcd_base;
887
888 /* MORE HACKS...This must be updated according to 823 manual
889 * for different panels.
wdenk682011f2003-06-03 23:54:09 +0000890 * Udi Finkelstein - done - see below:
891 * Note: You better not try unsupported combinations such as
892 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
wdenk5b1d7132002-11-03 00:07:02 +0000893 */
wdenk682011f2003-06-03 23:54:09 +0000894 lchcr_hpc_tmp =
wdenk8bde7f72003-06-27 21:31:46 +0000895 (panel_info.vl_col *
wdenk682011f2003-06-03 23:54:09 +0000896 (panel_info.vl_tft ? 8 :
897 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
898 /* use << to mult by: single scan = 1, dual scan = 2 */
899 panel_info.vl_splt) *
900 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
901
wdenk5b1d7132002-11-03 00:07:02 +0000902 lcdp->lcd_lchcr = LCHCR_BO |
903 LCDBIT (LCHCR_AT_BIT, 4) |
wdenk682011f2003-06-03 23:54:09 +0000904 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
wdenk5b1d7132002-11-03 00:07:02 +0000905 panel_info.vl_wbl;
wdenk5b1d7132002-11-03 00:07:02 +0000906
907 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
908 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
909 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
910 panel_info.vl_wbf;
911
912}
913
914/*----------------------------------------------------------------------*/
915
916#ifdef NOT_USED_SO_FAR
917static void
918lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
919{
920 volatile immap_t *immr = (immap_t *) CFG_IMMR;
921 volatile cpm8xx_t *cp = &(immr->im_cpm);
922 unsigned short colreg, *cmap_ptr;
923
924 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
925
926 colreg = *cmap_ptr;
927#ifdef CFG_INVERT_COLORS
928 colreg ^= 0x0FFF;
929#endif
930
931 *red = (colreg >> 8) & 0x0F;
932 *green = (colreg >> 4) & 0x0F;
933 *blue = colreg & 0x0F;
934}
935#endif /* NOT_USED_SO_FAR */
936
937/*----------------------------------------------------------------------*/
938
939#if LCD_BPP == LCD_COLOR8
940static void
941lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
942{
943 volatile immap_t *immr = (immap_t *) CFG_IMMR;
944 volatile cpm8xx_t *cp = &(immr->im_cpm);
945 unsigned short colreg, *cmap_ptr;
946
947 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
948
949 colreg = ((red & 0x0F) << 8) |
950 ((green & 0x0F) << 4) |
951 (blue & 0x0F) ;
952#ifdef CFG_INVERT_COLORS
953 colreg ^= 0x0FFF;
954#endif
955 *cmap_ptr = colreg;
956
957 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
958 regno, &(cp->lcd_cmap[regno * 2]),
959 red, green, blue,
wdenk8bde7f72003-06-27 21:31:46 +0000960 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
wdenk5b1d7132002-11-03 00:07:02 +0000961}
962#endif /* LCD_COLOR8 */
963
964/*----------------------------------------------------------------------*/
965
966#if LCD_BPP == LCD_MONOCHROME
967static
968void lcd_initcolregs (void)
969{
970 volatile immap_t *immr = (immap_t *) CFG_IMMR;
971 volatile cpm8xx_t *cp = &(immr->im_cpm);
972 ushort regno;
973
974 for (regno = 0; regno < 16; regno++) {
975 cp->lcd_cmap[regno * 2] = 0;
976 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
977 }
978}
979#endif
980
981/*----------------------------------------------------------------------*/
982
983static void lcd_setfgcolor (int color)
984{
985 lcd_color_fg = color & 0x0F;
986}
987
988/*----------------------------------------------------------------------*/
989
990static void lcd_setbgcolor (int color)
991{
992 lcd_color_bg = color & 0x0F;
993}
994
995/*----------------------------------------------------------------------*/
996
997#ifdef NOT_USED_SO_FAR
998static int lcd_getfgcolor (void)
999{
1000 return lcd_color_fg;
1001}
1002#endif /* NOT_USED_SO_FAR */
1003
1004/*----------------------------------------------------------------------*/
1005
1006static int lcd_getbgcolor (void)
1007{
1008 return lcd_color_bg;
1009}
1010
1011/*----------------------------------------------------------------------*/
1012
1013static void lcd_enable (void)
1014{
1015 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1016 volatile lcd823_t *lcdp = &immr->im_lcd;
1017
1018 /* Enable the LCD panel */
wdenk682011f2003-06-03 23:54:09 +00001019#ifndef CONFIG_RBC823
wdenk5b1d7132002-11-03 00:07:02 +00001020 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
wdenk682011f2003-06-03 23:54:09 +00001021#endif
wdenk5b1d7132002-11-03 00:07:02 +00001022 lcdp->lcd_lccr |= LCCR_PON;
wdenk608c9142003-01-13 23:54:46 +00001023
1024#ifdef CONFIG_V37
1025 /* Turn on display backlight */
1026 immr->im_cpm.cp_pbpar |= 0x00008000;
1027 immr->im_cpm.cp_pbdir |= 0x00008000;
wdenk682011f2003-06-03 23:54:09 +00001028#elif defined(CONFIG_RBC823)
1029 /* Turn on display backlight */
1030 immr->im_cpm.cp_pbdat |= 0x00004000;
wdenk608c9142003-01-13 23:54:46 +00001031#endif
1032
wdenk5b1d7132002-11-03 00:07:02 +00001033#if defined(CONFIG_LWMON)
1034 { uchar c = pic_read (0x60);
wdenk4532cb62003-04-27 22:52:51 +00001035#if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
wdenk8bde7f72003-06-27 21:31:46 +00001036 c |= 0x04; /* Chip Enable LCD */
wdenk4532cb62003-04-27 22:52:51 +00001037#else
wdenk8bde7f72003-06-27 21:31:46 +00001038 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
wdenk4532cb62003-04-27 22:52:51 +00001039#endif
wdenk5b1d7132002-11-03 00:07:02 +00001040 pic_write (0x60, c);
1041 }
wdenk5b1d7132002-11-03 00:07:02 +00001042#endif /* CONFIG_LWMON */
wdenk4a6fd342003-04-12 23:38:12 +00001043
1044#if defined(CONFIG_R360MPI)
1045 {
1046 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenkcb4dbb72003-07-16 16:40:22 +00001047 unsigned long bgi, ctr;
1048 char *p;
1049
1050 if ((p = getenv("lcdbgi")) != NULL) {
1051 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1052 } else {
1053 bgi = 0xFFF;
1054 }
1055
1056 if ((p = getenv("lcdctr")) != NULL) {
1057 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1058 } else {
1059 ctr=0x7FF;
1060 }
wdenk4a6fd342003-04-12 23:38:12 +00001061
1062 r360_i2c_lcd_write(0x10, 0x01);
1063 r360_i2c_lcd_write(0x20, 0x01);
wdenkcb4dbb72003-07-16 16:40:22 +00001064 r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1065 r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
wdenk4a6fd342003-04-12 23:38:12 +00001066 }
1067#endif /* CONFIG_R360MPI */
wdenk682011f2003-06-03 23:54:09 +00001068#ifdef CONFIG_RBC823
1069 udelay(200000); /* wait 200ms */
1070 /* Turn VEE_ON first */
1071 immr->im_cpm.cp_pbdat |= 0x00000001;
1072 udelay(200000); /* wait 200ms */
1073 /* Now turn on LCD_ON */
1074 immr->im_cpm.cp_pbdat |= 0x00001000;
1075#endif
wdenk8564acf2003-07-14 22:13:32 +00001076#ifdef CONFIG_RRVISION
1077 debug ("PC4->Output(1): enable LVDS\n");
1078 debug ("PC5->Output(0): disable PAL clock\n");
1079 immr->im_ioport.iop_pddir |= 0x1000;
1080 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1081 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1082 immr->im_ioport.iop_pcdat |= 0x0800 ;
1083 immr->im_ioport.iop_pcdat &= ~(0x0400);
1084 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1085 immr->im_ioport.iop_pdpar,
1086 immr->im_ioport.iop_pddir,
1087 immr->im_ioport.iop_pddat);
1088 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1089 immr->im_ioport.iop_pcpar,
1090 immr->im_ioport.iop_pcdir,
1091 immr->im_ioport.iop_pcdat);
1092#endif
wdenk5b1d7132002-11-03 00:07:02 +00001093}
1094
1095/*----------------------------------------------------------------------*/
1096
wdenk682011f2003-06-03 23:54:09 +00001097#if defined (CONFIG_RBC823)
1098void lcd_disable (void)
wdenk5b1d7132002-11-03 00:07:02 +00001099{
1100 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1101 volatile lcd823_t *lcdp = &immr->im_lcd;
1102
1103#if defined(CONFIG_LWMON)
1104 { uchar c = pic_read (0x60);
wdenk8bde7f72003-06-27 21:31:46 +00001105 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
wdenk5b1d7132002-11-03 00:07:02 +00001106 pic_write (0x60, c);
1107 }
1108#elif defined(CONFIG_R360MPI)
1109 {
wdenk4a6fd342003-04-12 23:38:12 +00001110 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenk5b1d7132002-11-03 00:07:02 +00001111
wdenk4a6fd342003-04-12 23:38:12 +00001112 r360_i2c_lcd_write(0x10, 0x00);
1113 r360_i2c_lcd_write(0x20, 0x00);
1114 r360_i2c_lcd_write(0x30, 0x00);
1115 r360_i2c_lcd_write(0x40, 0x00);
wdenk5b1d7132002-11-03 00:07:02 +00001116 }
1117#endif /* CONFIG_LWMON */
1118 /* Disable the LCD panel */
1119 lcdp->lcd_lccr &= ~LCCR_PON;
wdenk682011f2003-06-03 23:54:09 +00001120#ifdef CONFIG_RBC823
1121 /* Turn off display backlight, VEE and LCD_ON */
1122 immr->im_cpm.cp_pbdat &= ~0x00005001;
1123#else
wdenk5b1d7132002-11-03 00:07:02 +00001124 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
wdenk682011f2003-06-03 23:54:09 +00001125#endif /* CONFIG_RBC823 */
wdenk5b1d7132002-11-03 00:07:02 +00001126}
wdenk682011f2003-06-03 23:54:09 +00001127#endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
wdenk5b1d7132002-11-03 00:07:02 +00001128
1129
1130/************************************************************************/
1131/* ** Chipset depending Bitmap / Logo stuff... */
1132/************************************************************************/
1133
1134
1135#ifdef CONFIG_LCD_LOGO
1136static void bitmap_plot (int x, int y)
1137{
1138 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1139 volatile cpm8xx_t *cp = &(immr->im_cpm);
1140 ushort *cmap;
1141 ushort i;
1142 uchar *bmap;
1143 uchar *fb;
1144
1145 debug ("Logo: width %d height %d colors %d cmap %d\n",
1146 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1147 sizeof(bmp_logo_palette)/(sizeof(ushort))
1148 );
1149
1150 /* Leave room for default color map */
1151 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1152
wdenk7aa78612003-05-03 15:50:43 +00001153 WATCHDOG_RESET();
1154
wdenk5b1d7132002-11-03 00:07:02 +00001155 /* Set color map */
1156 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1157 ushort colreg = bmp_logo_palette[i];
1158#ifdef CFG_INVERT_COLORS
1159 colreg ^= 0xFFF;
1160#endif
1161 *cmap++ = colreg;
1162 }
1163
1164 bmap = &bmp_logo_bitmap[0];
1165 fb = (char *)(lcd_base + y * lcd_line_length + x);
1166
wdenk7aa78612003-05-03 15:50:43 +00001167 WATCHDOG_RESET();
1168
wdenk5b1d7132002-11-03 00:07:02 +00001169 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1170 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1171 bmap += BMP_LOGO_WIDTH;
1172 fb += panel_info.vl_col;
1173 }
wdenk7aa78612003-05-03 15:50:43 +00001174
1175 WATCHDOG_RESET();
wdenk5b1d7132002-11-03 00:07:02 +00001176}
1177#endif /* CONFIG_LCD_LOGO */
1178
wdenk27b207f2003-07-24 23:38:38 +00001179#if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenkd791b1d2003-04-20 14:04:18 +00001180/*
wdenk824a1eb2003-04-20 16:49:37 +00001181 * Display the BMP file located at address bmp_image.
1182 * Only uncompressed
1183 */
wdenkd791b1d2003-04-20 14:04:18 +00001184int lcd_display_bitmap(ulong bmp_image)
1185{
1186 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1187 volatile cpm8xx_t *cp = &(immr->im_cpm);
1188 ushort *cmap;
1189 ushort i, j;
1190 uchar *fb;
1191 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1192 uchar *bmap;
1193 ushort padded_line;
1194 unsigned long width, height;
1195 unsigned colors,bpix;
1196 unsigned long compression;
1197
wdenk7aa78612003-05-03 15:50:43 +00001198 WATCHDOG_RESET();
1199
wdenkd791b1d2003-04-20 14:04:18 +00001200 if (!((bmp->header.signature[0]=='B') &&
1201 (bmp->header.signature[1]=='M'))) {
1202 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1203 return 1;
1204 }
1205
1206 width = le32_to_cpu (bmp->header.width);
1207 height = le32_to_cpu (bmp->header.height);
1208 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1209 compression = le32_to_cpu (bmp->header.compression);
1210
1211 bpix = NBITS(panel_info.vl_bpix);
1212
1213 if ((bpix != 1) && (bpix != 8)) {
1214 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1215 bpix);
1216 return 1;
1217 }
1218
1219 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1220 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1221 bpix,
1222 le16_to_cpu(bmp->header.bit_count));
1223 return 1;
1224 }
1225
1226 if (compression!=BMP_BI_RGB) {
1227 printf ("Error: compression type %ld not supported\n",
1228 compression);
1229 return 1;
1230 }
1231
1232 debug ("Display-bmp: %d x %d with %d colors\n",
1233 width, height, colors);
1234
1235 if (bpix==8) {
1236 /* Fill the entire color map */
1237 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1238
1239 /* Set color map */
1240 for (i = 0; i < colors; ++i) {
1241 bmp_color_table_entry_t cte = bmp->color_table[i];
1242 ushort colreg =
1243 ((cte.red>>4) << 8) |
1244 ((cte.green>>4) << 4) |
1245 (cte.blue>>4) ;
1246#ifdef CFG_INVERT_COLORS
1247 colreg ^= 0xFFF;
1248#endif
1249 *cmap-- = colreg;
1250 }
wdenk7aa78612003-05-03 15:50:43 +00001251
1252 WATCHDOG_RESET();
wdenkd791b1d2003-04-20 14:04:18 +00001253 }
1254
1255 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1256 if (width>panel_info.vl_col)
1257 width = panel_info.vl_col;
1258 if (height>panel_info.vl_row)
1259 height = panel_info.vl_row;
1260
1261 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1262 fb = (uchar *)
1263 (lcd_base +
1264 (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
1265 * lcd_line_length);
1266 for (i = 0; i < height; ++i) {
wdenk7aa78612003-05-03 15:50:43 +00001267 WATCHDOG_RESET();
wdenkd791b1d2003-04-20 14:04:18 +00001268 for (j = 0; j < width ; j++)
1269 *(fb++)=255-*(bmap++);
1270 bmap += (width - padded_line);
1271 fb -= (width + lcd_line_length);
1272 }
1273
1274 return (0);
1275}
wdenk27b207f2003-07-24 23:38:38 +00001276#endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
wdenkd791b1d2003-04-20 14:04:18 +00001277
wdenk5b1d7132002-11-03 00:07:02 +00001278/*----------------------------------------------------------------------*/
1279
1280static void *lcd_logo (void)
1281{
1282#ifdef LCD_INFO
1283 DECLARE_GLOBAL_DATA_PTR;
1284
1285 char info[80];
1286 char temp[32];
1287#endif /* LCD_INFO */
1288
wdenkd791b1d2003-04-20 14:04:18 +00001289#ifdef CONFIG_SPLASH_SCREEN
1290 char *s;
1291 ulong addr;
1292
1293 if ((s = getenv("splashimage")) != NULL) {
1294 addr = simple_strtoul(s, NULL, 16);
1295
1296 if (lcd_display_bitmap (addr) == 0) {
1297 return ((void *)lcd_base);
1298 }
1299 }
1300#endif /* CONFIG_SPLASH_SCREEN */
1301
wdenk5b1d7132002-11-03 00:07:02 +00001302#ifdef CONFIG_LCD_LOGO
1303 bitmap_plot (0, 0);
1304#endif /* CONFIG_LCD_LOGO */
1305
1306
1307#ifdef LCD_INFO
1308 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1309 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1310
wdenkd791b1d2003-04-20 14:04:18 +00001311 sprintf (info, "(C) 2003 DENX Software Engineering");
wdenk5b1d7132002-11-03 00:07:02 +00001312 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1313 info, strlen(info));
1314
1315 sprintf (info, " Wolfgang DENK, wd@denx.de");
1316 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1317 info, strlen(info));
1318#ifdef LCD_INFO_BELOW_LOGO
1319 sprintf (info, "MPC823 CPU at %s MHz",
1320 strmhz(temp, gd->cpu_clk));
1321 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1322 info, strlen(info));
1323 sprintf (info, " %ld MB RAM, %ld MB Flash",
1324 gd->ram_size >> 20,
1325 gd->bd->bi_flashsize >> 20 );
1326 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1327 info, strlen(info));
1328#else
1329 /* leave one blank line */
1330
1331 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1332 strmhz(temp, gd->cpu_clk),
1333 gd->ram_size >> 20,
1334 gd->bd->bi_flashsize >> 20 );
1335 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1336 info, strlen(info));
1337#endif /* LCD_INFO_BELOW_LOGO */
1338#endif /* LCD_INFO */
1339
1340#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1341 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1342#else
1343 return ((void *)lcd_base);
1344#endif /* CONFIG_LCD_LOGO */
1345}
1346
1347/************************************************************************/
1348/************************************************************************/
1349
1350#endif /* CONFIG_LCD */