2 * (C) Copyright 2001-2002
3 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 /************************************************************************/
26 /************************************************************************/
34 #include <linux/types.h>
36 #include <asm/arch/pxa-regs.h>
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 */
49 #undef CONFIG_LCD_LOGO
53 #undef CONFIG_LCD_LOGO
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 /************************************************************************/
60 /************************************************************************/
61 /* ** FONT AND LOGO DATA */
62 /************************************************************************/
64 #include <video_font.h> /* Get font data, width and height */
66 #ifdef CONFIG_LCD_LOGO
67 # include <bmp_nexus.h> /* Get logo data, width and height */
70 /************************************************************************/
71 /************************************************************************/
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.
78 #define CFG_HIGH 0 /* Pins are active high */
79 #define CFG_LOW 1 /* Pins are active low */
81 /* PXA LCD DMA descriptor */
82 struct pxafb_dma_descriptor {
100 /* DMA descriptors */
101 struct pxafb_dma_descriptor * dmadesc_fblow;
102 struct pxafb_dma_descriptor * dmadesc_fbhigh;
103 struct pxafb_dma_descriptor * dmadesc_palette;
105 u_long screen; /* physical address of frame buffer */
106 u_long palette; /* physical address of palette memory */
110 typedef 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 */
116 /* LCD configuration register.
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 */
129 /* Horizontal control register. Timing from data sheet.
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 */
135 /* Vertical control register.
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 */
141 u_char vl_lcdac; /* LCD AC timing */
143 /* PXA LCD controller params
145 struct pxafb_info pxa;
149 #define LCD_MONOCHROME 0
153 #define LCD_COLOR16 4
155 /*----------------------------------------------------------------------*/
156 #define CONFIG_PXA_VGA
157 #ifdef CONFIG_PXA_VGA
159 * LCD outputs connected to a video DAC
162 #define LCD_BPP LCD_COLOR8
164 /* you have to set lccr0 and lccr3 (including pcd) */
165 #define REG_LCCR0 0x003008f8
166 #define REG_LCCR3 0x0300FF01
168 /* 640x480x16 @ 61 Hz */
169 static vidinfo_t panel_info = {
192 #endif /* CONFIG_PXA_VIDEO */
194 #ifdef CONFIG_SHARP_LM8V31
196 #define LCD_BPP LCD_COLOR8
197 #define LCD_INVERT_COLORS /* Needed for colors to be correct, but why? */
199 /* you have to set lccr0 and lccr3 (including pcd) */
200 #define REG_LCCR0 0x0030087C
201 #define REG_LCCR3 0x0340FF08
203 static vidinfo_t panel_info = {
226 #endif /* CONFIG_SHARP_LM8V31 */
228 /*----------------------------------------------------------------------*/
230 /*----------------------------------------------------------------------*/
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)
239 # define LCD_INFO_X (VIDEO_FONT_WIDTH)
240 # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
244 #define LCD_BPP LCD_COLOR8
250 #define NBITS(bit_code) (1 << (bit_code))
251 #define NCOLORS(bit_code) (1 << NBITS(bit_code))
253 static int lcd_line_length;
255 static int lcd_color_fg;
256 static int lcd_color_bg;
258 static char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
261 * Frame buffer memory information
263 static void *lcd_base; /* Start of framebuffer memory */
264 static void *lcd_console_address; /* Start of console buffer */
267 /************************************************************************/
268 /* ** CONSOLE CONSTANTS */
269 /************************************************************************/
271 #if LCD_BPP == LCD_MONOCHROME
274 * Simple color definitions
276 #define CONSOLE_COLOR_BLACK 0
277 #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
279 #elif LCD_BPP == LCD_COLOR8
282 * Simple color definitions
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 */
296 #define CONSOLE_COLOR_BLACK 0x0000
297 #define CONSOLE_COLOR_WHITE 0xffff /* Must remain last / highest */
301 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
302 #error Default Color Map overlaps with Logo Color Map
305 /************************************************************************/
308 #define PAGE_SIZE 4096
312 /************************************************************************/
313 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
314 /************************************************************************/
316 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
317 #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
320 #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
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 \
328 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
329 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
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)
339 #error Unsupported LCD BPP.
342 static short console_col;
343 static short console_row;
345 /************************************************************************/
347 ulong lcd_setmem (ulong addr);
349 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
350 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
351 static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
353 static int lcd_init (void *lcdbase);
354 static void lcd_ctrl_init (void *lcdbase);
355 static void lcd_enable (void);
356 static void *lcd_logo (void);
357 #if LCD_BPP == LCD_COLOR8
358 static void lcd_setcolreg (ushort regno,
359 ushort red, ushort green, ushort blue);
361 #if LCD_BPP == LCD_MONOCHROME
362 static void lcd_initcolregs (void);
364 static void lcd_setfgcolor (int color);
365 static void lcd_setbgcolor (int color);
367 #ifdef NOT_USED_SO_FAR
368 static int lcd_getbgcolor (void);
369 static void lcd_disable (void);
370 static void lcd_getcolreg (ushort regno,
371 ushort *red, ushort *green, ushort *blue);
372 static int lcd_getfgcolor (void);
373 #endif /* NOT_USED_SO_FAR */
376 static int pxafb_init_mem(void *lcdbase, vidinfo_t *vid);
377 static void pxafb_setup_gpio(vidinfo_t *vid);
378 static void pxafb_enable_controller(vidinfo_t *vid);
379 static int pxafb_init(vidinfo_t *vid);
381 /************************************************************************/
383 /*----------------------------------------------------------------------*/
385 static void console_scrollup (void)
387 /* Copy up rows ignoring the first one */
388 memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
390 /* Clear the last one */
391 memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
394 /*----------------------------------------------------------------------*/
396 static inline void console_back (void)
398 if (--console_col < 0) {
399 console_col = CONSOLE_COLS-1 ;
400 if (--console_row < 0) {
405 lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
406 console_row * VIDEO_FONT_HEIGHT,
410 /*----------------------------------------------------------------------*/
412 static inline void console_newline (void)
417 /* Check if we need to scroll the terminal */
418 if (console_row >= CONSOLE_ROWS) {
419 /* Scroll everything up */
420 console_scrollup () ;
425 /*----------------------------------------------------------------------*/
427 void lcd_putc (const char c)
429 if (!lcd_is_enabled) {
435 case '\r': console_col = 0;
438 case '\n': console_newline();
441 case '\t': /* Tab (8 chars alignment) */
445 if (console_col >= CONSOLE_COLS) {
450 case '\b': console_back();
453 default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
454 console_row * VIDEO_FONT_HEIGHT,
456 if (++console_col >= CONSOLE_COLS) {
464 /*----------------------------------------------------------------------*/
466 void lcd_puts (const char *s)
468 if (!lcd_is_enabled) {
478 /************************************************************************/
479 /* ** Low-Level Graphics Routines */
480 /************************************************************************/
482 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
487 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
488 off = x * (1 << LCD_BPP) % 8;
490 for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
495 #if LCD_BPP == LCD_MONOCHROME
496 uchar rest = *d & -(1 << (8-off));
499 for (i=0; i<count; ++i) {
503 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
505 #if LCD_BPP == LCD_MONOCHROME
506 sym = (COLOR_MASK(lcd_color_fg) & bits) |
507 (COLOR_MASK(lcd_color_bg) & ~bits);
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;
517 #elif LCD_BPP == LCD_COLOR16
518 for (c=0; c<16; ++c) {
519 *d++ = (bits & 0x80) ?
520 lcd_color_fg : lcd_color_bg;
526 #if LCD_BPP == LCD_MONOCHROME
527 *d = rest | (*d & ((1 << (8-off)) - 1));
532 /*----------------------------------------------------------------------*/
534 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
536 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
537 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
539 lcd_drawchars (x, y, s, strlen (s));
543 /*----------------------------------------------------------------------*/
545 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
547 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
548 lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
550 lcd_drawchars (x, y, &c, 1);
554 /************************************************************************/
555 /** Small utility to check that you got the colours right */
556 /************************************************************************/
557 #ifdef LCD_TEST_PATTERN
562 static 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,
567 static void test_pattern (void)
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;
574 uchar *pix = (uchar *)lcd_base;
576 printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
577 h_max, v_max, h_step, v_step);
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];
588 #endif /* LCD_TEST_PATTERN */
591 /************************************************************************/
592 /* ** GENERIC Initialization Routines */
593 /************************************************************************/
595 int drv_lcd_init (void)
597 DECLARE_GLOBAL_DATA_PTR;
602 lcd_base = (void *)(gd->fb_base);
604 lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
606 lcd_init (lcd_base); /* LCD initialization */
608 /* Device initialization */
609 memset (&lcddev, 0, sizeof (lcddev));
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 */
617 rc = device_register (&lcddev);
618 return (rc == 0) ? 1 : rc;
621 /*----------------------------------------------------------------------*/
623 static int lcd_init (void *lcdbase)
625 /* Initialize the lcd controller */
626 debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
628 lcd_ctrl_init (lcdbase);
630 #if LCD_BPP == LCD_MONOCHROME
631 /* Setting the palette */
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);
647 #define CFG_WHITE_ON_BLACK
648 #ifndef CFG_WHITE_ON_BLACK
649 lcd_setfgcolor (CONSOLE_COLOR_BLACK);
650 lcd_setbgcolor (CONSOLE_COLOR_WHITE);
652 lcd_setfgcolor (CONSOLE_COLOR_WHITE);
653 lcd_setbgcolor (CONSOLE_COLOR_BLACK);
654 #endif /* CFG_WHITE_ON_BLACK */
656 #ifdef LCD_TEST_PATTERN
659 /* set framebuffer to background color */
660 memset ((char *)lcd_base,
661 COLOR_MASK(lcd_getbgcolor()),
662 lcd_line_length*panel_info.vl_row);
667 /* Paint the logo and retrieve LCD base address */
668 debug ("[LCD] Drawing the logo...\n");
669 lcd_console_address = lcd_logo ();
671 /* Initialize the console */
673 #ifdef LCD_INFO_BELOW_LOGO
674 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
676 console_row = 1; /* leave 1 blank line below logo */
684 /************************************************************************/
685 /* ** ROM capable initialization part - needed to reserve FB memory */
686 /************************************************************************/
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
693 * Note that this is running from ROM, so no write access to global data.
695 ulong lcd_setmem (ulong addr)
698 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
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) );
703 /* extra page for dma descriptors and palette */
704 size = line_length * panel_info.vl_row + PAGE_SIZE;
706 /* Round up to nearest full page */
707 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
709 /* Allocate pages for the frame buffer. */
712 debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
718 /************************************************************************/
719 /* ----------------- chipset specific functions ----------------------- */
720 /************************************************************************/
722 static void lcd_ctrl_init (void *lcdbase)
724 pxafb_init_mem(lcdbase, &panel_info);
725 pxafb_init(&panel_info);
726 pxafb_setup_gpio(&panel_info);
727 pxafb_enable_controller(&panel_info);
730 /*----------------------------------------------------------------------*/
732 #ifdef NOT_USED_SO_FAR
734 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
737 #endif /* NOT_USED_SO_FAR */
739 /*----------------------------------------------------------------------*/
741 #if LCD_BPP == LCD_COLOR8
743 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
745 struct pxafb_info *fbi = &panel_info.pxa;
746 unsigned short *palette = (unsigned short *)fbi->palette;
749 if (regno < fbi->palette_size) {
750 val = ((red << 8) & 0xf800);
751 val |= ((green << 4) & 0x07e0);
752 val |= (blue & 0x001f);
754 #ifdef LCD_INVERT_COLORS
755 palette[regno] = ~val;
757 palette[regno] = ~val;
761 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
762 regno, &palette[regno],
766 #endif /* LCD_COLOR8 */
768 /*----------------------------------------------------------------------*/
770 #if LCD_BPP == LCD_MONOCHROME
772 void lcd_initcolregs (void)
774 volatile immap_t *immr = (immap_t *) CFG_IMMR;
775 volatile cpm8xx_t *cp = &(immr->im_cpm);
778 for (regno = 0; regno < 16; regno++) {
779 cp->lcd_cmap[regno * 2] = 0;
780 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
785 /*----------------------------------------------------------------------*/
787 static void lcd_setfgcolor (int color)
789 lcd_color_fg = color & 0x0F;
792 /*----------------------------------------------------------------------*/
794 static void lcd_setbgcolor (int color)
796 lcd_color_bg = color & 0x0F;
799 /*----------------------------------------------------------------------*/
801 #ifdef NOT_USED_SO_FAR
802 static int lcd_getfgcolor (void)
806 #endif /* NOT_USED_SO_FAR */
808 /*----------------------------------------------------------------------*/
810 #ifdef NOT_USED_SO_FAR
811 static int lcd_getbgcolor (void)
815 #endif /* NOT_USED_SO_FAR */
817 /*----------------------------------------------------------------------*/
819 static void lcd_enable (void)
823 /*----------------------------------------------------------------------*/
825 #ifdef NOT_USED_SO_FAR
826 static void lcd_disable (void)
829 #endif /* NOT_USED_SO_FAR */
832 /************************************************************************/
833 /* ** Chipset depending Bitmap / Logo stuff... */
834 /************************************************************************/
836 #ifdef CONFIG_LCD_LOGO
837 static void bitmap_plot (int x, int y)
843 struct pxafb_info *fbi = &panel_info.pxa;
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))
850 /* Leave room for default color map */
851 cmap = (ushort *)fbi->palette;
854 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
855 ushort colreg = bmp_logo_palette[i];
856 #ifdef CFG_INVERT_COLORS
862 bmap = &bmp_logo_bitmap[0];
863 fb = (char *)(lcd_base + y * lcd_line_length + x);
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;
871 #endif /* CONFIG_LCD_LOGO */
873 /*----------------------------------------------------------------------*/
875 static void *lcd_logo (void)
877 #ifdef CONFIG_LCD_LOGO
878 DECLARE_GLOBAL_DATA_PTR;
883 #endif /* CONFIG_LCD_LOGO */
885 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
886 return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
888 return ((void *)lcd_base);
889 #endif /* CONFIG_LCD_LOGO */
892 /************************************************************************
893 PXA255 specific routines
894 ************************************************************************/
896 static int pxafb_init_mem(void *lcdbase, vidinfo_t *vid)
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;
902 fbi->screen = (u_long)lcdbase;
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;
913 static void pxafb_setup_gpio(vidinfo_t *vid)
918 * setup is based on type of panel supported
921 lccr0 = vid->pxa.reg_lccr0;
923 /* 4 bit interface */
924 if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
926 debug("Setting GPIO for 4 bit data\n");
928 GPDR1 |= (0xf << 26);
929 GAFR1_U = (GAFR1_U & ~(0xff << 20)) | (0xaa << 20);
932 GPDR2 |= (0xf << 10);
933 GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);
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)))
940 debug("Setting GPIO for 8 bit data\n");
942 GPDR1 |= (0x3f << 26);
945 GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);
946 GAFR2_L = (GAFR2_L & ~0xf) | (0xa);
949 GPDR2 |= (0xf << 10);
950 GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);
953 /* 16 bit interface */
954 else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
956 debug("Setting GPIO for 16 bit data\n");
958 GPDR1 |= (0x3f << 26);
961 GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);
962 GAFR2_L = (GAFR2_L & 0xf0000000) | 0x0aaaaaaa;
966 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
970 static void pxafb_enable_controller(vidinfo_t *vid)
972 debug("Enabling LCD controller\n");
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;
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);
993 static int pxafb_init(vidinfo_t *vid)
995 struct pxafb_info *fbi = &vid->pxa;
997 debug("Configuring PXA LCD\n");
999 fbi->reg_lccr0 = REG_LCCR0;
1000 fbi->reg_lccr3 = REG_LCCR3;
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);
1010 LCCR1_DisWdth(vid->vl_col) +
1011 LCCR1_HorSnchWdth(vid->vl_hpw) +
1012 LCCR1_BegLnDel(vid->vl_blw) +
1013 LCCR1_EndLnDel(vid->vl_elw);
1016 LCCR2_DisHght(vid->vl_row) +
1017 LCCR2_VrtSnchWdth(vid->vl_vpw) +
1018 LCCR2_BegFrmDel(vid->vl_bfw) +
1019 LCCR2_EndFrmDel(vid->vl_efw);
1021 fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
1023 (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
1024 | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
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);
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))
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;
1042 fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
1044 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
1045 fbi->dmadesc_fbhigh->fidr = 0;
1046 fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
1048 fbi->dmadesc_palette->fsadr = fbi->palette;
1049 fbi->dmadesc_palette->fidr = 0;
1050 fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
1052 if( NBITS(vid->vl_bpix) < 12)
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;
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 */
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);
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);
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);
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);
1086 /************************************************************************/
1087 /************************************************************************/
1089 #endif /* CONFIG_LCD */