blob: e1e0d802f657279585a50f2410e02784d49034cd [file] [log] [blame]
Donghwa Lee6d4339f2012-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 Denk3765b3e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
Donghwa Lee6d4339f2012-04-05 19:36:17 +00008 */
9
10#include <config.h>
11#include <common.h>
12#include <lcd.h>
Ajay Kumarc23f3152013-02-21 23:53:01 +000013#include <fdtdec.h>
14#include <libfdt.h>
Donghwa Lee6d4339f2012-04-05 19:36:17 +000015#include <asm/io.h>
16#include <asm/arch/cpu.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/clk.h>
19#include <asm/arch/mipi_dsim.h>
Donghwa Leea29c8322012-07-02 01:16:08 +000020#include <asm/arch/dp_info.h>
Donghwa Lee6d4339f2012-04-05 19:36:17 +000021#include <asm/arch/system.h>
Ajay Kumarc23f3152013-02-21 23:53:01 +000022#include <asm-generic/errno.h>
Donghwa Lee6d4339f2012-04-05 19:36:17 +000023
24#include "exynos_fb.h"
25
Ajay Kumarc23f3152013-02-21 23:53:01 +000026DECLARE_GLOBAL_DATA_PTR;
27
Donghwa Lee6d4339f2012-04-05 19:36:17 +000028static unsigned int panel_width, panel_height;
29
Ajay Kumarc23f3152013-02-21 23:53:01 +000030/*
31 * board_init_f(arch/arm/lib/board.c) calls lcd_setmem() which needs
32 * panel_info.vl_col, panel_info.vl_row and panel_info.vl_bpix to reserve
33 * FB memory at a very early stage, i.e even before exynos_fimd_parse_dt()
34 * is called. So, we are forced to statically assign it.
35 */
36#ifdef CONFIG_OF_CONTROL
37vidinfo_t panel_info = {
38 .vl_col = LCD_XRES,
39 .vl_row = LCD_YRES,
40 .vl_bpix = LCD_COLOR16,
41};
42#endif
43
Donghwa Lee6d4339f2012-04-05 19:36:17 +000044static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
45{
46 unsigned long palette_size;
47 unsigned int fb_size;
48
Donghwa Leef78095e2012-04-23 15:37:05 +000049 fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000050
Donghwa Lee6d4339f2012-04-05 19:36:17 +000051 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
52
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +000053 exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
Donghwa Lee6d4339f2012-04-05 19:36:17 +000054 (unsigned long)fb_size, palette_size);
55}
56
57static void exynos_lcd_init(vidinfo_t *vid)
58{
59 exynos_fimd_lcd_init(vid);
Ɓukasz Majewskic6d647e2013-01-08 03:48:40 +000060
61 /* Enable flushing after LCD writes if requested */
62 lcd_set_flush_dcache(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000063}
64
Ajay Kumar29fd5702013-02-21 23:52:57 +000065void __exynos_cfg_lcd_gpio(void)
66{
67}
68void exynos_cfg_lcd_gpio(void)
69 __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
70
71void __exynos_backlight_on(unsigned int onoff)
72{
73}
74void exynos_backlight_on(unsigned int onoff)
75 __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
76
77void __exynos_reset_lcd(void)
78{
79}
80void exynos_reset_lcd(void)
81 __attribute__((weak, alias("__exynos_reset_lcd")));
82
83void __exynos_lcd_power_on(void)
84{
85}
86void exynos_lcd_power_on(void)
87 __attribute__((weak, alias("__exynos_lcd_power_on")));
88
89void __exynos_cfg_ldo(void)
90{
91}
92void exynos_cfg_ldo(void)
93 __attribute__((weak, alias("__exynos_cfg_ldo")));
94
95void __exynos_enable_ldo(unsigned int onoff)
96{
97}
98void exynos_enable_ldo(unsigned int onoff)
99 __attribute__((weak, alias("__exynos_enable_ldo")));
100
101void __exynos_backlight_reset(void)
102{
103}
104void exynos_backlight_reset(void)
105 __attribute__((weak, alias("__exynos_backlight_reset")));
106
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100107int __exynos_lcd_misc_init(vidinfo_t *vid)
108{
109 return 0;
110}
111int exynos_lcd_misc_init(vidinfo_t *vid)
112 __attribute__((weak, alias("__exynos_lcd_misc_init")));
113
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000114static void lcd_panel_on(vidinfo_t *vid)
115{
116 udelay(vid->init_delay);
117
Ajay Kumar29fd5702013-02-21 23:52:57 +0000118 exynos_backlight_reset();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000119
Ajay Kumar29fd5702013-02-21 23:52:57 +0000120 exynos_cfg_lcd_gpio();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000121
Ajay Kumar29fd5702013-02-21 23:52:57 +0000122 exynos_lcd_power_on();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000123
124 udelay(vid->power_on_delay);
125
Donghwa Leea29c8322012-07-02 01:16:08 +0000126 if (vid->dp_enabled)
127 exynos_init_dp();
128
Ajay Kumar29fd5702013-02-21 23:52:57 +0000129 exynos_reset_lcd();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000130
Ajay Kumar29fd5702013-02-21 23:52:57 +0000131 udelay(vid->reset_delay);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000132
Ajay Kumar29fd5702013-02-21 23:52:57 +0000133 exynos_backlight_on(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000134
Ajay Kumar29fd5702013-02-21 23:52:57 +0000135 exynos_cfg_ldo();
136
137 exynos_enable_ldo(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000138
139 if (vid->mipi_enabled)
140 exynos_mipi_dsi_init();
141}
142
Ajay Kumarc23f3152013-02-21 23:53:01 +0000143#ifdef CONFIG_OF_CONTROL
144int exynos_fimd_parse_dt(const void *blob)
145{
146 unsigned int node;
147 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
148 if (node <= 0) {
149 debug("exynos_fb: Can't get device node for fimd\n");
150 return -ENODEV;
151 }
152
153 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
154 if (panel_info.vl_col == 0) {
155 debug("Can't get XRES\n");
156 return -ENXIO;
157 }
158
159 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
160 if (panel_info.vl_row == 0) {
161 debug("Can't get YRES\n");
162 return -ENXIO;
163 }
164
165 panel_info.vl_width = fdtdec_get_int(blob, node,
166 "samsung,vl-width", 0);
167
168 panel_info.vl_height = fdtdec_get_int(blob, node,
169 "samsung,vl-height", 0);
170
171 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
172 if (panel_info.vl_freq == 0) {
173 debug("Can't get refresh rate\n");
174 return -ENXIO;
175 }
176
177 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
178 panel_info.vl_clkp = CONFIG_SYS_LOW;
179
180 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
181 panel_info.vl_oep = CONFIG_SYS_LOW;
182
183 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
184 panel_info.vl_hsp = CONFIG_SYS_LOW;
185
186 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
187 panel_info.vl_vsp = CONFIG_SYS_LOW;
188
189 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
190 panel_info.vl_dp = CONFIG_SYS_LOW;
191
192 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
193 if (panel_info.vl_bpix == 0) {
194 debug("Can't get bits per pixel\n");
195 return -ENXIO;
196 }
197
198 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
199 if (panel_info.vl_hspw == 0) {
200 debug("Can't get hsync width\n");
201 return -ENXIO;
202 }
203
204 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
205 if (panel_info.vl_hfpd == 0) {
206 debug("Can't get right margin\n");
207 return -ENXIO;
208 }
209
210 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
211 "samsung,vl-hbpd", 0);
212 if (panel_info.vl_hbpd == 0) {
213 debug("Can't get left margin\n");
214 return -ENXIO;
215 }
216
217 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
218 "samsung,vl-vspw", 0);
219 if (panel_info.vl_vspw == 0) {
220 debug("Can't get vsync width\n");
221 return -ENXIO;
222 }
223
224 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
225 "samsung,vl-vfpd", 0);
226 if (panel_info.vl_vfpd == 0) {
227 debug("Can't get lower margin\n");
228 return -ENXIO;
229 }
230
231 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
232 if (panel_info.vl_vbpd == 0) {
233 debug("Can't get upper margin\n");
234 return -ENXIO;
235 }
236
237 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
238 "samsung,vl-cmd-allow-len", 0);
239
240 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
241 panel_info.init_delay = fdtdec_get_int(blob, node,
242 "samsung,init-delay", 0);
243 panel_info.power_on_delay = fdtdec_get_int(blob, node,
244 "samsung,power-on-delay", 0);
245 panel_info.reset_delay = fdtdec_get_int(blob, node,
246 "samsung,reset-delay", 0);
247 panel_info.interface_mode = fdtdec_get_int(blob, node,
248 "samsung,interface-mode", 0);
249 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
250 "samsung,mipi-enabled", 0);
251 panel_info.dp_enabled = fdtdec_get_int(blob, node,
252 "samsung,dp-enabled", 0);
253 panel_info.cs_setup = fdtdec_get_int(blob, node,
254 "samsung,cs-setup", 0);
255 panel_info.wr_setup = fdtdec_get_int(blob, node,
256 "samsung,wr-setup", 0);
257 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
258 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
259
260 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
261 if (panel_info.logo_on) {
262 panel_info.logo_width = fdtdec_get_int(blob, node,
263 "samsung,logo-width", 0);
264 panel_info.logo_height = fdtdec_get_int(blob, node,
265 "samsung,logo-height", 0);
266 panel_info.logo_addr = fdtdec_get_int(blob, node,
267 "samsung,logo-addr", 0);
268 }
269
270 panel_info.rgb_mode = fdtdec_get_int(blob, node,
271 "samsung,rgb-mode", 0);
272 panel_info.pclk_name = fdtdec_get_int(blob, node,
273 "samsung,pclk-name", 0);
274 panel_info.sclk_div = fdtdec_get_int(blob, node,
275 "samsung,sclk-div", 0);
276 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
277 "samsung,dual-lcd-enabled", 0);
278
279 return 0;
280}
281#endif
282
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000283void lcd_ctrl_init(void *lcdbase)
284{
285 set_system_display_ctrl();
286 set_lcd_clk();
287
Ajay Kumarc23f3152013-02-21 23:53:01 +0000288#ifdef CONFIG_OF_CONTROL
289 if (exynos_fimd_parse_dt(gd->fdt_blob))
290 debug("Can't get proper panel info\n");
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100291#ifdef CONFIG_EXYNOS_MIPI_DSIM
292 exynos_init_dsim_platform_data(&panel_info);
293#endif
294 exynos_lcd_misc_init(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530295#else
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000296 /* initialize parameters which is specific to panel. */
297 init_panel_info(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530298#endif
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100299
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000300 panel_width = panel_info.vl_width;
301 panel_height = panel_info.vl_height;
302
303 exynos_lcd_init_mem(lcdbase, &panel_info);
304
305 exynos_lcd_init(&panel_info);
306}
307
308void lcd_enable(void)
309{
Donghwa Lee90464972012-05-09 19:23:46 +0000310 if (panel_info.logo_on) {
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000311 memset((void *) gd->fb_base, 0, panel_width * panel_height *
Donghwa Lee90464972012-05-09 19:23:46 +0000312 (NBITS(panel_info.vl_bpix) >> 3));
Donghwa Lee90464972012-05-09 19:23:46 +0000313 }
314
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000315 lcd_panel_on(&panel_info);
316}
317
318/* dummy function */
319void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
320{
321 return;
322}