2 * S5PC100 and S5PC110 LCD Controller Specific 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,
25 #include <linux/types.h>
29 #include <asm/arch/cpu.h>
30 #include <asm/arch/regs-fb.h>
31 #include <asm/arch/hardware.h>
36 /* LCD Panel definitions */
37 #define PANEL_WIDTH 480
38 #define PANEL_HEIGHT 800
39 #define S5P_LCD_BPP 32
45 #define S5PCFB_HRES 480
46 #define S5PCFB_VRES 800
48 #define S5PCFB_HRES_VIRTUAL 480
49 #define S5PCFB_VRES_VIRTUAL 800
51 #define S5PCFB_HRES_OSD 480
52 #define S5PCFB_VRES_OSD 800
54 #define S5P_VFRAME_FREQ 60
56 static unsigned int ctrl_base;
57 static unsigned long *lcd_base_addr;
59 extern unsigned long get_pll_clk(int pllreg);
61 void s5pc_fimd_lcd_init_mem(u_long screen_base, u_long fb_size, u_long palette_size)
63 lcd_base_addr = (unsigned long *)screen_base;
65 udebug("lcd_base_addr(framebuffer memory) = %x\n", lcd_base_addr);
70 void s5pc_c100_gpio_setup(void)
72 /* set GPF0[0:7] for RGB Interface and Data lines */
73 writel(0x22222222, 0xE03000E0);
76 writel(0x22222222, 0xE0300100);
77 writel(0x22222222, 0xE0300120);
78 writel(0x2222, 0xE0300140);
80 /* set gpio configuration pin for MLCD_RST */
81 writel(0x10000000, 0xE0300C20);
83 /* set gpio configuration pin for MLCD_ON */
84 writel(0x1000, 0xE0300220);
85 writel(readl(0xE0300224) & 0xf7, 0xE0300224);
87 /* set gpio configuration pin for DISPLAY_CS, DISPLAY_CLK and DISPLSY_SI */
88 writel(0x11100000, 0xE0300300);
91 void s5pc_c110_gpio_setup(void)
93 /* set GPF0[0:7] for RGB Interface and Data lines */
94 writel(0x22222222, 0xE0200120);
95 /* pull-up/down disable */
96 writel(0x0, 0xE0200128);
97 /* drive strength to max */
98 writel(0xffffffff, 0xE020012C);
101 writel(0x22222222, 0xE0200140);
102 writel(0x22222222, 0xE0200160);
103 writel(readl(0xE0200180) & 0xFF0000, 0xE0200180);
104 writel(readl(0xE0200180) | 0x002222, 0xE0200180);
106 /* drive strength to max */
107 writel(0xffffffff, 0xE020014C);
108 writel(0xffffffff, 0xE020016C);
109 writel(readl(0xE020018C) & 0xFF00, 0xE020018C);
110 writel(readl(0xE020018C) | 0x00FF, 0xE020018C);
112 /* pull-up/down disable */
113 writel(0x0, 0xE0200148);
114 writel(0x0, 0xE0200168);
115 writel(0x0, 0xE0200188);
117 /* display output path selection */
118 writel(0x2, 0xE0107008);
120 /* set gpio configuration pin for MLCD_RST */
121 writel(readl(0xE0200C20) & 0x0fffffff, 0xE0200C20);
122 writel(readl(0xE0200C20) | 0x10000000, 0xE0200C20);
124 /* set gpio configuration pin for MLCD_ON */
125 writel(readl(0xE0200260) & 0xFFFF0FFF, 0xE0200260);
126 writel(readl(0xE0200260) | 0x00001000, 0xE0200260);
127 writel(readl(0xE0200264) & 0xf7, 0xE0200264);
129 /* set gpio configuration pin for DISPLAY_CS, DISPLAY_CLK, DISPLSY_SI and LCD_ID */
130 writel(readl(0xE02002E0) & 0xFFFFFF0F, 0xE02002E0);
131 writel(readl(0xE02002E0) | 0x00000010, 0xE02002E0);
132 writel(readl(0xE0200340) & 0xFFFF000F, 0xE0200340);
133 writel(readl(0xE0200340) | 0x00001110, 0xE0200340);
138 static void s5pc_fimd_set_par(unsigned int win_id)
140 unsigned int cfg = 0;
142 /* set window control */
143 cfg = readl(ctrl_base + S5P_WINCON(win_id));
145 cfg &= ~(S5P_WINCON_BITSWP_ENABLE | S5P_WINCON_BYTESWP_ENABLE | \
146 S5P_WINCON_HAWSWP_ENABLE | S5P_WINCON_WSWP_ENABLE | \
147 S5P_WINCON_BURSTLEN_MASK | S5P_WINCON_BPPMODE_MASK | \
148 S5P_WINCON_INRGB_MASK | S5P_WINCON_DATAPATH_MASK);
150 /* DATAPATH is DMA */
151 cfg |= S5P_WINCON_DATAPATH_DMA;
154 cfg |= S5P_WINCON_WSWP_ENABLE;
156 /* dma burst is 16 */
157 cfg |= S5P_WINCON_BURSTLEN_16WORD;
159 /* pixel format is unpacked RGB888 */
160 cfg |= S5P_WINCON_BPPMODE_24BPP_888;
162 writel(cfg, ctrl_base + S5P_WINCON(win_id));
163 udebug("wincon%d = %x\n", win_id, cfg);
165 /* set window position to x=0, y=0*/
166 cfg = S5P_VIDOSD_LEFT_X(0) | S5P_VIDOSD_TOP_Y(0);
167 writel(cfg, ctrl_base + S5P_VIDOSD_A(win_id));
168 udebug("window postion left,top = %x\n", cfg);
170 cfg = S5P_VIDOSD_RIGHT_X(PANEL_WIDTH - 1) |
171 S5P_VIDOSD_BOTTOM_Y(PANEL_HEIGHT - 1);
172 writel(cfg, ctrl_base + S5P_VIDOSD_B(win_id));
173 udebug("window postion right,bottom= %x\n", cfg);
175 /* set window size for window0*/
176 cfg = S5P_VIDOSD_SIZE(PANEL_WIDTH * PANEL_HEIGHT);
177 writel(cfg, ctrl_base + S5P_VIDOSD_C(win_id));
178 udebug("vidosd_c%d= %x\n", win_id, cfg);
183 static void s5pc_fimd_set_buffer_address(unsigned int win_id)
185 unsigned long start_addr, end_addr;
187 start_addr = (unsigned long)lcd_base_addr;
188 end_addr = start_addr + ((PANEL_WIDTH * (S5P_LCD_BPP / 8))
191 writel(start_addr, ctrl_base + S5P_VIDADDR_START0(win_id));
192 writel(end_addr, ctrl_base + S5P_VIDADDR_END0(win_id));
194 udebug("start addr = %x, end addr = %x\n", start_addr, end_addr);
199 static void s5pc_fimd_set_clock(vidinfo_t *vid)
201 unsigned int cfg = 0, div = 0, mpll_ratio = 0;
202 unsigned long pixel_clock, src_clock, max_clock;
204 max_clock = 66 * 1000000;
206 pixel_clock = S5P_VFRAME_FREQ * (vid->vl_hpw + vid->vl_blw + vid->vl_elw + vid->vl_width) *
207 (vid->vl_vpw + vid->vl_bfw + vid->vl_efw + vid->vl_height);
209 src_clock = get_pll_clk(MPLL);
211 cfg = readl(ctrl_base + S5P_VIDCON0);
212 cfg &= ~(S5P_VIDCON0_CLKSEL_MASK | S5P_VIDCON0_CLKVALUP_MASK | \
213 S5P_VIDCON0_VCLKEN_MASK | S5P_VIDCON0_CLKDIR_MASK);
214 cfg |= (S5P_VIDCON0_CLKSEL_HCLK | S5P_VIDCON0_CLKVALUP_ALWAYS | \
215 S5P_VIDCON0_VCLKEN_NORMAL | S5P_VIDCON0_CLKDIR_DIVIDED);
217 if (pixel_clock > max_clock)
218 pixel_clock = max_clock;
221 if (cpu_is_s5pc110())
222 mpll_ratio = (readl(0xE0100300) & 0xf0000) >> 16;
224 mpll_ratio = (readl(0xE0100304) & 0xf0) >> 4;
227 * It can get sorce clock speed as (mpll / mpll_ratio)
228 * because lcd controller uses hclk_dsys.
229 * mpll is a parent of hclk_dsys.
231 div = (unsigned int)((src_clock / (mpll_ratio + 1)) / pixel_clock);
232 cfg |= S5P_VIDCON0_CLKVAL_F(div - 1);
233 writel(cfg, ctrl_base + S5P_VIDCON0);
235 udebug("mpll_ratio = %d, src_clock = %d, pixel_clock = %d, div = %d\n",
236 mpll_ratio, src_clock, pixel_clock, div);
241 void s5pc_fimd_lcd_init(vidinfo_t *vid)
243 unsigned int cfg = 0, rgb_mode, win_id = 0;
245 /* select register base according to cpu type */
246 if (cpu_is_s5pc110())
247 ctrl_base = 0xF8000000;
249 ctrl_base = 0xEE000000;
251 /* set output to RGB */
252 rgb_mode = MODE_RGB_P;
253 cfg = readl(ctrl_base + S5P_VIDCON0);
254 cfg &= ~S5P_VIDCON0_VIDOUT_MASK;
256 /* clock source is HCLK */
259 cfg |= S5P_VIDCON0_VIDOUT_RGB;
260 writel(cfg, ctrl_base + S5P_VIDCON0);
262 /* set display mode */
263 cfg = readl(ctrl_base + S5P_VIDCON0);
264 cfg &= ~S5P_VIDCON0_PNRMODE_MASK;
265 cfg |= (rgb_mode << S5P_VIDCON0_PNRMODE_SHIFT);
266 writel(cfg, ctrl_base + S5P_VIDCON0);
270 cfg |= S5P_VIDCON1_IVDEN_INVERT | S5P_VIDCON1_IVCLK_RISING_EDGE;
271 writel(cfg, ctrl_base + S5P_VIDCON1);
276 //cfg |= S5P_VIDTCON0_VBPDE(S5PCFB_VBPE - 1);
277 cfg |= S5P_VIDTCON0_VBPD(vid->vl_bfw - 1);
278 cfg |= S5P_VIDTCON0_VFPD(vid->vl_efw - 1);
279 cfg |= S5P_VIDTCON0_VSPW(vid->vl_vpw - 1);
280 writel(cfg, ctrl_base + S5P_VIDTCON0);
281 udebug("vidtcon0 = %x\n", cfg);
284 //cfg |= S5P_VIDTCON1_VFPDE(S5PCFB_VFPE - 1);
285 cfg |= S5P_VIDTCON1_HBPD(vid->vl_blw - 1);
286 cfg |= S5P_VIDTCON1_HFPD(vid->vl_elw - 1);
287 cfg |= S5P_VIDTCON1_HSPW(vid->vl_hpw - 1);
289 writel(cfg, ctrl_base + S5P_VIDTCON1);
290 udebug("vidtcon1 = %x\n", cfg);
294 cfg |= S5P_VIDTCON2_HOZVAL(PANEL_WIDTH - 1);
295 cfg |= S5P_VIDTCON2_LINEVAL(PANEL_HEIGHT - 1);
297 writel(cfg, ctrl_base + S5P_VIDTCON2);
298 udebug("vidtcon2 = %x\n", cfg);
301 s5pc_fimd_set_par(win_id);
303 /* set memory address */
304 s5pc_fimd_set_buffer_address(win_id);
306 /* set buffer size */
307 cfg = S5P_VIDADDR_PAGEWIDTH(PANEL_WIDTH * S5P_LCD_BPP / 8);
308 writel(cfg, ctrl_base + S5P_VIDADDR_SIZE(win_id));
309 udebug("vidaddr_pagewidth = %d\n", cfg);
312 s5pc_fimd_set_clock(vid);
315 cfg = readl(ctrl_base + S5P_VIDCON0);
316 cfg |= (S5P_VIDCON0_ENVID_ENABLE | S5P_VIDCON0_ENVID_F_ENABLE);
317 writel(cfg, ctrl_base + S5P_VIDCON0);
318 udebug("vidcon0 = %x\n", cfg);
321 cfg = readl(ctrl_base + S5P_WINCON(win_id));
322 cfg |= S5P_WINCON_ENWIN_ENABLE;
323 writel(cfg, ctrl_base + S5P_WINCON(win_id));
324 udebug("wincon%d=%x\n", win_id, cfg);
326 udebug("lcd controller init completed.\n");
331 ulong s5pc_fimd_calc_fbsize(void)
333 return (PANEL_WIDTH * PANEL_HEIGHT * (S5P_LCD_BPP / 8));