]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/esd/common/lcd.c
05c76ff09880749512a153133501a75787dc680c
[karo-tx-uboot.git] / board / esd / common / lcd.c
1 /*
2  * (C) Copyright 2003-2004
3  * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4  *
5  * (C) Copyright 2005
6  * Stefan Roese, DENX Software Engineering, sr@denx.de.
7  *
8  * 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
30 extern int video_display_bitmap (ulong, int, int);
31
32
33 int palette_index;
34 int palette_value;
35 int lcd_depth;
36 unsigned char *glob_lcd_reg;
37 unsigned char *glob_lcd_mem;
38
39 #ifdef CFG_LCD_ENDIAN
40 void 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
78 void lcd_bmp(uchar *logo_bmp)
79 {
80         int i;
81         uchar *ptr;
82         ushort *ptr2;
83         ushort val;
84         unsigned char *dst;
85         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;
91         ulong len;
92         int do_free = 0;
93
94         /*
95          * Check for bmp mark 'BM'
96          */
97         if (*(ushort *)logo_bmp != 0x424d) {
98
99                 /*
100                  * Decompress bmp image
101                  */
102                 len = CFG_LCD_LOGO_MAX_SIZE;
103                 dst = malloc(CFG_LCD_LOGO_MAX_SIZE);
104                 do_free = 1;
105                 if (gunzip(dst, CFG_LCD_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) {
106                         return;
107                 }
108
109                 /*
110                  * Check for bmp mark 'BM'
111                  */
112                 if (*(ushort *)dst != 0x424d) {
113                         printf("LCD: Unknown image format!\n");
114                         free(dst);
115                         return;
116                 }
117         } else {
118                 /*
119                  * Uncompressed BMP image, just use this pointer
120                  */
121                 dst = (uchar *)logo_bmp;
122         }
123
124         /*
125          * Get image info from bmp-header
126          */
127         bm_info = (BITMAPINFOHEADER *)(dst + 14);
128         bpp = LOAD_SHORT(bm_info->biBitCount);
129         width = LOAD_LONG(bm_info->biWidth);
130         height = LOAD_LONG(bm_info->biHeight);
131         switch (bpp) {
132         case 1:
133                 colors = 1;
134                 line_size = width >> 3;
135                 break;
136         case 4:
137                 colors = 16;
138                 line_size = width >> 1;
139                 break;
140         case 8:
141                 colors = 256;
142                 line_size = width;
143                 break;
144         case 24:
145                 colors = 0;
146                 line_size = width * 3;
147                 break;
148         default:
149                 printf("LCD: Unknown bpp (%d) im image!\n", bpp);
150                 free(dst);
151                 return;
152         }
153         printf(" (%d*%d, %dbpp)\n", width, height, bpp);
154
155         /*
156          * Write color palette
157          */
158         if ((colors <= 256) && (lcd_depth <= 8)) {
159                 ptr = (unsigned char *)(dst + 14 + 40);
160                 for (i=0; i<colors; i++) {
161                         b = *ptr++;
162                         g = *ptr++;
163                         r = *ptr++;
164                         ptr++;
165                         S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
166                 }
167         }
168
169         /*
170          * Write bitmap data into framebuffer
171          */
172         ptr = glob_lcd_mem;
173         ptr2 = (ushort *)glob_lcd_mem;
174         header_size = 14 + 40 + 4*colors;          /* skip bmp header */
175         for (y=0; y<height; y++) {
176                 bmp = &dst[(height-1-y)*line_size + header_size];
177                 if (lcd_depth == 16) {
178                         if (bpp == 24) {
179                                 for (x=0; x<width; x++) {
180                                         /*
181                                          * Generate epson 16bpp fb-format from 24bpp image
182                                          */
183                                         b = *bmp++ >> 3;
184                                         g = *bmp++ >> 2;
185                                         r = *bmp++ >> 3;
186                                         val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
187                                         *ptr2++ = val;
188                                 }
189                         } else if (bpp == 8) {
190                                 for (x=0; x<line_size; x++) {
191                                         /* query rgb value from palette */
192                                         ptr = (unsigned char *)(dst + 14 + 40) ;
193                                         ptr += (*bmp++) << 2;
194                                         b = *ptr++ >> 3;
195                                         g = *ptr++ >> 2;
196                                         r = *ptr++ >> 3;
197                                         val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
198                                         *ptr2++ = val;
199                                 }
200                         }
201                 } else {
202                         for (x=0; x<line_size; x++) {
203                                 *ptr++ = *bmp++;
204                         }
205                 }
206         }
207
208         if (do_free) {
209                 free(dst);
210         }
211 }
212
213
214 void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
215               uchar *logo_bmp, ulong len)
216 {
217         int i;
218         ushort s1dReg;
219         uchar s1dValue;
220         int reg_byte_swap;
221
222         /*
223          * Detect epson
224          */
225         if (lcd_reg[0] == 0x1c) {
226                 /*
227                  * Big epson detected
228                  */
229                 reg_byte_swap = FALSE;
230                 palette_index = 0x1e2;
231                 palette_value = 0x1e4;
232                 lcd_depth = 16;
233                 puts("LCD:   S1D13806");
234         } else if (lcd_reg[1] == 0x1c) {
235                 /*
236                  * Big epson detected (with register swap bug)
237                  */
238                 reg_byte_swap = TRUE;
239                 palette_index = 0x1e3;
240                 palette_value = 0x1e5;
241                 lcd_depth = 16;
242                 puts("LCD:   S1D13806S");
243         } else if (lcd_reg[0] == 0x18) {
244                 /*
245                  * Small epson detected (704)
246                  */
247                 reg_byte_swap = FALSE;
248                 palette_index = 0x15;
249                 palette_value = 0x17;
250                 lcd_depth = 8;
251                 puts("LCD:   S1D13704");
252         } else if (lcd_reg[0x10000] == 0x24) {
253                 /*
254                  * Small epson detected (705)
255                  */
256                 reg_byte_swap = FALSE;
257                 palette_index = 0x15;
258                 palette_value = 0x17;
259                 lcd_depth = 8;
260                 lcd_reg += 0x10000; /* add offset for 705 regs */
261                 puts("LCD:   S1D13705");
262         } else {
263                 puts("LCD:   No controller detected!\n");
264                 return;
265         }
266
267         /*
268          * Setup lcd controller regs
269          */
270         for (i = 0; i<reg_count; i++) {
271                 s1dReg = regs[i].Index;
272                 if (reg_byte_swap) {
273                         if ((s1dReg & 0x0001) == 0)
274                                 s1dReg |= 0x0001;
275                         else
276                                 s1dReg &= ~0x0001;
277                 }
278                 s1dValue = regs[i].Value;
279                 lcd_reg[s1dReg] = s1dValue;
280         }
281
282         /*
283          * Save reg & mem pointer for later usage (e.g. bmp command)
284          */
285         glob_lcd_reg = lcd_reg;
286         glob_lcd_mem = lcd_mem;
287
288         /*
289          * Display bmp image
290          */
291         lcd_bmp(logo_bmp);
292 }
293
294 #ifdef CONFIG_VIDEO_SM501
295 int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
296 {
297         ulong addr;
298         char *str;
299
300         if (argc != 2) {
301                 printf ("Usage:\n%s\n", cmdtp->usage);
302                 return 1;
303         }
304
305         addr = simple_strtoul(argv[1], NULL, 16);
306
307         str = getenv("bd_type");
308         if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
309                 /*
310                  * SM501 available, use standard bmp command
311                  */
312                 return (video_display_bitmap(addr, 0, 0));
313         } else {
314                 /*
315                  * No SM501 available, use esd epson bmp command
316                  */
317                 lcd_bmp((uchar *)addr);
318                 return 0;
319         }
320 }
321
322 U_BOOT_CMD(
323         esdbmp, 2,      1,      do_esdbmp,
324         "esdbmp   - display BMP image\n",
325         "<imageAddr> - display image\n"
326 );
327 #endif