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