blob: 83b1187c989e921ab394eb7e628187baa6d66627 [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>
Simon Glassc9ed7a42016-02-21 21:08:48 -070012#include <div64.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000013#include <lcd.h>
Ajay Kumarebbace32013-02-21 23:53:01 +000014#include <fdtdec.h>
15#include <libfdt.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000016#include <asm/io.h>
17#include <asm/arch/cpu.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/clk.h>
20#include <asm/arch/mipi_dsim.h>
Donghwa Leebc72aeb2012-07-02 01:16:08 +000021#include <asm/arch/dp_info.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000022#include <asm/arch/system.h>
Ajay Kumar39ea08b2015-03-04 19:05:26 +053023#include <asm/gpio.h>
Ajay Kumarebbace32013-02-21 23:53:01 +000024#include <asm-generic/errno.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000025
26#include "exynos_fb.h"
27
Ajay Kumarebbace32013-02-21 23:53:01 +000028DECLARE_GLOBAL_DATA_PTR;
29
Simon Glass6d275592016-02-21 21:08:40 -070030struct vidinfo panel_info = {
Ajay Kumar11763482014-09-05 16:53:30 +053031 /*
32 * Insert a value here so that we don't end up in the BSS
33 * Reference: drivers/video/tegra.c
34 */
35 .vl_col = -1,
Ajay Kumarebbace32013-02-21 23:53:01 +000036};
Ajay Kumarebbace32013-02-21 23:53:01 +000037
Simon Glass305f5812016-02-21 21:09:00 -070038static void exynos_fimd_set_dualrgb(struct vidinfo *priv, unsigned int enabled)
Simon Glassc9ed7a42016-02-21 21:08:48 -070039{
Simon Glass305f5812016-02-21 21:09:00 -070040 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -070041 unsigned int cfg = 0;
42
43 if (enabled) {
44 cfg = EXYNOS_DUALRGB_BYPASS_DUAL | EXYNOS_DUALRGB_LINESPLIT |
45 EXYNOS_DUALRGB_VDEN_EN_ENABLE;
46
47 /* in case of Line Split mode, MAIN_CNT doesn't neet to set. */
Simon Glass305f5812016-02-21 21:09:00 -070048 cfg |= EXYNOS_DUALRGB_SUB_CNT(priv->vl_col / 2) |
Simon Glassc9ed7a42016-02-21 21:08:48 -070049 EXYNOS_DUALRGB_MAIN_CNT(0);
50 }
51
Simon Glass305f5812016-02-21 21:09:00 -070052 writel(cfg, &reg->dualrgb);
Simon Glassc9ed7a42016-02-21 21:08:48 -070053}
54
Simon Glass305f5812016-02-21 21:09:00 -070055static void exynos_fimd_set_dp_clkcon(struct vidinfo *priv,
Simon Glassc9ed7a42016-02-21 21:08:48 -070056 unsigned int enabled)
57{
Simon Glass305f5812016-02-21 21:09:00 -070058 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -070059 unsigned int cfg = 0;
60
61 if (enabled)
62 cfg = EXYNOS_DP_CLK_ENABLE;
63
Simon Glass305f5812016-02-21 21:09:00 -070064 writel(cfg, &reg->dp_mie_clkcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -070065}
66
Simon Glass305f5812016-02-21 21:09:00 -070067static void exynos_fimd_set_par(struct vidinfo *priv, unsigned int win_id)
Simon Glassc9ed7a42016-02-21 21:08:48 -070068{
Simon Glass305f5812016-02-21 21:09:00 -070069 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -070070 unsigned int cfg = 0;
71
72 /* set window control */
Simon Glass305f5812016-02-21 21:09:00 -070073 cfg = readl((unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -070074 EXYNOS_WINCON(win_id));
75
76 cfg &= ~(EXYNOS_WINCON_BITSWP_ENABLE | EXYNOS_WINCON_BYTESWP_ENABLE |
77 EXYNOS_WINCON_HAWSWP_ENABLE | EXYNOS_WINCON_WSWP_ENABLE |
78 EXYNOS_WINCON_BURSTLEN_MASK | EXYNOS_WINCON_BPPMODE_MASK |
79 EXYNOS_WINCON_INRGB_MASK | EXYNOS_WINCON_DATAPATH_MASK);
80
81 /* DATAPATH is DMA */
82 cfg |= EXYNOS_WINCON_DATAPATH_DMA;
83
84 cfg |= EXYNOS_WINCON_HAWSWP_ENABLE;
85
86 /* dma burst is 16 */
87 cfg |= EXYNOS_WINCON_BURSTLEN_16WORD;
88
Simon Glass305f5812016-02-21 21:09:00 -070089 switch (priv->vl_bpix) {
Simon Glassc9ed7a42016-02-21 21:08:48 -070090 case 4:
91 cfg |= EXYNOS_WINCON_BPPMODE_16BPP_565;
92 break;
93 default:
94 cfg |= EXYNOS_WINCON_BPPMODE_24BPP_888;
95 break;
96 }
97
Simon Glass305f5812016-02-21 21:09:00 -070098 writel(cfg, (unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -070099 EXYNOS_WINCON(win_id));
100
101 /* set window position to x=0, y=0*/
102 cfg = EXYNOS_VIDOSD_LEFT_X(0) | EXYNOS_VIDOSD_TOP_Y(0);
Simon Glass305f5812016-02-21 21:09:00 -0700103 writel(cfg, (unsigned int)&reg->vidosd0a +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700104 EXYNOS_VIDOSD(win_id));
105
Simon Glass305f5812016-02-21 21:09:00 -0700106 cfg = EXYNOS_VIDOSD_RIGHT_X(priv->vl_col - 1) |
107 EXYNOS_VIDOSD_BOTTOM_Y(priv->vl_row - 1) |
Simon Glassc9ed7a42016-02-21 21:08:48 -0700108 EXYNOS_VIDOSD_RIGHT_X_E(1) |
109 EXYNOS_VIDOSD_BOTTOM_Y_E(0);
110
Simon Glass305f5812016-02-21 21:09:00 -0700111 writel(cfg, (unsigned int)&reg->vidosd0b +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700112 EXYNOS_VIDOSD(win_id));
113
114 /* set window size for window0*/
Simon Glass305f5812016-02-21 21:09:00 -0700115 cfg = EXYNOS_VIDOSD_SIZE(priv->vl_col * priv->vl_row);
116 writel(cfg, (unsigned int)&reg->vidosd0c +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700117 EXYNOS_VIDOSD(win_id));
118}
119
Simon Glass305f5812016-02-21 21:09:00 -0700120static void exynos_fimd_set_buffer_address(struct vidinfo *priv,
Simon Glassc9ed7a42016-02-21 21:08:48 -0700121 unsigned int win_id,
122 ulong lcd_base_addr)
123{
Simon Glass305f5812016-02-21 21:09:00 -0700124 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700125 unsigned long start_addr, end_addr;
126
127 start_addr = lcd_base_addr;
Simon Glass305f5812016-02-21 21:09:00 -0700128 end_addr = start_addr + ((priv->vl_col * (NBITS(priv->vl_bpix) / 8)) *
129 priv->vl_row);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700130
Simon Glass305f5812016-02-21 21:09:00 -0700131 writel(start_addr, (unsigned int)&reg->vidw00add0b0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700132 EXYNOS_BUFFER_OFFSET(win_id));
Simon Glass305f5812016-02-21 21:09:00 -0700133 writel(end_addr, (unsigned int)&reg->vidw00add1b0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700134 EXYNOS_BUFFER_OFFSET(win_id));
135}
136
Simon Glass305f5812016-02-21 21:09:00 -0700137static void exynos_fimd_set_clock(struct vidinfo *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700138{
Simon Glass305f5812016-02-21 21:09:00 -0700139 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700140 unsigned int cfg = 0, div = 0, remainder, remainder_div;
141 unsigned long pixel_clock;
142 unsigned long long src_clock;
143
Simon Glass305f5812016-02-21 21:09:00 -0700144 if (priv->dual_lcd_enabled) {
145 pixel_clock = priv->vl_freq *
146 (priv->vl_hspw + priv->vl_hfpd +
147 priv->vl_hbpd + priv->vl_col / 2) *
148 (priv->vl_vspw + priv->vl_vfpd +
149 priv->vl_vbpd + priv->vl_row);
150 } else if (priv->interface_mode == FIMD_CPU_INTERFACE) {
151 pixel_clock = priv->vl_freq *
152 priv->vl_width * priv->vl_height *
153 (priv->cs_setup + priv->wr_setup +
154 priv->wr_act + priv->wr_hold + 1);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700155 } else {
Simon Glass305f5812016-02-21 21:09:00 -0700156 pixel_clock = priv->vl_freq *
157 (priv->vl_hspw + priv->vl_hfpd +
158 priv->vl_hbpd + priv->vl_col) *
159 (priv->vl_vspw + priv->vl_vfpd +
160 priv->vl_vbpd + priv->vl_row);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700161 }
162
Simon Glass305f5812016-02-21 21:09:00 -0700163 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700164 cfg &= ~(EXYNOS_VIDCON0_CLKSEL_MASK | EXYNOS_VIDCON0_CLKVALUP_MASK |
165 EXYNOS_VIDCON0_CLKVAL_F(0xFF) | EXYNOS_VIDCON0_VCLKEN_MASK |
166 EXYNOS_VIDCON0_CLKDIR_MASK);
167 cfg |= (EXYNOS_VIDCON0_CLKSEL_SCLK | EXYNOS_VIDCON0_CLKVALUP_ALWAYS |
168 EXYNOS_VIDCON0_VCLKEN_NORMAL | EXYNOS_VIDCON0_CLKDIR_DIVIDED);
169
170 src_clock = (unsigned long long) get_lcd_clk();
171
172 /* get quotient and remainder. */
173 remainder = do_div(src_clock, pixel_clock);
174 div = src_clock;
175
176 remainder *= 10;
177 remainder_div = remainder / pixel_clock;
178
179 /* round about one places of decimals. */
180 if (remainder_div >= 5)
181 div++;
182
183 /* in case of dual lcd mode. */
Simon Glass305f5812016-02-21 21:09:00 -0700184 if (priv->dual_lcd_enabled)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700185 div--;
186
187 cfg |= EXYNOS_VIDCON0_CLKVAL_F(div - 1);
Simon Glass305f5812016-02-21 21:09:00 -0700188 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700189}
190
Simon Glass305f5812016-02-21 21:09:00 -0700191void exynos_set_trigger(struct vidinfo *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700192{
Simon Glass305f5812016-02-21 21:09:00 -0700193 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700194 unsigned int cfg = 0;
195
Simon Glass305f5812016-02-21 21:09:00 -0700196 cfg = readl(&reg->trigcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700197
198 cfg |= (EXYNOS_I80SOFT_TRIG_EN | EXYNOS_I80START_TRIG);
199
Simon Glass305f5812016-02-21 21:09:00 -0700200 writel(cfg, &reg->trigcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700201}
202
Simon Glass305f5812016-02-21 21:09:00 -0700203int exynos_is_i80_frame_done(struct vidinfo *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700204{
Simon Glass305f5812016-02-21 21:09:00 -0700205 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700206 unsigned int cfg = 0;
207 int status;
208
Simon Glass305f5812016-02-21 21:09:00 -0700209 cfg = readl(&reg->trigcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700210
211 /* frame done func is valid only when TRIMODE[0] is set to 1. */
212 status = (cfg & EXYNOS_I80STATUS_TRIG_DONE) ==
213 EXYNOS_I80STATUS_TRIG_DONE;
214
215 return status;
216}
217
Simon Glass305f5812016-02-21 21:09:00 -0700218static void exynos_fimd_lcd_on(struct vidinfo *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700219{
Simon Glass305f5812016-02-21 21:09:00 -0700220 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700221 unsigned int cfg = 0;
222
223 /* display on */
Simon Glass305f5812016-02-21 21:09:00 -0700224 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700225 cfg |= (EXYNOS_VIDCON0_ENVID_ENABLE | EXYNOS_VIDCON0_ENVID_F_ENABLE);
Simon Glass305f5812016-02-21 21:09:00 -0700226 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700227}
228
Simon Glass305f5812016-02-21 21:09:00 -0700229static void exynos_fimd_window_on(struct vidinfo *priv, unsigned int win_id)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700230{
Simon Glass305f5812016-02-21 21:09:00 -0700231 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700232 unsigned int cfg = 0;
233
234 /* enable window */
Simon Glass305f5812016-02-21 21:09:00 -0700235 cfg = readl((unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700236 EXYNOS_WINCON(win_id));
237 cfg |= EXYNOS_WINCON_ENWIN_ENABLE;
Simon Glass305f5812016-02-21 21:09:00 -0700238 writel(cfg, (unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700239 EXYNOS_WINCON(win_id));
240
Simon Glass305f5812016-02-21 21:09:00 -0700241 cfg = readl(&reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700242 cfg |= EXYNOS_WINSHMAP_CH_ENABLE(win_id);
Simon Glass305f5812016-02-21 21:09:00 -0700243 writel(cfg, &reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700244}
245
Simon Glass305f5812016-02-21 21:09:00 -0700246void exynos_fimd_lcd_off(struct vidinfo *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700247{
Simon Glass305f5812016-02-21 21:09:00 -0700248 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700249 unsigned int cfg = 0;
250
Simon Glass305f5812016-02-21 21:09:00 -0700251 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700252 cfg &= (EXYNOS_VIDCON0_ENVID_DISABLE | EXYNOS_VIDCON0_ENVID_F_DISABLE);
Simon Glass305f5812016-02-21 21:09:00 -0700253 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700254}
255
Simon Glass305f5812016-02-21 21:09:00 -0700256void exynos_fimd_window_off(struct vidinfo *priv, unsigned int win_id)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700257{
Simon Glass305f5812016-02-21 21:09:00 -0700258 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700259 unsigned int cfg = 0;
260
Simon Glass305f5812016-02-21 21:09:00 -0700261 cfg = readl((unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700262 EXYNOS_WINCON(win_id));
263 cfg &= EXYNOS_WINCON_ENWIN_DISABLE;
Simon Glass305f5812016-02-21 21:09:00 -0700264 writel(cfg, (unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700265 EXYNOS_WINCON(win_id));
266
Simon Glass305f5812016-02-21 21:09:00 -0700267 cfg = readl(&reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700268 cfg &= ~EXYNOS_WINSHMAP_CH_DISABLE(win_id);
Simon Glass305f5812016-02-21 21:09:00 -0700269 writel(cfg, &reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700270}
271
272/*
273* The reset value for FIMD SYSMMU register MMU_CTRL is 3
274* on Exynos5420 and newer versions.
275* This means FIMD SYSMMU is on by default on Exynos5420
276* and newer versions.
277* Since in u-boot we don't use SYSMMU, we should disable
278* those FIMD SYSMMU.
279* Note that there are 2 SYSMMU for FIMD: m0 and m1.
280* m0 handles windows 0 and 4, and m1 handles windows 1, 2 and 3.
281* We disable both of them here.
282*/
283void exynos_fimd_disable_sysmmu(void)
284{
285 u32 *sysmmufimd;
286 unsigned int node;
287 int node_list[2];
288 int count;
289 int i;
290
291 count = fdtdec_find_aliases_for_id(gd->fdt_blob, "fimd",
292 COMPAT_SAMSUNG_EXYNOS_SYSMMU, node_list, 2);
293 for (i = 0; i < count; i++) {
294 node = node_list[i];
295 if (node <= 0) {
296 debug("Can't get device node for fimd sysmmu\n");
297 return;
298 }
299
300 sysmmufimd = (u32 *)fdtdec_get_addr(gd->fdt_blob, node, "reg");
301 if (!sysmmufimd) {
302 debug("Can't get base address for sysmmu fimdm0");
303 return;
304 }
305
306 writel(0x0, sysmmufimd);
307 }
308}
309
Simon Glass305f5812016-02-21 21:09:00 -0700310void exynos_fimd_lcd_init(struct vidinfo *priv, ulong lcd_base_address)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700311{
Simon Glass305f5812016-02-21 21:09:00 -0700312 struct exynos_fb *reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700313 unsigned int cfg = 0, rgb_mode;
314 unsigned int offset;
315 unsigned int node;
316
317 node = fdtdec_next_compatible(gd->fdt_blob,
318 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
319 if (node <= 0)
320 debug("exynos_fb: Can't get device node for fimd\n");
321
Simon Glass305f5812016-02-21 21:09:00 -0700322 reg = (struct exynos_fb *)fdtdec_get_addr(gd->fdt_blob, node,
Simon Glassc9ed7a42016-02-21 21:08:48 -0700323 "reg");
Simon Glass305f5812016-02-21 21:09:00 -0700324 if (reg == NULL)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700325 debug("Can't get the FIMD base address\n");
Simon Glass305f5812016-02-21 21:09:00 -0700326 priv->reg = reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700327
328 if (fdtdec_get_bool(gd->fdt_blob, node, "samsung,disable-sysmmu"))
329 exynos_fimd_disable_sysmmu();
330
331 offset = exynos_fimd_get_base_offset();
332
Simon Glass305f5812016-02-21 21:09:00 -0700333 rgb_mode = priv->rgb_mode;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700334
Simon Glass305f5812016-02-21 21:09:00 -0700335 if (priv->interface_mode == FIMD_RGB_INTERFACE) {
Simon Glassc9ed7a42016-02-21 21:08:48 -0700336 cfg |= EXYNOS_VIDCON0_VIDOUT_RGB;
Simon Glass305f5812016-02-21 21:09:00 -0700337 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700338
Simon Glass305f5812016-02-21 21:09:00 -0700339 cfg = readl(&reg->vidcon2);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700340 cfg &= ~(EXYNOS_VIDCON2_WB_MASK |
341 EXYNOS_VIDCON2_TVFORMATSEL_MASK |
342 EXYNOS_VIDCON2_TVFORMATSEL_YUV_MASK);
343 cfg |= EXYNOS_VIDCON2_WB_DISABLE;
Simon Glass305f5812016-02-21 21:09:00 -0700344 writel(cfg, &reg->vidcon2);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700345
346 /* set polarity */
347 cfg = 0;
Simon Glass305f5812016-02-21 21:09:00 -0700348 if (!priv->vl_clkp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700349 cfg |= EXYNOS_VIDCON1_IVCLK_RISING_EDGE;
Simon Glass305f5812016-02-21 21:09:00 -0700350 if (!priv->vl_hsp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700351 cfg |= EXYNOS_VIDCON1_IHSYNC_INVERT;
Simon Glass305f5812016-02-21 21:09:00 -0700352 if (!priv->vl_vsp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700353 cfg |= EXYNOS_VIDCON1_IVSYNC_INVERT;
Simon Glass305f5812016-02-21 21:09:00 -0700354 if (!priv->vl_dp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700355 cfg |= EXYNOS_VIDCON1_IVDEN_INVERT;
356
Simon Glass305f5812016-02-21 21:09:00 -0700357 writel(cfg, (unsigned int)&reg->vidcon1 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700358
359 /* set timing */
Simon Glass305f5812016-02-21 21:09:00 -0700360 cfg = EXYNOS_VIDTCON0_VFPD(priv->vl_vfpd - 1);
361 cfg |= EXYNOS_VIDTCON0_VBPD(priv->vl_vbpd - 1);
362 cfg |= EXYNOS_VIDTCON0_VSPW(priv->vl_vspw - 1);
363 writel(cfg, (unsigned int)&reg->vidtcon0 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700364
Simon Glass305f5812016-02-21 21:09:00 -0700365 cfg = EXYNOS_VIDTCON1_HFPD(priv->vl_hfpd - 1);
366 cfg |= EXYNOS_VIDTCON1_HBPD(priv->vl_hbpd - 1);
367 cfg |= EXYNOS_VIDTCON1_HSPW(priv->vl_hspw - 1);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700368
Simon Glass305f5812016-02-21 21:09:00 -0700369 writel(cfg, (unsigned int)&reg->vidtcon1 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700370
371 /* set lcd size */
Simon Glass305f5812016-02-21 21:09:00 -0700372 cfg = EXYNOS_VIDTCON2_HOZVAL(priv->vl_col - 1) |
373 EXYNOS_VIDTCON2_LINEVAL(priv->vl_row - 1) |
374 EXYNOS_VIDTCON2_HOZVAL_E(priv->vl_col - 1) |
375 EXYNOS_VIDTCON2_LINEVAL_E(priv->vl_row - 1);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700376
Simon Glass305f5812016-02-21 21:09:00 -0700377 writel(cfg, (unsigned int)&reg->vidtcon2 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700378 }
379
380 /* set display mode */
Simon Glass305f5812016-02-21 21:09:00 -0700381 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700382 cfg &= ~EXYNOS_VIDCON0_PNRMODE_MASK;
383 cfg |= (rgb_mode << EXYNOS_VIDCON0_PNRMODE_SHIFT);
Simon Glass305f5812016-02-21 21:09:00 -0700384 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700385
386 /* set par */
Simon Glass305f5812016-02-21 21:09:00 -0700387 exynos_fimd_set_par(priv, priv->win_id);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700388
389 /* set memory address */
Simon Glass305f5812016-02-21 21:09:00 -0700390 exynos_fimd_set_buffer_address(priv, priv->win_id, lcd_base_address);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700391
392 /* set buffer size */
Simon Glass305f5812016-02-21 21:09:00 -0700393 cfg = EXYNOS_VIDADDR_PAGEWIDTH(priv->vl_col *
394 NBITS(priv->vl_bpix) / 8) |
395 EXYNOS_VIDADDR_PAGEWIDTH_E(priv->vl_col *
396 NBITS(priv->vl_bpix) / 8) |
Simon Glassc9ed7a42016-02-21 21:08:48 -0700397 EXYNOS_VIDADDR_OFFSIZE(0) |
398 EXYNOS_VIDADDR_OFFSIZE_E(0);
399
Simon Glass305f5812016-02-21 21:09:00 -0700400 writel(cfg, (unsigned int)&reg->vidw00add2 +
401 EXYNOS_BUFFER_SIZE(priv->win_id));
Simon Glassc9ed7a42016-02-21 21:08:48 -0700402
403 /* set clock */
Simon Glass305f5812016-02-21 21:09:00 -0700404 exynos_fimd_set_clock(priv);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700405
406 /* set rgb mode to dual lcd. */
Simon Glass305f5812016-02-21 21:09:00 -0700407 exynos_fimd_set_dualrgb(priv, priv->dual_lcd_enabled);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700408
409 /* display on */
Simon Glass305f5812016-02-21 21:09:00 -0700410 exynos_fimd_lcd_on(priv);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700411
412 /* window on */
Simon Glass305f5812016-02-21 21:09:00 -0700413 exynos_fimd_window_on(priv, priv->win_id);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700414
Simon Glass305f5812016-02-21 21:09:00 -0700415 exynos_fimd_set_dp_clkcon(priv, priv->dp_enabled);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700416}
417
Simon Glass305f5812016-02-21 21:09:00 -0700418unsigned long exynos_fimd_calc_fbsize(struct vidinfo *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700419{
Simon Glass305f5812016-02-21 21:09:00 -0700420 return priv->vl_col * priv->vl_row * (NBITS(priv->vl_bpix) / 8);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700421}
422
Nikita Kiryanovec3685d2015-02-03 13:32:21 +0200423ushort *configuration_get_cmap(void)
424{
425#if defined(CONFIG_LCD_LOGO)
426 return bmp_logo_palette;
427#else
428 return NULL;
429#endif
430}
431
Simon Glass4d022cc2016-02-21 21:08:41 -0700432static void exynos_lcd_init(struct vidinfo *vid, ulong lcd_base)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000433{
Simon Glass4d022cc2016-02-21 21:08:41 -0700434 exynos_fimd_lcd_init(vid, lcd_base);
Łukasz Majewski43905f42013-01-08 03:48:40 +0000435
436 /* Enable flushing after LCD writes if requested */
437 lcd_set_flush_dcache(1);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000438}
439
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200440__weak void exynos_cfg_lcd_gpio(void)
Ajay Kumar41022a12013-02-21 23:52:57 +0000441{
442}
Ajay Kumar41022a12013-02-21 23:52:57 +0000443
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200444__weak void exynos_backlight_on(unsigned int onoff)
Ajay Kumar41022a12013-02-21 23:52:57 +0000445{
446}
Ajay Kumar41022a12013-02-21 23:52:57 +0000447
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200448__weak void exynos_reset_lcd(void)
Ajay Kumar41022a12013-02-21 23:52:57 +0000449{
450}
Ajay Kumar41022a12013-02-21 23:52:57 +0000451
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200452__weak void exynos_lcd_power_on(void)
Ajay Kumar41022a12013-02-21 23:52:57 +0000453{
454}
Ajay Kumar41022a12013-02-21 23:52:57 +0000455
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200456__weak void exynos_cfg_ldo(void)
Ajay Kumar41022a12013-02-21 23:52:57 +0000457{
458}
Ajay Kumar41022a12013-02-21 23:52:57 +0000459
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200460__weak void exynos_enable_ldo(unsigned int onoff)
Ajay Kumar41022a12013-02-21 23:52:57 +0000461{
462}
Ajay Kumar41022a12013-02-21 23:52:57 +0000463
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +0200464__weak void exynos_backlight_reset(void)
Ajay Kumar41022a12013-02-21 23:52:57 +0000465{
466}
Ajay Kumar41022a12013-02-21 23:52:57 +0000467
Simon Glass6d275592016-02-21 21:08:40 -0700468__weak int exynos_lcd_misc_init(struct vidinfo *vid)
Piotr Wilczek386fd022014-03-07 14:59:40 +0100469{
470 return 0;
471}
Piotr Wilczek386fd022014-03-07 14:59:40 +0100472
Simon Glass6d275592016-02-21 21:08:40 -0700473static void lcd_panel_on(struct vidinfo *vid)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000474{
Ajay Kumar39ea08b2015-03-04 19:05:26 +0530475 struct gpio_desc pwm_out_gpio;
476 struct gpio_desc bl_en_gpio;
477 unsigned int node;
478
Donghwa Lee0112fed2012-04-05 19:36:17 +0000479 udelay(vid->init_delay);
480
Ajay Kumar41022a12013-02-21 23:52:57 +0000481 exynos_backlight_reset();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000482
Ajay Kumar41022a12013-02-21 23:52:57 +0000483 exynos_cfg_lcd_gpio();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000484
Ajay Kumar41022a12013-02-21 23:52:57 +0000485 exynos_lcd_power_on();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000486
487 udelay(vid->power_on_delay);
488
Donghwa Leebc72aeb2012-07-02 01:16:08 +0000489 if (vid->dp_enabled)
490 exynos_init_dp();
491
Ajay Kumar41022a12013-02-21 23:52:57 +0000492 exynos_reset_lcd();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000493
Ajay Kumar41022a12013-02-21 23:52:57 +0000494 udelay(vid->reset_delay);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000495
Ajay Kumar41022a12013-02-21 23:52:57 +0000496 exynos_backlight_on(1);
497
Ajay Kumar39ea08b2015-03-04 19:05:26 +0530498 node = fdtdec_next_compatible(gd->fdt_blob, 0,
499 COMPAT_SAMSUNG_EXYNOS_FIMD);
500 if (node <= 0) {
501 debug("FIMD: Can't get device node for FIMD\n");
502 return;
503 }
504 gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,pwm-out-gpio",
505 0, &pwm_out_gpio,
506 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
507
508 gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,bl-en-gpio", 0,
509 &bl_en_gpio,
510 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
511
Ajay Kumar41022a12013-02-21 23:52:57 +0000512 exynos_cfg_ldo();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000513
Ajay Kumar41022a12013-02-21 23:52:57 +0000514 exynos_enable_ldo(1);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000515
516 if (vid->mipi_enabled)
Simon Glassef4e7792016-02-21 21:08:46 -0700517 exynos_mipi_dsi_init(panel_info.dsim_platform_data_dt);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000518}
Ajay Kumarebbace32013-02-21 23:53:01 +0000519
Ajay Kumar11763482014-09-05 16:53:30 +0530520int exynos_lcd_early_init(const void *blob)
Ajay Kumarebbace32013-02-21 23:53:01 +0000521{
522 unsigned int node;
523 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
524 if (node <= 0) {
525 debug("exynos_fb: Can't get device node for fimd\n");
526 return -ENODEV;
527 }
528
529 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
530 if (panel_info.vl_col == 0) {
531 debug("Can't get XRES\n");
532 return -ENXIO;
533 }
534
535 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
536 if (panel_info.vl_row == 0) {
537 debug("Can't get YRES\n");
538 return -ENXIO;
539 }
540
541 panel_info.vl_width = fdtdec_get_int(blob, node,
542 "samsung,vl-width", 0);
543
544 panel_info.vl_height = fdtdec_get_int(blob, node,
545 "samsung,vl-height", 0);
546
547 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
548 if (panel_info.vl_freq == 0) {
549 debug("Can't get refresh rate\n");
550 return -ENXIO;
551 }
552
553 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
554 panel_info.vl_clkp = CONFIG_SYS_LOW;
555
556 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
557 panel_info.vl_oep = CONFIG_SYS_LOW;
558
559 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
560 panel_info.vl_hsp = CONFIG_SYS_LOW;
561
562 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
563 panel_info.vl_vsp = CONFIG_SYS_LOW;
564
565 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
566 panel_info.vl_dp = CONFIG_SYS_LOW;
567
568 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
569 if (panel_info.vl_bpix == 0) {
570 debug("Can't get bits per pixel\n");
571 return -ENXIO;
572 }
573
574 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
575 if (panel_info.vl_hspw == 0) {
576 debug("Can't get hsync width\n");
577 return -ENXIO;
578 }
579
580 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
581 if (panel_info.vl_hfpd == 0) {
582 debug("Can't get right margin\n");
583 return -ENXIO;
584 }
585
586 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
587 "samsung,vl-hbpd", 0);
588 if (panel_info.vl_hbpd == 0) {
589 debug("Can't get left margin\n");
590 return -ENXIO;
591 }
592
593 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
594 "samsung,vl-vspw", 0);
595 if (panel_info.vl_vspw == 0) {
596 debug("Can't get vsync width\n");
597 return -ENXIO;
598 }
599
600 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
601 "samsung,vl-vfpd", 0);
602 if (panel_info.vl_vfpd == 0) {
603 debug("Can't get lower margin\n");
604 return -ENXIO;
605 }
606
607 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
608 if (panel_info.vl_vbpd == 0) {
609 debug("Can't get upper margin\n");
610 return -ENXIO;
611 }
612
613 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
614 "samsung,vl-cmd-allow-len", 0);
615
616 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
617 panel_info.init_delay = fdtdec_get_int(blob, node,
618 "samsung,init-delay", 0);
619 panel_info.power_on_delay = fdtdec_get_int(blob, node,
620 "samsung,power-on-delay", 0);
621 panel_info.reset_delay = fdtdec_get_int(blob, node,
622 "samsung,reset-delay", 0);
623 panel_info.interface_mode = fdtdec_get_int(blob, node,
624 "samsung,interface-mode", 0);
625 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
626 "samsung,mipi-enabled", 0);
627 panel_info.dp_enabled = fdtdec_get_int(blob, node,
628 "samsung,dp-enabled", 0);
629 panel_info.cs_setup = fdtdec_get_int(blob, node,
630 "samsung,cs-setup", 0);
631 panel_info.wr_setup = fdtdec_get_int(blob, node,
632 "samsung,wr-setup", 0);
633 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
634 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
635
636 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
637 if (panel_info.logo_on) {
638 panel_info.logo_width = fdtdec_get_int(blob, node,
639 "samsung,logo-width", 0);
640 panel_info.logo_height = fdtdec_get_int(blob, node,
641 "samsung,logo-height", 0);
642 panel_info.logo_addr = fdtdec_get_int(blob, node,
643 "samsung,logo-addr", 0);
644 }
645
646 panel_info.rgb_mode = fdtdec_get_int(blob, node,
647 "samsung,rgb-mode", 0);
648 panel_info.pclk_name = fdtdec_get_int(blob, node,
649 "samsung,pclk-name", 0);
650 panel_info.sclk_div = fdtdec_get_int(blob, node,
651 "samsung,sclk-div", 0);
652 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
653 "samsung,dual-lcd-enabled", 0);
654
655 return 0;
656}
Donghwa Lee0112fed2012-04-05 19:36:17 +0000657
658void lcd_ctrl_init(void *lcdbase)
659{
660 set_system_display_ctrl();
661 set_lcd_clk();
662
Piotr Wilczek386fd022014-03-07 14:59:40 +0100663#ifdef CONFIG_EXYNOS_MIPI_DSIM
664 exynos_init_dsim_platform_data(&panel_info);
665#endif
666 exynos_lcd_misc_init(&panel_info);
Piotr Wilczek386fd022014-03-07 14:59:40 +0100667
Simon Glass4d022cc2016-02-21 21:08:41 -0700668 exynos_lcd_init(&panel_info, (ulong)lcdbase);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000669}
670
671void lcd_enable(void)
672{
Donghwa Lee37980dd2012-05-09 19:23:46 +0000673 if (panel_info.logo_on) {
Simon Glass860ef002016-02-21 21:08:43 -0700674 memset((void *)gd->fb_base, 0,
675 panel_info.vl_width * panel_info.vl_height *
Donghwa Lee37980dd2012-05-09 19:23:46 +0000676 (NBITS(panel_info.vl_bpix) >> 3));
Donghwa Lee37980dd2012-05-09 19:23:46 +0000677 }
678
Donghwa Lee0112fed2012-04-05 19:36:17 +0000679 lcd_panel_on(&panel_info);
680}
681
682/* dummy function */
683void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
684{
685 return;
686}