xref: /utopia/UTPA2-700.0.x/modules/dmx/hal/macan/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 //--------------------------------------------------------------------------------------------------
107 //  Driver Compiler Option
108 //--------------------------------------------------------------------------------------------------
109 #define MIU_BUS                     4UL
110 
111 //--------------------------------------------------------------------------------------------------
112 //  TSP Hardware Abstraction Layer
113 //--------------------------------------------------------------------------------------------------
114 static REG_Ctrl_MMFI* _MFCtrl= NULL;
115 static REG_Ctrl_MMFI2* _MFCtrl2 = NULL;
116 
117 static MS_VIRT   _virtMMFIRegBase = 0;
118 static MS_PHY    _phyMMFIMiuOffset[MMFI_ENGINE_NUM] = {[0 ... (MMFI_ENGINE_NUM-1)] = 0UL};
119 
120 //[NOTE] Jerry
121 // Some register has write order, for example, writing PCR_L will disable PCR counter
122 // writing PCR_M trigger nothing, writing PCR_H will enable PCR counter
123 #define _HAL_REG32_W(reg, value)    do { (reg)->L = ((value) & 0x0000FFFFUL);                          \
124                                     (reg)->H = ((value) >> 16UL); } while(0)
125 
126 #define _HAL_REG16_W(reg, value)    do { (reg)->data = (MS_U16)((value) & 0xFFFF);} while(0)
127 
128 #define TSP_TSP5_REG(addr)       (*((volatile MS_U16*)(_virtMMFIRegBase + 0xC7600UL + ((addr)<<2UL))))
129     #define REG_TSP5_INIT_TIMESTAMP             0x07UL
130         #define REG_TSP5_INIT_MMFI0_TIMESTAMP   2UL
131         #define REG_TSP5_INIT_MMFI1_TIMESTAMP   4UL
132     #define REG_TSP5_TIMESTAMP_MMFI0_L          0x65UL
133     #define REG_TSP5_TIMESTAMP_MMFI0_H          0x66UL
134     #define REG_TSP5_TIMESTAMP_MMFI1_L          0x67UL
135     #define REG_TSP5_TIMESTAMP_MMFI1_H          0x68UL
136 
137 #define MMFI_REG(addr)              (*((volatile MS_U16*)(_virtMMFIRegBase + REG_CTRL_BASE_MMFI0 + ((addr)<<2UL))))
138 
139 
140 //--------------------------------------------------------------------------------------------------
141 //  Macro of bit operations
142 //--------------------------------------------------------------------------------------------------
143 
144 //--------------------------------------------------------------------------------------------------
145 //  Implementation
146 //--------------------------------------------------------------------------------------------------
_HAL_REG32_R(REG32 * reg)147 static MS_U32 _HAL_REG32_R(REG32 *reg)
148 {
149     MS_U32     value = 0UL;
150     value  = (reg)->H << 16UL;
151     value |= (reg)->L;
152     return value;
153 }
154 
_HAL_REG16_R(REG16 * reg)155 static MS_U16 _HAL_REG16_R(REG16 *reg)
156 {
157     MS_U16              value = 0;
158     value = (reg)->data;
159     return value;
160 }
161 
_HAL_MMFI_MIU_OFFSET(MS_PHY Phyaddr)162 static MS_PHY _HAL_MMFI_MIU_OFFSET(MS_PHY Phyaddr)
163 {
164     #ifdef HAL_MIU2_BASE
165     if(Phyaddr >= (MS_PHY)HAL_MIU2_BASE)
166         return (MS_PHY)HAL_MIU2_BASE;
167     else
168     #endif  //HAL_MIU2_BASE
169     #ifdef HAL_MIU1_BASE
170     if(Phyaddr >= (MS_PHY)HAL_MIU1_BASE)
171         return (MS_PHY)HAL_MIU1_BASE;
172     else
173     #endif //HAL_MIU1_BASE
174         return (MS_PHY)HAL_MIU0_BASE;
175 }
176 
HAL_MMFI_SetBank(MS_VIRT virtBank)177 void HAL_MMFI_SetBank(MS_VIRT virtBank)
178 {
179     _virtMMFIRegBase = virtBank;
180     _MFCtrl = (REG_Ctrl_MMFI*)(_virtMMFIRegBase+ REG_CTRL_BASE_MMFI0);
181     _MFCtrl2 = (REG_Ctrl_MMFI2*)(_virtMMFIRegBase + REG_CTRL2);
182 }
183 
184 // ------------------------------------------------------
185 //   APIs
186 //-------------------------------------------------------
HAL_MMFI_PidFlt_Set(MS_U8 u8Eng,MS_U8 u8Idx,MS_U16 u16PID,MS_U32 u32entype)187 void HAL_MMFI_PidFlt_Set(MS_U8 u8Eng, MS_U8 u8Idx, MS_U16 u16PID, MS_U32 u32entype)
188 {
189     REG32* Reg = NULL;
190 
191     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
192     {
193         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
194     }
195     else
196     {
197         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
198     }
199 
200     _HAL_REG32_W(Reg, ((MS_U32)u16PID & 0xFFFFUL) | u32entype);
201 }
202 
HAL_MMFI_PidFlt_SetPid(MS_U8 u8Eng,MS_U8 u8Idx,MS_U16 u16PID)203 void HAL_MMFI_PidFlt_SetPid(MS_U8 u8Eng, MS_U8 u8Idx, MS_U16 u16PID)
204 {
205     MS_U32 u32data;
206     REG32* Reg = NULL;
207 
208     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
209     {
210         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
211     }
212     else
213     {
214         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
215     }
216 
217     u32data = (_HAL_REG32_R(Reg) & ~MMFI_PIDFLT_PID_MASK) | ((MS_U32)u16PID & 0xFFFFUL);
218     _HAL_REG32_W(Reg, u32data);
219 }
220 
HAL_MMFI_PidFlt_Enable(MS_U8 u8Eng,MS_U8 u8Idx,MS_U32 u32entype,MS_BOOL benable)221 void HAL_MMFI_PidFlt_Enable(MS_U8 u8Eng, MS_U8 u8Idx, MS_U32 u32entype, MS_BOOL benable)
222 {
223     MS_U32 u32data;
224     REG32* Reg = NULL;
225 
226     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
227     {
228         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
229     }
230     else
231     {
232         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
233     }
234 
235     u32data = _HAL_REG32_R(Reg) & ~MMFI_PIDFLT_EN_MASK;
236 
237     if(benable)
238         u32data |= u32entype;
239 
240     _HAL_REG32_W(Reg, u32data);
241 }
242 
HAL_MMFI_PidFlt_Reset(MS_U8 u8Eng,MS_U8 u8Idx)243 void HAL_MMFI_PidFlt_Reset(MS_U8 u8Eng, MS_U8 u8Idx)
244 {
245     REG32* Reg = NULL;
246 
247     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
248     {
249         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
250     }
251     else
252     {
253         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
254     }
255 
256     _HAL_REG32_W(Reg, MMFI_PID_NULL);
257 }
258 
HAL_MMFI_Set_Filein_ReadAddr(MS_U8 u8Eng,MS_PHY phyAddr)259 void HAL_MMFI_Set_Filein_ReadAddr(MS_U8 u8Eng, MS_PHY phyAddr)
260 {
261     _phyMMFIMiuOffset[u8Eng] = _HAL_MMFI_MIU_OFFSET(phyAddr);
262     _HAL_REG32_W(&(_MFCtrl[u8Eng].FileIn_RAddr), (MS_U32)(phyAddr - _phyMMFIMiuOffset[u8Eng]));
263 }
264 
HAL_MMFI_Set_Filein_ReadLen(MS_U8 u8Eng,MS_U32 u32len)265 void HAL_MMFI_Set_Filein_ReadLen(MS_U8 u8Eng, MS_U32 u32len)
266 {
267     _HAL_REG32_W(&(_MFCtrl[u8Eng].FileIn_RNum), u32len);
268 }
269 
HAL_MMFI_Set_Filein_Ctrl(MS_U8 u8Eng,MS_U16 u16ctrl,MS_BOOL bEnable)270 void HAL_MMFI_Set_Filein_Ctrl(MS_U8 u8Eng, MS_U16 u16ctrl, MS_BOOL bEnable)
271 {
272     if(bEnable)
273     {
274         _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) | u16ctrl);
275     }
276     else
277     {
278         _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~u16ctrl);
279     }
280 }
281 
HAL_MMFI_Get_Filein_Ctrl(MS_U8 u8Eng)282 MS_U16 HAL_MMFI_Get_Filein_Ctrl(MS_U8 u8Eng)
283 {
284     return (_HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & MMFI_FILEIN_CTRL_MASK);
285 }
286 
HAL_MMFI_Set_FileinTimer(MS_U8 u8Eng,MS_U8 u8timer)287 void HAL_MMFI_Set_FileinTimer(MS_U8 u8Eng, MS_U8 u8timer)
288 {
289     MS_U16 u16data = (_HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~MMFI_FILEIN_TIMER_MASK) | (((MS_U16)u8timer & 0x00FF) << MMFI_FILEIN_TIMER_SHIFT);
290     _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), u16data);
291 }
292 
HAL_MMFI_Get_Filein_WriteAddr(MS_U8 u8Eng)293 MS_PHY HAL_MMFI_Get_Filein_WriteAddr(MS_U8 u8Eng)
294 {
295     MS_PHY phyaddr = 0;
296 
297     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_RADDR_READ, FALSE);
298     phyaddr = (MS_PHY)(_HAL_REG32_R(&(_MFCtrl[u8Eng].RAddr)) << MIU_BUS) + _phyMMFIMiuOffset[u8Eng];
299     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_RADDR_READ, TRUE);
300 
301     return phyaddr;
302 }
303 
HAL_MMFI_CmdQ_FIFO_Get_WRCnt(MS_U8 u8Eng)304 MS_U16 HAL_MMFI_CmdQ_FIFO_Get_WRCnt(MS_U8 u8Eng)
305 {
306     return (_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_WRCNT_MASK);
307 }
308 
HAL_MMFI_CmdQ_FIFO_IsFull(MS_U8 u8Eng)309 MS_BOOL HAL_MMFI_CmdQ_FIFO_IsFull(MS_U8 u8Eng)
310 {
311     return (MS_BOOL)(_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_FULL);
312 }
313 
HAL_MMFI_CmdQ_FIFO_IsEmpty(MS_U8 u8Eng)314 MS_BOOL HAL_MMFI_CmdQ_FIFO_IsEmpty(MS_U8 u8Eng)
315 {
316     return (MS_BOOL)(_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_EMPTY);
317 }
318 
HAL_MMFI_CmdQ_FIFO_Get_WRLevel(MS_U8 u8Eng)319 MS_U16 HAL_MMFI_CmdQ_FIFO_Get_WRLevel(MS_U8 u8Eng)
320 {
321     return ((_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_WRLEVEL_MASK) >> MMFI_CMDQSTS_FIFO_WRLEVEL_SHIFT);
322 }
323 
HAL_MMFI_Cfg_Enable(MS_U8 u8Eng,MS_U32 u32CfgItem,MS_BOOL benable)324 void HAL_MMFI_Cfg_Enable(MS_U8 u8Eng, MS_U32 u32CfgItem, MS_BOOL benable)
325 {
326     if(benable)
327     {
328         _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) | u32CfgItem));
329     }
330     else
331     {
332         _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) & ~u32CfgItem));
333     }
334 }
335 
HAL_MMFI_Cfg_Set(MS_U8 u8Eng,MS_U32 u32CfglItem)336 void   HAL_MMFI_Cfg_Set(MS_U8 u8Eng, MS_U32 u32CfglItem)
337 {
338     _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), u32CfglItem);
339 }
340 
HAL_MMFI_Cfg_Get(MS_U8 u8Eng)341 MS_U32 HAL_MMFI_Cfg_Get(MS_U8 u8Eng)
342 {
343     return (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)));
344 }
345 
HAL_MMFI_Cfg2_Enable(MS_U8 u8Eng,MS_U16 u16CfgItem,MS_BOOL benable)346 void HAL_MMFI_Cfg2_Enable(MS_U8 u8Eng, MS_U16 u16CfgItem, MS_BOOL benable)
347 {
348     if(benable)
349     {
350         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), (_HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) | u16CfgItem));
351     }
352     else
353     {
354         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), (_HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) & ~u16CfgItem));
355     }
356 }
357 
HAL_MMFI_Cfg2_Set(MS_U8 u8Eng,MS_U16 u16CfglItem)358 void   HAL_MMFI_Cfg2_Set(MS_U8 u8Eng, MS_U16 u16CfglItem)
359 {
360     _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), u16CfglItem);
361 }
362 
HAL_MMFI_Cfg2_Get(MS_U8 u8Eng)363 MS_U16 HAL_MMFI_Cfg2_Get(MS_U8 u8Eng)
364 {
365     return (_HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])));
366 }
367 
368 
HAL_MMFI_Get_TsHeaderInfo(MS_U8 u8Eng,MS_U32 * pu32header)369 void HAL_MMFI_Get_TsHeaderInfo(MS_U8 u8Eng, MS_U32 *pu32header)
370 {
371     *pu32header = _HAL_REG32_R(&(_MFCtrl[u8Eng].TsHeader));
372 }
373 
HAL_MMFI_Get_APid_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)374 void HAL_MMFI_Get_APid_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
375 {
376     MS_U16 u16temp;
377 
378     u16temp = (MS_U16)_HAL_REG16_R(&(_MFCtrl[u8Eng].APid_Status));
379 
380     *pu16pid = u16temp & MMFI_APID_MATCHED_MASK;
381     *pbchanged = (MS_BOOL)(u16temp & MMFI_APID_CHANGE);
382 }
383 
HAL_MMFI_Get_APidB_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)384 void HAL_MMFI_Get_APidB_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
385 {
386     MS_U16 u16temp;
387 
388     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].APidB_Status));
389 
390     *pu16pid = u16temp & MMFI_APIDB_MATCHED_MASK;
391     *pbchanged = (MS_BOOL)(u16temp & MMFI_APIDB_CHANGE);
392 }
393 
HAL_MMFI_Get_VPid_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)394 void HAL_MMFI_Get_VPid_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
395 {
396     MS_U16 u16temp;
397 
398     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].VPID_Status));
399 
400     *pu16pid = u16temp & MMFI_VPID_MATCHED_MASK;
401     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID_CHANGE);
402 }
403 
HAL_MMFI_Get_VPid3D_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)404 void HAL_MMFI_Get_VPid3D_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
405 {
406     MS_U16 u16temp;
407 
408     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].VPID3D_Status));
409 
410     *pu16pid = u16temp & MMFI_VPID3D_MATCHED_MASK;
411     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID3D_CHANGE);
412 }
413 
HAL_MMFI_LPcr2_Set(MS_U8 u8Eng,MS_U32 u32lpcr2)414 void HAL_MMFI_LPcr2_Set(MS_U8 u8Eng, MS_U32 u32lpcr2)
415 {
416     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_WLD, TRUE);
417     _HAL_REG32_W(&(_MFCtrl[u8Eng].LPcr2_Buf), u32lpcr2);
418     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_WLD, FALSE);
419 }
420 
HAL_MMFI_LPcr2_Get(MS_U8 u8Eng)421 MS_U32 HAL_MMFI_LPcr2_Get(MS_U8 u8Eng)
422 {
423     MS_U32 u32value;
424 
425     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_LD, TRUE);
426     u32value = _HAL_REG32_R(&(_MFCtrl[u8Eng].LPcr2_Buf));
427     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_LD, FALSE);
428 
429     return u32value;
430 }
431 
HAL_MMFI_TimeStamp_Get(MS_U8 u8Eng)432 MS_U32 HAL_MMFI_TimeStamp_Get(MS_U8 u8Eng)
433 {
434     return _HAL_REG32_R(&(_MFCtrl[u8Eng].TimeStamp_FIn));
435 }
436 
HAL_MMFI_PktChkSize_Set(MS_U8 u8Eng,MS_U16 u16size)437 void HAL_MMFI_PktChkSize_Set(MS_U8 u8Eng, MS_U16 u16size)
438 {
439     _HAL_REG16_W(&(_MFCtrl[u8Eng].PktChkSize), (_HAL_REG16_R(&(_MFCtrl[u8Eng].PktChkSize)) & ~MMFI_PKTCHK_SIZE_MASK) | u16size);
440 }
441 
HAL_MMFI_MOBF_Set_FileinKey(MS_U8 u8Eng,MS_U16 u16KeyIndex)442 void HAL_MMFI_MOBF_Set_FileinKey(MS_U8 u8Eng, MS_U16 u16KeyIndex)
443 {
444     _HAL_REG16_W(&(_MFCtrl[u8Eng].MOBFKey), u16KeyIndex);
445 }
446 
HAL_MMFI_MOBF_Enable(MS_U8 u8Eng,MS_BOOL bEnable)447 void HAL_MMFI_MOBF_Enable(MS_U8 u8Eng, MS_BOOL bEnable)
448 {
449     return;
450 }
451 
HAL_MMFI_AU_RemoveDupPkt(MS_U8 u8Eng,MS_BOOL bEnable)452 void HAL_MMFI_AU_RemoveDupPkt(MS_U8 u8Eng, MS_BOOL bEnable)
453 {
454     MS_U32 u32data = _HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) & ~MMFI_CFG_DUP_PKT_SKIP;
455 
456     if(bEnable)
457         u32data |= MMFI_CFG_DUP_PKT_SKIP;
458 
459     _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), u32data);
460 }
461 
HAL_MMFI_TimeStampClk_Set(MS_U8 u8Eng,MS_U32 u32ClkSrc)462 void HAL_MMFI_TimeStampClk_Set(MS_U8 u8Eng, MS_U32 u32ClkSrc)
463 {
464     if(u32ClkSrc == 0x0UL) // 90k
465     {
466         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), _HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) & ~MMFI_CFG2_MMFI_27M_EN);
467     }
468     else
469     {
470         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), _HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) | MMFI_CFG2_MMFI_27M_EN);
471     }
472     return;
473 }
474 //
475 // General API
476 //
HAL_MMFI_Reset(void)477 void HAL_MMFI_Reset(void)
478 {
479     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) &~ MMFI_SW_RSTZ_MMFILEIN_DISABLE));
480     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | MMFI_SW_RSTZ_MMFILEIN_DISABLE));
481 }
482 
HAL_MMFI_Reset_SubItem(MS_U16 u16RstItem)483 void HAL_MMFI_Reset_SubItem(MS_U16 u16RstItem)
484 {
485     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | u16RstItem));
486     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) & ~u16RstItem));
487 
488     // init MMFI time-stamp
489     if(u16RstItem == MMFI_RST_CMDQ0)
490     {
491         TSP_TSP5_REG(REG_TSP5_TIMESTAMP_MMFI0_L) = 0;
492         TSP_TSP5_REG(REG_TSP5_TIMESTAMP_MMFI0_H) = 0;
493         TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) = TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) | REG_TSP5_INIT_MMFI0_TIMESTAMP;
494         TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) = TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) & (~REG_TSP5_INIT_MMFI0_TIMESTAMP);
495     }
496     else if(u16RstItem == MMFI_RST_CMDQ1)
497     {
498         TSP_TSP5_REG(REG_TSP5_TIMESTAMP_MMFI1_L) = 0;
499         TSP_TSP5_REG(REG_TSP5_TIMESTAMP_MMFI1_H) = 0;
500         TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) = TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) | REG_TSP5_INIT_MMFI1_TIMESTAMP;
501         TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) = TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) & (~REG_TSP5_INIT_MMFI1_TIMESTAMP);
502     }
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 }
513 
HAL_MMFI_HWInt_Enable(MS_BOOL benable,MS_U16 u16init)514 void HAL_MMFI_HWInt_Enable(MS_BOOL benable, MS_U16 u16init)
515 {
516     MS_U16 u16data = _HAL_REG16_R(&(_MFCtrl[0].HWInt)) & ~u16init;
517 
518     if(benable)
519     {
520         _HAL_REG16_W(&(_MFCtrl[0].HWInt), (u16data | u16init));
521     }
522     else
523     {
524         _HAL_REG16_W(&(_MFCtrl[0].HWInt), u16data);
525     }
526 }
527 
HAL_MMFI_HWInt_Clear(MS_U16 u16Int)528 void HAL_MMFI_HWInt_Clear(MS_U16 u16Int)
529 {
530     _HAL_REG16_W(&(_MFCtrl[0].HWInt), (_HAL_REG16_R(&(_MFCtrl[0].HWInt)) & ~u16Int));
531 }
532 
HAL_MMFI_HWInt_Status(void)533 MS_U32 HAL_MMFI_HWInt_Status(void)
534 {
535     return (MS_U32)(_HAL_REG16_R(&(_MFCtrl[0].HWInt)) & MMFI_HWINT_STS_MASK);
536 }
537 
538