xref: /utopia/UTPA2-700.0.x/modules/vdec_v1/drv/mvd/drvMVD.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 /// file  drvMVD.c
94 /// @brief MPEG-2/4 Video Decoder Driver
95 /// @author MStar Semiconductor Inc.
96 ///
97 ////////////////////////////////////////////////////////////////////////////////
98 
99 //-------------------------------------------------------------------------------------------------
100 //  Include Files
101 //-------------------------------------------------------------------------------------------------
102 #ifdef REDLION_LINUX_KERNEL_ENVI
103 #include "drvMVD_Common.h"
104 #include "drvMVD.h"
105 #include "regMVD.h"
106 #include "halMVD.h"
107 #include "halVPU.h"
108 #include "drvmvd_cc.h"      //ATSC Closed Caption
109 #else
110 
111 // Common Definition
112 #include "MsCommon.h"
113 #include "MsVersion.h"
114 #include "halCHIP.h"
115 #include "drvMMIO.h"
116 #include "drvMIU.h"
117 #include "drvBDMA.h"
118 #include "drvMVD.h"
119 
120 // Internal Definition
121 #include "regMVD.h"
122 #include "halMVD.h"
123 #include "asmCPU.h"
124 #include "osalMVD.h"
125 #include "drvmvd_cc.h"      //ATSC Closed Caption
126 #endif
127 
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 // Local defines & local structures
131 ////////////////////////////////////////////////////////////////////////////////
132 //Different level debug message
133 #define MVD_DEBUGVERBAL(x)    if (_u8DbgLevel>4)  { (x); }
134 #define MVD_DEBUGINFO(x)      if (_u8DbgLevel>1)  { (x); }
135 #define MVD_DEBUGERROR(x)     if (_u8DbgLevel>0)  { (x); }
136 #define MVD_FUNC_ENTRY()      {}//printf(" $$$ drvMVD::%s\n", __FUNCTION__)
137 #define MVD_DBG_STS(x)        {}
138 #define _SLQTBL_DUMP_PTS      FALSE//TRUE
139 #define _SLQTBL_DUMP_PUSHQ    FALSE//TRUE
140 #define _SLQTBL_DUMP_PKT      FALSE//TRUE
141 #define _DUMP_FRMINFO         FALSE
142 #define MVD_TURBO_INIT        FALSE//TRUE
143 #define MVD_PROFILING         FALSE//TRUE
144 #define SLQ_NEW_PUSH          TRUE
145 #define UPDATE_NEXT_WRPTR     FALSE //SlqTbl mode: update (validWrPtr+1) to hw for mvd6
146 //#define _MVD_V3              //define for sub decoder verification
147 
148 #define MVD_FBNUM_DEFAULT 4
149 #define MVD_FBNUM_MAX     5
150 #define MVD_FBNUM_MIN     MVD_FBNUM_DEFAULT
151 
152 #define MVD_DHD_FBSIZE           0x5FA000  //Framebuffer size minimum for Dual HD: (1920*2)*1088*1.5
153 #define MVD_HD_FBSIZE            0x2FD000  //Framebuffer size minimum for High Definition
154 #define MVD4_5_FBSIZE_HDMIN      0xEF1000  //5 * 1920 * 1088 * 1.5 = 14.95MB
155 #define MVD4_4_FBSIZE_HDMIN      0xBF4000  //4 * 1920 * 1088 * 1.5 = 11.96MB
156 #define MVD4_VC1_FBSIZE_SDMIN    0x2F7600  //5 * 720 * 576 * 1.5 = 2.97MB
157 #define MVD4_MPEG_FBSIZE_HDMIN   0xBF4000  //4 * 1920 * 1088 * 1.5 = 11.96MB
158 #define MVD4_MPEG_FBSIZE_SDMIN   0x25F800  //4 * 720 * 576 * 1.5 = 2.38MB
159 
160 #if (defined(CHIP_A1) || defined(CHIP_A5) || defined(CHIP_A2) || defined(CHIP_A7)\
161     || defined(CHIP_A3) || defined(CHIP_AMETHYST) || defined(CHIP_EDISON) || defined(CHIP_EMERALD)\
162     || defined(CHIP_AGATE) || defined(CHIP_EAGLE) || defined(CHIP_EIFFEL)) || defined(CHIP_EULER)\
163     || defined(CHIP_NUGGET)
164 #define _MVD6
165 #endif
166 
167 #define _MS_TO_90K(x)   (x*90)  //ms ==> 90k counter
168 #define _90K_TO_MS(x)   ((x!=MVD_U32_MAX)?(x/90):(x))  //90k counter ==> ms
169 
170 #define _IS_VC1(x) ((x==E_MVD_CODEC_VC1_ADV) || (x==E_MVD_CODEC_VC1_MAIN))
171 
172 #define _MVD_Memset(pDstAddr, u32value, u32Size)                        \
173             do {                                                        \
174                 MS_U32 x = 0;                                           \
175                 for (x = 0; x < (u32Size/4); x=x+4)                     \
176                 {                                                       \
177                     HAL_MVD_MemWrite4Byte(pDstAddr+x,u32value);         \
178                 }                                                       \
179             } while (0)
180 
181 #define _MVD_Memcpy(pDstAddr, pSrcAddr, u32Size)                        \
182             do {                                                        \
183                 MS_U32 i = 0;                                           \
184                 volatile MS_U8 *dst = (volatile MS_U8 *)(pDstAddr);     \
185                 volatile MS_U8 *src = (volatile MS_U8 *)(pSrcAddr);     \
186                 for (i = 0; i < (u32Size); i++)                         \
187                 {                                                       \
188                     dst[i] = src[i];                                    \
189                 }                                                       \
190             } while (0)
191 
192 #define _MVD_INIT_FAIL_RET()                                            \
193             do {                                                        \
194                 if (_bFwLoad)                                           \
195                     _bFwLoad = FALSE;                                   \
196                 HAL_MVD_SetVpuFwDecoder(E_VPU_DECODER_NONE);            \
197                 return FALSE;                                           \
198             } while (0)
199 
200 #define MVD_U32_MAX                 0xffffffffUL
201 #define MVD_NULLPKT_PTS             MVD_U32_MAX
202 #define MAX_ADD_28BIT               0x0fffffff
203 #define MAX_ADD_27BIT               0x07ffffff
204 
205 //Initial value for PTS table
206 #define _INIT_ADDR                  MVD_U32_MAX
207 #define _INIT_LEN                   0
208 #define _INIT_TIMESTAMP             MVD_U32_MAX
209 #define _INIT_ID                    MVD_U32_MAX
210 
211 #define SLQ_ENTRY_MAX               1024
212 #define SLQ_ENTRY_LEN               8   //8-byte per entry
213 #define SLQ_TBL_SIZE                (SLQ_ENTRY_MAX * SLQ_ENTRY_LEN)
214 #define ES_TBL_SIZE                 (SLQ_ENTRY_MAX * 8) //8-byte per entry
215 
216 #define MVD_FW_SLQTBL_PTS_LEN       32
217 
218 #define SLQ_TBL_SAFERANGE              (40*SLQ_ENTRY_LEN)
219 //this should be smaller than FW's lookup range (current it's 16 entries)
220 
221 #define SLQTBL_CHECKVACANCY_WATERLEVEL (44*SLQ_ENTRY_LEN)
222 
223 #define DIVX_PATTERN    0x63643030
224 #define FLV_PATTERN     0xffff0000
225 #define MPEG_PATTERN_0  0xC6010000 //this SC just for mpeg2/4
226 #if SLQ_NEW_PUSH
227 #define VC1_PATTERN    0x0D010000
228 #define RCV_PATTERN     0xFF00A55A
229 #endif
230 #define VC1_PATTERN_0   0xff010000
231 #define VC1_PATTERN_1   0x0000ffff
232 #define VC1_PATTERN_2   0xffffff01
233 
234 #define RCV_PATTERN_0   0x00000000
235 #define RCV_PATTERN_1   0xffffffff
236 #define RCV_PATTERN_2   0x00000000
237 
238 #define DUMMY_PATTERN   0xBE010000
239 #define DUMMY_SIZE      0x2000     //8K
240 
241 #define END_PATTERN_0   0xFF010000
242 #define END_PATTERN_1   0xDDCCBBAA
243 #define END_PATTERN_2   0xBBAAFFEE
244 #define END_PATTERN_3   0xFFEEDDCC
245 #define END_PATTERN_SIZE 256
246 
247 #define SKIP_PATTERN_0  0xc5010000
248 #define SKIP_PATTERN_1  0x270608ab
249 #define SKIP_PATTERN_SIZE 8
250 
251 #define CMD_TIMEOUT_MS  500
252 
253 //Length of internal buffers
254 #ifdef _MVD6
255 #define MVD3_FW_IAP_BUF_ALIGN               (0x4000UL)   // 16k
256 #define MVD3_FW_DP_BUF_ALIGN                (0x8000UL)   // 32k
257 #define MVD3_FW_MV_BUF_ALIGN                (0x8000UL)   // 32k
258 #define MVD3_FW_IAP_BUF_LEN                 (0x4000UL)   // 16k
259 #define MVD3_FW_DP_BUF_LEN                  (0x80000UL)  //512k
260 #define MVD3_FW_MV_BUF_LEN                  (0x48000UL)  //288K
261 #else
262 #define MVD3_FW_IAP_BUF_ALIGN               (0x2000UL)   //  8k
263 #define MVD3_FW_DP_BUF_ALIGN                (0x08)       //  8  byte
264 #define MVD3_FW_MV_BUF_ALIGN                (0x0800UL)   //  2k
265 #define MVD3_FW_IAP_BUF_LEN                 (0x4000UL)   // 16k
266 #define MVD3_FW_DP_BUF_LEN                  (0x40000UL)  //256k (1920/16) * (1088/16)* 4 * 8 = 255KB
267 #define MVD3_FW_MV_BUF_LEN                  (0x40000UL)  //256K ((1920/16)*4*1.5+((1920/16)*(1088/16)*4*1.5)*4
268 #endif
269 #define MVD3_FW_VOL_INFO_BUF_LEN            (0x1000UL)   //  4K
270 #define MVD3_FW_FRAME_INFO_BUF_LEN          (0x1000UL)   //  4K
271 #define MVD3_FW_DIVX_INFO_BUF_LEN           (0x1000UL)   //  4K
272 #define MVD3_FW_USER_DATA_BUF_LEN           (0x1000UL)   //  4K
273 #define MVD3_FW_USER_DATA_BUF_BACKUP_LEN    MVD3_FW_USER_DATA_BUF_LEN // 4K
274 #define MVD3_FW_SLQ_TAB_BUF_LEN             (0x2000UL)   //  8K
275 #define MVD3_FW_SLQ_TAB_TMPBUF_LEN          (0x200UL)
276 
277 #define MVD_FW_SLQTBL_PTS_BUF_LEN           (SLQ_ENTRY_MAX*MVD_FW_SLQTBL_PTS_LEN)
278 
279 #define MVD_FW_DYN_SCALE_BUF_LEN            (0x1000UL)   //  4K
280 #define MVD_FW_SCALER_INFO_BUF_LEN          (0x100UL)    // 256bytes reserved
281 #define MVD_FW_DECFRM_INFO_BUF_LEN          (0x100UL)    // 256bytes reserved
282 #define MVD_FW_USER_DATA_HDR_LEN            (6)
283 #define MVD_FW_USER_DATA_PKT_LEN            (256)
284 #define MVD_FW_USER_DATA_EXT_HDR_LEN        (16)
285 
286 #define PB_ONLY_UNMUTE_VSYNC_COUNT          30
287 
288 #define MVD_UNMUTE_STC_PTS_GAP              (5500 * 90)
289 
290 //Default framerate 30fps, i.e. 30 frames or 60 fields per sec.
291 #define MVD_FRAMERATE_DEFAULT               30000
292 
293 #ifndef UNUSED
294 #define UNUSED(x) (void)(x)
295 #endif
296 
297 //Table of frame rate code for MPEG-2
298 static const MS_U16 stFrameRateCode[9]=
299 {
300     NULL,23976,24000,25000,29976,30000,50000,59947,60000
301 };
302 
303 typedef struct _MVD_SLQ_TBL_ST
304 {
305     MS_U32 u32StAdd;
306     MS_U32 u32EndAdd;
307     MS_U32 u32EntryCntMax;
308 
309     MS_U32 u32RdPtr;
310     MS_U32 u32WrPtr;
311     MS_U32 u32Empty;
312 } MVD_SLQ_TBL_ST;
313 
314 typedef struct _MVD_SLQ_ES_ST
315 {
316     MS_U32 u32StAdd;
317     MS_U32 u32EndAdd;
318 
319     MS_U32 u32RdPtr;
320     MS_U32 u32WrPtr;
321 } MVD_SLQ_ES_ST;
322 
323 typedef struct _MVD_CMD_QUEUE
324 {
325     MS_U32 u32PtsBase;
326 } MVD_CMD_QUEUE;
327 #if SLQ_NEW_PUSH
328 typedef struct _MVD_SLQ_STATUS
329 {
330     MS_BOOL bSlqPicStart;
331     MS_BOOL bSlqPicCollect;
332     MS_BOOL bSlqPicWaitNextStart;
333     MS_BOOL bSlqFireRdy;
334     MS_BOOL bSlqCtrlBit;
335     MS_BOOL bSlqEnLastFrameShow;
336     MS_U32 u32SlqPatternAddr;
337     MS_U32 u32SlqPushLength;
338     MS_U32 u32VaildWptrAddr;
339 } MVD_SLQ_STATUS;
340 #endif
341 ////////////////////////////////////////////////////////////////////////////////
342 // Local Global Variables
343 ////////////////////////////////////////////////////////////////////////////////
344 /// Version string
345 static MSIF_Version _drv_mvd_version = {
346     .DDI = { MVD_DRV_VERSION, },
347 };
348 
349 static MS_U32 pu8MVDSetHeaderBufStart=NULL;
350 static MS_U32 pu8MVDGetVolBufStart=NULL;
351 static MS_U32 pu8MVDGetFrameInfoBufStart=NULL;
352 static MS_U32 u32MVDFWSLQTABTmpbufAdr = NULL;
353 static MS_U32 u32MVDFWPtsTblAddr = NULL;
354 static MS_U32 u32DecFrmInfoAdd = NULL;
355 static MS_U32 u32DynScalingAdd = NULL;
356 static MS_U32 u32ScalerInfoAdd = NULL;
357 static MS_U8  u8DynScalingDepth = 0;
358 static MS_U32 u32VolAdd;
359 static MS_U32 u32ESBuffEnd = 0; //miu offset of ES buffer end
360 static MS_U32 u32UsrData = NULL;
361 static MS_U32 u32UsrDataRd = 0;
362 static MS_U32 u32UsrDataWr = 0;
363 
364 static FW_DIVX_INFO gdivxInfo;
365 #if (!defined(CHIP_T7))
366 static FW_VOL_INFO gvolInfo;
367 #endif
368 static MS_BOOL _bDecodeIFrame = FALSE;
369 static MS_BOOL _bDrvInit = FALSE;
370 MS_BOOL bStopped = TRUE;
371 static MS_BOOL _bFwLoad = FALSE;
372 
373 static MS_U8   u8FBMode;
374 static MS_U8   u8FBNum = 0;
375 static MS_U32  u32FbHdSize = 0;
376 static MS_U32  u32FbSdSize = 0;
377 
378 static MVD_TrickDec eTrickMode = E_MVD_TRICK_DEC_UNKNOWN;
379 static MS_BOOL bAVSyncOn = FALSE;
380 
381 static MS_U8 _u8DbgLevel = 0;
382 static MVD_DrvInfo _stDrvInfo = {
383                                     1,      //1 MVD HW
384                                     0,      //Device#   fixme
385                                     MVD_FW_VERSION,        //firmware version
386                                     { FALSE, FALSE, FALSE } //capability
387                                 };
388 
389 static MVD_FrameInfo stPreFrmInfo;
390 static MVD_CodecType curCodecType;
391 static MVD_SrcMode curSrcMode;
392 static MS_U8 curDisablePESParsing;
393 #if SLQ_NEW_PUSH
394 static MVD_SLQ_STATUS _SlqStatus;
395 #define SLQ_PIC_START_FLAG 0x40000000
396 #endif
397 MVD_MEMCfg stMemCfg;
398 MVD_FWCfg stFwCfg;
399 static MS_BOOL bStepDecode = FALSE;
400 #if (defined(CHIP_T2))||(defined(CHIP_T7))
401 static MS_U32 u32StepDecodeCnt = 0;
402 #endif
403 static MS_BOOL bStepDisp = FALSE;
404 static MS_BOOL bStep2Pts = FALSE;
405 static MS_BOOL bSkip2Pts = FALSE;
406 static MS_BOOL bDropErrFrm = FALSE;
407 static MS_BOOL bDropDispfrm = FALSE;
408 static MVD_FrcMode _eFrcMode = E_MVD_FRC_NORMAL;
409 static MS_BOOL bEnableLastFrmShow = FALSE;
410 static MS_U32 u32LastPts = MVD_NULLPKT_PTS;
411 static MS_U32 u32DummyPktCnt = 0;
412 static MS_U32 u32SlqByteCnt = 0;
413 static MS_BOOL bSlqTblSync = FALSE; //need to BDMA SLQ table from DrvProcBuff to BitstreamBuff
414 static MS_BOOL bSlqTblHasValidData = FALSE;
415 static MS_BOOL bSlqTblHKCtrl = FALSE;   //read/write pointer can be accessed by HK directly
416 static MS_U32 u32FileEndPtr;
417 
418 #ifndef REDLION_LINUX_KERNEL_ENVI
419 static BDMA_CpyType bdmaCpyType = E_BDMA_CPYTYPE_MAX;
420 #endif
421 
422 static MVD_SLQ_TBL_ST _drvSlqTbl;
423 static MS_U32 u32PreEsRd = MVD_U32_MAX;
424 static MS_U32 u32PreEsWr = 0;
425 
426 static MVD_SLQ_ES_ST _drvEsTbl;
427 static MVD_SLQ_ES_ST _drvDivxTbl;
428 
429 static MVD_CMD_QUEUE _mvdCmdQ;
430 
431 static MVD_TIMESTAMP_TYPE _eFileSyncMode;
432 static MVD_AVSyncCfg stSyncCfg;
433 static MVD_SpeedType ePreSpeedType = E_MVD_SPEED_DEFAULT;
434 #if defined(CHIP_T7)
435 static MS_U8 u8MvdPlayMode = 0;
436 #endif
437 
438 #ifdef MVD_ENABLE_ISR
439 MVD_InterruptCb pfnCallback;
440 static MS_U32 eEventFlag;
441 static MS_U32 eCurEvent;
442 #endif
443 
444 static MVD_InternalMemCfg _stInternalMemCfg;
445 
446 static MS_U32 u32SyncDoneCnt = 0;
447 static MS_U32 u32VSyncCnt = 0;
448 static MS_BOOL bIsrAttached = FALSE;
449 #define MST_MODE_TRUE   1
450 #define MST_MODE_FALSE  0
451 static MS_U8 u8MstMode = MST_MODE_FALSE; //MStreamer mode=1; Non-MSt mode=0.
452 #define MDrv_MVD_IsMStreamerMode()  (MST_MODE_TRUE == u8MstMode)
453 #ifdef _MVD_V3
454 static MS_BOOL bRdyToFireCmd = FALSE;
455 #endif
456 static MS_U32 u32HWBuffTotalSize = 0;
457 
458 //MVD_HWCfg* _pMvdHWCfg;
459 ////////////////////////////////////////////////////////////////////////////////
460 // Local functions
461 ////////////////////////////////////////////////////////////////////////////////
462 static MS_BOOL MVD_MVDSetInternalBuffAddr(MS_U32 u32start, MS_U32 u32len);
463 static void MVD_InitVar(void);
464 static MS_BOOL MVD_Init(void);
465 static MS_U8 MVD_MapCodecType(MVD_CodecType type);
466 static MS_U8 MVD_MapSrcMode(MVD_SrcMode mode);
467 static void MVD_WriteDivx311Data(FW_DIVX_INFO *divxInfo);
468 static MVD_ErrStatus MVD_GetErrShapeStat(MS_U32 u32errStat);
469 static MVD_ErrStatus MVD_GetErrSpriteStat(MS_U32 u32errStat);
470 static MS_U8 MVD_MapFrcMode(MVD_FrcMode eFrcMode);
471 static E_MVD_Result MVD_RstFrmInfo(MVD_FrmInfoType eType);
472 
473 static MS_BOOL MVD_SLQTblSendPacket(MVD_PacketInfo *pstVideoPKT);
474 #if SLQ_NEW_PUSH
475 static void MVD_SLQTblGetHdrPkt(MVD_PacketInfo* pHdr, MVD_PacketInfo* pData);
476 #else
477 static void MVD_SLQTblGetDivxHdrPkt(MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData);
478 #endif
479 static MS_BOOL MDrv_MVD_Stop(void);
480 static void MVD_SLQTblInit(void);
481 //static void _SLQTbl_DumpInfo(MVD_SLQ_TBL_ST* pInfo);
482 static MS_U32 MVD_GetMemOffset(MS_PHYADDR u32PhyAdd);
483 static MS_U32 MVD_Map2DrvSlqTbl(MS_U32 u32HWPtr);
484 static void MVD_SLQTblGetDummyPkt(MVD_PacketInfo* pDummy);
485 static void MVD_SLQTblGetFileEndPkt(MVD_PacketInfo* pFileEnd);
486 
487 static MS_BOOL MDrv_MVD_ClearCmdFinished(MVD_HANDSHAKE_CMD eCmd);
488 
489 static MS_BOOL MVD_SLQTblInsertPattern(MVD_PatternType ePattern);
490 #if _SLQTBL_DUMP_PTS
491 static void _SLQTbl_DumpPtsTbl(MS_U32 u32EntryStart, MS_U32 u32EntryEnd);
492 #endif
493 
494 #if _DUMP_FRMINFO
MVD_DumpFrmInfo(MVD_FrmInfo * pInfo)495 static void MVD_DumpFrmInfo(MVD_FrmInfo* pInfo)
496 {
497     if (NULL == pInfo)
498     {
499         printf("%s: pInfo invalid!\n", __FUNCTION__);
500         return;
501     }
502 
503     printf("u32LumaAddr  =0x%lx\n", pInfo->u32LumaAddr  );
504     printf("u32ChromaAddr=0x%lx\n", pInfo->u32ChromaAddr);
505     printf("u32TimeStamp =0x%lx\n", pInfo->u32TimeStamp );
506     printf("u32ID_L      =0x%lx\n", pInfo->u32ID_L      );
507     printf("u32ID_H      =0x%lx\n", pInfo->u32ID_H      );
508     printf("u16Pitch     =0x%x\n", pInfo->u16Pitch      );
509     printf("u16Width     =0x%x\n", pInfo->u16Width      );
510     printf("u16Height    =0x%x\n", pInfo->u16Height     );
511     printf("eFrmType     =0x%x\n", pInfo->eFrmType      );
512     return;
513 }
514 #endif
515 
516 
517 //------------------------------------------------------------------------------
518 /// Get MVD driver information
519 /// @return -the pointer to the driver information
520 //------------------------------------------------------------------------------
MDrv_MVD_GetInfo(void)521 const MVD_DrvInfo* MDrv_MVD_GetInfo(void)
522 {
523     MDrv_MVD_GetCaps(&_stDrvInfo.stCaps);
524     return (&_stDrvInfo);
525 }
526 
527 
528 //------------------------------------------------------------------------------
529 /// Get MVD driver version
530 /// @return -the pointer to the driver version
531 //------------------------------------------------------------------------------
MDrv_MVD_GetLibVer(const MSIF_Version ** ppVersion)532 E_MVD_Result MDrv_MVD_GetLibVer(const MSIF_Version **ppVersion)
533 {
534     if (!ppVersion)
535         return E_MVD_RET_FAIL;
536 
537     *ppVersion = &_drv_mvd_version;
538     return E_MVD_RET_OK;
539 }
540 
541 //------------------------------------------------------------------------------
542 /// Get MVD driver status
543 /// @return -the pointer to the driver status
544 //------------------------------------------------------------------------------
MDrv_MVD_GetStatus(MVD_DrvStatus * pDrvStatus)545 void MDrv_MVD_GetStatus(MVD_DrvStatus* pDrvStatus)
546 {
547     if (!pDrvStatus)
548        return;
549 
550     pDrvStatus->u32FWVer = MDrv_MVD_GetFWVer();
551     if (pDrvStatus->u32FWVer == 0) //timeout to get FW version
552     {
553         pDrvStatus->bIsBusy = TRUE;
554     }
555     else
556     {
557         pDrvStatus->bIsBusy = FALSE;
558     }
559     pDrvStatus->eDecStat = MDrv_MVD_GetDecodeStatus();
560     pDrvStatus->u8LastFWCmd = MDrv_MVD_GetLastCmd();
561     return;
562 }
563 
564 
565 //------------------------------------------------------------------------------
566 /// Set detailed level of MVD driver debug message
567 /// 0: None, 1: MVD_DEBUGERROR, 2: MVD_DEBUGINFO
568 /// @param level  \b IN  level from 0 to 2
569 //------------------------------------------------------------------------------
MDrv_MVD_SetDbgLevel(MS_U8 level)570 void MDrv_MVD_SetDbgLevel(MS_U8 level)
571 {
572     _u8DbgLevel = level;
573     if (level >= 2)
574     {
575         HAL_MVD_SetDbgLevel(level-1);
576     }
577     return;
578 }
579 
580 
581 //------------------------------------------------------------------------------
582 /// Get MVD firmware version
583 /// @return -firmware version
584 //------------------------------------------------------------------------------
MDrv_MVD_GetFWVer(void)585 MS_U32 MDrv_MVD_GetFWVer(void)
586 {
587     return HAL_MVD_GetFWVer();
588 }
589 
590 //------------------------------------------------------------------------------
591 /// Set SLQ table buffer address to MVD
592 /// @param -u32addr \b IN : start address
593 //------------------------------------------------------------------------------
MDrv_MVD_SetSLQTblBufStartEnd(MS_U32 u32start,MS_U32 u32end)594 void MDrv_MVD_SetSLQTblBufStartEnd(MS_U32 u32start, MS_U32 u32end)
595 {
596     MVD_FUNC_ENTRY();
597     MVD_DEBUGINFO(printf("%s st=0x%lx end=0x%lx\n", __FUNCTION__, u32start, u32end));
598     HAL_MVD_SetSLQTblBufStartEnd(u32start, u32end);
599     return;
600 }
601 
602 //------------------------------------------------------------------------------
603 /// Set HW buffers' start address to MVD FW
604 /// Return (the end address - 1)
605 /// @param -u32Addr \b IN : start address (MIU offset)
606 //------------------------------------------------------------------------------
MVD_SetHWBuffer(MS_U32 u32Add)607 static MS_U32 MVD_SetHWBuffer(MS_U32 u32Add)
608 {
609     MS_U32 tmpAdr;
610 
611     MVD_DEBUGINFO(printf("====> %s u32Add = 0x%lx\n", __FUNCTION__, u32Add));
612     tmpAdr = MemAlign(u32Add, MVD3_FW_IAP_BUF_ALIGN);
613     MVD_DEBUGINFO(printf("set MVD3_FW_IAP_BUF_ADR =%lx\n",tmpAdr));
614     HAL_MVD_SetIAPBufferAddr(tmpAdr);
615     tmpAdr += MVD3_FW_IAP_BUF_LEN;
616 
617     tmpAdr = MemAlign(tmpAdr, MVD3_FW_DP_BUF_ALIGN);
618     MVD_DEBUGINFO(printf("set MVD3_FW_DP_BUF_ADR=%lx\n",tmpAdr));
619     HAL_MVD_SetDPBufferAddr(tmpAdr);
620     tmpAdr += MVD3_FW_DP_BUF_LEN;
621 
622     tmpAdr = MemAlign(tmpAdr, MVD3_FW_MV_BUF_ALIGN);
623     MVD_DEBUGINFO(printf("set MVD3_FW_MV_BUF_ADR=%lx\n",tmpAdr));
624     HAL_MVD_SetMVBufferAddr(tmpAdr);
625     tmpAdr += MVD3_FW_MV_BUF_LEN;
626     MVD_DEBUGINFO(printf("====> %s End of HW buffers = 0x%lx\n", __FUNCTION__, tmpAdr));
627 
628     return tmpAdr;
629 }
630 #if defined(CHIP_K2)
631 
632 //------------------------------------------------------------------------------
633 /// Set HW buffers' offset size to MVD FW
634 /// @param -u32Addr \b IN : start address (MIU offset)
635 //------------------------------------------------------------------------------
MVD_SetHWBufferOffset(void)636 static void MVD_SetHWBufferOffset(void)
637 {
638 
639 #define MIU_256MB 0x10000000
640 #define MIU_512MB 0x20000000
641     MS_BOOL bBSHighOffset=FALSE,bFBHighOffset=FALSE;
642 
643 
644     MVD_DEBUGINFO(printf("MIU Select %d  %d\n",stMemCfg.bHWMiuSel,stMemCfg.bFWMiuSel));
645     MVD_DEBUGINFO(printf("MIU Base %lx \n",stMemCfg.u32Miu1BaseAddr));
646     if((stMemCfg.u32FBAddr>=(MIU_512MB + stMemCfg.u32Miu1BaseAddr)) || (stMemCfg.u32BSAddr>=(MIU_512MB + stMemCfg.u32Miu1BaseAddr)))
647     {
648         MVD_DEBUGERROR(printf("Unsupported buffer Addr!! (0x%lx,0x%lx)\r\n",stMemCfg.u32BSAddr,stMemCfg.u32FBAddr));
649         return;
650     }
651     if(stMemCfg.u32FBAddr >= stMemCfg.u32Miu1BaseAddr)
652     {
653         if(stMemCfg.u32FBAddr >= (stMemCfg.u32Miu1BaseAddr+MIU_256MB))
654         {
655             bFBHighOffset = TRUE;
656     }
657     }
658     else
659     {
660         if(stMemCfg.u32FBAddr>=MIU_256MB)
661         {
662             bFBHighOffset=TRUE;
663         }
664     }
665 
666 
667     if(stMemCfg.u32BSAddr >= stMemCfg.u32Miu1BaseAddr)
668     {
669         if(stMemCfg.u32BSAddr >= (stMemCfg.u32Miu1BaseAddr+MIU_256MB))
670         {
671             bBSHighOffset = TRUE;
672         }
673     }
674     else
675     {
676         if(stMemCfg.u32BSAddr >= MIU_256MB)
677         {
678             bBSHighOffset = TRUE;
679         }
680     }
681 
682     HAL_MVD_SetBufferOffset(bBSHighOffset,bFBHighOffset);
683 #undef MIU_256MB
684 #undef MIU_512MB
685 
686     return;
687 }
688 #endif
689 
690 //------------------------------------------------------------------------------
691 /// Set the number of VC1 framebuffer
692 /// @param -u8FrmNum \b IN : the number of framebuffer
693 //------------------------------------------------------------------------------
MVD_SetFrameBuffNum(MS_U8 u8FrmNum)694 static void MVD_SetFrameBuffNum(MS_U8 u8FrmNum)
695 {
696     MVD_CmdArg mvdcmd;
697 
698     MVD_DEBUGINFO(printf("%s u8FrmNum = %d\n", __FUNCTION__, u8FrmNum));
699     if (u8FrmNum < MVD_FBNUM_MIN)
700     {
701         MVD_DEBUGINFO(printf("%s set u8FrmNum as %d instead of %d!\n",
702             __FUNCTION__, MVD_FBNUM_MIN, u8FrmNum));
703         u8FrmNum = MVD_FBNUM_MIN;
704     }
705     SETUP_CMDARG(mvdcmd);
706     mvdcmd.Arg0 = u8FrmNum;
707     if (HAL_MVD_MVDCommand( CMD_FB_NUM, &mvdcmd ) == FALSE)
708     {
709         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FB_NUM ) );
710         return;
711     }
712     return;
713 }
714 
715 
716 
717 //------------------------------------------------------------------------------
718 /// Set internal buffer address to MVD
719 /// @param -u32addr \b IN : start address
720 /// @param -u32len  \b IN : length
721 //------------------------------------------------------------------------------
MVD_MVDSetInternalBuffAddr(MS_U32 u32start,MS_U32 u32len)722 static MS_BOOL MVD_MVDSetInternalBuffAddr(MS_U32 u32start, MS_U32 u32len)
723 {
724 #if(defined(CHIP_T7))//fix me later
725       return __MVDSetInternalBuffAddr(u32start,u32len);
726 #else
727     MS_U32 tmpAdr, tmpLen;
728     MS_U32 i;
729     MS_BOOL bRet = TRUE;
730 
731     tmpAdr = u32start;
732     tmpAdr += MVD_FW_CODE_LEN;
733 
734     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
735     MVD_DEBUGINFO(printf("set MVD3_FW_VOL_INFO_BUF_ADR 2=%lx\n",tmpAdr));
736     HAL_MVD_SetVolInfoBufferAddr(tmpAdr);
737 
738     pu8MVDGetVolBufStart = tmpAdr;
739     tmpAdr += MVD3_FW_VOL_INFO_BUF_LEN;
740     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
741 
742     for (i=0; i<MVD3_FW_VOL_INFO_BUF_LEN; i+=4)
743     {
744         HAL_MVD_MemWrite4Byte(pu8MVDGetVolBufStart+i, 0x00UL);
745     }
746 
747 
748     u32VolAdd = pu8MVDGetVolBufStart;
749     if (stMemCfg.bFWMiuSel == MIU_SEL_1)
750     {
751         u32VolAdd += stMemCfg.u32Miu1BaseAddr;
752     }
753     u32VolAdd = HAL_MVD_PA2NonCacheSeg(u32VolAdd);
754     MVD_DEBUGVERBAL(printf("gvolInfo = 0x%lx, volBuf=0x%lx\n", u32VolAdd, pu8MVDGetVolBufStart));
755 
756 
757     MVD_DEBUGINFO(printf("set MVD3_FW_FRAME_INFO_BUF_ADR 3=%lx\n",tmpAdr));
758     HAL_MVD_SetFrameInfoBufferAddr(tmpAdr);
759 
760     pu8MVDGetFrameInfoBufStart = tmpAdr;
761     tmpAdr += MVD3_FW_FRAME_INFO_BUF_LEN;
762     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
763 
764     for (i=0; i<MVD3_FW_FRAME_INFO_BUF_LEN; i+=4)
765     {
766         HAL_MVD_MemWrite4Byte(pu8MVDGetFrameInfoBufStart+i, 0x00UL);
767     }
768 
769     MVD_DEBUGINFO(printf("set MVD3_FW_DIVX_INFO_BUF_ADR=%lx\n",tmpAdr));
770     HAL_MVD_SetHeaderBufferAddr(tmpAdr);
771 
772     pu8MVDSetHeaderBufStart = tmpAdr;
773     tmpAdr += MVD3_FW_DIVX_INFO_BUF_LEN;
774     //set user data
775     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
776 
777     MVD_DEBUGINFO(printf("set MVD3_FW_USER_DATA_BUF_ADR 4 =%lx\n",tmpAdr));
778     HAL_MVD_SetUserDataBuf(tmpAdr, MVD3_FW_USER_DATA_BUF_LEN);
779     _stInternalMemCfg.u32UserDataBuf = tmpAdr;
780     u32UsrDataRd = _stInternalMemCfg.u32UserDataBuf;
781     u32UsrDataWr = _stInternalMemCfg.u32UserDataBuf;
782 
783     tmpAdr += MVD3_FW_USER_DATA_BUF_LEN;
784 
785     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
786     MVD_DEBUGINFO(printf("set MVD3_FW_USER_DATA_BUF2 =%lx\n",tmpAdr));
787     //Used as CC decoding buffer for MVD_SUPPORT_X4_CC
788     tmpAdr += MVD3_FW_USER_DATA_BUF_BACKUP_LEN;
789 
790     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
791 #ifndef _MVD_V3
792     tmpAdr += 0x10000;  //sync to MM
793     tmpAdr += MVD3_FW_SLQ_TAB_BUF_LEN;
794 
795     tmpAdr = (MemAlign(tmpAdr, 0x1000));//4k align
796     MVD_DEBUGINFO(printf("set MVD3_FW_SLQ_TAB_TMPBUF_ADR=%lx\n",tmpAdr));
797     tmpAdr += MVD3_FW_SLQ_TAB_BUF_LEN;  //sync to MM
798 #endif
799     u32MVDFWSLQTABTmpbufAdr = tmpAdr;
800 
801     MVD_DEBUGINFO(printf("set u32MVDFWSLQTABTmpbufAdr=%lx\n",tmpAdr));
802 
803     if ((u32start + u32len) < tmpAdr)
804     {
805         MS_ASSERT(0);
806         //return FALSE;
807     }
808 
809     if((curSrcMode != E_MVD_TS_FILE_MODE)
810     && (curSrcMode != E_MVD_TS_MODE))
811     {
812         HAL_MVD_MemWrite4Byte(tmpAdr, 0xBE010000UL);
813         tmpAdr+=4;
814         HAL_MVD_MemWrite4Byte(tmpAdr, 0x000000FAUL);
815         tmpAdr+=4;
816         for (i=8; i<MVD3_FW_SLQ_TAB_TMPBUF_LEN; i+=4)
817         {
818             HAL_MVD_MemWrite4Byte(tmpAdr, 0x00UL);
819             tmpAdr+=4;
820         }
821 
822         u32MVDFWPtsTblAddr = tmpAdr;
823         HAL_MVD_SetPtsTblAddr(u32MVDFWPtsTblAddr);
824         for (i=0; i<MVD_FW_SLQTBL_PTS_BUF_LEN; i+=MVD_FW_SLQTBL_PTS_LEN)
825         {
826             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i, 0);     //byteCnt
827             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+4, 0);   //dummyPktCnt
828             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+8, 0);   //idLow
829             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+12, 0);  //idHigh
830 
831             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+16, MVD_NULLPKT_PTS);  //PTS
832             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+20, 0);  //reserved0
833             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+24, 0);  //reserved1
834             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+i+28, 0);  //reserved2
835         }
836 
837         MS_ASSERT((u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_BUF_LEN)<=(u32start+u32len));
838         MVD_DEBUGINFO(printf("PTS tbl start=%lx end=%lx\n",
839                u32MVDFWPtsTblAddr, (u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_BUF_LEN)));
840         tmpAdr += MVD_FW_SLQTBL_PTS_BUF_LEN;
841     }
842     else
843     {
844         tmpAdr += (MVD3_FW_SLQ_TAB_TMPBUF_LEN + MVD_FW_SLQTBL_PTS_BUF_LEN);
845     }
846 
847     u32DynScalingAdd = tmpAdr;
848     if (stMemCfg.bEnableDynScale)
849     {
850         HAL_MVD_SetDynamicScaleAddr(tmpAdr);
851         HAL_MVD_EnableDynamicScale();
852         u8DynScalingDepth = 16; //HAL_MVD_GetDynamicScaleDepth
853         MVD_DEBUGINFO(printf("bEnableMIUSel    = 0x%x\n", stMemCfg.bFWMiuSel));
854         MVD_DEBUGINFO(printf("u32DynScalingAddr= 0x%lx\n", u32DynScalingAdd));
855         MVD_DEBUGINFO(printf("u8DynScalingDepth= 0x%x\n", u8DynScalingDepth));
856     }
857     MVD_DEBUGINFO(printf("DynScaling start=%lx end=%lx\n",
858            u32DynScalingAdd, (u32DynScalingAdd+MVD_FW_DYN_SCALE_BUF_LEN)));
859 
860     tmpAdr += MVD_FW_DYN_SCALE_BUF_LEN;
861 
862     u32ScalerInfoAdd = tmpAdr;
863     MVD_DEBUGINFO(printf("ScalerInfo start=%lx end=%lx\n",
864            u32ScalerInfoAdd, (u32ScalerInfoAdd+MVD_FW_SCALER_INFO_BUF_LEN)));
865     tmpAdr += MVD_FW_SCALER_INFO_BUF_LEN;
866 
867     u32DecFrmInfoAdd = tmpAdr;
868     HAL_MVD_SetDecFrmInfoAddr(tmpAdr);
869     MVD_RstFrmInfo(E_MVD_FRMINFO_DECODE);
870     MVD_RstFrmInfo(E_MVD_FRMINFO_DISPLAY);
871     MVD_DEBUGINFO(printf("DecFrmInfo start=%lx\n", u32DecFrmInfoAdd));
872     tmpAdr += MVD_FW_DECFRM_INFO_BUF_LEN;
873 
874 #ifdef _MVD_V3
875     if (tmpAdr > MVD_FW_MPOOL_START_OFFSET)
876     {
877         //shared memory should not overlap with FW memory pool.
878         MVD_DEBUGERROR(printf("%s err: out of memory boundary!\n", __FUNCTION__));
879         return FALSE;
880     }
881 #endif
882 
883 #if (!defined(_MVD_V3) && !defined(_MVD6))
884     if (stMemCfg.bFWMiuSel == stMemCfg.bHWMiuSel)
885     {
886         tmpAdr = MVD_SetHWBuffer(tmpAdr);
887     }
888 #endif
889 
890 #if defined(CHIP_K2)
891     MVD_SetHWBufferOffset();
892 #endif
893     HAL_MVD_MemGetMap(E_MVD_MMAP_FB, &tmpAdr, &tmpLen);
894     MVD_DEBUGINFO(printf("set MVD_FRAMEBUFFER_ADR=%lx\n",tmpAdr));
895     MDrv_MVD_SetFrameBuffAddr(tmpAdr);
896 
897 
898 
899     MVD_SetFrameBuffNum(u8FBNum);
900 
901 //  If VD_MHEG5(CPU) and MVD HW engine are run on different MIU,
902 // IAP, DP, and MV buffers are allocated after FB.
903 // The reason is that these 3 buffers are used by MVD HW engine.
904 #if (!defined(_MVD_V3) && !defined(_MVD6))
905     if (stMemCfg.bFWMiuSel != stMemCfg.bHWMiuSel)
906 #endif
907     {
908         if ((u8FBMode == MVD3_HD_MODE) || (u8FBMode == MVD3_DHD_MODE))
909         {
910             tmpAdr += u32FbHdSize;
911             if (stMemCfg.u32FBSize < (u32FbHdSize + MVD3_FW_IAP_BUF_LEN + MVD3_FW_DP_BUF_LEN + MVD3_FW_DP_BUF_LEN))
912             {
913                 MVD_DEBUGERROR(printf("MVD HW buffers larger than FB size!!!\n"));
914             }
915         }
916         else if (MVD3_SD_MODE == u8FBMode)
917         {
918             tmpAdr += u32FbSdSize;
919         }
920         else
921         {
922             MVD_DEBUGERROR(printf("%s invalid u8FBMode(0x%x)!\n", __FUNCTION__, u8FBMode));
923             return FALSE;
924         }
925         MVD_DEBUGINFO(printf("MVD FB boundary =0x%lx\n",tmpAdr));
926         tmpAdr = MVD_SetHWBuffer(tmpAdr);
927     }
928 
929 
930     HAL_MVD_MemGetMap(E_MVD_MMAP_BS, &tmpAdr, &tmpLen);
931     MVD_DEBUGINFO(printf("set MVD_BITSTREAM_ADR=%lx\n",tmpAdr));
932     bRet = MDrv_MVD_SetBitStreamAddr(tmpAdr,tmpAdr+tmpLen);
933     u32ESBuffEnd = tmpAdr+tmpLen;
934 //Set Compression mode
935 #if !(defined(CHIP_MARIA10) || defined(CHIP_MACAW12) || defined(CHIP_EDEN) || defined(CHIP_EULER))
936     if((stFwCfg.stFBReduction.LumaFBReductionMode != E_MVD_FB_REDUCTION_NONE)
937     || (stFwCfg.stFBReduction.ChromaFBReductionMode  != E_MVD_FB_REDUCTION_NONE))
938     {
939         MVD_DEBUGERROR(printf("MVD Err: Not support FB reduction mode!!\n"));
940         ////return FALSE;
941     }
942 #else
943    if((stFwCfg.stFBReduction.LumaFBReductionMode == E_MVD_FB_REDUCTION_1_4)
944     || (stFwCfg.stFBReduction.ChromaFBReductionMode  == E_MVD_FB_REDUCTION_1_4))
945     {
946         MVD_DEBUGERROR(printf("MVD Err: Not support FB reduction 1/4 mode!!\n"));
947         return FALSE;
948     }
949     MS_U8 u8CompressionMode = ((MS_U8)stFwCfg.stFBReduction.LumaFBReductionMode)||
950         (((MS_U8)stFwCfg.stFBReduction.ChromaFBReductionMode)<<1);
951 
952     HAL_MVD_SetCompressionMode(u8CompressionMode ,stFwCfg.u16FBReduceValue, stFwCfg.stFBReduction.u8EnableAutoMode);
953 
954     if (stFwCfg.stFBReduction.u8EnableAutoMode == 1)
955     {
956         if ((curCodecType == E_MVD_CODEC_VC1_ADV) || (curCodecType == E_MVD_CODEC_VC1_MAIN))
957         {
958             MVD_CmdArg mvdcmd;
959 
960             SETUP_CMDARG(mvdcmd);
961             printf("HAL_MVD_MVDCommand(CMD_FIXED_FRAME_BUFFER, 0)\n");
962             mvdcmd.Arg0 = 0;
963             if (HAL_MVD_MVDCommand( CMD_FIXED_FRAME_BUFFER, &mvdcmd ) == FALSE)
964             {
965                 printf( "Command: 0x%x fail!!\r\n", CMD_FIXED_FRAME_BUFFER );
966                 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FIXED_FRAME_BUFFER ) );
967                 return FALSE;
968             }
969         }
970     }
971 #endif
972 
973 
974     MVD_DEBUGINFO(printf("set pu8MVDGetVolBufStart=%lx\n",pu8MVDGetVolBufStart));
975     MVD_DEBUGINFO(printf("set pu8MVDGetFrameInfoBufStart=%lx\n",pu8MVDGetFrameInfoBufStart));
976     MVD_DEBUGINFO(printf("set pu8MVDSetHeaderBufStart=%lx\n",pu8MVDSetHeaderBufStart));
977 
978     return bRet;
979 #endif
980 }
981 
982 
983 //------------------------------------------------------------------------------
984 /// Initialize variables for MVD driver
985 //------------------------------------------------------------------------------
MVD_InitVar(void)986 static void MVD_InitVar(void)
987 {
988     pu8MVDSetHeaderBufStart=0;
989     pu8MVDGetVolBufStart=0;
990     pu8MVDGetFrameInfoBufStart=0;
991     u32ScalerInfoAdd = NULL;
992     bAVSyncOn = FALSE;
993     bStepDecode = FALSE;
994 #if (defined(CHIP_T2))||(defined(CHIP_T7))
995     u32StepDecodeCnt = 0;
996 #endif
997     bStepDisp = FALSE;
998     bStep2Pts = FALSE;
999     bDropErrFrm = FALSE;
1000     bDropDispfrm = FALSE;
1001     _eFrcMode = E_MVD_FRC_NORMAL;
1002 
1003     bEnableLastFrmShow = FALSE;
1004     u32LastPts = MVD_NULLPKT_PTS;
1005     eTrickMode = E_MVD_TRICK_DEC_UNKNOWN;
1006     u32PreEsRd = MVD_U32_MAX;
1007     u32PreEsWr = 0;
1008     u32ESBuffEnd = 0;
1009 
1010     stPreFrmInfo.u16HorSize   = 0;
1011     stPreFrmInfo.u16VerSize   = 0;
1012     stPreFrmInfo.u8AspectRate = 0;
1013     stPreFrmInfo.u32FrameRate = 0;
1014     stPreFrmInfo.u8Interlace  = 0;
1015 
1016     _eFileSyncMode = E_MVD_TIMESTAMP_FREERUN;
1017     ePreSpeedType = E_MVD_SPEED_DEFAULT;
1018 
1019     stSyncCfg.bEnable = FALSE;
1020     stSyncCfg.u32Delay = 0;
1021     stSyncCfg.u16Tolerance = 0;
1022 #ifdef _MVD_V3
1023     bRdyToFireCmd = FALSE;
1024 #endif
1025     #if SLQ_NEW_PUSH
1026     _SlqStatus.u32SlqPatternAddr = 0;
1027     _SlqStatus.u32SlqPushLength = 0;
1028     _SlqStatus.bSlqPicStart = FALSE;
1029     _SlqStatus.bSlqPicCollect = FALSE;
1030     _SlqStatus.bSlqPicWaitNextStart = FALSE;
1031     _SlqStatus.bSlqEnLastFrameShow =FALSE;
1032     _SlqStatus.bSlqFireRdy = FALSE;
1033     _SlqStatus.bSlqCtrlBit =FALSE;
1034     #endif
1035 #if(defined(CHIP_T7))
1036     u8MvdPlayMode = 0;
1037 #endif
1038 
1039     u32SyncDoneCnt = 0;
1040     u32VSyncCnt = 0;
1041 
1042 #if !defined(SEC_X4)
1043     bIsrAttached = FALSE;
1044 #endif
1045 
1046     return;
1047 }
1048 
1049 #if 0
1050 static void MVD_DumpMemCfg(MVD_MEMCfg* pCfg)
1051 {
1052     if (pCfg)
1053     {
1054         printf("u32FWBinAddr          = 0x%lx\n", pCfg->u32FWBinAddr);
1055         printf("u32FWBinSize          = 0x%lx\n", pCfg->u32FWBinSize);
1056         printf("u32FWCodeAddr         = 0x%lx\n", pCfg->u32FWCodeAddr);
1057         printf("u32FWCodeSize         = 0x%lx\n", pCfg->u32FWCodeSize);
1058         printf("u32FBAddr             = 0x%lx\n", pCfg->u32FBAddr);
1059         printf("u32FBSize             = 0x%lx\n", pCfg->u32FBSize);
1060         printf("u32BSAddr             = 0x%lx\n", pCfg->u32BSAddr);
1061         printf("u32BSSize             = 0x%lx\n", pCfg->u32BSSize);
1062         printf("u32DrvBufAddr         = 0x%lx\n", pCfg->u32DrvBufAddr);
1063         printf("u32DrvBufSize         = 0x%lx\n", pCfg->u32DrvBufSize);
1064         printf("u32DynSacalingBufAddr = 0x%lx\n", pCfg->u32DynSacalingBufAddr);
1065         printf("u32DynSacalingBufSize = 0x%lx\n", pCfg->u32DynSacalingBufSize);
1066         printf("u32Miu1BaseAddr       = 0x%lx\n", pCfg->u32Miu1BaseAddr);
1067         printf("bFWMiuSel             = 0x%x\n", pCfg->bFWMiuSel);
1068         printf("bHWMiuSel             = 0x%x\n", pCfg->bHWMiuSel);
1069     }
1070 }
1071 #endif
1072 
MVD_CheckFrmBuffSizeMin(MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)1073 static MS_BOOL MVD_CheckFrmBuffSizeMin(MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
1074 {
1075     MS_BOOL ret = TRUE;
1076 
1077     //printf("[DBG] MVD_CheckFrmBuffSizeMin\n");
1078 #if (defined(CHIP_MARIA10) || defined(CHIP_MACAW12) || defined(CHIP_EDEN) || defined(CHIP_EULER))
1079     //printf("[DBG] MVD_CheckFrmBuffSizeMin force return TRUE\n");
1080     return ret; //  u8FBMode : MVD3_SD_MODE; u8FBNum : MVD_FBNUM_MIN;
1081 #else
1082     if (_IS_VC1(fwCfg->eCodecType))
1083     {
1084         MVD_DEBUGERROR(printf("Framebuffer size(0x%lx) < (0x%x+0x%lx)!\n",
1085             memCfg->u32FBSize, (MVD_HD_FBSIZE*MVD_FBNUM_MIN), u32HWBuffTotalSize));
1086         ret = FALSE;
1087     }
1088     else if (memCfg->u32FBSize < (MVD4_MPEG_FBSIZE_SDMIN+u32HWBuffTotalSize))
1089     {
1090         MVD_DEBUGERROR(printf("Framebuffer size(0x%lx) < (0x%x+0x%lx)\n",
1091             memCfg->u32FBSize, MVD4_MPEG_FBSIZE_SDMIN, u32HWBuffTotalSize));
1092         ret = FALSE;
1093     }
1094     return ret;
1095 #endif
1096 }
1097 
1098 //------------------------------------------------------------------------------
1099 /// Determine u8FBMode & u8FBNum according to the assigned FBSize
1100 //------------------------------------------------------------------------------
MVD_CheckFrmBuffSize(MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)1101 static MS_BOOL MVD_CheckFrmBuffSize(MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
1102 {
1103     MS_BOOL ret = TRUE;
1104     u8FBMode = 0xff;
1105 
1106 #if defined(MVD_SUPPORT_SD_ONLY)
1107     u8FBMode = MVD3_SD_MODE;
1108 #else
1109     if(memCfg->bSupportSDModeOnly)
1110     {
1111         u8FBMode = MVD3_SD_MODE;
1112     }
1113 #endif //MVD_SUPPORT_SD_ONLY
1114 
1115 #if (defined(_MVD_V3) || defined(_MVD6))
1116     //Three HW buffers are allocated after framebuffer for mvd6, so we need to
1117     //consider these buffers when checking the available framebuffer size/number.
1118     u32HWBuffTotalSize = MVD3_FW_IAP_BUF_LEN + MVD3_FW_DP_BUF_LEN + MVD3_FW_MV_BUF_LEN;
1119 #endif
1120 
1121     //For SD only cases: defined(MVD_SUPPORT_SD_ONLY) and bSupportSDModeOnly
1122     if (MVD3_SD_MODE == u8FBMode)
1123     {
1124         ret = MVD_CheckFrmBuffSizeMin(fwCfg, memCfg);
1125 
1126         //set frmBuffNum as 4
1127         u8FBNum = MVD_FBNUM_MIN;
1128         u32FbSdSize = MVD4_MPEG_FBSIZE_SDMIN;
1129         printf("[MVD_SD_MODE] u8FBNum=%d, FBSize=0x%lx\n", u8FBNum, memCfg->u32FBSize);
1130         return ret;
1131     }
1132 
1133     MS_U32 u32AvailFrmBuffSize = memCfg->u32FBSize - u32HWBuffTotalSize;
1134     if ((MVD_SUPPORT_DHD) && (u32AvailFrmBuffSize >= (MVD_DHD_FBSIZE*MVD_FBNUM_MAX)))
1135     {
1136         MVD_DEBUGINFO(printf("%s(%d) DHD*5\n", __FUNCTION__, __LINE__));
1137         //Dual HD: (1920*2)*1088 or 1920*(1088*2)
1138         u8FBMode = MVD3_DHD_MODE;
1139         u8FBNum = MVD_FBNUM_MAX;
1140         u32FbHdSize = (MVD_DHD_FBSIZE*MVD_FBNUM_MAX);
1141     }
1142     else if ((MVD_SUPPORT_DHD) && (u32AvailFrmBuffSize >= (MVD_DHD_FBSIZE*MVD_FBNUM_MIN)))
1143     {
1144         MVD_DEBUGINFO(printf("%s(%d) DHD*4\n", __FUNCTION__, __LINE__));
1145         //Dual HD: (1920*2)*1088 or 1920*(1088*2)
1146         u8FBMode = MVD3_DHD_MODE;
1147         u8FBNum = MVD_FBNUM_MIN;
1148         u32FbHdSize = (MVD_DHD_FBSIZE*MVD_FBNUM_MIN);
1149     }
1150     else if (u32AvailFrmBuffSize >= (MVD_HD_FBSIZE*MVD_FBNUM_MAX))
1151     {
1152         MVD_DEBUGINFO(printf("%s(%d) HD*5\n", __FUNCTION__, __LINE__));
1153         u8FBMode = MVD3_HD_MODE;
1154         u8FBNum = MVD_FBNUM_MAX;
1155         u32FbHdSize = (MVD_HD_FBSIZE*MVD_FBNUM_MAX);
1156     }
1157     else if (u32AvailFrmBuffSize >= (MVD_HD_FBSIZE*MVD_FBNUM_MIN))
1158     {
1159         MVD_DEBUGINFO(printf("%s(%d) HD*4\n", __FUNCTION__, __LINE__));
1160         u8FBMode = MVD3_HD_MODE;
1161         u8FBNum = MVD_FBNUM_MIN;
1162         u32FbHdSize = (MVD_HD_FBSIZE*MVD_FBNUM_MIN);
1163     }
1164     else
1165     {
1166         MVD_DEBUGINFO(printf("%s(%d) SD\n", __FUNCTION__, __LINE__));
1167         ret = MVD_CheckFrmBuffSizeMin(fwCfg, memCfg);
1168         if (TRUE == ret)
1169         {
1170             u8FBMode = MVD3_SD_MODE;
1171             u8FBNum = MVD_FBNUM_MIN;
1172             u32FbSdSize = MVD4_MPEG_FBSIZE_SDMIN;
1173             MVD_DEBUGINFO(printf("Framebuffer [SD] mode, size = 0x%lx\n", u32FbSdSize));
1174         }
1175     }
1176 
1177     MVD_DEBUGINFO(printf("%s u8FBMode=0x%x, u8FBNum=%d, FBSize=0x%lx\n", __FUNCTION__, u8FBMode, u8FBNum, memCfg->u32FBSize));
1178     return ret;
1179 }
1180 
1181 //------------------------------------------------------------------------------
1182 /// Configure MVD for memory and firmware and info.
1183 /// Notice:
1184 ///     (1) u32FWAddr & u32DrvBufAddr should be on the same MIU
1185 ///     (2) u32FBAddr & u32BSAddr should be on the same MIU
1186 /// @param -fwCfg  \b IN : pointer to firmware configuration
1187 /// @param -memCfg \b IN : pointer to memory configuration
1188 /// @param -InfoCfg \b IN : pointer to mvd info configuration
1189 //------------------------------------------------------------------------------
MDrv_MVD_SetCfg(MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg,MVD_InfoCfg * InfoCfg)1190 E_MVD_Result MDrv_MVD_SetCfg(MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg, MVD_InfoCfg* InfoCfg)
1191 {
1192     MS_BOOL bDrvBuffMiuSel=FALSE;
1193     MVD_FUNC_ENTRY();
1194     if ((!fwCfg) || (!memCfg))
1195     {
1196         return E_MVD_RET_INVALID_PARAM;
1197     }
1198 
1199     //config firmware: framebuffer mode
1200 #if (defined(CHIP_T2) || defined(CHIP_T7))
1201     if ((memCfg->u32FBSize < (MVD_HD_FBSIZE*4))
1202     || (stMemCfg.bSupportSDModeOnly))
1203     {   //Set Framebuffer mode as SD mode if FB < (1920*1088*1.5*4)
1204         u8FBMode = MVD3_SD_MODE;    //720*576
1205     }
1206     else
1207     {
1208         u8FBMode = MVD3_HD_MODE;    //1920*1088
1209     }
1210 #else
1211     if (TRUE != MVD_CheckFrmBuffSize(fwCfg, memCfg))
1212     {
1213         return E_MVD_RET_INVALID_PARAM;
1214     }
1215 
1216     if (TRUE != MDrv_MVD_IsMStreamerMode())
1217     {
1218         //Keep FBNum=4 for mpeg2/4, not-mstreamer/uniplayer mode.
1219         if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
1220         {
1221             if (u8FBNum != MVD_FBNUM_DEFAULT)
1222             {
1223                 u8FBNum = MVD_FBNUM_DEFAULT;
1224             }
1225         }
1226     }
1227 #endif
1228     stMemCfg.bSupportSDModeOnly = memCfg->bSupportSDModeOnly;
1229     stFwCfg.eCodecType = fwCfg->eCodecType;
1230     stFwCfg.bNotReload = fwCfg->bNotReload;
1231     MVD_DEBUGINFO(printf("bNotReload=0x%x\n", stFwCfg.bNotReload));
1232     stFwCfg.u8FBMode = u8FBMode;
1233     stFwCfg.stFBReduction.LumaFBReductionMode = fwCfg->stFBReduction.LumaFBReductionMode;
1234     stFwCfg.stFBReduction.ChromaFBReductionMode = fwCfg->stFBReduction.ChromaFBReductionMode;
1235     stFwCfg.stFBReduction.u8EnableAutoMode = fwCfg->stFBReduction.u8EnableAutoMode;
1236 
1237     if (MDrv_MIU_IsSupportMIU1())
1238     {
1239         if (memCfg->u32Miu1BaseAddr == 0)
1240         {
1241 #if MVD_ENABLE_MSOS_MIU1_BASE
1242             memCfg->u32Miu1BaseAddr = HAL_MIU1_BASE;
1243 #else
1244             memCfg->u32Miu1BaseAddr = MVD_MIU1_BASE_ADDRESS;
1245 #endif
1246         }
1247         memCfg->bFWMiuSel = (memCfg->u32FWCodeAddr < memCfg->u32Miu1BaseAddr)?MIU_SEL_0:MIU_SEL_1;
1248         memCfg->bHWMiuSel = (memCfg->u32FBAddr < memCfg->u32Miu1BaseAddr)?MIU_SEL_0:MIU_SEL_1;
1249         bDrvBuffMiuSel = (memCfg->u32DrvBufAddr < memCfg->u32Miu1BaseAddr)?MIU_SEL_0:MIU_SEL_1;
1250     }
1251     else
1252     {
1253         memCfg->u32Miu1BaseAddr= 0;
1254         memCfg->bFWMiuSel = MIU_SEL_0;
1255         memCfg->bHWMiuSel = MIU_SEL_0;
1256         bDrvBuffMiuSel = MIU_SEL_0;
1257     }
1258 
1259     MVD_DEBUGINFO(printf("MIUSEL:: FW=%x HW=%x, miu1base=0x%lx\n",
1260                   memCfg->bFWMiuSel, memCfg->bHWMiuSel, memCfg->u32Miu1BaseAddr));
1261     MVD_DEBUGINFO(printf("bDrvBuffMiuSel = %x\n", bDrvBuffMiuSel));
1262     MS_ASSERT(bDrvBuffMiuSel == memCfg->bFWMiuSel);
1263 
1264     //set these attributes before HAL_MVD_MemSetMap() and HAL_MVD_LoadCode()
1265     stMemCfg.u32Miu1BaseAddr = memCfg->u32Miu1BaseAddr;
1266     stMemCfg.bFWMiuSel = memCfg->bFWMiuSel;
1267     stMemCfg.bHWMiuSel = memCfg->bHWMiuSel;
1268 
1269     //config memory
1270     HAL_MVD_MemSetMap(E_MVD_MMAP_FW, memCfg->u32FWCodeAddr, memCfg->u32FWCodeSize);
1271     HAL_MVD_MemSetMap(E_MVD_MMAP_FB, memCfg->u32FBAddr, memCfg->u32FBSize);
1272     HAL_MVD_MemSetMap(E_MVD_MMAP_BS, memCfg->u32BSAddr, memCfg->u32BSSize);
1273     HAL_MVD_MemSetMap(E_MVD_MMAP_DRV, memCfg->u32DrvBufAddr, memCfg->u32DrvBufSize);
1274 
1275     //both stMemCfg & memCfg are physical addr, except field u32FWSrcVAddr
1276     stMemCfg.eFWSrcType = memCfg->eFWSrcType;
1277 
1278     if (stMemCfg.eFWSrcType == E_MVD_FW_SOURCE_DRAM)
1279     {
1280         stMemCfg.u32FWSrcVAddr = HAL_MVD_PA2NonCacheSeg((MS_U32)memCfg->u32FWBinAddr);
1281     }
1282     else
1283     {
1284         stMemCfg.u32FWSrcVAddr = NULL;
1285     }
1286 
1287     stMemCfg.u32FWBinAddr = memCfg->u32FWBinAddr;
1288     stMemCfg.u32FWBinSize = memCfg->u32FWBinSize;
1289     stMemCfg.u32FWCodeAddr = memCfg->u32FWCodeAddr;
1290     stMemCfg.u32FWCodeSize = memCfg->u32FWCodeSize;
1291     stMemCfg.u32FBAddr = memCfg->u32FBAddr;
1292     stMemCfg.u32FBSize = memCfg->u32FBSize;
1293     stMemCfg.u32BSAddr = memCfg->u32BSAddr;
1294     stMemCfg.u32BSSize = memCfg->u32BSSize;
1295     stMemCfg.u32DrvBufAddr = memCfg->u32DrvBufAddr;
1296     stMemCfg.u32DrvBufSize = memCfg->u32DrvBufSize;
1297     stMemCfg.u32DynSacalingBufAddr = memCfg->u32DynSacalingBufAddr;
1298     stMemCfg.u32DynSacalingBufSize = memCfg->u32DynSacalingBufSize;
1299     stMemCfg.bEnableDynScale = memCfg->bEnableDynScale;
1300 
1301     bSlqTblSync = ((stMemCfg.u32DrvBufAddr < stMemCfg.u32BSAddr) ||
1302                    ((stMemCfg.u32DrvBufAddr+stMemCfg.u32DrvBufSize) > (stMemCfg.u32BSAddr+stMemCfg.u32BSSize)));
1303     MVD_DEBUGINFO(printf("bSlqTblSync = %x\n", bSlqTblSync));
1304     //MVD_DumpMemCfg(&stMemCfg);
1305 
1306     curCodecType = InfoCfg->u8CodecType;
1307     curSrcMode = InfoCfg->u8BSProviderMode;
1308     curDisablePESParsing = InfoCfg->bDisablePESParsing;
1309 
1310     return E_MVD_RET_OK;
1311 }
1312 
1313 
MVD_Init(void)1314 static MS_BOOL MVD_Init(void)
1315 {
1316 #ifndef REDLION_LINUX_KERNEL_ENVI
1317     if (!OSAL_MVD_MutexInit())
1318     {
1319         MVD_DEBUGERROR(printf("%s: fail to init mutex\n", __FUNCTION__));
1320         _MVD_INIT_FAIL_RET();
1321     }
1322 #endif
1323 #if MVD_PROFILING
1324     MS_U32 t1=0, t2=0;
1325     t1 = MsOS_GetSystemTime();
1326 #endif
1327     //load code
1328     if (!HAL_MVD_LoadCode())
1329     {
1330         MVD_DEBUGERROR(printf("_MVD_Init:MDrv_MVD_LoadCode failed\n"));
1331         _MVD_INIT_FAIL_RET();
1332     }
1333     else
1334     {
1335         MVD_DEBUGINFO(printf("_MVD_Init:MDrv_MVD_LoadCode success\n"));
1336     }
1337 #if MVD_PROFILING
1338     t2 = MsOS_GetSystemTime();
1339     printf("i000: t2=%ld, diff=%ld\n", t2, t2-t1);
1340     t1 = t2;
1341 #endif
1342     if (!HAL_MVD_InitHW())
1343     {
1344         MVD_DEBUGERROR(printf("_MVD_Init:HAL_MVD_InitHW failed\n"));
1345         _MVD_INIT_FAIL_RET();
1346     }
1347     else
1348     {
1349         MVD_DEBUGINFO(printf("_MVD_Init:HAL_MVD_InitHW success\n"));
1350     }
1351 #if MVD_PROFILING
1352     t2 = MsOS_GetSystemTime();
1353     printf("i001: t2=%ld, diff=%ld\n", t2, t2-t1);
1354     t1 = t2;
1355 #endif
1356 
1357     bStopped = FALSE;
1358     if (!HAL_MVD_InitFW())
1359     {
1360         MVD_DEBUGERROR(printf("_MVD_Init:HAL_MVD_InitFW failed\n"));
1361         _MVD_INIT_FAIL_RET();
1362     }
1363     else
1364     {
1365         MVD_DEBUGINFO(printf("_MVD_Init:HAL_MVD_InitFW success\n"));
1366     }
1367 #if MVD_PROFILING
1368     t2 = MsOS_GetSystemTime();
1369     printf("i002: t2=%ld, diff=%ld\n", t2, t2-t1);
1370     t1 = t2;
1371 #endif
1372 
1373     _bFwLoad = TRUE;
1374     HAL_MVD_SetVpuFwDecoder(E_VPU_DECODER_MVD);
1375     return TRUE;
1376 }
1377 
MDrv_MVD_RegSetBase(MS_U32 u32RegBaseAddr)1378 void MDrv_MVD_RegSetBase(MS_U32 u32RegBaseAddr)
1379 {
1380     HAL_MVD_RegSetBase(u32RegBaseAddr);
1381 }
1382 
1383 //------------------------------------------------------------------------------
1384 /// MVD driver initialization
1385 /// @return TRUE or FALSE
1386 ///     - TRUE, Success
1387 ///     - FALSE, Failed
1388 //------------------------------------------------------------------------------
MDrv_MVD_Init(void)1389 MS_BOOL MDrv_MVD_Init(void)
1390 {
1391     MS_U32 u32Addr = 0;
1392     MS_U32 u32Len = 0;
1393 
1394     MVD_DEBUGINFO(printf("MDrv_MVD_Init:start\n"));
1395 
1396     MVD_InitVar();
1397     _bDecodeIFrame = FALSE;
1398     _bDrvInit = FALSE;
1399 
1400     if (!MVD_Init())
1401     {
1402         MVD_DEBUGERROR(printf("MDrv_MVD_Init:_MVD_Init failed\n"));
1403         return FALSE;
1404     }
1405     else
1406     {
1407         MVD_DEBUGINFO(printf("MDrv_MVD_Init:_MVD_Init success\n"));
1408     }
1409 #ifndef _MVD_V3
1410     HAL_MVD_MemGetMap(E_MVD_MMAP_FW, &u32Addr, &u32Len);
1411     if(!MVD_MVDSetInternalBuffAddr(u32Addr, u32Len))
1412     {
1413         MVD_DEBUGERROR(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr failed\n"));
1414         return FALSE;
1415     }
1416     else
1417     {
1418         MVD_DEBUGINFO(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr success\n"));
1419     }
1420 #endif
1421 #if 0
1422     if(!HAL_MVD_GetMVDEngineCfg(_pMvdHWCfg))
1423     {
1424         MVD_DEBUGERROR(printf("MDrv_MVD_Init:HAL_MVD_GetMVDEngineCfg failed\n"));
1425         return FALSE;
1426     }
1427     printf("[VDEC] dbg %lx %lx %lx %lx %lx %lx %x %x %x \n",
1428         _pMvdHWCfg->MVD_HWVER,_pMvdHWCfg->u32MvdSlqTabLens,_pMvdHWCfg->u32MvdSlqTabSizes  ,_pMvdHWCfg->u32MvdSlqTabShiftBit1,
1429         _pMvdHWCfg->u32MvdSlqTabShiftBit2,_pMvdHWCfg->u32MvdSlqTabShiftMask,_pMvdHWCfg->u16MvdTileModePitchLens,
1430         _pMvdHWCfg->u16MvdTileModePitchSize,_pMvdHWCfg->u16MvdTileModeMask);
1431 #endif
1432     _bDrvInit = TRUE;
1433 
1434     return TRUE;
1435 }
1436 
1437 
1438 //------------------------------------------------------------------------------
1439 /// MVD driver exit
1440 /// @return TRUE or FALSE
1441 ///     - TRUE, Success
1442 ///     - FALSE, Failed
1443 //------------------------------------------------------------------------------
MDrv_MVD_Exit(void)1444 MS_BOOL MDrv_MVD_Exit(void)
1445 {
1446     MVD_DEBUGINFO(printf("MDrv_MVD_Exit:start\n"));
1447 
1448     //do nothing if driver is not initialized
1449     if (_bDrvInit != TRUE)
1450     {
1451         MVD_DEBUGINFO(printf("MDrv_MVD_Exit: not-init yet\n"));
1452 #if (!defined(CHIP_T2))&&(!defined(CHIP_T7))
1453         HAL_MVD_PowerCtrl(DISABLE);
1454         //HAL_VPU_PowerCtrl(DISABLE);
1455         HAL_VPU_DeInit();
1456 #endif
1457         return FALSE;
1458     }
1459 
1460     //stop and reset FW/HW
1461     if (MDrv_MVD_Stop() != TRUE)
1462     {
1463         MVD_DEBUGINFO(printf("MDrv_MVD_Exit: stop fail\n"));
1464         HAL_MVD_Delayms(1);
1465         if ( HAL_MVD_TimeOut() == TRUE )
1466         {
1467             MVD_DEBUGERROR(printf("*** MVD ERR: STOP TIMEOUT!!! ***\n"));
1468         }
1469     }
1470 
1471     bStopped = TRUE;
1472 
1473 #ifdef MVD_ENABLE_ISR
1474     //dettach isr
1475     if (eEventFlag)
1476     {
1477         if(E_MVD_RET_OK != MDrv_MVD_SetIsrEvent(E_MVD_EVENT_DISABLE_ALL, (MVD_InterruptCb)NULL))
1478         {
1479             MVD_DEBUGERROR(printf("MDrv_MVD_Exit: dettach isr fail\n"));
1480         }
1481     }
1482 #endif
1483 
1484 #if !(defined(CHIP_T2) || defined(CHIP_T7))
1485     //From T4, need to check MAU idle before reset VPU
1486     {
1487         MS_U32 mau_idle_cnt = 100;// ms
1488         while(mau_idle_cnt)
1489         {
1490             if(TRUE == HAL_VPU_MAU_IDLE())
1491             {
1492                 break;
1493             }
1494             mau_idle_cnt--;
1495             HAL_MVD_Delayms(1);
1496         }
1497 
1498         if(mau_idle_cnt == 0)
1499         {
1500             MVD_DEBUGERROR(printf("MAU idle time out~~~~~\n"));
1501         }
1502     }
1503 
1504     //CPU hold
1505     HAL_VPU_SwRst();
1506 #endif
1507 
1508     //MVD HW reset
1509     if (!HAL_MVD_RstHW())
1510     {
1511         MVD_DEBUGERROR(printf("MDrv_MVD_Exit:MVD4ResetHW failed\n"));
1512     }
1513     else
1514     {
1515         MVD_DEBUGINFO(printf("MDrv_MVD_Exit:MVD4ResetHW success\n"));
1516     }
1517 
1518     //reset internal variables.
1519     MVD_InitVar();
1520     _bDecodeIFrame = FALSE;
1521     _bDrvInit = FALSE;
1522 
1523 #if (!defined(CHIP_T2))&&(!defined(CHIP_T7))
1524     HAL_MVD_PowerCtrl(DISABLE);
1525     //HAL_VPU_PowerCtrl(DISABLE);
1526     HAL_VPU_DeInit();
1527     HAL_VPU_SwRelseMAU();
1528 #endif
1529 
1530 #ifndef REDLION_LINUX_KERNEL_ENVI
1531     OSAL_MVD_MutexExit();
1532 #endif
1533 
1534     return TRUE;
1535 }
1536 
1537 //------------------------------------------------------------------------------
1538 /// Reset MVD
1539 //------------------------------------------------------------------------------
MDrv_MVD_Rst(void)1540 E_MVD_Result MDrv_MVD_Rst( void )
1541 {
1542     MVD_FUNC_ENTRY();
1543     if (TRUE == HAL_MVD_SoftRstHW())
1544     {
1545         //notice: T2 MVD3 does not support soft-reset HW.
1546         //Thus, MDrv_MVD_Rst()==MDrv_MVD_Init() for T2.
1547         return E_MVD_RET_OK;
1548     }
1549 
1550     //For T3&Euclid MVD4, do re-init only when SoftRst does not work.
1551     if (FALSE == MDrv_MVD_Init())
1552     {
1553         MVD_DEBUGERROR(printf("MDrv_MVD_Rst:_MVD_Init failed\n"));
1554         return E_MVD_RET_FAIL;
1555     }
1556     else
1557     {
1558         MVD_DEBUGERROR(printf("MDrv_MVD_Rst:_MVD_Init success\n"));
1559     }
1560 
1561     return E_MVD_RET_OK;
1562 }
1563 
1564 //------------------------------------------------------------------------------
1565 /// Allow MVD to start decoding even without sequence header.
1566 //------------------------------------------------------------------------------
MDrv_MVD_EnableForcePlay(void)1567 void MDrv_MVD_EnableForcePlay(void)
1568 {
1569     MVD_FUNC_ENTRY();
1570     if (HAL_MVD_EnableForcePlay() == FALSE)
1571     {
1572         MVD_DEBUGERROR( printf("HAL_MVD_EnableForcePlay fail!!\r\n") );
1573         return;
1574     }
1575     return;
1576 }
1577 
1578 //------------------------------------------------------------------------------
1579 /// Issue Play command to MVD
1580 //------------------------------------------------------------------------------
MDrv_MVD_Play(void)1581 void MDrv_MVD_Play(void)
1582 {
1583     MVD_CmdArg mvdcmd;
1584 
1585     MVD_FUNC_ENTRY();
1586 #if defined(CHIP_T7)
1587     SETUP_CMDARG(mvdcmd);
1588     mvdcmd.Arg0= u8MvdPlayMode;
1589     if (HAL_MVD_MVDCommand( CMD_PLAY, &mvdcmd ) == FALSE)
1590     {
1591         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PLAY ) );
1592         return;
1593     }
1594 #else
1595     SETUP_CMDARG(mvdcmd);
1596     mvdcmd.Arg0 = 1;
1597     if (HAL_MVD_MVDCommand( CMD_DIU_WIDTH_ALIGN, &mvdcmd ) == FALSE)
1598     {
1599         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DIU_WIDTH_ALIGN ) );
1600         return;
1601     }
1602 
1603     SETUP_CMDARG(mvdcmd);
1604     if (HAL_MVD_MVDCommand( CMD_PLAY, &mvdcmd ) == FALSE)
1605     {
1606         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PLAY ) );
1607         return;
1608     }
1609 
1610 #if (!defined(CHIP_T2))
1611     if (HAL_MVD_Resume() == FALSE)
1612     {
1613         MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
1614         return;
1615     }
1616 #endif
1617 #endif
1618     _bDecodeIFrame = FALSE;
1619     return;
1620 }
1621 
1622 //------------------------------------------------------------------------------
1623 /// Set bit stream buffer address to MVD
1624 /// @param -u32start \b IN : start address
1625 /// @param -u32end \b IN : end address
1626 //------------------------------------------------------------------------------
MDrv_MVD_SetBitStreamAddr(MS_U32 u32start,MS_U32 u32end)1627 MS_BOOL MDrv_MVD_SetBitStreamAddr(MS_U32 u32start, MS_U32 u32end)
1628 {
1629     MVD_CmdArg mvdcmd;
1630     MS_ASSERT((u32start%8)==0);
1631     u32start >>= 3;
1632     SETUP_CMDARG(mvdcmd);
1633     mvdcmd.Arg0 = L_WORD(u32start);
1634     mvdcmd.Arg1 = H_WORD(u32start);
1635     mvdcmd.Arg2 = L_DWORD(u32start);
1636     mvdcmd.Arg3 = H_DWORD(u32start);
1637 
1638     if (HAL_MVD_MVDCommand( CMD_STREAM_BUF_START, &mvdcmd ) == FALSE)
1639     {
1640         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STREAM_BUF_START ) );
1641         return FALSE;
1642     }
1643 
1644     MS_ASSERT((u32end%8)==0);
1645     u32end >>= 3;
1646     SETUP_CMDARG(mvdcmd);
1647     mvdcmd.Arg0 = L_WORD(u32end);
1648     mvdcmd.Arg1 = H_WORD(u32end);
1649     mvdcmd.Arg2 = L_DWORD(u32end);
1650     mvdcmd.Arg3 = H_DWORD(u32end);
1651 
1652     if (HAL_MVD_MVDCommand( CMD_STREAM_BUF_END, &mvdcmd ) == FALSE)
1653     {
1654         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STREAM_BUF_END ) );
1655         return FALSE;
1656     }
1657     return TRUE;
1658 }
1659 
1660 //------------------------------------------------------------------------------
1661 /// Set frame buffer address to MVD
1662 /// @param -u32addr \b IN : start address
1663 //------------------------------------------------------------------------------
MDrv_MVD_SetFrameBuffAddr(MS_U32 u32addr)1664 void MDrv_MVD_SetFrameBuffAddr(MS_U32 u32addr)
1665 {
1666     if ((u32addr>>3) > MAX_ADD_28BIT)
1667     {
1668         MVD_DEBUGERROR(printf("MDrv_MVD_SetFrameBuffAddr: only support 28bit add!\n"));
1669     }
1670     HAL_MVD_SetFrameBuffAddr(u32addr, u8FBMode);
1671 }
1672 
1673 
1674 //------------------------------------------------------------------------------
1675 /// Set MVD SLQ start & end address
1676 /// @param -u32start \b IN : start address
1677 /// @param -u32end \b IN : end address
1678 //------------------------------------------------------------------------------
MDrv_MVD_SetSLQStartEnd(MS_U32 u32start,MS_U32 u32end)1679 void MDrv_MVD_SetSLQStartEnd(MS_U32 u32start, MS_U32 u32end)
1680 {
1681     MVD_CmdArg mvdcmd;
1682 
1683     if ((u32start > MAX_ADD_27BIT) || ((u32end+1) > MAX_ADD_27BIT))
1684     {
1685         MVD_DEBUGERROR(printf("MDrv_MVD_SetSLQStartEnd: only support 27bit add!\n"));
1686     }
1687     MVD_FUNC_ENTRY();
1688     SET_CMDARG(mvdcmd, (u32end+1));
1689     if (HAL_MVD_MVDCommand( CMD_SLQ_END, &mvdcmd ) == FALSE)
1690     {
1691         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_END ) );
1692         return;
1693     }
1694 
1695     SET_CMDARG(mvdcmd, u32start);
1696     if (HAL_MVD_MVDCommand( CMD_SLQ_START, &mvdcmd ) == FALSE)
1697     {
1698         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_START ) );
1699         return;
1700     }
1701 
1702     return;
1703 }
1704 
1705 //------------------------------------------------------------------------------
1706 /// Get SLQ available level
1707 /// @return SLQ available level
1708 //------------------------------------------------------------------------------
MDrv_MVD_GetSLQAvailableLevel(void)1709 MS_U8 MDrv_MVD_GetSLQAvailableLevel(void)
1710 {
1711     MVD_CmdArg mvdcmd;
1712 
1713     MVD_FUNC_ENTRY();
1714     SETUP_CMDARG(mvdcmd);
1715     if (HAL_MVD_MVDCommand( CMD_SLQ_AVAIL_LEVEL, &mvdcmd ) == FALSE)
1716     {
1717         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_AVAIL_LEVEL ) );
1718         return 0;
1719     }
1720     MVD_DEBUGINFO( printf( "MDrv_MVD_GetSLQAvailableLevel=%x\n", mvdcmd.Arg2 ) );
1721 
1722     return mvdcmd.Arg2;
1723 }
1724 
1725 
1726 //Map driver CodecType to firmware CodecType
MVD_MapCodecType(MVD_CodecType type)1727 static MS_U8 MVD_MapCodecType(MVD_CodecType type)
1728 {
1729     MS_U8 u8type = 0xff;
1730     switch (type)
1731     {
1732         case E_MVD_CODEC_MPEG2:
1733             u8type = CODEC_MPEG2;
1734             break;
1735         case E_MVD_CODEC_MPEG4:
1736             u8type = CODEC_MPEG4;
1737             break;
1738         case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
1739             u8type = CODEC_MPEG4_SHORT_VIDEO_HEADER;
1740             break;
1741         case E_MVD_CODEC_DIVX311:
1742             u8type = CODEC_DIVX311;
1743             break;
1744 
1745         case E_MVD_CODEC_FLV:
1746             u8type = 0x03;
1747             break;
1748 
1749         case E_MVD_CODEC_VC1_MAIN: //RCV
1750             u8type = 0x05;
1751             break;
1752 
1753         case E_MVD_CODEC_VC1_ADV:  //VC1
1754             u8type = 0x04;
1755             break;
1756 
1757         default:
1758             break;
1759     }
1760 
1761     return u8type;
1762 }
1763 
1764 
1765 //Map driver SrcType to firmware SrcType
MVD_MapSrcMode(MVD_SrcMode mode)1766 static MS_U8 MVD_MapSrcMode(MVD_SrcMode mode)
1767 {
1768     MS_U8 u8mode = 0xff;
1769     switch (mode)
1770     {
1771         case E_MVD_TS_MODE:
1772             u8mode = STREAM_MODE;
1773             break;
1774         case E_MVD_FILE_MODE:
1775             u8mode = FILE_MODE;
1776             break;
1777         case E_MVD_SLQ_MODE:
1778             u8mode = SLQ_MODE;
1779             break;
1780         case E_MVD_SLQ_TBL_MODE:
1781             u8mode = SLQ_TBL_MODE;
1782             break;
1783         case E_MVD_TS_FILE_MODE:
1784             u8mode = TS_FILE_MODE;
1785             break;
1786 
1787         default:
1788             break;
1789     }
1790 
1791     return u8mode;
1792 }
1793 
1794 
1795 //------------------------------------------------------------------------------
1796 /// Set codec type.
1797 /// @param -u8CodecType \b IN : 0: mpeg4, 1: mpeg4 with short_video_header, 2: DivX311
1798 /// @param -u8BSProviderMode \b IN : TS live stream, file, SLQ, SLQ table link and TS file mode.
1799 //------------------------------------------------------------------------------
MDrv_MVD_SetCodecInfo(MVD_CodecType u8CodecType,MVD_SrcMode u8BSProviderMode,MS_U8 bDisablePESParsing)1800 void MDrv_MVD_SetCodecInfo(MVD_CodecType u8CodecType, MVD_SrcMode u8BSProviderMode, MS_U8 bDisablePESParsing)
1801 {
1802    #if (defined(CHIP_T7))
1803        return;
1804    #endif
1805 
1806     MVD_CmdArg stCmdArg;
1807 
1808     MVD_FUNC_ENTRY();
1809     //printf("u8CodecType=0x%x\n", u8CodecType);
1810     //printf("u8BSProviderMode=0x%x\n", u8BSProviderMode);
1811     SETUP_CMDARG(stCmdArg);
1812     stCmdArg.Arg0 = MVD_MapCodecType(u8CodecType);
1813     stCmdArg.Arg1 = MVD_MapSrcMode(u8BSProviderMode);
1814     stCmdArg.Arg2 = bDisablePESParsing;
1815     //arg2 is only valid for STREAM_MODE and TS_FILE_MODE
1816     //set as 0 to enable MVD parser and parser interrupt
1817     stCmdArg.Arg3 = 0;
1818     MVD_DEBUGINFO(printf("MDrv_MVD_SetCodecInfo: Cmd: %x, Arg0: %x, Arg1: %x. Arg2: %x\n",
1819                   CMD_CODEC_INFO, stCmdArg.Arg0, stCmdArg.Arg1, stCmdArg.Arg2));
1820     if (HAL_MVD_MVDCommand(CMD_CODEC_INFO, &stCmdArg) == FALSE)
1821     {
1822         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_CODEC_INFO ) );
1823         return;
1824     }
1825 
1826 #ifdef _MVD_V3
1827     MS_U32 u32Addr, u32Len;
1828     MS_U32 i;
1829     MVD_CmdArg mvdcmd;
1830     //set code offset to MVD
1831     HAL_MVD_MemGetMap(E_MVD_MMAP_FW, &u32Addr, &u32Len);
1832     SETUP_CMDARG(mvdcmd);
1833     i = u32Addr >> 3;
1834     mvdcmd.Arg0 = L_WORD(i);
1835     mvdcmd.Arg1 = H_WORD(i);
1836     mvdcmd.Arg2 = L_DWORD(i);
1837     mvdcmd.Arg3 = H_DWORD(i);
1838     if (HAL_MVD_MVDCommand( CMD_CODE_OFFSET, &mvdcmd ) == FALSE)
1839     {
1840         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_CODE_OFFSET ) );
1841         return;
1842     }
1843 #endif
1844 
1845     curCodecType = u8CodecType;
1846     curSrcMode = u8BSProviderMode;
1847     curDisablePESParsing = bDisablePESParsing;
1848 
1849     //Refer to msAPI_VDPlayer_DecodeMPEG4.c (core\kernel\api\videoplayer)
1850     if (u8BSProviderMode == E_MVD_SLQ_TBL_MODE)
1851     {
1852         if ((u8CodecType == E_MVD_CODEC_MPEG4) ||
1853             (u8CodecType == E_MVD_CODEC_DIVX311) ||
1854             (u8CodecType == E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER))
1855         {
1856             // Enable PackMode
1857             SETUP_CMDARG(stCmdArg);
1858             stCmdArg.Arg0 = 3;
1859             HAL_MVD_MVDCommand(CMD_PARSE_M4V_PACKMD, &stCmdArg);
1860 
1861             // Set DIU width of rounding mode (align to 8byte)
1862             SETUP_CMDARG(stCmdArg);
1863             stCmdArg.Arg0 = 1;
1864             HAL_MVD_MVDCommand(CMD_DIU_WIDTH_ALIGN, &stCmdArg);
1865         }
1866 #ifndef _MVD_V3
1867         MVD_SLQTblInit();
1868 #endif
1869     }
1870 
1871 #ifdef _MVD_V3
1872     //set internal buffers after setting codecinfo for V3
1873     HAL_MVD_MemGetMap(E_MVD_MMAP_FW, &u32Addr, &u32Len);
1874     if (!MVD_MVDSetInternalBuffAddr(u32Addr, u32Len))
1875     {
1876         MVD_DEBUGERROR(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr failed\n"));
1877     }
1878     else
1879     {
1880         MVD_DEBUGINFO(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr success\n"));
1881     }
1882     if (u8BSProviderMode == E_MVD_SLQ_TBL_MODE)
1883     {
1884         MVD_SLQTblInit();
1885     }
1886 #endif
1887 
1888     return;
1889 }
1890 
1891 //------------------------------------------------------------------------------
1892 /// Set DivX patch.
1893 /// @param -u8MvAdjust \b IN : chroma adjustment
1894 /// @param -u8IdctSel \b IN : idct algorithm selection
1895 //------------------------------------------------------------------------------
MDrv_MVD_SetDivXCfg(MS_U8 u8MvAdjust,MS_U8 u8IdctSel)1896 void MDrv_MVD_SetDivXCfg(MS_U8 u8MvAdjust, MS_U8 u8IdctSel)
1897 {
1898     MVD_CmdArg stCmdArg;
1899 
1900     MVD_FUNC_ENTRY();
1901     SETUP_CMDARG(stCmdArg);
1902     stCmdArg.Arg0 = u8MvAdjust;
1903     if (HAL_MVD_MVDCommand(CMD_DIVX_PATCH, &stCmdArg) == FALSE)
1904     {
1905         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DIVX_PATCH ) );
1906         return;
1907     }
1908 
1909     SETUP_CMDARG(stCmdArg);
1910     stCmdArg.Arg0 = u8IdctSel;
1911     if (HAL_MVD_MVDCommand(CMD_IDCT_SEL, &stCmdArg) == FALSE)
1912     {
1913         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_IDCT_SEL ) );
1914         return;
1915     }
1916 
1917     return;
1918 }
1919 
1920 
1921 //------------------------------------------------------------------------------
1922 /// Set DivX311 stream info.
1923 /// @param divxInfo \b IN : DivX311 stream info.
1924 //------------------------------------------------------------------------------
MVD_WriteDivx311Data(FW_DIVX_INFO * divxInfo)1925 static void MVD_WriteDivx311Data(FW_DIVX_INFO *divxInfo)
1926 {
1927     HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_VOL_HANDLE_DONE,divxInfo->vol_handle_done);
1928     HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_WIDTH,divxInfo->width);
1929     HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_HEIGHT,divxInfo->height);
1930     HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_COUNT,divxInfo->frame_count);
1931     HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_TIME,divxInfo->frame_time);
1932     HAL_MVD_MemWrite2Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PTS_INCR,divxInfo->pts_incr);
1933     HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_RATE,divxInfo->frame_rate);
1934     HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_ASPECT_RATIO,divxInfo->aspect_ratio);
1935     HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PROGRESSIVE_SEQUENCE,divxInfo->progressive_sequence);
1936     HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_MPEG1,divxInfo->mpeg1);
1937     HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PLAY_MODE,divxInfo->play_mode);
1938     HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_MPEG_FRC_MODE,divxInfo->mpeg_frc_mode);
1939     return;
1940 }
1941 
1942 
1943 //static MS_U32 writePtrLast;   //SlqTbl debug
1944 //------------------------------------------------------------------------------
1945 /// Get MVD decoded picture counter
1946 /// @return -decoded picture counter
1947 //------------------------------------------------------------------------------
MDrv_MVD_GetPicCounter(void)1948 MS_U32 MDrv_MVD_GetPicCounter( void )
1949 {
1950     //printf("==>> wr=%lx rpt=%lx\n", _drvSlqTbl.u32WrPtr, MDrv_MVD_GetSLQReadPtr());
1951 #if 0
1952     if (MDrv_MVD_GetVldErrCount()!=0)
1953     {
1954         printf("$$ wPtr= 0x%lx(0x%lx) rPtr=0x%lx(0x%lx) vldErr=0x%lx\n", writePtrLast, _drvSlqTbl.u32WrPtr,
1955         MDrv_MVD_GetSLQReadPtr(), _drvSlqTbl.u32RdPtr, MDrv_MVD_GetVldErrCount());
1956         _SLQTbl_DumpPtsTbl(0x530, 0x620);
1957         while(1);
1958     }
1959 #endif
1960     MVD_FUNC_ENTRY();
1961 #if (defined(CHIP_T7))
1962     return __MVD_GetPicCounter();
1963 #else
1964     if(pu8MVDGetFrameInfoBufStart==0)
1965     {
1966         MVD_DEBUGERROR(printf("MDrv_MVD_GetPicCounter error: pu8MVDGetFrameInfoBufStart=NULL\n"));
1967             return 0;
1968     }
1969 
1970     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_FRAME_COUNT);
1971 #endif
1972 }
1973 
1974 
1975 //------------------------------------------------------------------------------
1976 /// Get MVD skipped picture counter
1977 /// @return -skipped picture counter
1978 //------------------------------------------------------------------------------
MDrv_MVD_GetSkipPicCounter(void)1979 MS_U32 MDrv_MVD_GetSkipPicCounter( void )
1980 {
1981     MVD_FUNC_ENTRY();
1982     #if (defined(CHIP_T7))
1983     return 0;
1984     #else
1985     if(pu8MVDGetFrameInfoBufStart==0)
1986     {
1987         MVD_DEBUGERROR(printf("MDrv_MVD_GetSkipPicCounter error: pu8MVDGetFrameInfoBufStart=NULL\n"));
1988         return 0;
1989     }
1990 
1991     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_SKIP_FRAME_COUNT);
1992     #endif
1993 }
1994 
1995 //------------------------------------------------------------------------------
1996 /// Get MVD picture type
1997 /// @return - picture type
1998 //------------------------------------------------------------------------------
MDrv_MVD_GetPicType(void)1999 MVD_PicType MDrv_MVD_GetPicType( void )
2000 {
2001     MS_U32 picType = 0xff;
2002     MVD_PicType ret = E_MVD_PIC_UNKNOWN;
2003 
2004     MVD_FUNC_ENTRY();
2005     if(pu8MVDGetFrameInfoBufStart==0)
2006     {
2007         MVD_DEBUGERROR(printf("MDrv_MVD_GetSkipPicCounter error: pu8MVDGetFrameInfoBufStart=NULL\n"));
2008         return E_MVD_PIC_UNKNOWN;
2009     }
2010 
2011     picType = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_PICTURE_TYPE);
2012     switch (picType)
2013     {
2014         case 0:
2015             ret = E_MVD_PIC_I;
2016             break;
2017         case 1:
2018             ret = E_MVD_PIC_P;
2019             break;
2020         case 2:
2021             ret = E_MVD_PIC_B;
2022             break;
2023         default:
2024             break;
2025     }
2026     return ret;
2027 }
2028 
2029 
2030 //------------------------------------------------------------------------------
2031 /// Get MVD bit rate (bits/sec)
2032 /// @return -bit rate
2033 //------------------------------------------------------------------------------
MDrv_MVD_GetBitsRate(void)2034 MS_U32 MDrv_MVD_GetBitsRate( void )
2035 {
2036     MVD_FUNC_ENTRY();
2037 
2038     if(pu8MVDGetVolBufStart==0)
2039     {
2040         MVD_DEBUGERROR(printf("MDrv_MVD_GetValidStreamFlag error: pu8MVDGetVolBufStart=NULL\n"));
2041         return FALSE;
2042     }
2043 
2044     //Ref 13818-2, this flag is unit of 400 bits/sec
2045     return HAL_MVD_MemRead4Byte(pu8MVDGetVolBufStart+OFFSET_BIT_RATE)*400;
2046 }
2047 
2048 
2049 //------------------------------------------------------------------------------
2050 /// Get video_range flag.
2051 /// Supported after MVD FW release v00720390
2052 /// Color team need this information for better color quality.
2053 /// When video_range = 0  gives a range of Y from 16 to 235 and Cb , Cr from 16 to 240
2054 /// When video_range = 1  gives a range of Y from  0 to 255 and Cb , Cr from  0 to 255
2055 /// @return -video_range
2056 //------------------------------------------------------------------------------
MDrv_MVD_GetVideoRange(void)2057 MS_U8 MDrv_MVD_GetVideoRange( void )
2058 {
2059     #if defined(CHIP_T7)
2060     return 1;
2061     #endif
2062     MVD_FUNC_ENTRY();
2063     if(pu8MVDGetVolBufStart==0)
2064     {
2065         MVD_DEBUGERROR(printf("MDrv_MVD_GetVideoRange error: pu8MVDGetVolBufStart=NULL\n"));
2066         return FALSE;
2067     }
2068 
2069     return HAL_MVD_MemReadByte(pu8MVDGetVolBufStart+OFFSET_VIDEO_RANGE);
2070 }
2071 
2072 //------------------------------------------------------------------------------
2073 /// Get LowDelay flag
2074 /// @return -True/False
2075 //------------------------------------------------------------------------------
MDrv_MVD_GetLowDelayFlag(void)2076 MS_BOOL MDrv_MVD_GetLowDelayFlag( void )
2077 {
2078     MVD_FUNC_ENTRY();
2079 
2080     if(pu8MVDGetVolBufStart==0)
2081     {
2082         MVD_DEBUGERROR(printf("MDrv_MVD_GetLowDelayFlag error: pu8MVDGetVolBufStart=NULL\n"));
2083         return FALSE;
2084     }
2085 
2086     return HAL_MVD_MemReadByte(pu8MVDGetVolBufStart+OFFSET_LOW_DELAY);
2087 }
2088 
2089 //------------------------------------------------------------------------------
2090 /// Get MPEG 3:2 pull down flag
2091 /// @return -TRUE or FALSE
2092 //------------------------------------------------------------------------------
MDrv_MVD_GetIs32PullDown(void)2093 MS_BOOL MDrv_MVD_GetIs32PullDown(void)
2094 {
2095     MVD_FUNC_ENTRY();
2096     if(pu8MVDGetVolBufStart==0)
2097     {
2098         MVD_DEBUGERROR(printf("MDrv_MVD_GetIs32PullDown error: pu8MVDGetVolBufStart=NULL\n"));
2099         return FALSE;
2100     }
2101 
2102     return (MS_BOOL)HAL_MVD_MemReadByte(pu8MVDGetVolBufStart+OFFSET_MPEG_FRC_MODE);
2103 }
2104 
2105 //------------------------------------------------------------------------------
2106 /// Get if Dynamic Scaling is enabled (reported by firmware)
2107 /// @return -TRUE or FALSE
2108 //------------------------------------------------------------------------------
MDrv_MVD_GetIsDynScalingEnabled(void)2109 MS_BOOL MDrv_MVD_GetIsDynScalingEnabled(void)
2110 {
2111     MVD_FUNC_ENTRY();
2112     MS_BOOL bEnDynScale = FALSE;
2113     if(pu8MVDGetVolBufStart==0)
2114     {
2115         MVD_DEBUGERROR(printf("MDrv_MVD_GetIsDSEnabled error: pu8MVDGetVolBufStart=NULL\n"));
2116         return FALSE;
2117     }
2118     bEnDynScale = (MS_BOOL)HAL_MVD_MemReadByte(pu8MVDGetVolBufStart+OFFSET_DS_ENABLE);
2119     if ((FALSE == stMemCfg.bEnableDynScale) && (bEnDynScale))
2120     {
2121         MVD_DEBUGERROR(printf("bEnDynScale err: %x\n", bEnDynScale));
2122     }
2123 
2124     return bEnDynScale;
2125 }
2126 
2127 //------------------------------------------------------------------------------
2128 /// Get the difference of PTS and STC
2129 /// @return -(PTS-STC)
2130 //------------------------------------------------------------------------------
MDrv_MVD_GetPtsStcDiff(void)2131 MS_S32 MDrv_MVD_GetPtsStcDiff(void)
2132 {
2133     MVD_FUNC_ENTRY();
2134 #if (defined(CHIP_T7) || defined(CHIP_T2))
2135     return 0; //to be implemented
2136 #else
2137     if(pu8MVDGetFrameInfoBufStart==0)
2138     {
2139         MVD_DEBUGERROR(printf("MDrv_MVD_GetPtsStcDiff err: pu8MVDGetFrameInfoBufStart=NULL\n"));
2140             return 0;
2141     }
2142     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_PTS_STC);
2143 #endif
2144 }
2145 
2146 //------------------------------------------------------------------------------
2147 /// Get MVD SLQ read pointer
2148 /// @return -SLQ read pointer
2149 //------------------------------------------------------------------------------
MDrv_MVD_GetSLQReadPtr(void)2150 MS_U32 MDrv_MVD_GetSLQReadPtr( void )
2151 {
2152     MS_U32 u32RdPtr = 0;
2153 
2154     if (!bSlqTblHKCtrl)
2155     {
2156         MVD_CmdArg mvdcmd;
2157 
2158         MVD_FUNC_ENTRY();
2159         SETUP_CMDARG(mvdcmd);
2160         if (HAL_MVD_MVDCommand( CMD_SLQ_GET_TBL_RPTR, &mvdcmd ) == FALSE)
2161         {
2162             MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_GET_TBL_RPTR ) );
2163             return 0;
2164         }
2165         u32RdPtr = mvdcmd.Arg0 | (mvdcmd.Arg1<<8) | (mvdcmd.Arg2<<16) | (mvdcmd.Arg3<<24);
2166     }
2167     else
2168     {
2169         u32RdPtr = HAL_MVD_SlqTblProbeRdPtr();
2170     }
2171 
2172     //printf("##### MDrv_MVD_GetSLQReadPtr 0x%lx\n", readPtr);
2173 
2174     if(u32RdPtr == 0)//not start decode yet,MVD return 0
2175     {
2176         u32RdPtr = 0;
2177     }
2178     else
2179     {
2180         u32RdPtr = u32RdPtr << 3;
2181     }
2182 
2183     return u32RdPtr;
2184 }
2185 
2186 //------------------------------------------------------------------------------
2187 /// Get MVD SLQ write pointer
2188 /// @return -SLQ write pointer
2189 //------------------------------------------------------------------------------
MDrv_MVD_SetSLQWritePtr(MS_BOOL bCheckData)2190 void MDrv_MVD_SetSLQWritePtr(MS_BOOL bCheckData)
2191 {
2192     MVD_CmdArg mvdcmd;
2193     MS_U32 u32WrPtr;
2194 
2195 #ifdef _MVD_V3
2196 #define CMD_TIMEOUT_MS  500
2197     if (!bRdyToFireCmd)
2198     {
2199         //check FW is init success and thus ready to update write pointer
2200         MS_U32 u32TimeCnt;
2201 
2202         u32TimeCnt = HAL_MVD_GetTime();
2203         while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
2204         {
2205             if (MDrv_MVD_GetDecodeStatus() != E_MVD_STAT_IDLE)
2206             {
2207                 bRdyToFireCmd = TRUE;
2208                 (printf("time=%ld ms, ", (HAL_MVD_GetTime() - u32TimeCnt)));
2209                 break;
2210             }
2211         }
2212         if (!bRdyToFireCmd)
2213         {
2214             MVD_DEBUGERROR(printf("%s: err timeout(%ld)! stat=0x%x\n", __FUNCTION__,
2215                     HAL_MVD_GetTime() - u32TimeCnt, MDrv_MVD_GetDecodeStatus()));
2216             return;
2217         }
2218         else
2219         {
2220             (printf("%s: ready to update WrPtr.\n", __FUNCTION__));
2221         }
2222     }
2223 #endif
2224 
2225     MS_ASSERT(_drvSlqTbl.u32WrPtr < _drvSlqTbl.u32EndAdd);
2226     MS_ASSERT(_drvSlqTbl.u32WrPtr >= _drvSlqTbl.u32StAdd);
2227 #if SLQ_NEW_PUSH
2228     if((!_SlqStatus.bSlqFireRdy)&&_SlqStatus.bSlqCtrlBit)
2229     {
2230         (printf("**** _SlqStatus.bSlqFireRdy is not Ready ** \n"));
2231         return;
2232     }
2233     _SlqStatus.bSlqFireRdy = FALSE;
2234 #endif
2235     if ((bCheckData==TRUE)&&(!bSlqTblHasValidData))
2236     {
2237         MVD_DEBUGINFO(printf("**** SlqWrPtr(0x%lx) is not update!(%x, %x) ****\n",
2238             _drvSlqTbl.u32WrPtr, bCheckData, bSlqTblHasValidData));
2239         return;
2240     }
2241     bSlqTblHasValidData = FALSE;
2242 
2243 #if UPDATE_NEXT_WRPTR
2244     u32WrPtr = _drvSlqTbl.u32WrPtr;
2245 #else
2246     //should report (WrPtr-8)
2247     if (_drvSlqTbl.u32WrPtr != _drvSlqTbl.u32StAdd)
2248     {
2249         u32WrPtr = _drvSlqTbl.u32WrPtr - SLQ_ENTRY_LEN;
2250     }
2251     else
2252     {
2253         u32WrPtr = _drvSlqTbl.u32EndAdd - SLQ_ENTRY_LEN;
2254     }
2255 #endif
2256 
2257     //printf("%s wPtr = 0x%lx rPtr=0x%lx\n", __FUNCTION__, *pu32WrPtr, MDrv_MVD_GetSLQReadPtr());
2258 
2259 #ifndef REDLION_LINUX_KERNEL_ENVI
2260     //if (stMemCfg.bFWMiuSel != stMemCfg.bHWMiuSel)
2261     if (bSlqTblSync)
2262     {
2263         //Update SLQ table, DivX311 patterns, and dummy patterns to bitstream buffer
2264         MS_U32 u32SrcOffset = _drvSlqTbl.u32StAdd;
2265         MS_U32 u32SrcAdd = u32SrcOffset;
2266         MS_U32 u32DstAdd = stMemCfg.u32BSAddr;
2267         MS_U32 u32DstOffset = MVD_GetMemOffset(stMemCfg.u32BSAddr);
2268         MS_U32 u32TblWr;
2269         //printf("===>offset(Src=0x%lx, Dst=0x%lx)", u32SrcAdd, u32DstAdd);
2270         if (stMemCfg.bFWMiuSel == MIU_SEL_1)
2271         {
2272             u32SrcAdd = u32SrcOffset + stMemCfg.u32Miu1BaseAddr;
2273         }
2274         //printf(" PA(Src=0x%lx, Dst=0x%lx)", u32SrcAdd, u32DstAdd);
2275 
2276         HAL_MVD_CPU_Sync();
2277 
2278         BDMA_Result bdmaRlt;
2279 
2280         bdmaRlt = MDrv_BDMA_CopyHnd(u32SrcAdd, u32DstAdd, stMemCfg.u32DrvBufSize, bdmaCpyType, BDMA_OPCFG_DEF);
2281 
2282         if (E_BDMA_OK != bdmaRlt)
2283         {
2284             MVD_DEBUGERROR(printf("%s MDrv_BDMA_MemCopy fail ret=%x!\n", __FUNCTION__, bdmaRlt));
2285         }
2286         MVD_DEBUGINFO(printf("SlqWrPtr_BDMA src=0x%lx dst=0x%lx size=0x%lx cpyType=0x%x\n",
2287             u32SrcAdd, u32DstAdd, stMemCfg.u32DrvBufSize, bdmaCpyType));
2288 
2289         u32TblWr = u32DstOffset + (u32WrPtr - _drvSlqTbl.u32StAdd);
2290         //printf(" wr=0x%lx, tblWr=0x%lx\n", writePtr, u32TblWr);
2291         u32WrPtr = u32TblWr;
2292     }
2293     //printf("wPtr= 0x%lx(0x%lx) rPtr=0x%lx(0x%lx)\n", writePtr, _drvSlqTbl.u32WrPtr,
2294     //    MDrv_MVD_GetSLQReadPtr(), _drvSlqTbl.u32RdPtr);
2295 #endif
2296 
2297     //writePtrLast = u32WrPtr;
2298     #if SLQ_NEW_PUSH
2299     if(!_SlqStatus.bSlqEnLastFrameShow && _SlqStatus.bSlqCtrlBit)
2300     {
2301         u32WrPtr = _SlqStatus.u32VaildWptrAddr;
2302     }
2303     #endif
2304     MS_ASSERT((u32WrPtr%8)==0);
2305     u32WrPtr >>= 3;
2306 
2307     if (!bSlqTblHKCtrl)
2308     {
2309         SET_CMDARG(mvdcmd, u32WrPtr);
2310         HAL_MVD_CPU_Sync();
2311         if (HAL_MVD_MVDCommand( CMD_SLQ_UPDATE_TBL_WPTR, &mvdcmd ) == FALSE)
2312         {
2313             MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_UPDATE_TBL_WPTR ) );
2314             return;
2315         }
2316     }
2317     else
2318     {
2319         HAL_MVD_SlqTblLoadWrPtr(u32WrPtr);
2320         if (HAL_MVD_SlqTblProbeWrPtr() != u32WrPtr)
2321         {
2322             MVD_DEBUGERROR(printf("Ooops! SlqWrPtr update fail!!! 0x%lx != 0x%lx\n", HAL_MVD_SlqTblProbeWrPtr(), u32WrPtr));
2323         }
2324     }
2325 
2326     return;
2327 }
2328 
2329 //------------------------------------------------------------------------------
2330 /// Get MVD decoded frame index.  For debug.
2331 /// @return -frame index of the decoded frame
2332 //------------------------------------------------------------------------------
MDrv_MVD_GetDecodedFrameIdx(void)2333 MS_U8 MDrv_MVD_GetDecodedFrameIdx ( void )
2334 {
2335     MVD_FUNC_ENTRY();
2336     if(pu8MVDGetFrameInfoBufStart==0)
2337     {
2338         MVD_DEBUGERROR(printf("MDrv_MVD_GetDecodedFrameIdx error: pu8MVDGetFrameInfoBufStart=NULL\n"));
2339         return 0;
2340     }
2341 
2342     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_FB_INDEX);
2343 }
2344 
2345 //------------------------------------------------------------------------------
2346 /// Get MVD VLD error count
2347 /// @return -VLD error count
2348 //------------------------------------------------------------------------------
MDrv_MVD_GetVldErrCount(void)2349 MS_U32 MDrv_MVD_GetVldErrCount( void )
2350 {
2351     MVD_FUNC_ENTRY();
2352 #if defined(CHIP_T7)
2353     return __MVD_GetVldErrCount();
2354 #else
2355     if(pu8MVDGetFrameInfoBufStart==0)
2356     {
2357         MVD_DEBUGERROR(printf("MDrv_MVD_GetVldErrCount error!\n"));
2358         return 0;
2359     }
2360 
2361     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_VLD_ERR_COUNT);
2362 #endif
2363 }
2364 
2365 
2366 //Get ErrStatus when ErrCode==ErrShape
MVD_GetErrShapeStat(MS_U32 u32errStat)2367 static MVD_ErrStatus MVD_GetErrShapeStat(MS_U32 u32errStat)
2368 {
2369     MVD_ErrStatus st = E_MVD_ERR_STATUS_UNKOWN;
2370     switch (u32errStat)
2371     {
2372         case 0:
2373             st = E_MVD_ERR_SHAPE_RECTANGULAR;
2374             break;
2375         case 1:
2376             st = E_MVD_ERR_SHAPE_BINARY;
2377             break;
2378         case 2:
2379             st = E_MVD_ERR_SHAPE_BINARY_ONLY;
2380             break;
2381         case 3:
2382             st = E_MVD_ERR_SHAPE_GRAYSCALE;
2383             break;
2384         default:
2385             break;
2386     }
2387     return st;
2388 }
2389 
2390 //Get ErrStatus when ErrCode==ErrSprite
MVD_GetErrSpriteStat(MS_U32 u32errStat)2391 static MVD_ErrStatus MVD_GetErrSpriteStat(MS_U32 u32errStat)
2392 {
2393     MVD_ErrStatus st = E_MVD_ERR_STATUS_UNKOWN;
2394     switch (u32errStat)
2395     {
2396         case 0:
2397             st = E_MVD_ERR_USED_SPRITE_UNUSED;
2398             break;
2399         case 1:
2400             st = E_MVD_ERR_USED_SPRITE_STATIC;
2401             break;
2402         case 2:
2403             st = E_MVD_ERR_USED_SPRITE_GMC;
2404             break;
2405         case 3:
2406             st = E_MVD_ERR_USED_SPRITE_RESERVED;
2407             break;
2408         default:
2409             break;
2410     }
2411     return st;
2412 }
2413 
2414 
2415 //------------------------------------------------------------------------------
2416 /// Get MVD error info.
2417 /// This function can be used to diagnosis when the 1st DispReady doesn't occur.
2418 ///
2419 /// @param - errorCode \b OUT : error code
2420 /// @param - errorStatus \b OUT : error status
2421 //------------------------------------------------------------------------------
MDrv_MVD_GetErrInfo(MVD_ErrCode * errCode,MVD_ErrStatus * errStatus)2422 void MDrv_MVD_GetErrInfo(MVD_ErrCode *errCode, MVD_ErrStatus *errStatus)
2423 {
2424     MS_U32 errorCode = E_MVD_ERR_UNKNOWN;
2425     MS_U32 errorStatus = E_MVD_ERR_STATUS_UNKOWN;
2426 
2427     MVD_FUNC_ENTRY();
2428     if(pu8MVDGetFrameInfoBufStart==0)
2429     {
2430         MVD_DEBUGERROR(printf("MDrv_MVD_GetErrInfo error!\n"));
2431         return;
2432     }
2433 
2434     errorCode = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_ERROR_CODE);
2435     errorStatus = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_ERROR_STATUS);
2436 
2437     switch (errorCode)
2438     {
2439         case VOL_SHAPE:
2440             *errCode = E_MVD_ERR_SHAPE;
2441             *errStatus = MVD_GetErrShapeStat(errorStatus);
2442             break;
2443         case VOL_USED_SPRITE:
2444             *errCode = E_MVD_ERR_USED_SPRITE;
2445             *errStatus = MVD_GetErrSpriteStat(errorStatus);
2446             break;
2447         case VOL_NOT_8_BIT:
2448             *errCode = E_MVD_ERR_NOT_8_BIT;
2449             *errStatus = E_MVD_ERR_STATUS_NONE;
2450             break;
2451         case VOL_NERPRED_ENABLE:
2452             *errCode = E_MVD_ERR_NERPRED_ENABLE;
2453             *errStatus = E_MVD_ERR_STATUS_NONE;
2454             break;
2455         case VOL_REDUCED_RES_ENABLE:
2456             *errCode = E_MVD_ERR_REDUCED_RES_ENABLE;
2457             *errStatus = E_MVD_ERR_STATUS_NONE;
2458             break;
2459         case VOL_SCALABILITY:
2460             *errCode = E_MVD_ERR_SCALABILITY;
2461             *errStatus = E_MVD_ERR_STATUS_NONE;
2462             break;
2463         case VOL_H263_ERROR:
2464             *errCode = E_MVD_ERR_H263_ERROR;
2465             *errStatus = E_MVD_ERR_STATUS_NONE;
2466             break;
2467         case VOL_RES_NOT_SUPPORT:
2468             *errCode = E_MVD_ERR_RES_NOT_SUPPORT;
2469             *errStatus = E_MVD_ERR_STATUS_NONE;
2470             break;
2471         case VOL_MPEG4_NOT_SUPPORT:
2472             *errCode = E_MVD_ERR_MPEG4_NOT_SUPPORT;
2473             *errStatus = E_MVD_ERR_STATUS_NONE;
2474             break;
2475         case VOL_PROFILE_NOT_SUPPORT:
2476             *errCode = E_MVD_ERR_PROFILE_NOT_SUPPORT;
2477             *errStatus = E_MVD_ERR_STATUS_NONE;
2478             break;
2479         case VOL_RCV_ERROR_OCCUR:
2480             *errCode = E_MVD_ERR_RCV_ERROR_OCCUR;
2481             *errStatus = E_MVD_ERR_STATUS_NONE;
2482             break;
2483         case VOL_OTHER:
2484             *errCode = E_MVD_ERR_OTHER;
2485             *errStatus = E_MVD_ERR_STATUS_NONE;
2486             break;
2487 
2488 #if (defined(CHIP_A6))
2489         //For A6, FW will report these error code for
2490         //SLQ_TBL mode and mpeg4/flv/svh/divx311/vc1.
2491         case VOL_VC1_NOT_SUPPORT:
2492             *errCode = E_MVD_ERR_VC1_NOT_SUPPORT;
2493             *errStatus = E_MVD_ERR_STATUS_NONE;
2494             break;
2495         case VOL_UNKNOW_CODEC_NOT_SUPPORT:
2496             *errCode = E_MVD_ERR_UNKNOW_CODEC_NOT_SUPPORT;
2497             *errStatus = E_MVD_ERR_STATUS_NONE;
2498             break;
2499         case VOL_SLQ_TBL_NOT_SUPPORT:
2500             *errCode = E_MVD_ERR_SLQ_TBL_NOT_SUPPORT;
2501             *errStatus = E_MVD_ERR_STATUS_NONE;
2502             break;
2503 #endif
2504 
2505         default:
2506             *errCode = E_MVD_ERR_UNKNOWN;
2507             *errStatus = E_MVD_ERR_STATUS_UNKOWN;
2508             break;
2509     }
2510 
2511     return;
2512 }
2513 
2514 //------------------------------------------------------------------------------
2515 /// Get valid MVD stream detected flag
2516 /// For MPEG2/4,
2517 ///     1. width<16(1 macroblock), height<16, width>1920, or height>1080
2518 ///     2. next start code not found
2519 /// the stream would be considered as invalid.
2520 /// For VC1/RCV, not impelment, default: valid
2521 /// @return -decoded flag
2522 //------------------------------------------------------------------------------
MDrv_MVD_GetValidStreamFlag(void)2523 MS_BOOL MDrv_MVD_GetValidStreamFlag( void )
2524 {
2525     MVD_FUNC_ENTRY();
2526 #if defined(CHIP_T7)
2527     return __MVD_GetValidStreamFlag();
2528 #else
2529     //printf("  validStream=%d\n\n",
2530     //    !HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_INVALIDSTREAM));
2531     return !HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_INVALIDSTREAM);
2532 #endif
2533 }
2534 
2535 #if !defined(CHIP_T7)
MVD_GCD(MS_U32 u32A,MS_U32 u32B)2536 static MS_U32 MVD_GCD(MS_U32 u32A, MS_U32 u32B)
2537 {
2538    MS_S32 i;
2539    MS_U32 x[4]; /* need x[0], x[1], x[i-1] */
2540 
2541    if (u32A > u32B)
2542    {
2543      x[0] = u32A; x[1] = u32B;
2544    }
2545    else
2546    {
2547      x[0] = u32B; x[1] = u32A;
2548    }
2549 
2550    i = 1;
2551 
2552    #define w(x) (((x)<4)?(x):(2+((x)&1)))
2553 
2554    while( x[w(i)] != 0 )
2555    {
2556        x[w(i+1)] = x[w(i-1)] % x[w(i)];
2557        i++;
2558    }
2559 
2560    return x[w(i-1)];
2561 
2562    #undef w
2563 }
2564 #endif
2565 
2566 //------------------------------------------------------------------------------
2567 /// Get video frame information from MVD
2568 /// (SourceW * ParH) : (SourceH * ParW) = DarW : DarH
2569 /// E.g. Source PAL 704x576, Par(Pixel aspect ratio)=12/11,
2570 ///      Dar(Display AR) = (704x12):(576x11) = 4:3
2571 /// @param -pinfo \b IN : pointer to video frame information
2572 //------------------------------------------------------------------------------
MDrv_MVD_GetFrameInfo(MVD_FrameInfo * pinfo)2573 void MDrv_MVD_GetFrameInfo(MVD_FrameInfo *pinfo)
2574 {
2575 #if defined (CHIP_T7)
2576     MVD_FUNC_ENTRY();
2577     __MVD_GetFrameInfo(pinfo);
2578 
2579 #else
2580     MS_U32 u32DAR_Width=0,u32DAR_Height=0,u32PAR_Width=0,u32PAR_Height=0,u32GCD=0;
2581     MS_U32 u32Vertical_Size=0, u32Horizontal_Size=0;
2582     //13818-2 page 38 Table 6-3
2583     MS_U8 u8DARTable[5][2] = { {1,1}, {1,1}, {4,3}, {16,9}, {221,100} };
2584 
2585     MVD_FUNC_ENTRY();
2586 
2587     if (pu8MVDGetVolBufStart == NULL)
2588     {
2589         MVD_DEBUGERROR(printf("MDrv_MVD_GetFrameInfo error: pu8MVDGetVolBufStart=NULL\n"));
2590         return;
2591     }
2592 
2593 //    MVD_ReadVolInfo(&gvolInfo);
2594     HAL_MVD_CPU_Sync();
2595     HAL_MVD_ReadMemory();
2596     gvolInfo = *(volatile FW_VOL_INFO*)u32VolAdd;
2597 
2598 #if 0
2599     MVD_DEBUGINFO(printf("vol info,vol_info=%d,sprite_usage=%d,pts_incr=%d,\n",
2600                   gvolInfo.vol_info,gvolInfo.sprite_usage,gvolInfo.pts_incr));
2601     MVD_DEBUGINFO(printf("vol info,width=%x,height=%x,frame_rate=%d,aspect_ratio=%x,\n",
2602                   gvolInfo.width,gvolInfo.height,gvolInfo.frame_rate,gvolInfo.aspect_ratio));
2603     MVD_DEBUGINFO(printf("vol info,progressive_sequence=%x,mpeg1=%x,play_mode=%x,bit_rate=%x,\n",
2604                   gvolInfo.progressive_sequence,gvolInfo.mpeg1,gvolInfo.play_mode,gvolInfo.bit_rate));
2605 #endif
2606 
2607     pinfo->u16HorSize = (MS_U16) gvolInfo.width;
2608     pinfo->u16VerSize = (MS_U16) gvolInfo.height;
2609     pinfo->u16par_width  = (MS_U16) gvolInfo.par_width;
2610     pinfo->u16par_height = (MS_U16) gvolInfo.par_height;
2611     pinfo->u8AspectRate = gvolInfo.aspect_ratio;
2612 
2613     pinfo->u16CropBottom = gvolInfo.CropBottom;
2614     pinfo->u16CropTop = 0;
2615     pinfo->u16CropLeft = 0;
2616     if (pinfo->u16HorSize & MVD_TILE_MODE_MASK)
2617     {
2618         //Notice: Firmware and driver have to be consistent for this part,
2619         // otherwise the pitch will not match and video is noisy.
2620         pinfo->u16CropRight =MVD_TILE_MODE_PITCH_LENS - (pinfo->u16HorSize & MVD_TILE_MODE_MASK);
2621         pinfo->u16HorSize = ((pinfo->u16HorSize >> MVD_TILE_MODE_PITCH_SIZES) + 1) << MVD_TILE_MODE_PITCH_SIZES;
2622     }
2623     else
2624     {
2625         pinfo->u16CropRight = 0;
2626     }
2627 
2628     if ((curCodecType == E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER) ||
2629         (curCodecType == E_MVD_CODEC_DIVX311) || (curCodecType == E_MVD_CODEC_FLV))
2630     {
2631         pinfo->u8Interlace= FALSE; //divx311/flv/svh just has progressive mode
2632         MS_ASSERT(gvolInfo.progressive_sequence == 1); //FW will init it as 1
2633     }
2634     else
2635     {
2636         if (gvolInfo.progressive_sequence == 0)
2637         {
2638             pinfo->u8Interlace=1;
2639         }
2640         else
2641         {
2642             pinfo->u8Interlace=0;
2643         }
2644     }
2645 
2646     ///Calculate PAR info
2647     if ((pinfo->u16par_width == 0) || (pinfo->u16par_height == 0))
2648     {
2649         if ((pinfo->u8AspectRate > 0) && (pinfo->u8AspectRate < 5 ))
2650         {
2651             if (pinfo->u8AspectRate == 1)
2652             {   //SAR=1.0 square sample
2653                 u32DAR_Width = (MS_U32)pinfo->u16HorSize;
2654                 u32DAR_Height = (MS_U32)pinfo->u16VerSize;
2655                 pinfo->u16par_width = 1;
2656                 pinfo->u16par_height = 1;
2657             }
2658             else
2659             {
2660                 u32DAR_Width = (MS_U32)u8DARTable[pinfo->u8AspectRate][0];
2661                 u32DAR_Height = (MS_U32)u8DARTable[pinfo->u8AspectRate][1];
2662                 u32Vertical_Size = (MS_U32)pinfo->u16VerSize;
2663                 u32Horizontal_Size = (MS_U32)(pinfo->u16HorSize - pinfo->u16CropRight);
2664                 u32PAR_Width = u32DAR_Width * u32Vertical_Size;
2665                 u32PAR_Height = u32DAR_Height * u32Horizontal_Size;
2666                 u32GCD = MVD_GCD(u32PAR_Width, u32PAR_Height);
2667                 if (0 == u32GCD)
2668                 {
2669                     pinfo->u16HorSize = 0xFFFF;
2670                     pinfo->u16VerSize = 0xFFFF;
2671 
2672                     return;
2673                 }
2674                 else
2675                 {
2676                     pinfo->u16par_width = (MS_U16) (u32PAR_Width / u32GCD);
2677                     pinfo->u16par_height = (MS_U16) (u32PAR_Height / u32GCD);
2678                     MVD_DEBUGVERBAL(printf("u32PAR_Width:%ld,u32PAR_Height:%ld,GCD:%ld\n",u32PAR_Width,u32PAR_Height,u32GCD));
2679                 }
2680             }
2681         }
2682         else
2683         {
2684             //set to 0 to indicate it's abnormal
2685             u32DAR_Width = 0;
2686             u32DAR_Height = 0;
2687             pinfo->u16par_width = 0;
2688             pinfo->u16par_height = 0;
2689         }
2690         MVD_DEBUGVERBAL(printf("u32DAR_Width:%ld,u32DAR_Height%ld\n",u32DAR_Width,u32DAR_Height));
2691     }
2692     MVD_DEBUGVERBAL(printf("pinfo->u16par_width:%d, pinfo->u16par_height:%d\n",pinfo->u16par_width, pinfo->u16par_height));
2693 
2694 
2695     if (curCodecType == E_MVD_CODEC_MPEG2)
2696     {
2697         if ((gvolInfo.frame_rate > 8 && pinfo->u8Interlace == 0))
2698            //||(gvolInfo.frame_rate > 5 && pinfo->u8Interlace == 1))
2699         {
2700             pinfo->u32FrameRate = 0;
2701         }
2702         else
2703         {
2704             pinfo->u32FrameRate = stFrameRateCode[gvolInfo.frame_rate];
2705         }
2706     }
2707     else if ((curCodecType == E_MVD_CODEC_VC1_ADV) || (curCodecType == E_MVD_CODEC_VC1_MAIN))
2708     {
2709         if ((gvolInfo.vc1_frame_rate != 0) && (gvolInfo.vc1_frame_rate != MVD_U32_MAX))
2710         {
2711             pinfo->u32FrameRate = gvolInfo.vc1_frame_rate;
2712         }
2713         else if (gdivxInfo.frame_rate != 0)
2714         {
2715             pinfo->u32FrameRate = gdivxInfo.frame_rate; //report framerate specified in MDrv_MVD_SetFrameInfo()
2716         }
2717         else
2718         {
2719             pinfo->u32FrameRate = MVD_FRAMERATE_DEFAULT;
2720         }
2721 
2722         MVD_DEBUGVERBAL(printf("MVD: vc1_frameRate=%ld\n", pinfo->u32FrameRate));
2723     }
2724     else if (curCodecType == E_MVD_CODEC_MPEG4)
2725     {
2726         if (gdivxInfo.frame_rate != 0)
2727         {
2728             pinfo->u32FrameRate = gdivxInfo.frame_rate;
2729             //report framerate specified in MDrv_MVD_SetFrameInfo(), which is usually obtained from container
2730         }
2731         else if (gvolInfo.frame_rate != 0)
2732         {
2733             pinfo->u32FrameRate = gvolInfo.frame_rate;  //report framerate from f/w
2734         }
2735         else if ((gvolInfo.fixed_vop_time_incr != 0) && (gvolInfo.vol_time_incr_res != 0))
2736         {
2737             pinfo->u32FrameRate = (gvolInfo.vol_time_incr_res * 1000) / gvolInfo.fixed_vop_time_incr;
2738             //calculate framerate according to vol header
2739         }
2740         else
2741         {
2742             pinfo->u32FrameRate = MVD_FRAMERATE_DEFAULT;
2743         }
2744         MVD_DEBUGVERBAL(printf("MVD: vol_time_incr_res=%d, fixed_vop_time_incr=%d\n", gvolInfo.vol_time_incr_res, gvolInfo.fixed_vop_time_incr));
2745     }
2746     else
2747     {
2748         if (gvolInfo.frame_rate != 0)
2749         {
2750             pinfo->u32FrameRate = gvolInfo.frame_rate;
2751         }
2752         else if (gdivxInfo.frame_rate != 0)
2753         {
2754             pinfo->u32FrameRate = gdivxInfo.frame_rate; //report framerate specified in MDrv_MVD_SetFrameInfo()
2755         }
2756         else
2757         {
2758             pinfo->u32FrameRate = MVD_FRAMERATE_DEFAULT;
2759         }
2760     }
2761 
2762     //printf("===> MVD: frameRate=%d  curCodecType=0x%x\n", pinfo->u32FrameRate, curCodecType);
2763 
2764     //for MM
2765     pinfo->u8MPEG1=gvolInfo.mpeg1;
2766     pinfo->u16PTSInterval=gvolInfo.pts_incr;
2767     pinfo->u8PlayMode=gvolInfo.play_mode;
2768     pinfo->u8FrcMode=gvolInfo.mpeg_frc_mode;
2769 
2770     //for dynamic scaling
2771     pinfo->bEnableMIUSel = stMemCfg.bFWMiuSel;
2772     if (stMemCfg.bEnableDynScale)
2773     {
2774         if (stMemCfg.bFWMiuSel == MIU_SEL_1)
2775         {
2776             pinfo->u32DynScalingAddr= u32DynScalingAdd + stMemCfg.u32Miu1BaseAddr;
2777         }
2778         else
2779         {
2780             pinfo->u32DynScalingAddr= u32DynScalingAdd;
2781         }
2782         pinfo->u8DynScalingDepth= u8DynScalingDepth;
2783         pinfo->u32DynScalingBufSize= gvolInfo.DSbufsize;
2784     }
2785     else
2786     {
2787         pinfo->u32DynScalingAddr= NULL;
2788         pinfo->u8DynScalingDepth= 0;
2789         pinfo->u32DynScalingBufSize= 0;
2790     }
2791 
2792     return;
2793 #endif
2794 }
2795 
2796 //------------------------------------------------------------------------------
2797 /// Set video frame information from MVD
2798 /// @param -pinfo \b IN : pointer to video frame information
2799 //------------------------------------------------------------------------------
MDrv_MVD_SetFrameInfo(MVD_FrameInfo * pinfo)2800 void MDrv_MVD_SetFrameInfo(MVD_FrameInfo *pinfo )
2801 {
2802     MVD_FUNC_ENTRY();
2803     if(pu8MVDSetHeaderBufStart==0)
2804     {
2805         MVD_DEBUGERROR(printf("MDrv_MVD_SetFrameInfo error: pu8MVDSetHeaderBufStart=NULL\n"));
2806         return;
2807     }
2808 
2809     gdivxInfo.width=pinfo->u16HorSize;
2810     gdivxInfo.height=pinfo->u16VerSize;
2811     gdivxInfo.aspect_ratio=pinfo->u8AspectRate;
2812     gdivxInfo.frame_rate = pinfo->u32FrameRate;
2813 
2814     //for MM
2815     gdivxInfo.mpeg1=pinfo->u8MPEG1;
2816     gdivxInfo.pts_incr=pinfo->u16PTSInterval;
2817     gdivxInfo.play_mode=pinfo->u8PlayMode;
2818     gdivxInfo.mpeg_frc_mode=pinfo->u8FrcMode;
2819 
2820     if(pinfo->u8Interlace==0)
2821         gdivxInfo.progressive_sequence=1;
2822     else
2823         gdivxInfo.progressive_sequence=0;
2824 
2825     gdivxInfo.frame_count=0;
2826     gdivxInfo.frame_time=0;
2827     gdivxInfo.vol_handle_done=0;
2828 //    gdivxInfo.invalidstream=0;
2829     MVD_DEBUGINFO(printf("set vol info,pts_incr=%d,\n",gdivxInfo.pts_incr));
2830     MVD_DEBUGINFO(printf("set vol info,width=%x,height=%x,frame_rate=%d,aspect_ratio=%x,\n",
2831                   (unsigned int)gdivxInfo.width,(unsigned int)gdivxInfo.height,gdivxInfo.frame_rate,gdivxInfo.aspect_ratio));
2832     MVD_DEBUGINFO(printf("set vol info,progressive_sequence=%x,mpeg1=%x,play_mode=%x,\n",
2833                   gdivxInfo.progressive_sequence,gdivxInfo.mpeg1,gdivxInfo.play_mode));
2834 
2835     MVD_WriteDivx311Data(&gdivxInfo);
2836     return;
2837 }
2838 
2839 
2840 //------------------------------------------------------------------------------
2841 /// Reset for I-frame decoding
2842 /// @return -none
2843 //------------------------------------------------------------------------------
MDrv_MVD_RstIFrameDec(void)2844 void MDrv_MVD_RstIFrameDec( void )
2845 {
2846     MVD_CmdArg mvdcmd;
2847 
2848     MVD_FUNC_ENTRY();
2849     SETUP_CMDARG(mvdcmd);
2850     if (HAL_MVD_MVDCommand( CMD_STOP, &mvdcmd ) == FALSE)
2851     {
2852         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STOP ) );
2853     }
2854 
2855     MDrv_MVD_Rst();
2856     return;
2857 }
2858 
2859 //take care MIU1 address
MVD_GetMemOffset(MS_PHYADDR u32PhyAdd)2860 static MS_U32 MVD_GetMemOffset(MS_PHYADDR u32PhyAdd)
2861 {
2862     if (u32PhyAdd >= stMemCfg.u32Miu1BaseAddr)
2863     {
2864         return (u32PhyAdd - stMemCfg.u32Miu1BaseAddr);
2865     }
2866     else
2867     {
2868         return u32PhyAdd;
2869     }
2870 }
2871 
2872 //------------------------------------------------------------------------------
2873 /// Decode I-frame
2874 /// @param -u32FrameBufAddr \b IN : start address of frame buffer
2875 /// @param -u32StreamBufAddr \b IN : start address of stream buffer
2876 /// @return -return decode I-frame success or not
2877 //------------------------------------------------------------------------------
MDrv_MVD_DecodeIFrame(MS_PHYADDR u32FrameBufAddr,MS_PHYADDR u32StreamBufAddr,MS_PHYADDR u32StreamBufEndAddr)2878 MS_BOOL MDrv_MVD_DecodeIFrame(MS_PHYADDR u32FrameBufAddr, MS_PHYADDR u32StreamBufAddr, MS_PHYADDR u32StreamBufEndAddr )
2879 {
2880 #if defined(CHIP_T7)
2881     u32FrameBufAddr     = MVD_GetMemOffset(u32FrameBufAddr);
2882     u32StreamBufAddr    = MVD_GetMemOffset(u32StreamBufAddr);
2883     u32StreamBufEndAddr = MVD_GetMemOffset(u32StreamBufEndAddr);
2884     _bDecodeIFrame = TRUE;
2885     return __MVD_DecodeIFrame( u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr);
2886 #else
2887     MS_U32 u32deley = 0;
2888     MS_U32 u32time = 0;
2889     MVD_CmdArg mvdcmd;
2890 
2891     MVD_DEBUGINFO(printf("%s input  FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
2892             __FUNCTION__, u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr));
2893     u32FrameBufAddr     = MVD_GetMemOffset(u32FrameBufAddr);
2894     u32StreamBufAddr    = MVD_GetMemOffset(u32StreamBufAddr);
2895     u32StreamBufEndAddr = MVD_GetMemOffset(u32StreamBufEndAddr);
2896     MVD_DEBUGINFO(printf("%s offset FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
2897             __FUNCTION__, u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr));
2898 
2899     MDrv_MVD_SetFrameBuffAddr( u32FrameBufAddr);
2900     MDrv_MVD_SetCodecInfo(E_MVD_CODEC_MPEG2, E_MVD_SLQ_MODE, DISABLE_PARSER);
2901 
2902     SETUP_CMDARG(mvdcmd);
2903     mvdcmd.Arg0 = 1;
2904     if (HAL_MVD_MVDCommand( CMD_DISPLAY_CTL, &mvdcmd ) == FALSE)
2905     {
2906         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DISPLAY_CTL ) );
2907         return FALSE;
2908     }
2909 
2910     if (MDrv_MVD_StepDecode() == FALSE)
2911     {
2912         MVD_DEBUGERROR( printf( "MDrv_MVD_StepDecode fail!!\r\n") );
2913         return FALSE;
2914     }
2915 
2916     SETUP_CMDARG(mvdcmd);
2917     mvdcmd.Arg0 = 1;
2918     mvdcmd.Arg1 = 1;
2919     if (HAL_MVD_MVDCommand(CMD_FAST_SLOW, &mvdcmd) == FALSE)
2920     {
2921         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FAST_SLOW ) );
2922         return FALSE;
2923     }
2924 
2925     //set data
2926     HAL_MVD_Delayms(2);
2927 
2928     HAL_MVD_CPU_Sync();
2929     HAL_MVD_FlushMemory();
2930 
2931     //wait vld init success or data may lost!
2932 #define WAIT_INIT_SUCCESS_TIME 100 //100ms
2933     u32deley = HAL_MVD_GetTime();
2934     while ((MDrv_MVD_GetDecodeStatus()==DEC_STAT_IDLE) && (u32time<WAIT_INIT_SUCCESS_TIME))
2935     {
2936         u32time = HAL_MVD_GetTime()-u32deley;
2937     }
2938     if (u32time>=WAIT_INIT_SUCCESS_TIME)
2939     {
2940         MVD_DEBUGERROR(printf("%s: wait init_success timeout!!!\n", __FUNCTION__));
2941     }
2942 
2943     MDrv_MVD_SetSLQStartEnd(u32StreamBufAddr, u32StreamBufEndAddr);
2944     MVD_DEBUGINFO(printf("set MVD3_FW_SLQ_TAB_TMPBUF_ADR=%lx\n",u32MVDFWSLQTABTmpbufAdr));
2945 
2946     HAL_MVD_CPU_Sync();
2947     HAL_MVD_FlushMemory();
2948     MDrv_MVD_SetSLQStartEnd(u32MVDFWSLQTABTmpbufAdr, u32MVDFWSLQTABTmpbufAdr+MVD3_FW_SLQ_TAB_TMPBUF_LEN);
2949 
2950     HAL_MVD_CPU_Sync();
2951     HAL_MVD_ReadMemory();
2952 
2953     // wait decode complete
2954 #define WAIT_DECODE_DONE_TIME 33 //To decode 1 frame should take less than 33ms
2955     u32deley = HAL_MVD_GetTime();
2956     u32time = 0;
2957     while ((MDrv_MVD_GetPicCounter()<1) && (u32time<WAIT_DECODE_DONE_TIME))
2958     {
2959         u32time = HAL_MVD_GetTime()-u32deley;
2960     }
2961     if (u32time >= WAIT_DECODE_DONE_TIME)
2962     {
2963         MVD_DEBUGERROR(printf ("MDrv_MVD_DecodeIFrame time out(%ld, %ld)\n", u32time, u32deley));
2964         MVD_DEBUGERROR(printf("frmCnt=%ld state=0x%x lastCmd=0x%x\n", MDrv_MVD_GetPicCounter(), MDrv_MVD_GetDecodeStatus(), MDrv_MVD_GetLastCmd()));
2965         return FALSE;
2966     }
2967     MVD_DEBUGINFO(printf ("MDrv_MVD_DecodeIFrame time (%ld, %ld)\n", u32time, u32deley));
2968     //printf("frmCnt=%ld state=0x%x lastCmd=0x%x\n", MDrv_MVD_GetPicCounter(), MDrv_MVD_GetDecodeStatus(), MDrv_MVD_GetLastCmd());
2969 
2970     _bDecodeIFrame = TRUE;
2971 
2972     return TRUE;
2973 #endif
2974 }
2975 
2976 //------------------------------------------------------------------------------
2977 /// Query if MVD is decoding frame
2978 /// @return -MVD is decoding frame or not
2979 //------------------------------------------------------------------------------
MDrv_MVD_GetIsIFrameDecoding(void)2980 MS_BOOL MDrv_MVD_GetIsIFrameDecoding(void)
2981 {
2982     return _bDecodeIFrame;
2983 }
2984 
2985 //------------------------------------------------------------------------------
2986 /// Set bitstream buffer overflow threshold
2987 /// @return -none
2988 //------------------------------------------------------------------------------
MDrv_MVD_SetOverflowTH(MS_U32 u32Threshold)2989 void MDrv_MVD_SetOverflowTH(MS_U32 u32Threshold)
2990 {
2991     MVD_CmdArg mvdcmd;
2992 
2993     MVD_FUNC_ENTRY();
2994     MS_ASSERT((u32Threshold%8)==0);
2995     u32Threshold >>= 3;
2996     SETUP_CMDARG(mvdcmd);
2997     mvdcmd.Arg0 = L_WORD(u32Threshold);
2998     mvdcmd.Arg1 = H_WORD(u32Threshold);
2999     mvdcmd.Arg2 = L_DWORD(u32Threshold);
3000     mvdcmd.Arg3 = H_DWORD(u32Threshold);
3001 
3002     if (HAL_MVD_MVDCommand( CMD_DMA_OVFTH, &mvdcmd ) == FALSE)
3003     {
3004         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DMA_OVFTH ) );
3005         return;
3006     }
3007     return;
3008 }
3009 
3010 //------------------------------------------------------------------------------
3011 /// Set bitstream buffer underflow threshold
3012 /// @return -none
3013 //------------------------------------------------------------------------------
MDrv_MVD_SetUnderflowTH(MS_U32 u32Threshold)3014 void MDrv_MVD_SetUnderflowTH(MS_U32 u32Threshold)
3015 {
3016     MVD_CmdArg mvdcmd;
3017 
3018     MVD_FUNC_ENTRY();
3019     MS_ASSERT((u32Threshold%8)==0);
3020     u32Threshold >>= 3;
3021     SETUP_CMDARG(mvdcmd);
3022     mvdcmd.Arg0 = L_WORD(u32Threshold);
3023     mvdcmd.Arg1 = H_WORD(u32Threshold);
3024     mvdcmd.Arg2 = L_DWORD(u32Threshold);
3025     mvdcmd.Arg3 = H_DWORD(u32Threshold);
3026 
3027     if (HAL_MVD_MVDCommand( CMD_DMA_UNFTH, &mvdcmd ) == FALSE)
3028     {
3029         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DMA_UNFTH ) );
3030         return;
3031     }
3032     return;
3033 }
3034 
3035 //------------------------------------------------------------------------------
3036 /// Get MVD active format
3037 /// @return -active format
3038 //------------------------------------------------------------------------------
MDrv_MVD_GetActiveFormat(void)3039 MS_U8 MDrv_MVD_GetActiveFormat(void)
3040 {
3041 #if defined (CHIP_T7)
3042     return __MVD_GetActiveFormat();
3043 #else
3044     MVD_CmdArg mvdcmd;
3045     static MS_U8 u8Afd = 0xff;
3046 #if (MVD_TURBO_INIT)
3047     static MS_U32 u32FrmCnt = 0;
3048 
3049     if (u32FrmCnt == MDrv_MVD_GetPicCounter())
3050     {
3051         return u8Afd;
3052     }
3053     u32FrmCnt = MDrv_MVD_GetPicCounter();
3054 #endif
3055     MVD_FUNC_ENTRY();
3056     SETUP_CMDARG(mvdcmd);
3057     if (HAL_MVD_MVDCommand( CMD_GET_AFD, &mvdcmd ) == FALSE)
3058     {
3059         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_AFD  ) );
3060         return 0xff;
3061     }
3062     u8Afd = mvdcmd.Arg0;
3063     return u8Afd;
3064 #endif
3065 }
3066 
3067 //------------------------------------------------------------------------------
3068 /// Enable or disable AV synchronization.
3069 /// Delay u32Delay ms if AVSync is enabled.
3070 /// @return -none
3071 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSync(MS_BOOL bEnable,MS_U32 u32Delay)3072 void MDrv_MVD_SetAVSync(MS_BOOL bEnable, MS_U32 u32Delay)
3073 {
3074 #if defined(CHIP_T7)
3075     __MVD_SetAVSync(bEnable, u32Delay);
3076     bAVSyncOn = bEnable;    //for IsAVSyncOn
3077     stSyncCfg.bEnable = bEnable;
3078     stSyncCfg.u32Delay = u32Delay;
3079     return;
3080 #else
3081     MVD_CmdArg mvdcmd;
3082 
3083     //printf("%s bEnable=%d u32Delay=%ld\n",__FUNCTION__,bEnable,u32Delay);
3084     MVD_FUNC_ENTRY();
3085 
3086     SETUP_CMDARG(mvdcmd);
3087     mvdcmd.Arg0 = bEnable;
3088     bAVSyncOn = bEnable;    //for IsAVSyncOn
3089     if (HAL_MVD_MVDCommand( CMD_SYNC_ON, &mvdcmd ) == FALSE)
3090     {
3091         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_SYNC_ON  ) );
3092         return;
3093     }
3094 
3095     if (bEnable && (u32Delay != 0))
3096     {
3097         SET_CMDARG(mvdcmd, _MS_TO_90K(u32Delay)); //u32Delay ms ==> 90k counter
3098         if (HAL_MVD_MVDCommand( CMD_SYNC_OFFSET, &mvdcmd ) == FALSE)
3099         {
3100             MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_SYNC_ON  ) );
3101             return;
3102         }
3103     }
3104 
3105     stSyncCfg.bEnable = bEnable;
3106     stSyncCfg.u32Delay = u32Delay;
3107     return;
3108 #endif
3109 }
3110 
3111 //------------------------------------------------------------------------------
3112 /// Set skip & repeat frame mode.
3113 /// mode : 1 skip B frame 0 : skip display frame
3114 /// @return -none
3115 //------------------------------------------------------------------------------
MDrv_MVD_SetSkipRepeatMode(MS_U8 u8Mode)3116 MS_BOOL MDrv_MVD_SetSkipRepeatMode(MS_U8 u8Mode)
3117 {
3118     MVD_CmdArg mvdcmd;
3119     MVD_FUNC_ENTRY();
3120 
3121     if (u8Mode != 1 && u8Mode != 0)
3122     {
3123         return FALSE; //invalid parameter, do nothing
3124     }
3125 
3126     SETUP_CMDARG(mvdcmd);
3127     mvdcmd.Arg4 = u8Mode;
3128     mvdcmd.Arg5 = u8Mode;
3129     if (HAL_MVD_MVDCommand( CMD_SYN_THRESHOLD , &mvdcmd ) == FALSE)
3130     {
3131         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SYN_THRESHOLD ) );
3132         return FALSE;
3133     }
3134     return TRUE;
3135 }
3136 
3137 //------------------------------------------------------------------------------
3138 /// Set the maximum repeat times for one frame when av is not sync.
3139 /// E.g. Arg5=0x01 mean that frame will be repeated once if av is not sync.
3140 ///      Arg5=0xff mean that frame will be always repeated when av is not sync.
3141 /// And customer can re-define the avsync skip behavior,
3142 /// i.e., Arg4 = 1 for skip-b-frame only and 0 for skip display(default)
3143 /// @return -none
3144 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSyncThreshold(MS_U32 u32Th)3145 void MDrv_MVD_SetAVSyncThreshold(MS_U32 u32Th)
3146 {
3147     MVD_CmdArg mvdcmd;
3148     MVD_FUNC_ENTRY();
3149 
3150     if (u32Th == 0x00)
3151     {
3152         return; //invalid parameter, do nothing
3153     }
3154     if (u32Th > 0xff)
3155     {
3156         u32Th = 0xff; //set to maximum
3157     }
3158 
3159     SETUP_CMDARG(mvdcmd);
3160     mvdcmd.Arg5 = u32Th;
3161     if (HAL_MVD_MVDCommand(CMD_SYN_THRESHOLD, &mvdcmd) == FALSE)
3162     {
3163         MVD_DEBUGERROR(printf("Ctrl: 0x%x fail!!\n", CMD_SYN_THRESHOLD));
3164         return;
3165     }
3166 
3167     return;
3168 
3169 }
3170 
3171 
3172 //------------------------------------------------------------------------------
3173 /// Set the threshold for VC1 avsync (live mode & file mode). Unit: 90K
3174 /// @return -none
3175 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSyncFreerunThreshold(MS_U32 u32Th)3176 void MDrv_MVD_SetAVSyncFreerunThreshold(MS_U32 u32Th)
3177 {
3178     MVD_CmdArg mvdcmd;
3179     MVD_FUNC_ENTRY();
3180 
3181     SET_CMDARG(mvdcmd, u32Th);
3182     if (HAL_MVD_MVDCommand(CMD_AVSYNC_FREERUN_THRESHOLD, &mvdcmd) == FALSE)
3183     {
3184         MVD_DEBUGERROR(printf("Ctrl: 0x%x fail!!\n", CMD_AVSYNC_FREERUN_THRESHOLD));
3185         return;
3186     }
3187 
3188     return;
3189 
3190 }
3191 
3192 //------------------------------------------------------------------------------
3193 /// Get MVD AVSync delay (ms)
3194 /// @return -avsync delay
3195 //------------------------------------------------------------------------------
MDrv_MVD_GetAVSyncDelay(void)3196 MS_U32 MDrv_MVD_GetAVSyncDelay(void)
3197 {
3198     return (stSyncCfg.u32Delay);
3199 }
3200 
3201 //------------------------------------------------------------------------------
3202 /// Get if AVSync is turned on
3203 /// @return -TRUE for yes or FALSE for no
3204 //------------------------------------------------------------------------------
MDrv_MVD_GetIsAVSyncOn(void)3205 MS_BOOL MDrv_MVD_GetIsAVSyncOn(void)
3206 {
3207     return bAVSyncOn;
3208 }
3209 
3210 
3211 //------------------------------------------------------------------------------
3212 /// Get if firmware is repeating frame for AVSync.
3213 /// @return -TRUE for yes or FALSE for no
3214 //------------------------------------------------------------------------------
MDrv_MVD_GetIsSyncRep(void)3215 MS_BOOL MDrv_MVD_GetIsSyncRep(void)
3216 {
3217 #if defined(CHIP_T7)
3218     return FALSE;
3219 #else
3220     MS_U32 u32IntStat = 0;
3221     MS_BOOL bRet = FALSE;
3222 
3223     u32IntStat = HAL_MVD_GetIntState();
3224     if (u32IntStat != 0)
3225     {
3226         bRet = ((u32IntStat&INT_SYN_REP)==INT_SYN_REP) ? TRUE : FALSE;
3227     }
3228     return bRet;
3229 #endif
3230 }
3231 
3232 
3233 //------------------------------------------------------------------------------
3234 /// Get if firmware is skipping frame for AVSync.
3235 /// @return -TRUE for yes or FALSE for no
3236 //------------------------------------------------------------------------------
MDrv_MVD_GetIsSyncSkip(void)3237 MS_BOOL MDrv_MVD_GetIsSyncSkip(void)
3238 {
3239 #if defined(CHIP_T7)
3240     return FALSE;
3241 #else
3242     MS_U32 u32IntStat = 0;
3243     MS_BOOL bRet = FALSE;
3244 
3245     u32IntStat = HAL_MVD_GetIntState();
3246     if (u32IntStat != 0)
3247     {
3248         bRet = ((u32IntStat&INT_SYN_SKIP)==INT_SYN_SKIP) ? TRUE : FALSE;
3249     }
3250 
3251     return bRet;
3252 #endif
3253 }
3254 
3255 //------------------------------------------------------------------------------
3256 /// Change PTS threshold for doing AVSync.
3257 /// Scenario: When disable black screen earlier than normal case, use this function
3258 /// to avoid frame skip too fast or video lag.
3259 /// @param -bEnable \b IN : enable this configuration
3260 /// @param -u16PTS \b IN : PTS threshold (unit: 90k counter, i.e. x/90 ms, max 728ms)
3261 /// @return -TRUE for success or FALSE for failure.
3262 //------------------------------------------------------------------------------
MDrv_MVD_ChangeAVsync(MS_BOOL bEnable,MS_U16 u16PTS)3263 MS_BOOL MDrv_MVD_ChangeAVsync(MS_BOOL bEnable, MS_U16 u16PTS)
3264 {
3265     #if !defined(CHIP_T7)
3266     MVD_CmdArg mvdcmd;
3267 
3268     stSyncCfg.u16Tolerance = u16PTS;
3269 
3270     u16PTS = _MS_TO_90K(u16PTS); //u16PTS ms ==> 90k counter
3271     SETUP_CMDARG(mvdcmd);
3272     mvdcmd.Arg0 = (MS_U8)bEnable;
3273     mvdcmd.Arg1 = 0;
3274     mvdcmd.Arg2 = (MS_U8)(u16PTS&0xff);
3275     mvdcmd.Arg3 = (MS_U8)((u16PTS&0xff00)>>8);
3276 
3277     if (HAL_MVD_MVDCommand( CMD_MVD_FAST_INT, &mvdcmd ) == FALSE)
3278     {
3279         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_MVD_FAST_INT  ) );
3280         return FALSE;
3281     }
3282     #endif
3283     return TRUE;
3284 }
3285 
3286 
3287 //------------------------------------------------------------------------------
3288 /// Get size of residual bitstream.
3289 /// @return -size of residual bitstream
3290 //------------------------------------------------------------------------------
MDrv_MVD_GetResidualStreamSize(void)3291 MS_U32 MDrv_MVD_GetResidualStreamSize( void )
3292 {
3293 #if defined(CHIP_T7)
3294     return __MVD_GetResidualStreamSize();
3295 #else
3296     MS_U32 u32Ret = 0;
3297     MVD_CmdArg mvdcmd;
3298 
3299     MVD_FUNC_ENTRY();
3300 
3301     SETUP_CMDARG(mvdcmd);
3302     if (HAL_MVD_MVDCommand( CMD_VBUFFER_COUNT, &mvdcmd ) == TRUE)
3303     {
3304         u32Ret = (((MS_U32)mvdcmd.Arg2) << 19) |
3305                  (((MS_U32)mvdcmd.Arg1) << 11) |
3306                  (((MS_U32)mvdcmd.Arg0) << 3);
3307     }
3308     else
3309     {
3310         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_VBUFFER_COUNT  ) );
3311     }
3312 
3313     return u32Ret;
3314 #endif
3315 }
3316 
3317 //------------------------------------------------------------------------------
3318 /// Get address of the first I-frame.
3319 /// @return -address of the first I-frame
3320 //------------------------------------------------------------------------------
MDrv_MVD_GetIsIPicFound()3321 MS_U8 MDrv_MVD_GetIsIPicFound()
3322 {
3323     MVD_FUNC_ENTRY();
3324 #if defined(CHIP_T7)
3325     return __MVD_GetIsIPicFound();
3326 #else
3327     return HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_FIRST_I_FOUND);
3328 #endif
3329 }
3330 
3331 //------------------------------------------------------------------------------
3332 /// Get sync status to know whether sync is complete or not
3333 /// @return - 1        : sync complete
3334 ////        - otherwise: sync not complete
3335 //------------------------------------------------------------------------------
MDrv_MVD_GetSyncStatus(void)3336 MS_U8 MDrv_MVD_GetSyncStatus(void)
3337 {
3338 #if defined(CHIP_T7)
3339     return __MVD_GetSyncStatus();
3340 #else
3341     MVD_CmdArg mvdcmd;
3342 
3343     MVD_FUNC_ENTRY();
3344     SETUP_CMDARG(mvdcmd);
3345     if (HAL_MVD_MVDCommand( CMD_GET_SYNC_STAT, &mvdcmd ) == FALSE)
3346     {
3347         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_SYNC_STAT  ) );
3348         return 0xFF;
3349     }
3350     MVD_DEBUGINFO(printf("Sync On/Off %x, Sync Done %x\n", mvdcmd.Arg0, mvdcmd.Arg1));
3351     if(mvdcmd.Arg1 == MVD_SYNC_DONE)
3352         return 1;
3353     else
3354         return 0xFF;
3355 #endif
3356 }
3357 
3358 //------------------------------------------------------------------------------
3359 /// Report if decoder is freerun or not
3360 /// @return - TRUE  : freerun
3361 ////        - FALSE : not freerun
3362 //------------------------------------------------------------------------------
MDrv_MVD_GetIsFreerun(void)3363 MS_BOOL MDrv_MVD_GetIsFreerun(void)
3364 {
3365 
3366     return (HAL_MVD_GetAVSyncStatus() == 0);
3367 
3368 }
3369 
3370 //------------------------------------------------------------------------------
3371 /// Get PTS (Presentation Time Stamp)
3372 /// @return -PTS (unit: ms)
3373 //------------------------------------------------------------------------------
MDrv_MVD_GetPTS(void)3374 MS_U32 MDrv_MVD_GetPTS(void)
3375 {
3376 #if defined(CHIP_T7)
3377     return __MVD_GetPTS();
3378 #else
3379     MS_U32 u32PTS = 0;
3380 
3381     MVD_FUNC_ENTRY();
3382 #if 1
3383     if(pu8MVDGetFrameInfoBufStart==0)
3384     {
3385         MVD_DEBUGERROR(printf("MDrv_MVD_GetPTS error!\n"));
3386         u32PTS = 0;
3387     }
3388     u32PTS = (MS_U32)HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_DISP_PTS);
3389 #else
3390     MVD_CmdArg mvdcmd;
3391     SETUP_CMDARG(mvdcmd);
3392     if (HAL_MVD_MVDCommand( CMD_RD_PTS, &mvdcmd ) == FALSE)
3393     {
3394         MVD_DEBUGERROR(printf( "Ctrl: CMD_RD_PTS fail!!\n"  ) );
3395         u32PTS = MVD_U32_MAX;
3396     }
3397     else
3398     {
3399         u32PTS = ((MS_U32)mvdcmd.Arg3 << 24 | (MS_U32)mvdcmd.Arg2 << 16 |
3400                   (MS_U32)mvdcmd.Arg1 << 8  | (MS_U32)mvdcmd.Arg0);
3401         MVD_DEBUGVERBAL(printf("MDrv_MVD_GetPTS:0x%lx\n", u32PTS));
3402     }
3403 #endif
3404 
3405     u32PTS = _90K_TO_MS(u32PTS);
3406     return u32PTS;
3407 #endif
3408 }
3409 
3410 //------------------------------------------------------------------------------
3411 /// Get Next PTS (Presentation Time Stamp)
3412 /// @return -Next PTS (unit: ms)
3413 //------------------------------------------------------------------------------
MDrv_MVD_GetNextPTS(void)3414 MS_U32 MDrv_MVD_GetNextPTS(void)
3415 {
3416 #if defined(CHIP_T2) || defined(CHIP_T7)
3417     return 0;
3418 #else
3419     MVD_FUNC_ENTRY();
3420     if(pu8MVDGetFrameInfoBufStart==0)
3421     {
3422         MVD_DEBUGERROR(printf("MDrv_MVD_GetNextPTS error!\n"));
3423         return 0;
3424     }
3425     return (MS_U32)_90K_TO_MS(HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_NEXT_PTS));
3426 #endif
3427 }
3428 
3429 
3430 //------------------------------------------------------------------------------
3431 /// Get Chroma format (MDrv_MVD_GetChromaFormat)
3432 /// @return -Chroma format ()
3433 //------------------------------------------------------------------------------
MDrv_MVD_GetChromaFormat(void)3434 MS_U32 MDrv_MVD_GetChromaFormat(void)
3435 {
3436     MVD_FUNC_ENTRY();
3437 
3438     if(pu8MVDGetFrameInfoBufStart==0)
3439     {
3440         MVD_DEBUGERROR(printf("MDrv_MVD_GetChromaFormat error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3441         return FALSE;
3442     }
3443 
3444     return HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_CHROMA_FORMAT);
3445 }
3446 
3447 //------------------------------------------------------------------------------
3448 /// Query if MVD is ready to display
3449 /// @return -MS_U8  0: not ready, !0: ready.
3450 //------------------------------------------------------------------------------
MDrv_MVD_GetDispRdy(void)3451 MS_U8 MDrv_MVD_GetDispRdy(void)
3452 {
3453     MVD_FUNC_ENTRY();
3454 #if (defined(CHIP_T7))
3455     return __MVD_GetDispRdy();
3456 #else
3457     if ((MDrv_MVD_GetPicCounter() > 0) || MDrv_MVD_GetIsIPicFound())
3458     {
3459         return 1;
3460     }
3461     else
3462     {
3463         return 0;
3464     }
3465 #endif
3466 }
3467 
3468 //------------------------------------------------------------------------------
3469 /// Query if the first frame is showed after play function is called.
3470 /// Whenever the first display frame is displayed, f/w will set this flag to 1.
3471 /// @return VDEC_Result
3472 //------------------------------------------------------------------------------
MDrv_MVD_Is1stFrmRdy(void)3473 MS_BOOL MDrv_MVD_Is1stFrmRdy(void)
3474 {
3475     if (pu8MVDGetVolBufStart==0)
3476     {
3477         MVD_DEBUGERROR(printf("%s err: pu8MVDGetVolBufStart=NULL\n", __FUNCTION__));
3478         return FALSE;
3479     }
3480 
3481     return HAL_MVD_MemReadByte(pu8MVDGetVolBufStart + OFFSET_FIRST_DISPLAY);
3482 }
3483 
3484 //------------------------------------------------------------------------------
3485 /// Get picture count of current GOP (Group of Picture)
3486 /// @return -picture count of GOP
3487 //------------------------------------------------------------------------------
MDrv_MVD_GetGOPCount(void)3488 MS_U32 MDrv_MVD_GetGOPCount(void)
3489 {
3490     MVD_FUNC_ENTRY();
3491     if(pu8MVDGetFrameInfoBufStart==0)
3492     {
3493         MVD_DEBUGERROR(printf("MDrv_MVD_GetPicCounter error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3494             return 0;
3495     }
3496 
3497     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_GOP_I_FCNT)
3498          + HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_GOP_P_FCNT)
3499          + HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_GOP_B_FCNT);
3500 }
3501 
3502 //------------------------------------------------------------------------------
3503 /// Enable or disable dropping error frames
3504 /// @return -command is set successfully or not
3505 //------------------------------------------------------------------------------
MDrv_MVD_DropErrorFrame(MS_BOOL bDrop)3506 MS_BOOL MDrv_MVD_DropErrorFrame(MS_BOOL bDrop)
3507 {
3508     #if (defined(CHIP_T7))
3509     MVD_DEBUGINFO( printf( "This Cmd is bypass in MVD1 <%x>!!\r\n", bDrop  ) );
3510     #else
3511     MVD_CmdArg mvdcmd;
3512 
3513     MVD_FUNC_ENTRY();
3514     SETUP_CMDARG(mvdcmd);
3515     mvdcmd.Arg1 = (MS_U8)bDrop;
3516     mvdcmd.Arg2 = (MS_U8)bDropDispfrm;
3517     mvdcmd.Arg3 = _eFrcMode;
3518     if (HAL_MVD_MVDCommand( CMD_DISPLAY_CTL, &mvdcmd ) == FALSE)
3519     {
3520         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_DISPLAY_CTL  ) );
3521         return FALSE;
3522     }
3523     #endif
3524     bDropErrFrm = bDrop;
3525     return TRUE;
3526 }
3527 
3528 //------------------------------------------------------------------------------
3529 /// Get byte count of parser.
3530 /// @return -byte count of parser
3531 //------------------------------------------------------------------------------
MDrv_MVD_GetParserByteCnt(void)3532 MS_U32 MDrv_MVD_GetParserByteCnt(void)
3533 {
3534     MVD_CmdArg mvdcmd;
3535     MS_U32 u32Cnt = 0;
3536 
3537     MVD_FUNC_ENTRY();
3538     SETUP_CMDARG(mvdcmd);
3539 
3540     //To be accurate, it's "VLD byte count", instead of "parser byte count".
3541     mvdcmd.Arg0 = 0x34;
3542     mvdcmd.Arg1 = 0x2;
3543     if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
3544     {
3545         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_RD_IO  ) );
3546         return 0;
3547     }
3548     u32Cnt = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8) |
3549              (((MS_U32)mvdcmd.Arg4) << 16) | (((MS_U32)mvdcmd.Arg5) << 24);
3550 
3551 
3552     //printf("  parser byte count = %lu byte \n", u32Cnt);
3553     return u32Cnt;
3554 }
3555 
3556 
3557 //------------------------------------------------------------------------------
3558 /// Get the decode status.
3559 /// @return -the decode status
3560 //------------------------------------------------------------------------------
MDrv_MVD_GetDecodeStatus(void)3561 MVD_DecStat MDrv_MVD_GetDecodeStatus(void)
3562 {
3563 #if defined(CHIP_T7)
3564     return __MVD_GetDecodeStatus();
3565 #else
3566     MVD_CmdArg mvdcmd;
3567     MVD_DecStat stat = E_MVD_STAT_UNKNOWN;
3568 
3569     MVD_FUNC_ENTRY();
3570     SETUP_CMDARG(mvdcmd);
3571     if (HAL_MVD_MVDCommand(CMD_DECODE_STATUS, &mvdcmd) == FALSE)
3572     {
3573         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_STATUS ) );
3574         return E_MVD_STAT_UNKNOWN;
3575     }
3576 
3577     switch(mvdcmd.Arg1)
3578     {
3579         case DEC_STAT_IDLE:
3580             stat = E_MVD_STAT_IDLE;
3581             break;
3582         case DEC_STAT_FIND_SC:
3583             stat = E_MVD_STAT_FIND_STARTCODE;
3584             break;
3585         case DEC_STAT_FIND_SPE_SC:
3586             stat = E_MVD_STAT_FIND_SPECIALCODE;
3587             break;
3588         case DEC_STAT_FIND_FRAMEBUFFER:
3589             stat = E_MVD_STAT_FIND_FRAMEBUFFER;
3590             break;
3591         case DEC_STAT_WAIT_DECODE_DONE:
3592             stat = E_MVD_STAT_WAIT_DECODEDONE;
3593             break;
3594         case DEC_STAT_DECODE_DONE:
3595             stat = E_MVD_STAT_DECODE_DONE;
3596             break;
3597         case DEC_STAT_WAIT_VDFIFO:
3598             stat = E_MVD_STAT_WAIT_VDFIFO;
3599             break;
3600         case DEC_STAT_INIT_SUCCESS:
3601             stat = E_MVD_STAT_INIT_SUCCESS;
3602             break;
3603         default:
3604             break;
3605     }
3606 
3607     return stat;
3608 #endif
3609 }
3610 
3611 
3612 //------------------------------------------------------------------------------
3613 /// Get the last command to firmware.
3614 /// @return -the last command
3615 //------------------------------------------------------------------------------
MDrv_MVD_GetLastCmd(void)3616 MS_U8 MDrv_MVD_GetLastCmd(void)
3617 {
3618     MVD_CmdArg mvdcmd;
3619 
3620     MVD_FUNC_ENTRY();
3621     SETUP_CMDARG(mvdcmd);
3622     if (HAL_MVD_MVDCommand( CMD_DECODE_STATUS, &mvdcmd ) == FALSE)
3623     {
3624         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_STATUS ) );
3625         return 0xff;
3626     }
3627 
3628     return (mvdcmd.Arg0);
3629 }
3630 
3631 
3632 //------------------------------------------------------------------------------
3633 /// Skip data in ES buffer.  It is used for flushing ES buffer.
3634 /// @return -TRUE for success; FALSE for failure.
3635 //------------------------------------------------------------------------------
MDrv_MVD_SkipData(void)3636 MS_BOOL MDrv_MVD_SkipData(void)
3637 {
3638 
3639     #define SKIP_DATA_TIMEOUT 0x20
3640     MS_U32 u32TimeOut = 0;
3641     MVD_CmdArg mvdcmd;
3642 
3643     MVD_FUNC_ENTRY();
3644     SETUP_CMDARG(mvdcmd);
3645 
3646     while(MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SKIP_DATA) && (u32TimeOut < SKIP_DATA_TIMEOUT))
3647     {
3648         if (HAL_MVD_MVDCommand(CMD_SKIP_DATA, &mvdcmd) == FALSE)
3649         {
3650             MVD_DEBUGINFO( printf( "Ctrl: 0x%x fail!!\r\n", CMD_SKIP_DATA ) );
3651             return FALSE;
3652         }
3653         u32TimeOut++;
3654     }
3655 
3656     if(u32TimeOut >= SKIP_DATA_TIMEOUT)
3657     {
3658         MVD_DEBUGERROR( printf( "Ctrl: 0x%x timeout(0x%x)!!\r\n", CMD_SKIP_DATA, SKIP_DATA_TIMEOUT) );
3659         return FALSE;
3660     }
3661     return TRUE;
3662 
3663 }
3664 
3665 
3666 //------------------------------------------------------------------------------
3667 /// Skip to I frame.
3668 /// Used for MediaCodec when input data is not continuous or in the beginning of
3669 /// streams.
3670 /// @return -TRUE for success; FALSE for failure.
3671 //------------------------------------------------------------------------------
MDrv_MVD_SkipToIFrame(void)3672 MS_BOOL MDrv_MVD_SkipToIFrame(void)
3673 {
3674     MVD_CmdArg mvdcmd;
3675 
3676     MVD_FUNC_ENTRY();
3677     SETUP_CMDARG(mvdcmd);
3678     if (HAL_MVD_MVDCommand(CMD_START_DEC_STRICT, &mvdcmd) == FALSE)
3679     {
3680         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_START_DEC_STRICT  ) );
3681         return FALSE;
3682     }
3683     return TRUE;
3684 }
3685 
3686 
3687 //Map driver FRC (Frame rate conversion) mode to firmware's.
MVD_MapFrcMode(MVD_FrcMode eFrcMode)3688 static MS_U8 MVD_MapFrcMode(MVD_FrcMode eFrcMode)
3689 {
3690     MS_U8 frcMode = 0xf;
3691     switch (eFrcMode)
3692     {
3693         case E_MVD_FRC_NORMAL:
3694             frcMode = FrcNormal;
3695             break;
3696         case E_MVD_FRC_DISP_TWICE:
3697             frcMode = FrcDisplayTwice;
3698             break;
3699         case E_MVD_FRC_3_2_PULLDOWN:    //film 24 -> 50i
3700             frcMode = Frc32Pulldown;
3701             break;
3702         case E_MVD_FRC_PAL_TO_NTSC:
3703             frcMode = FrcPALtoNTSC;
3704             break;
3705         case E_MVD_FRC_NTSC_TO_PAL:
3706             frcMode = FrcNTSCtoPAL;
3707             break;
3708         case E_MVD_FRC_DISP_ONEFIELD:
3709             frcMode = FrcShowOneFiled;
3710             break;
3711         default:
3712             break;
3713     }
3714     return frcMode;
3715 }
3716 
3717 
3718 //------------------------------------------------------------------------------
3719 /// Display control for decoding order, enabling drop error frame, dropping
3720 /// display and setting FRC (frame rate conversion) mode.
3721 /// @return -TRUE for success; FALSE for failure.
3722 //------------------------------------------------------------------------------
MDrv_MVD_DispCtrl(MS_BOOL bDecOrder,MS_BOOL bDropErr,MS_BOOL bDropDisp,MVD_FrcMode eFrcMode)3723 MS_BOOL MDrv_MVD_DispCtrl(MS_BOOL bDecOrder, MS_BOOL bDropErr, MS_BOOL bDropDisp, MVD_FrcMode eFrcMode)
3724 {
3725     MVD_CmdArg mvdcmd;
3726 
3727     MVD_FUNC_ENTRY();
3728     SETUP_CMDARG(mvdcmd);
3729     mvdcmd.Arg0 = (MS_U8)bDecOrder;
3730     mvdcmd.Arg1 = (MS_U8)bDropErr;
3731     mvdcmd.Arg2 = (MS_U8)bDropDisp;
3732     mvdcmd.Arg3 = MVD_MapFrcMode(eFrcMode);
3733 
3734     if (HAL_MVD_MVDCommand( CMD_DISPLAY_CTL, &mvdcmd ) == FALSE)
3735     {
3736         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_DISPLAY_CTL  ) );
3737         return FALSE;
3738     }
3739 
3740     _eFrcMode = eFrcMode;
3741     if (bDropErrFrm != bDropErr)
3742     {
3743         MVD_DEBUGINFO( printf("bDropErrFrm(%d) != bDropErr(%d)\n", bDropErrFrm, bDropErr));
3744         bDropErrFrm = bDropErr;
3745     }
3746     bDropDispfrm = bDropDisp;
3747 
3748     return TRUE;
3749 }
3750 
3751 
3752 //------------------------------------------------------------------------------
3753 /// Enable/Disable to repeat the last field when repeat for avsync or display pause.
3754 /// E.g. Top field first: T-B-B-B-...; Bottom field first: B-T-T-T-...
3755 /// Usage scenario: scaler framebufferless mode to avoid frame flicker
3756 /// @return -TRUE for success; FALSE for failure.
3757 //------------------------------------------------------------------------------
MDrv_MVD_DispRepeatField(MS_BOOL bEnable)3758 MS_BOOL MDrv_MVD_DispRepeatField(MS_BOOL bEnable)
3759 {
3760     #if (defined(CHIP_T7))
3761     MVD_DEBUGINFO( printf( "This Cmd is bypass in MVD1 <%x>!!\r\n", bEnable  ) );
3762     #else
3763     MVD_CmdArg mvdcmd;
3764 
3765     MVD_FUNC_ENTRY();
3766     SETUP_CMDARG(mvdcmd);
3767     mvdcmd.Arg0 = bEnable;
3768     if (HAL_MVD_MVDCommand( CMD_REPEAT_MODE, &mvdcmd ) == FALSE)
3769     {
3770         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_REPEAT_MODE  ) );
3771         return FALSE;
3772     }
3773     #endif
3774     return TRUE;
3775 }
3776 
3777 //------------------------------------------------------------------------------
3778 /// Get RFF (Repeat First Field) flag.
3779 /// @return -TRUE or FALSE
3780 //------------------------------------------------------------------------------
MDrv_MVD_GetTop1stField(void)3781 MS_BOOL MDrv_MVD_GetTop1stField(void)
3782 {
3783     MVD_FUNC_ENTRY();
3784 
3785     if(pu8MVDGetFrameInfoBufStart==0)
3786     {
3787         MVD_DEBUGERROR(printf("MDrv_MVD_GetTop1stField error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3788         return FALSE;
3789     }
3790 
3791     if (HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_TOP_FF))
3792         return TRUE;
3793     else
3794         return FALSE;
3795 }
3796 
3797 
3798 //------------------------------------------------------------------------------
3799 /// Get RFF (Repeat First Field) flag.
3800 /// @return -TRUE or FALSE
3801 //------------------------------------------------------------------------------
MDrv_MVD_GetRepeat1stField(void)3802 MS_BOOL MDrv_MVD_GetRepeat1stField(void)
3803 {
3804     MVD_FUNC_ENTRY();
3805 
3806     if(pu8MVDGetFrameInfoBufStart==0)
3807     {
3808         MVD_DEBUGERROR(printf("MDrv_MVD_GetRepeat1stField error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3809         return FALSE;
3810     }
3811 
3812     if (HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_REPEAT_FF))
3813         return TRUE;
3814     else
3815         return FALSE;
3816 }
3817 
3818 //------------------------------------------------------------------------------
3819 /// Get tmp ref flag.
3820 /// @return -TRUE or FALSE
3821 //------------------------------------------------------------------------------
MDrv_MVD_GetTmpRefField(void)3822 MS_BOOL MDrv_MVD_GetTmpRefField(void)
3823 {
3824     MVD_FUNC_ENTRY();
3825 
3826     if(pu8MVDGetFrameInfoBufStart==0)
3827     {
3828         MVD_DEBUGERROR(printf("MDrv_MVD_GetTmpRefField error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3829         return FALSE;
3830     }
3831 
3832     if (HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_TMP_REF))
3833         return TRUE;
3834     else
3835         return FALSE;
3836 }
3837 
3838 //------------------------------------------------------------------------------
3839 /// Get color format.
3840 /// @return - value (0~8)
3841 //------------------------------------------------------------------------------
MDrv_MVD_GetColorFormat(void)3842 MS_U8 MDrv_MVD_GetColorFormat(void)
3843 {
3844     MVD_FUNC_ENTRY();
3845 
3846     if(pu8MVDGetFrameInfoBufStart==0)
3847     {
3848         MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3849         return 0xff;
3850     }
3851 
3852     return (HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_VIDEO_FORMAT));
3853 
3854 }
3855 
3856 //------------------------------------------------------------------------------
3857 /// Get matrix coefficients in 13818-2 sequence_display_extension().
3858 /// @return - value (0~255)
3859 //------------------------------------------------------------------------------
MDrv_MVD_GetMatrixCoef(void)3860 MS_U8 MDrv_MVD_GetMatrixCoef(void)
3861 {
3862     MVD_FUNC_ENTRY();
3863 
3864     if(pu8MVDGetFrameInfoBufStart==0)
3865     {
3866         MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3867         return 0xff;
3868     }
3869 
3870     return (HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart + OFFSET_MATRIX_COEF));
3871 
3872 }
3873 
3874 //------------------------------------------------------------------------------
3875 /// Issue Pause command.
3876 //------------------------------------------------------------------------------
MDrv_MVD_Pause(void)3877 void MDrv_MVD_Pause(void)
3878 {
3879     MVD_CmdArg mvdcmd;
3880 
3881     MVD_FUNC_ENTRY();
3882     SETUP_CMDARG(mvdcmd);
3883     mvdcmd.Arg0 = DISPLAY_PAUSE_ON;
3884     if (HAL_MVD_MVDCommand(CMD_DISPLAY_PAUSE, &mvdcmd)== FALSE)
3885     {
3886         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PAUSE) );
3887         return;
3888     }
3889 
3890     HAL_MVD_Delayms(4);
3891 
3892     return;
3893 }
3894 
3895 
3896 //------------------------------------------------------------------------------
3897 /// Issue "Decode Pause" command.
3898 //------------------------------------------------------------------------------
MDrv_MVD_DecodePause(void)3899 void MDrv_MVD_DecodePause(void)
3900 {
3901     MVD_CmdArg mvdcmd;
3902 
3903     MVD_FUNC_ENTRY();
3904     SETUP_CMDARG(mvdcmd);
3905     if (HAL_MVD_MVDCommand(CMD_PAUSE, &mvdcmd)== FALSE)
3906     {
3907         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PAUSE) );
3908         return;
3909     }
3910 
3911     HAL_MVD_Delayms(4);
3912 
3913     return;
3914 }
3915 
3916 
3917 //------------------------------------------------------------------------------
3918 /// Issue Resume command.
3919 //------------------------------------------------------------------------------
MDrv_MVD_Resume(void)3920 void MDrv_MVD_Resume(void)
3921 {
3922     MVD_FUNC_ENTRY();
3923     if (HAL_MVD_Resume() == FALSE)
3924     {
3925         MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
3926     }
3927     return;
3928 }
3929 
3930 
3931 //------------------------------------------------------------------------------
3932 /// Issue Stop command.
3933 //------------------------------------------------------------------------------
MDrv_MVD_Stop(void)3934 static MS_BOOL MDrv_MVD_Stop(void)
3935 {
3936     MVD_CmdArg mvdcmd;
3937 
3938     MVD_FUNC_ENTRY();
3939     SETUP_CMDARG(mvdcmd);
3940     if (HAL_MVD_MVDCommand(CMD_STOP, &mvdcmd)== FALSE)
3941     {
3942         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STOP) );
3943         return FALSE;
3944     }
3945 
3946     return TRUE;
3947 }
3948 
3949 
3950 //-----------------------------------------------------------------------------
3951 /// Is MVD step decode done after step decode command.
3952 /// @return - TRUE/FALSE
3953 /// @retval     -FALSE(0): decoding, or user did not send step decode command.
3954 /// @retval     -TRUE(1): decode done
3955 //-----------------------------------------------------------------------------
MDrv_MVD_IsStepDecodeDone(void)3956 MS_BOOL MDrv_MVD_IsStepDecodeDone(void)
3957 {
3958     MS_BOOL bRet = FALSE;
3959 
3960     MVD_FUNC_ENTRY();
3961 
3962     if (bStepDecode)
3963     {
3964         #if (defined(CHIP_T2))||(defined(CHIP_T7))
3965         MS_U32 u32DecodedFrameCnt = 0;
3966         u32DecodedFrameCnt = MDrv_MVD_GetPicCounter();
3967         if (u32StepDecodeCnt != u32DecodedFrameCnt)
3968         {
3969             u32StepDecodeCnt = u32DecodedFrameCnt;
3970             bStepDecode = FALSE;
3971             bRet = TRUE;
3972         }
3973         #else
3974         if (MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SINGLE_STEP))
3975         {
3976             printf( "MVD_HANDSHAKE_SINGLE_STEP -------: 0x%x \n", MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SINGLE_STEP));
3977             bStepDecode = FALSE;
3978             bRet = TRUE;
3979         }
3980         #endif
3981     }
3982     return bRet;
3983 }
3984 
3985 //------------------------------------------------------------------------------
3986 /// Issue StepPlay command.
3987 /// @return -TRUE for success; FALSE for failure.
3988 //------------------------------------------------------------------------------
MDrv_MVD_StepDecode(void)3989 MS_BOOL MDrv_MVD_StepDecode(void)
3990 {
3991     MVD_CmdArg mvdcmd;
3992 
3993     MVD_FUNC_ENTRY();
3994     SETUP_CMDARG(mvdcmd);
3995     if (HAL_MVD_MVDCommand( CMD_SINGLE_STEP, &mvdcmd ) == FALSE)
3996     {
3997         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SINGLE_STEP ) );
3998         return FALSE;
3999     }
4000 
4001     if (HAL_MVD_Resume() == FALSE)
4002     {
4003         MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
4004         return FALSE;
4005     }
4006     bStepDecode = TRUE;
4007     return TRUE;
4008 }
4009 
4010 //-----------------------------------------------------------------------------
4011 /// Is MVD step display done after step display command.
4012 /// @return - TRUE/FALSE
4013 /// @retval     -FALSE(0): decoding, or user did not send step decode command.
4014 /// @retval     -TRUE(1): decode done
4015 //-----------------------------------------------------------------------------
MDrv_MVD_IsStepDispDone(void)4016 MS_BOOL MDrv_MVD_IsStepDispDone(void)
4017 {
4018     MVD_FUNC_ENTRY();
4019 
4020     if (!bStepDisp)
4021     {
4022         MVD_DEBUGERROR(printf("%s err: hasn't issue StepDisp\n", __FUNCTION__));
4023         return FALSE;
4024     }
4025     if(pu8MVDGetFrameInfoBufStart==0)
4026     {
4027         MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
4028         return FALSE;
4029     }
4030 
4031     return HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_STEP_DISP_DONE);
4032 
4033 }
4034 
4035 //------------------------------------------------------------------------------
4036 /// Issue StepDisplay command.
4037 /// @return -TRUE for success; FALSE for failure.
4038 //------------------------------------------------------------------------------
MDrv_MVD_StepDisp(void)4039 MS_BOOL MDrv_MVD_StepDisp(void)
4040 {
4041     MVD_FUNC_ENTRY();
4042     MDrv_MVD_SetSpeed(E_MVD_SPEED_DEFAULT, 1);
4043     if (HAL_MVD_StepDisp() == FALSE)
4044     {
4045         MVD_DEBUGERROR( printf( "%s fail!!\n", __FUNCTION__ ) );
4046         return FALSE;
4047     }
4048     bStepDisp = TRUE;
4049     return TRUE;
4050 }
4051 
4052 //-----------------------------------------------------------------------------
4053 /// Is MVD step display done after step display command.
4054 /// @return - TRUE/FALSE
4055 /// @retval     -FALSE(0): decoding, or user did not send step decode command.
4056 /// @retval     -TRUE(1): decode done
4057 //-----------------------------------------------------------------------------
MDrv_MVD_IsStep2PtsDone(void)4058 MS_BOOL MDrv_MVD_IsStep2PtsDone(void)
4059 {
4060     MVD_FUNC_ENTRY();
4061 
4062     if (!bStep2Pts)
4063     {
4064         return FALSE;
4065     }
4066 
4067     if(pu8MVDGetFrameInfoBufStart==0)
4068     {
4069         MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
4070         return FALSE;
4071     }
4072 
4073     return HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_STEP_TO_PTS_DONE);
4074 
4075 }
4076 
4077 //------------------------------------------------------------------------------
4078 /// Step to the specific PTS (u32Pts ms)
4079 /// @return -TRUE for success; FALSE for failure.
4080 //------------------------------------------------------------------------------
MDrv_MVD_SeekToPTS(MS_U32 u32Pts)4081 MS_BOOL MDrv_MVD_SeekToPTS(MS_U32 u32Pts)
4082 {
4083     MVD_FUNC_ENTRY();
4084 
4085     MDrv_MVD_SetSpeed(E_MVD_SPEED_DEFAULT, 1);
4086     bStep2Pts = HAL_MVD_SeekToPTS(_MS_TO_90K(u32Pts));
4087     return bStep2Pts;
4088 }
4089 
4090 //------------------------------------------------------------------------------
4091 /// Skip to the specific PTS (u32Pts ms)
4092 /// @return -TRUE for success; FALSE for failure.
4093 //------------------------------------------------------------------------------
MDrv_MVD_SkipToPTS(MS_U32 u32Pts)4094 MS_BOOL MDrv_MVD_SkipToPTS(MS_U32 u32Pts)
4095 {
4096     MVD_FUNC_ENTRY();
4097 
4098     bSkip2Pts = HAL_MVD_SkipToPTS(_MS_TO_90K(u32Pts));
4099     return bSkip2Pts;
4100 }
4101 
4102 //------------------------------------------------------------------------------
4103 /// Issue TrickPlay command.
4104 /// @return -TRUE for success; FALSE for failure.
4105 //------------------------------------------------------------------------------
MDrv_MVD_TrickPlay(MVD_TrickDec trickDec,MS_U8 u8DispDuration)4106 MS_BOOL MDrv_MVD_TrickPlay(MVD_TrickDec trickDec, MS_U8 u8DispDuration)
4107 {
4108     MVD_CmdArg mvdcmd;
4109     MS_U8 u8DecType;
4110     MVD_FUNC_ENTRY();
4111 
4112     switch (trickDec)
4113     {
4114         case E_MVD_TRICK_DEC_ALL:
4115             u8DecType = 0;
4116             break;
4117         case E_MVD_TRICK_DEC_I:
4118             u8DecType = 1;
4119             break;
4120         case E_MVD_TRICK_DEC_IP:
4121             u8DecType = 2;
4122             break;
4123         default:
4124             return FALSE;
4125             break;
4126     }
4127 
4128     SETUP_CMDARG(mvdcmd);
4129     mvdcmd.Arg0 = u8DecType;
4130     mvdcmd.Arg1 = u8DispDuration;
4131     eTrickMode = trickDec;    //for MDrv_MVD_GetTrickMode
4132 
4133     if (HAL_MVD_MVDCommand(CMD_FAST_SLOW, &mvdcmd) == FALSE)
4134     {
4135         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FAST_SLOW) );
4136         return FALSE;
4137     }
4138     MDrv_MVD_SetAVSync(FALSE, 0);
4139     return TRUE;
4140 }
4141 
4142 
4143 //------------------------------------------------------------------------------
4144 /// Get the trick mode which has been set.
4145 /// @return MVD_TrickDec
4146 //------------------------------------------------------------------------------
MDrv_MVD_GetTrickMode(void)4147 MVD_TrickDec MDrv_MVD_GetTrickMode(void)
4148 {
4149     return eTrickMode;
4150 }
4151 
4152 
4153 //------------------------------------------------------------------------------
4154 /// Flush display buffer.
4155 /// @return -TRUE for success; FALSE for failure.
4156 //------------------------------------------------------------------------------
MDrv_MVD_FlushDisplayBuf(void)4157 MS_BOOL MDrv_MVD_FlushDisplayBuf(void)
4158 {
4159     MVD_CmdArg mvdcmd;
4160 
4161     MVD_FUNC_ENTRY();
4162     SETUP_CMDARG(mvdcmd);
4163     if (HAL_MVD_MVDCommand(CMD_FLUSH_DISP_QUEUE, &mvdcmd) == FALSE)
4164     {
4165         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FLUSH_LAST_IPFRAME) );
4166         return FALSE;
4167     }
4168     return TRUE;
4169 }
4170 
4171 
4172 //------------------------------------------------------------------------------
4173 /// Get capabilities of MPEG Video Decoder.
4174 /// @return -TRUE for success; FALSE for failure.
4175 //------------------------------------------------------------------------------
MDrv_MVD_GetCaps(MVD_Caps * pCaps)4176 MS_BOOL MDrv_MVD_GetCaps(MVD_Caps* pCaps)
4177 {
4178     MS_U8 caps = HAL_MVD_GetCaps();
4179     if (!pCaps)
4180         return FALSE;
4181 
4182     pCaps->bMPEG2 = ((caps & MVD_SUPPORT_MPEG2) == MVD_SUPPORT_MPEG2);
4183     pCaps->bMPEG4 = ((caps & MVD_SUPPORT_MPEG4) == MVD_SUPPORT_MPEG4);
4184     pCaps->bVC1   = ((caps & MVD_SUPPORT_VC1) == MVD_SUPPORT_VC1);
4185 
4186     //printf("MP2=%d, MP4=%d, VC1=%d\n", pCaps->bMPEG2, pCaps->bMPEG4, pCaps->bVC1);
4187     return TRUE;
4188 }
4189 
4190 
4191 //------------------------------------------------------------------------------
4192 /// Get if MVD decoder is playing.
4193 /// @return TRUE or FALSE
4194 ///     - TRUE, Yes
4195 ///     - FALSE, No
4196 //------------------------------------------------------------------------------
MDrv_MVD_IsPlaying(void)4197 MS_BOOL MDrv_MVD_IsPlaying(void)
4198 {
4199     MS_BOOL bIsPlaying = FALSE;
4200     bIsPlaying = ( MDrv_MVD_GetDecodeStatus() == E_MVD_STAT_WAIT_DECODEDONE );
4201 
4202     return bIsPlaying;
4203 }
4204 
4205 //------------------------------------------------------------------------------
4206 /// Get if MVD decoder is in idle state.
4207 /// @return TRUE or FALSE
4208 ///     - TRUE, Yes
4209 ///     - FALSE, No
4210 //------------------------------------------------------------------------------
MDrv_MVD_IsIdle(void)4211 MS_BOOL MDrv_MVD_IsIdle(void)
4212 {
4213     return (MDrv_MVD_GetDecodeStatus() == E_MVD_STAT_IDLE);
4214 }
4215 
4216 
4217 ////////////////////////////////////////////////////////////////////////////////
4218 //  FIXME::  Below functions are under construction.
4219 ////////////////////////////////////////////////////////////////////////////////
4220 //------------------------------------------------------------------------------
4221 /// Enable/Disable error concealment function
4222 /// @param -bDisable \b IN : enable/disable this function
4223 /// @return -return E_MVD_Result success/fail to enable/disable
4224 //------------------------------------------------------------------------------
MDrv_MVD_DisableErrConceal(MS_BOOL bDisable)4225 E_MVD_Result MDrv_MVD_DisableErrConceal(MS_BOOL bDisable)
4226 {
4227     return E_MVD_RET_FAIL;
4228 }
4229 
4230 //------------------------------------------------------------------------------
4231 /// Push queue.
4232 /// @param -u32StAddr \b IN : the start address of the queue
4233 /// @param -u32Size \b IN : the data size to be pushed
4234 /// @param -u32TimeStamp \b IN : the corresponding PTS
4235 /// @return -return E_MVD_Result success/fail to push queue
4236 //------------------------------------------------------------------------------
MDrv_MVD_PushQueue(MVD_PacketInfo * pInfo)4237 E_MVD_Result MDrv_MVD_PushQueue(MVD_PacketInfo* pInfo)
4238 {
4239     E_MVD_Result eRet=E_MVD_RET_INVALID_PARAM;
4240 
4241     //check input parameters
4242     if (pInfo == NULL)
4243     {
4244         MVD_DEBUGERROR(printf("PushQueue NULL pInfo\n"));
4245         return E_MVD_RET_INVALID_PARAM;
4246     }
4247 
4248 #if _SLQTBL_DUMP_PUSHQ
4249 {
4250     static MS_U32 u32pqTimes = 0;
4251 
4252     printf("Push[%lx] st=0x%lx len=0x%lx pts=0x%lx\n", u32pqTimes++,
4253             pInfo->u32StAddr, pInfo->u32Length, pInfo->u32TimeStamp);
4254 }
4255 #endif
4256     MVD_FUNC_ENTRY();
4257     #if SLQ_NEW_PUSH
4258     if((pInfo->u32StAddr & SLQ_PIC_START_FLAG) == SLQ_PIC_START_FLAG)
4259     {
4260         pInfo->u32StAddr = pInfo->u32StAddr&~SLQ_PIC_START_FLAG;
4261         _SlqStatus.bSlqPicStart =TRUE;
4262         _SlqStatus.bSlqCtrlBit = TRUE;
4263     }
4264     else
4265     {
4266         _SlqStatus.bSlqPicStart = FALSE;
4267     }
4268 #endif
4269     //check input parameters
4270     if (pInfo == NULL)
4271     {
4272         MVD_DEBUGERROR(printf("PushQueue NULL pInfo\n"));
4273         return E_MVD_RET_INVALID_PARAM;
4274     }
4275 #if 0
4276     else if ((pInfo->u32TimeStamp!= 0) && (pInfo->u32Length==0))
4277     {
4278         printf("PushQueue invalid pInfo pts=0x%lx\n", pInfo->u32TimeStamp);
4279         eRet=E_MVD_RET_INVALID_PARAM;
4280     }
4281 #endif
4282     else if (pInfo->u32StAddr >= stMemCfg.u32BSSize)
4283     {
4284         //since u32StAddr is offset, it shouldn't be larger than size.
4285         MVD_DEBUGERROR(printf("PushQueue invalid u32StAddr=0x%lx, bsSize=0x%lx\n", pInfo->u32StAddr, stMemCfg.u32BSSize));
4286         return E_MVD_RET_INVALID_PARAM;
4287     }
4288     else if ((pInfo->u32TimeStamp == MVD_NULLPKT_PTS) && (pInfo->u32Length==0))
4289     {
4290         // AVI NULL packet.
4291         u32DummyPktCnt++;
4292         //printf("Pos:0x%x%08x; PTS:%08d; NullPKT:%d\n", pInfo->u32ID_H, pInfo->u32ID_L, pInfo->u32TimeStamp, u32DummyPktCnt);
4293         return E_MVD_RET_OK;
4294     }
4295 
4296     if (FALSE == MDrv_MVD_IsMStreamerMode())
4297     {   //Check repeat PTS for non-MStreamer mode.
4298         //printf(".Pos:0x%x%08x; PTS:%08d; NullPKT:%d\n", pInfo->u32ID_H, pInfo->u32ID_L, pInfo->u32TimeStamp, u32DummyPktCnt);
4299         if (pInfo->u32TimeStamp == u32LastPts)
4300         {
4301             //printf("Repeat PTS!\n");
4302             if (pInfo->u32TimeStamp != MVD_NULLPKT_PTS)
4303                 pInfo->u32TimeStamp = MVD_NULLPKT_PTS; //repeat PTS
4304         }
4305         else
4306         {
4307             u32LastPts = pInfo->u32TimeStamp;
4308         }
4309     }
4310 
4311     //check queue vacancy
4312     if (_drvSlqTbl.u32Empty >= SLQ_TBL_SAFERANGE)
4313     {   //put packets
4314 #if SLQ_NEW_PUSH
4315         if (E_MVD_CODEC_DIVX311 == curCodecType
4316             ||E_MVD_CODEC_VC1_MAIN == curCodecType //rcv
4317             ||E_MVD_CODEC_VC1_ADV == curCodecType)
4318         {
4319             MVD_PacketInfo stHdr;
4320             if((_SlqStatus.bSlqCtrlBit) || (E_MVD_CODEC_DIVX311 == curCodecType))
4321             {
4322                 MVD_SLQTblGetHdrPkt(&stHdr, pInfo);
4323 
4324                 if(_SlqStatus.bSlqPicStart||(!_SlqStatus.bSlqCtrlBit))
4325                 {
4326                     if (MDrv_MVD_IsMStreamerMode())
4327                     {   //to mark this packet's pts as unused.
4328                         stHdr.u32TimeStamp = MVD_NULLPKT_PTS;
4329                         stHdr.u32ID_H = MVD_NULLPKT_PTS;
4330                     }
4331                     MVD_SLQTblSendPacket(&stHdr);
4332                 }
4333             }
4334         }
4335 #else
4336         if (E_MVD_CODEC_DIVX311 == curCodecType)
4337         {
4338             MVD_PacketInfo stDivxHdr;
4339             MVD_SLQTblGetDivxHdrPkt(&stDivxHdr, pInfo);
4340             if (MDrv_MVD_IsMStreamerMode())
4341             {   //to mark this packet's pts as unused.
4342                 stDivxHdr.u32TimeStamp = MVD_NULLPKT_PTS;
4343                 stDivxHdr.u32ID_H = MVD_NULLPKT_PTS;
4344             }
4345             MVD_SLQTblSendPacket(&stDivxHdr);
4346         }
4347 #endif
4348         MVD_SLQTblSendPacket(pInfo);
4349         eRet=E_MVD_RET_OK;
4350         bSlqTblHasValidData = TRUE;
4351     }
4352     else
4353     {
4354         MS_ASSERT(0); //shouldn't be here!
4355         MVD_DEBUGERROR(printf("PushQueue FULL!!! empty=0x%lx\n", _drvSlqTbl.u32Empty));
4356         //Player will only push queue when queue vacancy != 0
4357         eRet=E_MVD_RET_QUEUE_FULL;
4358     }
4359 
4360     if (E_MVD_RET_OK != eRet)
4361     {
4362         MVD_DEBUGERROR(printf("%s ret = %d\n", __FUNCTION__, eRet));
4363     }
4364     return eRet;
4365 }
4366 
4367 
MVD_FlushTSQueue(void)4368 static E_MVD_Result MVD_FlushTSQueue(void)
4369 {
4370     MS_U32 u32TimeOut = 10;
4371     static MS_BOOL bSetSkip = FALSE;
4372 
4373     if (MDrv_MVD_GetLastCmd()!=CMD_PAUSE)
4374     {
4375         MDrv_MVD_Pause();
4376         MDrv_MVD_DecodePause();
4377         MDrv_MVD_FlushDisplayBuf();
4378     }
4379     if (!bSetSkip)
4380     {
4381         MDrv_MVD_SkipData();
4382         bSetSkip = TRUE;
4383     }
4384 
4385     while (u32TimeOut>0)
4386     {
4387         HAL_MVD_Delayms(5);
4388 
4389         if ( (MDrv_MVD_GetDecodeStatus()==E_MVD_STAT_FIND_SPECIALCODE)
4390               && (MDrv_MVD_GetLastCmd()==CMD_PAUSE) )
4391         {
4392             break;
4393         }
4394         else if (MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SKIP_DATA))
4395         {
4396             break;
4397         }
4398 
4399         u32TimeOut--;
4400     }
4401 
4402     if (u32TimeOut==0)
4403     {
4404         MVD_DEBUGVERBAL(printf("\n***** MVD_FlushTSQueue TS flush TIMEOUT!!! *****\n\n"));
4405         return E_MVD_RET_FAIL;
4406     }
4407 
4408     bSetSkip = FALSE;
4409     return E_MVD_RET_OK;
4410 }
4411 
4412 //------------------------------------------------------------------------------
4413 /// Flush PVR queue: flush ES buffer, reset SLQ TABLE, flush decoded frame, and
4414 ///              keep the display frame.
4415 /// @return -return E_MVD_Result success/fail to flush queue
4416 //------------------------------------------------------------------------------
MDrv_MVD_PVRFlushDispQueue(MS_BOOL bEnable)4417 E_MVD_Result MDrv_MVD_PVRFlushDispQueue(MS_BOOL bEnable)
4418 {
4419     E_MVD_Result eRet = E_MVD_RET_OK;
4420     MVD_FUNC_ENTRY();
4421 
4422 
4423     if(!bEnable)
4424     {
4425         return E_MVD_RET_FAIL;
4426     }
4427     if (MDrv_MVD_GetDecodeStatus() == E_MVD_STAT_IDLE)
4428     {
4429         return eRet;
4430     }
4431 
4432     //flush Frame buffer only
4433     if (MDrv_MVD_GetLastCmd()!=CMD_PAUSE)
4434     {
4435         MDrv_MVD_Pause();
4436         MDrv_MVD_DecodePause();
4437         MDrv_MVD_FlushDisplayBuf();
4438     }
4439     else
4440     {
4441         MDrv_MVD_FlushDisplayBuf();
4442     }
4443 
4444     MVD_RstFrmInfo(E_MVD_FRMINFO_DECODE);
4445 
4446     if (TRUE == MDrv_MVD_SkipToIFrame())
4447     {
4448        return E_MVD_RET_OK;
4449     }
4450     else
4451     {
4452         return E_MVD_RET_FAIL;
4453     }
4454 }
4455 
MVD_PatternLenIsValid(MS_U32 u32Len)4456 static MS_BOOL MVD_PatternLenIsValid(MS_U32 u32Len)
4457 {
4458 
4459     MS_U32 u32ValidLen = 0;
4460 #define MAX_VALIDLEN    0x200000    //2M
4461 
4462     if (E_MVD_CODEC_VC1_MAIN != curCodecType)
4463     {
4464         return TRUE;
4465     }
4466     else
4467     {
4468         //only RCV has to check this
4469         u32ValidLen = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_RCV_PAYLOAD_LENGTH);
4470         if (u32ValidLen > MAX_VALIDLEN)
4471         {   //avoid the extreme large value due to error bitstream
4472             u32ValidLen = MAX_VALIDLEN;
4473         }
4474         MVD_DEBUGVERBAL(printf("(%x) ValidLen=0x%lx CurLen=0x%lx\n",
4475                        (u32Len > u32ValidLen), u32ValidLen, u32Len));
4476         return (u32Len > u32ValidLen);
4477     }
4478 }
4479 
4480 
MVD_FlushSlqTblQueue(void)4481 static E_MVD_Result MVD_FlushSlqTblQueue(void)
4482 {
4483     MS_U32 u32TimeCnt, u32TimeOut;
4484     MS_U32 u32PatternByteCnt = 0;
4485 
4486     MDrv_MVD_Pause();
4487     MDrv_MVD_DecodePause();
4488     MDrv_MVD_FlushDisplayBuf();
4489 
4490     u32TimeCnt = HAL_MVD_GetTime();
4491     while (((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS) ||
4492            (TRUE != MVD_PatternLenIsValid(u32PatternByteCnt)))
4493     {
4494         if (MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_PAUSE))
4495         {
4496             MVD_DEBUGVERBAL(printf("\nPause finished!\n"));
4497             MDrv_MVD_FlushDisplayBuf();
4498             break;
4499         }
4500 
4501         if (_drvSlqTbl.u32Empty < SLQ_TBL_SAFERANGE)
4502         {
4503             MDrv_MVD_GetQueueVacancy(FALSE); //update _drvSlqTbl.u32Empty
4504             HAL_MVD_Delayms(1); //avoid busy query
4505         }
4506         //insert dummy pattern
4507         if (TRUE == MVD_SLQTblInsertPattern(E_MVD_PATTERN_FLUSH))
4508         {
4509             u32PatternByteCnt += DUMMY_SIZE*2; //2 dummy were inserted
4510         }
4511     }
4512     MVD_DEBUGVERBAL(printf("====> %s (t1=%lu t2=%lu diff=%lu)\n", __FUNCTION__,
4513             u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
4514     //if ((HAL_MVD_GetTime() - u32TimeCnt) >= CMD_TIMEOUT_MS)
4515     if (TRUE != MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_PAUSE))
4516     {
4517         MVD_DEBUGERROR(printf("\n***** MDrv_MVD_FlushQueue PAUSE TIMEOUT!!! *****\n\n"));
4518         MVD_DEBUGERROR(printf("ValidLen=0x%lx CurPatternLen=0x%lx\n",
4519                       HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+92), u32PatternByteCnt));
4520 
4521         return E_MVD_RET_FAIL;
4522     }
4523 
4524     //flush ES buffer & reset SLQ tbl
4525     if (HAL_MVD_SlqTblRst() == TRUE)
4526     {
4527         //return E_MVD_RET_OK;
4528     }
4529 
4530     u32TimeOut = 10;
4531     while (u32TimeOut>0)
4532     {
4533         if (MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SLQ_RST))
4534         {
4535             //printf("\nSlqRst finished! x=0x%lx\n", x);
4536             break;
4537         }
4538         u32TimeOut--;
4539         HAL_MVD_Delayms(10);
4540     }
4541     //printf("\n\n=====> SlqRst u32TimeOut =%lx\n", u32TimeOut);
4542     if (u32TimeOut==0)
4543     {
4544         MVD_DEBUGERROR(printf("\n***** MDrv_MVD_FlushQueue SlqRst TIMEOUT!!! *****\n\n"));
4545         return E_MVD_RET_FAIL;
4546     }
4547 
4548     MVD_SLQTblInit(); //reset related buffers
4549 
4550     return E_MVD_RET_OK;
4551 }
4552 
4553 
4554 //------------------------------------------------------------------------------
4555 /// Flush PTS buffer.
4556 /// @return -TRUE for success; FALSE for failure.
4557 //------------------------------------------------------------------------------
MDrv_MVD_FlushPTSBuf(void)4558 MS_BOOL MDrv_MVD_FlushPTSBuf(void)
4559 {
4560     MVD_CmdArg mvdcmd;
4561 
4562     MVD_FUNC_ENTRY();
4563     SETUP_CMDARG(mvdcmd);
4564     mvdcmd.Arg0 = 1;
4565     if (HAL_MVD_MVDCommand(CMD_SEND_UNI_PTS, &mvdcmd) == FALSE)
4566     {
4567         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SEND_UNI_PTS) );
4568         return FALSE;
4569     }
4570     return TRUE;
4571 }
4572 
4573 //------------------------------------------------------------------------------
4574 /// Flush queue: flush ES buffer, reset SLQ TABLE, flush decoded frame, and
4575 ///              keep the display frame.
4576 /// @return -return E_MVD_Result success/fail to flush queue
4577 //------------------------------------------------------------------------------
MDrv_MVD_FlushQueue(void)4578 E_MVD_Result MDrv_MVD_FlushQueue(void)
4579 {
4580     E_MVD_Result eRet = E_MVD_RET_OK;
4581 
4582     MVD_FUNC_ENTRY();
4583 
4584     if (MDrv_MVD_GetDecodeStatus() == E_MVD_STAT_IDLE)
4585     {
4586         return eRet;
4587     }
4588 
4589     //flush ES buffer (and cmd queue if used)
4590     if (E_MVD_SLQ_TBL_MODE == curSrcMode)
4591     {
4592         eRet = MVD_FlushSlqTblQueue();
4593     }
4594     else if (E_MVD_TS_FILE_MODE == curSrcMode)
4595     {
4596         eRet = MVD_FlushTSQueue();
4597     }
4598     if (E_MVD_RET_OK != eRet)
4599     {
4600         return eRet;
4601     }
4602 
4603     MVD_RstFrmInfo(E_MVD_FRMINFO_DECODE);
4604     //flush display buffer
4605     if (MDrv_MVD_FlushDisplayBuf() != TRUE)
4606     {
4607         return E_MVD_RET_FAIL;
4608     }
4609 
4610     if (TRUE == MDrv_MVD_SkipToIFrame())
4611     {
4612         return E_MVD_RET_OK;
4613     }
4614     else
4615     {
4616         return E_MVD_RET_FAIL;
4617     }
4618 }
4619 
MVD_Map2DrvSlqTbl(MS_U32 u32HWPtr)4620 static MS_U32 MVD_Map2DrvSlqTbl(MS_U32 u32HWPtr)
4621 {
4622     MS_U32 u32HWSt = MVD_GetMemOffset(stMemCfg.u32BSAddr);
4623     MS_U32 u32DrvPtr;
4624 
4625     if ((u32HWPtr<u32HWSt) && (u32HWPtr!=0))
4626     {
4627         MVD_DEBUGERROR(printf("Invalid u32HWPtr=0x%lx\n", u32HWPtr));
4628         return 0;
4629     }
4630     if ((bSlqTblSync) && (u32HWPtr!=0))
4631     {
4632         u32DrvPtr = _drvSlqTbl.u32StAdd + (u32HWPtr - u32HWSt);
4633         return u32DrvPtr;
4634     }
4635     return u32HWPtr;
4636 }
4637 
4638 
4639 //------------------------------------------------------------------------------
4640 /// Get the queue vacancy (unit in slq entry).
4641 /// @param -pQueueVacancy \b IN : pointer to the queue vacancy
4642 /// @return -return E_MVD_Result success/fail to get the queue vacancy
4643 //------------------------------------------------------------------------------
MDrv_MVD_GetQueueVacancy(MS_BOOL bCached)4644 MS_U32 MDrv_MVD_GetQueueVacancy(MS_BOOL bCached)
4645 {
4646     MS_U32 u32Empty;
4647 
4648 #if 0
4649     if (MDrv_MVD_GetVldErrCount()!=0)
4650     {
4651         printf("QQQ wPtr= 0x%lx(0x%lx) rPtr=0x%lx(0x%lx) vldErr=0x%lx\n", writePtrLast, _drvSlqTbl.u32WrPtr,
4652         MDrv_MVD_GetSLQReadPtr(), _drvSlqTbl.u32RdPtr, MDrv_MVD_GetVldErrCount());
4653         printf("Previous EsRead=0x%lx EsWrite=0x%lx\n", u32PreEsRd, u32PreEsWr);
4654         _SLQTbl_DumpPtsTbl(0x0, 0x620);
4655         while(1);
4656     }
4657 #endif
4658 
4659     u32Empty = _drvSlqTbl.u32Empty;
4660     if ((TRUE == bCached) && (u32Empty > SLQTBL_CHECKVACANCY_WATERLEVEL))
4661     {
4662         //To have better performance, we only query F/W read pointer
4663         //when queue_vacancy is lower than water_level
4664         u32Empty -= SLQ_TBL_SAFERANGE;
4665         return (u32Empty / SLQ_ENTRY_LEN);
4666     }
4667 
4668     _drvSlqTbl.u32RdPtr = MVD_Map2DrvSlqTbl(MDrv_MVD_GetSLQReadPtr());
4669     //printf("QV=0x%lx rd=0x%lx==>", u32Empty, _drvSlqTbl.u32RdPtr);
4670     if (_drvSlqTbl.u32RdPtr >= (_drvSlqTbl.u32StAdd+SLQ_ENTRY_LEN))
4671     {
4672         if (_drvSlqTbl.u32RdPtr >= _drvSlqTbl.u32EndAdd)
4673         {
4674             MVD_DEBUGERROR(printf("%s: readPtr 0x%lx out of range: too large!\n",
4675                            __FUNCTION__, _drvSlqTbl.u32RdPtr));
4676         }
4677         _drvSlqTbl.u32RdPtr -= SLQ_ENTRY_LEN;
4678     }
4679     else if (_drvSlqTbl.u32RdPtr == _drvSlqTbl.u32StAdd)
4680     {
4681         _drvSlqTbl.u32RdPtr = _drvSlqTbl.u32EndAdd - SLQ_ENTRY_LEN;
4682     }
4683     else
4684     {
4685         MVD_DEBUGERROR(printf("%s: readPtr 0x%lx out of range: too small!\n",
4686                        __FUNCTION__, _drvSlqTbl.u32RdPtr));
4687         _drvSlqTbl.u32RdPtr = _drvSlqTbl.u32StAdd;
4688     }
4689     //printf("0x%lx\n", _drvSlqTbl.u32RdPtr);
4690 
4691     if (_drvSlqTbl.u32WrPtr > _drvSlqTbl.u32RdPtr)
4692     {
4693         u32Empty = SLQ_TBL_SIZE - (_drvSlqTbl.u32WrPtr - _drvSlqTbl.u32RdPtr);
4694     }
4695     else
4696     {
4697         u32Empty = _drvSlqTbl.u32RdPtr - _drvSlqTbl.u32WrPtr;
4698     }
4699 
4700     if (u32Empty == 0)// && (_drvSlqTbl.u32WrPtr == _drvSlqTbl.u32StAdd))
4701     {
4702         u32Empty = SLQ_TBL_SIZE;
4703     }
4704 
4705     _drvSlqTbl.u32Empty = u32Empty;
4706 
4707     if (u32Empty < SLQ_TBL_SAFERANGE)
4708     {//to avoid write_pointer catch up to read_pointer
4709         u32Empty= 0;
4710     }
4711     else
4712     {
4713         u32Empty -= SLQ_TBL_SAFERANGE;
4714     }
4715 
4716     //printf("%s r=0x%lx w=0x%lx u32Empty=0x%lx\n", __FUNCTION__,
4717     //        _drvSlqTbl.u32RdPtr, _drvSlqTbl.u32WrPtr, u32Empty);
4718     return (u32Empty / SLQ_ENTRY_LEN);
4719 }
4720 
4721 
4722 #define _IsNotInStreamBuff(x)                                       \
4723         (((x) < stMemCfg.u32DrvBufSize) ||   \
4724          ((x) > stMemCfg.u32BSSize) )
4725 
4726 //------------------------------------------------------------------------------
4727 /// Get read pointer in ElementaryStream buffer for SLQ table mode
4728 /// @return -the read pointer
4729 //------------------------------------------------------------------------------
MVD_GetSlqTblESReadPtr(void)4730 static MS_U32 MVD_GetSlqTblESReadPtr(void)
4731 {
4732     MS_U32 u32Idx;
4733     MS_U32 u32SlqRp = 0, u32SlqRp1 = 0;//_drvSlqTbl.u32RdPtr;
4734     MS_U32 u32EsRp;
4735     MS_U32 u32EsStart;
4736 
4737     u32SlqRp1 = MDrv_MVD_GetSLQReadPtr();
4738 
4739     if (u32SlqRp1 == 0)
4740     {
4741         return MVD_U32_MAX;
4742     }
4743     else
4744     {
4745         u32SlqRp = MVD_Map2DrvSlqTbl(u32SlqRp1);
4746     }
4747 
4748     //report (readPtr-1) for HW may still use (readPtr)
4749     if (u32SlqRp > (_drvSlqTbl.u32StAdd))
4750     {
4751         u32Idx = ((u32SlqRp - _drvSlqTbl.u32StAdd)/SLQ_ENTRY_LEN) - 1;
4752     }
4753     else
4754     {
4755         u32Idx = SLQ_ENTRY_MAX - 1;
4756     }
4757     u32EsRp = _drvEsTbl.u32StAdd + u32Idx*8;
4758 
4759     u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
4760 #if 0
4761     MS_U32 u32EsEnd;
4762     u32EsEnd = HAL_MVD_MemRead4Byte(u32EsRp+4);
4763     printf("GetESReadPtr ES[%lx] Start=0x%lx End=0x%lx u32EsRp=%lx u32SlqRp=%lx\n",
4764             u32Idx, HAL_MVD_MemRead4Byte(u32EsRp), u32EsEnd, u32EsRp, u32SlqRp);
4765 #endif
4766 
4767     if ((_IsNotInStreamBuff(u32EsStart)) && (u32EsStart != 0))
4768     {   //ESRead is not in BS buffer, so this entry is a divx or dummy pattern.
4769         //Report the last ESRead, instead of this one.
4770         MVD_DEBUGINFO(printf("0x%lx Not in BS, report u32PreEsRd=0x%lx\n", u32EsStart, u32PreEsRd));
4771         return u32PreEsRd;
4772     }
4773     u32PreEsRd = u32EsStart;
4774 
4775     return u32EsStart;
4776 }
4777 
4778 //------------------------------------------------------------------------------
4779 /// Get write pointer in ElementaryStream buffer for SLQ table mode
4780 /// @return -the read pointer
4781 //------------------------------------------------------------------------------
MVD_GetSlqTblESWritePtr(void)4782 static MS_U32 MVD_GetSlqTblESWritePtr(void)
4783 {
4784     MS_U32 u32EsWp;
4785     MS_U32 u32EsEnd;
4786     MS_U32 u32Idx;
4787 
4788     if (_drvSlqTbl.u32WrPtr > (_drvSlqTbl.u32StAdd))
4789     {
4790         u32Idx = ((_drvSlqTbl.u32WrPtr - _drvSlqTbl.u32StAdd)/SLQ_ENTRY_LEN) - 1;
4791     }
4792     else
4793     {
4794         u32Idx = SLQ_ENTRY_MAX - 1;
4795     }
4796     u32EsWp = _drvEsTbl.u32StAdd + u32Idx*8;
4797 
4798     u32EsEnd = HAL_MVD_MemRead4Byte(u32EsWp+4);
4799 #if 0
4800     printf("GetESWritePtr[%lx] ES Start=0x%lx End=0x%lx u32EsWp=%lx\n",
4801         (u32EsWp - _drvEsTbl.u32StAdd)/8,
4802         HAL_MVD_MemRead4Byte(u32EsWp), u32EsEnd, u32EsWp);
4803 #endif
4804 
4805     if ((_IsNotInStreamBuff(u32EsEnd)) && (u32EsEnd != 0))
4806     {   //ESRead is not in BS buffer, so this entry is a divx pattern.
4807         //Report the last ESRead, instead of this one.
4808         MVD_DEBUGINFO(printf("0x%lx Not in BS, report u32PreEsWr=0x%lx\n", u32EsEnd, u32PreEsWr));
4809         return u32PreEsWr;
4810     }
4811     u32PreEsWr = u32EsEnd;
4812 
4813     return u32EsEnd;
4814 }
4815 
4816 //------------------------------------------------------------------------------
4817 /// Get ES read address for TS file mode.
4818 /// @return ES read address
4819 //------------------------------------------------------------------------------
MVD_GetTsFileESReadPtr(void)4820 static MS_U32 MVD_GetTsFileESReadPtr(void)
4821 {
4822     MS_U32 u32Add = 0;
4823     MVD_CmdArg mvdcmd;
4824 
4825     SETUP_CMDARG(mvdcmd);
4826     mvdcmd.Arg0 = 2;    //ES diff
4827     if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
4828     {
4829         //in order to latch the newest parser status
4830         //u32Diff = (((MS_U32)mvdcmd.Arg3) <<24) | (((MS_U32)mvdcmd.Arg2) <<16) |
4831         //          (((MS_U32)mvdcmd.Arg1) << 8) | (((MS_U32)mvdcmd.Arg0));
4832     }
4833     else
4834     {
4835         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
4836     }
4837 
4838     SETUP_CMDARG(mvdcmd);
4839     mvdcmd.Arg0 = 1;
4840     if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
4841     {
4842         u32Add = (((MS_U32)mvdcmd.Arg3) <<24) |
4843                  (((MS_U32)mvdcmd.Arg2) <<16) |
4844                  (((MS_U32)mvdcmd.Arg1) << 8) |
4845                  (((MS_U32)mvdcmd.Arg0));
4846     }
4847     else
4848     {
4849         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
4850     }
4851 
4852     return (u32Add*8);
4853 
4854 }
4855 
4856 //------------------------------------------------------------------------------
4857 /// Get ES write address for TS file mode.
4858 /// @return ES write address
4859 //------------------------------------------------------------------------------
MVD_GetTsFileESWritePtr(void)4860 static MS_U32 MVD_GetTsFileESWritePtr(void)
4861 {
4862     MS_U32 u32Diff = 0;
4863     MS_U32 u32WrPtr = 0;
4864     MVD_CmdArg mvdcmd;
4865 
4866     SETUP_CMDARG(mvdcmd);
4867     mvdcmd.Arg0 = 2;    //ES diff
4868     if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
4869     {
4870         u32Diff = (((MS_U32)mvdcmd.Arg3) <<24) | (((MS_U32)mvdcmd.Arg2) <<16) |
4871                   (((MS_U32)mvdcmd.Arg1) << 8) | (((MS_U32)mvdcmd.Arg0));
4872     }
4873     else
4874     {
4875         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
4876     }
4877 
4878     u32WrPtr = u32Diff*8 + MVD_GetTsFileESReadPtr();
4879     if (u32WrPtr > u32ESBuffEnd)
4880     {
4881         MVD_DEBUGVERBAL(printf("ES wrapping Wr=0x%lx ==> ", u32WrPtr));
4882         u32WrPtr -= stMemCfg.u32BSSize;
4883         MVD_DEBUGVERBAL(printf("0x%lx\n", u32WrPtr));
4884     }
4885     return u32WrPtr;
4886 
4887 }
4888 
4889 //------------------------------------------------------------------------------
4890 /// Get read pointer in ElementaryStream buffer
4891 /// @return -the read pointer
4892 //------------------------------------------------------------------------------
MDrv_MVD_GetESReadPtr(void)4893 MS_U32 MDrv_MVD_GetESReadPtr(void)
4894 {
4895     MS_U32 u32ESR = 0;
4896     if (E_MVD_SLQ_TBL_MODE == curSrcMode)
4897     {
4898         u32ESR = MVD_GetSlqTblESReadPtr();
4899     }
4900     else if (E_MVD_TS_FILE_MODE == curSrcMode || E_MVD_TS_MODE == curSrcMode)
4901     {
4902         u32ESR = MVD_GetTsFileESReadPtr();
4903     }
4904     return u32ESR;
4905 }
4906 
4907 
4908 //------------------------------------------------------------------------------
4909 /// Get write pointer in ElementaryStream buffer
4910 /// @return -the read pointer
4911 //------------------------------------------------------------------------------
MDrv_MVD_GetESWritePtr(void)4912 MS_U32 MDrv_MVD_GetESWritePtr(void)
4913 {
4914     MS_U32 u32ESW = 0;
4915     if (E_MVD_SLQ_TBL_MODE == curSrcMode)
4916     {
4917         u32ESW = MVD_GetSlqTblESWritePtr();
4918     }
4919     else if (E_MVD_TS_FILE_MODE == curSrcMode || E_MVD_TS_MODE == curSrcMode)
4920     {
4921         u32ESW = MVD_GetTsFileESWritePtr();
4922     }
4923     return u32ESW;
4924 }
4925 
4926 
4927 //------------------------------------------------------------------------------
4928 /// Enable/Disable driver to show the last frame
4929 /// @param -bEnable \b IN : enable/disable this function
4930 /// @return -return E_MVD_Result success/fail to enable/disable
4931 //------------------------------------------------------------------------------
MDrv_MVD_EnableLastFrameShow(MS_BOOL bEnable)4932 E_MVD_Result MDrv_MVD_EnableLastFrameShow(MS_BOOL bEnable)
4933 {
4934     MVD_FUNC_ENTRY();
4935 
4936     if (E_MVD_SLQ_TBL_MODE == curSrcMode)
4937     {
4938     #if SLQ_NEW_PUSH
4939         if(_SlqStatus.bSlqCtrlBit)
4940         {
4941             _drvSlqTbl.u32WrPtr = _SlqStatus.u32VaildWptrAddr + SLQ_ENTRY_LEN;
4942         }
4943     #endif
4944 
4945     #if UPDATE_NEXT_WRPTR
4946         u32FileEndPtr = _drvSlqTbl.u32WrPtr;
4947     #else
4948         //save current writePtr
4949         if (_drvSlqTbl.u32WrPtr != _drvSlqTbl.u32StAdd)
4950         {
4951             u32FileEndPtr = _drvSlqTbl.u32WrPtr - SLQ_ENTRY_LEN;
4952         }
4953         else
4954         {
4955             if (_drvSlqTbl.u32WrPtr != _drvSlqTbl.u32RdPtr)
4956             {
4957                 u32FileEndPtr = _drvSlqTbl.u32EndAdd - SLQ_ENTRY_LEN;
4958             }
4959             else
4960             {
4961                 //R==W==ST indicates SlqTbl may just be reset
4962                 u32FileEndPtr = _drvSlqTbl.u32StAdd;
4963             }
4964         }
4965     #endif
4966         MVD_DEBUGVERBAL(printf("fe=%lx, rd=%lx, wr=%lx\n", u32FileEndPtr,
4967                         _drvSlqTbl.u32RdPtr, _drvSlqTbl.u32WrPtr));
4968     }
4969 
4970     if (HAL_MVD_EnableLastFrameShow(bEnable) == FALSE)
4971     {
4972         MVD_DEBUGERROR(printf("%s fail!!\n", __FUNCTION__));
4973         return E_MVD_RET_FAIL;
4974     }
4975     bEnableLastFrmShow = bEnable;
4976     return E_MVD_RET_OK;
4977 }
4978 
4979 #define FLAG_LAST_FRM_SHOW (HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_CMD_LAST_FRAME_SHOW))
4980 //------------------------------------------------------------------------------
4981 /// Get if MVD decoder finish display.
4982 /// @return TRUE or FALSE
4983 ///     - TRUE, Yes
4984 ///     - FALSE, No
4985 //------------------------------------------------------------------------------
MDrv_MVD_IsDispFinish(void)4986 E_MVD_Result MDrv_MVD_IsDispFinish(void)
4987 {
4988     MS_U32 u32TimeCnt;
4989     MS_U32 u32FeByteCnt = 0;
4990 
4991     MVD_FUNC_ENTRY();
4992 
4993     //printf("MDrv_MVD_IsDispFinish::");
4994     if (bEnableLastFrmShow != TRUE)
4995     {
4996         MVD_DEBUGINFO(printf("%s: bEnableLastFrmShow!=TRUE\n", __FUNCTION__));
4997         return E_MVD_RET_FAIL;
4998     }
4999 
5000     if(pu8MVDGetFrameInfoBufStart==0)
5001     {
5002         MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
5003         return E_MVD_RET_FAIL;
5004     }
5005 
5006     //printf("0x%x\n", FLAG_LAST_FRM_SHOW);
5007     if ((E_MVD_SLQ_TBL_MODE == curSrcMode) && (TRUE != FLAG_LAST_FRM_SHOW))
5008     {
5009 #if (!UPDATE_NEXT_WRPTR)
5010         //insert pattern when each time checking IsDispFinish
5011         if (MVD_SLQTblInsertPattern(E_MVD_PATTERN_FILEEND))
5012         {
5013             u32FeByteCnt += END_PATTERN_SIZE;
5014         }
5015 #endif
5016         if (u32FileEndPtr == MVD_Map2DrvSlqTbl(MDrv_MVD_GetSLQReadPtr()))
5017         {
5018             //insert padding pattern until timeout
5019             u32TimeCnt= HAL_MVD_GetTime();
5020             while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
5021             {
5022                 if (TRUE == FLAG_LAST_FRM_SHOW)
5023                 {
5024                     //printf("\nDisp finished!\n");
5025                     break;
5026                 }
5027                 //insert file-end pattern again
5028                 if (MVD_SLQTblInsertPattern(E_MVD_PATTERN_FILEEND))
5029                 {
5030                     u32FeByteCnt += END_PATTERN_SIZE;
5031                 }
5032             }
5033             if ((HAL_MVD_GetTime() - u32TimeCnt) >= CMD_TIMEOUT_MS)
5034             {
5035                 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_IsDispFinish TIMEOUT!!! *****\n\n"));
5036                 if (E_MVD_CODEC_VC1_MAIN == curCodecType)
5037                 {
5038                     if ((HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_RCV_PAYLOAD_LENGTH) > 0x200000)
5039                         && (TRUE != HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_MEET_FILE_END_SC)))
5040                     {
5041                         MVD_DEBUGERROR(printf("RCV payloadLen(0x%lx) invalid!\n",
5042                             HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_RCV_PAYLOAD_LENGTH)));
5043                     }
5044                 }
5045                 MVD_DEBUGERROR(printf("***** fe=%lx, rd=%lx(%lx,%lx), wr=%lx, empty=%lx, u32FeByteCnt=%lx\n",
5046                     u32FileEndPtr, _drvSlqTbl.u32RdPtr, MVD_Map2DrvSlqTbl(MDrv_MVD_GetSLQReadPtr()),
5047                     MDrv_MVD_GetSLQReadPtr(), _drvSlqTbl.u32WrPtr, _drvSlqTbl.u32Empty, u32FeByteCnt));
5048                 return E_MVD_RET_TIME_OUT;
5049             }
5050             else
5051             {
5052                 return E_MVD_RET_OK;
5053             }
5054         }
5055         else
5056         {
5057             //just return fail if readPtr is not closed to file-end ptr
5058             MVD_DEBUGVERBAL(printf("fe=%lx, rd=%lx(%lx), wr=%lx, empty=%lx\n", u32FileEndPtr, _drvSlqTbl.u32RdPtr,
5059                             MVD_Map2DrvSlqTbl(MDrv_MVD_GetSLQReadPtr()), _drvSlqTbl.u32WrPtr, _drvSlqTbl.u32Empty));
5060             return E_MVD_RET_FAIL;
5061         }
5062     }
5063 
5064     if (FLAG_LAST_FRM_SHOW)
5065     {
5066         return E_MVD_RET_OK;
5067     }
5068     else
5069     {
5070         return E_MVD_RET_FAIL;
5071     }
5072 
5073 }
5074 
5075 //------------------------------------------------------------------------------
5076 /// Set speed.
5077 /// @param -eSpeedType \b IN : specify the speed
5078 /// @param -u8Multiple \b IN :
5079 /// @return -return E_MVD_Result success/fail to set the speed
5080 //------------------------------------------------------------------------------
MDrv_MVD_SetSpeed(MVD_SpeedType eSpeedType,MS_U8 u8Multiple)5081 E_MVD_Result MDrv_MVD_SetSpeed(MVD_SpeedType eSpeedType, MS_U8 u8Multiple)
5082 {
5083     static MVD_AVSyncCfg stNFPSyncCfg;
5084 
5085     if ((u8Multiple > 32) || (eSpeedType==E_MVD_SPEED_TYPE_UNKNOWN))
5086     {
5087         MVD_DEBUGINFO(printf("%s: invalid para!\n", __FUNCTION__));
5088         return E_MVD_RET_INVALID_PARAM;
5089     }
5090 
5091     if (ePreSpeedType == E_MVD_SPEED_DEFAULT)
5092     {   //save avsync config when normal play for restoring it later
5093         stNFPSyncCfg.bEnable = stSyncCfg.bEnable;
5094         stNFPSyncCfg.u32Delay = stSyncCfg.u32Delay;
5095         stNFPSyncCfg.u16Tolerance = stSyncCfg.u16Tolerance;
5096         MVD_DEBUGINFO(printf("MDrv_MVD_SetSpeed save avsync: bEnable=0x%x u32Delay=0x%lx u16Tolerance=0x%x\n",
5097                   stNFPSyncCfg.bEnable, stNFPSyncCfg.u32Delay, stNFPSyncCfg.u16Tolerance));
5098     }
5099 
5100     if (E_MVD_SPEED_DEFAULT != eSpeedType) //fast or slow forward
5101     {
5102         //disable avsyn when fast/slow forward
5103         MDrv_MVD_SetAVSync(FALSE, 0);
5104     }
5105 
5106     if (HAL_MVD_SetSpeed(eSpeedType, u8Multiple) == TRUE)
5107     {
5108         if (E_MVD_SPEED_DEFAULT == eSpeedType) //Normal Play
5109         {
5110             if (ePreSpeedType != E_MVD_SPEED_DEFAULT)
5111             {
5112                 //set AVSync again for firmware doesn't remember AVSync settings after FF
5113                 MVD_DEBUGINFO(printf("MDrv_MVD_SetSpeed reset avsync: bEnable=0x%x u32Delay=0x%lx u16Tolerance=0x%x\n",
5114                               stNFPSyncCfg.bEnable, stNFPSyncCfg.u32Delay, stNFPSyncCfg.u16Tolerance));
5115 
5116                 MDrv_MVD_SetAVSync(stNFPSyncCfg.bEnable, stNFPSyncCfg.u32Delay);
5117                 if ((stNFPSyncCfg.u16Tolerance!=0) && (FALSE == MDrv_MVD_ChangeAVsync(stNFPSyncCfg.bEnable, stNFPSyncCfg.u16Tolerance)))
5118                 {
5119                     return E_MVD_RET_FAIL;
5120                 }
5121             }
5122         }
5123 
5124         ePreSpeedType = eSpeedType;
5125         return E_MVD_RET_OK;
5126     }
5127     else
5128     {
5129         return E_MVD_RET_FAIL;
5130    }
5131 }
5132 
5133 //------------------------------------------------------------------------------
5134 /// Set PTS base to MVD F/W
5135 /// @param -u32pts \b IN : pts unit in 90k counter
5136 //------------------------------------------------------------------------------
MVD_SetPTSBase(MS_U32 u32pts)5137 static void MVD_SetPTSBase(MS_U32 u32pts)
5138 {
5139     MVD_CmdArg mvdcmd;
5140 
5141     SET_CMDARG(mvdcmd, u32pts);
5142     if (HAL_MVD_MVDCommand( CMD_PTS_BASE, &mvdcmd ) == FALSE)
5143     {
5144         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PTS_BASE ) );
5145     }
5146 
5147     return;
5148 }
5149 
5150 //------------------------------------------------------------------------------
5151 /// Reset Presentation Time Stamp according to u32PtsBase
5152 /// @param -u32PtsBase \b IN : the PTS base specified by user
5153 /// @return -return E_MVD_Result success/fail to reset PTS base
5154 //------------------------------------------------------------------------------
MDrv_MVD_ResetPTS(MS_U32 u32PtsBase)5155 E_MVD_Result MDrv_MVD_ResetPTS(MS_U32 u32PtsBase)
5156 {
5157     _mvdCmdQ.u32PtsBase = _MS_TO_90K(u32PtsBase);
5158     MVD_SetPTSBase(_mvdCmdQ.u32PtsBase);
5159     return E_MVD_RET_OK;
5160 }
5161 
5162 
5163 //------------------------------------------------------------------------------
5164 /// Get if sequence change (width/height/framerate/interlace) occurs.
5165 /// @return TRUE or FALSE
5166 ///     - TRUE, Yes
5167 ///     - FALSE, No
5168 //------------------------------------------------------------------------------
MDrv_MVD_IsSeqChg(void)5169 MS_BOOL MDrv_MVD_IsSeqChg(void)
5170 {
5171     static MVD_FrameInfo stFrmInfo;
5172 
5173     if (
5174 #ifdef MVD_ENABLE_ISR
5175         (eCurEvent & E_MVD_EVENT_SEQ_FOUND) ||
5176 #endif
5177         (MDrv_MVD_GetDispRdy())// && (TRUE == MDrv_MVD_GetValidStreamFlag()))
5178         )
5179     {
5180         MDrv_MVD_GetFrameInfo(&stFrmInfo);
5181 
5182         if (FALSE == stMemCfg.bEnableDynScale)
5183         {
5184             if((stPreFrmInfo.u16HorSize   != stFrmInfo.u16HorSize) ||
5185                (stPreFrmInfo.u16VerSize   != stFrmInfo.u16VerSize) ||
5186                (stPreFrmInfo.u32FrameRate != stFrmInfo.u32FrameRate) ||
5187                (stPreFrmInfo.u8Interlace  != stFrmInfo.u8Interlace))
5188             {
5189 #if 0
5190                 (printf( "MDrv_MVD_IsSeqChg::Previous\n" ));
5191                 (printf( "H=%u\n", stPreFrmInfo.u16HorSize ));
5192                 (printf( "V=%u\n", stPreFrmInfo.u16VerSize ));
5193                 (printf( "F=%lu\n", stPreFrmInfo.u32FrameRate ));
5194                 (printf( "A=%u\n", stPreFrmInfo.u8AspectRate ));
5195                 (printf( "I=%u\n", stPreFrmInfo.u8Interlace ));
5196 #endif
5197 #if 0
5198                 (printf( "MDrv_MVD_IsSeqChg\n" ));
5199                 (printf( "H=%u\n", stFrmInfo.u16HorSize ));
5200                 (printf( "V=%u\n", stFrmInfo.u16VerSize ));
5201                 (printf( "F=%lu\n", stFrmInfo.u32FrameRate ));
5202                 (printf( "A=%u\n", stFrmInfo.u8AspectRate ));
5203                 (printf( "I=%u\n", stFrmInfo.u8Interlace ));
5204 #endif
5205 
5206                 //memcpy(&stPreFrmInfo, &stFrmInfo, sizeof(MVD_FrameInfo));
5207                 stPreFrmInfo.u16HorSize   = stFrmInfo.u16HorSize;
5208                 stPreFrmInfo.u16VerSize   = stFrmInfo.u16VerSize;
5209                 stPreFrmInfo.u8AspectRate = stFrmInfo.u8AspectRate;
5210                 stPreFrmInfo.u32FrameRate = stFrmInfo.u32FrameRate;
5211                 stPreFrmInfo.u8Interlace  = stFrmInfo.u8Interlace;
5212 #if 0
5213                 (printf( "MDrv_MVD_IsSeqChg===>\n" ));
5214                 (printf( "H=%u\n", stFrmInfo.u16HorSize ));
5215                 (printf( "V=%u\n", stFrmInfo.u16VerSize ));
5216                 (printf( "F=%u\n", stFrmInfo.u32FrameRate ));
5217                 (printf( "A=%u\n", stFrmInfo.u8AspectRate ));
5218                 (printf( "I=%u\n", stFrmInfo.u8Interlace ));
5219 #endif
5220                 return TRUE;
5221             }
5222         }
5223         else
5224         {
5225             //When dynamic scaling is enabled, f/w will handle the width/height change.
5226             //Therefore, only report SeqChg if framerate or interlace flag changes.
5227             if((stPreFrmInfo.u32FrameRate != stFrmInfo.u32FrameRate) ||
5228                (stPreFrmInfo.u8Interlace  != stFrmInfo.u8Interlace))
5229             {
5230                 stPreFrmInfo.u8AspectRate = stFrmInfo.u8AspectRate;
5231                 stPreFrmInfo.u32FrameRate = stFrmInfo.u32FrameRate;
5232                 stPreFrmInfo.u8Interlace  = stFrmInfo.u8Interlace;
5233                 return TRUE;
5234             }
5235         }
5236     }
5237 
5238     return FALSE;
5239 }
5240 
5241 //------------------------------------------------------------------------------
5242 /// Set Debug Data which will be queried by MDrv_MVD_DbgGetData()
5243 /// @param -u32Addr \b IN : address of debug data
5244 /// @param -u32Data \b IN : the debug data
5245 /// @return -return E_MVD_Result success/fail to set debug data
5246 //------------------------------------------------------------------------------
MDrv_MVD_DbgSetData(MS_U32 u32Addr,MS_U32 u32Data)5247 E_MVD_Result MDrv_MVD_DbgSetData(MS_U32 u32Addr, MS_U32 u32Data)
5248 {
5249     return E_MVD_RET_FAIL;
5250 }
5251 
5252 //------------------------------------------------------------------------------
5253 /// Get Debug Data
5254 /// @param -u32Addr \b IN : address of debug data
5255 /// @param -u32Data \b IN : pointer to the debug data
5256 /// @return -return E_MVD_Result success/fail to get debug data
5257 //------------------------------------------------------------------------------
MDrv_MVD_DbgGetData(MS_U32 u32Addr,MS_U32 * u32Data)5258 E_MVD_Result MDrv_MVD_DbgGetData(MS_U32 u32Addr, MS_U32* u32Data)
5259 {
5260     MVD_CmdArg mvdcmd;
5261     MS_U32 u32Val;
5262 
5263     if (!u32Data)
5264     {
5265         return E_MVD_RET_INVALID_PARAM;
5266     }
5267 
5268     SET_CMDARG(mvdcmd, u32Addr);
5269     if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
5270     {
5271         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_IO ) );
5272         return E_MVD_RET_FAIL;
5273     }
5274 
5275 #if (defined(CHIP_T2) || defined(CHIP_T7))
5276     u32Val = (((MS_U32)mvdcmd.Arg0)) | ((MS_U32)mvdcmd.Arg1 << 8) |
5277              (((MS_U32)mvdcmd.Arg2) << 16) | (((MS_U32)mvdcmd.Arg3) << 24);
5278 #else
5279     u32Val = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8) |
5280              (((MS_U32)mvdcmd.Arg4) << 16) | (((MS_U32)mvdcmd.Arg5) << 24);
5281 #endif
5282     *u32Data = u32Val;
5283 
5284     return E_MVD_RET_OK;
5285 }
5286 
5287 
5288 //------------------------------------------------------------------------------
5289 /// Set MVD firmware command
5290 /// @param -u8cmd \b IN : MVD command
5291 /// @param -pstCmdArg \b IN : pointer to command argument
5292 //------------------------------------------------------------------------------
MDrv_MVD_MVDCommand(MS_U8 u8cmd,MVD_CmdArg * pstCmdArg)5293 MS_BOOL MDrv_MVD_MVDCommand ( MS_U8 u8cmd, MVD_CmdArg *pstCmdArg )
5294 {
5295     return HAL_MVD_MVDCommand(u8cmd, pstCmdArg);
5296 }
5297 
5298 
5299 
5300 #ifndef REDLION_LINUX_KERNEL_ENVI
5301 //------------- Below functions are for ATSC Closed Caption --------------------
5302 //------------------------------------------------------------------------------
5303 /// Reset MVD CC.  It can be called when overflow occurrs.
5304 /// @return -Result of Reset CC.
5305 //------------------------------------------------------------------------------
MDrv_MVD_CCRst(MVD_CCCfg * pCCParam)5306 E_MVD_Result MDrv_MVD_CCRst(MVD_CCCfg* pCCParam)
5307 {
5308     return MDrv_MVD_CCStartParsing(pCCParam);
5309 }
5310 
5311 
5312 //------------------------------------------------------------------------------
5313 /// Start CC data parsing.
5314 /// @return -Result of issuing command to firmware.
5315 //------------------------------------------------------------------------------
MDrv_MVD_CCStartParsing(MVD_CCCfg * pCCParam)5316 E_MVD_Result MDrv_MVD_CCStartParsing(MVD_CCCfg* pCCParam)
5317 {
5318     MS_U8 u8CC608 = (MS_U8)TRUE;
5319     MS_U8 u8Operation = 0;
5320 
5321     if ((!pCCParam) || (pCCParam->eFormat==E_MVD_CC_NONE) || (pCCParam->eType==E_MVD_CC_TYPE_NONE))
5322     {
5323         return E_MVD_RET_INVALID_PARAM;
5324     }
5325 
5326     switch (pCCParam->eType)
5327     {
5328         case E_MVD_CC_TYPE_NTSC_FIELD1:
5329             u8Operation = 0x01;
5330             break;
5331         case E_MVD_CC_TYPE_NTSC_FIELD2:
5332             u8Operation = 0x02;
5333             break;
5334         case E_MVD_CC_TYPE_NTSC_TWOFIELD:
5335             u8Operation = 0x03;
5336             break;
5337         case E_MVD_CC_TYPE_DTVCC:
5338             u8Operation = 0x04;
5339             u8CC608 = FALSE;
5340             break;
5341         default:
5342             break;
5343     }
5344 
5345     MDrv_CC_Init();
5346     MDrv_CC_CM_SetMVDRB_HWAddr(pCCParam->u32BufStAdd, u8CC608);//fixme: VA2PA?
5347     MDrv_CC_CM_SetParsingType(u8Operation, (MS_U16)pCCParam->u32BufSize, u8CC608);
5348 
5349     return E_MVD_RET_OK;
5350 }
5351 
5352 
5353 //------------------------------------------------------------------------------
5354 /// Stop CC data parsing.
5355 /// @return -Result of issuing command to firmware.
5356 //------------------------------------------------------------------------------
MDrv_MVD_CCStopParsing(MVD_CCFormat eCCFormat)5357 E_MVD_Result MDrv_MVD_CCStopParsing(MVD_CCFormat eCCFormat)
5358 {
5359     MS_U8 u8CC608 = 0xff;
5360 
5361     switch (eCCFormat)
5362     {
5363         case E_MVD_CC_608:
5364             u8CC608 = 1;
5365             break;
5366         case E_MVD_CC_708:
5367             u8CC608 = 0;
5368             break;
5369         default:
5370             return E_MVD_RET_INVALID_PARAM;
5371     }
5372     MDrv_CC_CM_DisableParsing(u8CC608);
5373     return E_MVD_RET_OK;
5374 }
5375 
5376 
5377 //------------------------------------------------------------------------------
5378 /// Get write pointer of CC data buffer.
5379 /// @return -Result of the query.
5380 //------------------------------------------------------------------------------
MDrv_MVD_CCGetWritePtr(MVD_CCFormat eCCFormat,MS_U32 * pWrite)5381 E_MVD_Result MDrv_MVD_CCGetWritePtr(MVD_CCFormat eCCFormat, MS_U32* pWrite)
5382 {
5383     MS_U8 u8CC608;
5384     if (!pWrite)
5385         return E_MVD_RET_INVALID_PARAM;
5386 
5387     u8CC608 = ((eCCFormat==E_MVD_CC_608)?1:0);
5388     *pWrite = MDrv_CC_PM_GetMVDRB_WriteAddr(u8CC608);
5389     return E_MVD_RET_OK;
5390 }
5391 
5392 
5393 //------------------------------------------------------------------------------
5394 /// Get the read pointer of CC data buffer.
5395 /// @return -Result of the query.
5396 //------------------------------------------------------------------------------
MDrv_MVD_CCGetReadPtr(MVD_CCFormat eCCFormat,MS_U32 * pRead)5397 E_MVD_Result MDrv_MVD_CCGetReadPtr(MVD_CCFormat eCCFormat, MS_U32* pRead)
5398 {
5399     MS_U8 u8CC608;
5400     if (!pRead)
5401         return E_MVD_RET_INVALID_PARAM;
5402 
5403     u8CC608 = ((eCCFormat==E_MVD_CC_608)?1:0);
5404     *pRead = MDrv_CC_PM_GetMVDRB_ReadAddr(u8CC608);
5405     return E_MVD_RET_OK;
5406 }
5407 
5408 
5409 //------------------------------------------------------------------------------
5410 /// Update the read pointer of CC data buffer.
5411 /// @return -Result of the update.
5412 //------------------------------------------------------------------------------
MDrv_MVD_CCUpdateReadPtr(MVD_CCFormat eCCFormat,MS_U32 u32EachPacketSize)5413 E_MVD_Result MDrv_MVD_CCUpdateReadPtr(MVD_CCFormat eCCFormat, MS_U32 u32EachPacketSize)
5414 {
5415     MS_U8 u8CC608;
5416 
5417     u8CC608 = ((eCCFormat==E_MVD_CC_608)?1:0);
5418     MDrv_CC_PM_SetMVDRB_ReadAddr(u32EachPacketSize, u8CC608);
5419 
5420     return E_MVD_RET_OK;
5421 }
5422 
5423 
5424 //------------------------------------------------------------------------------
5425 /// Get if CC data buffer is overflow.
5426 /// @return -Result of the query.
5427 //------------------------------------------------------------------------------
MDrv_MVD_CCGetIsOverflow(MVD_CCFormat eCCFormat,MS_BOOL * pbOverflow)5428 E_MVD_Result MDrv_MVD_CCGetIsOverflow(MVD_CCFormat eCCFormat, MS_BOOL* pbOverflow)
5429 {
5430     MS_U8 u8CC608;
5431     if (!pbOverflow)
5432         return E_MVD_RET_INVALID_PARAM;
5433 
5434     u8CC608 = ((eCCFormat==E_MVD_CC_608)?1:0);
5435     *pbOverflow = MDrv_CC_CM_GetOverflowStatus(u8CC608);
5436 
5437     return E_MVD_RET_OK;
5438 }
5439 #endif
5440 
5441 
5442 
5443 //------------- Below functions are for MediaCodec SLQ Table --------------------
5444 #if _SLQTBL_DUMP_PTS
_SLQTbl_DumpPtsTbl(MS_U32 u32EntryStart,MS_U32 u32EntryEnd)5445 static void _SLQTbl_DumpPtsTbl(MS_U32 u32EntryStart, MS_U32 u32EntryEnd)
5446 {
5447     MS_U32 i;
5448     MS_U32 u32EsRp, u32EsStart, u32EsEnd;
5449 
5450     for (i=u32EntryStart; i<u32EntryEnd; i++)
5451     {
5452         u32EsRp = _drvEsTbl.u32StAdd + i*8;
5453 
5454         u32EsEnd = HAL_MVD_MemRead4Byte(u32EsRp+4);
5455         u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
5456         printf("ES[%lx] Start=0x%lx End=0x%lx u32EsRp=%lx\n",
5457             i, u32EsStart, u32EsEnd, u32EsRp);
5458     }
5459 
5460     printf("\n=======Dump PTS table========\n");
5461     printf("addr\t byte_cnt\t dummy_cnt\t id_low\t id_high\t time_stamp\n");
5462     for (i=u32EntryStart; i<u32EntryEnd; i++)
5463     {
5464         printf("0x%lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\n", u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN,
5465                HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN),   //byteCnt
5466                HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+4), //dummyPktCnt
5467                HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+8), //idLow
5468                HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+12),//idHigh
5469                HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+16) //pts
5470                );
5471     }
5472     printf("=====================================\n");
5473 }
5474 #endif
5475 
5476 
MVD_SLQTblInsertPattern(MVD_PatternType ePattern)5477 static MS_BOOL MVD_SLQTblInsertPattern(MVD_PatternType ePattern)
5478 {
5479     MS_U32 i;
5480 
5481     if (_drvSlqTbl.u32Empty < SLQ_TBL_SAFERANGE)
5482     {
5483         MVD_DEBUGINFO(printf("SLQTbl full!(0x%lx) Cannot insert pattern any more!\n", _drvSlqTbl.u32Empty));
5484         return FALSE;
5485     }
5486 
5487 #if SLQ_NEW_PUSH
5488     if(_SlqStatus.bSlqCtrlBit)
5489     {
5490         if(_SlqStatus.bSlqPicWaitNextStart)
5491         {
5492             _drvSlqTbl.u32WrPtr = _SlqStatus.u32VaildWptrAddr;
5493         }
5494         _SlqStatus.bSlqCtrlBit = FALSE;
5495     }
5496 #endif // #if SLQ_NEW_PUSH
5497     for (i =0; i<2; i++)
5498     {   //insert dummy pattern
5499         MVD_PacketInfo stDummyPkt;
5500 
5501         if (E_MVD_PATTERN_FLUSH == ePattern)
5502         {
5503             MVD_SLQTblGetDummyPkt(&stDummyPkt);
5504         }
5505         else if (E_MVD_PATTERN_FILEEND == ePattern)
5506         {
5507             MVD_SLQTblGetFileEndPkt(&stDummyPkt);
5508         }
5509         else
5510         {
5511             MVD_DEBUGERROR(printf("Invalid MVD_PatternType! Won't insert pattern!\n"));
5512             return FALSE;
5513         }
5514         #if SLQ_NEW_PUSH
5515         _SlqStatus.bSlqFireRdy = TRUE;
5516         #endif
5517         //printf("WrPtr 0x%lx ", _drvSlqTbl.u32WrPtr);
5518         MVD_SLQTblSendPacket(&stDummyPkt);
5519         //printf("==> 0x%lx\n", _drvSlqTbl.u32WrPtr);
5520         MDrv_MVD_SetSLQWritePtr(FALSE);
5521     }
5522     return TRUE;
5523 }
5524 
5525 
MVD_SLQTblSendPacket(MVD_PacketInfo * pstVideoPKT)5526 static MS_BOOL MVD_SLQTblSendPacket(MVD_PacketInfo *pstVideoPKT)
5527 {
5528     static MS_U32 u32EsLast;
5529     static MS_U32* u32LastEntry = &_drvSlqTbl.u32WrPtr;
5530     MS_U32* pu32EsNew = &_drvEsTbl.u32WrPtr;
5531     MS_U32 u32EntryWord = 0;
5532     MS_U32 u32Index = 0;
5533     MS_U32 u32Pts;
5534     MS_U32 u32ESStart=0;
5535     MS_U32 u32ESEnd=0;
5536 #if _SLQTBL_DUMP_PKT
5537     static MS_U32 u32SendTimes = 0;
5538 
5539     printf("Pkt[%lx] st=0x%lx len=0x%lx pts=0x%lx id_l=0x%lx id_h=0x%lx\n", u32SendTimes++,
5540         pstVideoPKT->u32StAddr, pstVideoPKT->u32Length, pstVideoPKT->u32TimeStamp,
5541         pstVideoPKT->u32ID_L, pstVideoPKT->u32ID_H);
5542 #endif
5543 
5544     MS_ASSERT(u32MVDFWPtsTblAddr != NULL);
5545     if (u32MVDFWPtsTblAddr)
5546     {
5547         MS_U32 u32PtsTblEntryAddr = 0;
5548         u32Index = (_drvSlqTbl.u32WrPtr - _drvSlqTbl.u32StAdd)/8;
5549         if (pstVideoPKT->u32TimeStamp != MVD_NULLPKT_PTS)
5550         {
5551             u32Pts = _MS_TO_90K(pstVideoPKT->u32TimeStamp);
5552         }
5553         else
5554         {
5555             u32Pts = MVD_NULLPKT_PTS;
5556         }
5557         u32PtsTblEntryAddr = u32MVDFWPtsTblAddr+u32Index*MVD_FW_SLQTBL_PTS_LEN;
5558         HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+4, u32DummyPktCnt);   //dummyPktCnt
5559         HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+8, pstVideoPKT->u32ID_L);  //idLow
5560         HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+12, pstVideoPKT->u32ID_H); //idHigh
5561         HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+16, u32Pts);  //PTS
5562         HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr, u32SlqByteCnt&0xffffff); //byteCnt
5563         //printf("PTS=0x%lx(%lx), idx=0x%lx add=0x%lx\n", pstVideoPKT->u32TimeStamp,
5564         //        HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+u32Index*MVD_FW_SLQTBL_PTS_LEN+4),
5565         //        u32Index, u32MVDFWPtsTblAddr+u32Index*MVD_FW_SLQTBL_PTS_LEN+4);
5566 
5567         if (MDrv_MVD_IsMStreamerMode())
5568         {
5569             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+12, pstVideoPKT->u32ID_H); //idHigh
5570             HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+16, pstVideoPKT->u32TimeStamp);  //PTS
5571 
5572             MVD_DBG_STS(printf(">>> drvMVD pts,idH = %lu, %lu\n", HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+16),
5573                    HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+12)));
5574             if (((MVD_NULLPKT_PTS == pstVideoPKT->u32ID_H) && (MVD_NULLPKT_PTS == pstVideoPKT->u32TimeStamp)) == FALSE)
5575             {   //Only update PTS to firmware when pts field is valid.
5576                 //Plz refer to MDrv_MVD_PushQueue if (u8MstMode == MST_MODE_TRUE) {}
5577                 HAL_MVD_UpdatePts();    //for uniplayer
5578             }
5579         }
5580     }
5581 #if _SLQTBL_DUMP_PTS
5582     if (u32Index == 0x177)
5583     {
5584         _SLQTbl_DumpPtsTbl(0, 0x179);
5585     }
5586 #endif
5587 
5588     u32SlqByteCnt += pstVideoPKT->u32Length;
5589 
5590     //update SLQ tbl entry
5591     //u32EsLast = (pstVideoPKT->u32StAddr)+_drvSlqTbl.u32StAdd;
5592     u32EsLast = (pstVideoPKT->u32StAddr)+MVD_GetMemOffset(stMemCfg.u32BSAddr);
5593     HAL_MVD_MemWrite4Byte(*pu32EsNew, u32EsLast-MVD_GetMemOffset(stMemCfg.u32BSAddr));
5594     u32ESStart = (u32EsLast) & MVD_SLQ_TBL_ENTRY_LENS;//SLQ_TBL_ENTRY_LEN;
5595 
5596     u32EsLast += pstVideoPKT->u32Length; //update ES write pointer
5597     //Notice: This is for MVD HW, so no need to minus one.
5598     HAL_MVD_MemWrite4Byte((*pu32EsNew)+4, u32EsLast-MVD_GetMemOffset(stMemCfg.u32BSAddr));
5599     u32ESEnd   = (u32EsLast) & MVD_SLQ_TBL_ENTRY_LENS;//SLQ_TBL_ENTRY_LEN;
5600 
5601     *pu32EsNew += 8;
5602     if (*pu32EsNew >= _drvEsTbl.u32EndAdd)
5603     {   //wrap to the beginning of the table
5604         MVD_DEBUGINFO(printf("...ES wrapping to the beginning!\n"));
5605         *pu32EsNew = _drvEsTbl.u32StAdd;
5606     }
5607 
5608 #ifdef _MVD6
5609     //MVD_PRINT("===>[%lx] u32ESStart=0x%lx u32ESEnd=0x%lx u32EsLast=0x%lx\n",
5610     //    pMVDHalContext->u32SendTimes[u8Idx]++, u32ESStart, u32ESEnd, u32EsLast);
5611 
5612     u32EntryWord = u32ESEnd;
5613     HAL_MVD_MemWrite4Byte(*u32LastEntry, u32EntryWord);
5614     //MVD_PRINT("===> u32EntryWord1 addr=0x%lx\n", (*u32LastEntry));
5615     //MVD_PRINT("===> u32EntryWord0=0x%lx\n", u32EntryWord);
5616 
5617     u32EntryWord = u32ESStart;
5618     HAL_MVD_MemWrite4Byte((*u32LastEntry)+4, u32EntryWord);
5619     //MVD_PRINT("===> u32EntryWord1 addr=0x%lx\n", (*u32LastEntry)+4);
5620     //MVD_PRINT("===> u32EntryWord1=0x%lx\n", u32EntryWord);
5621 #else
5622     //printf("===>[%lx] u32ESStart=0x%lx u32ESEnd=0x%lx u32EsLast=0x%lx\n",
5623     //    u32SendTimes++, u32ESStart, u32ESEnd, u32EsLast);
5624 
5625     u32EntryWord = u32ESEnd | (u32ESStart <<  MVD_SLQ_TBL_ENTRY_SIZES);//29);
5626     HAL_MVD_MemWrite4Byte(*u32LastEntry, u32EntryWord);
5627     //printf("===> u32EntryWord1 addr=0x%lx\n", (*u32LastEntry));
5628     //printf("===> u32EntryWord0=0x%lx\n", u32EntryWord);
5629 
5630     u32EntryWord = ((pstVideoPKT->u32ID_L & MVD_SLQ_TBL_SHIFT_MASK)<<
5631             MVD_SLQ_TBL_SHIFT_BIT1) | (u32ESStart >> MVD_SLQ_TBL_SHIFT_BIT2);
5632 
5633 
5634     HAL_MVD_MemWrite4Byte((*u32LastEntry)+4, u32EntryWord);
5635     //printf("===> u32EntryWord1 addr=0x%lx\n", (*u32LastEntry)+4);
5636     //printf("===> u32EntryWord1=0x%lx\n", u32EntryWord);
5637 #endif
5638     *u32LastEntry += 8;
5639     if (*u32LastEntry >= _drvSlqTbl.u32EndAdd)
5640     {   //wrap to the beginning of the table
5641         MVD_DEBUGINFO(printf("...wrapping to the beginning!\n"));
5642         *u32LastEntry = _drvSlqTbl.u32StAdd;
5643         //also wrap DivX311 pattern table
5644         _drvDivxTbl.u32WrPtr = _drvDivxTbl.u32StAdd;
5645     }
5646 
5647     if (_drvSlqTbl.u32Empty)
5648     {
5649         _drvSlqTbl.u32Empty -= SLQ_ENTRY_LEN;
5650     }
5651 
5652     return TRUE;
5653 }
5654 #if SLQ_NEW_PUSH
MVD_SLQTblGetHdrPkt(MVD_PacketInfo * pDivxHdr,MVD_PacketInfo * pDivxData)5655 static void MVD_SLQTblGetHdrPkt(MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData)
5656 #else
5657 static void MVD_SLQTblGetDivxHdrPkt(MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData)
5658 #endif
5659 {
5660     MS_U32 u32DivXPattern = _drvDivxTbl.u32WrPtr;
5661     MS_U32 u32FrmSize = pDivxData->u32Length;
5662 #if SLQ_NEW_PUSH
5663     if(_SlqStatus.bSlqCtrlBit)
5664     {
5665         if(_SlqStatus.bSlqPicWaitNextStart && _SlqStatus.bSlqPicStart)
5666         {
5667              //printf("Show KC the SlqPushLength = 0x%lx\n",_SlqStatus.u32SlqPushLength);
5668             if (E_MVD_CODEC_DIVX311 == curCodecType)
5669             {
5670                 HAL_MVD_MemWrite4Byte(_SlqStatus.u32SlqPatternAddr +4, _SlqStatus.u32SlqPushLength);
5671                 HAL_MVD_MemWrite4Byte(_SlqStatus.u32SlqPatternAddr , DIVX_PATTERN);
5672             }
5673             else if(E_MVD_CODEC_VC1_MAIN == curCodecType)
5674             {//rcv
5675                 HAL_MVD_MemWrite4Byte(_SlqStatus.u32SlqPatternAddr +4, RCV_PATTERN);
5676                 HAL_MVD_MemWrite4Byte(_SlqStatus.u32SlqPatternAddr , _SlqStatus.u32SlqPushLength);
5677             }
5678             else if (E_MVD_CODEC_VC1_ADV == curCodecType)
5679             {
5680                 HAL_MVD_MemWrite4Byte(_SlqStatus.u32SlqPatternAddr , VC1_PATTERN);
5681             }
5682             _SlqStatus.u32SlqPushLength = 0;
5683             _SlqStatus.u32SlqPatternAddr  = 0;
5684             _SlqStatus.bSlqFireRdy =TRUE;
5685 #if UPDATE_NEXT_WRPTR
5686             _SlqStatus.u32VaildWptrAddr = _drvSlqTbl.u32WrPtr + SLQ_ENTRY_LEN;
5687 #else
5688             _SlqStatus.u32VaildWptrAddr = _drvSlqTbl.u32WrPtr;
5689 #endif
5690             _SlqStatus.bSlqPicWaitNextStart = FALSE;
5691             _SlqStatus.bSlqPicCollect = FALSE;
5692         }
5693 
5694         if(_SlqStatus.bSlqPicStart)
5695         {
5696             _SlqStatus.u32SlqPatternAddr = u32DivXPattern;
5697             _SlqStatus.u32SlqPushLength += u32FrmSize;
5698             _SlqStatus.bSlqPicCollect = TRUE;
5699             _SlqStatus.bSlqPicWaitNextStart =TRUE;
5700         }
5701         else if(_SlqStatus.bSlqPicCollect)
5702         {
5703             _SlqStatus.u32SlqPushLength += u32FrmSize;
5704             _SlqStatus.bSlqPicWaitNextStart =TRUE;
5705         }
5706     }
5707     else
5708     {
5709         HAL_MVD_MemWrite4Byte(u32DivXPattern, DIVX_PATTERN);
5710         HAL_MVD_MemWrite4Byte(u32DivXPattern +4,u32FrmSize);
5711     }
5712 #else
5713     HAL_MVD_MemWrite4Byte(u32DivXPattern, DIVX_PATTERN);
5714     HAL_MVD_MemWrite4Byte(u32DivXPattern+4, u32FrmSize);
5715 #endif
5716     pDivxHdr->u32StAddr = u32DivXPattern - MVD_GetMemOffset(stMemCfg.u32DrvBufAddr);
5717     pDivxHdr->u32TimeStamp = pDivxData->u32TimeStamp; //unit: ms
5718     pDivxHdr->u32ID_L = pDivxData->u32ID_L;
5719     pDivxHdr->u32ID_H = pDivxData->u32ID_H;
5720     //printf("u32DivXPattern(0x%lx==>0x%lx)=0x%lx 0x%lx\n", u32DivXPattern, pDivxHdr->u32StAddr,
5721     //        HAL_MVD_MemRead4Byte(u32DivXPattern), HAL_MVD_MemRead4Byte(u32DivXPattern+4));
5722     if (E_MVD_CODEC_VC1_ADV == curCodecType)
5723     {
5724         _drvDivxTbl.u32WrPtr += 4;
5725         pDivxHdr->u32Length = 4;
5726     }
5727     else
5728     {
5729         _drvDivxTbl.u32WrPtr += 8;
5730         pDivxHdr->u32Length = 8;
5731     }
5732 #if SLQ_NEW_PUSH
5733     if(_SlqStatus.bSlqPicStart)
5734     {
5735         if (E_MVD_CODEC_VC1_ADV == curCodecType)
5736         {
5737             _drvDivxTbl.u32WrPtr += 4;
5738             pDivxHdr->u32Length = 4;
5739         }
5740         else
5741         {
5742             _drvDivxTbl.u32WrPtr += 8;
5743             pDivxHdr->u32Length = 8;
5744         }
5745     }
5746 #endif
5747 
5748 #if 0   //move to SendPacket
5749     if (_drvDivxTbl.u32WrPtr >= _drvDivxTbl.u32EndAdd)
5750     {   //wrap to the beginning of the table
5751         printf("...wrapping to the DivXTbl beginning!\n");
5752         _drvDivxTbl.u32WrPtr = _drvDivxTbl.u32StAdd;
5753     }
5754 #endif
5755 }
5756 
5757 
MVD_SLQTblGetFileEndPkt(MVD_PacketInfo * pFileEnd)5758 static void MVD_SLQTblGetFileEndPkt(MVD_PacketInfo* pFileEnd)
5759 {
5760     MS_U32 u32EndPattern = MVD_GetMemOffset(stMemCfg.u32DrvBufAddr+SLQ_TBL_SIZE*3);
5761 
5762     pFileEnd->u32StAddr = SLQ_TBL_SIZE*3;//u32EndPattern - MVD_GetMemOffset(stMemCfg.u32DrvBufAddr);
5763     pFileEnd->u32Length = END_PATTERN_SIZE;
5764     pFileEnd->u32TimeStamp = MVD_NULLPKT_PTS;
5765     pFileEnd->u32ID_L = MVD_U32_MAX;
5766     pFileEnd->u32ID_H = MVD_U32_MAX;
5767     MVD_DEBUGINFO(printf("u32EndPattern(0x%lx)=0x%lx 0x%lx 0x%lx 0x%lx\n", pFileEnd->u32StAddr,
5768             HAL_MVD_MemRead4Byte(u32EndPattern), HAL_MVD_MemRead4Byte(u32EndPattern+4),
5769             HAL_MVD_MemRead4Byte(u32EndPattern+8), HAL_MVD_MemRead4Byte(u32EndPattern+12)));
5770 }
5771 
5772 
MVD_SLQTblGetDummyPkt(MVD_PacketInfo * pDummy)5773 static void MVD_SLQTblGetDummyPkt(MVD_PacketInfo* pDummy)
5774 {
5775     //MS_U32 u32DummyES = MVD_GetMemOffset(stMemCfg.u32DrvBufAddr+SLQ_TBL_SIZE*2);
5776 
5777     pDummy->u32StAddr = SLQ_TBL_SIZE*2;//u32DummyES - MVD_GetMemOffset(stMemCfg.u32DrvBufAddr);
5778     pDummy->u32Length = DUMMY_SIZE;
5779     pDummy->u32TimeStamp = MVD_NULLPKT_PTS;
5780     pDummy->u32ID_L = MVD_U32_MAX;
5781     pDummy->u32ID_H = MVD_U32_MAX;
5782 #if 0
5783     printf("u32DummyES(0x%lx-->0x%lx, size=0x%lx)=0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", u32DummyES,
5784             pDummy->u32StAddr, pDummy->u32Length, HAL_MVD_MemRead4Byte(u32DummyES),
5785             HAL_MVD_MemRead4Byte(u32DummyES+4),HAL_MVD_MemRead4Byte(u32DummyES+8),HAL_MVD_MemRead4Byte(u32DummyES+12));
5786 #endif
5787 
5788 }
5789 
5790 
MVD_SLQTblInitFileEndPkt(MVD_CodecType eType)5791 static void MVD_SLQTblInitFileEndPkt(MVD_CodecType eType)
5792 {
5793     MS_U32 u32EndPattern = MVD_GetMemOffset(stMemCfg.u32DrvBufAddr+SLQ_TBL_SIZE*3);
5794     MS_U32 i;
5795 
5796     for (i=0; i<END_PATTERN_SIZE; i+=4)
5797     {
5798         HAL_MVD_MemWrite4Byte(u32EndPattern+i, 0xffffffff);
5799     }
5800     if ((E_MVD_CODEC_FLV == eType)||(E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER == eType))
5801     {
5802         HAL_MVD_MemWrite4Byte(u32EndPattern, FLV_PATTERN);
5803         HAL_MVD_MemWrite4Byte(u32EndPattern+4, 0xffffffff);
5804         HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_1); //scw
5805         HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_2); //scw
5806         HAL_MVD_MemWrite4Byte(u32EndPattern+16,END_PATTERN_3); //scw
5807         //printf("##########FileEnd for FLV/SVH!, u32EndPattern=%lx\n",u32EndPattern);
5808     }
5809     else if (E_MVD_CODEC_DIVX311 == eType)
5810     {
5811         HAL_MVD_MemWrite4Byte(u32EndPattern, DIVX_PATTERN);
5812         HAL_MVD_MemWrite4Byte(u32EndPattern+4, 0xffffffff);
5813         HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_1); //scw
5814         HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_2); //scw
5815         HAL_MVD_MemWrite4Byte(u32EndPattern+16,END_PATTERN_3); //scw
5816         //printf("##########FileEnd for DIVX311!, u32EndPattern=%lx\n",u32EndPattern);
5817     }
5818     else if ((E_MVD_CODEC_MPEG2 == eType)||(E_MVD_CODEC_MPEG4 == eType))
5819     {
5820         HAL_MVD_MemWrite4Byte(u32EndPattern, MPEG_PATTERN_0);
5821         HAL_MVD_MemWrite4Byte(u32EndPattern+4, END_PATTERN_1);
5822         HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_2);
5823         HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_3);
5824         //printf("##########FileEnd for MPEG2/4!, u32EndPattern=%lx\n",u32EndPattern);
5825     }
5826     else
5827     {
5828         HAL_MVD_MemWrite4Byte(u32EndPattern, END_PATTERN_0);
5829         HAL_MVD_MemWrite4Byte(u32EndPattern+4, END_PATTERN_1);
5830         HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_2); //scw
5831         HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_3); //scw
5832         //printf("##########FileEnd for VC1!, u32EndPattern=%lx\n",u32EndPattern);
5833     }
5834 
5835     MVD_DEBUGINFO(printf("u32EndPattern(0x%lx)=0x%lx 0x%lx\n", u32EndPattern,
5836             HAL_MVD_MemRead4Byte(u32EndPattern), HAL_MVD_MemRead4Byte(u32EndPattern+4)));
5837 }
5838 
5839 
MVD_SLQTblInitDummyPkt(MVD_CodecType eType)5840 static void MVD_SLQTblInitDummyPkt(MVD_CodecType eType)
5841 {
5842     MS_U32 u32DummyES = MVD_GetMemOffset(stMemCfg.u32DrvBufAddr+SLQ_TBL_SIZE*2);
5843     MS_U32 u32DummyPattern[3];
5844     MS_U32 u32PatternSize;
5845     MS_U32 i;
5846 
5847     //printf("eType = 0x%x\n", eType);
5848     //initial content for dummy packet
5849     for (i=0; i<DUMMY_SIZE; i+=4)
5850     {
5851         HAL_MVD_MemWrite4Byte(u32DummyES+i, 0xffffffff);
5852     }
5853 
5854     switch (eType)
5855     {
5856         case E_MVD_CODEC_FLV:
5857         case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
5858             u32DummyPattern[0] = FLV_PATTERN;
5859             u32PatternSize = 1;
5860             break;
5861 
5862         case E_MVD_CODEC_DIVX311:
5863             u32DummyPattern[0] = DIVX_PATTERN;
5864             u32PatternSize = 1;
5865             break;
5866 
5867         case E_MVD_CODEC_VC1_ADV: //vc1
5868             u32DummyPattern[0] = VC1_PATTERN_0;
5869             u32DummyPattern[1] = VC1_PATTERN_1;
5870             u32DummyPattern[2] = VC1_PATTERN_2;
5871             u32PatternSize = 3;
5872             break;
5873 
5874         case E_MVD_CODEC_VC1_MAIN: //rcv
5875             u32DummyPattern[0] = RCV_PATTERN_0;
5876             u32DummyPattern[1] = RCV_PATTERN_1;
5877             u32DummyPattern[2] = RCV_PATTERN_2;
5878             u32PatternSize = 3;
5879             break;
5880 
5881         default:
5882             u32DummyPattern[0] = DUMMY_PATTERN;
5883             u32PatternSize = 1;
5884             break;
5885     }
5886     for (i=0; i<u32PatternSize; i++)
5887     {
5888         HAL_MVD_MemWrite4Byte(u32DummyES+i*4, u32DummyPattern[i]);
5889     }
5890 #if 0
5891     printf("u32DummyES(0x%lx)=0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", u32DummyES, HAL_MVD_MemRead4Byte(u32DummyES),
5892             HAL_MVD_MemRead4Byte(u32DummyES+4),HAL_MVD_MemRead4Byte(u32DummyES+8),HAL_MVD_MemRead4Byte(u32DummyES+12));
5893 #endif
5894 
5895 }
5896 
5897 
5898 //------------------------------------------------------------------------------------------------------------
5899 // Layout of drvProcBuffer
5900 //              -----------------
5901 // drvProcBuff | SlqTbl entries  | <- _drvSlqTbl.u32StAdd
5902 //             |     8K bytes    |
5903 //             | (1024 entries)  |
5904 //             |                 |
5905 //             |-----------------|
5906 //             | DivX311         | <- _drvSlqTbl.u32EndAdd   <- _drvDivxTbl.u32StAdd
5907 //             |     8K bytes    |
5908 //             | (1024 entries)  |
5909 //             |                 |
5910 //             |-----------------|
5911 //             | Flush Patterns  |... <- _drvDivxTbl.u32EndAdd   <- _drvDummy.u32StAdd
5912 //             |     8K bytes    |
5913 //             | (1024 entries)  |
5914 //             |                 |
5915 //             |-----------------|
5916 //             | FileEnd Pattern |... <- _drvDummy.u32EndAdd   <- _drvFileEnd.u32StAdd
5917 //             |     8K bytes    |
5918 //             | (1024 entries)  |
5919 //             |                 |
5920 //             |-----------------|
5921 //             |  ES table       |... <- _drvFileEnd.u32EndAdd   <- _drvEsTbl.u32StAdd
5922 //             |     8K bytes    |
5923 //             | (1024 entries)  |
5924 //             |                 |
5925 //             |-----------------|
5926 //             |                 |........ End of drvProcBuff
5927 //
5928 //------------------------------------------------------------------------------------------------------------
MVD_SLQTblInit(void)5929 static void MVD_SLQTblInit(void)
5930 {
5931     //printf("%s\n", __FUNCTION__);
5932     MS_U32 u32Addr, u32Len, i;//, u32EsStart;
5933 
5934     u32DummyPktCnt = 0;//reset dummy packet counter
5935     u32SlqByteCnt = 0; //reset SLQ table byte counter
5936     bSlqTblHasValidData = FALSE;
5937 
5938     HAL_MVD_MemGetMap(E_MVD_MMAP_DRV, &u32Addr, &u32Len);
5939     //u32EsStart = u32Addr + u32Len;
5940     //printf("DRV_PROC@0x%lx 0x%lx es@0x%lx\n", u32Addr, u32Len, u32EsStart);
5941 
5942     //init SLQ table attributes
5943     _drvSlqTbl.u32StAdd  = u32Addr;
5944     _drvSlqTbl.u32EndAdd = u32Addr + SLQ_TBL_SIZE;
5945     _drvSlqTbl.u32EntryCntMax = SLQ_ENTRY_MAX;
5946     u32FileEndPtr = _drvSlqTbl.u32StAdd;
5947 
5948     //reset SLQ table read/write pointers
5949     _drvSlqTbl.u32RdPtr = _drvSlqTbl.u32StAdd;
5950     _drvSlqTbl.u32WrPtr = _drvSlqTbl.u32StAdd;
5951     #if SLQ_NEW_PUSH
5952     #if UPDATE_NEXT_WRPTR
5953     _SlqStatus.u32VaildWptrAddr = _drvSlqTbl.u32WrPtr + SLQ_ENTRY_LEN;
5954     #else
5955     _SlqStatus.u32VaildWptrAddr = _drvSlqTbl.u32WrPtr;
5956     #endif
5957     _SlqStatus.bSlqPicWaitNextStart = FALSE;
5958     _SlqStatus.bSlqCtrlBit = FALSE;
5959     _SlqStatus.u32SlqPushLength = 0;
5960     _SlqStatus.bSlqPicStart = FALSE;
5961     _SlqStatus.bSlqPicCollect = FALSE;
5962     _SlqStatus.bSlqEnLastFrameShow =FALSE;
5963     _SlqStatus.bSlqFireRdy = FALSE;
5964     #endif
5965     _drvSlqTbl.u32Empty = SLQ_TBL_SIZE;
5966 
5967     //_SLQTbl_DumpInfo(&_drvSlqTbl);
5968 
5969     {
5970         _mvdCmdQ.u32PtsBase = MVD_NULLPKT_PTS;
5971     }
5972 
5973 #if (!MVD_TURBO_INIT)
5974     //reset SLQ table
5975     _MVD_Memset(_drvSlqTbl.u32StAdd, 0, SLQ_TBL_SIZE);
5976 #endif
5977 
5978     //set SLQ table start/end to F/W
5979     MDrv_MVD_SetSLQTblBufStartEnd(MVD_GetMemOffset(stMemCfg.u32BSAddr), MVD_GetMemOffset(stMemCfg.u32BSAddr+SLQ_TBL_SIZE));
5980     //if (stMemCfg.bFWMiuSel != stMemCfg.bHWMiuSel)
5981     if (bSlqTblSync)
5982     {
5983         //init BDMA for SLQ table update when MDrv_MVD_SetSLQWritePtr
5984 
5985 #ifndef REDLION_LINUX_KERNEL_ENVI
5986         const BDMA_Info* pBDMA;
5987         pBDMA = MDrv_BDMA_GetInfo();
5988         if ((pBDMA == NULL) || (pBDMA->bInit != TRUE))
5989         {
5990             if (E_BDMA_OK != MDrv_BDMA_Init(stMemCfg.u32Miu1BaseAddr))
5991             {
5992                 printf("%s fail at MDrv_BDMA_Init!!!\n", __FUNCTION__);
5993             }
5994         }
5995 
5996         if (stMemCfg.bHWMiuSel == MIU_SEL_1)
5997         {
5998             if (stMemCfg.bFWMiuSel == MIU_SEL_0)
5999             {
6000                 bdmaCpyType = E_BDMA_SDRAM2SDRAM1;
6001             }
6002             else if (stMemCfg.bFWMiuSel == MIU_SEL_1)
6003             {
6004                 bdmaCpyType = E_BDMA_SDRAM12SDRAM1;
6005             }
6006             else
6007             {
6008                 MS_ASSERT(0);
6009             }
6010         }
6011         else if (stMemCfg.bHWMiuSel == MIU_SEL_0)
6012         {
6013             if (stMemCfg.bFWMiuSel == MIU_SEL_0)
6014             {
6015                 bdmaCpyType = E_BDMA_SDRAM2SDRAM;
6016             }
6017             else if (stMemCfg.bFWMiuSel == MIU_SEL_1)
6018             {
6019                 bdmaCpyType = E_BDMA_SDRAM12SDRAM;
6020             }
6021             else
6022             {
6023                 MS_ASSERT(0);
6024             }
6025         }
6026         else
6027         {
6028             MS_ASSERT(0);
6029         }
6030 #endif
6031     }
6032 
6033     ///// init SLQ entries for DivX311
6034     _drvDivxTbl.u32StAdd = _drvSlqTbl.u32EndAdd;
6035     _drvDivxTbl.u32EndAdd= _drvDivxTbl.u32StAdd + SLQ_TBL_SIZE;
6036     _drvDivxTbl.u32WrPtr = _drvDivxTbl.u32StAdd;
6037     //_drvDivxTbl.u32RdPtr = _drvDivxTbl.u32StAdd;
6038 #if (!MVD_TURBO_INIT)
6039     //reset DivX311 pattern table
6040     _MVD_Memset(_drvDivxTbl.u32StAdd, 0, SLQ_TBL_SIZE);
6041 #endif
6042 
6043     ///// init flush pattern
6044     MVD_SLQTblInitDummyPkt(curCodecType);
6045 
6046     ///// init file-end pattern
6047     MVD_SLQTblInitFileEndPkt(curCodecType);
6048 
6049     ///// init ES table
6050     _drvEsTbl.u32StAdd = _drvDivxTbl.u32EndAdd + DUMMY_SIZE*2;
6051     _drvEsTbl.u32EndAdd= _drvEsTbl.u32StAdd + ES_TBL_SIZE;
6052     _drvEsTbl.u32WrPtr = _drvEsTbl.u32StAdd;
6053     //reset ES table
6054     for (i = 0; i < ES_TBL_SIZE; i+=4)
6055     {
6056         HAL_MVD_MemWrite4Byte(_drvEsTbl.u32StAdd+i, stMemCfg.u32DrvBufSize);
6057     }
6058 
6059     u32PreEsRd = MVD_U32_MAX;    //reset ES read pointer
6060     u32PreEsWr = 0;              //reset ES write pointer
6061 
6062     return;
6063 }
6064 
6065 
6066 #if 0
6067 static void _SLQTbl_DumpInfo(MVD_SLQ_TBL_ST* pInfo)
6068 {
6069     printf("str=0x%lx\n", pInfo->u32StAdd);
6070     printf("end=0x%lx\n", pInfo->u32EndAdd);
6071     printf("cnt=0x%lx\n", pInfo->u32EntryCntMax);
6072     printf("rd =0x%lx\n", pInfo->u32RdPtr);
6073     printf("wr =0x%lx\n", pInfo->u32WrPtr);
6074     return;
6075 }
6076 #endif
6077 
6078 #ifdef MVD_ENABLE_ISR
MVD_IntHasUsrDataDisp(MS_U32 u32IntStat)6079 static MS_BOOL MVD_IntHasUsrDataDisp(MS_U32 u32IntStat)
6080 {
6081 
6082     return (((u32IntStat&INT_USER_DATA_DISP)==INT_USER_DATA_DISP) ? TRUE : FALSE);
6083 
6084 }
6085 
MVD_IntHasUsrData(MS_U32 u32IntStat)6086 static MS_BOOL MVD_IntHasUsrData(MS_U32 u32IntStat)
6087 {
6088     return (((u32IntStat&INT_USER_DATA)==INT_USER_DATA) ? TRUE : FALSE);
6089 }
6090 
MVD_IntIsDispRdy(MS_U32 u32IntStat)6091 static MS_BOOL MVD_IntIsDispRdy(MS_U32 u32IntStat)
6092 {
6093     return (((u32IntStat&INT_DISP_RDY)==INT_DISP_RDY) ? TRUE : FALSE);
6094 }
6095 
MVD_IntHasSeqHdr(MS_U32 u32IntStat)6096 static MS_BOOL MVD_IntHasSeqHdr(MS_U32 u32IntStat)
6097 {
6098     return (((u32IntStat&INT_SEQ_FOUND)==INT_SEQ_FOUND) ? TRUE : FALSE);
6099 }
6100 
6101 //INT_FIRST_FRAME means "1st frame be push to display queue & ready for display"
6102 //So, (1) in IPB or IP stream, that's I-frame
6103 //    (2) in PB only stream, that's first P-frame
MVD_IntHas1stFrame(MS_U32 u32IntStat)6104 static MS_BOOL MVD_IntHas1stFrame(MS_U32 u32IntStat)
6105 {
6106     return (((u32IntStat&INT_FIRST_FRAME)==INT_FIRST_FRAME) ? TRUE : FALSE);
6107 }
6108 
6109 #define INT_DEC_I (1<<17) // wait for release to remove
6110 //INT_DEC_I
MVD_IntHasDecodeIframe(MS_U32 u32IntStat)6111 static MS_BOOL MVD_IntHasDecodeIframe(MS_U32 u32IntStat)
6112 {
6113     return (((u32IntStat&INT_DEC_I)==INT_DEC_I) ? TRUE : FALSE);
6114 }
6115 
MVD_IntVSyncInt(MS_U32 u32IntStat)6116 static MS_BOOL MVD_IntVSyncInt(MS_U32 u32IntStat)
6117 {
6118 
6119     return (((u32IntStat&INT_DISP_VSYNC)==INT_DISP_VSYNC) ? TRUE : FALSE);
6120 
6121 }
6122 
6123 ///Notice: This function only works when being called by fnHandler, which was
6124 ///registered by AP using MDrv_MVD_SetIsrEvent()
MDrv_MVD_GetIsrEvent(void)6125 MS_U32 MDrv_MVD_GetIsrEvent(void)
6126 {
6127     return eCurEvent;
6128 }
6129 
MVD_IsrProc(void)6130 void MVD_IsrProc(void)
6131 {
6132     MS_U32 u32IntStat = 0;
6133 
6134 
6135     u32IntStat = HAL_MVD_GetIntState();
6136 
6137     if (u32IntStat != 0)
6138     {
6139         //MVD_DEBUGINFO(printf("MVD_IsrProc u32IntStat=%lx\n", u32IntStat));
6140         eCurEvent = E_MVD_EVENT_DISABLE_ALL;
6141 
6142         if ((eEventFlag & E_MVD_EVENT_USER_DATA) == E_MVD_EVENT_USER_DATA)
6143         {
6144             if (MVD_IntHasUsrData(u32IntStat))
6145             {
6146                 eCurEvent |= E_MVD_EVENT_USER_DATA;
6147                 MVD_DEBUGINFO(printf("===> UsrData!!!\n"));
6148             }
6149         }
6150         if ((eEventFlag & E_MVD_EVENT_USER_DATA_DISP) == E_MVD_EVENT_USER_DATA_DISP)
6151         {
6152             if (MVD_IntHasUsrDataDisp(u32IntStat))
6153             {
6154                 eCurEvent |= E_MVD_EVENT_USER_DATA_DISP;
6155                 MVD_DEBUGINFO(printf("===> DispUsrData!!!\n"));
6156             }
6157         }
6158         if ((eEventFlag & E_MVD_EVENT_DISP_RDY) == E_MVD_EVENT_DISP_RDY)
6159         {
6160             if (MVD_IntIsDispRdy(u32IntStat))
6161             {
6162                 eCurEvent |= E_MVD_EVENT_DISP_RDY;
6163                 MVD_DEBUGINFO(printf("===> DispRdy!!!\n"));
6164             }
6165         }
6166         if ((eEventFlag & E_MVD_EVENT_SEQ_FOUND) == E_MVD_EVENT_SEQ_FOUND)
6167         {
6168             if (MVD_IntHasSeqHdr(u32IntStat))
6169             {
6170                 eCurEvent |= E_MVD_EVENT_SEQ_FOUND;
6171                 MVD_DEBUGINFO(printf("===> SeqHdrFound!!!\n"));
6172             }
6173         }
6174         if ((eEventFlag & E_MVD_EVENT_FIRST_FRAME) == E_MVD_EVENT_FIRST_FRAME)
6175         {
6176             if (MVD_IntHas1stFrame(u32IntStat))
6177             {
6178                 eCurEvent |= E_MVD_EVENT_FIRST_FRAME;
6179                 MVD_DEBUGINFO(printf("===> 1stFrame!!!\n"));
6180             }
6181         }
6182         if ((eEventFlag & E_MVD_EVENT_DEC_I) == E_MVD_EVENT_DEC_I)
6183         {
6184             if (MVD_IntHasDecodeIframe(u32IntStat))
6185             {
6186                 eCurEvent |= E_MVD_EVENT_DEC_I;
6187                 MVD_DEBUGINFO(printf("===> E_MVD_EVENT_DEC_I!!!\n"));
6188             }
6189         }
6190         if ((eEventFlag & E_MVD_EVENT_DISP_VSYNC) == E_MVD_EVENT_DISP_VSYNC)
6191         {
6192             if (MVD_IntVSyncInt(u32IntStat))
6193             {
6194                 eCurEvent |= E_MVD_EVENT_DISP_VSYNC;
6195                 MVD_DEBUGINFO(printf("===> VSyncInt!!!\n"));
6196             }
6197         }
6198         if ((eEventFlag & E_MVD_EVENT_UNMUTE) == E_MVD_EVENT_UNMUTE)
6199         {
6200             MVD_DEBUGINFO(printf("E_MVD_EVENT_UNMUTE...\n"));
6201             if (MVD_IntVSyncInt(u32IntStat))
6202             {
6203                 MVD_DEBUGINFO(printf("===> UNMUTE?!\n"));
6204                 if (MDrv_MVD_GetIsIPicFound() != NULL)
6205                 {
6206                     u32VSyncCnt++;
6207                     if (MDrv_MVD_GetSyncStatus()==1)
6208                     {
6209                         u32VSyncCnt = 0;
6210                         eCurEvent |= E_MVD_EVENT_UNMUTE;
6211                         MVD_DEBUGINFO(printf("UnMute Sync!!!\n"));
6212                         eEventFlag &= (~E_MVD_EVENT_UNMUTE);
6213                         MDrv_MVD_EnableInt(eEventFlag);
6214                     }
6215                     else //time out checking
6216                     {
6217                         if((MDrv_MVD_GetPtsStcDiff() > MVD_UNMUTE_STC_PTS_GAP)
6218                         && (u32VSyncCnt > 25))
6219                         {
6220                             u32VSyncCnt = 0;
6221                             eCurEvent |= E_MVD_EVENT_UNMUTE;
6222                             MVD_DEBUGINFO(printf("UnMute 25 Vsync!!!\n"));
6223                             eEventFlag &= (~E_MVD_EVENT_UNMUTE);
6224                             MDrv_MVD_EnableInt(eEventFlag);
6225                         }
6226 
6227                         if(u32VSyncCnt > 60)
6228                         {
6229                             u32VSyncCnt = 0;
6230                             eCurEvent |= E_MVD_EVENT_UNMUTE;
6231                             MVD_DEBUGINFO(printf("UnMute 60 Vsync!!!\n"));
6232                             eEventFlag &= (~E_MVD_EVENT_UNMUTE);
6233                             MDrv_MVD_EnableInt(eEventFlag);
6234                         }
6235                     }
6236                 }
6237                 else // for P/B frame only stream
6238                 {
6239                     if (MDrv_MVD_GetSyncStatus() == 1) //sync done
6240                     {
6241                         u32SyncDoneCnt++;
6242                     }
6243 
6244                     if (u32SyncDoneCnt > PB_ONLY_UNMUTE_VSYNC_COUNT) //sync done
6245                     {
6246                         MVD_DEBUGINFO(printf("UnMute after %d vsync!!!\n", PB_ONLY_UNMUTE_VSYNC_COUNT));
6247                         eCurEvent |= E_MVD_EVENT_UNMUTE;
6248                         eEventFlag &= (~E_MVD_EVENT_UNMUTE);
6249                         MDrv_MVD_EnableInt(eEventFlag);
6250                         u32SyncDoneCnt = 0;
6251                     }
6252                 }
6253             }
6254         }
6255 
6256         //Events that user registered occurred, call user's callback function
6257         if ((eCurEvent!=E_MVD_EVENT_DISABLE_ALL) && (pfnCallback!=NULL))
6258         {
6259             pfnCallback();
6260         }
6261     }
6262 
6263     //clear interrupt & events
6264     eCurEvent = E_MVD_EVENT_DISABLE_ALL;
6265     HAL_MVD_ClearIRQ();
6266     OSAL_MVD_IntEnable(); //enable cpu interrupt mask
6267 }
6268 
6269 //-----------------------------------------------------------------------------
6270 /// @brief \b Function \b Name: MDrv_HVD_SetISREvent()
6271 /// @brief \b Function \b Description: Set the ISR event type sended by HVD fw.
6272 /// @param -eEvent \b IN : event types
6273 /// @param -fnISRHandler \b IN : function pointer to a interrupt handler.
6274 /// @return -The result of command set ISR event.
6275 //-----------------------------------------------------------------------------
MDrv_MVD_SetIsrEvent(MS_U32 eEvent,MVD_InterruptCb fnHandler)6276 E_MVD_Result MDrv_MVD_SetIsrEvent(MS_U32 eEvent, MVD_InterruptCb fnHandler)
6277 {
6278     if (_bDrvInit != TRUE)
6279     {
6280         MVD_DEBUGERROR(printf("Call %s before Init\n", __FUNCTION__));
6281         return E_MVD_RET_FAIL;
6282     }
6283 
6284     if (eEvent == E_MVD_EVENT_DISABLE_ALL)
6285     {
6286         //HAL_MVD_Enable_ISR(FALSE);
6287         OSAL_MVD_IntDisable();
6288 #if !defined(SEC_X4)
6289         if(TRUE == bIsrAttached)
6290         {
6291             OSAL_MVD_IsrDetach();
6292             bIsrAttached = FALSE;
6293         }
6294 #endif
6295         pfnCallback = NULL;
6296         eEventFlag = E_MVD_EVENT_DISABLE_ALL;
6297     }
6298     else
6299     {
6300         if(fnHandler != NULL)
6301         {
6302             //disable int & dettach isr?
6303 
6304             pfnCallback = (MVD_InterruptCb)fnHandler;
6305             eEventFlag = eEvent;
6306             if (FALSE == bIsrAttached)
6307             {
6308                 if (OSAL_MVD_IsrAttach((void*)MVD_IsrProc) != TRUE)
6309                 {
6310                     MVD_DEBUGERROR(printf("fail to attach MVD_IsrProc!\n"));
6311                     return E_MVD_RET_FAIL;
6312                 }
6313                 bIsrAttached = TRUE;
6314                 if (OSAL_MVD_IntEnable() != TRUE)
6315                 {
6316                     MVD_DEBUGERROR(printf("fail to OSAL_MVD_IntEnable!\n"));
6317                     return E_MVD_RET_FAIL;
6318                 }
6319             }
6320 
6321             MVD_DEBUGINFO(printf("MDrv_MVD_SetIsrEvent eEventFlag=0x%lx\n", eEventFlag));
6322             MDrv_MVD_EnableInt(eEventFlag);
6323             MVD_DEBUGINFO(printf("attach ISR number:%d\n" , E_INT_IRQ_MVD));
6324             return E_MVD_RET_OK;
6325         }
6326         else
6327         {
6328             MVD_DEBUGERROR(printf( "SetISREvent with NULL pointer. ISR type:%lu\n", (MS_U32)eEvent));
6329             return E_MVD_RET_INVALID_PARAM;
6330         }
6331     }
6332     return E_MVD_RET_OK;
6333 }
6334 
6335 #endif //MVD_ENABLE_ISR
6336 
6337 
6338 //------------------------------------------------------------------------------
6339 /// Set AVSync mode for file mode.
6340 /// @param -eSyncMode: avsync mode for file mode
6341 //------------------------------------------------------------------------------
MDrv_MVD_SetFileModeAVSync(MVD_TIMESTAMP_TYPE eSyncMode)6342 MS_BOOL MDrv_MVD_SetFileModeAVSync(MVD_TIMESTAMP_TYPE eSyncMode)
6343 {
6344     _eFileSyncMode = eSyncMode;
6345     MVD_DEBUGINFO(printf("%s eSyncMode=%d\n", __FUNCTION__, _eFileSyncMode));
6346     return HAL_MVD_SetFileModeAVSync(eSyncMode);
6347 }
6348 
6349 
6350 //-----------------------------------------------------------------------------
6351 /// Is MVD firmware command finished.
6352 /// @return - TRUE/FALSE
6353 /// @retval     -FALSE(0): not finished.
6354 /// @retval     -TRUE(1): well done!
6355 //-----------------------------------------------------------------------------
MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_CMD eCmd)6356 MS_BOOL MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_CMD eCmd)
6357 {
6358 
6359     MVD_CMD_HANDSHADE_INDEX u32CmdState;
6360     MS_BOOL bCmdRdy = FALSE;
6361     MVD_FUNC_ENTRY();
6362 
6363     if(pu8MVDGetFrameInfoBufStart==0)
6364     {
6365         MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
6366         return FALSE;
6367     }
6368 
6369     u32CmdState.value = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_CMD_HANDSHAKE_INDEX);
6370     MVD_DEBUGINFO(printf("u32CmdState.value = 0x%x\n", u32CmdState.value));
6371     switch (eCmd)
6372     {
6373         case MVD_HANDSHAKE_PAUSE:
6374             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_pause);
6375             break;
6376         case MVD_HANDSHAKE_SLQ_RST:
6377             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_slq_reset);
6378             break;
6379         case MVD_HANDSHAKE_STOP:
6380             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_stop);
6381             break;
6382         case MVD_HANDSHAKE_SKIP_DATA:
6383             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_skip_data);
6384             break;
6385         case MVD_HANDSHAKE_SINGLE_STEP:
6386             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_single_step);
6387             break;
6388         case MVD_HANDSHAKE_SCALER_INFO:
6389             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_scaler_data_ready);
6390             break;
6391         case MVD_HANDSHAKE_GET_NXTDISPFRM:  //uniplayer
6392             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_get_nextdispfrm_ready);
6393             break;
6394         case MVD_HANDSHAKE_PARSER_RST:
6395             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_parser_rst);
6396             break;
6397         case MVD_HANDSHAKE_RST_CC608:
6398             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_cc608_rst);
6399             break;
6400         case MVD_HANDSHAKE_RST_CC708:
6401             bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_cc708_rst);
6402             break;
6403         default:
6404             bCmdRdy = FALSE;
6405             break;
6406     }
6407     return bCmdRdy;
6408 
6409 }
6410 
6411 //-----------------------------------------------------------------------------
6412 /// Clear MVD firmware command finished bit.
6413 /// @return - TRUE/FALSE
6414 /// @retval     -FALSE(0): not finished.
6415 /// @retval     -TRUE(1): well done!
6416 //-----------------------------------------------------------------------------
MDrv_MVD_ClearCmdFinished(MVD_HANDSHAKE_CMD eCmd)6417 static MS_BOOL MDrv_MVD_ClearCmdFinished(MVD_HANDSHAKE_CMD eCmd)
6418 {
6419 
6420     MVD_CMD_HANDSHADE_INDEX u32CmdState;
6421     MVD_FUNC_ENTRY();
6422 
6423     if(pu8MVDGetFrameInfoBufStart==0)
6424     {
6425         MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
6426         return FALSE;
6427     }
6428 
6429     u32CmdState.value = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_CMD_HANDSHAKE_INDEX);
6430     MVD_DEBUGINFO(printf("before CLR u32CmdState.value = 0x%x\n", u32CmdState.value));
6431 
6432     if (MVD_HANDSHAKE_SCALER_INFO == eCmd)
6433     {
6434         u32CmdState.mvdcmd_handshake_scaler_data_ready = 0;
6435         //write the value back: may it overwrite the value that f/w is supposed to write?
6436         HAL_MVD_MemWrite4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_CMD_HANDSHAKE_INDEX, u32CmdState.value);
6437         MVD_DEBUGINFO(printf("after CLR u32CmdState.value = 0x%lx\n",
6438                       HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_CMD_HANDSHAKE_INDEX)));
6439     }
6440 
6441     return TRUE;
6442 }
6443 
6444 
6445 //-----------------------------------------------------------------------------
6446 /// @brief Check if all of the buffers(display, decoded, bitstream) are empty.
6447 /// @return - TRUE / FALSE
6448 /// @retval     -FALSE(0): Not Empty.
6449 /// @retval     -TRUE(1): Empty.
6450 //-----------------------------------------------------------------------------
MDrv_MVD_IsAllBufferEmpty(void)6451 MS_BOOL MDrv_MVD_IsAllBufferEmpty(void)
6452 {
6453     MVD_DEBUGINFO(printf("%s stat=0x%x, cmd=0x%x\n", __FUNCTION__,
6454                   MDrv_MVD_GetDecodeStatus(), MDrv_MVD_GetLastCmd()));
6455 #if defined(CHIP_T2)
6456     return ((MDrv_MVD_GetDecodeStatus()!=E_MVD_STAT_FIND_SPECIALCODE)
6457          && (MDrv_MVD_GetDecodeStatus()!=E_MVD_STAT_WAIT_VDFIFO)
6458          && (MDrv_MVD_GetLastCmd()==CMD_PAUSE));
6459 #else
6460     return MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SKIP_DATA);
6461 #endif
6462 }
6463 
6464 
6465 //-----------------------------------------------------------------------------
6466 /// @brief Generate specific pattern to support some special function.
6467 /// @param -u32VAddr \b IN : the virtual address of specific pattern
6468 /// @param -u32Size \b IN, OUT :
6469 ///                             IN: the input array size.
6470 ///                             OUT: the used array size.
6471 /// @return -The result of command generate specific pattern
6472 //-----------------------------------------------------------------------------
MDrv_MVD_GenPattern(MVD_PatternType ePattern,MS_PHYADDR u32PAddr,MS_U32 * pu32Size)6473 MS_BOOL MDrv_MVD_GenPattern(MVD_PatternType ePattern, MS_PHYADDR u32PAddr, MS_U32* pu32Size)
6474 {
6475     MS_U32* pu32DummyData = NULL;
6476 
6477     if ((!pu32Size) || (*pu32Size < SKIP_PATTERN_SIZE))
6478     {
6479         return FALSE;
6480     }
6481 
6482     pu32DummyData = (MS_U32 *) HAL_MVD_PA2NonCacheSeg(u32PAddr);
6483 
6484     switch (ePattern)
6485     {
6486         case E_MVD_PATTERN_FLUSH:
6487             *pu32DummyData = SKIP_PATTERN_0;
6488             pu32DummyData++;
6489             *pu32DummyData = SKIP_PATTERN_1;
6490             *pu32Size = SKIP_PATTERN_SIZE;
6491             //printf("##########FLUSH!, 0x%lx 0x%lx\n",*pu32DummyData, *(pu32DummyData-1));
6492             break;
6493         case E_MVD_PATTERN_FILEEND:
6494             if ((E_MVD_CODEC_FLV == curCodecType)||(E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER == curCodecType))
6495             {
6496                 *pu32DummyData = FLV_PATTERN;
6497                 pu32DummyData++;
6498                 *pu32DummyData = 0xffffffff;
6499                 pu32DummyData++;
6500                 *pu32DummyData = END_PATTERN_1;
6501                 pu32DummyData++;
6502                 *pu32DummyData = END_PATTERN_2;
6503                 pu32DummyData++;
6504                 *pu32DummyData = END_PATTERN_3;
6505                 //printf("##########FileEnd for FLV/SVH!, *pu32DummyData=%lx\n",*pu32DummyData);
6506             }
6507             else if (E_MVD_CODEC_DIVX311 == curCodecType)
6508             {
6509                 *pu32DummyData = DIVX_PATTERN;
6510                 pu32DummyData++;
6511                 *pu32DummyData = 0xffffffff;
6512                 pu32DummyData++;
6513                 *pu32DummyData = END_PATTERN_1;
6514                 pu32DummyData++;
6515                 *pu32DummyData = END_PATTERN_2;
6516                 pu32DummyData++;
6517                 *pu32DummyData = END_PATTERN_3;
6518                 //printf("##########FileEnd for DIVX311!, *pu32DummyData=%lx\n",*pu32DummyData);
6519             }
6520             else if ((E_MVD_CODEC_MPEG2 == curCodecType)||(E_MVD_CODEC_MPEG4 == curCodecType))
6521             {
6522                 *pu32DummyData = MPEG_PATTERN_0;
6523                 pu32DummyData++;
6524                 *pu32DummyData = END_PATTERN_1;
6525                 pu32DummyData++;
6526                 *pu32DummyData = END_PATTERN_2;
6527                 pu32DummyData++;
6528                 *pu32DummyData = END_PATTERN_3;
6529                 //printf("##########FileEnd for MPEG2/4!, *pu32DummyData=%lx\n",*pu32DummyData);
6530             }
6531             else
6532             {
6533                 *pu32DummyData = END_PATTERN_0;
6534                 pu32DummyData++;
6535                 *pu32DummyData = END_PATTERN_1;
6536                 pu32DummyData++;
6537                 *pu32DummyData = END_PATTERN_2;
6538                 pu32DummyData++;
6539                 *pu32DummyData = END_PATTERN_3;
6540                 //printf("##########FileEnd for VC1!, *pu32DummyData=%lx\n",*pu32DummyData);
6541             }
6542             *pu32Size = 16;
6543             break;
6544         default:
6545             break;
6546     }
6547 
6548     return TRUE;
6549 }
6550 
6551 
6552 //-----------------------------------------------------------------------------
6553 /// @brief Get driver specific data information
6554 /// @return -the information of choosed type
6555 //-----------------------------------------------------------------------------
MDrv_MVD_GetPatternInfo(void)6556 MS_U32 MDrv_MVD_GetPatternInfo(void)
6557 {
6558     return MVD_U32_MAX;
6559 }
6560 
6561 //-----------------------------------------------------------------------------
6562 /// @brief Pass scalar parameters to f/w
6563 /// @return -The result of command.
6564 //-----------------------------------------------------------------------------
MDrv_MVD_SetDynScalingParam(MS_PHYADDR u32StAddr,MS_U32 u32Size)6565 E_MVD_Result MDrv_MVD_SetDynScalingParam(MS_PHYADDR u32StAddr, MS_U32 u32Size)
6566 {
6567 
6568     #define SCALER_INFO_TIMEOUT 0x1000
6569     MS_U32 u32TimeOut = 0;
6570     MS_U32 u32SrcAdd = NULL;
6571     MS_U32 i;
6572 
6573     if ((u32StAddr==NULL) || (u32Size==0) || (u32Size>MVD_FW_SCALER_INFO_BUF_LEN))
6574     {
6575         MVD_DEBUGERROR(printf("%s invalid para u32StAddr=0x%lx, u32Size=0x%lx\n",
6576                        __FUNCTION__, u32StAddr, u32Size));
6577         return E_MVD_RET_INVALID_PARAM;
6578     }
6579     if (TRUE != stMemCfg.bEnableDynScale)
6580     {
6581         MVD_DEBUGERROR(printf("%s !bEnableDynScale\n", __FUNCTION__));
6582         return E_MVD_RET_FAIL;
6583     }
6584 
6585     //copy data
6586     u32SrcAdd = HAL_MVD_PA2NonCacheSeg(u32StAddr);
6587     u32Size = ((u32Size+3)>>2)<<2;
6588     MVD_DEBUGINFO(printf("u32Size= 0x%lx, u32SrcAdd= 0x%lx\n", u32Size, u32SrcAdd));
6589     for (i=0; i<u32Size; i=i+4)
6590     {
6591         HAL_MVD_MemWrite4Byte(u32ScalerInfoAdd+i, *(volatile MS_U32*)(u32SrcAdd+i));
6592         MVD_DEBUGINFO(printf("0x%lx = 0x%lx\n", u32ScalerInfoAdd+i, HAL_MVD_MemRead4Byte(u32ScalerInfoAdd+i)));
6593     }
6594 
6595     //notify f/w
6596     if (TRUE!=HAL_MVD_SetScalerInfoAddr(u32ScalerInfoAdd)) //Set the buffer address (MIU offset) to f/w
6597     {
6598         MVD_DEBUGERROR(printf("%s fail to set ScalerInfoAdd\n", __FUNCTION__));
6599         return E_MVD_RET_FAIL;
6600     }
6601 
6602     //check f/w already handle the data
6603     while((TRUE!=MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_SCALER_INFO)) && (u32TimeOut < SCALER_INFO_TIMEOUT))
6604     {
6605         u32TimeOut++;
6606     }
6607     if(u32TimeOut >= SCALER_INFO_TIMEOUT)
6608     {
6609         MVD_DEBUGERROR(printf("%s timeout!!!\n", __FUNCTION__));
6610         return E_MVD_RET_FAIL;
6611     }
6612 
6613     //clear ack bit
6614     MDrv_MVD_ClearCmdFinished(MVD_HANDSHAKE_SCALER_INFO);
6615 
6616     MVD_DEBUGINFO(printf("=====> %s u32TimeOut = 0x%lx\n", __FUNCTION__, u32TimeOut));
6617     return E_MVD_RET_OK;
6618 
6619 }
6620 
6621 //------------------------------------------------------------------------------
6622 /// Set the dynamic scale base address
6623 /// @return -TRUE for success; FALSE for failure.
6624 //------------------------------------------------------------------------------
MDrv_MVD_SetDynamicScaleAddr(MS_U32 u32addr)6625 MS_BOOL MDrv_MVD_SetDynamicScaleAddr(MS_U32 u32addr)
6626 {
6627     MS_U32 u32offset;
6628     u32offset = MVD_GetMemOffset(u32addr);
6629     return HAL_MVD_SetDynamicScaleAddr(u32offset);
6630 }
6631 
6632 //------------------------------------------------------------------------------
6633 /// Set virtual box width/height to F/W.
6634 /// F/W will use the same w/h as scaler to calculate scaling factor.
6635 /// @return -TRUE for success; FALSE for failure.
6636 //------------------------------------------------------------------------------
MDrv_MVD_SetVirtualBox(MS_U16 u16Width,MS_U16 u16Height)6637 MS_BOOL MDrv_MVD_SetVirtualBox(MS_U16 u16Width, MS_U16 u16Height)
6638 {
6639     MVD_DEBUGINFO(printf("%s: w=0x%x h=0x%x\n", __FUNCTION__, u16Width, u16Height));
6640     return HAL_MVD_SetVirtualBox(u16Width, u16Height);
6641 }
6642 
6643 //------------------------------------------------------------------------------
6644 /// Set blue screen
6645 /// @return -TRUE for success; FALSE for failure.
6646 //------------------------------------------------------------------------------
MDrv_MVD_SetBlueScreen(MS_BOOL bEn)6647 MS_BOOL MDrv_MVD_SetBlueScreen(MS_BOOL bEn)
6648 {
6649     return HAL_MVD_SetBlueScreen(bEn);
6650 }
6651 
6652 //------------------------------------------------------------------------------
6653 /// Enable/Disable VSync interrupt
6654 /// @return -TRUE for success; FALSE for failure.
6655 //------------------------------------------------------------------------------
MDrv_MVD_EnableInt(MS_U32 bEn)6656 MS_BOOL MDrv_MVD_EnableInt(MS_U32 bEn)
6657 {
6658 
6659     MVD_CmdArg mvdcmd;
6660     MS_U16 u16IntFlag = 0;
6661 
6662     u16IntFlag = (((bEn & E_MVD_EVENT_USER_DATA) == E_MVD_EVENT_USER_DATA) ? INT_USER_DATA : 0) |
6663                  (((bEn & E_MVD_EVENT_USER_DATA_DISP) == E_MVD_EVENT_USER_DATA_DISP) ? INT_USER_DATA_DISP : 0) |
6664                  (((bEn & E_MVD_EVENT_PIC_FOUND) == E_MVD_EVENT_PIC_FOUND) ? INT_PIC_FOUND : 0) |
6665                  (((bEn & E_MVD_EVENT_FIRST_FRAME) == E_MVD_EVENT_FIRST_FRAME) ? INT_FIRST_FRAME : 0) |
6666                  (((bEn & E_MVD_EVENT_DISP_RDY) == E_MVD_EVENT_DISP_RDY) ? INT_DISP_RDY : 0) |
6667                  (((bEn & E_MVD_EVENT_SEQ_FOUND) == E_MVD_EVENT_SEQ_FOUND) ? INT_SEQ_FOUND : 0)|
6668                  (((bEn & E_MVD_EVENT_DEC_I) == E_MVD_EVENT_DEC_I) ? INT_DEC_I : 0);
6669     if (((bEn & E_MVD_EVENT_DISP_VSYNC) == E_MVD_EVENT_DISP_VSYNC) ||
6670         ((bEn & E_MVD_EVENT_UNMUTE) == E_MVD_EVENT_UNMUTE))
6671     {
6672         u16IntFlag |= INT_DISP_VSYNC;
6673     }
6674 
6675     MVD_DEBUGINFO(printf("u16IntFlag = 0x%x\n", u16IntFlag));
6676     SETUP_CMDARG(mvdcmd);
6677     mvdcmd.Arg0 = u16IntFlag & 0xff;
6678     mvdcmd.Arg1 = (u16IntFlag>>8) & 0xff;
6679     if (HAL_MVD_MVDCommand(CMD_ENABLE_INT_STAT, &mvdcmd ) == FALSE)
6680     {
6681         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_INT_STAT ) );
6682         return FALSE;
6683     }
6684 
6685     return TRUE;
6686 }
6687 
6688 //------------------------------------------------------------------------------
6689 /// Enable FW only show one field.
6690 /// @return -TRUE for success; FALSE for failure.
6691 //------------------------------------------------------------------------------
MDrv_MVD_EnableDispOneField(MS_BOOL bEn)6692 E_MVD_Result MDrv_MVD_EnableDispOneField(MS_BOOL bEn)
6693 {
6694 #if defined(CHIP_T2) || defined(CHIP_T7)
6695     return E_MVD_RET_FAIL;
6696 #else
6697     MVD_CmdArg stCmdArg;
6698 
6699     MVD_FUNC_ENTRY();
6700     SETUP_CMDARG(stCmdArg);
6701     if(TRUE == bEn)
6702     {
6703         stCmdArg.Arg0 = 1;
6704     }
6705     if (HAL_MVD_MVDCommand(CMD_SHOW_ONE_FIELD, &stCmdArg) == FALSE)
6706     {
6707         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SHOW_ONE_FIELD ) );
6708         return E_MVD_RET_FAIL;
6709     }
6710     return E_MVD_RET_OK;
6711 #endif
6712 }
6713 
6714 
MVD_RstFrmInfo(MVD_FrmInfoType eType)6715 static E_MVD_Result MVD_RstFrmInfo(MVD_FrmInfoType eType)
6716 {
6717     E_MVD_Result eRet = E_MVD_RET_OK;
6718     if (NULL == u32DecFrmInfoAdd)
6719     {
6720         return E_MVD_RET_FAIL;
6721     }
6722 
6723     //printf("%s u32DecFrmInfoAdd = 0x%lx\n", __FUNCTION__, u32DecFrmInfoAdd);
6724 
6725     if (E_MVD_FRMINFO_DECODE == eType)
6726     {
6727         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_LUMAADDR), _INIT_ADDR);
6728         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_CHROMAADDR), _INIT_ADDR);
6729         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_TIMESTAMP), _INIT_TIMESTAMP);
6730         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_L), _INIT_ID);
6731         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_H), _INIT_ID);
6732         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_PITCH), _INIT_LEN);
6733         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_WIDTH), _INIT_LEN);
6734         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_HEIGHT), _INIT_LEN);
6735         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_FRAMETYPE), 0xff);
6736     }
6737     else if (E_MVD_FRMINFO_DISPLAY == eType)
6738     {
6739         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_LUMAADDR), _INIT_ADDR);
6740         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_CHROMAADDR), _INIT_ADDR);
6741         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_TIMESTAMP), _INIT_TIMESTAMP);
6742         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_L), _INIT_ID);
6743         HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_H), _INIT_ID);
6744         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_PITCH), _INIT_LEN);
6745         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_WIDTH), _INIT_LEN);
6746         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_HEIGHT), _INIT_LEN);
6747         HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_FRAMETYPE), 0xff);
6748     }
6749     else
6750     {
6751         eRet = E_MVD_RET_INVALID_PARAM;
6752     }
6753 
6754     return eRet;
6755 }
6756 
6757 
MVD_IsNextDispFrmRdy(void)6758 static MS_BOOL MVD_IsNextDispFrmRdy(void)
6759 {
6760     #define NXT_DISP_TIMEOUT 20000//0x20
6761     MS_U32 u32TimeOut = 0;
6762     MVD_CmdArg mvdcmd;
6763 
6764     MVD_FUNC_ENTRY();
6765     SETUP_CMDARG(mvdcmd);
6766     if (HAL_MVD_MVDCommand(CMD_GET_NEXTDISPFRM, &mvdcmd)== FALSE)
6767     {
6768         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_GET_NEXTDISPFRM) );
6769         return FALSE;
6770     }
6771     //HAL_MVD_Delayms(4);
6772 
6773     while((TRUE != MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_GET_NXTDISPFRM))
6774         && (u32TimeOut < NXT_DISP_TIMEOUT))
6775     {
6776         u32TimeOut++;
6777     }
6778     if(u32TimeOut >= NXT_DISP_TIMEOUT)
6779     {
6780         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_NEXTDISPFRM ) );
6781         return FALSE;
6782     }
6783     return TRUE;
6784 }
6785 
6786 //------------------------------------------------------------------------------
6787 /// Get extension info of the display .
6788 /// @return -TRUE for success; FALSE for failure.
6789 //------------------------------------------------------------------------------
MDrv_MVD_GetExtDispInfo(MVD_ExtDispInfo * pInfo)6790 E_MVD_Result MDrv_MVD_GetExtDispInfo(MVD_ExtDispInfo* pInfo)
6791 {
6792     E_MVD_Result eRet = E_MVD_RET_OK;
6793     if (NULL == pInfo)
6794     {
6795         MVD_DEBUGERROR(printf("GetExtDispInfo NULL pInfo!\n"));
6796         return E_MVD_RET_INVALID_PARAM;
6797     }
6798 
6799     if (pu8MVDGetFrameInfoBufStart==0)
6800     {
6801         MVD_DEBUGERROR(printf("GetExtDispInfo NULL pu8MVDGetFrameInfoBufStart!\n"));
6802         return E_MVD_RET_FAIL;
6803     }
6804 
6805     pInfo->u16VSize  = HAL_MVD_MemRead2Byte(pu8MVDGetFrameInfoBufStart+OFFSET_DISP_V_SIZE);
6806     pInfo->u16HSize  = HAL_MVD_MemRead2Byte(pu8MVDGetFrameInfoBufStart+OFFSET_DISP_H_SIZE);
6807     pInfo->u16VOffset = HAL_MVD_MemRead2Byte(pu8MVDGetFrameInfoBufStart+OFFSET_CENTRE_V_OFFSET);
6808     pInfo->u16HOffset = HAL_MVD_MemRead2Byte(pu8MVDGetFrameInfoBufStart+OFFSET_CENTRE_H_OFFSET);
6809 
6810     return eRet;
6811 }
6812 
6813 //------------------------------------------------------------------------------
6814 /// Get info of the decoded/displaying frame.
6815 /// @return -TRUE for success; FALSE for failure.
6816 //------------------------------------------------------------------------------
MDrv_MVD_GetFrmInfo(MVD_FrmInfoType eType,MVD_FrmInfo * pInfo)6817 E_MVD_Result MDrv_MVD_GetFrmInfo(MVD_FrmInfoType eType, MVD_FrmInfo* pInfo)
6818 {
6819     E_MVD_Result eRet = E_MVD_RET_OK;
6820     if (NULL == pInfo)
6821     {
6822         MVD_DEBUGERROR(printf("GetFrmInfo NULL pInfo!\n"));
6823         return E_MVD_RET_INVALID_PARAM;
6824     }
6825     if (NULL == u32DecFrmInfoAdd)
6826     {
6827         MVD_DEBUGERROR(printf("GetFrmInfo NULL u32DecFrmInfoAdd!\n"));
6828         return E_MVD_RET_FAIL;
6829     }
6830 
6831     //printf("%s u32DecFrmInfoAdd = 0x%lx\n", __FUNCTION__, u32DecFrmInfoAdd);
6832 
6833     if (E_MVD_FRMINFO_DECODE == eType)
6834     {
6835         pInfo->u32LumaAddr  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_LUMAADDR);
6836         pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_CHROMAADDR);
6837         pInfo->u32TimeStamp = _90K_TO_MS(HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_TIMESTAMP));
6838         pInfo->u32ID_L  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_L);
6839         pInfo->u32ID_H  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_H);
6840         pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_PITCH);
6841         pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_WIDTH);
6842         pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_HEIGHT);
6843         pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_FRAMETYPE);
6844     }
6845     else if (E_MVD_FRMINFO_DISPLAY == eType)
6846     {
6847         pInfo->u32LumaAddr  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_LUMAADDR);
6848         pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_CHROMAADDR);
6849         pInfo->u32TimeStamp = _90K_TO_MS(HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_TIMESTAMP));
6850         pInfo->u32ID_L  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_L);
6851         pInfo->u32ID_H  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_H);
6852         pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_PITCH);
6853         pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_WIDTH);
6854         pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_HEIGHT);
6855         pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_FRAMETYPE);
6856     }
6857 
6858     else if (E_MVD_FRMINFO_NEXT_DISPLAY == eType)
6859     {
6860         if (!MVD_IsNextDispFrmRdy())
6861         {
6862             MVD_DEBUGINFO(printf("NextDispFrm not ready!\n"));
6863             return E_MVD_RET_FAIL;
6864         }
6865         pInfo->u16FrmIdx= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_FRAMEIDX);
6866         if (pInfo->u16FrmIdx  == 0xFFFF)
6867         {
6868             MVD_DEBUGINFO(printf("GetFrmInfo no available frame!\n"));
6869             return E_MVD_RET_FAIL;
6870         }
6871         pInfo->u32LumaAddr  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_LUMAADDR);
6872         pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_CHROMAADDR);
6873         // 64BIT_PTS = (TimeStamp | (ID_H<<32)) , unit: 90K
6874         pInfo->u32TimeStamp = (HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_TIMESTAMP));
6875         pInfo->u32ID_L  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_ID_L);
6876         pInfo->u32ID_H  = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_ID_H);
6877         pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_PITCH);
6878         pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_WIDTH);
6879         pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_HEIGHT);
6880         pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_FRAMETYPE);
6881 
6882 #if 0
6883     printf("NxtFrm:: Idx=0x%x, ", pInfo->u16FrmIdx);
6884     printf("Type=0x%x, ", pInfo->eFrmType      );
6885     printf("Luma=0x%lx, ", pInfo->u32LumaAddr  );
6886     printf("Chroma=0x%lx, ", pInfo->u32ChromaAddr);
6887     printf("Pts=%lu, ", pInfo->u32TimeStamp );
6888     printf("ID_H=%lu, ", pInfo->u32ID_H      );
6889     printf("ID_L=0x%lx\n", pInfo->u32ID_L      );
6890 #endif
6891         MVD_DBG_STS(printf("<<< drvMVD pts,idH = %lu, %lu\n", pInfo->u32TimeStamp, pInfo->u32ID_H));
6892         //MVD_DumpFrmInfo(pInfo);
6893     }
6894     else
6895     {
6896         eRet = E_MVD_RET_INVALID_PARAM;
6897     }
6898 
6899     if ((pInfo->u32LumaAddr  == _INIT_ADDR) || (pInfo->u32ChromaAddr== _INIT_ADDR) ||
6900         (pInfo->u16Pitch == _INIT_LEN) || (pInfo->u16Width == _INIT_LEN) ||
6901         (pInfo->u16Height== _INIT_LEN))
6902     {
6903         MVD_DEBUGINFO(printf("GetFrmInfo not ready!\n"));
6904         return E_MVD_RET_FAIL;
6905     }
6906 
6907     if (stMemCfg.bHWMiuSel == MIU_SEL_0)
6908     {
6909         pInfo->u32LumaAddr = pInfo->u32LumaAddr * 8;
6910         pInfo->u32ChromaAddr = pInfo->u32ChromaAddr * 8;
6911     }
6912     else
6913     {
6914         pInfo->u32LumaAddr = pInfo->u32LumaAddr * 8 + stMemCfg.u32Miu1BaseAddr;
6915         pInfo->u32ChromaAddr = pInfo->u32ChromaAddr * 8 + stMemCfg.u32Miu1BaseAddr;
6916     }
6917 
6918     //printf("===> Luma=0x%lx, Chroma=0x%lx\n", pInfo->u32LumaAddr, pInfo->u32ChromaAddr);
6919     return eRet;
6920 }
6921 
6922 //------------------------------------------------------------------------------
6923 /// Get time_code of the decoded/displaying frame.
6924 /// @return -TRUE for success; FALSE for failure.
6925 //------------------------------------------------------------------------------
MDrv_MVD_GetTimeCode(MVD_FrmInfoType eType,MVD_TimeCode * pInfo)6926 E_MVD_Result MDrv_MVD_GetTimeCode(MVD_FrmInfoType eType, MVD_TimeCode* pInfo)
6927 {
6928     E_MVD_Result eRet = E_MVD_RET_OK;
6929     if (NULL == pInfo)
6930     {
6931         return E_MVD_RET_INVALID_PARAM;
6932     }
6933     if (NULL == pu8MVDGetFrameInfoBufStart)
6934     {
6935         MVD_DEBUGERROR(printf("MDrv_MVD_GetTimeCode error: pu8MVDGetFrameInfoBufStart=NULL\n"));
6936         return E_MVD_RET_FAIL;
6937     }
6938 
6939     if (E_MVD_FRMINFO_DECODE == eType)
6940     {
6941         pInfo->u8TimeCodeHr  = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_HOURS);
6942         pInfo->u8TimeCodeMin = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_MINUTES);
6943         pInfo->u8TimeCodeSec = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_SECONDS);
6944         pInfo->u8TimeCodePic = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_PICTURES);
6945         pInfo->u8DropFrmFlag = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_DROP_FRAME_FLAG);
6946     }
6947     else if (E_MVD_FRMINFO_DISPLAY == eType)
6948     {
6949         pInfo->u8TimeCodeHr  = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_HOURS_DISP);
6950         pInfo->u8TimeCodeMin = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_MINUTES_DISP);
6951         pInfo->u8TimeCodeSec = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_SECONDS_DISP);
6952         pInfo->u8TimeCodePic = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_PICTURES_DISP);
6953         pInfo->u8DropFrmFlag = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_DROP_FRAME_FLAG_DISP);
6954     }
6955     else
6956     {
6957         eRet = E_MVD_RET_INVALID_PARAM;
6958     }
6959 
6960     return eRet;
6961 }
6962 
MDrv_MVD_GetUsrDataIsAvailable(void)6963 MS_BOOL MDrv_MVD_GetUsrDataIsAvailable(void)
6964 {
6965 #if defined(MVD_SUPPORT_X4_CC)
6966     u32UsrDataWr = MDrv_CC_CM_GetMVDRB_HWAddr(4)>>3;
6967 #else
6968     u32UsrDataWr = MDrv_CC_CM_GetMVDRB_HWAddr(2)>>3;
6969 #endif
6970 
6971     MVD_DEBUGINFO(printf("IsAvail:%x rd=%lx wr=%lx\n", !(u32UsrDataRd == u32UsrDataWr), u32UsrDataRd, u32UsrDataWr));
6972     return !(u32UsrDataRd == u32UsrDataWr);
6973 }
6974 
6975 //------------------------------------------------------------------------------
6976 /// Get info of user data
6977 //------------------------------------------------------------------------------
MDrv_MVD_GetUsrDataInfo(MVD_UsrDataInfo * pUsrInfo)6978 MS_BOOL MDrv_MVD_GetUsrDataInfo(MVD_UsrDataInfo* pUsrInfo)
6979 {
6980 #if defined(MVD_SUPPORT_X4_CC)
6981     FW_USER_DATA_BUF_EXT stUsrDataExt;
6982 #else
6983     FW_USER_DATA_BUF stUsrDataInfo;
6984 #endif
6985 
6986     if ((!pUsrInfo) || (pu8MVDGetFrameInfoBufStart==0))
6987     {
6988         MVD_DEBUGERROR(printf("%s: NULL ptr.\n", __FUNCTION__));
6989         return FALSE;
6990     }
6991 
6992     //get write pointer
6993 #if defined(MVD_SUPPORT_X4_CC)
6994     u32UsrDataWr = MDrv_CC_CM_GetMVDRB_HWAddr(4)>>3;
6995 #else
6996     u32UsrDataWr = MDrv_CC_CM_GetMVDRB_HWAddr(2)>>3;
6997 #endif
6998     if (u32UsrDataRd == (_stInternalMemCfg.u32UserDataBuf+MVD3_FW_USER_DATA_BUF_LEN))
6999     {
7000         u32UsrDataRd = _stInternalMemCfg.u32UserDataBuf; //wrap to BufStart
7001     }
7002     MVD_DEBUGINFO(printf("CC Rd=0x%lx Wr=0x%lx\n", u32UsrDataRd, u32UsrDataWr));
7003 
7004     if (u32UsrDataRd == u32UsrDataWr)
7005     {
7006         MVD_DEBUGERROR(printf("%s: no data?\n", __FUNCTION__));
7007         return FALSE;
7008     }
7009 
7010     //miuOffset --> physical add --> noncached add
7011     u32UsrData = (stMemCfg.bFWMiuSel==MIU_SEL_1)?(u32UsrDataRd+stMemCfg.u32Miu1BaseAddr):(u32UsrDataRd);
7012     u32UsrData = HAL_MVD_PA2NonCacheSeg(u32UsrData);
7013 
7014     HAL_MVD_CPU_Sync();
7015     HAL_MVD_ReadMemory();
7016 
7017 #if defined(MVD_SUPPORT_X4_CC)
7018     stUsrDataExt = *(volatile FW_USER_DATA_BUF_EXT*)u32UsrData;
7019 
7020     pUsrInfo->u32Pts = stUsrDataExt.pts;
7021     pUsrInfo->u8PicStruct = stUsrDataExt.PicStruct;
7022     pUsrInfo->u8PicType   = stUsrDataExt.picType;
7023     pUsrInfo->u8TopFieldFirst = stUsrDataExt.top_ff;
7024     pUsrInfo->u8RptFirstField = stUsrDataExt.rpt_ff;
7025     pUsrInfo->u16TmpRef = stUsrDataExt.tmpRef;
7026     pUsrInfo->u8ByteCnt = stUsrDataExt.userdatabytecnt;
7027     pUsrInfo->u32DataBuf = u32UsrData + MVD_FW_USER_DATA_EXT_HDR_LEN;
7028 #else
7029     stUsrDataInfo = *(volatile FW_USER_DATA_BUF*)u32UsrData;
7030 
7031     //pUsrInfo->u8PicStruct = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_PICTURE_STRUCTURE);
7032     pUsrInfo->u8PicType   = stUsrDataInfo.picType;
7033     pUsrInfo->u8TopFieldFirst = stUsrDataInfo.top_ff;
7034     pUsrInfo->u8RptFirstField = stUsrDataInfo.rpt_ff;
7035     pUsrInfo->u16TmpRef = stUsrDataInfo.tmpRef;
7036     pUsrInfo->u8ByteCnt = stUsrDataInfo.userdatabytecnt;
7037     pUsrInfo->u32DataBuf = u32UsrData + MVD_FW_USER_DATA_HDR_LEN;
7038 #endif
7039     //update read pointer
7040     u32UsrDataRd += MVD_FW_USER_DATA_PKT_LEN;
7041 #if 0
7042     printf("xxInfo: ");
7043     printf("%d, ", pUsrInfo->u16TmpRef);
7044     printf("%d, ", pUsrInfo->u8PicStruct);
7045     printf("%d, ", pUsrInfo->u8TopFieldFirst);
7046     printf("0x%lx, ", pUsrInfo->u32DataBuf);
7047     printf("%d, ", pUsrInfo->u8ByteCnt);
7048     printf("%ld, ", pUsrInfo->u32Pts);
7049     printf("%d\n", pUsrInfo->u8PicType);
7050 #endif
7051     return TRUE;
7052 }
7053 
7054 //------------------------------------------------------------------------------
7055 /// Enable/Disable freezing display
7056 /// Once this flag is set, firmware continue decode new frame
7057 /// but not to push this frame into display queue.
7058 /// @return -TRUE for success; FALSE for failure.
7059 //------------------------------------------------------------------------------
MDrv_MVD_SetFreezeDisp(MS_BOOL bEn)7060 E_MVD_Result MDrv_MVD_SetFreezeDisp(MS_BOOL bEn)
7061 {
7062     MDrv_MVD_SetSpeed(E_MVD_SPEED_DEFAULT, 1);
7063     if (TRUE == HAL_MVD_SetFreezeDisp(bEn))
7064         return E_MVD_RET_OK;
7065     else
7066         return E_MVD_RET_FAIL;
7067 }
7068 
7069 
7070 //------------------------------------------------------------------------------
7071 /// Get MVD displayed picture counter
7072 /// @return - displayed picture counter
7073 //------------------------------------------------------------------------------
MDrv_MVD_GetDispCount(void)7074 MS_U32 MDrv_MVD_GetDispCount(void)
7075 {
7076 #if defined(CHIP_T2) || defined(CHIP_T7)
7077     return 0;
7078 #else
7079     MVD_FUNC_ENTRY();
7080     if(pu8MVDGetFrameInfoBufStart==0)
7081     {
7082         MVD_DEBUGERROR(printf("MDrv_MVD_GetDispCount error: pu8MVDGetFrameInfoBufStart=NULL\n"));
7083         return 0;
7084     }
7085 
7086     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_DISPLAYED_CNT);
7087 #endif
7088 }
7089 
7090 
7091 //------------------------------------------------------------------------------
7092 /// Set MVD fd mask delay count
7093 /// 16bits and unit in vsync for mute the fd_mask
7094 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
7095 //------------------------------------------------------------------------------
MDrv_MVD_SetFdMaskDelayCount(MS_U16 u16Cnt)7096 E_MVD_Result MDrv_MVD_SetFdMaskDelayCount(MS_U16 u16Cnt)
7097 {
7098 #if defined(CHIP_T2) || defined(CHIP_T7)
7099     return E_MVD_RET_FAIL;
7100 #else
7101     MVD_CmdArg stCmdArg;
7102 
7103     MVD_FUNC_ENTRY();
7104     SETUP_CMDARG(stCmdArg);
7105 
7106     //16bits and unit in vsync for mute the fd_mask
7107     stCmdArg.Arg0 = u16Cnt & 0xff;
7108     stCmdArg.Arg1 = (u16Cnt>>8) & 0xff;
7109 
7110     if (HAL_MVD_MVDCommand(CMD_FD_MASK_DELAY_CNT, &stCmdArg) == FALSE)
7111     {
7112         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FD_MASK_DELAY_CNT ) );
7113         return E_MVD_RET_FAIL;
7114     }
7115     return E_MVD_RET_OK;
7116 #endif
7117 }
7118 
7119 //------------------------------------------------------------------------------
7120 /// Set MVD output frame rate convert
7121 /// @param u8FrameRate \b IN : output frame rate of 8bits and unit in vsync
7122 /// @param u8Interlace \b IN : scan style 0:progress, 1:interlace
7123 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
7124 //------------------------------------------------------------------------------
MDrv_MVD_SetOutputFRCMode(MS_U8 u8FrameRate,MS_U8 u8Interlace)7125 E_MVD_Result MDrv_MVD_SetOutputFRCMode(MS_U8 u8FrameRate, MS_U8 u8Interlace)
7126 {
7127 #if defined(CHIP_T7)
7128     return E_MVD_RET_FAIL;
7129 #else
7130     MVD_CmdArg stCmdArg;
7131 
7132     MVD_FUNC_ENTRY();
7133 
7134     MVD_DEBUGINFO(printf("%s u8Interlace is unused.\n", __FUNCTION__));
7135 
7136     SETUP_CMDARG(stCmdArg);
7137     stCmdArg.Arg0 = u8FrameRate;
7138     if (HAL_MVD_MVDCommand(CMD_FRC_OUPUT, &stCmdArg) == FALSE)
7139     {
7140         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRC_OUPUT ) );
7141         return E_MVD_RET_FAIL;
7142     }
7143     return E_MVD_RET_OK;
7144 #endif
7145 }
7146 
7147 //------------------------------------------------------------------------------
7148 /// Set MVD FRC drop type.
7149 /// @param u8DropType \b IN : drop type. 0:drop frame, 1:drop field. default:0
7150 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
7151 //------------------------------------------------------------------------------
MDrv_MVD_SetFRCDropType(MS_U8 u8DropType)7152 E_MVD_Result MDrv_MVD_SetFRCDropType(MS_U8 u8DropType)
7153 {
7154 #if defined(CHIP_T7)
7155     return E_MVD_RET_FAIL;
7156 #else
7157     MVD_CmdArg stCmdArg;
7158 
7159     MVD_FUNC_ENTRY();
7160 
7161     if((u8DropType != FRC_DROP_FRAME)
7162     && (u8DropType != FRC_DROP_FIELD))
7163     {
7164         return E_MVD_RET_FAIL;
7165     }
7166 
7167     SETUP_CMDARG(stCmdArg);
7168 
7169     stCmdArg.Arg0 = u8DropType;
7170 
7171     if (HAL_MVD_MVDCommand(CMD_FRC_DROP_BEHAVIOR, &stCmdArg) == FALSE)
7172     {
7173         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRC_DROP_BEHAVIOR ) );
7174         return E_MVD_RET_FAIL;
7175     }
7176     return E_MVD_RET_OK;
7177 #endif
7178 }
7179 
7180 //------------------------------------------------------------------------------
7181 /// Set disable resolution change.
7182 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
7183 //------------------------------------------------------------------------------
MDrv_MVD_SetDisableSeqChange(MS_BOOL bEnable)7184 E_MVD_Result MDrv_MVD_SetDisableSeqChange(MS_BOOL bEnable)
7185 {
7186 #if defined(CHIP_T7)
7187     return E_MVD_RET_FAIL;
7188 #else
7189     MVD_CmdArg stCmdArg;
7190     MVD_FUNC_ENTRY();
7191     SETUP_CMDARG(stCmdArg);
7192     stCmdArg.Arg0 = bEnable;
7193 
7194     if (HAL_MVD_MVDCommand(0x8F, &stCmdArg) == FALSE)
7195     {
7196         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", 0x8F ) );
7197         return E_MVD_RET_FAIL;
7198     }
7199     MVD_DEBUGINFO(printf("MVD CMD_FORBID_RESOLUTION_CHANGE(0x%x) OK\n", 0x8F));
7200 
7201     return E_MVD_RET_OK;
7202 #endif
7203 }
7204 
7205 //------------------------------------------------------------------------------
MDrv_MVD_GetInternalMemCfg(void)7206 MVD_InternalMemCfg *MDrv_MVD_GetInternalMemCfg(void)
7207 {
7208     return &_stInternalMemCfg;
7209 }
7210 
7211 //------------------------------------------------------------------------------
7212 /// Debug function to dump useful info.
7213 //------------------------------------------------------------------------------
MDrv_MVD_DbgDump(void)7214 void MDrv_MVD_DbgDump(void)
7215 {
7216     MS_U32 u32VdCnt=0;
7217     static MS_U32 u32PreVdCnt=0;
7218     MS_U32 u32ErrCnt=0;
7219     static MS_U32 u32PreErrCnt=0;
7220     static MS_BOOL b1stDump = TRUE;
7221 
7222     MVD_FrmInfo stFrm = {_INIT_ADDR, _INIT_ADDR, _INIT_TIMESTAMP, _INIT_ID,
7223                          _INIT_ID, _INIT_LEN, _INIT_LEN, _INIT_LEN, 0xff, E_MVD_PIC_UNKNOWN};
7224 
7225 
7226     if (!_bDrvInit)
7227     {
7228         printf("%s: _bDrvInit false!\n", __FUNCTION__);
7229         return;
7230     }
7231 
7232     if (b1stDump)
7233     {
7234         printf("curDisablePESParsing = %d\n", curDisablePESParsing);
7235         b1stDump = FALSE;
7236     }
7237 
7238     u32VdCnt=MDrv_MVD_GetParserByteCnt();
7239     u32ErrCnt=MDrv_MVD_GetVldErrCount();
7240     printf("input: vfifo=%d(full=%d,empty=%d), vdCnt=%ld(%ld), vldErr=%ld(%ld); ",
7241             HAL_MVD_RegReadByte(0x1564)>>6, HAL_MVD_RegReadByte(0x1564)&0x20,
7242             HAL_MVD_RegReadByte(0x1564)&0x10, u32VdCnt, (u32VdCnt-u32PreVdCnt),
7243             u32ErrCnt, (u32ErrCnt-u32PreErrCnt));
7244     u32PreVdCnt = u32VdCnt;
7245     u32PreErrCnt = u32ErrCnt;
7246     printf("state: fw=0x%x, lastCmd=0x%x, pc=0x%lx\n",
7247             MDrv_MVD_GetDecodeStatus(), MDrv_MVD_GetLastCmd(), HAL_VPU_GetProgCnt());
7248     printf("seq(%d): w=%d, h=%d, i/p=%x, fps=%ld; ", MDrv_MVD_GetDispRdy(), stPreFrmInfo.u16HorSize,
7249             stPreFrmInfo.u16VerSize, stPreFrmInfo.u8Interlace, stPreFrmInfo.u32FrameRate);
7250     printf("cnt: dec=%ld, skip=%ld, drop=%ld\n", MDrv_MVD_GetPicCounter(), MDrv_MVD_GetSkipPicCounter(), 0x0UL);
7251     printf("avsync on=%x, delay=%ld, tolerance=%d, done=%x, skip=%x, repeat=%x, pts=%ldms\n",
7252             stSyncCfg.bEnable, stSyncCfg.u32Delay, stSyncCfg.u16Tolerance, (MDrv_MVD_GetSyncStatus()==1),
7253             MDrv_MVD_GetIsSyncSkip(), MDrv_MVD_GetIsSyncRep(), MDrv_MVD_GetPTS());
7254     MDrv_MVD_GetFrmInfo(E_MVD_FRMINFO_DECODE, &stFrm);
7255     printf("frm Dec Y=%lx UV=%lx Pitch=%x; ", stFrm.u32LumaAddr, stFrm.u32ChromaAddr, stFrm.u16Pitch);
7256     MDrv_MVD_GetFrmInfo(E_MVD_FRMINFO_DISPLAY, &stFrm);
7257     printf("Disp Y=%lx UV=%lx Pitch=%x\n", stFrm.u32LumaAddr, stFrm.u32ChromaAddr, stFrm.u16Pitch);
7258     if (curSrcMode == E_MVD_SLQ_TBL_MODE)
7259     {
7260         printf("fe=%lx, rd=%lx(%lx), wr=%lx, empty=%lx; ", u32FileEndPtr, _drvSlqTbl.u32RdPtr,
7261                 MVD_Map2DrvSlqTbl(MDrv_MVD_GetSLQReadPtr()), _drvSlqTbl.u32WrPtr, _drvSlqTbl.u32Empty);
7262         printf("es rd=0x%lx, wr=0x%lx\n", MDrv_MVD_GetESReadPtr(), MDrv_MVD_GetESWritePtr());
7263     }
7264     else if (curSrcMode == E_MVD_TS_FILE_MODE)
7265     {
7266         printf("es rd=0x%lx, wr=0x%lx\n", MDrv_MVD_GetESReadPtr(), MDrv_MVD_GetESWritePtr());
7267     }
7268 }
7269 
7270 //------------------------------------------------------------------------------
7271 /// Dump the bitstream to predefined buffer address.
7272 /// Before PLAY command, set the bitstream base & bitstream length, and then
7273 /// CPU would continue to dump bitstream at the base address.
7274 /// @param -u32base \b IN : start address (MIU offset, e.g. 128M==>0MB)
7275 /// @param -u32size \b IN : size (bytes)
7276 //------------------------------------------------------------------------------
MDrv_MVD_DbgDumpBits(MS_PHYADDR u32base,MS_U32 u32size)7277 void MDrv_MVD_DbgDumpBits(MS_PHYADDR u32base, MS_U32 u32size)
7278 {
7279 
7280     MVD_CmdArg mvdcmd;
7281 
7282     u32base = MVD_GetMemOffset(u32base);
7283     printf("%s base=0x%lx size=0x%lx\n", __FUNCTION__, u32base, u32size);
7284     MS_ASSERT((u32base%8)==0);
7285     u32base >>= 3;
7286     SETUP_CMDARG(mvdcmd);
7287     mvdcmd.Arg0 = L_WORD(u32base);
7288     mvdcmd.Arg1 = H_WORD(u32base);
7289     mvdcmd.Arg2 = L_DWORD(u32base);
7290     mvdcmd.Arg3 = H_DWORD(u32base);
7291     if (HAL_MVD_MVDCommand( CMD_DUMP_BITSTREAM_BASE, &mvdcmd ) == FALSE)
7292     {
7293         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\n", CMD_DUMP_BITSTREAM_BASE ) );
7294         return;
7295     }
7296 
7297     MS_ASSERT((u32size%8)==0);
7298     u32size >>= 3;
7299     SETUP_CMDARG(mvdcmd);
7300     mvdcmd.Arg0 = L_WORD(u32size);
7301     mvdcmd.Arg1 = H_WORD(u32size);
7302     mvdcmd.Arg2 = L_DWORD(u32size);
7303     mvdcmd.Arg3 = H_DWORD(u32size);
7304     if (HAL_MVD_MVDCommand( CMD_DUMP_BITSTREAM_LENGTH, &mvdcmd ) == FALSE)
7305     {
7306         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\n", CMD_DUMP_BITSTREAM_LENGTH ) );
7307         return;
7308     }
7309     return;
7310 
7311 }
7312 
7313 
7314 #if (defined(CHIP_T7))
7315 //-----------------------------------------------------------------------------
7316 /// MVD set VOP Done
7317 /// @return - TRUE/FALSE
7318 /// @retval     -FALSE(0): not finished.
7319 /// @retval     -TRUE(1): well done!
7320 //-----------------------------------------------------------------------------
MDrv_Mvd_SetVOPDone(void)7321 void MDrv_Mvd_SetVOPDone(void)
7322 {
7323     MVD_CmdArg stCmdArg;
7324 
7325     MVD_FUNC_ENTRY();
7326     SETUP_CMDARG(stCmdArg);
7327     stCmdArg.Arg0 = VOP_INI_DONE;
7328     stCmdArg.Arg1 = 0;
7329     stCmdArg.Arg2 = 1;
7330     stCmdArg.Arg3 = 0;
7331 
7332     if (HAL_MVD_MVDCommand(CMD_SET_PARAMETER, &stCmdArg) == FALSE)
7333     {
7334         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", VOP_INI_DONE ) );
7335         return;
7336     }
7337 
7338 }
7339 
7340 /********************************************************************************/
7341 /// Set mvd play mode
7342 /// @return -none
7343 /********************************************************************************/
7344 //need check
7345 
MDrv_Mvd_SetPlayMode(MS_U8 bFileMode,MS_U8 bDisablePESParsing)7346 void MDrv_Mvd_SetPlayMode(MS_U8 bFileMode, MS_U8 bDisablePESParsing)
7347 {
7348     u8MvdPlayMode = (MS_U8)((bFileMode?1:0)<<2) | (MS_U8)((bDisablePESParsing?1:0)<<3);
7349 }
7350 
MDrv_Mvd_CallDummy(void)7351 void MDrv_Mvd_CallDummy(void)
7352 {
7353     u32MVDFWSLQTABTmpbufAdr = NULL;
7354     u32MVDFWPtsTblAddr = NULL;
7355     u32DecFrmInfoAdd = NULL;
7356     u32DynScalingAdd = NULL;
7357     u8DynScalingDepth = 0;
7358     u32ScalerInfoAdd = NULL;
7359     u32VolAdd = 0;
7360 }
7361 #endif
7362 // only for VDEC internal link patch
MDrv_MVD_LinkWeakSymbolPatch(void)7363 MS_BOOL MDrv_MVD_LinkWeakSymbolPatch(void)
7364 {
7365     return TRUE;
7366 }
7367 
7368 //------------------------------------------------------------------------------
7369 /// Set firmware as MStreamer mode
7370 /// @return -TRUE for success; FALSE for failure.
7371 //------------------------------------------------------------------------------
MDrv_MVD_SetMStreamerMode(MS_U8 u8Mode)7372 MS_BOOL MDrv_MVD_SetMStreamerMode(MS_U8 u8Mode)
7373 {
7374     u8MstMode = u8Mode;
7375     return HAL_MVD_SetMStreamerMode(u8Mode);
7376 }
7377 
7378 //------------------------------------------------------------------------------
7379 /// Flip the specified frame
7380 /// @return -TRUE for success; FALSE for failure.
7381 //------------------------------------------------------------------------------
MDrv_MVD_FrameFlip(MS_U8 u8FrmIdx)7382 MS_BOOL MDrv_MVD_FrameFlip(MS_U8 u8FrmIdx)
7383 {
7384     if (TRUE != MDrv_MVD_IsMStreamerMode())
7385     {
7386         MVD_DEBUGINFO(printf("Need to SetMStreamerMode before using this function\n"));
7387         return FALSE;
7388     }
7389     return HAL_MVD_FrameOpt(u8FrmIdx, E_MVD_FRAME_FLIP);
7390 }
7391 
7392 //------------------------------------------------------------------------------
7393 /// Release the specified frame
7394 /// @return -TRUE for success; FALSE for failure.
7395 //------------------------------------------------------------------------------
MDrv_MVD_FrameRelease(MS_U8 u8FrmIdx)7396 MS_BOOL MDrv_MVD_FrameRelease(MS_U8 u8FrmIdx)
7397 {
7398     if (TRUE != MDrv_MVD_IsMStreamerMode())
7399     {
7400         MVD_DEBUGINFO(printf("Need to SetMStreamerMode before using this function\n"));
7401         return FALSE;
7402     }
7403     return HAL_MVD_FrameOpt(u8FrmIdx, E_MVD_FRAME_RELEASE);
7404 }
7405 
7406 //------------------------------------------------------------------------------
7407 /// Reset MVD parser .  It is used for Reset MVD Parser.
7408 /// @return -TRUE for success; FALSE for failure.
7409 //------------------------------------------------------------------------------
MDrv_MVD_ParserRstDone(MS_BOOL bEnable)7410 MS_BOOL MDrv_MVD_ParserRstDone(MS_BOOL bEnable)
7411 {
7412     #define PARSER_RST_TIMEOUT 0x40000
7413     MS_U32 u32TimeOut = 0;
7414     MVD_CmdArg mvdcmd;
7415 
7416     MVD_FUNC_ENTRY();
7417     SETUP_CMDARG(mvdcmd);
7418     mvdcmd.Arg1 = bEnable;
7419     if (HAL_MVD_MVDCommand(CMD_PTS_TBL_RESET, &mvdcmd) == FALSE)
7420     {
7421         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_PTS_TBL_RESET ) );
7422         return FALSE;
7423     }
7424     while((!(MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_PARSER_RST))) && (u32TimeOut < PARSER_RST_TIMEOUT))
7425     {
7426         u32TimeOut++;
7427     }
7428 
7429     if(u32TimeOut >= PARSER_RST_TIMEOUT)
7430     {
7431         MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_PTS_TBL_RESET ) );
7432         return FALSE;
7433     }
7434     return TRUE;
7435 }
7436 //------------------------------------------------------------------------------
7437 /// Enable/Disable to capture the specified frame
7438 /// @return -TRUE for success; FALSE for failure.
7439 //------------------------------------------------------------------------------
MDrv_MVD_FrameCapture(MS_U8 u8FrmIdx,MS_BOOL bEnable)7440 MS_BOOL MDrv_MVD_FrameCapture(MS_U8 u8FrmIdx, MS_BOOL bEnable)
7441 {
7442     MS_BOOL ret = FALSE;
7443 
7444     if (TRUE != MDrv_MVD_IsMStreamerMode())
7445     {
7446         MVD_DEBUGINFO(printf("Need to SetMStreamerMode before using this function\n"));
7447         return FALSE;
7448     }
7449 
7450     ret = HAL_MVD_FrameCapture(u8FrmIdx, bEnable);
7451 
7452     //firmware will keep this frame until we release it.
7453     if ((TRUE == ret) && (TRUE != bEnable))
7454     {
7455         ret = MDrv_MVD_FrameRelease(u8FrmIdx);
7456     }
7457 
7458     return ret;
7459 }
7460 
7461 //-----------------------------------------------------------------------------
7462 /// @brief \b Function \b Name: MDrv_MVD_GetFrmRateIsSupported()
7463 /// @brief \b Function \b Description:  Get if the framerate is supported
7464 /// @return -The result of supported or not.
7465 //-----------------------------------------------------------------------------
MDrv_MVD_GetFrmRateIsSupported(void)7466 MS_BOOL MDrv_MVD_GetFrmRateIsSupported(void)
7467 {
7468     MVD_FrameInfo stInfo;
7469     MDrv_MVD_GetFrameInfo(&stInfo);
7470     return HAL_MVD_GetFrmRateIsSupported(stInfo.u16HorSize, stInfo.u16VerSize, stInfo.u32FrameRate);
7471 }
7472 
7473 //------------------------------------------------------------------------------
7474 /// set fw auto mute
7475 /// @return -TRUE for success; FALSE for failure.
7476 //------------------------------------------------------------------------------
MDrv_MVD_SetAutoMute(MS_BOOL bEnable)7477 E_MVD_Result MDrv_MVD_SetAutoMute(MS_BOOL bEnable)
7478 {
7479     MVD_CmdArg mvdcmd;
7480 
7481     MVD_FUNC_ENTRY();
7482     SETUP_CMDARG(mvdcmd);
7483     mvdcmd.Arg0 = bEnable;
7484     if (HAL_MVD_MVDCommand(CMD_ENABLE_AUTO_MUTE, &mvdcmd)== FALSE)
7485     {
7486         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_AUTO_MUTE) );
7487         return E_MVD_RET_FAIL;
7488     }
7489     return E_MVD_RET_OK;
7490 }
7491 
MDrv_MVD_SetVSizeAlign(MS_BOOL bEnable)7492 E_MVD_Result MDrv_MVD_SetVSizeAlign(MS_BOOL bEnable)
7493 {
7494     MVD_CmdArg mvdcmd;
7495 
7496     MVD_FUNC_ENTRY();
7497     SETUP_CMDARG(mvdcmd);
7498     mvdcmd.Arg0 = bEnable;
7499     if (HAL_MVD_MVDCommand(CMD_FORCE_ALIGN_VSIZE, &mvdcmd)== FALSE)
7500     {
7501         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FORCE_ALIGN_VSIZE) );
7502         return E_MVD_RET_FAIL;
7503     }
7504     return E_MVD_RET_OK;
7505 }
7506 
7507 // Please set it before cmd "CMD_ENABLE_LAST_FRAME_SHOW"
7508 // 0(default): for original just assert the last_frame_show_done when push to dispQ
7509 // 1: for strict qualify the last_frame_show_done after the last_frame been displayed by mvop, 20120309
MDrv_MVD_SetDispFinishMode(MS_U8 u8Mode)7510 E_MVD_Result MDrv_MVD_SetDispFinishMode(MS_U8 u8Mode)
7511 {
7512     MVD_CmdArg mvdcmd;
7513 
7514     MVD_FUNC_ENTRY();
7515     SETUP_CMDARG(mvdcmd);
7516     mvdcmd.Arg0 = u8Mode;
7517 
7518     MVD_DEBUGINFO(printf("%s CMD_ENABLE_LAST_FRAME_QUALIFIER arg0=%x\n", __FUNCTION__, u8Mode));
7519     if (HAL_MVD_MVDCommand(CMD_ENABLE_LAST_FRAME_QUALIFIER, &mvdcmd)== FALSE)
7520     {
7521         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_LAST_FRAME_QUALIFIER) );
7522         return E_MVD_RET_FAIL;
7523     }
7524     return E_MVD_RET_OK;
7525 }
7526 
7527 // Set AVSync Qualifier
7528 // 0(default): for compatibility to original avsync bahavior
7529 // 1: for enhance to do avsync when "enable_avsync=1" && "(lastcommand != CMD_PLAY)" for patch avsync on particular clip, 20120314
MDrv_MVD_SetAVSyncMode(MS_U8 u8Mode)7530 E_MVD_Result MDrv_MVD_SetAVSyncMode(MS_U8 u8Mode)
7531 {
7532     MVD_CmdArg mvdcmd;
7533 
7534     MVD_FUNC_ENTRY();
7535     SETUP_CMDARG(mvdcmd);
7536     mvdcmd.Arg0 = u8Mode;
7537 
7538     MVD_DEBUGINFO(printf("%s CMD_ENABLE_AVSYNC_QUALIFIER arg0=%x\n", __FUNCTION__, u8Mode));
7539     if (HAL_MVD_MVDCommand(CMD_ENABLE_AVSYNC_QUALIFIER, &mvdcmd)== FALSE)
7540     {
7541         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_AVSYNC_QUALIFIER) );
7542         return E_MVD_RET_FAIL;
7543     }
7544     return E_MVD_RET_OK;
7545 }
7546 
7547 //------------------------------------------------------------------------------
7548 /// Set IDCT mode
7549 /// @return -TRUE for success; FALSE for failure.
7550 //------------------------------------------------------------------------------
MDrv_MVD_SetIdctMode(MS_U8 u8Mode)7551 E_MVD_Result MDrv_MVD_SetIdctMode(MS_U8 u8Mode)
7552 {
7553     MVD_CmdArg mvdcmd;
7554 
7555     MVD_FUNC_ENTRY();
7556     SETUP_CMDARG(mvdcmd);
7557     mvdcmd.Arg0 = u8Mode;
7558 
7559     MVD_DEBUGINFO(printf("%s CMD_IDCT_SEL arg0=%x\n", __FUNCTION__, u8Mode));
7560     if (HAL_MVD_MVDCommand(CMD_IDCT_SEL, &mvdcmd) == FALSE)
7561     {
7562         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_IDCT_SEL) );
7563         return E_MVD_RET_FAIL;
7564     }
7565 
7566     return E_MVD_RET_OK;
7567 }
7568 
7569 //------------------------------------------------------------------------------
7570 /// Get MVD DivX plus Version,
7571 /// @return -non DivX plus  \b OUT 0
7572 //------------------------------------------------------------------------------
MDrv_MVD_GetDivxVer(void)7573 MS_U32 MDrv_MVD_GetDivxVer(void)
7574 {
7575     MVD_FUNC_ENTRY();
7576 
7577     if(pu8MVDGetFrameInfoBufStart==0)
7578     {
7579         MVD_DEBUGERROR(printf("%s error!get FrameInfo buffer start=0\n", __FUNCTION__));
7580         return 0;
7581     }
7582     return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_DIVX_VER_5X);
7583 }
7584 
7585 
7586 //-----------------------------------------------------------------------------
7587 /// @brief \b Function \b Name: MDrv_MVD_SetMVDClockSpeed()
7588 /// @brief \b Function \b Description:  set mvd clock speed
7589 /// @return - The result of setting mvd clock speed
7590 //-----------------------------------------------------------------------------
MDrv_MVD_SetMVDClockSpeed(MVD_ClockSpeed eClockSpeed)7591 E_MVD_Result MDrv_MVD_SetMVDClockSpeed(MVD_ClockSpeed eClockSpeed)
7592 {
7593 #if defined(CHIP_A3) || defined(CHIP_K1)|| defined(CHIP_KELTIC) || defined(CHIP_KAPPA)
7594     HAL_MVD_ClockSpeed eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_NONE;
7595     switch (eClockSpeed)
7596     {
7597         case E_MVD_CLOCK_SPEED_HIGHEST:
7598             eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_HIGHEST;
7599             break;
7600         case E_MVD_CLOCK_SPEED_HIGH:
7601             eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_HIGH;
7602             break;
7603         case E_MVD_CLOCK_SPEED_MEDIUM:
7604             eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_MEDIUM;
7605             break;
7606         case E_MVD_CLOCK_SPEED_LOW:
7607             eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_LOW;
7608             break;
7609         case E_MVD_CLOCK_SPEED_LOWEST:
7610             eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_LOWEST;
7611             break;
7612         case E_MVD_CLOCK_SPEED_DEFAULT:
7613             eMVDClockSpeed = E_HAL_MVD_CLOCK_SPEED_DEFAULT;
7614             break;
7615         default:
7616             MVD_DEBUGERROR(printf("mvd clock setting is wrong(%d)\n", eClockSpeed));
7617             return E_MVD_RET_FAIL;
7618             break;
7619     }
7620 
7621     return HAL_MVD_SetClockSpeed(eMVDClockSpeed);
7622 #else
7623     UNUSED(eClockSpeed);
7624     printf("This chip does not support mvd clock presetting~\n");
7625     return E_MVD_RET_FAIL;
7626 #endif
7627 }
7628 
7629 //-----------------------------------------------------------------------------
7630 /// @brief \b Function \b Name: MDrv_MVD_ShowFirstFrameDirect()
7631 /// @brief \b Function \b Description:   Enable/ Disable to push first frame to display queue directly
7632 /// @param -bEnable \b IN :  Enable/ Disable
7633 ///                 -FALSE(0): disable this mode
7634 ///                 -TRUE(1): enable this mode
7635 /// @return -The result of command MDrv_MVD_ShowFirstFrameDirect
7636 //-----------------------------------------------------------------------------
MDrv_MVD_ShowFirstFrameDirect(MS_BOOL bEnable)7637 E_MVD_Result MDrv_MVD_ShowFirstFrameDirect(MS_BOOL bEnable)
7638 {
7639     MVD_CmdArg stCmdArg;
7640 
7641     MVD_FUNC_ENTRY();
7642     SETUP_CMDARG(stCmdArg);
7643 
7644     stCmdArg.Arg0 = bEnable;
7645 
7646     MVD_DEBUGINFO(printf("%s CMD_PUSH_FIRST_FRAME_DISP arg0=%x\n", __FUNCTION__, bEnable));
7647     if (HAL_MVD_MVDCommand(CMD_PUSH_FIRST_FRAME_DISP, &stCmdArg) == FALSE)
7648     {
7649         MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PUSH_FIRST_FRAME_DISP) );
7650         return E_MVD_RET_FAIL;
7651     }
7652 
7653     return E_MVD_RET_OK;
7654 }
7655 
7656 
7657