blob: 0edc08308a1320d0bc7db82e54d5443988ee7d34 [file] [log] [blame]
stroese56b9e4f2004-12-16 18:43:13 +00001/*
2 * (C) Copyright 2003-2004
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Stefan Roesed9d97742005-09-22 09:04:17 +02005 * (C) Copyright 2005
6 * Stefan Roese, DENX Software Engineering, sr@denx.de.
7 *
stroese56b9e4f2004-12-16 18:43:13 +00008 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
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.
15 *
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.
20 *
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,
24 * MA 02111-1307 USA
25 */
26
27#include "lcd.h"
28
Stefan Roesed9d97742005-09-22 09:04:17 +020029
30extern int video_display_bitmap (ulong, int, int);
31
stroese56b9e4f2004-12-16 18:43:13 +000032
33int palette_index;
34int palette_value;
Stefan Roesed9d97742005-09-22 09:04:17 +020035int lcd_depth;
36unsigned char *glob_lcd_reg;
37unsigned char *glob_lcd_mem;
stroese56b9e4f2004-12-16 18:43:13 +000038
39#ifdef CFG_LCD_ENDIAN
40void lcd_setup(int lcd, int config)
41{
42 if (lcd == 0) {
43 /*
44 * Set endianess and reset lcd controller 0 (small)
45 */
46 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */
47 udelay(10); /* wait 10us */
48 if (config == 1) {
49 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
50 } else {
51 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
52 }
53 udelay(10); /* wait 10us */
54 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD0_RST); /* set reset to high */
55 } else {
56 /*
57 * Set endianess and reset lcd controller 1 (big)
58 */
59 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD1_RST); /* set reset to low */
60 udelay(10); /* wait 10us */
61 if (config == 1) {
62 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
63 } else {
64 out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
65 }
66 udelay(10); /* wait 10us */
67 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD1_RST); /* set reset to high */
68 }
69
70 /*
71 * CFG_LCD_ENDIAN may also be FPGA_RESET, so set inactive
72 */
73 out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */
74}
75#endif /* #ifdef CFG_LCD_ENDIAN */
76
77
Stefan Roesed9d97742005-09-22 09:04:17 +020078void lcd_bmp(uchar *logo_bmp)
stroese56b9e4f2004-12-16 18:43:13 +000079{
80 int i;
stroese56b9e4f2004-12-16 18:43:13 +000081 uchar *ptr;
82 ushort *ptr2;
83 ushort val;
Stefan Roese13b93692005-10-08 10:19:07 +020084 unsigned char *dst = NULL;
stroese56b9e4f2004-12-16 18:43:13 +000085 int x, y;
86 int width, height, bpp, colors, line_size;
87 int header_size;
88 unsigned char *bmp;
89 unsigned char r, g, b;
90 BITMAPINFOHEADER *bm_info;
Stefan Roesed9d97742005-09-22 09:04:17 +020091 ulong len;
stroese56b9e4f2004-12-16 18:43:13 +000092
93 /*
Stefan Roesed9d97742005-09-22 09:04:17 +020094 * Check for bmp mark 'BM'
stroese56b9e4f2004-12-16 18:43:13 +000095 */
Stefan Roesed9d97742005-09-22 09:04:17 +020096 if (*(ushort *)logo_bmp != 0x424d) {
97
stroese56b9e4f2004-12-16 18:43:13 +000098 /*
Stefan Roesed9d97742005-09-22 09:04:17 +020099 * Decompress bmp image
stroese56b9e4f2004-12-16 18:43:13 +0000100 */
Stefan Roese13b93692005-10-08 10:19:07 +0200101 len = CFG_VIDEO_LOGO_MAX_SIZE;
102 dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
103 if (dst == NULL) {
104 printf("Error: malloc in gunzip failed!\n");
Stefan Roesed9d97742005-09-22 09:04:17 +0200105 return;
106 }
Stefan Roese13b93692005-10-08 10:19:07 +0200107 if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) {
108 return;
109 }
110 if (len == CFG_VIDEO_LOGO_MAX_SIZE) {
111 printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
112 }
Stefan Roesed9d97742005-09-22 09:04:17 +0200113
stroese56b9e4f2004-12-16 18:43:13 +0000114 /*
Stefan Roesed9d97742005-09-22 09:04:17 +0200115 * Check for bmp mark 'BM'
stroese56b9e4f2004-12-16 18:43:13 +0000116 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200117 if (*(ushort *)dst != 0x424d) {
118 printf("LCD: Unknown image format!\n");
119 free(dst);
120 return;
121 }
122 } else {
stroese56b9e4f2004-12-16 18:43:13 +0000123 /*
Stefan Roesed9d97742005-09-22 09:04:17 +0200124 * Uncompressed BMP image, just use this pointer
stroese56b9e4f2004-12-16 18:43:13 +0000125 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200126 dst = (uchar *)logo_bmp;
wdenk07d7e6b2004-12-16 21:44:03 +0000127 }
stroese56b9e4f2004-12-16 18:43:13 +0000128
129 /*
stroese56b9e4f2004-12-16 18:43:13 +0000130 * Get image info from bmp-header
131 */
132 bm_info = (BITMAPINFOHEADER *)(dst + 14);
133 bpp = LOAD_SHORT(bm_info->biBitCount);
134 width = LOAD_LONG(bm_info->biWidth);
135 height = LOAD_LONG(bm_info->biHeight);
136 switch (bpp) {
137 case 1:
138 colors = 1;
139 line_size = width >> 3;
140 break;
141 case 4:
142 colors = 16;
143 line_size = width >> 1;
144 break;
145 case 8:
146 colors = 256;
147 line_size = width;
148 break;
149 case 24:
150 colors = 0;
151 line_size = width * 3;
152 break;
153 default:
154 printf("LCD: Unknown bpp (%d) im image!\n", bpp);
Stefan Roese13b93692005-10-08 10:19:07 +0200155 if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
156 free(dst);
157 }
stroese56b9e4f2004-12-16 18:43:13 +0000158 return;
159 }
160 printf(" (%d*%d, %dbpp)\n", width, height, bpp);
161
162 /*
163 * Write color palette
164 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200165 if ((colors <= 256) && (lcd_depth <= 8)) {
stroese56b9e4f2004-12-16 18:43:13 +0000166 ptr = (unsigned char *)(dst + 14 + 40);
167 for (i=0; i<colors; i++) {
168 b = *ptr++;
169 g = *ptr++;
170 r = *ptr++;
171 ptr++;
Stefan Roesed9d97742005-09-22 09:04:17 +0200172 S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
stroese56b9e4f2004-12-16 18:43:13 +0000173 }
174 }
175
176 /*
177 * Write bitmap data into framebuffer
178 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200179 ptr = glob_lcd_mem;
180 ptr2 = (ushort *)glob_lcd_mem;
stroese56b9e4f2004-12-16 18:43:13 +0000181 header_size = 14 + 40 + 4*colors; /* skip bmp header */
182 for (y=0; y<height; y++) {
183 bmp = &dst[(height-1-y)*line_size + header_size];
Stefan Roesed9d97742005-09-22 09:04:17 +0200184 if (lcd_depth == 16) {
185 if (bpp == 24) {
186 for (x=0; x<width; x++) {
187 /*
188 * Generate epson 16bpp fb-format from 24bpp image
189 */
190 b = *bmp++ >> 3;
191 g = *bmp++ >> 2;
192 r = *bmp++ >> 3;
193 val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
194 *ptr2++ = val;
195 }
196 } else if (bpp == 8) {
197 for (x=0; x<line_size; x++) {
198 /* query rgb value from palette */
199 ptr = (unsigned char *)(dst + 14 + 40) ;
200 ptr += (*bmp++) << 2;
201 b = *ptr++ >> 3;
202 g = *ptr++ >> 2;
203 r = *ptr++ >> 3;
204 val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
205 *ptr2++ = val;
206 }
stroese56b9e4f2004-12-16 18:43:13 +0000207 }
208 } else {
209 for (x=0; x<line_size; x++) {
210 *ptr++ = *bmp++;
211 }
212 }
Stefan Roesed9d97742005-09-22 09:04:17 +0200213 }
214
Stefan Roese13b93692005-10-08 10:19:07 +0200215 if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
Stefan Roesed9d97742005-09-22 09:04:17 +0200216 free(dst);
217 }
218}
219
220
221void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
222 uchar *logo_bmp, ulong len)
223{
224 int i;
225 ushort s1dReg;
226 uchar s1dValue;
227 int reg_byte_swap;
228
229 /*
230 * Detect epson
231 */
232 if (lcd_reg[0] == 0x1c) {
233 /*
234 * Big epson detected
235 */
236 reg_byte_swap = FALSE;
237 palette_index = 0x1e2;
238 palette_value = 0x1e4;
239 lcd_depth = 16;
240 puts("LCD: S1D13806");
241 } else if (lcd_reg[1] == 0x1c) {
242 /*
243 * Big epson detected (with register swap bug)
244 */
245 reg_byte_swap = TRUE;
246 palette_index = 0x1e3;
247 palette_value = 0x1e5;
248 lcd_depth = 16;
249 puts("LCD: S1D13806S");
250 } else if (lcd_reg[0] == 0x18) {
251 /*
252 * Small epson detected (704)
253 */
254 reg_byte_swap = FALSE;
255 palette_index = 0x15;
256 palette_value = 0x17;
257 lcd_depth = 8;
258 puts("LCD: S1D13704");
259 } else if (lcd_reg[0x10000] == 0x24) {
260 /*
261 * Small epson detected (705)
262 */
263 reg_byte_swap = FALSE;
264 palette_index = 0x15;
265 palette_value = 0x17;
266 lcd_depth = 8;
267 lcd_reg += 0x10000; /* add offset for 705 regs */
268 puts("LCD: S1D13705");
269 } else {
270 puts("LCD: No controller detected!\n");
271 return;
272 }
273
274 /*
275 * Setup lcd controller regs
276 */
277 for (i = 0; i<reg_count; i++) {
278 s1dReg = regs[i].Index;
279 if (reg_byte_swap) {
280 if ((s1dReg & 0x0001) == 0)
281 s1dReg |= 0x0001;
282 else
283 s1dReg &= ~0x0001;
284 }
285 s1dValue = regs[i].Value;
286 lcd_reg[s1dReg] = s1dValue;
stroese56b9e4f2004-12-16 18:43:13 +0000287 }
288
Stefan Roesed9d97742005-09-22 09:04:17 +0200289 /*
290 * Save reg & mem pointer for later usage (e.g. bmp command)
291 */
292 glob_lcd_reg = lcd_reg;
293 glob_lcd_mem = lcd_mem;
294
295 /*
296 * Display bmp image
297 */
298 lcd_bmp(logo_bmp);
stroese56b9e4f2004-12-16 18:43:13 +0000299}
Stefan Roesed9d97742005-09-22 09:04:17 +0200300
Wolfgang Denkb9c93d22005-09-25 16:31:16 +0200301#ifdef CONFIG_VIDEO_SM501
Stefan Roesed9d97742005-09-22 09:04:17 +0200302int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
303{
304 ulong addr;
305 char *str;
306
307 if (argc != 2) {
308 printf ("Usage:\n%s\n", cmdtp->usage);
309 return 1;
310 }
311
312 addr = simple_strtoul(argv[1], NULL, 16);
313
314 str = getenv("bd_type");
315 if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
316 /*
317 * SM501 available, use standard bmp command
318 */
319 return (video_display_bitmap(addr, 0, 0));
320 } else {
321 /*
322 * No SM501 available, use esd epson bmp command
323 */
324 lcd_bmp((uchar *)addr);
325 return 0;
326 }
327}
328
329U_BOOT_CMD(
330 esdbmp, 2, 1, do_esdbmp,
331 "esdbmp - display BMP image\n",
332 "<imageAddr> - display image\n"
333);
Wolfgang Denkb9c93d22005-09-25 16:31:16 +0200334#endif