blob: 90d203822f82236ab98cb48361198f577dcded4d [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 Glass6d275592016-02-21 21:08:40 -070048static void exynos_lcd_init_mem(void *lcdbase, struct vidinfo *vid)
Donghwa Lee0112fed2012-04-05 19:36:17 +000049{
50 unsigned long palette_size;
51 unsigned int fb_size;
52
Donghwa Lee2386f452012-04-23 15:37:05 +000053 fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
Donghwa Lee0112fed2012-04-05 19:36:17 +000054
Donghwa Lee0112fed2012-04-05 19:36:17 +000055 palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
56
Jeroen Hofstee881c4ec2013-01-22 10:44:12 +000057 exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
Donghwa Lee0112fed2012-04-05 19:36:17 +000058 (unsigned long)fb_size, palette_size);
59}
60
Simon Glass6d275592016-02-21 21:08:40 -070061static void exynos_lcd_init(struct vidinfo *vid)
Donghwa Lee0112fed2012-04-05 19:36:17 +000062{
63 exynos_fimd_lcd_init(vid);
Ɓukasz Majewski43905f42013-01-08 03:48:40 +000064
65 /* Enable flushing after LCD writes if requested */
66 lcd_set_flush_dcache(1);
Donghwa Lee0112fed2012-04-05 19:36:17 +000067}
68
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020069__weak void exynos_cfg_lcd_gpio(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000070{
71}
Ajay Kumar41022a12013-02-21 23:52:57 +000072
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020073__weak void exynos_backlight_on(unsigned int onoff)
Ajay Kumar41022a12013-02-21 23:52:57 +000074{
75}
Ajay Kumar41022a12013-02-21 23:52:57 +000076
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020077__weak void exynos_reset_lcd(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000078{
79}
Ajay Kumar41022a12013-02-21 23:52:57 +000080
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020081__weak void exynos_lcd_power_on(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000082{
83}
Ajay Kumar41022a12013-02-21 23:52:57 +000084
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020085__weak void exynos_cfg_ldo(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000086{
87}
Ajay Kumar41022a12013-02-21 23:52:57 +000088
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020089__weak void exynos_enable_ldo(unsigned int onoff)
Ajay Kumar41022a12013-02-21 23:52:57 +000090{
91}
Ajay Kumar41022a12013-02-21 23:52:57 +000092
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +020093__weak void exynos_backlight_reset(void)
Ajay Kumar41022a12013-02-21 23:52:57 +000094{
95}
Ajay Kumar41022a12013-02-21 23:52:57 +000096
Simon Glass6d275592016-02-21 21:08:40 -070097__weak int exynos_lcd_misc_init(struct vidinfo *vid)
Piotr Wilczek386fd022014-03-07 14:59:40 +010098{
99 return 0;
100}
Piotr Wilczek386fd022014-03-07 14:59:40 +0100101
Simon Glass6d275592016-02-21 21:08:40 -0700102static void lcd_panel_on(struct vidinfo *vid)
Donghwa Lee0112fed2012-04-05 19:36:17 +0000103{
Ajay Kumar39ea08b2015-03-04 19:05:26 +0530104 struct gpio_desc pwm_out_gpio;
105 struct gpio_desc bl_en_gpio;
106 unsigned int node;
107
Donghwa Lee0112fed2012-04-05 19:36:17 +0000108 udelay(vid->init_delay);
109
Ajay Kumar41022a12013-02-21 23:52:57 +0000110 exynos_backlight_reset();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000111
Ajay Kumar41022a12013-02-21 23:52:57 +0000112 exynos_cfg_lcd_gpio();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000113
Ajay Kumar41022a12013-02-21 23:52:57 +0000114 exynos_lcd_power_on();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000115
116 udelay(vid->power_on_delay);
117
Donghwa Leebc72aeb2012-07-02 01:16:08 +0000118 if (vid->dp_enabled)
119 exynos_init_dp();
120
Ajay Kumar41022a12013-02-21 23:52:57 +0000121 exynos_reset_lcd();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000122
Ajay Kumar41022a12013-02-21 23:52:57 +0000123 udelay(vid->reset_delay);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000124
Ajay Kumar41022a12013-02-21 23:52:57 +0000125 exynos_backlight_on(1);
126
Ajay Kumar39ea08b2015-03-04 19:05:26 +0530127 node = fdtdec_next_compatible(gd->fdt_blob, 0,
128 COMPAT_SAMSUNG_EXYNOS_FIMD);
129 if (node <= 0) {
130 debug("FIMD: Can't get device node for FIMD\n");
131 return;
132 }
133 gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,pwm-out-gpio",
134 0, &pwm_out_gpio,
135 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
136
137 gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,bl-en-gpio", 0,
138 &bl_en_gpio,
139 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
140
Ajay Kumar41022a12013-02-21 23:52:57 +0000141 exynos_cfg_ldo();
Donghwa Lee0112fed2012-04-05 19:36:17 +0000142
Ajay Kumar41022a12013-02-21 23:52:57 +0000143 exynos_enable_ldo(1);
Donghwa Lee0112fed2012-04-05 19:36:17 +0000144
145 if (vid->mipi_enabled)
146 exynos_mipi_dsi_init();
147}
Ajay Kumarebbace32013-02-21 23:53:01 +0000148
Ajay Kumar11763482014-09-05 16:53:30 +0530149int exynos_lcd_early_init(const void *blob)
Ajay Kumarebbace32013-02-21 23:53:01 +0000150{
151 unsigned int node;
152 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
153 if (node <= 0) {
154 debug("exynos_fb: Can't get device node for fimd\n");
155 return -ENODEV;
156 }
157
158 panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
159 if (panel_info.vl_col == 0) {
160 debug("Can't get XRES\n");
161 return -ENXIO;
162 }
163
164 panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
165 if (panel_info.vl_row == 0) {
166 debug("Can't get YRES\n");
167 return -ENXIO;
168 }
169
170 panel_info.vl_width = fdtdec_get_int(blob, node,
171 "samsung,vl-width", 0);
172
173 panel_info.vl_height = fdtdec_get_int(blob, node,
174 "samsung,vl-height", 0);
175
176 panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
177 if (panel_info.vl_freq == 0) {
178 debug("Can't get refresh rate\n");
179 return -ENXIO;
180 }
181
182 if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
183 panel_info.vl_clkp = CONFIG_SYS_LOW;
184
185 if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
186 panel_info.vl_oep = CONFIG_SYS_LOW;
187
188 if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
189 panel_info.vl_hsp = CONFIG_SYS_LOW;
190
191 if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
192 panel_info.vl_vsp = CONFIG_SYS_LOW;
193
194 if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
195 panel_info.vl_dp = CONFIG_SYS_LOW;
196
197 panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
198 if (panel_info.vl_bpix == 0) {
199 debug("Can't get bits per pixel\n");
200 return -ENXIO;
201 }
202
203 panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
204 if (panel_info.vl_hspw == 0) {
205 debug("Can't get hsync width\n");
206 return -ENXIO;
207 }
208
209 panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
210 if (panel_info.vl_hfpd == 0) {
211 debug("Can't get right margin\n");
212 return -ENXIO;
213 }
214
215 panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
216 "samsung,vl-hbpd", 0);
217 if (panel_info.vl_hbpd == 0) {
218 debug("Can't get left margin\n");
219 return -ENXIO;
220 }
221
222 panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
223 "samsung,vl-vspw", 0);
224 if (panel_info.vl_vspw == 0) {
225 debug("Can't get vsync width\n");
226 return -ENXIO;
227 }
228
229 panel_info.vl_vfpd = fdtdec_get_int(blob, node,
230 "samsung,vl-vfpd", 0);
231 if (panel_info.vl_vfpd == 0) {
232 debug("Can't get lower margin\n");
233 return -ENXIO;
234 }
235
236 panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
237 if (panel_info.vl_vbpd == 0) {
238 debug("Can't get upper margin\n");
239 return -ENXIO;
240 }
241
242 panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
243 "samsung,vl-cmd-allow-len", 0);
244
245 panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
246 panel_info.init_delay = fdtdec_get_int(blob, node,
247 "samsung,init-delay", 0);
248 panel_info.power_on_delay = fdtdec_get_int(blob, node,
249 "samsung,power-on-delay", 0);
250 panel_info.reset_delay = fdtdec_get_int(blob, node,
251 "samsung,reset-delay", 0);
252 panel_info.interface_mode = fdtdec_get_int(blob, node,
253 "samsung,interface-mode", 0);
254 panel_info.mipi_enabled = fdtdec_get_int(blob, node,
255 "samsung,mipi-enabled", 0);
256 panel_info.dp_enabled = fdtdec_get_int(blob, node,
257 "samsung,dp-enabled", 0);
258 panel_info.cs_setup = fdtdec_get_int(blob, node,
259 "samsung,cs-setup", 0);
260 panel_info.wr_setup = fdtdec_get_int(blob, node,
261 "samsung,wr-setup", 0);
262 panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
263 panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
264
265 panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
266 if (panel_info.logo_on) {
267 panel_info.logo_width = fdtdec_get_int(blob, node,
268 "samsung,logo-width", 0);
269 panel_info.logo_height = fdtdec_get_int(blob, node,
270 "samsung,logo-height", 0);
271 panel_info.logo_addr = fdtdec_get_int(blob, node,
272 "samsung,logo-addr", 0);
273 }
274
275 panel_info.rgb_mode = fdtdec_get_int(blob, node,
276 "samsung,rgb-mode", 0);
277 panel_info.pclk_name = fdtdec_get_int(blob, node,
278 "samsung,pclk-name", 0);
279 panel_info.sclk_div = fdtdec_get_int(blob, node,
280 "samsung,sclk-div", 0);
281 panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
282 "samsung,dual-lcd-enabled", 0);
283
284 return 0;
285}
Donghwa Lee0112fed2012-04-05 19:36:17 +0000286
287void lcd_ctrl_init(void *lcdbase)
288{
289 set_system_display_ctrl();
290 set_lcd_clk();
291
Piotr Wilczek386fd022014-03-07 14:59:40 +0100292#ifdef CONFIG_EXYNOS_MIPI_DSIM
293 exynos_init_dsim_platform_data(&panel_info);
294#endif
295 exynos_lcd_misc_init(&panel_info);
Piotr Wilczek386fd022014-03-07 14:59:40 +0100296
Donghwa Lee0112fed2012-04-05 19:36:17 +0000297 panel_width = panel_info.vl_width;
298 panel_height = panel_info.vl_height;
299
300 exynos_lcd_init_mem(lcdbase, &panel_info);
301
302 exynos_lcd_init(&panel_info);
303}
304
305void lcd_enable(void)
306{
Donghwa Lee37980dd2012-05-09 19:23:46 +0000307 if (panel_info.logo_on) {
Jeroen Hofstee881c4ec2013-01-22 10:44:12 +0000308 memset((void *) gd->fb_base, 0, panel_width * panel_height *
Donghwa Lee37980dd2012-05-09 19:23:46 +0000309 (NBITS(panel_info.vl_bpix) >> 3));
Donghwa Lee37980dd2012-05-09 19:23:46 +0000310 }
311
Donghwa Lee0112fed2012-04-05 19:36:17 +0000312 lcd_panel_on(&panel_info);
313}
314
315/* dummy function */
316void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
317{
318 return;
319}