blob: 196171ce5aa9dab779def53adb4952fa47352765 [file] [log] [blame]
stroese0621f6f2004-12-16 18:43:13 +00001/*
2 * (C) Copyright 2003-2004
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Stefan Roese98f4a3d2005-09-22 09:04:17 +02005 * (C) Copyright 2005
6 * Stefan Roese, DENX Software Engineering, sr@denx.de.
7 *
stroese0621f6f2004-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
29
Stefan Roese98f4a3d2005-09-22 09:04:17 +020030extern int video_display_bitmap (ulong, int, int);
31
32
stroese0621f6f2004-12-16 18:43:13 +000033int palette_index;
34int palette_value;
Stefan Roese98f4a3d2005-09-22 09:04:17 +020035int lcd_depth;
36unsigned char *glob_lcd_reg;
37unsigned char *glob_lcd_mem;
stroese0621f6f2004-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 Roese98f4a3d2005-09-22 09:04:17 +020078void lcd_bmp(uchar *logo_bmp)
stroese0621f6f2004-12-16 18:43:13 +000079{
80 int i;
stroese0621f6f2004-12-16 18:43:13 +000081 uchar *ptr;
82 ushort *ptr2;
83 ushort val;
Stefan Roesec29ab9d2005-10-08 10:19:07 +020084 unsigned char *dst = NULL;
stroese0621f6f2004-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 Roese98f4a3d2005-09-22 09:04:17 +020091 ulong len;
stroese0621f6f2004-12-16 18:43:13 +000092
93 /*
94 * Check for bmp mark 'BM'
95 */
Stefan Roese98f4a3d2005-09-22 09:04:17 +020096 if (*(ushort *)logo_bmp != 0x424d) {
97
98 /*
99 * Decompress bmp image
100 */
Stefan Roesec29ab9d2005-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 Roese98f4a3d2005-09-22 09:04:17 +0200105 return;
106 }
Stefan Roesec29ab9d2005-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 Roese98f4a3d2005-09-22 09:04:17 +0200113
114 /*
115 * Check for bmp mark 'BM'
116 */
117 if (*(ushort *)dst != 0x424d) {
118 printf("LCD: Unknown image format!\n");
119 free(dst);
120 return;
121 }
122 } else {
123 /*
124 * Uncompressed BMP image, just use this pointer
125 */
126 dst = (uchar *)logo_bmp;
stroese0621f6f2004-12-16 18:43:13 +0000127 }
128
129 /*
130 * 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 Roesec29ab9d2005-10-08 10:19:07 +0200155 if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
156 free(dst);
157 }
stroese0621f6f2004-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 Roese98f4a3d2005-09-22 09:04:17 +0200165 if ((colors <= 256) && (lcd_depth <= 8)) {
stroese0621f6f2004-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 Roese98f4a3d2005-09-22 09:04:17 +0200172 S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
stroese0621f6f2004-12-16 18:43:13 +0000173 }
174 }
175
176 /*
177 * Write bitmap data into framebuffer
178 */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200179 ptr = glob_lcd_mem;
180 ptr2 = (ushort *)glob_lcd_mem;
stroese0621f6f2004-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 Roese98f4a3d2005-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 }
stroese0621f6f2004-12-16 18:43:13 +0000207 }
208 } else {
209 for (x=0; x<line_size; x++) {
210 *ptr++ = *bmp++;
211 }
212 }
213 }
214
Stefan Roesec29ab9d2005-10-08 10:19:07 +0200215 if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200216 free(dst);
217 }
stroese0621f6f2004-12-16 18:43:13 +0000218}
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200219
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 */
Stefan Roese48a05a52006-02-07 16:51:04 +0100232 lcd_reg[0] = 0x00;
233 lcd_reg[1] = 0x00;
234
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200235 if (lcd_reg[0] == 0x1c) {
236 /*
237 * Big epson detected
238 */
239 reg_byte_swap = FALSE;
240 palette_index = 0x1e2;
241 palette_value = 0x1e4;
242 lcd_depth = 16;
243 puts("LCD: S1D13806");
244 } else if (lcd_reg[1] == 0x1c) {
245 /*
246 * Big epson detected (with register swap bug)
247 */
248 reg_byte_swap = TRUE;
249 palette_index = 0x1e3;
250 palette_value = 0x1e5;
251 lcd_depth = 16;
252 puts("LCD: S1D13806S");
253 } else if (lcd_reg[0] == 0x18) {
254 /*
255 * Small epson detected (704)
256 */
257 reg_byte_swap = FALSE;
258 palette_index = 0x15;
259 palette_value = 0x17;
260 lcd_depth = 8;
261 puts("LCD: S1D13704");
262 } else if (lcd_reg[0x10000] == 0x24) {
263 /*
264 * Small epson detected (705)
265 */
266 reg_byte_swap = FALSE;
267 palette_index = 0x15;
268 palette_value = 0x17;
269 lcd_depth = 8;
270 lcd_reg += 0x10000; /* add offset for 705 regs */
271 puts("LCD: S1D13705");
272 } else {
273 puts("LCD: No controller detected!\n");
274 return;
275 }
276
277 /*
278 * Setup lcd controller regs
279 */
280 for (i = 0; i<reg_count; i++) {
281 s1dReg = regs[i].Index;
282 if (reg_byte_swap) {
283 if ((s1dReg & 0x0001) == 0)
284 s1dReg |= 0x0001;
285 else
286 s1dReg &= ~0x0001;
287 }
288 s1dValue = regs[i].Value;
289 lcd_reg[s1dReg] = s1dValue;
290 }
291
292 /*
293 * Save reg & mem pointer for later usage (e.g. bmp command)
294 */
295 glob_lcd_reg = lcd_reg;
296 glob_lcd_mem = lcd_mem;
297
298 /*
299 * Display bmp image
300 */
301 lcd_bmp(logo_bmp);
302}
303
Wolfgang Denkc177bb52005-09-25 16:31:16 +0200304#ifdef CONFIG_VIDEO_SM501
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200305int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
306{
307 ulong addr;
308 char *str;
309
310 if (argc != 2) {
311 printf ("Usage:\n%s\n", cmdtp->usage);
312 return 1;
313 }
314
315 addr = simple_strtoul(argv[1], NULL, 16);
316
317 str = getenv("bd_type");
318 if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
319 /*
320 * SM501 available, use standard bmp command
321 */
322 return (video_display_bitmap(addr, 0, 0));
323 } else {
324 /*
325 * No SM501 available, use esd epson bmp command
326 */
327 lcd_bmp((uchar *)addr);
328 return 0;
329 }
330}
331
332U_BOOT_CMD(
333 esdbmp, 2, 1, do_esdbmp,
334 "esdbmp - display BMP image\n",
335 "<imageAddr> - display image\n"
336);
Wolfgang Denkc177bb52005-09-25 16:31:16 +0200337#endif