2 * S5PC100 and S5PC110 LCD Controller driver.
4 * Author: InKi Dae <inki.dae@samsung.com>
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.
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.
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,
26 #include <linux/types.h>
28 #include <asm/arch/cpu.h>
34 #include "logo_rgb24_wvga_portrait.h"
35 #include "opening_logo_rgb24_143_44.h"
38 extern void tl2796_panel_power_on(void);
39 extern void tl2796_panel_enable(void);
40 extern void tl2796_panel_init(void);
47 void *lcd_console_address;
52 static unsigned int panel_width, panel_height;
54 static unsigned short makepixel565(char r, char g, char b)
56 return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
59 static unsigned int makepixel8888(char a, char r, char g, char b)
61 return (unsigned int)((a << 24) | (r << 16) | (g << 8) | b);
64 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
65 int y2pos, unsigned short pixel)
67 unsigned short *pDst = (unsigned short *)pImg;
68 unsigned int offset_s;
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;
79 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
80 int y2pos, unsigned int pixel)
82 unsigned int *pDst = (unsigned int *)pImg;
83 unsigned int offset_s;
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;
95 vidinfo_t panel_info = {
102 struct lcd_panel_operation {
103 void (*lcd_panel_init)(void);
104 void (*lcd_panel_power_on)(void);
105 void (*lcd_panel_enable)(void);
108 static struct lcd_panel_operation lcd_calls;
110 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
112 unsigned long palette_size, palette_mem_size;
113 unsigned int fb_size;
115 fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix >> 3);
119 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
120 palette_mem_size = palette_size * sizeof(u32);
122 s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
124 udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
125 fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
128 static void s5pc_gpio_setup(void)
130 if (cpu_is_s5pc100())
131 s5pc_c100_gpio_setup();
133 s5pc_c110_gpio_setup();
136 static void s5pc_lcd_init(vidinfo_t *vid)
138 s5pc_fimd_lcd_init(vid);
141 static void lcd_test(void)
144 read_image32((char *)lcd_base, 0, 0, 480, 200,
145 makepixel8888(0, 255, 0, 0));
147 read_image32((char *)lcd_base, 0, 200, 480, 400,
148 makepixel8888(0, 0, 255, 0));
150 read_image32((char *)lcd_base, 0, 400, 480, 600,
151 makepixel8888(0, 0, 0, 255));
153 read_image32((char *)lcd_base, 0, 600, 480, 800,
154 makepixel8888(0, 255, 255, 255));
157 int conv_rgb565_to_rgb888(unsigned short rgb565, unsigned int sw)
159 char red, green, blue;
160 unsigned int threshold = 150;
162 red = (rgb565 & 0xF800) >> 11;
163 green = (rgb565 & 0x7E0) >> 5;
164 blue = (rgb565 & 0x1F);
170 /* correct error pixels of samsung logo. */
174 if (green > threshold)
176 if (blue > threshold)
180 return (red << 16 | green << 8 | blue);
183 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
187 unsigned long *fb = (unsigned long*)lcdbase;
189 for (j = y; j < (y + h); j++) {
190 for (i = x; i < (x + w); i++)
191 *(fb + (j * panel_width) + i) = *(bmp + k++);
195 void _draw_samsung_logo(void *lcdbase, int x, int y, int w, int h, unsigned short *bmp)
197 int i, j, error_range = 40;
200 unsigned long *fb = (unsigned long*)lcdbase;
202 for (j = y; j < (y + h); j++) {
203 for (i = x; i < (x + w); i++) {
204 pixel = (*(bmp + k++));
206 /* 40 lines under samsung logo image are error range. */
207 if (j > h + y - error_range)
208 *(fb + (j * panel_width) + i) =
209 conv_rgb565_to_rgb888(pixel, 1);
211 *(fb + (j * panel_width) + i) =
212 conv_rgb565_to_rgb888(pixel, 0);
217 static void draw_samsung_logo(void* lcdbase)
221 x = ((panel_width - 298) >> 1);
222 y = ((panel_height - 78) >> 1) - 5;
224 _draw_samsung_logo(lcdbase, x, y, 298, 78, (unsigned short *) logo);
227 static void s5pc_init_panel_info(vidinfo_t *vid, struct lcd_panel_operation *calls)
230 printf("lcd info is NULL.\n");
235 printf("lcd calls is NULL.\n");
242 vid->vl_height = 800,
243 vid->vl_clkp = CONFIG_SYS_HIGH,
244 vid->vl_hsp = CONFIG_SYS_LOW,
245 vid->vl_vsp = CONFIG_SYS_LOW,
246 vid->vl_dp = CONFIG_SYS_HIGH,
249 /* S6E63M0 LCD Panel */
250 vid->vl_hpw = 2, /* HLW */
251 vid->vl_blw = 16, /* HBP */
252 vid->vl_elw = 16, /* HFP */
254 vid->vl_vpw = 2, /* VLW */
255 vid->vl_bfw = 3, /* VBP */
256 vid->vl_efw = 28, /* VFP */
258 calls->lcd_panel_init = s6e63m0_lcd_panel_init;
259 calls->lcd_panel_power_on = s6e63m0_lcd_panel_power_on;
260 calls->lcd_panel_enable = s6e63m0_lcd_panel_enable;
266 vid->vl_height = 800,
267 vid->vl_clkp = CONFIG_SYS_HIGH,
268 vid->vl_hsp = CONFIG_SYS_LOW,
269 vid->vl_vsp = CONFIG_SYS_LOW,
270 vid->vl_dp = CONFIG_SYS_HIGH,
282 calls->lcd_panel_init = /* */;
283 calls->lcd_panel_power_on = /* */;
284 calls->lcd_panel_enable = /* */;
289 vid->vl_width = 1024,
290 vid->vl_height = 600,
291 vid->vl_clkp = CONFIG_SYS_HIGH,
292 vid->vl_hsp = CONFIG_SYS_HIGH,
293 vid->vl_vsp = CONFIG_SYS_HIGH,
294 vid->vl_dp = CONFIG_SYS_LOW,
297 /* AMS701KA AMOLED Panel. */
306 calls->lcd_panel_init = /* */;
307 calls->lcd_panel_power_on = /* */;
308 calls->lcd_panel_enable = /* */;
311 panel_width = vid->vl_col;
312 panel_height = vid->vl_row;
315 static void lcd_panel_on(struct lcd_panel_operation *calls)
318 printf("lcd calls is NULL.\n");
322 if (calls->lcd_panel_init)
323 calls->lcd_panel_init();
324 if (calls->lcd_panel_power_on)
325 calls->lcd_panel_power_on();
326 if (calls->lcd_panel_enable)
327 calls->lcd_panel_enable();
330 void lcd_ctrl_init(void *lcdbase)
334 s5pc_lcd_init_mem(lcdbase, &panel_info);
336 /* initialize parameters which is specific to panel. */
337 s5pc_init_panel_info(&panel_info, &lcd_calls);
339 option = getenv("lcd");
342 if (strcmp(option, "test") == 0) {
343 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
345 } else if (strcmp(option, "image") == 0)
346 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
348 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
349 draw_samsung_logo(lcdbase);
353 memset(lcdbase, 0, panel_width * panel_height * (32 >> 3));
354 draw_samsung_logo(lcdbase);
358 s5pc_lcd_init(&panel_info);
363 set_font_color(FONT_WHITE);
370 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
375 void lcd_enable(void)
377 lcd_panel_on((struct lcd_panel_operation *) &lcd_calls);
380 ulong calc_fbsize(void)
382 return s5pc_fimd_calc_fbsize();
385 void s5pc1xxfb_test(void *lcdbase)
387 lcd_ctrl_init(lcdbase);