forked from torvalds/linux
/
disp_hdmi.c
343 lines (284 loc) · 8.71 KB
/
disp_hdmi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
* Copyright (C) 2007-2012 Allwinner Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include "disp_display_i.h"
#include "disp_hdmi.h"
#include "disp_display.h"
#include "disp_event.h"
#include "disp_de.h"
#include "disp_tv.h"
#include "disp_lcd.h"
#include "disp_clk.h"
__s32 Display_Hdmi_Init(void)
{
hdmi_clk_init();
gdisp.screen[0].hdmi_mode = DISP_TV_MOD_720P_50HZ;
gdisp.screen[1].hdmi_mode = DISP_TV_MOD_720P_50HZ;
return DIS_SUCCESS;
}
__s32 Display_Hdmi_Exit(void)
{
hdmi_clk_exit();
return DIS_SUCCESS;
}
__s32 BSP_disp_hdmi_open(__u32 sel)
{
if (!(gdisp.screen[sel].status & HDMI_ON)) {
__disp_tv_mode_t tv_mod = gdisp.screen[sel].hdmi_mode;
if (!gdisp.init_para.hdmi_wait_edid) {
pr_err("hdmi funcs NULL, hdmi module not loaded?\n");
return -1;
}
hdmi_clk_on();
if (gdisp.screen[sel].use_edid &&
gdisp.init_para.hdmi_wait_edid() == 0) {
tv_mod = DISP_TV_MODE_EDID;
gdisp.init_para.hdmi_set_mode(tv_mod);
gdisp.screen[sel].hdmi_mode = tv_mod;
}
lcdc_clk_on(sel);
image_clk_on(sel);
/*
* set image normal channel start bit, because every
* de_clk_off( ) will reset this bit
*/
Image_open(sel);
disp_clk_cfg(sel, DISP_OUTPUT_TYPE_HDMI, tv_mod);
#ifdef CONFIG_ARCH_SUN4I
BSP_disp_set_output_csc(sel, DISP_OUTPUT_TYPE_HDMI);
#else
BSP_disp_set_output_csc(sel, DISP_OUTPUT_TYPE_HDMI,
gdisp.screen[sel].
iep_status & DRC_USED);
#endif
DE_BE_set_display_size(sel, tv_mode_to_width(tv_mod),
tv_mode_to_height(tv_mod));
DE_BE_Output_Select(sel, sel);
#ifdef CONFIG_ARCH_SUN5I
DE_BE_Set_Outitl_enable(sel, Disp_get_screen_scan_mode(tv_mod));
{
int scaler_index;
for (scaler_index = 0; scaler_index < 2; scaler_index++)
if ((gdisp.scaler[scaler_index].status &
SCALER_USED) &&
(gdisp.scaler[scaler_index].screen_index ==
sel)) {
/* interlace output */
if (Disp_get_screen_scan_mode(tv_mod) ==
1)
Scaler_Set_Outitl(scaler_index,
TRUE);
else
Scaler_Set_Outitl(scaler_index,
FALSE);
}
}
#endif /* CONFIG_ARCH_SUN5I */
TCON1_set_hdmi_mode(sel, tv_mod);
TCON1_open(sel);
if (gdisp.init_para.Hdmi_open)
gdisp.init_para.Hdmi_open();
else {
DE_WRN("Hdmi_open is NULL\n");
return -1;
}
Disp_Switch_Dram_Mode(DISP_OUTPUT_TYPE_HDMI, tv_mod);
gdisp.screen[sel].b_out_interlace =
Disp_get_screen_scan_mode(tv_mod);
gdisp.screen[sel].status |= HDMI_ON;
gdisp.screen[sel].lcdc_status |= LCDC_TCON1_USED;
gdisp.screen[sel].output_type = DISP_OUTPUT_TYPE_HDMI;
Display_set_fb_timing(sel);
}
return DIS_SUCCESS;
}
__s32 BSP_disp_hdmi_close(__u32 sel)
{
if (gdisp.screen[sel].status & HDMI_ON) {
if (gdisp.init_para.Hdmi_close) {
gdisp.init_para.Hdmi_close();
} else {
DE_WRN("Hdmi_close is NULL\n");
return -1;
}
Image_close(sel);
TCON1_close(sel);
image_clk_off(sel);
lcdc_clk_off(sel);
hdmi_clk_off();
#ifdef CONFIG_ARCH_SUN5I
DE_BE_Set_Outitl_enable(sel, FALSE);
{
int scaler_index;
for (scaler_index = 0; scaler_index < 2; scaler_index++)
if ((gdisp.scaler[scaler_index].status &
SCALER_USED) &&
(gdisp.scaler[scaler_index].screen_index ==
sel))
Scaler_Set_Outitl(scaler_index, FALSE);
}
#endif /* CONFIG_ARCH_SUN5I */
gdisp.screen[sel].b_out_interlace = 0;
gdisp.screen[sel].lcdc_status &= ~LCDC_TCON1_USED;
gdisp.screen[sel].status &= ~HDMI_ON;
gdisp.screen[sel].output_type = DISP_OUTPUT_TYPE_NONE;
gdisp.screen[sel].pll_use_status &=
(gdisp.screen[sel].pll_use_status == VIDEO_PLL0_USED) ?
~VIDEO_PLL0_USED : ~VIDEO_PLL1_USED;
}
return DIS_SUCCESS;
}
__s32 BSP_disp_hdmi_set_mode(__u32 sel, __disp_tv_mode_t mode)
{
if (mode >= DISP_TV_MODE_NUM) {
DE_WRN("unsupported hdmi mode:%d in BSP_disp_hdmi_set_mode\n",
mode);
return DIS_FAIL;
}
if (gdisp.init_para.hdmi_set_mode) {
gdisp.init_para.hdmi_set_mode(mode);
} else {
DE_WRN("hdmi_set_mode is NULL\n");
return -1;
}
gdisp.screen[sel].hdmi_mode = mode;
gdisp.screen[sel].output_type = DISP_OUTPUT_TYPE_HDMI;
return DIS_SUCCESS;
}
void videomode_to_video_timing(struct __disp_video_timing *video_timing,
const struct fb_videomode *mode)
{
memset(video_timing, 0, sizeof(struct __disp_video_timing));
video_timing->VIC = 511;
video_timing->PCLK = (PICOS2KHZ(mode->pixclock) * 1000);
video_timing->AVI_PR = 0;
video_timing->INPUTX = mode->xres;
video_timing->INPUTY = mode->yres;
video_timing->HT = mode->xres + mode->left_margin +
mode->right_margin + mode->hsync_len;
video_timing->HBP = mode->left_margin + mode->hsync_len;
video_timing->HFP = mode->right_margin;
video_timing->HPSW = mode->hsync_len;
video_timing->VT = mode->yres + mode->upper_margin +
mode->lower_margin + mode->vsync_len;
video_timing->VBP = mode->upper_margin + mode->vsync_len;
video_timing->VFP = mode->lower_margin;
video_timing->VPSW = mode->vsync_len;
if (mode->vmode & FB_VMODE_INTERLACED)
video_timing->I = true;
if (mode->sync & FB_SYNC_HOR_HIGH_ACT)
video_timing->HSYNC = true;
if (mode->sync & FB_SYNC_VERT_HIGH_ACT)
video_timing->VSYNC = true;
}
__s32 BSP_disp_set_videomode(__u32 sel, const struct fb_videomode *mode)
{
struct __disp_video_timing *old_video_timing =
kzalloc(sizeof(struct __disp_video_timing), GFP_KERNEL);
struct __disp_video_timing *new_video_timing =
kzalloc(sizeof(struct __disp_video_timing), GFP_KERNEL);
__disp_tv_mode_t hdmi_mode = gdisp.screen[sel].hdmi_mode;
if (!old_video_timing && !new_video_timing)
return DIS_FAIL;
if (!gdisp.init_para.hdmi_set_videomode)
return DIS_FAIL;
if (gdisp.init_para.hdmi_get_video_timing(hdmi_mode,
old_video_timing) != 0)
return DIS_FAIL;
videomode_to_video_timing(new_video_timing, mode);
if (gdisp.init_para.hdmi_set_videomode(new_video_timing) != 0)
return DIS_FAIL;
if (disp_clk_cfg(sel, DISP_OUTPUT_TYPE_HDMI, hdmi_mode) != 0)
goto failure;
if (DE_BE_set_display_size(sel, new_video_timing->INPUTX,
new_video_timing->INPUTY) != 0)
goto failure;
if (TCON1_set_hdmi_mode(sel, hdmi_mode) != 0)
goto failure;
gdisp.screen[sel].b_out_interlace = new_video_timing->I;
kfree(old_video_timing);
kfree(new_video_timing);
return DIS_SUCCESS;
failure:
gdisp.init_para.hdmi_set_videomode(old_video_timing);
disp_clk_cfg(sel, DISP_OUTPUT_TYPE_HDMI, hdmi_mode);
DE_BE_set_display_size(sel, old_video_timing->INPUTX,
old_video_timing->INPUTY);
TCON1_set_hdmi_mode(sel, hdmi_mode);
kfree(old_video_timing);
kfree(new_video_timing);
return DIS_FAIL;
}
__s32 BSP_disp_hdmi_get_mode(__u32 sel)
{
return gdisp.screen[sel].hdmi_mode;
}
__s32 BSP_disp_hdmi_check_support_mode(__u32 sel, __u8 mode)
{
__s32 ret = 0;
if (gdisp.init_para.hdmi_mode_support) {
ret = gdisp.init_para.hdmi_mode_support(mode);
} else {
DE_WRN("hdmi_mode_support is NULL\n");
return -1;
}
return ret;
}
__s32 BSP_disp_hdmi_get_hpd_status(__u32 sel)
{
__s32 ret = 0;
if (gdisp.init_para.hdmi_get_HPD_status) {
ret = gdisp.init_para.hdmi_get_HPD_status();
} else {
DE_WRN("hdmi_get_HPD_status is NULL\n");
return -1;
}
return ret;
}
__s32 BSP_disp_hdmi_set_src(__u32 sel, __disp_lcdc_src_t src)
{
switch (src) {
case DISP_LCDC_SRC_DE_CH1:
TCON1_select_src(sel, LCDC_SRC_DE1);
break;
case DISP_LCDC_SRC_DE_CH2:
TCON1_select_src(sel, LCDC_SRC_DE2);
break;
case DISP_LCDC_SRC_BLUT:
TCON1_select_src(sel, LCDC_SRC_BLUE);
break;
default:
DE_WRN("not supported lcdc src:%d in BSP_disp_tv_set_src\n",
src);
return DIS_NOT_SUPPORT;
}
return DIS_SUCCESS;
}
__s32 BSP_disp_set_hdmi_func(__disp_hdmi_func *func)
{
gdisp.init_para.hdmi_wait_edid = func->hdmi_wait_edid;
gdisp.init_para.Hdmi_open = func->Hdmi_open;
gdisp.init_para.Hdmi_close = func->Hdmi_close;
gdisp.init_para.hdmi_set_mode = func->hdmi_set_mode;
gdisp.init_para.hdmi_set_videomode = func->hdmi_set_videomode;
gdisp.init_para.hdmi_mode_support = func->hdmi_mode_support;
gdisp.init_para.hdmi_get_video_timing = func->hdmi_get_video_timing;
gdisp.init_para.hdmi_get_HPD_status = func->hdmi_get_HPD_status;
gdisp.init_para.hdmi_set_pll = func->hdmi_set_pll;
return DIS_SUCCESS;
}