Merge branch 'master' of git://git.denx.de/u-boot
[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 "opening_wvga_32.h"
33 //#include "logo_rgb24_wvga_portrait.h"
34 //#include "opening_logo_rgb24_143_44.h"
35
36 #define PANEL_WIDTH             480
37 #define PANEL_HEIGHT            800
38 #define S5P_LCD_BPP             32
39
40 extern void tl2796_panel_power_on(void);
41 extern void tl2796_panel_enable(void);
42 extern void tl2796_panel_init(void);
43
44 int lcd_line_length;
45 int lcd_color_fg;
46 int lcd_color_bg;
47
48 void *lcd_base;
49 void *lcd_console_address;
50
51 short console_col;
52 short console_row;
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                 .vl_col         = PANEL_WIDTH,
97                 .vl_row         = PANEL_HEIGHT,
98                 .vl_width       = PANEL_WIDTH,
99                 .vl_height      = PANEL_HEIGHT,
100                 .vl_clkp        = CONFIG_SYS_HIGH,
101                 .vl_hsp         = CONFIG_SYS_LOW,
102                 .vl_vsp         = CONFIG_SYS_LOW,
103                 .vl_dp          = CONFIG_SYS_HIGH,
104                 .vl_bpix        = S5P_LCD_BPP,
105                 .vl_lbw         = 0,
106                 .vl_splt        = 0,
107                 .vl_clor        = 1,
108                 .vl_tft         = 1,
109
110                 /* S6E63M0 LCD Panel */
111                 .vl_hpw         = 2,
112                 .vl_blw         = 16,
113                 .vl_elw         = 16,
114
115                 .vl_vpw         = 2,
116                 .vl_bfw         = 3,
117                 .vl_efw         = 28,
118                 /* tl2796 panel.
119                 .vl_hpw         = 4,
120                 .vl_blw         = 8,
121                 .vl_elw         = 8,
122
123                 .vl_vpw         = 4,
124                 .vl_bfw         = 8,
125                 .vl_efw         = 8,
126                 */
127 };
128
129 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
130 {
131         unsigned long palette_size, palette_mem_size;
132         unsigned int fb_size;
133
134         fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix / 8);
135
136         lcd_base = lcdbase;
137
138         palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
139         palette_mem_size = palette_size * sizeof(u32);
140
141         s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
142
143         udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
144                         fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
145 }
146
147 static void s5pc_gpio_setup(void)
148 {
149         if (cpu_is_s5pc100())
150                 s5pc_c100_gpio_setup();
151         else
152                 s5pc_c110_gpio_setup();
153 }
154
155 static void s5pc_lcd_init(vidinfo_t *vid)
156 {
157         s5pc_fimd_lcd_init(vid);
158 }
159
160 static void lcd_test(void)
161 {
162         /* red */
163         read_image32((char *)lcd_base, 0, 0, 480, 200,
164                         makepixel8888(0, 255, 0, 0));
165         /* green */
166         read_image32((char *)lcd_base, 0, 200, 480, 400,
167                         makepixel8888(0, 0, 255, 0));
168         /* blue */
169         read_image32((char *)lcd_base, 0, 400, 480, 600,
170                         makepixel8888(0, 0, 0, 255));
171         /* write */
172         read_image32((char *)lcd_base, 0, 600, 480, 800,
173                         makepixel8888(0, 255, 255, 255));
174 }
175
176 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
177 {
178         int i, j, k = 0;
179         unsigned long *fb = (unsigned  long*)lcdbase;
180
181         for (j = y; j < (y + h); j++) {
182                 for (i = x; i < (x + w); i++)
183                         *(fb + (j * PANEL_WIDTH) + i) = *(bmp + k++);
184         }
185 }
186
187 static void draw_samsung_logo(void* lcdbase)
188 {
189         int x, y;
190
191         x = (PANEL_WIDTH - 138) / 2;
192         y = (PANEL_HEIGHT - 28) / 2 - 5;
193
194         draw_bitmap(lcdbase, x, y, 138, 28, (unsigned long *)opening_32);
195 }
196
197 static void lcd_panel_on(void)
198 {
199         lcd_panel_init();
200         lcd_panel_power_on();
201
202         lcd_panel_enable();
203 }
204
205 void lcd_ctrl_init(void *lcdbase)
206 {
207         char *option;
208
209         s5pc_lcd_init_mem(lcdbase, &panel_info);
210
211         option = getenv("lcd");
212
213         /*
214         if (strcmp(option, "test") == 0) {
215                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
216                 lcd_test();
217         } else if (strcmp(option, "image") == 0)
218                 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
219         else {
220                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
221                 draw_samsung_logo(lcdbase);
222         }
223         */
224
225         memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
226         draw_samsung_logo(lcdbase);
227
228         s5pc_gpio_setup();
229
230         s5pc_lcd_init(&panel_info);
231 }
232
233
234 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
235 {
236         return;
237 }
238
239 void lcd_enable(void)
240 {
241         lcd_panel_on();
242 }
243
244 ulong calc_fbsize(void)
245 {
246         return s5pc_fimd_calc_fbsize();
247 }
248
249 void s5pc1xxfb_test(void *lcdbase)
250 {
251         lcd_ctrl_init(lcdbase);
252         lcd_enable();
253
254         //memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
255 }