blob: be35b982acd12f6019281248145a06124a483720 [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
Donghwa Lee6d4339f2012-04-05 19:36:17 +000040static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
41{
42 unsigned long palette_size;
43 unsigned int fb_size;
44
Donghwa Leef78095e2012-04-23 15:37:05 +000045 fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000046
Donghwa Lee6d4339f2012-04-05 19:36:17 +000047 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
48
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +000049 exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
Donghwa Lee6d4339f2012-04-05 19:36:17 +000050 (unsigned long)fb_size, palette_size);
51}
52
53static void exynos_lcd_init(vidinfo_t *vid)
54{
55 exynos_fimd_lcd_init(vid);
Ɓukasz Majewskic6d647e2013-01-08 03:48:40 +000056
57 /* Enable flushing after LCD writes if requested */
58 lcd_set_flush_dcache(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000059}
60
Jeroen Hofstee69d27542014-10-08 22:57:30 +020061__weak void exynos_cfg_lcd_gpio(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000062{
63}
Ajay Kumar29fd5702013-02-21 23:52:57 +000064
Jeroen Hofstee69d27542014-10-08 22:57:30 +020065__weak void exynos_backlight_on(unsigned int onoff)
Ajay Kumar29fd5702013-02-21 23:52:57 +000066{
67}
Ajay Kumar29fd5702013-02-21 23:52:57 +000068
Jeroen Hofstee69d27542014-10-08 22:57:30 +020069__weak void exynos_reset_lcd(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000070{
71}
Ajay Kumar29fd5702013-02-21 23:52:57 +000072
Jeroen Hofstee69d27542014-10-08 22:57:30 +020073__weak void exynos_lcd_power_on(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000074{
75}
Ajay Kumar29fd5702013-02-21 23:52:57 +000076
Jeroen Hofstee69d27542014-10-08 22:57:30 +020077__weak void exynos_cfg_ldo(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000078{
79}
Ajay Kumar29fd5702013-02-21 23:52:57 +000080
Jeroen Hofstee69d27542014-10-08 22:57:30 +020081__weak void exynos_enable_ldo(unsigned int onoff)
Ajay Kumar29fd5702013-02-21 23:52:57 +000082{
83}
Ajay Kumar29fd5702013-02-21 23:52:57 +000084
Jeroen Hofstee69d27542014-10-08 22:57:30 +020085__weak void exynos_backlight_reset(void)
Ajay Kumar29fd5702013-02-21 23:52:57 +000086{
87}
Ajay Kumar29fd5702013-02-21 23:52:57 +000088
Jeroen Hofstee69d27542014-10-08 22:57:30 +020089__weak int exynos_lcd_misc_init(vidinfo_t *vid)
Piotr Wilczek1591ee72014-03-07 14:59:40 +010090{
91 return 0;
92}
Piotr Wilczek1591ee72014-03-07 14:59:40 +010093
Donghwa Lee6d4339f2012-04-05 19:36:17 +000094static void lcd_panel_on(vidinfo_t *vid)
95{
96 udelay(vid->init_delay);
97
Ajay Kumar29fd5702013-02-21 23:52:57 +000098 exynos_backlight_reset();
Donghwa Lee6d4339f2012-04-05 19:36:17 +000099
Ajay Kumar29fd5702013-02-21 23:52:57 +0000100 exynos_cfg_lcd_gpio();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000101
Ajay Kumar29fd5702013-02-21 23:52:57 +0000102 exynos_lcd_power_on();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000103
104 udelay(vid->power_on_delay);
105
Donghwa Leea29c8322012-07-02 01:16:08 +0000106 if (vid->dp_enabled)
107 exynos_init_dp();
108
Ajay Kumar29fd5702013-02-21 23:52:57 +0000109 exynos_reset_lcd();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000110
Ajay Kumar29fd5702013-02-21 23:52:57 +0000111 udelay(vid->reset_delay);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000112
Ajay Kumar29fd5702013-02-21 23:52:57 +0000113 exynos_backlight_on(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000114
Ajay Kumar29fd5702013-02-21 23:52:57 +0000115 exynos_cfg_ldo();
116
117 exynos_enable_ldo(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000118
119 if (vid->mipi_enabled)
120 exynos_mipi_dsi_init();
121}
122
Ajay Kumarc23f3152013-02-21 23:53:01 +0000123#ifdef CONFIG_OF_CONTROL
Ajay Kumarf0017172014-09-05 16:53:30 +0530124int exynos_lcd_early_init(const void *blob)
Ajay Kumarc23f3152013-02-21 23:53:01 +0000125{
126 unsigned int node;
127 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
128 if (node <= 0) {
129 debug("exynos_fb: Can't get device node for fimd\n");
130 return -ENODEV;
131 }
132
133 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
134 if (panel_info.vl_col == 0) {
135 debug("Can't get XRES\n");
136 return -ENXIO;
137 }
138
139 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
140 if (panel_info.vl_row == 0) {
141 debug("Can't get YRES\n");
142 return -ENXIO;
143 }
144
145 panel_info.vl_width = fdtdec_get_int(blob, node,
146 "samsung,vl-width", 0);
147
148 panel_info.vl_height = fdtdec_get_int(blob, node,
149 "samsung,vl-height", 0);
150
151 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
152 if (panel_info.vl_freq == 0) {
153 debug("Can't get refresh rate\n");
154 return -ENXIO;
155 }
156
157 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
158 panel_info.vl_clkp = CONFIG_SYS_LOW;
159
160 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
161 panel_info.vl_oep = CONFIG_SYS_LOW;
162
163 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
164 panel_info.vl_hsp = CONFIG_SYS_LOW;
165
166 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
167 panel_info.vl_vsp = CONFIG_SYS_LOW;
168
169 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
170 panel_info.vl_dp = CONFIG_SYS_LOW;
171
172 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
173 if (panel_info.vl_bpix == 0) {
174 debug("Can't get bits per pixel\n");
175 return -ENXIO;
176 }
177
178 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
179 if (panel_info.vl_hspw == 0) {
180 debug("Can't get hsync width\n");
181 return -ENXIO;
182 }
183
184 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
185 if (panel_info.vl_hfpd == 0) {
186 debug("Can't get right margin\n");
187 return -ENXIO;
188 }
189
190 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
191 "samsung,vl-hbpd", 0);
192 if (panel_info.vl_hbpd == 0) {
193 debug("Can't get left margin\n");
194 return -ENXIO;
195 }
196
197 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
198 "samsung,vl-vspw", 0);
199 if (panel_info.vl_vspw == 0) {
200 debug("Can't get vsync width\n");
201 return -ENXIO;
202 }
203
204 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
205 "samsung,vl-vfpd", 0);
206 if (panel_info.vl_vfpd == 0) {
207 debug("Can't get lower margin\n");
208 return -ENXIO;
209 }
210
211 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
212 if (panel_info.vl_vbpd == 0) {
213 debug("Can't get upper margin\n");
214 return -ENXIO;
215 }
216
217 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
218 "samsung,vl-cmd-allow-len", 0);
219
220 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
221 panel_info.init_delay = fdtdec_get_int(blob, node,
222 "samsung,init-delay", 0);
223 panel_info.power_on_delay = fdtdec_get_int(blob, node,
224 "samsung,power-on-delay", 0);
225 panel_info.reset_delay = fdtdec_get_int(blob, node,
226 "samsung,reset-delay", 0);
227 panel_info.interface_mode = fdtdec_get_int(blob, node,
228 "samsung,interface-mode", 0);
229 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
230 "samsung,mipi-enabled", 0);
231 panel_info.dp_enabled = fdtdec_get_int(blob, node,
232 "samsung,dp-enabled", 0);
233 panel_info.cs_setup = fdtdec_get_int(blob, node,
234 "samsung,cs-setup", 0);
235 panel_info.wr_setup = fdtdec_get_int(blob, node,
236 "samsung,wr-setup", 0);
237 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
238 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
239
240 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
241 if (panel_info.logo_on) {
242 panel_info.logo_width = fdtdec_get_int(blob, node,
243 "samsung,logo-width", 0);
244 panel_info.logo_height = fdtdec_get_int(blob, node,
245 "samsung,logo-height", 0);
246 panel_info.logo_addr = fdtdec_get_int(blob, node,
247 "samsung,logo-addr", 0);
248 }
249
250 panel_info.rgb_mode = fdtdec_get_int(blob, node,
251 "samsung,rgb-mode", 0);
252 panel_info.pclk_name = fdtdec_get_int(blob, node,
253 "samsung,pclk-name", 0);
254 panel_info.sclk_div = fdtdec_get_int(blob, node,
255 "samsung,sclk-div", 0);
256 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
257 "samsung,dual-lcd-enabled", 0);
258
259 return 0;
260}
261#endif
262
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000263void lcd_ctrl_init(void *lcdbase)
264{
265 set_system_display_ctrl();
266 set_lcd_clk();
267
Ajay Kumarc23f3152013-02-21 23:53:01 +0000268#ifdef CONFIG_OF_CONTROL
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100269#ifdef CONFIG_EXYNOS_MIPI_DSIM
270 exynos_init_dsim_platform_data(&panel_info);
271#endif
272 exynos_lcd_misc_init(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530273#else
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000274 /* initialize parameters which is specific to panel. */
275 init_panel_info(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530276#endif
Piotr Wilczek1591ee72014-03-07 14:59:40 +0100277
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000278 panel_width = panel_info.vl_width;
279 panel_height = panel_info.vl_height;
280
281 exynos_lcd_init_mem(lcdbase, &panel_info);
282
283 exynos_lcd_init(&panel_info);
284}
285
286void lcd_enable(void)
287{
Donghwa Lee90464972012-05-09 19:23:46 +0000288 if (panel_info.logo_on) {
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000289 memset((void *) gd->fb_base, 0, panel_width * panel_height *
Donghwa Lee90464972012-05-09 19:23:46 +0000290 (NBITS(panel_info.vl_bpix) >> 3));
Donghwa Lee90464972012-05-09 19:23:46 +0000291 }
292
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000293 lcd_panel_on(&panel_info);
294}
295
296/* dummy function */
297void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
298{
299 return;
300}