blob: 4ef1513a0a3d1295b0c3e06ac3a53114ec7d8115 [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
28#include <config.h>
29#include <common.h>
30#include <version.h>
31#include <stdarg.h>
32#include <lcdvideo.h>
33#include <linux/types.h>
34#include <devices.h>
35
36
37#ifdef CONFIG_LCD
38
39/************************************************************************/
40/* ** CONFIG STUFF -- should be moved to board config file */
41/************************************************************************/
42#ifndef CONFIG_EDT32F10
43#define CONFIG_LCD_LOGO
44#define LCD_INFO /* Display Logo, (C) and system info */
45#endif
wdenk608c9142003-01-13 23:54:46 +000046
47#ifdef CONFIG_V37
48#undef CONFIG_LCD_LOGO
49#undef LCD_INFO
50#endif
51
wdenk5b1d7132002-11-03 00:07:02 +000052/* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
53/* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
54/************************************************************************/
55
56/************************************************************************/
57/* ** FONT AND LOGO DATA */
58/************************************************************************/
59
60#include <video_font.h> /* Get font data, width and height */
61
62#ifdef CONFIG_LCD_LOGO
63# include <bmp_logo.h> /* Get logo data, width and height */
64#endif
65
66/************************************************************************/
67/************************************************************************/
68
69/*
70 * Information about displays we are using. This is for configuring
71 * the LCD controller and memory allocation. Someone has to know what
72 * is connected, as we can't autodetect anything.
73 */
74#define CFG_HIGH 0 /* Pins are active high */
75#define CFG_LOW 1 /* Pins are active low */
76
77typedef struct vidinfo {
78 ushort vl_col; /* Number of columns (i.e. 640) */
79 ushort vl_row; /* Number of rows (i.e. 480) */
80 ushort vl_width; /* Width of display area in millimeters */
81 ushort vl_height; /* Height of display area in millimeters */
82
83 /* LCD configuration register.
84 */
85 u_char vl_clkp; /* Clock polarity */
86 u_char vl_oep; /* Output Enable polarity */
87 u_char vl_hsp; /* Horizontal Sync polarity */
88 u_char vl_vsp; /* Vertical Sync polarity */
89 u_char vl_dp; /* Data polarity */
90 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
91 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
92 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
93 u_char vl_clor; /* Color, 0 = mono, 1 = color */
94 u_char vl_tft; /* 0 = passive, 1 = TFT */
95
96 /* Horizontal control register. Timing from data sheet.
97 */
98 ushort vl_wbl; /* Wait between lines */
99
100 /* Vertical control register.
101 */
102 u_char vl_vpw; /* Vertical sync pulse width */
103 u_char vl_lcdac; /* LCD AC timing */
104 u_char vl_wbf; /* Wait between frames */
105} vidinfo_t;
106
107#define LCD_MONOCHROME 0
108#define LCD_COLOR2 1
109#define LCD_COLOR4 2
110#define LCD_COLOR8 3
111
112/*----------------------------------------------------------------------*/
113#ifdef CONFIG_KYOCERA_KCS057QV1AJ
114/*
115 * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
116 */
117#define LCD_BPP LCD_COLOR4
118
119static vidinfo_t panel_info = {
120 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
121 LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
122 /* wbl, vpw, lcdac, wbf */
123};
124#endif /* CONFIG_KYOCERA_KCS057QV1AJ */
125/*----------------------------------------------------------------------*/
126
127/*----------------------------------------------------------------------*/
128#ifdef CONFIG_NEC_NL6648AC33
129/*
130 * NEC NL6648AC33-18. Active, color, single scan.
131 */
132static vidinfo_t panel_info = {
133 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
134 3, 0, 0, 1, 1, 144, 2, 0, 33
135 /* wbl, vpw, lcdac, wbf */
136};
137#endif /* CONFIG_NEC_NL6648AC33 */
138/*----------------------------------------------------------------------*/
139
140#ifdef CONFIG_NEC_NL6648BC20
141/*
142 * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
143 */
144static vidinfo_t panel_info = {
145 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
146 3, 0, 0, 1, 1, 144, 2, 0, 33
147 /* wbl, vpw, lcdac, wbf */
148};
149#endif /* CONFIG_NEC_NL6648BC20 */
150/*----------------------------------------------------------------------*/
151
152#ifdef CONFIG_SHARP_LQ104V7DS01
153/*
154 * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
155 */
156static vidinfo_t panel_info = {
157 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
158 3, 0, 0, 1, 1, 25, 1, 0, 33
159 /* wbl, vpw, lcdac, wbf */
160};
161#endif /* CONFIG_SHARP_LQ104V7DS01 */
162/*----------------------------------------------------------------------*/
163
164#ifdef CONFIG_SHARP_16x9
165/*
166 * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
167 * not sure what it is.......
168 */
169static vidinfo_t panel_info = {
170 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
171 3, 0, 0, 1, 1, 15, 4, 0, 3
172};
173#endif /* CONFIG_SHARP_16x9 */
174/*----------------------------------------------------------------------*/
175
176#ifdef CONFIG_SHARP_LQ057Q3DC02
177/*
178 * Sharp LQ057Q3DC02 display. Active, color, single scan.
179 */
wdenk4a6fd342003-04-12 23:38:12 +0000180#define LCD_DF 12
181
wdenk5b1d7132002-11-03 00:07:02 +0000182static vidinfo_t panel_info = {
183 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
184 3, 0, 0, 1, 1, 15, 4, 0, 3
185 /* wbl, vpw, lcdac, wbf */
186};
187#define LCD_INFO_BELOW_LOGO
188#endif /* CONFIG_SHARP_LQ057Q3DC02 */
189/*----------------------------------------------------------------------*/
190
191#ifdef CONFIG_SHARP_LQ64D341
192/*
193 * Sharp LQ64D341 display, 640x480. Active, color, single scan.
194 */
195static vidinfo_t panel_info = {
196 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
197 3, 0, 0, 1, 1, 128, 16, 0, 32
198 /* wbl, vpw, lcdac, wbf */
199};
200#endif /* CONFIG_SHARP_LQ64D341 */
wdenk608c9142003-01-13 23:54:46 +0000201
202#ifdef CONFIG_SHARP_LQ084V1DG21
203/*
204 * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
205 */
206static vidinfo_t panel_info = {
207 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
208 3, 0, 0, 1, 1, 160, 3, 0, 48
209 /* wbl, vpw, lcdac, wbf */
210};
211#endif /* CONFIG_SHARP_LQ084V1DG21 */
212
wdenk5b1d7132002-11-03 00:07:02 +0000213/*----------------------------------------------------------------------*/
214
215#ifdef CONFIG_HLD1045
216/*
217 * HLD1045 display, 640x480. Active, color, single scan.
218 */
219static vidinfo_t panel_info = {
220 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
221 3, 0, 0, 1, 1, 160, 3, 0, 48
222 /* wbl, vpw, lcdac, wbf */
223};
224#endif /* CONFIG_HLD1045 */
225/*----------------------------------------------------------------------*/
226
227#ifdef CONFIG_PRIMEVIEW_V16C6448AC
228/*
229 * Prime View V16C6448AC
230 */
231static vidinfo_t panel_info = {
232 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
233 3, 0, 0, 1, 1, 144, 2, 0, 35
234 /* wbl, vpw, lcdac, wbf */
235};
236#endif /* CONFIG_PRIMEVIEW_V16C6448AC */
237
238/*----------------------------------------------------------------------*/
239
240#ifdef CONFIG_OPTREX_BW
241/*
242 * Optrex CBL50840-2 NF-FW 99 22 M5
243 * or
244 * Hitachi LMG6912RPFC-00T
245 * or
246 * Hitachi SP14Q002
247 *
248 * 320x240. Black & white.
249 */
250#define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
251 /* 1 - 4 grey levels, 2 bpp */
252 /* 2 - 16 grey levels, 4 bpp */
253static vidinfo_t panel_info = {
254 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
255 OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
256};
257#endif /* CONFIG_OPTREX_BW */
258
259/*-----------------------------------------------------------------*/
260#ifdef CONFIG_EDT32F10
261/*
262 * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
263 */
264#define LCD_BPP LCD_MONOCHROME
wdenk4a6fd342003-04-12 23:38:12 +0000265#define LCD_DF 10
wdenk5b1d7132002-11-03 00:07:02 +0000266
267static vidinfo_t panel_info = {
268 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
wdenk4a6fd342003-04-12 23:38:12 +0000269 LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
wdenk5b1d7132002-11-03 00:07:02 +0000270};
271#endif
272/*----------------------------------------------------------------------*/
273
274#if defined(LCD_INFO_BELOW_LOGO)
275# define LCD_INFO_X 0
276# define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
277#elif defined(CONFIG_LCD_LOGO)
278# define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
279# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
280#else
281# define LCD_INFO_X (VIDEO_FONT_WIDTH)
282# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
283#endif
284
285#ifndef LCD_BPP
286#define LCD_BPP LCD_COLOR8
287#endif
288#ifndef LCD_DF
289#define LCD_DF 1
290#endif
291
292#define NBITS(bit_code) (1 << (bit_code))
293#define NCOLORS(bit_code) (1 << NBITS(bit_code))
294
295static int lcd_line_length;
296
297static int lcd_color_fg;
298static int lcd_color_bg;
299
300static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
301
302/*
303 * Frame buffer memory information
304 */
305static void *lcd_base; /* Start of framebuffer memory */
306static void *lcd_console_address; /* Start of console buffer */
307
308
309/************************************************************************/
310/* ** CONSOLE CONSTANTS */
311/************************************************************************/
312
313#if LCD_BPP == LCD_MONOCHROME
314
315/*
316 * Simple color definitions
317 */
318#define CONSOLE_COLOR_BLACK 0
319#define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
320
321#else
322
323/*
324 * Simple color definitions
325 */
326#define CONSOLE_COLOR_BLACK 0
327#define CONSOLE_COLOR_RED 1
328#define CONSOLE_COLOR_GREEN 2
329#define CONSOLE_COLOR_YELLOW 3
330#define CONSOLE_COLOR_BLUE 4
331#define CONSOLE_COLOR_MAGENTA 5
332#define CONSOLE_COLOR_CYAN 6
333#define CONSOLE_COLOR_GREY 14
334#define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
335
336#endif
337
338#if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
339#error Default Color Map overlaps with Logo Color Map
340#endif
341
342/************************************************************************/
343
344#ifndef PAGE_SIZE
345#define PAGE_SIZE 4096
346#endif
347
348
349/************************************************************************/
350/* ** CONSOLE DEFINITIONS & FUNCTIONS */
351/************************************************************************/
352
353#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
354#define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
355 / VIDEO_FONT_HEIGHT)
356#else
357#define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
358#endif
359#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
360#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
361#define CONSOLE_ROW_FIRST (lcd_console_address)
362#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
363#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
364 - CONSOLE_ROW_SIZE)
365#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
366#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
367
368#if LCD_BPP == LCD_MONOCHROME
369#define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
370 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
371#elif LCD_BPP == LCD_COLOR8
372#define COLOR_MASK(c) (c)
373#else
374#error Unsupported LCD BPP.
375#endif
376
377static short console_col;
378static short console_row;
379
380/************************************************************************/
381
382ulong lcd_setmem (ulong addr);
383
384static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
385static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
386static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
387
388static int lcd_init (void *lcdbase);
389static void lcd_ctrl_init (void *lcdbase);
390static void lcd_enable (void);
391static void *lcd_logo (void);
392#if LCD_BPP == LCD_COLOR8
393static void lcd_setcolreg (ushort regno,
394 ushort red, ushort green, ushort blue);
395#endif
396#if LCD_BPP == LCD_MONOCHROME
397static void lcd_initcolregs (void);
398#endif
399static int lcd_getbgcolor (void);
400static void lcd_setfgcolor (int color);
401static void lcd_setbgcolor (int color);
402
403#ifdef NOT_USED_SO_FAR
404static void lcd_disable (void);
405static void lcd_getcolreg (ushort regno,
406 ushort *red, ushort *green, ushort *blue);
407static int lcd_getfgcolor (void);
408#endif /* NOT_USED_SO_FAR */
409
410/************************************************************************/
411
412/*----------------------------------------------------------------------*/
413
414static void console_scrollup (void)
415{
416#if 1
417 /* Copy up rows ignoring the first one */
418 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
419
420 /* Clear the last one */
421 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
422#else
423 /*
424 * Poor attempt to optimize speed by moving "long"s.
425 * But the code is ugly, and not a bit faster :-(
426 */
427 ulong *t = (ulong *)CONSOLE_ROW_FIRST;
428 ulong *s = (ulong *)CONSOLE_ROW_SECOND;
429 ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
430 uchar c = lcd_color_bg & 0xFF;
431 ulong val= (c<<24) | (c<<16) | (c<<8) | c;
432
433 while (l--)
434 *t++ = *s++;
435
436 t = (ulong *)CONSOLE_ROW_LAST;
437 l = CONSOLE_ROW_SIZE / sizeof(ulong);
438
439 while (l-- > 0)
440 *t++ = val;
441#endif
442}
443
444/*----------------------------------------------------------------------*/
445
446static inline void console_back (void)
447{
448 if (--console_col < 0) {
449 console_col = CONSOLE_COLS-1 ;
450 if (--console_row < 0) {
451 console_row = 0;
452 }
453 }
454
455 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
456 console_row * VIDEO_FONT_HEIGHT,
457 ' ');
458}
459
460/*----------------------------------------------------------------------*/
461
462static inline void console_newline (void)
463{
464 ++console_row;
465 console_col = 0;
466
467 /* Check if we need to scroll the terminal */
468 if (console_row >= CONSOLE_ROWS) {
469 /* Scroll everything up */
470 console_scrollup () ;
471 --console_row;
472 }
473}
474
475/*----------------------------------------------------------------------*/
476
477void lcd_putc (const char c)
478{
479 if (!lcd_is_enabled) {
480 serial_putc(c);
481 return;
482 }
483
484 switch (c) {
485 case '\r': console_col = 0;
486 return;
487
488 case '\n': console_newline();
489 return;
490
491 case '\t': /* Tab (8 chars alignment) */
492 console_col |= 8;
493 console_col &= ~7;
494
495 if (console_col >= CONSOLE_COLS) {
496 console_newline();
497 }
498 return;
499
500 case '\b': console_back();
501 return;
502
503 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
504 console_row * VIDEO_FONT_HEIGHT,
505 c);
506 if (++console_col >= CONSOLE_COLS) {
507 console_newline();
508 }
509 return;
510 }
511 /* NOTREACHED */
512}
513
514/*----------------------------------------------------------------------*/
515
516void lcd_puts (const char *s)
517{
518 if (!lcd_is_enabled) {
519 serial_puts (s);
520 return;
521 }
522
523 while (*s) {
524 lcd_putc (*s++);
525 }
526}
527
528/************************************************************************/
529/* ** Low-Level Graphics Routines */
530/************************************************************************/
531
532static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
533{
534 uchar *dest;
535 ushort off, row;
536
537 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
538 off = x * (1 << LCD_BPP) % 8;
539
540 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
541 uchar *s = str;
542 uchar *d = dest;
543 int i;
544
545#if LCD_BPP == LCD_MONOCHROME
546 uchar rest = *d & -(1 << (8-off));
547 uchar sym;
548#endif
549 for (i=0; i<count; ++i) {
550 uchar c, bits;
551
552 c = *s++;
553 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
554
555#if LCD_BPP == LCD_MONOCHROME
556 sym = (COLOR_MASK(lcd_color_fg) & bits) |
557 (COLOR_MASK(lcd_color_bg) & ~bits);
558
559 *d++ = rest | (sym >> off);
560 rest = sym << (8-off);
561#elif LCD_BPP == LCD_COLOR8
562 for (c=0; c<8; ++c) {
563 *d++ = (bits & 0x80) ?
564 lcd_color_fg : lcd_color_bg;
565 bits <<= 1;
566 }
567#endif
568 }
569
570#if LCD_BPP == LCD_MONOCHROME
571 *d = rest | (*d & ((1 << (8-off)) - 1));
572#endif
573 }
574}
575
576/*----------------------------------------------------------------------*/
577
578static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
579{
580#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
581 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
582#else
583 lcd_drawchars (x, y, s, strlen (s));
584#endif
585}
586
587/*----------------------------------------------------------------------*/
588
589static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
590{
591#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
592 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
593#else
594 lcd_drawchars (x, y, &c, 1);
595#endif
596}
597
598/************************************************************************/
599/** Small utility to check that you got the colours right */
600/************************************************************************/
601#ifdef LCD_TEST_PATTERN
602
603#define N_BLK_VERT 2
604#define N_BLK_HOR 3
605
606static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
607 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
608 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
609};
610
611static void test_pattern (void)
612{
613 ushort v_max = panel_info.vl_row;
614 ushort h_max = panel_info.vl_col;
615 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
616 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
617 ushort v, h;
618 uchar *pix = (uchar *)lcd_base;
619
620 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
621 h_max, v_max, h_step, v_step);
622
623 /* WARNING: Code silently assumes 8bit/pixel */
624 for (v=0; v<v_max; ++v) {
625 uchar iy = v / v_step;
626 for (h=0; h<h_max; ++h) {
627 uchar ix = N_BLK_HOR * iy + (h/h_step);
628 *pix++ = test_colors[ix];
629 }
630 }
631}
632#endif /* LCD_TEST_PATTERN */
633
634
635/************************************************************************/
636/* ** GENERIC Initialization Routines */
637/************************************************************************/
638
639int drv_lcd_init (void)
640{
641 DECLARE_GLOBAL_DATA_PTR;
642
643 device_t lcddev;
644 int rc;
645
646 lcd_base = (void *)(gd->fb_base);
647
648 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
649
650 lcd_init (lcd_base); /* LCD initialization */
651
652 /* Device initialization */
653 memset (&lcddev, 0, sizeof (lcddev));
654
655 strcpy (lcddev.name, "lcd");
656 lcddev.ext = 0; /* No extensions */
657 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
658 lcddev.putc = lcd_putc; /* 'putc' function */
659 lcddev.puts = lcd_puts; /* 'puts' function */
660
661 rc = device_register (&lcddev);
662
663 return (rc == 0) ? 1 : rc;
664}
665
666/*----------------------------------------------------------------------*/
667
668static int lcd_init (void *lcdbase)
669{
670 /* Initialize the lcd controller */
671 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
672
673 lcd_ctrl_init (lcdbase);
674
675#if LCD_BPP == LCD_MONOCHROME
676 /* Setting the palette */
677 lcd_initcolregs();
678
679#elif LCD_BPP == LCD_COLOR8
680 /* Setting the palette */
681 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
682 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
683 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
684 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
685 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
686 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
687 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
688 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
689 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
690#endif
691
692#ifndef CFG_WHITE_ON_BLACK
693 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
694 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
695#else
696 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
697 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
698#endif /* CFG_WHITE_ON_BLACK */
699
700#ifdef LCD_TEST_PATTERN
701 test_pattern();
702#else
703 /* set framebuffer to background color */
704 memset ((char *)lcd_base,
705 COLOR_MASK(lcd_getbgcolor()),
706 lcd_line_length*panel_info.vl_row);
707#endif
708
709 lcd_enable ();
710
711 /* Paint the logo and retrieve LCD base address */
712 debug ("[LCD] Drawing the logo...\n");
713 lcd_console_address = lcd_logo ();
714
715 /* Initialize the console */
716 console_col = 0;
717#ifdef LCD_INFO_BELOW_LOGO
718 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
719#else
720 console_row = 1; /* leave 1 blank line below logo */
721#endif
722 lcd_is_enabled = 1;
723
724 return 0;
725}
726
727
728/************************************************************************/
729/* ** ROM capable initialization part - needed to reserve FB memory */
730/************************************************************************/
731
732/*
733 * This is called early in the system initialization to grab memory
734 * for the LCD controller.
735 * Returns new address for monitor, after reserving LCD buffer memory
736 *
737 * Note that this is running from ROM, so no write access to global data.
738 */
739ulong lcd_setmem (ulong addr)
740{
741 ulong size;
742 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
743
744 debug ("LCD panel info: %d x %d, %d bit/pix\n",
745 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
746
747 size = line_length * panel_info.vl_row;
748
749 /* Round up to nearest full page */
750 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
751
752 /* Allocate pages for the frame buffer. */
753 addr -= size;
754
755 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
756
757 return (addr);
758}
759
760
761/************************************************************************/
762/* ----------------- chipset specific functions ----------------------- */
763/************************************************************************/
764
765static void lcd_ctrl_init (void *lcdbase)
766{
767 volatile immap_t *immr = (immap_t *) CFG_IMMR;
768 volatile lcd823_t *lcdp = &immr->im_lcd;
769
770 uint lccrtmp;
771
772 /* Initialize the LCD control register according to the LCD
773 * parameters defined. We do everything here but enable
774 * the controller.
775 */
776
777 lccrtmp = LCDBIT (LCCR_BNUM_BIT,
778 (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
779
780 lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
781 LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
782 LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
783 LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
784 LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
785 LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
786 LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
787 LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
788 LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
789 LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
790
791#if 0
792 lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
793 lccrtmp |= LCCR_EIEN;
794#endif
795
796 lcdp->lcd_lccr = lccrtmp;
797 lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
798
799 /* Initialize LCD controller bus priorities.
800 */
801 immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
802
803 /* set SHFT/CLOCK division factor 4
804 * This needs to be set based upon display type and processor
805 * speed. The TFT displays run about 20 to 30 MHz.
806 * I was running 64 MHz processor speed.
807 * The value for this divider must be chosen so the result is
808 * an integer of the processor speed (i.e., divide by 3 with
809 * 64 MHz would be bad).
810 */
811 immr->im_clkrst.car_sccr &= ~0x1F;
812 immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
813
814#ifndef CONFIG_EDT32F10
815 /* Enable LCD on port D.
816 */
817 immr->im_ioport.iop_pdpar |= 0x1FFF;
818 immr->im_ioport.iop_pddir |= 0x1FFF;
819
820 /* Enable LCD_A/B/C on port B.
821 */
822 immr->im_cpm.cp_pbpar |= 0x00005001;
823 immr->im_cpm.cp_pbdir |= 0x00005001;
824#else
825 /* Enable LCD on port D.
826 */
827 immr->im_ioport.iop_pdpar |= 0x1DFF;
828 immr->im_ioport.iop_pdpar &= ~0x0200;
829 immr->im_ioport.iop_pddir |= 0x1FFF;
830 immr->im_ioport.iop_pddat |= 0x0200;
831#endif
832
833 /* Load the physical address of the linear frame buffer
834 * into the LCD controller.
835 * BIG NOTE: This has to be modified to load A and B depending
836 * upon the split mode of the LCD.
837 */
838 lcdp->lcd_lcfaa = (ulong)lcd_base;
839 lcdp->lcd_lcfba = (ulong)lcd_base;
840
841 /* MORE HACKS...This must be updated according to 823 manual
842 * for different panels.
843 */
844#ifndef CONFIG_EDT32F10
845 lcdp->lcd_lchcr = LCHCR_BO |
846 LCDBIT (LCHCR_AT_BIT, 4) |
847 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
848 panel_info.vl_wbl;
849#else
850 lcdp->lcd_lchcr = LCHCR_BO |
851 LCDBIT (LCHCR_AT_BIT, 4) |
852 LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
853 panel_info.vl_wbl;
854#endif
855
856 lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
857 LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
858 LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
859 panel_info.vl_wbf;
860
861}
862
863/*----------------------------------------------------------------------*/
864
865#ifdef NOT_USED_SO_FAR
866static void
867lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
868{
869 volatile immap_t *immr = (immap_t *) CFG_IMMR;
870 volatile cpm8xx_t *cp = &(immr->im_cpm);
871 unsigned short colreg, *cmap_ptr;
872
873 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
874
875 colreg = *cmap_ptr;
876#ifdef CFG_INVERT_COLORS
877 colreg ^= 0x0FFF;
878#endif
879
880 *red = (colreg >> 8) & 0x0F;
881 *green = (colreg >> 4) & 0x0F;
882 *blue = colreg & 0x0F;
883}
884#endif /* NOT_USED_SO_FAR */
885
886/*----------------------------------------------------------------------*/
887
888#if LCD_BPP == LCD_COLOR8
889static void
890lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
891{
892 volatile immap_t *immr = (immap_t *) CFG_IMMR;
893 volatile cpm8xx_t *cp = &(immr->im_cpm);
894 unsigned short colreg, *cmap_ptr;
895
896 cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
897
898 colreg = ((red & 0x0F) << 8) |
899 ((green & 0x0F) << 4) |
900 (blue & 0x0F) ;
901#ifdef CFG_INVERT_COLORS
902 colreg ^= 0x0FFF;
903#endif
904 *cmap_ptr = colreg;
905
906 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
907 regno, &(cp->lcd_cmap[regno * 2]),
908 red, green, blue,
909 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
910}
911#endif /* LCD_COLOR8 */
912
913/*----------------------------------------------------------------------*/
914
915#if LCD_BPP == LCD_MONOCHROME
916static
917void lcd_initcolregs (void)
918{
919 volatile immap_t *immr = (immap_t *) CFG_IMMR;
920 volatile cpm8xx_t *cp = &(immr->im_cpm);
921 ushort regno;
922
923 for (regno = 0; regno < 16; regno++) {
924 cp->lcd_cmap[regno * 2] = 0;
925 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
926 }
927}
928#endif
929
930/*----------------------------------------------------------------------*/
931
932static void lcd_setfgcolor (int color)
933{
934 lcd_color_fg = color & 0x0F;
935}
936
937/*----------------------------------------------------------------------*/
938
939static void lcd_setbgcolor (int color)
940{
941 lcd_color_bg = color & 0x0F;
942}
943
944/*----------------------------------------------------------------------*/
945
946#ifdef NOT_USED_SO_FAR
947static int lcd_getfgcolor (void)
948{
949 return lcd_color_fg;
950}
951#endif /* NOT_USED_SO_FAR */
952
953/*----------------------------------------------------------------------*/
954
955static int lcd_getbgcolor (void)
956{
957 return lcd_color_bg;
958}
959
960/*----------------------------------------------------------------------*/
961
962static void lcd_enable (void)
963{
964 volatile immap_t *immr = (immap_t *) CFG_IMMR;
965 volatile lcd823_t *lcdp = &immr->im_lcd;
966
967 /* Enable the LCD panel */
968 immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
969 lcdp->lcd_lccr |= LCCR_PON;
wdenk608c9142003-01-13 23:54:46 +0000970
971#ifdef CONFIG_V37
972 /* Turn on display backlight */
973 immr->im_cpm.cp_pbpar |= 0x00008000;
974 immr->im_cpm.cp_pbdir |= 0x00008000;
975#endif
976
wdenk5b1d7132002-11-03 00:07:02 +0000977#if defined(CONFIG_LWMON)
978 { uchar c = pic_read (0x60);
979 c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
980 pic_write (0x60, c);
981 }
wdenk5b1d7132002-11-03 00:07:02 +0000982#endif /* CONFIG_LWMON */
wdenk4a6fd342003-04-12 23:38:12 +0000983
984#if defined(CONFIG_R360MPI)
985 {
986 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
987
988 r360_i2c_lcd_write(0x10, 0x01);
989 r360_i2c_lcd_write(0x20, 0x01);
990 r360_i2c_lcd_write(0x3F, 0xFF);
991 r360_i2c_lcd_write(0x47, 0xFF);
992 }
993#endif /* CONFIG_R360MPI */
wdenk5b1d7132002-11-03 00:07:02 +0000994}
995
996/*----------------------------------------------------------------------*/
997
998#ifdef NOT_USED_SO_FAR
999static void lcd_disable (void)
1000{
1001 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1002 volatile lcd823_t *lcdp = &immr->im_lcd;
1003
1004#if defined(CONFIG_LWMON)
1005 { uchar c = pic_read (0x60);
1006 c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1007 pic_write (0x60, c);
1008 }
1009#elif defined(CONFIG_R360MPI)
1010 {
wdenk4a6fd342003-04-12 23:38:12 +00001011 extern void r360_i2c_lcd_write (uchar data0, uchar data1);
wdenk5b1d7132002-11-03 00:07:02 +00001012
wdenk4a6fd342003-04-12 23:38:12 +00001013 r360_i2c_lcd_write(0x10, 0x00);
1014 r360_i2c_lcd_write(0x20, 0x00);
1015 r360_i2c_lcd_write(0x30, 0x00);
1016 r360_i2c_lcd_write(0x40, 0x00);
wdenk5b1d7132002-11-03 00:07:02 +00001017 }
1018#endif /* CONFIG_LWMON */
1019 /* Disable the LCD panel */
1020 lcdp->lcd_lccr &= ~LCCR_PON;
1021 immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1022}
1023#endif /* NOT_USED_SO_FAR */
1024
1025
1026/************************************************************************/
1027/* ** Chipset depending Bitmap / Logo stuff... */
1028/************************************************************************/
1029
1030
1031#ifdef CONFIG_LCD_LOGO
1032static void bitmap_plot (int x, int y)
1033{
1034 volatile immap_t *immr = (immap_t *) CFG_IMMR;
1035 volatile cpm8xx_t *cp = &(immr->im_cpm);
1036 ushort *cmap;
1037 ushort i;
1038 uchar *bmap;
1039 uchar *fb;
1040
1041 debug ("Logo: width %d height %d colors %d cmap %d\n",
1042 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1043 sizeof(bmp_logo_palette)/(sizeof(ushort))
1044 );
1045
1046 /* Leave room for default color map */
1047 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1048
1049 /* Set color map */
1050 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1051 ushort colreg = bmp_logo_palette[i];
1052#ifdef CFG_INVERT_COLORS
1053 colreg ^= 0xFFF;
1054#endif
1055 *cmap++ = colreg;
1056 }
1057
1058 bmap = &bmp_logo_bitmap[0];
1059 fb = (char *)(lcd_base + y * lcd_line_length + x);
1060
1061 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1062 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1063 bmap += BMP_LOGO_WIDTH;
1064 fb += panel_info.vl_col;
1065 }
1066}
1067#endif /* CONFIG_LCD_LOGO */
1068
1069/*----------------------------------------------------------------------*/
1070
1071static void *lcd_logo (void)
1072{
1073#ifdef LCD_INFO
1074 DECLARE_GLOBAL_DATA_PTR;
1075
1076 char info[80];
1077 char temp[32];
1078#endif /* LCD_INFO */
1079
1080#ifdef CONFIG_LCD_LOGO
1081 bitmap_plot (0, 0);
1082#endif /* CONFIG_LCD_LOGO */
1083
1084
1085#ifdef LCD_INFO
1086 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1087 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1088
1089 sprintf (info, "(C) 2002 DENX Software Engineering");
1090 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1091 info, strlen(info));
1092
1093 sprintf (info, " Wolfgang DENK, wd@denx.de");
1094 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1095 info, strlen(info));
1096#ifdef LCD_INFO_BELOW_LOGO
1097 sprintf (info, "MPC823 CPU at %s MHz",
1098 strmhz(temp, gd->cpu_clk));
1099 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1100 info, strlen(info));
1101 sprintf (info, " %ld MB RAM, %ld MB Flash",
1102 gd->ram_size >> 20,
1103 gd->bd->bi_flashsize >> 20 );
1104 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1105 info, strlen(info));
1106#else
1107 /* leave one blank line */
1108
1109 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1110 strmhz(temp, gd->cpu_clk),
1111 gd->ram_size >> 20,
1112 gd->bd->bi_flashsize >> 20 );
1113 lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1114 info, strlen(info));
1115#endif /* LCD_INFO_BELOW_LOGO */
1116#endif /* LCD_INFO */
1117
1118#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1119 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1120#else
1121 return ((void *)lcd_base);
1122#endif /* CONFIG_LCD_LOGO */
1123}
1124
1125/************************************************************************/
1126/************************************************************************/
1127
1128#endif /* CONFIG_LCD */