blob: 5c7ec9199b551fe992e2c289e8210df44cd74ece [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 Denk1a459662013-07-08 09:37:19 +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 Kumare4660e02013-01-13 23:32:16 +000065#ifdef CONFIG_CMD_BMP
Donghwa Lee90464972012-05-09 19:23:46 +000066static void draw_logo(void)
67{
68 int x, y;
69 ulong addr;
70
Piotr Wilczek28c9e342012-10-19 05:34:06 +000071 if (panel_width >= panel_info.logo_width) {
72 x = ((panel_width - panel_info.logo_width) >> 1);
73 } else {
74 x = 0;
75 printf("Warning: image width is bigger than display width\n");
76 }
77
78 if (panel_height >= panel_info.logo_height) {
79 y = ((panel_height - panel_info.logo_height) >> 1) - 4;
80 } else {
81 y = 0;
82 printf("Warning: image height is bigger than display height\n");
83 }
Donghwa Lee90464972012-05-09 19:23:46 +000084
85 addr = panel_info.logo_addr;
86 bmp_display(addr, x, y);
87}
Ajay Kumare4660e02013-01-13 23:32:16 +000088#endif
Donghwa Lee90464972012-05-09 19:23:46 +000089
Ajay Kumar29fd5702013-02-21 23:52:57 +000090void __exynos_cfg_lcd_gpio(void)
91{
92}
93void exynos_cfg_lcd_gpio(void)
94 __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
95
96void __exynos_backlight_on(unsigned int onoff)
97{
98}
99void exynos_backlight_on(unsigned int onoff)
100 __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
101
102void __exynos_reset_lcd(void)
103{
104}
105void exynos_reset_lcd(void)
106 __attribute__((weak, alias("__exynos_reset_lcd")));
107
108void __exynos_lcd_power_on(void)
109{
110}
111void exynos_lcd_power_on(void)
112 __attribute__((weak, alias("__exynos_lcd_power_on")));
113
114void __exynos_cfg_ldo(void)
115{
116}
117void exynos_cfg_ldo(void)
118 __attribute__((weak, alias("__exynos_cfg_ldo")));
119
120void __exynos_enable_ldo(unsigned int onoff)
121{
122}
123void exynos_enable_ldo(unsigned int onoff)
124 __attribute__((weak, alias("__exynos_enable_ldo")));
125
126void __exynos_backlight_reset(void)
127{
128}
129void exynos_backlight_reset(void)
130 __attribute__((weak, alias("__exynos_backlight_reset")));
131
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000132static void lcd_panel_on(vidinfo_t *vid)
133{
134 udelay(vid->init_delay);
135
Ajay Kumar29fd5702013-02-21 23:52:57 +0000136 exynos_backlight_reset();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000137
Ajay Kumar29fd5702013-02-21 23:52:57 +0000138 exynos_cfg_lcd_gpio();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000139
Ajay Kumar29fd5702013-02-21 23:52:57 +0000140 exynos_lcd_power_on();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000141
142 udelay(vid->power_on_delay);
143
Donghwa Leea29c8322012-07-02 01:16:08 +0000144 if (vid->dp_enabled)
145 exynos_init_dp();
146
Ajay Kumar29fd5702013-02-21 23:52:57 +0000147 exynos_reset_lcd();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000148
Ajay Kumar29fd5702013-02-21 23:52:57 +0000149 udelay(vid->reset_delay);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000150
Ajay Kumar29fd5702013-02-21 23:52:57 +0000151 exynos_backlight_on(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000152
Ajay Kumar29fd5702013-02-21 23:52:57 +0000153 exynos_cfg_ldo();
154
155 exynos_enable_ldo(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000156
157 if (vid->mipi_enabled)
158 exynos_mipi_dsi_init();
159}
160
Ajay Kumarc23f3152013-02-21 23:53:01 +0000161#ifdef CONFIG_OF_CONTROL
162int exynos_fimd_parse_dt(const void *blob)
163{
164 unsigned int node;
165 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
166 if (node <= 0) {
167 debug("exynos_fb: Can't get device node for fimd\n");
168 return -ENODEV;
169 }
170
171 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
172 if (panel_info.vl_col == 0) {
173 debug("Can't get XRES\n");
174 return -ENXIO;
175 }
176
177 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
178 if (panel_info.vl_row == 0) {
179 debug("Can't get YRES\n");
180 return -ENXIO;
181 }
182
183 panel_info.vl_width = fdtdec_get_int(blob, node,
184 "samsung,vl-width", 0);
185
186 panel_info.vl_height = fdtdec_get_int(blob, node,
187 "samsung,vl-height", 0);
188
189 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
190 if (panel_info.vl_freq == 0) {
191 debug("Can't get refresh rate\n");
192 return -ENXIO;
193 }
194
195 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
196 panel_info.vl_clkp = CONFIG_SYS_LOW;
197
198 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
199 panel_info.vl_oep = CONFIG_SYS_LOW;
200
201 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
202 panel_info.vl_hsp = CONFIG_SYS_LOW;
203
204 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
205 panel_info.vl_vsp = CONFIG_SYS_LOW;
206
207 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
208 panel_info.vl_dp = CONFIG_SYS_LOW;
209
210 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
211 if (panel_info.vl_bpix == 0) {
212 debug("Can't get bits per pixel\n");
213 return -ENXIO;
214 }
215
216 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
217 if (panel_info.vl_hspw == 0) {
218 debug("Can't get hsync width\n");
219 return -ENXIO;
220 }
221
222 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
223 if (panel_info.vl_hfpd == 0) {
224 debug("Can't get right margin\n");
225 return -ENXIO;
226 }
227
228 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
229 "samsung,vl-hbpd", 0);
230 if (panel_info.vl_hbpd == 0) {
231 debug("Can't get left margin\n");
232 return -ENXIO;
233 }
234
235 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
236 "samsung,vl-vspw", 0);
237 if (panel_info.vl_vspw == 0) {
238 debug("Can't get vsync width\n");
239 return -ENXIO;
240 }
241
242 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
243 "samsung,vl-vfpd", 0);
244 if (panel_info.vl_vfpd == 0) {
245 debug("Can't get lower margin\n");
246 return -ENXIO;
247 }
248
249 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
250 if (panel_info.vl_vbpd == 0) {
251 debug("Can't get upper margin\n");
252 return -ENXIO;
253 }
254
255 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
256 "samsung,vl-cmd-allow-len", 0);
257
258 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
259 panel_info.init_delay = fdtdec_get_int(blob, node,
260 "samsung,init-delay", 0);
261 panel_info.power_on_delay = fdtdec_get_int(blob, node,
262 "samsung,power-on-delay", 0);
263 panel_info.reset_delay = fdtdec_get_int(blob, node,
264 "samsung,reset-delay", 0);
265 panel_info.interface_mode = fdtdec_get_int(blob, node,
266 "samsung,interface-mode", 0);
267 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
268 "samsung,mipi-enabled", 0);
269 panel_info.dp_enabled = fdtdec_get_int(blob, node,
270 "samsung,dp-enabled", 0);
271 panel_info.cs_setup = fdtdec_get_int(blob, node,
272 "samsung,cs-setup", 0);
273 panel_info.wr_setup = fdtdec_get_int(blob, node,
274 "samsung,wr-setup", 0);
275 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
276 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
277
278 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
279 if (panel_info.logo_on) {
280 panel_info.logo_width = fdtdec_get_int(blob, node,
281 "samsung,logo-width", 0);
282 panel_info.logo_height = fdtdec_get_int(blob, node,
283 "samsung,logo-height", 0);
284 panel_info.logo_addr = fdtdec_get_int(blob, node,
285 "samsung,logo-addr", 0);
286 }
287
288 panel_info.rgb_mode = fdtdec_get_int(blob, node,
289 "samsung,rgb-mode", 0);
290 panel_info.pclk_name = fdtdec_get_int(blob, node,
291 "samsung,pclk-name", 0);
292 panel_info.sclk_div = fdtdec_get_int(blob, node,
293 "samsung,sclk-div", 0);
294 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
295 "samsung,dual-lcd-enabled", 0);
296
297 return 0;
298}
299#endif
300
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000301void lcd_ctrl_init(void *lcdbase)
302{
303 set_system_display_ctrl();
304 set_lcd_clk();
305
Ajay Kumarc23f3152013-02-21 23:53:01 +0000306#ifdef CONFIG_OF_CONTROL
307 if (exynos_fimd_parse_dt(gd->fdt_blob))
308 debug("Can't get proper panel info\n");
Amar752f4c42013-04-27 11:42:57 +0530309#else
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000310 /* initialize parameters which is specific to panel. */
311 init_panel_info(&panel_info);
Amar752f4c42013-04-27 11:42:57 +0530312#endif
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000313 panel_width = panel_info.vl_width;
314 panel_height = panel_info.vl_height;
315
316 exynos_lcd_init_mem(lcdbase, &panel_info);
317
318 exynos_lcd_init(&panel_info);
319}
320
321void lcd_enable(void)
322{
Donghwa Lee90464972012-05-09 19:23:46 +0000323 if (panel_info.logo_on) {
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000324 memset((void *) gd->fb_base, 0, panel_width * panel_height *
Donghwa Lee90464972012-05-09 19:23:46 +0000325 (NBITS(panel_info.vl_bpix) >> 3));
Ajay Kumare4660e02013-01-13 23:32:16 +0000326#ifdef CONFIG_CMD_BMP
Donghwa Lee90464972012-05-09 19:23:46 +0000327 draw_logo();
Ajay Kumare4660e02013-01-13 23:32:16 +0000328#endif
Donghwa Lee90464972012-05-09 19:23:46 +0000329 }
330
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000331 lcd_panel_on(&panel_info);
332}
333
334/* dummy function */
335void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
336{
337 return;
338}