blob: 16a489b88dc299423bc90a12ae17abfca55b8ac5 [file] [log] [blame]
Stefan Bosch5ed5ad42020-07-10 19:07:36 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2016 Nexell Co., Ltd.
4 *
5 * Author: junghyun, kim <jhkim@nexell.co.kr>
6 */
7
8#include <config.h>
Stefan Bosch5ed5ad42020-07-10 19:07:36 +02009#include <errno.h>
10#include <log.h>
11#include <asm/arch/reset.h>
12#include <asm/arch/nexell.h>
13#include <asm/arch/display.h>
14
15#include "soc/s5pxx18_soc_disptop.h"
16#include "soc/s5pxx18_soc_dpc.h"
17#include "soc/s5pxx18_soc_mlc.h"
18
19#define MLC_LAYER_RGB_0 0 /* number of RGB layer 0 */
20#define MLC_LAYER_RGB_1 1 /* number of RGB layer 1 */
21#define MLC_LAYER_VIDEO 3 /* number of Video layer: 3 = VIDEO */
22
23#define __io_address(a) (void *)(uintptr_t)(a)
24
25void dp_control_init(int module)
26{
27 void *base;
28
29 /* top */
30 base = __io_address(nx_disp_top_get_physical_address());
31 nx_disp_top_set_base_address(base);
32
33 /* control */
34 base = __io_address(nx_dpc_get_physical_address(module));
35 nx_dpc_set_base_address(module, base);
36
37 /* top controller */
38 nx_rstcon_setrst(RESET_ID_DISP_TOP, RSTCON_ASSERT);
39 nx_rstcon_setrst(RESET_ID_DISP_TOP, RSTCON_NEGATE);
40
41 /* display controller */
42 nx_rstcon_setrst(RESET_ID_DISPLAY, RSTCON_ASSERT);
43 nx_rstcon_setrst(RESET_ID_DISPLAY, RSTCON_NEGATE);
44
45 nx_dpc_set_clock_pclk_mode(module, nx_pclkmode_always);
46}
47
48int dp_control_setup(int module,
49 struct dp_sync_info *sync, struct dp_ctrl_info *ctrl)
50{
51 unsigned int out_format;
52 unsigned int delay_mask;
53 int rgb_pvd = 0, hsync_cp1 = 7, vsync_fram = 7, de_cp2 = 7;
54 int v_vso = 1, v_veo = 1, e_vso = 1, e_veo = 1;
55
56 int interlace = 0;
57 int invert_field;
58 int swap_rb;
59 unsigned int yc_order;
60 int vck_select;
61 int vclk_invert;
62 int emb_sync;
63
64 enum nx_dpc_dither r_dither, g_dither, b_dither;
65 int rgb_mode = 0;
66
67 if (NULL == sync || NULL == ctrl) {
68 debug("error, dp.%d not set sync or pad clock info !!!\n",
69 module);
70 return -EINVAL;
71 }
72
73 out_format = ctrl->out_format;
74 delay_mask = ctrl->delay_mask;
75 interlace = sync->interlace;
76 invert_field = ctrl->invert_field;
77 swap_rb = ctrl->swap_RB;
78 yc_order = ctrl->yc_order;
79 vck_select = ctrl->vck_select;
80 vclk_invert = ctrl->clk_inv_lv0 | ctrl->clk_inv_lv1;
81 emb_sync = (out_format == DPC_FORMAT_CCIR656 ? 1 : 0);
82
83 /* set delay mask */
84 if (delay_mask & DP_SYNC_DELAY_RGB_PVD)
85 rgb_pvd = ctrl->d_rgb_pvd;
86 if (delay_mask & DP_SYNC_DELAY_HSYNC_CP1)
87 hsync_cp1 = ctrl->d_hsync_cp1;
88 if (delay_mask & DP_SYNC_DELAY_VSYNC_FRAM)
89 vsync_fram = ctrl->d_vsync_fram;
90 if (delay_mask & DP_SYNC_DELAY_DE_CP)
91 de_cp2 = ctrl->d_de_cp2;
92
93 if (ctrl->vs_start_offset != 0 ||
94 ctrl->vs_end_offset != 0 ||
95 ctrl->ev_start_offset != 0 || ctrl->ev_end_offset != 0) {
96 v_vso = ctrl->vs_start_offset;
97 v_veo = ctrl->vs_end_offset;
98 e_vso = ctrl->ev_start_offset;
99 e_veo = ctrl->ev_end_offset;
100 }
101
102 if (nx_dpc_format_rgb555 == out_format ||
103 nx_dpc_format_mrgb555a == out_format ||
104 nx_dpc_format_mrgb555b == out_format) {
105 r_dither = nx_dpc_dither_5bit;
106 g_dither = nx_dpc_dither_5bit;
107 b_dither = nx_dpc_dither_5bit;
108 rgb_mode = 1;
109 } else if (nx_dpc_format_rgb565 == out_format ||
110 nx_dpc_format_mrgb565 == out_format) {
111 r_dither = nx_dpc_dither_5bit;
112 b_dither = nx_dpc_dither_5bit;
113 g_dither = nx_dpc_dither_6bit, rgb_mode = 1;
114 } else if ((nx_dpc_format_rgb666 == out_format) ||
115 (nx_dpc_format_mrgb666 == out_format)) {
116 r_dither = nx_dpc_dither_6bit;
117 g_dither = nx_dpc_dither_6bit;
118 b_dither = nx_dpc_dither_6bit;
119 rgb_mode = 1;
120 } else {
121 r_dither = nx_dpc_dither_bypass;
122 g_dither = nx_dpc_dither_bypass;
123 b_dither = nx_dpc_dither_bypass;
124 rgb_mode = 1;
125 }
126
127 /* CLKGEN0/1 */
128 nx_dpc_set_clock_source(module, 0, ctrl->clk_src_lv0 == 3 ?
129 6 : ctrl->clk_src_lv0);
130 nx_dpc_set_clock_divisor(module, 0, ctrl->clk_div_lv0);
131 nx_dpc_set_clock_source(module, 1, ctrl->clk_src_lv1);
132 nx_dpc_set_clock_divisor(module, 1, ctrl->clk_div_lv1);
133 nx_dpc_set_clock_out_delay(module, 0, ctrl->clk_delay_lv0);
134 nx_dpc_set_clock_out_delay(module, 1, ctrl->clk_delay_lv1);
135
136 /* LCD out */
137 nx_dpc_set_mode(module, out_format, interlace, invert_field,
138 rgb_mode, swap_rb, yc_order, emb_sync, emb_sync,
139 vck_select, vclk_invert, 0);
140 nx_dpc_set_hsync(module, sync->h_active_len, sync->h_sync_width,
141 sync->h_front_porch, sync->h_back_porch,
142 sync->h_sync_invert);
143 nx_dpc_set_vsync(module, sync->v_active_len, sync->v_sync_width,
144 sync->v_front_porch, sync->v_back_porch,
145 sync->v_sync_invert, sync->v_active_len,
146 sync->v_sync_width, sync->v_front_porch,
147 sync->v_back_porch);
148 nx_dpc_set_vsync_offset(module, v_vso, v_veo, e_vso, e_veo);
149 nx_dpc_set_delay(module, rgb_pvd, hsync_cp1, vsync_fram, de_cp2);
150 nx_dpc_set_dither(module, r_dither, g_dither, b_dither);
151
152 if (IS_ENABLED(CONFIG_MACH_S5P6818)) {
153 /* Set TFT_CLKCTRL (offset : 1030h)
154 * Field name : DPC0_CLKCTRL, DPC1_CLKCRL
155 * Default value : clk_inv_lv0/1 = 0 : PADCLK_InvCLK
156 * Invert case : clk_inv_lv0/1 = 1 : PADCLK_CLK
157 */
158 if (module == 0 && ctrl->clk_inv_lv0)
159 nx_disp_top_set_padclock(padmux_primary_mlc,
160 padclk_clk);
161 if (module == 1 && ctrl->clk_inv_lv1)
162 nx_disp_top_set_padclock(padmux_secondary_mlc,
163 padclk_clk);
164 }
165
166 debug("%s: dp.%d x:%4d, hf:%3d, hb:%3d, hs:%3d, hi=%d\n",
167 __func__, module, sync->h_active_len, sync->h_front_porch,
168 sync->h_back_porch, sync->h_sync_width, sync->h_sync_invert);
169 debug("%s: dp.%d y:%4d, vf:%3d, vb:%3d, vs:%3d, vi=%d\n",
170 __func__, module, sync->v_active_len, sync->v_front_porch,
171 sync->v_back_porch, sync->v_sync_width, sync->h_sync_invert);
172 debug("%s: dp.%d ck.0:%d:%d:%d, ck.1:%d:%d:%d\n",
173 __func__, module,
174 ctrl->clk_src_lv0, ctrl->clk_div_lv0, ctrl->clk_inv_lv0,
175 ctrl->clk_src_lv1, ctrl->clk_div_lv1, ctrl->clk_inv_lv1);
176 debug("%s: dp.%d vs:%d, ve:%d, es:%d, ee:%d\n",
177 __func__, module, v_vso, v_veo, e_vso, e_veo);
178 debug("%s: dp.%d delay RGB:%d, hs:%d, vs:%d, de:%d, fmt:0x%x\n",
179 __func__, module, rgb_pvd, hsync_cp1, vsync_fram, de_cp2,
180 out_format);
181
182 return 0;
183}
184
185void dp_control_enable(int module, int on)
186{
187 debug("%s: dp.%d top %s\n", __func__, module, on ? "ON" : "OFF");
188
189 nx_dpc_set_dpc_enable(module, on);
190 nx_dpc_set_clock_divisor_enable(module, on);
191}
192
193void dp_plane_init(int module)
194{
195 void *base = __io_address(nx_mlc_get_physical_address(module));
196
197 nx_mlc_set_base_address(module, base);
198 nx_mlc_set_clock_pclk_mode(module, nx_pclkmode_always);
199 nx_mlc_set_clock_bclk_mode(module, nx_bclkmode_always);
200}
201
202int dp_plane_screen_setup(int module, struct dp_plane_top *top)
203{
204 int width = top->screen_width;
205 int height = top->screen_height;
206 int interlace = top->interlace;
207 int video_prior = top->video_prior;
208 unsigned int bg_color = top->back_color;
209
210 /* MLC TOP layer */
211 nx_mlc_set_screen_size(module, width, height);
212 nx_mlc_set_layer_priority(module, video_prior);
213 nx_mlc_set_background(module, bg_color);
214 nx_mlc_set_field_enable(module, interlace);
215 nx_mlc_set_rgblayer_gama_table_power_mode(module, 0, 0, 0);
216 nx_mlc_set_rgblayer_gama_table_sleep_mode(module, 1, 1, 1);
217 nx_mlc_set_rgblayer_gamma_enable(module, 0);
218 nx_mlc_set_dither_enable_when_using_gamma(module, 0);
219 nx_mlc_set_gamma_priority(module, 0);
220 nx_mlc_set_top_power_mode(module, 1);
221 nx_mlc_set_top_sleep_mode(module, 0);
222
223 debug("%s: dp.%d screen %dx%d, %s, priority:%d, bg:0x%x\n",
224 __func__, module, width, height,
225 interlace ? "Interlace" : "Progressive",
226 video_prior, bg_color);
227
228 return 0;
229}
230
231void dp_plane_screen_enable(int module, int on)
232{
233 /* enable top screen */
234 nx_mlc_set_mlc_enable(module, on);
235 nx_mlc_set_top_dirty_flag(module);
236 debug("%s: dp.%d top %s\n", __func__, module, on ? "ON" : "OFF");
237}
238
239int dp_plane_layer_setup(int module, struct dp_plane_info *plane)
240{
241 int sx = plane->left;
242 int sy = plane->top;
243 int ex = sx + plane->width - 1;
244 int ey = sy + plane->height - 1;
245 int pixel_byte = plane->pixel_byte;
246 int mem_lock_size = 16; /* fix mem lock size */
247 int layer = plane->layer;
248 unsigned int format = plane->format;
249
250 if (!plane->enable)
251 return -EINVAL;
252
253 /* MLC layer */
254 nx_mlc_set_lock_size(module, layer, mem_lock_size);
255 nx_mlc_set_alpha_blending(module, layer, 0, 15);
256 nx_mlc_set_transparency(module, layer, 0, 0);
257 nx_mlc_set_color_inversion(module, layer, 0, 0);
258 nx_mlc_set_rgblayer_invalid_position(module, layer, 0, 0, 0, 0, 0, 0);
259 nx_mlc_set_rgblayer_invalid_position(module, layer, 1, 0, 0, 0, 0, 0);
260 nx_mlc_set_format_rgb(module, layer, format);
261 nx_mlc_set_position(module, layer, sx, sy, ex, ey);
262 nx_mlc_set_rgblayer_stride(module, layer, pixel_byte,
263 plane->width * pixel_byte);
264 nx_mlc_set_rgblayer_address(module, layer, plane->fb_base);
265
266 debug("%s: dp.%d.%d %d * %d, %dbpp, fmt:0x%x\n",
267 __func__, module, layer, plane->width, plane->height,
268 pixel_byte * 8, format);
269 debug("%s: b:0x%x, l:%d, t:%d, r:%d, b:%d, hs:%d, vs:%d\n",
270 __func__, plane->fb_base, sx, sy, ex, ey,
271 plane->width * pixel_byte, pixel_byte);
272
273 return 0;
274}
275
276int dp_plane_set_enable(int module, int layer, int on)
277{
278 int hl, hc;
279 int vl, vc;
280
281 debug("%s: dp.%d.%d %s:%s\n",
282 __func__, module, layer,
283 layer == MLC_LAYER_VIDEO ? "Video" : "RGB",
284 on ? "ON" : "OFF");
285
286 if (layer != MLC_LAYER_VIDEO) {
287 nx_mlc_set_layer_enable(module, layer, on);
288 nx_mlc_set_dirty_flag(module, layer);
289 return 0;
290 }
291
292 /* video layer */
293 if (on) {
294 nx_mlc_set_video_layer_line_buffer_power_mode(module, 1);
295 nx_mlc_set_video_layer_line_buffer_sleep_mode(module, 0);
296 nx_mlc_set_layer_enable(module, layer, 1);
297 nx_mlc_set_dirty_flag(module, layer);
298 } else {
299 nx_mlc_set_layer_enable(module, layer, 0);
300 nx_mlc_set_dirty_flag(module, layer);
301 nx_mlc_get_video_layer_scale_filter(module,
302 &hl, &hc, &vl, &vc);
303 if (hl || hc || vl || vc)
304 nx_mlc_set_video_layer_scale_filter(module, 0, 0, 0, 0);
305 nx_mlc_set_video_layer_line_buffer_power_mode(module, 0);
306 nx_mlc_set_video_layer_line_buffer_sleep_mode(module, 1);
307 nx_mlc_set_dirty_flag(module, layer);
308 }
309
310 return 0;
311}
312
313void dp_plane_layer_enable(int module,
314 struct dp_plane_info *plane, int on)
315{
316 dp_plane_set_enable(module, plane->layer, on);
317}
318
319int dp_plane_set_address(int module, int layer, unsigned int address)
320{
321 nx_mlc_set_rgblayer_address(module, layer, address);
322 nx_mlc_set_dirty_flag(module, layer);
323
324 return 0;
325}
326
327int dp_plane_wait_vsync(int module, int layer, int fps)
328{
329 int cnt = 0;
330
331 if (fps == 0)
332 return (int)nx_mlc_get_dirty_flag(module, layer);
333
334 while (fps > cnt++) {
335 while (nx_mlc_get_dirty_flag(module, layer))
336 ;
337 nx_mlc_set_dirty_flag(module, layer);
338 }
339 return 0;
340}