xref: /utopia/UTPA2-700.0.x/modules/dmx/drv/mmfi/drvMMFilein.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ///////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2010-2012 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ///////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    drvMMFilein.c
98 /// @brief  Multimedia File In (MMFILEIN) Driver Interface
99 /// @author MStar Semiconductor,Inc.
100 /// @attention
101 /// All MMFILEIN DDI are not allowed to use in any interrupt context other than MMFILEIN ISR and Callback
102 ///////////////////////////////////////////////////////////////////////////////////////////////////
103 
104 //-------------------------------------------------------------------------------------------------
105 //  Include Files
106 //-------------------------------------------------------------------------------------------------
107 
108 // Common Definition
109 #include "MsCommon.h"
110 #include "MsVersion.h"
111 #include "drvMMIO.h"
112 
113 // Internal Definition
114 #include "asmCPU.h"
115 #include "halMMFilein.h"
116 #include "drvMMFilein.h"
117 
118 #ifdef MSOS_TYPE_LINUX
119     #include <sys/ioctl.h>
120     #include <unistd.h>
121     #include <fcntl.h> // O_RDWR
122 #endif
123 
124 #ifdef MSOS_TYPE_LINUX_KERNEL
125 #include <linux/string.h>
126 #endif
127 
128 //-------------------------------------------------------------------------------------------------
129 //  Driver Compiler Options
130 //-------------------------------------------------------------------------------------------------
131 
132 
133 //-------------------------------------------------------------------------------------------------
134 //  Local Defines
135 //-------------------------------------------------------------------------------------------------
136 #define MMFI_MUTEX_WAIT_TIME                            0xFFFFFFFFUL
137 
138 #define MMFI_DBGERR(x)                                  {if(_dbglevel >= E_DRVMMFI_DBG_ERR) x;  }
139 #define MMFI_DBGINFO(x)                                 {if(_dbglevel >= E_DRVMMFI_DBG_INFO) x;  }
140 
141 #define MMFI_ASSERT(_bool)                              if(!(_bool))   \
142                                                         {               \
143                                                             if(_dbglevel >= E_DRVMMFI_DBG_INFO)    \
144                                                               {  printf("ASSERT ERR\n");  }           \
145                                                             return DRVMMFI_FAIL;                    \
146                                                         }
147 
148 
149 #define _MMFI_ENTRY()                                   if (!MsOS_ObtainMutex(_pmmfi_res->_s32MMFIMutexId, MMFI_MUTEX_WAIT_TIME))      \
150                                                         {               \
151                                                             return DRVMMFI_FAIL;                                           \
152                                                         }
153 
154 #define _MMFI_RETURN(_ret)                              do{                                                                \
155                                                             MsOS_ReleaseMutex(_pmmfi_res->_s32MMFIMutexId);         \
156                                                             return _ret;                                                   \
157                                                         }while(0);
158 //-------------------------------------------------------------------------------------------------
159 //  Local Structures
160 //-------------------------------------------------------------------------------------------------
161 typedef struct _DrvMMFI_State
162 {
163     DrvMMFI_FltType   FltType[MMFI_PIDFLT_NUM_ALL];
164 }DRVMMFI_State;
165 
166 
167 typedef struct _MMFI_RESOURCE_PRIVATE
168 {
169     MS_S32                       _s32MMFIMutexId;
170     DRVMMFI_State                _MMFIState;
171 
172     MS_BOOL                      _bSWInit;
173 }MMFI_RESOURCE_PRIVATE;
174 
175 //-------------------------------------------------------------------------------------------------
176 //  Global Variables
177 //-------------------------------------------------------------------------------------------------
178 
179 #ifndef MMFI_UTOPIA_20
180 static MMFI_RESOURCE_PRIVATE _mmfi_res = {
181     ._s32MMFIMutexId                        = -1,
182     ._MMFIState                             = {
183         .FltType                            = {E_DRVMMFI_FLTTYPE_NONE},
184     },
185     ._bSWInit                               = FALSE,
186 };
187 
188 static MMFI_RESOURCE_PRIVATE*    _pmmfi_res = &_mmfi_res;
189 #else
190 static MMFI_RESOURCE_PRIVATE*    _pmmfi_res = NULL;
191 #endif
192 
193 //-------------------------------------------------------------------------------------------------
194 //  Local Variables
195 //-------------------------------------------------------------------------------------------------
196 DrvMMFI_DbgLevel                    _dbglevel = E_DRVMMFI_DBG_Release;
197 static MS_BOOL                   _bBankInit = FALSE;
198 
199 //-------------------------------------------------------------------------------------------------
200 //  Local Functions
201 //-------------------------------------------------------------------------------------------------
_MMFI_InitResource(MMFI_RESOURCE_PRIVATE * presource)202 static MS_BOOL _MMFI_InitResource(MMFI_RESOURCE_PRIVATE* presource)
203 {
204     MS_U32 u32ii;
205 
206     if(presource == NULL)
207         return FALSE;
208 
209     presource->_s32MMFIMutexId = -1;
210 
211     for(u32ii = 0; u32ii < MMFI_PIDFLT_NUM_ALL; u32ii++)
212     {
213         presource->_MMFIState.FltType[u32ii] = E_DRVMMFI_FLTTYPE_NONE;
214     }
215 
216     presource->_bSWInit = FALSE;
217 
218     return TRUE;
219 }
220 
221 //-------------------------------------------------------------------------------------------------
222 /// Initialize lib resource API
223 /// @param pResMemAddr                \b IN: Pointer to store resource memory address
224 /// @return MMFI_Result
225 /// @note
226 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_InitLibResource(void * pResMemAddr)227 MMFI_Result MDrv_MMFI_InitLibResource(void* pResMemAddr)
228 {
229     MMFI_ASSERT(pResMemAddr != 0);
230     MS_VIRT virtBank;
231     MS_PHY u32BankSize;
232 
233     _pmmfi_res = (MMFI_RESOURCE_PRIVATE*)pResMemAddr;
234 
235     if(_pmmfi_res->_bSWInit != TRUE)
236     {
237         if(_MMFI_InitResource(_pmmfi_res) == FALSE)
238             return DRVMMFI_FAIL;
239     }
240 
241     // For multi-process use case. (different process should set the value of bank again)
242     if(_bBankInit == FALSE)
243     {
244         if (FALSE == MDrv_MMIO_GetBASE(&virtBank, &u32BankSize, MS_MODULE_MMFILEIN))
245         {
246             MMFI_DBGERR(printf("MDrv_MMIO_GetBASE failed\n"));
247             return DRVMMFI_FAIL;
248         }
249         MMFI_DBGINFO((printf("MMFI Base Bank 0x%08x\n", (int)virtBank)));
250         HAL_MMFI_SetBank(virtBank);
251         _bBankInit = TRUE;
252     }
253 
254     return DRVMMFI_OK;
255 }
256 
257 //-------------------------------------------------------------------------------------------------
258 /// Initialize MMFilein driver
259 /// @return MMFI_Result
260 /// @note
261 /// It should be called before calling any other MMFilein DDI functions.
262 /// Driver task is in @ref E_TASK_PRI_SYS level.
263 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_Init(void)264 MMFI_Result MDrv_MMFI_Init(void)
265 {
266     MS_VIRT virtBank;
267     MS_PHY u32BankSize;
268     MS_U8 u8ii;
269 
270     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
271 
272     if (FALSE == MDrv_MMIO_GetBASE(&virtBank, &u32BankSize, MS_MODULE_MMFILEIN))
273     {
274         MMFI_DBGERR(printf("MDrv_MMIO_GetBASE failed\n"));
275         return DRVMMFI_FAIL;
276     }
277     MMFI_DBGINFO((printf("MMFI Base Bank 0x%08x\n", (unsigned int)virtBank)));
278     HAL_MMFI_SetBank(virtBank);
279 
280     if(_pmmfi_res->_bSWInit)
281         return DRVMMFI_OK;
282 
283     _pmmfi_res->_s32MMFIMutexId = MsOS_CreateMutex(E_MSOS_FIFO, "Mutex_MMFI", MSOS_PROCESS_SHARED);
284     if(_pmmfi_res->_s32MMFIMutexId == -1)
285     {
286         MMFI_DBGERR(printf("MsOS_CreateMutex failed\n"));
287         return DRVMMFI_FAIL;
288     }
289 
290     for(u8ii = 0; u8ii < (MS_U8)MMFI_PIDFLT_NUM_ALL; u8ii++)
291         _pmmfi_res->_MMFIState.FltType[u8ii] = E_DRVMMFI_FLTTYPE_NONE;
292 
293     _MMFI_ENTRY();
294     HAL_MMFI_Reset_All();
295 
296     HAL_MMFI_AU_Cfg_Set(MMFI_WBDMA_ECO);
297 
298     for(u8ii = 0; u8ii < (MS_U8)MMFI_AUDPIDFLT_NUM; u8ii++)
299     {
300         HAL_MMFI_AudPidFlt_Reset(u8ii);
301     }
302 
303     HAL_MMFI_AU_Set_FileinTimer(0x0A);
304 
305 #ifdef MMFI_VD3D
306 
307     HAL_MMFI_V3D_Cfg_Set(MMFI_WBDMA_ECO);
308 
309     for(u8ii = 0; u8ii < (MS_U8)MMFI_V3DPIDFLT_NUM; u8ii++)
310     {
311         HAL_MMFI_VD3DPidFlt_Reset(u8ii);
312     }
313     HAL_MMFI_V3D_Set_FileinTimer(0x0A);
314 #endif //MMFI_VD3D
315 
316     _pmmfi_res->_bSWInit = TRUE;
317 
318     _MMFI_RETURN(DRVMMFI_OK);
319 }
320 
321 //-------------------------------------------------------------------------------------------------
322 /// Close MMFilein
323 /// @return MMFI_Result
324 /// @note
325 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_Exit(void)326 MMFI_Result MDrv_MMFI_Exit(void)
327 {
328     MS_U8 u8ii;
329 
330     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
331 
332     if(_pmmfi_res->_bSWInit == FALSE)
333         return DRVMMFI_OK;
334 
335     for(u8ii = 0; u8ii < (MS_U8)MMFI_PIDFLT_NUM_ALL; u8ii++)
336         _pmmfi_res->_MMFIState.FltType[u8ii] = E_DRVMMFI_FLTTYPE_NONE;
337 
338     _MMFI_ENTRY();
339     for(u8ii = 0; u8ii < (MS_U8)MMFI_AUDPIDFLT_NUM; u8ii++)
340     {
341         HAL_MMFI_AudPidFlt_Reset(u8ii);
342         _pmmfi_res->_MMFIState.FltType[u8ii] = E_DRVMMFI_FLTTYPE_NONE;
343     }
344 
345     HAL_MMFI_AU_Cfg_Enable(MMFI_USE_AUD_PATH, FALSE);
346 
347 #ifdef MMFI_VD3D
348     for(u8ii = 0; u8ii < (MS_U8)MMFI_V3DPIDFLT_NUM; u8ii++)
349     {
350         HAL_MMFI_VD3DPidFlt_Reset(u8ii);
351     }
352     HAL_MMFI_V3D_Cfg_Enable(MMFI_USE_VD3D_PATH, FALSE);
353 #endif //MMFI_VD3D
354 
355     MsOS_ReleaseMutex(_pmmfi_res->_s32MMFIMutexId);
356     MsOS_DeleteMutex(_pmmfi_res->_s32MMFIMutexId);
357     _pmmfi_res->_s32MMFIMutexId = -1;
358 
359     _pmmfi_res->_bSWInit = FALSE;
360 
361     return DRVMMFI_OK;
362 }
363 
364 //-------------------------------------------------------------------------------------------------
365 /// Get MM File-in HW interrupt status
366 /// @param  pu32status                        \b OUT: pointer of storing HW interrupt status value
367 /// @return MMFI_Result
368 /// @note
369 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_Get_HWIntStatus(MS_U32 * pu32status)370 MMFI_Result MDrv_MMFI_Get_HWIntStatus(MS_U32* pu32status)
371 {
372     *pu32status = HAL_MMFI_HWInt_Status();
373     return DRVMMFI_OK;
374 }
375 
376 //-------------------------------------------------------------------------------------------------
377 /// Set debug level of MMFilein
378 /// @param  DbgLevel                     \b IN: Debug Level Value
379 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_SetDbgLevel(DrvMMFI_DbgLevel DbgLevel)380 MMFI_Result MDrv_MMFI_SetDbgLevel(DrvMMFI_DbgLevel DbgLevel)
381 {
382     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
383 
384     _dbglevel = DbgLevel;
385     return DRVMMFI_OK;
386 }
387 
388 //-------------------------------------------------------------------------------------------------
389 /// Set Audio path to be MMFI
390 /// @param  bEnable             \b IN: Enable Flag
391 /// @return MMFI_Result
392 /// @note
393 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_AudPath_Enable(MS_BOOL bEnable)394 MMFI_Result MDrv_MMFI_AudPath_Enable(MS_BOOL bEnable)
395 {
396     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
397 
398     _MMFI_ENTRY();
399     HAL_MMFI_AU_Cfg_Enable((MMFI_USE_AUD_PATH|MMFI_USE_AUDB_PATH), bEnable);
400     _MMFI_RETURN(DRVMMFI_OK);
401 }
402 
403 //-------------------------------------------------------------------------------------------------
404 /// Set MM File-in Timer
405 /// @param  epath                         \b IN: MM Filein Path
406 /// @param  u8timer                       \b IN: Filein Timer
407 /// @return MMFI_Result
408 /// @note
409 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_SetTimer(DrvMMFI_Path epath,MS_U8 u8timer)410 MMFI_Result MDrv_MMFI_File_SetTimer(DrvMMFI_Path epath, MS_U8 u8timer)
411 {
412     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
413 
414     _MMFI_ENTRY();
415 
416     if(epath == E_DRVMMFI_PTH_AUDIO)
417         HAL_MMFI_AU_Set_FileinTimer(u8timer);
418 
419 #ifdef MMFI_VD3D
420     if(epath == E_DRVMMFI_PATH_VD3D)
421         HAL_MMFI_V3D_Set_FileinTimer(u8timer);
422 #endif
423 
424     _MMFI_RETURN(DRVMMFI_OK);
425 }
426 
427 //-------------------------------------------------------------------------------------------------
428 /// Enable File-in Byte Timer
429 /// @param  epath                         \b IN: MM Filein Path
430 /// @param  bEnable                       \b IN: Enable flag
431 /// @return MMFI_Result
432 /// @note
433 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_ByteTimer_En(DrvMMFI_Path epath,MS_BOOL bEnable)434 MMFI_Result MDrv_MMFI_File_ByteTimer_En(DrvMMFI_Path epath, MS_BOOL bEnable)
435 {
436     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
437 
438     _MMFI_ENTRY();
439 
440     if(epath == E_DRVMMFI_PTH_AUDIO)
441         HAL_MMFI_AU_Cfg_Enable(MMFI_BYTE_TIMER_EN, bEnable);
442 
443 #ifdef MMFI_VD3D
444     if(epath == E_DRVMMFI_PATH_VD3D)
445         HAL_MMFI_V3D_Cfg_Enable(MMFI_BYTE_TIMER_EN, bEnable);
446 #endif
447 
448     _MMFI_RETURN(DRVMMFI_OK);
449 }
450 
451 //-------------------------------------------------------------------------------------------------
452 /// Allocate MMFI PID filter
453 /// @param  DrvMMFI_FltType                \b IN: PID filter type
454 /// @param  pu8PidFltId                        \b OUT: pointer of PID filter ID for return
455 /// @return MMFI_Result
456 /// @note
457 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_PidFlt_Alloc(DrvMMFI_FltType eFilterType,MS_U8 * pu8PidFltId)458 MMFI_Result MDrv_MMFI_PidFlt_Alloc(DrvMMFI_FltType eFilterType, MS_U8 *pu8PidFltId)
459 {
460     MS_U8 u8ii;
461     *pu8PidFltId = 0xFF;
462 
463     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
464     MMFI_ASSERT(eFilterType > E_DRVMMFI_FLTTYPE_NONE);
465 
466     _MMFI_ENTRY();
467     if(eFilterType <= E_DRVMMFI_FLTTYPE_AUDB)
468     {
469         for(u8ii = 0; u8ii < (MS_U8)MMFI_AUDPIDFLT_NUM; u8ii++)
470         {
471             if(_pmmfi_res->_MMFIState.FltType[u8ii] == E_DRVMMFI_FLTTYPE_NONE)
472             {
473                 MMFI_DBGINFO(printf("Allocate PID Filter %d\n", (int)u8ii));
474                 *pu8PidFltId = u8ii;
475                 _pmmfi_res->_MMFIState.FltType[u8ii] = eFilterType;
476                 _MMFI_RETURN(DRVMMFI_OK);
477             }
478         }
479     }
480 #ifdef MMFI_VD3D
481     else if(eFilterType == E_DRVMMFI_FLTTYPE_VD3D)
482     {
483         for(u8ii = 0; u8ii < (MS_U8)MMFI_V3DPIDFLT_NUM; u8ii++)
484         {
485             if(_pmmfi_res->_MMFIState.FltType[u8ii + MMFI_AUDPIDFLT_NUM] == E_DRVMMFI_FLTTYPE_NONE)
486             {
487                 *pu8PidFltId = u8ii + MMFI_AUDPIDFLT_NUM;
488                 _pmmfi_res->_MMFIState.FltType[u8ii + MMFI_AUDPIDFLT_NUM] = eFilterType;
489                 _MMFI_RETURN(DRVMMFI_OK);
490             }
491         }
492     }
493 #endif
494 
495     _MMFI_RETURN(DRVMMFI_FAIL);
496 
497 }
498 
499 //-------------------------------------------------------------------------------------------------
500 /// Free MMFI PID filter
501 /// @param u8PidFltId                     \b IN: PID filter ID
502 /// @return MMFI_Result
503 /// @note
504 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_PidFlt_Free(MS_U8 u8PidFltId)505 MMFI_Result MDrv_MMFI_PidFlt_Free(MS_U8 u8PidFltId)
506 {
507     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
508 
509     if(_pmmfi_res->_MMFIState.FltType[u8PidFltId] == E_DRVMMFI_FLTTYPE_NONE)
510         return DRVMMFI_OK;
511 
512     _MMFI_ENTRY();
513 
514     if(_pmmfi_res->_MMFIState.FltType[u8PidFltId] <= E_DRVMMFI_FLTTYPE_AUDB)
515     {
516         MS_U8 u8ii = 0;
517         MS_U32 u32AUFlag = 0;
518 
519         HAL_MMFI_AudPidFlt_Reset(u8PidFltId);
520         _pmmfi_res->_MMFIState.FltType[u8PidFltId] = E_DRVMMFI_FLTTYPE_NONE;
521 
522         //disable audio path
523         u32AUFlag = HAL_MMFI_AU_Cfg_Get() & (~(MMFI_USE_AUD_PATH | MMFI_USE_AUDB_PATH));
524         for(u8ii = 0; u8ii < MMFI_AUDPIDFLT_NUM; u8ii++)
525         {
526             if(_pmmfi_res->_MMFIState.FltType[u8ii] == E_DRVMMFI_FLTTYPE_AUD)
527                 u32AUFlag |= MMFI_USE_AUD_PATH;
528             else if(_pmmfi_res->_MMFIState.FltType[u8ii] == E_DRVMMFI_FLTTYPE_AUDB)
529                 u32AUFlag |= MMFI_USE_AUDB_PATH;
530         }
531         HAL_MMFI_AU_Cfg_Set(u32AUFlag);
532 
533         _MMFI_RETURN(DRVMMFI_OK);
534     }
535 
536 #ifdef MMFI_VD3D
537     else if(_pmmfi_res->_MMFIState.FltType[u8PidFltId] == E_DRVMMFI_FLTTYPE_VD3D)
538     {
539         HAL_MMFI_VD3DPidFlt_Reset(u8PidFltId - E_DRVMMFI_FLTTYPE_AUDB);
540         HAL_MMFI_V3D_Cfg_Enable(MMFI_USE_VD3D_PATH, FALSE);
541         _pmmfi_res->_MMFIState.FltType[u8PidFltId] = E_DRVMMFI_FLTTYPE_NONE;
542         _MMFI_RETURN(DRVMMFI_OK);
543     }
544 #endif
545 
546     _MMFI_RETURN(DRVMMFI_INVALID_PARAM);
547 }
548 
549 //-------------------------------------------------------------------------------------------------
550 /// Enable PID filter
551 /// @param  u8PidFltId                       \b IN: PID filter ID
552 /// @param  bEnable                          \b IN: Enable Flag
553 /// @return MMFI_Result
554 /// @note
555 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_PidFlt_Enable(MS_U8 u8PidFltId,MS_BOOL bEnable)556 MMFI_Result MDrv_MMFI_PidFlt_Enable(MS_U8 u8PidFltId, MS_BOOL bEnable)
557 {
558     MS_U16 u16type = 0;
559 
560     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
561     MMFI_ASSERT(_pmmfi_res->_MMFIState.FltType[u8PidFltId] > E_DRVMMFI_FLTTYPE_NONE);
562 
563     switch(_pmmfi_res->_MMFIState.FltType[u8PidFltId])
564     {
565         case E_DRVMMFI_FLTTYPE_AUD:
566             u16type = MMFI_PIDFLT_AFIFO_EN;
567             HAL_MMFI_AU_Cfg_Enable(MMFI_USE_AUD_PATH, bEnable);
568             break;
569         case E_DRVMMFI_FLTTYPE_AUDB:
570             #ifdef MMFI_PIDFLT_AFIFOB_EN
571             u16type = MMFI_PIDFLT_AFIFOB_EN;
572             HAL_MMFI_AU_Cfg_Enable(MMFI_USE_AUDB_PATH, bEnable);
573             break;
574             #else
575             return DRVMMFI_INVALID_PARAM;
576             #endif
577 
578         #ifdef MMFI_VD3D
579         case E_DRVMMFI_FLTTYPE_VD3D:
580             u16type = MMFI_PIDFLT_VD3D_EN;
581             HAL_MMFI_V3D_Cfg_Enable(MMFI_USE_VD3D_PATH, bEnable);
582             break;
583         #endif
584 
585         default:
586             return DRVMMFI_INVALID_PARAM;
587     }
588 
589     _MMFI_ENTRY();
590 
591     if(_pmmfi_res->_MMFIState.FltType[u8PidFltId] <= E_DRVMMFI_FLTTYPE_AUDB)
592     {
593         HAL_MMFI_AudPidFlt_Enable(u8PidFltId, u16type, bEnable);
594         _MMFI_RETURN(DRVMMFI_OK);
595     }
596     #ifdef MMFI_VD3D
597     else if(_pmmfi_res->_MMFIState.FltType[u8PidFltId] == E_DRVMMFI_FLTTYPE_VD3D)
598     {
599         HAL_MMFI_VD3DPidFlt_Enable(u8PidFltId - MMFI_AUDPIDFLT_NUM, u16type, bEnable);
600         _MMFI_RETURN(DRVMMFI_OK);
601     }
602     #endif
603 
604     _MMFI_RETURN(DRVMMFI_INVALID_PARAM);
605 }
606 
607 //-------------------------------------------------------------------------------------------------
608 /// Set PID to PID filter
609 /// @param  u8PidFltId                       \b IN: PID filter ID
610 /// @param  u16Pid                           \b IN: Enable Flag
611 /// @return MMFI_Result
612 /// @note
613 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_PidFlt_SetPid(MS_U8 u8PidFltId,MS_U16 u16Pid)614 MMFI_Result MDrv_MMFI_PidFlt_SetPid(MS_U8 u8PidFltId, MS_U16 u16Pid)
615 {
616     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
617 
618     _MMFI_ENTRY();
619 
620     if(u8PidFltId < MMFI_AUDPIDFLT_NUM)
621     {
622         HAL_MMFI_AudPidFlt_SetPid(u8PidFltId, u16Pid);
623         _MMFI_RETURN(DRVMMFI_OK);
624     }
625 #ifdef MMFI_VD3D
626     else if(u8PidFltId < MMFI_PIDFLT_NUM_ALL)
627     {
628         HAL_MMFI_VD3DPidFlt_SetPid(u8PidFltId, u16Pid);
629         _MMFI_RETURN(DRVMMFI_OK);
630     }
631 #endif
632 
633     _MMFI_RETURN(DRVMMFI_INVALID_PARAM);
634 }
635 
636 //-------------------------------------------------------------------------------------------------
637 /// Command Queue Reset
638 /// @param  epath                         \b IN: MM Filein Path
639 /// @return MMFI_Result
640 /// @note
641 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_CmdQ_Reset(DrvMMFI_Path epath)642 MMFI_Result MDrv_MMFI_File_CmdQ_Reset(DrvMMFI_Path epath)
643 {
644     MS_U16 u32value = 0;
645 
646     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
647 
648     _MMFI_ENTRY();
649 
650     if(epath == E_DRVMMFI_PTH_AUDIO)
651         u32value |= MMFI_RST_CMDQ_AU;
652 
653 #ifdef MMFI_VD3D
654     if(epath == E_DRVMMFI_PATH_VD3D)
655         u32value |= MMFI_RST_CMDQ_VD;
656 #endif
657 
658     HAL_MMFI_Reset_SubItem(u32value);
659 
660     //check R done
661     #ifdef MMFI_FILEIN_DONE
662     if(HAL_MMFI_Chk_CmdQResetDone(u32value) == FALSE)
663     {
664         _MMFI_RETURN(DRVMMFI_FAIL);
665     }
666     #endif
667 
668     _MMFI_RETURN(DRVMMFI_OK);
669 }
670 
671 //-------------------------------------------------------------------------------------------------
672 /// Get Command Queue Write Level value
673 /// @param  epath                                \b IN: MM Filein Path
674 /// @param  pu8FifoLevel                       \b OUT: pointer of Command Queue Write Level value for return
675 /// @return MMFI_Result
676 /// @note
677 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_CmdQFifo_Status(DrvMMFI_Path epath,MS_U8 * pu8FifoLevel)678 MMFI_Result MDrv_MMFI_File_CmdQFifo_Status(DrvMMFI_Path epath, MS_U8 *pu8FifoLevel)
679 {
680     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
681 
682     *pu8FifoLevel = 0xFFUL;
683 
684     if(epath == E_DRVMMFI_PTH_AUDIO)
685         *pu8FifoLevel = HAL_MMFI_AU_CmdQ_FIFO_Get_WRLevel();
686 
687 #ifdef MMFI_VD3D
688     else if(epath == E_DRVMMFI_PATH_VD3D)
689         *pu8FifoLevel = HAL_MMFI_V3D_CmdQ_FIFO_Get_WRLevel();
690 #endif
691 
692     return DRVMMFI_OK;
693 }
694 
695 //-------------------------------------------------------------------------------------------------
696 /// Get Command Queue Empty Slot value
697 /// @param  epath                                   \b IN: MM Filein Path
698 /// @param  pu32EmptySlot                       \b OUT: pointer of Command Queue Empty Slot value for return
699 /// @return MMFI_Result
700 /// @note
701 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_CmdQ_GetSlot(DrvMMFI_Path epath,MS_U32 * pu32EmptySlot)702 MMFI_Result MDrv_MMFI_File_CmdQ_GetSlot(DrvMMFI_Path epath, MS_U32 *pu32EmptySlot)
703 {
704     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
705 
706     *pu32EmptySlot = 0;
707 
708     if(epath == E_DRVMMFI_PTH_AUDIO)
709         *pu32EmptySlot = MMFI_CMDQ_SIZE - (MS_U32)HAL_MMFI_AU_CmdQ_FIFO_Get_WRCnt();
710 #ifdef MMFI_VD3D
711     else if(epath == E_DRVMMFI_PATH_VD3D)
712         *pu32EmptySlot = MMFI_CMDQ_SIZE - (MS_U32)HAL_MMFI_V3D_CmdQ_FIFO_Get_WRCnt();
713 #endif
714 
715     return DRVMMFI_OK;
716 }
717 
718 //-------------------------------------------------------------------------------------------------
719 /// Set playback timestamp
720 /// @param  epath                            \b IN: MM Filein Path
721 /// @param  u8PidFltId                       \b IN: LPCR32 value
722 /// @return MMFI_Result
723 /// @note
724 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_SetPlaybackTimeStamp(DrvMMFI_Path epath,MS_U32 u32lpcr2)725 MMFI_Result MDrv_MMFI_SetPlaybackTimeStamp(DrvMMFI_Path epath, MS_U32 u32lpcr2)
726 {
727     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
728 
729     _MMFI_ENTRY();
730 
731     if(epath == E_DRVMMFI_PTH_AUDIO)
732         HAL_MMFI_AU_LPcr2_Set(u32lpcr2);
733 #ifdef MMFI_VD3D
734     else if(epath == E_DRVMMFI_PATH_VD3D)
735         HAL_MMFI_V3D_LPcr2_Set(u32lpcr2);
736 #endif
737 
738     _MMFI_RETURN(DRVMMFI_OK);
739 }
740 
741 //-------------------------------------------------------------------------------------------------
742 /// Get playback timestamp
743 /// @param  epath                            \b IN: MM Filein Path
744 /// @param pu32lpcr2                        \b OUT: pointer of LPCR32 value for return
745 /// @return MMFI_Result
746 /// @note
747 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_GetPlaybackTimeStamp(DrvMMFI_Path epath,MS_U32 * pu32lpcr2)748 MMFI_Result MDrv_MMFI_GetPlaybackTimeStamp(DrvMMFI_Path epath, MS_U32 *pu32lpcr2)
749 {
750     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
751     MMFI_ASSERT((pu32lpcr2 != 0));
752 
753     _MMFI_ENTRY();
754 
755     *pu32lpcr2 = 0;
756 
757     if(epath == E_DRVMMFI_PTH_AUDIO)
758         *pu32lpcr2 = HAL_MMFI_AU_LPcr2_Get();
759 #ifdef MMFI_VD3D
760     else if(epath == E_DRVMMFI_PATH_VD3D)
761         *pu32lpcr2 = HAL_MMFI_V3D_LPcr2_Get();
762 #endif
763 
764     _MMFI_RETURN(DRVMMFI_OK);
765 
766     return DRVMMFI_OK;
767 }
768 
769 //-------------------------------------------------------------------------------------------------
770 /// Get File-in timestamp value
771 /// @param  epath                              \b IN: MM Filein Path
772 /// @param  pu32TSLen                       \b OUT: pointer of Timestamp value for return
773 /// @return MMFI_Result
774 /// @note
775 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_GetFileInTimeStamp(DrvMMFI_Path epath,MS_U32 * pu32TSLen)776 MMFI_Result MDrv_MMFI_GetFileInTimeStamp(DrvMMFI_Path epath, MS_U32* pu32TSLen)
777 {
778     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
779 
780     *pu32TSLen = 0;
781 
782     if(epath == E_DRVMMFI_PTH_AUDIO)
783         *pu32TSLen = HAL_MMFI_AU_TimeStamp_Get();
784 #ifdef MMFI_VD3D
785     else if(epath == E_DRVMMFI_PATH_VD3D)
786         *pu32TSLen = HAL_MMFI_V3D_TimeStamp_Get();
787 #endif
788 
789     return DRVMMFI_OK;
790 }
791 
792 //-------------------------------------------------------------------------------------------------
793 /// Set File-in Read Start Address
794 /// @param  epath                                   \b IN: MM Filein Path
795 /// @param  u32StreamAddr                       \b IN: MIU Physical Address of File-in Read Start Address.
796 /// @return MMFI_Result
797 /// @note
798 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_SetAddr(DrvMMFI_Path epath,MS_PHY phyStreamAddr)799 MMFI_Result MDrv_MMFI_File_SetAddr(DrvMMFI_Path epath, MS_PHY phyStreamAddr)
800 {
801     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
802 
803     _MMFI_ENTRY();
804 
805     if(epath == E_DRVMMFI_PTH_AUDIO)
806         HAL_MMFI_AU_Set_Filein_ReadAddr(phyStreamAddr);
807 #ifdef MMFI_VD3D
808     else if(epath == E_DRVMMFI_PATH_VD3D)
809         HAL_MMFI_V3D_Set_Filein_ReadAddr(phyStreamAddr);
810 #endif
811 
812     _MMFI_RETURN(DRVMMFI_OK);
813 }
814 
815 //-------------------------------------------------------------------------------------------------
816 /// Set File-in Read Size
817 /// @param  epath                                   \b IN: MM Filein Path
818 /// @param  u32StreamSize                       \b IN: File-in Read Size.
819 /// @return MMFI_Result
820 //   @note u32StreamSize must be larger than 16
821 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_SetSize(DrvMMFI_Path epath,MS_U32 u32StreamSize)822 MMFI_Result MDrv_MMFI_File_SetSize(DrvMMFI_Path epath, MS_U32 u32StreamSize)
823 {
824     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
825 
826     if(u32StreamSize <= 16UL) //HW limitation
827         return DRVMMFI_FAIL;
828 
829     _MMFI_ENTRY();
830 
831     if(epath == E_DRVMMFI_PTH_AUDIO)
832         HAL_MMFI_AU_Set_Filein_ReadLen(u32StreamSize);
833 #ifdef MMFI_VD3D
834     else if(epath == E_DRVMMFI_PATH_VD3D)
835         HAL_MMFI_V3D_Set_Filein_ReadLen(u32StreamSize);
836 #endif
837 
838     _MMFI_RETURN(DRVMMFI_OK);
839 }
840 
841 //-------------------------------------------------------------------------------------------------
842 /// Set packet size to MMFilein file
843 /// @param  epath                         \b IN: MM Filein Path
844 /// @param  PacketMode                 \b IN: Mode of MMFilein packet mode (192, 204, 188)
845 /// @return TSP_Result
846 /// @note
847 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_SetPacketMode(DrvMMFI_Path epath,DrvMMFI_PacketMode PacketMode)848 MMFI_Result MDrv_MMFI_File_SetPacketMode(DrvMMFI_Path epath, DrvMMFI_PacketMode PacketMode)
849 {
850     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
851 
852     _MMFI_ENTRY();
853 
854     if(epath == E_DRVMMFI_PTH_AUDIO)
855     {
856         switch (PacketMode)
857         {
858             case E_DRVMMFI_PKTMODE_188:
859                 HAL_MMFI_AU_PktChkSize_Set(0xBB);
860                 HAL_MMFI_AU_Cfg_Enable(MMFI_ALT_TS_SIZE, FALSE);
861                 break;
862             case E_DRVMMFI_PKTMODE_192:
863                 HAL_MMFI_AU_PktChkSize_Set(0xBF);
864                 HAL_MMFI_AU_Cfg_Enable(MMFI_ALT_TS_SIZE, TRUE);
865                 break;
866             case E_DRVMMFI_PKTMODE_204:
867                 HAL_MMFI_AU_PktChkSize_Set(0xCB);
868                 HAL_MMFI_AU_Cfg_Enable(MMFI_ALT_TS_SIZE, TRUE);
869                 break;
870             default:
871                 break;
872         }
873     }
874 #ifdef MMFI_VD3D
875     else if(epath == E_DRVMMFI_PATH_VD3D)
876     {
877         switch (PacketMode)
878         {
879             case E_DRVMMFI_PKTMODE_188:
880                 HAL_MMFI_V3D_PktChkSize_Set(0xBB);
881                 HAL_MMFI_V3D_Cfg_Enable(MMFI_ALT_TS_SIZE, FALSE);
882                 break;
883             case E_DRVMMFI_PKTMODE_192:
884                 HAL_MMFI_V3D_PktChkSize_Set(0xBF);
885                 HAL_MMFI_V3D_Cfg_Enable(MMFI_ALT_TS_SIZE, TRUE);
886                 break;
887             case E_DRVMMFI_PKTMODE_204:
888                 HAL_MMFI_V3D_PktChkSize_Set(0xCB);
889                 HAL_MMFI_V3D_Cfg_Enable(MMFI_ALT_TS_SIZE, TRUE);
890                 break;
891             default:
892                 break;
893         }
894     }
895 #endif
896 
897     _MMFI_RETURN(DRVMMFI_OK);
898 }
899 //-------------------------------------------------------------------------------------------------
900 /// Set File-in time stamp clock source
901 /// @param  epath                         \b IN: MM Filein Path
902 /// @param  u32Clksrc                     \b IN: clock source
903 /// @return MMFI_Result
904 /// @note
905 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_SetTimeStampClk(DrvMMFI_Path ePath,MS_U32 u32ClkSrc)906 MMFI_Result MDrv_MMFI_File_SetTimeStampClk(DrvMMFI_Path ePath, MS_U32 u32ClkSrc)
907 {
908     return DRVMMFI_FAIL;
909 }
910 //-------------------------------------------------------------------------------------------------
911 /// Enable/Disable File-in 192 Mode
912 /// @param  epath                         \b IN: MM Filein Path
913 /// @param  bEnable                       \b IN: Enable Flag
914 /// @return MMFI_Result
915 /// @note
916 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_192Mode_En(DrvMMFI_Path epath,MS_BOOL bEnable)917 MMFI_Result MDrv_MMFI_File_192Mode_En(DrvMMFI_Path epath, MS_BOOL bEnable)
918 {
919     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
920 
921     _MMFI_ENTRY();
922 
923     if(epath == E_DRVMMFI_PTH_AUDIO)
924         HAL_MMFI_AU_Cfg_Enable(MMFI_PKT192_EN, bEnable);
925 #ifdef MMFI_VD3D
926     else if(epath == E_DRVMMFI_PATH_VD3D)
927         HAL_MMFI_V3D_Cfg_Enable(MMFI_PKT192_EN, bEnable);
928 #endif
929 
930     _MMFI_RETURN(DRVMMFI_OK);
931 
932 }
933 
934 //-------------------------------------------------------------------------------------------------
935 /// Enable/Disable File-in 192 Block Scheme
936 /// @param  epath                         \b IN: MM Filein Path
937 /// @param  bEnable                       \b IN: Enable Flag
938 /// @return MMFI_Result
939 /// @note
940 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_192BlockScheme_En(DrvMMFI_Path epath,MS_BOOL bEnable)941 MMFI_Result MDrv_MMFI_File_192BlockScheme_En(DrvMMFI_Path epath, MS_BOOL bEnable)
942 {
943     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
944 
945     _MMFI_ENTRY();
946 
947     if(epath == E_DRVMMFI_PTH_AUDIO)
948         HAL_MMFI_AU_Cfg_Enable(MMFI_PKT192_BLK_DISABLE, bEnable);
949 #ifdef MMFI_VD3D
950     else if(epath == E_DRVMMFI_PATH_VD3D)
951         HAL_MMFI_V3D_Cfg_Enable(MMFI_PKT192_BLK_DISABLE, bEnable);
952 #endif
953 
954     _MMFI_RETURN(DRVMMFI_OK);
955 }
956 
957 //-------------------------------------------------------------------------------------------------
958 /// Enable/Disable Drop duplicate packets
959 /// @param  epath                          \b IN: MM Filein Path
960 /// @param  bEnable                       \b IN: Enable Flag
961 /// @return MMFI_Result
962 /// @note
963 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_DupPktSkip(DrvMMFI_Path epath,MS_BOOL bEnable)964 MMFI_Result MDrv_MMFI_DupPktSkip(DrvMMFI_Path epath, MS_BOOL bEnable)
965 {
966     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
967 
968     _MMFI_ENTRY();
969 
970     if(epath == E_DRVMMFI_PTH_AUDIO)
971         HAL_MMFI_AU_Cfg_Enable(MMFI_DUP_PKT_SKIP, bEnable);
972 #ifdef MMFI_VD3D
973     else if(epath == E_DRVMMFI_PATH_VD3D)
974         HAL_MMFI_V3D_Cfg_Enable(MMFI_DUP_PKT_SKIP, bEnable);
975 #endif
976 
977     _MMFI_RETURN(DRVMMFI_OK);
978 }
979 
980 //-------------------------------------------------------------------------------------------------
981 /// Enable/Disable Skip TEL packet
982 /// @param  epath                         \b IN: MM Filein Path
983 /// @param  bEnable                       \b IN: Enable Flag
984 /// @return MMFI_Result
985 /// @note
986 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_TEI_SkipPktf(DrvMMFI_Path epath,MS_BOOL bEnable)987 MMFI_Result MDrv_MMFI_TEI_SkipPktf(DrvMMFI_Path epath, MS_BOOL bEnable)
988 {
989     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
990 
991     _MMFI_ENTRY();
992 
993     if(epath == E_DRVMMFI_PTH_AUDIO)
994         HAL_MMFI_AU_Cfg_Enable(MMFI_TEI_SKIP_PKTF, bEnable);
995 #ifdef MMFI_VD3D
996     else if(epath == E_DRVMMFI_PATH_VD3D)
997         HAL_MMFI_V3D_Cfg_Enable(MMFI_TEI_SKIP_PKTF, bEnable);
998 #endif
999 
1000     _MMFI_RETURN(DRVMMFI_OK);
1001 }
1002 
1003 //-------------------------------------------------------------------------------------------------
1004 /// Clear PID filter byte counter
1005 /// @param  epath                         \b IN: MM Filein Path
1006 /// @return MMFI_Result
1007 /// @note
1008 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_Clr_Pidflt_ByteCnt(DrvMMFI_Path epath)1009 MMFI_Result MDrv_MMFI_Clr_Pidflt_ByteCnt(DrvMMFI_Path epath)
1010 {
1011     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1012 
1013     _MMFI_ENTRY();
1014 
1015     if(epath == E_DRVMMFI_PTH_AUDIO)
1016         HAL_MMFI_AU_Cfg_Enable(MMFI_CLR_PIDFLT_BYTE_CNT, TRUE);
1017 #ifdef MMFI_VD3D
1018     else if(epath == E_DRVMMFI_PATH_VD3D)
1019         HAL_MMFI_V3D_Cfg_Enable(MMFI_CLR_PIDFLT_BYTE_CNT, TRUE);
1020 #endif
1021 
1022     _MMFI_RETURN(DRVMMFI_OK);
1023 }
1024 
1025 //-------------------------------------------------------------------------------------------------
1026 /// Enable/Disable TS Data Endian Swap
1027 /// @param  epath                         \b IN: MM Filein Path
1028 /// @param  bEnable                       \b IN: Enable Flag
1029 /// @return MMFI_Result
1030 /// @note
1031 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_TSDataEndian_Swap(DrvMMFI_Path epath,MS_BOOL bEnable)1032 MMFI_Result MDrv_MMFI_TSDataEndian_Swap(DrvMMFI_Path epath, MS_BOOL bEnable)
1033 {
1034     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1035 
1036     _MMFI_ENTRY();
1037 
1038     if(epath == E_DRVMMFI_PTH_AUDIO)
1039         HAL_MMFI_AU_Cfg_Enable(MMFI_MEM_TSDATA_ENDIAN_AU, bEnable);
1040 #ifdef MMFI_VD3D
1041     else if(epath == E_DRVMMFI_PATH_VD3D)
1042         HAL_MMFI_V3D_Cfg_Enable(MMFI_MEM_TSDATA_ENDIAN_V3D, bEnable);
1043 #endif
1044 
1045     _MMFI_RETURN(DRVMMFI_OK);
1046 }
1047 
1048 //-------------------------------------------------------------------------------------------------
1049 /// Enable/Disable TS Order Swap
1050 /// @param  epath                         \b IN: MM Filein Path
1051 /// @param  bEnable                       \b IN: Enable Flag
1052 /// @return MMFI_Result
1053 /// @note
1054 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_TSOrder_Swap(DrvMMFI_Path epath,MS_BOOL bEnable)1055 MMFI_Result MDrv_MMFI_TSOrder_Swap(DrvMMFI_Path epath, MS_BOOL bEnable)
1056 {
1057     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1058 
1059     _MMFI_ENTRY();
1060 
1061     if(epath == E_DRVMMFI_PTH_AUDIO)
1062         HAL_MMFI_AU_Cfg_Enable(MMFI_MEM_TSORDER_ENDIAN_AU, bEnable);
1063 #ifdef MMFI_VD3D
1064     else if(epath == E_DRVMMFI_PATH_VD3D)
1065         HAL_MMFI_V3D_Cfg_Enable(MMFI_MEM_TSORDER_ENDIAN_V3D, bEnable);
1066 #endif
1067 
1068     _MMFI_RETURN(DRVMMFI_OK);
1069 }
1070 
MDrv_MMFI_GetCap(DrvMMFI_Cap eCap,void * pOutput)1071 MMFI_Result MDrv_MMFI_GetCap(DrvMMFI_Cap eCap, void* pOutput)
1072 {
1073     *((MS_U32*)pOutput) = 0;
1074 
1075     switch (eCap)
1076     {
1077         case E_DRVMMFI_CAP_RESOURCE_SIZE:
1078             *((MS_U32*)pOutput) = (MS_U32)sizeof(MMFI_RESOURCE_PRIVATE);
1079             return DRVMMFI_OK;
1080         case E_DRVMMFI_CAP_FILTER_AU_NUM:
1081             *((MS_U32*)pOutput) += MMFI_AUDPIDFLT_NUM;
1082             return DRVMMFI_OK;
1083         case E_DRVMMFI_CAP_FILTER_ALL_NUM:
1084             *((MS_U32*)pOutput) += MMFI_AUDPIDFLT_NUM;
1085 #ifdef MMFI_VD3D
1086         case E_DRVMMFI_CAP_FILTER_VD_NUM:
1087             *((MS_U32*)pOutput) += MMFI_V3DPIDFLT_NUM;
1088 #endif
1089             return DRVMMFI_OK;
1090         default:
1091             return DRVMMFI_INVALID_PARAM;
1092     }
1093 }
1094 
1095 //-------------------------------------------------------------------------------------------------
1096 /// Get Command queue state
1097 /// @param  epath                                 \b IN: MM Filein Path
1098 /// @param  peFileinState                       \b OUT: Pointer of Filein state to return
1099 /// @return MMFI_Result
1100 /// @note
1101 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_GetState(DrvMMFI_Path epath,DrvMMFI_FileinState * peFileinState)1102 MMFI_Result MDrv_MMFI_File_GetState(DrvMMFI_Path epath, DrvMMFI_FileinState *peFileinState)
1103 {
1104     MS_U32 u32state = 0xFF, u32cmdcnt = 0;
1105 
1106     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1107 
1108     _MMFI_ENTRY();
1109 
1110     if(epath == E_DRVMMFI_PTH_AUDIO)
1111     {
1112         u32state = HAL_MMFI_AU_Get_Filein_Ctrl();
1113         u32cmdcnt = HAL_MMFI_AU_CmdQ_FIFO_Get_WRCnt();
1114     }
1115 #ifdef MMFI_VD3D
1116     else if(epath == E_DRVMMFI_PATH_VD3D)
1117     {
1118         u32state = HAL_MMFI_V3D_Get_Filein_Ctrl();
1119         u32cmdcnt = HAL_MMFI_V3D_CmdQ_FIFO_Get_WRCnt();
1120     }
1121 #endif
1122 
1123     if((u32state & MMFI_FILEIN_RSTART) || u32cmdcnt)
1124         *peFileinState = E_DRVMMFI_STATE_BUSY;
1125     else
1126         *peFileinState = E_DRVMMFI_STATE_IDLE;
1127 
1128     _MMFI_RETURN(DRVMMFI_OK);
1129 }
1130 
1131 //-------------------------------------------------------------------------------------------------
1132 /// Get Command queue interrupt state
1133 /// @param  peFileinState                       \b OUT: Pointer of Filein state to return
1134 /// @return MMFI_Result
1135 /// @note
1136 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_ChkStatus(DrvMMFI_Status * pStatus)1137 MMFI_Result MDrv_MMFI_File_ChkStatus(DrvMMFI_Status* pStatus)
1138 {
1139     MS_U32 u32temp = 0;
1140 
1141     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1142 
1143     u32temp = HAL_MMFI_HWInt_Status();
1144 
1145     *pStatus = E_DRVMMFI_STATUS_UNKNOWN;
1146     if(u32temp & MMFI_HWINT_STS_FILEIN_DONE_AU)
1147         *pStatus |= E_DRVMMFI_STATUS_AU_FILEINDONE;
1148     if(u32temp & MMFI_HWINT_STS_AU_ERR)
1149         *pStatus |= E_DRVMMFI_STATUS_AU_PKTERR;
1150 #ifdef MMFI_VD3D
1151     if(u32temp & MMFI_HWINT_STS_FILEIN_DONE_VD)
1152         *pStatus |= E_DRVMMFI_STATUS_VD_FILEINDONE;
1153     if(u32temp & MMFI_HWINT_STS_VD3D_ERR)
1154         *pStatus |= E_DRVMMFI_STATUS_VD_PKTERR;
1155 #endif
1156 
1157     return DRVMMFI_OK;
1158 }
1159 
1160 //-------------------------------------------------------------------------------------------------
1161 /// Clear Command queue interrupt state
1162 /// @param  u32int                       \b OUT: Interrupt bit to clear
1163 /// @return MMFI_Result
1164 /// @note
1165 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_ClearHWInt(MS_U32 u32int)1166 MMFI_Result MDrv_MMFI_File_ClearHWInt(MS_U32 u32int)
1167 {
1168     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1169 
1170     _MMFI_ENTRY();
1171     HAL_MMFI_HWInt_Clear(u32int);
1172     _MMFI_RETURN(DRVMMFI_OK);
1173 }
1174 
1175 //-------------------------------------------------------------------------------------------------
1176 /// Get TS Header information
1177 /// @param  epath                          \b IN: MM Filein Path
1178 /// @param  pheader                       \b OUT: Poniter to store TS Header information
1179 /// @return MMFI_Result
1180 /// @note
1181 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_Get_TsHeader(DrvMMFI_Path epath,DrvPIDFLT_HEADER * pheader)1182 MMFI_Result MDrv_MMFI_Get_TsHeader(DrvMMFI_Path epath, DrvPIDFLT_HEADER *pheader)
1183 {
1184     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1185 
1186     if(epath == E_DRVMMFI_PTH_AUDIO)
1187         HAL_MMFI_AU_Get_TsHeaderInfo((MS_U32*)pheader);
1188 #ifdef MMFI_VD3D
1189     else if(epath == E_DRVMMFI_PATH_VD3D)
1190         HAL_MMFI_V3D_Get_TsHeaderInfo((MS_U32*)pheader);
1191 #endif
1192 
1193     return DRVMMFI_OK;
1194 }
1195 
1196 //-------------------------------------------------------------------------------------------------
1197 /// Control Filein to Start
1198 /// @param  epath                          \b IN: MM Filein Path
1199 /// @return MMFI_Result
1200 /// @note
1201 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_Start(DrvMMFI_Path epath)1202 MMFI_Result MDrv_MMFI_File_Start(DrvMMFI_Path epath)
1203 {
1204     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1205 
1206     _MMFI_ENTRY();
1207 
1208     if(epath == E_DRVMMFI_PTH_AUDIO)
1209     {
1210         HAL_MMFI_AU_Cfg_Enable(MMFI_BYTE_TIMER_EN, TRUE);
1211         HAL_MMFI_AU_Set_Filein_Ctrl(MMFI_FILEIN_RSTART);
1212     }
1213 #ifdef MMFI_VD3D
1214     else if(epath == E_DRVMMFI_PATH_VD3D)
1215     {
1216         HAL_MMFI_V3D_Cfg_Enable(MMFI_BYTE_TIMER_EN, TRUE);
1217         HAL_MMFI_V3D_Set_Filein_Ctrl(MMFI_FILEIN_RSTART);
1218     }
1219 #endif
1220 
1221     _MMFI_RETURN(DRVMMFI_OK);
1222 }
1223 
1224 //-------------------------------------------------------------------------------------------------
1225 /// Control Filein to Abort
1226 /// @param  epath                          \b IN: MM Filein Path
1227 /// @return MMFI_Result
1228 /// @note
1229 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_Abort(DrvMMFI_Path epath)1230 MMFI_Result MDrv_MMFI_File_Abort(DrvMMFI_Path epath)
1231 {
1232     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1233 
1234     _MMFI_ENTRY();
1235 
1236     if(epath == E_DRVMMFI_PTH_AUDIO)
1237         HAL_MMFI_AU_Set_Filein_Ctrl(MMFI_FILEIN_ABORT);
1238 #ifdef MMFI_VD3D
1239     else if(epath == E_DRVMMFI_PATH_VD3D)
1240         HAL_MMFI_V3D_Set_Filein_Ctrl(MMFI_FILEIN_ABORT);
1241 #endif
1242 
1243     _MMFI_RETURN(DRVMMFI_OK);
1244 }
1245 
1246 //-------------------------------------------------------------------------------------------------
1247 /// Enable/Disable MM Filein Path
1248 /// @param  eFileinMode                       \b IN: File-in Mode
1249 /// @param  bEnable                            \b IN: Enable Flag
1250 /// @return MMFI_Result
1251 /// @note
1252 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_File_ModeEnable(DrvMMFI_FileinMode fileinmode,MS_BOOL bEnable)1253 MMFI_Result MDrv_MMFI_File_ModeEnable(DrvMMFI_FileinMode fileinmode, MS_BOOL bEnable)
1254 {
1255     MS_U32 u32cfg = 0;
1256 
1257     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1258 
1259     _MMFI_ENTRY();
1260 
1261     if((fileinmode == E_DRVMMFI_MODE_APID_BYPASS) || (fileinmode == E_DRVMMFI_MODE_NO_BYPASS_AU) ||
1262         (fileinmode == E_DRVMMFI_MODE_PS_AU) || (fileinmode == E_DRVMMFI_MODE_PS_AUB) ||
1263         (fileinmode == E_DRVMMFI_MODE_APIDB_BYPASS))
1264     {
1265         u32cfg = HAL_MMFI_AU_Cfg_Get() & ~MMFI_AU_CFG_MASK;
1266 
1267         if(fileinmode == E_DRVMMFI_MODE_APID_BYPASS)
1268             u32cfg |= MMFI_APID_BYPASS;
1269 
1270         #ifdef MMFI_APIDB_BYPASS
1271         if(fileinmode == E_DRVMMFI_MODE_APIDB_BYPASS)
1272             u32cfg |= MMFI_APIDB_BYPASS;
1273         #endif
1274 
1275         HAL_MMFI_AU_Cfg_Set(u32cfg);
1276     }
1277 
1278     #ifdef MMFI_VD3D
1279     if((fileinmode == E_DRVMMFI_MODE_V3DPID_BYPASS) || (fileinmode == E_DRVMMFI_MODE_NO_BYPASS_V3D) ||
1280         (fileinmode == E_DRVMMFI_MODE_PS_V3D))
1281     {
1282         u32cfg = HAL_MMFI_V3D_Cfg_Get() & ~MMFI_VD_CFG_MASK;
1283 
1284         if(fileinmode == E_DRVMMFI_MODE_V3DPID_BYPASS)
1285             u32cfg |= MMFI_VPID3D_BYPASS;
1286         HAL_MMFI_V3D_Cfg_Set(u32cfg);
1287     }
1288     #endif
1289 
1290     _MMFI_RETURN(DRVMMFI_OK);
1291 }
1292 
MDrv_MMFI_ResetAll(void)1293 MMFI_Result MDrv_MMFI_ResetAll(void)
1294 {
1295     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1296 
1297     _MMFI_ENTRY();
1298     HAL_MMFI_Reset_All();
1299     _MMFI_RETURN(DRVMMFI_OK);
1300 }
1301 
1302 //-------------------------------------------------------------------------------------------------
1303 /// Enable remove duplicate A/V packets
1304 /// @param  bEnable                \b IN: Enable or Disable
1305 /// @return TSP_Result
1306 /// @note
1307 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_RemoveDupAVPkt(MS_BOOL bEnable)1308 MMFI_Result MDrv_MMFI_RemoveDupAVPkt(MS_BOOL bEnable)
1309 {
1310     _MMFI_ENTRY();
1311     HAL_MMFI_AU_RemoveDupPkt(bEnable);
1312 
1313 #ifdef MMFI_VD3D
1314     HAL_MMFI_V3D_RemoveDupPkt(bEnable);
1315 #endif //MMFI_VD3D
1316 
1317     _MMFI_RETURN(DRVMMFI_OK);
1318 }
1319 
1320 //-------------------------------------------------------------------------------------------------
1321 /// Set Video 3D path to be MMFI
1322 /// @param  bEnable             \b IN: Enable Flag
1323 /// @return MMFI_Result
1324 /// @note
1325 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_VD3DPath_Enable(MS_BOOL bEnable)1326 MMFI_Result MDrv_MMFI_VD3DPath_Enable(MS_BOOL bEnable)
1327 {
1328     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1329 
1330 #ifdef MMFI_VD3D
1331     _MMFI_ENTRY();
1332     HAL_MMFI_V3D_Cfg_Enable(MMFI_USE_VD3D_PATH, bEnable);
1333     _MMFI_RETURN(DRVMMFI_OK);
1334 #else    //MMFI_VD3D
1335     return DRVMMFI_FUNC_ERROR;
1336 #endif
1337 }
1338 
1339 //-------------------------------------------------------------------------------------------------
1340 /// Set MOBF filein key
1341 /// @param  eFileinMode                        \b IN: File-in Mode
1342 /// @param  u32Key                      \b IN: MOBF key value
1343 /// @return MMFI_Result
1344 /// @note
1345 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_Set_MOBF_FileinKey(DrvMMFI_Path epath,MS_U32 u32Key)1346 MMFI_Result MDrv_MMFI_Set_MOBF_FileinKey(DrvMMFI_Path epath, MS_U32 u32Key)
1347 {
1348     MMFI_DBGINFO(printf("[%d]%s\n", __LINE__, __FUNCTION__));
1349 
1350 #ifdef MM_MOBF
1351 
1352     _MMFI_ENTRY();
1353 
1354     if(epath == E_DRVMMFI_PTH_AUDIO)
1355         HAL_MMFI_AU_MOBF_Set_FileinKey(u32Key);
1356 #ifdef MMFI_VD3D
1357     else if(epath == E_DRVMMFI_PATH_VD3D)
1358         HAL_MMFI_V3D_MOBF_Set_FileinKey(u32Key);
1359 #endif //MMFI_VD3D
1360 
1361     _MMFI_RETURN(DRVMMFI_OK);
1362 
1363 #else
1364 
1365     return DRVMMFI_FUNC_ERROR;
1366 
1367 #endif
1368 }
1369 
1370 //-------------------------------------------------------------------------------------------------
1371 /// Enable/Disable MOBF decrypt mode
1372 /// @param  benable                \b IN: Enable flag
1373 /// @return TSP_Result
1374 /// @note
1375 //-------------------------------------------------------------------------------------------------
MDrv_MMFI_MOBF_FileIn_Enable(DrvMMFI_Path epath,MS_BOOL benable)1376 MMFI_Result MDrv_MMFI_MOBF_FileIn_Enable(DrvMMFI_Path epath, MS_BOOL benable)
1377 {
1378 #ifdef MM_MOBF
1379 
1380     _MMFI_ENTRY();
1381 
1382     if(epath == E_DRVMMFI_PTH_AUDIO)
1383         HAL_MMFI_AU_MOBF_Enable(benable);
1384 #ifdef MMFI_VD3D
1385     else if(epath == E_DRVMMFI_PATH_VD3D)
1386         HAL_MMFI_V3D_MOBF_Enable(benable);
1387 #endif //MMFI_VD3D
1388 
1389     _MMFI_RETURN(DRVMMFI_OK);
1390 
1391 #else
1392 
1393     return DRVMMFI_FUNC_ERROR;
1394 
1395 #endif
1396 
1397 }
1398 
MDrv_MMFI_MOBF_FileIn_SetLevel(DrvMMFI_Path epath,MS_U8 u8level)1399 MMFI_Result MDrv_MMFI_MOBF_FileIn_SetLevel(DrvMMFI_Path epath, MS_U8 u8level)
1400 {
1401 #ifdef MM_MOBF
1402 
1403     _MMFI_ENTRY();
1404 
1405     if(epath == E_DRVMMFI_PTH_AUDIO)
1406         HAL_MMFI_AU_MOBF_SetLevel(u8level);
1407 #ifdef MMFI_VD3D
1408     else if(epath == E_DRVMMFI_PATH_VD3D)
1409         HAL_MMFI_V3D_MOBF_SetLevel(u8level);
1410 #endif //MMFI_VD3D
1411 
1412     _MMFI_RETURN(DRVMMFI_OK);
1413 
1414 #else
1415 
1416     return DRVMMFI_FUNC_ERROR;
1417 
1418 #endif
1419 
1420 }
1421 
1422 
1423 
1424