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(CONFIG_SYS_LCD_ENDIAN)
41 void lcd_setup(int lcd, int config)
45 * Set endianess and reset lcd controller 0 (small)
48 /* set reset to low */
49 out_be32((void*)GPIO0_OR,
50 in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_LCD0_RST);
51 udelay(10); /* wait 10us */
54 out_be32((void*)GPIO0_OR,
55 in_be32((void*)GPIO0_OR) | CONFIG_SYS_LCD_ENDIAN);
58 out_be32((void*)GPIO0_OR,
59 in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_LCD_ENDIAN);
61 udelay(10); /* wait 10us */
62 /* set reset to high */
63 out_be32((void*)GPIO0_OR,
64 in_be32((void*)GPIO0_OR) | CONFIG_SYS_LCD0_RST);
67 * Set endianess and reset lcd controller 1 (big)
70 /* set reset to low */
71 out_be32((void*)GPIO0_OR,
72 in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_LCD1_RST);
73 udelay(10); /* wait 10us */
76 out_be32((void*)GPIO0_OR,
77 in_be32((void*)GPIO0_OR) | CONFIG_SYS_LCD_ENDIAN);
80 out_be32((void*)GPIO0_OR,
81 in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_LCD_ENDIAN);
83 udelay(10); /* wait 10us */
84 /* set reset to high */
85 out_be32((void*)GPIO0_OR,
86 in_be32((void*)GPIO0_OR) | CONFIG_SYS_LCD1_RST);
90 * CONFIG_SYS_LCD_ENDIAN may also be FPGA_RESET, so set inactive
92 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_LCD_ENDIAN);
94 #endif /* CONFIG_SYS_LCD_ENDIAN */
97 int lcd_bmp(uchar *logo_bmp)
103 unsigned char *dst = NULL;
105 int width, height, bpp, colors, line_size;
108 unsigned char r, g, b;
109 BITMAPINFOHEADER *bm_info;
113 * Check for bmp mark 'BM'
115 if (*(ushort *)logo_bmp != 0x424d) {
117 * Decompress bmp image
119 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
120 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
122 printf("Error: malloc for gunzip failed!\n");
125 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
126 (uchar *)logo_bmp, &len) != 0) {
130 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
131 printf("Image could be truncated"
132 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
136 * Check for bmp mark 'BM'
138 if (*(ushort *)dst != 0x424d) {
139 printf("LCD: Unknown image format!\n");
145 * Uncompressed BMP image, just use this pointer
147 dst = (uchar *)logo_bmp;
151 * Get image info from bmp-header
153 bm_info = (BITMAPINFOHEADER *)(dst + 14);
154 bpp = LOAD_SHORT(bm_info->biBitCount);
155 width = LOAD_LONG(bm_info->biWidth);
156 height = LOAD_LONG(bm_info->biHeight);
160 line_size = width >> 3;
164 line_size = width >> 1;
172 line_size = width * 3;
175 printf("LCD: Unknown bpp (%d) im image!\n", bpp);
176 if ((dst != NULL) && (dst != (uchar *)logo_bmp))
180 printf(" (%d*%d, %dbpp)\n", width, height, bpp);
183 * Write color palette
185 if ((colors <= 256) && (lcd_depth <= 8)) {
186 ptr = (unsigned char *)(dst + 14 + 40);
187 for (i = 0; i < colors; i++) {
192 S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
197 * Write bitmap data into framebuffer
200 ptr2 = (ushort *)glob_lcd_mem;
201 header_size = 14 + 40 + 4*colors; /* skip bmp header */
202 for (y = 0; y < height; y++) {
203 bmp = &dst[(height-1-y)*line_size + header_size];
204 if (lcd_depth == 16) {
206 for (x = 0; x < width; x++) {
208 * Generate epson 16bpp fb-format
214 val = ((r & 0x1f) << 11) |
219 } else if (bpp == 8) {
220 for (x = 0; x < line_size; x++) {
221 /* query rgb value from palette */
222 ptr = (unsigned char *)(dst + 14 + 40);
223 ptr += (*bmp++) << 2;
227 val = ((r & 0x1f) << 11) |
234 for (x = 0; x < line_size; x++)
239 if ((dst != NULL) && (dst != (uchar *)logo_bmp))
245 int lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
246 uchar *logo_bmp, ulong len)
256 out_8(&lcd_reg[0], 0x00);
257 out_8(&lcd_reg[1], 0x00);
259 if (in_8(&lcd_reg[0]) == 0x1c) {
263 reg_byte_swap = FALSE;
264 palette_index = 0x1e2;
265 palette_value = 0x1e4;
267 puts("LCD: S1D13806");
268 } else if (in_8(&lcd_reg[1]) == 0x1c) {
270 * Big epson detected (with register swap bug)
272 reg_byte_swap = TRUE;
273 palette_index = 0x1e3;
274 palette_value = 0x1e5;
276 puts("LCD: S1D13806S");
277 } else if (in_8(&lcd_reg[0]) == 0x18) {
279 * Small epson detected (704)
281 reg_byte_swap = FALSE;
282 palette_index = 0x15;
283 palette_value = 0x17;
285 puts("LCD: S1D13704");
286 } else if (in_8(&lcd_reg[0x10000]) == 0x24) {
288 * Small epson detected (705)
290 reg_byte_swap = FALSE;
291 palette_index = 0x15;
292 palette_value = 0x17;
294 lcd_reg += 0x10000; /* add offset for 705 regs */
295 puts("LCD: S1D13705");
297 out_8(&lcd_reg[0x1a], 0x00);
299 if (in_8(&lcd_reg[1]) == 0x0c) {
303 reg_byte_swap = TRUE;
304 palette_index = 0x25;
305 palette_value = 0x27;
308 puts("LCD: S1D13505");
310 puts("LCD: No controller detected!\n");
316 * Setup lcd controller regs
318 for (i = 0; i < reg_count; i++) {
319 s1dReg = regs[i].Index;
321 if ((s1dReg & 0x0001) == 0)
326 s1dValue = regs[i].Value;
327 out_8(&lcd_reg[s1dReg], s1dValue);
331 * Save reg & mem pointer for later usage (e.g. bmp command)
333 glob_lcd_reg = lcd_reg;
334 glob_lcd_mem = lcd_mem;
339 return lcd_bmp(logo_bmp);
342 int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
345 #ifdef CONFIG_VIDEO_SM501
349 return cmd_usage(cmdtp);
351 addr = simple_strtoul(argv[1], NULL, 16);
353 #ifdef CONFIG_VIDEO_SM501
354 str = getenv("bd_type");
355 if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
357 * SM501 available, use standard bmp command
359 return video_display_bitmap(addr, 0, 0);
362 * No SM501 available, use esd epson bmp command
364 return lcd_bmp((uchar *)addr);
367 return lcd_bmp((uchar *)addr);
372 esdbmp, 2, 1, do_esdbmp,
374 "<imageAddr> - display image"