blob: a3acdcc2d9b0dbd7e17dd1ddb944c607d3eb4754 [file] [log] [blame]
Donghwa Lee0112fed2012-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 Denkbd8ec7e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
Donghwa Lee0112fed2012-04-05 19:36:17 +00008 */
9
10#include <config.h>
11#include <common.h>
12#include <lcd.h>
Ajay Kumarebbace32013-02-21 23:53:01 +000013#include <fdtdec.h>
14#include <libfdt.h>
Donghwa Lee0112fed2012-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 Leebc72aeb2012-07-02 01:16:08 +000020#include <asm/arch/dp_info.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000021#include <asm/arch/system.h>
Ajay Kumar39ea08b2015-03-04 19:05:26 +053022#include <asm/gpio.h>
Ajay Kumarebbace32013-02-21 23:53:01 +000023#include <asm-generic/errno.h>
Donghwa Lee0112fed2012-04-05 19:36:17 +000024
25#include "exynos_fb.h"
26
Ajay Kumarebbace32013-02-21 23:53:01 +000027DECLARE_GLOBAL_DATA_PTR;
28
Donghwa Lee0112fed2012-04-05 19:36:17 +000029static unsigned int panel_width, panel_height;
30
Simon Glass6d275592016-02-21 21:08:40 -070031struct vidinfo panel_info = {
Ajay Kumar11763482014-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 Kumarebbace32013-02-21 23:53:01 +000037};
Ajay Kumarebbace32013-02-21 23:53:01 +000038
Nikita Kiryanovec3685d2015-02-03 13:32:21 +020039ushort *configuration_get_cmap(void)
40{
41#if defined(CONFIG_LCD_LOGO)
42 return bmp_logo_palette;
43#else
44 return NULL;
45#endif
46}
47
Simon Glass4d022cc2016-02-21 21:08:41 -070048static void exynos_lcd_init(struct vidinfo *vid, ulong lcd_base)
Donghwa Lee0112fed2012-04-05 19:36:17 +000049{
Simon Glass4d022cc2016-02-21 21:08:41 -070050 exynos_fimd_lcd_init(vid, lcd_base);
Ɓukasz Majewski43905f42013-01-08 03:48:40 +000051
52 /* Enable flushing after LCD writes if requested */
53 lcd_set_flush_dcache(1);
Donghwa Lee0112fed2012-04-05 19:36:17 +000054}
55
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020056__weak void exynos_cfg_lcd_gpio(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000057{
58}
Ajay Kumar41022a12013-02-21 23:52:57 +000059
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020060__weak void exynos_backlight_on(unsigned int onoff)
Ajay Kumar41022a12013-02-21 23:52:57 +000061{
62}
Ajay Kumar41022a12013-02-21 23:52:57 +000063
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020064__weak void exynos_reset_lcd(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000065{
66}
Ajay Kumar41022a12013-02-21 23:52:57 +000067
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020068__weak void exynos_lcd_power_on(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000069{
70}
Ajay Kumar41022a12013-02-21 23:52:57 +000071
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020072__weak void exynos_cfg_ldo(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000073{
74}
Ajay Kumar41022a12013-02-21 23:52:57 +000075
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020076__weak void exynos_enable_ldo(unsigned int onoff)
Ajay Kumar41022a12013-02-21 23:52:57 +000077{
78}
Ajay Kumar41022a12013-02-21 23:52:57 +000079
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020080__weak void exynos_backlight_reset(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000081{
82}
Ajay Kumar41022a12013-02-21 23:52:57 +000083
Simon Glass6d275592016-02-21 21:08:40 -070084__weak int exynos_lcd_misc_init(struct vidinfo *vid)
Piotr Wilczek386fd022014-03-07 14:59:40 +010085{
86 return 0;
87}
Piotr Wilczek386fd022014-03-07 14:59:40 +010088
Simon Glass6d275592016-02-21 21:08:40 -070089static void lcd_panel_on(struct vidinfo *vid)
Donghwa Lee0112fed2012-04-05 19:36:17 +000090{
Ajay Kumar39ea08b2015-03-04 19:05:26 +053091 struct gpio_desc pwm_out_gpio;
92 struct gpio_desc bl_en_gpio;
93 unsigned int node;
94
Donghwa Lee0112fed2012-04-05 19:36:17 +000095 udelay(vid->init_delay);
96
Ajay Kumar41022a12013-02-21 23:52:57 +000097 exynos_backlight_reset();
Donghwa Lee0112fed2012-04-05 19:36:17 +000098
Ajay Kumar41022a12013-02-21 23:52:57 +000099 exynos_cfg_lcd_gpio();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000100
Ajay Kumar41022a12013-02-21 23:52:57 +0000101 exynos_lcd_power_on();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000102
103 udelay(vid->power_on_delay);
104
Donghwa Leebc72aeb2012-07-02 01:16:08 +0000105 if (vid->dp_enabled)
106 exynos_init_dp();
107
Ajay Kumar41022a12013-02-21 23:52:57 +0000108 exynos_reset_lcd();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000109
Ajay Kumar41022a12013-02-21 23:52:57 +0000110 udelay(vid->reset_delay);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000111
Ajay Kumar41022a12013-02-21 23:52:57 +0000112 exynos_backlight_on(1);
113
Ajay Kumar39ea08b2015-03-04 19:05:26 +0530114 node = fdtdec_next_compatible(gd->fdt_blob, 0,
115 COMPAT_SAMSUNG_EXYNOS_FIMD);
116 if (node <= 0) {
117 debug("FIMD: Can't get device node for FIMD\n");
118 return;
119 }
120 gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,pwm-out-gpio",
121 0, &pwm_out_gpio,
122 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
123
124 gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,bl-en-gpio", 0,
125 &bl_en_gpio,
126 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
127
Ajay Kumar41022a12013-02-21 23:52:57 +0000128 exynos_cfg_ldo();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000129
Ajay Kumar41022a12013-02-21 23:52:57 +0000130 exynos_enable_ldo(1);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000131
132 if (vid->mipi_enabled)
133 exynos_mipi_dsi_init();
134}
Ajay Kumarebbace32013-02-21 23:53:01 +0000135
Ajay Kumar11763482014-09-05 16:53:30 +0530136int exynos_lcd_early_init(const void *blob)
Ajay Kumarebbace32013-02-21 23:53:01 +0000137{
138 unsigned int node;
139 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
140 if (node <= 0) {
141 debug("exynos_fb: Can't get device node for fimd\n");
142 return -ENODEV;
143 }
144
145 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
146 if (panel_info.vl_col == 0) {
147 debug("Can't get XRES\n");
148 return -ENXIO;
149 }
150
151 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
152 if (panel_info.vl_row == 0) {
153 debug("Can't get YRES\n");
154 return -ENXIO;
155 }
156
157 panel_info.vl_width = fdtdec_get_int(blob, node,
158 "samsung,vl-width", 0);
159
160 panel_info.vl_height = fdtdec_get_int(blob, node,
161 "samsung,vl-height", 0);
162
163 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
164 if (panel_info.vl_freq == 0) {
165 debug("Can't get refresh rate\n");
166 return -ENXIO;
167 }
168
169 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
170 panel_info.vl_clkp = CONFIG_SYS_LOW;
171
172 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
173 panel_info.vl_oep = CONFIG_SYS_LOW;
174
175 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
176 panel_info.vl_hsp = CONFIG_SYS_LOW;
177
178 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
179 panel_info.vl_vsp = CONFIG_SYS_LOW;
180
181 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
182 panel_info.vl_dp = CONFIG_SYS_LOW;
183
184 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
185 if (panel_info.vl_bpix == 0) {
186 debug("Can't get bits per pixel\n");
187 return -ENXIO;
188 }
189
190 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
191 if (panel_info.vl_hspw == 0) {
192 debug("Can't get hsync width\n");
193 return -ENXIO;
194 }
195
196 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
197 if (panel_info.vl_hfpd == 0) {
198 debug("Can't get right margin\n");
199 return -ENXIO;
200 }
201
202 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
203 "samsung,vl-hbpd", 0);
204 if (panel_info.vl_hbpd == 0) {
205 debug("Can't get left margin\n");
206 return -ENXIO;
207 }
208
209 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
210 "samsung,vl-vspw", 0);
211 if (panel_info.vl_vspw == 0) {
212 debug("Can't get vsync width\n");
213 return -ENXIO;
214 }
215
216 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
217 "samsung,vl-vfpd", 0);
218 if (panel_info.vl_vfpd == 0) {
219 debug("Can't get lower margin\n");
220 return -ENXIO;
221 }
222
223 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
224 if (panel_info.vl_vbpd == 0) {
225 debug("Can't get upper margin\n");
226 return -ENXIO;
227 }
228
229 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
230 "samsung,vl-cmd-allow-len", 0);
231
232 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
233 panel_info.init_delay = fdtdec_get_int(blob, node,
234 "samsung,init-delay", 0);
235 panel_info.power_on_delay = fdtdec_get_int(blob, node,
236 "samsung,power-on-delay", 0);
237 panel_info.reset_delay = fdtdec_get_int(blob, node,
238 "samsung,reset-delay", 0);
239 panel_info.interface_mode = fdtdec_get_int(blob, node,
240 "samsung,interface-mode", 0);
241 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
242 "samsung,mipi-enabled", 0);
243 panel_info.dp_enabled = fdtdec_get_int(blob, node,
244 "samsung,dp-enabled", 0);
245 panel_info.cs_setup = fdtdec_get_int(blob, node,
246 "samsung,cs-setup", 0);
247 panel_info.wr_setup = fdtdec_get_int(blob, node,
248 "samsung,wr-setup", 0);
249 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
250 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
251
252 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
253 if (panel_info.logo_on) {
254 panel_info.logo_width = fdtdec_get_int(blob, node,
255 "samsung,logo-width", 0);
256 panel_info.logo_height = fdtdec_get_int(blob, node,
257 "samsung,logo-height", 0);
258 panel_info.logo_addr = fdtdec_get_int(blob, node,
259 "samsung,logo-addr", 0);
260 }
261
262 panel_info.rgb_mode = fdtdec_get_int(blob, node,
263 "samsung,rgb-mode", 0);
264 panel_info.pclk_name = fdtdec_get_int(blob, node,
265 "samsung,pclk-name", 0);
266 panel_info.sclk_div = fdtdec_get_int(blob, node,
267 "samsung,sclk-div", 0);
268 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
269 "samsung,dual-lcd-enabled", 0);
270
271 return 0;
272}
Donghwa Lee0112fed2012-04-05 19:36:17 +0000273
274void lcd_ctrl_init(void *lcdbase)
275{
276 set_system_display_ctrl();
277 set_lcd_clk();
278
Piotr Wilczek386fd022014-03-07 14:59:40 +0100279#ifdef CONFIG_EXYNOS_MIPI_DSIM
280 exynos_init_dsim_platform_data(&panel_info);
281#endif
282 exynos_lcd_misc_init(&panel_info);
Piotr Wilczek386fd022014-03-07 14:59:40 +0100283
Donghwa Lee0112fed2012-04-05 19:36:17 +0000284 panel_width = panel_info.vl_width;
285 panel_height = panel_info.vl_height;
286
Simon Glass4d022cc2016-02-21 21:08:41 -0700287 exynos_lcd_init(&panel_info, (ulong)lcdbase);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000288}
289
290void lcd_enable(void)
291{
Donghwa Lee37980dd2012-05-09 19:23:46 +0000292 if (panel_info.logo_on) {
Jeroen Hofstee881c4ec2013-01-22 10:44:12 +0000293 memset((void *) gd->fb_base, 0, panel_width * panel_height *
Donghwa Lee37980dd2012-05-09 19:23:46 +0000294 (NBITS(panel_info.vl_bpix) >> 3));
Donghwa Lee37980dd2012-05-09 19:23:46 +0000295 }
296
Donghwa Lee0112fed2012-04-05 19:36:17 +0000297 lcd_panel_on(&panel_info);
298}
299
300/* dummy function */
301void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
302{
303 return;
304}