blob: f6a25754bd7eb0321cca102b5f3fa381b2c7cc70 [file] [log] [blame]
wdenk71f95112003-06-15 22:40:42 +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#define DEBUG 1
29#include <config.h>
30#include <common.h>
31#include <version.h>
32#include <stdarg.h>
33#include <lcdvideo.h>
34#include <linux/types.h>
35#include <devices.h>
36#include <asm/arch/pxa-regs.h>
37
38#ifdef CONFIG_LCD
39
40/************************************************************************/
41/* ** CONFIG STUFF -- should be moved to board config file */
42/************************************************************************/
43#ifndef CONFIG_EDT32F10
44#define CONFIG_LCD_LOGO
45#define LCD_INFO /* Display Logo, (C) and system info */
46#endif
47
48#ifdef CONFIG_V37
49#undef CONFIG_LCD_LOGO
50#undef LCD_INFO
51#endif
52
53#undef CONFIG_LCD_LOGO
54
55#define LCD_TEST_PATTERN
56/* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
57/* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
58/************************************************************************/
59
60/************************************************************************/
61/* ** FONT AND LOGO DATA */
62/************************************************************************/
63
64#include <video_font.h> /* Get font data, width and height */
65
66#ifdef CONFIG_LCD_LOGO
67# include <bmp_nexus.h> /* Get logo data, width and height */
68#endif
69
70/************************************************************************/
71/************************************************************************/
72
73/*
74 * Information about displays we are using. This is for configuring
75 * the LCD controller and memory allocation. Someone has to know what
76 * is connected, as we can't autodetect anything.
77 */
78#define CFG_HIGH 0 /* Pins are active high */
79#define CFG_LOW 1 /* Pins are active low */
80
81/* PXA LCD DMA descriptor */
82struct pxafb_dma_descriptor {
83 u_long fdadr;
84 u_long fsadr;
85 u_long fidr;
86 u_long ldcmd;
87};
88
89/* PXA LCD info */
90struct pxafb_info {
91
92 /* Misc registers */
93 u_long reg_lccr3;
94 u_long reg_lccr2;
95 u_long reg_lccr1;
96 u_long reg_lccr0;
97 u_long fdadr0;
98 u_long fdadr1;
99
100 /* DMA descriptors */
101 struct pxafb_dma_descriptor * dmadesc_fblow;
102 struct pxafb_dma_descriptor * dmadesc_fbhigh;
103 struct pxafb_dma_descriptor * dmadesc_palette;
104
105 u_long screen; /* physical address of frame buffer */
106 u_long palette; /* physical address of palette memory */
107 u_int palette_size;
108};
109
110typedef struct vidinfo {
111 ushort vl_col; /* Number of columns (i.e. 640) */
112 ushort vl_row; /* Number of rows (i.e. 480) */
113 ushort vl_width; /* Width of display area in millimeters */
114 ushort vl_height; /* Height of display area in millimeters */
115
116 /* LCD configuration register.
117 */
118 u_char vl_clkp; /* Clock polarity */
119 u_char vl_oep; /* Output Enable polarity */
120 u_char vl_hsp; /* Horizontal Sync polarity */
121 u_char vl_vsp; /* Vertical Sync polarity */
122 u_char vl_dp; /* Data polarity */
123 u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16 */
124 u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
125 u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
126 u_char vl_clor; /* Color, 0 = mono, 1 = color */
127 u_char vl_tft; /* 0 = passive, 1 = TFT */
128
129 /* Horizontal control register. Timing from data sheet.
130 */
131 ushort vl_hpw; /* Horz sync pulse width */
132 u_char vl_blw; /* Wait before of line */
133 u_char vl_elw; /* Wait end of line */
134
135 /* Vertical control register.
136 */
137 u_char vl_vpw; /* Vertical sync pulse width */
138 u_char vl_bfw; /* Wait before of frame */
139 u_char vl_efw; /* Wait end of frame */
140
141 u_char vl_lcdac; /* LCD AC timing */
142
143 /* PXA LCD controller params
144 */
145 struct pxafb_info pxa;
146
147} vidinfo_t;
148
149#define LCD_MONOCHROME 0
150#define LCD_COLOR2 1
151#define LCD_COLOR4 2
152#define LCD_COLOR8 3
153#define LCD_COLOR16 4
154
155/*----------------------------------------------------------------------*/
156#define CONFIG_PXA_VGA
157#ifdef CONFIG_PXA_VGA
158/*
159 * LCD outputs connected to a video DAC
160 */
161
162#define LCD_BPP LCD_COLOR8
163
164/* you have to set lccr0 and lccr3 (including pcd) */
165#define REG_LCCR0 0x003008f8
166#define REG_LCCR3 0x0300FF01
167
168/* 640x480x16 @ 61 Hz */
169static vidinfo_t panel_info = {
170 vl_col: 640,
171 vl_row: 480,
172 vl_width: 640,
173 vl_height: 480,
174 vl_clkp: CFG_HIGH,
175 vl_oep: CFG_HIGH,
176 vl_hsp: CFG_HIGH,
177 vl_vsp: CFG_HIGH,
178 vl_dp: CFG_HIGH,
179 vl_bpix: LCD_BPP,
180 vl_lbw: 0,
181 vl_splt: 0,
182 vl_clor: 0,
183 vl_lcdac: 0,
184 vl_tft: 1,
185 vl_hpw: 40,
186 vl_blw: 56,
187 vl_elw: 56,
188 vl_vpw: 20,
189 vl_bfw: 8,
190 vl_efw: 8,
191};
192#endif /* CONFIG_PXA_VIDEO */
193
194#ifdef CONFIG_SHARP_LM8V31
195
196#define LCD_BPP LCD_COLOR8
197#define LCD_INVERT_COLORS /* Needed for colors to be correct, but why? */
198
199/* you have to set lccr0 and lccr3 (including pcd) */
200#define REG_LCCR0 0x0030087C
201#define REG_LCCR3 0x0340FF08
202
203static vidinfo_t panel_info = {
204 vl_col: 640,
205 vl_row: 480,
206 vl_width: 157,
207 vl_height: 118,
208 vl_clkp: CFG_HIGH,
209 vl_oep: CFG_HIGH,
210 vl_hsp: CFG_HIGH,
211 vl_vsp: CFG_HIGH,
212 vl_dp: CFG_HIGH,
213 vl_bpix: LCD_BPP,
214 vl_lbw: 0,
215 vl_splt: 1,
216 vl_clor: 1,
217 vl_lcdac: 0,
218 vl_tft: 0,
219 vl_hpw: 1,
220 vl_blw: 3,
221 vl_elw: 3,
222 vl_vpw: 1,
223 vl_bfw: 0,
224 vl_efw: 0,
225};
226#endif /* CONFIG_SHARP_LM8V31 */
227
228/*----------------------------------------------------------------------*/
229
230/*----------------------------------------------------------------------*/
231
232#if defined(LCD_INFO_BELOW_LOGO)
233# define LCD_INFO_X 0
234# define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
235#elif defined(CONFIG_LCD_LOGO)
236# define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
237# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
238#else
239# define LCD_INFO_X (VIDEO_FONT_WIDTH)
240# define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
241#endif
242
243#ifndef LCD_BPP
244#define LCD_BPP LCD_COLOR8
245#endif
246#ifndef LCD_DF
247#define LCD_DF 1
248#endif
249
250#define NBITS(bit_code) (1 << (bit_code))
251#define NCOLORS(bit_code) (1 << NBITS(bit_code))
252
253static int lcd_line_length;
254
255static int lcd_color_fg;
256static int lcd_color_bg;
257
258static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
259
260/*
261 * Frame buffer memory information
262 */
263static void *lcd_base; /* Start of framebuffer memory */
264static void *lcd_console_address; /* Start of console buffer */
265
266
267/************************************************************************/
268/* ** CONSOLE CONSTANTS */
269/************************************************************************/
270
271#if LCD_BPP == LCD_MONOCHROME
272
273/*
274 * Simple color definitions
275 */
276#define CONSOLE_COLOR_BLACK 0
277#define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
278
279#elif LCD_BPP == LCD_COLOR8
280
281/*
282 * Simple color definitions
283 */
284#define CONSOLE_COLOR_BLACK 0
285#define CONSOLE_COLOR_RED 1
286#define CONSOLE_COLOR_GREEN 2
287#define CONSOLE_COLOR_YELLOW 3
288#define CONSOLE_COLOR_BLUE 4
289#define CONSOLE_COLOR_MAGENTA 5
290#define CONSOLE_COLOR_CYAN 6
291#define CONSOLE_COLOR_GREY 14
292#define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
293
294#else /* 16 bit */
295
296#define CONSOLE_COLOR_BLACK 0x0000
297#define CONSOLE_COLOR_WHITE 0xffff /* Must remain last / highest */
298
299#endif
300
301#if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
302#error Default Color Map overlaps with Logo Color Map
303#endif
304
305/************************************************************************/
306
307#ifndef PAGE_SIZE
308#define PAGE_SIZE 4096
309#endif
310
311
312/************************************************************************/
313/* ** CONSOLE DEFINITIONS & FUNCTIONS */
314/************************************************************************/
315
316#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
317#define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
318 / VIDEO_FONT_HEIGHT)
319#else
320#define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
321#endif
322#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
323#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
324#define CONSOLE_ROW_FIRST (lcd_console_address)
325#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
326#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
327 - CONSOLE_ROW_SIZE)
328#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
329#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
330
331#if LCD_BPP == LCD_MONOCHROME
332#define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
333 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
334#elif LCD_BPP == LCD_COLOR8
335#define COLOR_MASK(c) (c)
336#elif LCD_BPP == LCD_COLOR16
337#define COLOR_MASK(c) (c)
338#else
339#error Unsupported LCD BPP.
340#endif
341
342static short console_col;
343static short console_row;
344
345/************************************************************************/
346
347ulong lcd_setmem (ulong addr);
348
349static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
350static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
351static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
352
353static int lcd_init (void *lcdbase);
354static void lcd_ctrl_init (void *lcdbase);
355static void lcd_enable (void);
356static void *lcd_logo (void);
357#if LCD_BPP == LCD_COLOR8
358static void lcd_setcolreg (ushort regno,
359 ushort red, ushort green, ushort blue);
360#endif
361#if LCD_BPP == LCD_MONOCHROME
362static void lcd_initcolregs (void);
363#endif
364static void lcd_setfgcolor (int color);
365static void lcd_setbgcolor (int color);
366
367#ifdef NOT_USED_SO_FAR
368static int lcd_getbgcolor (void);
369static void lcd_disable (void);
370static void lcd_getcolreg (ushort regno,
371 ushort *red, ushort *green, ushort *blue);
372static int lcd_getfgcolor (void);
373#endif /* NOT_USED_SO_FAR */
374
375
376static int pxafb_init_mem(void *lcdbase, vidinfo_t *vid);
377static void pxafb_setup_gpio(vidinfo_t *vid);
378static void pxafb_enable_controller(vidinfo_t *vid);
379static int pxafb_init(vidinfo_t *vid);
380
381/************************************************************************/
382
383/*----------------------------------------------------------------------*/
384
385static void console_scrollup (void)
386{
387 /* Copy up rows ignoring the first one */
388 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
389
390 /* Clear the last one */
391 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
392}
393
394/*----------------------------------------------------------------------*/
395
396static inline void console_back (void)
397{
398 if (--console_col < 0) {
399 console_col = CONSOLE_COLS-1 ;
400 if (--console_row < 0) {
401 console_row = 0;
402 }
403 }
404
405 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
406 console_row * VIDEO_FONT_HEIGHT,
407 ' ');
408}
409
410/*----------------------------------------------------------------------*/
411
412static inline void console_newline (void)
413{
414 ++console_row;
415 console_col = 0;
416
417 /* Check if we need to scroll the terminal */
418 if (console_row >= CONSOLE_ROWS) {
419 /* Scroll everything up */
420 console_scrollup () ;
421 --console_row;
422 }
423}
424
425/*----------------------------------------------------------------------*/
426
427void lcd_putc (const char c)
428{
429 if (!lcd_is_enabled) {
430 serial_putc(c);
431 return;
432 }
433
434 switch (c) {
435 case '\r': console_col = 0;
436 return;
437
438 case '\n': console_newline();
439 return;
440
441 case '\t': /* Tab (8 chars alignment) */
442 console_col |= 8;
443 console_col &= ~7;
444
445 if (console_col >= CONSOLE_COLS) {
446 console_newline();
447 }
448 return;
449
450 case '\b': console_back();
451 return;
452
453 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
454 console_row * VIDEO_FONT_HEIGHT,
455 c);
456 if (++console_col >= CONSOLE_COLS) {
457 console_newline();
458 }
459 return;
460 }
461 /* NOTREACHED */
462}
463
464/*----------------------------------------------------------------------*/
465
466void lcd_puts (const char *s)
467{
468 if (!lcd_is_enabled) {
469 serial_puts (s);
470 return;
471 }
472
473 while (*s) {
474 lcd_putc (*s++);
475 }
476}
477
478/************************************************************************/
479/* ** Low-Level Graphics Routines */
480/************************************************************************/
481
482static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
483{
484 uchar *dest;
485 ushort off, row;
486
487 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
488 off = x * (1 << LCD_BPP) % 8;
489
490 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
491 uchar *s = str;
492 uchar *d = dest;
493 int i;
494
495#if LCD_BPP == LCD_MONOCHROME
496 uchar rest = *d & -(1 << (8-off));
497 uchar sym;
498#endif
499 for (i=0; i<count; ++i) {
500 uchar c, bits;
501
502 c = *s++;
503 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
504
505#if LCD_BPP == LCD_MONOCHROME
506 sym = (COLOR_MASK(lcd_color_fg) & bits) |
507 (COLOR_MASK(lcd_color_bg) & ~bits);
508
509 *d++ = rest | (sym >> off);
510 rest = sym << (8-off);
511#elif LCD_BPP == LCD_COLOR8
512 for (c=0; c<8; ++c) {
513 *d++ = (bits & 0x80) ?
514 lcd_color_fg : lcd_color_bg;
515 bits <<= 1;
516 }
517#elif LCD_BPP == LCD_COLOR16
518 for (c=0; c<16; ++c) {
519 *d++ = (bits & 0x80) ?
520 lcd_color_fg : lcd_color_bg;
521 bits <<= 1;
522 }
523#endif
524 }
525
526#if LCD_BPP == LCD_MONOCHROME
527 *d = rest | (*d & ((1 << (8-off)) - 1));
528#endif
529 }
530}
531
532/*----------------------------------------------------------------------*/
533
534static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
535{
536#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
537 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
538#else
539 lcd_drawchars (x, y, s, strlen (s));
540#endif
541}
542
543/*----------------------------------------------------------------------*/
544
545static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
546{
547#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
548 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
549#else
550 lcd_drawchars (x, y, &c, 1);
551#endif
552}
553
554/************************************************************************/
555/** Small utility to check that you got the colours right */
556/************************************************************************/
557#ifdef LCD_TEST_PATTERN
558
559#define N_BLK_VERT 2
560#define N_BLK_HOR 3
561
562static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
563 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
564 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
565};
566
567static void test_pattern (void)
568{
569 ushort v_max = panel_info.vl_row;
570 ushort h_max = panel_info.vl_col;
571 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
572 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
573 ushort v, h;
574 uchar *pix = (uchar *)lcd_base;
575
576 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
577 h_max, v_max, h_step, v_step);
578
579 /* WARNING: Code silently assumes 8bit/pixel */
580 for (v=0; v<v_max; ++v) {
581 uchar iy = v / v_step;
582 for (h=0; h<h_max; ++h) {
583 uchar ix = N_BLK_HOR * iy + (h/h_step);
584 *pix++ = test_colors[ix];
585 }
586 }
587}
588#endif /* LCD_TEST_PATTERN */
589
590
591/************************************************************************/
592/* ** GENERIC Initialization Routines */
593/************************************************************************/
594
595int drv_lcd_init (void)
596{
597 DECLARE_GLOBAL_DATA_PTR;
598
599 device_t lcddev;
600 int rc;
601
602 lcd_base = (void *)(gd->fb_base);
603
604 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
605
606 lcd_init (lcd_base); /* LCD initialization */
607
608 /* Device initialization */
609 memset (&lcddev, 0, sizeof (lcddev));
610
611 strcpy (lcddev.name, "lcd");
612 lcddev.ext = 0; /* No extensions */
613 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
614 lcddev.putc = lcd_putc; /* 'putc' function */
615 lcddev.puts = lcd_puts; /* 'puts' function */
616
617 rc = device_register (&lcddev);
618 return (rc == 0) ? 1 : rc;
619}
620
621/*----------------------------------------------------------------------*/
622
623static int lcd_init (void *lcdbase)
624{
625 /* Initialize the lcd controller */
626 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
627
628 lcd_ctrl_init (lcdbase);
629
630#if LCD_BPP == LCD_MONOCHROME
631 /* Setting the palette */
632 lcd_initcolregs();
633
634#elif LCD_BPP == LCD_COLOR8
635 /* Setting the palette */
636 lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
637 lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
638 lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
639 lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
640 lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
641 lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
642 lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
643 lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
644 lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
645#endif
646
647#define CFG_WHITE_ON_BLACK
648#ifndef CFG_WHITE_ON_BLACK
649 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
650 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
651#else
652 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
653 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
654#endif /* CFG_WHITE_ON_BLACK */
655
656#ifdef LCD_TEST_PATTERN
657 test_pattern();
658#else
659 /* set framebuffer to background color */
660 memset ((char *)lcd_base,
661 COLOR_MASK(lcd_getbgcolor()),
662 lcd_line_length*panel_info.vl_row);
663#endif
664
665 lcd_enable ();
666
667 /* Paint the logo and retrieve LCD base address */
668 debug ("[LCD] Drawing the logo...\n");
669 lcd_console_address = lcd_logo ();
670
671 /* Initialize the console */
672 console_col = 0;
673#ifdef LCD_INFO_BELOW_LOGO
674 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
675#else
676 console_row = 1; /* leave 1 blank line below logo */
677#endif
678 lcd_is_enabled = 1;
679
680 return 0;
681}
682
683
684/************************************************************************/
685/* ** ROM capable initialization part - needed to reserve FB memory */
686/************************************************************************/
687
688/*
689 * This is called early in the system initialization to grab memory
690 * for the LCD controller.
691 * Returns new address for monitor, after reserving LCD buffer memory
692 *
693 * Note that this is running from ROM, so no write access to global data.
694 */
695ulong lcd_setmem (ulong addr)
696{
697 ulong size;
698 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
699
700 debug ("LCD panel info: %d x %d, %d bit/pix\n",
701 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
702
703 /* extra page for dma descriptors and palette */
704 size = line_length * panel_info.vl_row + PAGE_SIZE;
705
706 /* Round up to nearest full page */
707 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
708
709 /* Allocate pages for the frame buffer. */
710 addr -= size;
711
712 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
713
714 return (addr);
715}
716
717
718/************************************************************************/
719/* ----------------- chipset specific functions ----------------------- */
720/************************************************************************/
721
722static void lcd_ctrl_init (void *lcdbase)
723{
724 pxafb_init_mem(lcdbase, &panel_info);
725 pxafb_init(&panel_info);
726 pxafb_setup_gpio(&panel_info);
727 pxafb_enable_controller(&panel_info);
728}
729
730/*----------------------------------------------------------------------*/
731
732#ifdef NOT_USED_SO_FAR
733static void
734lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
735{
736}
737#endif /* NOT_USED_SO_FAR */
738
739/*----------------------------------------------------------------------*/
740
741#if LCD_BPP == LCD_COLOR8
742static void
743lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
744{
745 struct pxafb_info *fbi = &panel_info.pxa;
746 unsigned short *palette = (unsigned short *)fbi->palette;
747 u_int val;
748
749 if (regno < fbi->palette_size) {
750 val = ((red << 8) & 0xf800);
751 val |= ((green << 4) & 0x07e0);
752 val |= (blue & 0x001f);
753
754#ifdef LCD_INVERT_COLORS
755 palette[regno] = ~val;
756#else
757 palette[regno] = ~val;
758#endif
759 }
760
761 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
762 regno, &palette[regno],
763 red, green, blue,
764 palette[regno]);
765}
766#endif /* LCD_COLOR8 */
767
768/*----------------------------------------------------------------------*/
769
770#if LCD_BPP == LCD_MONOCHROME
771static
772void lcd_initcolregs (void)
773{
774 volatile immap_t *immr = (immap_t *) CFG_IMMR;
775 volatile cpm8xx_t *cp = &(immr->im_cpm);
776 ushort regno;
777
778 for (regno = 0; regno < 16; regno++) {
779 cp->lcd_cmap[regno * 2] = 0;
780 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
781 }
782}
783#endif
784
785/*----------------------------------------------------------------------*/
786
787static void lcd_setfgcolor (int color)
788{
789 lcd_color_fg = color & 0x0F;
790}
791
792/*----------------------------------------------------------------------*/
793
794static void lcd_setbgcolor (int color)
795{
796 lcd_color_bg = color & 0x0F;
797}
798
799/*----------------------------------------------------------------------*/
800
801#ifdef NOT_USED_SO_FAR
802static int lcd_getfgcolor (void)
803{
804 return lcd_color_fg;
805}
806#endif /* NOT_USED_SO_FAR */
807
808/*----------------------------------------------------------------------*/
809
810#ifdef NOT_USED_SO_FAR
811static int lcd_getbgcolor (void)
812{
813 return lcd_color_bg;
814}
815#endif /* NOT_USED_SO_FAR */
816
817/*----------------------------------------------------------------------*/
818
819static void lcd_enable (void)
820{
821}
822
823/*----------------------------------------------------------------------*/
824
825#ifdef NOT_USED_SO_FAR
826static void lcd_disable (void)
827{
828}
829#endif /* NOT_USED_SO_FAR */
830
831
832/************************************************************************/
833/* ** Chipset depending Bitmap / Logo stuff... */
834/************************************************************************/
835
836#ifdef CONFIG_LCD_LOGO
837static void bitmap_plot (int x, int y)
838{
839 ushort *cmap;
840 ushort i;
841 uchar *bmap;
842 uchar *fb;
843 struct pxafb_info *fbi = &panel_info.pxa;
844
845 debug ("Logo: width %d height %d colors %d cmap %d\n",
846 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
847 sizeof(bmp_logo_palette)/(sizeof(ushort))
848 );
849
850 /* Leave room for default color map */
851 cmap = (ushort *)fbi->palette;
852
853 /* Set color map */
854 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
855 ushort colreg = bmp_logo_palette[i];
856#ifdef CFG_INVERT_COLORS
857 colreg ^= 0xFFF;
858#endif
859 *cmap++ = colreg;
860 }
861
862 bmap = &bmp_logo_bitmap[0];
863 fb = (char *)(lcd_base + y * lcd_line_length + x);
864
865 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
866 memcpy (fb, bmap, BMP_LOGO_WIDTH);
867 bmap += BMP_LOGO_WIDTH;
868 fb += panel_info.vl_col;
869 }
870}
871#endif /* CONFIG_LCD_LOGO */
872
873/*----------------------------------------------------------------------*/
874
875static void *lcd_logo (void)
876{
877#ifdef CONFIG_LCD_LOGO
878 DECLARE_GLOBAL_DATA_PTR;
879 char info[80];
880 char temp[32];
881
882 bitmap_plot (0, 0);
883#endif /* CONFIG_LCD_LOGO */
884
885#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
886 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
887#else
888 return ((void *)lcd_base);
889#endif /* CONFIG_LCD_LOGO */
890}
891
892/************************************************************************
893 PXA255 specific routines
894************************************************************************/
895
896static int pxafb_init_mem(void *lcdbase, vidinfo_t *vid)
897{
898 u_long palette_mem_size;
899 struct pxafb_info *fbi = &vid->pxa;
900 int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
901
902 fbi->screen = (u_long)lcdbase;
903
904 fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
905 palette_mem_size = fbi->palette_size * sizeof(u16);
906 debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
907 /* locate palette and descs at end of page following fb */
908 fbi->palette = (u_long)lcdbase + fb_size + 2*PAGE_SIZE - palette_mem_size;
909
910 return 0;
911}
912
913static void pxafb_setup_gpio(vidinfo_t *vid)
914{
915 u_long lccr0;
916
917 /*
918 * setup is based on type of panel supported
919 */
920
921 lccr0 = vid->pxa.reg_lccr0;
922
923 /* 4 bit interface */
924 if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
925 {
926 debug("Setting GPIO for 4 bit data\n");
927 /* bits 58-61 */
928 GPDR1 |= (0xf << 26);
929 GAFR1_U = (GAFR1_U & ~(0xff << 20)) | (0xaa << 20);
930
931 /* bits 74-77 */
932 GPDR2 |= (0xf << 10);
933 GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);
934 }
935
936 /* 8 bit interface */
937 else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||
938 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))
939 {
940 debug("Setting GPIO for 8 bit data\n");
941 /* bits 58-65 */
942 GPDR1 |= (0x3f << 26);
943 GPDR2 |= (0x3);
944
945 GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);
946 GAFR2_L = (GAFR2_L & ~0xf) | (0xa);
947
948 /* bits 74-77 */
949 GPDR2 |= (0xf << 10);
950 GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);
951 }
952
953 /* 16 bit interface */
954 else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
955 {
956 debug("Setting GPIO for 16 bit data\n");
957 /* bits 58-77 */
958 GPDR1 |= (0x3f << 26);
959 GPDR2 |= 0x00003fff;
960
961 GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);
962 GAFR2_L = (GAFR2_L & 0xf0000000) | 0x0aaaaaaa;
963 }
964 else
965 {
966 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
967 }
968}
969
970static void pxafb_enable_controller(vidinfo_t *vid)
971{
972 debug("Enabling LCD controller\n");
973
974 /* Sequence from 11.7.10 */
975 LCCR3 = vid->pxa.reg_lccr3;
976 LCCR2 = vid->pxa.reg_lccr2;
977 LCCR1 = vid->pxa.reg_lccr1;
978 LCCR0 = vid->pxa.reg_lccr0 & ~LCCR0_ENB;
979 FDADR0 = vid->pxa.fdadr0;
980 FDADR1 = vid->pxa.fdadr1;
981 LCCR0 |= LCCR0_ENB;
982
983 CKEN |= CKEN16_LCD;
984
985 debug("FDADR0 = 0x%08x\n", (unsigned int)FDADR0);
986 debug("FDADR1 = 0x%08x\n", (unsigned int)FDADR1);
987 debug("LCCR0 = 0x%08x\n", (unsigned int)LCCR0);
988 debug("LCCR1 = 0x%08x\n", (unsigned int)LCCR1);
989 debug("LCCR2 = 0x%08x\n", (unsigned int)LCCR2);
990 debug("LCCR3 = 0x%08x\n", (unsigned int)LCCR3);
991}
992
993static int pxafb_init(vidinfo_t *vid)
994{
995 struct pxafb_info *fbi = &vid->pxa;
996
997 debug("Configuring PXA LCD\n");
998
999 fbi->reg_lccr0 = REG_LCCR0;
1000 fbi->reg_lccr3 = REG_LCCR3;
1001
1002 debug("vid: vl_col=%d hslen=%d lm=%d rm=%d\n",
1003 vid->vl_col, vid->vl_hpw,
1004 vid->vl_blw, vid->vl_elw);
1005 debug("vid: vl_row=%d vslen=%d um=%d bm=%d\n",
1006 vid->vl_row, vid->vl_vpw,
1007 vid->vl_bfw, vid->vl_efw);
1008
1009 fbi->reg_lccr1 =
1010 LCCR1_DisWdth(vid->vl_col) +
1011 LCCR1_HorSnchWdth(vid->vl_hpw) +
1012 LCCR1_BegLnDel(vid->vl_blw) +
1013 LCCR1_EndLnDel(vid->vl_elw);
1014
1015 fbi->reg_lccr2 =
1016 LCCR2_DisHght(vid->vl_row) +
1017 LCCR2_VrtSnchWdth(vid->vl_vpw) +
1018 LCCR2_BegFrmDel(vid->vl_bfw) +
1019 LCCR2_EndFrmDel(vid->vl_efw);
1020
1021 fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
1022 fbi->reg_lccr3 |=
1023 (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
1024 | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
1025
1026
1027 /* setup dma descriptors */
1028 fbi->dmadesc_fblow = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 3*16);
1029 fbi->dmadesc_fbhigh = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
1030 fbi->dmadesc_palette = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
1031
1032 #define BYTES_PER_PANEL ((fbi->reg_lccr0 & LCCR0_SDS) ? \
1033 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8 / 2) : \
1034 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8))
1035
1036 /* populate descriptors */
1037 fbi->dmadesc_fblow->fdadr = (u_long)fbi->dmadesc_fblow;
1038 fbi->dmadesc_fblow->fsadr = fbi->screen + BYTES_PER_PANEL;
1039 fbi->dmadesc_fblow->fidr = 0;
1040 fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL;
1041
1042 fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
1043
1044 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
1045 fbi->dmadesc_fbhigh->fidr = 0;
1046 fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
1047
1048 fbi->dmadesc_palette->fsadr = fbi->palette;
1049 fbi->dmadesc_palette->fidr = 0;
1050 fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
1051
1052 if( NBITS(vid->vl_bpix) < 12)
1053 {
1054 /* assume any mode with <12 bpp is palette driven */
1055 fbi->dmadesc_palette->fdadr = (u_long)fbi->dmadesc_fbhigh;
1056 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_palette;
1057 /* flips back and forth between pal and fbhigh */
1058 fbi->fdadr0 = (u_long)fbi->dmadesc_palette;
1059 }
1060 else
1061 {
1062 /* palette shouldn't be loaded in true-color mode */
1063 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_fbhigh;
1064 fbi->fdadr0 = (u_long)fbi->dmadesc_fbhigh; /* no pal just fbhigh */
1065 }
1066
1067 debug("fbi->dmadesc_fblow = 0x%lx\n", (u_long)fbi->dmadesc_fblow);
1068 debug("fbi->dmadesc_fbhigh = 0x%lx\n", (u_long)fbi->dmadesc_fbhigh);
1069 debug("fbi->dmadesc_palette = 0x%lx\n", (u_long)fbi->dmadesc_palette);
1070
1071 debug("fbi->dmadesc_fblow->fdadr = 0x%lx\n", fbi->dmadesc_fblow->fdadr);
1072 debug("fbi->dmadesc_fbhigh->fdadr = 0x%lx\n", fbi->dmadesc_fbhigh->fdadr);
1073 debug("fbi->dmadesc_palette->fdadr = 0x%lx\n", fbi->dmadesc_palette->fdadr);
1074
1075 debug("fbi->dmadesc_fblow->fsadr = 0x%lx\n", fbi->dmadesc_fblow->fsadr);
1076 debug("fbi->dmadesc_fbhigh->fsadr = 0x%lx\n", fbi->dmadesc_fbhigh->fsadr);
1077 debug("fbi->dmadesc_palette->fsadr = 0x%lx\n", fbi->dmadesc_palette->fsadr);
1078
1079 debug("fbi->dmadesc_fblow->ldcmd = 0x%lx\n", fbi->dmadesc_fblow->ldcmd);
1080 debug("fbi->dmadesc_fbhigh->ldcmd = 0x%lx\n", fbi->dmadesc_fbhigh->ldcmd);
1081 debug("fbi->dmadesc_palette->ldcmd = 0x%lx\n", fbi->dmadesc_palette->ldcmd);
1082
1083 return 0;
1084}
1085
1086/************************************************************************/
1087/************************************************************************/
1088
1089#endif /* CONFIG_LCD */