blob: 794ca025096c9c171e52a2729a5ee13c5a81691b [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>
wdenkc3f4d172004-06-25 23:35:58 +000032#include <command.h>
wdenk7aa78612003-05-03 15:50:43 +000033#include <watchdog.h>
wdenk5b1d7132002-11-03 00:07:02 +000034#include <version.h>
35#include <stdarg.h>
36#include <lcdvideo.h>
37#include <linux/types.h>
38#include <devices.h>
wdenk4532cb62003-04-27 22:52:51 +000039#if defined(CONFIG_POST)
40#include <post.h>
41#endif
wdenk682011f2003-06-03 23:54:09 +000042#include <lcd.h>
wdenk5b1d7132002-11-03 00:07:02 +000043
44#ifdef CONFIG_LCD
45
46/************************************************************************/
47/* ** CONFIG STUFF -- should be moved to board config file */
48/************************************************************************/
wdenk5b1d7132002-11-03 00:07:02 +000049#define CONFIG_LCD_LOGO
50#define LCD_INFO /* Display Logo, (C) and system info */
wdenk608c9142003-01-13 23:54:46 +000051
wdenkd791b1d2003-04-20 14:04:18 +000052#if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
wdenk608c9142003-01-13 23:54:46 +000053#undef CONFIG_LCD_LOGO
54#undef LCD_INFO
55#endif
56
wdenk5b1d7132002-11-03 00:07:02 +000057/* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
58/* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
59/************************************************************************/
60
61/************************************************************************/
wdenkd791b1d2003-04-20 14:04:18 +000062/* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
63/************************************************************************/
64
wdenk27b207f2003-07-24 23:38:38 +000065#if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenkd791b1d2003-04-20 14:04:18 +000066#include <bmp_layout.h>
wdenk27b207f2003-07-24 23:38:38 +000067#endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
wdenkd791b1d2003-04-20 14:04:18 +000068
69/************************************************************************/
wdenk5b1d7132002-11-03 00:07:02 +000070/* ** FONT AND LOGO DATA */
71/************************************************************************/
72
73#include <video_font.h> /* Get font data, width and height */
74
75#ifdef CONFIG_LCD_LOGO
76# include <bmp_logo.h> /* Get logo data, width and height */
77#endif
78
79/************************************************************************/
80/************************************************************************/
81
82/*
83 * Information about displays we are using. This is for configuring
84 * the LCD controller and memory allocation. Someone has to know what
85 * is connected, as we can't autodetect anything.
86 */
87#define CFG_HIGH 0 /* Pins are active high */
88#define CFG_LOW 1 /* Pins are active low */
89
90typedef struct vidinfo {
91 ushort vl_col; /* Number of columns (i.e. 640) */
92 ushort vl_row; /* Number of rows (i.e. 480) */
93 ushort vl_width; /* Width of display area in millimeters */
94 ushort vl_height; /* Height of display area in millimeters */
95
96 /* LCD configuration register.
97 */
98 u_char vl_clkp; /* Clock polarity */
99 u_char vl_oep; /* Output Enable polarity */
100 u_char vl_hsp; /* Horizontal Sync polarity */
101 u_char vl_vsp; /* Vertical Sync polarity */
102 u_char vl_dp; /* Data polarity */
103 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
104 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
105 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
106 u_char vl_clor; /* Color, 0 = mono, 1 = color */
107 u_char vl_tft; /* 0 = passive, 1 = TFT */
108
109 /* Horizontal control register. Timing from data sheet.
110 */
111 ushort vl_wbl; /* Wait between lines */
112
113 /* Vertical control register.
114 */
115 u_char vl_vpw; /* Vertical sync pulse width */
116 u_char vl_lcdac; /* LCD AC timing */
117 u_char vl_wbf; /* Wait between frames */
118} vidinfo_t;
119
120#define LCD_MONOCHROME 0
121#define LCD_COLOR2 1
122#define LCD_COLOR4 2
123#define LCD_COLOR8 3
124
125/*----------------------------------------------------------------------*/
126#ifdef CONFIG_KYOCERA_KCS057QV1AJ
127/*
128 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
129 */
130#define LCD_BPP LCD_COLOR4
131
132static vidinfo_t panel_info = {
133 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
134 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
135 /* wbl, vpw, lcdac, wbf */
136};
137#endif /* CONFIG_KYOCERA_KCS057QV1AJ */
138/*----------------------------------------------------------------------*/
139
140/*----------------------------------------------------------------------*/
wdenk682011f2003-06-03 23:54:09 +0000141#ifdef CONFIG_HITACHI_SP19X001_Z1A
142/*
143 * Hitachi SP19X001-. Active, color, single scan.
144 */
145static vidinfo_t panel_info = {
146 640, 480, 154, 116, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
147 LCD_COLOR8, 1, 0, 1, 0, 0, 0, 0, 0
148 /* wbl, vpw, lcdac, wbf */
149};
150#endif /* CONFIG_HITACHI_SP19X001_Z1A */
151/*----------------------------------------------------------------------*/
152
153/*----------------------------------------------------------------------*/
wdenkfd3103b2003-11-25 16:55:19 +0000154#ifdef CONFIG_NEC_NL6448AC33
wdenk5b1d7132002-11-03 00:07:02 +0000155/*
wdenkfd3103b2003-11-25 16:55:19 +0000156 * NEC NL6448AC33-18. Active, color, single scan.
wdenk5b1d7132002-11-03 00:07:02 +0000157 */
158static vidinfo_t panel_info = {
159 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
160 3, 0, 0, 1, 1, 144, 2, 0, 33
161 /* wbl, vpw, lcdac, wbf */
162};
wdenkfd3103b2003-11-25 16:55:19 +0000163#endif /* CONFIG_NEC_NL6448AC33 */
wdenk5b1d7132002-11-03 00:07:02 +0000164/*----------------------------------------------------------------------*/
165
wdenkfd3103b2003-11-25 16:55:19 +0000166#ifdef CONFIG_NEC_NL6448BC20
wdenk5b1d7132002-11-03 00:07:02 +0000167/*
wdenkfd3103b2003-11-25 16:55:19 +0000168 * NEC NL6448BC20-08. 6.5", 640x480. Active, color, single scan.
wdenk5b1d7132002-11-03 00:07:02 +0000169 */
170static vidinfo_t panel_info = {
171 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
172 3, 0, 0, 1, 1, 144, 2, 0, 33
173 /* wbl, vpw, lcdac, wbf */
174};
wdenkfd3103b2003-11-25 16:55:19 +0000175#endif /* CONFIG_NEC_NL6448BC20 */
176/*----------------------------------------------------------------------*/
177
178#ifdef CONFIG_NEC_NL6448BC33_54
179/*
180 * NEC NL6448BC33-54. 10.4", 640x480. Active, color, single scan.
181 */
182static vidinfo_t panel_info = {
183 640, 480, 212, 158, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
184 3, 0, 0, 1, 1, 144, 2, 0, 33
185 /* wbl, vpw, lcdac, wbf */
186};
187#endif /* CONFIG_NEC_NL6448BC33_54 */
wdenk5b1d7132002-11-03 00:07:02 +0000188/*----------------------------------------------------------------------*/
189
190#ifdef CONFIG_SHARP_LQ104V7DS01
191/*
192 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
193 */
194static vidinfo_t panel_info = {
195 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
196 3, 0, 0, 1, 1, 25, 1, 0, 33
197 /* wbl, vpw, lcdac, wbf */
198};
199#endif /* CONFIG_SHARP_LQ104V7DS01 */
200/*----------------------------------------------------------------------*/
201
202#ifdef CONFIG_SHARP_16x9
203/*
204 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
205 * not sure what it is.......
206 */
207static vidinfo_t panel_info = {
208 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
209 3, 0, 0, 1, 1, 15, 4, 0, 3
210};
211#endif /* CONFIG_SHARP_16x9 */
212/*----------------------------------------------------------------------*/
213
214#ifdef CONFIG_SHARP_LQ057Q3DC02
215/*
216 * Sharp LQ057Q3DC02 display. Active, color, single scan.
217 */
wdenk4a6fd342003-04-12 23:38:12 +0000218#define LCD_DF 12
219
wdenk5b1d7132002-11-03 00:07:02 +0000220static vidinfo_t panel_info = {
221 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
222 3, 0, 0, 1, 1, 15, 4, 0, 3
223 /* wbl, vpw, lcdac, wbf */
224};
225#define LCD_INFO_BELOW_LOGO
226#endif /* CONFIG_SHARP_LQ057Q3DC02 */
227/*----------------------------------------------------------------------*/
228
229#ifdef CONFIG_SHARP_LQ64D341
230/*
231 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
232 */
233static vidinfo_t panel_info = {
234 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
235 3, 0, 0, 1, 1, 128, 16, 0, 32
236 /* wbl, vpw, lcdac, wbf */
237};
238#endif /* CONFIG_SHARP_LQ64D341 */
wdenk608c9142003-01-13 23:54:46 +0000239
dzu29127b62003-09-25 22:30:12 +0000240#ifdef CONFIG_SHARP_LQ065T9DR51U
241/*
242 * Sharp LQ065T9DR51U display, 400x240. Active, color, single scan.
243 */
244static vidinfo_t panel_info = {
245 400, 240, 143, 79, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
246 3, 0, 0, 1, 1, 248, 4, 0, 35
247 /* wbl, vpw, lcdac, wbf */
248};
249#define LCD_INFO_BELOW_LOGO
250#endif /* CONFIG_SHARP_LQ065T9DR51U */
251
wdenk608c9142003-01-13 23:54:46 +0000252#ifdef CONFIG_SHARP_LQ084V1DG21
253/*
254 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
255 */
256static vidinfo_t panel_info = {
257 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
258 3, 0, 0, 1, 1, 160, 3, 0, 48
259 /* wbl, vpw, lcdac, wbf */
260};
261#endif /* CONFIG_SHARP_LQ084V1DG21 */
262
wdenk5b1d7132002-11-03 00:07:02 +0000263/*----------------------------------------------------------------------*/
264
265#ifdef CONFIG_HLD1045
266/*
267 * HLD1045 display, 640x480. Active, color, single scan.
268 */
269static vidinfo_t panel_info = {
270 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
271 3, 0, 0, 1, 1, 160, 3, 0, 48
272 /* wbl, vpw, lcdac, wbf */
273};
274#endif /* CONFIG_HLD1045 */
275/*----------------------------------------------------------------------*/
276
277#ifdef CONFIG_PRIMEVIEW_V16C6448AC
278/*
279 * Prime View V16C6448AC
280 */
281static vidinfo_t panel_info = {
282 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
283 3, 0, 0, 1, 1, 144, 2, 0, 35
284 /* wbl, vpw, lcdac, wbf */
285};
286#endif /* CONFIG_PRIMEVIEW_V16C6448AC */
287
288/*----------------------------------------------------------------------*/
289
290#ifdef CONFIG_OPTREX_BW
291/*
292 * Optrex CBL50840-2 NF-FW 99 22 M5
293 * or
294 * Hitachi LMG6912RPFC-00T
295 * or
296 * Hitachi SP14Q002
297 *
298 * 320x240. Black & white.
299 */
300#define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
301 /* 1 - 4 grey levels, 2 bpp */
302 /* 2 - 16 grey levels, 4 bpp */
303static vidinfo_t panel_info = {
304 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
305 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
306};
307#endif /* CONFIG_OPTREX_BW */
308
309/*-----------------------------------------------------------------*/
310#ifdef CONFIG_EDT32F10
311/*
312 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
313 */
314#define LCD_BPP LCD_MONOCHROME
wdenk4a6fd342003-04-12 23:38:12 +0000315#define LCD_DF 10
wdenk5b1d7132002-11-03 00:07:02 +0000316
317static vidinfo_t panel_info = {
318 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
wdenk4a6fd342003-04-12 23:38:12 +0000319 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
wdenk5b1d7132002-11-03 00:07:02 +0000320};
321#endif
322/*----------------------------------------------------------------------*/
323
324#if defined(LCD_INFO_BELOW_LOGO)
325# define LCD_INFO_X 0
326# define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
327#elif defined(CONFIG_LCD_LOGO)
328# define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
329# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
330#else
331# define LCD_INFO_X (VIDEO_FONT_WIDTH)
332# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
333#endif
334
335#ifndef LCD_BPP
336#define LCD_BPP LCD_COLOR8
337#endif
338#ifndef LCD_DF
339#define LCD_DF 1
340#endif
341
342#define NBITS(bit_code) (1 << (bit_code))
343#define NCOLORS(bit_code) (1 << NBITS(bit_code))
344
345static int lcd_line_length;
346
347static int lcd_color_fg;
348static int lcd_color_bg;
349
wdenk682011f2003-06-03 23:54:09 +0000350char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
wdenk5b1d7132002-11-03 00:07:02 +0000351
352/*
353 * Frame buffer memory information
354 */
355static void *lcd_base; /* Start of framebuffer memory */
356static void *lcd_console_address; /* Start of console buffer */
357
358
359/************************************************************************/
360/* ** CONSOLE CONSTANTS */
361/************************************************************************/
362
363#if LCD_BPP == LCD_MONOCHROME
364
365/*
366 * Simple color definitions
367 */
368#define CONSOLE_COLOR_BLACK 0
369#define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
370
371#else
372
373/*
374 * Simple color definitions
375 */
376#define CONSOLE_COLOR_BLACK 0
377#define CONSOLE_COLOR_RED 1
378#define CONSOLE_COLOR_GREEN 2
379#define CONSOLE_COLOR_YELLOW 3
380#define CONSOLE_COLOR_BLUE 4
381#define CONSOLE_COLOR_MAGENTA 5
382#define CONSOLE_COLOR_CYAN 6
383#define CONSOLE_COLOR_GREY 14
384#define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
385
386#endif
387
388#if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
389#error Default Color Map overlaps with Logo Color Map
390#endif
391
392/************************************************************************/
393
394#ifndef PAGE_SIZE
395#define PAGE_SIZE 4096
396#endif
397
398
399/************************************************************************/
400/* ** CONSOLE DEFINITIONS & FUNCTIONS */
401/************************************************************************/
402
403#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
404#define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
405 / VIDEO_FONT_HEIGHT)
406#else
407#define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
408#endif
409#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
410#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
411#define CONSOLE_ROW_FIRST (lcd_console_address)
412#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
413#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
414 - CONSOLE_ROW_SIZE)
415#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
416#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
417
418#if LCD_BPP == LCD_MONOCHROME
419#define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
420 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
421#elif LCD_BPP == LCD_COLOR8
422#define COLOR_MASK(c) (c)
423#else
424#error Unsupported LCD BPP.
425#endif
426
427static short console_col;
428static short console_row;
429
430/************************************************************************/
431
432ulong lcd_setmem (ulong addr);
433
434static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
435static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
436static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
437
wdenkc3f4d172004-06-25 23:35:58 +0000438static int lcd_init (void *lcdbase);
wdenk682011f2003-06-03 23:54:09 +0000439
wdenkc3f4d172004-06-25 23:35:58 +0000440static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
wdenk5b1d7132002-11-03 00:07:02 +0000441static void lcd_ctrl_init (void *lcdbase);
442static void lcd_enable (void);
443static void *lcd_logo (void);
444#if LCD_BPP == LCD_COLOR8
445static void lcd_setcolreg (ushort regno,
446 ushort red, ushort green, ushort blue);
447#endif
448#if LCD_BPP == LCD_MONOCHROME
449static void lcd_initcolregs (void);
450#endif
451static int lcd_getbgcolor (void);
452static void lcd_setfgcolor (int color);
453static void lcd_setbgcolor (int color);
454
wdenk682011f2003-06-03 23:54:09 +0000455#if defined(CONFIG_RBC823)
456void lcd_disable (void);
457#endif
458
wdenk5b1d7132002-11-03 00:07:02 +0000459#ifdef NOT_USED_SO_FAR
wdenk5b1d7132002-11-03 00:07:02 +0000460static void lcd_getcolreg (ushort regno,
461 ushort *red, ushort *green, ushort *blue);
462static int lcd_getfgcolor (void);
463#endif /* NOT_USED_SO_FAR */
464
465/************************************************************************/
466
467/*----------------------------------------------------------------------*/
468
469static void console_scrollup (void)
470{
471#if 1
472 /* Copy up rows ignoring the first one */
473 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
474
475 /* Clear the last one */
476 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
477#else
478 /*
479 * Poor attempt to optimize speed by moving "long"s.
480 * But the code is ugly, and not a bit faster :-(
481 */
482 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
483 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
484 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
485 uchar c = lcd_color_bg & 0xFF;
486 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
487
488 while (l--)
489 *t++ = *s++;
490
491 t = (ulong *)CONSOLE_ROW_LAST;
492 l = CONSOLE_ROW_SIZE / sizeof(ulong);
493
494 while (l-- > 0)
495 *t++ = val;
496#endif
497}
498
499/*----------------------------------------------------------------------*/
500
501static inline void console_back (void)
502{
503 if (--console_col < 0) {
504 console_col = CONSOLE_COLS-1 ;
505 if (--console_row < 0) {
506 console_row = 0;
507 }
508 }
509
510 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
511 console_row * VIDEO_FONT_HEIGHT,
512 ' ');
513}
514
515/*----------------------------------------------------------------------*/
516
517static inline void console_newline (void)
518{
519 ++console_row;
520 console_col = 0;
521
522 /* Check if we need to scroll the terminal */
523 if (console_row >= CONSOLE_ROWS) {
524 /* Scroll everything up */
525 console_scrollup () ;
526 --console_row;
527 }
528}
529
530/*----------------------------------------------------------------------*/
531
532void lcd_putc (const char c)
533{
534 if (!lcd_is_enabled) {
535 serial_putc(c);
536 return;
537 }
538
539 switch (c) {
540 case '\r': console_col = 0;
541 return;
542
543 case '\n': console_newline();
544 return;
545
546 case '\t': /* Tab (8 chars alignment) */
547 console_col |= 8;
548 console_col &= ~7;
549
550 if (console_col >= CONSOLE_COLS) {
551 console_newline();
552 }
553 return;
554
555 case '\b': console_back();
556 return;
557
558 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
559 console_row * VIDEO_FONT_HEIGHT,
560 c);
561 if (++console_col >= CONSOLE_COLS) {
562 console_newline();
563 }
564 return;
565 }
566 /* NOTREACHED */
567}
568
569/*----------------------------------------------------------------------*/
570
571void lcd_puts (const char *s)
572{
573 if (!lcd_is_enabled) {
574 serial_puts (s);
575 return;
576 }
577
578 while (*s) {
579 lcd_putc (*s++);
580 }
581}
582
583/************************************************************************/
584/* ** Low-Level Graphics Routines */
585/************************************************************************/
586
587static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
588{
589 uchar *dest;
590 ushort off, row;
591
592 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
593 off = x * (1 << LCD_BPP) % 8;
594
595 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
596 uchar *s = str;
597 uchar *d = dest;
598 int i;
599
600#if LCD_BPP == LCD_MONOCHROME
601 uchar rest = *d & -(1 << (8-off));
602 uchar sym;
603#endif
604 for (i=0; i<count; ++i) {
605 uchar c, bits;
606
607 c = *s++;
608 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
609
610#if LCD_BPP == LCD_MONOCHROME
611 sym = (COLOR_MASK(lcd_color_fg) & bits) |
612 (COLOR_MASK(lcd_color_bg) & ~bits);
613
614 *d++ = rest | (sym >> off);
615 rest = sym << (8-off);
616#elif LCD_BPP == LCD_COLOR8
617 for (c=0; c<8; ++c) {
618 *d++ = (bits & 0x80) ?
619 lcd_color_fg : lcd_color_bg;
620 bits <<= 1;
621 }
622#endif
623 }
624
625#if LCD_BPP == LCD_MONOCHROME
626 *d = rest | (*d & ((1 << (8-off)) - 1));
627#endif
628 }
629}
630
631/*----------------------------------------------------------------------*/
632
633static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
634{
635#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
636 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
637#else
638 lcd_drawchars (x, y, s, strlen (s));
639#endif
640}
641
642/*----------------------------------------------------------------------*/
643
644static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
645{
646#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
647 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
648#else
649 lcd_drawchars (x, y, &c, 1);
650#endif
651}
652
653/************************************************************************/
654/** Small utility to check that you got the colours right */
655/************************************************************************/
656#ifdef LCD_TEST_PATTERN
657
658#define N_BLK_VERT 2
659#define N_BLK_HOR 3
660
661static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
662 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
663 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
664};
665
666static void test_pattern (void)
667{
668 ushort v_max = panel_info.vl_row;
669 ushort h_max = panel_info.vl_col;
670 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
671 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
672 ushort v, h;
673 uchar *pix = (uchar *)lcd_base;
674
675 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
676 h_max, v_max, h_step, v_step);
677
678 /* WARNING: Code silently assumes 8bit/pixel */
679 for (v=0; v<v_max; ++v) {
680 uchar iy = v / v_step;
681 for (h=0; h<h_max; ++h) {
682 uchar ix = N_BLK_HOR * iy + (h/h_step);
683 *pix++ = test_colors[ix];
684 }
685 }
686}
687#endif /* LCD_TEST_PATTERN */
688
689
690/************************************************************************/
691/* ** GENERIC Initialization Routines */
692/************************************************************************/
693
694int drv_lcd_init (void)
695{
696 DECLARE_GLOBAL_DATA_PTR;
697
698 device_t lcddev;
699 int rc;
700
701 lcd_base = (void *)(gd->fb_base);
702
703 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
704
705 lcd_init (lcd_base); /* LCD initialization */
706
707 /* Device initialization */
708 memset (&lcddev, 0, sizeof (lcddev));
709
710 strcpy (lcddev.name, "lcd");
711 lcddev.ext = 0; /* No extensions */
712 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
713 lcddev.putc = lcd_putc; /* 'putc' function */
714 lcddev.puts = lcd_puts; /* 'puts' function */
715
716 rc = device_register (&lcddev);
717
718 return (rc == 0) ? 1 : rc;
719}
720
721/*----------------------------------------------------------------------*/
722
wdenkc3f4d172004-06-25 23:35:58 +0000723static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
wdenk5b1d7132002-11-03 00:07:02 +0000724{
wdenk5b1d7132002-11-03 00:07:02 +0000725#if LCD_BPP == LCD_MONOCHROME
726 /* Setting the palette */
727 lcd_initcolregs();
728
729#elif LCD_BPP == LCD_COLOR8
730 /* Setting the palette */
731 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
732 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
733 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
734 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
735 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
736 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
737 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
738 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
739 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
740#endif
741
742#ifndef CFG_WHITE_ON_BLACK
743 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
744 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
745#else
746 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
747 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
748#endif /* CFG_WHITE_ON_BLACK */
749
750#ifdef LCD_TEST_PATTERN
751 test_pattern();
752#else
753 /* set framebuffer to background color */
754 memset ((char *)lcd_base,
755 COLOR_MASK(lcd_getbgcolor()),
756 lcd_line_length*panel_info.vl_row);
757#endif
wdenk5b1d7132002-11-03 00:07:02 +0000758 /* Paint the logo and retrieve LCD base address */
759 debug ("[LCD] Drawing the logo...\n");
760 lcd_console_address = lcd_logo ();
761
wdenkc3f4d172004-06-25 23:35:58 +0000762 console_col = 0;
763 console_row = 0;
764
765 return (0);
766}
767
768U_BOOT_CMD(
769 cls, 1, 1, lcd_clear,
770 "cls - clear screen\n",
771 NULL
772);
773
774/*----------------------------------------------------------------------*/
775
776static int lcd_init (void *lcdbase)
777{
778 /* Initialize the lcd controller */
779 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
780
781 lcd_ctrl_init (lcdbase);
782 lcd_clear (NULL, 1, 1, NULL); /* dummy args */
783 lcd_enable ();
784
wdenk5b1d7132002-11-03 00:07:02 +0000785 /* Initialize the console */
786 console_col = 0;
787#ifdef LCD_INFO_BELOW_LOGO
788 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
789#else
790 console_row = 1; /* leave 1 blank line below logo */
791#endif
792 lcd_is_enabled = 1;
793
794 return 0;
795}
796
797
798/************************************************************************/
799/* ** ROM capable initialization part - needed to reserve FB memory */
800/************************************************************************/
801
802/*
803 * This is called early in the system initialization to grab memory
804 * for the LCD controller.
805 * Returns new address for monitor, after reserving LCD buffer memory
806 *
807 * Note that this is running from ROM, so no write access to global data.
808 */
809ulong lcd_setmem (ulong addr)
810{
811 ulong size;
812 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
813
814 debug ("LCD panel info: %d x %d, %d bit/pix\n",
815 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
816
817 size = line_length * panel_info.vl_row;
818
819 /* Round up to nearest full page */
820 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
821
822 /* Allocate pages for the frame buffer. */
823 addr -= size;
824
825 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
826
827 return (addr);
828}
829
830
831/************************************************************************/
832/* ----------------- chipset specific functions ----------------------- */
833/************************************************************************/
834
835static void lcd_ctrl_init (void *lcdbase)
836{
837 volatile immap_t *immr = (immap_t *) CFG_IMMR;
838 volatile lcd823_t *lcdp = &immr->im_lcd;
839
840 uint lccrtmp;
wdenk682011f2003-06-03 23:54:09 +0000841 uint lchcr_hpc_tmp;
wdenk5b1d7132002-11-03 00:07:02 +0000842
843 /* Initialize the LCD control register according to the LCD
844 * parameters defined. We do everything here but enable
845 * the controller.
846 */
847
wdenke63c8ee2004-06-09 21:04:48 +0000848#ifdef CONFIG_RPXLITE
849 /* This is special for RPXlite_DW Software Development Platform **[Sam]** */
850 panel_info.vl_dp = CFG_LOW;
851#endif
852
wdenk5b1d7132002-11-03 00:07:02 +0000853 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
854 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
855
856 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
857 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
858 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
859 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
860 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
861 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
862 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
863 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
864 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
865 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
866
867#if 0
868 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
869 lccrtmp |= LCCR_EIEN;
870#endif
871
872 lcdp->lcd_lccr = lccrtmp;
873 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
874
875 /* Initialize LCD controller bus priorities.
876 */
wdenk682011f2003-06-03 23:54:09 +0000877#ifdef CONFIG_RBC823
878 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
879#else
wdenk5b1d7132002-11-03 00:07:02 +0000880 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
881
882 /* set SHFT/CLOCK division factor 4
883 * This needs to be set based upon display type and processor
884 * speed. The TFT displays run about 20 to 30 MHz.
885 * I was running 64 MHz processor speed.
886 * The value for this divider must be chosen so the result is
887 * an integer of the processor speed (i.e., divide by 3 with
888 * 64 MHz would be bad).
889 */
890 immr->im_clkrst.car_sccr &= ~0x1F;
891 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
892
wdenk682011f2003-06-03 23:54:09 +0000893#endif /* CONFIG_RBC823 */
894
895#if defined(CONFIG_RBC823)
896 /* Enable LCD on port D.
897 */
898 immr->im_ioport.iop_pddat &= 0x0300;
899 immr->im_ioport.iop_pdpar |= 0x1CFF;
900 immr->im_ioport.iop_pddir |= 0x1CFF;
901
902 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
903 */
904 immr->im_cpm.cp_pbdat &= ~0x00005001;
905 immr->im_cpm.cp_pbpar &= ~0x00005001;
906 immr->im_cpm.cp_pbdir |= 0x00005001;
907#elif !defined(CONFIG_EDT32F10)
wdenk5b1d7132002-11-03 00:07:02 +0000908 /* Enable LCD on port D.
909 */
910 immr->im_ioport.iop_pdpar |= 0x1FFF;
911 immr->im_ioport.iop_pddir |= 0x1FFF;
912
913 /* Enable LCD_A/B/C on port B.
914 */
915 immr->im_cpm.cp_pbpar |= 0x00005001;
916 immr->im_cpm.cp_pbdir |= 0x00005001;
917#else
918 /* Enable LCD on port D.
919 */
920 immr->im_ioport.iop_pdpar |= 0x1DFF;
921 immr->im_ioport.iop_pdpar &= ~0x0200;
922 immr->im_ioport.iop_pddir |= 0x1FFF;
923 immr->im_ioport.iop_pddat |= 0x0200;
924#endif
925
926 /* Load the physical address of the linear frame buffer
927 * into the LCD controller.
928 * BIG NOTE: This has to be modified to load A and B depending
929 * upon the split mode of the LCD.
930 */
931 lcdp->lcd_lcfaa = (ulong)lcd_base;
932 lcdp->lcd_lcfba = (ulong)lcd_base;
933
934 /* MORE HACKS...This must be updated according to 823 manual
935 * for different panels.
wdenk682011f2003-06-03 23:54:09 +0000936 * Udi Finkelstein - done - see below:
937 * Note: You better not try unsupported combinations such as
938 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
wdenk5b1d7132002-11-03 00:07:02 +0000939 */
wdenk682011f2003-06-03 23:54:09 +0000940 lchcr_hpc_tmp =
wdenk8bde7f72003-06-27 21:31:46 +0000941 (panel_info.vl_col *
wdenk682011f2003-06-03 23:54:09 +0000942 (panel_info.vl_tft ? 8 :
943 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
944 /* use << to mult by: single scan = 1, dual scan = 2 */
945 panel_info.vl_splt) *
946 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
947
wdenk5b1d7132002-11-03 00:07:02 +0000948 lcdp->lcd_lchcr = LCHCR_BO |
949 LCDBIT (LCHCR_AT_BIT, 4) |
wdenk682011f2003-06-03 23:54:09 +0000950 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
wdenk5b1d7132002-11-03 00:07:02 +0000951 panel_info.vl_wbl;
wdenk5b1d7132002-11-03 00:07:02 +0000952
953 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
954 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
955 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
956 panel_info.vl_wbf;
957
958}
959
960/*----------------------------------------------------------------------*/
961
962#ifdef NOT_USED_SO_FAR
963static void
964lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
965{
966 volatile immap_t *immr = (immap_t *) CFG_IMMR;
967 volatile cpm8xx_t *cp = &(immr->im_cpm);
968 unsigned short colreg, *cmap_ptr;
969
970 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
971
972 colreg = *cmap_ptr;
973#ifdef CFG_INVERT_COLORS
974 colreg ^= 0x0FFF;
975#endif
976
977 *red = (colreg >> 8) & 0x0F;
978 *green = (colreg >> 4) & 0x0F;
979 *blue = colreg & 0x0F;
980}
981#endif /* NOT_USED_SO_FAR */
982
983/*----------------------------------------------------------------------*/
984
985#if LCD_BPP == LCD_COLOR8
986static void
987lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
988{
989 volatile immap_t *immr = (immap_t *) CFG_IMMR;
990 volatile cpm8xx_t *cp = &(immr->im_cpm);
991 unsigned short colreg, *cmap_ptr;
992
993 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
994
995 colreg = ((red & 0x0F) << 8) |
996 ((green & 0x0F) << 4) |
997 (blue & 0x0F) ;
998#ifdef CFG_INVERT_COLORS
999 colreg ^= 0x0FFF;
1000#endif
1001 *cmap_ptr = colreg;
1002
1003 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
1004 regno, &(cp->lcd_cmap[regno * 2]),
1005 red, green, blue,
wdenk8bde7f72003-06-27 21:31:46 +00001006 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
wdenk5b1d7132002-11-03 00:07:02 +00001007}
1008#endif /* LCD_COLOR8 */
1009
1010/*----------------------------------------------------------------------*/
1011
1012#if LCD_BPP == LCD_MONOCHROME
1013static
1014void lcd_initcolregs (void)
1015{
1016 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1017 volatile cpm8xx_t *cp = &(immr->im_cpm);
1018 ushort regno;
1019
1020 for (regno = 0; regno < 16; regno++) {
1021 cp->lcd_cmap[regno * 2] = 0;
1022 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
1023 }
1024}
1025#endif
1026
1027/*----------------------------------------------------------------------*/
1028
1029static void lcd_setfgcolor (int color)
1030{
1031 lcd_color_fg = color & 0x0F;
1032}
1033
1034/*----------------------------------------------------------------------*/
1035
1036static void lcd_setbgcolor (int color)
1037{
1038 lcd_color_bg = color & 0x0F;
1039}
1040
1041/*----------------------------------------------------------------------*/
1042
1043#ifdef NOT_USED_SO_FAR
1044static int lcd_getfgcolor (void)
1045{
1046 return lcd_color_fg;
1047}
1048#endif /* NOT_USED_SO_FAR */
1049
1050/*----------------------------------------------------------------------*/
1051
1052static int lcd_getbgcolor (void)
1053{
1054 return lcd_color_bg;
1055}
1056
1057/*----------------------------------------------------------------------*/
1058
1059static void lcd_enable (void)
1060{
1061 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1062 volatile lcd823_t *lcdp = &immr->im_lcd;
1063
1064 /* Enable the LCD panel */
wdenk682011f2003-06-03 23:54:09 +00001065#ifndef CONFIG_RBC823
wdenk5b1d7132002-11-03 00:07:02 +00001066 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
wdenk682011f2003-06-03 23:54:09 +00001067#endif
wdenk5b1d7132002-11-03 00:07:02 +00001068 lcdp->lcd_lccr |= LCCR_PON;
wdenk608c9142003-01-13 23:54:46 +00001069
1070#ifdef CONFIG_V37
1071 /* Turn on display backlight */
1072 immr->im_cpm.cp_pbpar |= 0x00008000;
1073 immr->im_cpm.cp_pbdir |= 0x00008000;
wdenk682011f2003-06-03 23:54:09 +00001074#elif defined(CONFIG_RBC823)
1075 /* Turn on display backlight */
1076 immr->im_cpm.cp_pbdat |= 0x00004000;
wdenk608c9142003-01-13 23:54:46 +00001077#endif
1078
wdenk5b1d7132002-11-03 00:07:02 +00001079#if defined(CONFIG_LWMON)
1080 { uchar c = pic_read (0x60);
wdenk4532cb62003-04-27 22:52:51 +00001081#if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
wdenk7d7ce412004-03-17 01:13:07 +00001082 /* Enable LCD later in sysmon test, only if temperature is OK */
wdenk4532cb62003-04-27 22:52:51 +00001083#else
wdenk8bde7f72003-06-27 21:31:46 +00001084 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
wdenk4532cb62003-04-27 22:52:51 +00001085#endif
wdenk5b1d7132002-11-03 00:07:02 +00001086 pic_write (0x60, c);
1087 }
wdenk5b1d7132002-11-03 00:07:02 +00001088#endif /* CONFIG_LWMON */
wdenk4a6fd342003-04-12 23:38:12 +00001089
1090#if defined(CONFIG_R360MPI)
1091 {
1092 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenkcb4dbb72003-07-16 16:40:22 +00001093 unsigned long bgi, ctr;
1094 char *p;
1095
1096 if ((p = getenv("lcdbgi")) != NULL) {
1097 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1098 } else {
1099 bgi = 0xFFF;
1100 }
1101
1102 if ((p = getenv("lcdctr")) != NULL) {
1103 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1104 } else {
1105 ctr=0x7FF;
1106 }
wdenk4a6fd342003-04-12 23:38:12 +00001107
1108 r360_i2c_lcd_write(0x10, 0x01);
1109 r360_i2c_lcd_write(0x20, 0x01);
wdenkcb4dbb72003-07-16 16:40:22 +00001110 r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1111 r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
wdenk4a6fd342003-04-12 23:38:12 +00001112 }
1113#endif /* CONFIG_R360MPI */
wdenk682011f2003-06-03 23:54:09 +00001114#ifdef CONFIG_RBC823
1115 udelay(200000); /* wait 200ms */
1116 /* Turn VEE_ON first */
1117 immr->im_cpm.cp_pbdat |= 0x00000001;
1118 udelay(200000); /* wait 200ms */
1119 /* Now turn on LCD_ON */
1120 immr->im_cpm.cp_pbdat |= 0x00001000;
1121#endif
wdenk8564acf2003-07-14 22:13:32 +00001122#ifdef CONFIG_RRVISION
1123 debug ("PC4->Output(1): enable LVDS\n");
1124 debug ("PC5->Output(0): disable PAL clock\n");
1125 immr->im_ioport.iop_pddir |= 0x1000;
1126 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1127 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1128 immr->im_ioport.iop_pcdat |= 0x0800 ;
1129 immr->im_ioport.iop_pcdat &= ~(0x0400);
1130 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1131 immr->im_ioport.iop_pdpar,
1132 immr->im_ioport.iop_pddir,
1133 immr->im_ioport.iop_pddat);
1134 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1135 immr->im_ioport.iop_pcpar,
1136 immr->im_ioport.iop_pcdir,
1137 immr->im_ioport.iop_pcdat);
1138#endif
wdenk5b1d7132002-11-03 00:07:02 +00001139}
1140
1141/*----------------------------------------------------------------------*/
1142
wdenk682011f2003-06-03 23:54:09 +00001143#if defined (CONFIG_RBC823)
1144void lcd_disable (void)
wdenk5b1d7132002-11-03 00:07:02 +00001145{
1146 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1147 volatile lcd823_t *lcdp = &immr->im_lcd;
1148
1149#if defined(CONFIG_LWMON)
1150 { uchar c = pic_read (0x60);
wdenk8bde7f72003-06-27 21:31:46 +00001151 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
wdenk5b1d7132002-11-03 00:07:02 +00001152 pic_write (0x60, c);
1153 }
1154#elif defined(CONFIG_R360MPI)
1155 {
wdenk4a6fd342003-04-12 23:38:12 +00001156 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenk5b1d7132002-11-03 00:07:02 +00001157
wdenk4a6fd342003-04-12 23:38:12 +00001158 r360_i2c_lcd_write(0x10, 0x00);
1159 r360_i2c_lcd_write(0x20, 0x00);
1160 r360_i2c_lcd_write(0x30, 0x00);
1161 r360_i2c_lcd_write(0x40, 0x00);
wdenk5b1d7132002-11-03 00:07:02 +00001162 }
1163#endif /* CONFIG_LWMON */
1164 /* Disable the LCD panel */
1165 lcdp->lcd_lccr &= ~LCCR_PON;
wdenk682011f2003-06-03 23:54:09 +00001166#ifdef CONFIG_RBC823
1167 /* Turn off display backlight, VEE and LCD_ON */
1168 immr->im_cpm.cp_pbdat &= ~0x00005001;
1169#else
wdenk5b1d7132002-11-03 00:07:02 +00001170 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
wdenk682011f2003-06-03 23:54:09 +00001171#endif /* CONFIG_RBC823 */
wdenk5b1d7132002-11-03 00:07:02 +00001172}
wdenk682011f2003-06-03 23:54:09 +00001173#endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
wdenk5b1d7132002-11-03 00:07:02 +00001174
1175
1176/************************************************************************/
1177/* ** Chipset depending Bitmap / Logo stuff... */
1178/************************************************************************/
1179
1180
1181#ifdef CONFIG_LCD_LOGO
1182static void bitmap_plot (int x, int y)
1183{
1184 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1185 volatile cpm8xx_t *cp = &(immr->im_cpm);
1186 ushort *cmap;
1187 ushort i;
1188 uchar *bmap;
1189 uchar *fb;
1190
1191 debug ("Logo: width %d height %d colors %d cmap %d\n",
1192 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1193 sizeof(bmp_logo_palette)/(sizeof(ushort))
1194 );
1195
1196 /* Leave room for default color map */
1197 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1198
wdenk7aa78612003-05-03 15:50:43 +00001199 WATCHDOG_RESET();
1200
wdenk5b1d7132002-11-03 00:07:02 +00001201 /* Set color map */
1202 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1203 ushort colreg = bmp_logo_palette[i];
1204#ifdef CFG_INVERT_COLORS
1205 colreg ^= 0xFFF;
1206#endif
1207 *cmap++ = colreg;
1208 }
1209
1210 bmap = &bmp_logo_bitmap[0];
1211 fb = (char *)(lcd_base + y * lcd_line_length + x);
1212
wdenk7aa78612003-05-03 15:50:43 +00001213 WATCHDOG_RESET();
1214
wdenk5b1d7132002-11-03 00:07:02 +00001215 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1216 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1217 bmap += BMP_LOGO_WIDTH;
1218 fb += panel_info.vl_col;
1219 }
wdenk7aa78612003-05-03 15:50:43 +00001220
1221 WATCHDOG_RESET();
wdenk5b1d7132002-11-03 00:07:02 +00001222}
1223#endif /* CONFIG_LCD_LOGO */
1224
wdenk27b207f2003-07-24 23:38:38 +00001225#if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenkd791b1d2003-04-20 14:04:18 +00001226/*
wdenk824a1eb2003-04-20 16:49:37 +00001227 * Display the BMP file located at address bmp_image.
1228 * Only uncompressed
1229 */
wdenk4b248f32004-03-14 16:51:43 +00001230int lcd_display_bitmap(ulong bmp_image, int x, int y)
wdenkd791b1d2003-04-20 14:04:18 +00001231{
1232 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1233 volatile cpm8xx_t *cp = &(immr->im_cpm);
1234 ushort *cmap;
1235 ushort i, j;
1236 uchar *fb;
1237 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1238 uchar *bmap;
1239 ushort padded_line;
1240 unsigned long width, height;
1241 unsigned colors,bpix;
1242 unsigned long compression;
1243
wdenk7aa78612003-05-03 15:50:43 +00001244 WATCHDOG_RESET();
1245
wdenkd791b1d2003-04-20 14:04:18 +00001246 if (!((bmp->header.signature[0]=='B') &&
1247 (bmp->header.signature[1]=='M'))) {
1248 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1249 return 1;
1250 }
1251
1252 width = le32_to_cpu (bmp->header.width);
1253 height = le32_to_cpu (bmp->header.height);
1254 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1255 compression = le32_to_cpu (bmp->header.compression);
1256
1257 bpix = NBITS(panel_info.vl_bpix);
1258
1259 if ((bpix != 1) && (bpix != 8)) {
1260 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1261 bpix);
1262 return 1;
1263 }
1264
1265 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1266 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1267 bpix,
1268 le16_to_cpu(bmp->header.bit_count));
1269 return 1;
1270 }
1271
1272 if (compression!=BMP_BI_RGB) {
1273 printf ("Error: compression type %ld not supported\n",
1274 compression);
1275 return 1;
1276 }
1277
1278 debug ("Display-bmp: %d x %d with %d colors\n",
1279 width, height, colors);
1280
1281 if (bpix==8) {
1282 /* Fill the entire color map */
1283 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1284
1285 /* Set color map */
1286 for (i = 0; i < colors; ++i) {
1287 bmp_color_table_entry_t cte = bmp->color_table[i];
1288 ushort colreg =
1289 ((cte.red>>4) << 8) |
1290 ((cte.green>>4) << 4) |
1291 (cte.blue>>4) ;
1292#ifdef CFG_INVERT_COLORS
1293 colreg ^= 0xFFF;
1294#endif
1295 *cmap-- = colreg;
1296 }
wdenk7aa78612003-05-03 15:50:43 +00001297
1298 WATCHDOG_RESET();
wdenkd791b1d2003-04-20 14:04:18 +00001299 }
1300
1301 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
wdenk4b248f32004-03-14 16:51:43 +00001302 if ((x + width)>panel_info.vl_col)
1303 width = panel_info.vl_col - x;
1304 if ((y + height)>panel_info.vl_row)
1305 height = panel_info.vl_row - y;
wdenkd791b1d2003-04-20 14:04:18 +00001306
1307 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001308 fb = (uchar *) (lcd_base +
1309 (y + height - 1) * lcd_line_length + x);
wdenkd791b1d2003-04-20 14:04:18 +00001310 for (i = 0; i < height; ++i) {
wdenk7aa78612003-05-03 15:50:43 +00001311 WATCHDOG_RESET();
wdenkd791b1d2003-04-20 14:04:18 +00001312 for (j = 0; j < width ; j++)
1313 *(fb++)=255-*(bmap++);
1314 bmap += (width - padded_line);
1315 fb -= (width + lcd_line_length);
1316 }
1317
1318 return (0);
1319}
wdenk27b207f2003-07-24 23:38:38 +00001320#endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
wdenkd791b1d2003-04-20 14:04:18 +00001321
wdenk5b1d7132002-11-03 00:07:02 +00001322/*----------------------------------------------------------------------*/
1323
1324static void *lcd_logo (void)
1325{
1326#ifdef LCD_INFO
1327 DECLARE_GLOBAL_DATA_PTR;
1328
1329 char info[80];
1330 char temp[32];
1331#endif /* LCD_INFO */
1332
wdenkd791b1d2003-04-20 14:04:18 +00001333#ifdef CONFIG_SPLASH_SCREEN
1334 char *s;
1335 ulong addr;
1336
1337 if ((s = getenv("splashimage")) != NULL) {
1338 addr = simple_strtoul(s, NULL, 16);
1339
wdenk4b248f32004-03-14 16:51:43 +00001340 if (lcd_display_bitmap (addr, 0, 0) == 0) {
wdenkd791b1d2003-04-20 14:04:18 +00001341 return ((void *)lcd_base);
1342 }
1343 }
1344#endif /* CONFIG_SPLASH_SCREEN */
1345
wdenk5b1d7132002-11-03 00:07:02 +00001346#ifdef CONFIG_LCD_LOGO
1347 bitmap_plot (0, 0);
1348#endif /* CONFIG_LCD_LOGO */
1349
1350
1351#ifdef LCD_INFO
1352 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1353 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1354
wdenkd791b1d2003-04-20 14:04:18 +00001355 sprintf (info, "(C) 2003 DENX Software Engineering");
wdenk5b1d7132002-11-03 00:07:02 +00001356 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1357 info, strlen(info));
1358
1359 sprintf (info, " Wolfgang DENK, wd@denx.de");
1360 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1361 info, strlen(info));
1362#ifdef LCD_INFO_BELOW_LOGO
1363 sprintf (info, "MPC823 CPU at %s MHz",
1364 strmhz(temp, gd->cpu_clk));
1365 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1366 info, strlen(info));
1367 sprintf (info, " %ld MB RAM, %ld MB Flash",
1368 gd->ram_size >> 20,
1369 gd->bd->bi_flashsize >> 20 );
1370 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1371 info, strlen(info));
1372#else
1373 /* leave one blank line */
1374
1375 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1376 strmhz(temp, gd->cpu_clk),
1377 gd->ram_size >> 20,
1378 gd->bd->bi_flashsize >> 20 );
1379 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1380 info, strlen(info));
1381#endif /* LCD_INFO_BELOW_LOGO */
1382#endif /* LCD_INFO */
1383
1384#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1385 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1386#else
1387 return ((void *)lcd_base);
1388#endif /* CONFIG_LCD_LOGO */
1389}
1390
1391/************************************************************************/
1392/************************************************************************/
1393
1394#endif /* CONFIG_LCD */