s5pc110: fb: changed samsung 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 #define PANEL_WIDTH             480
39 #define PANEL_HEIGHT            800
40 #define S5P_LCD_BPP             32
41
42 extern void tl2796_panel_power_on(void);
43 extern void tl2796_panel_enable(void);
44 extern void tl2796_panel_init(void);
45
46 int lcd_line_length;
47 int lcd_color_fg;
48 int lcd_color_bg;
49
50 void *lcd_base;
51 void *lcd_console_address;
52
53 short console_col;
54 short console_row;
55
56 static unsigned short makepixel565(char r, char g, char b)
57 {
58     return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
59 }
60
61 static unsigned int makepixel8888(char a, char r, char g, char b)
62 {
63         return (unsigned int)((a << 24) | (r << 16) | (g << 8)  | b);
64 }
65
66 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
67                 int y2pos, unsigned short pixel)
68 {
69         unsigned short *pDst = (unsigned short *)pImg;
70         unsigned int offset_s;
71         int i, j;
72
73         for(i = y1pos; i < y2pos; i++) {
74                 for(j = x1pos; j < x2pos; j++) {
75                         offset_s = i * PANEL_WIDTH + j;
76                         *(pDst + offset_s) = pixel;
77                 }
78         }
79 }
80
81 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
82                 int y2pos, unsigned int pixel)
83 {
84         unsigned int *pDst = (unsigned int *)pImg;
85         unsigned int offset_s;
86         int i, j;
87
88         for(i = y1pos; i < y2pos; i++) {
89                 for(j = x1pos; j < x2pos; j++) {
90                         offset_s = i * PANEL_WIDTH + j;
91                         *(pDst+offset_s) = pixel;
92                 }
93         }
94 }
95
96 /* LCD Panel data */
97 vidinfo_t panel_info = {
98                 .vl_col         = PANEL_WIDTH,
99                 .vl_row         = PANEL_HEIGHT,
100                 .vl_width       = PANEL_WIDTH,
101                 .vl_height      = PANEL_HEIGHT,
102                 .vl_clkp        = CONFIG_SYS_HIGH,
103                 .vl_hsp         = CONFIG_SYS_LOW,
104                 .vl_vsp         = CONFIG_SYS_LOW,
105                 .vl_dp          = CONFIG_SYS_HIGH,
106                 .vl_bpix        = S5P_LCD_BPP,
107                 .vl_lbw         = 0,
108                 .vl_splt        = 0,
109                 .vl_clor        = 1,
110                 .vl_tft         = 1,
111
112                 /* S6E63M0 LCD Panel */
113                 .vl_hpw         = 2,
114                 .vl_blw         = 16,
115                 .vl_elw         = 16,
116
117                 .vl_vpw         = 2,
118                 .vl_bfw         = 3,
119                 .vl_efw         = 28,
120                 /* tl2796 panel.
121                 .vl_hpw         = 4,
122                 .vl_blw         = 8,
123                 .vl_elw         = 8,
124
125                 .vl_vpw         = 4,
126                 .vl_bfw         = 8,
127                 .vl_efw         = 8,
128                 */
129 };
130
131 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
132 {
133         unsigned long palette_size, palette_mem_size;
134         unsigned int fb_size;
135
136         fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix / 8);
137
138         lcd_base = lcdbase;
139
140         palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
141         palette_mem_size = palette_size * sizeof(u32);
142
143         s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
144
145         udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
146                         fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
147 }
148
149 static void s5pc_gpio_setup(void)
150 {
151         if (cpu_is_s5pc100())
152                 s5pc_c100_gpio_setup();
153         else
154                 s5pc_c110_gpio_setup();
155 }
156
157 static void s5pc_lcd_init(vidinfo_t *vid)
158 {
159         s5pc_fimd_lcd_init(vid);
160 }
161
162 static void lcd_test(void)
163 {
164         /* red */
165         read_image32((char *)lcd_base, 0, 0, 480, 200,
166                         makepixel8888(0, 255, 0, 0));
167         /* green */
168         read_image32((char *)lcd_base, 0, 200, 480, 400,
169                         makepixel8888(0, 0, 255, 0));
170         /* blue */
171         read_image32((char *)lcd_base, 0, 400, 480, 600,
172                         makepixel8888(0, 0, 0, 255));
173         /* write */
174         read_image32((char *)lcd_base, 0, 600, 480, 800,
175                         makepixel8888(0, 255, 255, 255));
176 }
177
178 int convrgb565_to_rgb888(unsigned short rgb565, unsigned int sw)
179 {
180         char red, green, blue;
181         unsigned int threshold = 100;
182
183         red = (rgb565 & 0xF800) >> 11;
184         green = (rgb565 & 0x7E0) >> 5;
185         blue = (rgb565 & 0x1F);
186
187         red = red << 3;
188         green = green << 2;
189         blue = blue << 3;
190
191         /* correct pixel value because of drawing samsung logo. */
192         if (sw) {
193                 if (red > threshold)
194                         red = 255;
195                 if (green > threshold)
196                         green = 255;
197                 if (blue > threshold)
198                         blue = 255;
199         }
200
201         return (red << 16 | green << 8 | blue);
202 }
203
204 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
205 {
206         int i, j;
207         short k = 0;
208         unsigned long *fb = (unsigned  long*)lcdbase;
209
210         for (j = y; j < (y + h); j++) {
211                 for (i = x; i < (x + w); i++)
212                         *(fb + (j * PANEL_WIDTH) + i) = *(bmp + k++);
213         }
214 }
215
216 void _draw_samsung_logo(void *lcdbase, int x, int y, int w, int h, unsigned short *bmp)
217 {
218         int i, j;
219         short k = 0;
220         unsigned long *fb = (unsigned  long*)lcdbase;
221
222         for (j = y; j < (y + h); j++) {
223                 for (i = x; i < (x + w); i++)
224                         *(fb + (j * PANEL_WIDTH) + i) =
225                                 convrgb565_to_rgb888(*(bmp + k++), 1);
226         }
227 }
228
229 static void draw_samsung_logo(void* lcdbase)
230 {
231         int x, y;
232
233         x = (PANEL_WIDTH - 298) / 2;
234         y = (PANEL_HEIGHT - 78) / 2 - 5;
235
236         _draw_samsung_logo(lcdbase, x, y, 298, 78, (unsigned long *)logo);
237 }
238
239 static void lcd_panel_on(void)
240 {
241         lcd_panel_init();
242         lcd_panel_power_on();
243
244         lcd_panel_enable();
245 }
246
247 void lcd_ctrl_init(void *lcdbase)
248 {
249         char *option;
250
251         s5pc_lcd_init_mem(lcdbase, &panel_info);
252
253         option = getenv("lcd");
254
255         /*
256         if (strcmp(option, "test") == 0) {
257                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
258                 lcd_test();
259         } else if (strcmp(option, "image") == 0)
260                 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
261         else {
262                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
263                 draw_samsung_logo(lcdbase);
264         }
265         */
266
267         memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
268         draw_samsung_logo(lcdbase);
269
270         s5pc_gpio_setup();
271
272         s5pc_lcd_init(&panel_info);
273
274         /* font test */
275         /*
276         init_font();
277         set_font_color(FONT_WHITE);
278         fb_printf("Test\n");
279         exit_font();
280         */
281 }
282
283
284 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
285 {
286         return;
287 }
288
289 void lcd_enable(void)
290 {
291         lcd_panel_on();
292 }
293
294 ulong calc_fbsize(void)
295 {
296         return s5pc_fimd_calc_fbsize();
297 }
298
299 void s5pc1xxfb_test(void *lcdbase)
300 {
301         lcd_ctrl_init(lcdbase);
302         lcd_enable();
303
304         //memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
305 }