blob: dfe329fbc631e21630509dfea41ed6fab5c453ab [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 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <config.h>
24#include <common.h>
25#include <lcd.h>
Ajay Kumarc23f3152013-02-21 23:53:01 +000026#include <fdtdec.h>
27#include <libfdt.h>
Donghwa Lee6d4339f2012-04-05 19:36:17 +000028#include <asm/io.h>
29#include <asm/arch/cpu.h>
30#include <asm/arch/clock.h>
31#include <asm/arch/clk.h>
32#include <asm/arch/mipi_dsim.h>
Donghwa Leea29c8322012-07-02 01:16:08 +000033#include <asm/arch/dp_info.h>
Donghwa Lee6d4339f2012-04-05 19:36:17 +000034#include <asm/arch/system.h>
Ajay Kumarc23f3152013-02-21 23:53:01 +000035#include <asm-generic/errno.h>
Donghwa Lee6d4339f2012-04-05 19:36:17 +000036
37#include "exynos_fb.h"
38
Ajay Kumarc23f3152013-02-21 23:53:01 +000039DECLARE_GLOBAL_DATA_PTR;
40
Donghwa Lee6d4339f2012-04-05 19:36:17 +000041int lcd_line_length;
42int lcd_color_fg;
43int lcd_color_bg;
44
45void *lcd_base;
46void *lcd_console_address;
47
48short console_col;
49short console_row;
50
51static unsigned int panel_width, panel_height;
52
Ajay Kumarc23f3152013-02-21 23:53:01 +000053/*
54 * board_init_f(arch/arm/lib/board.c) calls lcd_setmem() which needs
55 * panel_info.vl_col, panel_info.vl_row and panel_info.vl_bpix to reserve
56 * FB memory at a very early stage, i.e even before exynos_fimd_parse_dt()
57 * is called. So, we are forced to statically assign it.
58 */
59#ifdef CONFIG_OF_CONTROL
60vidinfo_t panel_info = {
61 .vl_col = LCD_XRES,
62 .vl_row = LCD_YRES,
63 .vl_bpix = LCD_COLOR16,
64};
65#endif
66
Donghwa Lee6d4339f2012-04-05 19:36:17 +000067static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
68{
69 unsigned long palette_size;
70 unsigned int fb_size;
71
Donghwa Leef78095e2012-04-23 15:37:05 +000072 fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000073
74 lcd_base = lcdbase;
75
76 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
77
78 exynos_fimd_lcd_init_mem((unsigned long)lcd_base,
79 (unsigned long)fb_size, palette_size);
80}
81
82static void exynos_lcd_init(vidinfo_t *vid)
83{
84 exynos_fimd_lcd_init(vid);
Ɓukasz Majewskic6d647e2013-01-08 03:48:40 +000085
86 /* Enable flushing after LCD writes if requested */
87 lcd_set_flush_dcache(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +000088}
89
Ajay Kumare4660e02013-01-13 23:32:16 +000090#ifdef CONFIG_CMD_BMP
Donghwa Lee90464972012-05-09 19:23:46 +000091static void draw_logo(void)
92{
93 int x, y;
94 ulong addr;
95
Piotr Wilczek28c9e342012-10-19 05:34:06 +000096 if (panel_width >= panel_info.logo_width) {
97 x = ((panel_width - panel_info.logo_width) >> 1);
98 } else {
99 x = 0;
100 printf("Warning: image width is bigger than display width\n");
101 }
102
103 if (panel_height >= panel_info.logo_height) {
104 y = ((panel_height - panel_info.logo_height) >> 1) - 4;
105 } else {
106 y = 0;
107 printf("Warning: image height is bigger than display height\n");
108 }
Donghwa Lee90464972012-05-09 19:23:46 +0000109
110 addr = panel_info.logo_addr;
111 bmp_display(addr, x, y);
112}
Ajay Kumare4660e02013-01-13 23:32:16 +0000113#endif
Donghwa Lee90464972012-05-09 19:23:46 +0000114
Ajay Kumar29fd5702013-02-21 23:52:57 +0000115void __exynos_cfg_lcd_gpio(void)
116{
117}
118void exynos_cfg_lcd_gpio(void)
119 __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
120
121void __exynos_backlight_on(unsigned int onoff)
122{
123}
124void exynos_backlight_on(unsigned int onoff)
125 __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
126
127void __exynos_reset_lcd(void)
128{
129}
130void exynos_reset_lcd(void)
131 __attribute__((weak, alias("__exynos_reset_lcd")));
132
133void __exynos_lcd_power_on(void)
134{
135}
136void exynos_lcd_power_on(void)
137 __attribute__((weak, alias("__exynos_lcd_power_on")));
138
139void __exynos_cfg_ldo(void)
140{
141}
142void exynos_cfg_ldo(void)
143 __attribute__((weak, alias("__exynos_cfg_ldo")));
144
145void __exynos_enable_ldo(unsigned int onoff)
146{
147}
148void exynos_enable_ldo(unsigned int onoff)
149 __attribute__((weak, alias("__exynos_enable_ldo")));
150
151void __exynos_backlight_reset(void)
152{
153}
154void exynos_backlight_reset(void)
155 __attribute__((weak, alias("__exynos_backlight_reset")));
156
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000157static void lcd_panel_on(vidinfo_t *vid)
158{
159 udelay(vid->init_delay);
160
Ajay Kumar29fd5702013-02-21 23:52:57 +0000161 exynos_backlight_reset();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000162
Ajay Kumar29fd5702013-02-21 23:52:57 +0000163 exynos_cfg_lcd_gpio();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000164
Ajay Kumar29fd5702013-02-21 23:52:57 +0000165 exynos_lcd_power_on();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000166
167 udelay(vid->power_on_delay);
168
Donghwa Leea29c8322012-07-02 01:16:08 +0000169 if (vid->dp_enabled)
170 exynos_init_dp();
171
Ajay Kumar29fd5702013-02-21 23:52:57 +0000172 exynos_reset_lcd();
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000173
Ajay Kumar29fd5702013-02-21 23:52:57 +0000174 udelay(vid->reset_delay);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000175
Ajay Kumar29fd5702013-02-21 23:52:57 +0000176 exynos_backlight_on(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000177
Ajay Kumar29fd5702013-02-21 23:52:57 +0000178 exynos_cfg_ldo();
179
180 exynos_enable_ldo(1);
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000181
182 if (vid->mipi_enabled)
183 exynos_mipi_dsi_init();
184}
185
Ajay Kumarc23f3152013-02-21 23:53:01 +0000186#ifdef CONFIG_OF_CONTROL
187int exynos_fimd_parse_dt(const void *blob)
188{
189 unsigned int node;
190 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
191 if (node <= 0) {
192 debug("exynos_fb: Can't get device node for fimd\n");
193 return -ENODEV;
194 }
195
196 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
197 if (panel_info.vl_col == 0) {
198 debug("Can't get XRES\n");
199 return -ENXIO;
200 }
201
202 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
203 if (panel_info.vl_row == 0) {
204 debug("Can't get YRES\n");
205 return -ENXIO;
206 }
207
208 panel_info.vl_width = fdtdec_get_int(blob, node,
209 "samsung,vl-width", 0);
210
211 panel_info.vl_height = fdtdec_get_int(blob, node,
212 "samsung,vl-height", 0);
213
214 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
215 if (panel_info.vl_freq == 0) {
216 debug("Can't get refresh rate\n");
217 return -ENXIO;
218 }
219
220 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
221 panel_info.vl_clkp = CONFIG_SYS_LOW;
222
223 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
224 panel_info.vl_oep = CONFIG_SYS_LOW;
225
226 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
227 panel_info.vl_hsp = CONFIG_SYS_LOW;
228
229 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
230 panel_info.vl_vsp = CONFIG_SYS_LOW;
231
232 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
233 panel_info.vl_dp = CONFIG_SYS_LOW;
234
235 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
236 if (panel_info.vl_bpix == 0) {
237 debug("Can't get bits per pixel\n");
238 return -ENXIO;
239 }
240
241 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
242 if (panel_info.vl_hspw == 0) {
243 debug("Can't get hsync width\n");
244 return -ENXIO;
245 }
246
247 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
248 if (panel_info.vl_hfpd == 0) {
249 debug("Can't get right margin\n");
250 return -ENXIO;
251 }
252
253 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
254 "samsung,vl-hbpd", 0);
255 if (panel_info.vl_hbpd == 0) {
256 debug("Can't get left margin\n");
257 return -ENXIO;
258 }
259
260 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
261 "samsung,vl-vspw", 0);
262 if (panel_info.vl_vspw == 0) {
263 debug("Can't get vsync width\n");
264 return -ENXIO;
265 }
266
267 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
268 "samsung,vl-vfpd", 0);
269 if (panel_info.vl_vfpd == 0) {
270 debug("Can't get lower margin\n");
271 return -ENXIO;
272 }
273
274 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
275 if (panel_info.vl_vbpd == 0) {
276 debug("Can't get upper margin\n");
277 return -ENXIO;
278 }
279
280 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
281 "samsung,vl-cmd-allow-len", 0);
282
283 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
284 panel_info.init_delay = fdtdec_get_int(blob, node,
285 "samsung,init-delay", 0);
286 panel_info.power_on_delay = fdtdec_get_int(blob, node,
287 "samsung,power-on-delay", 0);
288 panel_info.reset_delay = fdtdec_get_int(blob, node,
289 "samsung,reset-delay", 0);
290 panel_info.interface_mode = fdtdec_get_int(blob, node,
291 "samsung,interface-mode", 0);
292 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
293 "samsung,mipi-enabled", 0);
294 panel_info.dp_enabled = fdtdec_get_int(blob, node,
295 "samsung,dp-enabled", 0);
296 panel_info.cs_setup = fdtdec_get_int(blob, node,
297 "samsung,cs-setup", 0);
298 panel_info.wr_setup = fdtdec_get_int(blob, node,
299 "samsung,wr-setup", 0);
300 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
301 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
302
303 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
304 if (panel_info.logo_on) {
305 panel_info.logo_width = fdtdec_get_int(blob, node,
306 "samsung,logo-width", 0);
307 panel_info.logo_height = fdtdec_get_int(blob, node,
308 "samsung,logo-height", 0);
309 panel_info.logo_addr = fdtdec_get_int(blob, node,
310 "samsung,logo-addr", 0);
311 }
312
313 panel_info.rgb_mode = fdtdec_get_int(blob, node,
314 "samsung,rgb-mode", 0);
315 panel_info.pclk_name = fdtdec_get_int(blob, node,
316 "samsung,pclk-name", 0);
317 panel_info.sclk_div = fdtdec_get_int(blob, node,
318 "samsung,sclk-div", 0);
319 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
320 "samsung,dual-lcd-enabled", 0);
321
322 return 0;
323}
324#endif
325
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000326void lcd_ctrl_init(void *lcdbase)
327{
328 set_system_display_ctrl();
329 set_lcd_clk();
330
Ajay Kumarc23f3152013-02-21 23:53:01 +0000331#ifdef CONFIG_OF_CONTROL
332 if (exynos_fimd_parse_dt(gd->fdt_blob))
333 debug("Can't get proper panel info\n");
334#endif
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000335 /* initialize parameters which is specific to panel. */
336 init_panel_info(&panel_info);
337
338 panel_width = panel_info.vl_width;
339 panel_height = panel_info.vl_height;
340
341 exynos_lcd_init_mem(lcdbase, &panel_info);
342
343 exynos_lcd_init(&panel_info);
344}
345
346void lcd_enable(void)
347{
Donghwa Lee90464972012-05-09 19:23:46 +0000348 if (panel_info.logo_on) {
349 memset(lcd_base, 0, panel_width * panel_height *
350 (NBITS(panel_info.vl_bpix) >> 3));
Ajay Kumare4660e02013-01-13 23:32:16 +0000351#ifdef CONFIG_CMD_BMP
Donghwa Lee90464972012-05-09 19:23:46 +0000352 draw_logo();
Ajay Kumare4660e02013-01-13 23:32:16 +0000353#endif
Donghwa Lee90464972012-05-09 19:23:46 +0000354 }
355
Donghwa Lee6d4339f2012-04-05 19:36:17 +0000356 lcd_panel_on(&panel_info);
357}
358
359/* dummy function */
360void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
361{
362 return;
363}