s5pc110: lcd: compress boot logo
[kernel/u-boot.git] / drivers / video / s5p-fb.c
1 /*
2  * S5PC100 and S5PC110 LCD Controller driver.
3  *
4  * Author: InKi Dae <inki.dae@samsung.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21
22 #include <config.h>
23 #include <common.h>
24 #include <version.h>
25 #include <stdarg.h>
26 #include <linux/types.h>
27 #include <asm/io.h>
28 #include <asm/arch/cpu.h>
29 #include <lcd.h>
30
31 #include "s5p-fb.h"
32 #include "logo.h"
33 /*
34 #include "logo_rgb24_wvga_portrait.h"
35 #include "opening_logo_rgb24_143_44.h"
36 */
37
38 extern void tl2796_panel_power_on(void);
39 extern void tl2796_panel_enable(void);
40 extern void tl2796_panel_init(void);
41
42 int lcd_line_length;
43 int lcd_color_fg;
44 int lcd_color_bg;
45
46 void *lcd_base;
47 void *lcd_console_address;
48
49 short console_col;
50 short console_row;
51
52 static unsigned int panel_width, panel_height;
53
54 static unsigned short makepixel565(char r, char g, char b)
55 {
56     return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
57 }
58
59 static unsigned int makepixel8888(char a, char r, char g, char b)
60 {
61         return (unsigned int)((a << 24) | (r << 16) | (g << 8)  | b);
62 }
63
64 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
65                 int y2pos, unsigned short pixel)
66 {
67         unsigned short *pDst = (unsigned short *)pImg;
68         unsigned int offset_s;
69         int i, j;
70
71         for(i = y1pos; i < y2pos; i++) {
72                 for(j = x1pos; j < x2pos; j++) {
73                         offset_s = i * panel_width + j;
74                         *(pDst + offset_s) = pixel;
75                 }
76         }
77 }
78
79 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
80                 int y2pos, unsigned int pixel)
81 {
82         unsigned int *pDst = (unsigned int *)pImg;
83         unsigned int offset_s;
84         int i, j;
85
86         for (i = y1pos; i < y2pos; i++) {
87                 for (j = x1pos; j < x2pos; j++) {
88                         offset_s = i * panel_width + j;
89                         *(pDst+offset_s) = pixel;
90                 }
91         }
92 }
93
94 /* LCD Panel data */
95 vidinfo_t panel_info;
96
97 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
98 {
99         unsigned long palette_size, palette_mem_size;
100         unsigned int fb_size;
101
102         fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix >> 3);
103
104         lcd_base = lcdbase;
105
106         palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
107         palette_mem_size = palette_size * sizeof(u32);
108
109         s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
110
111         udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
112                         fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
113 }
114
115 static void s5pc_lcd_init(vidinfo_t *vid)
116 {
117         s5pc_fimd_lcd_init(vid);
118 }
119
120 static void lcd_test(unsigned int width, unsigned int height)
121 {
122         unsigned int height_level = height / 3;
123
124         /* red */
125         read_image32((char *)lcd_base, 0, 0, width, height_level,
126                         makepixel8888(0, 255, 0, 0));
127         /* green */
128         read_image32((char *)lcd_base, 0, height_level, width,
129                 height_level * 2, makepixel8888(0, 0, 255, 0));
130         /* blue */
131         read_image32((char *)lcd_base, 0, height_level * 2, width, height,
132                         makepixel8888(0, 0, 0, 255));
133 }
134
135 int conv_rgb565_to_rgb888(unsigned short rgb565, unsigned int sw)
136 {
137         char red, green, blue;
138         unsigned int threshold = 150;
139
140         red = (rgb565 & 0xF800) >> 11;
141         green = (rgb565 & 0x7E0) >> 5;
142         blue = (rgb565 & 0x1F);
143
144         red = red << 3;
145         green = green << 2;
146         blue = blue << 3;
147
148         /* correct error pixels of samsung logo. */
149         if (sw) {
150                 if (red > threshold)
151                         red = 255;
152                 if (green > threshold)
153                         green = 255;
154                 if (blue > threshold)
155                         blue = 255;
156         }
157
158         return (red << 16 | green << 8 | blue);
159 }
160
161 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
162 {
163         int i, j;
164         short k = 0;
165         unsigned long *fb = (unsigned  long*)lcdbase;
166
167         for (j = y; j < (y + h); j++) {
168                 for (i = x; i < (x + w); i++)
169                         *(fb + (j * panel_width) + i) = *(bmp + k++);
170         }
171 }
172
173 void _draw_samsung_logo(void *lcdbase, int x, int y, int w, int h, unsigned short *bmp)
174 {
175         int i, j, error_range = 40;
176         short k = 0;
177         unsigned int pixel;
178         unsigned long *fb = (unsigned  long*)lcdbase;
179
180         for (j = y; j < (y + h); j++) {
181                 for (i = x; i < (x + w); i++) {
182                         pixel = (*(bmp + k++));
183
184                         /* 40 lines under samsung logo image are error range. */
185                         if (j > h + y - error_range)
186                                 *(fb + (j * panel_width) + i) =
187                                         conv_rgb565_to_rgb888(pixel, 1);
188                         else
189                                 *(fb + (j * panel_width) + i) =
190                                         conv_rgb565_to_rgb888(pixel, 0);
191                 }
192         }
193 }
194
195 static void draw_samsung_logo(void* lcdbase)
196 {
197         int x, y;
198         unsigned int in_len,out_len, width, height;
199         void *dst = NULL;
200
201         width = 298;
202         height = 78;
203         x = ((panel_width - width) >> 1);
204         y = ((panel_height - height) >> 1) - 5;
205
206         in_len = width * height * 4;
207         dst = malloc(in_len);
208         if (dst == NULL) {
209                 printf("Error: malloc in gunzip failed!\n");
210                 return NULL;
211         }
212         if (gunzip(dst, in_len, (uchar *)logo, &out_len) != 0) {
213                 free(dst);
214                 return NULL;
215         }
216         if (out_len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
217                 printf("Image could be truncated"
218                                 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
219         _draw_samsung_logo(lcdbase, x, y, width, height, (unsigned short *) dst);
220 }
221
222 static void lcd_panel_on(vidinfo_t *vid)
223 {
224         udelay(vid->init_delay);
225
226         if (vid->cfg_gpio)
227                 vid->cfg_gpio();
228
229         if (vid->lcd_power_on) {
230                 vid->lcd_power_on(1);
231         }
232
233         udelay(vid->power_on_delay);
234
235         if (vid->reset_lcd) {
236                 vid->reset_lcd();
237         }
238
239         udelay(vid->reset_delay);
240
241         if (vid->backlight_on) {
242                 vid->backlight_on(1);
243         }
244
245         if (vid->cfg_ldo) {
246                 vid->cfg_ldo();
247         }
248
249         if (vid->enable_ldo) {
250                 vid->enable_ldo(1);
251         }
252 }
253
254 /* extern void init_onenand_ext2(void); */
255 extern void init_panel_info(vidinfo_t *vid);
256
257 void lcd_ctrl_init(void *lcdbase)
258 {
259         char *option;
260
261         s5pc_lcd_init_mem(lcdbase, &panel_info);
262
263         /* initialize parameters which is specific to panel. */
264         init_panel_info(&panel_info);
265
266         panel_width = panel_info.vl_width;
267         panel_height = panel_info.vl_height;
268
269         option = getenv("lcd");
270
271         /*
272         if (strcmp(option, "test") == 0) {
273                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
274                 lcd_test(panel_width, panel_height);
275         } else if (strcmp(option, "image") == 0)
276                 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
277         else {
278                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
279                 draw_samsung_logo(lcdbase);
280         }
281         */
282
283         memset(lcdbase, 0, panel_width * panel_height * (32 >> 3));
284         draw_samsung_logo(lcdbase);
285
286         s5pc_lcd_init(&panel_info);
287
288         /* font test */
289         /*
290         init_font();
291         set_font_color(FONT_WHITE);
292         fb_printf("Test\n");
293         exit_font();
294         */
295
296         /* init_onenand_ext2(); */
297 }
298
299
300 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
301 {
302         return;
303 }
304
305 void lcd_enable(void)
306 {
307         lcd_panel_on(&panel_info);
308 }
309
310 ulong calc_fbsize(void)
311 {
312         return s5pc_fimd_calc_fbsize();
313 }
314
315 void s5pc1xxfb_test(void *lcdbase)
316 {
317         lcd_ctrl_init(lcdbase);
318         lcd_enable();
319 }