xref: /utopia/UTPA2-700.0.x/modules/graphic/drv/gopsc/drv_gop_sc.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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 ////////////////////////////////////////////////////////////////////////////////#include <stdio.h>
94 #define DRV_GOP_SC_C
95 
96 #include "MsCommon.h"
97 #include "MsOS.h"
98 
99 #include "drv_gop_sc.h"
100 #include "mhal_gop_sc.h"
101 
102 #ifdef MSOS_TYPE_LINUX_KERNEL
103 #include <linux/string.h>
104 #include <asm/div64.h>
105 #else
106 #include <string.h>
107 //#define do_div(x,y) ((x)/=(y))
108 #endif
109 
110 
111 //-------------------------------------------------------------------------------------------------
112 //  Local Defines
113 //-------------------------------------------------------------------------------------------------
114 #define DBG_GOP_SC(x) //x
115 
116 //-------------------------------------------------------------------------------------------------
117 //  Local Variables
118 //-------------------------------------------------------------------------------------------------
119 static DRV_GOP_SC_INFO gGopSC_Info = {0};
120 static GOP_SC_REF         gGopSC_Ref = {0};
121 
122 //-------------------------------------------------------------------------------------------------
123 //  Local Functions
124 //-------------------------------------------------------------------------------------------------
_GCD(MS_U32 u32A,MS_U32 u32B)125 static MS_U32 _GCD(MS_U32 u32A,MS_U32 u32B)
126 {
127     MS_U32 u32R;
128 
129 #ifdef  MSOS_TYPE_LINUX_KERNEL
130     while((u32R=do_div(u32A,u32B))!=0)
131 #else
132     while((u32R=u32A%u32B)!=0)
133 #endif
134     {
135         u32A=u32B;
136         u32B=u32R;
137     }
138 
139     return u32B;
140 }
141 
_ReductionFrac(MS_U32 * pu32A,MS_U32 * pu32B)142 static MS_BOOL _ReductionFrac (MS_U32 *pu32A,MS_U32 *pu32B)
143 {
144     MS_U32 u32GCD;
145     while(1)
146     {
147         if( (*pu32A<3000) && (*pu32B<3000))  return TRUE;
148         if( (u32GCD = _GCD(*pu32A,*pu32B))==1) return TRUE;
149         *pu32A /= u32GCD;
150         *pu32B /= u32GCD;
151     }
152     return TRUE;
153 }
154 
_MultiplFrac(MS_U32 * pu32A,MS_U32 * pu32B)155 static MS_BOOL _MultiplFrac(MS_U32 *pu32A,MS_U32 *pu32B)
156 {
157     while(1)
158     {
159         if( ( (*pu32A<<1)<3000) && ( (*pu32B<<1) <3000))
160         {
161              *pu32A<<=1;
162              *pu32B<<=1;
163         }
164         else
165         {
166             return TRUE;
167         }
168     }
169     return TRUE;
170 }
171 
_MDrv_GOP_SC_Set_ScalingFac(VOID)172 static MS_BOOL _MDrv_GOP_SC_Set_ScalingFac(VOID)
173 {
174     MS_U32 u32VscFac,u32HscFac;
175 
176     MS_U32 u32Fac ;
177 
178     DBG_GOP_SC(printf("[GOP_SC] _MDrv_GOP_SC_Set_ScalingFac\n");)
179     DBG_GOP_SC(printf("[GOP_SC] VdeIn = %x \t H=%x\n",gGopSC_Info.InCfg.u16VdeIn,gGopSC_Ref.u16ValidH);)
180     DBG_GOP_SC(printf("[GOP_SC] ValidV = %x\t HdeIn=%x\n",gGopSC_Ref.u16ValidV,gGopSC_Info.InCfg.u16HdeIn);)
181 
182     u32Fac = gGopSC_Info.InCfg.u16VdeIn;
183     u32VscFac =(MS_U32) V_ScalingDownRatio(u32Fac, gGopSC_Ref.u16ValidV);
184 
185     //If H in = H out , must disable H Scaling
186     if(gGopSC_Ref.u16ValidH == gGopSC_Info.InCfg.u16HdeIn)
187         u32HscFac = 0;
188     else
189     {
190         u32Fac = gGopSC_Ref.u16ValidH;
191         u32HscFac = (MS_U32) H_ScalingDownRatio(u32Fac, gGopSC_Info.InCfg.u16HdeIn);
192     }
193 
194     DBG_GOP_SC(printf("[GOP_SC] Scalilng FacV = %lx \t Scaling FacH = %lx\n",u32VscFac,u32HscFac);)
195 
196     //_XC_ENTRY();
197     HAL_GOP_SC_Set_ScalingFac(u32VscFac,u32HscFac);
198     //_XC_RETURN();
199 
200     return TRUE;
201 }
202 
_MDrv_GOP_SC_AheadMode(VOID)203 static MS_BOOL _MDrv_GOP_SC_AheadMode(VOID)
204 {
205     MS_U16 u16VRatio,u16Mod;
206     MS_BOOL bEnMode = TRUE;
207 
208     #ifdef MSOS_TYPE_LINUX_KERNEL
209     u16VRatio = gGopSC_Info.InCfg.u16VdeIn;
210     u16Mod = do_div(u16VRatio,  gGopSC_Ref.u16ValidV);
211     #else
212     u16VRatio = gGopSC_Info.InCfg.u16VdeIn / gGopSC_Ref.u16ValidV;
213     u16Mod = gGopSC_Info.InCfg.u16VdeIn - (u16VRatio* gGopSC_Ref.u16ValidV);
214     #endif
215 
216     bEnMode = ( ((u16Mod>0) && (u16VRatio>=2))) ? FALSE : TRUE;
217 
218     DBG_GOP_SC(printf("[GOP_SC] Vratio =%d \t Mod = %d\n",u16VRatio,u16Mod);)
219     DBG_GOP_SC(printf("[GOP_SC] AheadMode =%d\n",bEnMode);)
220 
221     //_XC_ENTRY();
222     HAL_GOP_SC_AheadMode(bEnMode);
223     //_XC_RETURN();
224 
225     if( u16VRatio>=2)
226     {
227         gGopSC_Ref.u16VFacInt = 3;
228         gGopSC_Ref.u16VFacFrac = 5;
229     }
230     else
231     {
232         gGopSC_Ref.u16VFacInt = 2;
233         gGopSC_Ref.u16VFacFrac = 0;
234     }
235 
236     return TRUE;
237 }
238 
_MDrv_GOP_SC_FreqSync(VOID)239 static MS_BOOL _MDrv_GOP_SC_FreqSync(VOID)
240 {
241     //idclk_div & odclk_div
242     MS_U32 u32FreqIn,u32FreqOut;
243 
244     u32FreqIn   = gGopSC_Info.InCfg.u16VttIn  *  gGopSC_Info.InCfg.u16HttIn;
245     u32FreqOut = ((MS_U32)(gGopSC_Info.OutCfg.u16VttOut)* (MS_U32)(gGopSC_Info.OutCfg.u16HttOut))*4;
246     if(!gGopSC_Info.OutCfg.bInterlace)
247         u32FreqOut *= 2;
248 
249     DBG_GOP_SC(printf("[GOP_SC] _MDrv_GOP_SC_FreqSync\n"););
250     DBG_GOP_SC(printf("[GOP_SC] 32FreqIn=%lx \t u32FreqOut=%lx \n",u32FreqIn,u32FreqOut););
251 
252     _ReductionFrac(&u32FreqIn, &u32FreqOut);
253     _MultiplFrac(&u32FreqIn,&u32FreqOut);
254 
255     gGopSC_Ref.u32IDclk  = u32FreqIn;
256     gGopSC_Ref.u32ODclk =  u32FreqOut;
257 
258     if(gGopSC_Ref.u32IDclk>0xFFFFFF || gGopSC_Ref.u32ODclk>0xFFFFFF )
259             DBG_GOP_SC(printf("[GOP_SC] ASSERT !!! idclk/odclk overflow\n");)
260 
261     DBG_GOP_SC(printf("[GOP_SC] idclk=%lx \t odclk=%lx\n",gGopSC_Ref.u32IDclk,gGopSC_Ref.u32ODclk););
262 
263     //_XC_ENTRY();
264     HAL_GOP_SC_FreqSync((gGopSC_Ref.u32IDclk&0xFFFFFF),(gGopSC_Ref.u32ODclk&0xFFFFFF));
265     //_XC_RETURN();
266 
267     return TRUE;
268 }
269 
_MDrv_GOP_SC_PhaseSync(VOID)270 static MS_BOOL _MDrv_GOP_SC_PhaseSync(VOID)
271 {
272     DBG_GOP_SC(printf("[GOP_SC]_MDrv_GOP_SC_PhaseSync\n"););
273 
274     //ivs_ref
275     MS_U32 u32TotalOffset;
276     MS_U32 u32IntY,u32ModF;
277     MS_U32 u32OffsetY,u32OffsetX;
278 
279     u32TotalOffset =  gGopSC_Ref.u16VFacInt *10 + gGopSC_Ref.u16VFacFrac ;
280     u32TotalOffset *= (gGopSC_Ref.u16ValidV/(1+gGopSC_Info.OutCfg.bInterlace));
281 
282     #ifdef MSOS_TYPE_LINUX_KERNEL
283     u32IntY = u32TotalOffset;
284     u32ModF = do_div(u32IntY,  (gGopSC_Info.InCfg.u16VdeIn*10));
285     #else
286     u32IntY = (u32TotalOffset / (gGopSC_Info.InCfg.u16VdeIn*10)) ;
287     u32ModF = u32TotalOffset - (u32IntY* gGopSC_Info.InCfg.u16VdeIn*10);
288     #endif
289 
290     u32OffsetY = u32IntY;
291     u32OffsetX = ((u32ModF<<7) *2 *gGopSC_Info.OutCfg.u16HttOut)/(gGopSC_Info.InCfg.u16VdeIn*10);
292     u32OffsetX >>=7;
293 
294     DBG_GOP_SC(printf("[GOP_SC] Offset_line=%ld\t Offset_pixel=%ld\n",u32OffsetY,u32OffsetX);)
295     DBG_GOP_SC(printf("[GOP_SC] u8SkipV=%d\t u8SkipH=%d\n",gGopSC_Ref.u8SkipV,gGopSC_Ref.u8SkipH);)
296 
297     if(u32OffsetX>255)
298     {
299         gGopSC_Ref.u16VE_RefY= 23-(u32OffsetY+1)-(gGopSC_Ref.u8SkipV/(2*(1+gGopSC_Info.OutCfg.bInterlace)));
300         gGopSC_Ref.u16VE_RefX = 255 + 2* gGopSC_Info.OutCfg.u16HttOut-u32OffsetX;
301     }
302     else
303     {
304         gGopSC_Ref.u16VE_RefY = 23-u32OffsetY-(gGopSC_Ref.u8SkipV/(2*(1+gGopSC_Info.OutCfg.bInterlace)));
305         gGopSC_Ref.u16VE_RefX = 255 -u32OffsetX;
306     }
307 
308     DBG_GOP_SC(printf("[GOP_SC] u16VE_RefY=%d\t u16VE_RefX=%d\n",gGopSC_Ref.u16VE_RefY,gGopSC_Ref.u16VE_RefX);)
309 
310     if(gGopSC_Info.u8TVSystem == 2) //EN_GOP_SC_PAL_M
311     {
312         gGopSC_Ref.u16VE_RefY-=3;
313     }
314 
315     //_XC_ENTRY();
316     HAL_GOP_SC_PhaseSync(gGopSC_Ref.u16VE_RefY ,gGopSC_Ref.u16VE_RefX,
317                   gGopSC_Info.InCfg.u16Hde_St, gGopSC_Info.InCfg.u16Vde_St,gGopSC_Info.InCfg.u16HttIn);
318     //_XC_RETURN();
319 
320     return TRUE;
321 }
322 
_MDrv_GOP_SC_CheckSyncDone(VOID)323 static MS_BOOL _MDrv_GOP_SC_CheckSyncDone(VOID)
324 {
325     //Check lock_done
326     MS_U32 u32Time,u32TimeOut;
327     MS_U8 u8Status;
328     u32Time = MsOS_GetSystemTime();
329     u32TimeOut = 5000;
330 
331     while(1)
332     {
333         u8Status= HAL_VEPLL_Check_LockDone();
334         if( u8Status == 0x01)
335         {
336             //printf("[%s]-[%d] : Lock done. \n", __FUNCTION__, __LINE__);
337             return TRUE;
338         }
339 
340         if ( ( MsOS_GetSystemTime() - u32Time) >= u32TimeOut )
341         {
342             printf("[%s]-[%d] : Timeout . \n", __FUNCTION__, __LINE__);
343             return FALSE;
344         }
345     }
346     return TRUE;
347 }
348 
_MDrv_GOP_SC_SkipFun(VOID)349 static MS_BOOL _MDrv_GOP_SC_SkipFun(VOID)
350 {
351     MS_U32 u32VttIn=0 ,u32VttOut=0 ;
352     MS_U32 u32ValidV= 0,u32ValidH= 0;
353 
354     u32VttIn   = gGopSC_Info.InCfg.u16VttIn;
355     u32VttOut = gGopSC_Info.OutCfg.u16VttOut;
356 
357     u32ValidV = (gGopSC_Info.InCfg.u16VdeIn*u32VttOut) / u32VttIn;
358     u32ValidH = (u32ValidV*gGopSC_Info.OutCfg.u16HdeOut) / gGopSC_Info.OutCfg.u16VdeOut;
359 
360     //ASSERT((u32ValidV<g_GOP_SC_Info.u16VdeOut)||(u32ValidH<g_GOP_SC_Info.u16HdeOut));
361 
362     gGopSC_Ref.u16ValidH = (MS_U16)(u32ValidH);
363     gGopSC_Ref.u16ValidV = (MS_U16)(u32ValidV);
364 
365     gGopSC_Ref.u8SkipH = (MS_U8)(u32ValidH-gGopSC_Info.OutCfg.u16HdeOut);
366     gGopSC_Ref.u8SkipV = (MS_U8)(u32ValidV-gGopSC_Info.OutCfg.u16VdeOut);
367 
368     //_XC_ENTRY();
369     HAL_GOP_SC_SkipFun(gGopSC_Ref.u8SkipV,gGopSC_Ref.u8SkipH,
370                                     gGopSC_Ref.u16ValidV,gGopSC_Ref.u16ValidH);
371     //_XC_RETURN();
372     DBG_GOP_SC(printf("[GOP_SC] ValidV = %ld \t ValidH = %ld\n",u32ValidV,u32ValidH);)
373     DBG_GOP_SC(printf("[GOP_SC] u8SkipV=%d\t u8SkipH=%d\n",gGopSC_Ref.u8SkipV,gGopSC_Ref.u8SkipH);)
374 
375     return TRUE;
376 }
377 
_MDrv_GOP_SC_SetHVSP(VOID)378 static MS_BOOL _MDrv_GOP_SC_SetHVSP(VOID)
379 {
380     //_XC_ENTRY();
381     HAL_GOP_SC_SetHVSP(gGopSC_Info.InCfg.u16HdeIn, gGopSC_Info.InCfg.u16VdeIn,
382                                     gGopSC_Info.OutCfg.u16HdeOut,gGopSC_Ref.u16ValidV);
383     //_XC_RETURN();
384     DBG_GOP_SC(printf("[GOP_SC] src_wd=%d\t src_ht=%d\n",gGopSC_Info.InCfg.u16HdeIn,gGopSC_Info.InCfg.u16VdeIn);)
385     DBG_GOP_SC(printf("[GOP_SC] dst_wd=%d\t dst_ht=%d\n",gGopSC_Info.OutCfg.u16HdeOut,gGopSC_Ref.u16ValidV);)
386     return TRUE;
387 
388 }
389 
_MDrv_GOP_SC_P2I(MS_U8 u8EnMode)390 static MS_BOOL _MDrv_GOP_SC_P2I(MS_U8 u8EnMode)
391 {
392     HAL_GOP_SC_P2I(u8EnMode);
393     return TRUE;
394 }
395 
396 //-------------------------------------------------------------------------------------------------
397 //  Global Functions
398 //-------------------------------------------------------------------------------------------------
MDrv_GOP_SC_Init(void)399 MS_BOOL MDrv_GOP_SC_Init(void)
400 {
401     //Initial Local Variable
402     memset(&gGopSC_Ref, 0 , sizeof(GOP_SC_REF) );
403     memset(&gGopSC_Info, 0 , sizeof(DRV_GOP_SC_INFO) );
404 
405     HAL_GOP_SC_SetClock(EN_DST_FBL);        //Default is FBL case , VEPLL mode
406     HAL_VEPLL_Reset(TRUE);
407 
408     //default setting
409     HAL_VEPLL_PLL_Ctrl(0x08,0x08,0x02);     //0x288
410     HAL_VEPLL_PllSet(0x19999999);             //initial PLL set
411 
412     //[FSYNC]
413     HAL_GOP_SC_Set_PllCfg();
414 
415     HAL_VEPLL_Reset(FALSE);
416     HAL_VEPLL_PowerDown(FALSE);             //Disable PowerDown LPLL
417 
418     return TRUE;
419 }
420 
MDrv_GOP_SC_Init_riu_base(MS_VIRT vriu_base)421 VOID MDrv_GOP_SC_Init_riu_base( MS_VIRT vriu_base )
422 {
423     HAL_GOP_SC_Init_riu_base(vriu_base);
424     return;
425 }
426 
427 
MDrv_GOP_SC_MuxSel(MS_U8 u8Source)428 MS_BOOL MDrv_GOP_SC_MuxSel(MS_U8 u8Source)
429 {
430     //_XC_ENTRY();
431     gGopSC_Info.u8MuxSel = u8Source;
432     HAL_GOP_SC_MuxSel(u8Source);
433     //_XC_RETURN();
434     return TRUE;
435 }
436 
MDrv_GOP_SC_SetParams(DRV_GOP_SC_InCfg * pInCfg,DRV_GOP_SC_OutCfg * pOutCfg,MS_U8 u8TvSys)437 VOID MDrv_GOP_SC_SetParams(DRV_GOP_SC_InCfg *pInCfg,DRV_GOP_SC_OutCfg *pOutCfg,MS_U8 u8TvSys)
438 {
439     gGopSC_Info.u8TVSystem = u8TvSys;
440     memcpy(&gGopSC_Info.InCfg,pInCfg,sizeof(DRV_GOP_SC_InCfg));
441     memcpy(&gGopSC_Info.OutCfg,pOutCfg,sizeof(DRV_GOP_SC_OutCfg));
442 }
443 
MDrv_GOP_SC_SetCfg(VOID)444 MS_BOOL  MDrv_GOP_SC_SetCfg(VOID)
445 {
446     //Scaling & Skip Fun
447     _MDrv_GOP_SC_SkipFun();
448     _MDrv_GOP_SC_SetHVSP();
449     _MDrv_GOP_SC_Set_ScalingFac();
450     _MDrv_GOP_SC_AheadMode();
451     _MDrv_GOP_SC_P2I(TRUE);
452 
453     return TRUE;
454 }
455 
MDrv_GOP_SC_SetDst(DRV_GOP_SC_Dst stDst)456 MS_BOOL MDrv_GOP_SC_SetDst(DRV_GOP_SC_Dst stDst)
457 {
458     gGopSC_Info.stDst = stDst;
459 
460     switch(stDst)
461     {
462         case EN_DST_FB : //case 2
463             HAL_VEPLL_PowerDown(TRUE);  //PowerDown LPLL
464             HAL_GOP_SC_SetClock(EN_DST_FB);
465             HAL_GOP_SC_Vsync(EN_VSYNC_VE);
466             break;
467 
468         case EN_DST_FBL: //case 3, 4
469             HAL_VEPLL_Limit_d5d6d7(0x00000100);     //limit d5d6d7
470             HAL_VEPLL_FPLL_Enable(FALSE);
471 
472             //initial PLL set
473 #if (VEPLL_FIXED_PLL)
474             if(gGopSC_Info.InCfg.u16HdeIn > 720 ) //HD timing
475             {
476                 HAL_VEPLL_PLL_Ctrl(0x08,0x08,0x02);
477                 HAL_VEPLL_PllSet(0x19999999);
478             }
479             else
480             {
481                 MS_U32 u32HdmiPll = HAL_VEPLL_Get_HdmiPllSet();
482                 HAL_VEPLL_PLL_Ctrl(0x00,0x01,0x03);
483                 HAL_VEPLL_PllSet(u32HdmiPll);
484             }
485 #else
486             HAL_VEPLL_PLL_Ctrl(0x08,0x08,0x02);
487             HAL_VEPLL_PllSet(0x19999999);
488 #endif
489             HAL_GOP_SC_Vsync(EN_VSYNC_SC);
490             break;
491 
492         default :
493             DBG_GOP_SC(printf("[GOP_SC] Fail GOP_SC Path!\n"));
494             break;
495     }
496     return TRUE;
497 }
498 
MDrv_GOP_SC_SetLock(VOID)499 MS_BOOL MDrv_GOP_SC_SetLock(VOID)
500 {
501     _MDrv_GOP_SC_FreqSync();
502     _MDrv_GOP_SC_PhaseSync();
503 
504     return TRUE;
505 }
506 
MDrv_GOP_SC_SetFPLL_Enable(MS_BOOL bEnable)507 MS_BOOL MDrv_GOP_SC_SetFPLL_Enable(MS_BOOL bEnable)
508 {
509     MS_BOOL bStatus = FALSE;
510 
511 #if (VEPLL_FIXED_PLL)
512     if(gGopSC_Info.InCfg.u16HdeIn > 720 ) //HD timing
513     {
514         HAL_VEPLL_PllSet(0x19999999);
515     }
516     else
517     {
518         MS_U32 u32HdmiPll = HAL_VEPLL_Get_HdmiPllSet();
519         HAL_VEPLL_PllSet(u32HdmiPll);
520     }
521 #else
522     HAL_VEPLL_PllSet(0x19999999);
523 #endif
524 
525     HAL_VEPLL_LockFreq_Enable(bEnable);
526     HAL_VEPLL_FPLL_Enable(bEnable);
527 
528     bStatus = _MDrv_GOP_SC_CheckSyncDone();
529 
530 #if (VEPLL_FIXED_PLL)
531     if( (gGopSC_Info.InCfg.u16HdeIn <= 720) && bStatus ) //SD timing
532     {
533         HAL_VEPLL_Limit_d5d6d7(0x00000000);     //limit d5d6d7
534     }
535 #endif
536 
537     return TRUE;
538 }
539 
540