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) 2008-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 /* Header Files */
97 /******************************************************************************/
98
99 // Common Definition
100 #include "MsCommon.h"
101 #include "mhal_xc_chip_config.h"
102 #include "utopia.h"
103 #include "drvXC_IOPort.h"
104 #include "apiXC.h"
105 #include "apiXC_Adc.h"
106 #include "apiXC_Auto.h"
107 #include "apiXC_ModeParse.h"
108 #include "drv_sc_display.h"
109 #include "drv_sc_isr.h"
110 #include "apiXC_PCMonitor.h"
111 #include "drvXC_HDMI_if.h"
112 #include "mvideo_context.h"
113 #include "drv_sc_ip.h"
114 #if (LD_ENABLE==1)
115 #include "mdrv_ld.h"
116 #include "mdrv_ldalgo.h"
117 #endif
118 #include "mdrv_sc_3d.h"
119 #include "drv_sc_menuload.h"
120 #include "drvXC_ADC_Internal.h"
121 #include "mhal_sc.h"
122 #if FRC_INSIDE
123 #include "mdrv_frc.h"
124 #include "mhal_frc.h"
125 #endif
126 #include "XC_private.h"
127 #include "apiXC_v2.h"
128 #include "mhal_offline.h"
129 #include "xc_hwreg_utility2.h"
130 #include "drv_sc_mux.h"
131 #include "mhal_mux.h"
132 #include "utopia_dapi.h"
133 #ifdef MSOS_TYPE_LINUX_KERNEL
134 #include <linux/string.h>
135 #else
136 #include <string.h>
137 #endif
138
139
140 //----------------------------
141 //
142 //----------------------------
143 #define AIS_Debug(x) //x
144
145
146 //------------------------------------------------------------------------------------------------
147 //------------------------------------------------------------------------------------------------
MDrv_XC_GetOffLineDetection(void * pInstance,INPUT_SOURCE_TYPE_t u8InputSourceType)148 MS_U8 MDrv_XC_GetOffLineDetection(void *pInstance, INPUT_SOURCE_TYPE_t u8InputSourceType )
149 {
150 MS_U8 u8CheckSrc = INPUT_PORT_NONE_PORT;
151
152 u8CheckSrc = MDrv_XC_MUX_MapInputSourceToVDYMuxPORT(pInstance, u8InputSourceType);
153
154 AIS_Debug(printf("u8CheckSrc=%u\n", u8CheckSrc);)
155
156 return Hal_XC_GetOffLineDetection(pInstance, u8CheckSrc);
157 }
158
159 //------------------------------------------------------------------------------------------------
160 //------------------------------------------------------------------------------------------------
MDrv_XC_SetOffLineDetection(void * pInstance,INPUT_SOURCE_TYPE_t u8InputSourceType)161 void MDrv_XC_SetOffLineDetection (void *pInstance, INPUT_SOURCE_TYPE_t u8InputSourceType )
162 {
163 MS_U8 u8CheckSrc = INPUT_PORT_NONE_PORT;
164 XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
165 UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
166 XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
167 UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
168 XC_OPTEE_MUX_DATA st_xc_mux_data;
169 memset(&st_xc_mux_data,0,sizeof(st_xc_mux_data));
170
171 _XC_ENTRY(pInstance);
172
173 u8CheckSrc = MDrv_XC_MUX_MapInputSourceToVDYMuxPORT(pInstance, u8InputSourceType);
174 AIS_Debug(printf("u8InputSourceType = %x, u8CheckSrc = %x\n", u8InputSourceType, (MS_U16)u8CheckSrc);)
175
176 Hal_XC_SetOfflineDetectClk(pInstance);
177
178 if (u8CheckSrc == INPUT_PORT_NONE_PORT)
179 {
180 Hal_XC_OffLineExit(pInstance);
181 }
182 _XC_RETURN(pInstance);
183
184 if ((u8CheckSrc >= (MS_U8)INPUT_PORT_YMUX_CVBS0) &&
185 (u8CheckSrc <= (MS_U8)INPUT_PORT_YMUX_CVBS7))
186 {
187 MsOS_DelayTask(10);
188
189 _XC_ENTRY(pInstance);
190 AIS_Debug(printf("MDrv_SetOffLineToSog VD Related Signal!\n");)
191 Hal_XC_SetOffLineToSog_AV(pInstance, u8CheckSrc - INPUT_PORT_YMUX_CVBS0);
192 if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
193 (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
194 {
195 MDrv_XC_OPTEE_Mux(pInstance, E_XC_OPTEE_SET_MUX, st_xc_mux_data);
196 }
197
198 MsOS_DelayTask(10);
199 Hal_XC_OffLineInit(pInstance);
200
201 _XC_RETURN(pInstance);
202
203 MsOS_DelayTask(20);
204
205 _XC_ENTRY(pInstance);
206 Hal_XC_WaitForHVCleared_AV(pInstance, u8CheckSrc - INPUT_PORT_YMUX_CVBS0);
207 Hal_XC_TurnOnDetectClkPath(pInstance, SC_SUBWIN_IPMUX_ADC_B);
208 if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
209 (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
210 {
211 MDrv_XC_OPTEE_Mux(pInstance, E_XC_OPTEE_SET_MUX, st_xc_mux_data);
212 }
213 _XC_RETURN(pInstance);
214
215 MsOS_DelayTask(50);
216 }
217 else if((u8CheckSrc >= (MS_U8)INPUT_PORT_ANALOG0)&&
218 (u8CheckSrc <= (MS_U8)INPUT_PORT_ANALOG4))
219 {
220 MsOS_DelayTask(10);
221
222 _XC_ENTRY(pInstance);
223 AIS_Debug(printf("MDrv_SetOffLineToSog_YUV Component!\n");)
224 Hal_XC_SetOffLineToSog_YUV(pInstance, u8CheckSrc - INPUT_PORT_ANALOG0);
225 if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
226 (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
227 {
228 MDrv_XC_OPTEE_Mux(pInstance, E_XC_OPTEE_SET_MUX, st_xc_mux_data);
229 }
230
231 MsOS_DelayTask(10);
232 Hal_XC_OffLineInit(pInstance);
233 _XC_RETURN(pInstance);
234
235 MsOS_DelayTask(20);
236
237 _XC_ENTRY(pInstance);
238 Hal_XC_WaitForHVCleared(pInstance, u8CheckSrc - INPUT_PORT_ANALOG0);
239 Hal_XC_TurnOnDetectClkPath(pInstance, SC_SUBWIN_IPMUX_ADC_B);
240 if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
241 (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
242 {
243 MDrv_XC_OPTEE_Mux(pInstance, E_XC_OPTEE_SET_MUX, st_xc_mux_data);
244 }
245 _XC_RETURN(pInstance);
246
247 MsOS_DelayTask(50);
248 }
249 else if ((u8CheckSrc >= INPUT_PORT_ANALOG0_SYNC) &&
250 (u8CheckSrc <= (MS_U8)INPUT_PORT_ANALOG4_SYNC) )
251 {
252 MsOS_DelayTask(10);
253
254 _XC_ENTRY(pInstance);
255 AIS_Debug(printf("MDrv_SetOffLineToHV VGA!\n");)
256 Hal_XC_SetOffLineToHv(pInstance, u8CheckSrc - INPUT_PORT_ANALOG0_SYNC);
257 if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
258 (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
259 {
260 MDrv_XC_OPTEE_Mux(pInstance, E_XC_OPTEE_SET_MUX, st_xc_mux_data);
261 }
262 _XC_RETURN(pInstance);
263
264 MsOS_DelayTask(20);
265
266 _XC_ENTRY(pInstance);
267 Hal_XC_WaitForHVCleared(pInstance, u8CheckSrc - INPUT_PORT_ANALOG0_SYNC);
268 Hal_XC_TurnOnDetectClkPath(pInstance, SC_SUBWIN_IPMUX_ADC_B);
269 if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
270 (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
271 {
272 MDrv_XC_OPTEE_Mux(pInstance, E_XC_OPTEE_SET_MUX, st_xc_mux_data);
273 }
274 _XC_RETURN(pInstance);
275
276 MsOS_DelayTask(50);
277 }
278 else if ((u8CheckSrc >= INPUT_PORT_DVI0) && (u8CheckSrc <= INPUT_PORT_DVI3))
279 {
280 AIS_Debug(printf("MDrv_SetOffLineToHDMI 1~3!\n");)
281 Hal_XC_SetOffLineToHDMI(pInstance, u8CheckSrc);
282 }
283 else if (u8CheckSrc == INPUT_PORT_MVOP )
284 {
285 AIS_Debug(printf("MDrv_SetOffLineToUSB!\n");)
286 Hal_XC_SetOffLineToUSB(pInstance, u8CheckSrc);
287 }
288 }
289
MDrv_XC_SetOffLineSogThreshold(void * pInstance,MS_U8 u8Threshold)290 MS_BOOL MDrv_XC_SetOffLineSogThreshold(void *pInstance, MS_U8 u8Threshold)
291 {
292 return Hal_XC_SetOffLineSogThreshold(pInstance, u8Threshold);
293 }
294
MDrv_XC_SetOffLineSogBW(void * pInstance,MS_U8 u8BW)295 MS_BOOL MDrv_XC_SetOffLineSogBW(void *pInstance, MS_U8 u8BW)
296 {
297 return Hal_XC_SetOffLineSogBW(pInstance, u8BW);
298 }
299
300 //-------------------------------------------------------------------------------------------------
301 /// Get Offline detection status to specific input source
302 /// @param u8InputSourceType \b IN: the specific input source type to do offline detection
303 //-------------------------------------------------------------------------------------------------
MApi_XC_GetOffLineDetection_U2(void * pInstance,INPUT_SOURCE_TYPE_t u8InputSourceType)304 MS_U8 MApi_XC_GetOffLineDetection_U2( void* pInstance, INPUT_SOURCE_TYPE_t u8InputSourceType )
305 {
306 MS_U8 u8Ret = 0;
307 _XC_ENTRY(pInstance);
308 u8Ret = MDrv_XC_GetOffLineDetection(pInstance, u8InputSourceType);
309 _XC_RETURN(pInstance);
310 return u8Ret;
311 }
312
MApi_XC_GetOffLineDetection(INPUT_SOURCE_TYPE_t u8InputSourceType)313 MS_U8 MApi_XC_GetOffLineDetection( INPUT_SOURCE_TYPE_t u8InputSourceType )
314 {
315 if (pu32XCInst == NULL)
316 {
317 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
318 return 0;
319 }
320
321 stXC_GET_OFFLINE_DETECTION XCArgs;
322 XCArgs.u8InputSourceType = u8InputSourceType;
323 XCArgs.u8ReturnValue = 0;
324
325 if(UtopiaIoctl(pu32XCInst, E_XC_CMD_GET_OFFLINE_DETECTION, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
326 {
327 printf("Obtain XC engine fail\n");
328 return 0;
329 }
330 else
331 {
332 return XCArgs.u8ReturnValue;
333 }
334 }
335
336 //-------------------------------------------------------------------------------------------------
337 /// Set Offline detection to specific input source
338 /// @param u8InputSourceType \b IN: the specific input source type to do offline detection
339 //-------------------------------------------------------------------------------------------------
MApi_XC_SetOffLineDetection_U2(void * pInstance,INPUT_SOURCE_TYPE_t u8InputSourceType)340 void MApi_XC_SetOffLineDetection_U2 ( void* pInstance, INPUT_SOURCE_TYPE_t u8InputSourceType )
341 {
342 MDrv_XC_SetOffLineDetection(pInstance, u8InputSourceType);
343 }
344
MApi_XC_SetOffLineDetection(INPUT_SOURCE_TYPE_t u8InputSourceType)345 void MApi_XC_SetOffLineDetection ( INPUT_SOURCE_TYPE_t u8InputSourceType )
346 {
347 if (pu32XCInst == NULL)
348 {
349 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
350 return;
351 }
352
353 stXC_SET_OFFLINE_DETECTION XCArgs;
354 XCArgs.u8InputSourceType = u8InputSourceType;
355
356 if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_OFFLINE_DETECTION, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
357 {
358 printf("Obtain XC engine fail\n");
359 return;
360 }
361 else
362 {
363 return;
364 }
365 }
366
367 //-------------------------------------------------------------------------------------------------
368 /// Set Offline detection Sog Threshold
369 /// @param u8Threshold \b IN: threshold value t2,u3,u4: 0~31 other chip: 0~255
370 /// @Return TRUE: Successful FALSE: Fail
371 //-------------------------------------------------------------------------------------------------
MApi_XC_SetOffLineSogThreshold_U2(void * pInstance,MS_U8 u8Threshold)372 MS_BOOL MApi_XC_SetOffLineSogThreshold_U2(void* pInstance, MS_U8 u8Threshold)
373 {
374 MS_BOOL bRet = FALSE;
375 _XC_ENTRY(pInstance);
376 bRet = MDrv_XC_SetOffLineSogThreshold(pInstance, u8Threshold);
377 _XC_RETURN(pInstance);
378 return bRet;
379 }
380
MApi_XC_SetOffLineSogThreshold(MS_U8 u8Threshold)381 MS_BOOL MApi_XC_SetOffLineSogThreshold(MS_U8 u8Threshold)
382 {
383 if (pu32XCInst == NULL)
384 {
385 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
386 return FALSE;
387 }
388
389 stXC_SET_OFFLINE_SOG_THRESHOLD XCArgs;
390 XCArgs.u8Threshold = u8Threshold;
391 XCArgs.bReturnValue = FALSE;
392
393 if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_OFFLINE_SOG_THRESHOLD, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
394 {
395 printf("Obtain XC engine fail\n");
396 return FALSE;
397 }
398 else
399 {
400 return XCArgs.bReturnValue;
401 }
402 }
403
404 //-------------------------------------------------------------------------------------------------
405 /// Set Offline Detection Sog filter bandwidth
406 /// @param u8BW \b IN: bandwidth value t2,u3,u4: 0~7 other chip: 0~31
407 /// @Return TRUE: Successful FALSE: Fail
408 //-------------------------------------------------------------------------------------------------
MApi_XC_SetOffLineSogBW_U2(void * pInstance,MS_U8 u8BW)409 MS_BOOL MApi_XC_SetOffLineSogBW_U2(void* pInstance, MS_U8 u8BW)
410 {
411 MS_BOOL bRet = FALSE;
412 _XC_ENTRY(pInstance);
413 bRet = MDrv_XC_SetOffLineSogBW(pInstance, u8BW);
414 _XC_RETURN(pInstance);
415 return bRet;
416 }
417
MApi_XC_SetOffLineSogBW(MS_U8 u8BW)418 MS_BOOL MApi_XC_SetOffLineSogBW(MS_U8 u8BW)
419 {
420 if (pu32XCInst == NULL)
421 {
422 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
423 return FALSE;
424 }
425
426 stXC_SET_OFFLINE_SOG_BW XCArgs;
427 XCArgs.u8BW = u8BW;
428 XCArgs.bReturnValue = FALSE;
429
430 if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_OFFLINE_SOG_BW, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
431 {
432 printf("Obtain XC engine fail\n");
433 return FALSE;
434 }
435 else
436 {
437 return XCArgs.bReturnValue;
438 }
439 }
440
MApi_XC_OffLineInit_U2(void * pInstance)441 MS_BOOL MApi_XC_OffLineInit_U2(void* pInstance)
442 {
443 _XC_ENTRY(pInstance);
444 Hal_XC_OffLineInit(pInstance);
445 MDrv_XC_SetOffLineSogThreshold(pInstance, 0x40);
446 MDrv_XC_SetOffLineSogBW(pInstance, 0x1F);
447 _XC_RETURN(pInstance);
448 return TRUE;
449 }
450
MApi_XC_OffLineInit(void)451 MS_BOOL MApi_XC_OffLineInit(void)
452 {
453 if (pu32XCInst == NULL)
454 {
455 printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
456 return FALSE;
457 }
458
459 stXC_SET_OFFLINE_INIT XCArgs;
460 XCArgs.bReturnValue = FALSE;
461
462 if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_OFFLINE_INIT, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
463 {
464 printf("Obtain XC engine fail\n");
465 return FALSE;
466 }
467 else
468 {
469 return XCArgs.bReturnValue;
470 }
471 }
472
473