xref: /utopia/UTPA2-700.0.x/modules/xc/hal/mooney/xc/mhal_offline.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) 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 #define  MHAL_OFFLINE_C
95 
96 
97 //-------------------------------------------------------------------------------------------------
98 //  Include Files
99 //-------------------------------------------------------------------------------------------------
100 
101 // Common Definition
102 #include "MsCommon.h"
103 #include "mhal_xc_chip_config.h"
104 
105 // Registers
106 #include "drvXC_IOPort.h"
107 #include "utopia.h"
108 #include "utopia_dapi.h"
109 #include "xc_hwreg_utility2.h"
110 #include "hwreg_sc.h"
111 #include "hwreg_adc_atop.h"
112 
113 #include "xc_Analog_Reg.h"
114 #include "mhal_mux.h"
115 #include "mhal_offline.h"
116 #include "mhal_mux.h"
117 #include "hwreg_sc.h"
118 #include "drvXC_IOPort.h"
119 #include "hwreg_dvi_atop.h"
120 #include "hwreg_hdmi.h"
121 #include "hwreg_pm_sleep.h"
122 #include "hwreg_ipmux.h"
123 
124 #include "apiXC.h"
125 #include "drv_sc_display.h"
126 #include "drv_sc_isr.h"
127 #include "apiXC_Adc.h"
128 #include "apiXC_PCMonitor.h"
129 #include "apiXC_ModeParse.h"
130 #include "apiXC_Auto.h"
131 #include "drvXC_HDMI_if.h"
132 #include "mvideo_context.h"
133 #include "drv_sc_ip.h"
134 #if (LD_ENABLE==1)
135 #include "mdrv_ld.h"
136 #include "mdrv_ldalgo.h"
137 #endif
138 #include "mdrv_sc_3d.h"
139 #include "drv_sc_menuload.h"
140 #include "drvXC_ADC_Internal.h"
141 #include "mhal_sc.h"
142 #if FRC_INSIDE
143 #include "mdrv_frc.h"
144 #include "mhal_frc.h"
145 #endif
146 #include "XC_private.h"
147 #include "mhal_adc.h"
148 
149 //-------------------------------------------------------------------------------------------------
150 //  Driver Compiler Options
151 //-------------------------------------------------------------------------------------------------
152 
153 
154 //-------------------------------------------------------------------------------------------------
155 //  Local Defines
156 //-------------------------------------------------------------------------------------------------
157 #define    AIS_HalDebug(x)    //x
158 
159 //-------------------------------------------------------------------------------------------------
160 //  Local Structures
161 //-------------------------------------------------------------------------------------------------
162 
163 
164 //-------------------------------------------------------------------------------------------------
165 //  Global Variables
166 //-------------------------------------------------------------------------------------------------
167 
168 
169 //-------------------------------------------------------------------------------------------------
170 //  Local Variables
171 //-------------------------------------------------------------------------------------------------
172 
173 
174 //-------------------------------------------------------------------------------------------------
175 //  Debug Functions
176 //-------------------------------------------------------------------------------------------------
177 
178 
179 //-------------------------------------------------------------------------------------------------
180 //  Local Functions
181 //-------------------------------------------------------------------------------------------------
182 
183 
184 //-------------------------------------------------------------------------------------------------
185 //  Global Functions
186 //-------------------------------------------------------------------------------------------------
187 
188 
189 //------------------------------------------------------------------------------------------------
190 //
191 //------------------------------------------------------------------------------------------------
Hal_XC_WaitForHVCleared_AV(void * pInstance,MS_U8 Channel)192 void Hal_XC_WaitForHVCleared_AV(void *pInstance, MS_U8 Channel)
193 {
194     MS_U16 u16Hcnt, u16Vcnt;
195     MS_U16 u16Count=0;
196 
197     u16Hcnt = Hal_XC_GetOffLineOfH(pInstance);
198     u16Vcnt = Hal_XC_GetOffLineOfV(pInstance);
199     while((u16Hcnt != 0x3fff)&&(u16Vcnt !=0x7ff)
200             &&(u16Hcnt != 0)&&(u16Vcnt !=0))
201     {
202         AIS_HalDebug(printf("u16Count=%u, Channel =%u, MApi_XC_GetOffLineDetection: vcnt=%x hcnt=%x\n", u16Count,Channel, u16Vcnt,u16Hcnt );)
203         u16Count++;
204         MsOS_DelayTask(10);
205         u16Hcnt = Hal_XC_GetOffLineOfH(pInstance);
206         u16Vcnt = Hal_XC_GetOffLineOfV(pInstance);
207         AIS_HalDebug(printf("u16Count=%u, Channel =%u, MApi_XC_GetOffLineDetection: vcnt=%x hcnt=%x\n", u16Count++,Channel, u16Vcnt,u16Hcnt );)
208         if(u16Count>=0x100)
209         {
210             AIS_HalDebug(printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");)
211             AIS_HalDebug(printf("!!!!!!!!!!!!!!!!!!!!!!Hal_XC_WaitForHVCleared(): reset fail!!!!!!!!!!!!!!!!!\n");)
212             AIS_HalDebug(printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");)
213             return;
214         }
215     }
216 }
217 
Hal_XC_WaitForHVCleared(void * pInstance,MS_U8 Channel)218 void Hal_XC_WaitForHVCleared(void *pInstance, MS_U8 Channel)
219 {
220     MS_U16 u16Hcnt, u16Vcnt;
221     MS_U16 u16Count=0;
222 
223     u16Hcnt = Hal_XC_GetOffLineOfH(pInstance);
224     u16Vcnt = Hal_XC_GetOffLineOfV(pInstance);
225     while((u16Hcnt != 0x3fff)&&(u16Vcnt !=0x7ff)
226            &&(u16Hcnt != 0)&&(u16Vcnt !=0))
227     {
228         AIS_HalDebug(printf("u16Count=%u, Channel =%u, MApi_XC_GetOffLineDetection: vcnt=%x hcnt=%x\n", u16Count,Channel, u16Vcnt,u16Hcnt );)
229         u16Count++;
230         //reset offline ip
231         SC_W2BYTEMSK(0, REG_SC_BK00_02_L, BIT(5), 0xFF );
232         MsOS_DelayTask(1);
233         SC_W2BYTEMSK(0, REG_SC_BK00_02_L, 0x00, 0xFF );
234 
235         MsOS_DelayTask(10);
236         u16Hcnt = Hal_XC_GetOffLineOfH(pInstance);
237         u16Vcnt = Hal_XC_GetOffLineOfV(pInstance);
238         AIS_HalDebug(printf("u16Count=%u, Channel =%u, MApi_XC_GetOffLineDetection: vcnt=%x hcnt=%x\n", u16Count++,Channel, u16Vcnt,u16Hcnt );)
239         if(u16Count>=0x100)
240         {
241             AIS_HalDebug(printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");)
242             AIS_HalDebug(printf("!!!!!!!!!!!!!!!!!!!!!!Hal_XC_WaitForHVCleared(): reset fail!!!!!!!!!!!!!!!!!\n");)
243             AIS_HalDebug(printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");)
244             return;
245         }
246     }
247 }
248 
Hal_XC_SetOffLineToSog_AV(void * pInstance,MS_U8 Channel)249 void Hal_XC_SetOffLineToSog_AV( void *pInstance, MS_U8 Channel )
250 {
251     W2BYTEMSK(REG_ADC_ATOP_3C_L, 0, BIT(13) );
252     OS_DELAY_TASK(1);
253     W2BYTEMSK(REG_ADC_ATOP_3C_L, BIT(13), BIT(13) );
254     SC_W2BYTE(0, REG_SC_BK13_02_L, 0x0071);
255     Hal_XC_TurnOnDetectClkPath(pInstance, SC_SUBWIN_IPMUX_MLINK);
256 
257     MDrv_Write2Byte(REG_ADC_ATOP_04_L, (MDrv_Read2Byte(REG_ADC_ATOP_04_L)&(0xFDE2)));
258     MDrv_Write2Byte(REG_ADC_ATOP_05_L, (MDrv_Read2Byte(REG_ADC_ATOP_05_L)&(0xF7CF)));
259     MDrv_Write2Byte(REG_ADC_ATOP_06_L, 0);
260     MDrv_Write2ByteMask(REG_ADC_ATOP_5E_L, 0, 0x3fc);
261     MDrv_Write2ByteMask(REG_ADC_ATOP_5A_L, 0, 0xC0);//PD_LDO25_ADCA,PD_LDO25_ADCB
262     MDrv_WriteByte(REG_ADC_ATOP_3D_L, (MDrv_ReadByte(REG_ADC_ATOP_3D_L) & 0xf0) | (Channel + 3));
263     AIS_HalDebug(printf("%s: SOG offline mux -> %d\n", __FUNCTION__, (Channel + 3)));
264 }
265 //------------------------------------------------------------------------------------------------
266 //
267 //------------------------------------------------------------------------------------------------
Hal_XC_SetOffLineToSog_YUV(void * pInstance,MS_U8 Channel)268 void Hal_XC_SetOffLineToSog_YUV( void *pInstance, MS_U8 Channel )
269 {
270     W2BYTEMSK(REG_ADC_ATOP_3C_L, 0, BIT(13) );
271     OS_DELAY_TASK(1);
272     W2BYTEMSK(REG_ADC_ATOP_3C_L, BIT(13), BIT(13) );
273     SC_W2BYTE(0, REG_SC_BK13_02_L, 0x0071);
274     Hal_XC_TurnOnDetectClkPath(pInstance, SC_SUBWIN_IPMUX_MLINK);
275     MDrv_Write2Byte(REG_ADC_ATOP_04_L, (MDrv_Read2Byte(REG_ADC_ATOP_04_L)&(0xFDE2)));
276     MDrv_Write2Byte(REG_ADC_ATOP_05_L, (MDrv_Read2Byte(REG_ADC_ATOP_05_L)&(0xF7CF)));
277     MDrv_Write2Byte(REG_ADC_ATOP_06_L, 0);
278     MDrv_Write2ByteMask(REG_ADC_ATOP_5E_L, 0, 0x3fc);
279     MDrv_Write2ByteMask(REG_ADC_ATOP_5A_L, 0, 0xC0);//PD_LDO25_ADCA,PD_LDO25_ADCB
280     if(Hal_ADC_ISOG_CheckEnabled(pInstance))
281     {
282         // Internal SOG & re-route SOG signal to channel 12~14 (Original is 0~2)
283         MDrv_WriteByte(REG_ADC_ATOP_3D_L, (MDrv_ReadByte(REG_ADC_ATOP_3D_L) & 0xf0) | (Channel+12) );
284     }
285     else
286     {
287         MDrv_WriteByte(REG_ADC_ATOP_3D_L, (MDrv_ReadByte(REG_ADC_ATOP_3D_L) & 0xf0) | Channel);
288     }
289 }
290 //------------------------------------------------------------------------------------------------
291 //
292 //------------------------------------------------------------------------------------------------
Hal_XC_SetOffLineToHv(void * pInstance,MS_U8 Channel)293 void Hal_XC_SetOffLineToHv( void *pInstance, MS_U8 Channel )
294 {
295     W2BYTEMSK(REG_ADC_ATOP_3C_L, 0, BIT(13) );
296     OS_DELAY_TASK(1);
297     W2BYTEMSK(REG_ADC_ATOP_3C_L, BIT(13), BIT(13) );
298     SC_W2BYTE(0, REG_SC_BK13_02_L,0x0001);
299     Hal_XC_TurnOnDetectClkPath(pInstance, SC_SUBWIN_IPMUX_MLINK);
300     MDrv_Write2Byte(REG_ADC_ATOP_04_L, (MDrv_Read2Byte(REG_ADC_ATOP_04_L)&(0xFDE2)));
301     MDrv_Write2Byte(REG_ADC_ATOP_05_L, (MDrv_Read2Byte(REG_ADC_ATOP_05_L)&(0xF7CF)));
302     MDrv_Write2Byte(REG_ADC_ATOP_06_L, 0);
303     MDrv_Write2ByteMask(REG_ADC_ATOP_5E_L, 0, 0x3fc);
304     MDrv_Write2ByteMask(REG_ADC_ATOP_5A_L, 0, 0x40);//PD_LDO25_ADCA
305     MDrv_WriteByte(REG_ADC_ATOP_01_L, (MDrv_ReadByte(REG_ADC_ATOP_01_L) & 0xf3) | (Channel << 2));
306     AIS_HalDebug(printf("%s: SOG offline mux -> %d\n", __FUNCTION__, (Channel << 2)));
307 }
308 
309 //------------------------------------------------------------------------------------------------
310 //
311 //------------------------------------------------------------------------------------------------
Hal_XC_SetOffLineToHDMI(void * pInstance,MS_U8 Channel)312 void Hal_XC_SetOffLineToHDMI( void *pInstance, MS_U8 Channel )
313 {
314 #if SUPPORT_IMMESWITCH
315     MS_U8 u8Tmp = Channel - INPUT_PORT_DVI0;
316     W2BYTEMSK(REG_PM_SLP_BASE+0x94,0,BIT(12 + u8Tmp));
317     switch(u8Tmp)
318     {
319         case 0:
320             W2BYTEMSK(REG_PM_SLP_BASE+0x96,0,(BIT(0)|BIT(4)|BIT(8)|BIT(12)));
321             break;
322         case 1:
323             W2BYTEMSK(REG_PM_SLP_BASE+0x96,0,(BIT(1)|BIT(5)|BIT(9)|BIT(13)));
324             break;
325         case 2:
326             W2BYTEMSK(REG_PM_SLP_BASE+0x96,0,(BIT(2)|BIT(6)|BIT(10)|BIT(14)));
327             break;
328         case 3:
329             W2BYTEMSK(REG_PM_SLP_BASE+0x96,0,(BIT(3)|BIT(7)|BIT(11)|BIT(15)));
330             break;
331         default:
332             break;
333     }
334 #endif
335 }
336 
337 //------------------------------------------------------------------------------------------------
338 //
339 //------------------------------------------------------------------------------------------------
Hal_XC_SetOffLineToUSB(void * pInstance,MS_U8 Channel)340 void Hal_XC_SetOffLineToUSB( void *pInstance, MS_U8 Channel )
341 {
342     //Need to do nothing
343 }
344 
345 //------------------------------------------------------------------------------------------------
346 //
347 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfH(void * pInstance)348 MS_U16 Hal_XC_GetOffLineOfH(void *pInstance)
349 {
350     MS_U16 u16Hcnt;
351     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
352     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
353     /*MS_U8 u8Bank;
354 
355     u8Bank = MDrv_ReadByte(BK_SELECT_00);
356     MDrv_WriteByte(BK_SELECT_00, REG_BANK_OFFLINE);
357     u16Hcnt = MDrv_Read2Byte(L_BK_OFFLINE(0x20)) & 0x3fff;
358     MDrv_WriteByte(BK_SELECT_00, u8Bank);*/
359     u16Hcnt = SC_R2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK13_20_L) & 0x3fff;
360     return u16Hcnt;
361 }
362 
363 //------------------------------------------------------------------------------------------------
364 //
365 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfV(void * pInstance)366 MS_U16 Hal_XC_GetOffLineOfV(void *pInstance)
367 {
368     MS_U16 u16Vcnt;
369     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
370     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
371     /*MS_U8 u8Bank;
372 
373     u8Bank = MDrv_ReadByte(BK_SELECT_00);
374     MDrv_WriteByte(BK_SELECT_00, REG_BANK_OFFLINE);
375     u16Vcnt = MDrv_Read2Byte(L_BK_OFFLINE(0x1f)) & 0x07ff;
376     MDrv_WriteByte(BK_SELECT_00, u8Bank);*/
377     u16Vcnt = SC_R2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK13_1F_L) & 0x07ff;
378     return u16Vcnt;
379 }
380 
381 //------------------------------------------------------------------------------------------------
382 //
383 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfDVI0(void)384 MS_U16 Hal_XC_GetOffLineOfDVI0(void)
385 {
386 #if SUPPORT_IMMESWITCH
387     MS_U16 u16Ret = 0;
388 
389     if((R2BYTE(REG_PM_SLEEP_3F_L) &BMASK(15:14)) != BMASK(15:14))
390     {
391         u16Ret = 1;
392     }
393 
394     return u16Ret;
395 
396 #else
397     return 0;
398 #endif
399 }
400 
401 //------------------------------------------------------------------------------------------------
402 //
403 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfDVI1(void)404 MS_U16 Hal_XC_GetOffLineOfDVI1(void)
405 {
406 #if SUPPORT_IMMESWITCH
407     MS_U16 u16Ret = 0;
408 
409     if((R2BYTE(REG_PM_SLEEP_42_L) &BMASK(15:14)) != BMASK(15:14))
410     {
411         u16Ret = 1;
412     }
413 
414     return u16Ret;
415 
416 #else
417     return 0;
418 #endif
419 }
420 
421 //------------------------------------------------------------------------------------------------
422 //
423 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfDVI2(void)424 MS_U16 Hal_XC_GetOffLineOfDVI2(void)
425 {
426 #if SUPPORT_IMMESWITCH
427     MS_U16 u16Ret = 0;
428 
429     if((R2BYTE(REG_PM_SLEEP_45_L) &BMASK(15:14)) != BMASK(15:14))
430     {
431         u16Ret = 1;
432     }
433 
434     return u16Ret;
435 
436 #else
437     return 0;
438 #endif
439 }
440 
441 //------------------------------------------------------------------------------------------------
442 //
443 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfDVI3(void)444 MS_U16 Hal_XC_GetOffLineOfDVI3(void)
445 {
446 #if SUPPORT_IMMESWITCH
447     MS_U16 u16Ret = 0;
448 
449     if((R2BYTE(REG_PM_SLEEP_48_L) &BMASK(15:14)) != BMASK(15:14))
450     {
451         u16Ret = 1;
452     }
453 
454     return u16Ret;
455 
456 #else
457     return 0;
458 #endif
459 }
460 
461 //------------------------------------------------------------------------------------------------
462 // Return HW connections status of UHCx
463 //------------------------------------------------------------------------------------------------
Hal_XC_GetOffLineOfStorage(void * pInstance)464 MS_U16 Hal_XC_GetOffLineOfStorage(void *pInstance)
465 {
466     return ((MDrv_ReadByte(REG_UHC0_BASE + 0x30) & 0x01) | (MDrv_ReadByte(REG_UHC1_BASE + 0x30) & 0x01));
467 }
468 
469 //------------------------------------------------------------------------------------------------
470 // Function: Switch Clk path
471 //----
472 // Input Source Select.
473 //   0000: ADC A.
474 //   0001: DVI
475 //   0010: VD
476 //   0011: Capture
477 //   0100: Reserved
478 //   0101: Ext VD
479 //   0110: ADC B
480 //
481 //------------------------------------------------------------------------------------------------
Hal_XC_TurnOnDetectClkPath(void * pInstance,MS_U8 u8DetectClkPath)482 void   Hal_XC_TurnOnDetectClkPath(void *pInstance, MS_U8 u8DetectClkPath)
483 {
484     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
485     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
486     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
487     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
488     if ((pXCResourcePrivate->sthal_Optee.op_tee_xc[MAIN_WINDOW].isEnable == TRUE) ||
489         (pXCResourcePrivate->sthal_Optee.op_tee_xc[SUB_WINDOW].isEnable == TRUE))
490     {
491         MS_U16 u16Delayms = 0;
492         while((pXCResourcePrivate->sthal_Optee.op_tee_mux.bfire == TRUE) && u16Delayms < 200)
493         {
494             MsOS_DelayTask(1);
495             u16Delayms++;
496         }
497         if (pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_cnt <=OP_TEE_XC_REG_MAX_CNT)
498         {
499             pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_data[pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_cnt].bk = REG_IPMUX_01_H;
500             pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_data[pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_cnt].value = (u8DetectClkPath << 8);
501             pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_data[pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_cnt].mask = 0xF000;
502             pXCResourcePrivate->sthal_Optee.op_tee_mux.regs_cnt++;
503         }
504         else
505         {
506             printf("op_tee_mux.regs_cnt too small\n");
507         }
508     }
509     MDrv_WriteByte(REG_IPMUX_01_H, (MDrv_ReadByte(REG_IPMUX_01_H) & 0xf0) | u8DetectClkPath);
510 }
511 
Hal_XC_SetOfflineDetectClk(void * pInstance)512 void Hal_XC_SetOfflineDetectClk(void *pInstance)
513 {
514     MDrv_WriteByteMask(REG_CKG_IDCLK0, CKG_IDCLK0_XTAL, CKG_IDCLK0_MASK); // initial to XTAL first, will be changed when switch input source
515 }
516 
Hal_XC_SetOffLineSogThreshold(void * pInstance,MS_U8 u8Threshold)517 MS_BOOL Hal_XC_SetOffLineSogThreshold(void *pInstance, MS_U8 u8Threshold)
518 {
519     UNUSED(pInstance);
520     MDrv_WriteByte(REG_ADC_ATOP_3E_L, u8Threshold); //8 bit
521     return TRUE;
522 }
523 
Hal_XC_SetOffLineSogBW(void * pInstance,MS_U8 u8BW)524 MS_BOOL Hal_XC_SetOffLineSogBW(void *pInstance, MS_U8 u8BW)
525 {
526     MS_BOOL bRet = TRUE;
527 
528     UNUSED(pInstance);
529 
530     if(u8BW < 32) // only 5 bit and always >= 0
531     {
532         bRet = TRUE;
533     }
534     else
535     {
536         printf("[Offline Detect]invalid sog filter bandwidth value, use default value:0x0!\n");
537         u8BW = 0;
538         bRet = FALSE;
539     }
540     MDrv_WriteByte(REG_ADC_ATOP_3C_L, (MDrv_ReadByte(REG_ADC_ATOP_3C_L) & 0xe0) | u8BW);
541     return bRet;
542 }
543 
Hal_XC_OffLineInit(void * pInstance)544 void Hal_XC_OffLineInit(void *pInstance)
545 {
546     MDrv_WriteByte(REG_ADC_ATOP_3F_L, MDrv_ReadByte(REG_ADC_ATOP_3F_L) & 0xfd);
547 }
548 
Hal_XC_OffLineExit(void * pInstance)549 void Hal_XC_OffLineExit(void *pInstance)
550 {
551     MDrv_WriteByteMask(REG_ADC_ATOP_3F_L, BIT(1), BIT(1));
552 }
553 
Hal_XC_GetOffLineDetection(void * pInstance,MS_U8 u8CheckSrc)554 MS_U8 Hal_XC_GetOffLineDetection(void *pInstance, MS_U8 u8CheckSrc)
555 {
556     if(((u8CheckSrc >= (MS_U8)INPUT_PORT_YMUX_CVBS0) &&
557         (u8CheckSrc <= (MS_U8)INPUT_PORT_YMUX_CVBS7))
558          ||
559         ((u8CheckSrc >= (MS_U8)INPUT_PORT_ANALOG0_SYNC)  &&
560         (u8CheckSrc <= (MS_U8)INPUT_PORT_ANALOG4_SYNC))
561          ||
562         ((u8CheckSrc >= (MS_U8)INPUT_PORT_ANALOG0)  &&
563         (u8CheckSrc <= (MS_U8)INPUT_PORT_ANALOG4)))
564     {
565         MS_U16 u16Hcnt, u16Vcnt;
566 
567         u16Hcnt = Hal_XC_GetOffLineOfH(pInstance);
568         u16Vcnt = Hal_XC_GetOffLineOfV(pInstance);
569         AIS_HalDebug(printf("MApi_XC_GetOffLineDetection: vcnt=%x hcnt=%x\n", u16Vcnt,u16Hcnt );)
570 
571         if((u16Hcnt == 0x3fff)
572             ||(u16Vcnt ==0x7ff)
573             ||(u16Hcnt == 0)
574             ||(u16Vcnt ==0)
575             )
576         {
577             return 0;        // Nosignal
578         }
579         else
580         {
581             return 1;        //Signal in
582         }
583     }
584     else if(u8CheckSrc == INPUT_PORT_DVI0)
585     {
586         return Hal_XC_GetOffLineOfDVI0();
587     }
588     else if(u8CheckSrc == INPUT_PORT_DVI1)
589     {
590         return Hal_XC_GetOffLineOfDVI1();
591     }
592     else if(u8CheckSrc == INPUT_PORT_DVI2)
593     {
594         return Hal_XC_GetOffLineOfDVI2();
595     }
596     else if(u8CheckSrc == INPUT_PORT_DVI3)
597     {
598         return Hal_XC_GetOffLineOfDVI3();
599     }
600     else if(u8CheckSrc == INPUT_PORT_MVOP)
601     {
602         //UHC0_REG_BASE and UHC1_REG_BASE
603         return (Hal_XC_GetOffLineOfStorage(pInstance))?1:0;
604     }
605     else
606     {
607         return 0;
608     }
609 }
610 
611 #undef MHAL_OFFLINE_C
612