2 * (C) Copyright 2003-2004
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
6 * Stefan Roese, DENX Software Engineering, sr@denx.de.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 extern int video_display_bitmap (ulong, int, int);
37 unsigned char *glob_lcd_reg;
38 unsigned char *glob_lcd_mem;
40 #if defined(CFG_LCD_ENDIAN)
41 void lcd_setup(int lcd, int config)
45 * Set endianess and reset lcd controller 0 (small)
47 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */
48 udelay(10); /* wait 10us */
50 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
52 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
53 udelay(10); /* wait 10us */
54 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_LCD0_RST); /* set reset to high */
57 * Set endianess and reset lcd controller 1 (big)
59 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CFG_LCD1_RST); /* set reset to low */
60 udelay(10); /* wait 10us */
62 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
64 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
65 udelay(10); /* wait 10us */
66 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_LCD1_RST); /* set reset to high */
70 * CFG_LCD_ENDIAN may also be FPGA_RESET, so set inactive
72 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */
74 #endif /* CFG_LCD_ENDIAN */
77 void lcd_bmp(uchar *logo_bmp)
83 unsigned char *dst = NULL;
85 int width, height, bpp, colors, line_size;
88 unsigned char r, g, b;
89 BITMAPINFOHEADER *bm_info;
93 * Check for bmp mark 'BM'
95 if (*(ushort *)logo_bmp != 0x424d) {
97 * Decompress bmp image
99 len = CFG_VIDEO_LOGO_MAX_SIZE;
100 dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
102 printf("Error: malloc in gunzip failed!\n");
105 if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0)
107 if (len == CFG_VIDEO_LOGO_MAX_SIZE)
108 printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
111 * Check for bmp mark 'BM'
113 if (*(ushort *)dst != 0x424d) {
114 printf("LCD: Unknown image format!\n");
120 * Uncompressed BMP image, just use this pointer
122 dst = (uchar *)logo_bmp;
126 * Get image info from bmp-header
128 bm_info = (BITMAPINFOHEADER *)(dst + 14);
129 bpp = LOAD_SHORT(bm_info->biBitCount);
130 width = LOAD_LONG(bm_info->biWidth);
131 height = LOAD_LONG(bm_info->biHeight);
135 line_size = width >> 3;
139 line_size = width >> 1;
147 line_size = width * 3;
150 printf("LCD: Unknown bpp (%d) im image!\n", bpp);
151 if ((dst != NULL) && (dst != (uchar *)logo_bmp))
155 printf(" (%d*%d, %dbpp)\n", width, height, bpp);
158 * Write color palette
160 if ((colors <= 256) && (lcd_depth <= 8)) {
161 ptr = (unsigned char *)(dst + 14 + 40);
162 for (i = 0; i < colors; i++) {
167 S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
172 * Write bitmap data into framebuffer
175 ptr2 = (ushort *)glob_lcd_mem;
176 header_size = 14 + 40 + 4*colors; /* skip bmp header */
177 for (y = 0; y < height; y++) {
178 bmp = &dst[(height-1-y)*line_size + header_size];
179 if (lcd_depth == 16) {
181 for (x = 0; x < width; x++) {
183 * Generate epson 16bpp fb-format from 24bpp image
188 val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
191 } else if (bpp == 8) {
192 for (x = 0; x < line_size; x++) {
193 /* query rgb value from palette */
194 ptr = (unsigned char *)(dst + 14 + 40) ;
195 ptr += (*bmp++) << 2;
199 val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
204 for (x = 0; x < line_size; x++)
209 if ((dst != NULL) && (dst != (uchar *)logo_bmp))
214 void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
215 uchar *logo_bmp, ulong len)
225 out_8(&lcd_reg[0], 0x00);
226 out_8(&lcd_reg[1], 0x00);
228 if (in_8(&lcd_reg[0]) == 0x1c) {
232 reg_byte_swap = FALSE;
233 palette_index = 0x1e2;
234 palette_value = 0x1e4;
236 puts("LCD: S1D13806");
237 } else if (in_8(&lcd_reg[1]) == 0x1c) {
239 * Big epson detected (with register swap bug)
241 reg_byte_swap = TRUE;
242 palette_index = 0x1e3;
243 palette_value = 0x1e5;
245 puts("LCD: S1D13806S");
246 } else if (in_8(&lcd_reg[0]) == 0x18) {
248 * Small epson detected (704)
250 reg_byte_swap = FALSE;
251 palette_index = 0x15;
252 palette_value = 0x17;
254 puts("LCD: S1D13704");
255 } else if (in_8(&lcd_reg[0x10000]) == 0x24) {
257 * Small epson detected (705)
259 reg_byte_swap = FALSE;
260 palette_index = 0x15;
261 palette_value = 0x17;
263 lcd_reg += 0x10000; /* add offset for 705 regs */
264 puts("LCD: S1D13705");
266 puts("LCD: No controller detected!\n");
271 * Setup lcd controller regs
273 for (i = 0; i < reg_count; i++) {
274 s1dReg = regs[i].Index;
276 if ((s1dReg & 0x0001) == 0)
281 s1dValue = regs[i].Value;
282 lcd_reg[s1dReg] = s1dValue;
286 * Save reg & mem pointer for later usage (e.g. bmp command)
288 glob_lcd_reg = lcd_reg;
289 glob_lcd_mem = lcd_mem;
297 #if defined(CONFIG_VIDEO_SM501)
298 int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
304 printf ("Usage:\n%s\n", cmdtp->usage);
308 addr = simple_strtoul(argv[1], NULL, 16);
310 str = getenv("bd_type");
311 if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
313 * SM501 available, use standard bmp command
315 return (video_display_bitmap(addr, 0, 0));
318 * No SM501 available, use esd epson bmp command
320 lcd_bmp((uchar *)addr);
326 esdbmp, 2, 1, do_esdbmp,
327 "esdbmp - display BMP image\n",
328 "<imageAddr> - display image\n"