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_ModeParse.c
98 /// @brief Scaler API layer Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #ifndef _API_XC_MODEPARSE_C_
103 #define _API_XC_MODEPARSE_C_
104
105 //-------------------------------------------------------------------------------------------------
106 // Include Files
107 //-------------------------------------------------------------------------------------------------
108 // Common Definition
109
110 // Common
111 #ifdef MSOS_TYPE_LINUX_KERNEL
112 #include <linux/string.h>
113 #else
114 #include "string.h"
115 #endif
116
117 // XC related include files
118 #include "MsCommon.h"
119 #include "utopia.h"
120 #include "utopia_dapi.h"
121 // Driver
122 #include "drvXC_IOPort.h"
123 #include "apiXC.h"
124
125
126 #include "drv_sc_display.h"
127 #include "drv_sc_isr.h"
128 #include "apiXC_PCMonitor.h"
129 #include "apiXC_ModeParse.h"
130 #include "apiXC_Adc.h"
131 #include "apiXC_Auto.h"
132 #include "drvXC_HDMI_if.h"
133 #include "mvideo_context.h"
134 #include "drv_sc_ip.h"
135 #include "mhal_xc_chip_config.h"
136 #if (LD_ENABLE==1)
137 #include "mdrv_ld.h"
138 #include "mdrv_ldalgo.h"
139 #endif
140 #include "mdrv_sc_3d.h"
141 #include "drv_sc_menuload.h"
142 #include "drvXC_ADC_Internal.h"
143 #include "mhal_sc.h"
144 #if FRC_INSIDE
145 #include "mdrv_frc.h"
146 #include "mhal_frc.h"
147 #endif
148 #include "XC_private.h"
149 #include "apiXC_v2.h"
150 #include "apiXC_ModeParse_v2.h"
151 #include "xc_hwreg_utility2.h"
152 // Internal Definition
153
154 //-------------------------------------------------------------------------------------------------
155 // Driver Compiler Options
156 //-------------------------------------------------------------------------------------------------
157 #define XC_ModeParse_MUTEX
158
159 //-------------------------------------------------------------------------------------------------
160 // Local Defines
161 //-------------------------------------------------------------------------------------------------
162
163 #define MODE_DBG(x) //x
164 #define EURO_HDTV_DBG(x) //x
165
166 #define MODE_NAME(str) str,
167
168 // search mode torlance
169 #define MD_HFREQ_TORLANCE 15 // Unit: 0.1kHz
170 #define MD_VFREQ_TORLANCE 15 // Unit: 0.1Hz
171 #define MD_HFREQ_TORLANCE_MIN 5
172 #define MD_VFREQ_TORLANCE_MIN 5
173 #define MD_FREQ_DELTA 100 // search the user mode
174
175
176
177 // input resolution
178 typedef struct
179 {
180 MS_U16 u16DisplayWidth; // width
181 MS_U16 u16DisplayHeight; // height
182
183 }MS_MODE_RESOLUTION;
184
185 #define _XC_ModeParse_MUTEX_TIME_OUT MSOS_WAIT_FOREVER
186
187 // Mutex function
188 #ifdef XC_ModeParse_MUTEX
189 #define _XC_ModeParse_ENTRY() \
190 if(!MsOS_ObtainMutex(_XC_ModeParse_MUTEX, _XC_ModeParse_MUTEX_TIME_OUT)) \
191 { \
192 MODE_DBG(printf("[apiXC_ModeParse][%06d] Mutex taking timeout\n",__LINE__)); \
193 }
194 #define _XC_ModeParse_RETURN() MsOS_ReleaseMutex(_XC_ModeParse_MUTEX);
195 //return _ret;
196 #else // #if not def XC_MUTEX
197 #define _XC_ModeParse_ENTRY() while(0)
198 #define _XC_ModeParse_RETURN() while(0)
199 #endif // #ifdef _XC_MUTEX
200 //-------------------------------------------------------------------------------------------------
201 // Local Structurs
202 //-------------------------------------------------------------------------------------------------
203
204
205 //-------------------------------------------------------------------------------------------------
206 // Global Variables
207 //-------------------------------------------------------------------------------------------------
208
209 //-------------------------------------------------------------------------------------------------
210 // Local Variables
211 //-------------------------------------------------------------------------------------------------
212 #ifdef XC_ModeParse_MUTEX
213 static MS_S32 _XC_ModeParse_MUTEX= -1;
214 #endif // #ifdef XC_ModeParse_MUTEX
215
216 static const MS_MODE_RESOLUTION astStandardModeResolution[RES_MAXIMUM] =
217 {
218 { 640, 350}, // 00: RES_640X350
219 { 640, 400}, // 01: RES_640X400
220 { 720, 400}, // 02: RES_720X400
221 { 640, 480}, // 03: RES_640X480
222 { 800, 600}, // 04: RES_800X600
223 { 832, 624}, // 05: RES_832X624
224 {1024, 768}, // 06: RES_1024X768
225 {1280, 1024}, // 07: RES_1280X1024
226 {1600, 1200}, // 08: RES_1600X1200
227 {1152, 864}, // 09: RES_1152X864
228 {1152, 870}, // 10: RES_1152X870
229 {1280, 768}, // 11: RES_1280x768
230 {1280, 960}, // 12: RES_1280X960
231 { 720, 480}, // 13: RES_720X480
232 {1920, 1080}, // 14: RES_1920X1080
233 {1280, 720}, // 15: RES_1280X720
234 { 720, 576}, // 16: RES_720X576
235 {1920, 1200}, // 17: RES_1920X1200
236 {1400, 1050}, // 18: RES_1400X1050
237 {1440, 900}, // 19: RES_1440X900
238 {1680, 1050}, // 20: RES_1680X1050
239 {1280, 800}, // 21: RES_1280X800
240 {1600, 1024}, // 22: RES_1600X1024
241 {1600, 900}, // 23: RES_1600X900
242 {1360, 768}, // 24: RES_1360X768
243 { 848, 480}, // 25: RES_848X480
244 {1920, 1080}, // 26: RES_1920X1080P
245 {1366, 768}, // 27: RES_1366X768,
246 { 864, 648}, // 28: RES_864X648,
247 {1280, 1470}, // 29: RES_1280X1470,
248 {1920, 2205}, // 30: RES_1920X2205,
249 { 720, 240}, // 31: RES_720x240,
250 { 720, 288}, // 32: RES_720x288,
251 {1152, 900}, // 33: RES_1152X900,
252 { 856, 480}, // 34: RES_856x480,
253 {1536, 960}, // 35: RES_1536X960,
254 {1600, 1000}, // 36: RES_1600X1000,
255 {1704, 960}, // 37: RES_1704X960,
256 {1728, 1080}, // 38: RES_1728X1080,
257 {1864, 1050}, // 39: RES_1864X1050,
258 };
259
260 //#define MODE_TABLE_MAXIMUM_NUM (sizeof(astStandardModeTable) / sizeof(MS_PCADC_MODETABLE_TYPE))
261
262 //-------------------------------------------------------------------------------------------------
263 // Debug Functions
264 //-------------------------------------------------------------------------------------------------
265
266 //-------------------------------------------------------------------------------------------------
267 // Local Functions
268 //-------------------------------------------------------------------------------------------------
269
270
_MApi_XC_ModeParse_CompareModePolarity(MS_PCADC_MODETABLE_TYPE * ModeDB,MS_U8 u8InputStatusFlag,MS_U8 u8StdModeIndex)271 static MS_BOOL _MApi_XC_ModeParse_CompareModePolarity(MS_PCADC_MODETABLE_TYPE* ModeDB,MS_U8 u8InputStatusFlag, MS_U8 u8StdModeIndex)
272 {
273 MS_U8 u8ModeFlag;
274
275 u8ModeFlag = ModeDB[u8StdModeIndex].u8StatusFlag;
276
277 if (u8ModeFlag & (MD_FLAG_POR_HPVP | MD_FLAG_POR_HPVN | MD_FLAG_POR_HNVP | MD_FLAG_POR_HNVN)) // check polarity
278 {
279 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) ) == 3) && !(u8ModeFlag&MD_FLAG_POR_HPVP) )
280 {
281 return FALSE;
282 }
283 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) )==2) && !(u8ModeFlag&MD_FLAG_POR_HPVN) )
284 {
285 return FALSE;
286 }
287 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) ) == 1) && !(u8ModeFlag&MD_FLAG_POR_HNVP) )
288 {
289 return FALSE;
290 }
291 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) ) == 0) && !(u8ModeFlag&MD_FLAG_POR_HNVN) )
292 {
293 return FALSE;
294 }
295
296 return TRUE;
297 }
298 else
299 {
300 return FALSE;
301 }
302 }
303
304 //*************************************************************************
305 //Function name: _MApi_XC_ModeParse_FindMatchMode
306 //Passing parameter: MS_PCADC_MODETABLE_TYPE * pstInputType: current mode parameters
307 // MS_U8 u8InputSourceType: current input source type
308 //Return parameter: MS_U8: Match table index
309 //Description: This function will search matched standard mode index
310 //*************************************************************************
_MApi_XC_ModeParse_FindMatchMode(void * pInstance,MS_PCADC_MODETABLE_TYPE * ModeDB,MS_U8 u8NumberOfItems,MS_PCADC_MODETABLE_TYPE * pstInputType,INPUT_SOURCE_TYPE_t enInputSourceType)311 static MS_U8 _MApi_XC_ModeParse_FindMatchMode(void *pInstance, MS_PCADC_MODETABLE_TYPE* ModeDB, MS_U8 u8NumberOfItems , MS_PCADC_MODETABLE_TYPE *pstInputType, INPUT_SOURCE_TYPE_t enInputSourceType )
312 {
313 MS_PCADC_MODETABLE_TYPE *pStdModeTbl; // table pointer
314 MS_U8 ucIndex; // loop index
315 MS_U8 ucFlagBff; // flag buffer
316 MS_U16 u16InputVTotal;
317
318 MS_U8 ucMatchIndex; // match index
319 MS_U16 u16FreqMatchDelta; // difference
320 MS_U16 u16FreqDelta;
321
322 MS_U16 u16VTotalMatchDelta;
323 MS_U16 u16VTotalDelta;
324 MS_U8 u8HFtolerance, u8VFtolerance;
325 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
326 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
327 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
328 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
329 //#if (SUPPORT_EURO_HDTV)
330 MS_BOOL bIsEURO_HDTV = FALSE;
331 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
332 {
333 bIsEURO_HDTV = MDrv_XC_ip_GetEuroHdtvStatus(pInstance, MAIN_WINDOW) == EURO_AUS_HDTV_NORMAL ? FALSE : TRUE;
334 }
335 //#endif
336
337 #if 0 //test AP for detect the similar resolution index
338 {
339 MS_U8 i,j;
340 MS_PCADC_MODETABLE_TYPE *modeTab1;
341 MS_PCADC_MODETABLE_TYPE *modeTab2;
342
343 u8HFtolerance = MD_HFREQ_TORLANCE;
344 u8VFtolerance = MD_VFREQ_TORLANCE;
345
346 for(i=0; i<u8NumberOfItems-1; i++)
347 {
348 modeTab1 = ModeDB + i;
349
350 if(modeTab1->u8StatusFlag & MD_FLAG_YPBPR_BIT)
351 {
352 continue;
353 }
354
355 for(j=i+1; j<u8NumberOfItems; j++)
356 {
357 modeTab2 = ModeDB+j;
358
359 if ( (abs(modeTab1->u16HorizontalFrequency - modeTab2->u16HorizontalFrequency) < u8HFtolerance) &&
360 (abs(modeTab1->u16VerticalFrequency - modeTab2->u16VerticalFrequency) < u8VFtolerance))
361 {
362 printf("mode(%d,%d) Res idx %d@%d is the same with %d@%d\n", i, j,
363 modeTab1->enResolutionIndex, modeTab1->u16VerticalFrequency,
364 modeTab2->enResolutionIndex, modeTab2->u16VerticalFrequency);
365 }
366 }
367
368 }
369 }
370 #endif
371
372 // initilaize
373 ucMatchIndex = u8NumberOfItems;
374 u16FreqMatchDelta = MD_HFREQ_TORLANCE + MD_VFREQ_TORLANCE;
375 u16VTotalMatchDelta = 0xFFFF;
376
377 u16InputVTotal = pstInputType->u16VerticalTotal;
378
379 pStdModeTbl = ModeDB; // initailize
380
381 for(ucIndex=0; ucIndex<u8NumberOfItems; ucIndex++, pStdModeTbl++)
382 {
383 ucFlagBff = pStdModeTbl->u8StatusFlag; // get sync flag
384
385 MODE_DBG(printf("1:Md=%u,StatusFlag=0x%x,Tbl=0x%x\n",
386 ucIndex, pstInputType->u8StatusFlag, ucFlagBff);)
387
388 if( IsSrcTypeYPbPr(enInputSourceType) || IsSrcTypeHDMI(enInputSourceType) ) // Mode detect for YPbPr
389 {
390 if( !(ucFlagBff & MD_FLAG_YPBPR_BIT) ) // check YPbPr mode only
391 continue;
392
393 //#if (SUPPORT_EURO_HDTV)
394 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
395 {
396 if(bIsEURO_HDTV)
397 {
398 if( !(ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
399 {
400 continue;
401 }
402 }
403 else
404 {
405 if( (ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
406 {
407 continue;
408 }
409 }
410 }
411 //#endif
412
413 }
414 else // Mode detect for PC
415 {
416 if( (ucFlagBff&MD_FLAG_YPBPR_BIT) /*&& (ucMatchIndex != _END_OF_TBL_)*/ )
417 continue;
418 }
419
420 if(_MApi_XC_ModeParse_CompareModePolarity(ModeDB,pstInputType->u8StatusFlag, ucIndex)) // check polarity
421 {
422 //printf("MDrv_Mode_CompareModePolarity TRUE ucIndex %u\n", (MS_U8)ucIndex);
423 ;
424 }
425 else
426 {
427 if(!IsSrcTypeYPbPr(enInputSourceType))
428 {
429 //printf("MDrv_Mode_CompareModePolarity fail ucIndex %u\n", (MS_U8)ucIndex);
430 continue;
431 }
432 }
433
434 // match interlace mode
435 if ((ucFlagBff & MD_FLAG_INTERLACE) != (pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT))
436 continue;
437
438 //if (wVTotal < tStandardModeResolution[pStdModeTbl->ResolutionIndex].DisplayHeight)
439 // continue;
440
441 u8HFtolerance = MD_HFREQ_TORLANCE;
442 u8VFtolerance = MD_VFREQ_TORLANCE;
443 if (pStdModeTbl->enResolutionIndex == RES_1920X1080P)
444 {
445 if ((abs(pStdModeTbl->u16VerticalFrequency - 250) < MD_VFREQ_TORLANCE_MIN)||
446 (abs(pStdModeTbl->u16VerticalFrequency - 240) < MD_VFREQ_TORLANCE_MIN))
447 {
448 u8HFtolerance = MD_HFREQ_TORLANCE_MIN;
449 u8VFtolerance = MD_VFREQ_TORLANCE_MIN;
450 }
451 }
452
453 MODE_DBG(printf("(HFreq, VFreq, Vtt) in (%u, %u, %u), mode (%u, %u, %u)\n",
454 pstInputType->u16HorizontalFrequency, pstInputType->u16VerticalFrequency, u16InputVTotal,
455 pStdModeTbl->u16HorizontalFrequency, pStdModeTbl->u16VerticalFrequency, pStdModeTbl->u16VerticalTotal);)
456 MODE_DBG(printf("Torlance (%u, %u, %u)\n", (MS_U8) u8HFtolerance, (MS_U8) u8VFtolerance, pStdModeTbl->u8VTotalTolerance);)
457
458 // match H/V frequency
459 if ( (abs(pstInputType->u16HorizontalFrequency - pStdModeTbl->u16HorizontalFrequency) < u8HFtolerance) &&
460 (abs(pstInputType->u16VerticalFrequency - pStdModeTbl->u16VerticalFrequency) < u8VFtolerance) &&
461 (abs(u16InputVTotal - pStdModeTbl->u16VerticalTotal) < pStdModeTbl->u8VTotalTolerance) )
462 {
463 // calculate frequency diffenece
464 u16FreqDelta = abs(pstInputType->u16HorizontalFrequency - pStdModeTbl->u16HorizontalFrequency) +
465 abs(pstInputType->u16VerticalFrequency - pStdModeTbl->u16VerticalFrequency);
466
467 u16VTotalDelta = abs(u16InputVTotal - pStdModeTbl->u16VerticalTotal);
468
469 MODE_DBG(printf("New FreqDelta, VTotalDelta (%u, %u), Old (%u, %u)\n",
470 u16FreqDelta, u16VTotalDelta, u16FreqMatchDelta, u16VTotalMatchDelta);)
471 // check more near
472 if ( ((u16FreqMatchDelta > u16FreqDelta) && (u16VTotalMatchDelta > u16VTotalDelta)) ||
473 ((u16FreqDelta < 10) && (u16VTotalDelta < u16VTotalMatchDelta)) ||
474 ((u16FreqMatchDelta == u16FreqDelta) && (u16VTotalMatchDelta > u16VTotalDelta)) ||
475 ((u16FreqMatchDelta > u16FreqDelta) && (u16VTotalMatchDelta == u16VTotalDelta))
476 )
477 {
478 MODE_DBG(printf("MatchIdx=%u\n", ucIndex);)
479 u16FreqMatchDelta = u16FreqDelta;
480 u16VTotalMatchDelta = u16VTotalDelta;
481 ucMatchIndex = ucIndex; // match standard mode table
482 }
483 }
484 } // for
485
486 if(ucMatchIndex != u8NumberOfItems)
487 {
488 MODE_DBG(printf("1:Idx=%u,W=%u,H=%u,interlaced=%u\n",
489 ucMatchIndex,
490 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayWidth,
491 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayHeight,
492 pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT));
493 return ucMatchIndex;
494 }
495 else
496 {
497 MODE_DBG(printf("search user mode\n"));
498
499 // initilaize
500 ucMatchIndex = u8NumberOfItems;
501 u16FreqMatchDelta = MD_FREQ_DELTA;
502 u16VTotalMatchDelta = 0xFFFF;
503
504 pStdModeTbl = ModeDB; // initailize
505
506 for(ucIndex=0; ucIndex<u8NumberOfItems; ucIndex++, pStdModeTbl++)
507 {
508 ucFlagBff = pStdModeTbl->u8StatusFlag; // get sync flag
509
510 MODE_DBG(printf("2:Md=%u,StatusFlag=0x%x,Tbl=0x%x\n",
511 ucIndex, pstInputType->u8StatusFlag, ucFlagBff);)
512
513 // check YPbPr mode detect(only suppot YPbPr mode)
514 if( IsSrcTypeYPbPr(enInputSourceType) || IsSrcTypeHDMI(enInputSourceType) ) // Mode detect for YPbPr
515 {
516 if( !(ucFlagBff & MD_FLAG_YPBPR_BIT) ) // check YPbPr mode only
517 continue;
518 //#if (SUPPORT_EURO_HDTV)
519 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
520 {
521 if(bIsEURO_HDTV)
522 {
523 if( !(ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
524 {
525 continue;
526 }
527 }
528 else
529 {
530 if( (ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
531 {
532 continue;
533 }
534 }
535 }
536 //#endif
537 }
538 else // Mode detect for PC
539 {
540 // if( (ucFlagBff&MD_FLAG_YPBPR_BIT) /*&& (ucMatchIndex != _END_OF_TBL_)*/ )
541 // continue;
542 }
543
544 if ((ucFlagBff & MD_FLAG_INTERLACE) != (pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT))
545 continue;
546
547 MODE_DBG(printf(" InputVtt=%u,Mode=%u\n", u16InputVTotal, astStandardModeResolution[pStdModeTbl->enResolutionIndex].u16DisplayHeight);)
548
549 if ( u16InputVTotal > astStandardModeResolution[pStdModeTbl->enResolutionIndex].u16DisplayHeight)
550 {
551 MODE_DBG(printf(" HFreq(%u,%u),VFreq(%u,%u)\n",
552 pstInputType->u16HorizontalFrequency,
553 pStdModeTbl->u16HorizontalFrequency,
554 pstInputType->u16VerticalFrequency,
555 pStdModeTbl->u16VerticalFrequency);)
556
557 // calculate frequency delta
558 u16FreqDelta = abs(pstInputType->u16HorizontalFrequency - pStdModeTbl->u16HorizontalFrequency) +
559 abs(pstInputType->u16VerticalFrequency - pStdModeTbl->u16VerticalFrequency);
560
561 u16VTotalDelta = abs(u16InputVTotal - pStdModeTbl->u16VerticalTotal);
562
563 // compare delta minimum & match interlace status
564 if ( ((u16FreqDelta < u16FreqMatchDelta) && (u16VTotalDelta < u16VTotalMatchDelta)) ||
565 ((u16FreqDelta <= 10) && (u16VTotalDelta < u16VTotalMatchDelta)))
566 {
567 u16FreqMatchDelta = u16FreqDelta;
568 ucMatchIndex = ucIndex; // match user mode index
569 u16VTotalMatchDelta = u16VTotalDelta;
570
571 MODE_DBG(printf(" --Delta Freq=%u,Vtt=%u\n", u16FreqMatchDelta, u16VTotalMatchDelta);)
572 }
573 }
574 } // for
575
576 if(ucMatchIndex != u8NumberOfItems)
577 {
578 //pstInputType->u8StatusFlag |= _BIT7; //user new mode
579 pstInputType->u8StatusFlag |= XC_MD_USER_MODE_BIT; //user new mode
580 // printf("This mode is USER MODE \n");
581 }
582
583 MODE_DBG(printf("2:Idx=%u,W=%u,H=%u,interlaced=%u\n",
584 ucMatchIndex,
585 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayWidth,
586 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayHeight,
587 pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT);)
588 return ucMatchIndex; // result
589 }
590 }
591
_MApi_XC_ModeParse_CompareModePolarityEx(MS_PCADC_MODETABLE_TYPE_EX * ModeDB,MS_U8 u8InputStatusFlag,MS_U8 u8StdModeIndex)592 static MS_BOOL _MApi_XC_ModeParse_CompareModePolarityEx(MS_PCADC_MODETABLE_TYPE_EX* ModeDB,MS_U8 u8InputStatusFlag, MS_U8 u8StdModeIndex)
593 {
594 MS_U8 u8ModeFlag;
595
596 u8ModeFlag = ModeDB[u8StdModeIndex].u8StatusFlag;
597
598 if (u8ModeFlag & (MD_FLAG_POR_HPVP | MD_FLAG_POR_HPVN | MD_FLAG_POR_HNVP | MD_FLAG_POR_HNVN)) // check polarity
599 {
600 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) ) == 3) && !(u8ModeFlag&MD_FLAG_POR_HPVP) )
601 {
602 return FALSE;
603 }
604 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) )==2) && !(u8ModeFlag&MD_FLAG_POR_HPVN) )
605 {
606 return FALSE;
607 }
608 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) ) == 1) && !(u8ModeFlag&MD_FLAG_POR_HNVP) )
609 {
610 return FALSE;
611 }
612 if( ( (u8InputStatusFlag&(XC_MD_HSYNC_POR_BIT|XC_MD_VSYNC_POR_BIT) ) == 0) && !(u8ModeFlag&MD_FLAG_POR_HNVN) )
613 {
614 return FALSE;
615 }
616
617 return TRUE;
618 }
619 else
620 {
621 return FALSE;
622 }
623 }
624
625 //*************************************************************************
626 //Function name: _MApi_XC_ModeParse_FindMatchMode
627 //Passing parameter: MS_PCADC_MODETABLE_TYPE_EX * pstInputType: current mode parameters
628 // MS_U8 u8InputSourceType: current input source type
629 //Return parameter: MS_U8: Match table index
630 //Description: This function will search matched standard mode index
631 //*************************************************************************
_MApi_XC_ModeParse_FindMatchModeEx(void * pInstance,MS_PCADC_MODETABLE_TYPE_EX * ModeDB,MS_U8 u8NumberOfItems,MS_PCADC_MODETABLE_TYPE_EX * pstInputType,INPUT_SOURCE_TYPE_t enInputSourceType)632 static MS_U8 _MApi_XC_ModeParse_FindMatchModeEx(void *pInstance, MS_PCADC_MODETABLE_TYPE_EX* ModeDB, MS_U8 u8NumberOfItems , MS_PCADC_MODETABLE_TYPE_EX *pstInputType, INPUT_SOURCE_TYPE_t enInputSourceType )
633 {
634 MS_PCADC_MODETABLE_TYPE_EX *pStdModeTbl; // table pointer
635 MS_U8 ucIndex; // loop index
636 MS_U8 ucFlagBff; // flag buffer
637 MS_U16 u16InputVTotal;
638
639 MS_U8 ucMatchIndex; // match index
640 MS_U16 u16FreqMatchDelta; // difference
641 MS_U16 u16FreqDelta;
642
643 MS_U16 u16VTotalMatchDelta;
644 MS_U16 u16VTotalDelta;
645 MS_U8 u8HFtolerance, u8VFtolerance;
646 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
647 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
648 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
649 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
650 //#if (SUPPORT_EURO_HDTV)
651 MS_BOOL bIsEURO_HDTV = FALSE;
652 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
653 {
654 bIsEURO_HDTV = MDrv_XC_ip_GetEuroHdtvStatus(pInstance, MAIN_WINDOW) == EURO_AUS_HDTV_NORMAL ? FALSE : TRUE;
655 }
656 //#endif
657
658 #if 0 //test AP for detect the similar resolution index
659 {
660 MS_U8 i,j;
661 MS_PCADC_MODETABLE_TYPE_EX *modeTab1;
662 MS_PCADC_MODETABLE_TYPE_EX *modeTab2;
663
664 u8HFtolerance = MD_HFREQ_TORLANCE;
665 u8VFtolerance = MD_VFREQ_TORLANCE;
666
667 for(i=0; i<u8NumberOfItems-1; i++)
668 {
669 modeTab1 = ModeDB + i;
670
671 if(modeTab1->u8StatusFlag & MD_FLAG_YPBPR_BIT)
672 {
673 continue;
674 }
675
676 for(j=i+1; j<u8NumberOfItems; j++)
677 {
678 modeTab2 = ModeDB+j;
679
680 if ( (abs(modeTab1->u16HorizontalFrequency - modeTab2->u16HorizontalFrequency) < u8HFtolerance) &&
681 (abs(modeTab1->u16VerticalFrequency - modeTab2->u16VerticalFrequency) < u8VFtolerance))
682 {
683 printf("mode(%d,%d) Res idx %d@%d is the same with %d@%d\n", i, j,
684 modeTab1->enResolutionIndex, modeTab1->u16VerticalFrequency,
685 modeTab2->enResolutionIndex, modeTab2->u16VerticalFrequency);
686 }
687 }
688
689 }
690 }
691 #endif
692
693 // initilaize
694 ucMatchIndex = u8NumberOfItems;
695 u16FreqMatchDelta = MD_HFREQ_TORLANCE + MD_VFREQ_TORLANCE;
696 u16VTotalMatchDelta = 0xFFFF;
697
698 u16InputVTotal = pstInputType->u16VerticalTotal;
699
700 pStdModeTbl = ModeDB; // initailize
701
702 for(ucIndex=0; ucIndex<u8NumberOfItems; ucIndex++, pStdModeTbl++)
703 {
704 ucFlagBff = pStdModeTbl->u8StatusFlag; // get sync flag
705
706 MODE_DBG(printf("1:Md=%u,StatusFlag=0x%x,Tbl=0x%x\n",
707 ucIndex, pstInputType->u8StatusFlag, ucFlagBff);)
708
709 if( IsSrcTypeYPbPr(enInputSourceType) || IsSrcTypeHDMI(enInputSourceType) ) // Mode detect for YPbPr
710 {
711 if( !(ucFlagBff & MD_FLAG_YPBPR_BIT) ) // check YPbPr mode only
712 continue;
713
714 //#if (SUPPORT_EURO_HDTV)
715 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
716 {
717 if(bIsEURO_HDTV)
718 {
719 if( !(ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
720 {
721 continue;
722 }
723 }
724 else
725 {
726 if( (ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
727 {
728 continue;
729 }
730 }
731 }
732 //#endif
733
734 }
735 else // Mode detect for PC
736 {
737 if( (ucFlagBff&MD_FLAG_YPBPR_BIT) /*&& (ucMatchIndex != _END_OF_TBL_)*/ )
738 continue;
739 }
740
741 if(_MApi_XC_ModeParse_CompareModePolarityEx(ModeDB,pstInputType->u8StatusFlag, ucIndex)) // check polarity
742 {
743 //printf("MDrv_Mode_CompareModePolarity TRUE ucIndex %u\n", (MS_U8)ucIndex);
744 ;
745 }
746 else
747 {
748 if(!IsSrcTypeYPbPr(enInputSourceType))
749 {
750 //printf("MDrv_Mode_CompareModePolarity fail ucIndex %u\n", (MS_U8)ucIndex);
751 continue;
752 }
753 }
754
755 // match interlace mode
756 if ((ucFlagBff & MD_FLAG_INTERLACE) != (pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT))
757 continue;
758
759 //if (wVTotal < tStandardModeResolution[pStdModeTbl->ResolutionIndex].DisplayHeight)
760 // continue;
761
762 u8HFtolerance = MD_HFREQ_TORLANCE;
763 u8VFtolerance = MD_VFREQ_TORLANCE;
764 if (pStdModeTbl->enResolutionIndex == RES_1920X1080P)
765 {
766 if ((abs(pStdModeTbl->u16VerticalFrequency - 250) < MD_VFREQ_TORLANCE_MIN)||
767 (abs(pStdModeTbl->u16VerticalFrequency - 240) < MD_VFREQ_TORLANCE_MIN))
768 {
769 u8HFtolerance = MD_HFREQ_TORLANCE_MIN;
770 u8VFtolerance = MD_VFREQ_TORLANCE_MIN;
771 }
772 }
773
774 MODE_DBG(printf("(HFreq, VFreq, Vtt) in (%u, %u, %u), mode (%u, %u, %u)\n",
775 pstInputType->u16HorizontalFrequency, pstInputType->u16VerticalFrequency, u16InputVTotal,
776 pStdModeTbl->u16HorizontalFrequency, pStdModeTbl->u16VerticalFrequency, pStdModeTbl->u16VerticalTotal);)
777 MODE_DBG(printf("Torlance (%u, %u, %u)\n", (MS_U8) u8HFtolerance, (MS_U8) u8VFtolerance, pStdModeTbl->u16VTotalTolerance);)
778
779 // match H/V frequency
780 if ( (abs(pstInputType->u16HorizontalFrequency - pStdModeTbl->u16HorizontalFrequency) < u8HFtolerance) &&
781 (abs(pstInputType->u16VerticalFrequency - pStdModeTbl->u16VerticalFrequency) < u8VFtolerance) &&
782 (abs(u16InputVTotal - pStdModeTbl->u16VerticalTotal) < pStdModeTbl->u16VTotalTolerance) )
783 {
784 // calculate frequency diffenece
785 u16FreqDelta = abs(pstInputType->u16HorizontalFrequency - pStdModeTbl->u16HorizontalFrequency) +
786 abs(pstInputType->u16VerticalFrequency - pStdModeTbl->u16VerticalFrequency);
787
788 u16VTotalDelta = abs(u16InputVTotal - pStdModeTbl->u16VerticalTotal);
789
790 MODE_DBG(printf("New FreqDelta, VTotalDelta (%u, %u), Old (%u, %u)\n",
791 u16FreqDelta, u16VTotalDelta, u16FreqMatchDelta, u16VTotalMatchDelta);)
792 // check more near
793 if ( ((u16FreqMatchDelta > u16FreqDelta) && (u16VTotalMatchDelta > u16VTotalDelta)) ||
794 ((u16FreqDelta < 10) && (u16VTotalDelta < u16VTotalMatchDelta)) ||
795 ((u16FreqMatchDelta == u16FreqDelta) && (u16VTotalMatchDelta > u16VTotalDelta)) ||
796 ((u16FreqMatchDelta > u16FreqDelta) && (u16VTotalMatchDelta == u16VTotalDelta))
797 )
798 {
799 MODE_DBG(printf("MatchIdx=%u\n", ucIndex);)
800 u16FreqMatchDelta = u16FreqDelta;
801 u16VTotalMatchDelta = u16VTotalDelta;
802 ucMatchIndex = ucIndex; // match standard mode table
803 }
804 }
805 } // for
806
807 if(ucMatchIndex != u8NumberOfItems)
808 {
809 MODE_DBG(printf("1:Idx=%u,W=%u,H=%u,interlaced=%u\n",
810 ucMatchIndex,
811 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayWidth,
812 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayHeight,
813 pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT));
814 return ucMatchIndex;
815 }
816 else
817 {
818 MODE_DBG(printf("search user mode\n"));
819
820 // initilaize
821 ucMatchIndex = u8NumberOfItems;
822 u16FreqMatchDelta = MD_FREQ_DELTA;
823 u16VTotalMatchDelta = 0xFFFF;
824
825 pStdModeTbl = ModeDB; // initailize
826
827 for(ucIndex=0; ucIndex<u8NumberOfItems; ucIndex++, pStdModeTbl++)
828 {
829 ucFlagBff = pStdModeTbl->u8StatusFlag; // get sync flag
830
831 MODE_DBG(printf("2:Md=%u,StatusFlag=0x%x,Tbl=0x%x\n",
832 ucIndex, pstInputType->u8StatusFlag, ucFlagBff);)
833
834 // check YPbPr mode detect(only suppot YPbPr mode)
835 if( IsSrcTypeYPbPr(enInputSourceType) || IsSrcTypeHDMI(enInputSourceType) ) // Mode detect for YPbPr
836 {
837 if( !(ucFlagBff & MD_FLAG_YPBPR_BIT) ) // check YPbPr mode only
838 continue;
839 //#if (SUPPORT_EURO_HDTV)
840 if (pXCResourcePrivate->stdrvXC_MVideo_Context._bEnableEuro)
841 {
842 if(bIsEURO_HDTV)
843 {
844 if( !(ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
845 {
846 continue;
847 }
848 }
849 else
850 {
851 if( (ucFlagBff & MD_FLAG_EURO_HDTV_BIT) )
852 {
853 continue;
854 }
855 }
856 }
857 //#endif
858 }
859 else // Mode detect for PC
860 {
861 // if( (ucFlagBff&MD_FLAG_YPBPR_BIT) /*&& (ucMatchIndex != _END_OF_TBL_)*/ )
862 // continue;
863 }
864
865 if ((ucFlagBff & MD_FLAG_INTERLACE) != (pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT))
866 continue;
867
868 MODE_DBG(printf(" InputVtt=%u,Mode=%u\n", u16InputVTotal, astStandardModeResolution[pStdModeTbl->enResolutionIndex].u16DisplayHeight);)
869
870 if ( u16InputVTotal > astStandardModeResolution[pStdModeTbl->enResolutionIndex].u16DisplayHeight)
871 {
872 MODE_DBG(printf(" HFreq(%u,%u),VFreq(%u,%u)\n",
873 pstInputType->u16HorizontalFrequency,
874 pStdModeTbl->u16HorizontalFrequency,
875 pstInputType->u16VerticalFrequency,
876 pStdModeTbl->u16VerticalFrequency);)
877
878 // calculate frequency delta
879 u16FreqDelta = abs(pstInputType->u16HorizontalFrequency - pStdModeTbl->u16HorizontalFrequency) +
880 abs(pstInputType->u16VerticalFrequency - pStdModeTbl->u16VerticalFrequency);
881
882 u16VTotalDelta = abs(u16InputVTotal - pStdModeTbl->u16VerticalTotal);
883
884 // compare delta minimum & match interlace status
885 if ( ((u16FreqDelta < u16FreqMatchDelta) && (u16VTotalDelta < u16VTotalMatchDelta)) ||
886 ((u16FreqDelta <= 10) && (u16VTotalDelta < u16VTotalMatchDelta)))
887 {
888 u16FreqMatchDelta = u16FreqDelta;
889 ucMatchIndex = ucIndex; // match user mode index
890 u16VTotalMatchDelta = u16VTotalDelta;
891
892 MODE_DBG(printf(" --Delta Freq=%u,Vtt=%u\n", u16FreqMatchDelta, u16VTotalMatchDelta);)
893 }
894 }
895 } // for
896
897 if(ucMatchIndex != u8NumberOfItems)
898 {
899 //pstInputType->u8StatusFlag |= _BIT7; //user new mode
900 pstInputType->u8StatusFlag |= XC_MD_USER_MODE_BIT; //user new mode
901 // printf("This mode is USER MODE \n");
902 }
903
904 MODE_DBG(printf("2:Idx=%u,W=%u,H=%u,interlaced=%u\n",
905 ucMatchIndex,
906 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayWidth,
907 astStandardModeResolution[ModeDB[ucMatchIndex].enResolutionIndex].u16DisplayHeight,
908 pstInputType->u8StatusFlag & XC_MD_INTERLACE_BIT);)
909 return ucMatchIndex; // result
910 }
911 }
912 //-------------------------------------------------------------------------------------------------
913 // Global Functions
914 //-------------------------------------------------------------------------------------------------
915
916
917 /********************************************************************************/
918 /* Local Function Prototypes */
919 /********************************************************************************/
920 /********************************************************************************/
921 /* Functions */
922 /********************************************************************************/
923
MApi_XC_ModeParse_Init_U2(void * pInstance)924 MS_BOOL MApi_XC_ModeParse_Init_U2(void* pInstance)
925 {
926 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
927 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
928 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
929 if (-1!=_XC_ModeParse_MUTEX)
930 {
931 MODE_DBG(printf("[_XC_ModeParse_MUTEX][%06d] Initialization more than once\n", __LINE__));
932 //return FALSE;
933 }
934
935 _XC_ModeParse_MUTEX = MsOS_CreateMutex(E_MSOS_FIFO, "_XC_ModeParse_MUTEX", MSOS_PROCESS_SHARED);
936
937 if (-1 == _XC_ModeParse_MUTEX)
938 {
939 MODE_DBG(printf("[_XC_ModeParse_MUTEX][%06d] create mutex fail\n", __LINE__));
940 }
941 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
942 return TRUE;
943 }
944
MApi_XC_ModeParse_Init(void)945 MS_BOOL MApi_XC_ModeParse_Init(void)
946 {
947 if (pu32XCInst == NULL)
948 {
949 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
950 return FALSE;
951 }
952
953 stXC_MODEPARSE_INIT XCArgs;
954 XCArgs.bReturnValue = FALSE;
955
956 if(UtopiaIoctl(pu32XCInst, E_XC_MODEPARSE_CMD_INIT, (void*)&XCArgs) != 0)
957 {
958 printf("Obtain XC engine fail\n");
959 return FALSE;
960 }
961 else
962 {
963 return XCArgs.bReturnValue;
964 }
965 }
966
967
MApi_XC_ModeParse_MatchMode_U2(void * pInstance,MS_PCADC_MODETABLE_TYPE * ModeDB,MS_U8 u8NumberOfItems,XC_MODEPARSE_INPUT_INFO * psInputInfo)968 XC_MODEPARSE_RESULT MApi_XC_ModeParse_MatchMode_U2(void* pInstance, MS_PCADC_MODETABLE_TYPE* ModeDB, MS_U8 u8NumberOfItems , XC_MODEPARSE_INPUT_INFO *psInputInfo)
969 {
970 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
971 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
972 MS_PCADC_MODETABLE_TYPE stTempInputBuff;
973 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
974 _XC_ModeParse_ENTRY();
975
976 if(IsSrcTypeAnalog(psInputInfo->eSrcType))
977 {
978 // VGA/YPbPr
979 // search standard mode, fill related parameter
980 stTempInputBuff.u16HorizontalFrequency = psInputInfo->u16HFreqx10;
981 stTempInputBuff.u16VerticalFrequency = psInputInfo->u16VFreqx10;
982 stTempInputBuff.u16VerticalTotal = psInputInfo->u16Vtotal;
983 stTempInputBuff.u8StatusFlag = psInputInfo->u8SyncStatus;
984
985 psInputInfo->u8ModeIndex = _MApi_XC_ModeParse_FindMatchMode(pInstance, ModeDB, u8NumberOfItems, &stTempInputBuff, psInputInfo->eSrcType);
986 MODE_DBG(printf("1.psInputInfo->eSrcType=%u, psInputInfo->u8ModeIndex=%u\n",psInputInfo->eSrcType, psInputInfo->u8ModeIndex));
987 if ( psInputInfo->u8ModeIndex == u8NumberOfItems ) // not match
988 {
989 MODE_DBG(printf("XC_MODEPARSE_UNSUPPORT_MODE\n"));
990 _XC_ModeParse_RETURN();
991 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
992 return XC_MODEPARSE_UNSUPPORT_MODE;
993 }
994 else
995 {
996 psInputInfo->u8SyncStatus |= (stTempInputBuff.u8StatusFlag & XC_MD_USER_MODE_BIT);
997 MODE_DBG(printf("LMd=%u,N=%u\n", psInputInfo->u8ModeIndex, (MS_BOOL)((stTempInputBuff.u8StatusFlag & XC_MD_USER_MODE_BIT)>0)));
998 psInputInfo->u16ResWidth = astStandardModeResolution[ModeDB[psInputInfo->u8ModeIndex].enResolutionIndex].u16DisplayWidth;
999 //_MApi_XC_ModeParse_GetStdMdResH(psInputInfo->u8ModeIndex);
1000 psInputInfo->u16ResHeight = astStandardModeResolution[ModeDB[psInputInfo->u8ModeIndex].enResolutionIndex].u16DisplayHeight;
1001 //_MApi_XC_ModeParse_GetStdMdResV(psInputInfo->u8ModeIndex);
1002 MODE_DBG(printf("XC_MODEPARSE_SUPPORT_MODE\n"));
1003 _XC_ModeParse_RETURN();
1004 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1005 return XC_MODEPARSE_SUPPORT_MODE;
1006 }
1007 }
1008 else
1009 {
1010 // DVI/HDMI
1011 psInputInfo->u8ModeIndex = 0;
1012 _XC_ModeParse_RETURN();
1013 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1014 return XC_MODEPARSE_SUPPORT_MODE;
1015 }
1016 MODE_DBG(printf("2.psInputInfo->eSrcType=%u, psInputInfo->u8ModeIndex=%u\n",psInputInfo->eSrcType, psInputInfo->u8ModeIndex));
1017 }
1018
MApi_XC_ModeParse_MatchMode(MS_PCADC_MODETABLE_TYPE * ModeDB,MS_U8 u8NumberOfItems,XC_MODEPARSE_INPUT_INFO * psInputInfo)1019 XC_MODEPARSE_RESULT MApi_XC_ModeParse_MatchMode(MS_PCADC_MODETABLE_TYPE* ModeDB, MS_U8 u8NumberOfItems , XC_MODEPARSE_INPUT_INFO *psInputInfo)
1020 {
1021 if (pu32XCInst == NULL)
1022 {
1023 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
1024 return XC_MODEPARSE_NOT_PARSED;
1025 }
1026
1027 static XC_MODEPARSE_INPUT_INFO tmp_psInputInfo;
1028 memcpy(&tmp_psInputInfo,psInputInfo,sizeof(XC_MODEPARSE_INPUT_INFO));
1029 stXC_MODEPARSE_MATCHMODE XCArgs;
1030 XCArgs.ModeDB = ModeDB;
1031 XCArgs.u8NumberOfItems = u8NumberOfItems;
1032 XCArgs.psInputInfo = &tmp_psInputInfo;
1033 XCArgs.eReturnValue = XC_MODEPARSE_NOT_PARSED;
1034
1035 if(UtopiaIoctl(pu32XCInst, E_XC_MODEPARSE_CMD_MATCHMODE, (void*)&XCArgs) != 0)
1036 {
1037 printf("Obtain XC engine fail\n");
1038 return XC_MODEPARSE_NOT_PARSED;
1039 }
1040 else
1041 {
1042 memcpy(psInputInfo,&tmp_psInputInfo,sizeof(XC_MODEPARSE_INPUT_INFO));
1043 return XCArgs.eReturnValue;
1044 }
1045 }
1046
MApi_XC_ModeParse_MatchModeEx_U2(void * pInstance,MS_PCADC_MODETABLE_TYPE_EX * ModeDB,MS_U8 u8NumberOfItems,XC_MODEPARSE_INPUT_INFO * psInputInfo)1047 XC_MODEPARSE_RESULT MApi_XC_ModeParse_MatchModeEx_U2(void* pInstance, MS_PCADC_MODETABLE_TYPE_EX* ModeDB, MS_U8 u8NumberOfItems , XC_MODEPARSE_INPUT_INFO *psInputInfo)
1048 {
1049 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1050 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1051 MS_PCADC_MODETABLE_TYPE_EX stTempInputBuff;
1052 _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR)
1053 _XC_ModeParse_ENTRY();
1054
1055 if(IsSrcTypeAnalog(psInputInfo->eSrcType))
1056 {
1057 // VGA/YPbPr
1058 // search standard mode, fill related parameter
1059 stTempInputBuff.u16HorizontalFrequency = psInputInfo->u16HFreqx10;
1060 stTempInputBuff.u16VerticalFrequency = psInputInfo->u16VFreqx10;
1061 stTempInputBuff.u16VerticalTotal = psInputInfo->u16Vtotal;
1062 stTempInputBuff.u8StatusFlag = psInputInfo->u8SyncStatus;
1063
1064 psInputInfo->u8ModeIndex = _MApi_XC_ModeParse_FindMatchModeEx(pInstance, ModeDB, u8NumberOfItems, &stTempInputBuff, psInputInfo->eSrcType);
1065 MODE_DBG(printf("1.psInputInfo->eSrcType=%u, psInputInfo->u8ModeIndex=%u\n",psInputInfo->eSrcType, psInputInfo->u8ModeIndex));
1066 if ( psInputInfo->u8ModeIndex == u8NumberOfItems ) // not match
1067 {
1068 MODE_DBG(printf("XC_MODEPARSE_UNSUPPORT_MODE\n"));
1069 _XC_ModeParse_RETURN();
1070 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1071 return XC_MODEPARSE_UNSUPPORT_MODE;
1072 }
1073 else
1074 {
1075 psInputInfo->u8SyncStatus |= (stTempInputBuff.u8StatusFlag & XC_MD_USER_MODE_BIT);
1076 MODE_DBG(printf("LMd=%u,N=%u\n", psInputInfo->u8ModeIndex, (MS_BOOL)((stTempInputBuff.u8StatusFlag & XC_MD_USER_MODE_BIT)>0)));
1077 psInputInfo->u16ResWidth = astStandardModeResolution[ModeDB[psInputInfo->u8ModeIndex].enResolutionIndex].u16DisplayWidth;
1078 //_MApi_XC_ModeParse_GetStdMdResH(psInputInfo->u8ModeIndex);
1079 psInputInfo->u16ResHeight = astStandardModeResolution[ModeDB[psInputInfo->u8ModeIndex].enResolutionIndex].u16DisplayHeight;
1080 //_MApi_XC_ModeParse_GetStdMdResV(psInputInfo->u8ModeIndex);
1081 MODE_DBG(printf("XC_MODEPARSE_SUPPORT_MODE\n"));
1082 _XC_ModeParse_RETURN();
1083 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1084 return XC_MODEPARSE_SUPPORT_MODE;
1085 }
1086 }
1087 else
1088 {
1089 // DVI/HDMI
1090 psInputInfo->u8ModeIndex = 0;
1091 _XC_ModeParse_RETURN();
1092 _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
1093 return XC_MODEPARSE_SUPPORT_MODE;
1094 }
1095 MODE_DBG(printf("2.psInputInfo->eSrcType=%u, psInputInfo->u8ModeIndex=%u\n",psInputInfo->eSrcType, psInputInfo->u8ModeIndex));
1096 }
1097
MApi_XC_ModeParse_MatchModeEx(MS_PCADC_MODETABLE_TYPE_EX * ModeDB,MS_U8 u8NumberOfItems,XC_MODEPARSE_INPUT_INFO * psInputInfo)1098 XC_MODEPARSE_RESULT MApi_XC_ModeParse_MatchModeEx(MS_PCADC_MODETABLE_TYPE_EX* ModeDB, MS_U8 u8NumberOfItems , XC_MODEPARSE_INPUT_INFO *psInputInfo)
1099 {
1100 if (pu32XCInst == NULL)
1101 {
1102 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
1103 return XC_MODEPARSE_NOT_PARSED;
1104 }
1105
1106 stXC_MODEPARSE_MATCHMODEEX XCArgs;
1107 XCArgs.ModeDB = ModeDB;
1108 XCArgs.u8NumberOfItems = u8NumberOfItems;
1109 XCArgs.psInputInfo = psInputInfo;
1110 XCArgs.eReturnValue = XC_MODEPARSE_NOT_PARSED;
1111
1112 if(UtopiaIoctl(pu32XCInst, E_XC_MODEPARSE_CMD_MATCHMODEEX, (void*)&XCArgs) != 0)
1113 {
1114 printf("Obtain XC engine fail\n");
1115 return XC_MODEPARSE_NOT_PARSED;
1116 }
1117 else
1118 {
1119 return XCArgs.eReturnValue;
1120 }
1121 }
1122
1123
1124 #undef _API_XC_MODEPARSE_C_
1125 #endif // _API_XC_MODEPARSE_C_
1126