xref: /utopia/UTPA2-700.0.x/modules/vd/drv/vbi/drvVBI.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!�L) 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 #define _DRV_VBI_C
96 
97 // Common Definition
98 #if defined(MSOS_TYPE_LINUX_KERNEL)
99 //    #include <linux/slab.h>
100     #include <linux/string.h> //for memcpy, memset
101 #else
102     #include <string.h>
103 #endif
104 #include "MsCommon.h"
105 #include "MsVersion.h"
106 #include "MsOS.h"
107 #include "ULog.h"
108 // Internal Definition
109 #include "halVBI.h"
110 #include "drvVBI.h"
111 #include "drvMMIO.h"
112 #include "drvSYS.h"
113 
114 #include "utopia.h"
115 
116 #if (VBI_UTOPIA20)
117 #include "drvVBI_v2.h"
118 #endif
119 
120 #include "drvVBI_private.h"
121 
122 //-------------------------------------------------------------------------------------------------
123 //  Driver Compiler Options
124 //-------------------------------------------------------------------------------------------------
125 
126 //-------------------------------------------------------------------------------------------------
127 //  Local Defines
128 //-------------------------------------------------------------------------------------------------
129 #define _BIT0       BIT(0)
130 #define _BIT1       BIT(1)
131 #define _BIT2       BIT(2)
132 #define _BIT3       BIT(3)
133 #define _BIT4       BIT(4)
134 #define _BIT5       BIT(5)
135 #define _BIT6       BIT(6)
136 #define _BIT7       BIT(7)
137 #define _BIT8       BIT(8)
138 #define _BIT9       BIT(9)
139 #define _BIT10      BIT(10)
140 #define _BIT11      BIT(11)
141 #define _BIT12      BIT(12)
142 #define _BIT13      BIT(13)
143 #define _BIT14      BIT(14)
144 #define _BIT15      BIT(15)
145 
146 #define UNUSED(x)       (void)((x)=(x))
147 
148 #define DEFAULT_WAIT_TIME MSOS_WAIT_FOREVER  //ms
149 
150 static VBI_CB_FN _pFN = NULL;
151 
152 static MSIF_Version _drv_VBI_version = {
153     .MW = { VBI_VER },
154 };
155 
156 static VBI_RING_BUFFER rb_handle;
157 static VBI_DrvInfo     _drvInfo;
158 static VBI_DrvStatus   _drvStatus;
159 
160 static VBI_StoreInfo _pStoreInfo = {
161     ._bSuspend = FALSE,
162     .eInitType = E_VBI_TELETEXT,
163 
164     // TTX buffer address & buffer size
165     ._ptrVBIRiuBaseAddr = 0xFFFFFFFFUL,
166     ._TTXBufAddr = 0xFFFFFFFFUL,
167     ._TTXBufLen  = 0,
168 
169     // CC buffer address & buffer size
170     ._CCBufAddr = 0xFFFFFFFFUL,
171     ._CCBufLen  = 0,
172 
173     // callback info
174     ._cbBufferAddr   = 0xFFFFFFFFUL,
175     ._cbBufferLength = 0,
176     ._pCbVABuff      = NULL,
177 
178     ._bTTXSupported = FALSE,
179     ._bVBIInit      = FALSE,
180     ._u16VBIDbgSwitch = 0,
181 };
182 
183 // Mutex & Lock
184 static MS_S32 _s32VBIMutex = -1;
185 
186 #if (VBI_UTOPIA20)
187 static void* pInstantVbi   = NULL;
188 static void* pAttributeVbi = NULL;
189 #endif
190 
191 #define VIDEO_TYPE_CNT          5
192 #define VIDEO_REGISTER_CNT      8
193 static MS_U8 video_standard_vbi_settings[VIDEO_TYPE_CNT][VIDEO_REGISTER_CNT + 1] = {
194    // type                      41h[7:0]   42h[5:0]    44h[7:0]    4Bh[5:0]    4Dh[7:0]    50h[4:0]    51h[4:0]    53h[4:0]
195     {VBI_VIDEO_NTSC,            0x52,      0x1c,       0x39,       0x24,       0x8e,       0xd2,       0x12,       0x90},  // NTSC
196     {VBI_VIDEO_PAL_M,           0x52,      0x1c,       0x39,       0x26,       0x8e,       0xd2,       0x12,       0x90},  // PAL-M
197     {VBI_VIDEO_PAL_NC,          0x52,      0x1c,       0x39,       0x16,       0x8e,       0xd2,       0x12,       0x90},  // PAL-NC
198     {VBI_VIDEO_NTSC443_PAL60,   0x52,      0x23,       0x47,       0x32,       0xb0,       0xd2,       0x12,       0xb2},  // NTSC-443, PAL-60
199     {VBI_VIDEO_PAL,             0xb5,      0x23,       0x47,       0x22,       0xb0,       0xd5,       0x15,       0xb2},  // PAL
200 };
201 //-------------------------------------------------------------------------------------------------
202 //  Debug Functions
203 //-------------------------------------------------------------------------------------------------
204 
205 //-------------------------------------------------------------------------------------------------
206 //  Local Functions
207 //-------------------------------------------------------------------------------------------------
208 ////////////////////////////////////////////////////////////////////////////////
209 /// @brief \b Function \b Name: _MDrv_VBI_ISR()
210 /// @brief \b Function \b Description:  This function is used to set the Decoder DSP ISR
211 ////////////////////////////////////////////////////////////////////////////////
212 #if defined (MSOS_TYPE_NOS)
_MDrv_VBI_ISR(MHAL_SavedRegisters * pHalReg,MS_U32 u32Data)213 static void _MDrv_VBI_ISR(MHAL_SavedRegisters *pHalReg, MS_U32 u32Data)
214 #else // Ecos and Linux
215 static void _MDrv_VBI_ISR( InterruptNum eIntNum )
216 #endif
217 {
218     #if defined (MSOS_TYPE_NOS)
219         UNUSED(pHalReg);
220         UNUSED(u32Data);
221     #else // Ecos and Linux
222         UNUSED(eIntNum);
223     #endif
224 
225 #if defined(MSOS_TYPE_LINUX_KERNEL)
226     if(_pStoreInfo._pCbVABuff!=NULL)
227 #else
228     if(_pFN!=NULL && _pStoreInfo._pCbVABuff!=NULL)
229 #endif
230     {
231         MS_U32 length = _pStoreInfo._cbBufferLength;
232 
233         switch(_drvStatus.eInitType)
234         {
235             case E_VBI_TELETEXT:
236                 if(_MDrv_VBI_TTX_GetPackets(_pStoreInfo._cbBufferAddr, &length)==TRUE)
237                 {
238 #if defined(MSOS_TYPE_LINUX_KERNEL)
239 #else
240                     (*_pFN)(_pStoreInfo._pCbVABuff, length);
241 #endif
242                 }
243                 break;
244 
245             case E_VBI_CC:
246                 // need to implement
247                 break;
248 
249             default:
250                 break;
251         }
252     }
253 
254     MsOS_EnableInterrupt(E_INT_IRQ_VBI);
255 }
256 
257 /****************************************************************************
258  *@brief            : Update TTX Write Pointer
259  *@param
260  *@return
261  *  - TRUE : update write pointer successfully.
262  *  - FALSE: update write pointer unsuccessfully.
263  ****************************************************************************/
_MDrv_VBI_TTX_UpdateWritePointer(void)264 static MS_BOOL _MDrv_VBI_TTX_UpdateWritePointer(void)
265 {
266     MS_S32 NumberOfFreePackets;
267 
268     if(VBI_TTX_CheckCircuitReady()==FALSE)
269     {
270         return FALSE;
271     }
272 
273     rb_handle.WritePacketNumber = VBI_TTX_GetPacketCount();
274 
275     if(rb_handle.pkt_received==TRUE)
276     {
277         NumberOfFreePackets = (MS_S32)(rb_handle.WritePacketNumber - rb_handle.ReadPacketNumber);
278         if (NumberOfFreePackets < 0)
279             NumberOfFreePackets += _pStoreInfo._TTXBufLen;
280 
281         NumberOfFreePackets = (MS_S32)(_pStoreInfo._TTXBufLen - NumberOfFreePackets);
282 
283         if (NumberOfFreePackets < 2)
284         {
285             rb_handle.NoOfPacketBufferOverflows++;
286             rb_handle.PacketBufferOverflow = TRUE;
287             return FALSE;
288         }
289     }
290 
291     if(rb_handle.WritePacketNumber==1)
292     {
293         if(rb_handle.pkt_received)
294         {
295             rb_handle.WritePacketNumber = _pStoreInfo._TTXBufLen;
296         }
297         else
298         {
299             rb_handle.WritePacketNumber = 0;
300         }
301     }
302     else
303     {
304         if(rb_handle.WritePacketNumber==0)
305         {
306             rb_handle.ReadPacketNumber = 0;
307             return FALSE;
308         }
309 
310         rb_handle.WritePacketNumber--;
311         rb_handle.pkt_received = TRUE;
312     }
313 
314     return TRUE;
315 }
316 
317 //-------------------------------------------------------------------------------------------------
318 //  Global Functions
319 //-------------------------------------------------------------------------------------------------
_MDrv_VBI_GetStatus(VBI_DrvStatus * pDrvStatus)320 MS_BOOL _MDrv_VBI_GetStatus(VBI_DrvStatus *pDrvStatus)
321 {
322     memcpy(pDrvStatus, &_drvStatus, sizeof(VBI_DrvStatus));
323     return TRUE;
324 }
325 
_MDrv_VBI_Init(EN_VBI_CMD cmd,VBI_INIT_TYPE type)326 MS_BOOL _MDrv_VBI_Init(EN_VBI_CMD cmd, VBI_INIT_TYPE type)
327 {
328     MS_PHY phyNonPMBankSize;
329     static char _vbiSyncMutexName[] = "OS_VBI_MUTEX";
330 
331     if(cmd == VBI_INIT)
332     {
333         if (type == E_VBI_WSS)
334         {
335             MS_VIRT ptrVBIRiuBaseAddrForWSS = 0;
336 
337             // get MMIO base
338             if (MDrv_MMIO_GetBASE( &ptrVBIRiuBaseAddrForWSS, &phyNonPMBankSize, MS_MODULE_VBI) != TRUE)
339             {
340                 return FALSE;
341             }
342             else
343             {
344                 //printf("MDrv_PNL_Init u32PnlRiuBaseAddr = %lx\n", gu32PnlRiuBaseAddr);
345             }
346 
347             VBI_WSSInit(ptrVBIRiuBaseAddrForWSS);
348 
349             return TRUE;
350         }
351 
352         _s32VBIMutex = //OS_CREATE_MUTEX(VBI);
353                     MsOS_CreateMutex(E_MSOS_FIFO, _vbiSyncMutexName, MSOS_PROCESS_PRIVATE);
354 
355         if(_s32VBIMutex < 0)
356         {
357             return FALSE;
358         }
359 
360         // get MMIO base
361         if(MDrv_MMIO_GetBASE( &_pStoreInfo._ptrVBIRiuBaseAddr, &phyNonPMBankSize, MS_MODULE_VBI ) != TRUE)
362         {
363             OS_DELETE_MUTEX(_s32VBIMutex);
364             return FALSE;
365         }
366         else
367         {
368             //ULOGD("VBI", "MDrv_PNL_Init u32PnlRiuBaseAddr = %lx\n", gu32PnlRiuBaseAddr);
369         }
370 
371         if(type==E_VBI_TELETEXT)
372         {
373             _pStoreInfo._bTTXSupported = MDrv_SYS_Query(E_SYS_QUERY_TTXNICAM_SUPPORTED);
374             if(_pStoreInfo._bTTXSupported == TRUE)
375             {
376                 VBI_TTXInit(_pStoreInfo._ptrVBIRiuBaseAddr);
377             }
378             else
379             {
380                 ULOGE("VBI", "[VBI ERROR] TELETEXT not support in this chip !!!\n");
381                 return FALSE;
382             }
383         }
384         else
385         {
386             ;   // should call CC VBI init
387         }
388 
389         _drvStatus.eInitType = type;
390         _pStoreInfo._bVBIInit = TRUE;
391         _pStoreInfo._bSuspend = FALSE;
392 
393 
394 #if defined (MSOS_TYPE_NOS)
395         // irq init
396         MsOS_AttachInterrupt(E_INT_IRQ_VBI, (InterruptCb)_MDrv_VBI_ISR );
397         MsOS_EnableInterrupt(E_INT_IRQ_VBI);
398 #else // Ecos and Linux
399         MsOS_AttachInterrupt(E_INT_IRQ_VBI, _MDrv_VBI_ISR );
400         MsOS_EnableInterrupt(E_INT_IRQ_VBI);
401 #endif
402     }
403     else
404     {
405         if(type==E_VBI_TELETEXT)
406         {
407             _pStoreInfo._bTTXSupported = MDrv_SYS_Query(E_SYS_QUERY_TTXNICAM_SUPPORTED);
408             if(_pStoreInfo._bTTXSupported == TRUE)
409             {
410                 VBI_TTXInit(_pStoreInfo._ptrVBIRiuBaseAddr);
411             }
412             else
413             {
414                 ULOGE("VBI", "[VBI ERROR] TELETEXT not support in this chip !!!\n");
415                 return FALSE;
416             }
417         }
418         else
419         {
420             ;   // should call CC VBI init
421         }
422 
423         MsOS_EnableInterrupt(E_INT_IRQ_VBI);
424     }
425 
426     return TRUE;
427 }
428 
_MDrv_VBI_Exit(EN_VBI_CMD cmd)429 MS_BOOL _MDrv_VBI_Exit(EN_VBI_CMD cmd)
430 {
431     _pStoreInfo._bVBIInit = FALSE;
432     if(cmd == VBI_EXIT) // vbi exit
433     {
434         if (_s32VBIMutex != -1)
435         {
436             OS_OBTAIN_MUTEX(_s32VBIMutex, DEFAULT_WAIT_TIME);
437             OS_RELEASE_MUTEX(_s32VBIMutex);
438             OS_DELETE_MUTEX(_s32VBIMutex);
439         }
440 
441         MsOS_DisableInterrupt(E_INT_IRQ_VBI);
442         MsOS_DetachInterrupt(E_INT_IRQ_VBI);
443     }
444     else // vbi suspend
445     {
446         MsOS_DisableInterrupt(E_INT_IRQ_VBI);
447     }
448 
449     return TRUE;
450 }
451 
_MDrv_VBI_RegisterCB(VBI_CB_FN pFN,MS_PHY bufferAddr,MS_U32 length)452 void _MDrv_VBI_RegisterCB(VBI_CB_FN pFN, MS_PHY bufferAddr, MS_U32 length)
453 {
454     _pFN = pFN;
455     _pStoreInfo._cbBufferAddr = bufferAddr;
456     _pStoreInfo._cbBufferLength = (length/VBI_TTX_DATA_LENGTH)*VBI_TTX_DATA_LENGTH;
457     _pStoreInfo._pCbVABuff = (MS_U8 *) MS_PA2KSEG1(_pStoreInfo._cbBufferAddr);
458 }
459 
_MDrv_VBI_RingBuffer_Reset(void)460 void _MDrv_VBI_RingBuffer_Reset(void)
461 {
462     memset((MS_U8 *) MS_PA2KSEG1(_pStoreInfo._TTXBufAddr), 0x20, _pStoreInfo._TTXBufLen*VBI_TTX_DATA_LENGTH);
463 
464     OS_OBTAIN_MUTEX(_s32VBIMutex, DEFAULT_WAIT_TIME);
465 
466     rb_handle.ReadPacketNumber = VBI_TTX_GetPacketCount();
467     rb_handle.WritePacketNumber = 0;
468     rb_handle.pkt_received = FALSE;
469     rb_handle.PacketBufferOverflow = FALSE;
470     rb_handle.NoOfPacketBufferOverflows = 0;
471 
472     OS_RELEASE_MUTEX(_s32VBIMutex);
473 }
474 
_MDrv_VBI_InitializeTTXSlicer(MS_PHY bufferAddr,MS_U16 packetCount)475 void _MDrv_VBI_InitializeTTXSlicer(MS_PHY bufferAddr, MS_U16 packetCount)
476 {
477     if(_pStoreInfo._bTTXSupported == FALSE)
478     {
479         ULOGE("VBI", "TTX not support\n");
480         return;
481     }
482 
483     VBI_TTX_InitSlicer(bufferAddr, packetCount);
484     _pStoreInfo._TTXBufAddr = bufferAddr;
485     _pStoreInfo._TTXBufLen = packetCount;
486     _MDrv_VBI_RingBuffer_Reset();
487 }
488 
_MDrv_VBI_EnableTTXSlicer(MS_BOOL bEnable)489 void _MDrv_VBI_EnableTTXSlicer(MS_BOOL bEnable)
490 {
491     if(_pStoreInfo._bTTXSupported == FALSE)
492     {
493         return;
494     }
495 
496     VBI_TTX_EnableSlicer(bEnable);
497 }
498 
_MDrv_VBI_IsVPS_Ready(void)499 MS_BOOL _MDrv_VBI_IsVPS_Ready(void)
500 {
501     MS_U8 regval;
502 
503     regval = VBI_TTX_GetHardware_Indication();
504 
505     if(regval & _BIT4)
506     {
507         return TRUE;
508     }
509     else
510     {
511         return FALSE;
512     }
513 }
514 
_MDrv_VBI_IsTTX_Ready(void)515 MS_BOOL _MDrv_VBI_IsTTX_Ready(void)
516 {
517     MS_U8 regval;
518 
519     if(_pStoreInfo._bTTXSupported == FALSE)
520     {
521         return FALSE;
522     }
523 
524     regval = VBI_TTX_GetHardware_Indication();
525 
526     if(regval & _BIT1)
527     {
528         return TRUE;
529     }
530     else
531     {
532         return FALSE;
533     }
534 }
535 
_MDrv_VBI_IsWSS_Ready(void)536 MS_BOOL _MDrv_VBI_IsWSS_Ready(void)
537 {
538     MS_U8 regval;
539 
540     regval = VBI_TTX_GetHardware_Indication();
541 
542     if(regval & _BIT6)
543     {
544         return TRUE;
545     }
546     else
547     {
548         return FALSE;
549     }
550 }
551 
_MDrv_VBI_GetWSS_Data(void)552 MS_U16 _MDrv_VBI_GetWSS_Data(void)
553 {
554     return VBI_GetWSS_Data();
555 }
556 
_MDrv_VBI_GetRawVPS_Data(MS_U8 * byte0,MS_U8 * byte1,MS_U8 * byte2,MS_U8 * byte3)557 void _MDrv_VBI_GetRawVPS_Data(MS_U8 *byte0, MS_U8 *byte1, MS_U8 *byte2, MS_U8 *byte3)
558 {
559     VBI_GetVPS_Data(byte0, byte1, byte2, byte3);
560 }
561 
_MDrv_VBI_GetVPS_Data(MS_U8 * lowerWord,MS_U8 * higherWord)562 void _MDrv_VBI_GetVPS_Data(MS_U8 *lowerWord, MS_U8 *higherWord)
563 {
564     MS_U8 ucLoop;
565     MS_U8 ucVpsDataH, ucVpsDataL;
566     MS_U8 VpsByte1, VpsByte2, VpsByte3, VpsByte4;
567 
568     VBI_GetVPS_Data(&VpsByte1, &VpsByte2, &VpsByte3, &VpsByte4);
569 
570     ucVpsDataH = 0x00;
571     ucVpsDataL = 0x00;
572 
573      for (ucLoop = _BIT7; ucLoop!=_BIT1; ucLoop>>=1)	// extract byte 14[2:7] as ucVpsDataL[5:0]
574     {
575         ucVpsDataL >>= 1;
576         if (VpsByte2 & ucLoop)
577             ucVpsDataL |= _BIT7;
578     } // for
579 
580     for (ucLoop = _BIT1; ucLoop!=0; ucLoop>>=1)		// extract byte 11[0:1] as ucVpsDataL[7:6]
581     {
582         ucVpsDataL >>= 1;
583         if (VpsByte4 & ucLoop)
584             ucVpsDataL |= _BIT7;
585     } // for
586 
587     for (ucLoop = _BIT1; ucLoop!=0; ucLoop>>=1)		// extract byte 14[0:1] as ucVpsDataH[1:0]
588     {
589         ucVpsDataH >>= 1;
590         if (VpsByte2 & ucLoop)
591             ucVpsDataH |= _BIT3;
592     } // for
593 
594     for (ucLoop = _BIT7; ucLoop!=_BIT5; ucLoop>>=1)	// extract byte-13[6:7] as ucVpsDataH[3:2]
595     {
596         ucVpsDataH >>= 1;
597         if (VpsByte1 & ucLoop)
598             ucVpsDataH |= _BIT3;
599     } // for
600 
601     *lowerWord = ucVpsDataL;
602     *higherWord = ucVpsDataH;
603 }
604 
_MDrv_VBI_SetVideoStandard(VBI_VIDEO_STANDARD eStandard)605 void _MDrv_VBI_SetVideoStandard(VBI_VIDEO_STANDARD eStandard)
606 {
607     switch(eStandard)
608     {
609         case VBI_VIDEO_SECAM:
610             VBI_Set_Secam_VideoStandard();
611             break;
612 
613         case VBI_VIDEO_PAL_NC:
614             VBI_Set_PalNC_VideoStandard();
615             break;
616 
617         default:
618             ULOGD("VBI", "[%s] not support standard 0x%x, use PAL instead\n", __FUNCTION__, (unsigned int)eStandard);
619             VBI_Set_Pal_VideoStandard();
620             break;
621     }
622 }
623 
_MDrv_VBI_TTX_PacketBufferIsEmpty(void)624 MS_BOOL _MDrv_VBI_TTX_PacketBufferIsEmpty(void)
625 {
626     if(_MDrv_VBI_TTX_UpdateWritePointer()==FALSE)   // if overflow or slicer is not ready, define it is buffer empty
627         return TRUE;
628 
629     if (rb_handle.WritePacketNumber - rb_handle.ReadPacketNumber) /* no of packets */
630         return FALSE;
631 
632     return TRUE;
633 }
634 
_MDrv_VBI_TTX_CheckCircuitReady(void)635 MS_BOOL _MDrv_VBI_TTX_CheckCircuitReady(void)
636 {
637     if(_pStoreInfo._bTTXSupported == FALSE)
638     {
639         return FALSE;
640     }
641     return VBI_TTX_CheckCircuitReady();
642 }
643 
_MDrv_VBI_TTX_GetPacketCount(void)644 MS_U16 _MDrv_VBI_TTX_GetPacketCount(void)
645 {
646     if(_pStoreInfo._bTTXSupported == FALSE)
647     {
648         return 0;
649     }
650     return VBI_TTX_GetPacketCount();
651 }
652 
_MDrv_VBI_TTX_GetPackets(MS_PHY dataAddr,MS_U32 * length)653 MS_BOOL _MDrv_VBI_TTX_GetPackets(MS_PHY dataAddr, MS_U32 *length)
654 {
655     MS_U8 *pData = (MS_U8 *) MS_PA2KSEG1(dataAddr);
656     MS_BOOL ret = FALSE;
657 
658     if((*length)==0)
659     {
660         return FALSE;
661     }
662 
663     OS_OBTAIN_MUTEX(_s32VBIMutex, DEFAULT_WAIT_TIME);
664 
665     if(_MDrv_VBI_TTX_PacketBufferIsEmpty()==FALSE)
666     {
667         MS_PHY packetAddress;
668         MS_U32 data_length;
669         MS_U32 data_length2;
670 
671         packetAddress = _pStoreInfo._TTXBufAddr + (rb_handle.ReadPacketNumber) * VBI_TTX_DATA_LENGTH;
672 
673         if(rb_handle.ReadPacketNumber > rb_handle.WritePacketNumber)
674         {
675             // HEAD <--- 2 ---> W ------R <--- 1 ---> TAIL
676 
677             // copy region 1
678             data_length = VBI_TTX_DATA_LENGTH*(_pStoreInfo._TTXBufLen - rb_handle.ReadPacketNumber);
679 
680             if(data_length > (*length))
681             {
682                 data_length = (*length);
683             }
684 
685             memcpy(pData, (MS_U8 *) MS_PA2KSEG1(packetAddress), data_length);
686 
687             // input buffer is full
688             if((*length)==data_length)
689             {
690                 rb_handle.ReadPacketNumber += data_length/VBI_TTX_DATA_LENGTH;
691                 ret = TRUE;
692                 goto GET_PACKETS_EXIT;
693             }
694 
695             // copy region 2
696             data_length2 = VBI_TTX_DATA_LENGTH*(rb_handle.WritePacketNumber);
697 
698             // calculate the left buffer size
699             if(data_length2 > ((*length) - data_length))
700             {
701                 data_length2 = ((*length) - data_length);
702             }
703 
704             memcpy(pData + data_length, (MS_U8 *) MS_PA2KSEG1(_pStoreInfo._TTXBufAddr), data_length2);
705 
706             rb_handle.ReadPacketNumber = data_length2/VBI_TTX_DATA_LENGTH;
707             (*length) = data_length + data_length2;
708 
709             ret = TRUE;
710         }
711         else
712         {
713             // R <--- 1 ---> W
714 
715             // copy region 1
716             data_length = VBI_TTX_DATA_LENGTH*(rb_handle.WritePacketNumber - rb_handle.ReadPacketNumber);
717 
718             if(data_length > (*length))
719             {
720                 data_length = (*length);
721             }
722 
723             memcpy(pData, (MS_U8 *) MS_PA2KSEG1(packetAddress), data_length);
724 
725             rb_handle.ReadPacketNumber += data_length/VBI_TTX_DATA_LENGTH;
726             (*length) = data_length;
727 
728             ret = TRUE;
729         }
730     }
731 
732 GET_PACKETS_EXIT:
733     OS_RELEASE_MUTEX(_s32VBIMutex);
734     return ret;
735 }
736 
_MDrv_VBI_TTX_GetPacket(MS_PHY * packetAddress)737 MS_BOOL _MDrv_VBI_TTX_GetPacket(MS_PHY *packetAddress)
738 {
739     MS_BOOL ret = FALSE;
740 
741     OS_OBTAIN_MUTEX(_s32VBIMutex, DEFAULT_WAIT_TIME);
742 
743     if (_MDrv_VBI_TTX_PacketBufferIsEmpty()==FALSE)
744     {
745         rb_handle.ReadPacketNumber++;
746 
747         // Venus, 0 -> 1 -> 2 ->3 -> N-1 -> N -> 1 ->2 -> 3 ...
748         if ( rb_handle.ReadPacketNumber > _pStoreInfo._TTXBufLen )
749         {
750             rb_handle.ReadPacketNumber = 1;
751         }
752 
753         *packetAddress = _pStoreInfo._TTXBufAddr + (rb_handle.ReadPacketNumber - 1) * VBI_TTX_DATA_LENGTH;
754 
755         ret = TRUE;
756     }
757 
758     OS_RELEASE_MUTEX(_s32VBIMutex);
759     return ret;
760 }
761 
_MDrv_VBI_TTX_PacketBufferIsOverflow(void)762 MS_BOOL _MDrv_VBI_TTX_PacketBufferIsOverflow( void )
763 {
764     return rb_handle.PacketBufferOverflow;
765 }
766 
_MDrv_VBI_TTX_PacketBufferGetNoOfOverflows(void)767 MS_U16 _MDrv_VBI_TTX_PacketBufferGetNoOfOverflows( void )
768 {
769     return rb_handle.NoOfPacketBufferOverflows;
770 }
771 
_MDrv_VBI_TTX_EnableLine(MS_U16 StartLine,MS_U16 EndLine)772 void _MDrv_VBI_TTX_EnableLine(MS_U16 StartLine, MS_U16 EndLine)
773 {
774     VBI_TTX_EnableLine(StartLine, EndLine);
775 }
776 
_MDrv_VBI_SyncMemory(MS_U32 u32Start,MS_U32 u32Size)777 MS_BOOL _MDrv_VBI_SyncMemory( MS_U32 u32Start, MS_U32 u32Size )
778 {
779     MsOS_ReadMemory();
780     return MsOS_Dcache_Flush(u32Start, u32Size);
781 }
782 
_MDrv_VBI_CC_InitSlicer(MS_VIRT u32RiuAddr,MS_PHY bufferAddr,MS_U16 packetCount)783 void _MDrv_VBI_CC_InitSlicer(MS_VIRT u32RiuAddr, MS_PHY bufferAddr, MS_U16 packetCount)
784 {
785     MS_PHY phyNonPMBankSize;
786 
787     // get MMIO base
788     if(MDrv_MMIO_GetBASE( &_pStoreInfo._ptrVBIRiuBaseAddr, &phyNonPMBankSize, MS_MODULE_VBI ) != TRUE)
789     {
790         return;
791     }
792     else
793     {
794         //ULOGD("VBI", "MDrv_PNL_Init u32PnlRiuBaseAddr = %lx\n", _gu32PnlRiuBaseAddr);
795     }
796 
797     if(bufferAddr != 0 && packetCount != 0)
798     {
799         if(_pStoreInfo._ptrVBIRiuBaseAddr != 0)
800         {
801             u32RiuAddr = _pStoreInfo._ptrVBIRiuBaseAddr;
802         }
803 
804         _pStoreInfo._CCBufAddr = bufferAddr;
805         _pStoreInfo._CCBufLen  = packetCount;
806 
807         VBI_CC_Init(u32RiuAddr, bufferAddr, packetCount);
808     }
809 }
810 
_MDrv_VBI_CC_InitYPbYr(MS_U8 cvbs_no)811 void _MDrv_VBI_CC_InitYPbYr(MS_U8 cvbs_no)
812 {
813     VBI_CC_YPbPr_Init(cvbs_no);
814 }
815 
_MDrv_VBI_CC_SetDataRate(MS_U8 * ptable)816 MS_U8 _MDrv_VBI_CC_SetDataRate(MS_U8 *ptable)
817 {
818     if(ptable != NULL)
819     {
820         return (VBI_CC_DataRateSet(ptable));
821     }
822 
823     return FALSE;
824 }
825 
_MDrv_VBI_CC_SetSCWindowLen(MS_U8 u8Len)826 MS_BOOL _MDrv_VBI_CC_SetSCWindowLen(MS_U8 u8Len)
827 {
828     return VBI_CC_SetSCWindowLen(u8Len);
829 }
830 
_MDrv_VBI_CC_SetStandard(VBI_VIDEO_STANDARD eStandard)831 MS_BOOL _MDrv_VBI_CC_SetStandard(VBI_VIDEO_STANDARD eStandard)
832 {
833     MS_U8 i=0;
834 
835     // Get the video system's type
836     for(i=0; i<VIDEO_TYPE_CNT; i++)
837     {
838         if(video_standard_vbi_settings[i][0] == eStandard)
839             break;
840     }
841 
842     if(i >= VIDEO_TYPE_CNT)
843     {
844         return FALSE;
845     }
846 
847     VBI_CC_DataRateSet(video_standard_vbi_settings[i]);
848     VBI_CC_SetSCWindowLen(video_standard_vbi_settings[i][8]); // BK_VBI_53
849     return TRUE;
850 }
851 
_MDrv_VBI_CC_GetInfo(MS_U32 selector)852 MS_U32 _MDrv_VBI_CC_GetInfo(MS_U32 selector)
853 {
854     // Functionality select
855     switch (selector)
856     {
857         case VBI_CC_PACKET_COUNT:
858             return  ((MS_U32)VBI_CC_GetPacketCnt());
859 
860             break;
861 
862         case VBI_CC_BYTE_FOUND_INDICATION:
863             return  ((MS_U32)VBI_CC_GetByteFoundIndication());
864 
865             break;
866 
867         case VBI_CC_DATA_GET:
868             return  ((MS_U32)VBI_CC_GetPacket());   // odd_filed_data + even_field_data
869 
870             break;
871 
872         default:
873             ;
874     }
875 
876     return  (MS_U32)VBI_ERRORCODE_SUCCESS;
877 }
878 
_MDrv_VBI_CC_SetFrameCnt(MS_U8 cnt)879 void _MDrv_VBI_CC_SetFrameCnt(MS_U8 cnt)
880 {
881     VBI_SetCCFrameCnt(cnt);
882 }
883 
_MDrv_VBI_CC_EnableSlicer(MS_BOOL bEnable)884 void _MDrv_VBI_CC_EnableSlicer(MS_BOOL bEnable)
885 {
886     VBI_CC_EnableSlicer(bEnable);
887 }
888 
_MDrv_VBI_CC_EnableLine(MS_U16 StartLine,MS_U16 EndLine,MS_U8 mode)889 void _MDrv_VBI_CC_EnableLine(MS_U16 StartLine, MS_U16 EndLine, MS_U8 mode)
890 {
891     // set line
892     VBI_CC_SetCCLine(StartLine, EndLine, mode);
893 }
894 
_MDrv_VBI_WSS_SetVpsByteNum(MS_U8 cnt)895 void _MDrv_VBI_WSS_SetVpsByteNum(MS_U8 cnt)
896 {
897     VBI_SetWssVpsByteNum(cnt);
898 }
899 
_MDrv_VBI_Suspend(void)900 MS_BOOL _MDrv_VBI_Suspend(void)
901 {
902     if((_pStoreInfo._bSuspend != FALSE) || (_s32VBIMutex == -1))
903     {
904         return FALSE;
905     }
906     _pStoreInfo._bSuspend = TRUE;
907     _pStoreInfo.eInitType = _drvStatus.eInitType;
908 
909     VBI_RegStateStore();
910     _MDrv_VBI_Exit(VBI_SUSPEND);
911 
912     return TRUE;
913 }
914 
_MDrv_VBI_Resume(void)915 MS_BOOL _MDrv_VBI_Resume(void)
916 {
917     if((_pStoreInfo._bSuspend != TRUE) || (_s32VBIMutex == -1))
918     {
919         return FALSE;
920     }
921     _pStoreInfo._bSuspend = FALSE;
922 
923     _MDrv_VBI_Init(VBI_RESUME, _pStoreInfo.eInitType);
924 
925     if((_pStoreInfo.eInitType == E_VBI_CC) && ((_pStoreInfo._CCBufAddr != 0xFFFFFFFFUL) && (_pStoreInfo._CCBufLen != 0)))
926         VBI_CC_Init(_pStoreInfo._ptrVBIRiuBaseAddr, _pStoreInfo._CCBufAddr, _pStoreInfo._CCBufLen);
927 
928     if((_pStoreInfo.eInitType == E_VBI_TELETEXT) && ((_pStoreInfo._TTXBufAddr != 0xFFFFFFFFUL) && (_pStoreInfo._TTXBufLen != 0)))
929     {
930         _MDrv_VBI_InitializeTTXSlicer(_pStoreInfo._TTXBufAddr, _pStoreInfo._TTXBufLen);
931     }
932 
933     VBI_RegStateRestore();
934 
935     return TRUE;
936 }
937 
_MDrv_VBI_SetPowerState(EN_POWER_MODE u16PowerState)938 MS_U32 _MDrv_VBI_SetPowerState(EN_POWER_MODE u16PowerState)
939 {
940     MS_U16 _ret = FALSE;
941 
942     switch (u16PowerState)
943     {
944         case E_POWER_SUSPEND:
945             _ret = _MDrv_VBI_Suspend();
946             break;
947 
948         case E_POWER_RESUME:
949             _ret = _MDrv_VBI_Resume();
950             break;
951 
952         case E_POWER_MECHANICAL:
953         case E_POWER_SOFT_OFF:
954         default:
955             ULOGE("VBI", "[%s] %d Power state not support!!\n", __FUNCTION__, __LINE__);
956             break;
957     }
958 
959     return ((TRUE == _ret)? UTOPIA_STATUS_SUCCESS: UTOPIA_STATUS_FAIL);
960 }
961 
_MDrv_VBI_ProtectMemory(MS_BOOL bEnable,MS_PHY phyAddr,MS_U32 u32Size)962 MS_BOOL _MDrv_VBI_ProtectMemory(MS_BOOL bEnable, MS_PHY phyAddr, MS_U32 u32Size)
963 {
964     return VBI_ProtectMemory(bEnable, phyAddr, u32Size);
965 }
966 
967 /****************************************************************************
968  *@brief            : Get VBI Library Version
969  *@param ppVersion  : [OUT] library version
970  *@return
971  *  - TRUE : get library version successfully.
972  *  - FALSE: get library version unsuccessfully.
973  ****************************************************************************/
MDrv_VBI_GetLibVer(const MSIF_Version ** ppVersion)974 MS_BOOL MDrv_VBI_GetLibVer(const MSIF_Version **ppVersion)
975 {
976     // No mutex check, it can be called before Init
977     if (!ppVersion)
978     {
979         return FALSE;
980     }
981 
982     *ppVersion = &_drv_VBI_version;
983 
984     return TRUE;
985 }
986 
987 /****************************************************************************
988  *@brief            : Get VBI Information
989  *@param
990  *@return
991  *@see VBI_DrvInfo
992  ****************************************************************************/
MDrv_VBI_GetInfo(void)993 const VBI_DrvInfo * MDrv_VBI_GetInfo(void)
994 {
995     return &_drvInfo;
996 }
997 
998 /****************************************************************************
999  *@brief            : Get VBI Driver Status
1000  *@param pDrvStatus : [OUT] driver status
1001  *@return
1002  *  - TRUE : get status successfully.
1003  *  - FALSE: get status unsuccessfully.
1004  ****************************************************************************/
MDrv_VBI_GetStatus(VBI_DrvStatus * pDrvStatus)1005 MS_BOOL MDrv_VBI_GetStatus(VBI_DrvStatus *pDrvStatus)
1006 {
1007     if(_pStoreInfo._bVBIInit == FALSE)
1008     {
1009         return FALSE;
1010     }
1011 
1012 #if (VBI_UTOPIA20)
1013     VBI_GETSTATUS_PARAM GetStatus;
1014     memset(&GetStatus, 0 , sizeof(VBI_GETSTATUS_PARAM));
1015 
1016     if (NULL == pInstantVbi)
1017     {
1018         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1019         return FALSE;
1020     }
1021 
1022     GetStatus.pDrvStatus = pDrvStatus;
1023 
1024     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_GetStatus,(void*)&GetStatus) != UTOPIA_STATUS_SUCCESS)
1025     {
1026         ULOGE("VBI", "Ioctl MDrv_VBI_GetStatus fail\n");
1027         return FALSE;
1028     }
1029     return TRUE;
1030 #else
1031     return _MDrv_VBI_GetStatus(pDrvStatus);
1032 #endif
1033 }
1034 
1035 /****************************************************************************
1036  *@brief                : Set VBI Debug Level
1037  *@param u16DbgSwitch   : [IN] debug level
1038  *@return
1039  *  - TRUE : set debug level successfully.
1040  *  - FALSE: set debug level unsuccessfully.
1041  ****************************************************************************/
MDrv_VBI_SetDbgLevel(MS_U16 u16DbgSwitch)1042 MS_BOOL MDrv_VBI_SetDbgLevel(MS_U16 u16DbgSwitch)
1043 {
1044     _pStoreInfo._u16VBIDbgSwitch = u16DbgSwitch;
1045 
1046     return TRUE;
1047 }
1048 
1049 /****************************************************************************
1050  *@brief            : Initialize VBI
1051  *@param type       : [IN] VBI type (Teletext/CC)
1052  *@return
1053  *  - TRUE : initialize VBI successfully.
1054  *  - FALSE: initialize VBI unsuccessfully.
1055  ****************************************************************************/
MDrv_VBI_Init(VBI_INIT_TYPE type)1056 MS_BOOL MDrv_VBI_Init(VBI_INIT_TYPE type)
1057 {
1058 #if (VBI_UTOPIA20)
1059     VBI_INIT_TYPE_PARAM InitType;
1060     memset(&InitType, 0 , sizeof(VBI_INIT_TYPE_PARAM));
1061 
1062     if (NULL == pInstantVbi)
1063     {
1064         if(UtopiaOpen(MODULE_VBI, (void**)&pInstantVbi, 0, pAttributeVbi) ==  UTOPIA_STATUS_FAIL)
1065         {
1066             ULOGE("VBI", "UtopiaOpen VBI fail\n");
1067             return FALSE;
1068         }
1069     }
1070     else
1071     {
1072         ULOGE("VBI", "VBI already Opened\n");
1073         return FALSE;
1074     }
1075 
1076     InitType.cmd = VBI_INIT;
1077     InitType.type = type;
1078 
1079     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_Init,(void*)&InitType) != UTOPIA_STATUS_SUCCESS)
1080     {
1081         ULOGE("VBI", "Ioctl MDrv_VBI_Init fail\n");
1082         return FALSE;
1083     }
1084     return TRUE;
1085 #else
1086     return _MDrv_VBI_Init(VBI_INIT, type);
1087 #endif
1088 }
1089 
1090 /****************************************************************************
1091  *@brief            : VBI Exit
1092  *@return
1093  *  - TRUE : VBI exit successfully.
1094  *  - FALSE: VBI exit unsuccessfully.
1095  ****************************************************************************/
MDrv_VBI_Exit(void)1096 MS_BOOL MDrv_VBI_Exit(void)
1097 {
1098 #if (VBI_UTOPIA20)
1099     VBI_CMD Cmd;
1100     memset(&Cmd, 0 , sizeof(VBI_CMD));
1101 
1102     if (NULL == pInstantVbi)
1103     {
1104         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1105         return FALSE;
1106     }
1107 
1108     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_Exit,(void*)&Cmd) != UTOPIA_STATUS_SUCCESS)
1109     {
1110         ULOGE("VBI", "Ioctl MDrv_VBI_Exit fail\n");
1111         return FALSE;
1112     }
1113     return TRUE;
1114 #else
1115     return _MDrv_VBI_Exit(VBI_EXIT);
1116 #endif
1117 }
1118 
1119 
1120 /****************************************************************************
1121  *@brief            : Set Callback to VBI driver, the CB will be called if VBI interrupt is catched
1122  *@param pFN : [IN] call back function pointer.
1123  *@param bufferAddr : [IN] the physical address of buffer which will store VBI data and pass pointer to CB
1124  *@param length : [IN] the data lebgth of th input buffer. Note: it should be the multiple of VBI_TTX_DATA_LENGTH
1125  *@return
1126  ****************************************************************************/
MDrv_VBI_RegisterCB(VBI_CB_FN pFN,MS_PHY bufferAddr,MS_U32 length)1127 void MDrv_VBI_RegisterCB(VBI_CB_FN pFN, MS_PHY bufferAddr, MS_U32 length)
1128 {
1129 #if (VBI_UTOPIA20)
1130     VBI_REGISTER_CB RegisterCB;
1131     memset(&RegisterCB, 0 , sizeof(VBI_REGISTER_CB));
1132 
1133     if (NULL == pInstantVbi)
1134     {
1135         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1136         return;
1137     }
1138 
1139     RegisterCB.pFN        = pFN;
1140     RegisterCB.bufferAddr = bufferAddr;
1141     RegisterCB.length     = length;
1142 
1143     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_RegisterCB,(void*)&RegisterCB) != UTOPIA_STATUS_SUCCESS)
1144     {
1145         ULOGE("VBI", "Ioctl MDrv_VBI_RegisterCB fail\n");
1146     }
1147 #else
1148     _MDrv_VBI_RegisterCB(pFN, bufferAddr, length);
1149 #endif
1150 }
1151 
1152 /****************************************************************************
1153  *@brief            : Reset TTX Ring Buffer
1154  *@param
1155  *@return
1156  ****************************************************************************/
MDrv_VBI_RingBuffer_Reset(void)1157 void MDrv_VBI_RingBuffer_Reset(void)
1158 {
1159 #if (VBI_UTOPIA20)
1160     if (NULL == pInstantVbi)
1161     {
1162         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1163         return;
1164     }
1165     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_RingBuffer_Reset, (void*)NULL) != UTOPIA_STATUS_SUCCESS)
1166     {
1167         ULOGE("VBI", "Ioctl MDrv_VBI_RingBuffer_Reset fail\n");
1168     }
1169 #else
1170     _MDrv_VBI_RingBuffer_Reset();
1171 #endif
1172 }
1173 
1174 /****************************************************************************
1175  *@brief            : Initialize TTX Slicer
1176  *@param bufferAddr : [IN] TTX buffer address
1177  *@param packetCount: [IN] TTX packet count
1178  *@return
1179  ****************************************************************************/
MDrv_VBI_InitializeTTXSlicer(MS_PHY bufferAddr,MS_U16 packetCount)1180 void MDrv_VBI_InitializeTTXSlicer(MS_PHY bufferAddr, MS_U16 packetCount)
1181 {
1182     if(_pStoreInfo._bTTXSupported == FALSE)
1183     {
1184         return;
1185     }
1186 
1187 #if (VBI_UTOPIA20)
1188     VBI_INITIALIZER_TTX_SLICER InitializerTTXSlicer;
1189     memset(&InitializerTTXSlicer, 0 , sizeof(VBI_INITIALIZER_TTX_SLICER));
1190 
1191     if (NULL == pInstantVbi)
1192     {
1193         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1194         return;
1195     }
1196 
1197     InitializerTTXSlicer.bufferAddr  = bufferAddr;
1198     InitializerTTXSlicer.packetCount = packetCount;
1199 
1200     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_InitializeTTXSlicer,(void*)&InitializerTTXSlicer) != UTOPIA_STATUS_SUCCESS)
1201     {
1202         ULOGE("VBI", "Ioctl MDrv_VBI_InitializeTTXSlicer fail\n");
1203     }
1204 #else
1205     _MDrv_VBI_InitializeTTXSlicer(bufferAddr, packetCount);
1206 #endif
1207 }
1208 
1209 /****************************************************************************
1210  *@brief            : Enable TTX Slicer
1211  *@param bEnable    : [IN] enable or disable TTX slicer
1212  *@return
1213  ****************************************************************************/
MDrv_VBI_EnableTTXSlicer(MS_BOOL bEnable)1214 void MDrv_VBI_EnableTTXSlicer(MS_BOOL bEnable)
1215 {
1216     if(_pStoreInfo._bTTXSupported == FALSE)
1217     {
1218         return;
1219     }
1220 
1221 #if (VBI_UTOPIA20)
1222     VBI_ENABLE_TTX_SLICER EnableTTXSlicer;
1223     memset(&EnableTTXSlicer, 0 , sizeof(VBI_ENABLE_TTX_SLICER));
1224 
1225     if (NULL == pInstantVbi)
1226     {
1227         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1228         return;
1229     }
1230 
1231     EnableTTXSlicer.bEnable = bEnable;
1232 
1233     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_EnableTTXSlicer,(void*)&EnableTTXSlicer) != UTOPIA_STATUS_SUCCESS)
1234     {
1235         ULOGE("VBI", "Ioctl MDrv_VBI_EnableTTXSlicer fail\n");
1236     }
1237 #else
1238     _MDrv_VBI_EnableTTXSlicer(bEnable);
1239 #endif
1240 }
1241 
1242 /****************************************************************************
1243  *@brief            : VPS Is Ready or Not
1244  *@param
1245  *@return
1246  *  - TRUE : VPS is ready.
1247  *  - FALSE: VPS is not ready.
1248  ****************************************************************************/
MDrv_VBI_IsVPS_Ready(void)1249 MS_BOOL MDrv_VBI_IsVPS_Ready(void)
1250 {
1251 #if (VBI_UTOPIA20)
1252     VBI_BOOL CheckTureFalse;
1253     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
1254 
1255     if (NULL == pInstantVbi)
1256     {
1257         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1258         return FALSE;
1259     }
1260 
1261     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_IsVPS_Ready,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
1262     {
1263         ULOGE("VBI", "Ioctl MDrv_VBI_IsVPS_Ready fail\n");
1264         return FALSE;
1265     }
1266     return CheckTureFalse.bCheck;
1267 #else
1268     return _MDrv_VBI_IsVPS_Ready();
1269 #endif
1270 }
1271 
1272 /****************************************************************************
1273  *@brief            : TTX Is Ready or Not
1274  *@param
1275  *@return
1276  *  - TRUE : TTX is ready.
1277  *  - FALSE: TTX is not ready.
1278  ****************************************************************************/
MDrv_VBI_IsTTX_Ready(void)1279 MS_BOOL MDrv_VBI_IsTTX_Ready(void)
1280 {
1281 #if (VBI_UTOPIA20)
1282     VBI_BOOL CheckTureFalse;
1283     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
1284 
1285     if (NULL == pInstantVbi)
1286     {
1287         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1288         return FALSE;
1289     }
1290 
1291     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_IsTTX_Ready,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
1292     {
1293         ULOGE("VBI", "Ioctl MDrv_VBI_IsTTX_Ready fail\n");
1294         return FALSE;
1295     }
1296     return CheckTureFalse.bCheck;
1297 #else
1298     return _MDrv_VBI_IsTTX_Ready();
1299 #endif
1300 }
1301 
1302 /****************************************************************************
1303  *@brief            : WSS Is Ready or Not
1304  *@param
1305  *@return
1306  *  - TRUE : WSS is ready.
1307  *  - FALSE: WSS is not ready.
1308  ****************************************************************************/
MDrv_VBI_IsWSS_Ready(void)1309 MS_BOOL MDrv_VBI_IsWSS_Ready(void)
1310 {
1311 #if (VBI_UTOPIA20)
1312     VBI_BOOL CheckTureFalse;
1313     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
1314 
1315     if (NULL == pInstantVbi)
1316     {
1317         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1318         return FALSE;
1319     }
1320 
1321     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_IsWSS_Ready,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
1322     {
1323         ULOGE("VBI", "Ioctl MDrv_VBI_IsWSS_Ready fail\n");
1324         return FALSE;
1325     }
1326     return CheckTureFalse.bCheck;
1327 #else
1328     return _MDrv_VBI_IsWSS_Ready();
1329 #endif
1330 }
1331 
1332 /****************************************************************************
1333  *@brief            : Get WSS Data
1334  *@param
1335  *@return           : return WSS data
1336  ****************************************************************************/
MDrv_VBI_GetWSS_Data(void)1337 MS_U16 MDrv_VBI_GetWSS_Data(void)
1338 {
1339 #if (VBI_UTOPIA20)
1340     VBI_GET_DATA GetData;
1341     memset(&GetData, 0 , sizeof(VBI_GET_DATA));
1342 
1343     if (NULL == pInstantVbi)
1344     {
1345         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1346         return FALSE;
1347     }
1348 
1349     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_GetWSS_Data,(void*)&GetData) != UTOPIA_STATUS_SUCCESS)
1350     {
1351         ULOGE("VBI", "Ioctl MDrv_VBI_GetWSS_Data fail\n");
1352         return FALSE;
1353     }
1354     return GetData.u16data;
1355 #else
1356     return _MDrv_VBI_GetWSS_Data();
1357 #endif
1358 }
1359 
1360 /****************************************************************************
1361  *@brief            : Get VPS Data
1362  *@param lowerWord  : [OUT] VPS lower data
1363  *@param higherWord : [OUT] VPS higher data
1364  *@return
1365  ****************************************************************************/
MDrv_VBI_GetVPS_Data(MS_U8 * lowerWord,MS_U8 * higherWord)1366 void MDrv_VBI_GetVPS_Data(MS_U8 *lowerWord, MS_U8 *higherWord)
1367 {
1368 #if (VBI_UTOPIA20)
1369     VBI_GET_VPS_DATA GetVPSData;
1370     memset(&GetVPSData, 0 , sizeof(VBI_GET_VPS_DATA));
1371 
1372     if (NULL == pInstantVbi)
1373     {
1374         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1375         return;
1376     }
1377 
1378     GetVPSData.lowerWord  = lowerWord;
1379     GetVPSData.higherWord = higherWord;
1380 
1381     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_GetVPS_Data,(void*)&GetVPSData) != UTOPIA_STATUS_SUCCESS)
1382     {
1383         ULOGE("VBI", "Ioctl MDrv_VBI_GetVPS_Data fail\n");
1384         return;
1385     }
1386 #else
1387     _MDrv_VBI_GetVPS_Data(lowerWord, higherWord);
1388 #endif
1389 }
1390 
1391 //-------------------------------------------------------------------------------------------------
1392 /// Get Complete VPS Data.
1393 /// @ingroup VBI_TTX_ToBeModified
1394 /// @param  pBuffer    \b IN/OUT: VPS buffer.
1395 /// @param  dataLen   \b IN: buffer size.
1396 /// @return None
1397 //-------------------------------------------------------------------------------------------------
1398 #define VPS_PACKET_LEN  15
1399 static MS_U8 _u8VPSData[VPS_PACKET_LEN];
MDrv_VBI_GetCompleteVPS_Data(MS_U8 ** pBuffer,MS_U32 * dataLen)1400 MS_BOOL MDrv_VBI_GetCompleteVPS_Data(MS_U8** pBuffer, MS_U32* dataLen)
1401 {
1402     VBI_GET_RAW_VPS_DATA GetRawVPSData;
1403     memset(&GetRawVPSData, 0 , sizeof(VBI_GET_RAW_VPS_DATA));
1404 
1405 #if (VBI_UTOPIA20)
1406 
1407     if (NULL == pInstantVbi)
1408     {
1409         printf("pInstantVbi=NULL fail\n");
1410         return FALSE;
1411     }
1412 
1413     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_GetRawVPS_Data, (void*)&GetRawVPSData) != UTOPIA_STATUS_SUCCESS)
1414     {
1415         printf("Ioctl MDrv_VBI_GetCompleteVPS_Data fail\n");
1416 		return FALSE;
1417     }
1418 
1419 #else
1420     _MDrv_VBI_GetRawVPS_Data(&GetRawVPSData.byte0, &GetRawVPSData.byte1, &GetRawVPSData.byte2, &GetRawVPSData.byte3);
1421 #endif
1422 
1423 
1424     if(MDrv_VBI_IsVPS_Ready())
1425     {
1426         memset(_u8VPSData, 0, VPS_PACKET_LEN);
1427         _u8VPSData[0x0D - 1] = GetRawVPSData.byte0;
1428         _u8VPSData[0x0E - 1] = GetRawVPSData.byte1;
1429         _u8VPSData[0x05 - 1] = GetRawVPSData.byte2;
1430         _u8VPSData[0x0B - 1] = GetRawVPSData.byte3;
1431 
1432         *dataLen = VPS_PACKET_LEN;
1433         *pBuffer = _u8VPSData;
1434 
1435         return TRUE;
1436     }
1437     else
1438     {
1439 	    return FALSE;
1440 	}
1441 }
1442 /****************************************************************************
1443  *@brief            : Set Video Standard
1444  *@param eStandard  : [IN] type (NTSC/PAL/SECAM)
1445  *@see VBI_VIDEO_STANDARD
1446  *@return
1447  ****************************************************************************/
MDrv_VBI_SetVideoStandard(VBI_VIDEO_STANDARD eStandard)1448 void MDrv_VBI_SetVideoStandard(VBI_VIDEO_STANDARD eStandard)
1449 {
1450 #if (VBI_UTOPIA20)
1451     VBI_SET_VIDEO_STANDARD SetVideoStandard;
1452     memset(&SetVideoStandard, 0 , sizeof(VBI_SET_VIDEO_STANDARD));
1453 
1454     if (NULL == pInstantVbi)
1455     {
1456         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1457         return;
1458     }
1459 
1460     SetVideoStandard.eStandard = eStandard;
1461 
1462     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_SetVideoStandard,(void*)&SetVideoStandard) != UTOPIA_STATUS_SUCCESS)
1463     {
1464         ULOGE("VBI", "Ioctl MDrv_VBI_SetVideoStandard fail\n");
1465     }
1466 #else
1467     _MDrv_VBI_SetVideoStandard(eStandard);
1468 #endif
1469 }
1470 
1471 /****************************************************************************
1472  *@brief            : Check if the TTX packet in VBI buffer is empty
1473  *@param
1474  *@return
1475  *  - TRUE : is empty
1476  *  - FALSE: not empty
1477  ****************************************************************************/
MDrv_VBI_TTX_PacketBufferIsEmpty(void)1478 MS_BOOL MDrv_VBI_TTX_PacketBufferIsEmpty(void)
1479 {
1480 #if (VBI_UTOPIA20)
1481     VBI_BOOL CheckTureFalse;
1482     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
1483 
1484     if (NULL == pInstantVbi)
1485     {
1486         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1487         return FALSE;
1488     }
1489 
1490     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_PacketBufferIsEmpty,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
1491     {
1492         ULOGE("VBI", "Ioctl MDrv_VBI_TTX_PacketBufferIsEmpty fail\n");
1493         return FALSE;
1494     }
1495     return CheckTureFalse.bCheck;
1496 #else
1497     return _MDrv_VBI_TTX_PacketBufferIsEmpty();
1498 #endif
1499 }
1500 
1501 /****************************************************************************
1502  *@brief            : Check TTX circuit ready
1503  *@param
1504  *@return
1505  *  - TRUE : TTX circuit is ready.
1506  *  - FALSE: TTX circuit is not ready.
1507  ****************************************************************************/
MDrv_VBI_TTX_CheckCircuitReady(void)1508 MS_BOOL MDrv_VBI_TTX_CheckCircuitReady(void)
1509 {
1510     if(_pStoreInfo._bTTXSupported == FALSE)
1511     {
1512         return FALSE;
1513     }
1514 
1515 #if (VBI_UTOPIA20)
1516     VBI_BOOL CheckTureFalse;
1517     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
1518 
1519     if (NULL == pInstantVbi)
1520     {
1521         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1522         return FALSE;
1523     }
1524 
1525     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_CheckCircuitReady,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
1526     {
1527         ULOGE("VBI", "Ioctl MDrv_VBI_TTX_CheckCircuitReady fail\n");
1528         return FALSE;
1529     }
1530     return CheckTureFalse.bCheck;
1531 #else
1532     return _MDrv_VBI_TTX_CheckCircuitReady();
1533 #endif
1534 }
1535 
1536 /****************************************************************************
1537  *@brief            : Get TTX Packet Count
1538  *@param
1539  *@return           : TTX packet count
1540  ****************************************************************************/
MDrv_VBI_TTX_GetPacketCount(void)1541 MS_U16 MDrv_VBI_TTX_GetPacketCount(void)
1542 {
1543     if(_pStoreInfo._bTTXSupported == FALSE)
1544     {
1545         return 0;
1546     }
1547 
1548 #if (VBI_UTOPIA20)
1549     VBI_GET_DATA GetData;
1550     memset(&GetData, 0 , sizeof(VBI_GET_DATA));
1551 
1552     if (NULL == pInstantVbi)
1553     {
1554         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1555         return FALSE;
1556     }
1557 
1558     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_GetPacketCount,(void*)&GetData) != UTOPIA_STATUS_SUCCESS)
1559     {
1560         ULOGE("VBI", "Ioctl MDrv_VBI_TTX_GetPacketCount fail\n");
1561         return FALSE;
1562     }
1563     return GetData.u16data;
1564 #else
1565     return _MDrv_VBI_TTX_GetPacketCount();
1566 #endif
1567 }
1568 
1569 /****************************************************************************
1570  *@brief            : Get TTX Packets
1571  *@param dataAddr   : [IN] data address
1572  *@param length     : [OUT] packet length
1573  *@return
1574  *  - TRUE : get TTX packets successfully.
1575  *  - FALSE: get TTX packets unsuccessfully.
1576  ****************************************************************************/
MDrv_VBI_TTX_GetPackets(MS_PHY dataAddr,MS_U32 * length)1577 MS_BOOL MDrv_VBI_TTX_GetPackets(MS_PHY dataAddr, MS_U32 *length)
1578 {
1579 #if (VBI_UTOPIA20)
1580     VBI_TTX_GET_PACKETS GetPackets;
1581     memset(&GetPackets, 0 , sizeof(VBI_TTX_GET_PACKETS));
1582 
1583     if (NULL == pInstantVbi)
1584     {
1585         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1586         return FALSE;
1587     }
1588 
1589     GetPackets.dataAddr= dataAddr;
1590     GetPackets.length = length;
1591 
1592     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_GetPackets,(void*)&GetPackets) != UTOPIA_STATUS_SUCCESS)
1593     {
1594         //ULOGE("VBI", "Ioctl MDrv_VBI_TTX_GetPackets fail\n");
1595         return FALSE;
1596     }
1597     return TRUE;
1598 #else
1599     return _MDrv_VBI_TTX_GetPackets(dataAddr, length);
1600 #endif
1601 }
1602 
1603 /****************************************************************************
1604  *@brief                : Get TTX Packet
1605  *@param packetAddress  : [OUT] packet address
1606  *@return
1607  *  - TRUE : get TTX packet successfully.
1608  *  - FALSE: get TTX packet unsuccessfully.
1609  ****************************************************************************/
MDrv_VBI_TTX_GetPacket(MS_PHY * packetAddress)1610 MS_BOOL MDrv_VBI_TTX_GetPacket(MS_PHY *packetAddress)
1611 {
1612 #if (VBI_UTOPIA20)
1613     VBI_TTX_GET_PACKET GetPacket;
1614     memset(&GetPacket, 0 , sizeof(VBI_TTX_GET_PACKET));
1615 
1616     if (NULL == pInstantVbi)
1617     {
1618         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1619         return FALSE;
1620     }
1621 
1622     GetPacket.packetAddress = packetAddress;
1623 
1624     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_GetPacket,(void*)&GetPacket) != UTOPIA_STATUS_SUCCESS)
1625     {
1626         //ULOGE("VBI", "Ioctl MDrv_VBI_TTX_GetPackets fail\n");
1627         return FALSE;
1628     }
1629     return TRUE;
1630 #else
1631     return _MDrv_VBI_TTX_GetPacket(packetAddress);
1632 #endif
1633 }
1634 
1635 /***********************************************************************
1636  * FUNCTION: MDrv_VBI_TTX_PacketBufferIsOverflow
1637  *
1638  * DESCRIPTION:
1639  *   Check if there is a packet buffer overflow. If there is an overflow,
1640  *   the the packet buffer should be cleared from the reading task.
1641  *
1642  * RETURN:
1643  *   TRUE if there is packet buffer overflow,
1644  *   NULL otherwise.
1645  ***********************************************************************/
MDrv_VBI_TTX_PacketBufferIsOverflow(void)1646 MS_BOOL MDrv_VBI_TTX_PacketBufferIsOverflow( void )
1647 {
1648 #if (VBI_UTOPIA20)
1649     VBI_BOOL CheckTureFalse;
1650     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
1651 
1652     if (NULL == pInstantVbi)
1653     {
1654         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1655         return FALSE;
1656     }
1657 
1658     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_PacketBufferIsOverflow,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
1659     {
1660         ULOGE("VBI", "Ioctl MDrv_VBI_TTX_PacketBufferIsOverflow fail\n");
1661         return FALSE;
1662     }
1663     return CheckTureFalse.bCheck;
1664 #else
1665     return _MDrv_VBI_TTX_PacketBufferIsOverflow();
1666 #endif
1667 }
1668 
1669 /***********************************************************************
1670  * FUNCTION: MDrv_VBI_TTX_PacketBufferGetNoOfOverflows
1671  *
1672  * DESCRIPTION:
1673  *   Resuren the nomber of packet buffer overflows since the last reset
1674  *   or creation.
1675  *
1676  * RETURN:
1677  *   The number of packet buffer overflows.
1678  ***********************************************************************/
MDrv_VBI_TTX_PacketBufferGetNoOfOverflows(void)1679 MS_U16 MDrv_VBI_TTX_PacketBufferGetNoOfOverflows( void )
1680 {
1681 #if (VBI_UTOPIA20)
1682     VBI_GET_DATA GetData;
1683     memset(&GetData, 0 , sizeof(VBI_GET_DATA));
1684 
1685     if (NULL == pInstantVbi)
1686     {
1687         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1688         return FALSE;
1689     }
1690 
1691     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_PacketBufferGetNoOfOverflows,(void*)&GetData) != UTOPIA_STATUS_SUCCESS)
1692     {
1693         ULOGE("VBI", "Ioctl MDrv_VBI_TTX_PacketBufferGetNoOfOverflows fail\n");
1694         return FALSE;
1695     }
1696     return GetData.u16data;
1697 #else
1698     return _MDrv_VBI_TTX_PacketBufferGetNoOfOverflows();
1699 #endif
1700 }
1701 
1702 /****************************************************************************
1703  *@brief            : Set TTX Enable Line
1704  *@param StartLine  : [IN] TTX start line
1705  *@param EndLine    : [IN] TTX end line
1706  *@return
1707  ****************************************************************************/
MDrv_VBI_TTX_EnableLine(MS_U16 StartLine,MS_U16 EndLine)1708 void MDrv_VBI_TTX_EnableLine(MS_U16 StartLine, MS_U16 EndLine)
1709 {
1710 #if (VBI_UTOPIA20)
1711     VBI_TTX_ENABLE_LINE EnableLine;
1712     memset(&EnableLine, 0 , sizeof(VBI_TTX_ENABLE_LINE));
1713 
1714     if (NULL == pInstantVbi)
1715     {
1716         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1717         return;
1718     }
1719 
1720     EnableLine.StartLine = StartLine;
1721     EnableLine.EndLine   = EndLine;
1722 
1723     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_TTX_EnableLine,(void*)&EnableLine) != UTOPIA_STATUS_SUCCESS)
1724     {
1725         ULOGE("VBI", "Ioctl MDrv_VBI_TTX_EnableLine fail\n");
1726         return;
1727     }
1728 #else
1729     _MDrv_VBI_TTX_EnableLine(StartLine, EndLine);
1730 #endif
1731 }
1732 
1733 /****************************************************************************
1734  *@brief            : Fresh memory to avoid cache coherence issue
1735  *@param  u32Start \b IN: start address (must be 16-B aligned and in cacheable area)
1736  *@param  u32Size  \b IN: size (must be 16-B aligned)
1737  *@return TRUE : succeed
1738  *@return FALSE : fail due to invalide parameter
1739  ****************************************************************************/
MDrv_VBI_SyncMemory(MS_U32 u32Start,MS_U32 u32Size)1740 MS_BOOL MDrv_VBI_SyncMemory( MS_U32 u32Start, MS_U32 u32Size )
1741 {
1742 #if (VBI_UTOPIA20)
1743     VBI_SYNC_MEMORY SyncMemory;
1744     memset(&SyncMemory, 0 , sizeof(VBI_SYNC_MEMORY));
1745 
1746     if (NULL == pInstantVbi)
1747     {
1748         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1749         return FALSE;
1750     }
1751 
1752     SyncMemory.u32Start = u32Start;
1753     SyncMemory.u32Size  = u32Size;
1754 
1755     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_SyncMemory,(void*)&SyncMemory) != UTOPIA_STATUS_SUCCESS)
1756     {
1757         ULOGE("VBI", "Ioctl MDrv_VBI_SyncMemory fail\n");
1758         return FALSE;
1759     }
1760     return TRUE;
1761 #else
1762     return _MDrv_VBI_SyncMemory(u32Start, u32Size);
1763 #endif
1764 }
1765 
1766 /****************************************************************************
1767  *@brief            : Initialize CC Slicer
1768  *@param u32RiuAddr : [IN] VBI CC RIU address
1769  *@param bufferAddr : [IN] VBI CC buffer address
1770  *@param packetCount: [IN] VBI CC packet count
1771  *@return
1772  ****************************************************************************/
MDrv_VBI_CC_InitSlicer(MS_VIRT u32RiuAddr,MS_PHY bufferAddr,MS_U16 packetCount)1773 void MDrv_VBI_CC_InitSlicer(MS_VIRT u32RiuAddr, MS_PHY bufferAddr, MS_U16 packetCount)
1774 {
1775 #if (VBI_UTOPIA20)
1776     VBI_CC_INIT_SLICER CCInitSlicer;
1777     memset(&CCInitSlicer, 0 , sizeof(VBI_CC_INIT_SLICER));
1778 
1779     if (NULL == pInstantVbi)
1780     {
1781         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1782         return;
1783     }
1784 
1785     CCInitSlicer.u32RiuAddr  = u32RiuAddr;
1786     CCInitSlicer.bufferAddr  = bufferAddr;
1787     CCInitSlicer.packetCount = packetCount;
1788 
1789     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_InitSlicer,(void*)&CCInitSlicer) != UTOPIA_STATUS_SUCCESS)
1790     {
1791         ULOGE("VBI", "Ioctl MDrv_VBI_CC_InitSlicer fail\n");
1792         return;
1793     }
1794 #else
1795     _MDrv_VBI_CC_InitSlicer(u32RiuAddr, bufferAddr, packetCount);
1796 #endif
1797 }
1798 
1799 /****************************************************************************
1800  *@brief            : Initialize CC CVBS number
1801  *@param cvbs_no    : [IN] CVBS number
1802  *@return
1803  ****************************************************************************/
MDrv_VBI_CC_InitYPbYr(MS_U8 cvbs_no)1804 void MDrv_VBI_CC_InitYPbYr(MS_U8 cvbs_no)
1805 {
1806 #if (VBI_UTOPIA20)
1807     VBI_CC_INIT_YPBYR CCInitYPbYr;
1808     memset(&CCInitYPbYr, 0 , sizeof(VBI_CC_INIT_YPBYR));
1809 
1810     if (NULL == pInstantVbi)
1811     {
1812         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1813         return;
1814     }
1815 
1816     CCInitYPbYr.cvbs_no = cvbs_no;
1817 
1818     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_InitYPbYr,(void*)&CCInitYPbYr) != UTOPIA_STATUS_SUCCESS)
1819     {
1820         ULOGE("VBI", "Ioctl MDrv_VBI_CC_InitYPbYr fail\n");
1821         return;
1822     }
1823 #else
1824     _MDrv_VBI_CC_InitYPbYr(cvbs_no);
1825 #endif
1826 }
1827 /****************************************************************************
1828  *@brief            : Set CC Data Rate
1829  *@param ptable     : [OUT] data rate table
1830  *@return           : data rate or 0 when failed
1831  ****************************************************************************/
MDrv_VBI_CC_SetDataRate(MS_U8 * ptable)1832 MS_U8 MDrv_VBI_CC_SetDataRate(MS_U8 *ptable)
1833 {
1834 #if (VBI_UTOPIA20)
1835     VBI_CC_SETDATARATE CCSetDataRate;
1836     memset(&CCSetDataRate, 0 , sizeof(VBI_CC_SETDATARATE));
1837 
1838     if (NULL == pInstantVbi)
1839     {
1840         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1841         return FALSE;
1842     }
1843 
1844     CCSetDataRate.ptable = ptable;
1845 
1846     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_SetDataRate,(void*)&CCSetDataRate) != UTOPIA_STATUS_SUCCESS)
1847     {
1848         ULOGE("VBI", "Ioctl MDrv_VBI_CC_SetDataRate fail\n");
1849         return FALSE;
1850     }
1851     return TRUE;
1852 #else
1853     return _MDrv_VBI_CC_SetDataRate(ptable);
1854 #endif
1855 }
1856 
1857 /****************************************************************************
1858  *@brief            : Set CC standard
1859  *@param eStandard  : [IN] video standard
1860  *@return           : TRUE or FALSE
1861  ****************************************************************************/
MDrv_VBI_CC_SetVideoStandard(VBI_VIDEO_STANDARD eStandard)1862 MS_BOOL MDrv_VBI_CC_SetVideoStandard(VBI_VIDEO_STANDARD eStandard)
1863 {
1864 #if (VBI_UTOPIA20)
1865     VBI_SET_VIDEO_STANDARD ccStandard;
1866     memset(&ccStandard, 0 , sizeof(VBI_SET_VIDEO_STANDARD));
1867 
1868     if (NULL == pInstantVbi)
1869     {
1870         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1871         return FALSE;
1872     }
1873 
1874     ccStandard.eStandard = eStandard;
1875     ccStandard.bRet = FALSE;
1876     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_SetVideoStandard,(void*)&ccStandard) != UTOPIA_STATUS_SUCCESS)
1877     {
1878         ULOGE("VBI", "Ioctl MDrv_CMD_VBI_CC_SetVideoStandard fail\n");
1879         return FALSE;
1880     }
1881 
1882     if(ccStandard.bRet == FALSE)
1883         ULOGE("VBI", "[%s] not support standard 0x%x\n", __FUNCTION__, (unsigned int)eStandard);
1884 
1885     return ccStandard.bRet;
1886 #else
1887     return _MDrv_VBI_CC_SetStandard(eStandard);
1888 #endif
1889 }
1890 
1891 /****************************************************************************
1892  *@brief            : Get CC Information
1893  *@param selector   : [IN] CC function select
1894  *@return           : packet count or indication
1895  ****************************************************************************/
MDrv_VBI_CC_GetInfo(MS_U32 selector)1896 MS_U32 MDrv_VBI_CC_GetInfo(MS_U32 selector)
1897 {
1898 #if (VBI_UTOPIA20)
1899     VBI_CC_GETINFO GetInfo;
1900     memset(&GetInfo, 0 , sizeof(VBI_CC_SETDATARATE));
1901 
1902     if (NULL == pInstantVbi)
1903     {
1904         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1905         return FALSE;
1906     }
1907 
1908     GetInfo.selector = selector;
1909 
1910     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_GetInfo,(void*)&GetInfo) != UTOPIA_STATUS_SUCCESS)
1911     {
1912         ULOGE("VBI", "Ioctl MDrv_VBI_CC_GetInfo fail\n");
1913         return FALSE;
1914     }
1915     return GetInfo.info;
1916 #else
1917     return _MDrv_VBI_CC_GetInfo(selector);
1918 #endif
1919 }
1920 
1921 /****************************************************************************
1922  *@brief            : Set CC Frame Count
1923  *@param cnt        : [IN] frame count
1924  *@return
1925  ****************************************************************************/
MDrv_VBI_CC_SetFrameCnt(MS_U8 cnt)1926 void MDrv_VBI_CC_SetFrameCnt(MS_U8 cnt)
1927 {
1928 #if (VBI_UTOPIA20)
1929     VBI_CC_SET_FRAMECNT CCSetFrameCnt;
1930     memset(&CCSetFrameCnt, 0 , sizeof(VBI_CC_SET_FRAMECNT));
1931 
1932     if (NULL == pInstantVbi)
1933     {
1934         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1935         return;
1936     }
1937 
1938     CCSetFrameCnt.cnt = cnt;
1939 
1940     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_SetFrameCnt,(void*)&CCSetFrameCnt) != UTOPIA_STATUS_SUCCESS)
1941     {
1942         ULOGE("VBI", "Ioctl MDrv_VBI_CC_SetFrameCnt fail\n");
1943         return;
1944     }
1945 #else
1946     _MDrv_VBI_CC_SetFrameCnt(cnt);
1947 #endif
1948 }
1949 
1950 /****************************************************************************
1951  *@brief            : Enable CC Slicer
1952  *@param bEnable    : [IN] enable or disable CC slicer
1953  *@return
1954  ****************************************************************************/
MDrv_VBI_CC_EnableSlicer(MS_BOOL bEnable)1955 void MDrv_VBI_CC_EnableSlicer(MS_BOOL bEnable)
1956 {
1957 #if (VBI_UTOPIA20)
1958     VBI_CC_ENABLE_SLICER CCEnableSlicer;
1959     memset(&CCEnableSlicer, 0 , sizeof(VBI_CC_ENABLE_SLICER));
1960 
1961     if (NULL == pInstantVbi)
1962     {
1963         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1964         return;
1965     }
1966 
1967     CCEnableSlicer.bEnable = bEnable;
1968 
1969     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_EnableSlicer,(void*)&CCEnableSlicer) != UTOPIA_STATUS_SUCCESS)
1970     {
1971         ULOGE("VBI", "Ioctl MDrv_VBI_CC_EnableSlicer fail\n");
1972         return;
1973     }
1974 #else
1975     _MDrv_VBI_CC_EnableSlicer(bEnable);
1976 #endif
1977 }
1978 
1979 /****************************************************************************
1980  *@brief            : Enable CC Line
1981  *@param StartLine  : [IN] start line
1982  *@param EndLine    : [IN] end line
1983  *@param mode       : [IN] NTSC/PAL/SECAM mode
1984  *@return
1985  ****************************************************************************/
MDrv_VBI_CC_EnableLine(MS_U16 StartLine,MS_U16 EndLine,MS_U8 mode)1986 void MDrv_VBI_CC_EnableLine(MS_U16 StartLine, MS_U16 EndLine, MS_U8 mode)
1987 {
1988 #if (VBI_UTOPIA20)
1989     VBI_CC_ENABLE_LINE CCEnableLine;
1990     memset(&CCEnableLine, 0 , sizeof(VBI_CC_ENABLE_LINE));
1991 
1992     if (NULL == pInstantVbi)
1993     {
1994         ULOGE("VBI", "pInstantVbi=NULL fail\n");
1995         return;
1996     }
1997 
1998     CCEnableLine.StartLine = StartLine;
1999     CCEnableLine.EndLine   = EndLine;
2000     CCEnableLine.mode      = mode;
2001 
2002     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_EnableLine,(void*)&CCEnableLine) != UTOPIA_STATUS_SUCCESS)
2003     {
2004         ULOGE("VBI", "Ioctl MDrv_VBI_CC_EnableLine fail\n");
2005         return;
2006     }
2007 #else
2008     _MDrv_VBI_CC_EnableLine(StartLine, EndLine, mode);
2009 #endif
2010 }
2011 
2012 /****************************************************************************
2013  *@brief            : Set CC SC window length
2014  *@param u8Len      : [IN] windows length
2015  *@return           : TRUE / FALSE
2016  ****************************************************************************/
MDrv_VBI_CC_SetSCWindowLen(MS_U8 u8Len)2017 MS_BOOL MDrv_VBI_CC_SetSCWindowLen(MS_U8 u8Len)
2018 {
2019 #if (VBI_UTOPIA20)
2020     VBI_CC_SET_SC_WND_LEN SCWndLen;
2021     memset(&SCWndLen, 0 , sizeof(VBI_CC_SET_SC_WND_LEN));
2022 
2023     if (NULL == pInstantVbi)
2024     {
2025         ULOGE("VBI", "pInstantVbi=NULL fail\n");
2026         return FALSE;
2027     }
2028 
2029     SCWndLen.u8Len  = u8Len;
2030     SCWndLen.bRet   = FALSE;
2031 
2032     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_CC_SetSCWindowLen,(void*)&SCWndLen) != UTOPIA_STATUS_SUCCESS)
2033     {
2034         ULOGE("VBI", "Ioctl MDrv_VBI_CC_SetSCWindowLen fail\n");
2035         return FALSE;
2036     }
2037 
2038     return SCWndLen.bRet;
2039 #else
2040     return _MDrv_VBI_CC_SetSCWindowLen(u8Len);
2041 #endif
2042 }
2043 /****************************************************************************
2044  *@brief            : Set WSS/VPS Byte Number
2045  *@param cnt        : [IN] byte number
2046  *@return
2047  ****************************************************************************/
MDrv_VBI_WSS_SetVpsByteNum(MS_U8 cnt)2048 void MDrv_VBI_WSS_SetVpsByteNum(MS_U8 cnt)
2049 {
2050 #if (VBI_UTOPIA20)
2051     VBI_VBI_WSS_VPSBYTENUM WSSSetVpsByteCnt;
2052     memset(&WSSSetVpsByteCnt, 0 , sizeof(VBI_VBI_WSS_VPSBYTENUM));
2053 
2054     if (NULL == pInstantVbi)
2055     {
2056         ULOGE("VBI", "pInstantVbi=NULL fail\n");
2057         return;
2058     }
2059 
2060     WSSSetVpsByteCnt.cnt = cnt;
2061 
2062     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_WSS_SetVpsByteNum,(void*)&WSSSetVpsByteCnt) != UTOPIA_STATUS_SUCCESS)
2063     {
2064         ULOGE("VBI", "Ioctl MDrv_VBI_WSS_SetVpsByteNum fail\n");
2065         return;
2066     }
2067 #else
2068     _MDrv_VBI_WSS_SetVpsByteNum(cnt);
2069 #endif
2070 }
2071 
2072 /****************************************************************************
2073 *@brief            : Suspend VBI driver
2074 *@return TRUE - Success
2075 *@return FALSE - Failure
2076 *@note
2077 *@Save VBI driver states to DRAM
2078 ****************************************************************************/
MDrv_VBI_Suspend(void)2079 MS_BOOL MDrv_VBI_Suspend(void)
2080 {
2081 #if (VBI_UTOPIA20)
2082     VBI_BOOL CheckTureFalse;
2083     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
2084 
2085     if (NULL == pInstantVbi)
2086     {
2087         ULOGE("VBI", "pInstantVbi=NULL fail\n");
2088         return FALSE;
2089     }
2090 
2091     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_Suspend,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
2092     {
2093         ULOGE("VBI", "Ioctl MDrv_VBI_Suspend fail\n");
2094         return FALSE;
2095     }
2096     return CheckTureFalse.bCheck;
2097 #else
2098     return _MDrv_VBI_Suspend();
2099 #endif
2100 }
2101 
2102 /****************************************************************************
2103 *@brief            :  Resume VBI driver
2104 *@return TRUE - Success
2105 *@return FALSE - Failure
2106 *@note
2107 *@Save VBI driver states to DRAM
2108 *@Restore VBI driver states from DRAM
2109 ****************************************************************************/
MDrv_VBI_Resume(void)2110 MS_BOOL MDrv_VBI_Resume(void)
2111 {
2112 #if (VBI_UTOPIA20)
2113     VBI_BOOL CheckTureFalse;
2114     memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
2115 
2116     if (NULL == pInstantVbi)
2117     {
2118         ULOGE("VBI", "pInstantVbi=NULL fail\n");
2119         return FALSE;
2120     }
2121 
2122     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_Resume,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
2123     {
2124         ULOGE("VBI", "Ioctl MDrv_VBI_Resume fail\n");
2125         return FALSE;
2126     }
2127     return CheckTureFalse.bCheck;
2128 #else
2129     return _MDrv_VBI_Resume();
2130 #endif
2131 }
2132 
2133 /****************************************************************************
2134 *@brief            : Set VBI suspend & resume
2135 *@param u16PowerState              \b IN: VBI power state
2136 *@return TRUE - Success
2137 *@return FALSE - Failure
2138 *@note
2139 ****************************************************************************/
MDrv_VBI_SetPowerState(EN_POWER_MODE u16PowerState)2140 MS_U32 MDrv_VBI_SetPowerState(EN_POWER_MODE u16PowerState)
2141 {
2142 #if (VBI_UTOPIA20)
2143     VBI_GET_RESULT GetResult;
2144     memset(&GetResult, 0 , sizeof(VBI_GET_RESULT));
2145 
2146     if (NULL == pInstantVbi)
2147     {
2148         ULOGE("VBI", "pInstantVbi=NULL fail\n");
2149         return FALSE;
2150     }
2151 
2152     GetResult.u16PowerState = u16PowerState;
2153 
2154     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_SetPowerState,(void*)&GetResult) != UTOPIA_STATUS_SUCCESS)
2155     {
2156         ULOGE("VBI", "Ioctl MDrv_VBI_SetPowerState fail\n");
2157         return FALSE;
2158     }
2159     return GetResult.u32result;
2160 #else
2161     return _MDrv_VBI_SetPowerState();
2162 #endif
2163 }
2164 
2165 /****************************************************************************
2166 *@brief                     : restrict vbi memory buffer range
2167 *@phyAddr                   : start address of the range
2168 *@u32Size                   : size of the range
2169 *@return TRUE - Success
2170 *@return FALSE - Failure
2171 ****************************************************************************/
MDrv_VBI_ProtectMemory(MS_BOOL bEnable,MS_PHY phyAddr,MS_U32 u32Size)2172 MS_BOOL MDrv_VBI_ProtectMemory(MS_BOOL bEnable, MS_PHY phyAddr, MS_U32 u32Size)
2173 {
2174     return VBI_ProtectMemory(bEnable, phyAddr, u32Size);
2175 
2176 #if (VBI_UTOPIA20)
2177     VBI_PROTECT_MEMORY ProtectMemory;
2178     memset(&ProtectMemory, 0 , sizeof(VBI_PROTECT_MEMORY));
2179 
2180     if (NULL == pInstantVbi)
2181     {
2182         ULOGE("VBI", "pInstantVbi=NULL fail\n");
2183         return FALSE;
2184     }
2185 
2186     ProtectMemory.bEnable = bEnable;
2187     ProtectMemory.phyAddr = phyAddr;
2188     ProtectMemory.u32Size = u32Size;
2189 
2190     if(UtopiaIoctl(pInstantVbi, MDrv_CMD_VBI_ProtectMemory,(void*)&ProtectMemory) != UTOPIA_STATUS_SUCCESS)
2191     {
2192         ULOGE("VBI", "Ioctl MDrv_VBI_ProtectMemory fail\n");
2193         return FALSE;
2194     }
2195     return ProtectMemory.bRet;
2196 #else
2197     return _MDrv_VBI_ProtectMemory(bEnable, phyAddr, u32Size);
2198 #endif
2199 }
2200 
2201 #undef _DRV_VBI_C
2202