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;
41 void lcd_setup(int lcd, int config)
45 * Set endianess and reset lcd controller 0 (small)
47 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */
48 udelay(10); /* wait 10us */
50 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
52 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
54 udelay(10); /* wait 10us */
55 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD0_RST); /* set reset to high */
58 * Set endianess and reset lcd controller 1 (big)
60 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD1_RST); /* set reset to low */
61 udelay(10); /* wait 10us */
63 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
65 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
67 udelay(10); /* wait 10us */
68 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD1_RST); /* set reset to high */
72 * CFG_LCD_ENDIAN may also be FPGA_RESET, so set inactive
74 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */
76 #endif /* #ifdef CFG_LCD_ENDIAN */
79 void lcd_bmp(uchar *logo_bmp)
85 unsigned char *dst = NULL;
87 int width, height, bpp, colors, line_size;
90 unsigned char r, g, b;
91 BITMAPINFOHEADER *bm_info;
95 * Check for bmp mark 'BM'
97 if (*(ushort *)logo_bmp != 0x424d) {
100 * Decompress bmp image
102 len = CFG_VIDEO_LOGO_MAX_SIZE;
103 dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
105 printf("Error: malloc in gunzip failed!\n");
108 if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) {
111 if (len == CFG_VIDEO_LOGO_MAX_SIZE) {
112 printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
116 * Check for bmp mark 'BM'
118 if (*(ushort *)dst != 0x424d) {
119 printf("LCD: Unknown image format!\n");
125 * Uncompressed BMP image, just use this pointer
127 dst = (uchar *)logo_bmp;
131 * Get image info from bmp-header
133 bm_info = (BITMAPINFOHEADER *)(dst + 14);
134 bpp = LOAD_SHORT(bm_info->biBitCount);
135 width = LOAD_LONG(bm_info->biWidth);
136 height = LOAD_LONG(bm_info->biHeight);
140 line_size = width >> 3;
144 line_size = width >> 1;
152 line_size = width * 3;
155 printf("LCD: Unknown bpp (%d) im image!\n", bpp);
156 if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
161 printf(" (%d*%d, %dbpp)\n", width, height, bpp);
164 * Write color palette
166 if ((colors <= 256) && (lcd_depth <= 8)) {
167 ptr = (unsigned char *)(dst + 14 + 40);
168 for (i=0; i<colors; i++) {
173 S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
178 * Write bitmap data into framebuffer
181 ptr2 = (ushort *)glob_lcd_mem;
182 header_size = 14 + 40 + 4*colors; /* skip bmp header */
183 for (y=0; y<height; y++) {
184 bmp = &dst[(height-1-y)*line_size + header_size];
185 if (lcd_depth == 16) {
187 for (x=0; x<width; x++) {
189 * Generate epson 16bpp fb-format from 24bpp image
194 val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
197 } else if (bpp == 8) {
198 for (x=0; x<line_size; x++) {
199 /* query rgb value from palette */
200 ptr = (unsigned char *)(dst + 14 + 40) ;
201 ptr += (*bmp++) << 2;
205 val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
210 for (x=0; x<line_size; x++) {
216 if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
222 void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
223 uchar *logo_bmp, ulong len)
233 out_8(&lcd_reg[0], 0x00);
234 out_8(&lcd_reg[1], 0x00);
236 if (in_8(&lcd_reg[0]) == 0x1c) {
240 reg_byte_swap = FALSE;
241 palette_index = 0x1e2;
242 palette_value = 0x1e4;
244 puts("LCD: S1D13806");
245 } else if (in_8(&lcd_reg[1]) == 0x1c) {
247 * Big epson detected (with register swap bug)
249 reg_byte_swap = TRUE;
250 palette_index = 0x1e3;
251 palette_value = 0x1e5;
253 puts("LCD: S1D13806S");
254 } else if (in_8(&lcd_reg[0]) == 0x18) {
256 * Small epson detected (704)
258 reg_byte_swap = FALSE;
259 palette_index = 0x15;
260 palette_value = 0x17;
262 puts("LCD: S1D13704");
263 } else if (in_8(&lcd_reg[0x10000]) == 0x24) {
265 * Small epson detected (705)
267 reg_byte_swap = FALSE;
268 palette_index = 0x15;
269 palette_value = 0x17;
271 lcd_reg += 0x10000; /* add offset for 705 regs */
272 puts("LCD: S1D13705");
274 puts("LCD: No controller detected!\n");
279 * Setup lcd controller regs
281 for (i = 0; i < reg_count; i++) {
282 s1dReg = regs[i].Index;
284 if ((s1dReg & 0x0001) == 0)
289 s1dValue = regs[i].Value;
290 lcd_reg[s1dReg] = s1dValue;
294 * Save reg & mem pointer for later usage (e.g. bmp command)
296 glob_lcd_reg = lcd_reg;
297 glob_lcd_mem = lcd_mem;
305 #ifdef CONFIG_VIDEO_SM501
306 int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
312 printf ("Usage:\n%s\n", cmdtp->usage);
316 addr = simple_strtoul(argv[1], NULL, 16);
318 str = getenv("bd_type");
319 if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
321 * SM501 available, use standard bmp command
323 return (video_display_bitmap(addr, 0, 0));
326 * No SM501 available, use esd epson bmp command
328 lcd_bmp((uchar *)addr);
334 esdbmp, 2, 1, do_esdbmp,
335 "esdbmp - display BMP image\n",
336 "<imageAddr> - display image\n"