lcd: Added font module for framebuffer.
[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 "font.h"
34 //#include "logo_rgb24_wvga_portrait.h"
35 //#include "opening_logo_rgb24_143_44.h"
36
37 #define PANEL_WIDTH             480
38 #define PANEL_HEIGHT            800
39 #define S5P_LCD_BPP             32
40
41 extern void tl2796_panel_power_on(void);
42 extern void tl2796_panel_enable(void);
43 extern void tl2796_panel_init(void);
44
45 int lcd_line_length;
46 int lcd_color_fg;
47 int lcd_color_bg;
48
49 void *lcd_base;
50 void *lcd_console_address;
51
52 short console_col;
53 short console_row;
54
55 static unsigned short makepixel565(char r, char g, char b)
56 {
57     return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
58 }
59
60 static unsigned int makepixel8888(char a, char r, char g, char b)
61 {
62         return (unsigned int)((a << 24) | (r << 16) | (g << 8)  | b);
63 }
64
65 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
66                 int y2pos, unsigned short pixel)
67 {
68         unsigned short *pDst = (unsigned short *)pImg;
69         unsigned int offset_s;
70         int i, j;
71
72         for(i = y1pos; i < y2pos; i++) {
73                 for(j = x1pos; j < x2pos; j++) {
74                         offset_s = i * PANEL_WIDTH + j;
75                         *(pDst + offset_s) = pixel;
76                 }
77         }
78 }
79
80 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
81                 int y2pos, unsigned int pixel)
82 {
83         unsigned int *pDst = (unsigned int *)pImg;
84         unsigned int offset_s;
85         int i, j;
86
87         for(i = y1pos; i < y2pos; i++) {
88                 for(j = x1pos; j < x2pos; j++) {
89                         offset_s = i * PANEL_WIDTH + j;
90                         *(pDst+offset_s) = pixel;
91                 }
92         }
93 }
94
95 /* LCD Panel data */
96 vidinfo_t panel_info = {
97                 .vl_col         = PANEL_WIDTH,
98                 .vl_row         = PANEL_HEIGHT,
99                 .vl_width       = PANEL_WIDTH,
100                 .vl_height      = PANEL_HEIGHT,
101                 .vl_clkp        = CONFIG_SYS_HIGH,
102                 .vl_hsp         = CONFIG_SYS_LOW,
103                 .vl_vsp         = CONFIG_SYS_LOW,
104                 .vl_dp          = CONFIG_SYS_HIGH,
105                 .vl_bpix        = S5P_LCD_BPP,
106                 .vl_lbw         = 0,
107                 .vl_splt        = 0,
108                 .vl_clor        = 1,
109                 .vl_tft         = 1,
110
111                 .vl_hpw         = 4,
112                 .vl_blw         = 8,
113                 .vl_elw         = 8,
114
115                 .vl_vpw         = 4,
116                 .vl_bfw         = 8,
117                 .vl_efw         = 8,
118 };
119
120 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
121 {
122         unsigned long palette_size, palette_mem_size;
123         unsigned int fb_size;
124
125         fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix / 8);
126
127         lcd_base = lcdbase;
128
129         palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
130         palette_mem_size = palette_size * sizeof(u32);
131
132         s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
133
134         udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
135                         fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
136 }
137
138 static void s5pc_gpio_setup(void)
139 {
140         if (cpu_is_s5pc100())
141                 s5pc_c100_gpio_setup();
142         else
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 lcd_test(void)
152 {
153         /* red */
154         read_image32((char *)lcd_base, 0, 0, 480, 200,
155                         makepixel8888(0, 255, 0, 0));
156         /* green */
157         read_image32((char *)lcd_base, 0, 200, 480, 400,
158                         makepixel8888(0, 0, 255, 0));
159         /* blue */
160         read_image32((char *)lcd_base, 0, 400, 480, 600,
161                         makepixel8888(0, 0, 0, 255));
162         /* write */
163         read_image32((char *)lcd_base, 0, 600, 480, 800,
164                         makepixel8888(0, 255, 255, 255));
165 }
166
167 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
168 {
169         int i, j, k = 0;
170         unsigned long *fb = (unsigned  long*)lcdbase;
171
172         for (j = y; j < (y + h); j++) {
173                 for (i = x; i < (x + w); i++)
174                         *(fb + (j * PANEL_WIDTH) + i) = *(bmp + k++);
175         }
176 }
177
178 static void draw_samsung_logo(void* lcdbase)
179 {
180         int x, y;
181
182         x = (PANEL_WIDTH - 138) / 2;
183         y = (PANEL_HEIGHT - 28) / 2 - 5;
184
185         draw_bitmap(lcdbase, x, y, 138, 28, (unsigned long *)opening_32);
186 }
187
188 static void lcd_panel_on(void)
189 {
190         if (cpu_is_s5pc100()) {
191                 tl2796_c100_panel_init();
192                 tl2796_c100_panel_power_on();
193         } else {
194                 tl2796_c110_panel_init();
195                 tl2796_c110_panel_power_on();
196         }
197
198         tl2796_panel_enable();
199 }
200
201 void lcd_ctrl_init(void *lcdbase)
202 {
203         char *option;
204
205         s5pc_lcd_init_mem(lcdbase, &panel_info);
206
207         option = getenv("lcd");
208
209         /*
210         if (strcmp(option, "test") == 0) {
211                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
212                 lcd_test();
213         } else if (strcmp(option, "image") == 0)
214                 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
215         else {
216                 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
217                 draw_samsung_logo(lcdbase);
218         }
219         */
220
221         memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
222         draw_samsung_logo(lcdbase);
223
224         s5pc_gpio_setup();
225
226         s5pc_lcd_init(&panel_info);
227
228         /* initialize font module for framebuffer. */
229         init_font();
230
231         set_font_xy(10, 10);
232         set_font_color(FONT_GREEN);
233         fb_printf("Framebuffer initialization is completed.\n");
234
235         set_font_color(FONT_WHITE);
236         fb_printf("Kernel/BSP");
237 }
238
239 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
240 {
241         return;
242 }
243
244 void lcd_enable(void)
245 {
246         lcd_panel_on();
247 }
248
249 ulong calc_fbsize(void)
250 {
251         return s5pc_fimd_calc_fbsize();
252 }
253
254 void s5pc1xxfb_test(void *lcdbase)
255 {
256         lcd_ctrl_init(lcdbase);
257         lcd_enable();
258
259         //memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
260 }