xref: /utopia/UTPA2-700.0.x/modules/dmx/hal/k6lite/mmfi/halMMFilein.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 // file   halMMFilein.c
97 // @brief  Multimedia File In (MMFILEIN) HAL
98 // @author MStar Semiconductor,Inc.
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 #include "MsCommon.h"
101 #include "regMMFilein.h"
102 #include "halMMFilein.h"
103 #include "halCHIP.h"
104 
105 //--------------------------------------------------------------------------------------------------
106 //  Driver Compiler Option
107 //--------------------------------------------------------------------------------------------------
108 #define MIU_BUS                     4
109 
110 //--------------------------------------------------------------------------------------------------
111 //  TSP Hardware Abstraction Layer
112 //--------------------------------------------------------------------------------------------------
113 static REG_Ctrl_MMFI*  _MFCtrl= NULL;
114 static REG_Ctrl_MMFI1* _MFCtrl1= NULL;
115 
116 
117 static MS_VIRT   _u32MMFIRegBase = 0;
118 
119 //[NOTE] Jerry
120 // Some register has write order, for example, writing PCR_L will disable PCR counter
121 // writing PCR_M trigger nothing, writing PCR_H will enable PCR counter
122 #define _HAL_REG32_W(reg, value)    do { (reg)->L = ((value) & 0x0000FFFF);                          \
123                                     (reg)->H = ((value) >> 16); } while(0)
124 
125 #define _HAL_REG16_W(reg, value)    do { (reg)->data = (MS_U16)((value) & 0xFFFF);} while(0)
126 //--------------------------------------------------------------------------------------------------
127 //  Macro of bit operations
128 //--------------------------------------------------------------------------------------------------
129 
130 //--------------------------------------------------------------------------------------------------
131 //  Implementation
132 //--------------------------------------------------------------------------------------------------
_HAL_REG32_R(REG32_MM * reg)133 static MS_U32 _HAL_REG32_R(REG32_MM *reg)
134 {
135     MS_U32     value = 0;
136     value  = (reg)->H << 16;
137     value |= (reg)->L;
138     return value;
139 }
140 
_HAL_REG16_R(REG16_MM * reg)141 static MS_U16 _HAL_REG16_R(REG16_MM *reg)
142 {
143     MS_U16              value = 0;
144     value = (reg)->data;
145     return value;
146 }
147 
HAL_MMFI_SetBank(MS_VIRT u32BankAddr)148 void HAL_MMFI_SetBank(MS_VIRT u32BankAddr)
149 {
150     _u32MMFIRegBase = u32BankAddr;
151     _MFCtrl = (REG_Ctrl_MMFI*)(_u32MMFIRegBase + REG_CTRL_BASE_MMFI0);
152     _MFCtrl1 = (REG_Ctrl_MMFI1*)(_u32MMFIRegBase + REG_CTRL_BASE_MMFI1);
153 }
154 
155 // ------------------------------------------------------
156 //   APIs
157 //-------------------------------------------------------
HAL_MMFI_PidFlt_Set(MS_U8 u8Eng,MS_U8 u8Idx,MS_U16 u16PID,MS_U32 u32entype)158 void HAL_MMFI_PidFlt_Set(MS_U8 u8Eng, MS_U8 u8Idx, MS_U16 u16PID, MS_U32 u32entype)
159 {
160     _HAL_REG32_W(&(_MFCtrl[u8Eng].PidFlt[u8Idx]), (MS_U32)u16PID | u32entype);
161 }
162 
HAL_MMFI_PidFlt_SetPid(MS_U8 u8Eng,MS_U8 u8Idx,MS_U16 u16PID)163 void HAL_MMFI_PidFlt_SetPid(MS_U8 u8Eng, MS_U8 u8Idx, MS_U16 u16PID)
164 {
165     MS_U32 u32data;
166 
167     u32data = (_HAL_REG32_R(&(_MFCtrl[u8Eng].PidFlt[u8Idx])) & ~MMFI_PIDFLT_PID_MASK) | (MS_U32)u16PID;
168     _HAL_REG32_W(&(_MFCtrl[u8Eng].PidFlt[u8Idx]), u32data);
169 }
170 
HAL_MMFI_PidFlt_Enable(MS_U8 u8Eng,MS_U8 u8Idx,MS_U32 u32entype,MS_BOOL benable)171 void HAL_MMFI_PidFlt_Enable(MS_U8 u8Eng, MS_U8 u8Idx, MS_U32 u32entype, MS_BOOL benable)
172 {
173     MS_U32 u32data;
174 
175     if(!u32entype)
176     {
177         printf("[MMFI_ERR][%s][%d] Wrong filter destination !!!\n", __FUNCTION__, __LINE__);
178         return;
179     }
180 
181     u32data = _HAL_REG32_R(&(_MFCtrl[u8Eng].PidFlt[u8Idx])) & ~MMFI_PIDFLT_EN_MASK;
182 
183     if(benable)
184         u32data |= u32entype;
185 
186     _HAL_REG32_W(&(_MFCtrl[u8Eng].PidFlt[u8Idx]), u32data);
187 }
188 
HAL_MMFI_PidFlt_Reset(MS_U8 u8Eng,MS_U8 u8Idx)189 void HAL_MMFI_PidFlt_Reset(MS_U8 u8Eng, MS_U8 u8Idx)
190 {
191     _HAL_REG32_W(&(_MFCtrl[u8Eng].PidFlt[u8Idx]), MMFI_PID_NULL);
192 }
193 
HAL_MMFI_Set_Filein_ReadAddr(MS_U8 u8Eng,MS_U32 u32Addr)194 void HAL_MMFI_Set_Filein_ReadAddr(MS_U8 u8Eng, MS_U32 u32Addr)
195 {
196     MS_U8 u8MiuSel = 0;
197     MS_PHY phyMiuOffsetMMFiBuf = 0;
198     _phy_to_miu_offset(u8MiuSel, phyMiuOffsetMMFiBuf, u32Addr);
199 
200     _HAL_REG32_W(&(_MFCtrl[u8Eng].FileIn_RAddr), phyMiuOffsetMMFiBuf);
201 }
202 
HAL_MMFI_Set_Filein_ReadLen(MS_U8 u8Eng,MS_U32 u32len)203 void HAL_MMFI_Set_Filein_ReadLen(MS_U8 u8Eng, MS_U32 u32len)
204 {
205     _HAL_REG32_W(&(_MFCtrl[u8Eng].FileIn_RNum), u32len);
206 }
207 
HAL_MMFI_Set_Filein_Ctrl(MS_U8 u8Eng,MS_U16 u16ctrl,MS_BOOL bEnable)208 void HAL_MMFI_Set_Filein_Ctrl(MS_U8 u8Eng, MS_U16 u16ctrl, MS_BOOL bEnable)
209 {
210     if(bEnable)
211     {
212         _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) | u16ctrl);
213     }
214     else
215     {
216         _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~u16ctrl);
217     }
218 }
219 
HAL_MMFI_Get_Filein_Ctrl(MS_U8 u8Eng)220 MS_U16 HAL_MMFI_Get_Filein_Ctrl(MS_U8 u8Eng)
221 {
222     return (_HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & MMFI_FILEIN_CTRL_MASK);
223 }
224 
HAL_MMFI_Filein_Pause(MS_U8 u8Eng)225 MS_BOOL HAL_MMFI_Filein_Pause(MS_U8 u8Eng)
226 {
227     _HAL_REG16_W(&(_MFCtrl1->CFG2[u8Eng]), _HAL_REG16_R(&(_MFCtrl1->CFG2[u8Eng])) | MMFI_CFG2_FILEIN_PAUSE);
228 
229     return TRUE;
230 }
231 
HAL_MMFI_Filein_Resume(MS_U8 u8Eng)232 MS_BOOL HAL_MMFI_Filein_Resume(MS_U8 u8Eng)
233 {
234     _HAL_REG16_W(&(_MFCtrl1->CFG2[u8Eng]), _HAL_REG16_R(&(_MFCtrl1->CFG2[u8Eng])) & ~MMFI_CFG2_FILEIN_PAUSE);
235 
236     return TRUE;
237 }
238 
HAL_MMFI_Set_FileinTimer(MS_U8 u8Eng,MS_U8 u8timer)239 void HAL_MMFI_Set_FileinTimer(MS_U8 u8Eng, MS_U8 u8timer)
240 {
241     MS_U16 u16data = (_HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~MMFI_FILEIN_TIMER_MASK) | ((MS_U16)(u8timer&0xFF) << MMFI_FILEIN_TIMER_SHIFT);
242     _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), u16data);
243 }
244 
HAL_MMFI_Get_Filein_WriteAddr(MS_U8 u8Eng)245 MS_U32 HAL_MMFI_Get_Filein_WriteAddr(MS_U8 u8Eng)
246 {
247     MS_U32 u32addr = 0;
248 
249     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_RADDR_READ, FALSE);
250     u32addr = _HAL_REG32_R(&(_MFCtrl[u8Eng].RAddr));
251     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_RADDR_READ, TRUE);
252 
253     return u32addr;
254 }
255 
HAL_MMFI_CmdQ_FIFO_Get_WRCnt(MS_U8 u8Eng)256 MS_U16 HAL_MMFI_CmdQ_FIFO_Get_WRCnt(MS_U8 u8Eng)
257 {
258     return (_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_WRCNT_MASK);
259 }
260 
HAL_MMFI_CmdQ_FIFO_IsFull(MS_U8 u8Eng)261 MS_BOOL HAL_MMFI_CmdQ_FIFO_IsFull(MS_U8 u8Eng)
262 {
263     return (MS_BOOL)(_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_FULL);
264 }
265 
HAL_MMFI_CmdQ_FIFO_IsEmpty(MS_U8 u8Eng)266 MS_BOOL HAL_MMFI_CmdQ_FIFO_IsEmpty(MS_U8 u8Eng)
267 {
268     return (MS_BOOL)(_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_EMPTY);
269 }
270 
HAL_MMFI_CmdQ_FIFO_Get_WRLevel(MS_U8 u8Eng)271 MS_U16 HAL_MMFI_CmdQ_FIFO_Get_WRLevel(MS_U8 u8Eng)
272 {
273     return ((_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_WRLEVEL_MASK) >> MMFI_CMDQSTS_FIFO_WRLEVEL_SHIFT);
274 }
275 
HAL_MMFI_Cfg_Enable(MS_U8 u8Eng,MS_U32 u32CfgItem,MS_BOOL benable)276 void HAL_MMFI_Cfg_Enable(MS_U8 u8Eng, MS_U32 u32CfgItem, MS_BOOL benable)
277 {
278     if(benable)
279     {
280         _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) | u32CfgItem));
281     }
282     else
283     {
284         _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) & ~u32CfgItem));
285     }
286 }
287 
HAL_MMFI_Cfg_Set(MS_U8 u8Eng,MS_U32 u32CfglItem)288 void HAL_MMFI_Cfg_Set(MS_U8 u8Eng, MS_U32 u32CfglItem)
289 {
290     _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), u32CfglItem);
291 }
292 
HAL_MMFI_Cfg_Get(MS_U8 u8Eng)293 MS_U32 HAL_MMFI_Cfg_Get(MS_U8 u8Eng)
294 {
295     return (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)));
296 }
297 
HAL_MMFI_Cfg2_Enable(MS_U8 u8Eng,MS_U16 u16CfgItem,MS_BOOL benable)298 void HAL_MMFI_Cfg2_Enable(MS_U8 u8Eng, MS_U16 u16CfgItem, MS_BOOL benable)
299 {
300     if(benable)
301     {
302         _HAL_REG16_W(&(_MFCtrl1->CFG2[u8Eng]), (_HAL_REG16_R(&(_MFCtrl1->CFG2[u8Eng])) | u16CfgItem));
303     }
304     else
305     {
306         _HAL_REG16_W(&(_MFCtrl1->CFG2[u8Eng]), (_HAL_REG16_R(&(_MFCtrl1->CFG2[u8Eng])) & ~u16CfgItem));
307     }
308 }
309 
HAL_MMFI_Cfg2_Set(MS_U8 u8Eng,MS_U16 u16CfglItem)310 void HAL_MMFI_Cfg2_Set(MS_U8 u8Eng, MS_U16 u16CfglItem)
311 {
312     _HAL_REG16_W(&(_MFCtrl1->CFG2[u8Eng]), u16CfglItem);
313 }
314 
HAL_MMFI_Cfg2_Get(MS_U8 u8Eng)315 MS_U16 HAL_MMFI_Cfg2_Get(MS_U8 u8Eng)
316 {
317     return (_HAL_REG16_R(&(_MFCtrl1->CFG2[u8Eng])));
318 }
319 
HAL_MMFI_Cfg3_Enable(MS_U8 u8Eng,MS_U16 u16CfgItem,MS_BOOL benable)320 void HAL_MMFI_Cfg3_Enable(MS_U8 u8Eng, MS_U16 u16CfgItem, MS_BOOL benable)
321 {
322     if(benable)
323     {
324         _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), (_HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])) | u16CfgItem));
325     }
326     else
327     {
328         _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), (_HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])) & ~u16CfgItem));
329     }
330 }
331 
HAL_MMFI_Cfg3_Set(MS_U8 u8Eng,MS_U16 u16CfglItem)332 void HAL_MMFI_Cfg3_Set(MS_U8 u8Eng, MS_U16 u16CfglItem)
333 {
334     _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), u16CfglItem);
335 }
336 
HAL_MMFI_Cfg3_Get(MS_U8 u8Eng)337 MS_U16 HAL_MMFI_Cfg3_Get(MS_U8 u8Eng)
338 {
339     return (_HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])));
340 }
341 
HAL_MMFI_Get_TsHeaderInfo(MS_U8 u8Eng,MS_U32 * pu32header)342 void HAL_MMFI_Get_TsHeaderInfo(MS_U8 u8Eng, MS_U32 *pu32header)
343 {
344     *pu32header = _HAL_REG32_R(&(_MFCtrl[u8Eng].TsHeader));
345 }
346 
HAL_MMFI_Get_APid_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)347 void HAL_MMFI_Get_APid_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
348 {
349     MS_U16 u16temp;
350 
351     u16temp = (MS_U16)_HAL_REG16_R(&(_MFCtrl[u8Eng].APid_Status));
352 
353     *pu16pid = u16temp & MMFI_APID_MATCHED_MASK;
354     *pbchanged = (MS_BOOL)(u16temp & MMFI_APID_CHANGE);
355 }
356 
HAL_MMFI_Get_APidB_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)357 void HAL_MMFI_Get_APidB_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
358 {
359     MS_U16 u16temp;
360 
361     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].APidB_Status));
362 
363     *pu16pid = u16temp & MMFI_APIDB_MATCHED_MASK;
364     *pbchanged = (MS_BOOL)(u16temp & MMFI_APIDB_CHANGE);
365 }
366 
HAL_MMFI_Get_APidC_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)367 void HAL_MMFI_Get_APidC_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
368 {
369     REG16_MM *reg;
370     MS_U16 u16temp;
371 
372     reg = (u8Eng == 0)? &(_MFCtrl1->APidC_Status_MMFI0) : &(_MFCtrl1->APidC_Status_MMFI1);
373     u16temp = _HAL_REG16_R(reg);
374 
375     *pu16pid = u16temp & MMFI_APIDC_MATCHED_MASK;
376     *pbchanged = (MS_BOOL)(u16temp & MMFI_APIDC_CHANGE);
377 }
378 
HAL_MMFI_Get_APidD_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)379 void HAL_MMFI_Get_APidD_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
380 {
381     REG16_MM *reg;
382     MS_U16 u16temp;
383 
384     reg = (u8Eng == 0)? &(_MFCtrl1->APidD_Status_MMFI0) : &(_MFCtrl1->APidD_Status_MMFI1);
385     u16temp = _HAL_REG16_R(reg);
386 
387     *pu16pid = u16temp & MMFI_APIDD_MATCHED_MASK;
388     *pbchanged = (MS_BOOL)(u16temp & MMFI_APIDD_CHANGE);
389 }
390 
HAL_MMFI_Get_VPid_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)391 void HAL_MMFI_Get_VPid_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
392 {
393     MS_U16 u16temp;
394 
395     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].VPID_Status));
396 
397     *pu16pid = u16temp & MMFI_VPID_MATCHED_MASK;
398     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID_CHANGE);
399 }
400 
HAL_MMFI_Get_VPid3D_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)401 void HAL_MMFI_Get_VPid3D_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
402 {
403     MS_U16 u16temp;
404 
405     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].VPID3D_Status));
406 
407     *pu16pid = u16temp & MMFI_VPID3D_MATCHED_MASK;
408     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID3D_CHANGE);
409 }
410 
HAL_MMFI_Get_VPid3_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)411 void HAL_MMFI_Get_VPid3_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
412 {
413     REG16_MM *reg;
414     MS_U16 u16temp;
415 
416     reg = (u8Eng == 0)? &(_MFCtrl1->VPid3_Status_MMFI0) : &(_MFCtrl1->VPid3_Status_MMFI1);
417     u16temp = _HAL_REG16_R(reg);
418 
419     *pu16pid = u16temp & MMFI_VPID3_MATCHED_MASK;
420     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID3_CHANGE);
421 }
422 
HAL_MMFI_Get_VPid4_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)423 void HAL_MMFI_Get_VPid4_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
424 {
425     REG16_MM *reg;
426     MS_U16 u16temp;
427 
428     reg = (u8Eng == 0)? &(_MFCtrl1->VPid4_Status_MMFI0) : &(_MFCtrl1->VPid4_Status_MMFI1);
429     u16temp = _HAL_REG16_R(reg);
430 
431     *pu16pid = u16temp & MMFI_VPID4_MATCHED_MASK;
432     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID4_CHANGE);
433 }
434 
HAL_MMFI_LPcr2_Set(MS_U8 u8Eng,MS_U32 u32lpcr2)435 void HAL_MMFI_LPcr2_Set(MS_U8 u8Eng, MS_U32 u32lpcr2)
436 {
437     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_WLD, TRUE);
438     _HAL_REG32_W(&(_MFCtrl[u8Eng].LPcr2_Buf), u32lpcr2);
439     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_WLD, FALSE);
440 }
441 
HAL_MMFI_LPcr2_Get(MS_U8 u8Eng)442 MS_U32 HAL_MMFI_LPcr2_Get(MS_U8 u8Eng)
443 {
444     MS_U32 u32value;
445 
446     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_LD, TRUE);
447     u32value = _HAL_REG32_R(&(_MFCtrl[u8Eng].LPcr2_Buf));
448     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_LD, FALSE);
449 
450     return u32value;
451 }
452 
HAL_MMFI_TimeStamp_Get(MS_U8 u8Eng)453 MS_U32 HAL_MMFI_TimeStamp_Get(MS_U8 u8Eng)
454 {
455     return _HAL_REG32_R(&(_MFCtrl[u8Eng].TimeStamp_FIn));
456 }
457 
HAL_MMFI_PktChkSize_Set(MS_U8 u8Eng,MS_U16 u16size)458 void HAL_MMFI_PktChkSize_Set(MS_U8 u8Eng, MS_U16 u16size)
459 {
460     _HAL_REG16_W(&(_MFCtrl[u8Eng].PktChkSize), (_HAL_REG16_R(&(_MFCtrl[u8Eng].PktChkSize)) & ~MMFI_PKTCHK_SIZE_MASK) | u16size);
461 }
462 
HAL_MMFI_MOBF_Set_FileinKey(MS_U8 u8Eng,MS_U16 u16KeyIndex)463 void HAL_MMFI_MOBF_Set_FileinKey(MS_U8 u8Eng, MS_U16 u16KeyIndex)
464 {
465     _HAL_REG16_W(&(_MFCtrl[u8Eng].MOBFKey), u16KeyIndex);
466 }
467 
HAL_MMFI_MOBF_Enable(MS_U8 u8Eng,MS_BOOL bEnable)468 void HAL_MMFI_MOBF_Enable(MS_U8 u8Eng, MS_BOOL bEnable)
469 {
470     MS_U16 u16data = _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~MMFI_FILEIN_CTRL_MOBF_EN;
471 
472     if(bEnable)
473     {
474         u16data |= MMFI_FILEIN_CTRL_MOBF_EN;
475     }
476 
477     _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), u16data);
478 }
479 
HAL_MMFI_AU_RemoveDupPkt(MS_U8 u8Eng,MS_BOOL bEnable)480 void HAL_MMFI_AU_RemoveDupPkt(MS_U8 u8Eng, MS_BOOL bEnable)
481 {
482     MS_U32 u32data = _HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) & ~MMFI_CFG_DUP_PKT_SKIP;
483 
484     if(bEnable)
485         u32data |= MMFI_CFG_DUP_PKT_SKIP;
486 
487     _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), u32data);
488 }
489 
490 //
491 // General API
492 //
HAL_MMFI_Reset(void)493 void HAL_MMFI_Reset(void)
494 {
495     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) &~ MMFI_SW_RSTZ_MMFILEIN_DISABLE));
496     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | MMFI_SW_RSTZ_MMFILEIN_DISABLE));
497 }
498 
HAL_MMFI_Reset_SubItem(MS_U16 u16RstItem)499 void HAL_MMFI_Reset_SubItem(MS_U16 u16RstItem)
500 {
501     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | u16RstItem));
502     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) & ~u16RstItem));
503 }
504 
HAL_MMFI_Reset_All(void)505 void HAL_MMFI_Reset_All(void)
506 {
507     MS_U16 u16data = _HAL_REG16_R(&(_MFCtrl[0].SWRst)) & ~MMFI_SWRST_MASK;
508 
509     _HAL_REG16_W(&(_MFCtrl[0].SWRst), u16data | MMFI_RST_ALL);
510     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (u16data & ~MMFI_SWRST_MASK) | MMFI_SW_RSTZ_MMFILEIN_DISABLE);
511 }
512 
HAL_MMFI_HWInt_Enable(MS_BOOL benable,MS_U16 u16init)513 void HAL_MMFI_HWInt_Enable(MS_BOOL benable, MS_U16 u16init)
514 {
515     MS_U16 u16data = _HAL_REG16_R(&(_MFCtrl[0].HWInt)) & ~u16init;
516 
517     if(benable)
518     {
519         _HAL_REG16_W(&(_MFCtrl[0].HWInt), (u16data | u16init));
520     }
521     else
522     {
523         _HAL_REG16_W(&(_MFCtrl[0].HWInt), u16data);
524     }
525 }
526 
HAL_MMFI_HWInt_Clear(MS_U16 u16Int)527 void HAL_MMFI_HWInt_Clear(MS_U16 u16Int)
528 {
529     _HAL_REG16_W(&(_MFCtrl[0].HWInt), (_HAL_REG16_R(&(_MFCtrl[0].HWInt)) & ~u16Int));
530 }
531 
HAL_MMFI_HWInt_Status(void)532 MS_U32 HAL_MMFI_HWInt_Status(void)
533 {
534     return (MS_U32)(_HAL_REG16_R(&(_MFCtrl[0].HWInt)) & MMFI_HWINT_STS_MASK);
535 }
536 
HAL_MMFI_TimeStampClk_Set(MS_U8 u8Eng,MS_U32 u32ClkSrc)537 void HAL_MMFI_TimeStampClk_Set(MS_U8 u8Eng, MS_U32 u32ClkSrc)
538 {
539     MS_U16 u16Mask = (u8Eng)? MMFI_RST_LPCR_27M_EN_MMFI1 : MMFI_RST_LPCR_27M_EN_MMFI0;
540 
541     if(u32ClkSrc == 0x0UL) // 90k
542     {
543         _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) & ~u16Mask));
544     }
545     else                   // 27M
546     {
547         _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | u16Mask));
548     }
549 }
550 
HAL_MMFI_RVU_Enable(MS_U8 u8Eng,MS_BOOL bEnable)551 MS_BOOL HAL_MMFI_RVU_Enable(MS_U8 u8Eng, MS_BOOL bEnable)
552 {
553     if(bEnable)
554     {
555         _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), _HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])) | MMFI_CFG3_RVU_EN);
556     }
557     else
558     {
559         _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), _HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])) & ~MMFI_CFG3_RVU_EN);
560     }
561 
562     return TRUE;
563 }
564 
HAL_MMFI_RVU_Timestamp_Enable(MS_U8 u8Eng,MS_BOOL bEnable)565 MS_BOOL HAL_MMFI_RVU_Timestamp_Enable(MS_U8 u8Eng, MS_BOOL bEnable)
566 {
567     if(bEnable)
568     {
569         _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), _HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])) | MMFI_CFG3_RVU_TIMESTAMP_EN);
570     }
571     else
572     {
573         _HAL_REG16_W(&(_MFCtrl1->CFG3[u8Eng]), _HAL_REG16_R(&(_MFCtrl1->CFG3[u8Eng])) & ~MMFI_CFG3_RVU_TIMESTAMP_EN);
574     }
575 
576     return TRUE;
577 }
578 
579 // Not implement
HAL_MMFI_SaveRegs(void)580 void HAL_MMFI_SaveRegs(void)
581 {
582 
583 }
584 
585 // Not implement
HAL_MMFI_RestoreRegs(void)586 void HAL_MMFI_RestoreRegs(void)
587 {
588 
589 }