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 // Common Definition
103 #include <string.h>
104 #include "MsCommon.h"
105 #include "MsVersion.h"
106 #include "halCHIP.h"
107 #include "drvMMIO.h"
108 #include "drvMIU.h"
109 #include "drvMVD_EX.h"
110
111 // Internal Definition
112 #include "halMVD_EX.h"
113 #include "asmCPU.h"
114 #include "osalMVD_EX.h"
115 #include "drvmvd_cc.h" //ATSC Closed Caption
116 #if !defined(MSOS_TYPE_NUTTX) || defined(SUPPORT_X_MODEL_FEATURE)
117
118 ////////////////////////////////////////////////////////////////////////////////
119 // Local defines & local structures
120 ////////////////////////////////////////////////////////////////////////////////
121 //Different level debug message
122 #if ((defined(CHIP_A1) || defined(CHIP_A7) || defined(CHIP_AMETHYST)) && defined (__aeon__))
123 #define MVD_DEBUGVERBAL(x)
124 #define MVD_DEBUGINFO(x)
125 #else
126 #define MVD_DEBUGVERBAL(x) if (_u8DbgLevel>4) { (x); }
127 #define MVD_DEBUGINFO(x) if (_u8DbgLevel>1) { (x); }
128 #endif
129 #define MVD_DEBUGERROR(x) if (_u8DbgLevel>0) { (x); }
130 #define MVD_FUNC_ENTRY() {}//MVD_PRINT(" $$$ drvMVD::%s\n", __FUNCTION__)
131
132 #ifndef ANDROID
133 #define MVD_PRINT printf
134 #define MVD_ERR printf
135 #else
136 #include <sys/mman.h>
137 #include <cutils/ashmem.h>
138 #include <cutils/log.h>
139 #ifndef LOGI // android 4.1 rename LOGx to ALOGx
140 #define MVD_PRINT ALOGI
141 #else
142 #define MVD_PRINT LOGI
143 #endif
144 #ifndef LOGE // android 4.1 rename LOGx to ALOGx
145 #define MVD_ERR ALOGE
146 #else
147 #define MVD_ERR LOGE
148 #endif
149 #endif
150
151 #define DISABLE_ISR_DETACH
152
153 #define _DUMP_FRMINFO FALSE
154
155 #define _MS_TO_90K(x) (x*90) //ms ==> 90k counter
156 #define _90K_TO_MS(x) (x/90) //90k counter ==> ms
157
158 #define _MVD_GET_IDX(x) (MS_U8)(((x) >>16) & 0xff)
159 #define _MVD_GET_HAL_SID(x) (HAL_MVD_StreamId)(((x) >>8) & 0xff)
160 #define _MVD_GET_VPU_SID(x) (HAL_VPU_StreamId)((x) & 0xff)
161
162 #define MVD_U32_MAX 0xffffffffUL
163 #define MVD_U32_MASK 0xf0000000UL
164 #define PB_ONLY_UNMUTE_VSYNC_COUNT 30
165
166 #define MVD_MAX_STREAMS 2
167
168 ////////////////////////////////////////////////////////////////////////////////
169 // Local Global Variables
170 ////////////////////////////////////////////////////////////////////////////////
171 #if 0
172 /// Version string
173 static MSIF_Version _drv_mvd_version = {
174 .DDI = { MVD_DRV_VERSION, },
175 };
176
177 static MVD_DrvInfo _stDrvInfo = {
178 1, //1 MVD HW
179 0, //Device# fixme
180 MVD_U32_MAX, //firmware version
181 { FALSE, FALSE, FALSE } //capability
182 };
183
184 static MS_U8 _u8DbgLevel = 0;
185
186 static MS_BOOL bFrmRateSupported[MVD_MAX_STREAMS];
187 static MVD_FrameInfo stPreFrmInfo[MVD_MAX_STREAMS];
188 static MVD_AVSyncCfg stNFPSyncCfg[MVD_MAX_STREAMS];
189 static MVD_AVSyncCfg stSyncCfg[MVD_MAX_STREAMS];
190
191 #ifdef MVD_ENABLE_ISR
192 static MVD_InterruptCb _pfnCallback[MVD_MAX_STREAMS];
193 static MS_U32 _eEventFlag[MVD_MAX_STREAMS];
194 static MS_U32 _eCurEvent[MVD_MAX_STREAMS];
195 static MS_U32 _u32CallbackPara[MVD_MAX_STREAMS];
196 #endif
197
198 static MS_U32 u32SyncDoneCnt = 0;
199 static MS_U32 u32VSyncCnt = 0;
200 static MS_BOOL bMVDIsrAttached = FALSE;
201 static MS_BOOL bSuspendDS_Ftime=TRUE; //to check 3d<->2d mode first time
202
203 typedef struct
204 {
205 MS_BOOL bUsed; //updated when init/exit
206 MS_U8 u8HalIdx; //index used by HAL. use it to communicate with HAL.
207 MS_U16 u16Rsvd; //reserved bytes
208
209 MS_U32 u32VpuSid; //StreamID obtained from VPU by HAL_VPU_GetFreeStream()
210 MS_U32 u32MvdSid; //StreamID obtained from VPU by HAL_MVD_GetFreeStream()
211 } MVD_Drv_Ctrl;
212 static MVD_Drv_Ctrl gMVDCtrl_EX[MVD_MAX_STREAMS]
213 = { { FALSE, 0, 0, 0, 0},
214 { FALSE, 0, 0, 0, 0},
215 };//ToDo: check when to init/reset!
216 #endif
217 typedef struct
218 {
219 MS_BOOL bUsed; //updated when init/exit
220 MS_U8 u8HalIdx; //index used by HAL. use it to communicate with HAL.
221 MS_U16 u16Rsvd; //reserved bytes
222
223 MS_U32 u32VpuSid; //StreamID obtained from VPU by HAL_VPU_GetFreeStream()
224 MS_U32 u32MvdSid; //StreamID obtained from VPU by HAL_MVD_GetFreeStream()
225 } MVD_Drv_Ctrl;
226
227 typedef struct
228 {
229 MS_BOOL bFrmRateSupported[MVD_MAX_STREAMS];
230 MVD_FrameInfo stPreFrmInfo[MVD_MAX_STREAMS];
231 MVD_AVSyncCfg stNFPSyncCfg[MVD_MAX_STREAMS];
232 MVD_AVSyncCfg stSyncCfg[MVD_MAX_STREAMS];
233
234 #ifdef MVD_ENABLE_ISR
235 MVD_InterruptCb _pfnCallback[MVD_MAX_STREAMS];
236 MS_U32 _eEventFlag[MVD_MAX_STREAMS];
237 MS_U32 _eCurEvent[MVD_MAX_STREAMS];
238 MS_U32 _u32CallbackPara[MVD_MAX_STREAMS];
239 MS_BOOL _bDisableFlag;
240 #endif
241
242 MS_U32 u32SyncDoneCnt[MVD_MAX_STREAMS];
243 MS_U32 u32VSyncCnt[MVD_MAX_STREAMS];
244 MS_BOOL bMVDIsrAttached;
245 MS_BOOL bSuspendDS_Ftime[MVD_MAX_STREAMS];
246
247 MVD_Drv_Ctrl gMVDCtrl_EX[MVD_MAX_STREAMS];//ToDo: check when to init/reset!
248
249 MS_U8 u8Afd[MVD_MAX_STREAMS];//MDrv_MVD_GetActiveFormat()
250 #if (MVD_TURBO_INIT)
251 MS_U32 u32FrmCnt[MVD_MAX_STREAMS];//MDrv_MVD_GetActiveFormat()
252 #endif
253 MS_BOOL bSelf_SeqChange[MVD_MAX_STREAMS];
254 //pre_set
255 MVD_Pre_Ctrl gMVDPreCtrl[MVD_MAX_STREAMS];
256
257 } MVD_Drv_CTX;
258
259 // global variables
260 MVD_Drv_CTX* pMVDDrvContext = NULL;
261 MVD_Drv_CTX gMVDDrvContext;
262 MSIF_Version _drv_mvd_version = {
263 .DDI = { MVD_DRV_VERSION, },
264 };
265 MVD_DrvInfo _stDrvInfo = {
266 1, //1 MVD HW
267 0, //Device# fixme
268 MVD_U32_MAX, //firmware version
269 {FALSE, FALSE, FALSE} //capability
270 };
271 MS_U8 _u8DbgLevel = 0;
272
273
274 ////////////////////////////////////////////////////////////////////////////////
275 // Local functions
276 ////////////////////////////////////////////////////////////////////////////////
277
MVD_Context_Init(void)278 static void MVD_Context_Init(void)
279 {
280 pMVDDrvContext->bSuspendDS_Ftime[0] = TRUE;
281 pMVDDrvContext->bSuspendDS_Ftime[1] = TRUE;
282 pMVDDrvContext->u8Afd[0] = 0xff;
283 pMVDDrvContext->u8Afd[1] = 0xff;
284 pMVDDrvContext->_bDisableFlag = TRUE;
285 pMVDDrvContext->bMVDIsrAttached = FALSE;
286 }
287
288
289 static void MVD_InitVar(MS_U8 u8DrvIdx,MS_U8 u8HalIdx);
290
MVD_SaveStreamId(MS_U8 u8DrvIdx,MS_U32 u32MvdSid,MS_U32 u32VpuSid)291 static MS_BOOL MVD_SaveStreamId(MS_U8 u8DrvIdx, MS_U32 u32MvdSid, MS_U32 u32VpuSid)
292 {
293 if (pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].bUsed)
294 {
295 MVD_ERR("%s err IsUsed: drv=%x mvd=%x vpu=%x\n", __FUNCTION__,
296 u8DrvIdx, u32MvdSid, u32VpuSid);
297 return FALSE;
298 }
299 pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u32MvdSid = u32MvdSid;
300 pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u32VpuSid = u32VpuSid;
301 pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u8HalIdx = HAL_MVD_SidToIdx((HAL_MVD_StreamId)u32MvdSid);
302 return TRUE;
303 }
304
MVD_GetHalIdx(MS_U32 u32Id)305 MS_U8 MVD_GetHalIdx(MS_U32 u32Id)
306 {
307 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
308 MS_U8 u8HalIdx = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u8HalIdx;
309 return u8HalIdx;
310 }
311
MVD_GetVpuStreamId(MS_U32 u32Id)312 static MS_U32 MVD_GetVpuStreamId(MS_U32 u32Id)
313 {
314 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
315 MS_U32 u32VpuSid = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u32VpuSid;
316 return u32VpuSid;
317 }
318
MVD_SetIsUsed(MS_U8 u8DrvIdx,MS_BOOL bUsed)319 static MS_BOOL MVD_SetIsUsed(MS_U8 u8DrvIdx, MS_BOOL bUsed)
320 {
321 pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].bUsed = bUsed;
322 //MVD_PRINT("%s u8DrvIdx=0x%x bUsed=%x\n", __FUNCTION__, u8DrvIdx, bUsed);
323 return TRUE;
324 }
325
MVD_GetIsUsed(MS_U8 u8DrvIdx)326 static MS_BOOL MVD_GetIsUsed(MS_U8 u8DrvIdx)
327 {
328 MS_BOOL bUsed = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].bUsed;
329 //MVD_PRINT("%s u8DrvIdx=0x%x bUsed=%x\n", __FUNCTION__, u8DrvIdx, bUsed);
330 return bUsed;
331 }
332
333 #if _DUMP_FRMINFO
MVD_DumpFrmInfo(MVD_FrmInfo * pInfo)334 static void MVD_DumpFrmInfo(MVD_FrmInfo* pInfo)
335 {
336 if (NULL == pInfo)
337 {
338 MVD_ERR("%s: pInfo invalid!\n", __FUNCTION__);
339 return;
340 }
341
342 MVD_PRINT("u32LumaAddr =0x%lx\n", pInfo->u32LumaAddr );
343 MVD_PRINT("u32ChromaAddr=0x%lx\n", pInfo->u32ChromaAddr);
344 MVD_PRINT("u32TimeStamp =0x%lx\n", pInfo->u32TimeStamp );
345 MVD_PRINT("u32ID_L =0x%lx\n", pInfo->u32ID_L );
346 MVD_PRINT("u32ID_H =0x%lx\n", pInfo->u32ID_H );
347 MVD_PRINT("u16Pitch =0x%x\n", pInfo->u16Pitch );
348 MVD_PRINT("u16Width =0x%x\n", pInfo->u16Width );
349 MVD_PRINT("u16Height =0x%x\n", pInfo->u16Height );
350 MVD_PRINT("eFrmType =0x%x\n", pInfo->eFrmType );
351 return;
352 }
353 #endif
354
355
356 //------------------------------------------------------------------------------
357 /// Get MVD driver information
358 /// @return -the pointer to the driver information
359 //------------------------------------------------------------------------------
MDrv_MVD_GetInfo(void)360 const MVD_DrvInfo* MDrv_MVD_GetInfo(void)
361 {
362 MDrv_MVD_GetCaps(&(_stDrvInfo.stCaps));
363 _stDrvInfo.u32FWVersion = HAL_MVD_GetDrvFwVer();
364 return (&_stDrvInfo);
365 }
366
367
368 //------------------------------------------------------------------------------
369 /// Get MVD driver version
370 /// @return -the pointer to the driver version
371 //------------------------------------------------------------------------------
MDrv_MVD_GetLibVer(const MSIF_Version ** ppVersion)372 E_MVD_Result MDrv_MVD_GetLibVer(const MSIF_Version **ppVersion)
373 {
374 if (!ppVersion)
375 return E_MVD_RET_FAIL;
376
377 *ppVersion = &_drv_mvd_version;
378 return E_MVD_RET_OK;
379 }
380
381
382 //------------------------------------------------------------------------------
383 /// Set detailed level of MVD driver debug message
384 /// 0: None, 1: MVD_DEBUGERROR, 2: MVD_DEBUGINFO
385 /// @param level \b IN level from 0 to 2
386 //------------------------------------------------------------------------------
MDrv_MVD_SetDbgLevel(MS_U8 level)387 void MDrv_MVD_SetDbgLevel(MS_U8 level)
388 {
389 _u8DbgLevel = level;
390 VPU_EX_UartLevel eVpuDbgLevel[6] =
391 {
392 E_VPU_EX_UART_LEVEL_NONE,
393 E_VPU_EX_UART_LEVEL_ERR,
394 E_VPU_EX_UART_LEVEL_INFO,
395 E_VPU_EX_UART_LEVEL_DBG,
396 E_VPU_EX_UART_LEVEL_TRACE,
397 E_VPU_EX_UART_LEVEL_FW,
398 };
399
400 if (level >= 1)
401 {
402 HAL_MVD_SetDbgLevel(level);
403 }
404 if (level<6) HAL_VPU_EX_SetDbgLevel(eVpuDbgLevel[level]);
405
406 return;
407 }
408
409
410 //------------------------------------------------------------------------------
411 /// Get MVD firmware version
412 /// @return -firmware version
413 //------------------------------------------------------------------------------
MDrv_MVD_GetFWVer(MS_U32 u32Id)414 MS_U32 MDrv_MVD_GetFWVer(MS_U32 u32Id)
415 {
416 MS_U32 u32VpuSid = MVD_GetVpuStreamId(u32Id);
417 return HAL_MVD_GetFWVer(u32VpuSid);
418 }
419
420 //------------------------------------------------------------------------------
421 /// Initialize variables for MVD driver
422 //------------------------------------------------------------------------------
MVD_InitVar(MS_U8 u8DrvIdx,MS_U8 u8HalIdx)423 static void MVD_InitVar(MS_U8 u8DrvIdx,MS_U8 u8HalIdx)
424 {
425 MVD_FrameInfo* pPreInfo = &(pMVDDrvContext->stPreFrmInfo[u8DrvIdx]);
426 HAL_MVD_InitVar(u8HalIdx);
427
428 pPreInfo->u16HorSize = 0;
429 pPreInfo->u16VerSize = 0;
430 pPreInfo->u8AspectRate = 0;
431 pPreInfo->u32FrameRate = 0;
432 pPreInfo->u8Interlace = 0;
433
434 memset(&(pMVDDrvContext->stSyncCfg[u8DrvIdx]), 0, sizeof(MVD_AVSyncCfg));
435
436 pMVDDrvContext->bFrmRateSupported[u8DrvIdx] = TRUE;
437
438 pMVDDrvContext->u32SyncDoneCnt[0] = 0;
439 pMVDDrvContext->u32SyncDoneCnt[1] = 0;
440 pMVDDrvContext->u32VSyncCnt[0] = 0;
441 pMVDDrvContext->u32VSyncCnt[1] = 0;
442
443 return;
444 }
445
446 #if 0
447 static void MVD_DumpMemCfg(MVD_MEMCfg* pCfg)
448 {
449 if (pCfg)
450 {
451 MVD_PRINT("u32FWBinAddr = 0x%lx\n", pCfg->u32FWBinAddr);
452 MVD_PRINT("u32FWBinSize = 0x%lx\n", pCfg->u32FWBinSize);
453 MVD_PRINT("u32FWCodeAddr = 0x%lx\n", pCfg->u32FWCodeAddr);
454 MVD_PRINT("u32FWCodeSize = 0x%lx\n", pCfg->u32FWCodeSize);
455 MVD_PRINT("u32FBAddr = 0x%lx\n", pCfg->u32FBAddr);
456 MVD_PRINT("u32FBSize = 0x%lx\n", pCfg->u32FBSize);
457 MVD_PRINT("u32BSAddr = 0x%lx\n", pCfg->u32BSAddr);
458 MVD_PRINT("u32BSSize = 0x%lx\n", pCfg->u32BSSize);
459 MVD_PRINT("u32DrvBufAddr = 0x%lx\n", pCfg->u32DrvBufAddr);
460 MVD_PRINT("u32DrvBufSize = 0x%lx\n", pCfg->u32DrvBufSize);
461 MVD_PRINT("u32DynSacalingBufAddr = 0x%lx\n", pCfg->u32DynSacalingBufAddr);
462 MVD_PRINT("u32DynSacalingBufSize = 0x%lx\n", pCfg->u32DynSacalingBufSize);
463 MVD_PRINT("u32Miu1BaseAddr = 0x%lx\n", pCfg->u32Miu1BaseAddr);
464 MVD_PRINT("bFWMiuSel = 0x%x\n", pCfg->bFWMiuSel);
465 MVD_PRINT("bHWMiuSel = 0x%x\n", pCfg->bHWMiuSel);
466 }
467 }
468 #endif
469
470 //------------------------------------------------------------------------------
471 /// Configure MVD for memory and firmware and info.
472 /// Notice:
473 /// (1) u32FWAddr & u32DrvBufAddr should be on the same MIU
474 /// (2) u32FBAddr & u32BSAddr should be on the same MIU
475 /// @param -fwCfg \b IN : pointer to firmware configuration
476 /// @param -memCfg \b IN : pointer to memory configuration
477 /// @param -InfoCfg \b IN : pointer to mvd info configuration
478 //------------------------------------------------------------------------------
MDrv_MVD_SetCfg(MS_U32 u32Id,MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)479 E_MVD_Result MDrv_MVD_SetCfg(MS_U32 u32Id, MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
480 {
481 MS_U8 u8DrvBuffMiuSel = 0;
482 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
483
484 MVD_FUNC_ENTRY();
485 if (!fwCfg || !memCfg)
486 return E_MVD_RET_INVALID_PARAM;
487
488 MVD_DEBUGINFO(MVD_PRINT("%s u32Id=0x%x, u8HalIdx=0x%x\n", __FUNCTION__, u32Id, u8HalIdx));
489 //1.1 Determine framebuffer mode, frame number, used size.
490 if (TRUE != HAL_MVD_CheckFrmBuffSize(u8HalIdx, fwCfg, memCfg))
491 {
492 return E_MVD_RET_INVALID_PARAM;
493 }
494
495 MVD_DEBUGINFO(MVD_PRINT("bNotReload=0x%x\n", fwCfg->bNotReload));
496 //1.2 Save the FWCfg in hal
497 HAL_MVD_SetFWCfg(u8HalIdx, fwCfg);
498
499 MS_U32 u32StartOffset;
500 MS_U8 u8MiuSel;
501
502 _phy_to_miu_offset(u8MiuSel, u32StartOffset, memCfg->u32FWCodeAddr);
503
504 memCfg->u8FWMiuSel = u8MiuSel;
505
506 if(u8MiuSel >= 1)
507 {
508 memCfg->bFWMiuSel = 1;
509 }
510 else
511 {
512 memCfg->bFWMiuSel = 0;
513 }
514
515 _phy_to_miu_offset(u8MiuSel, u32StartOffset, memCfg->u32FBAddr);
516
517 memCfg->u8HWMiuSel = u8MiuSel;
518 if(u8MiuSel >= 1)
519 {
520 memCfg->bHWMiuSel = 1;
521 }
522 else
523 {
524 memCfg->bHWMiuSel = 0;
525 }
526
527 _phy_to_miu_offset(u8MiuSel, u32StartOffset, memCfg->u32DrvBufAddr);
528
529 u8DrvBuffMiuSel = u8MiuSel;
530
531 _miu_offset_to_phy(E_CHIP_MIU_1,0,memCfg->u32Miu1BaseAddr);
532 _miu_offset_to_phy(E_CHIP_MIU_2,0,memCfg->u32Miu2BaseAddr);
533 _miu_offset_to_phy(E_CHIP_MIU_3,0,memCfg->u32Miu3BaseAddr);
534
535 MVD_DEBUGINFO(MVD_PRINT("MIUSEL:: FW=%x HW=%x, miu1base=0x%lx,miu2base=0x%lx,miu3base=0x%lx\n",
536 memCfg->u8FWMiuSel, memCfg->u8HWMiuSel, memCfg->u32Miu1BaseAddr,memCfg->u32Miu2BaseAddr,memCfg->u32Miu3BaseAddr));
537 MVD_DEBUGINFO(MVD_PRINT("bDrvBuffMiuSel = %x\n", u8DrvBuffMiuSel));
538
539 if(fwCfg->eSrcMode == E_MVD_SLQ_TBL_MODE)
540 {
541 MS_ASSERT(u8DrvBuffMiuSel == memCfg->u8FWMiuSel);
542 }
543
544 //addr of memCfg are physical addr, except field u32FWSrcVAddr
545 if (memCfg->eFWSrcType == E_MVD_FW_SOURCE_DRAM)
546 {
547 memCfg->u32FWSrcVAddr = HAL_MVD_PA2NonCacheSeg(memCfg->u32FWBinAddr);
548 }
549 else
550 {
551 memCfg->u32FWSrcVAddr = NULL;
552 }
553 //2.2 Save the memory config in hal
554 HAL_MVD_SetMEMCfg(u8HalIdx, memCfg);
555
556 return E_MVD_RET_OK;
557 }
558
MDrv_MVD_RegSetBase(MS_VIRT u32RegBaseAddr)559 void MDrv_MVD_RegSetBase(MS_VIRT u32RegBaseAddr)
560 {
561 HAL_MVD_RegSetBase(u32RegBaseAddr);
562 }
563
564 //------------------------------------------------------------------------------
565 /// MVD driver initialization
566 /// @return TRUE or FALSE
567 /// - TRUE, Success
568 /// - FALSE, Failed
569 //------------------------------------------------------------------------------
MDrv_MVD_Init(MS_U32 u32Id,MVD_CodecType eCodecType)570 MS_BOOL MDrv_MVD_Init(MS_U32 u32Id,MVD_CodecType eCodecType)
571 {
572 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
573 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
574 MS_U32 u32VpuSid = MVD_GetVpuStreamId(u32Id);
575 MS_VIRT u32ShmAddr;
576
577 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Init:start u32Id=0x%x, sid=0x%x, halIdx=0x%x\n",
578 u32Id, _MVD_GET_HAL_SID(u32Id), u8HalIdx));
579
580 MVD_InitVar(u8DrvIdx,u8HalIdx);
581
582 u32ShmAddr = HAL_VPU_EX_GetSHMAddr();
583
584 HAL_VPU_EX_SetShareInfoAddr(u32Id, u32ShmAddr);
585
586 if (!HAL_MVD_Init(u8HalIdx,eCodecType,u32VpuSid))
587 {
588 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Init:_MVD_Init failed\n"));
589 return FALSE;
590 }
591 else
592 {
593 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Init:_MVD_Init success\n"));
594 }
595
596 MVD_SetIsUsed(u8DrvIdx, TRUE);
597
598 return TRUE;
599 }
600
601
602 //------------------------------------------------------------------------------
603 /// MVD driver exit
604 /// @return TRUE or FALSE
605 /// - TRUE, Success
606 /// - FALSE, Failed
607 //------------------------------------------------------------------------------
MDrv_MVD_Exit(MS_U32 u32Id)608 MS_BOOL MDrv_MVD_Exit(MS_U32 u32Id)
609 {
610 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
611 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
612 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit:start\n"));
613 MVD_DEBUGINFO(MVD_PRINT("%s u8DrvIdx=0x%x u8HalIdx=0x%x u32Id=0x%x\n",__FUNCTION__, u8DrvIdx, u8HalIdx, u32Id));
614
615 //do nothing if driver is not initialized
616 if (FALSE == MVD_GetIsUsed(u8DrvIdx))
617 {
618 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Exit: not-init yet\n"));
619 goto _HW_TILE_DOWN;
620 //HAL_MVD_PowerCtrl(DISABLE);
621 //HAL_VPU_EX_PowerCtrl(DISABLE);
622 return FALSE;
623 }
624
625 //stop and reset FW/HW
626 if (HAL_MVD_Stop(u8HalIdx) != TRUE)
627 {
628 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit: stop fail\n"));
629 }
630
631 #ifdef MVD_ENABLE_ISR
632 //dettach isr
633 if (pMVDDrvContext->_eEventFlag[u8DrvIdx])
634 {
635 if(E_MVD_RET_OK != MDrv_MVD_SetIsrEvent(u32Id, E_MVD_EVENT_DISABLE_ALL, (MVD_InterruptCb)NULL)) //FIXME!
636 {
637 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Exit: dettach isr fail\n"));
638 }
639 }
640 #endif
641
642 if (!HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MVD_GetVpuStreamId(u32Id)))
643 {
644 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit: fail to delete task\n"));
645 }
646
647 _HW_TILE_DOWN:
648 if (HAL_MVD_Exit(u8HalIdx) != TRUE)
649 {
650 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Exit: fail\n"));
651 //return FALSE;
652 }
653
654 //reset internal variables.
655 MVD_InitVar(u8DrvIdx,u8HalIdx);
656
657 MVD_DEBUGINFO(MVD_PRINT("%s i=0x%x u32Id=0x%x\n", __FUNCTION__, u8DrvIdx, u32Id));
658 MVD_SetIsUsed(u8DrvIdx, FALSE);
659
660 return TRUE;
661 }
662
663 //------------------------------------------------------------------------------
664 /// Reset MVD
665 //------------------------------------------------------------------------------
MDrv_MVD_Rst(MS_U32 u32Id,MVD_CodecType eCodecType)666 E_MVD_Result MDrv_MVD_Rst(MS_U32 u32Id,MVD_CodecType eCodecType)
667 {
668 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
669 MVD_FUNC_ENTRY();
670 if (TRUE == HAL_MVD_SoftRstHW())
671 {
672 //notice: T2 MVD3 does not support soft-reset HW.
673 //Thus, MDrv_MVD_Rst()==MDrv_MVD_Init() for T2.
674 return E_MVD_RET_OK;
675 }
676 if (!HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MVD_GetVpuStreamId(u32Id)))
677 {
678 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Rst: fail to delete task\n"));
679 }
680 //For T3&Euclid MVD4, do re-init only when SoftRst does not work.
681 if (FALSE == MDrv_MVD_Init(u32Id,eCodecType))
682 {
683 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Rst:_MVD_Init failed\n"));
684 return E_MVD_RET_FAIL;
685 }
686 else
687 {
688 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Rst:_MVD_Init success\n"));
689 }
690
691 return E_MVD_RET_OK;
692 }
693
694 //------------------------------------------------------------------------------
695 /// Issue Play command to MVD
696 //------------------------------------------------------------------------------
MDrv_MVD_Play(MS_U32 u32Id)697 void MDrv_MVD_Play(MS_U32 u32Id)
698 {
699 MVD_FUNC_ENTRY();
700 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
701 if (TRUE != HAL_MVD_Play(u8HalIdx))
702 {
703 MVD_DEBUGERROR(MVD_ERR("%s fail\n", __FUNCTION__));
704 }
705 return;
706 }
707
708 //------------------------------------------------------------------------------
709 /// Set frame buffer address to MVD
710 /// @param -u32addr \b IN : start address
711 //------------------------------------------------------------------------------
MDrv_MVD_SetFrameBuffAddr(MS_U32 u32Id,MS_VIRT u32addr)712 void MDrv_MVD_SetFrameBuffAddr(MS_U32 u32Id, MS_VIRT u32addr)
713 {
714 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
715
716 HAL_MVD_SetFrameBuffAddr(u8HalIdx, u32addr, HAL_MVD_GetFBMode(u8HalIdx));
717 }
718
719 //------------------------------------------------------------------------------
720 /// Set codec type.
721 /// @param -u8CodecType \b IN : 0: mpeg4, 1: mpeg4 with short_video_header, 2: DivX311
722 /// @param -u8BSProviderMode \b IN : TS live stream, file, SLQ, SLQ table link and TS file mode.
723 //------------------------------------------------------------------------------
MDrv_MVD_SetCodecInfo(MS_U32 u32Id,MVD_CodecType u8CodecType,MVD_SrcMode u8BSProviderMode,MS_U8 bDisablePESParsing)724 void MDrv_MVD_SetCodecInfo(MS_U32 u32Id, MVD_CodecType u8CodecType, MVD_SrcMode u8BSProviderMode, MS_U8 bDisablePESParsing)
725 {
726 MVD_FUNC_ENTRY();
727 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
728 //MVD_PRINT("u8CodecType=0x%x\n", u8CodecType);
729 //MVD_PRINT("u8BSProviderMode=0x%x\n", u8BSProviderMode);
730 if (HAL_MVD_SetCodecInfo(u8HalIdx, u8CodecType, u8BSProviderMode, bDisablePESParsing) == FALSE)
731 {
732 MVD_DEBUGERROR(MVD_ERR("%s fail!!\r\n", __FUNCTION__));
733 return;
734 }
735
736 return;
737 }
738
739 //------------------------------------------------------------------------------
740 /// Set DivX patch.
741 /// @param -u8MvAdjust \b IN : chroma adjustment
742 /// @param -u8IdctSel \b IN : idct algorithm selection
743 //------------------------------------------------------------------------------
MDrv_MVD_SetDivXCfg(MS_U32 u32Id,MS_U8 u8MvAdjust,MS_U8 u8IdctSel)744 void MDrv_MVD_SetDivXCfg(MS_U32 u32Id, MS_U8 u8MvAdjust, MS_U8 u8IdctSel)
745 {
746 MVD_FUNC_ENTRY();
747 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
748 HAL_MVD_SetDivXCfg(u8HalIdx, u8MvAdjust, u8IdctSel);
749 return;
750 }
751
752
753 //------------------------------------------------------------------------------
754 /// Get MVD decoded picture counter
755 /// @return -decoded picture counter
756 //------------------------------------------------------------------------------
MDrv_MVD_GetPicCounter(MS_U32 u32Id)757 MS_U32 MDrv_MVD_GetPicCounter(MS_U32 u32Id)
758 {
759 MVD_FUNC_ENTRY();
760 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
761 return HAL_MVD_GetPicCounter(u8HalIdx);
762 }
763
764
765 //------------------------------------------------------------------------------
766 /// Get MVD skipped picture counter
767 /// @return -skipped picture counter
768 //------------------------------------------------------------------------------
MDrv_MVD_GetSkipPicCounter(MS_U32 u32Id)769 MS_U32 MDrv_MVD_GetSkipPicCounter(MS_U32 u32Id)
770 {
771 MVD_FUNC_ENTRY();
772 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
773 return HAL_MVD_GetSkipPicCounter(u8HalIdx);
774 }
775
776 //------------------------------------------------------------------------------
777 /// Get MVD picture type
778 /// @return - picture type
779 //------------------------------------------------------------------------------
MDrv_MVD_GetPicType(MS_U32 u32Id)780 MVD_PicType MDrv_MVD_GetPicType(MS_U32 u32Id)
781 {
782 MVD_FUNC_ENTRY();
783 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
784 return HAL_MVD_GetPicType(u8HalIdx);
785 }
786
787 //------------------------------------------------------------------------------
788 /// Get MVD bit rate (bits/sec)
789 /// @return -bit rate
790 //------------------------------------------------------------------------------
MDrv_MVD_GetBitsRate(MS_U32 u32Id)791 MS_U32 MDrv_MVD_GetBitsRate(MS_U32 u32Id)
792 {
793 MVD_FUNC_ENTRY();
794 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
795 return HAL_MVD_GetBitsRate(u8HalIdx);
796 }
797
798
799 //------------------------------------------------------------------------------
800 /// Get video_range flag.
801 /// Supported after MVD FW release v00720390
802 /// Color team need this information for better color quality.
803 /// When video_range = 0 gives a range of Y from 16 to 235 and Cb , Cr from 16 to 240
804 /// When video_range = 1 gives a range of Y from 0 to 255 and Cb , Cr from 0 to 255
805 /// @return -video_range
806 //------------------------------------------------------------------------------
MDrv_MVD_GetVideoRange(MS_U32 u32Id)807 MS_U8 MDrv_MVD_GetVideoRange(MS_U32 u32Id)
808 {
809 MVD_FUNC_ENTRY();
810 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
811 return HAL_MVD_GetVideoRange(u8HalIdx);
812 }
813
814 //------------------------------------------------------------------------------
815 /// Get LowDelay flag
816 /// @return -True/False
817 //------------------------------------------------------------------------------
MDrv_MVD_GetLowDelayFlag(MS_U32 u32Id)818 MS_BOOL MDrv_MVD_GetLowDelayFlag(MS_U32 u32Id)
819 {
820 MVD_FUNC_ENTRY();
821 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
822 return HAL_MVD_GetLowDelayFlag(u8HalIdx);
823 }
824
825 //------------------------------------------------------------------------------
826 /// Get MPEG 3:2 pull down flag
827 /// @return -TRUE or FALSE
828 //------------------------------------------------------------------------------
MDrv_MVD_GetIs32PullDown(MS_U32 u32Id)829 MS_BOOL MDrv_MVD_GetIs32PullDown(MS_U32 u32Id)
830 {
831 MVD_FUNC_ENTRY();
832 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
833 return HAL_MVD_GetIs32PullDown(u8HalIdx);
834 }
835
836 //------------------------------------------------------------------------------
837 /// Get if Dynamic Scaling is enabled (reported by firmware)
838 /// @return -TRUE or FALSE
839 //------------------------------------------------------------------------------
MDrv_MVD_GetIsDynScalingEnabled(MS_U32 u32Id)840 MS_BOOL MDrv_MVD_GetIsDynScalingEnabled(MS_U32 u32Id)
841 {
842 MVD_FUNC_ENTRY();
843 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
844 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
845 MS_BOOL bEnDynScale = FALSE;
846
847 bEnDynScale = (MS_BOOL)HAL_MVD_GetIsDynScalingEnabled(u8HalIdx);
848 if ((FALSE == pstMemCfg->bEnableDynScale) && (bEnDynScale))
849 {
850 MVD_DEBUGERROR(MVD_ERR("bEnDynScale err: %x\n", bEnDynScale));
851 }
852
853 //MVD_PRINT("%s bEnDS: %x, %x\n", __FUNCTION__, bEnDynScale, pstMemCfg->bEnableDynScale);
854 return bEnDynScale;
855 }
856
857 //------------------------------------------------------------------------------
858 /// Get the difference of PTS and STC
859 /// @return -(PTS-STC)
860 //------------------------------------------------------------------------------
MDrv_MVD_GetPtsStcDiff(MS_U32 u32Id)861 MS_S32 MDrv_MVD_GetPtsStcDiff(MS_U32 u32Id)
862 {
863 MVD_FUNC_ENTRY();
864 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
865 return HAL_MVD_GetPtsStcDiff(u8HalIdx);
866 }
867
868 //------------------------------------------------------------------------------
869 /// Get MVD SLQ read pointer
870 /// @return -SLQ read pointer
871 //------------------------------------------------------------------------------
MDrv_MVD_GetSLQReadPtr(MS_U32 u32Id)872 MS_U32 MDrv_MVD_GetSLQReadPtr(MS_U32 u32Id)
873 {
874 MVD_FUNC_ENTRY();
875 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
876 return HAL_MVD_GetSLQReadPtr(u8HalIdx);
877 }
878
879 //------------------------------------------------------------------------------
880 /// Get MVD SLQ write pointer
881 /// @return -SLQ write pointer
882 //------------------------------------------------------------------------------
MDrv_MVD_SetSLQWritePtr(MS_U32 u32Id,MS_BOOL bCheckData)883 void MDrv_MVD_SetSLQWritePtr(MS_U32 u32Id, MS_BOOL bCheckData)
884 {
885 MVD_FUNC_ENTRY();
886 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
887 HAL_MVD_SetSLQWritePtr(u8HalIdx, bCheckData);
888 return;
889 }
890
891 //------------------------------------------------------------------------------
892 /// Get MVD decoded frame index. For debug.
893 /// @return -frame index of the decoded frame
894 //------------------------------------------------------------------------------
MDrv_MVD_GetDecodedFrameIdx(MS_U32 u32Id)895 MS_U8 MDrv_MVD_GetDecodedFrameIdx(MS_U32 u32Id)
896 {
897 MVD_FUNC_ENTRY();
898 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
899 return HAL_MVD_GetDecodedFrameIdx(u8HalIdx);
900 }
901
902 //------------------------------------------------------------------------------
903 /// Get MVD VLD error count
904 /// @return -VLD error count
905 //------------------------------------------------------------------------------
MDrv_MVD_GetVldErrCount(MS_U32 u32Id)906 MS_U32 MDrv_MVD_GetVldErrCount(MS_U32 u32Id)
907 {
908 MVD_FUNC_ENTRY();
909 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
910 return HAL_MVD_GetVldErrCount(u8HalIdx);
911 }
912
913
914 //------------------------------------------------------------------------------
915 /// Get MVD error info.
916 /// This function can be used to diagnosis when the 1st DispReady doesn't occur.
917 ///
918 /// @param - errorCode \b OUT : error code
919 /// @param - errorStatus \b OUT : error status
920 //------------------------------------------------------------------------------
MDrv_MVD_GetErrInfo(MS_U32 u32Id,MVD_ErrCode * errCode,MVD_ErrStatus * errStatus)921 void MDrv_MVD_GetErrInfo(MS_U32 u32Id, MVD_ErrCode *errCode, MVD_ErrStatus *errStatus)
922 {
923 MVD_FUNC_ENTRY();
924 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
925 HAL_MVD_GetErrInfo(u8HalIdx, errCode, errStatus);
926 return;
927 }
928
929 //------------------------------------------------------------------------------
930 /// Get valid MVD stream detected flag
931 /// For MPEG2/4,
932 /// 1. width<16(1 macroblock), height<16, width>1920, or height>1080
933 /// 2. next start code not found
934 /// the stream would be considered as invalid.
935 /// For VC1/RCV, not impelment, default: valid
936 /// @return -decoded flag
937 //------------------------------------------------------------------------------
MDrv_MVD_GetValidStreamFlag(MS_U32 u32Id)938 MS_BOOL MDrv_MVD_GetValidStreamFlag(MS_U32 u32Id)
939 {
940 MVD_FUNC_ENTRY();
941 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
942 return HAL_MVD_GetValidStreamFlag(u8HalIdx);
943 }
944
945 //------------------------------------------------------------------------------
946 /// Get video frame information from MVD
947 /// (SourceW * ParH) : (SourceH * ParW) = DarW : DarH
948 /// E.g. Source PAL 704x576, Par(Pixel aspect ratio)=12/11,
949 /// Dar(Display AR) = (704x12):(576x11) = 4:3
950 /// @param -pinfo \b IN : pointer to video frame information
951 //------------------------------------------------------------------------------
MDrv_MVD_GetFrameInfo(MS_U32 u32Id,MVD_FrameInfo * pinfo)952 void MDrv_MVD_GetFrameInfo(MS_U32 u32Id, MVD_FrameInfo *pinfo)
953 {
954 MVD_FUNC_ENTRY();
955 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
956 HAL_MVD_GetFrameInfo(u8HalIdx, pinfo);
957 }
958
959 //------------------------------------------------------------------------------
960 /// Set video frame information from MVD
961 /// @param -pinfo \b IN : pointer to video frame information
962 //------------------------------------------------------------------------------
MDrv_MVD_SetFrameInfo(MS_U32 u32Id,MVD_FrameInfo * pinfo)963 void MDrv_MVD_SetFrameInfo(MS_U32 u32Id, MVD_FrameInfo *pinfo )
964 {
965 MVD_FUNC_ENTRY();
966 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
967 HAL_MVD_SetFrameInfo(u8HalIdx, pinfo);
968 return;
969 }
970
971 //------------------------------------------------------------------------------
972 /// Reset for I-frame decoding
973 /// @return -none
974 //------------------------------------------------------------------------------
MDrv_MVD_RstIFrameDec(MS_U32 u32Id,MVD_CodecType eCodecType)975 void MDrv_MVD_RstIFrameDec(MS_U32 u32Id,MVD_CodecType eCodecType)
976 {
977 MVD_FUNC_ENTRY();
978 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
979 if (HAL_MVD_Stop(u8HalIdx) == FALSE)
980 {
981 MVD_DEBUGERROR(MVD_ERR("%s fail!!\n", __FUNCTION__));
982 }
983
984 MDrv_MVD_Rst(u32Id,eCodecType);
985 return;
986 }
987
988 //------------------------------------------------------------------------------
989 /// Decode I-frame
990 /// @param -u32FrameBufAddr \b IN : start address of frame buffer
991 /// @param -u32StreamBufAddr \b IN : start address of stream buffer
992 /// @return -return decode I-frame success or not
993 //------------------------------------------------------------------------------
MDrv_MVD_DecodeIFrame(MS_U32 u32Id,MS_PHY u32FrameBufAddr,MS_PHY u32StreamBufAddr,MS_PHY u32StreamBufEndAddr)994 MS_BOOL MDrv_MVD_DecodeIFrame(MS_U32 u32Id, MS_PHY u32FrameBufAddr, MS_PHY u32StreamBufAddr, MS_PHY u32StreamBufEndAddr )
995 {
996 MS_BOOL bRet = FALSE;
997 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
998 MVD_DEBUGINFO(MVD_PRINT("%s input FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
999 __FUNCTION__, u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr));
1000 u32FrameBufAddr = HAL_MVD_GetMemOffset(u32FrameBufAddr);
1001 u32StreamBufAddr = HAL_MVD_GetMemOffset(u32StreamBufAddr);
1002 u32StreamBufEndAddr = HAL_MVD_GetMemOffset(u32StreamBufEndAddr);
1003 MVD_DEBUGINFO(MVD_PRINT("%s offset FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
1004 __FUNCTION__, u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr));
1005
1006 bRet = HAL_MVD_DecodeIFrame(u8HalIdx, u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr);
1007 return bRet;
1008 }
1009
1010 //------------------------------------------------------------------------------
1011 /// Query if MVD is decoding frame
1012 /// @return -MVD is decoding frame or not
1013 //------------------------------------------------------------------------------
MDrv_MVD_GetIsIFrameDecoding(MS_U32 u32Id)1014 MS_BOOL MDrv_MVD_GetIsIFrameDecoding(MS_U32 u32Id)
1015 {
1016 MS_BOOL bDecodeIFrame = FALSE;
1017 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1018 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1019 if (pCtrlCfg)
1020 {
1021 bDecodeIFrame = pCtrlCfg->bDecodeIFrame;
1022 }
1023 return bDecodeIFrame;
1024 }
1025
1026 //------------------------------------------------------------------------------
1027 /// Get MVD active format
1028 /// @return -active format
1029 //------------------------------------------------------------------------------
MDrv_MVD_GetActiveFormat(MS_U32 u32Id)1030 MS_U8 MDrv_MVD_GetActiveFormat(MS_U32 u32Id)
1031 {
1032 MVD_FUNC_ENTRY();
1033 //set default as invalid AFD that is ignored by AP.
1034 //static MS_U8 u8Afd[MVD_MAX_STREAMS] = { 0xff, 0xff};
1035 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1036 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1037 #if (MVD_TURBO_INIT)
1038 //static MS_U32 u32FrmCnt[MVD_MAX_STREAMS] = { 0, 0};
1039
1040 if (pMVDDrvContext->u32FrmCnt[u8DrvIdx] == HAL_MVD_GetPicCounter(u8HalIdx))
1041 {
1042 return pMVDDrvContext->u8Afd[u8DrvIdx];
1043 }
1044 pMVDDrvContext->u32FrmCnt[u8DrvIdx] = HAL_MVD_GetPicCounter(u8HalIdx);
1045 #endif
1046 pMVDDrvContext->u8Afd[u8DrvIdx] = HAL_MVD_GetActiveFormat(u8HalIdx);
1047 return pMVDDrvContext->u8Afd[u8DrvIdx];
1048 }
1049
1050 //------------------------------------------------------------------------------
1051 /// Enable or disable AV synchronization.
1052 /// Delay u32Delay ms if AVSync is enabled.
1053 /// @return -none
1054 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSync(MS_U32 u32Id,MS_BOOL bEnable,MS_U32 u32Delay)1055 void MDrv_MVD_SetAVSync(MS_U32 u32Id, MS_BOOL bEnable, MS_U32 u32Delay)
1056 {
1057 //MVD_PRINT("%s bEnable=%d u32Delay=%ld\n",__FUNCTION__,bEnable,u32Delay);
1058 MVD_FUNC_ENTRY();
1059 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1060 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1061 if (TRUE != HAL_MVD_EnableAVSync(u8HalIdx, bEnable))
1062 {
1063 MVD_DEBUGERROR(MVD_ERR("%s: fail to set avsync on\n", __FUNCTION__));
1064 return;
1065 }
1066 //bAVSyncOn = bEnable; //for IsAVSyncOn
1067
1068 if (bEnable && (u32Delay != 0))
1069 {
1070 if (TRUE != HAL_MVD_SetAVSyncDelay(u8HalIdx, u32Delay))
1071 {
1072 MVD_DEBUGERROR(MVD_ERR("%s: fail to set avsync delay\n", __FUNCTION__));
1073 return;
1074 }
1075 }
1076
1077 pMVDDrvContext->stSyncCfg[u8DrvIdx].bEnable = bEnable;
1078 pMVDDrvContext->stSyncCfg[u8DrvIdx].u32Delay = u32Delay;
1079 return;
1080 }
1081
1082 //------------------------------------------------------------------------------
1083 /// Set the maximum repeat times for one frame when av is not sync.
1084 /// E.g. Arg5=0x01 mean that frame will be repeated once if av is not sync.
1085 /// Arg5=0xff mean that frame will be always repeated when av is not sync.
1086 /// And customer can re-define the avsync skip behavior,
1087 /// i.e., Arg4 = 1 for skip-b-frame only and 0 for skip display(default)
1088 /// @return -none
1089 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSyncThreshold(MS_U32 u32Id,MS_U32 u32Th)1090 void MDrv_MVD_SetAVSyncThreshold(MS_U32 u32Id, MS_U32 u32Th)
1091 {
1092 MVD_FUNC_ENTRY();
1093 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1094 HAL_MVD_SetAVSyncThreshold(u8HalIdx, u32Th);
1095 return;
1096 }
1097
1098 //------------------------------------------------------------------------------
1099 /// Set the threshold for VC1 avsync (live mode & file mode). Unit: 90K
1100 /// @return -none
1101 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSyncFreerunThreshold(MS_U32 u32Id,MS_U32 u32Th)1102 void MDrv_MVD_SetAVSyncFreerunThreshold(MS_U32 u32Id, MS_U32 u32Th)
1103 {
1104 MVD_FUNC_ENTRY();
1105 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1106 HAL_MVD_SetAVSyncFreerunThreshold(u8HalIdx, u32Th);
1107 return;
1108 }
1109
1110 //------------------------------------------------------------------------------
1111 /// Get MVD AVSync delay (ms)
1112 /// @return -avsync delay
1113 //------------------------------------------------------------------------------
MDrv_MVD_GetAVSyncDelay(MS_U32 u32Id)1114 MS_U32 MDrv_MVD_GetAVSyncDelay(MS_U32 u32Id)
1115 {
1116 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1117 return (pMVDDrvContext->stSyncCfg[u8DrvIdx].u32Delay);
1118 }
1119
1120 //------------------------------------------------------------------------------
1121 /// Get if AVSync is turned on
1122 /// @return -TRUE for yes or FALSE for no
1123 //------------------------------------------------------------------------------
MDrv_MVD_GetIsAVSyncOn(MS_U32 u32Id)1124 MS_BOOL MDrv_MVD_GetIsAVSyncOn(MS_U32 u32Id)
1125 {
1126 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1127 return HAL_MVD_GetIsAVSyncOn(u8HalIdx);
1128 }
1129
1130 //------------------------------------------------------------------------------
1131 /// Get if firmware is repeating frame for AVSync.
1132 /// @return -TRUE for yes or FALSE for no
1133 //------------------------------------------------------------------------------
MDrv_MVD_GetIsSyncRep(MS_U32 u32Id)1134 MS_BOOL MDrv_MVD_GetIsSyncRep(MS_U32 u32Id)
1135 {
1136 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1137 return HAL_MVD_GetIsSyncRep(u8HalIdx);
1138 }
1139
1140 //------------------------------------------------------------------------------
1141 /// Get if firmware is skipping frame for AVSync.
1142 /// @return -TRUE for yes or FALSE for no
1143 //------------------------------------------------------------------------------
MDrv_MVD_GetIsSyncSkip(MS_U32 u32Id)1144 MS_BOOL MDrv_MVD_GetIsSyncSkip(MS_U32 u32Id)
1145 {
1146 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1147 return HAL_MVD_GetIsSyncSkip(u8HalIdx);
1148 }
1149
1150 //------------------------------------------------------------------------------
1151 /// Change PTS threshold for doing AVSync.
1152 /// Scenario: When disable black screen earlier than normal case, use this function
1153 /// to avoid frame skip too fast or video lag.
1154 /// @param -bEnable \b IN : enable this configuration
1155 /// @param -u16PTS \b IN : PTS threshold (unit: 90k counter, i.e. x/90 ms, max 728ms)
1156 /// @return -TRUE for success or FALSE for failure.
1157 //------------------------------------------------------------------------------
MDrv_MVD_ChangeAVsync(MS_U32 u32Id,MS_BOOL bEnable,MS_U16 u16PTS)1158 MS_BOOL MDrv_MVD_ChangeAVsync(MS_U32 u32Id, MS_BOOL bEnable, MS_U16 u16PTS)
1159 {
1160 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1161 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1162 if (HAL_MVD_ChangeAVsync(u8HalIdx, bEnable, u16PTS) == TRUE)
1163 {
1164 pMVDDrvContext->stSyncCfg[u8DrvIdx].u16Tolerance = u16PTS;
1165 return TRUE;
1166 }
1167 return FALSE;
1168 }
1169
1170 //------------------------------------------------------------------------------
1171 /// Get address of the first I-frame.
1172 /// @return -address of the first I-frame
1173 //------------------------------------------------------------------------------
MDrv_MVD_GetIsIPicFound(MS_U32 u32Id)1174 MS_U8 MDrv_MVD_GetIsIPicFound(MS_U32 u32Id)
1175 {
1176 MVD_FUNC_ENTRY();
1177 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1178 return HAL_MVD_GetIsIPicFound(u8HalIdx);
1179 }
1180
1181 //------------------------------------------------------------------------------
1182 /// Get sync status to know whether sync is complete or not
1183 /// @return - 1 : sync complete
1184 //// - otherwise: sync not complete
1185 //------------------------------------------------------------------------------
MDrv_MVD_GetSyncStatus(MS_U32 u32Id)1186 MS_U8 MDrv_MVD_GetSyncStatus(MS_U32 u32Id)
1187 {
1188 MVD_FUNC_ENTRY();
1189 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1190 return HAL_MVD_GetIsSyncReach(u8HalIdx);
1191 }
1192
1193 //------------------------------------------------------------------------------
1194 /// Report if decoder is freerun or not
1195 /// @return - TRUE : freerun
1196 //// - FALSE : not freerun
1197 //------------------------------------------------------------------------------
MDrv_MVD_GetIsFreerun(MS_U32 u32Id)1198 MS_BOOL MDrv_MVD_GetIsFreerun(MS_U32 u32Id)
1199 {
1200 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1201 return (HAL_MVD_GetAVSyncStatus(u8HalIdx) == 0);
1202 }
1203
1204 //------------------------------------------------------------------------------
1205 /// Get PTS (Presentation Time Stamp)
1206 /// @return -PTS (unit: ms)
1207 //------------------------------------------------------------------------------
MDrv_MVD_GetPTS(MS_U32 u32Id)1208 MS_U32 MDrv_MVD_GetPTS(MS_U32 u32Id)
1209 {
1210 MVD_FUNC_ENTRY();
1211 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1212 return HAL_MVD_GetPTS(u8HalIdx);
1213 }
1214
1215
1216 //------------------------------------------------------------------------------
1217 /// Get 33 bits PTS (Presentation Time Stamp)
1218 /// @return -PTS (unit: ms)
1219 //------------------------------------------------------------------------------
MDrv_MVD_GetU64PTS(MS_U32 u32Id)1220 MS_U64 MDrv_MVD_GetU64PTS(MS_U32 u32Id)
1221 {
1222 MVD_FUNC_ENTRY();
1223 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1224 return HAL_MVD_GetU64PTS(u8HalIdx);
1225 }
1226
1227
1228
1229 //------------------------------------------------------------------------------
1230 /// Get Next PTS (Presentation Time Stamp)
1231 /// @return -Next PTS (unit: ms)
1232 //------------------------------------------------------------------------------
MDrv_MVD_GetNextPTS(MS_U32 u32Id)1233 MS_U32 MDrv_MVD_GetNextPTS(MS_U32 u32Id)
1234 {
1235 MVD_FUNC_ENTRY();
1236 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1237 return HAL_MVD_GetNextPTS(u8HalIdx);
1238 }
1239
1240 //------------------------------------------------------------------------------
1241 /// Get Chroma format (MDrv_MVD_GetChromaFormat)
1242 /// @return -Chroma format ()
1243 //------------------------------------------------------------------------------
MDrv_MVD_GetChromaFormat(MS_U32 u32Id)1244 MS_U32 MDrv_MVD_GetChromaFormat(MS_U32 u32Id)
1245 {
1246 MVD_FUNC_ENTRY();
1247 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1248 return HAL_MVD_GetChromaFormat(u8HalIdx);
1249 }
1250
1251 //------------------------------------------------------------------------------
1252 /// Query if MVD is ready to display
1253 /// @return -MS_U8 0: not ready, !0: ready.
1254 //------------------------------------------------------------------------------
MDrv_MVD_GetDispRdy(MS_U32 u32Id)1255 MS_U8 MDrv_MVD_GetDispRdy(MS_U32 u32Id)
1256 {
1257 MVD_FUNC_ENTRY();
1258 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1259 MS_BOOL bDispRdy = HAL_MVD_GetDispRdy(u8HalIdx);
1260 MS_BOOL bIFound = HAL_MVD_GetIsIPicFound(u8HalIdx);
1261
1262 return (bDispRdy || bIFound);
1263 }
1264
1265 //------------------------------------------------------------------------------
1266 /// Query if the first frame is showed after play function is called.
1267 /// Whenever the first display frame is displayed, f/w will set this flag to 1.
1268 /// @return VDEC_Result
1269 //------------------------------------------------------------------------------
MDrv_MVD_Is1stFrmRdy(MS_U32 u32Id)1270 MS_BOOL MDrv_MVD_Is1stFrmRdy(MS_U32 u32Id)
1271 {
1272 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1273 return HAL_MVD_Is1stFrmRdy(u8HalIdx);
1274 }
1275
1276 //------------------------------------------------------------------------------
1277 /// Get picture count of current GOP (Group of Picture)
1278 /// @return -picture count of GOP
1279 //------------------------------------------------------------------------------
MDrv_MVD_GetGOPCount(MS_U32 u32Id)1280 MS_U32 MDrv_MVD_GetGOPCount(MS_U32 u32Id)
1281 {
1282 MVD_FUNC_ENTRY();
1283 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1284 return HAL_MVD_GetGOPCount(u8HalIdx);
1285 }
1286
1287 //------------------------------------------------------------------------------
1288 /// Enable or disable dropping error frames
1289 /// @return -command is set successfully or not
1290 //------------------------------------------------------------------------------
MDrv_MVD_DropErrorFrame(MS_U32 u32Id,MS_BOOL bDrop)1291 MS_BOOL MDrv_MVD_DropErrorFrame(MS_U32 u32Id, MS_BOOL bDrop)
1292 {
1293 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1294 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1295 if (HAL_MVD_DropErrorFrame(u8HalIdx, bDrop) == FALSE)
1296 {
1297 MVD_DEBUGERROR( MVD_ERR( "%s fail!!\n", __FUNCTION__));
1298 return FALSE;
1299 }
1300 pstCtrlCfg->bDropErrFrm = bDrop;
1301 return TRUE;
1302 }
1303
1304 //------------------------------------------------------------------------------
1305 /// Get byte count of parser.
1306 /// @return -byte count of parser
1307 //------------------------------------------------------------------------------
MDrv_MVD_GetParserByteCnt(MS_U32 u32Id)1308 MS_U32 MDrv_MVD_GetParserByteCnt(MS_U32 u32Id)
1309 {
1310 MVD_FUNC_ENTRY();
1311 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1312 return HAL_MVD_GetParserByteCnt(u8HalIdx);
1313 }
1314
1315 //------------------------------------------------------------------------------
1316 /// Get the decode status.
1317 /// @return -the decode status
1318 //------------------------------------------------------------------------------
MDrv_MVD_GetDecodeStatus(MS_U32 u32Id)1319 MVD_DecStat MDrv_MVD_GetDecodeStatus(MS_U32 u32Id)
1320 {
1321 MVD_FUNC_ENTRY();
1322 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1323 return HAL_MVD_GetDecodeStatus(u8HalIdx);
1324 }
1325
1326 //------------------------------------------------------------------------------
1327 /// Get the last command to firmware.
1328 /// @return -the last command
1329 //------------------------------------------------------------------------------
MDrv_MVD_GetLastCmd(MS_U32 u32Id)1330 MS_U8 MDrv_MVD_GetLastCmd(MS_U32 u32Id)
1331 {
1332 MVD_FUNC_ENTRY();
1333 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1334 return HAL_MVD_GetLastCmd(u8HalIdx);
1335 }
1336
1337 //------------------------------------------------------------------------------
1338 /// Skip data in ES buffer. It is used for flushing ES buffer.
1339 /// @return -TRUE for success; FALSE for failure.
1340 //------------------------------------------------------------------------------
MDrv_MVD_SkipData(MS_U32 u32Id)1341 MS_BOOL MDrv_MVD_SkipData(MS_U32 u32Id)
1342 {
1343 MVD_FUNC_ENTRY();
1344 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1345 return HAL_MVD_SkipData(u8HalIdx);
1346 }
1347
1348 //------------------------------------------------------------------------------
1349 /// Skip to I frame.
1350 /// Used for MediaCodec when input data is not continuous or in the beginning of
1351 /// streams.
1352 /// @return -TRUE for success; FALSE for failure.
1353 //------------------------------------------------------------------------------
MDrv_MVD_SkipToIFrame(MS_U32 u32Id)1354 MS_BOOL MDrv_MVD_SkipToIFrame(MS_U32 u32Id)
1355 {
1356 MVD_FUNC_ENTRY();
1357 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1358 return HAL_MVD_SkipToIFrame(u8HalIdx);
1359 }
1360
1361 //------------------------------------------------------------------------------
1362 /// Display control for decoding order, enabling drop error frame, dropping
1363 /// display and setting FRC (frame rate conversion) mode.
1364 /// @return -TRUE for success; FALSE for failure.
1365 //------------------------------------------------------------------------------
MDrv_MVD_DispCtrl(MS_U32 u32Id,MS_BOOL bDecOrder,MS_BOOL bDropErr,MS_BOOL bDropDisp,MVD_FrcMode eFrcMode)1366 MS_BOOL MDrv_MVD_DispCtrl(MS_U32 u32Id, MS_BOOL bDecOrder, MS_BOOL bDropErr, MS_BOOL bDropDisp, MVD_FrcMode eFrcMode)
1367 {
1368 MVD_FUNC_ENTRY();
1369 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1370 return HAL_MVD_DispCtrl(u8HalIdx, bDecOrder, bDropErr, bDropDisp, eFrcMode);
1371 }
1372
1373 //------------------------------------------------------------------------------
1374 /// Enable/Disable to repeat the last field when repeat for avsync or display pause.
1375 /// E.g. Top field first: T-B-B-B-...; Bottom field first: B-T-T-T-...
1376 /// Usage scenario: scaler framebufferless mode to avoid frame flicker
1377 /// @return -TRUE for success; FALSE for failure.
1378 //------------------------------------------------------------------------------
MDrv_MVD_DispRepeatField(MS_U32 u32Id,MS_BOOL bEnable)1379 MS_BOOL MDrv_MVD_DispRepeatField(MS_U32 u32Id, MS_BOOL bEnable)
1380 {
1381 MVD_FUNC_ENTRY();
1382 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1383 return HAL_MVD_DispRepeatField(u8HalIdx, bEnable);
1384 }
1385
1386 //------------------------------------------------------------------------------
1387 /// Get color format.
1388 /// @return - value (0~8)
1389 //------------------------------------------------------------------------------
MDrv_MVD_GetColorFormat(MS_U32 u32Id)1390 MS_U8 MDrv_MVD_GetColorFormat(MS_U32 u32Id)
1391 {
1392 MVD_FUNC_ENTRY();
1393 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1394 return HAL_MVD_GetColorFormat(u8HalIdx);
1395 }
1396
1397 //------------------------------------------------------------------------------
1398 /// Get matrix coefficients in 13818-2 sequence_display_extension().
1399 /// @return - value (0~255)
1400 //------------------------------------------------------------------------------
MDrv_MVD_GetMatrixCoef(MS_U32 u32Id)1401 MS_U8 MDrv_MVD_GetMatrixCoef(MS_U32 u32Id)
1402 {
1403 MVD_FUNC_ENTRY();
1404 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1405 return HAL_MVD_GetMatrixCoef(u8HalIdx);
1406 }
1407
1408 //------------------------------------------------------------------------------
1409 /// Issue PauseDisplay command.
1410 //------------------------------------------------------------------------------
MDrv_MVD_Pause(MS_U32 u32Id)1411 void MDrv_MVD_Pause(MS_U32 u32Id)
1412 {
1413 MVD_FUNC_ENTRY();
1414 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1415 HAL_MVD_PauseDisp(u8HalIdx);
1416 return;
1417 }
1418
1419 //------------------------------------------------------------------------------
1420 /// Issue Resume command.
1421 //------------------------------------------------------------------------------
MDrv_MVD_Resume(MS_U32 u32Id)1422 void MDrv_MVD_Resume(MS_U32 u32Id)
1423 {
1424 MVD_FUNC_ENTRY();
1425 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1426 if (HAL_MVD_Resume(u8HalIdx) == FALSE)
1427 {
1428 MVD_DEBUGERROR( MVD_ERR( "Command: HAL_MVD_Resume fail!!\r\n" ) );
1429 }
1430
1431 return;
1432 }
1433
1434 //-----------------------------------------------------------------------------
1435 /// Is MVD step decode done after step decode command.
1436 /// @return - TRUE/FALSE
1437 /// @retval -FALSE(0): decoding, or user did not send step decode command.
1438 /// @retval -TRUE(1): decode done
1439 //-----------------------------------------------------------------------------
MDrv_MVD_IsStepDecodeDone(MS_U32 u32Id)1440 MS_BOOL MDrv_MVD_IsStepDecodeDone(MS_U32 u32Id)
1441 {
1442 MS_BOOL bRet = FALSE;
1443 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1444
1445 MVD_FUNC_ENTRY();
1446 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1447 if (pCtrlCfg->bStepDecode)
1448 {
1449 if (HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_SINGLE_STEP))
1450 {
1451 MVD_PRINT( "MVD_HANDSHAKE_SINGLE_STEP -------: 0x%x \n", HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_SINGLE_STEP));
1452 pCtrlCfg->bStepDecode = FALSE;
1453 bRet = TRUE;
1454 }
1455 }
1456 return bRet;
1457 }
1458
1459 //------------------------------------------------------------------------------
1460 /// Issue StepPlay command.
1461 /// @return -TRUE for success; FALSE for failure.
1462 //------------------------------------------------------------------------------
MDrv_MVD_StepDecode(MS_U32 u32Id)1463 MS_BOOL MDrv_MVD_StepDecode(MS_U32 u32Id)
1464 {
1465 MVD_FUNC_ENTRY();
1466 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1467 HAL_MVD_ResetHandShake(u8HalIdx, MVD_HANDSHAKE_SINGLE_STEP);
1468 if (HAL_MVD_StepDecode(u8HalIdx) == FALSE)
1469 {
1470 MVD_DEBUGERROR(MVD_ERR("Command: HAL_MVD_StepDecode fail!!\r\n"));
1471 return FALSE;
1472 }
1473
1474 if (HAL_MVD_Resume(u8HalIdx) == FALSE)
1475 {
1476 MVD_DEBUGERROR(MVD_ERR("Command: HAL_MVD_Resume fail!!\r\n"));
1477 return FALSE;
1478 }
1479
1480 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1481 if (pCtrlCfg)
1482 {
1483 pCtrlCfg->bStepDecode = TRUE;
1484 }
1485 return TRUE;
1486 }
1487
1488 //-----------------------------------------------------------------------------
1489 /// Is MVD step display done after step display command.
1490 /// @return - TRUE/FALSE
1491 /// @retval -FALSE(0): decoding, or user did not send step decode command.
1492 /// @retval -TRUE(1): decode done
1493 //-----------------------------------------------------------------------------
MDrv_MVD_IsStepDispDone(MS_U32 u32Id)1494 MS_BOOL MDrv_MVD_IsStepDispDone(MS_U32 u32Id)
1495 {
1496 MVD_FUNC_ENTRY();
1497 MS_BOOL bRet = FALSE;
1498 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1499 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1500
1501 if (FALSE == pCtrlCfg->bStepDisp)
1502 {
1503 MVD_DEBUGERROR(MVD_ERR("%s err: hasn't issue StepDisp\n", __FUNCTION__));
1504 return FALSE;
1505 }
1506
1507 bRet = HAL_MVD_IsStepDispDone(u8HalIdx);
1508 if (bRet)
1509 {
1510 pCtrlCfg->bStepDisp = FALSE;
1511 }
1512 return bRet;
1513 }
1514
1515 //------------------------------------------------------------------------------
1516 /// Issue StepDisplay command.
1517 /// @return -TRUE for success; FALSE for failure.
1518 //------------------------------------------------------------------------------
MDrv_MVD_StepDisp(MS_U32 u32Id)1519 MS_BOOL MDrv_MVD_StepDisp(MS_U32 u32Id)
1520 {
1521 MVD_FUNC_ENTRY();
1522 MDrv_MVD_SetSpeed(u32Id, E_MVD_SPEED_DEFAULT, 1);
1523 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1524 if (HAL_MVD_StepDisp(u8HalIdx) == FALSE)
1525 {
1526 MVD_DEBUGERROR( MVD_ERR( "%s fail!!\n", __FUNCTION__ ) );
1527 return FALSE;
1528 }
1529
1530 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1531 if (pCtrlCfg)
1532 {
1533 pCtrlCfg->bStepDisp = TRUE;
1534 }
1535 return TRUE;
1536 }
1537
1538 //-----------------------------------------------------------------------------
1539 /// Is MVD step display done after step display command.
1540 /// @return - TRUE/FALSE
1541 /// @retval -FALSE(0): decoding, or user did not send step decode command.
1542 /// @retval -TRUE(1): decode done
1543 //-----------------------------------------------------------------------------
MDrv_MVD_IsStep2PtsDone(MS_U32 u32Id)1544 MS_BOOL MDrv_MVD_IsStep2PtsDone(MS_U32 u32Id)
1545 {
1546 MVD_FUNC_ENTRY();
1547 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1548 return HAL_MVD_IsStep2PtsDone(u8HalIdx);
1549 }
1550
1551 //------------------------------------------------------------------------------
1552 /// Step to the specific PTS (u32Pts ms)
1553 /// @return -TRUE for success; FALSE for failure.
1554 //------------------------------------------------------------------------------
MDrv_MVD_SeekToPTS(MS_U32 u32Id,MS_U32 u32Pts)1555 MS_BOOL MDrv_MVD_SeekToPTS(MS_U32 u32Id, MS_U32 u32Pts)
1556 {
1557 MVD_FUNC_ENTRY();
1558 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1559 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1560
1561 MDrv_MVD_SetSpeed(u32Id, E_MVD_SPEED_DEFAULT, 1);
1562 pCtrlCfg->bStep2Pts = HAL_MVD_SeekToPTS(u8HalIdx, _MS_TO_90K(u32Pts));
1563 return (pCtrlCfg->bStep2Pts);
1564 }
1565
1566 //------------------------------------------------------------------------------
1567 /// Skip to the specific PTS (u32Pts ms)
1568 /// @return -TRUE for success; FALSE for failure.
1569 //------------------------------------------------------------------------------
MDrv_MVD_SkipToPTS(MS_U32 u32Id,MS_U32 u32Pts)1570 MS_BOOL MDrv_MVD_SkipToPTS(MS_U32 u32Id, MS_U32 u32Pts)
1571 {
1572 MVD_FUNC_ENTRY();
1573 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1574 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1575
1576 pCtrlCfg->bSkip2Pts = HAL_MVD_SkipToPTS(u8HalIdx, _MS_TO_90K(u32Pts));
1577 return (pCtrlCfg->bSkip2Pts);
1578 }
1579
1580 //------------------------------------------------------------------------------
1581 /// Issue TrickPlay command.
1582 /// @return -TRUE for success; FALSE for failure.
1583 //------------------------------------------------------------------------------
MDrv_MVD_TrickPlay(MS_U32 u32Id,MVD_TrickDec trickDec,MS_U8 u8DispDuration)1584 MS_BOOL MDrv_MVD_TrickPlay(MS_U32 u32Id, MVD_TrickDec trickDec, MS_U8 u8DispDuration)
1585 {
1586 MVD_FUNC_ENTRY();
1587 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1588 //eTrickMode = trickDec; //for MDrv_MVD_GetTrickMode
1589 if (HAL_MVD_TrickPlay(u8HalIdx, trickDec, u8DispDuration) == FALSE)
1590 {
1591 MVD_DEBUGERROR(MVD_ERR("HAL_MVD_TrickPlay fail!!\r\n"));
1592 return FALSE;
1593 }
1594 MDrv_MVD_SetAVSync(u32Id, FALSE, 0);
1595 return TRUE;
1596 }
1597
1598 //------------------------------------------------------------------------------
1599 /// Get the trick mode which has been set.
1600 /// @return MVD_TrickDec
1601 //------------------------------------------------------------------------------
MDrv_MVD_GetTrickMode(MS_U32 u32Id)1602 MVD_TrickDec MDrv_MVD_GetTrickMode(MS_U32 u32Id)
1603 {
1604 MVD_TrickDec eTrickMode = E_MVD_TRICK_DEC_UNKNOWN;
1605 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1606 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1607 if (pCtrlCfg)
1608 {
1609 eTrickMode = pCtrlCfg->eTrickMode;
1610 }
1611
1612 return eTrickMode;
1613 }
1614
1615 //------------------------------------------------------------------------------
1616 /// Flush display buffer.
1617 /// @return -TRUE for success; FALSE for failure.
1618 //------------------------------------------------------------------------------
MDrv_MVD_FlushDisplayBuf(MS_U32 u32Id)1619 MS_BOOL MDrv_MVD_FlushDisplayBuf(MS_U32 u32Id)
1620 {
1621 MVD_FUNC_ENTRY();
1622 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1623 return HAL_MVD_FlushDisplayBuf(u8HalIdx);
1624 }
1625
1626 //------------------------------------------------------------------------------
1627 /// Get capabilities of MPEG Video Decoder.
1628 /// @return -TRUE for success; FALSE for failure.
1629 //------------------------------------------------------------------------------
MDrv_MVD_GetCaps(MVD_Caps * pCaps)1630 MS_BOOL MDrv_MVD_GetCaps(MVD_Caps* pCaps)
1631 {
1632 MS_U8 caps = HAL_MVD_GetCaps();
1633 if (!pCaps)
1634 return FALSE;
1635
1636 pCaps->bMPEG2 = ((caps & MVD_SUPPORT_MPEG2) == MVD_SUPPORT_MPEG2);
1637 pCaps->bMPEG4 = ((caps & MVD_SUPPORT_MPEG4) == MVD_SUPPORT_MPEG4);
1638 pCaps->bVC1 = ((caps & MVD_SUPPORT_VC1) == MVD_SUPPORT_VC1);
1639
1640 //MVD_PRINT("MP2=%d, MP4=%d, VC1=%d\n", pCaps->bMPEG2, pCaps->bMPEG4, pCaps->bVC1);
1641 return TRUE;
1642 }
1643
1644 //------------------------------------------------------------------------------
1645 /// Get if MVD decoder is playing.
1646 /// @return TRUE or FALSE
1647 /// - TRUE, Yes
1648 /// - FALSE, No
1649 //------------------------------------------------------------------------------
MDrv_MVD_IsPlaying(MS_U32 u32Id)1650 MS_BOOL MDrv_MVD_IsPlaying(MS_U32 u32Id)
1651 {
1652 MS_BOOL bIsPlaying = FALSE;
1653 bIsPlaying = ( MDrv_MVD_GetDecodeStatus(u32Id) == E_MVD_STAT_WAIT_DECODEDONE );
1654
1655 return bIsPlaying;
1656 }
1657
1658 //------------------------------------------------------------------------------
1659 /// Get if MVD decoder is in idle state.
1660 /// @return TRUE or FALSE
1661 /// - TRUE, Yes
1662 /// - FALSE, No
1663 //------------------------------------------------------------------------------
MDrv_MVD_IsIdle(MS_U32 u32Id)1664 MS_BOOL MDrv_MVD_IsIdle(MS_U32 u32Id)
1665 {
1666 return (MDrv_MVD_GetDecodeStatus(u32Id) == E_MVD_STAT_IDLE);
1667 }
1668
1669 //------------------------------------------------------------------------------
1670 /// Enable/Disable error concealment function
1671 /// @param -bDisable \b IN : enable/disable this function
1672 /// @return -return E_MVD_Result success/fail to enable/disable
1673 //------------------------------------------------------------------------------
MDrv_MVD_DisableErrConceal(MS_U32 u32Id,MS_BOOL bDisable)1674 E_MVD_Result MDrv_MVD_DisableErrConceal(MS_U32 u32Id, MS_BOOL bDisable)
1675 {
1676 return E_MVD_RET_FAIL;
1677 }
1678
1679 //------------------------------------------------------------------------------
1680 /// Push queue.
1681 /// @param -u32StAddr \b IN : the start address of the queue
1682 /// @param -u32Size \b IN : the data size to be pushed
1683 /// @param -u32TimeStamp \b IN : the corresponding PTS
1684 /// @return -return E_MVD_Result success/fail to push queue
1685 //------------------------------------------------------------------------------
MDrv_MVD_PushQueue(MS_U32 u32Id,MVD_PacketInfo * pInfo)1686 E_MVD_Result MDrv_MVD_PushQueue(MS_U32 u32Id, MVD_PacketInfo* pInfo)
1687 {
1688 MVD_FUNC_ENTRY();
1689 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1690
1691 //check input parameters
1692 if (pInfo == NULL)
1693 {
1694 MVD_DEBUGERROR(MVD_ERR("PushQueue NULL pInfo\n"));
1695 return E_MVD_RET_INVALID_PARAM;
1696 }
1697
1698 return HAL_MVD_PushQueue(u8HalIdx, pInfo);
1699 }
1700
1701 //------------------------------------------------------------------------------
1702 /// Flush queue: flush ES buffer, reset SLQ TABLE, flush decoded frame, and
1703 /// keep the display frame.
1704 /// @return -return E_MVD_Result success/fail to flush queue
1705 //------------------------------------------------------------------------------
MDrv_MVD_FlushQueue(MS_U32 u32Id)1706 E_MVD_Result MDrv_MVD_FlushQueue(MS_U32 u32Id)
1707 {
1708 MVD_FUNC_ENTRY();
1709 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1710 return HAL_MVD_FlushQueue(u8HalIdx);
1711 }
1712
1713
1714 //------------------------------------------------------------------------------
1715 /// Get the queue vacancy (unit in slq entry).
1716 /// @param -pQueueVacancy \b IN : pointer to the queue vacancy
1717 /// @return -return E_MVD_Result success/fail to get the queue vacancy
1718 //------------------------------------------------------------------------------
MDrv_MVD_GetQueueVacancy(MS_U32 u32Id,MS_BOOL bCached)1719 MS_U32 MDrv_MVD_GetQueueVacancy(MS_U32 u32Id, MS_BOOL bCached)
1720 {
1721 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1722 return HAL_MVD_GetQueueVacancy(u8HalIdx, bCached);
1723 }
1724
1725 //------------------------------------------------------------------------------
1726 /// Get read pointer in ElementaryStream buffer
1727 /// @return -the read pointer
1728 //------------------------------------------------------------------------------
MDrv_MVD_GetESReadPtr(MS_U32 u32Id)1729 MS_U32 MDrv_MVD_GetESReadPtr(MS_U32 u32Id)
1730 {
1731 MS_U32 u32ESR = 0;
1732 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1733 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8HalIdx);
1734
1735 if (E_MVD_SLQ_TBL_MODE == curSrcMode)
1736 {
1737 u32ESR = MVD_GetSlqTblESReadPtr(u8HalIdx);
1738 }
1739 else if (E_MVD_TS_FILE_MODE == curSrcMode || E_MVD_TS_MODE == curSrcMode)
1740 {
1741 u32ESR = HAL_MVD_GetTsFileESReadPtr(u8HalIdx);
1742 }
1743 return u32ESR;
1744 }
1745
1746
1747 //------------------------------------------------------------------------------
1748 /// Get write pointer in ElementaryStream buffer
1749 /// @return -the read pointer
1750 //------------------------------------------------------------------------------
MDrv_MVD_GetESWritePtr(MS_U32 u32Id)1751 MS_U32 MDrv_MVD_GetESWritePtr(MS_U32 u32Id)
1752 {
1753 MS_U32 u32ESW = 0;
1754 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1755 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8HalIdx);
1756
1757 if (E_MVD_SLQ_TBL_MODE == curSrcMode)
1758 {
1759 u32ESW = MVD_GetSlqTblESWritePtr(u8HalIdx);
1760 }
1761 else if (E_MVD_TS_FILE_MODE == curSrcMode || E_MVD_TS_MODE == curSrcMode)
1762 {
1763 u32ESW = HAL_MVD_GetTsFileESWritePtr(u8HalIdx);
1764 }
1765 return u32ESW;
1766 }
1767
1768
1769 //------------------------------------------------------------------------------
1770 /// Enable/Disable driver to show the last frame
1771 /// @param -bEnable \b IN : enable/disable this function
1772 /// @return -return E_MVD_Result success/fail to enable/disable
1773 //------------------------------------------------------------------------------
MDrv_MVD_EnableLastFrameShow(MS_U32 u32Id,MS_BOOL bEnable)1774 E_MVD_Result MDrv_MVD_EnableLastFrameShow(MS_U32 u32Id, MS_BOOL bEnable)
1775 {
1776 MVD_FUNC_ENTRY();
1777 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1778 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1779 if (HAL_MVD_EnableLastFrameShow(u8HalIdx, bEnable) == FALSE)
1780 {
1781 MVD_DEBUGERROR(MVD_ERR("%s fail!!\n", __FUNCTION__));
1782 return E_MVD_RET_FAIL;
1783 }
1784 pCtrlCfg->bEnableLastFrmShow = bEnable;
1785 return E_MVD_RET_OK;
1786 }
1787
1788 //------------------------------------------------------------------------------
1789 /// Get if MVD decoder finish display.
1790 /// @return TRUE or FALSE
1791 /// - TRUE, Yes
1792 /// - FALSE, No
1793 //------------------------------------------------------------------------------
MDrv_MVD_IsDispFinish(MS_U32 u32Id)1794 E_MVD_Result MDrv_MVD_IsDispFinish(MS_U32 u32Id)
1795 {
1796 MVD_FUNC_ENTRY();
1797 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1798 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1799 if (pCtrlCfg->bEnableLastFrmShow != TRUE)
1800 {
1801 MVD_DEBUGINFO(MVD_PRINT("%s: bEnableLastFrmShow!=TRUE\n", __FUNCTION__));
1802 return E_MVD_RET_FAIL;
1803 }
1804 return HAL_MVD_IsDispFinish(u8HalIdx);
1805 }
1806
1807 //------------------------------------------------------------------------------
1808 /// Set speed.
1809 /// @param -eSpeedType \b IN : specify the speed
1810 /// @param -u8Multiple \b IN :
1811 /// @return -return E_MVD_Result success/fail to set the speed
1812 //------------------------------------------------------------------------------
MDrv_MVD_SetSpeed(MS_U32 u32Id,MVD_SpeedType eSpeedType,MS_U8 u8Multiple)1813 E_MVD_Result MDrv_MVD_SetSpeed(MS_U32 u32Id, MVD_SpeedType eSpeedType, MS_U8 u8Multiple)
1814 {
1815 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1816 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1817 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1818 MVD_AVSyncCfg* pstNFPSyncCfg = &(pMVDDrvContext->stNFPSyncCfg[u8DrvIdx]);
1819
1820 if ((u8Multiple > 32) || (eSpeedType==E_MVD_SPEED_TYPE_UNKNOWN))
1821 {
1822 MVD_DEBUGINFO(MVD_PRINT("%s: invalid para!\n", __FUNCTION__));
1823 return E_MVD_RET_INVALID_PARAM;
1824 }
1825
1826 if (pstCtrlCfg->ePreSpeedType == E_MVD_SPEED_DEFAULT)
1827 { //save avsync config when normal play for restoring it later
1828 memcpy(pstNFPSyncCfg, &(pMVDDrvContext->stSyncCfg[u8DrvIdx]), sizeof(MVD_AVSyncCfg));
1829 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetSpeed save avsync: bEnable=0x%x u32Delay=0x%x u16Tolerance=0x%x\n",
1830 pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u32Delay, pstNFPSyncCfg->u16Tolerance));
1831 }
1832
1833 if (E_MVD_SPEED_DEFAULT != eSpeedType) //fast or slow forward
1834 {
1835 //disable avsyn when fast/slow forward
1836 MDrv_MVD_SetAVSync(u32Id, FALSE, 0);
1837 }
1838
1839 if (HAL_MVD_SetSpeed(u8HalIdx, eSpeedType, u8Multiple) == TRUE)
1840 {
1841 if (E_MVD_SPEED_DEFAULT == eSpeedType) //Normal Play
1842 {
1843 if (pstCtrlCfg->ePreSpeedType != E_MVD_SPEED_DEFAULT)
1844 {
1845 //set AVSync again for firmware doesn't remember AVSync settings after FF
1846 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetSpeed reset avsync: bEnable=0x%x u32Delay=0x%x u16Tolerance=0x%x\n",
1847 pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u32Delay, pstNFPSyncCfg->u16Tolerance));
1848
1849 MDrv_MVD_SetAVSync(u32Id, pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u32Delay);
1850 if ((pstNFPSyncCfg->u16Tolerance!=0) &&
1851 (FALSE == MDrv_MVD_ChangeAVsync(u32Id, pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u16Tolerance)))
1852 {
1853 return E_MVD_RET_FAIL;
1854 }
1855 }
1856 }
1857
1858 pstCtrlCfg->ePreSpeedType = eSpeedType;
1859 return E_MVD_RET_OK;
1860 }
1861 else
1862 {
1863 return E_MVD_RET_FAIL;
1864 }
1865 }
1866
1867 //------------------------------------------------------------------------------
1868 /// Reset Presentation Time Stamp according to u32PtsBase
1869 /// @param -u32PtsBase \b IN : the PTS base specified by user
1870 /// @return -return E_MVD_Result success/fail to reset PTS base
1871 //------------------------------------------------------------------------------
MDrv_MVD_ResetPTS(MS_U32 u32Id,MS_U32 u32PtsBase)1872 E_MVD_Result MDrv_MVD_ResetPTS(MS_U32 u32Id, MS_U32 u32PtsBase)
1873 {
1874 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1875 MS_U32 u32PtsBaseIn90K = 0;
1876 u32PtsBaseIn90K = _MS_TO_90K(u32PtsBase);
1877 HAL_MVD_SetPTSBase(u8HalIdx, u32PtsBaseIn90K);
1878 return E_MVD_RET_OK;
1879 }
1880
1881 //------------------------------------------------------------------------------
1882 /// Get if sequence change (width/height/framerate/interlace) occurs.
1883 /// @return TRUE or FALSE
1884 /// - TRUE, Yes
1885 /// - FALSE, No
1886 //------------------------------------------------------------------------------
MDrv_MVD_IsSeqChg(MS_U32 u32Id)1887 MS_BOOL MDrv_MVD_IsSeqChg(MS_U32 u32Id)
1888 {
1889 MVD_FrameInfo stFrmInfo;
1890 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1891 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1892 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
1893 MVD_FrameInfo* pPreInfo = &(pMVDDrvContext->stPreFrmInfo[u8DrvIdx]);
1894 MS_BOOL bRet = FALSE;
1895 MS_BOOL bResolutionChange = FALSE;
1896 memset(&stFrmInfo, 0, sizeof(stFrmInfo));
1897
1898 if (
1899 #ifdef MVD_ENABLE_ISR
1900 (MDrv_MVD_GetIsrEvent(u32Id) & E_MVD_EVENT_SEQ_FOUND) ||
1901 #endif
1902 (MDrv_MVD_GetDispRdy(u32Id))
1903 )
1904 {
1905 MDrv_MVD_GetFrameInfo(u32Id, &stFrmInfo);
1906
1907 if(pMVDDrvContext->bSelf_SeqChange[u8DrvIdx]==FALSE)
1908 {
1909 if (FALSE == pstMemCfg->bEnableDynScale)
1910 {
1911 if((pPreInfo->u16HorSize != stFrmInfo.u16HorSize) ||
1912 (pPreInfo->u16VerSize != stFrmInfo.u16VerSize) ||
1913 (pPreInfo->u32FrameRate != stFrmInfo.u32FrameRate) ||
1914 (pPreInfo->u8Interlace != stFrmInfo.u8Interlace))
1915 {
1916 #if 0
1917 (MVD_PRINT( "MDrv_MVD_IsSeqChg::Previous\n" ));
1918 (MVD_PRINT( "H=%u\n", pPreInfo->u16HorSize ));
1919 (MVD_PRINT( "V=%u\n", pPreInfo->u16VerSize ));
1920 (MVD_PRINT( "F=%lu\n", pPreInfo->u32FrameRate ));
1921 (MVD_PRINT( "A=%u\n", pPreInfo->u8AspectRate ));
1922 (MVD_PRINT( "I=%u\n", pPreInfo->u8Interlace ));
1923 #endif
1924 #if 0
1925 (MVD_PRINT( "MDrv_MVD_IsSeqChg\n" ));
1926 (MVD_PRINT( "H=%u\n", stFrmInfo.u16HorSize ));
1927 (MVD_PRINT( "V=%u\n", stFrmInfo.u16VerSize ));
1928 (MVD_PRINT( "F=%lu\n", stFrmInfo.u32FrameRate ));
1929 (MVD_PRINT( "A=%u\n", stFrmInfo.u8AspectRate ));
1930 (MVD_PRINT( "I=%u\n", stFrmInfo.u8Interlace ));
1931 #endif
1932
1933 //memcpy(&(pMVDDrvContext->stPreFrmInfo), &stFrmInfo, sizeof(MVD_FrameInfo));
1934 pPreInfo->u16HorSize = stFrmInfo.u16HorSize;
1935 pPreInfo->u16VerSize = stFrmInfo.u16VerSize;
1936 pPreInfo->u8AspectRate = stFrmInfo.u8AspectRate;
1937 pPreInfo->u32FrameRate = stFrmInfo.u32FrameRate;
1938 pPreInfo->u8Interlace = stFrmInfo.u8Interlace;
1939 #if 0
1940 (MVD_PRINT( "MDrv_MVD_IsSeqChg===>\n" ));
1941 (MVD_PRINT( "H=%u\n", stFrmInfo.u16HorSize ));
1942 (MVD_PRINT( "V=%u\n", stFrmInfo.u16VerSize ));
1943 (MVD_PRINT( "F=%u\n", stFrmInfo.u32FrameRate ));
1944 (MVD_PRINT( "A=%u\n", stFrmInfo.u8AspectRate ));
1945 (MVD_PRINT( "I=%u\n", stFrmInfo.u8Interlace ));
1946 #endif
1947 bRet = TRUE;
1948 }
1949 }
1950 else
1951 {
1952 //When dynamic scaling is enabled, f/w will handle the width/height change.
1953 //Therefore, only report SeqChg if framerate or interlace flag changes.
1954 if((pPreInfo->u32FrameRate != stFrmInfo.u32FrameRate) ||
1955 (pPreInfo->u8Interlace != stFrmInfo.u8Interlace))
1956 {
1957 pPreInfo->u8AspectRate = stFrmInfo.u8AspectRate;
1958 pPreInfo->u32FrameRate = stFrmInfo.u32FrameRate;
1959 pPreInfo->u8Interlace = stFrmInfo.u8Interlace;
1960 bRet = TRUE;
1961 }
1962 }
1963 }
1964 else
1965 {
1966
1967 if((pPreInfo->u16HorSize != stFrmInfo.u16HorSize) ||
1968 (pPreInfo->u16VerSize != stFrmInfo.u16VerSize) ||
1969 (pPreInfo->u32FrameRate != stFrmInfo.u32FrameRate) ||
1970 (pPreInfo->u8Interlace != stFrmInfo.u8Interlace) )
1971 {
1972 pPreInfo->u16HorSize = stFrmInfo.u16HorSize;
1973 pPreInfo->u16VerSize = stFrmInfo.u16VerSize;
1974 pPreInfo->u8AspectRate = stFrmInfo.u8AspectRate;
1975 pPreInfo->u32FrameRate = stFrmInfo.u32FrameRate;
1976 pPreInfo->u8Interlace = stFrmInfo.u8Interlace;
1977 bRet = TRUE;
1978 }
1979 }
1980 }
1981
1982 bResolutionChange = bRet;
1983
1984 if(HAL_MVD_GetSuspendDynamicScale(u8HalIdx) == TRUE)
1985 {
1986 if(pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] ==TRUE) //happen in first time suspend ds
1987 {
1988 pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] = FALSE;
1989 if(pMVDDrvContext->bSelf_SeqChange[u8DrvIdx]==TRUE)
1990 {
1991 bRet = bResolutionChange;
1992 }
1993 else
1994 {
1995 bRet = TRUE;
1996 }
1997 }
1998 else
1999 {
2000 if(bResolutionChange == TRUE) //happen in suspend ds and resolution change
2001 {
2002 bRet = TRUE;
2003 }
2004 else
2005 {
2006 bRet = FALSE;
2007 }
2008 }
2009 }
2010 else //normal case
2011 {
2012 if(pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] == FALSE)//happen in close suspend ds,it will reset bSuspendDS_Ftime flag
2013 {
2014 pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] = TRUE;
2015 bRet = TRUE;
2016 }
2017 else
2018 {
2019 bRet = bResolutionChange;
2020 }
2021 }
2022
2023 if (TRUE == bRet)
2024 {
2025 //Update bFrmRateSupported when IsSeqChg
2026 pMVDDrvContext->bFrmRateSupported[u8DrvIdx] = HAL_MVD_GetFrmRateIsSupported(stFrmInfo.u16HorSize, stFrmInfo.u16VerSize, stFrmInfo.u32FrameRate);
2027 MVD_DEBUGINFO(MVD_PRINT("%s bFrmRateSupported[0x%x]=%x\n", __FUNCTION__, u8DrvIdx, pMVDDrvContext->bFrmRateSupported[u8DrvIdx]));
2028 }
2029
2030 return bRet;
2031 }
2032
2033 //------------------------------------------------------------------------------
2034 /// Set Debug Data which will be queried by MDrv_MVD_DbgGetData()
2035 /// @param -u32Addr \b IN : address of debug data
2036 /// @param -u32Data \b IN : the debug data
2037 /// @return -return E_MVD_Result success/fail to set debug data
2038 //------------------------------------------------------------------------------
MDrv_MVD_DbgSetData(MS_U32 u32Id,MS_VIRT u32Addr,MS_U32 u32Data)2039 E_MVD_Result MDrv_MVD_DbgSetData(MS_U32 u32Id, MS_VIRT u32Addr, MS_U32 u32Data)
2040 {
2041 return E_MVD_RET_FAIL;
2042 }
2043
2044 //------------------------------------------------------------------------------
2045 /// Get Debug Data
2046 /// @param -u32Addr \b IN : address of debug data
2047 /// @param -u32Data \b IN : pointer to the debug data
2048 /// @return -return E_MVD_Result success/fail to get debug data
2049 //------------------------------------------------------------------------------
MDrv_MVD_DbgGetData(MS_U32 u32Id,MS_VIRT u32Addr,MS_U32 * u32Data)2050 E_MVD_Result MDrv_MVD_DbgGetData(MS_U32 u32Id, MS_VIRT u32Addr, MS_U32* u32Data)
2051 {
2052 if (!u32Data)
2053 {
2054 return E_MVD_RET_INVALID_PARAM;
2055 }
2056 return HAL_MVD_DbgGetData(u32Addr, u32Data);
2057 }
2058
2059
2060 //------------------------------------------------------------------------------
2061 /// Set MVD firmware command
2062 /// @param -u8cmd \b IN : MVD command
2063 /// @param -pstCmdArg \b IN : pointer to command argument
2064 //------------------------------------------------------------------------------
MDrv_MVD_MVDCommand(MS_U8 u8cmd,MVD_CmdArg * pstCmdArg)2065 MS_BOOL MDrv_MVD_MVDCommand ( MS_U8 u8cmd, MVD_CmdArg *pstCmdArg )
2066 {
2067 return HAL_MVD_MVDCommand(u8cmd, pstCmdArg);
2068 }
2069
2070
2071 #ifdef MVD_ENABLE_ISR
2072 ///Notice: This function only works when being called by fnHandler, which was
2073 ///registered by AP using MDrv_MVD_SetIsrEvent()
MDrv_MVD_GetIsrEvent(MS_U32 u32Id)2074 MS_U32 MDrv_MVD_GetIsrEvent(MS_U32 u32Id)
2075 {
2076 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2077 return pMVDDrvContext->_eCurEvent[u8DrvIdx];
2078 }
2079
MVD_IsrProc(void)2080 void MVD_IsrProc(void)
2081 {
2082 MS_U32 u32IntStat = 0;
2083 MS_U8 u8DrvIdx = 0xff;
2084 MS_U8 u8HalIdx = 0;
2085 MS_U32* pu32EventFlag;
2086 MS_U32* pu32CurEvent;
2087 MVD_InterruptCb pfnCb = NULL;
2088 MS_U32 u32CbData = MVD_U32_MAX;
2089
2090 //we can attach only one ISR, so we need to check the INT is from which decoder.
2091 for (u8DrvIdx=0; u8DrvIdx<MVD_MAX_STREAMS; u8DrvIdx++)
2092 {
2093 if(MVD_GetIsUsed(u8DrvIdx) == FALSE)
2094 {
2095 continue;
2096 }
2097
2098 pu32EventFlag = &(pMVDDrvContext->_eEventFlag[u8DrvIdx]);
2099 if (*pu32EventFlag == E_MVD_EVENT_DISABLE_ALL)
2100 {
2101 MVD_DEBUGINFO(MVD_PRINT("%s skip 0x%x for no registered events.\n", __FUNCTION__, u8DrvIdx));
2102 continue;
2103 }
2104
2105 u8HalIdx = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u8HalIdx;
2106
2107 if (FALSE == HAL_MVD_GetHasInt(u8HalIdx))
2108 {
2109 MVD_DEBUGINFO(MVD_PRINT("%s no INT for %x\n", __FUNCTION__, u8DrvIdx));
2110 continue;
2111 }
2112
2113 pu32CurEvent = &(pMVDDrvContext->_eCurEvent[u8DrvIdx]);
2114 pfnCb = pMVDDrvContext->_pfnCallback[u8DrvIdx];
2115 u32CbData = pMVDDrvContext->_u32CallbackPara[u8DrvIdx];
2116
2117 u32IntStat = HAL_MVD_GetIntState(u8HalIdx);
2118 if (u32IntStat != 0)
2119 {
2120 //MVD_DEBUGINFO(MVD_PRINT("MVD_IsrProc u32IntStat=%lx\n", u32IntStat));
2121 *pu32CurEvent = E_MVD_EVENT_DISABLE_ALL;
2122
2123 if ((*pu32EventFlag & E_MVD_EVENT_USER_DATA) == E_MVD_EVENT_USER_DATA)
2124 {
2125 if (MVD_IntHasUsrData(u32IntStat))
2126 {
2127 *pu32CurEvent |= E_MVD_EVENT_USER_DATA;
2128 MVD_DEBUGINFO(MVD_PRINT("===> UsrData!!!\n"));
2129 }
2130 }
2131 if ((*pu32EventFlag & E_MVD_EVENT_USER_DATA_DISP) == E_MVD_EVENT_USER_DATA_DISP)
2132 {
2133 if (MVD_IntHasUsrDataDisp(u32IntStat))
2134 {
2135 *pu32CurEvent |= E_MVD_EVENT_USER_DATA_DISP;
2136 MVD_DEBUGINFO(MVD_PRINT("===> DispUsrData!!!\n"));
2137 }
2138 }
2139 if ((*pu32EventFlag & E_MVD_EVENT_DISP_RDY) == E_MVD_EVENT_DISP_RDY)
2140 {
2141 if (MVD_IntIsDispRdy(u32IntStat))
2142 {
2143 *pu32CurEvent |= E_MVD_EVENT_DISP_RDY;
2144 MVD_DEBUGINFO(MVD_PRINT("===> DispRdy!!!\n"));
2145 }
2146 }
2147 if ((*pu32EventFlag & E_MVD_EVENT_SEQ_FOUND) == E_MVD_EVENT_SEQ_FOUND)
2148 {
2149 if (MVD_IntHasSeqHdr(u32IntStat))
2150 {
2151 *pu32CurEvent |= E_MVD_EVENT_SEQ_FOUND;
2152 MVD_DEBUGINFO(MVD_PRINT("===> SeqHdrFound!!!\n"));
2153 }
2154 }
2155 if ((*pu32EventFlag & E_MVD_EVENT_FIRST_FRAME) == E_MVD_EVENT_FIRST_FRAME)
2156 {
2157 if (MVD_IntHas1stFrame(u32IntStat))
2158 {
2159 *pu32CurEvent |= E_MVD_EVENT_FIRST_FRAME;
2160 MVD_DEBUGINFO(MVD_PRINT("===> 1stFrame!!!\n"));
2161 }
2162 }
2163 if ((*pu32EventFlag & E_MVD_EVENT_XC_LOW_DEALY) == E_MVD_EVENT_XC_LOW_DEALY)
2164 {
2165 if (MVD_IntHasXcLowDelay(u32IntStat))
2166 {
2167 *pu32CurEvent |= E_MVD_EVENT_XC_LOW_DEALY;
2168 MVD_DEBUGINFO(MVD_PRINT("===> E_MVD_EVENT_XC_LOW_DEALY!!!\n"));
2169 }
2170 }
2171 if ((*pu32EventFlag & E_MVD_EVENT_DEC_I) == E_MVD_EVENT_DEC_I)
2172 {
2173 if (MVD_IntHasDecodeIframe(u32IntStat))
2174 {
2175 *pu32CurEvent |= E_MVD_EVENT_DEC_I;
2176 MVD_DEBUGINFO(MVD_PRINT("===> E_MVD_EVENT_DEC_I!!!\n"));
2177 }
2178 }
2179 if ((*pu32EventFlag & E_MVD_EVENT_DISP_VSYNC) == E_MVD_EVENT_DISP_VSYNC)
2180 {
2181 if (MVD_IntVSyncInt(u32IntStat))
2182 {
2183 *pu32CurEvent |= E_MVD_EVENT_DISP_VSYNC;
2184 MVD_DEBUGINFO(MVD_PRINT("===> VSyncInt!!!\n"));
2185 }
2186 }
2187
2188 if ((*pu32EventFlag & E_MVD_EVENT_DEC_ONE_FRAME) == E_MVD_EVENT_DEC_ONE_FRAME)
2189 {
2190 if (MVD_IntDecOneFrmInt(u32IntStat))
2191 {
2192 *pu32CurEvent |= E_MVD_EVENT_DEC_ONE_FRAME;
2193 MVD_DEBUGINFO(MVD_PRINT("===> DecOneFrameInt!!!\n"));
2194 }
2195 }
2196
2197
2198 if ((*pu32EventFlag & E_MVD_EVENT_UNMUTE) == E_MVD_EVENT_UNMUTE)
2199 {
2200 MVD_DEBUGINFO(MVD_PRINT("E_MVD_EVENT_UNMUTE...\n"));
2201 if (MVD_IntVSyncInt(u32IntStat))
2202 {
2203 MVD_DEBUGINFO(MVD_PRINT("===> UNMUTE?!\n"));
2204 if (HAL_MVD_GetIsIPicFound(u8HalIdx) != NULL)
2205 {
2206 (pMVDDrvContext->u32VSyncCnt[u8DrvIdx])++;
2207 if ((HAL_MVD_GetIsSyncReach(u8HalIdx)==1) ||
2208 (pMVDDrvContext->u32VSyncCnt[u8DrvIdx] > 60) ||
2209 (HAL_MVD_GetIsAVSyncOn(u8HalIdx) == FALSE))
2210 {
2211 pMVDDrvContext->u32VSyncCnt[u8DrvIdx] = 0;
2212 *pu32CurEvent |= E_MVD_EVENT_UNMUTE;
2213 MVD_DEBUGINFO(MVD_PRINT("UnMute!!!\n"));
2214 *pu32EventFlag &= (~E_MVD_EVENT_UNMUTE);
2215 HAL_MVD_EnableInt(u8HalIdx, *pu32EventFlag);
2216 }
2217 }
2218 else // for P/B frame only stream
2219 {
2220 if (HAL_MVD_GetIsSyncReach(u8HalIdx) == 1) //sync done
2221 {
2222 (pMVDDrvContext->u32SyncDoneCnt[u8DrvIdx])++;
2223 }
2224
2225 if (pMVDDrvContext->u32SyncDoneCnt[u8DrvIdx] > PB_ONLY_UNMUTE_VSYNC_COUNT) //sync done
2226 {
2227 MVD_DEBUGINFO(MVD_PRINT("UnMute after %d vsync!!!\n", PB_ONLY_UNMUTE_VSYNC_COUNT));
2228 *pu32CurEvent |= E_MVD_EVENT_UNMUTE;
2229 *pu32EventFlag &= (~E_MVD_EVENT_UNMUTE);
2230 HAL_MVD_EnableInt(u8HalIdx, *pu32EventFlag);
2231 pMVDDrvContext->u32SyncDoneCnt[u8DrvIdx] = 0;
2232 }
2233 }
2234 }
2235 }
2236
2237 if ((*pu32EventFlag & E_MVD_EVENT_DEC_ERR) == E_MVD_EVENT_DEC_ERR)
2238 {
2239 if (MVD_IntHasDecodeErr(u32IntStat))
2240 {
2241 *pu32CurEvent |= E_MVD_EVENT_DEC_ERR;
2242 MVD_DEBUGINFO(MVD_PRINT("===> Decode error!!!\n"));
2243 }
2244 }
2245
2246 if ((*pu32EventFlag & E_MVD_EVENT_DEC_DATA_ERR) == E_MVD_EVENT_DEC_DATA_ERR)
2247 {
2248 if (MVD_IntHasESDataInvalid(u32IntStat))
2249 {
2250 *pu32CurEvent |= E_MVD_EVENT_DEC_DATA_ERR;
2251 MVD_DEBUGINFO(MVD_PRINT("===> ES data invaild!!!\n"));
2252 }
2253 }
2254
2255 //Events that user registered occurred, call user's callback function
2256 if ((*pu32CurEvent!=E_MVD_EVENT_DISABLE_ALL) && (pfnCb!=NULL))
2257 {
2258 MVD_DEBUGINFO(MVD_PRINT("%s Callback for *pu32CurEvent=0x%x, cbData=0x%x\n",
2259 __FUNCTION__, *pu32CurEvent, u32CbData));
2260 pfnCb(u32CbData); //FIXME: need to transfer u32Id(24-bit)
2261 }
2262 }
2263
2264 //clear events
2265 *pu32CurEvent = E_MVD_EVENT_DISABLE_ALL;
2266 }
2267
2268 HAL_MVD_ClearIRQ(); //clear interrupt
2269 if(TRUE == OSAL_MVD_IntEnable())//enable cpu interrupt mask
2270 {
2271 pMVDDrvContext->_bDisableFlag = FALSE;
2272 }
2273 }
2274
2275 //-----------------------------------------------------------------------------
2276 /// @brief \b Function \b Name: MDrv_HVD_SetISREvent()
2277 /// @brief \b Function \b Description: Set the ISR event type sended by HVD fw.
2278 /// @param -eEvent \b IN : event types
2279 /// @param -fnISRHandler \b IN : function pointer to a interrupt handler.
2280 /// @return -The result of command set ISR event.
2281 //-----------------------------------------------------------------------------
MDrv_MVD_SetIsrEvent(MS_U32 u32Id,MS_U32 eEvent,MVD_InterruptCb fnHandler)2282 E_MVD_Result MDrv_MVD_SetIsrEvent(MS_U32 u32Id, MS_U32 eEvent, MVD_InterruptCb fnHandler)
2283 {
2284 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2285
2286 if (FALSE == MVD_GetIsUsed(u8DrvIdx))
2287 {
2288 MVD_DEBUGERROR(MVD_ERR("Call %s before Init\n", __FUNCTION__));
2289 return E_MVD_RET_FAIL;
2290 }
2291
2292 if (eEvent == E_MVD_EVENT_DISABLE_ALL)
2293 {
2294 // Fix the ISR imbalance of Enable and Disable
2295 // this is the rootcase of MVD ISR fail.
2296 if((pMVDDrvContext->_bDisableFlag != TRUE) && (FALSE == pMVDDrvContext->gMVDCtrl_EX[1-u8DrvIdx].bUsed))
2297 {
2298 pMVDDrvContext->_bDisableFlag = OSAL_MVD_IntDisable();
2299 if(pMVDDrvContext->_bDisableFlag == FALSE)
2300 {
2301 MVD_DEBUGERROR(printf("%s Disable Interrupt Fail\n", __FUNCTION__));
2302 }
2303 #if !defined(SUPPORT_X_MODEL_FEATURE) && !defined(DISABLE_ISR_DETACH)
2304 if(TRUE == pMVDDrvContext->bMVDIsrAttached)
2305 {
2306 OSAL_MVD_IsrDetach();
2307 pMVDDrvContext->bMVDIsrAttached = FALSE;
2308 }
2309 #endif
2310 }
2311 pMVDDrvContext->_pfnCallback[u8DrvIdx] = NULL;
2312 pMVDDrvContext->_u32CallbackPara[u8DrvIdx] = MVD_U32_MAX;
2313 pMVDDrvContext->_eEventFlag[u8DrvIdx] = E_MVD_EVENT_DISABLE_ALL;
2314 }
2315 else
2316 {
2317 if(fnHandler != NULL)
2318 {
2319 //disable int & dettach isr?
2320
2321 pMVDDrvContext->_pfnCallback[u8DrvIdx] = (MVD_InterruptCb)fnHandler;
2322 pMVDDrvContext->_u32CallbackPara[u8DrvIdx] = u32Id;
2323 MVD_DEBUGINFO(MVD_PRINT("%s Hook callback u32Id=0x%x u8HalIdx=0x%x eEvent=0x%x\n",
2324 __FUNCTION__, u32Id, u8DrvIdx, eEvent));
2325 pMVDDrvContext->_eEventFlag[u8DrvIdx] = eEvent;
2326
2327 #if !defined(SUPPORT_X_MODEL_FEATURE) && !defined(DISABLE_ISR_DETACH)
2328 if (FALSE == pMVDDrvContext->bMVDIsrAttached)
2329 {
2330 if (OSAL_MVD_IsrAttach((void*)MVD_IsrProc) != TRUE)
2331 {
2332 MVD_DEBUGERROR(MVD_ERR("fail to attach MVD_IsrProc!\n"));
2333 return E_MVD_RET_FAIL;
2334 }
2335 pMVDDrvContext->bMVDIsrAttached = TRUE;
2336 if (OSAL_MVD_IntEnable() != TRUE)
2337 {
2338 MVD_DEBUGERROR(MVD_ERR("fail to OSAL_MVD_IntEnable!\n"));
2339 return E_MVD_RET_FAIL;
2340 }
2341 pMVDDrvContext->_bDisableFlag = FALSE;
2342 }
2343 #else
2344 if (FALSE == pMVDDrvContext->bMVDIsrAttached)
2345 {
2346 if (OSAL_MVD_IsrAttach((void*)MVD_IsrProc) != TRUE)
2347 {
2348 MVD_DEBUGERROR(MVD_ERR("fail to attach MVD_IsrProc!\n"));
2349 return E_MVD_RET_FAIL;
2350 }
2351 pMVDDrvContext->bMVDIsrAttached = TRUE;
2352 }
2353
2354 if (OSAL_MVD_IntEnable() != TRUE)
2355 {
2356 MVD_DEBUGERROR(MVD_ERR("fail to OSAL_MVD_IntEnable!\n"));
2357 return E_MVD_RET_FAIL;
2358 }
2359 pMVDDrvContext->_bDisableFlag = FALSE;
2360 #endif
2361 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetIsrEvent eEventFlag=0x%x\n", pMVDDrvContext->_eEventFlag[u8DrvIdx]));
2362 MDrv_MVD_EnableInt(u32Id, pMVDDrvContext->_eEventFlag[u8DrvIdx]);
2363 MVD_DEBUGINFO(MVD_PRINT("attach ISR number:%d\n" , E_INT_IRQ_MVD));
2364 return E_MVD_RET_OK;
2365 }
2366 else
2367 {
2368 MVD_DEBUGERROR(MVD_ERR( "SetISREvent with NULL pointer. ISR type:%u\n", (MS_U32)eEvent));
2369 return E_MVD_RET_INVALID_PARAM;
2370 }
2371 }
2372 return E_MVD_RET_OK;
2373 }
2374
2375 #endif //MVD_ENABLE_ISR
2376
2377
2378 //------------------------------------------------------------------------------
2379 /// Set AVSync mode for file mode.
2380 /// @param -eSyncMode: avsync mode for file mode
2381 //------------------------------------------------------------------------------
MDrv_MVD_SetFileModeAVSync(MS_U32 u32Id,MVD_TIMESTAMP_TYPE eSyncMode)2382 MS_BOOL MDrv_MVD_SetFileModeAVSync(MS_U32 u32Id, MVD_TIMESTAMP_TYPE eSyncMode)
2383 {
2384 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2385 return HAL_MVD_SetFileModeAVSync(u8HalIdx, eSyncMode);
2386 }
2387
2388 //-----------------------------------------------------------------------------
2389 /// @brief Check if all of the buffers(display, decoded, bitstream) are empty.
2390 /// @return - TRUE / FALSE
2391 /// @retval -FALSE(0): Not Empty.
2392 /// @retval -TRUE(1): Empty.
2393 //-----------------------------------------------------------------------------
MDrv_MVD_IsAllBufferEmpty(MS_U32 u32Id)2394 MS_BOOL MDrv_MVD_IsAllBufferEmpty(MS_U32 u32Id)
2395 {
2396 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2397 MVD_DEBUGINFO(MVD_PRINT("%s stat=0x%x, cmd=0x%x\n", __FUNCTION__,
2398 MDrv_MVD_GetDecodeStatus(u32Id), MDrv_MVD_GetLastCmd(u32Id)));
2399 return HAL_MVD_IsAllBufferEmpty(u8HalIdx);
2400 }
2401
2402 //-----------------------------------------------------------------------------
2403 /// @brief Generate specific pattern to support some special function.
2404 /// @param -u32VAddr \b IN : the virtual address of specific pattern
2405 /// @param -u32Size \b IN, OUT :
2406 /// IN: the input array size.
2407 /// OUT: the used array size.
2408 /// @return -The result of command generate specific pattern
2409 //-----------------------------------------------------------------------------
MDrv_MVD_GenPattern(MS_U32 u32Id,MVD_PatternType ePattern,MS_PHY u32PAddr,MS_U32 * pu32Size)2410 MS_BOOL MDrv_MVD_GenPattern(MS_U32 u32Id, MVD_PatternType ePattern, MS_PHY u32PAddr, MS_U32* pu32Size)
2411 {
2412 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2413 if (!pu32Size)
2414 {
2415 return FALSE;
2416 }
2417 return HAL_MVD_GenPattern(u8HalIdx, ePattern, u32PAddr, pu32Size);
2418 }
2419
2420 //-----------------------------------------------------------------------------
2421 /// @brief Get driver specific data information
2422 /// @return -the information of choosed type
2423 //-----------------------------------------------------------------------------
MDrv_MVD_GetPatternInfo(void)2424 MS_U32 MDrv_MVD_GetPatternInfo(void)
2425 {
2426 return MVD_U32_MAX;
2427 }
2428
2429 //-----------------------------------------------------------------------------
2430 /// @brief Pass scalar parameters to f/w
2431 /// @return -The result of command.
2432 //-----------------------------------------------------------------------------
MDrv_MVD_SetDynScalingParam(MS_U32 u32Id,MS_PHY u32StAddr,MS_VIRT u32Size)2433 E_MVD_Result MDrv_MVD_SetDynScalingParam(MS_U32 u32Id, MS_PHY u32StAddr, MS_VIRT u32Size)
2434 {
2435 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2436 if ((u32StAddr==NULL) || (u32Size==0))
2437 {
2438 MVD_DEBUGERROR(MVD_ERR("%s invalid para u32StAddr=0x%lx, u32Size=0x%lx\n",
2439 __FUNCTION__, u32StAddr, u32Size));
2440 return E_MVD_RET_INVALID_PARAM;
2441 }
2442 return HAL_MVD_SetDynScalingParam(u8HalIdx, u32StAddr, u32Size);
2443 }
2444
2445 //------------------------------------------------------------------------------
2446 /// Set virtual box width/height to F/W.
2447 /// F/W will use the same w/h as scaler to calculate scaling factor.
2448 /// @return -TRUE for success; FALSE for failure.
2449 //------------------------------------------------------------------------------
MDrv_MVD_SetVirtualBox(MS_U32 u32Id,MS_U16 u16Width,MS_U16 u16Height)2450 MS_BOOL MDrv_MVD_SetVirtualBox(MS_U32 u32Id, MS_U16 u16Width, MS_U16 u16Height)
2451 {
2452 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2453 MVD_DEBUGINFO(MVD_PRINT("%s: w=0x%x h=0x%x\n", __FUNCTION__, u16Width, u16Height));
2454 return HAL_MVD_SetVirtualBox(u8HalIdx, u16Width, u16Height);
2455 }
2456
2457 //------------------------------------------------------------------------------
2458 /// Set blue screen
2459 /// @return -TRUE for success; FALSE for failure.
2460 //------------------------------------------------------------------------------
MDrv_MVD_SetBlueScreen(MS_U32 u32Id,MS_BOOL bEn)2461 MS_BOOL MDrv_MVD_SetBlueScreen(MS_U32 u32Id, MS_BOOL bEn)
2462 {
2463 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2464 return HAL_MVD_SetBlueScreen(u8HalIdx, bEn);
2465 }
2466
2467 //------------------------------------------------------------------------------
2468 /// Enable/Disable VSync interrupt
2469 /// @return -TRUE for success; FALSE for failure.
2470 //------------------------------------------------------------------------------
MDrv_MVD_EnableInt(MS_U32 u32Id,MS_U32 bEn)2471 MS_BOOL MDrv_MVD_EnableInt(MS_U32 u32Id, MS_U32 bEn)
2472 {
2473 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2474 return HAL_MVD_EnableInt(u8HalIdx, bEn);
2475 }
2476
2477 //------------------------------------------------------------------------------
2478 /// Enable FW only show one field.
2479 /// @return -TRUE for success; FALSE for failure.
2480 //------------------------------------------------------------------------------
MDrv_MVD_EnableDispOneField(MS_U32 u32Id,MS_BOOL bEn)2481 E_MVD_Result MDrv_MVD_EnableDispOneField(MS_U32 u32Id, MS_BOOL bEn)
2482 {
2483 MVD_FUNC_ENTRY();
2484 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2485 return HAL_MVD_EnableDispOneField(u8HalIdx, bEn);
2486 }
2487
2488 //------------------------------------------------------------------------------
2489 /// Get extension info of the display .
2490 /// @return -TRUE for success; FALSE for failure.
2491 //------------------------------------------------------------------------------
MDrv_MVD_GetExtDispInfo(MS_U32 u32Id,MVD_ExtDispInfo * pInfo)2492 E_MVD_Result MDrv_MVD_GetExtDispInfo(MS_U32 u32Id, MVD_ExtDispInfo* pInfo)
2493 {
2494 E_MVD_Result eRet = E_MVD_RET_OK;
2495 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2496 if (NULL == pInfo)
2497 {
2498 MVD_DEBUGERROR(MVD_ERR("GetExtDispInfo NULL pInfo!\n"));
2499 return E_MVD_RET_INVALID_PARAM;
2500 }
2501
2502 HAL_MVD_GetExtDispInfo(u8HalIdx, pInfo);
2503 return eRet;
2504 }
2505
2506 //------------------------------------------------------------------------------
2507 /// Get info of the decoded/displaying frame.
2508 /// @return -TRUE for success; FALSE for failure.
2509 //------------------------------------------------------------------------------
MDrv_MVD_GetFrmInfo(MS_U32 u32Id,MVD_FrmInfoType eType,MVD_FrmInfo * pInfo)2510 E_MVD_Result MDrv_MVD_GetFrmInfo(MS_U32 u32Id, MVD_FrmInfoType eType, MVD_FrmInfo* pInfo)
2511 {
2512 E_MVD_Result eRet = E_MVD_RET_OK;
2513 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2514 if (NULL == pInfo)
2515 {
2516 MVD_DEBUGERROR(MVD_ERR("GetFrmInfo NULL pInfo!\n"));
2517 return E_MVD_RET_INVALID_PARAM;
2518 }
2519 eRet = HAL_MVD_GetFrmInfo(u8HalIdx, eType, pInfo);
2520 //MVD_DumpFrmInfo(pInfo);
2521 return eRet;
2522 }
2523
2524 //------------------------------------------------------------------------------
2525 /// Get time_code of the decoded/displaying frame.
2526 /// @return -TRUE for success; FALSE for failure.
2527 //------------------------------------------------------------------------------
MDrv_MVD_GetTimeCode(MS_U32 u32Id,MVD_FrmInfoType eType,MVD_TimeCode * pInfo)2528 E_MVD_Result MDrv_MVD_GetTimeCode(MS_U32 u32Id, MVD_FrmInfoType eType, MVD_TimeCode* pInfo)
2529 {
2530 E_MVD_Result eRet = E_MVD_RET_OK;
2531 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2532 if (NULL == pInfo)
2533 {
2534 return E_MVD_RET_INVALID_PARAM;
2535 }
2536
2537 if (TRUE != HAL_MVD_GetTimeCode(u8HalIdx, eType, pInfo))
2538 {
2539 MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_GetTimeCode fail\n"));
2540 return E_MVD_RET_FAIL;
2541 }
2542
2543 if ((E_MVD_FRMINFO_DECODE != eType) || (E_MVD_FRMINFO_DISPLAY == eType))
2544 {
2545 eRet = E_MVD_RET_INVALID_PARAM;
2546 }
2547
2548 return eRet;
2549 }
2550
MDrv_MVD_GetUsrDataIsAvailable(MS_U32 u32Id)2551 MS_BOOL MDrv_MVD_GetUsrDataIsAvailable(MS_U32 u32Id)
2552 {
2553 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2554 return HAL_MVD_GetUsrDataIsAvailable(u8HalIdx);
2555 }
2556
2557 //------------------------------------------------------------------------------
2558 /// Get info of user data
2559 //------------------------------------------------------------------------------
MDrv_MVD_GetUsrDataInfo(MS_U32 u32Id,MVD_UsrDataInfo * pUsrInfo)2560 MS_BOOL MDrv_MVD_GetUsrDataInfo(MS_U32 u32Id, MVD_UsrDataInfo* pUsrInfo)
2561 {
2562 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2563 if (!pUsrInfo)
2564 {
2565 MVD_DEBUGERROR(MVD_ERR("%s: NULL ptr.\n", __FUNCTION__));
2566 return FALSE;
2567 }
2568 return HAL_MVD_GetUsrDataInfo(u8HalIdx, pUsrInfo);
2569 }
2570
2571 //------------------------------------------------------------------------------
2572 /// Enable/Disable freezing display
2573 /// Once this flag is set, firmware continue decode new frame
2574 /// but not to push this frame into display queue.
2575 /// @return -TRUE for success; FALSE for failure.
2576 //------------------------------------------------------------------------------
MDrv_MVD_SetFreezeDisp(MS_U32 u32Id,MS_BOOL bEn)2577 E_MVD_Result MDrv_MVD_SetFreezeDisp(MS_U32 u32Id, MS_BOOL bEn)
2578 {
2579 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2580
2581 MDrv_MVD_SetSpeed(u32Id, E_MVD_SPEED_DEFAULT, 1);
2582 if (TRUE == HAL_MVD_SetFreezeDisp(u8HalIdx, bEn))
2583 {
2584 return E_MVD_RET_OK;
2585 }
2586 else
2587 {
2588 return E_MVD_RET_FAIL;
2589 }
2590 }
2591
2592 //------------------------------------------------------------------------------
2593 /// Get MVD displayed picture counter
2594 /// @return - displayed picture counter
2595 //------------------------------------------------------------------------------
MDrv_MVD_GetDispCount(MS_U32 u32Id)2596 MS_U32 MDrv_MVD_GetDispCount(MS_U32 u32Id)
2597 {
2598 MVD_FUNC_ENTRY();
2599 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2600 return HAL_MVD_GetDispCnt(u8HalIdx);
2601 }
2602
2603 //------------------------------------------------------------------------------
2604 /// Set MVD fd mask delay count
2605 /// 16bits and unit in vsync for mute the fd_mask
2606 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2607 //------------------------------------------------------------------------------
MDrv_MVD_SetFdMaskDelayCount(MS_U32 u32Id,MS_U16 u16Cnt)2608 E_MVD_Result MDrv_MVD_SetFdMaskDelayCount(MS_U32 u32Id, MS_U16 u16Cnt)
2609 {
2610 MVD_FUNC_ENTRY();
2611 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2612 return HAL_MVD_SetFdMaskDelayCount(u8HalIdx, u16Cnt);
2613 }
2614
2615 //------------------------------------------------------------------------------
2616 /// Set MVD fd mask delay count
2617 /// 16bits and unit in vsync for mute the fd_mask
2618 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2619 //------------------------------------------------------------------------------
MDrv_MVD_GetXcLowDelayIntState(MS_U32 u32Id)2620 E_MVD_Result MDrv_MVD_GetXcLowDelayIntState(MS_U32 u32Id)
2621 {
2622 MVD_FUNC_ENTRY();
2623 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2624 return HAL_MVD_GetXcLowDelayIntState(u8HalIdx);
2625 }
2626
2627 //------------------------------------------------------------------------------
2628 /// Set MVD output frame rate convert
2629 /// @param u8FrameRate \b IN : output frame rate of 8bits and unit in vsync
2630 /// @param u8Interlace \b IN : scan style 0:progress, 1:interlace
2631 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2632 //------------------------------------------------------------------------------
MDrv_MVD_SetOutputFRCMode(MS_U32 u32Id,MS_U8 u8FrameRate,MS_U8 u8Interlace)2633 E_MVD_Result MDrv_MVD_SetOutputFRCMode(MS_U32 u32Id, MS_U8 u8FrameRate, MS_U8 u8Interlace)
2634 {
2635 MVD_FUNC_ENTRY();
2636 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2637 return HAL_MVD_SetOutputFRCMode(u8HalIdx, u8FrameRate, u8Interlace);
2638 }
2639
2640 //------------------------------------------------------------------------------
2641 /// Set MVD FRC drop type.
2642 /// @param u8DropType \b IN : drop type. 0:drop frame, 1:drop field. default:0
2643 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2644 //------------------------------------------------------------------------------
MDrv_MVD_SetFRCDropType(MS_U32 u32Id,MS_U8 u8DropType)2645 E_MVD_Result MDrv_MVD_SetFRCDropType(MS_U32 u32Id, MS_U8 u8DropType)
2646 {
2647 MVD_FUNC_ENTRY();
2648 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2649 return HAL_MVD_SetFRCDropType(u8HalIdx, u8DropType);
2650 }
2651
2652 //------------------------------------------------------------------------------
2653 /// Set disable resolution change.
2654 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2655 //------------------------------------------------------------------------------
MDrv_MVD_SetDisableSeqChange(MS_U32 u32Id,MS_BOOL bEnable)2656 E_MVD_Result MDrv_MVD_SetDisableSeqChange(MS_U32 u32Id, MS_BOOL bEnable)
2657 {
2658 MVD_FUNC_ENTRY();
2659 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2660 return HAL_MVD_SetDisableSeqChange(u8HalIdx, bEnable);
2661 }
2662
2663 //------------------------------------------------------------------------------
2664 /// Debug function to dump useful info.
2665 //------------------------------------------------------------------------------
MDrv_MVD_DbgDump(MS_U32 u32Id)2666 void MDrv_MVD_DbgDump(MS_U32 u32Id)
2667 {
2668 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2669 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2670 MVD_FrameInfo* pPreInfo = &(pMVDDrvContext->stPreFrmInfo[u8DrvIdx]);
2671 MVD_AVSyncCfg* pAVSyncCfg = &(pMVDDrvContext->stSyncCfg[u8DrvIdx]);
2672
2673 if (FALSE == MVD_GetIsUsed(u8DrvIdx))
2674 {
2675 MVD_PRINT("%s: _bDrvInit false!\n", __FUNCTION__);
2676 return;
2677 }
2678
2679 HAL_MVD_DbgDump(u8HalIdx);
2680 MVD_PRINT("avsync on=%x, delay=%d, tolerance=%d, done=%x, skip=%x, repeat=%x, pts=%dms\n",
2681 pAVSyncCfg->bEnable, pAVSyncCfg->u32Delay, pAVSyncCfg->u16Tolerance, (MDrv_MVD_GetSyncStatus(u32Id)==1),
2682 MDrv_MVD_GetIsSyncSkip(u32Id), MDrv_MVD_GetIsSyncRep(u32Id), MDrv_MVD_GetPTS(u32Id));
2683 MVD_PRINT("seq(%d): w=%d, h=%d, i/p=%x, fps=%d\n", MDrv_MVD_GetDispRdy(u32Id),
2684 pPreInfo->u16HorSize, pPreInfo->u16VerSize,
2685 pPreInfo->u8Interlace, pPreInfo->u32FrameRate);
2686 }
2687
2688 //------------------------------------------------------------------------------
2689 /// Dump the bitstream to predefined buffer address.
2690 /// Before PLAY command, set the bitstream base & bitstream length, and then
2691 /// CPU would continue to dump bitstream at the base address.
2692 /// @param -u32base \b IN : start address (MIU offset, e.g. 128M==>0MB)
2693 /// @param -u32size \b IN : size (bytes)
2694 //------------------------------------------------------------------------------
MDrv_MVD_DbgDumpBits(MS_U32 u32Id,MS_PHY u32base,MS_U32 u32size)2695 void MDrv_MVD_DbgDumpBits(MS_U32 u32Id, MS_PHY u32base, MS_U32 u32size)
2696 {
2697 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2698 HAL_MVD_DbgDumpBits(u8HalIdx, u32base, u32size);
2699 return;
2700 }
2701
2702 // only for VDEC internal link patch
MDrv_MVD_LinkWeakSymbolPatch(void)2703 MS_BOOL MDrv_MVD_LinkWeakSymbolPatch(void)
2704 {
2705 return TRUE;
2706 }
2707
2708 //------------------------------------------------------------------------------
2709 /// Set firmware as MStreamer mode
2710 /// @return -TRUE for success; FALSE for failure.
2711 //------------------------------------------------------------------------------
MDrv_MVD_SetMStreamerMode(MS_U32 u32Id,MS_U8 u8Mode)2712 MS_BOOL MDrv_MVD_SetMStreamerMode(MS_U32 u32Id, MS_U8 u8Mode)
2713 {
2714 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2715 return HAL_MVD_SetMStreamerMode(u8HalIdx, u8Mode);
2716 }
2717
2718 //-----------------------------------------------------------------------------
2719 /// set firmware as MCU mode
2720 /// @return -TRUE for success; FALSE for failure.
2721 //-----------------------------------------------------------------------------
MDrv_MVD_SetMcuMode(MS_U32 u32Id,MS_U8 u8Mode)2722 MS_BOOL MDrv_MVD_SetMcuMode(MS_U32 u32Id, MS_U8 u8Mode)
2723 {
2724 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2725 return HAL_MVD_SetMcuMode(u8HalIdx, u8Mode);
2726 }
2727
2728 //-----------------------------------------------------------------------------
2729 /// set firmware as I/P clip mode mode
2730 /// @return -TRUE for success; FALSE for failure.
2731 //-----------------------------------------------------------------------------
MDrv_MVD_ShowDecodeOrder(MS_U32 u32Id,MS_U8 u8Mode)2732 MS_BOOL MDrv_MVD_ShowDecodeOrder(MS_U32 u32Id, MS_U8 u8Mode)
2733 {
2734 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2735 return HAL_MVD_ShowDecodeOrder(u8HalIdx, u8Mode);
2736 }
2737
2738
2739
2740 //------------------------------------------------------------------------------
2741 /// Flip the specified frame
2742 /// @return -TRUE for success; FALSE for failure.
2743 //------------------------------------------------------------------------------
MDrv_MVD_FrameFlip(MS_U32 u32Id,MS_U8 u8FrmIdx)2744 MS_BOOL MDrv_MVD_FrameFlip(MS_U32 u32Id, MS_U8 u8FrmIdx)
2745 {
2746 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2747 if (TRUE != HAL_MVD_IsMStreamerMode(u8HalIdx))
2748 {
2749 MVD_DEBUGINFO(MVD_PRINT("Need to SetMStreamerMode before using this function\n"));
2750 return FALSE;
2751 }
2752
2753 if (TRUE == HAL_MVD_IsMcuMode(u8HalIdx))
2754 {
2755 MVD_DEBUGINFO(MVD_PRINT("It's MCU mode, doesn't need to using this fuction\n"));
2756 return FALSE;
2757 }
2758
2759 return HAL_MVD_FrameOpt(u8HalIdx, u8FrmIdx, E_MVD_FRAME_FLIP);
2760 }
2761
2762 //------------------------------------------------------------------------------
2763 /// Release the specified frame
2764 /// @return -TRUE for success; FALSE for failure.
2765 //------------------------------------------------------------------------------
MDrv_MVD_FrameRelease(MS_U32 u32Id,MS_U8 u8FrmIdx)2766 MS_BOOL MDrv_MVD_FrameRelease(MS_U32 u32Id, MS_U8 u8FrmIdx)
2767 {
2768 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2769 if (TRUE != (HAL_MVD_IsMStreamerMode(u8HalIdx) || HAL_MVD_IsMcuMode(u8HalIdx)) )
2770 {
2771 MVD_DEBUGINFO(MVD_PRINT("Need to SetMStreamerMode or SetMcuMode before using this function\n"));
2772 return FALSE;
2773 }
2774 return HAL_MVD_FrameOpt(u8HalIdx, u8FrmIdx, E_MVD_FRAME_RELEASE);
2775 }
2776
2777 //------------------------------------------------------------------------------
2778 /// Enable/Disable to capture the specified frame
2779 /// @return -TRUE for success; FALSE for failure.
2780 //------------------------------------------------------------------------------
MDrv_MVD_FrameCapture(MS_U32 u32Id,MS_U8 u8FrmIdx,MS_BOOL bEnable)2781 MS_BOOL MDrv_MVD_FrameCapture(MS_U32 u32Id, MS_U8 u8FrmIdx, MS_BOOL bEnable)
2782 {
2783 MS_BOOL ret = FALSE;
2784 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2785
2786 if (TRUE != HAL_MVD_IsMStreamerMode(u8HalIdx))
2787 {
2788 MVD_DEBUGINFO(MVD_PRINT("Need to SetMStreamerMode before using this function\n"));
2789 return FALSE;
2790 }
2791
2792 ret = HAL_MVD_FrameCapture(u8HalIdx, u8FrmIdx, bEnable);
2793
2794 //firmware will keep this frame until we release it.
2795 if (ret && !bEnable)
2796 {
2797 ret = MDrv_MVD_FrameRelease(u32Id, u8FrmIdx);
2798 }
2799
2800 return ret;
2801 }
2802
2803 //------------------------------------------------------------------------------
2804 /// Allocate share memory from MSOS for Drv MVD
2805 /// @return -TRUE for success; FALSE for failure.
2806 //------------------------------------------------------------------------------
MDrv_MVD_Init_Share_Mem(void)2807 E_MVD_Result MDrv_MVD_Init_Share_Mem(void)
2808 {
2809 #if ((defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_ECOS)) && (!defined(SUPPORT_X_MODEL_FEATURE)))
2810 MS_U32 u32ShmId;
2811 MS_VIRT u32Addr;
2812 MS_U32 u32BufSize;
2813
2814
2815 if (FALSE == MsOS_SHM_GetId( (MS_U8*)"Linux MVD driver",
2816 sizeof(MVD_Drv_CTX),
2817 &u32ShmId,
2818 &u32Addr,
2819 &u32BufSize,
2820 MSOS_SHM_QUERY))
2821 {
2822 if (FALSE == MsOS_SHM_GetId((MS_U8*)"Linux MVD driver",
2823 sizeof(MVD_Drv_CTX),
2824 &u32ShmId,
2825 &u32Addr,
2826 &u32BufSize,
2827 MSOS_SHM_CREATE))
2828 {
2829 MVD_DEBUGERROR(MVD_ERR("[%s]SHM allocation failed!!! use global structure instead!!!\n",__FUNCTION__));
2830 if(pMVDDrvContext == NULL)
2831 {
2832 pMVDDrvContext = &gMVDDrvContext;
2833 memset(pMVDDrvContext,0,sizeof(MVD_Drv_CTX));
2834 MVD_Context_Init();
2835 MVD_PRINT("[%s]Global structure init Success!!!\n",__FUNCTION__);
2836 }
2837 else
2838 {
2839 MVD_PRINT("[%s]Global structure exists!!!\n",__FUNCTION__);
2840 }
2841 //return E_MVD_RET_FAIL;
2842 }
2843 else
2844 {
2845 memset((MS_U8*)u32Addr,0,sizeof(MVD_Drv_CTX));
2846 pMVDDrvContext = (MVD_Drv_CTX*)u32Addr; // for one process
2847 MVD_Context_Init();
2848 }
2849 }
2850 else
2851 {
2852 pMVDDrvContext = (MVD_Drv_CTX*)u32Addr; // for another process
2853 }
2854 #else
2855 if(pMVDDrvContext == NULL)
2856 {
2857 pMVDDrvContext = &gMVDDrvContext;
2858 memset(pMVDDrvContext,0,sizeof(MVD_Drv_CTX));
2859 MVD_Context_Init();
2860 }
2861 #endif
2862
2863 if(HAL_MVD_Init_Share_Mem() != TRUE)
2864 {
2865 return E_MVD_RET_FAIL;
2866 }
2867
2868 if(HAL_VPU_EX_Init_Share_Mem() != TRUE)
2869 {
2870 return E_MVD_RET_FAIL;
2871 }
2872
2873 return E_MVD_RET_OK;
2874 }
2875
2876
2877 //------------------------------------------------------------------------------
2878 /// Get the available streamID for the specified stream type
2879 /// @return u32ID as (drvIdx << 16 | u32MVDStreamId << 8 | u32VPUStreamId)
2880 //------------------------------------------------------------------------------
MDrv_MVD_GetFreeStream(MS_U32 * pu32Id,MVD_DRV_StreamType eStreamType)2881 E_MVD_Result MDrv_MVD_GetFreeStream(MS_U32 *pu32Id, MVD_DRV_StreamType eStreamType)
2882 {
2883 MS_U8 i = 0xff;
2884 MS_U32 u32VPUStreamId = 0;
2885 MS_U32 u32MVDStreamId = 0;
2886 HAL_VPU_StreamType eVpuStreamType = E_HAL_VPU_MAIN_STREAM;
2887 HAL_MVD_StreamType eHalStreamType = E_HAL_MVD_MAIN_STREAM;
2888
2889 if(pu32Id == NULL)
2890 {
2891 MVD_DEBUGERROR(MVD_ERR("%s err: NULL pu32Id\n", __FUNCTION__));
2892 return E_MVD_RET_INVALID_PARAM;
2893 }
2894 else
2895 {
2896 *pu32Id = 0;
2897 }
2898
2899 //Get drvIdx
2900 switch (eStreamType)
2901 {
2902 // drvIdx is fixed for one MVD_DRV_StreamType
2903 case E_MVD_DRV_MAIN_STREAM:
2904 i=0;
2905 break;
2906 case E_MVD_DRV_SUB_STREAM:
2907 i=1;
2908 break;
2909 case E_MVD_DRV_STREAM_NONE:
2910 default:
2911 i=0xff;
2912 break;
2913 }
2914 if ((i>=MVD_MAX_STREAMS) || (TRUE == MVD_GetIsUsed(i)))
2915 {
2916 MVD_DEBUGERROR(MVD_ERR("eStreamType=%x is used or invalid, i=%x\n", eStreamType, i));
2917 *pu32Id = 0;
2918 return E_MVD_RET_FAIL;
2919 }
2920
2921 //Get VPU & HAL stream id
2922 if (E_MVD_DRV_MAIN_STREAM == eStreamType)
2923 {
2924 eVpuStreamType = E_HAL_VPU_MAIN_STREAM;
2925 eHalStreamType = E_HAL_MVD_MAIN_STREAM;
2926 }
2927 else if (E_MVD_DRV_SUB_STREAM == eStreamType)
2928 {
2929 eVpuStreamType = E_HAL_VPU_SUB_STREAM;
2930 eHalStreamType = E_HAL_MVD_SUB_STREAM;
2931 }
2932 u32VPUStreamId = (MS_U32) HAL_VPU_EX_GetFreeStream(eVpuStreamType);
2933 if(u32VPUStreamId == E_HAL_VPU_STREAM_NONE)
2934 {
2935 return E_MVD_RET_FAIL;
2936 }
2937 u32MVDStreamId = (MS_U32) HAL_MVD_GetFreeStream(eHalStreamType);
2938
2939 MVD_DEBUGVERBAL(MVD_PRINT("%s:: i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__,
2940 i, u32MVDStreamId, u32VPUStreamId));
2941 if (u32VPUStreamId && u32MVDStreamId)
2942 {
2943 MVD_DEBUGINFO(MVD_PRINT("%s i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__,
2944 i, u32MVDStreamId, u32VPUStreamId));
2945 *pu32Id = (i << 16 | u32MVDStreamId << 8 | u32VPUStreamId);
2946 if (FALSE == MVD_SaveStreamId(i, u32MVDStreamId, u32VPUStreamId))
2947 {
2948 return E_MVD_RET_FAIL;
2949 }
2950 }
2951 else
2952 {
2953 MVD_DEBUGINFO(MVD_PRINT("%s(%d) NG i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__, __LINE__,
2954 i, u32MVDStreamId, u32VPUStreamId));
2955 }
2956
2957 return E_MVD_RET_OK;
2958 }
2959
2960 //------------------------------------------------------------------------------
2961 /// Set bitstream buffer overflow threshold
2962 /// @return -none
2963 //------------------------------------------------------------------------------
MDrv_MVD_SetOverflowTH(MS_U32 u32Id,MS_U32 u32Threshold)2964 void MDrv_MVD_SetOverflowTH(MS_U32 u32Id, MS_U32 u32Threshold)
2965 {
2966 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2967 HAL_MVD_SetOverflowTH(u8HalIdx, u32Threshold);
2968 return;
2969 }
2970
2971 //------------------------------------------------------------------------------
2972 /// Set bitstream buffer underflow threshold
2973 /// @return -none
2974 //------------------------------------------------------------------------------
MDrv_MVD_SetUnderflowTH(MS_U32 u32Id,MS_U32 u32Threshold)2975 void MDrv_MVD_SetUnderflowTH(MS_U32 u32Id, MS_U32 u32Threshold)
2976 {
2977 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2978 HAL_MVD_SetUnderflowTH(u8HalIdx, u32Threshold);
2979 return;
2980 }
2981
MDrv_MVD_SetSingleDecodeMode(MS_BOOL bEnable)2982 MS_BOOL MDrv_MVD_SetSingleDecodeMode(MS_BOOL bEnable)
2983 {
2984 return HAL_VPU_EX_SetSingleDecodeMode(bEnable);
2985 }
2986
2987 //-----------------------------------------------------------------------------
2988 /// Release fd mask
2989 /// @return -TRUE for success; FALSE for failure.
2990 //-----------------------------------------------------------------------------
MDrv_MVD_ReleaseFdMask(MS_U32 u32Id,MS_BOOL bRls)2991 MS_BOOL MDrv_MVD_ReleaseFdMask(MS_U32 u32Id, MS_BOOL bRls)
2992 {
2993 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2994 return HAL_MVD_ReleaseFdMask(u8HalIdx, bRls);
2995 }
2996
2997 //------------------------------------------------------------------------------
2998 /// Reset MVD parser . It is used to reset MVD Parser.
2999 /// @return -TRUE for success; FALSE for failure.
3000 //------------------------------------------------------------------------------
MDrv_MVD_ParserRstDone(MS_U32 u32Id,MS_BOOL bEnable)3001 MS_BOOL MDrv_MVD_ParserRstDone(MS_U32 u32Id, MS_BOOL bEnable)
3002 {
3003 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3004 return HAL_MVD_ParserRstDone(u8HalIdx, bEnable);
3005 }
3006 //------------------------------------------------------------------------------
3007 /// Flush PTS buffer.
3008 /// @return -TRUE for success; FALSE for failure.
3009 //------------------------------------------------------------------------------
MDrv_MVD_FlushPTSBuf(MS_U32 u32Id,MS_BOOL bEnable)3010 MS_BOOL MDrv_MVD_FlushPTSBuf(MS_U32 u32Id,MS_BOOL bEnable)
3011 {
3012 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3013 return HAL_MVD_FlushPTSBuf(u8HalIdx ,bEnable);
3014 }
3015
3016 //------------------------------------------------------------------------------
3017 /// Get SLQ number
3018 /// @return -the SLQ number
3019 //------------------------------------------------------------------------------
MDrv_MVD_GetSLQNum(MS_U32 u32Id)3020 MS_U32 MDrv_MVD_GetSLQNum(MS_U32 u32Id)
3021 {
3022 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3023 return HAL_MVD_GetSLQNum(u8HalIdx);
3024 }
3025
3026
3027 //-----------------------------------------------------------------------------
3028 /// @brief \b Function \b Name: MDrv_MVD_GetFrmRateIsSupported()
3029 /// @brief \b Function \b Description: Get if the framerate is supported
3030 /// @return -The result of supported or not.
3031 //-----------------------------------------------------------------------------
MDrv_MVD_GetFrmRateIsSupported(MS_U32 u32Id)3032 MS_BOOL MDrv_MVD_GetFrmRateIsSupported(MS_U32 u32Id)
3033 {
3034 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
3035 MS_BOOL bSupported = pMVDDrvContext->bFrmRateSupported[u8DrvIdx];
3036
3037 return bSupported;
3038 }
3039
3040 //------------------------------------------------------------------------------
3041 /// set fw auto mute
3042 /// @return -TRUE for success; FALSE for failure.
3043 //------------------------------------------------------------------------------
MDrv_MVD_SetAutoMute(MS_U32 u32Id,MS_BOOL bEnable)3044 E_MVD_Result MDrv_MVD_SetAutoMute(MS_U32 u32Id, MS_BOOL bEnable)
3045 {
3046 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3047 MS_BOOL bRet = HAL_MVD_SetAutoMute(u8HalIdx, bEnable);
3048 return ((TRUE == bRet) ? E_MVD_RET_OK : E_MVD_RET_FAIL);
3049 }
3050
MDrv_MVD_SetVSizeAlign(MS_U32 u32Id,MS_BOOL bEnable)3051 MS_BOOL MDrv_MVD_SetVSizeAlign(MS_U32 u32Id, MS_BOOL bEnable)
3052 {
3053 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3054 return HAL_MVD_SetVSizeAlign(u8HalIdx, bEnable);
3055 }
3056
3057 //------------------------------------------------------------------------------
3058 /// Set codec type.
3059 /// @param -pCrcIn \b IN : the struct of generate CRC
3060 /// @param -pCrcOut \b OUT : CRC value from mvd hw
3061 //------------------------------------------------------------------------------
MDrv_MVD_GetCrcValue(MS_U32 u32Id,MVD_CrcIn * pCrcIn,MVD_CrcOut * pCrcOut)3062 E_MVD_Result MDrv_MVD_GetCrcValue(MS_U32 u32Id, MVD_CrcIn *pCrcIn, MVD_CrcOut *pCrcOut)
3063 {
3064 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3065
3066 //check input parameters
3067 if (pCrcIn == NULL)
3068 {
3069 MVD_DEBUGERROR(MVD_ERR("PushQueue NULL pInfo\n"));
3070 return E_MVD_RET_INVALID_PARAM;
3071 }
3072
3073 return HAL_MVD_GetCrcValue(u8HalIdx, pCrcIn, pCrcOut);
3074 }
3075
3076 //------------------------------------------------------------------------------
3077 /// set debug mode
3078 /// @return -TRUE for success; FALSE for failure.
3079 //------------------------------------------------------------------------------
MDrv_MVD_SetDbgMode(MS_U32 u32Id,MVD_DbgMode enDbgMode,MS_BOOL bEn)3080 E_MVD_Result MDrv_MVD_SetDbgMode(MS_U32 u32Id, MVD_DbgMode enDbgMode, MS_BOOL bEn)
3081 {
3082 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3083 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
3084 E_MVD_Result eRet=E_MVD_RET_FAIL;
3085
3086 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetDbgMode...%x\n",(unsigned int)pstCtrlCfg->stDbgModeCfg.value));
3087 switch (enDbgMode)
3088 {
3089 case E_MVD_EX_DBG_MODE_BYPASS_INSERT_START_CODE:
3090 {
3091 pstCtrlCfg->stDbgModeCfg.bBypassInsertStartCode=bEn;
3092 eRet=E_MVD_RET_OK;
3093 }
3094 break;
3095 case E_MVD_EX_DBG_MODE_BYPASS_DIVX_MC_PATCH:
3096 {
3097 pstCtrlCfg->stDbgModeCfg.bBypassDivxMCPatch=bEn;
3098 eRet=E_MVD_RET_OK;
3099 }
3100 break;
3101 default:
3102 eRet=E_MVD_RET_INVALID_PARAM;
3103 break;
3104 }
3105 MVD_DEBUGINFO(MVD_PRINT("%s stDbgModeCfg=%x\n", __FUNCTION__, (unsigned int)pstCtrlCfg->stDbgModeCfg.value));
3106 return eRet;
3107 }
3108
3109 //------------------------------------------------------------------------------
3110 /// Get SLQ number
3111 /// @return -the SLQ number
3112 //------------------------------------------------------------------------------
MDrv_MVD_GetDispQNum(MS_U32 u32Id)3113 MS_U32 MDrv_MVD_GetDispQNum(MS_U32 u32Id)
3114 {
3115 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3116 return HAL_MVD_GetDispQNum(u8HalIdx);
3117 }
3118
3119 //------------------------------------------------------------------------------
3120 /// set fw fask suspend
3121 /// @return -TRUE for success; FALSE for failure.
3122 //------------------------------------------------------------------------------
3123
MDrv_MVD_SuspendDynamicScale(MS_U32 u32Id,MS_BOOL bEnable)3124 MS_BOOL MDrv_MVD_SuspendDynamicScale(MS_U32 u32Id, MS_BOOL bEnable)
3125 {
3126 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3127 return HAL_MVD_SuspendDynamicScale(u8HalIdx, bEnable);
3128 }
3129
MDrv_MVD_GetSuspendDynamicScale(MS_U32 u32Id)3130 MS_U8 MDrv_MVD_GetSuspendDynamicScale(MS_U32 u32Id)
3131 {
3132 MVD_FUNC_ENTRY();
3133 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3134 return HAL_MVD_GetSuspendDynamicScale(u8HalIdx);
3135 }
3136
3137 //------------------------------------------------------------------------------
3138 /// Get MVD DivX plus Version,
3139 /// @return -non DivX plus \b OUT 0
3140 //------------------------------------------------------------------------------
MDrv_MVD_GetDivxVer(MS_U32 u32Id)3141 MS_U32 MDrv_MVD_GetDivxVer(MS_U32 u32Id)
3142 {
3143 MVD_FUNC_ENTRY();
3144 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3145 return HAL_MVD_GetDivxVer(u8HalIdx);
3146 }
3147
3148 //------------------------------------------------------------------------------
3149 /// Set IDCT mode
3150 /// @param -u8Mode \b IN : 0 for original IDCT, 1 for new IDCT
3151 /// @return -TRUE for success; FALSE for failure.
3152 //------------------------------------------------------------------------------
MDrv_MVD_SetIdctMode(MS_U32 u32Id,MS_U8 u8Mode)3153 MS_BOOL MDrv_MVD_SetIdctMode(MS_U32 u32Id, MS_U8 u8Mode)
3154 {
3155 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3156
3157 return HAL_MVD_SetIdctMode(u8HalIdx, u8Mode);
3158 }
3159
3160 //-----------------------------------------------------------------------------
3161 /// @brief \b Function \b Name: MDrv_MVD_EX_SetMVDClockSpeed()
3162 /// @brief \b Function \b Description: set mvd clock speed
3163 /// @return - The result of setting mvd clock speed
3164 //-----------------------------------------------------------------------------
MDrv_MVD_EX_SetMVDClockSpeed(MVD_EX_ClockSpeed eClockSpeed)3165 E_MVD_Result MDrv_MVD_EX_SetMVDClockSpeed(MVD_EX_ClockSpeed eClockSpeed)
3166 {
3167 HAL_MVD_EX_ClockSpeed eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_NONE;
3168 switch (eClockSpeed)
3169 {
3170 case E_MVD_EX_CLOCK_SPEED_HIGHEST:
3171 eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_HIGHEST;
3172 break;
3173 case E_MVD_EX_CLOCK_SPEED_HIGH:
3174 eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_HIGH;
3175 break;
3176 case E_MVD_EX_CLOCK_SPEED_MEDIUM:
3177 eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_MEDIUM;
3178 break;
3179 case E_MVD_EX_CLOCK_SPEED_LOW:
3180 eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_LOW;
3181 break;
3182 case E_MVD_EX_CLOCK_SPEED_LOWEST:
3183 eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_LOWEST;
3184 break;
3185 case E_MVD_EX_CLOCK_SPEED_DEFAULT:
3186 eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_DEFAULT;
3187 break;
3188 default:
3189 MVD_DEBUGERROR(MVD_ERR("mvd clock setting is wrong(%d)\n", eClockSpeed));
3190 return E_MVD_RET_FAIL;
3191 break;
3192 }
3193
3194 return HAL_MVD_EX_SetClockSpeed(eMVDClockSpeed);
3195 }
3196
3197
3198 //-----------------------------------------------------------------------------
3199 /// @brief \b Function \b Name: MDrv_MVD_HWBuffer_ReMappingMode()
3200 /// @brief \b Function \b Description: Enable/ Disable to push first frame to display queue directly
3201 /// @param -bEnable \b IN : Enable/ Disable
3202 /// -FALSE(0): disable this mode
3203 /// -TRUE(1): enable this mode
3204 /// @return -The result of command MDrv_MVD_HWBuffer_ReMappingMode
3205 //-----------------------------------------------------------------------------
MDrv_MVD_HWBuffer_ReMappingMode(MS_U32 u32Id,MS_BOOL bEnable)3206 E_MVD_Result MDrv_MVD_HWBuffer_ReMappingMode(MS_U32 u32Id,MS_BOOL bEnable)
3207 {
3208
3209 E_MVD_Result eRet = E_MVD_RET_OK;
3210 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3211
3212 pMVDDrvContext->gMVDPreCtrl[u8HalIdx].bHWBufferReMapping = bEnable;
3213 eRet=HAL_MVD_HWBuffer_ReMappingMode(u8HalIdx,bEnable);
3214 return eRet;
3215 }
3216
3217
3218 //-----------------------------------------------------------------------------
3219 /// @brief \b Function \b Name: MDrv_MVD_ShowFirstFrameDirect()
3220 /// @brief \b Function \b Description: Enable/ Disable to push first frame to display queue directly
3221 /// @param -bEnable \b IN : Enable/ Disable
3222 /// -FALSE(0): disable this mode
3223 /// -TRUE(1): enable this mode
3224 /// @return -The result of command MDrv_MVD_ShowFirstFrameDirect
3225 //-----------------------------------------------------------------------------
MDrv_MVD_ShowFirstFrameDirect(MS_U32 u32Id,MS_BOOL bEnable)3226 MS_BOOL MDrv_MVD_ShowFirstFrameDirect(MS_U32 u32Id,MS_BOOL bEnable)
3227 {
3228 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3229
3230 return HAL_MVD_ShowFirstFrameDirect(u8HalIdx, bEnable);
3231 }
3232
3233 //------------------------------------------------------------------------------
3234 /// Set xc_low_delay parameter for xc_low_delay mechanism
3235 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
3236 //------------------------------------------------------------------------------
MDrv_MVD_SetXCLowDelayPara(MS_U32 u32Id,MS_U32 u32Para)3237 E_MVD_Result MDrv_MVD_SetXCLowDelayPara(MS_U32 u32Id,MS_U32 u32Para)
3238 {
3239 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3240
3241 return HAL_MVD_SetXCLowDelayPara(u8HalIdx, u32Para);
3242
3243 }
3244
3245 //------------------------------------------------------------------------------
3246 /// Set self seqchange mode
3247 /// @param -bEnable \b IN : 0 for original seqchange, 1 for self seqchange
3248 /// @return -TRUE for success; FALSE for failure.
3249 //------------------------------------------------------------------------------
MDrv_MVD_SetSelfSeqChange(MS_U32 u32Id,MS_BOOL bEnable)3250 E_MVD_Result MDrv_MVD_SetSelfSeqChange(MS_U32 u32Id, MS_BOOL bEnable)
3251 {
3252 MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
3253 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3254 MS_BOOL ret;
3255
3256 ret = HAL_MVD_EnableDynamicScale(u8HalIdx,bEnable);
3257
3258 if(ret == TRUE)
3259 {
3260 pMVDDrvContext->bSelf_SeqChange[u8DrvIdx] = bEnable;
3261 return E_MVD_RET_OK;
3262 }
3263 else
3264 {
3265 return E_MVD_RET_FAIL;
3266 }
3267 }
3268
3269
3270 //------------------------------------------------------------------------------
3271 /// Set external DS buffer info.
3272 /// @param -pExternalBuf \b IN : External DS buffer info.
3273 /// @return -The result of setting external DS buffer
3274 //------------------------------------------------------------------------------
MDrv_MVD_SetExternalDSBuffer(MS_U32 u32Id,MVD_EX_ExternalDSBuf * pExternalBuf)3275 E_MVD_Result MDrv_MVD_SetExternalDSBuffer(MS_U32 u32Id, MVD_EX_ExternalDSBuf *pExternalBuf)
3276 {
3277 #define SIZE_3K 0xC00
3278 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3279 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
3280
3281 //MS_U32 u32DrvAddr = NULL;
3282 if((pstMemCfg == NULL) || (pExternalBuf->u32DSBufSize < SIZE_3K)) /// DS buffer size need more than 3K (0xC00)
3283 {
3284 return E_MVD_RET_FAIL;
3285 }
3286
3287 #if defined(CHIP_MONACO)
3288 if(VPU_FORCE_MIU_MODE == 1)
3289 {
3290 printf("this chip does not support set external DS buffer since VPU_FORCE_MIU_MODE == 1 !!\n");
3291 return E_MVD_RET_FAIL;
3292 }
3293 #endif
3294
3295 #if (defined(CHIP_EDISON) || defined(CHIP_EINSTEIN) || defined(CHIP_NAPOLI) || defined(CHIP_MONACO))
3296 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
3297 MS_BOOL bRet = FALSE;
3298 MS_BOOL bExternalInMIU1 = FALSE;
3299 MS_VIRT u32DSAddr = pExternalBuf->u32DSBufAddr;
3300 MS_VIRT u32VPUAddr = NULL;
3301
3302 if((pExternalBuf->u32DSBufAddr >= HAL_MVD_GetMiu1BaseAdd()) && (HAL_MVD_GetMiu1BaseAdd() != 0))
3303 {
3304 bExternalInMIU1 = TRUE;
3305 u32DSAddr -= HAL_MVD_GetMiu1BaseAdd();
3306 }
3307
3308 /// If FW and external buf is in the same MIU, the External buffer do nothing.
3309 if(HAL_MVD_GetFWSelMiu1() == bExternalInMIU1)
3310 {
3311 u32VPUAddr = u32DSAddr;
3312 }
3313 else
3314 {
3315 /// If FW and external buf is not in the same MIU, the External buffer add the VPU Miu base size
3316 u32VPUAddr = u32DSAddr + HAL_VPU_EX_MIU1BASE();
3317 }
3318
3319 ///printf("[EDS] VPU addr 0x%lx, drv addr 0x%lx, enable %d.\n",u32VPUAddr,pExternalBuf->u32DSBufAddr,pExternalBuf->bEnable);
3320 bRet = HAL_MVD_SetExternalDSBuff(u8HalIdx,u32VPUAddr,pExternalBuf->u32DSBufAddr);
3321
3322 pstCtrlCfg->bExternalDSBuf = TRUE;
3323
3324 if(bRet == TRUE)
3325 {
3326 return E_MVD_RET_OK;
3327 }
3328 else
3329 {
3330 return E_MVD_RET_FAIL;
3331 }
3332 #endif
3333
3334 return E_MVD_RET_FAIL;
3335 }
3336
MDrv_MVD_GetESBufferStatus(MS_U32 u32Id)3337 MS_U8 MDrv_MVD_GetESBufferStatus(MS_U32 u32Id)
3338 {
3339 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3340
3341 return HAL_MVD_GetESBufferStatus(u8HalIdx);
3342 }
3343
MDrv_MVD_Field_Polarity_Display_One_field(MS_U32 u32Id,MS_BOOL bEnable,MS_U8 top_bottom)3344 MS_BOOL MDrv_MVD_Field_Polarity_Display_One_field(MS_U32 u32Id, MS_BOOL bEnable,MS_U8 top_bottom)
3345 {
3346 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3347 return HAL_MVD_Field_Polarity_Display_One_field(u8HalIdx, bEnable,top_bottom);
3348 }
3349
3350
3351 //------------------------------------------------------------------------------
3352 /// set share memory base between driver and fw
3353 /// @return -TRUE for success; FALSE for failure.
3354 //------------------------------------------------------------------------------
MDrv_MVD_SetShareMemoryBase(MS_U32 u32Id,MS_U32 u32base)3355 MS_BOOL MDrv_MVD_SetShareMemoryBase(MS_U32 u32Id, MS_U32 u32base)
3356 {
3357 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3358
3359 if((u32base & MVD_U32_MASK) == HAL_MIU1_BASE)
3360 {
3361 u32base -= HAL_MIU1_BASE;
3362 return HAL_MVD_SetShareMemoryBase(u8HalIdx, u32base,MIU_SEL_1); //in miu1
3363 }
3364 else
3365 {
3366 return HAL_MVD_SetShareMemoryBase(u8HalIdx, u32base,MIU_SEL_0); // in miu0
3367 }
3368 }
3369
MDrv_MVD_GetShareMemoryOffset(MS_U32 u32Id,MS_U32 * u32base)3370 MS_U32 MDrv_MVD_GetShareMemoryOffset(MS_U32 u32Id, MS_U32 *u32base)
3371 {
3372 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3373 return HAL_MVD_GetShareMemoryOffset(u8HalIdx, u32base);
3374 }
3375
MDrv_MVD_EnableVPUSecurityMode(MS_BOOL enable)3376 MS_BOOL MDrv_MVD_EnableVPUSecurityMode(MS_BOOL enable)
3377 {
3378 return HAL_VPU_EX_EnableSecurityMode(enable);
3379 }
3380
MDrv_MVD_GetSupport2ndMVOPInterface(void)3381 MS_BOOL MDrv_MVD_GetSupport2ndMVOPInterface(void)
3382 {
3383 MVD_FUNC_ENTRY();
3384
3385 return HAL_MVD_Support2ndMVOPInterface();
3386 }
3387
MDrv_MVD_GetVsyncBridgeAddr(MS_U32 u32Id)3388 MS_U32 MDrv_MVD_GetVsyncBridgeAddr(MS_U32 u32Id)
3389 {
3390 MVD_FUNC_ENTRY();
3391 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3392 return HAL_MVD_GetVsyncBridgeAddr(u8HalIdx);
3393 }
3394
3395
MDrv_MVD_REE_RegisterMBX(void)3396 MS_BOOL MDrv_MVD_REE_RegisterMBX(void)
3397 {
3398 return HAL_VPU_EX_REE_RegisterMBX();
3399 }
3400
MDrv_MVD_REE_SetSHMBaseAddr(void)3401 MS_BOOL MDrv_MVD_REE_SetSHMBaseAddr(void)
3402 {
3403 return HAL_VPU_EX_REE_SetSHMBaseAddr();
3404 }
3405
3406 //------------------------------------------------------------------------------
3407 /// set CC 608 or 708 share memory base between driver and fw
3408 /// @return -TRUE for success; FALSE for failure.
3409 //------------------------------------------------------------------------------
MDrv_MVD_SetExternal_CC608_Buffer(MS_U32 u32Id,MS_U32 u32base,MS_U8 u8size)3410 MS_BOOL MDrv_MVD_SetExternal_CC608_Buffer(MS_U32 u32Id, MS_U32 u32base,MS_U8 u8size)
3411 {
3412 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3413 return HAL_MVD_SetExternal_CC_Buffer(u8HalIdx,u32base,u8size,1);
3414 }
3415
MDrv_MVD_SetExternal_CC708_Buffer(MS_U32 u32Id,MS_U32 u32base,MS_U8 u8size)3416 MS_BOOL MDrv_MVD_SetExternal_CC708_Buffer(MS_U32 u32Id, MS_U32 u32base,MS_U8 u8size)
3417 {
3418 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3419 return HAL_MVD_SetExternal_CC_Buffer(u8HalIdx,u32base,u8size,0);
3420 }
3421
MDrv_MVD_SetPrebufferSize(MS_U32 u32Id,MS_U32 size)3422 MS_BOOL MDrv_MVD_SetPrebufferSize(MS_U32 u32Id, MS_U32 size)
3423 {
3424 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3425 return HAL_MVD_SetPrebufferSize(u8HalIdx,size);
3426 }
3427
MDrv_MVD_REE_GetSHMInformation(MS_VIRT * u32SHMAddr,MS_U32 * u32VsyncSHMOffset)3428 void MDrv_MVD_REE_GetSHMInformation(MS_VIRT* u32SHMAddr,MS_U32* u32VsyncSHMOffset)
3429 {
3430 *u32SHMAddr = HAL_VPU_EX_GetSHMAddr();
3431 *u32VsyncSHMOffset = HAL_MVD_GetVsyncAddrOffset();
3432 }
3433
3434 //------------------------------------------------------------------------------
3435 /// Set mvd/mpeg4 time_inc predict parameter...
3436 /// @param u32Para \b IN :
3437 /// -Arg0(enable), 1 for enable, default is 0.
3438 /// -Arg1(vop_time_incr_predict_count), 1 for predict once, 2 for twice...0xff for always guess the vop_time_incr even with the vol_header, default is 0...
3439 /// -Arg2(vop_time_incr_follow_vol_header), // 0 for follow vol_header...1 for bypass vol_header, default is 0...
3440 /// -Arg3, reserve...
3441 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
3442 //------------------------------------------------------------------------------
MDrv_MVD_SetTimeIncPredictParam(MS_U32 u32Id,MS_U32 u32Para)3443 E_MVD_Result MDrv_MVD_SetTimeIncPredictParam(MS_U32 u32Id,MS_U32 u32Para)
3444 {
3445 #if defined(CHIP_T2) || defined(CHIP_T7)
3446 return E_MVD_RET_FAIL;
3447 #else
3448 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3449 return HAL_MVD_SetTimeIncPredictParam(u8HalIdx,u32Para);
3450 #endif
3451 }
3452
MDrv_MVD_SetDcodeTimeoutParam(MS_U32 u32Id,MS_BOOL enable,MS_U32 u32timeout)3453 MS_BOOL MDrv_MVD_SetDcodeTimeoutParam(MS_U32 u32Id,MS_BOOL enable,MS_U32 u32timeout)
3454 {
3455 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3456 return HAL_MVD_SetDecodeTimeoutParam(u8HalIdx,enable,u32timeout);
3457 }
3458
MDrv_MVD_SetFramebufferAutoMode(MS_U32 u32Id,MS_BOOL bEnable)3459 MS_BOOL MDrv_MVD_SetFramebufferAutoMode(MS_U32 u32Id,MS_BOOL bEnable)
3460 {
3461 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3462 return _MVD_SetDynamicAllocateFB(u8HalIdx,bEnable);
3463 }
3464
3465 //------------------------------------------------------------------------------
3466 /// set smooth rewind cmd to fw
3467 /// @return -TRUE for success; FALSE for failure.
3468 //------------------------------------------------------------------------------
MDrv_MVD_Set_Smooth_Rewind(MS_U32 u32Id,MS_U8 btype)3469 E_MVD_Result MDrv_MVD_Set_Smooth_Rewind(MS_U32 u32Id, MS_U8 btype)
3470 {
3471 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3472 return HAL_MVD_Set_Smooth_Rewind(u8HalIdx, btype);
3473 }
3474
3475 //------------------------------------------------------------------------------
3476 /// get mvd is alive or not
3477 /// @return -TRUE for success; FALSE for failure.
3478 //------------------------------------------------------------------------------
3479
MDrv_MVD_IsAlive(MS_U32 u32Id)3480 E_MVD_Result MDrv_MVD_IsAlive(MS_U32 u32Id)
3481 {
3482 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3483 return HAL_MVD_IsAlive(u8HalIdx);
3484 }
3485
3486 //------------------------------------------------------------------------------
3487 /// enable/disable and set error tolerance value
3488 /// @return -TRUE for success; FALSE for failure.
3489 //------------------------------------------------------------------------------
MDrv_MVD_Set_Err_Tolerance(MS_U32 u32Id,MS_U16 u16Para)3490 E_MVD_Result MDrv_MVD_Set_Err_Tolerance(MS_U32 u32Id, MS_U16 u16Para)
3491 {
3492 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3493 return HAL_MVD_Set_Err_Tolerance(u8HalIdx,u16Para);
3494 }
3495
3496
3497 //------------------------------------------------------------------------------
3498 /// enable/disable Auto insert dummy pattern in SLQ mode
3499 /// @return -TRUE for success; FALSE for failure.
3500 //------------------------------------------------------------------------------
MDrv_MVD_EnableAutoInsertDummyPattern(MS_U32 u32Id,MS_BOOL bEnable)3501 void MDrv_MVD_EnableAutoInsertDummyPattern(MS_U32 u32Id, MS_BOOL bEnable)
3502 {
3503 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3504 return HAL_MVD_EnableAutoInsertDummyPattern(u8HalIdx,bEnable);
3505 }
3506
MDrv_MVD_Drop_One_PTS(MS_U32 u32Id)3507 void MDrv_MVD_Drop_One_PTS(MS_U32 u32Id)
3508 {
3509 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3510 return HAL_MVD_Drop_One_PTS(u8HalIdx);
3511 }
MDrv_MVD_PVR_Seamless_mode(MS_U32 u32Id,MS_U8 u8Arg)3512 E_MVD_Result MDrv_MVD_PVR_Seamless_mode(MS_U32 u32Id, MS_U8 u8Arg)
3513 {
3514 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3515 return HAL_MVD_PVR_Seamless_mode(u8HalIdx,u8Arg);
3516 }
3517
3518 // Please set it before cmd "CMD_ENABLE_LAST_FRAME_SHOW"
3519 // 0(default): for original just assert the last_frame_show_done when push to dispQ
3520 // 1: for strict qualify the last_frame_show_done after the last_frame been displayed by mvop, 20120309
MDrv_MVD_SetDispFinishMode(MS_U32 u32Id,MS_U8 u8Mode)3521 E_MVD_Result MDrv_MVD_SetDispFinishMode(MS_U32 u32Id,MS_U8 u8Mode)
3522 {
3523 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3524 return HAL_MVD_SetDisplayFinishMode(u8HalIdx,u8Mode);
3525 }
3526
3527 #endif
3528