blob: c5d73308047fac83a9a663a136a6b3c1e3ed7a78 [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#ifdef CONFIG_OF_CONTROL
31vidinfo_t panel_info = {
Ajay Kumarf0017172014-09-05 16:53:30 +053032 /*
33 * Insert a value here so that we don't end up in the BSS
34 * Reference: drivers/video/tegra.c
35 */
36 .vl_col = -1,
Ajay Kumarc23f3152013-02-21 23:53:01 +000037};
38#endif
39
Nikita Kiryanov38b55082015-02-03 13:32:21 +020040ushort *configuration_get_cmap(void)
41{
42#if defined(CONFIG_LCD_LOGO)
43 return bmp_logo_palette;
44#else
45 return NULL;
46#endif
47}
48
Donghwa Lee6d4339f2012-04-05 19:36:17 +000049static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
50{
51 unsigned long palette_size;
52 unsigned int fb_size;
53
Donghwa Leef78095e2012-04-23 15:37:05 +000054 fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000055
Donghwa Lee6d4339f2012-04-05 19:36:17 +000056 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
57
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +000058 exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
Donghwa Lee6d4339f2012-04-05 19:36:17 +000059 (unsigned long)fb_size, palette_size);
60}
61
62static void exynos_lcd_init(vidinfo_t *vid)
63{
64 exynos_fimd_lcd_init(vid);
Ɓukasz Majewskic6d647e2013-01-08 03:48:40 +000065
66 /* Enable flushing after LCD writes if requested */
67 lcd_set_flush_dcache(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000068}
69
Jeroen Hofstee69d27542014-10-08 22:57:30 +020070__weak void exynos_cfg_lcd_gpio(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000071{
72}
Ajay Kumar29fd5702013-02-21 23:52:57 +000073
Jeroen Hofstee69d27542014-10-08 22:57:30 +020074__weak void exynos_backlight_on(unsigned int onoff)
Ajay Kumar29fd5702013-02-21 23:52:57 +000075{
76}
Ajay Kumar29fd5702013-02-21 23:52:57 +000077
Jeroen Hofstee69d27542014-10-08 22:57:30 +020078__weak void exynos_reset_lcd(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000079{
80}
Ajay Kumar29fd5702013-02-21 23:52:57 +000081
Jeroen Hofstee69d27542014-10-08 22:57:30 +020082__weak void exynos_lcd_power_on(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000083{
84}
Ajay Kumar29fd5702013-02-21 23:52:57 +000085
Jeroen Hofstee69d27542014-10-08 22:57:30 +020086__weak void exynos_cfg_ldo(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000087{
88}
Ajay Kumar29fd5702013-02-21 23:52:57 +000089
Jeroen Hofstee69d27542014-10-08 22:57:30 +020090__weak void exynos_enable_ldo(unsigned int onoff)
Ajay Kumar29fd5702013-02-21 23:52:57 +000091{
92}
Ajay Kumar29fd5702013-02-21 23:52:57 +000093
Jeroen Hofstee69d27542014-10-08 22:57:30 +020094__weak void exynos_backlight_reset(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000095{
96}
Ajay Kumar29fd5702013-02-21 23:52:57 +000097
Jeroen Hofstee69d27542014-10-08 22:57:30 +020098__weak int exynos_lcd_misc_init(vidinfo_t *vid)
Piotr Wilczek1591ee72014-03-07 14:59:40 +010099{
100 return 0;
101}
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100102
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000103static void lcd_panel_on(vidinfo_t *vid)
104{
105 udelay(vid->init_delay);
106
Ajay Kumar29fd5702013-02-21 23:52:57 +0000107 exynos_backlight_reset();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000108
Ajay Kumar29fd5702013-02-21 23:52:57 +0000109 exynos_cfg_lcd_gpio();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000110
Ajay Kumar29fd5702013-02-21 23:52:57 +0000111 exynos_lcd_power_on();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000112
113 udelay(vid->power_on_delay);
114
Donghwa Leea29c8322012-07-02 01:16:08 +0000115 if (vid->dp_enabled)
116 exynos_init_dp();
117
Ajay Kumar29fd5702013-02-21 23:52:57 +0000118 exynos_reset_lcd();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000119
Ajay Kumar29fd5702013-02-21 23:52:57 +0000120 udelay(vid->reset_delay);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000121
Ajay Kumar29fd5702013-02-21 23:52:57 +0000122 exynos_backlight_on(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000123
Ajay Kumar29fd5702013-02-21 23:52:57 +0000124 exynos_cfg_ldo();
125
126 exynos_enable_ldo(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000127
128 if (vid->mipi_enabled)
129 exynos_mipi_dsi_init();
130}
131
Ajay Kumarc23f3152013-02-21 23:53:01 +0000132#ifdef CONFIG_OF_CONTROL
Ajay Kumarf0017172014-09-05 16:53:30 +0530133int exynos_lcd_early_init(const void *blob)
Ajay Kumarc23f3152013-02-21 23:53:01 +0000134{
135 unsigned int node;
136 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
137 if (node <= 0) {
138 debug("exynos_fb: Can't get device node for fimd\n");
139 return -ENODEV;
140 }
141
142 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
143 if (panel_info.vl_col == 0) {
144 debug("Can't get XRES\n");
145 return -ENXIO;
146 }
147
148 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
149 if (panel_info.vl_row == 0) {
150 debug("Can't get YRES\n");
151 return -ENXIO;
152 }
153
154 panel_info.vl_width = fdtdec_get_int(blob, node,
155 "samsung,vl-width", 0);
156
157 panel_info.vl_height = fdtdec_get_int(blob, node,
158 "samsung,vl-height", 0);
159
160 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
161 if (panel_info.vl_freq == 0) {
162 debug("Can't get refresh rate\n");
163 return -ENXIO;
164 }
165
166 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
167 panel_info.vl_clkp = CONFIG_SYS_LOW;
168
169 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
170 panel_info.vl_oep = CONFIG_SYS_LOW;
171
172 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
173 panel_info.vl_hsp = CONFIG_SYS_LOW;
174
175 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
176 panel_info.vl_vsp = CONFIG_SYS_LOW;
177
178 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
179 panel_info.vl_dp = CONFIG_SYS_LOW;
180
181 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
182 if (panel_info.vl_bpix == 0) {
183 debug("Can't get bits per pixel\n");
184 return -ENXIO;
185 }
186
187 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
188 if (panel_info.vl_hspw == 0) {
189 debug("Can't get hsync width\n");
190 return -ENXIO;
191 }
192
193 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
194 if (panel_info.vl_hfpd == 0) {
195 debug("Can't get right margin\n");
196 return -ENXIO;
197 }
198
199 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
200 "samsung,vl-hbpd", 0);
201 if (panel_info.vl_hbpd == 0) {
202 debug("Can't get left margin\n");
203 return -ENXIO;
204 }
205
206 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
207 "samsung,vl-vspw", 0);
208 if (panel_info.vl_vspw == 0) {
209 debug("Can't get vsync width\n");
210 return -ENXIO;
211 }
212
213 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
214 "samsung,vl-vfpd", 0);
215 if (panel_info.vl_vfpd == 0) {
216 debug("Can't get lower margin\n");
217 return -ENXIO;
218 }
219
220 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
221 if (panel_info.vl_vbpd == 0) {
222 debug("Can't get upper margin\n");
223 return -ENXIO;
224 }
225
226 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
227 "samsung,vl-cmd-allow-len", 0);
228
229 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
230 panel_info.init_delay = fdtdec_get_int(blob, node,
231 "samsung,init-delay", 0);
232 panel_info.power_on_delay = fdtdec_get_int(blob, node,
233 "samsung,power-on-delay", 0);
234 panel_info.reset_delay = fdtdec_get_int(blob, node,
235 "samsung,reset-delay", 0);
236 panel_info.interface_mode = fdtdec_get_int(blob, node,
237 "samsung,interface-mode", 0);
238 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
239 "samsung,mipi-enabled", 0);
240 panel_info.dp_enabled = fdtdec_get_int(blob, node,
241 "samsung,dp-enabled", 0);
242 panel_info.cs_setup = fdtdec_get_int(blob, node,
243 "samsung,cs-setup", 0);
244 panel_info.wr_setup = fdtdec_get_int(blob, node,
245 "samsung,wr-setup", 0);
246 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
247 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
248
249 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
250 if (panel_info.logo_on) {
251 panel_info.logo_width = fdtdec_get_int(blob, node,
252 "samsung,logo-width", 0);
253 panel_info.logo_height = fdtdec_get_int(blob, node,
254 "samsung,logo-height", 0);
255 panel_info.logo_addr = fdtdec_get_int(blob, node,
256 "samsung,logo-addr", 0);
257 }
258
259 panel_info.rgb_mode = fdtdec_get_int(blob, node,
260 "samsung,rgb-mode", 0);
261 panel_info.pclk_name = fdtdec_get_int(blob, node,
262 "samsung,pclk-name", 0);
263 panel_info.sclk_div = fdtdec_get_int(blob, node,
264 "samsung,sclk-div", 0);
265 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
266 "samsung,dual-lcd-enabled", 0);
267
268 return 0;
269}
270#endif
271
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000272void lcd_ctrl_init(void *lcdbase)
273{
274 set_system_display_ctrl();
275 set_lcd_clk();
276
Ajay Kumarc23f3152013-02-21 23:53:01 +0000277#ifdef CONFIG_OF_CONTROL
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100278#ifdef CONFIG_EXYNOS_MIPI_DSIM
279 exynos_init_dsim_platform_data(&panel_info);
280#endif
281 exynos_lcd_misc_init(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530282#else
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000283 /* initialize parameters which is specific to panel. */
284 init_panel_info(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530285#endif
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100286
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000287 panel_width = panel_info.vl_width;
288 panel_height = panel_info.vl_height;
289
290 exynos_lcd_init_mem(lcdbase, &panel_info);
291
292 exynos_lcd_init(&panel_info);
293}
294
295void lcd_enable(void)
296{
Donghwa Lee90464972012-05-09 19:23:46 +0000297 if (panel_info.logo_on) {
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000298 memset((void *) gd->fb_base, 0, panel_width * panel_height *
Donghwa Lee90464972012-05-09 19:23:46 +0000299 (NBITS(panel_info.vl_bpix) >> 3));
Donghwa Lee90464972012-05-09 19:23:46 +0000300 }
301
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000302 lcd_panel_on(&panel_info);
303}
304
305/* dummy function */
306void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
307{
308 return;
309}