blob: a1de9ac38cdf9946fe5ba72332a8dd00962b9899 [file] [log] [blame]
Donghwa Lee0112fed2012-04-05 19:36:17 +00001/*
2 * Copyright (C) 2012 Samsung Electronics
3 *
4 * Author: InKi Dae <inki.dae@samsung.com>
5 * Author: Donghwa Lee <dh09.lee@samsung.com>
6 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
Donghwa Lee0112fed2012-04-05 19:36:17 +00008 */
9
10#include <config.h>
11#include <common.h>
12#include <asm/io.h>
13#include <lcd.h>
14#include <div64.h>
Ajay Kumarebbace32013-02-21 23:53:01 +000015#include <fdtdec.h>
16#include <libfdt.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000017#include <asm/arch/clk.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/cpu.h>
20#include "exynos_fb.h"
21
Ajay Kumarebbace32013-02-21 23:53:01 +000022DECLARE_GLOBAL_DATA_PTR;
23
Simon Glass6d275592016-02-21 21:08:40 -070024static struct vidinfo *pvid;
Ajay Kumar4acd4ee2013-02-21 23:52:59 +000025static struct exynos_fb *fimd_ctrl;
Donghwa Lee0112fed2012-04-05 19:36:17 +000026
Donghwa Lee0112fed2012-04-05 19:36:17 +000027static void exynos_fimd_set_dualrgb(unsigned int enabled)
28{
Donghwa Lee0112fed2012-04-05 19:36:17 +000029 unsigned int cfg = 0;
30
31 if (enabled) {
32 cfg = EXYNOS_DUALRGB_BYPASS_DUAL | EXYNOS_DUALRGB_LINESPLIT |
33 EXYNOS_DUALRGB_VDEN_EN_ENABLE;
34
35 /* in case of Line Split mode, MAIN_CNT doesn't neet to set. */
36 cfg |= EXYNOS_DUALRGB_SUB_CNT(pvid->vl_col / 2) |
37 EXYNOS_DUALRGB_MAIN_CNT(0);
38 }
39
40 writel(cfg, &fimd_ctrl->dualrgb);
41}
42
Simon Glass4d022cc2016-02-21 21:08:41 -070043static void exynos_fimd_set_dp_clkcon(struct vidinfo *pvid,
44 unsigned int enabled)
Donghwa Leebc72aeb2012-07-02 01:16:08 +000045{
Donghwa Leebc72aeb2012-07-02 01:16:08 +000046 unsigned int cfg = 0;
47
48 if (enabled)
49 cfg = EXYNOS_DP_CLK_ENABLE;
50
51 writel(cfg, &fimd_ctrl->dp_mie_clkcon);
52}
53
Simon Glass4d022cc2016-02-21 21:08:41 -070054static void exynos_fimd_set_par(struct vidinfo *pvid, unsigned int win_id)
Donghwa Lee0112fed2012-04-05 19:36:17 +000055{
56 unsigned int cfg = 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +000057
58 /* set window control */
59 cfg = readl((unsigned int)&fimd_ctrl->wincon0 +
60 EXYNOS_WINCON(win_id));
61
62 cfg &= ~(EXYNOS_WINCON_BITSWP_ENABLE | EXYNOS_WINCON_BYTESWP_ENABLE |
63 EXYNOS_WINCON_HAWSWP_ENABLE | EXYNOS_WINCON_WSWP_ENABLE |
64 EXYNOS_WINCON_BURSTLEN_MASK | EXYNOS_WINCON_BPPMODE_MASK |
65 EXYNOS_WINCON_INRGB_MASK | EXYNOS_WINCON_DATAPATH_MASK);
66
67 /* DATAPATH is DMA */
68 cfg |= EXYNOS_WINCON_DATAPATH_DMA;
69
Przemyslaw Marczak65b3f772014-01-22 11:24:15 +010070 cfg |= EXYNOS_WINCON_HAWSWP_ENABLE;
Donghwa Lee0112fed2012-04-05 19:36:17 +000071
72 /* dma burst is 16 */
73 cfg |= EXYNOS_WINCON_BURSTLEN_16WORD;
74
Przemyslaw Marczak65b3f772014-01-22 11:24:15 +010075 switch (pvid->vl_bpix) {
76 case 4:
Ajay Kumar1e655b32013-01-08 20:42:25 +000077 cfg |= EXYNOS_WINCON_BPPMODE_16BPP_565;
Przemyslaw Marczak65b3f772014-01-22 11:24:15 +010078 break;
79 default:
80 cfg |= EXYNOS_WINCON_BPPMODE_24BPP_888;
81 break;
82 }
Donghwa Lee0112fed2012-04-05 19:36:17 +000083
84 writel(cfg, (unsigned int)&fimd_ctrl->wincon0 +
85 EXYNOS_WINCON(win_id));
86
87 /* set window position to x=0, y=0*/
88 cfg = EXYNOS_VIDOSD_LEFT_X(0) | EXYNOS_VIDOSD_TOP_Y(0);
89 writel(cfg, (unsigned int)&fimd_ctrl->vidosd0a +
90 EXYNOS_VIDOSD(win_id));
91
92 cfg = EXYNOS_VIDOSD_RIGHT_X(pvid->vl_col - 1) |
Donghwa Lee64b45d92012-07-26 15:30:49 +000093 EXYNOS_VIDOSD_BOTTOM_Y(pvid->vl_row - 1) |
94 EXYNOS_VIDOSD_RIGHT_X_E(1) |
95 EXYNOS_VIDOSD_BOTTOM_Y_E(0);
96
Donghwa Lee0112fed2012-04-05 19:36:17 +000097 writel(cfg, (unsigned int)&fimd_ctrl->vidosd0b +
98 EXYNOS_VIDOSD(win_id));
99
100 /* set window size for window0*/
101 cfg = EXYNOS_VIDOSD_SIZE(pvid->vl_col * pvid->vl_row);
102 writel(cfg, (unsigned int)&fimd_ctrl->vidosd0c +
103 EXYNOS_VIDOSD(win_id));
104}
105
Simon Glass4d022cc2016-02-21 21:08:41 -0700106static void exynos_fimd_set_buffer_address(struct vidinfo *pvid,
107 unsigned int win_id,
108 ulong lcd_base_addr)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000109{
110 unsigned long start_addr, end_addr;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000111
Simon Glass4d022cc2016-02-21 21:08:41 -0700112 start_addr = lcd_base_addr;
Donghwa Lee2386f452012-04-23 15:37:05 +0000113 end_addr = start_addr + ((pvid->vl_col * (NBITS(pvid->vl_bpix) / 8)) *
Donghwa Lee0112fed2012-04-05 19:36:17 +0000114 pvid->vl_row);
115
116 writel(start_addr, (unsigned int)&fimd_ctrl->vidw00add0b0 +
117 EXYNOS_BUFFER_OFFSET(win_id));
118 writel(end_addr, (unsigned int)&fimd_ctrl->vidw00add1b0 +
119 EXYNOS_BUFFER_OFFSET(win_id));
120}
121
Simon Glass6d275592016-02-21 21:08:40 -0700122static void exynos_fimd_set_clock(struct vidinfo *pvid)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000123{
124 unsigned int cfg = 0, div = 0, remainder, remainder_div;
125 unsigned long pixel_clock;
126 unsigned long long src_clock;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000127
128 if (pvid->dual_lcd_enabled) {
129 pixel_clock = pvid->vl_freq *
130 (pvid->vl_hspw + pvid->vl_hfpd +
131 pvid->vl_hbpd + pvid->vl_col / 2) *
132 (pvid->vl_vspw + pvid->vl_vfpd +
133 pvid->vl_vbpd + pvid->vl_row);
134 } else if (pvid->interface_mode == FIMD_CPU_INTERFACE) {
135 pixel_clock = pvid->vl_freq *
136 pvid->vl_width * pvid->vl_height *
137 (pvid->cs_setup + pvid->wr_setup +
138 pvid->wr_act + pvid->wr_hold + 1);
139 } else {
140 pixel_clock = pvid->vl_freq *
141 (pvid->vl_hspw + pvid->vl_hfpd +
142 pvid->vl_hbpd + pvid->vl_col) *
143 (pvid->vl_vspw + pvid->vl_vfpd +
144 pvid->vl_vbpd + pvid->vl_row);
145 }
146
147 cfg = readl(&fimd_ctrl->vidcon0);
148 cfg &= ~(EXYNOS_VIDCON0_CLKSEL_MASK | EXYNOS_VIDCON0_CLKVALUP_MASK |
149 EXYNOS_VIDCON0_CLKVAL_F(0xFF) | EXYNOS_VIDCON0_VCLKEN_MASK |
150 EXYNOS_VIDCON0_CLKDIR_MASK);
151 cfg |= (EXYNOS_VIDCON0_CLKSEL_SCLK | EXYNOS_VIDCON0_CLKVALUP_ALWAYS |
152 EXYNOS_VIDCON0_VCLKEN_NORMAL | EXYNOS_VIDCON0_CLKDIR_DIVIDED);
153
Donghwa Lee0112fed2012-04-05 19:36:17 +0000154 src_clock = (unsigned long long) get_lcd_clk();
155
156 /* get quotient and remainder. */
157 remainder = do_div(src_clock, pixel_clock);
158 div = src_clock;
159
160 remainder *= 10;
161 remainder_div = remainder / pixel_clock;
162
163 /* round about one places of decimals. */
164 if (remainder_div >= 5)
165 div++;
166
167 /* in case of dual lcd mode. */
168 if (pvid->dual_lcd_enabled)
169 div--;
170
171 cfg |= EXYNOS_VIDCON0_CLKVAL_F(div - 1);
172 writel(cfg, &fimd_ctrl->vidcon0);
173}
174
175void exynos_set_trigger(void)
176{
177 unsigned int cfg = 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000178
179 cfg = readl(&fimd_ctrl->trigcon);
180
181 cfg |= (EXYNOS_I80SOFT_TRIG_EN | EXYNOS_I80START_TRIG);
182
183 writel(cfg, &fimd_ctrl->trigcon);
184}
185
186int exynos_is_i80_frame_done(void)
187{
188 unsigned int cfg = 0;
189 int status;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000190
191 cfg = readl(&fimd_ctrl->trigcon);
192
193 /* frame done func is valid only when TRIMODE[0] is set to 1. */
194 status = (cfg & EXYNOS_I80STATUS_TRIG_DONE) ==
195 EXYNOS_I80STATUS_TRIG_DONE;
196
197 return status;
198}
199
200static void exynos_fimd_lcd_on(void)
201{
202 unsigned int cfg = 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000203
204 /* display on */
205 cfg = readl(&fimd_ctrl->vidcon0);
206 cfg |= (EXYNOS_VIDCON0_ENVID_ENABLE | EXYNOS_VIDCON0_ENVID_F_ENABLE);
207 writel(cfg, &fimd_ctrl->vidcon0);
208}
209
210static void exynos_fimd_window_on(unsigned int win_id)
211{
212 unsigned int cfg = 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000213
214 /* enable window */
215 cfg = readl((unsigned int)&fimd_ctrl->wincon0 +
216 EXYNOS_WINCON(win_id));
217 cfg |= EXYNOS_WINCON_ENWIN_ENABLE;
218 writel(cfg, (unsigned int)&fimd_ctrl->wincon0 +
219 EXYNOS_WINCON(win_id));
220
221 cfg = readl(&fimd_ctrl->winshmap);
222 cfg |= EXYNOS_WINSHMAP_CH_ENABLE(win_id);
223 writel(cfg, &fimd_ctrl->winshmap);
224}
225
226void exynos_fimd_lcd_off(void)
227{
228 unsigned int cfg = 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000229
230 cfg = readl(&fimd_ctrl->vidcon0);
231 cfg &= (EXYNOS_VIDCON0_ENVID_DISABLE | EXYNOS_VIDCON0_ENVID_F_DISABLE);
232 writel(cfg, &fimd_ctrl->vidcon0);
233}
234
235void exynos_fimd_window_off(unsigned int win_id)
236{
237 unsigned int cfg = 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000238
239 cfg = readl((unsigned int)&fimd_ctrl->wincon0 +
240 EXYNOS_WINCON(win_id));
241 cfg &= EXYNOS_WINCON_ENWIN_DISABLE;
242 writel(cfg, (unsigned int)&fimd_ctrl->wincon0 +
243 EXYNOS_WINCON(win_id));
244
245 cfg = readl(&fimd_ctrl->winshmap);
246 cfg &= ~EXYNOS_WINSHMAP_CH_DISABLE(win_id);
247 writel(cfg, &fimd_ctrl->winshmap);
248}
249
Ajay Kumare24c5022014-09-05 16:53:33 +0530250/*
251* The reset value for FIMD SYSMMU register MMU_CTRL is 3
252* on Exynos5420 and newer versions.
253* This means FIMD SYSMMU is on by default on Exynos5420
254* and newer versions.
255* Since in u-boot we don't use SYSMMU, we should disable
256* those FIMD SYSMMU.
257* Note that there are 2 SYSMMU for FIMD: m0 and m1.
258* m0 handles windows 0 and 4, and m1 handles windows 1, 2 and 3.
259* We disable both of them here.
260*/
261void exynos_fimd_disable_sysmmu(void)
262{
263 u32 *sysmmufimd;
264 unsigned int node;
265 int node_list[2];
266 int count;
267 int i;
268
269 count = fdtdec_find_aliases_for_id(gd->fdt_blob, "fimd",
270 COMPAT_SAMSUNG_EXYNOS_SYSMMU, node_list, 2);
271 for (i = 0; i < count; i++) {
272 node = node_list[i];
273 if (node <= 0) {
274 debug("Can't get device node for fimd sysmmu\n");
275 return;
276 }
277
278 sysmmufimd = (u32 *)fdtdec_get_addr(gd->fdt_blob, node, "reg");
279 if (!sysmmufimd) {
280 debug("Can't get base address for sysmmu fimdm0");
281 return;
282 }
283
284 writel(0x0, sysmmufimd);
285 }
286}
Donghwa Lee64b45d92012-07-26 15:30:49 +0000287
Simon Glass4d022cc2016-02-21 21:08:41 -0700288void exynos_fimd_lcd_init(struct vidinfo *vid, ulong lcd_base_address)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000289{
290 unsigned int cfg = 0, rgb_mode;
Donghwa Lee64b45d92012-07-26 15:30:49 +0000291 unsigned int offset;
Ajay Kumarebbace32013-02-21 23:53:01 +0000292 unsigned int node;
293
294 node = fdtdec_next_compatible(gd->fdt_blob,
295 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
296 if (node <= 0)
297 debug("exynos_fb: Can't get device node for fimd\n");
298
299 fimd_ctrl = (struct exynos_fb *)fdtdec_get_addr(gd->fdt_blob,
300 node, "reg");
301 if (fimd_ctrl == NULL)
302 debug("Can't get the FIMD base address\n");
Ajay Kumare24c5022014-09-05 16:53:33 +0530303
304 if (fdtdec_get_bool(gd->fdt_blob, node, "samsung,disable-sysmmu"))
305 exynos_fimd_disable_sysmmu();
306
Donghwa Lee64b45d92012-07-26 15:30:49 +0000307 offset = exynos_fimd_get_base_offset();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000308
309 /* store panel info to global variable */
310 pvid = vid;
311
Donghwa Lee37980dd2012-05-09 19:23:46 +0000312 rgb_mode = vid->rgb_mode;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000313
314 if (vid->interface_mode == FIMD_RGB_INTERFACE) {
315 cfg |= EXYNOS_VIDCON0_VIDOUT_RGB;
316 writel(cfg, &fimd_ctrl->vidcon0);
317
318 cfg = readl(&fimd_ctrl->vidcon2);
319 cfg &= ~(EXYNOS_VIDCON2_WB_MASK |
320 EXYNOS_VIDCON2_TVFORMATSEL_MASK |
321 EXYNOS_VIDCON2_TVFORMATSEL_YUV_MASK);
322 cfg |= EXYNOS_VIDCON2_WB_DISABLE;
323 writel(cfg, &fimd_ctrl->vidcon2);
324
325 /* set polarity */
326 cfg = 0;
327 if (!pvid->vl_clkp)
328 cfg |= EXYNOS_VIDCON1_IVCLK_RISING_EDGE;
329 if (!pvid->vl_hsp)
330 cfg |= EXYNOS_VIDCON1_IHSYNC_INVERT;
331 if (!pvid->vl_vsp)
332 cfg |= EXYNOS_VIDCON1_IVSYNC_INVERT;
333 if (!pvid->vl_dp)
334 cfg |= EXYNOS_VIDCON1_IVDEN_INVERT;
335
Donghwa Lee64b45d92012-07-26 15:30:49 +0000336 writel(cfg, (unsigned int)&fimd_ctrl->vidcon1 + offset);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000337
338 /* set timing */
339 cfg = EXYNOS_VIDTCON0_VFPD(pvid->vl_vfpd - 1);
340 cfg |= EXYNOS_VIDTCON0_VBPD(pvid->vl_vbpd - 1);
341 cfg |= EXYNOS_VIDTCON0_VSPW(pvid->vl_vspw - 1);
Donghwa Lee64b45d92012-07-26 15:30:49 +0000342 writel(cfg, (unsigned int)&fimd_ctrl->vidtcon0 + offset);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000343
344 cfg = EXYNOS_VIDTCON1_HFPD(pvid->vl_hfpd - 1);
345 cfg |= EXYNOS_VIDTCON1_HBPD(pvid->vl_hbpd - 1);
346 cfg |= EXYNOS_VIDTCON1_HSPW(pvid->vl_hspw - 1);
347
Donghwa Lee64b45d92012-07-26 15:30:49 +0000348 writel(cfg, (unsigned int)&fimd_ctrl->vidtcon1 + offset);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000349
350 /* set lcd size */
Donghwa Lee64b45d92012-07-26 15:30:49 +0000351 cfg = EXYNOS_VIDTCON2_HOZVAL(pvid->vl_col - 1) |
352 EXYNOS_VIDTCON2_LINEVAL(pvid->vl_row - 1) |
353 EXYNOS_VIDTCON2_HOZVAL_E(pvid->vl_col - 1) |
354 EXYNOS_VIDTCON2_LINEVAL_E(pvid->vl_row - 1);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000355
Donghwa Lee64b45d92012-07-26 15:30:49 +0000356 writel(cfg, (unsigned int)&fimd_ctrl->vidtcon2 + offset);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000357 }
358
359 /* set display mode */
360 cfg = readl(&fimd_ctrl->vidcon0);
361 cfg &= ~EXYNOS_VIDCON0_PNRMODE_MASK;
362 cfg |= (rgb_mode << EXYNOS_VIDCON0_PNRMODE_SHIFT);
363 writel(cfg, &fimd_ctrl->vidcon0);
364
365 /* set par */
Simon Glass4d022cc2016-02-21 21:08:41 -0700366 exynos_fimd_set_par(pvid, pvid->win_id);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000367
368 /* set memory address */
Simon Glass4d022cc2016-02-21 21:08:41 -0700369 exynos_fimd_set_buffer_address(pvid, pvid->win_id, lcd_base_address);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000370
371 /* set buffer size */
Donghwa Lee64b45d92012-07-26 15:30:49 +0000372 cfg = EXYNOS_VIDADDR_PAGEWIDTH(pvid->vl_col * NBITS(pvid->vl_bpix) / 8) |
373 EXYNOS_VIDADDR_PAGEWIDTH_E(pvid->vl_col * NBITS(pvid->vl_bpix) / 8) |
374 EXYNOS_VIDADDR_OFFSIZE(0) |
375 EXYNOS_VIDADDR_OFFSIZE_E(0);
376
Donghwa Lee0112fed2012-04-05 19:36:17 +0000377 writel(cfg, (unsigned int)&fimd_ctrl->vidw00add2 +
378 EXYNOS_BUFFER_SIZE(pvid->win_id));
379
380 /* set clock */
381 exynos_fimd_set_clock(pvid);
382
383 /* set rgb mode to dual lcd. */
384 exynos_fimd_set_dualrgb(pvid->dual_lcd_enabled);
385
386 /* display on */
387 exynos_fimd_lcd_on();
388
389 /* window on */
390 exynos_fimd_window_on(pvid->win_id);
Donghwa Leebc72aeb2012-07-02 01:16:08 +0000391
Simon Glass4d022cc2016-02-21 21:08:41 -0700392 exynos_fimd_set_dp_clkcon(pvid, pvid->dp_enabled);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000393}
394
395unsigned long exynos_fimd_calc_fbsize(void)
396{
Donghwa Lee2386f452012-04-23 15:37:05 +0000397 return pvid->vl_col * pvid->vl_row * (NBITS(pvid->vl_bpix) / 8);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000398}