xref: /utopia/UTPA2-700.0.x/modules/dmx/hal/manhattan/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 
121 #ifdef MSOS_TYPE_LINUX_KERNEL
122 static MS_U16    _u16MMFIRegArray[128] = {[0 ... 127] = 0UL};
123 #endif
124 
125 
126 //[NOTE] Jerry
127 // Some register has write order, for example, writing PCR_L will disable PCR counter
128 // writing PCR_M trigger nothing, writing PCR_H will enable PCR counter
129 #define _HAL_REG32_W(reg, value)    do { (reg)->L = ((value) & 0x0000FFFFUL);                          \
130                                     (reg)->H = ((value) >> 16UL); } while(0)
131 
132 #define _HAL_REG16_W(reg, value)    do { (reg)->data = (MS_U16)((value) & 0xFFFF);} while(0)
133 
134 #define TSP_TSP5_REG(addr)       (*((volatile MS_U16*)(_virtMMFIRegBase + 0xC7600UL + ((addr)<<2UL))))
135     #define REG_TSP5_INIT_TIMESTAMP             0x07UL
136         #define REG_TSP5_INIT_MMFI0_TIMESTAMP   2UL
137         #define REG_TSP5_INIT_MMFI1_TIMESTAMP   4UL
138 
139 #define MMFI_REG(addr)              (*((volatile MS_U16*)(_virtMMFIRegBase + REG_CTRL_BASE_MMFI0 + ((addr)<<2UL))))
140 
141 
142 //--------------------------------------------------------------------------------------------------
143 //  Macro of bit operations
144 //--------------------------------------------------------------------------------------------------
145 
146 //--------------------------------------------------------------------------------------------------
147 //  Implementation
148 //--------------------------------------------------------------------------------------------------
_HAL_REG32_R(REG32 * reg)149 static MS_U32 _HAL_REG32_R(REG32 *reg)
150 {
151     MS_U32     value = 0UL;
152     value  = (reg)->H << 16UL;
153     value |= (reg)->L;
154     return value;
155 }
156 
_HAL_REG16_R(REG16 * reg)157 static MS_U16 _HAL_REG16_R(REG16 *reg)
158 {
159     MS_U16              value = 0;
160     value = (reg)->data;
161     return value;
162 }
163 
_HAL_MMFI_MIU_OFFSET(MS_PHY Phyaddr)164 static MS_PHY _HAL_MMFI_MIU_OFFSET(MS_PHY Phyaddr)
165 {
166     #ifdef HAL_MIU2_BASE
167     if(Phyaddr >= (MS_PHY)HAL_MIU2_BASE)
168         return ((MS_PHY)HAL_MIU2_BASE & 0xFFFFFFFFUL);
169     else
170     #endif  //HAL_MIU2_BASE
171     #ifdef HAL_MIU1_BASE
172     if(Phyaddr >= (MS_PHY)HAL_MIU1_BASE)
173         return ((MS_PHY)HAL_MIU1_BASE & 0xFFFFFFFFUL);
174     else
175     #endif //HAL_MIU1_BASE
176         return ((MS_PHY)HAL_MIU0_BASE & 0xFFFFFFFFUL);
177 }
178 
HAL_MMFI_SetBank(MS_VIRT virtBank)179 void HAL_MMFI_SetBank(MS_VIRT virtBank)
180 {
181     _virtMMFIRegBase = virtBank;
182     _MFCtrl = (REG_Ctrl_MMFI*)(_virtMMFIRegBase+ REG_CTRL_BASE_MMFI0);
183     _MFCtrl2 = (REG_Ctrl_MMFI2*)(_virtMMFIRegBase + REG_CTRL2);
184 }
185 
186 // ------------------------------------------------------
187 //   APIs
188 //-------------------------------------------------------
HAL_MMFI_PidFlt_Set(MS_U8 u8Eng,MS_U8 u8Idx,MS_U16 u16PID,MS_U32 u32entype)189 void HAL_MMFI_PidFlt_Set(MS_U8 u8Eng, MS_U8 u8Idx, MS_U16 u16PID, MS_U32 u32entype)
190 {
191     REG32* Reg = NULL;
192 
193     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
194     {
195         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
196     }
197     else
198     {
199         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
200     }
201 
202     _HAL_REG32_W(Reg, ((MS_U32)u16PID & 0xFFFFUL) | u32entype);
203 }
204 
HAL_MMFI_PidFlt_SetPid(MS_U8 u8Eng,MS_U8 u8Idx,MS_U16 u16PID)205 void HAL_MMFI_PidFlt_SetPid(MS_U8 u8Eng, MS_U8 u8Idx, MS_U16 u16PID)
206 {
207     MS_U32 u32data;
208     REG32* Reg = NULL;
209 
210     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
211     {
212         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
213     }
214     else
215     {
216         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
217     }
218 
219     u32data = (_HAL_REG32_R(Reg) & ~MMFI_PIDFLT_PID_MASK) | ((MS_U32)u16PID & 0xFFFFUL);
220     _HAL_REG32_W(Reg, u32data);
221 }
222 
HAL_MMFI_PidFlt_Enable(MS_U8 u8Eng,MS_U8 u8Idx,MS_U32 u32entype,MS_BOOL benable)223 void HAL_MMFI_PidFlt_Enable(MS_U8 u8Eng, MS_U8 u8Idx, MS_U32 u32entype, MS_BOOL benable)
224 {
225     MS_U32 u32data;
226     REG32* Reg = NULL;
227 
228     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
229     {
230         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
231     }
232     else
233     {
234         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
235     }
236 
237     u32data = _HAL_REG32_R(Reg) & ~MMFI_PIDFLT_EN_MASK;
238 
239     if(benable)
240         u32data |= u32entype;
241 
242     _HAL_REG32_W(Reg, u32data);
243 }
244 
HAL_MMFI_PidFlt_Reset(MS_U8 u8Eng,MS_U8 u8Idx)245 void HAL_MMFI_PidFlt_Reset(MS_U8 u8Eng, MS_U8 u8Idx)
246 {
247     REG32* Reg = NULL;
248 
249     if(u8Idx < (MS_U8)MMFI_PIDFLT_GROUP0)
250     {
251         Reg = &(_MFCtrl[u8Eng].PidFlt[u8Idx]);
252     }
253     else
254     {
255         Reg = &(_MFCtrl2[0].PidFlt[u8Eng][u8Idx - (MS_U8)MMFI_PIDFLT_GROUP0]);
256     }
257 
258     _HAL_REG32_W(Reg, MMFI_PID_NULL);
259 }
260 
HAL_MMFI_Set_Filein_ReadAddr(MS_U8 u8Eng,MS_PHY phyAddr)261 void HAL_MMFI_Set_Filein_ReadAddr(MS_U8 u8Eng, MS_PHY phyAddr)
262 {
263     _phyMMFIMiuOffset[u8Eng] = _HAL_MMFI_MIU_OFFSET(phyAddr);
264     _HAL_REG32_W(&(_MFCtrl[u8Eng].FileIn_RAddr), (MS_U32)(phyAddr - _phyMMFIMiuOffset[u8Eng]));
265 }
266 
HAL_MMFI_Set_Filein_ReadLen(MS_U8 u8Eng,MS_U32 u32len)267 void HAL_MMFI_Set_Filein_ReadLen(MS_U8 u8Eng, MS_U32 u32len)
268 {
269     _HAL_REG32_W(&(_MFCtrl[u8Eng].FileIn_RNum), u32len);
270 }
271 
HAL_MMFI_Set_Filein_Ctrl(MS_U8 u8Eng,MS_U16 u16ctrl,MS_BOOL bEnable)272 void HAL_MMFI_Set_Filein_Ctrl(MS_U8 u8Eng, MS_U16 u16ctrl, MS_BOOL bEnable)
273 {
274     if(bEnable)
275     {
276         _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) | u16ctrl);
277     }
278     else
279     {
280         _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), _HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~u16ctrl);
281     }
282 }
283 
HAL_MMFI_Get_Filein_Ctrl(MS_U8 u8Eng)284 MS_U16 HAL_MMFI_Get_Filein_Ctrl(MS_U8 u8Eng)
285 {
286     return (_HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & MMFI_FILEIN_CTRL_MASK);
287 }
288 
HAL_MMFI_Set_FileinTimer(MS_U8 u8Eng,MS_U8 u8timer)289 void HAL_MMFI_Set_FileinTimer(MS_U8 u8Eng, MS_U8 u8timer)
290 {
291     MS_U16 u16data = (_HAL_REG16_R(&(_MFCtrl[u8Eng].FileIn_Ctrl)) & ~MMFI_FILEIN_TIMER_MASK) | (((MS_U16)u8timer & 0x00FF) << MMFI_FILEIN_TIMER_SHIFT);
292     _HAL_REG16_W(&(_MFCtrl[u8Eng].FileIn_Ctrl), u16data);
293 }
294 
HAL_MMFI_Get_Filein_WriteAddr(MS_U8 u8Eng)295 MS_PHY HAL_MMFI_Get_Filein_WriteAddr(MS_U8 u8Eng)
296 {
297     MS_PHY phyaddr = 0;
298 
299     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_RADDR_READ, FALSE);
300     phyaddr = (MS_PHY)(_HAL_REG32_R(&(_MFCtrl[u8Eng].RAddr)) << MIU_BUS) + _phyMMFIMiuOffset[u8Eng];
301     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_RADDR_READ, TRUE);
302 
303     return phyaddr;
304 }
305 
HAL_MMFI_CmdQ_FIFO_Get_WRCnt(MS_U8 u8Eng)306 MS_U16 HAL_MMFI_CmdQ_FIFO_Get_WRCnt(MS_U8 u8Eng)
307 {
308     return (_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_WRCNT_MASK);
309 }
310 
HAL_MMFI_CmdQ_FIFO_IsFull(MS_U8 u8Eng)311 MS_BOOL HAL_MMFI_CmdQ_FIFO_IsFull(MS_U8 u8Eng)
312 {
313     return (MS_BOOL)(_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_FULL);
314 }
315 
HAL_MMFI_CmdQ_FIFO_IsEmpty(MS_U8 u8Eng)316 MS_BOOL HAL_MMFI_CmdQ_FIFO_IsEmpty(MS_U8 u8Eng)
317 {
318     return (MS_BOOL)(_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_EMPTY);
319 }
320 
HAL_MMFI_CmdQ_FIFO_Get_WRLevel(MS_U8 u8Eng)321 MS_U16 HAL_MMFI_CmdQ_FIFO_Get_WRLevel(MS_U8 u8Eng)
322 {
323     return ((_HAL_REG16_R(&(_MFCtrl[u8Eng].CmdQSts)) & MMFI_CMDQSTS_FIFO_WRLEVEL_MASK) >> MMFI_CMDQSTS_FIFO_WRLEVEL_SHIFT);
324 }
325 
HAL_MMFI_Cfg_Enable(MS_U8 u8Eng,MS_U32 u32CfgItem,MS_BOOL benable)326 void HAL_MMFI_Cfg_Enable(MS_U8 u8Eng, MS_U32 u32CfgItem, MS_BOOL benable)
327 {
328     if(benable)
329     {
330         _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) | u32CfgItem));
331     }
332     else
333     {
334         _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) & ~u32CfgItem));
335     }
336 }
337 
HAL_MMFI_Cfg_Set(MS_U8 u8Eng,MS_U32 u32CfglItem)338 void   HAL_MMFI_Cfg_Set(MS_U8 u8Eng, MS_U32 u32CfglItem)
339 {
340     _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), u32CfglItem);
341 }
342 
HAL_MMFI_Cfg_Get(MS_U8 u8Eng)343 MS_U32 HAL_MMFI_Cfg_Get(MS_U8 u8Eng)
344 {
345     return (_HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)));
346 }
347 
HAL_MMFI_Cfg2_Enable(MS_U8 u8Eng,MS_U16 u16CfgItem,MS_BOOL benable)348 void HAL_MMFI_Cfg2_Enable(MS_U8 u8Eng, MS_U16 u16CfgItem, MS_BOOL benable)
349 {
350     if(benable)
351     {
352         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), (_HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) | u16CfgItem));
353     }
354     else
355     {
356         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), (_HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) & ~u16CfgItem));
357     }
358 }
359 
HAL_MMFI_Cfg2_Set(MS_U8 u8Eng,MS_U16 u16CfglItem)360 void   HAL_MMFI_Cfg2_Set(MS_U8 u8Eng, MS_U16 u16CfglItem)
361 {
362     _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), u16CfglItem);
363 }
364 
HAL_MMFI_Cfg2_Get(MS_U8 u8Eng)365 MS_U16 HAL_MMFI_Cfg2_Get(MS_U8 u8Eng)
366 {
367     return (_HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])));
368 }
369 
370 
HAL_MMFI_Get_TsHeaderInfo(MS_U8 u8Eng,MS_U32 * pu32header)371 void HAL_MMFI_Get_TsHeaderInfo(MS_U8 u8Eng, MS_U32 *pu32header)
372 {
373     *pu32header = _HAL_REG32_R(&(_MFCtrl[u8Eng].TsHeader));
374 }
375 
HAL_MMFI_Get_APid_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)376 void HAL_MMFI_Get_APid_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
377 {
378     MS_U16 u16temp;
379 
380     u16temp = (MS_U16)_HAL_REG16_R(&(_MFCtrl[u8Eng].APid_Status));
381 
382     *pu16pid = u16temp & MMFI_APID_MATCHED_MASK;
383     *pbchanged = (MS_BOOL)(u16temp & MMFI_APID_CHANGE);
384 }
385 
HAL_MMFI_Get_APidB_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)386 void HAL_MMFI_Get_APidB_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
387 {
388     MS_U16 u16temp;
389 
390     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].APidB_Status));
391 
392     *pu16pid = u16temp & MMFI_APIDB_MATCHED_MASK;
393     *pbchanged = (MS_BOOL)(u16temp & MMFI_APIDB_CHANGE);
394 }
395 
HAL_MMFI_Get_VPid_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)396 void HAL_MMFI_Get_VPid_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
397 {
398     MS_U16 u16temp;
399 
400     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].VPID_Status));
401 
402     *pu16pid = u16temp & MMFI_VPID_MATCHED_MASK;
403     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID_CHANGE);
404 }
405 
HAL_MMFI_Get_VPid3D_Status(MS_U8 u8Eng,MS_U16 * pu16pid,MS_BOOL * pbchanged)406 void HAL_MMFI_Get_VPid3D_Status(MS_U8 u8Eng, MS_U16 *pu16pid, MS_BOOL *pbchanged)
407 {
408     MS_U16 u16temp;
409 
410     u16temp = _HAL_REG16_R(&(_MFCtrl[u8Eng].VPID3D_Status));
411 
412     *pu16pid = u16temp & MMFI_VPID3D_MATCHED_MASK;
413     *pbchanged = (MS_BOOL)(u16temp & MMFI_VPID3D_CHANGE);
414 }
415 
HAL_MMFI_LPcr2_Set(MS_U8 u8Eng,MS_U32 u32lpcr2)416 void HAL_MMFI_LPcr2_Set(MS_U8 u8Eng, MS_U32 u32lpcr2)
417 {
418 
419     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_WLD, TRUE);
420     _HAL_REG32_W(&(_MFCtrl[u8Eng].LPcr2_Buf), u32lpcr2);
421     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_WLD, FALSE);
422 
423 }
424 
HAL_MMFI_LPcr2_Get(MS_U8 u8Eng)425 MS_U32 HAL_MMFI_LPcr2_Get(MS_U8 u8Eng)
426 {
427     MS_U32 u32value;
428 
429     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_LD, TRUE);
430     u32value = _HAL_REG32_R(&(_MFCtrl[u8Eng].LPcr2_Buf));
431     HAL_MMFI_Cfg_Enable(u8Eng, MMFI_CFG_LPCR2_LD, FALSE);
432 
433     return u32value;
434 }
435 
HAL_MMFI_TimeStamp_Get(MS_U8 u8Eng)436 MS_U32 HAL_MMFI_TimeStamp_Get(MS_U8 u8Eng)
437 {
438     return _HAL_REG32_R(&(_MFCtrl[u8Eng].TimeStamp_FIn));
439 }
440 
HAL_MMFI_PktChkSize_Set(MS_U8 u8Eng,MS_U16 u16size)441 void HAL_MMFI_PktChkSize_Set(MS_U8 u8Eng, MS_U16 u16size)
442 {
443     _HAL_REG16_W(&(_MFCtrl[u8Eng].PktChkSize), (_HAL_REG16_R(&(_MFCtrl[u8Eng].PktChkSize)) & ~MMFI_PKTCHK_SIZE_MASK) | u16size);
444 }
445 
HAL_MMFI_MOBF_Set_FileinKey(MS_U8 u8Eng,MS_U16 u16KeyIndex)446 void HAL_MMFI_MOBF_Set_FileinKey(MS_U8 u8Eng, MS_U16 u16KeyIndex)
447 {
448     _HAL_REG16_W(&(_MFCtrl[u8Eng].MOBFKey), u16KeyIndex);
449 }
450 
HAL_MMFI_MOBF_Enable(MS_U8 u8Eng,MS_BOOL bEnable)451 void HAL_MMFI_MOBF_Enable(MS_U8 u8Eng, MS_BOOL bEnable)
452 {
453     return;
454 }
455 
HAL_MMFI_AU_RemoveDupPkt(MS_U8 u8Eng,MS_BOOL bEnable)456 void HAL_MMFI_AU_RemoveDupPkt(MS_U8 u8Eng, MS_BOOL bEnable)
457 {
458     MS_U32 u32data = _HAL_REG32_R(&(_MFCtrl[u8Eng].Cfg)) & ~MMFI_CFG_DUP_PKT_SKIP;
459 
460     if(bEnable)
461         u32data |= MMFI_CFG_DUP_PKT_SKIP;
462 
463     _HAL_REG32_W(&(_MFCtrl[u8Eng].Cfg), u32data);
464 }
465 
HAL_MMFI_TimeStampClk_Set(MS_U8 u8Eng,MS_U32 u32ClkSrc)466 void HAL_MMFI_TimeStampClk_Set(MS_U8 u8Eng, MS_U32 u32ClkSrc)
467 {
468     if(u32ClkSrc == 0x0UL) // 90k
469     {
470         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), _HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) & ~MMFI_CFG2_MMFI_27M_EN);
471     }
472     else
473     {
474         _HAL_REG16_W(&(_MFCtrl2[0].Cfg2[u8Eng]), _HAL_REG16_R(&(_MFCtrl2[0].Cfg2[u8Eng])) | MMFI_CFG2_MMFI_27M_EN);
475     }
476     return;
477 }
478 //
479 // General API
480 //
HAL_MMFI_Reset(void)481 void HAL_MMFI_Reset(void)
482 {
483     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) &~ MMFI_SW_RSTZ_MMFILEIN_DISABLE));
484     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | MMFI_SW_RSTZ_MMFILEIN_DISABLE));
485 }
486 
HAL_MMFI_Reset_SubItem(MS_U16 u16RstItem)487 void HAL_MMFI_Reset_SubItem(MS_U16 u16RstItem)
488 {
489     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) | u16RstItem));
490     _HAL_REG16_W(&(_MFCtrl[0].SWRst), (_HAL_REG16_R(&(_MFCtrl[0].SWRst)) & ~u16RstItem));
491 
492     // init MMFI time-stamp
493     if(u16RstItem == MMFI_RST_CMDQ0)
494     {
495         TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) = TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) | REG_TSP5_INIT_MMFI0_TIMESTAMP;
496         TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) = TSP_TSP5_REG(REG_TSP5_INIT_TIMESTAMP) & (~REG_TSP5_INIT_MMFI0_TIMESTAMP);
497     }
498     else if(u16RstItem == MMFI_RST_CMDQ1)
499     {
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 
539 #ifdef MSOS_TYPE_LINUX_KERNEL
540 
HAL_MMFI_SaveRegs(void)541 MS_BOOL HAL_MMFI_SaveRegs(void)
542 {
543     MS_U32 u32ii = 0;
544 
545     for(u32ii = 0; u32ii <= 0x78; u32ii++)
546     {
547         _u16MMFIRegArray[u32ii] = MMFI_REG(u32ii);
548     }
549 
550     return TRUE;
551 }
552 
HAL_MMFI_RestoreRegs(void)553 MS_BOOL HAL_MMFI_RestoreRegs(void)
554 {
555     MS_U32 u32ii = 0, u32jj = 0, u32temp = 0;
556     MS_U16 u16temp = 0;
557 
558     for(u32ii = 0; u32ii < MMFI_ENGINE_NUM; u32ii++)
559     {
560         for(u32jj = 0x00; u32jj <= 0x0b; u32jj++)
561         {
562             MMFI_REG(u32temp+u32jj) = _u16MMFIRegArray[u32temp+u32jj];
563         }
564         MMFI_REG(u32temp+0x0e) |= (_u16MMFIRegArray[u32temp+0x0e] & ~0x0083);
565         MMFI_REG(u32temp+0x0f) |= (_u16MMFIRegArray[u32temp+0x0f] & ~0x0001);
566         if(u32temp == 0)
567         {
568             MMFI_REG(0x1b) = _u16MMFIRegArray[0x1b];
569         }
570         MMFI_REG(u32temp+0x1c) = _u16MMFIRegArray[u32temp+0x1c];
571         u32temp += 0x20;
572     }
573     MMFI_REG(0x40) = _u16MMFIRegArray[0x40];
574     MMFI_REG(0x41) = _u16MMFIRegArray[0x41];
575     MMFI_REG(0x50) |= (_u16MMFIRegArray[0x50] & ~0x0600);
576     MMFI_REG(0x51) |= (_u16MMFIRegArray[0x51] & ~0x0600);
577 
578     MMFI_REG(0x56) = _u16MMFIRegArray[0x56];
579     MMFI_REG(0x57) = _u16MMFIRegArray[0x57];
580     MMFI_REG(0x58) = _u16MMFIRegArray[0x58];
581     MMFI_REG(0x59) = _u16MMFIRegArray[0x59];
582     MMFI_REG(0x5e) = _u16MMFIRegArray[0x5e];
583     MMFI_REG(0x5f) = _u16MMFIRegArray[0x5f];
584     MMFI_REG(0x60) = _u16MMFIRegArray[0x60];
585     MMFI_REG(0x61) = _u16MMFIRegArray[0x61];
586     MMFI_REG(0x66) = _u16MMFIRegArray[0x66];
587     MMFI_REG(0x67) = _u16MMFIRegArray[0x67];
588     MMFI_REG(0x70) = _u16MMFIRegArray[0x70];
589     MMFI_REG(0x78) = _u16MMFIRegArray[0x78];
590 
591     //restart file in
592     u16temp = 0;
593     for(u32ii = 0; u32ii < MMFI_ENGINE_NUM; u32ii++)
594     {
595         if((_u16MMFIRegArray[u16temp+0x0c] & MMFI_FILEIN_CTRL_DONE) == 0)
596         {
597             u16temp = (MMFI_REG(u16temp+0x0C) & MMFI_FILEIN_TIMER_MASK) >> MMFI_FILEIN_TIMER_SHIFT;
598             HAL_MMFI_Set_FileinTimer((MS_U8)u32ii, (MS_U8)u16temp);
599 
600             u32temp = (MS_U32)MMFI_REG(u16temp+0x16) & 0xFFFF;
601             u32temp += (((MS_U32)MMFI_REG(u16temp+0x17) & 0xFFFF) << 16);
602             HAL_MMFI_LPcr2_Set((MS_U8)u32ii, u32temp);
603 
604             HAL_MMFI_Cfg_Enable((MS_U8)u32ii, MMFI_CFG_BYTETIMER_EN, TRUE);
605             HAL_MMFI_Set_Filein_Ctrl((MS_U8)u32ii, MMFI_FILEIN_CTRL_START, TRUE);
606         }
607     }
608 
609     return TRUE;
610 }
611 
612 #endif //MSOS_TYPE_LINUX_KERNEL
613 
614