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 #define PANEL_WIDTH 480
39 #define PANEL_HEIGHT 800
40 #define S5P_LCD_BPP 32
42 #define PANEL_WIDTH 1024
43 #define PANEL_HEIGHT 600
44 #define S5P_LCD_BPP 32
47 extern void tl2796_panel_power_on(void);
48 extern void tl2796_panel_enable(void);
49 extern void tl2796_panel_init(void);
56 void *lcd_console_address;
61 static unsigned short makepixel565(char r, char g, char b)
63 return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
66 static unsigned int makepixel8888(char a, char r, char g, char b)
68 return (unsigned int)((a << 24) | (r << 16) | (g << 8) | b);
71 static void read_image16(char* pImg, int x1pos, int y1pos, int x2pos,
72 int y2pos, unsigned short pixel)
74 unsigned short *pDst = (unsigned short *)pImg;
75 unsigned int offset_s;
78 for(i = y1pos; i < y2pos; i++) {
79 for(j = x1pos; j < x2pos; j++) {
80 offset_s = i * PANEL_WIDTH + j;
81 *(pDst + offset_s) = pixel;
86 static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
87 int y2pos, unsigned int pixel)
89 unsigned int *pDst = (unsigned int *)pImg;
90 unsigned int offset_s;
93 for(i = y1pos; i < y2pos; i++) {
94 for(j = x1pos; j < x2pos; j++) {
95 offset_s = i * PANEL_WIDTH + j;
96 *(pDst+offset_s) = pixel;
102 vidinfo_t panel_info = {
103 .vl_col = PANEL_WIDTH,
104 .vl_row = PANEL_HEIGHT,
105 .vl_width = PANEL_WIDTH,
106 .vl_height = PANEL_HEIGHT,
107 .vl_clkp = CONFIG_SYS_HIGH,
108 .vl_hsp = CONFIG_SYS_LOW,
109 .vl_vsp = CONFIG_SYS_LOW,
110 .vl_dp = CONFIG_SYS_HIGH,
111 .vl_bpix = S5P_LCD_BPP,
117 /* S6E63M0 LCD Panel */
134 /* AMS701KA AMOLED Panel
145 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
147 unsigned long palette_size, palette_mem_size;
148 unsigned int fb_size;
150 fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix / 8);
154 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
155 palette_mem_size = palette_size * sizeof(u32);
157 s5pc_fimd_lcd_init_mem((unsigned long)lcd_base, (unsigned long)fb_size, palette_size);
159 udebug("fb_size=%d, screen_base=%x, palette_size=%d, palettle_mem_size=%d\n",
160 fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
163 static void s5pc_gpio_setup(void)
165 if (cpu_is_s5pc100())
166 s5pc_c100_gpio_setup();
168 s5pc_c110_gpio_setup();
171 static void s5pc_lcd_init(vidinfo_t *vid)
173 s5pc_fimd_lcd_init(vid);
176 static void lcd_test(void)
179 read_image32((char *)lcd_base, 0, 0, 480, 200,
180 makepixel8888(0, 255, 0, 0));
182 read_image32((char *)lcd_base, 0, 200, 480, 400,
183 makepixel8888(0, 0, 255, 0));
185 read_image32((char *)lcd_base, 0, 400, 480, 600,
186 makepixel8888(0, 0, 0, 255));
188 read_image32((char *)lcd_base, 0, 600, 480, 800,
189 makepixel8888(0, 255, 255, 255));
192 int conv_rgb565_to_rgb888(unsigned short rgb565, unsigned int sw)
194 char red, green, blue;
195 unsigned int threshold = 150;
197 red = (rgb565 & 0xF800) >> 11;
198 green = (rgb565 & 0x7E0) >> 5;
199 blue = (rgb565 & 0x1F);
205 /* correct error pixels of samsung logo. */
209 if (green > threshold)
211 if (blue > threshold)
215 return (red << 16 | green << 8 | blue);
218 void draw_bitmap(void *lcdbase, int x, int y, int w, int h, unsigned long *bmp)
222 unsigned long *fb = (unsigned long*)lcdbase;
224 for (j = y; j < (y + h); j++) {
225 for (i = x; i < (x + w); i++)
226 *(fb + (j * PANEL_WIDTH) + i) = *(bmp + k++);
230 void _draw_samsung_logo(void *lcdbase, int x, int y, int w, int h, unsigned short *bmp)
232 int i, j, error_range = 40;
235 unsigned long *fb = (unsigned long*)lcdbase;
237 for (j = y; j < (y + h); j++) {
238 for (i = x; i < (x + w); i++) {
239 pixel = (*(bmp + k++));
241 /* 40 lines under samsung logo image are error range. */
242 if (j > h + y - error_range)
243 *(fb + (j * PANEL_WIDTH) + i) =
244 conv_rgb565_to_rgb888(pixel, 1);
246 *(fb + (j * PANEL_WIDTH) + i) =
247 conv_rgb565_to_rgb888(pixel, 0);
252 static void draw_samsung_logo(void* lcdbase)
256 x = (PANEL_WIDTH - 298) / 2;
257 y = (PANEL_HEIGHT - 78) / 2 - 5;
259 _draw_samsung_logo(lcdbase, x, y, 298, 78, (unsigned short *) logo);
262 static void lcd_panel_on(void)
265 lcd_panel_power_on();
270 void lcd_ctrl_init(void *lcdbase)
274 s5pc_lcd_init_mem(lcdbase, &panel_info);
276 option = getenv("lcd");
279 if (strcmp(option, "test") == 0) {
280 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
282 } else if (strcmp(option, "image") == 0)
283 memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
285 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
286 draw_samsung_logo(lcdbase);
290 memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
291 draw_samsung_logo(lcdbase);
295 s5pc_lcd_init(&panel_info);
300 set_font_color(FONT_WHITE);
307 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
312 void lcd_enable(void)
317 ulong calc_fbsize(void)
319 return s5pc_fimd_calc_fbsize();
322 void s5pc1xxfb_test(void *lcdbase)
324 lcd_ctrl_init(lcdbase);
327 //memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);