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