1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (¡§MStar Confidential Information¡¨) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file apiXC_PCMonitor.c
98 /// @brief Scaler API layer Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #ifndef _API_XC_PC_MONITOR_C_
103 #define _API_XC_PC_MONITOR_C_
104
105 //-------------------------------------------------------------------------------------------------
106 // Include Files
107 //-------------------------------------------------------------------------------------------------
108 // Common Definition
109 #define PCMSG(x) //x
110
111 // Common
112 #ifdef MSOS_TYPE_LINUX_KERNEL
113 #include <linux/string.h>
114 #include <asm/div64.h>
115 #else
116 #include <string.h>
117 #define do_div(x,y) ((x)/=(y))
118 #endif
119 #include "MsCommon.h"
120 #include "utopia.h"
121 #include "utopia_dapi.h"
122 // Driver
123 #include "drvXC_IOPort.h"
124 #include "mhal_xc_chip_config.h"
125 #include "xc_hwreg_utility2.h"
126 #include "apiXC.h"
127 #include "drvXC_HDMI_Internal.h"
128 #include "drvXC_HDMI_if.h"
129 #include "mhal_hdmi.h"
130 #include "mhal_ip.h"
131 #include "apiXC_Adc.h"
132 #include "apiXC_Auto.h"
133 #include "drv_sc_display.h"
134 #include "drv_sc_isr.h"
135 #include "apiXC_PCMonitor.h"
136 #include "apiXC_ModeParse.h"
137 #include "mhal_xc_chip_config.h"
138 #include "mvideo_context.h"
139 #include "drv_sc_ip.h"
140 #if (LD_ENABLE==1)
141 #include "mdrv_ld.h"
142 #include "mdrv_ldalgo.h"
143 #endif
144 #include "mdrv_sc_3d.h"
145 #include "drv_sc_menuload.h"
146 #include "drvXC_ADC_Internal.h"
147 #include "mhal_sc.h"
148 #if FRC_INSIDE
149 #include "mdrv_frc.h"
150 #include "mhal_frc.h"
151 #endif
152 #include "XC_private.h"
153 #include "apiXC_v2.h"
154 #include "drv_sc_scaling.h"
155 #include "apiXC_PCMonitor_v2.h"
156
157 //-------------------------------------------------------------------------------------------------
158 // Driver Compiler Options
159 //-------------------------------------------------------------------------------------------------
160
161 //-------------------------------------------------------------------------------------------------
162 // Local Defines
163 //-------------------------------------------------------------------------------------------------
164
165 #define PC_POLLING_COUNTER 30 // (30/TIMER_PERIOD), unit ms
166
167 #define MD_TIMING_SOG_DETECT 20
168 #if 1//(INPUT_HDMI_VIDEO_COUNT > 0)
169 #if 1
170 // Change these count value just for HDMI fast to recover video,
171 // But have to delay 200mSec to reduce flash blue screen when plug-in/out HDMI fast,
172 #define MD_TIMING_STABLE_COUNT (MDrv_XC_PCMonitor_GetStableCounter(pInstance, eWindow))
173 #define MD_TIMING_NOSYNC_COUNT (MDrv_XC_PCMonitor_GetNoSyncCounter(pInstance, eWindow))
174 #else
175 #define MD_TIMING_STABLE_COUNT (((IsSrcTypeHDMI(psPCMONITOR_HK_Info[eWindow]->eCurrentSrc)?120:25))
176 #define MD_TIMING_NOSYNC_COUNT (((IsSrcTypeHDMI(psPCMONITOR_HK_Info[eWindow]->eCurrentSrc)?80:40))
177 #endif
178 #else
179 #define MD_TIMING_STABLE_COUNT 25 // input timing stable counter
180 #define MD_TIMING_NOSYNC_COUNT 40
181 #endif
182
183 #define TIMING_CHANGE_DEBOUNCE_FOR_STR 3
184 //-------------------------------------------------------------------------------------------------
185 // Local Structurs
186 //-------------------------------------------------------------------------------------------------
187
188 //-------------------------------------------------------------------------------------------------
189 // Global Variables
190 //-------------------------------------------------------------------------------------------------
191
192 //-------------------------------------------------------------------------------------------------
193 // Local Variables
194 //-------------------------------------------------------------------------------------------------
195
196 //-------------------------------------------------------------------------------------------------
197 // Debug Functions
198 //-------------------------------------------------------------------------------------------------
199
200 //-------------------------------------------------------------------------------------------------
201 // Local Functions
202 //-------------------------------------------------------------------------------------------------
203
204 //*************************************************************************
205 //Function name: _MApi_XC_PCMonitor_SetSyncStatusFlag
206 //Passing parameter: MS_U8 u8TempSyncStatus: b0: VSync polarity
207 // b1: HSync polarity
208 // b2: Hsync active
209 // b3: Vsync active
210 //Return parameter: none
211 //Description: Set signal sync status flags
212 //*************************************************************************
_MApi_XC_PCMonitor_SetSyncStatusFlag(void * pInstance,MS_U8 u8TempSyncStatus,SCALER_WIN eWindow)213 static void _MApi_XC_PCMonitor_SetSyncStatusFlag (void *pInstance, MS_U8 u8TempSyncStatus, SCALER_WIN eWindow)
214 {
215 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
216 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
217 stPCMonitorInfo.u8SyncStatus = u8TempSyncStatus;
218 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
219 }
220
221 //*************************************************************************
222 //------------------------------ Warning ----------------------------------
223 //Attention: !!!!!!------ Don't add UI variable or unneeded code in this file
224 //
225 // Don't modify this procedure !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
226 //*************************************************************************
227 //*************************************************************************
228 //Function name: _MApi_XC_PCMonitor_DetectSync
229 //Passing parameter: none
230 //Return parameter: MS_BOOL: true: sync loss false: sync active
231 //Description: Get signal sync status, true for sync loss, false for sync active
232 //*************************************************************************
_MApi_XC_PCMonitor_DetectSync(void * pInstance,INPUT_SOURCE_TYPE_t eCurrentSrc,SCALER_WIN eWindow)233 static MS_BOOL _MApi_XC_PCMonitor_DetectSync (void *pInstance, INPUT_SOURCE_TYPE_t eCurrentSrc , SCALER_WIN eWindow )
234 {
235 PCMSG(static MS_BOOL bSyncLoss = TRUE);
236
237 MS_BOOL bResult = FALSE;
238 XC_IP_SYNC_STATUS sXC_Sync_Status;
239 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
240 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
241 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
242 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
243 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
244 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
245 memset(&sXC_Sync_Status, 0, sizeof(XC_IP_SYNC_STATUS));
246 _XC_ENTRY(pInstance);
247 MDrv_XC_GetSyncStatus(pInstance, eCurrentSrc, &sXC_Sync_Status, eWindow);
248 _XC_RETURN(pInstance);
249 if ( sXC_Sync_Status.u8SyncStatus & XC_MD_SYNC_LOSS ) // check no signal
250 {
251 PCMSG(if(!bSyncLoss) printf("XC_MD_SYNC_LOSS 0x%x\n", sXC_Sync_Status.u8SyncStatus); bSyncLoss = TRUE);
252
253 if( IsSrcTypeVga(eCurrentSrc) || IsSrcTypeYPbPr(eCurrentSrc))
254 {
255 MDrv_ADC_ISOG_SetDetectMode(pInstance, E_ADC_ISOG_STANDBY_MODE);
256 }
257
258 if (MDrv_XC_GetVGASogEn(pInstance)) // Daten FixMe -> Please refine VGA SOG flow
259 {
260 if( IsSrcTypeVga(eCurrentSrc)&&
261 ((stPCMonitorInfo.ucInputTimingStableCounter % MD_TIMING_SOG_DETECT)==0))
262 {
263 Hal_SC_ip_sog_detect(pInstance); // toggle analog input and detect next time
264 }
265 }
266
267 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
268 {
269 if( IsSrcTypeYPbPr(eCurrentSrc) )
270 {
271 MApi_XC_EuroHdtvHandler(pInstance, eWindow);
272 }
273 else
274 {
275 MDrv_XC_HWAuto_SyncSeparate(pInstance, eWindow);
276 }
277 }
278 }
279 else // have signal
280 {
281
282 if (MDrv_XC_GetVGASogEn(pInstance)) // Daten FixMe -> Please refine VGA SOG flow
283 {
284 _XC_ENTRY(pInstance);
285 if( IsSrcTypeVga(eCurrentSrc)&&
286 ((stPCMonitorInfo.ucInputTimingStableCounter % MD_TIMING_SOG_DETECT)==0)
287 && (SC_R2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK01_02_L,0x70)!=0x70)
288 && (stPCMonitorInfo.ucInputTimingStableCounter <=0x14))
289 {
290 Hal_SC_ip_sog_detect(pInstance); // toggle analog input and detect next time
291 }
292 _XC_RETURN(pInstance);
293 }
294
295 bResult = TRUE;
296
297 if( IsSrcTypeVga(eCurrentSrc) || IsSrcTypeYPbPr(eCurrentSrc))
298 {
299 MDrv_ADC_ISOG_SetDetectMode(pInstance, E_ADC_ISOG_NORMAL_MODE);
300 }
301
302 PCMSG(if(bSyncLoss) printf("MD_SYNC_DETECT 0x%x\n", sXC_Sync_Status.u8SyncStatus); bSyncLoss = FALSE);
303 }
304
305 if ( bResult ) // neet to update flag
306 {
307 _MApi_XC_PCMonitor_SetSyncStatusFlag(pInstance, sXC_Sync_Status.u8SyncStatus, eWindow);
308 } // set global sync status flag
309
310 return bResult;
311 }
312
313 // If IP1 detect P mode, but IPM set I mode for 3D FramePacking I 60/50hz.
314 // It is possible IPM detect wrong field from IP2. Only for A5/A3 serial scaler.
315 // Affected chips
316 // Old Patch Method: Force interlace
317 // A3/A5/A6/Agate U01/Eagle U01/J2
318 // New Patch Method: Register REG_SC_BK12_05[10] to let HW auto force i
319 // Agate U02/Edison/Eagle U02/Emerald/Kaiser/Macaw12
320 //
_MApi_XC_PCMonitor_FPi_Patch(void * pInstance,SCALER_WIN eWindow)321 static void _MApi_XC_PCMonitor_FPi_Patch(void *pInstance, SCALER_WIN eWindow)
322 {
323 MS_WINDOW_TYPE sWin;
324 memset(&sWin, 0 , sizeof(MS_WINDOW_TYPE));
325
326 if (MDrv_SC_Get_DE_Bypass_Mode(pInstance, eWindow) == FALSE)
327 {
328 _XC_ENTRY(pInstance);
329 MDrv_XC_GetDEWindow(pInstance, &sWin, eWindow);
330 _XC_RETURN(pInstance);
331 }
332 else
333 {
334 MDrv_XC_GetDEWidthHeightInDEByPassMode(pInstance, &sWin.width, &sWin.height, eWindow);
335 }
336
337 // Check DE for framepacking I
338 if ( ( sWin.height > ( DOUBLEHD_1080X2I_VSIZE - 5) )
339 && ( sWin.height < ( DOUBLEHD_1080X2I_VSIZE + 5) )
340 && ( sWin.width < ( DOUBLEHD_1080X2I_HSIZE + 5) )
341 && ( sWin.width > ( DOUBLEHD_1080X2I_HSIZE - 5) ) )
342 {
343 MDrv_SC_ForceInterlaceInPMode(pInstance, ENABLE,eWindow);
344 MsOS_DelayTask(150);
345 }
346 }
347
_MApi_XC_PCMonitor_InitRegInTimingChange(void * pInstance,SCALER_WIN eWindow)348 static void _MApi_XC_PCMonitor_InitRegInTimingChange(void *pInstance, SCALER_WIN eWindow)
349 {
350 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
351 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
352 if(IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc) || IsSrcTypeDVI(stPCMonitorInfo.eCurrentSrc))
353 {
354 //ToDo HDMI
355 Hal_HDMI_audio_output(DISABLE);
356 if ( MDrv_SC_GetInterlaceInPModeStatus(pInstance, eWindow) )
357 {
358 MDrv_SC_ForceInterlaceInPMode(pInstance, DISABLE,eWindow);
359 }
360 }
361 _XC_ENTRY(pInstance);
362 if(eWindow == MAIN_WINDOW)
363 {
364 MDrv_XC_SoftwareReset(pInstance, REST_IP_F2, eWindow);
365 }
366 else
367 {
368 MDrv_XC_SoftwareReset(pInstance, REST_IP_F1, eWindow);
369 }
370 _XC_RETURN(pInstance);
371 // 20081226 - DVI+HDCP snow noise patch - start ...
372 //Note: Don't use rest function after HPD Hi/Low or it will cause snow image in a while.
373 // MDrv_XC_ADC_reset(REST_DVI|REST_HDCP|REST_HDMI); // Bright20080918
374 // 20081226 - DVI+HDCP snow noise patch - end ...
375 MApi_XC_TimingChangeInit(pInstance, eWindow);
376
377 if(IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc))
378 MApi_XC_VsyncPolarityDetectMode(pInstance, ENABLE, eWindow);
379 else
380 MApi_XC_VsyncPolarityDetectMode(pInstance, DISABLE, eWindow);
381
382 }
383
384 //*************************************************************************
385 //------------------------------ Warning ----------------------------------
386 //Attention: !!!!!!------ Don't add UI variable or unneeded code in this file
387 //
388 // Don't modify this procedure !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
389 //*************************************************************************
390 //*************************************************************************
391 //Function name: _MApi_XC_PCMonitor_PrepareForTimingChange
392 //Passing parameter: none
393 //Return parameter: none
394 //Description: This function will pre-set flags and registers for timing change
395 //*************************************************************************
_MApi_XC_PCMonitor_PrepareForTimingChange(void * pInstance,SCALER_WIN eWindow)396 static void _MApi_XC_PCMonitor_PrepareForTimingChange(void *pInstance, SCALER_WIN eWindow)
397 {
398 //MS_U8 u8TurnOffDestination = DISABLE;
399
400 PCMSG(printf("PrepareForTimingChange\n"));
401 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
402 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
403
404 if ( stPCMonitorInfo.bInputTimingStable )
405 {
406 _MApi_XC_PCMonitor_InitRegInTimingChange(pInstance, eWindow);
407
408 }
409
410 if( IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc) || IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc) || IsSrcTypeDVI(stPCMonitorInfo.eCurrentSrc))
411 {
412 MApi_XC_InitRegInTimingChange_Post(pInstance, stPCMonitorInfo.u8SyncStatus, eWindow );
413 }
414
415 // reset input timing stable and wait for timing stable
416 stPCMonitorInfo.bInputTimingStable = FALSE;
417
418 // reset timing stable counter
419 stPCMonitorInfo.ucInputTimingStableCounter = 0;
420
421 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
422 }
423
424 /*
425 void _MApi_XC_PCMonitor_ModeParse(SCALER_WIN eWindow)
426 {
427
428
429 // to match mode, we need these information
430 // H/V freq., Vtt
431 // Sync polarity
432 // Interlaced or Progrssive
433 psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.eSrcType = psPCMONITOR_HK_Info[eWindow]->eCurrentSrc;
434 psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u16HFreqx10 = MApi_XC_CalculateHFreqx10(psPCMONITOR_HK_Info[eWindow]->u16Hperiod);
435 psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u16VFreqx10 = MApi_XC_CalculateVFreqx10(psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u16HFreqx10, psPCMONITOR_HK_Info[eWindow]->u16Vtotal);
436
437 if(psPCMONITOR_HK_Info[eWindow]->u8SyncStatus & XC_MD_INTERLACE_BIT)
438 {
439 psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u16VFreqx10 *=2;
440 }
441
442 psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u16Vtotal = psPCMONITOR_HK_Info[eWindow]->u16Vtotal;
443 psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u8SyncStatus = psPCMONITOR_HK_Info[eWindow]->u8SyncStatus;
444 //psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.eEuroHDTVStatus = EURO_AUS_HDTV_NORMAL;
445 memcpy(&(psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.sDVI_HDMI_DE_Info), &(psPCMONITOR_HK_Info[eWindow]->sDVI_HDMI_DE_Info), sizeof(MS_WINDOW_TYPE));
446
447 #if (INPUT_HDMI_VIDEO_COUNT > 0)
448 // search mode
449 if(IsSrcTypeHDMI(psPCMONITOR_HK_Info[eWindow]->eCurrentSrc))
450 {
451 // check if HDMI or DVI
452 MApi_XC_HDMI_CheckModeChanged(TRUE);
453 }
454 #endif
455
456 psPCMONITOR_HK_Info[eWindow]->eModeParseResult = MApi_XC_ModeParse_SearchMode(&(psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo));
457
458 if(psPCMONITOR_HK_Info[eWindow]->sModeParseInputInfo.u8SyncStatus & XC_MD_USER_MODE_BIT)
459 {
460 // mode parse indicate this is a user mode
461 psPCMONITOR_HK_Info[eWindow]->u8SyncStatus |= XC_MD_USER_MODE_BIT;
462 }
463
464 if(psPCMONITOR_HK_Info[eWindow]->eModeParseResult == XC_MODEPARSE_SUPPORT_MODE)
465 {
466 psPCMONITOR_HK_Info[eWindow]->eCurrentState = E_XC_PCMONITOR_STABLE_SUPPORT_MODE;
467 }
468 else
469 {
470 psPCMONITOR_HK_Info[eWindow]->eCurrentState = E_XC_PCMONITOR_STABLE_UN_SUPPORT;
471 }
472 }
473 */
474
475 //-------------------------------------------------------------------------------------------------
476 // Global Functions
477 //-------------------------------------------------------------------------------------------------
478
479 //*************************************************************************
480 //Function name: MApi_XC_PCMonitor_InvalidTimingDetect
481 //Passing parameter: none
482 //Return parameter: MS_BOOL : timing is valid or not
483 //Description: Detect invalid timing. true: timing invalid false : timing valid
484 //*************************************************************************
MApi_XC_PCMonitor_InvalidTimingDetect_U2(void * pInstance,MS_BOOL bPollingOnly,SCALER_WIN eWindow)485 MS_BOOL MApi_XC_PCMonitor_InvalidTimingDetect_U2( void* pInstance, MS_BOOL bPollingOnly, SCALER_WIN eWindow)
486 {
487 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
488 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
489 MS_BOOL bReturn = FALSE;
490 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
491 _XC_ENTRY(pInstance);
492 bReturn = MDrv_XC_PCMonitor_InvalidTimingDetect(pInstance, bPollingOnly, eWindow);
493 _XC_RETURN(pInstance);
494 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
495 return bReturn;
496 }
497
MApi_XC_PCMonitor_InvalidTimingDetect(MS_BOOL bPollingOnly,SCALER_WIN eWindow)498 MS_BOOL MApi_XC_PCMonitor_InvalidTimingDetect( MS_BOOL bPollingOnly, SCALER_WIN eWindow)
499 {
500 if (pu32XCInst == NULL)
501 {
502 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
503 return FALSE;
504 }
505
506 stXC_PCMONITOR_INVALIDTIMINGDETECT XCArgs;
507 XCArgs.bPollingOnly = bPollingOnly;
508 XCArgs.eWindow = eWindow;
509 XCArgs.bReturnValue = FALSE;
510
511 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_INVALIDTIMINGDETECT, (void*)&XCArgs) != 0)
512 {
513 printf("Obtain XC engine fail\n");
514 return FALSE;
515 }
516 else
517 {
518 return XCArgs.bReturnValue;
519 }
520 }
521
MApi_XC_PCMonitor_Restart_U2(void * pInstance,SCALER_WIN eWindow)522 void MApi_XC_PCMonitor_Restart_U2(void* pInstance, SCALER_WIN eWindow)
523 {
524 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
525 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
526 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
527 MDrv_XC_PCMonitor_Restart(pInstance, eWindow);
528 _XC_ENTRY(pInstance);
529 MDrv_DVI_Accumulator_Monitor();
530 _XC_RETURN(pInstance);
531 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
532 }
533
MApi_XC_PCMonitor_Restart(SCALER_WIN eWindow)534 void MApi_XC_PCMonitor_Restart(SCALER_WIN eWindow)
535 {
536 if (pu32XCInst == NULL)
537 {
538 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
539 return;
540 }
541
542 stXC_PCMONITOR_RESTART XCArgs;
543 XCArgs.eWindow = eWindow;
544
545 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_RESTART, (void*)&XCArgs) != 0)
546 {
547 printf("Obtain XC engine fail\n");
548 return;
549 }
550 else
551 {
552 return;
553 }
554 }
555
MApi_XC_PCMonitor_Init_U2(void * pInstance,MS_U8 u8MaxWindowNum)556 MS_BOOL MApi_XC_PCMonitor_Init_U2(void* pInstance, MS_U8 u8MaxWindowNum)
557 {
558 MS_U8 i;
559 SCALER_WIN eWindow = MAIN_WINDOW;
560 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
561 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
562 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
563 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
564 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
565 // initialize House keeping info
566 MDrv_XC_PCMonitor_Init(pInstance, u8MaxWindowNum);
567 for(i = 0; i < u8MaxWindowNum; i++)
568 {
569 switch(i)
570 {
571 case 0:
572 MDrv_XC_PCMonitor_Restart(pInstance, MAIN_WINDOW);
573 eWindow = MAIN_WINDOW;
574 break;
575
576 case 1:
577 MDrv_XC_PCMonitor_Restart(pInstance, SUB_WINDOW);
578 eWindow = SUB_WINDOW;
579 break;
580
581 default:
582 // un-supported
583 break;
584 }
585
586 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow] = MD_TIMING_STABLE_COUNT;
587 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow] = MD_TIMING_NOSYNC_COUNT;
588 pXCResourcePrivate->stdrvXC_IP.sPCMONITOR_status[eWindow].eCurrentSrc = INPUT_SOURCE_NONE;
589
590 }
591 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_VGA = MD_TIMING_STABLE_COUNT;
592 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_VGA = MD_TIMING_NOSYNC_COUNT;
593 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_YPBPR = MD_TIMING_STABLE_COUNT;
594 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_YPBPR = MD_TIMING_NOSYNC_COUNT;
595 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_HDMI = MD_TIMING_STABLE_COUNT;
596 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_HDMI = MD_TIMING_NOSYNC_COUNT;
597 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
598 return TRUE;
599 }
600
MApi_XC_PCMonitor_Init(MS_U8 u8MaxWindowNum)601 MS_BOOL MApi_XC_PCMonitor_Init(MS_U8 u8MaxWindowNum)
602 {
603 if (pu32XCInst == NULL)
604 {
605 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
606 return FALSE;
607 }
608
609 stXC_PCMONITOR_INIT XCArgs;
610 XCArgs.u8MaxWindowNum = u8MaxWindowNum;
611 XCArgs.bReturnValue = FALSE;
612
613 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_INIT, (void*)&XCArgs) != 0)
614 {
615 printf("Obtain XC engine fail\n");
616 return FALSE;
617 }
618 else
619 {
620 return XCArgs.bReturnValue;
621 }
622 }
623
624
MApi_XC_PCMonitor_SetTimingCount_U2(void * pInstance,MS_U16 u16TimingStableCounter,MS_U16 u16TimingNosyncCounter)625 void MApi_XC_PCMonitor_SetTimingCount_U2(void* pInstance, MS_U16 u16TimingStableCounter, MS_U16 u16TimingNosyncCounter)
626 {
627 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
628 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
629 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
630 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
631 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
632 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_VGA = u16TimingStableCounter;
633 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_VGA = u16TimingNosyncCounter;
634 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_YPBPR = u16TimingStableCounter;
635 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_YPBPR = u16TimingNosyncCounter;
636 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_HDMI = u16TimingStableCounter;
637 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_HDMI = u16TimingNosyncCounter;
638 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
639 }
640
MApi_XC_PCMonitor_SetTimingCount(MS_U16 u16TimingStableCounter,MS_U16 u16TimingNosyncCounter)641 void MApi_XC_PCMonitor_SetTimingCount(MS_U16 u16TimingStableCounter, MS_U16 u16TimingNosyncCounter)
642 {
643 if (pu32XCInst == NULL)
644 {
645 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
646 return;
647 }
648
649 stXC_PCMONITOR_SETTIMINGCOUNT XCArgs;
650 XCArgs.u16TimingStableCounter = u16TimingStableCounter;
651 XCArgs.u16TimingNosyncCounter = u16TimingNosyncCounter;
652
653 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_SETTIMINGCOUNT, (void*)&XCArgs) != 0)
654 {
655 printf("Obtain XC engine fail\n");
656 return;
657 }
658 else
659 {
660 return;
661 }
662 }
663
MApi_XC_PCMonitor_SetTimingCountEx_U2(void * pInstance,INPUT_SOURCE_TYPE_t eCurrentSrc,MS_U16 u16TimingStableCounter,MS_U16 u16TimingNosyncCounter)664 E_APIXC_ReturnValue MApi_XC_PCMonitor_SetTimingCountEx_U2(void* pInstance, INPUT_SOURCE_TYPE_t eCurrentSrc, MS_U16 u16TimingStableCounter, MS_U16 u16TimingNosyncCounter)
665 {
666 E_APIXC_ReturnValue eResult = E_APIXC_RET_FAIL;
667 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
668 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
669 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
670
671 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
672 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
673 if (IsSrcTypeVga(eCurrentSrc))
674 {
675 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_VGA = u16TimingStableCounter;
676 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_VGA = u16TimingNosyncCounter;
677 eResult = E_APIXC_RET_OK;
678 }
679 else if (IsSrcTypeYPbPr(eCurrentSrc))
680 {
681 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_YPBPR= u16TimingStableCounter;
682 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_YPBPR= u16TimingNosyncCounter;
683 eResult = E_APIXC_RET_OK;
684 }
685 else if (IsSrcTypeHDMI(eCurrentSrc) || IsSrcTypeDVI(eCurrentSrc))
686 {
687 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_HDMI= u16TimingStableCounter;
688 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_HDMI= u16TimingNosyncCounter;
689 eResult = E_APIXC_RET_OK;
690 }
691 else
692 {
693 printf("<ATTENTION> Not support this source type for timing count setting ! \n");
694 eResult = E_APIXC_RET_FAIL_INVALID_PARAMETER;
695 }
696 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
697 return eResult;
698 }
699
MApi_XC_PCMonitor_SetTimingCountEx(INPUT_SOURCE_TYPE_t eCurrentSrc,MS_U16 u16TimingStableCounter,MS_U16 u16TimingNosyncCounter)700 E_APIXC_ReturnValue MApi_XC_PCMonitor_SetTimingCountEx(INPUT_SOURCE_TYPE_t eCurrentSrc, MS_U16 u16TimingStableCounter, MS_U16 u16TimingNosyncCounter)
701 {
702 if (pu32XCInst == NULL)
703 {
704 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
705 return E_APIXC_RET_FAIL;
706 }
707
708 stXC_PCMONITOR_SETTIMINGCOUNTEX XCArgs;
709 XCArgs.eCurrentSrc = eCurrentSrc;
710 XCArgs.u16TimingStableCounter = u16TimingStableCounter;
711 XCArgs.u16TimingNosyncCounter = u16TimingNosyncCounter;
712 XCArgs.eReturnValue = E_APIXC_RET_FAIL;
713
714 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_SETTIMINGCOUNTEX, (void*)&XCArgs) != 0)
715 {
716 printf("Obtain XC engine fail\n");
717 return E_APIXC_RET_FAIL;
718 }
719 else
720 {
721 return XCArgs.eReturnValue;
722 }
723 }
724
MApi_XC_PCMonitor_GetCurrentState_U2(void * pInstance,SCALER_WIN eWindow)725 XC_PCMONITOR_STATUS MApi_XC_PCMonitor_GetCurrentState_U2(void* pInstance, SCALER_WIN eWindow)
726 {
727 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
728 XC_PCMONITOR_STATUS eReturn = E_XC_PCMONITOR_STABLE_NOSYNC;
729 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
730 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
731 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
732 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
733 eReturn = stPCMonitorInfo.eCurrentState;
734 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
735 return eReturn;
736 }
737
MApi_XC_PCMonitor_GetCurrentState(SCALER_WIN eWindow)738 XC_PCMONITOR_STATUS MApi_XC_PCMonitor_GetCurrentState(SCALER_WIN eWindow)
739 {
740 if (pu32XCInst == NULL)
741 {
742 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
743 return E_XC_PCMONITOR_STABLE_NOSYNC;
744 }
745
746 stXC_PCMONITOR_GETCURRENTSTATE XCArgs;
747 XCArgs.eWindow = eWindow;
748 XCArgs.eReturnValue = E_XC_PCMONITOR_STABLE_NOSYNC;
749
750 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GETCURRENTSTATE, (void*)&XCArgs) != 0)
751 {
752 printf("Obtain XC engine fail\n");
753 return E_XC_PCMONITOR_STABLE_NOSYNC;
754 }
755 else
756 {
757 return XCArgs.eReturnValue;
758 }
759 }
760
761 //*************************************************************************
762 //------------------------------ Warning ----------------------------------
763 //Attention: !!!!!!------ Don't add UI variable or unneeded code in this file
764 //
765 // Don't modify this procedure !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
766 //*************************************************************************
767 //*************************************************************************
768 //Function name: MApi_XC_PCMonitor_SyncLoss
769 //Passing parameter: none
770 //Return parameter: MS_BOOL: true: sync loss false: sync active
771 //Description: Get signal sync status, true for sync loss, false for sync active
772 //*************************************************************************
MApi_XC_PCMonitor_SyncLoss_U2(void * pInstance,SCALER_WIN eWindow)773 MS_BOOL MApi_XC_PCMonitor_SyncLoss_U2(void* pInstance, SCALER_WIN eWindow)
774 {
775 MS_BOOL bReturn = FALSE;
776 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
777 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
778 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
779 bReturn = MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow);
780 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
781 return bReturn;
782 }
783
MApi_XC_PCMonitor_SyncLoss(SCALER_WIN eWindow)784 MS_BOOL MApi_XC_PCMonitor_SyncLoss(SCALER_WIN eWindow)
785 {
786 if (pu32XCInst == NULL)
787 {
788 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
789 return FALSE;
790 }
791
792 stXC_PCMONITOR_SYNCLOSS XCArgs;
793 XCArgs.eWindow = eWindow;
794 XCArgs.bReturnValue = FALSE;
795
796 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_SYNCLOSS, (void*)&XCArgs) != 0)
797 {
798 printf("Obtain XC engine fail\n");
799 return FALSE;
800 }
801 else
802 {
803 return XCArgs.bReturnValue;
804 }
805 }
806
MApi_XC_PCMonitor_GetSyncStatus_U2(void * pInstance,SCALER_WIN eWindow)807 MS_U8 MApi_XC_PCMonitor_GetSyncStatus_U2(void* pInstance, SCALER_WIN eWindow)
808 {
809 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
810 MS_U8 u8Return = 0;
811 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
812 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
813 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
814 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
815 u8Return = stPCMonitorInfo.u8SyncStatus;
816 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
817 return u8Return;
818 }
819
MApi_XC_PCMonitor_GetSyncStatus(SCALER_WIN eWindow)820 MS_U8 MApi_XC_PCMonitor_GetSyncStatus(SCALER_WIN eWindow)
821 {
822 if (pu32XCInst == NULL)
823 {
824 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
825 return 0;
826 }
827
828 stXC_PCMONITOR_GETSYNCSTATUS XCArgs;
829 XCArgs.eWindow = eWindow;
830 XCArgs.u8ReturnValue = 0;
831
832 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GETSYNCSTATUS, (void*)&XCArgs) != 0)
833 {
834 printf("Obtain XC engine fail\n");
835 return 0;
836 }
837 else
838 {
839 return XCArgs.u8ReturnValue;
840 }
841 }
842
MDrv_XC_PCMonitor_GetVSyncTime(void * pInstance,SCALER_WIN eWindow)843 MS_U8 MDrv_XC_PCMonitor_GetVSyncTime(void *pInstance, SCALER_WIN eWindow)
844 {
845 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
846 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
847
848 if((stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_UNSTABLE) || (stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_STABLE_NOSYNC))
849 {
850 return 0;
851 }
852 else
853 {
854 return stPCMonitorInfo.u16VSyncTime;
855 }
856 }
MApi_XC_PCMonitor_Get_Dvi_Hdmi_De_Info_U2(void * pInstance,SCALER_WIN eWindow,MS_WINDOW_TYPE * msWin)857 void MApi_XC_PCMonitor_Get_Dvi_Hdmi_De_Info_U2(void* pInstance, SCALER_WIN eWindow,MS_WINDOW_TYPE* msWin)
858 {
859 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
860 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
861 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
862 MDrv_XC_PCMonitor_Get_Dvi_Hdmi_De_Info(pInstance, eWindow,msWin);
863 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
864 }
865
MApi_XC_PCMonitor_Get_Dvi_Hdmi_De_Info(SCALER_WIN eWindow,MS_WINDOW_TYPE * msWin)866 void MApi_XC_PCMonitor_Get_Dvi_Hdmi_De_Info(SCALER_WIN eWindow,MS_WINDOW_TYPE* msWin)
867 {
868 if (pu32XCInst == NULL)
869 {
870 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
871 return;
872 }
873
874 static MS_WINDOW_TYPE tmp_msWin;
875 memcpy(&tmp_msWin,msWin,sizeof(MS_WINDOW_TYPE));
876 stXC_PCMONITOR_GET_DVI_HDMI_DE_INFO XCArgs;
877 XCArgs.eWindow = eWindow;
878 XCArgs.msWin = &tmp_msWin;
879
880 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GET_DVI_HDMI_DE_INFO, (void*)&XCArgs) != 0)
881 {
882 printf("Obtain XC engine fail\n");
883 return;
884 }
885 else
886 {
887 memcpy(msWin,&tmp_msWin,sizeof(MS_WINDOW_TYPE));
888 return;
889 }
890 }
891
MApi_XC_PCMonitor_Get_HFreqx10_U2(void * pInstance,SCALER_WIN eWindow)892 MS_U16 MApi_XC_PCMonitor_Get_HFreqx10_U2(void* pInstance, SCALER_WIN eWindow)
893 {
894 MS_U16 u16Return = 0;
895 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
896 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
897 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
898 u16Return = MDrv_XC_PCMonitor_Get_HFreqx10(pInstance, eWindow);
899 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
900 return u16Return;
901 }
902
MApi_XC_PCMonitor_Get_HFreqx10(SCALER_WIN eWindow)903 MS_U16 MApi_XC_PCMonitor_Get_HFreqx10(SCALER_WIN eWindow)
904 {
905 if (pu32XCInst == NULL)
906 {
907 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
908 return 0;
909 }
910
911 stXC_PCMONITOR_GET_HFREQX10 XCArgs;
912 XCArgs.eWindow = eWindow;
913 XCArgs.u16ReturnValue = 0;
914
915 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GET_HFREQX10, (void*)&XCArgs) != 0)
916 {
917 printf("Obtain XC engine fail\n");
918 return 0;
919 }
920 else
921 {
922 return XCArgs.u16ReturnValue;
923 }
924 }
925
MApi_XC_PCMonitor_Get_HFreqx1K_U2(void * pInstance,SCALER_WIN eWindow)926 MS_U32 MApi_XC_PCMonitor_Get_HFreqx1K_U2(void* pInstance, SCALER_WIN eWindow)
927 {
928 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
929 MS_U32 u32HFreq = 0;
930 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
931 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
932 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
933 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
934 if((stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_UNSTABLE) || (stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_STABLE_NOSYNC))
935 {
936 u32HFreq = 0;
937 }
938 else
939 {
940 u32HFreq = MDrv_XC_CalculateHFreqx1K(pInstance, stPCMonitorInfo.u16Hperiod);
941
942 }
943 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
944 return u32HFreq;
945 }
946
MApi_XC_PCMonitor_Get_HFreqx1K(SCALER_WIN eWindow)947 MS_U32 MApi_XC_PCMonitor_Get_HFreqx1K(SCALER_WIN eWindow)
948 {
949 if (pu32XCInst == NULL)
950 {
951 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
952 return 0;
953 }
954
955 stXC_PCMONITOR_GET_HFREQX1K XCArgs;
956 XCArgs.eWindow = eWindow;
957 XCArgs.u32ReturnValue = 0;
958
959 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GET_HFREQX1K, (void*)&XCArgs) != 0)
960 {
961 printf("Obtain XC engine fail\n");
962 return 0;
963 }
964 else
965 {
966 return XCArgs.u32ReturnValue;
967 }
968 }
MDrv_XC_PCMonitor_Get_VFreqx10(void * pInstance,SCALER_WIN eWindow)969 MS_U16 MDrv_XC_PCMonitor_Get_VFreqx10(void *pInstance, SCALER_WIN eWindow)
970 {
971 MS_U16 u16VFreq = 0, u16AccurateVFreq = 0;
972 MS_U32 u32AccurateVPeriod = 0;
973 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
974 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
975 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
976 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
977 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
978 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
979
980 if((stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_UNSTABLE) || (stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_STABLE_NOSYNC))
981 {
982 // Original return value is 1
983 // Change to 1 to prevent 4K2K home screen (4K2K 30Hz) force SetPanelTiming with no signal cause core dump issue.
984 return 1;
985 }
986 else
987 {
988 if(FALSE == (pXCResourcePrivate->stdrvXC_MVideo_Context.g_bFast_Get_VFreq))
989 {
990 u16VFreq = MDrv_XC_CalculateVFreqx10(pInstance, MDrv_XC_PCMonitor_Get_HFreqx10(pInstance, eWindow), stPCMonitorInfo.u16Vtotal);
991 if(stPCMonitorInfo.u8SyncStatus& XC_MD_INTERLACE_BIT)
992 {
993 u16VFreq *= 2;
994 }
995
996 /// for more correct Vfreq to instead
997 u32AccurateVPeriod = MDrv_SC_ip_get_verticalperiod(pInstance, eWindow);
998 if(u32AccurateVPeriod != 0)
999 {
1000 u16AccurateVFreq = (MS_U16)((pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.u32XTAL_Clock * 10 +u32AccurateVPeriod /2) / u32AccurateVPeriod);
1001 }
1002
1003 XC_LOG_TRACE(XC_DBGLEVEL_MODEPARSE, "InputVFreq=%u->%u, Tolerance=%u\n", u16VFreq, u16AccurateVFreq, (MS_U8)ACCURATE_VFREQ_TOLERANCE);
1004 if(abs(u16VFreq - u16AccurateVFreq) < ACCURATE_VFREQ_TOLERANCE)
1005 {
1006 u16VFreq = u16AccurateVFreq; //In tolerance range, using new accurate vfreq
1007 }
1008 }
1009 else
1010 {
1011 u16VFreq =(MS_U16)(stPCMonitorInfo.u32FrameRatex1K/100);
1012 }
1013
1014 return u16VFreq;
1015 }
1016 }
1017
MApi_XC_PCMonitor_Get_VFreqx10_U2(void * pInstance,SCALER_WIN eWindow)1018 MS_U16 MApi_XC_PCMonitor_Get_VFreqx10_U2(void* pInstance, SCALER_WIN eWindow)
1019 {
1020 MS_U16 u16Return = 0;
1021 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1022 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1023 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
1024 _XC_ENTRY(pInstance);
1025 u16Return = MDrv_XC_PCMonitor_Get_VFreqx10(pInstance, eWindow);
1026 _XC_RETURN(pInstance);
1027 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1028 return u16Return;
1029 }
1030
MApi_XC_PCMonitor_Get_VFreqx10(SCALER_WIN eWindow)1031 MS_U16 MApi_XC_PCMonitor_Get_VFreqx10(SCALER_WIN eWindow)
1032 {
1033 if (pu32XCInst == NULL)
1034 {
1035 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
1036 return 0;
1037 }
1038
1039 stXC_PCMONITOR_GET_VFREQX10 XCArgs;
1040 XCArgs.eWindow = eWindow;
1041 XCArgs.u16ReturnValue = 0;
1042
1043 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GET_VFREQX10, (void*)&XCArgs) != 0)
1044 {
1045 printf("Obtain XC engine fail\n");
1046 return 0;
1047 }
1048 else
1049 {
1050 return XCArgs.u16ReturnValue;
1051 }
1052 }
1053
1054 //comparing with MApi_XC_PCMonitor_Get_VFreqx1K, MDrv_XC_PCMonitor_Get_FrameRatex1K gets Frame rate without judging Input timing stable.
MDrv_XC_PCMonitor_Get_FrameRatex1K(void * pInstance,SCALER_WIN eWindow)1055 MS_U32 MDrv_XC_PCMonitor_Get_FrameRatex1K(void* pInstance, SCALER_WIN eWindow)
1056 {
1057 MS_U32 u32VFreq = 0, u32HFreq=0, u32AccurateVFreq = 0, u32AccurateVPeriod = 0 /*,u32PrevAccurateVPeriod = 0*/;
1058 MS_U64 u64XTALClk = 0;
1059 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
1060 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1061 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1062 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1063 //MS_U8 u8VSyncTime=0, u8Count=0;
1064 UtopiaResourceGetPrivate(g_pXCResource[E_XC_POOL_ID_INTERNAL_VARIABLE],(void**)(&pXCResourcePrivate));
1065 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1066
1067 u32HFreq = MDrv_XC_CalculateHFreqx1K(pInstance, stPCMonitorInfo.u16Hperiod);
1068 u32VFreq = MDrv_XC_CalculateVFreqx1K(pInstance, u32HFreq, stPCMonitorInfo.u16Vtotal);
1069 if(stPCMonitorInfo.u8SyncStatus& XC_MD_INTERLACE_BIT)
1070 {
1071 u32VFreq *= 2;
1072 }
1073 XC_LOG_TRACE(XC_DBGLEVEL_MODEPARSE, "u32VFreq = %tu\n", (ptrdiff_t)u32VFreq);
1074 #if 0
1075 // for more correct VPeriod
1076 if (u32VFreq != 0)
1077 u8VSyncTime = stPCMonitorInfo.u16VSyncTime =((1000000)+(u32VFreq/2))/(u32VFreq);
1078 else
1079 u8VSyncTime = WAIT_VSYNC_TIME_MAX;
1080
1081 while (u8Count < MAX_GET_VPERIOD_TIME)
1082 {
1083 u32AccurateVPeriod = HAL_SC_ip_get_verticalperiod(pInstance, eWindow);
1084 if (abs(u32AccurateVPeriod - u32PrevAccurateVPeriod) <= PERIOD_TOLARANCE)
1085 {
1086 break;
1087 }
1088 u32PrevAccurateVPeriod = u32AccurateVPeriod;
1089 MsOS_DelayTask(u8VSyncTime);
1090 u8Count++;
1091 }
1092 #else
1093 u32AccurateVPeriod = HAL_SC_ip_get_verticalperiod(pInstance, eWindow);
1094 #endif
1095 XC_LOG_TRACE(XC_DBGLEVEL_MODEPARSE, "u32AccurateVPeriod = %tu\n", (ptrdiff_t)u32AccurateVPeriod);
1096
1097 if(u32AccurateVPeriod != 0)
1098 {
1099 u64XTALClk = (MS_U64)pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.u32XTAL_Clock * 1000;
1100 do_div(u64XTALClk,u32AccurateVPeriod);
1101 u32AccurateVFreq = (MS_U32)(u64XTALClk);
1102 //u32AccurateVFreq = (MS_U32)(u64XTALClk / u32AccurateVPeriod);
1103 }
1104 XC_LOG_TRACE(XC_DBGLEVEL_MODEPARSE, "u32AccurateVFreq = %tu\n", (ptrdiff_t)u32AccurateVFreq);
1105
1106 XC_LOG_TRACE(XC_DBGLEVEL_MODEPARSE, "InputVFreq=%tu->%tu, Tolerance=%tu\n", (ptrdiff_t)u32VFreq, (ptrdiff_t)u32AccurateVFreq, (ptrdiff_t)ACCURATE_VFREQ_TOLERANCE * 100);
1107 if(abs(u32VFreq - u32AccurateVFreq) < ACCURATE_VFREQ_TOLERANCE * 100)
1108 {
1109 u32VFreq = u32AccurateVFreq; //In tolerance range, using new accurate vfreq
1110 }
1111 return u32VFreq;
1112 }
1113
MApi_XC_PCMonitor_Get_VFreqx1K_U2(void * pInstance,SCALER_WIN eWindow)1114 MS_U32 MApi_XC_PCMonitor_Get_VFreqx1K_U2(void* pInstance, SCALER_WIN eWindow)
1115 {
1116 MS_U32 u32VFreq = 0;
1117 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1118 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1119 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
1120 _XC_ENTRY(pInstance);
1121 u32VFreq = MDrv_XC_PCMonitor_Get_VFreqx1K(pInstance, eWindow);
1122 _XC_RETURN(pInstance);
1123 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1124 return u32VFreq;
1125 }
1126
MApi_XC_PCMonitor_Get_VFreqx1K(SCALER_WIN eWindow)1127 MS_U32 MApi_XC_PCMonitor_Get_VFreqx1K(SCALER_WIN eWindow)
1128 {
1129 if (pu32XCInst == NULL)
1130 {
1131 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
1132 return 0;
1133 }
1134
1135 stXC_PCMONITOR_GET_VFREQX1K XCArgs;
1136 XCArgs.eWindow = eWindow;
1137 XCArgs.u32ReturnValue = 0;
1138
1139 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GET_VFREQX1K, (void*)&XCArgs) != 0)
1140 {
1141 printf("Obtain XC engine fail\n");
1142 return 0;
1143 }
1144 else
1145 {
1146 return XCArgs.u32ReturnValue;
1147 }
1148 }
1149
MDrv_XC_PCMonitor_GetDEWidthHeightInDEByPassMode(void * pInstance,MS_U16 * pu16Width,MS_U16 * pu16Height,SCALER_WIN eWindow)1150 MS_BOOL MDrv_XC_PCMonitor_GetDEWidthHeightInDEByPassMode(void* pInstance, MS_U16* pu16Width, MS_U16* pu16Height, SCALER_WIN eWindow)
1151 {
1152 if(MDrv_SC_Get_DE_Bypass_Mode(pInstance, eWindow) == FALSE)
1153 {
1154 printf("[%s,%5d] Cannot get HV width and height under DE mode!! please check your xc lib!\n", __FUNCTION__,__LINE__);
1155 return FALSE;
1156 }
1157 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
1158 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1159
1160 MDrv_XC_GetDEWidthHeightInDEByPassMode(pInstance, pu16Width, pu16Height, eWindow);
1161 stPCMonitorInfo.sDVI_HDMI_DE_Info.width = *pu16Width;
1162 stPCMonitorInfo.sDVI_HDMI_DE_Info.height = *pu16Height;
1163 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1164 return TRUE;
1165 }
1166
MApi_XC_PCMonitor_Get_Vtotal_U2(void * pInstance,SCALER_WIN eWindow)1167 MS_U16 MApi_XC_PCMonitor_Get_Vtotal_U2(void* pInstance, SCALER_WIN eWindow)
1168 {
1169 MS_U16 u16Return = 0;
1170 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1171 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1172 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
1173 u16Return = MDrv_XC_PCMonitor_Get_Vtotal(pInstance, eWindow);
1174 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1175 return u16Return;
1176 }
1177
MApi_XC_PCMonitor_Get_Vtotal(SCALER_WIN eWindow)1178 MS_U16 MApi_XC_PCMonitor_Get_Vtotal(SCALER_WIN eWindow)
1179 {
1180 if (pu32XCInst == NULL)
1181 {
1182 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
1183 return 0;
1184 }
1185
1186 stXC_PCMONITOR_GET_VTOTAL XCArgs;
1187 XCArgs.eWindow = eWindow;
1188 XCArgs.u16ReturnValue = 0;
1189
1190 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD_GET_VTOTAL, (void*)&XCArgs) != 0)
1191 {
1192 printf("Obtain XC engine fail\n");
1193 return 0;
1194 }
1195 else
1196 {
1197 return XCArgs.u16ReturnValue;
1198 }
1199 }
1200
MDrv_XC_PCMonitor_Update_TimingCount(void * pInstance,INPUT_SOURCE_TYPE_t eCurrentSrc,SCALER_WIN eWindow)1201 void MDrv_XC_PCMonitor_Update_TimingCount(void *pInstance, INPUT_SOURCE_TYPE_t eCurrentSrc, SCALER_WIN eWindow)
1202 {
1203 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1204 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1205 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1206
1207 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1208 if (IsSrcTypeVga(eCurrentSrc))
1209 {
1210 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow] = pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_VGA;
1211 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow] = pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_VGA;
1212 }
1213 else if (IsSrcTypeYPbPr(eCurrentSrc))
1214 {
1215 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow] = pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_YPBPR;
1216 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow] = pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_YPBPR;
1217 }
1218 else if (IsSrcTypeHDMI(eCurrentSrc) || IsSrcTypeDVI(eCurrentSrc))
1219 {
1220 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow] = pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter_HDMI;
1221 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow] = pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter_HDMI;
1222 }
1223 else
1224 {
1225 printf("<ATTENTION> Not support timing count for this source, use default vaule \n");
1226 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow] = MD_TIMING_STABLE_COUNT;
1227 pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow] = MD_TIMING_NOSYNC_COUNT;
1228 }
1229 }
1230
MDrv_XC_NewModeInterlacedDetect(void * pInstance,SCALER_WIN eWindow)1231 static void MDrv_XC_NewModeInterlacedDetect(void *pInstance, SCALER_WIN eWindow)
1232 {
1233 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1234 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1235 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1236 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1237 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
1238 // enable H/V sync status check
1239 MDrv_XC_SetHVSyncStatusCheck(pInstance, ENABLE, eWindow);
1240 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1241 if((IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc)
1242 || IsSrcTypeDVI(stPCMonitorInfo.eCurrentSrc)
1243 || IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc))
1244 && (stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_STABLE_SYNC))
1245 {
1246 MS_WINDOW_TYPE stCapWin;
1247 MS_U16 u16HFreqx10, u16VFreqx10, u16Vtotal;
1248 MDrv_XC_GetCaptureWindow(pInstance, &stCapWin, eWindow);
1249
1250 if((stCapWin.width > 1915) && (stCapWin.width < 1925)
1251 && (stCapWin.height > 535) && (stCapWin.height < 545)
1252 && ((u16HFreqx10 = MDrv_XC_PCMonitor_Get_HFreqx10(pInstance, eWindow)) > 305) && (u16HFreqx10 < 315)
1253 && ((u16VFreqx10 = MDrv_XC_PCMonitor_Get_VFreqx10(pInstance, eWindow)) > 498) && (u16VFreqx10 < 502)
1254 && ((u16Vtotal = MDrv_XC_PCMonitor_Get_Vtotal(pInstance, eWindow)) > 620) && (u16Vtotal < 630)
1255 && (Hal_SC_ip_get_interlace_status(pInstance, eWindow) == 0))
1256 {
1257 // enable new mode interlaced detect
1258 MDrv_XC_SetNewModeInterlacedDetect(pInstance, ENABLE, 2, ENABLE, TRUE, FALSE, eWindow);
1259 stPCMonitorInfo.eCurrentState = E_XC_PCMONITOR_UNSTABLE;
1260 pXCResourcePrivate->stapiXC_PCMonitor._bNewModeInterlacedDetect = TRUE;
1261 }
1262 else if((pXCResourcePrivate->stapiXC_PCMonitor._bNewModeInterlacedDetect == TRUE)
1263 && (!(((u16HFreqx10 = MDrv_XC_PCMonitor_Get_HFreqx10(pInstance, eWindow)) > 305) && (u16HFreqx10 < 315)
1264 && ((u16VFreqx10 = MDrv_XC_PCMonitor_Get_VFreqx10(pInstance, eWindow)) > 498) && (u16VFreqx10 < 502)
1265 && ((u16Vtotal = MDrv_XC_PCMonitor_Get_Vtotal(pInstance, eWindow)) > 1245) && (u16Vtotal < 1255)
1266 && (Hal_SC_ip_get_interlace_status(pInstance, eWindow) == 1))))
1267 {
1268 // disable new mode interlaced detect
1269 MDrv_XC_SetNewModeInterlacedDetect(pInstance, DISABLE, 0, DISABLE, FALSE, FALSE, eWindow);
1270 pXCResourcePrivate->stapiXC_PCMonitor._bNewModeInterlacedDetect = FALSE;
1271 }
1272 }
1273 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1274 }
1275
1276 //*************************************************************************
1277 //Function name: MApi_XC_PCMonitor
1278 //Passing parameter: none
1279 //Return parameter: none
1280 //Description: Monitor signal timing from analog port
1281 //
1282 //Attention: !!!!!!------ Don't put UI/CC code in this function,
1283 // if need, you can use in "MApp_PCMode_PrepareForTimingChange" ------!!!!!!
1284 //
1285 //*************************************************************************
MApi_XC_PCMonitor_U2(void * pInstance,INPUT_SOURCE_TYPE_t eCurrentSrc,SCALER_WIN eWindow)1286 XC_PCMONITOR_STATUS MApi_XC_PCMonitor_U2(void* pInstance, INPUT_SOURCE_TYPE_t eCurrentSrc, SCALER_WIN eWindow)
1287 {
1288 //#ifdef VGA_PATH_WITH_AUDIO
1289 //static bit bNoSyncStatus=0;
1290 //#endif
1291 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1292 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1293 PCMSG(static MS_BOOL bNoSyncStatus = TRUE);
1294 XC_PCMONITOR_HK_INFO stPCMonitorInfo;
1295 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
1296 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1297 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1298 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1299 MS_U8 u8Interlace = 0;
1300
1301 if(MDrv_SC_Check_IP_Gen_Timing(pInstance))
1302 {
1303 //it ip gen timing case, we need to return previous state to AP to keep everything unchanged.
1304 return stPCMonitorInfo.eCurrentState;
1305 }
1306
1307 if(stPCMonitorInfo.eCurrentSrc != eCurrentSrc)
1308 {
1309 PCMSG(printf("Restart src %d\n", eCurrentSrc));
1310 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
1311 stPCMonitorInfo.eCurrentSrc = eCurrentSrc;
1312 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1313 MDrv_XC_PCMonitor_Restart(pInstance, eWindow); // source changed, restart monitor
1314
1315 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1316 MDrv_XC_PCMonitor_Update_TimingCount(pInstance, eCurrentSrc, eWindow);
1317 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1318 }
1319
1320 //printf("PCMonitor %d, %ld, %ld\n", psPCMONITOR_HK_Info[eWindow]->bInputTimingChange,
1321 // psPCMONITOR_HK_Info[eWindow]->u32LastExecutedTime,
1322 // OS_SYSTEM_TIME());
1323
1324 if((FALSE == stPCMonitorInfo.bInputTimingChange) &&
1325 (MsOS_GetSystemTime() - stPCMonitorInfo.u32LastExecutedTime < PC_POLLING_COUNTER))
1326 {
1327 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
1328 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1329 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1330 return stPCMonitorInfo.eCurrentState;
1331 }
1332 else
1333 {
1334 // update last executed time
1335 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
1336 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1337 stPCMonitorInfo.u32LastExecutedTime = MsOS_GetSystemTime();
1338 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1339 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1340 }
1341
1342 // DE-Bypass is applied in HDMI HV mode. It will ignore pixel repetition package from HDMI.
1343 // We use the software mointor to monitor this package.
1344 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
1345 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1346 if( (IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc) || IsSrcTypeDVI(eCurrentSrc) )
1347 &&(MDrv_XC_GetHdmiSyncMode(pInstance) == HDMI_SYNC_HV)
1348 &&(eWindow == MAIN_WINDOW) )
1349 {
1350 MS_U8 u8CurHDMIPixelRep = MDrv_HDMI_avi_infoframe_info(_BYTE_5)& 0x0F;
1351
1352 MS_U8 u8IP_PixelRep = gSrcInfo[eWindow].Status2.u8IP_PixelRep;
1353 if( u8CurHDMIPixelRep != u8IP_PixelRep)
1354 {
1355 if( u8CurHDMIPixelRep )
1356 {
1357 //printf("daniel_test PC HV mode: Pixel-Rep=1 FIR=81\n");
1358 // If avi pkg report pixel repetition, IP1 should enable divider.
1359 MApi_XC_SetFIRDownSampleDivider(pInstance, ENABLE,0x01,eWindow);
1360 }
1361 else
1362 {
1363 //printf("daniel_test PC HV mode: Pixel-Rep=0 FIR=0\n");
1364 MApi_XC_SetFIRDownSampleDivider(pInstance, DISABLE,0x00,eWindow);
1365 }
1366 //_s_u32LastResetTime = MsOS_GetSystemTime();
1367 //MApi_XC_SoftwareReset(REST_IP_F2, eWindow);
1368
1369 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1370 stPCMonitorInfo.bInputTimingChange = TRUE;
1371 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1372
1373 //printf("@@@--- HDMI Pixel-Rep change from [%u] to [%u]\n", gSrcInfo[eWindow].Status2.u8IP_PixelRep, u8CurHDMIPixelRep);
1374 gSrcInfo[eWindow].Status2.u8IP_PixelRep = u8CurHDMIPixelRep;
1375 }
1376 }
1377
1378 //--------------------------------------------------
1379 //display active or no signal?
1380 if ( stPCMonitorInfo.bInputTimingChange == FALSE ) // check timing change flag have be setting
1381 {
1382 if ( MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow) ) // no sync
1383 {
1384 MDrv_XC_SetSogDetectStatus(pInstance, pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus);
1385 if ( _MApi_XC_PCMonitor_DetectSync(pInstance, stPCMonitorInfo.eCurrentSrc,eWindow) ) // check signal active
1386 {
1387 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1388 stPCMonitorInfo.bInputTimingChange = TRUE;
1389 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1390 PCMSG(if(bNoSyncStatus) printf("NewSync\n"); bNoSyncStatus = FALSE);
1391 }
1392 else
1393 {
1394 PCMSG(if(!bNoSyncStatus) printf("NoSync\n"); bNoSyncStatus = TRUE);
1395 }
1396 }
1397 else //have sync?
1398 {
1399 _XC_ENTRY(pInstance);
1400 if(gSrcInfo[eWindow].bAutoNoSignalEnabled && pXCResourcePrivate->stapiXC_PCMonitor._bEnableAutoNoSignalDetect[eWindow])
1401 {
1402 // check invalid
1403 if ( MDrv_XC_PCMonitor_InvalidTimingDetect(pInstance, TRUE, eWindow) )
1404 {
1405 ++pXCResourcePrivate->stapiXC_PCMonitor.u8DeNoiseCount[eWindow];
1406
1407 // PC monitor have to changed when auto nosignal enabled.
1408 // If no signal bit is enabled, that's treaded as no-signal
1409 // Here have to update variables for hw-detected-no-signal.
1410 if ( pXCResourcePrivate->stapiXC_PCMonitor.u8DeNoiseCount[eWindow] > 3)
1411 {
1412 Hal_SC_ip_set_IPAutoNoSignal(pInstance, DISABLE,MAIN_WINDOW);
1413 #if (HW_DESIGN_4K2K_VER >= 4 )
1414 // if enable input source before video mute, it would shows temp garbage
1415 // so need to mute video first before enable input source
1416 MDrv_SC_GenerateBlackVideo(pInstance, TRUE, eWindow );
1417 #ifndef DISABLE_3D_FUNCTION
1418 if( (MDrv_XC_Get_3D_Output_Mode(pInstance) == E_XC_3D_OUTPUT_TOP_BOTTOM_HW)
1419 || (MDrv_XC_Get_3D_Output_Mode(pInstance) == E_XC_3D_OUTPUT_TOP_BOTTOM)
1420 || (MDrv_XC_Get_3D_Output_Mode(pInstance) == E_XC_3D_OUTPUT_SIDE_BY_SIDE_HALF_HW)
1421 || (MDrv_XC_Get_3D_Output_Mode(pInstance) == E_XC_3D_OUTPUT_SIDE_BY_SIDE_HALF)
1422 || (MDrv_XC_Get_3D_Output_Mode(pInstance) == E_XC_3D_OUTPUT_FRAME_PACKING)
1423 || (MDrv_XC_Get_3D_Output_Mode(pInstance) == E_XC_3D_OUTPUT_LINE_ALTERNATIVE)
1424 )
1425 {
1426 #if PIP_PATCH_USING_SC1_MAIN_AS_SC0_SUB
1427 MDrv_SC_GenerateBlackVideo(g_pDevice1Instance, TRUE, MAIN_WINDOW);
1428 #else
1429 MDrv_SC_GenerateBlackVideo(pInstance, TRUE, SUB_WINDOW);
1430 #endif
1431 }
1432 #endif
1433
1434 // Only SW patch for YPbPr timing change case, reset IP1 to avoid HW Auto No signal not work
1435 if((MAIN_WINDOW == eWindow) && IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc))
1436 {
1437 Hal_SC_ip_software_reset(pInstance, REST_IP_F2, MAIN_WINDOW);
1438 }
1439
1440 #endif
1441 MDrv_XC_DisableInputSource(pInstance, DISABLE, eWindow); //enable the input source
1442 MDrv_XC_PCMonitor_InvalidTimingDetect(pInstance, FALSE, eWindow);
1443 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1444 stPCMonitorInfo.u8SyncStatus |= XC_MD_SYNC_LOSS;
1445 stPCMonitorInfo.bInputTimingChange = TRUE;
1446 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1447 pXCResourcePrivate->stapiXC_PCMonitor.u8DeNoiseCount[eWindow] = 0;
1448 }
1449 }
1450 else // time stable
1451 {
1452 if( gSrcInfo[eWindow].bAutoNoSignalEnabled )
1453 {
1454 if( MDrv_XC_IsInputSourceDisabled(pInstance, eWindow)&&(pXCResourcePrivate->stapiXC_PCMonitor.u8DeNoiseCount[eWindow]!=0)
1455 &&(stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_STABLE_SYNC) )
1456 {
1457 MDrv_XC_DisableInputSource(pInstance, DISABLE, eWindow); //enable the input source
1458 pXCResourcePrivate->stapiXC_PCMonitor.u8DeStableCnt[eWindow] = 0;
1459 }
1460 else
1461 {
1462 pXCResourcePrivate->stapiXC_PCMonitor.u8DeStableCnt[eWindow]++;
1463 }
1464 }
1465
1466 if((pXCResourcePrivate->stapiXC_PCMonitor.u8DeStableCnt[eWindow] ==20) && MDrv_XC_IsInputSourceDisabled(pInstance, eWindow)) // to check the input source status
1467 {
1468 MDrv_XC_DisableInputSource(pInstance, DISABLE, eWindow);
1469 pXCResourcePrivate->stapiXC_PCMonitor.u8DeStableCnt[eWindow]=0;
1470 }
1471
1472 if(pXCResourcePrivate->stapiXC_PCMonitor.u8DeStableCnt[eWindow] >=20)
1473 {
1474 pXCResourcePrivate->stapiXC_PCMonitor.u8DeStableCnt[eWindow] = 0;
1475 }
1476
1477 pXCResourcePrivate->stapiXC_PCMonitor.u8DeNoiseCount[eWindow] = 0;
1478 }
1479 }
1480 else if ( MDrv_XC_PCMonitor_InvalidTimingDetect(pInstance, FALSE, eWindow) ) // check invalid sync
1481 {
1482 PCMSG(printf("InvalidTimingDetect GO TO UNSTABLE! \n" )) ;
1483 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1484 stPCMonitorInfo.u8SyncStatus |= XC_MD_SYNC_LOSS;
1485 stPCMonitorInfo.bInputTimingChange = TRUE;
1486 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1487 MDrv_DVI_Accumulator_Monitor();
1488 }
1489 _XC_RETURN(pInstance);
1490
1491 #if ENABLE_IP_AUTO_COAST
1492 if ( IsSrcTypeVideo(stPCMonitorInfo.eCurrentSrc) )
1493 {
1494 msAPI_Scaler_IPAutoCoastHandler();
1495 }
1496 #endif
1497 }
1498 }
1499
1500 //is input timing changed and check debounce
1501 //--------------------------------------------------
1502 if ( stPCMonitorInfo.bInputTimingChange) // input timing is unstable
1503 {
1504 PCMSG(printf("TimingChg\n"));
1505 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1506 stPCMonitorInfo.bInputTimingChange = FALSE;
1507 stPCMonitorInfo.ucTimingChangeDebounce++;
1508
1509 PCMSG(printf("Deb=%d\n", stPCMonitorInfo.ucTimingChangeDebounce));
1510
1511 if ( !MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow) ) // have signal
1512 {
1513 if ( stPCMonitorInfo.ucTimingChangeDebounce <= 3 ) // prevent from SOG
1514 {
1515 stPCMonitorInfo.u8SyncStatus |= XC_MD_SYNC_LOSS;
1516 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1517 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1518 return stPCMonitorInfo.eCurrentState;
1519 }
1520 }
1521 else
1522 {
1523 if ( IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc ) ||
1524 IsSrcTypeVga(stPCMonitorInfo.eCurrentSrc ) )
1525 {
1526 // System have to set free run as soon as possible when timing unstable.
1527 MDrv_XC_ADC_Set_Freerun(pInstance, TRUE);
1528 }
1529 }
1530
1531 stPCMonitorInfo.eCurrentState = E_XC_PCMONITOR_UNSTABLE;
1532 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1533
1534 _MApi_XC_PCMonitor_PrepareForTimingChange(pInstance, eWindow);
1535
1536 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1537 // Already enter timing change, turn off AutoNoSignal
1538 if( gSrcInfo[eWindow].bAutoNoSignalEnabled )
1539 {
1540 //MApi_XC_EnableIPAutoNoSignal(FALSE, eWindow);
1541 pXCResourcePrivate->stapiXC_PCMonitor._bEnableAutoNoSignalDetect[eWindow] = FALSE;
1542 Hal_SC_ip_set_IPAutoNoSignal(pInstance, DISABLE,eWindow);
1543 // HW PIP architeucture
1544 // sub's input source and extra request should always enable/disable together
1545 if(MDrv_XC_IsInputSourceDisabled(pInstance, eWindow) && (eWindow == SUB_WINDOW))
1546 {
1547 MDrv_XC_Enable_Extra_Request(pInstance, FALSE);
1548 }
1549 //printf("daniel_test AutoNoSignal=0 t=%lu %s\n", MsOS_GetSystemTime(), __FUNCTION__);
1550 }
1551 }
1552 else // input timing is stable
1553 {
1554 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1555 stPCMonitorInfo.ucTimingChangeDebounce = 0; // reset timing change debounce counter
1556
1557 stPCMonitorInfo.ucInputTimingStableCounter++; // timing stable counter
1558
1559 if ( stPCMonitorInfo.ucInputTimingStableCounter == 0 )
1560 stPCMonitorInfo.ucInputTimingStableCounter = 1;
1561
1562 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1563 if ( !stPCMonitorInfo.bInputTimingStable )
1564 {
1565 #ifndef MSOS_TYPE_LINUX_KERNEL
1566 MS_ASSERT(pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow] > 0);
1567 MS_ASSERT(pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow] > 0);
1568 #endif
1569 if( ((!MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow)) && (stPCMonitorInfo.ucInputTimingStableCounter >= pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow])) ||
1570 (MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow) && (stPCMonitorInfo.ucInputTimingStableCounter >= pXCResourcePrivate->stapiXC_PCMonitor._u16TimingNosyncCounter[eWindow])) )
1571 {
1572 stPCMonitorInfo.bInputTimingStable = TRUE;
1573 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1574 //g_PcadcModeSetting.u8ModeIndex = 0; // reset mode index
1575 pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus = MDrv_XC_GetSogDetectStatus(pInstance);
1576
1577 if (MDrv_XC_GetVGASogEn(pInstance)) // Daten FixMe -> Please refine VGA SOG flow
1578 {
1579 if(IsSrcTypeVga(stPCMonitorInfo.eCurrentSrc) && // Is RGB in
1580 (!MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow)) && // Has signal
1581 ((pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus & (0x0001) ) == (0x0001)) && // In detecting SOG
1582 (!((pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus & (0x0002)) == (0x0002)))) // 1st time detecting SOG
1583
1584 {
1585 // only if RGB input, has sync and in SOG detecting enter here
1586 // force to check from other sync type again.
1587 pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus |= (0x0002);
1588 stPCMonitorInfo.u8SyncStatus ^= XC_MD_VSYNC_POR_BIT;
1589
1590 stPCMonitorInfo.bInputTimingStable = TRUE;
1591 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1592 }
1593 else
1594 {
1595 if(!MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow))
1596 {
1597 // has sync, no matter what sync detected, clear the SOG_DETECTED_BIT
1598 pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus &= ~(0x0002);
1599 }
1600 if((pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus & (0x0001)) &&
1601 (MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow)))
1602 {
1603 // in detecting the SOG and no Sync, clear the SOG_DETECTED_BIT
1604 pXCResourcePrivate->stapiXC_PCMonitor.g_u8RGBSOG_DetectStatus &= ~(0x0002);
1605 }
1606 stPCMonitorInfo.bInputTimingStable = TRUE;
1607 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1608 }
1609 }
1610
1611 if(MDrv_XC_PCMonitor_SyncLoss(pInstance, eWindow))
1612 {
1613 stPCMonitorInfo.eCurrentState = E_XC_PCMONITOR_STABLE_NOSYNC;
1614 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1615 }
1616 else
1617 {
1618 stPCMonitorInfo.eCurrentState = E_XC_PCMONITOR_STABLE_SYNC;
1619 // for get accurate v freq, need call msAPI_Scaler_Field_Detect and MDrv_XC_ADC_Set_Freerun
1620 u8Interlace = Hal_SC_ip_get_interlace_status(pInstance, eWindow);
1621 msAPI_Scaler_Field_Detect(pInstance, stPCMonitorInfo.eCurrentSrc, u8Interlace, eWindow);
1622 if ( IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc ) ||
1623 IsSrcTypeVga(stPCMonitorInfo.eCurrentSrc ) )
1624 {
1625 MDrv_XC_ADC_Set_Freerun(pInstance, FALSE);
1626 }
1627 // Update V sync time when timing stable.
1628 stPCMonitorInfo.u16VSyncTime = MApi_XC_CalculateVsyncTime(pInstance, stPCMonitorInfo.u16Vtotal, stPCMonitorInfo.u16Hperiod);
1629 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1630 if ( IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc ) )
1631 {
1632 _MApi_XC_PCMonitor_FPi_Patch(pInstance, eWindow);
1633 }
1634 // error flow: setwindow ->MDrv_XC_ADC_Reload -> enable auto nosignal -> htt change because ADC reload -> auto no signal disable input source(HW) -> load PQ -> unmute
1635 // it's not flash buffer because load PQ in disable input source
1636 // so here is not enable auto nosignal when video mute
1637 if(gSrcInfo[eWindow].bAutoNoSignalEnabled)
1638 {
1639 MDrv_XC_DisableInputSource(pInstance, DISABLE, eWindow);
1640 //YPbPr have some garbage when enable the auto signal detect.
1641 if((!IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc)) || (!MDrv_SC_CheckMuteStatusByRegister(pInstance, eWindow)))
1642 {
1643 pXCResourcePrivate->stapiXC_PCMonitor._bEnableAutoNoSignalDetect[eWindow] = TRUE;
1644 Hal_SC_ip_set_IPAutoNoSignal(pInstance, ENABLE,eWindow);
1645 }
1646 }
1647 //_MApi_XC_PCMonitor_ModeParse(eWindow);
1648 }
1649
1650 PCMSG(printf("*** Do Mode In Analog Path ***\n"));
1651 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1652 return stPCMonitorInfo.eCurrentState;
1653 }
1654 }
1655
1656 if(gSrcInfo[eWindow].bAutoNoSignalEnabled)
1657 {
1658 _XC_ENTRY(pInstance);
1659 if(( stPCMonitorInfo.eCurrentState == E_XC_PCMONITOR_STABLE_SYNC)
1660 &&(stPCMonitorInfo.ucInputTimingStableCounter
1661 >=pXCResourcePrivate->stapiXC_PCMonitor._u16TimingStableCounter[eWindow])
1662 &&(!Hal_SC_ip_get_IPAutoNoSignal(pInstance, eWindow ))&&(!MDrv_XC_IsInputSourceDisabled(pInstance, eWindow)))
1663 {
1664 // error flow: setwindow ->MDrv_XC_ADC_Reload -> enable auto nosignal -> htt change because ADC reload -> auto no signal disable input source(HW) -> load PQ -> unmute
1665 // it's not flash buffer because load PQ in disable input source
1666 // so here is not enable auto nosignal when video mute
1667 if((!IsSrcTypeYPbPr(stPCMonitorInfo.eCurrentSrc)) || (!MDrv_SC_CheckMuteStatusByRegister(pInstance, eWindow)))
1668 {
1669 //when signal stable, enable the auto signal detect.
1670 pXCResourcePrivate->stapiXC_PCMonitor._bEnableAutoNoSignalDetect[eWindow] = TRUE;
1671 Hal_SC_ip_set_IPAutoNoSignal(pInstance, ENABLE,eWindow);
1672 }
1673 }
1674 _XC_RETURN(pInstance);
1675 }
1676
1677 }
1678
1679 //Mantis issue of 0270665. Set the DE HV Mode when pre monitor state is E_XC_PCMONITOR_UNSTABLE .
1680 if((IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc) || IsSrcTypeDVI(stPCMonitorInfo.eCurrentSrc) )
1681 && ((stPCMonitorInfo.ePreMonitorState == E_XC_PCMONITOR_UNSTABLE)
1682 || (stPCMonitorInfo.ePreMonitorState == E_XC_PCMONITOR_STABLE_NOSYNC)))
1683 {
1684 MDrv_XC_Switch_DE_HV_Mode_By_Timing(pInstance, eWindow);
1685 }
1686
1687 if (IsSrcTypeHDMI(stPCMonitorInfo.eCurrentSrc) || IsSrcTypeDVI(stPCMonitorInfo.eCurrentSrc))
1688 {
1689 #if SUPPORT_IP_HDMI_FOR_HV_MODE
1690 MDrv_XC_Switch_DE_HV_Mode_By_Timing(pInstance, eWindow);
1691 #else
1692 //MDrv_XC_Set_DE_Lock_Mode(pInstance, eWindow);
1693 #endif
1694 MDrv_DVI_HF_adjust_internal();
1695 }
1696
1697 _XC_ENTRY(pInstance);
1698 MDrv_XC_NewModeInterlacedDetect(pInstance, eWindow);
1699 _XC_RETURN(pInstance);
1700
1701 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1702 stPCMonitorInfo.ePreMonitorState = stPCMonitorInfo.eCurrentState;
1703 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1704 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1705
1706 #ifdef MSOS_TYPE_LINUX_KERNEL
1707 if(pXCResourcePrivate->stdrvXC_MVideo.bTimingUnstableForStr == TRUE)
1708 {
1709 if(pXCResourcePrivate->stdrvXC_MVideo.u8DebounceForStr < TIMING_CHANGE_DEBOUNCE_FOR_STR)
1710 {
1711 stPCMonitorInfo = MDrv_XC_PCMonitor_GetStatus(pInstance, eWindow);
1712 stPCMonitorInfo.eCurrentState = E_XC_PCMONITOR_UNSTABLE;
1713 stPCMonitorInfo.bInputTimingChange = TRUE;
1714 stPCMonitorInfo.ePreMonitorState = stPCMonitorInfo.eCurrentState;
1715 MDrv_XC_PCMonitor_SetStatus(pInstance, stPCMonitorInfo, eWindow);
1716 ++(pXCResourcePrivate->stdrvXC_MVideo.u8DebounceForStr);
1717 }
1718 else
1719 {
1720 pXCResourcePrivate->stdrvXC_MVideo.bTimingUnstableForStr = FALSE;
1721 pXCResourcePrivate->stdrvXC_MVideo.u8DebounceForStr = 0;
1722 }
1723 }
1724 #endif
1725 return stPCMonitorInfo.eCurrentState;
1726 }
1727
MApi_XC_PCMonitor(INPUT_SOURCE_TYPE_t eCurrentSrc,SCALER_WIN eWindow)1728 XC_PCMONITOR_STATUS MApi_XC_PCMonitor(INPUT_SOURCE_TYPE_t eCurrentSrc, SCALER_WIN eWindow)
1729 {
1730 if (pu32XCInst == NULL)
1731 {
1732 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
1733 return E_XC_PCMONITOR_STABLE_NOSYNC;
1734 }
1735
1736 stXC_PCMONITOR XCArgs;
1737 XCArgs.eCurrentSrc = eCurrentSrc;
1738 XCArgs.eWindow = eWindow;
1739 XCArgs.eReturnValue = E_XC_PCMONITOR_STABLE_NOSYNC;
1740
1741 if(UtopiaIoctl(pu32XCInst, E_XC_PCMONITOR_CMD, (void*)&XCArgs) != 0)
1742 {
1743 printf("Obtain XC engine fail\n");
1744 return E_XC_PCMONITOR_STABLE_NOSYNC;
1745 }
1746 else
1747 {
1748 return XCArgs.eReturnValue;
1749 }
1750 }
1751
1752 #undef _API_XC_PC_MONITOR_C_
1753 #endif // _API_XC_PC_MONITOR_C_
1754