Tizen 2.0 Release
[platform/kernel/u-boot.git] / drivers / video / s5p-dualfb.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 "opening_wvga_32.h"
33
34 #define PANEL_WIDTH             480
35 #define PANEL_HEIGHT            800
36 #define S5P_LCD_BPP             32
37
38 /* for DUAL LCD */
39 #define SCREEN_WIDTH            (480 * 2)
40 #define SCREEN_HEIGHT           800
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 int dual_lcd = 1;
51
52 void *lcd_base;
53 void *lcd_console_address;
54
55 short console_col;
56 short console_row;
57
58 static unsigned short makepixel565(char r, char g, char b)
59 {
60     return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
61 }
62
63 static unsigned int makepixel8888(char a, char r, char g, char b)
64 {
65         return (unsigned int)((a << 24) | (r << 16) | (g << 8)  | b);
66 }
67
68 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
69                 int y2pos, unsigned short pixel)
70 {
71         unsigned short *pDst = (unsigned short *)pImg;
72         unsigned int offset_s;
73         int i, j;
74
75         for(i = y1pos; i < y2pos; i++) {
76                 for(j = x1pos; j < x2pos; j++) {
77                         offset_s = i * SCREEN_WIDTH + j;
78                         *(pDst + offset_s) = pixel;
79                 }
80         }
81 }
82
83 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
84                 int y2pos, unsigned int pixel)
85 {
86         unsigned int *pDst = (unsigned int *)pImg;
87         unsigned int offset_s;
88         int i, j;
89
90         for(i = y1pos; i < y2pos; i++) {
91                 for(j = x1pos; j < x2pos; j++) {
92                         offset_s = i * SCREEN_WIDTH + j;
93                         *(pDst+offset_s) = pixel;
94                 }
95         }
96 }
97
98 /* LCD Panel data */
99 vidinfo_t panel_info = {
100                 .vl_col         = SCREEN_WIDTH,
101                 .vl_row         = SCREEN_HEIGHT,
102                 .vl_width       = PANEL_WIDTH,
103                 .vl_height      = PANEL_HEIGHT,
104                 .vl_clkp        = CONFIG_SYS_HIGH,
105                 .vl_hsp         = CONFIG_SYS_LOW,
106                 .vl_vsp         = CONFIG_SYS_LOW,
107                 .vl_dp          = CONFIG_SYS_HIGH,
108                 .vl_bpix        = S5P_LCD_BPP,
109                 .vl_lbw         = 0,
110                 .vl_splt        = 0,
111                 .vl_clor        = 1,
112                 .vl_tft         = 1,
113
114                 .vl_hpw         = 4,
115                 .vl_blw         = 8,
116                 .vl_elw         = 8,
117
118                 .vl_vpw         = 4,
119                 .vl_bfw         = 8,
120                 .vl_efw         = 8,
121 };
122
123 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
124 {
125         unsigned long palette_size, palette_mem_size;
126         unsigned int fb_size;
127
128         fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix / 8);
129
130         lcd_base = lcdbase;
131
132         palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
133         palette_mem_size = palette_size * sizeof(u32);
134
135         s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
136
137         udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
138                         fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
139 }
140
141 static void s5pc_gpio_setup(void)
142 {
143         s5pc_c110_gpio_setup();
144 }
145
146 static void s5pc_lcd_init(vidinfo_t *vid)
147 {
148         s5pc_fimd_lcd_init(vid);
149 }
150
151 static void dual_lcd_test(void)
152 {
153         int x1 = 100, y1 = 50, x2 = 100, y2 = 50, i;
154         /* red */
155         read_image32((char *)lcd_base, 0+x1, 0+y1, 960-x2, 200,
156                         makepixel8888(0, 255, 0, 0));
157         /* green */
158         read_image32((char *)lcd_base, 0+x1, 200, 960-x2, 400,
159                         makepixel8888(0, 0, 255, 0));
160         /* blue */
161         read_image32((char *)lcd_base, 0+x1, 400, 960-x2, 600,
162                         makepixel8888(0, 0, 0, 255));
163         /* write */
164         read_image32((char *)lcd_base, 0+x1, 600, 960-x2, 800-y2,
165                         makepixel8888(0, 255, 255, 255));
166 }
167
168 static void repeat_test(void)
169 {
170         int i;
171
172         for (i = 100; i < 200; i++) {
173                 read_image32((char *)lcd_base, 0, 0, 960, 800,
174                                 makepixel8888(0, (0x1234 * i) & 255, (0x5421 * i) & 255, (0x6789 * i) & 255));
175         }
176 }
177
178 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
179 {
180         int i, j, k = 0;
181         unsigned long *fb = (unsigned  long*)lcdbase;
182
183         for (j = y; j < (y + h); j++) {
184                 for (i = x; i < (w + x); i++) {
185                         *(fb + (j * SCREEN_WIDTH) + i) =
186                             *(unsigned long *)(bmp + k);
187                         k++;
188                 }
189         }
190 }
191
192 static void draw_samsung_logo(void* lcdbase)
193 {
194         int x, y;
195
196         x = (SCREEN_WIDTH - 138) / 2;
197         y = (SCREEN_HEIGHT - 28) / 2 - 5;
198
199         draw_bitmap(lcdbase, x, y, 138, 28, (unsigned long *)opening_32);
200 }
201
202 static void lcd_panel_on(void)
203 {
204         tl2796_c110_panel_init();
205         tl2796_c110_panel_power_on();
206
207         tl2796_panel_enable();
208 }
209
210 void lcd_ctrl_init(void *lcdbase)
211 {
212         s5pc_lcd_init_mem(lcdbase, &panel_info);
213
214         memset(lcd_base, 0, panel_info.vl_col * panel_info.vl_row * S5P_LCD_BPP >> 3);
215
216         s5pc_gpio_setup();
217
218         s5pc_lcd_init(&panel_info);
219 }
220
221 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
222 {
223         return;
224 }
225
226 void lcd_enable(void)
227 {
228         char *option;
229
230         lcd_panel_on();
231
232         option = getenv("lcd");
233         if (strcmp(option, "test") == 0)
234                 dual_lcd_test();
235         else if (strcmp(option, "on") == 0)
236                 draw_samsung_logo(lcd_base);
237         else if (strcmp(option, "repeat") == 0)
238                 repeat_test();
239         else
240                 draw_samsung_logo(lcd_base);
241 }
242
243 ulong calc_fbsize(void)
244 {
245         return s5pc_fimd_calc_fbsize();
246 }
247
248 void s5pc1xxfb_test(void *lcdbase)
249 {
250         lcd_ctrl_init(lcdbase);
251         lcd_enable();
252 }