blob: 8a8c846262b9cb9716a14522562affb7e8a391af [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Donghwa Lee0112fed2012-04-05 19:36:17 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 *
5 * Author: InKi Dae <inki.dae@samsung.com>
6 * Author: Donghwa Lee <dh09.lee@samsung.com>
Donghwa Lee0112fed2012-04-05 19:36:17 +00007 */
8
9#include <config.h>
10#include <common.h>
Simon Glassa1015ad2016-02-21 21:09:01 -070011#include <display.h>
Simon Glassc9ed7a42016-02-21 21:08:48 -070012#include <div64.h>
Simon Glassa1015ad2016-02-21 21:09:01 -070013#include <dm.h>
Ajay Kumarebbace32013-02-21 23:53:01 +000014#include <fdtdec.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Simon Glassa1015ad2016-02-21 21:09:01 -070016#include <panel.h>
17#include <video.h>
18#include <video_bridge.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000019#include <asm/io.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/clk.h>
23#include <asm/arch/mipi_dsim.h>
Donghwa Leebc72aeb2012-07-02 01:16:08 +000024#include <asm/arch/dp_info.h>
Simon Glassa1015ad2016-02-21 21:09:01 -070025#include <asm/arch/fb.h>
26#include <asm/arch/pinmux.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000027#include <asm/arch/system.h>
Ajay Kumar39ea08b2015-03-04 19:05:26 +053028#include <asm/gpio.h>
Masahiro Yamada64e4f7f2016-09-21 11:28:57 +090029#include <linux/errno.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000030
Ajay Kumarebbace32013-02-21 23:53:01 +000031DECLARE_GLOBAL_DATA_PTR;
32
Simon Glassa1015ad2016-02-21 21:09:01 -070033enum {
34 FIMD_RGB_INTERFACE = 1,
35 FIMD_CPU_INTERFACE = 2,
36};
37
38enum exynos_fb_rgb_mode_t {
39 MODE_RGB_P = 0,
40 MODE_BGR_P = 1,
41 MODE_RGB_S = 2,
42 MODE_BGR_S = 3,
Ajay Kumarebbace32013-02-21 23:53:01 +000043};
Ajay Kumarebbace32013-02-21 23:53:01 +000044
Simon Glassa1015ad2016-02-21 21:09:01 -070045struct exynos_fb_priv {
46 ushort vl_col; /* Number of columns (i.e. 640) */
47 ushort vl_row; /* Number of rows (i.e. 480) */
48 ushort vl_rot; /* Rotation of Display (0, 1, 2, 3) */
49 ushort vl_width; /* Width of display area in millimeters */
50 ushort vl_height; /* Height of display area in millimeters */
51
52 /* LCD configuration register */
53 u_char vl_freq; /* Frequency */
54 u_char vl_clkp; /* Clock polarity */
55 u_char vl_oep; /* Output Enable polarity */
56 u_char vl_hsp; /* Horizontal Sync polarity */
57 u_char vl_vsp; /* Vertical Sync polarity */
58 u_char vl_dp; /* Data polarity */
59 u_char vl_bpix; /* Bits per pixel */
60
61 /* Horizontal control register. Timing from data sheet */
62 u_char vl_hspw; /* Horz sync pulse width */
63 u_char vl_hfpd; /* Wait before of line */
64 u_char vl_hbpd; /* Wait end of line */
65
66 /* Vertical control register. */
67 u_char vl_vspw; /* Vertical sync pulse width */
68 u_char vl_vfpd; /* Wait before of frame */
69 u_char vl_vbpd; /* Wait end of frame */
70 u_char vl_cmd_allow_len; /* Wait end of frame */
71
72 unsigned int win_id;
73 unsigned int init_delay;
74 unsigned int power_on_delay;
75 unsigned int reset_delay;
76 unsigned int interface_mode;
77 unsigned int mipi_enabled;
78 unsigned int dp_enabled;
79 unsigned int cs_setup;
80 unsigned int wr_setup;
81 unsigned int wr_act;
82 unsigned int wr_hold;
83 unsigned int logo_on;
84 unsigned int logo_width;
85 unsigned int logo_height;
86 int logo_x_offset;
87 int logo_y_offset;
88 unsigned long logo_addr;
89 unsigned int rgb_mode;
90 unsigned int resolution;
91
92 /* parent clock name(MPLL, EPLL or VPLL) */
93 unsigned int pclk_name;
94 /* ratio value for source clock from parent clock. */
95 unsigned int sclk_div;
96
97 unsigned int dual_lcd_enabled;
98 struct exynos_fb *reg;
99 struct exynos_platform_mipi_dsim *dsim_platform_data_dt;
100};
101
102static void exynos_fimd_set_dualrgb(struct exynos_fb_priv *priv, bool enabled)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700103{
Simon Glass305f5812016-02-21 21:09:00 -0700104 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700105 unsigned int cfg = 0;
106
107 if (enabled) {
108 cfg = EXYNOS_DUALRGB_BYPASS_DUAL | EXYNOS_DUALRGB_LINESPLIT |
109 EXYNOS_DUALRGB_VDEN_EN_ENABLE;
110
111 /* in case of Line Split mode, MAIN_CNT doesn't neet to set. */
Simon Glass305f5812016-02-21 21:09:00 -0700112 cfg |= EXYNOS_DUALRGB_SUB_CNT(priv->vl_col / 2) |
Simon Glassc9ed7a42016-02-21 21:08:48 -0700113 EXYNOS_DUALRGB_MAIN_CNT(0);
114 }
115
Simon Glass305f5812016-02-21 21:09:00 -0700116 writel(cfg, &reg->dualrgb);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700117}
118
Simon Glassa1015ad2016-02-21 21:09:01 -0700119static void exynos_fimd_set_dp_clkcon(struct exynos_fb_priv *priv,
Simon Glassc9ed7a42016-02-21 21:08:48 -0700120 unsigned int enabled)
121{
Simon Glass305f5812016-02-21 21:09:00 -0700122 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700123 unsigned int cfg = 0;
124
125 if (enabled)
126 cfg = EXYNOS_DP_CLK_ENABLE;
127
Simon Glass305f5812016-02-21 21:09:00 -0700128 writel(cfg, &reg->dp_mie_clkcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700129}
130
Simon Glassa1015ad2016-02-21 21:09:01 -0700131static void exynos_fimd_set_par(struct exynos_fb_priv *priv,
132 unsigned int win_id)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700133{
Simon Glass305f5812016-02-21 21:09:00 -0700134 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700135 unsigned int cfg = 0;
136
137 /* set window control */
Simon Glass305f5812016-02-21 21:09:00 -0700138 cfg = readl((unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700139 EXYNOS_WINCON(win_id));
140
141 cfg &= ~(EXYNOS_WINCON_BITSWP_ENABLE | EXYNOS_WINCON_BYTESWP_ENABLE |
142 EXYNOS_WINCON_HAWSWP_ENABLE | EXYNOS_WINCON_WSWP_ENABLE |
143 EXYNOS_WINCON_BURSTLEN_MASK | EXYNOS_WINCON_BPPMODE_MASK |
144 EXYNOS_WINCON_INRGB_MASK | EXYNOS_WINCON_DATAPATH_MASK);
145
146 /* DATAPATH is DMA */
147 cfg |= EXYNOS_WINCON_DATAPATH_DMA;
148
149 cfg |= EXYNOS_WINCON_HAWSWP_ENABLE;
150
151 /* dma burst is 16 */
152 cfg |= EXYNOS_WINCON_BURSTLEN_16WORD;
153
Simon Glass305f5812016-02-21 21:09:00 -0700154 switch (priv->vl_bpix) {
Simon Glassc9ed7a42016-02-21 21:08:48 -0700155 case 4:
156 cfg |= EXYNOS_WINCON_BPPMODE_16BPP_565;
157 break;
158 default:
159 cfg |= EXYNOS_WINCON_BPPMODE_24BPP_888;
160 break;
161 }
162
Simon Glass305f5812016-02-21 21:09:00 -0700163 writel(cfg, (unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700164 EXYNOS_WINCON(win_id));
165
166 /* set window position to x=0, y=0*/
167 cfg = EXYNOS_VIDOSD_LEFT_X(0) | EXYNOS_VIDOSD_TOP_Y(0);
Simon Glass305f5812016-02-21 21:09:00 -0700168 writel(cfg, (unsigned int)&reg->vidosd0a +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700169 EXYNOS_VIDOSD(win_id));
170
Simon Glass305f5812016-02-21 21:09:00 -0700171 cfg = EXYNOS_VIDOSD_RIGHT_X(priv->vl_col - 1) |
172 EXYNOS_VIDOSD_BOTTOM_Y(priv->vl_row - 1) |
Simon Glassc9ed7a42016-02-21 21:08:48 -0700173 EXYNOS_VIDOSD_RIGHT_X_E(1) |
174 EXYNOS_VIDOSD_BOTTOM_Y_E(0);
175
Simon Glass305f5812016-02-21 21:09:00 -0700176 writel(cfg, (unsigned int)&reg->vidosd0b +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700177 EXYNOS_VIDOSD(win_id));
178
179 /* set window size for window0*/
Simon Glass305f5812016-02-21 21:09:00 -0700180 cfg = EXYNOS_VIDOSD_SIZE(priv->vl_col * priv->vl_row);
181 writel(cfg, (unsigned int)&reg->vidosd0c +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700182 EXYNOS_VIDOSD(win_id));
183}
184
Simon Glassa1015ad2016-02-21 21:09:01 -0700185static void exynos_fimd_set_buffer_address(struct exynos_fb_priv *priv,
Simon Glassc9ed7a42016-02-21 21:08:48 -0700186 unsigned int win_id,
187 ulong lcd_base_addr)
188{
Simon Glass305f5812016-02-21 21:09:00 -0700189 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700190 unsigned long start_addr, end_addr;
191
192 start_addr = lcd_base_addr;
Simon Glassa1015ad2016-02-21 21:09:01 -0700193 end_addr = start_addr + ((priv->vl_col * (VNBITS(priv->vl_bpix) / 8)) *
Simon Glass305f5812016-02-21 21:09:00 -0700194 priv->vl_row);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700195
Simon Glass305f5812016-02-21 21:09:00 -0700196 writel(start_addr, (unsigned int)&reg->vidw00add0b0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700197 EXYNOS_BUFFER_OFFSET(win_id));
Simon Glass305f5812016-02-21 21:09:00 -0700198 writel(end_addr, (unsigned int)&reg->vidw00add1b0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700199 EXYNOS_BUFFER_OFFSET(win_id));
200}
201
Simon Glassa1015ad2016-02-21 21:09:01 -0700202static void exynos_fimd_set_clock(struct exynos_fb_priv *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700203{
Simon Glass305f5812016-02-21 21:09:00 -0700204 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700205 unsigned int cfg = 0, div = 0, remainder, remainder_div;
206 unsigned long pixel_clock;
207 unsigned long long src_clock;
208
Simon Glass305f5812016-02-21 21:09:00 -0700209 if (priv->dual_lcd_enabled) {
210 pixel_clock = priv->vl_freq *
211 (priv->vl_hspw + priv->vl_hfpd +
212 priv->vl_hbpd + priv->vl_col / 2) *
213 (priv->vl_vspw + priv->vl_vfpd +
214 priv->vl_vbpd + priv->vl_row);
215 } else if (priv->interface_mode == FIMD_CPU_INTERFACE) {
216 pixel_clock = priv->vl_freq *
217 priv->vl_width * priv->vl_height *
218 (priv->cs_setup + priv->wr_setup +
219 priv->wr_act + priv->wr_hold + 1);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700220 } else {
Simon Glass305f5812016-02-21 21:09:00 -0700221 pixel_clock = priv->vl_freq *
222 (priv->vl_hspw + priv->vl_hfpd +
223 priv->vl_hbpd + priv->vl_col) *
224 (priv->vl_vspw + priv->vl_vfpd +
225 priv->vl_vbpd + priv->vl_row);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700226 }
227
Simon Glass305f5812016-02-21 21:09:00 -0700228 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700229 cfg &= ~(EXYNOS_VIDCON0_CLKSEL_MASK | EXYNOS_VIDCON0_CLKVALUP_MASK |
230 EXYNOS_VIDCON0_CLKVAL_F(0xFF) | EXYNOS_VIDCON0_VCLKEN_MASK |
231 EXYNOS_VIDCON0_CLKDIR_MASK);
232 cfg |= (EXYNOS_VIDCON0_CLKSEL_SCLK | EXYNOS_VIDCON0_CLKVALUP_ALWAYS |
233 EXYNOS_VIDCON0_VCLKEN_NORMAL | EXYNOS_VIDCON0_CLKDIR_DIVIDED);
234
235 src_clock = (unsigned long long) get_lcd_clk();
236
237 /* get quotient and remainder. */
238 remainder = do_div(src_clock, pixel_clock);
239 div = src_clock;
240
241 remainder *= 10;
242 remainder_div = remainder / pixel_clock;
243
244 /* round about one places of decimals. */
245 if (remainder_div >= 5)
246 div++;
247
248 /* in case of dual lcd mode. */
Simon Glass305f5812016-02-21 21:09:00 -0700249 if (priv->dual_lcd_enabled)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700250 div--;
251
252 cfg |= EXYNOS_VIDCON0_CLKVAL_F(div - 1);
Simon Glass305f5812016-02-21 21:09:00 -0700253 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700254}
255
Simon Glassa1015ad2016-02-21 21:09:01 -0700256void exynos_set_trigger(struct exynos_fb_priv *priv)
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(&reg->trigcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700262
263 cfg |= (EXYNOS_I80SOFT_TRIG_EN | EXYNOS_I80START_TRIG);
264
Simon Glass305f5812016-02-21 21:09:00 -0700265 writel(cfg, &reg->trigcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700266}
267
Simon Glassa1015ad2016-02-21 21:09:01 -0700268int exynos_is_i80_frame_done(struct exynos_fb_priv *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700269{
Simon Glass305f5812016-02-21 21:09:00 -0700270 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700271 unsigned int cfg = 0;
272 int status;
273
Simon Glass305f5812016-02-21 21:09:00 -0700274 cfg = readl(&reg->trigcon);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700275
276 /* frame done func is valid only when TRIMODE[0] is set to 1. */
277 status = (cfg & EXYNOS_I80STATUS_TRIG_DONE) ==
278 EXYNOS_I80STATUS_TRIG_DONE;
279
280 return status;
281}
282
Simon Glassa1015ad2016-02-21 21:09:01 -0700283static void exynos_fimd_lcd_on(struct exynos_fb_priv *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700284{
Simon Glass305f5812016-02-21 21:09:00 -0700285 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700286 unsigned int cfg = 0;
287
288 /* display on */
Simon Glass305f5812016-02-21 21:09:00 -0700289 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700290 cfg |= (EXYNOS_VIDCON0_ENVID_ENABLE | EXYNOS_VIDCON0_ENVID_F_ENABLE);
Simon Glass305f5812016-02-21 21:09:00 -0700291 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700292}
293
Simon Glassa1015ad2016-02-21 21:09:01 -0700294static void exynos_fimd_window_on(struct exynos_fb_priv *priv,
295 unsigned int win_id)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700296{
Simon Glass305f5812016-02-21 21:09:00 -0700297 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700298 unsigned int cfg = 0;
299
300 /* enable window */
Simon Glass305f5812016-02-21 21:09:00 -0700301 cfg = readl((unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700302 EXYNOS_WINCON(win_id));
303 cfg |= EXYNOS_WINCON_ENWIN_ENABLE;
Simon Glass305f5812016-02-21 21:09:00 -0700304 writel(cfg, (unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700305 EXYNOS_WINCON(win_id));
306
Simon Glass305f5812016-02-21 21:09:00 -0700307 cfg = readl(&reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700308 cfg |= EXYNOS_WINSHMAP_CH_ENABLE(win_id);
Simon Glass305f5812016-02-21 21:09:00 -0700309 writel(cfg, &reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700310}
311
Simon Glassa1015ad2016-02-21 21:09:01 -0700312void exynos_fimd_lcd_off(struct exynos_fb_priv *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700313{
Simon Glass305f5812016-02-21 21:09:00 -0700314 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700315 unsigned int cfg = 0;
316
Simon Glass305f5812016-02-21 21:09:00 -0700317 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700318 cfg &= (EXYNOS_VIDCON0_ENVID_DISABLE | EXYNOS_VIDCON0_ENVID_F_DISABLE);
Simon Glass305f5812016-02-21 21:09:00 -0700319 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700320}
321
Simon Glassa1015ad2016-02-21 21:09:01 -0700322void exynos_fimd_window_off(struct exynos_fb_priv *priv, unsigned int win_id)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700323{
Simon Glass305f5812016-02-21 21:09:00 -0700324 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700325 unsigned int cfg = 0;
326
Simon Glass305f5812016-02-21 21:09:00 -0700327 cfg = readl((unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700328 EXYNOS_WINCON(win_id));
329 cfg &= EXYNOS_WINCON_ENWIN_DISABLE;
Simon Glass305f5812016-02-21 21:09:00 -0700330 writel(cfg, (unsigned int)&reg->wincon0 +
Simon Glassc9ed7a42016-02-21 21:08:48 -0700331 EXYNOS_WINCON(win_id));
332
Simon Glass305f5812016-02-21 21:09:00 -0700333 cfg = readl(&reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700334 cfg &= ~EXYNOS_WINSHMAP_CH_DISABLE(win_id);
Simon Glass305f5812016-02-21 21:09:00 -0700335 writel(cfg, &reg->winshmap);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700336}
337
338/*
339* The reset value for FIMD SYSMMU register MMU_CTRL is 3
340* on Exynos5420 and newer versions.
341* This means FIMD SYSMMU is on by default on Exynos5420
342* and newer versions.
343* Since in u-boot we don't use SYSMMU, we should disable
344* those FIMD SYSMMU.
345* Note that there are 2 SYSMMU for FIMD: m0 and m1.
346* m0 handles windows 0 and 4, and m1 handles windows 1, 2 and 3.
347* We disable both of them here.
348*/
349void exynos_fimd_disable_sysmmu(void)
350{
351 u32 *sysmmufimd;
352 unsigned int node;
353 int node_list[2];
354 int count;
355 int i;
356
357 count = fdtdec_find_aliases_for_id(gd->fdt_blob, "fimd",
358 COMPAT_SAMSUNG_EXYNOS_SYSMMU, node_list, 2);
359 for (i = 0; i < count; i++) {
360 node = node_list[i];
361 if (node <= 0) {
362 debug("Can't get device node for fimd sysmmu\n");
363 return;
364 }
365
366 sysmmufimd = (u32 *)fdtdec_get_addr(gd->fdt_blob, node, "reg");
367 if (!sysmmufimd) {
368 debug("Can't get base address for sysmmu fimdm0");
369 return;
370 }
371
372 writel(0x0, sysmmufimd);
373 }
374}
375
Simon Glassa1015ad2016-02-21 21:09:01 -0700376void exynos_fimd_lcd_init(struct udevice *dev)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700377{
Simon Glassa1015ad2016-02-21 21:09:01 -0700378 struct exynos_fb_priv *priv = dev_get_priv(dev);
379 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
380 struct exynos_fb *reg = priv->reg;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700381 unsigned int cfg = 0, rgb_mode;
382 unsigned int offset;
383 unsigned int node;
384
Simon Glassdd79d6e2017-01-17 16:52:55 -0700385 node = dev_of_offset(dev);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700386 if (fdtdec_get_bool(gd->fdt_blob, node, "samsung,disable-sysmmu"))
387 exynos_fimd_disable_sysmmu();
388
389 offset = exynos_fimd_get_base_offset();
390
Simon Glass305f5812016-02-21 21:09:00 -0700391 rgb_mode = priv->rgb_mode;
Simon Glassc9ed7a42016-02-21 21:08:48 -0700392
Simon Glass305f5812016-02-21 21:09:00 -0700393 if (priv->interface_mode == FIMD_RGB_INTERFACE) {
Simon Glassc9ed7a42016-02-21 21:08:48 -0700394 cfg |= EXYNOS_VIDCON0_VIDOUT_RGB;
Simon Glass305f5812016-02-21 21:09:00 -0700395 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700396
Simon Glass305f5812016-02-21 21:09:00 -0700397 cfg = readl(&reg->vidcon2);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700398 cfg &= ~(EXYNOS_VIDCON2_WB_MASK |
399 EXYNOS_VIDCON2_TVFORMATSEL_MASK |
400 EXYNOS_VIDCON2_TVFORMATSEL_YUV_MASK);
401 cfg |= EXYNOS_VIDCON2_WB_DISABLE;
Simon Glass305f5812016-02-21 21:09:00 -0700402 writel(cfg, &reg->vidcon2);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700403
404 /* set polarity */
405 cfg = 0;
Simon Glass305f5812016-02-21 21:09:00 -0700406 if (!priv->vl_clkp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700407 cfg |= EXYNOS_VIDCON1_IVCLK_RISING_EDGE;
Simon Glass305f5812016-02-21 21:09:00 -0700408 if (!priv->vl_hsp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700409 cfg |= EXYNOS_VIDCON1_IHSYNC_INVERT;
Simon Glass305f5812016-02-21 21:09:00 -0700410 if (!priv->vl_vsp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700411 cfg |= EXYNOS_VIDCON1_IVSYNC_INVERT;
Simon Glass305f5812016-02-21 21:09:00 -0700412 if (!priv->vl_dp)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700413 cfg |= EXYNOS_VIDCON1_IVDEN_INVERT;
414
Simon Glass305f5812016-02-21 21:09:00 -0700415 writel(cfg, (unsigned int)&reg->vidcon1 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700416
417 /* set timing */
Simon Glass305f5812016-02-21 21:09:00 -0700418 cfg = EXYNOS_VIDTCON0_VFPD(priv->vl_vfpd - 1);
419 cfg |= EXYNOS_VIDTCON0_VBPD(priv->vl_vbpd - 1);
420 cfg |= EXYNOS_VIDTCON0_VSPW(priv->vl_vspw - 1);
421 writel(cfg, (unsigned int)&reg->vidtcon0 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700422
Simon Glass305f5812016-02-21 21:09:00 -0700423 cfg = EXYNOS_VIDTCON1_HFPD(priv->vl_hfpd - 1);
424 cfg |= EXYNOS_VIDTCON1_HBPD(priv->vl_hbpd - 1);
425 cfg |= EXYNOS_VIDTCON1_HSPW(priv->vl_hspw - 1);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700426
Simon Glass305f5812016-02-21 21:09:00 -0700427 writel(cfg, (unsigned int)&reg->vidtcon1 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700428
429 /* set lcd size */
Simon Glass305f5812016-02-21 21:09:00 -0700430 cfg = EXYNOS_VIDTCON2_HOZVAL(priv->vl_col - 1) |
431 EXYNOS_VIDTCON2_LINEVAL(priv->vl_row - 1) |
432 EXYNOS_VIDTCON2_HOZVAL_E(priv->vl_col - 1) |
433 EXYNOS_VIDTCON2_LINEVAL_E(priv->vl_row - 1);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700434
Simon Glass305f5812016-02-21 21:09:00 -0700435 writel(cfg, (unsigned int)&reg->vidtcon2 + offset);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700436 }
437
438 /* set display mode */
Simon Glass305f5812016-02-21 21:09:00 -0700439 cfg = readl(&reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700440 cfg &= ~EXYNOS_VIDCON0_PNRMODE_MASK;
441 cfg |= (rgb_mode << EXYNOS_VIDCON0_PNRMODE_SHIFT);
Simon Glass305f5812016-02-21 21:09:00 -0700442 writel(cfg, &reg->vidcon0);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700443
444 /* set par */
Simon Glass305f5812016-02-21 21:09:00 -0700445 exynos_fimd_set_par(priv, priv->win_id);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700446
447 /* set memory address */
Simon Glassa1015ad2016-02-21 21:09:01 -0700448 exynos_fimd_set_buffer_address(priv, priv->win_id, plat->base);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700449
450 /* set buffer size */
Simon Glass305f5812016-02-21 21:09:00 -0700451 cfg = EXYNOS_VIDADDR_PAGEWIDTH(priv->vl_col *
Simon Glassa1015ad2016-02-21 21:09:01 -0700452 VNBITS(priv->vl_bpix) / 8) |
Simon Glass305f5812016-02-21 21:09:00 -0700453 EXYNOS_VIDADDR_PAGEWIDTH_E(priv->vl_col *
Simon Glassa1015ad2016-02-21 21:09:01 -0700454 VNBITS(priv->vl_bpix) / 8) |
Simon Glassc9ed7a42016-02-21 21:08:48 -0700455 EXYNOS_VIDADDR_OFFSIZE(0) |
456 EXYNOS_VIDADDR_OFFSIZE_E(0);
457
Simon Glass305f5812016-02-21 21:09:00 -0700458 writel(cfg, (unsigned int)&reg->vidw00add2 +
459 EXYNOS_BUFFER_SIZE(priv->win_id));
Simon Glassc9ed7a42016-02-21 21:08:48 -0700460
461 /* set clock */
Simon Glass305f5812016-02-21 21:09:00 -0700462 exynos_fimd_set_clock(priv);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700463
464 /* set rgb mode to dual lcd. */
Simon Glass305f5812016-02-21 21:09:00 -0700465 exynos_fimd_set_dualrgb(priv, priv->dual_lcd_enabled);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700466
467 /* display on */
Simon Glass305f5812016-02-21 21:09:00 -0700468 exynos_fimd_lcd_on(priv);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700469
470 /* window on */
Simon Glass305f5812016-02-21 21:09:00 -0700471 exynos_fimd_window_on(priv, priv->win_id);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700472
Simon Glass305f5812016-02-21 21:09:00 -0700473 exynos_fimd_set_dp_clkcon(priv, priv->dp_enabled);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700474}
475
Simon Glassa1015ad2016-02-21 21:09:01 -0700476unsigned long exynos_fimd_calc_fbsize(struct exynos_fb_priv *priv)
Simon Glassc9ed7a42016-02-21 21:08:48 -0700477{
Simon Glassa1015ad2016-02-21 21:09:01 -0700478 return priv->vl_col * priv->vl_row * (VNBITS(priv->vl_bpix) / 8);
Simon Glassc9ed7a42016-02-21 21:08:48 -0700479}
480
Simon Glassa1015ad2016-02-21 21:09:01 -0700481int exynos_fb_ofdata_to_platdata(struct udevice *dev)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000482{
Simon Glassa1015ad2016-02-21 21:09:01 -0700483 struct exynos_fb_priv *priv = dev_get_priv(dev);
Simon Glassdd79d6e2017-01-17 16:52:55 -0700484 unsigned int node = dev_of_offset(dev);
Simon Glassa1015ad2016-02-21 21:09:01 -0700485 const void *blob = gd->fdt_blob;
486 fdt_addr_t addr;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000487
Simon Glassba1dea42017-05-17 17:18:05 -0600488 addr = devfdt_get_addr(dev);
Simon Glassa1015ad2016-02-21 21:09:01 -0700489 if (addr == FDT_ADDR_T_NONE) {
490 debug("Can't get the FIMD base address\n");
491 return -EINVAL;
Ajay Kumarebbace32013-02-21 23:53:01 +0000492 }
Simon Glassa1015ad2016-02-21 21:09:01 -0700493 priv->reg = (struct exynos_fb *)addr;
Ajay Kumarebbace32013-02-21 23:53:01 +0000494
Simon Glassa1015ad2016-02-21 21:09:01 -0700495 priv->vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
496 if (priv->vl_col == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000497 debug("Can't get XRES\n");
498 return -ENXIO;
499 }
500
Simon Glassa1015ad2016-02-21 21:09:01 -0700501 priv->vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
502 if (priv->vl_row == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000503 debug("Can't get YRES\n");
504 return -ENXIO;
505 }
506
Simon Glassa1015ad2016-02-21 21:09:01 -0700507 priv->vl_width = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000508 "samsung,vl-width", 0);
509
Simon Glassa1015ad2016-02-21 21:09:01 -0700510 priv->vl_height = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000511 "samsung,vl-height", 0);
512
Simon Glassa1015ad2016-02-21 21:09:01 -0700513 priv->vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
514 if (priv->vl_freq == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000515 debug("Can't get refresh rate\n");
516 return -ENXIO;
517 }
518
519 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
Simon Glassa1015ad2016-02-21 21:09:01 -0700520 priv->vl_clkp = VIDEO_ACTIVE_LOW;
Ajay Kumarebbace32013-02-21 23:53:01 +0000521
522 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
Simon Glassa1015ad2016-02-21 21:09:01 -0700523 priv->vl_oep = VIDEO_ACTIVE_LOW;
Ajay Kumarebbace32013-02-21 23:53:01 +0000524
525 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
Simon Glassa1015ad2016-02-21 21:09:01 -0700526 priv->vl_hsp = VIDEO_ACTIVE_LOW;
Ajay Kumarebbace32013-02-21 23:53:01 +0000527
528 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
Simon Glassa1015ad2016-02-21 21:09:01 -0700529 priv->vl_vsp = VIDEO_ACTIVE_LOW;
Ajay Kumarebbace32013-02-21 23:53:01 +0000530
531 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
Simon Glassa1015ad2016-02-21 21:09:01 -0700532 priv->vl_dp = VIDEO_ACTIVE_LOW;
Ajay Kumarebbace32013-02-21 23:53:01 +0000533
Simon Glassa1015ad2016-02-21 21:09:01 -0700534 priv->vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
535 if (priv->vl_bpix == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000536 debug("Can't get bits per pixel\n");
537 return -ENXIO;
538 }
539
Simon Glassa1015ad2016-02-21 21:09:01 -0700540 priv->vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
541 if (priv->vl_hspw == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000542 debug("Can't get hsync width\n");
543 return -ENXIO;
544 }
545
Simon Glassa1015ad2016-02-21 21:09:01 -0700546 priv->vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
547 if (priv->vl_hfpd == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000548 debug("Can't get right margin\n");
549 return -ENXIO;
550 }
551
Simon Glassa1015ad2016-02-21 21:09:01 -0700552 priv->vl_hbpd = (u_char)fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000553 "samsung,vl-hbpd", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700554 if (priv->vl_hbpd == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000555 debug("Can't get left margin\n");
556 return -ENXIO;
557 }
558
Simon Glassa1015ad2016-02-21 21:09:01 -0700559 priv->vl_vspw = (u_char)fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000560 "samsung,vl-vspw", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700561 if (priv->vl_vspw == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000562 debug("Can't get vsync width\n");
563 return -ENXIO;
564 }
565
Simon Glassa1015ad2016-02-21 21:09:01 -0700566 priv->vl_vfpd = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000567 "samsung,vl-vfpd", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700568 if (priv->vl_vfpd == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000569 debug("Can't get lower margin\n");
570 return -ENXIO;
571 }
572
Simon Glassa1015ad2016-02-21 21:09:01 -0700573 priv->vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
574 if (priv->vl_vbpd == 0) {
Ajay Kumarebbace32013-02-21 23:53:01 +0000575 debug("Can't get upper margin\n");
576 return -ENXIO;
577 }
578
Simon Glassa1015ad2016-02-21 21:09:01 -0700579 priv->vl_cmd_allow_len = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000580 "samsung,vl-cmd-allow-len", 0);
581
Simon Glassa1015ad2016-02-21 21:09:01 -0700582 priv->win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
583 priv->init_delay = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000584 "samsung,init-delay", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700585 priv->power_on_delay = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000586 "samsung,power-on-delay", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700587 priv->reset_delay = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000588 "samsung,reset-delay", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700589 priv->interface_mode = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000590 "samsung,interface-mode", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700591 priv->mipi_enabled = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000592 "samsung,mipi-enabled", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700593 priv->dp_enabled = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000594 "samsung,dp-enabled", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700595 priv->cs_setup = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000596 "samsung,cs-setup", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700597 priv->wr_setup = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000598 "samsung,wr-setup", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700599 priv->wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
600 priv->wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
Ajay Kumarebbace32013-02-21 23:53:01 +0000601
Simon Glassa1015ad2016-02-21 21:09:01 -0700602 priv->logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
603 if (priv->logo_on) {
604 priv->logo_width = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000605 "samsung,logo-width", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700606 priv->logo_height = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000607 "samsung,logo-height", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700608 priv->logo_addr = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000609 "samsung,logo-addr", 0);
610 }
611
Simon Glassa1015ad2016-02-21 21:09:01 -0700612 priv->rgb_mode = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000613 "samsung,rgb-mode", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700614 priv->pclk_name = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000615 "samsung,pclk-name", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700616 priv->sclk_div = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000617 "samsung,sclk-div", 0);
Simon Glassa1015ad2016-02-21 21:09:01 -0700618 priv->dual_lcd_enabled = fdtdec_get_int(blob, node,
Ajay Kumarebbace32013-02-21 23:53:01 +0000619 "samsung,dual-lcd-enabled", 0);
620
621 return 0;
622}
Donghwa Lee0112fed2012-04-05 19:36:17 +0000623
Simon Glassa1015ad2016-02-21 21:09:01 -0700624static int exynos_fb_probe(struct udevice *dev)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000625{
Simon Glassa1015ad2016-02-21 21:09:01 -0700626 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
627 struct exynos_fb_priv *priv = dev_get_priv(dev);
628 struct udevice *panel, *bridge;
629 struct udevice *dp;
630 int ret;
631
632 debug("%s: start\n", __func__);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000633 set_system_display_ctrl();
634 set_lcd_clk();
635
Piotr Wilczek386fd022014-03-07 14:59:40 +0100636#ifdef CONFIG_EXYNOS_MIPI_DSIM
637 exynos_init_dsim_platform_data(&panel_info);
638#endif
Simon Glassa1015ad2016-02-21 21:09:01 -0700639 exynos_fimd_lcd_init(dev);
Piotr Wilczek386fd022014-03-07 14:59:40 +0100640
Simon Glassa1015ad2016-02-21 21:09:01 -0700641 ret = uclass_first_device(UCLASS_PANEL, &panel);
642 if (ret) {
643 printf("LCD panel failed to probe\n");
644 return ret;
645 }
646 if (!panel) {
647 printf("LCD panel not found\n");
648 return -ENODEV;
649 }
Donghwa Lee0112fed2012-04-05 19:36:17 +0000650
Simon Glassa1015ad2016-02-21 21:09:01 -0700651 ret = uclass_first_device(UCLASS_DISPLAY, &dp);
652 if (ret) {
653 debug("%s: Display device error %d\n", __func__, ret);
654 return ret;
655 }
656 if (!dev) {
657 debug("%s: Display device missing\n", __func__);
658 return -ENODEV;
659 }
660 ret = display_enable(dp, 18, NULL);
661 if (ret) {
662 debug("%s: Display enable error %d\n", __func__, ret);
663 return ret;
664 }
665
666 /* backlight / pwm */
667 ret = panel_enable_backlight(panel);
668 if (ret) {
669 debug("%s: backlight error: %d\n", __func__, ret);
670 return ret;
671 }
672
673 ret = uclass_get_device(UCLASS_VIDEO_BRIDGE, 0, &bridge);
674 if (!ret)
675 ret = video_bridge_set_backlight(bridge, 80);
676 if (ret) {
677 debug("%s: No video bridge, or no backlight on bridge\n",
678 __func__);
679 exynos_pinmux_config(PERIPH_ID_PWM0, 0);
Donghwa Lee37980dd2012-05-09 19:23:46 +0000680 }
681
Simon Glassa1015ad2016-02-21 21:09:01 -0700682 uc_priv->xsize = priv->vl_col;
683 uc_priv->ysize = priv->vl_row;
684 uc_priv->bpix = priv->vl_bpix;
685
686 /* Enable flushing after LCD writes if requested */
687 video_set_flush_dcache(dev, true);
688
689 return 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000690}
691
Simon Glassa1015ad2016-02-21 21:09:01 -0700692static int exynos_fb_bind(struct udevice *dev)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000693{
Simon Glassa1015ad2016-02-21 21:09:01 -0700694 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
695
696 /* This is the maximum panel size we expect to see */
697 plat->size = 1920 * 1080 * 2;
698
699 return 0;
Donghwa Lee0112fed2012-04-05 19:36:17 +0000700}
Simon Glassa1015ad2016-02-21 21:09:01 -0700701
702static const struct video_ops exynos_fb_ops = {
703};
704
705static const struct udevice_id exynos_fb_ids[] = {
706 { .compatible = "samsung,exynos-fimd" },
707 { }
708};
709
710U_BOOT_DRIVER(exynos_fb) = {
711 .name = "exynos_fb",
712 .id = UCLASS_VIDEO,
713 .of_match = exynos_fb_ids,
714 .ops = &exynos_fb_ops,
715 .bind = exynos_fb_bind,
716 .probe = exynos_fb_probe,
717 .ofdata_to_platdata = exynos_fb_ofdata_to_platdata,
718 .priv_auto_alloc_size = sizeof(struct exynos_fb_priv),
719};