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>
35 #include "logo_rgb24_wvga_portrait.h"
36 #include "opening_logo_rgb24_143_44.h"
39 extern void tl2796_panel_power_on(void);
40 extern void tl2796_panel_enable(void);
41 extern void tl2796_panel_init(void);
48 void *lcd_console_address;
53 static unsigned int panel_width, panel_height;
56 static unsigned short makepixel565(char r, char g, char b)
58 return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
61 static unsigned int makepixel8888(char a, char r, char g, char b)
63 return (unsigned int)((a << 24) | (r << 16) | (g << 8) | b);
66 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
67 int y2pos, unsigned short pixel)
69 unsigned short *pDst = (unsigned short *)pImg;
70 unsigned int offset_s;
73 for(i = y1pos; i < y2pos; i++) {
74 for(j = x1pos; j < x2pos; j++) {
75 offset_s = i * panel_width + j;
76 *(pDst + offset_s) = pixel;
81 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
82 int y2pos, unsigned int pixel)
84 unsigned int *pDst = (unsigned int *)pImg;
85 unsigned int offset_s;
88 for (i = y1pos; i < y2pos; i++) {
89 for (j = x1pos; j < x2pos; j++) {
90 offset_s = i * panel_width + j;
91 *(pDst+offset_s) = pixel;
100 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
102 unsigned long palette_size, palette_mem_size;
103 unsigned int fb_size;
105 fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix >> 3);
109 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
110 palette_mem_size = palette_size * sizeof(u32);
112 s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
114 udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
115 fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
118 static void s5pc_lcd_init(vidinfo_t *vid)
120 s5pc_fimd_lcd_init(vid);
124 static void lcd_test(unsigned int width, unsigned int height)
126 unsigned int height_level = height / 3;
129 read_image32((char *)lcd_base, 0, 0, width, height_level,
130 makepixel8888(0, 255, 0, 0));
132 read_image32((char *)lcd_base, 0, height_level, width,
133 height_level * 2, makepixel8888(0, 0, 255, 0));
135 read_image32((char *)lcd_base, 0, height_level * 2, width, height,
136 makepixel8888(0, 0, 0, 255));
140 int conv_rgb565_to_rgb888(unsigned short rgb565, unsigned int sw)
142 char red, green, blue;
143 unsigned int threshold = 150;
145 red = (rgb565 & 0xF800) >> 11;
146 green = (rgb565 & 0x7E0) >> 5;
147 blue = (rgb565 & 0x1F);
153 /* correct error pixels of samsung logo. */
157 if (green > threshold)
159 if (blue > threshold)
163 return (red << 16 | green << 8 | blue);
166 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
170 unsigned long *fb = (unsigned long*)lcdbase;
172 for (j = y; j < (y + h); j++) {
173 for (i = x; i < (x + w); i++)
174 *(fb + (j * panel_width) + i) = *(bmp + k++);
178 void _draw_samsung_logo(void *lcdbase, int x, int y, int w, int h, unsigned short *bmp)
180 int i, j, error_range = 40;
183 unsigned long *fb = (unsigned long*)lcdbase;
185 for (j = y; j < (y + h); j++) {
186 for (i = x; i < (x + w); i++) {
187 pixel = (*(bmp + k++));
189 /* 40 lines under samsung logo image are error range. */
190 if (j > h + y - error_range)
191 *(fb + (j * panel_width) + i) =
192 conv_rgb565_to_rgb888(pixel, 1);
194 *(fb + (j * panel_width) + i) =
195 conv_rgb565_to_rgb888(pixel, 0);
200 static void draw_samsung_logo(void* lcdbase)
203 unsigned int in_len, width, height;
204 unsigned long out_len;
208 x = ((panel_width - width) >> 1);
209 y = ((panel_height - height) >> 1) - 5;
211 in_len = width * height * 4;
212 dst = malloc(in_len);
214 printf("Error: malloc in gunzip failed!\n");
217 if (gunzip(dst, in_len, (uchar *)logo, &out_len) != 0) {
221 if (out_len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
222 printf("Image could be truncated"
223 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
224 _draw_samsung_logo(lcdbase, x, y, width, height, (unsigned short *) dst);
227 static void lcd_panel_on(vidinfo_t *vid)
229 udelay(vid->init_delay);
234 if (vid->lcd_power_on)
235 vid->lcd_power_on(1);
237 udelay(vid->power_on_delay);
242 udelay(vid->reset_delay);
244 if (vid->backlight_on)
245 vid->backlight_on(1);
257 /* extern void init_onenand_ext2(void); */
258 extern void init_panel_info(vidinfo_t *vid);
260 void lcd_ctrl_init(void *lcdbase)
264 s5pc_lcd_init_mem(lcdbase, &panel_info);
266 /* initialize parameters which is specific to panel. */
267 init_panel_info(&panel_info);
269 panel_width = panel_info.vl_width;
270 panel_height = panel_info.vl_height;
272 option = getenv("lcd");
275 if (strcmp(option, "test") == 0) {
276 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
278 lcd_test(panel_width, panel_height);
280 } else if (strcmp(option, "image") == 0)
281 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
283 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
284 draw_samsung_logo(lcdbase);
288 memset(lcdbase, 0, panel_width * panel_height * (32 >> 3));
289 draw_samsung_logo(lcdbase);
291 s5pc_lcd_init(&panel_info);
296 set_font_color(FONT_WHITE);
301 /* init_onenand_ext2(); */
305 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
310 void lcd_enable(void)
312 lcd_panel_on(&panel_info);
315 ulong calc_fbsize(void)
317 return s5pc_fimd_calc_fbsize();
320 void s5pc1xxfb_test(void *lcdbase)
322 lcd_ctrl_init(lcdbase);