blob: 1dc5f4e4b301875af0bdcfa80b09fe909b13c015 [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/*----------------------------------------------------------------------*/
wdenkfd3103b2003-11-25 16:55:19 +0000153#ifdef CONFIG_NEC_NL6448AC33
wdenk5b1d7132002-11-03 00:07:02 +0000154/*
wdenkfd3103b2003-11-25 16:55:19 +0000155 * NEC NL6448AC33-18. Active, color, single scan.
wdenk5b1d7132002-11-03 00:07:02 +0000156 */
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};
wdenkfd3103b2003-11-25 16:55:19 +0000162#endif /* CONFIG_NEC_NL6448AC33 */
wdenk5b1d7132002-11-03 00:07:02 +0000163/*----------------------------------------------------------------------*/
164
wdenkfd3103b2003-11-25 16:55:19 +0000165#ifdef CONFIG_NEC_NL6448BC20
wdenk5b1d7132002-11-03 00:07:02 +0000166/*
wdenkfd3103b2003-11-25 16:55:19 +0000167 * NEC NL6448BC20-08. 6.5", 640x480. Active, color, single scan.
wdenk5b1d7132002-11-03 00:07:02 +0000168 */
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};
wdenkfd3103b2003-11-25 16:55:19 +0000174#endif /* CONFIG_NEC_NL6448BC20 */
175/*----------------------------------------------------------------------*/
176
177#ifdef CONFIG_NEC_NL6448BC33_54
178/*
179 * NEC NL6448BC33-54. 10.4", 640x480. Active, color, single scan.
180 */
181static vidinfo_t panel_info = {
182 640, 480, 212, 158, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
183 3, 0, 0, 1, 1, 144, 2, 0, 33
184 /* wbl, vpw, lcdac, wbf */
185};
186#endif /* CONFIG_NEC_NL6448BC33_54 */
wdenk5b1d7132002-11-03 00:07:02 +0000187/*----------------------------------------------------------------------*/
188
189#ifdef CONFIG_SHARP_LQ104V7DS01
190/*
191 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
192 */
193static vidinfo_t panel_info = {
194 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
195 3, 0, 0, 1, 1, 25, 1, 0, 33
196 /* wbl, vpw, lcdac, wbf */
197};
198#endif /* CONFIG_SHARP_LQ104V7DS01 */
199/*----------------------------------------------------------------------*/
200
201#ifdef CONFIG_SHARP_16x9
202/*
203 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
204 * not sure what it is.......
205 */
206static vidinfo_t panel_info = {
207 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
208 3, 0, 0, 1, 1, 15, 4, 0, 3
209};
210#endif /* CONFIG_SHARP_16x9 */
211/*----------------------------------------------------------------------*/
212
213#ifdef CONFIG_SHARP_LQ057Q3DC02
214/*
215 * Sharp LQ057Q3DC02 display. Active, color, single scan.
216 */
wdenk4a6fd342003-04-12 23:38:12 +0000217#define LCD_DF 12
218
wdenk5b1d7132002-11-03 00:07:02 +0000219static vidinfo_t panel_info = {
220 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
221 3, 0, 0, 1, 1, 15, 4, 0, 3
222 /* wbl, vpw, lcdac, wbf */
223};
224#define LCD_INFO_BELOW_LOGO
225#endif /* CONFIG_SHARP_LQ057Q3DC02 */
226/*----------------------------------------------------------------------*/
227
228#ifdef CONFIG_SHARP_LQ64D341
229/*
230 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
231 */
232static vidinfo_t panel_info = {
233 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
234 3, 0, 0, 1, 1, 128, 16, 0, 32
235 /* wbl, vpw, lcdac, wbf */
236};
237#endif /* CONFIG_SHARP_LQ64D341 */
wdenk608c9142003-01-13 23:54:46 +0000238
dzu29127b62003-09-25 22:30:12 +0000239#ifdef CONFIG_SHARP_LQ065T9DR51U
240/*
241 * Sharp LQ065T9DR51U display, 400x240. Active, color, single scan.
242 */
243static vidinfo_t panel_info = {
244 400, 240, 143, 79, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
245 3, 0, 0, 1, 1, 248, 4, 0, 35
246 /* wbl, vpw, lcdac, wbf */
247};
248#define LCD_INFO_BELOW_LOGO
249#endif /* CONFIG_SHARP_LQ065T9DR51U */
250
wdenk608c9142003-01-13 23:54:46 +0000251#ifdef CONFIG_SHARP_LQ084V1DG21
252/*
253 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
254 */
255static vidinfo_t panel_info = {
256 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
257 3, 0, 0, 1, 1, 160, 3, 0, 48
258 /* wbl, vpw, lcdac, wbf */
259};
260#endif /* CONFIG_SHARP_LQ084V1DG21 */
261
wdenk5b1d7132002-11-03 00:07:02 +0000262/*----------------------------------------------------------------------*/
263
264#ifdef CONFIG_HLD1045
265/*
266 * HLD1045 display, 640x480. Active, color, single scan.
267 */
268static vidinfo_t panel_info = {
269 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
270 3, 0, 0, 1, 1, 160, 3, 0, 48
271 /* wbl, vpw, lcdac, wbf */
272};
273#endif /* CONFIG_HLD1045 */
274/*----------------------------------------------------------------------*/
275
276#ifdef CONFIG_PRIMEVIEW_V16C6448AC
277/*
278 * Prime View V16C6448AC
279 */
280static vidinfo_t panel_info = {
281 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
282 3, 0, 0, 1, 1, 144, 2, 0, 35
283 /* wbl, vpw, lcdac, wbf */
284};
285#endif /* CONFIG_PRIMEVIEW_V16C6448AC */
286
287/*----------------------------------------------------------------------*/
288
289#ifdef CONFIG_OPTREX_BW
290/*
291 * Optrex CBL50840-2 NF-FW 99 22 M5
292 * or
293 * Hitachi LMG6912RPFC-00T
294 * or
295 * Hitachi SP14Q002
296 *
297 * 320x240. Black & white.
298 */
299#define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
300 /* 1 - 4 grey levels, 2 bpp */
301 /* 2 - 16 grey levels, 4 bpp */
302static vidinfo_t panel_info = {
303 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
304 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
305};
306#endif /* CONFIG_OPTREX_BW */
307
308/*-----------------------------------------------------------------*/
309#ifdef CONFIG_EDT32F10
310/*
311 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
312 */
313#define LCD_BPP LCD_MONOCHROME
wdenk4a6fd342003-04-12 23:38:12 +0000314#define LCD_DF 10
wdenk5b1d7132002-11-03 00:07:02 +0000315
316static vidinfo_t panel_info = {
317 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
wdenk4a6fd342003-04-12 23:38:12 +0000318 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
wdenk5b1d7132002-11-03 00:07:02 +0000319};
320#endif
321/*----------------------------------------------------------------------*/
322
323#if defined(LCD_INFO_BELOW_LOGO)
324# define LCD_INFO_X 0
325# define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
326#elif defined(CONFIG_LCD_LOGO)
327# define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
328# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
329#else
330# define LCD_INFO_X (VIDEO_FONT_WIDTH)
331# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
332#endif
333
334#ifndef LCD_BPP
335#define LCD_BPP LCD_COLOR8
336#endif
337#ifndef LCD_DF
338#define LCD_DF 1
339#endif
340
341#define NBITS(bit_code) (1 << (bit_code))
342#define NCOLORS(bit_code) (1 << NBITS(bit_code))
343
344static int lcd_line_length;
345
346static int lcd_color_fg;
347static int lcd_color_bg;
348
wdenk682011f2003-06-03 23:54:09 +0000349char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
wdenk5b1d7132002-11-03 00:07:02 +0000350
351/*
352 * Frame buffer memory information
353 */
354static void *lcd_base; /* Start of framebuffer memory */
355static void *lcd_console_address; /* Start of console buffer */
356
357
358/************************************************************************/
359/* ** CONSOLE CONSTANTS */
360/************************************************************************/
361
362#if LCD_BPP == LCD_MONOCHROME
363
364/*
365 * Simple color definitions
366 */
367#define CONSOLE_COLOR_BLACK 0
368#define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
369
370#else
371
372/*
373 * Simple color definitions
374 */
375#define CONSOLE_COLOR_BLACK 0
376#define CONSOLE_COLOR_RED 1
377#define CONSOLE_COLOR_GREEN 2
378#define CONSOLE_COLOR_YELLOW 3
379#define CONSOLE_COLOR_BLUE 4
380#define CONSOLE_COLOR_MAGENTA 5
381#define CONSOLE_COLOR_CYAN 6
382#define CONSOLE_COLOR_GREY 14
383#define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
384
385#endif
386
387#if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
388#error Default Color Map overlaps with Logo Color Map
389#endif
390
391/************************************************************************/
392
393#ifndef PAGE_SIZE
394#define PAGE_SIZE 4096
395#endif
396
397
398/************************************************************************/
399/* ** CONSOLE DEFINITIONS & FUNCTIONS */
400/************************************************************************/
401
402#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
403#define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
404 / VIDEO_FONT_HEIGHT)
405#else
406#define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
407#endif
408#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
409#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
410#define CONSOLE_ROW_FIRST (lcd_console_address)
411#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
412#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
413 - CONSOLE_ROW_SIZE)
414#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
415#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
416
417#if LCD_BPP == LCD_MONOCHROME
418#define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
419 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
420#elif LCD_BPP == LCD_COLOR8
421#define COLOR_MASK(c) (c)
422#else
423#error Unsupported LCD BPP.
424#endif
425
426static short console_col;
427static short console_row;
428
429/************************************************************************/
430
431ulong lcd_setmem (ulong addr);
432
433static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
434static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
435static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
436
wdenk682011f2003-06-03 23:54:09 +0000437int lcd_init (void *lcdbase);
438
wdenk5b1d7132002-11-03 00:07:02 +0000439static void lcd_ctrl_init (void *lcdbase);
440static void lcd_enable (void);
441static void *lcd_logo (void);
442#if LCD_BPP == LCD_COLOR8
443static void lcd_setcolreg (ushort regno,
444 ushort red, ushort green, ushort blue);
445#endif
446#if LCD_BPP == LCD_MONOCHROME
447static void lcd_initcolregs (void);
448#endif
449static int lcd_getbgcolor (void);
450static void lcd_setfgcolor (int color);
451static void lcd_setbgcolor (int color);
452
wdenk682011f2003-06-03 23:54:09 +0000453#if defined(CONFIG_RBC823)
454void lcd_disable (void);
455#endif
456
wdenk5b1d7132002-11-03 00:07:02 +0000457#ifdef NOT_USED_SO_FAR
wdenk5b1d7132002-11-03 00:07:02 +0000458static void lcd_getcolreg (ushort regno,
459 ushort *red, ushort *green, ushort *blue);
460static int lcd_getfgcolor (void);
461#endif /* NOT_USED_SO_FAR */
462
463/************************************************************************/
464
465/*----------------------------------------------------------------------*/
466
467static void console_scrollup (void)
468{
469#if 1
470 /* Copy up rows ignoring the first one */
471 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
472
473 /* Clear the last one */
474 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
475#else
476 /*
477 * Poor attempt to optimize speed by moving "long"s.
478 * But the code is ugly, and not a bit faster :-(
479 */
480 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
481 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
482 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
483 uchar c = lcd_color_bg & 0xFF;
484 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
485
486 while (l--)
487 *t++ = *s++;
488
489 t = (ulong *)CONSOLE_ROW_LAST;
490 l = CONSOLE_ROW_SIZE / sizeof(ulong);
491
492 while (l-- > 0)
493 *t++ = val;
494#endif
495}
496
497/*----------------------------------------------------------------------*/
498
499static inline void console_back (void)
500{
501 if (--console_col < 0) {
502 console_col = CONSOLE_COLS-1 ;
503 if (--console_row < 0) {
504 console_row = 0;
505 }
506 }
507
508 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
509 console_row * VIDEO_FONT_HEIGHT,
510 ' ');
511}
512
513/*----------------------------------------------------------------------*/
514
515static inline void console_newline (void)
516{
517 ++console_row;
518 console_col = 0;
519
520 /* Check if we need to scroll the terminal */
521 if (console_row >= CONSOLE_ROWS) {
522 /* Scroll everything up */
523 console_scrollup () ;
524 --console_row;
525 }
526}
527
528/*----------------------------------------------------------------------*/
529
530void lcd_putc (const char c)
531{
532 if (!lcd_is_enabled) {
533 serial_putc(c);
534 return;
535 }
536
537 switch (c) {
538 case '\r': console_col = 0;
539 return;
540
541 case '\n': console_newline();
542 return;
543
544 case '\t': /* Tab (8 chars alignment) */
545 console_col |= 8;
546 console_col &= ~7;
547
548 if (console_col >= CONSOLE_COLS) {
549 console_newline();
550 }
551 return;
552
553 case '\b': console_back();
554 return;
555
556 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
557 console_row * VIDEO_FONT_HEIGHT,
558 c);
559 if (++console_col >= CONSOLE_COLS) {
560 console_newline();
561 }
562 return;
563 }
564 /* NOTREACHED */
565}
566
567/*----------------------------------------------------------------------*/
568
569void lcd_puts (const char *s)
570{
571 if (!lcd_is_enabled) {
572 serial_puts (s);
573 return;
574 }
575
576 while (*s) {
577 lcd_putc (*s++);
578 }
579}
580
581/************************************************************************/
582/* ** Low-Level Graphics Routines */
583/************************************************************************/
584
585static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
586{
587 uchar *dest;
588 ushort off, row;
589
590 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
591 off = x * (1 << LCD_BPP) % 8;
592
593 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
594 uchar *s = str;
595 uchar *d = dest;
596 int i;
597
598#if LCD_BPP == LCD_MONOCHROME
599 uchar rest = *d & -(1 << (8-off));
600 uchar sym;
601#endif
602 for (i=0; i<count; ++i) {
603 uchar c, bits;
604
605 c = *s++;
606 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
607
608#if LCD_BPP == LCD_MONOCHROME
609 sym = (COLOR_MASK(lcd_color_fg) & bits) |
610 (COLOR_MASK(lcd_color_bg) & ~bits);
611
612 *d++ = rest | (sym >> off);
613 rest = sym << (8-off);
614#elif LCD_BPP == LCD_COLOR8
615 for (c=0; c<8; ++c) {
616 *d++ = (bits & 0x80) ?
617 lcd_color_fg : lcd_color_bg;
618 bits <<= 1;
619 }
620#endif
621 }
622
623#if LCD_BPP == LCD_MONOCHROME
624 *d = rest | (*d & ((1 << (8-off)) - 1));
625#endif
626 }
627}
628
629/*----------------------------------------------------------------------*/
630
631static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
632{
633#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
634 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
635#else
636 lcd_drawchars (x, y, s, strlen (s));
637#endif
638}
639
640/*----------------------------------------------------------------------*/
641
642static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
643{
644#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
645 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
646#else
647 lcd_drawchars (x, y, &c, 1);
648#endif
649}
650
651/************************************************************************/
652/** Small utility to check that you got the colours right */
653/************************************************************************/
654#ifdef LCD_TEST_PATTERN
655
656#define N_BLK_VERT 2
657#define N_BLK_HOR 3
658
659static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
660 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
661 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
662};
663
664static void test_pattern (void)
665{
666 ushort v_max = panel_info.vl_row;
667 ushort h_max = panel_info.vl_col;
668 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
669 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
670 ushort v, h;
671 uchar *pix = (uchar *)lcd_base;
672
673 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
674 h_max, v_max, h_step, v_step);
675
676 /* WARNING: Code silently assumes 8bit/pixel */
677 for (v=0; v<v_max; ++v) {
678 uchar iy = v / v_step;
679 for (h=0; h<h_max; ++h) {
680 uchar ix = N_BLK_HOR * iy + (h/h_step);
681 *pix++ = test_colors[ix];
682 }
683 }
684}
685#endif /* LCD_TEST_PATTERN */
686
687
688/************************************************************************/
689/* ** GENERIC Initialization Routines */
690/************************************************************************/
691
692int drv_lcd_init (void)
693{
694 DECLARE_GLOBAL_DATA_PTR;
695
696 device_t lcddev;
697 int rc;
698
699 lcd_base = (void *)(gd->fb_base);
700
701 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
702
703 lcd_init (lcd_base); /* LCD initialization */
704
705 /* Device initialization */
706 memset (&lcddev, 0, sizeof (lcddev));
707
708 strcpy (lcddev.name, "lcd");
709 lcddev.ext = 0; /* No extensions */
710 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
711 lcddev.putc = lcd_putc; /* 'putc' function */
712 lcddev.puts = lcd_puts; /* 'puts' function */
713
714 rc = device_register (&lcddev);
715
716 return (rc == 0) ? 1 : rc;
717}
718
719/*----------------------------------------------------------------------*/
720
wdenk682011f2003-06-03 23:54:09 +0000721int lcd_init (void *lcdbase)
wdenk5b1d7132002-11-03 00:07:02 +0000722{
723 /* Initialize the lcd controller */
724 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
725
726 lcd_ctrl_init (lcdbase);
727
728#if LCD_BPP == LCD_MONOCHROME
729 /* Setting the palette */
730 lcd_initcolregs();
731
732#elif LCD_BPP == LCD_COLOR8
733 /* Setting the palette */
734 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
735 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
736 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
737 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
738 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
739 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
740 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
741 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
742 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
743#endif
744
745#ifndef CFG_WHITE_ON_BLACK
746 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
747 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
748#else
749 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
750 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
751#endif /* CFG_WHITE_ON_BLACK */
752
753#ifdef LCD_TEST_PATTERN
754 test_pattern();
755#else
756 /* set framebuffer to background color */
757 memset ((char *)lcd_base,
758 COLOR_MASK(lcd_getbgcolor()),
759 lcd_line_length*panel_info.vl_row);
760#endif
761
762 lcd_enable ();
763
764 /* Paint the logo and retrieve LCD base address */
765 debug ("[LCD] Drawing the logo...\n");
766 lcd_console_address = lcd_logo ();
767
768 /* Initialize the console */
769 console_col = 0;
770#ifdef LCD_INFO_BELOW_LOGO
771 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
772#else
773 console_row = 1; /* leave 1 blank line below logo */
774#endif
775 lcd_is_enabled = 1;
776
777 return 0;
778}
779
780
781/************************************************************************/
782/* ** ROM capable initialization part - needed to reserve FB memory */
783/************************************************************************/
784
785/*
786 * This is called early in the system initialization to grab memory
787 * for the LCD controller.
788 * Returns new address for monitor, after reserving LCD buffer memory
789 *
790 * Note that this is running from ROM, so no write access to global data.
791 */
792ulong lcd_setmem (ulong addr)
793{
794 ulong size;
795 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
796
797 debug ("LCD panel info: %d x %d, %d bit/pix\n",
798 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
799
800 size = line_length * panel_info.vl_row;
801
802 /* Round up to nearest full page */
803 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
804
805 /* Allocate pages for the frame buffer. */
806 addr -= size;
807
808 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
809
810 return (addr);
811}
812
813
814/************************************************************************/
815/* ----------------- chipset specific functions ----------------------- */
816/************************************************************************/
817
818static void lcd_ctrl_init (void *lcdbase)
819{
820 volatile immap_t *immr = (immap_t *) CFG_IMMR;
821 volatile lcd823_t *lcdp = &immr->im_lcd;
822
823 uint lccrtmp;
wdenk682011f2003-06-03 23:54:09 +0000824 uint lchcr_hpc_tmp;
wdenk5b1d7132002-11-03 00:07:02 +0000825
826 /* Initialize the LCD control register according to the LCD
827 * parameters defined. We do everything here but enable
828 * the controller.
829 */
830
wdenke63c8ee2004-06-09 21:04:48 +0000831#ifdef CONFIG_RPXLITE
832 /* This is special for RPXlite_DW Software Development Platform **[Sam]** */
833 panel_info.vl_dp = CFG_LOW;
834#endif
835
wdenk5b1d7132002-11-03 00:07:02 +0000836 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
837 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
838
839 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
840 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
841 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
842 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
843 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
844 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
845 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
846 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
847 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
848 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
849
850#if 0
851 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
852 lccrtmp |= LCCR_EIEN;
853#endif
854
855 lcdp->lcd_lccr = lccrtmp;
856 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
857
858 /* Initialize LCD controller bus priorities.
859 */
wdenk682011f2003-06-03 23:54:09 +0000860#ifdef CONFIG_RBC823
861 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
862#else
wdenk5b1d7132002-11-03 00:07:02 +0000863 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
864
865 /* set SHFT/CLOCK division factor 4
866 * This needs to be set based upon display type and processor
867 * speed. The TFT displays run about 20 to 30 MHz.
868 * I was running 64 MHz processor speed.
869 * The value for this divider must be chosen so the result is
870 * an integer of the processor speed (i.e., divide by 3 with
871 * 64 MHz would be bad).
872 */
873 immr->im_clkrst.car_sccr &= ~0x1F;
874 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
875
wdenk682011f2003-06-03 23:54:09 +0000876#endif /* CONFIG_RBC823 */
877
878#if defined(CONFIG_RBC823)
879 /* Enable LCD on port D.
880 */
881 immr->im_ioport.iop_pddat &= 0x0300;
882 immr->im_ioport.iop_pdpar |= 0x1CFF;
883 immr->im_ioport.iop_pddir |= 0x1CFF;
884
885 /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
886 */
887 immr->im_cpm.cp_pbdat &= ~0x00005001;
888 immr->im_cpm.cp_pbpar &= ~0x00005001;
889 immr->im_cpm.cp_pbdir |= 0x00005001;
890#elif !defined(CONFIG_EDT32F10)
wdenk5b1d7132002-11-03 00:07:02 +0000891 /* Enable LCD on port D.
892 */
893 immr->im_ioport.iop_pdpar |= 0x1FFF;
894 immr->im_ioport.iop_pddir |= 0x1FFF;
895
896 /* Enable LCD_A/B/C on port B.
897 */
898 immr->im_cpm.cp_pbpar |= 0x00005001;
899 immr->im_cpm.cp_pbdir |= 0x00005001;
900#else
901 /* Enable LCD on port D.
902 */
903 immr->im_ioport.iop_pdpar |= 0x1DFF;
904 immr->im_ioport.iop_pdpar &= ~0x0200;
905 immr->im_ioport.iop_pddir |= 0x1FFF;
906 immr->im_ioport.iop_pddat |= 0x0200;
907#endif
908
909 /* Load the physical address of the linear frame buffer
910 * into the LCD controller.
911 * BIG NOTE: This has to be modified to load A and B depending
912 * upon the split mode of the LCD.
913 */
914 lcdp->lcd_lcfaa = (ulong)lcd_base;
915 lcdp->lcd_lcfba = (ulong)lcd_base;
916
917 /* MORE HACKS...This must be updated according to 823 manual
918 * for different panels.
wdenk682011f2003-06-03 23:54:09 +0000919 * Udi Finkelstein - done - see below:
920 * Note: You better not try unsupported combinations such as
921 * 4-bit wide passive dual scan LCD at 4/8 Bit color.
wdenk5b1d7132002-11-03 00:07:02 +0000922 */
wdenk682011f2003-06-03 23:54:09 +0000923 lchcr_hpc_tmp =
wdenk8bde7f72003-06-27 21:31:46 +0000924 (panel_info.vl_col *
wdenk682011f2003-06-03 23:54:09 +0000925 (panel_info.vl_tft ? 8 :
926 (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
927 /* use << to mult by: single scan = 1, dual scan = 2 */
928 panel_info.vl_splt) *
929 (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
930
wdenk5b1d7132002-11-03 00:07:02 +0000931 lcdp->lcd_lchcr = LCHCR_BO |
932 LCDBIT (LCHCR_AT_BIT, 4) |
wdenk682011f2003-06-03 23:54:09 +0000933 LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
wdenk5b1d7132002-11-03 00:07:02 +0000934 panel_info.vl_wbl;
wdenk5b1d7132002-11-03 00:07:02 +0000935
936 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
937 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
938 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
939 panel_info.vl_wbf;
940
941}
942
943/*----------------------------------------------------------------------*/
944
945#ifdef NOT_USED_SO_FAR
946static void
947lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
948{
949 volatile immap_t *immr = (immap_t *) CFG_IMMR;
950 volatile cpm8xx_t *cp = &(immr->im_cpm);
951 unsigned short colreg, *cmap_ptr;
952
953 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
954
955 colreg = *cmap_ptr;
956#ifdef CFG_INVERT_COLORS
957 colreg ^= 0x0FFF;
958#endif
959
960 *red = (colreg >> 8) & 0x0F;
961 *green = (colreg >> 4) & 0x0F;
962 *blue = colreg & 0x0F;
963}
964#endif /* NOT_USED_SO_FAR */
965
966/*----------------------------------------------------------------------*/
967
968#if LCD_BPP == LCD_COLOR8
969static void
970lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
971{
972 volatile immap_t *immr = (immap_t *) CFG_IMMR;
973 volatile cpm8xx_t *cp = &(immr->im_cpm);
974 unsigned short colreg, *cmap_ptr;
975
976 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
977
978 colreg = ((red & 0x0F) << 8) |
979 ((green & 0x0F) << 4) |
980 (blue & 0x0F) ;
981#ifdef CFG_INVERT_COLORS
982 colreg ^= 0x0FFF;
983#endif
984 *cmap_ptr = colreg;
985
986 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
987 regno, &(cp->lcd_cmap[regno * 2]),
988 red, green, blue,
wdenk8bde7f72003-06-27 21:31:46 +0000989 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
wdenk5b1d7132002-11-03 00:07:02 +0000990}
991#endif /* LCD_COLOR8 */
992
993/*----------------------------------------------------------------------*/
994
995#if LCD_BPP == LCD_MONOCHROME
996static
997void lcd_initcolregs (void)
998{
999 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1000 volatile cpm8xx_t *cp = &(immr->im_cpm);
1001 ushort regno;
1002
1003 for (regno = 0; regno < 16; regno++) {
1004 cp->lcd_cmap[regno * 2] = 0;
1005 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
1006 }
1007}
1008#endif
1009
1010/*----------------------------------------------------------------------*/
1011
1012static void lcd_setfgcolor (int color)
1013{
1014 lcd_color_fg = color & 0x0F;
1015}
1016
1017/*----------------------------------------------------------------------*/
1018
1019static void lcd_setbgcolor (int color)
1020{
1021 lcd_color_bg = color & 0x0F;
1022}
1023
1024/*----------------------------------------------------------------------*/
1025
1026#ifdef NOT_USED_SO_FAR
1027static int lcd_getfgcolor (void)
1028{
1029 return lcd_color_fg;
1030}
1031#endif /* NOT_USED_SO_FAR */
1032
1033/*----------------------------------------------------------------------*/
1034
1035static int lcd_getbgcolor (void)
1036{
1037 return lcd_color_bg;
1038}
1039
1040/*----------------------------------------------------------------------*/
1041
1042static void lcd_enable (void)
1043{
1044 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1045 volatile lcd823_t *lcdp = &immr->im_lcd;
1046
1047 /* Enable the LCD panel */
wdenk682011f2003-06-03 23:54:09 +00001048#ifndef CONFIG_RBC823
wdenk5b1d7132002-11-03 00:07:02 +00001049 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
wdenk682011f2003-06-03 23:54:09 +00001050#endif
wdenk5b1d7132002-11-03 00:07:02 +00001051 lcdp->lcd_lccr |= LCCR_PON;
wdenk608c9142003-01-13 23:54:46 +00001052
1053#ifdef CONFIG_V37
1054 /* Turn on display backlight */
1055 immr->im_cpm.cp_pbpar |= 0x00008000;
1056 immr->im_cpm.cp_pbdir |= 0x00008000;
wdenk682011f2003-06-03 23:54:09 +00001057#elif defined(CONFIG_RBC823)
1058 /* Turn on display backlight */
1059 immr->im_cpm.cp_pbdat |= 0x00004000;
wdenk608c9142003-01-13 23:54:46 +00001060#endif
1061
wdenk5b1d7132002-11-03 00:07:02 +00001062#if defined(CONFIG_LWMON)
1063 { uchar c = pic_read (0x60);
wdenk4532cb62003-04-27 22:52:51 +00001064#if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
wdenk7d7ce412004-03-17 01:13:07 +00001065 /* Enable LCD later in sysmon test, only if temperature is OK */
wdenk4532cb62003-04-27 22:52:51 +00001066#else
wdenk8bde7f72003-06-27 21:31:46 +00001067 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
wdenk4532cb62003-04-27 22:52:51 +00001068#endif
wdenk5b1d7132002-11-03 00:07:02 +00001069 pic_write (0x60, c);
1070 }
wdenk5b1d7132002-11-03 00:07:02 +00001071#endif /* CONFIG_LWMON */
wdenk4a6fd342003-04-12 23:38:12 +00001072
1073#if defined(CONFIG_R360MPI)
1074 {
1075 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenkcb4dbb72003-07-16 16:40:22 +00001076 unsigned long bgi, ctr;
1077 char *p;
1078
1079 if ((p = getenv("lcdbgi")) != NULL) {
1080 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1081 } else {
1082 bgi = 0xFFF;
1083 }
1084
1085 if ((p = getenv("lcdctr")) != NULL) {
1086 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1087 } else {
1088 ctr=0x7FF;
1089 }
wdenk4a6fd342003-04-12 23:38:12 +00001090
1091 r360_i2c_lcd_write(0x10, 0x01);
1092 r360_i2c_lcd_write(0x20, 0x01);
wdenkcb4dbb72003-07-16 16:40:22 +00001093 r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1094 r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
wdenk4a6fd342003-04-12 23:38:12 +00001095 }
1096#endif /* CONFIG_R360MPI */
wdenk682011f2003-06-03 23:54:09 +00001097#ifdef CONFIG_RBC823
1098 udelay(200000); /* wait 200ms */
1099 /* Turn VEE_ON first */
1100 immr->im_cpm.cp_pbdat |= 0x00000001;
1101 udelay(200000); /* wait 200ms */
1102 /* Now turn on LCD_ON */
1103 immr->im_cpm.cp_pbdat |= 0x00001000;
1104#endif
wdenk8564acf2003-07-14 22:13:32 +00001105#ifdef CONFIG_RRVISION
1106 debug ("PC4->Output(1): enable LVDS\n");
1107 debug ("PC5->Output(0): disable PAL clock\n");
1108 immr->im_ioport.iop_pddir |= 0x1000;
1109 immr->im_ioport.iop_pcpar &= ~(0x0C00);
1110 immr->im_ioport.iop_pcdir |= 0x0C00 ;
1111 immr->im_ioport.iop_pcdat |= 0x0800 ;
1112 immr->im_ioport.iop_pcdat &= ~(0x0400);
1113 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1114 immr->im_ioport.iop_pdpar,
1115 immr->im_ioport.iop_pddir,
1116 immr->im_ioport.iop_pddat);
1117 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1118 immr->im_ioport.iop_pcpar,
1119 immr->im_ioport.iop_pcdir,
1120 immr->im_ioport.iop_pcdat);
1121#endif
wdenk5b1d7132002-11-03 00:07:02 +00001122}
1123
1124/*----------------------------------------------------------------------*/
1125
wdenk682011f2003-06-03 23:54:09 +00001126#if defined (CONFIG_RBC823)
1127void lcd_disable (void)
wdenk5b1d7132002-11-03 00:07:02 +00001128{
1129 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1130 volatile lcd823_t *lcdp = &immr->im_lcd;
1131
1132#if defined(CONFIG_LWMON)
1133 { uchar c = pic_read (0x60);
wdenk8bde7f72003-06-27 21:31:46 +00001134 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
wdenk5b1d7132002-11-03 00:07:02 +00001135 pic_write (0x60, c);
1136 }
1137#elif defined(CONFIG_R360MPI)
1138 {
wdenk4a6fd342003-04-12 23:38:12 +00001139 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenk5b1d7132002-11-03 00:07:02 +00001140
wdenk4a6fd342003-04-12 23:38:12 +00001141 r360_i2c_lcd_write(0x10, 0x00);
1142 r360_i2c_lcd_write(0x20, 0x00);
1143 r360_i2c_lcd_write(0x30, 0x00);
1144 r360_i2c_lcd_write(0x40, 0x00);
wdenk5b1d7132002-11-03 00:07:02 +00001145 }
1146#endif /* CONFIG_LWMON */
1147 /* Disable the LCD panel */
1148 lcdp->lcd_lccr &= ~LCCR_PON;
wdenk682011f2003-06-03 23:54:09 +00001149#ifdef CONFIG_RBC823
1150 /* Turn off display backlight, VEE and LCD_ON */
1151 immr->im_cpm.cp_pbdat &= ~0x00005001;
1152#else
wdenk5b1d7132002-11-03 00:07:02 +00001153 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
wdenk682011f2003-06-03 23:54:09 +00001154#endif /* CONFIG_RBC823 */
wdenk5b1d7132002-11-03 00:07:02 +00001155}
wdenk682011f2003-06-03 23:54:09 +00001156#endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
wdenk5b1d7132002-11-03 00:07:02 +00001157
1158
1159/************************************************************************/
1160/* ** Chipset depending Bitmap / Logo stuff... */
1161/************************************************************************/
1162
1163
1164#ifdef CONFIG_LCD_LOGO
1165static void bitmap_plot (int x, int y)
1166{
1167 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1168 volatile cpm8xx_t *cp = &(immr->im_cpm);
1169 ushort *cmap;
1170 ushort i;
1171 uchar *bmap;
1172 uchar *fb;
1173
1174 debug ("Logo: width %d height %d colors %d cmap %d\n",
1175 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1176 sizeof(bmp_logo_palette)/(sizeof(ushort))
1177 );
1178
1179 /* Leave room for default color map */
1180 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1181
wdenk7aa78612003-05-03 15:50:43 +00001182 WATCHDOG_RESET();
1183
wdenk5b1d7132002-11-03 00:07:02 +00001184 /* Set color map */
1185 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1186 ushort colreg = bmp_logo_palette[i];
1187#ifdef CFG_INVERT_COLORS
1188 colreg ^= 0xFFF;
1189#endif
1190 *cmap++ = colreg;
1191 }
1192
1193 bmap = &bmp_logo_bitmap[0];
1194 fb = (char *)(lcd_base + y * lcd_line_length + x);
1195
wdenk7aa78612003-05-03 15:50:43 +00001196 WATCHDOG_RESET();
1197
wdenk5b1d7132002-11-03 00:07:02 +00001198 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1199 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1200 bmap += BMP_LOGO_WIDTH;
1201 fb += panel_info.vl_col;
1202 }
wdenk7aa78612003-05-03 15:50:43 +00001203
1204 WATCHDOG_RESET();
wdenk5b1d7132002-11-03 00:07:02 +00001205}
1206#endif /* CONFIG_LCD_LOGO */
1207
wdenk27b207f2003-07-24 23:38:38 +00001208#if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenkd791b1d2003-04-20 14:04:18 +00001209/*
wdenk824a1eb2003-04-20 16:49:37 +00001210 * Display the BMP file located at address bmp_image.
1211 * Only uncompressed
1212 */
wdenk4b248f32004-03-14 16:51:43 +00001213int lcd_display_bitmap(ulong bmp_image, int x, int y)
wdenkd791b1d2003-04-20 14:04:18 +00001214{
1215 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1216 volatile cpm8xx_t *cp = &(immr->im_cpm);
1217 ushort *cmap;
1218 ushort i, j;
1219 uchar *fb;
1220 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1221 uchar *bmap;
1222 ushort padded_line;
1223 unsigned long width, height;
1224 unsigned colors,bpix;
1225 unsigned long compression;
1226
wdenk7aa78612003-05-03 15:50:43 +00001227 WATCHDOG_RESET();
1228
wdenkd791b1d2003-04-20 14:04:18 +00001229 if (!((bmp->header.signature[0]=='B') &&
1230 (bmp->header.signature[1]=='M'))) {
1231 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1232 return 1;
1233 }
1234
1235 width = le32_to_cpu (bmp->header.width);
1236 height = le32_to_cpu (bmp->header.height);
1237 colors = 1<<le16_to_cpu (bmp->header.bit_count);
1238 compression = le32_to_cpu (bmp->header.compression);
1239
1240 bpix = NBITS(panel_info.vl_bpix);
1241
1242 if ((bpix != 1) && (bpix != 8)) {
1243 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1244 bpix);
1245 return 1;
1246 }
1247
1248 if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1249 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1250 bpix,
1251 le16_to_cpu(bmp->header.bit_count));
1252 return 1;
1253 }
1254
1255 if (compression!=BMP_BI_RGB) {
1256 printf ("Error: compression type %ld not supported\n",
1257 compression);
1258 return 1;
1259 }
1260
1261 debug ("Display-bmp: %d x %d with %d colors\n",
1262 width, height, colors);
1263
1264 if (bpix==8) {
1265 /* Fill the entire color map */
1266 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1267
1268 /* Set color map */
1269 for (i = 0; i < colors; ++i) {
1270 bmp_color_table_entry_t cte = bmp->color_table[i];
1271 ushort colreg =
1272 ((cte.red>>4) << 8) |
1273 ((cte.green>>4) << 4) |
1274 (cte.blue>>4) ;
1275#ifdef CFG_INVERT_COLORS
1276 colreg ^= 0xFFF;
1277#endif
1278 *cmap-- = colreg;
1279 }
wdenk7aa78612003-05-03 15:50:43 +00001280
1281 WATCHDOG_RESET();
wdenkd791b1d2003-04-20 14:04:18 +00001282 }
1283
1284 padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
wdenk4b248f32004-03-14 16:51:43 +00001285 if ((x + width)>panel_info.vl_col)
1286 width = panel_info.vl_col - x;
1287 if ((y + height)>panel_info.vl_row)
1288 height = panel_info.vl_row - y;
wdenkd791b1d2003-04-20 14:04:18 +00001289
1290 bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001291 fb = (uchar *) (lcd_base +
1292 (y + height - 1) * lcd_line_length + x);
wdenkd791b1d2003-04-20 14:04:18 +00001293 for (i = 0; i < height; ++i) {
wdenk7aa78612003-05-03 15:50:43 +00001294 WATCHDOG_RESET();
wdenkd791b1d2003-04-20 14:04:18 +00001295 for (j = 0; j < width ; j++)
1296 *(fb++)=255-*(bmap++);
1297 bmap += (width - padded_line);
1298 fb -= (width + lcd_line_length);
1299 }
1300
1301 return (0);
1302}
wdenk27b207f2003-07-24 23:38:38 +00001303#endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
wdenkd791b1d2003-04-20 14:04:18 +00001304
wdenk5b1d7132002-11-03 00:07:02 +00001305/*----------------------------------------------------------------------*/
1306
1307static void *lcd_logo (void)
1308{
1309#ifdef LCD_INFO
1310 DECLARE_GLOBAL_DATA_PTR;
1311
1312 char info[80];
1313 char temp[32];
1314#endif /* LCD_INFO */
1315
wdenkd791b1d2003-04-20 14:04:18 +00001316#ifdef CONFIG_SPLASH_SCREEN
1317 char *s;
1318 ulong addr;
1319
1320 if ((s = getenv("splashimage")) != NULL) {
1321 addr = simple_strtoul(s, NULL, 16);
1322
wdenk4b248f32004-03-14 16:51:43 +00001323 if (lcd_display_bitmap (addr, 0, 0) == 0) {
wdenkd791b1d2003-04-20 14:04:18 +00001324 return ((void *)lcd_base);
1325 }
1326 }
1327#endif /* CONFIG_SPLASH_SCREEN */
1328
wdenk5b1d7132002-11-03 00:07:02 +00001329#ifdef CONFIG_LCD_LOGO
1330 bitmap_plot (0, 0);
1331#endif /* CONFIG_LCD_LOGO */
1332
1333
1334#ifdef LCD_INFO
1335 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1336 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1337
wdenkd791b1d2003-04-20 14:04:18 +00001338 sprintf (info, "(C) 2003 DENX Software Engineering");
wdenk5b1d7132002-11-03 00:07:02 +00001339 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1340 info, strlen(info));
1341
1342 sprintf (info, " Wolfgang DENK, wd@denx.de");
1343 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1344 info, strlen(info));
1345#ifdef LCD_INFO_BELOW_LOGO
1346 sprintf (info, "MPC823 CPU at %s MHz",
1347 strmhz(temp, gd->cpu_clk));
1348 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1349 info, strlen(info));
1350 sprintf (info, " %ld MB RAM, %ld MB Flash",
1351 gd->ram_size >> 20,
1352 gd->bd->bi_flashsize >> 20 );
1353 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1354 info, strlen(info));
1355#else
1356 /* leave one blank line */
1357
1358 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1359 strmhz(temp, gd->cpu_clk),
1360 gd->ram_size >> 20,
1361 gd->bd->bi_flashsize >> 20 );
1362 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1363 info, strlen(info));
1364#endif /* LCD_INFO_BELOW_LOGO */
1365#endif /* LCD_INFO */
1366
1367#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1368 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1369#else
1370 return ((void *)lcd_base);
1371#endif /* CONFIG_LCD_LOGO */
1372}
1373
1374/************************************************************************/
1375/************************************************************************/
1376
1377#endif /* CONFIG_LCD */