]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/video/exynos_fb.c
Merge branch 'master' of git://git.denx.de/u-boot-spi
[karo-tx-uboot.git] / drivers / video / exynos_fb.c
1 /*
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  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <config.h>
11 #include <common.h>
12 #include <lcd.h>
13 #include <fdtdec.h>
14 #include <libfdt.h>
15 #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>
20 #include <asm/arch/dp_info.h>
21 #include <asm/arch/system.h>
22 #include <asm-generic/errno.h>
23
24 #include "exynos_fb.h"
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 static unsigned int panel_width, panel_height;
29
30 /*
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
37 vidinfo_t panel_info  = {
38         .vl_col = LCD_XRES,
39         .vl_row = LCD_YRES,
40         .vl_bpix = LCD_COLOR16,
41 };
42 #endif
43
44 static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
45 {
46         unsigned long palette_size;
47         unsigned int fb_size;
48
49         fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
50
51         palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
52
53         exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
54                         (unsigned long)fb_size, palette_size);
55 }
56
57 static void exynos_lcd_init(vidinfo_t *vid)
58 {
59         exynos_fimd_lcd_init(vid);
60
61         /* Enable flushing after LCD writes if requested */
62         lcd_set_flush_dcache(1);
63 }
64
65 void __exynos_cfg_lcd_gpio(void)
66 {
67 }
68 void exynos_cfg_lcd_gpio(void)
69         __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
70
71 void __exynos_backlight_on(unsigned int onoff)
72 {
73 }
74 void exynos_backlight_on(unsigned int onoff)
75         __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
76
77 void __exynos_reset_lcd(void)
78 {
79 }
80 void exynos_reset_lcd(void)
81         __attribute__((weak, alias("__exynos_reset_lcd")));
82
83 void __exynos_lcd_power_on(void)
84 {
85 }
86 void exynos_lcd_power_on(void)
87         __attribute__((weak, alias("__exynos_lcd_power_on")));
88
89 void __exynos_cfg_ldo(void)
90 {
91 }
92 void exynos_cfg_ldo(void)
93         __attribute__((weak, alias("__exynos_cfg_ldo")));
94
95 void __exynos_enable_ldo(unsigned int onoff)
96 {
97 }
98 void exynos_enable_ldo(unsigned int onoff)
99         __attribute__((weak, alias("__exynos_enable_ldo")));
100
101 void __exynos_backlight_reset(void)
102 {
103 }
104 void exynos_backlight_reset(void)
105         __attribute__((weak, alias("__exynos_backlight_reset")));
106
107 static void lcd_panel_on(vidinfo_t *vid)
108 {
109         udelay(vid->init_delay);
110
111         exynos_backlight_reset();
112
113         exynos_cfg_lcd_gpio();
114
115         exynos_lcd_power_on();
116
117         udelay(vid->power_on_delay);
118
119         if (vid->dp_enabled)
120                 exynos_init_dp();
121
122         exynos_reset_lcd();
123
124         udelay(vid->reset_delay);
125
126         exynos_backlight_on(1);
127
128         exynos_cfg_ldo();
129
130         exynos_enable_ldo(1);
131
132         if (vid->mipi_enabled)
133                 exynos_mipi_dsi_init();
134 }
135
136 #ifdef CONFIG_OF_CONTROL
137 int exynos_fimd_parse_dt(const void *blob)
138 {
139         unsigned int node;
140         node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
141         if (node <= 0) {
142                 debug("exynos_fb: Can't get device node for fimd\n");
143                 return -ENODEV;
144         }
145
146         panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
147         if (panel_info.vl_col == 0) {
148                 debug("Can't get XRES\n");
149                 return -ENXIO;
150         }
151
152         panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
153         if (panel_info.vl_row == 0) {
154                 debug("Can't get YRES\n");
155                 return -ENXIO;
156         }
157
158         panel_info.vl_width = fdtdec_get_int(blob, node,
159                                                 "samsung,vl-width", 0);
160
161         panel_info.vl_height = fdtdec_get_int(blob, node,
162                                                 "samsung,vl-height", 0);
163
164         panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
165         if (panel_info.vl_freq == 0) {
166                 debug("Can't get refresh rate\n");
167                 return -ENXIO;
168         }
169
170         if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
171                 panel_info.vl_clkp = CONFIG_SYS_LOW;
172
173         if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
174                 panel_info.vl_oep = CONFIG_SYS_LOW;
175
176         if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
177                 panel_info.vl_hsp = CONFIG_SYS_LOW;
178
179         if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
180                 panel_info.vl_vsp = CONFIG_SYS_LOW;
181
182         if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
183                 panel_info.vl_dp = CONFIG_SYS_LOW;
184
185         panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
186         if (panel_info.vl_bpix == 0) {
187                 debug("Can't get bits per pixel\n");
188                 return -ENXIO;
189         }
190
191         panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
192         if (panel_info.vl_hspw == 0) {
193                 debug("Can't get hsync width\n");
194                 return -ENXIO;
195         }
196
197         panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
198         if (panel_info.vl_hfpd == 0) {
199                 debug("Can't get right margin\n");
200                 return -ENXIO;
201         }
202
203         panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
204                                                         "samsung,vl-hbpd", 0);
205         if (panel_info.vl_hbpd == 0) {
206                 debug("Can't get left margin\n");
207                 return -ENXIO;
208         }
209
210         panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
211                                                         "samsung,vl-vspw", 0);
212         if (panel_info.vl_vspw == 0) {
213                 debug("Can't get vsync width\n");
214                 return -ENXIO;
215         }
216
217         panel_info.vl_vfpd = fdtdec_get_int(blob, node,
218                                                         "samsung,vl-vfpd", 0);
219         if (panel_info.vl_vfpd == 0) {
220                 debug("Can't get lower margin\n");
221                 return -ENXIO;
222         }
223
224         panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
225         if (panel_info.vl_vbpd == 0) {
226                 debug("Can't get upper margin\n");
227                 return -ENXIO;
228         }
229
230         panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
231                                                 "samsung,vl-cmd-allow-len", 0);
232
233         panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
234         panel_info.init_delay = fdtdec_get_int(blob, node,
235                                                 "samsung,init-delay", 0);
236         panel_info.power_on_delay = fdtdec_get_int(blob, node,
237                                                 "samsung,power-on-delay", 0);
238         panel_info.reset_delay = fdtdec_get_int(blob, node,
239                                                 "samsung,reset-delay", 0);
240         panel_info.interface_mode = fdtdec_get_int(blob, node,
241                                                 "samsung,interface-mode", 0);
242         panel_info.mipi_enabled = fdtdec_get_int(blob, node,
243                                                 "samsung,mipi-enabled", 0);
244         panel_info.dp_enabled = fdtdec_get_int(blob, node,
245                                                 "samsung,dp-enabled", 0);
246         panel_info.cs_setup = fdtdec_get_int(blob, node,
247                                                 "samsung,cs-setup", 0);
248         panel_info.wr_setup = fdtdec_get_int(blob, node,
249                                                 "samsung,wr-setup", 0);
250         panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
251         panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
252
253         panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
254         if (panel_info.logo_on) {
255                 panel_info.logo_width = fdtdec_get_int(blob, node,
256                                                 "samsung,logo-width", 0);
257                 panel_info.logo_height = fdtdec_get_int(blob, node,
258                                                 "samsung,logo-height", 0);
259                 panel_info.logo_addr = fdtdec_get_int(blob, node,
260                                                 "samsung,logo-addr", 0);
261         }
262
263         panel_info.rgb_mode = fdtdec_get_int(blob, node,
264                                                 "samsung,rgb-mode", 0);
265         panel_info.pclk_name = fdtdec_get_int(blob, node,
266                                                 "samsung,pclk-name", 0);
267         panel_info.sclk_div = fdtdec_get_int(blob, node,
268                                                 "samsung,sclk-div", 0);
269         panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
270                                                 "samsung,dual-lcd-enabled", 0);
271
272         return 0;
273 }
274 #endif
275
276 void lcd_ctrl_init(void *lcdbase)
277 {
278         set_system_display_ctrl();
279         set_lcd_clk();
280
281 #ifdef CONFIG_OF_CONTROL
282         if (exynos_fimd_parse_dt(gd->fdt_blob))
283                 debug("Can't get proper panel info\n");
284 #else
285         /* initialize parameters which is specific to panel. */
286         init_panel_info(&panel_info);
287 #endif
288         panel_width = panel_info.vl_width;
289         panel_height = panel_info.vl_height;
290
291         exynos_lcd_init_mem(lcdbase, &panel_info);
292
293         exynos_lcd_init(&panel_info);
294 }
295
296 void lcd_enable(void)
297 {
298         if (panel_info.logo_on) {
299                 memset((void *) gd->fb_base, 0, panel_width * panel_height *
300                                 (NBITS(panel_info.vl_bpix) >> 3));
301         }
302
303         lcd_panel_on(&panel_info);
304 }
305
306 /* dummy function */
307 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
308 {
309         return;
310 }