xref: /utopia/UTPA2-700.0.x/modules/dscmb/hal/curry/nsk2/halEMMflt.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) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 ////////////////////////////////////////////////////////////////////////////////
93 #define _HAL_EMMFLT_C
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// @file halEMMflt.c
97 /// @author MStar Semiconductor Inc.
98 /// @brief
99 ////////////////////////////////////////////////////////////////////////////////
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 // Header Files
103 ////////////////////////////////////////////////////////////////////////////////
104 #include "MsCommon.h"
105 #include "MsTypes.h"
106 #include "drvEMMFlt.h"
107 #include "halEMMflt.h"
108 #include "regEMMflt.h"
109 #include "../../include/drvNSK2Type.h"
110 ////////////////////////////////////////////////////////////////////////////////
111 // Define & data type
112 ///////////////////////////////////////////////////////////////////////////////
113 //0x113c for emm filter..
114 
115 //0x100B
116 #define CLKGEN0_REG(addr)       (*((volatile MS_U16*)(_gCLKGEN0_Addr + ((addr)<<2))))
117 
118 //0x100A
119 #define CLKGEN2_REG(addr)       (*((volatile MS_U16*)(_gCLKGEN2_Addr + ((addr)<<2))))
120 
121 //bank 0x101E
122 #define CHIP_REG(addr)          (*((volatile MS_U16*)(_gCHIPTOP_Addr + ((addr)<<2))))
123 
124 //bank 0x1137
125 #define PVR0_REG(addr)          (*((volatile MS_U16*)(_gPVR0_Addr + ((addr)<<2))))
126 
127 //bank 0x19xx
128 #define OTP_REG(addr)           (*((volatile MS_U32*)(_gOTP_Addr + addr )))
129 
130 //bank 0x1713
131 #define OTP_CTRL_REG(addr)      (*((volatile MS_U32*)(_gOTP_CTRL_Addr + (addr<<2) )))
132 
133 
134 static MS_U32 _g32EMMHalDbgLv = EMM_DBGLV_INFO;
135 
136 #define HALEMM_DBG(lv, x, args...)   if (lv <= _g32EMMHalDbgLv ) \
137                                         {printf(x, ##args);}
138 
139 
140 #define ConnectionCheck(x) { if(x>EMMENG_NUMBER)  \
141                             { printf("only one emm allow\n"); \
142                             return FALSE;} }
143 
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 // Local variable
147 ////////////////////////////////////////////////////////////////////////////////
148 
149 //static MS_U32 _gEMMflt_BankAddr = 0;
150 static MS_U32 _gEMMflt_Addr[EMMENG_NUMBER];
151 static MS_U32 _gBasicAddr = 0;
152 static MS_U32 _gOTP_Addr = 0;
153 static MS_U32 _gOTP_CTRL_Addr = 0;
154 static MS_U32 _gPVR0_Addr = 0;
155 static MS_U32 _gCLKGEN0_Addr = 0;
156 static MS_U32 _gCLKGEN2_Addr = 0;
157 static MS_U32 _gCHIPTOP_Addr = 0;
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 // Global variable
161 ////////////////////////////////////////////////////////////////////////////////
162 
163 
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 // Extern Function
167 ////////////////////////////////////////////////////////////////////////////////
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 // Function Declaration
171 ////////////////////////////////////////////////////////////////////////////////
172 void PrintSetting(void);
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 // Local Function
176 ////////////////////////////////////////////////////////////////////////////////
177 
HAL_EMMFLT_WriteReg_Word(MS_U32 connection,MS_U32 u32RegAddr,MS_U16 u16Data)178 static void HAL_EMMFLT_WriteReg_Word(MS_U32 connection, MS_U32 u32RegAddr, MS_U16 u16Data)
179 {
180     MS_U32 u32reg;
181     u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection];
182     (*(volatile MS_U16*)(u32reg)) = u16Data;
183 }
184 
HAL_EMMFLT_ReadReg_Word(MS_U32 connection,MS_U32 u32RegAddr)185 static MS_U16 HAL_EMMFLT_ReadReg_Word(MS_U32 connection, MS_U32 u32RegAddr)
186 {
187     MS_U32 u32reg;
188     MS_U16 u16Data;
189     u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection];
190     u16Data = (*(volatile MS_U16*)(u32reg));
191 
192     return u16Data;
193 }
194 
HAL_EMMFLT_WriteReg_Dword(MS_U32 connection,MS_U32 u32RegAddr,MS_U32 u32Data)195 static void HAL_EMMFLT_WriteReg_Dword(MS_U32 connection, MS_U32 u32RegAddr, MS_U32 u32Data)
196 {
197     MS_U32 u32reg;
198 
199     u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection];
200     (*(volatile MS_U16*)(u32reg)) = (MS_U16)(u32Data&0xffff);
201 
202     u32reg += 4;
203     (*(volatile MS_U16*)(u32reg)) = (MS_U16)((u32Data>>16)&0xffff);
204 }
205 
HAL_EMMFLT_ReadReg_Dword(MS_U32 connection,MS_U32 u32RegAddr)206 static MS_U32 HAL_EMMFLT_ReadReg_Dword(MS_U32 connection, MS_U32 u32RegAddr)
207 {
208     MS_U32 u32reg,u32Data;
209     MS_U16 u16Data1,u16Data2;
210 
211     u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection];
212     u16Data1 = (*(volatile MS_U16*)(u32reg));
213 
214     u32reg += 4;
215     u16Data2 = (*(volatile MS_U16*)(u32reg));
216     u32Data = (u16Data1) + ((MS_U32)u16Data2<<16);
217 
218     return u32Data;
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 // Global Function
223 ////////////////////////////////////////////////////////////////////////////////
224 
HAL_EMMFLT_SetBank(MS_U32 u32Base)225 void HAL_EMMFLT_SetBank(MS_U32 u32Base)
226 {
227     MS_U16 u16I,u16J;
228     MS_U16 u16Data;
229 
230     HALEMM_DBG(EMM_DBGLV_INFO, "%s: u32Base = 0x%x\n", __FUNCTION__, u32Base);
231 
232     _gBasicAddr = u32Base;
233 
234     _gEMMflt_Addr[0] = _gBasicAddr + REG_EMMFLT_BASE1;
235     _gEMMflt_Addr[1] = _gBasicAddr + REG_EMMFLT_BASE2;
236 
237     _gOTP_Addr  = _gBasicAddr + REG_OTP_BASE;
238     _gOTP_CTRL_Addr  = _gBasicAddr + REG_OTP_CTRL_BASE;
239     _gPVR0_Addr  = _gBasicAddr + REG_PVR0_BASE;
240     _gCHIPTOP_Addr= _gBasicAddr + REG_CHIPTOP_BASE;
241     _gCLKGEN0_Addr= _gBasicAddr + REG_CLKGEN0_BASE;
242     _gCLKGEN2_Addr= _gBasicAddr + REG_CLKGEN2_BASE;
243 
244 
245     HALEMM_DBG(EMM_DBGLV_INFO,"_gBasicAddr = %x, _gEMMflt_Addr[0] = %x, _gEMMflt_Addr[1] = %x\n",_gBasicAddr,_gEMMflt_Addr[0],_gEMMflt_Addr[1]);
246     HALEMM_DBG(EMM_DBGLV_INFO,"_gCHIPTOP_Addr = %x, _gCLKGEN0_Addr = %x\n",_gCHIPTOP_Addr,_gCLKGEN0_Addr);
247     HALEMM_DBG(EMM_DBGLV_INFO,"int ctrl addr = %x\n", (_gBasicAddr+ (0x101900<<1) ));
248 
249     for( u16J=0; u16J<EMMENG_NUMBER; u16J++ )
250     {
251         for(u16I=0; u16I<=REG_EMM_TSIF_LOCKED_CNT_STATUS; u16I++)
252         {
253             u16Data = HAL_EMMFLT_ReadReg_Word(u16J,u16I);
254             HALEMM_DBG(EMM_DBGLV_ARRAY, " %x = %x \n",u16I,u16Data);
255         }
256     }
257 
258 }
259 
260 #define FileInTest
261 
HAL_EMMFLT_FileInSet(void)262 static void HAL_EMMFLT_FileInSet(void)
263 {
264     //MS_U32 u32Addr;
265     MS_U16 u16Data,i;
266 
267     HALEMM_DBG(EMM_DBGLV_INFO, "CHIP_REG(0x2) = %x\n",CHIP_REG(0x2));
268     HALEMM_DBG(EMM_DBGLV_INFO, "CHIP_REG(0x3A) = %x\n",CHIP_REG(0x3A));
269 
270 #if 0
271     HALEMM_DBG(0, "CHIP_REG(0x2A) = %x\n",CHIP_REG(0x2A));
272     HALEMM_DBG(0, "CHIP_REG(0x28) = %x\n",CHIP_REG(0x28));
273     HALEMM_DBG(0, "CHIP_REG(0x29) = %x\n",CHIP_REG(0x29));
274 
275 
276     if(CHIP_REG(0x29) != 0)
277     {
278         CHIP_REG(0x29) = 0;
279     }
280 #endif
281 
282     for( i=0 ; i<EMMENG_NUMBER ; i++ )
283     {
284         u16Data = HAL_EMMFLT_ReadReg_Word(i,REG_EMM_CTRL0_L);
285 
286 #if 0 //file in and bypass
287     HALEMM_DBG(EMM_DBGLV_INFO, "File in and bypass\n");
288     u16Data |= (EMM_FW_FILEIN | EMM_FLT_BYPASS);
289 #else //file in only
290     HALEMM_DBG(EMM_DBGLV_INFO, "File in only\n");
291     u16Data |= (EMM_FW_FILEIN);
292 #endif
293 
294         HAL_EMMFLT_WriteReg_Word(i,REG_EMM_CTRL0_L, u16Data);
295     }
296 
297 
298 }
299 
HAL_EMMFLT_LiveInSet(void)300 static void HAL_EMMFLT_LiveInSet(void)
301 {
302     MS_U16 u16Data,i;
303 
304     for( i=0 ; i<EMMENG_NUMBER ; i++ )
305     {
306         u16Data = HAL_EMMFLT_ReadReg_Word(i,REG_EMM_CTRL0_L);
307         u16Data &= ~(EMM_FW_FILEIN);
308 
309         HAL_EMMFLT_WriteReg_Word(i,REG_EMM_CTRL0_L, u16Data);
310     }
311 
312 }
313 
HAL_EMMFLT_SrcSelect(MS_U32 connection,MS_U32 u32SrcFrom,MS_U32 u32SrcType)314 MS_U32 HAL_EMMFLT_SrcSelect(MS_U32 connection, MS_U32 u32SrcFrom, MS_U32 u32SrcType)
315 {
316 
317     //CLKGEN0 bank, [0x29]_bit[11:8]=4'h8
318     //CLKGEN0_REG(0x29) = ( CLKGEN0_REG(0x29) & 0xf0ff ) | 0x800 ;
319 
320     HALEMM_DBG(EMM_DBGLV_INFO,"Enter %s.....\n",__FUNCTION__);
321 
322     //[0x1137]_[0x1e]_[9] = 0
323     //[0x101e]_[0x3a]_[6:4] = 3'b100: from demod0
324     //[0x101e]_[0x43]_[15:0] = 16'h8000: reg_miu_wc_bypass
325     //[0x101e]_[0x44]_[15:0] = 16'h0003: reg_miu_wc_bypass
326     //[0x101e]_[0x02]_[7:0] = 8'h11  (reg_ts1_mode = 1, reg_ts0_mode=1)
327     //[0x100b]_[0x2f]_[12:8] = 5'b100_00  :  clk_ts6_p
328     //[0x100b]_[0x2a]_[4:0]  = 5'b010_00  :  clk_tsp
329     //[0x1015]_[0x7a]_[15:0] = 16'h0002  software reset
330 
331 
332     MS_U32 addr;
333     MS_U16 u16Reg;
334 
335 #if 1
336 	addr = _gBasicAddr + (0x101200*2 + 0x18*4);		// MIU_EN
337     (*((volatile MS_U16*)(addr))) = 0xffff;
338 
339 	addr = _gBasicAddr + (0x161300*2 + 0x00*4);		//$ enable MIUCrossbar
340     (*((volatile MS_U16*)(addr))) = 0x000f;
341 #endif
342 
343 
344     MsOS_DelayTask(1);
345     PrintSetting();
346 
347 
348     //connection needs to modify for K3
349     if(u32SrcFrom == EMM_SRC_FILEIN)
350     {
351         HAL_EMMFLT_FileInSet();
352     }
353     else //EMM_LIVEIN
354     {
355         HAL_EMMFLT_LiveInSet();
356 
357         if(u32SrcType == EMM_SRC_TS0)
358         {
359             HALEMM_DBG(EMM_DBGLV_INFO,"[%s][%d] EMM_SRC_TS0\n",__FUNCTION__,__LINE__);
360 
361             //clock setting to TS0
362             u16Reg = CLKGEN0_REG(0x26);
363             CLKGEN0_REG(0x26) = 0;
364 
365             //pad set to TS0
366             u16Reg = CHIP_REG(0x39);
367             u16Reg &= (~0xf00<<(connection*4));
368             u16Reg |= (EMM_FROM_TS0<<(8+connection*4));
369             CHIP_REG(0x39) = u16Reg;
370 
371 
372             u16Reg = CLKGEN2_REG(0x04+connection);
373             u16Reg &= (~0x001f);
374             u16Reg |= (EMM_FROM_TS0<<2);
375             CLKGEN2_REG(0x04+connection) = u16Reg;
376         }
377         else if(u32SrcType == EMM_SRC_TS1)
378         {
379             HALEMM_DBG(EMM_DBGLV_INFO,"[%s][%d] EMM_SRC_TS1\n",__FUNCTION__,__LINE__);
380 
381             //clock setting to TS1
382             u16Reg = CLKGEN0_REG(0x26);
383             CLKGEN0_REG(0x26) = 0x404;
384 
385             //pad set to TS1
386             u16Reg = CHIP_REG(0x39);
387             u16Reg &= ~(0xf00<<(connection*4));
388             u16Reg |= (EMM_FROM_TS1<<(8+connection*4));
389             CHIP_REG(0x39) = u16Reg;
390 
391 
392             u16Reg = CLKGEN2_REG(0x04+connection);
393             u16Reg &= (~0x001f);
394             u16Reg |= (EMM_FROM_TS1<<2);
395             CLKGEN2_REG(0x04+connection) = u16Reg;
396         }
397         else if(u32SrcType == EMM_SRC_TS3)
398         {
399             //u16Reg = CHIP_REG(0x2);
400             //u16Reg |= 0x18;
401             //CHIP_REG(0x2) = u16Reg;
402 
403             //pad set to TS3
404             u16Reg = CHIP_REG(0x39);
405             u16Reg &= ~(0xf00<<(connection*4));
406             u16Reg |= (EMM_FROM_TS3<<(8+connection*4));
407             CHIP_REG(0x39) = u16Reg;
408 
409 
410             u16Reg = CLKGEN2_REG(0x04+connection);
411             u16Reg &= (~0x003f);
412             u16Reg |= (EMM_FROM_TS3<<2);
413             CLKGEN2_REG(0x04+connection) = u16Reg;
414         }
415 
416 
417     }
418 
419     return TRUE;
420 }
421 
422 
PrintSetting(void)423 void PrintSetting(void)
424 {
425 
426     MS_U32 addr;
427     MS_U16 u16Reg;
428 
429 
430 	#if 0
431 
432 	KERES EMM PADDING
433 	//a.	reg_ts0_mode : bank_101e_0x02_[2:0]    = 3'd001;		//TS0 Mode
434     u16Reg = CHIP_REG(0x02);
435     u16Reg = (u16Reg & ~0x0007) | 0x1;
436     CHIP_REG(0x02) = u16Reg;
437 
438 	//b.	reg_ckg_ts4 :	   bank_100b_0x26_[3:0]    = 4'b0;
439 	//clk source for ts4: ts0_clk
440 	u16Reg = CLKGEN0_REG(0x26);
441     u16Reg = (u16Reg & ~0x000f) | 0x0;
442     CLKGEN0_REG(0x26) = u16Reg;
443 
444 	//c.	reg_ckg_ts5 :	   bank_100b_0x26_[11:8]  = 4'b0;
445 	//clk source for ts5: ts0_clk
446 	u16Reg = CLKGEN0_REG(0x26);
447     u16Reg = (u16Reg & ~0x0f00) | 0x0;
448     CLKGEN0_REG(0x26) = u16Reg;
449 
450 	//d.	reg_emmflt0_mux:  bank_101e_0x39_[10:8]    = 3'd000
451 	//Source Selections for EMMFLT Channel 0: come from PAD_TS0
452 	u16Reg = CHIP_REG(0x39);
453     u16Reg = (u16Reg & ~0x0700) | 0x0;
454     CHIP_REG(0x39) = u16Reg;
455 
456 	//e.	reg_emmflt1_mux:  bank_101e_0x39_[14:12]	= 3'd000
457 	//Source Selections for EMMFLT Channel 1: come from PAD_TS0
458 	u16Reg = CHIP_REG(0x39);
459     u16Reg = (u16Reg & ~0x7000) | 0x0;
460     CHIP_REG(0x39) = u16Reg;
461 
462 	#endif
463 
464     u16Reg = CHIP_REG(0x2);
465     HALEMM_DBG(EMM_DBGLV_DEBUG, "CHIP 0x2 = %x\n", u16Reg);
466 
467     u16Reg = CHIP_REG(0x39);
468     HALEMM_DBG(EMM_DBGLV_DEBUG, "CHIP 0x39 = %x\n", u16Reg);
469 
470     u16Reg = CLKGEN0_REG(0x26);
471     HALEMM_DBG(EMM_DBGLV_DEBUG, "CLKGEN0 0x26 = %x\n", u16Reg);
472 
473 
474     addr = _gBasicAddr + (0x101500*2 + 0x7a*4);
475     u16Reg = (*((volatile MS_U16*)(addr)));
476     HALEMM_DBG(EMM_DBGLV_DEBUG, "(TSP0, 0x101500*2 + 0x7a*4) = %x\n", u16Reg);
477 
478 	#if 0
479     addr = _gBasicAddr + (0x113700*2 + 0x1e*4);
480     u16Reg = (*((volatile MS_U16*)(addr)));
481     HALEMM_DBG(EMM_DBGLV_DEBUG, "(0x113700*2 + 0x1e*4) = %x\n", u16Reg);
482 	#endif
483 }
484 
485 
HAL_EMMFLT_Init(void)486 MS_U32 HAL_EMMFLT_Init(void)
487 {
488     MS_U16 u16Data;
489     MS_U32 i;
490 
491     for( i=0 ; i<EMMENG_NUMBER ; i++ )
492     {
493         u16Data = HAL_EMMFLT_ReadReg_Word(i,REG_EMM_RESET);
494 
495         u16Data |= EMM_RESET_UNLOCK;
496         HAL_EMMFLT_WriteReg_Word(i,REG_EMM_RESET, u16Data);
497     }
498 
499     for( i=0 ; i<EMMENG_NUMBER ; i++ )
500     {
501         u16Data = HAL_EMMFLT_ReadReg_Word(i,REG_EMM_STR2MIU_EN);
502         u16Data |= EMM_STR2MIU_EN;
503         HAL_EMMFLT_WriteReg_Word(i, REG_EMM_STR2MIU_EN, u16Data); //string 2 miu enable
504 
505         HALEMM_DBG(EMM_DBGLV_INFO, "enable stream to miu \n");
506 
507         //designer suggest setting....still needs to confirm
508 
509 		HAL_EMMFLT_WriteReg_Word(i, REG_EMM_TS_IF2_CTRL, 0x80e1);
510         //HAL_EMMFLT_WriteReg_Word(i, REG_EMM_TS_IF2_CTRL, 0x8fe1);		//DEBUG
511     }
512 
513     return TRUE;
514 }
515 
HAL_EMMFLT_GetHwBufCnt(MS_U32 * pHwBufCnt)516 MS_U32 HAL_EMMFLT_GetHwBufCnt(MS_U32 *pHwBufCnt)
517 {
518     *pHwBufCnt = EMMFLT_HWBUF_NUM;
519     return TRUE;
520 }
521 
522 //does connection needs to be increased.
HAL_EMMFLT_SWReset(MS_U32 connection)523 MS_U32 HAL_EMMFLT_SWReset(MS_U32 connection)
524 {
525     MS_U16 u16Data;
526 
527     u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_RESET);
528     u16Data &= (~EMM_RESET_UNLOCK);
529 
530     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_RESET, u16Data);
531 
532     u16Data |= EMM_RESET_UNLOCK;
533     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_RESET, u16Data);
534 
535     return TRUE;
536 }
537 
HAL_EMMFLT_SetDbgLevel(MS_U32 u32Level)538 MS_U32 HAL_EMMFLT_SetDbgLevel(MS_U32 u32Level)
539 {
540     _g32EMMHalDbgLv = u32Level;
541     HALEMM_DBG(EMM_DBGLV_DEBUG, "%s level: %x\n", __FUNCTION__, u32Level);
542     return TRUE;
543 }
544 
545 
HAL_EMMFLT_SetOutputType(MS_U32 connection,MS_U32 u32Type)546 MS_U32 HAL_EMMFLT_SetOutputType(MS_U32 connection, MS_U32 u32Type)
547 {
548     MS_U16 u16Data;
549 
550     HALEMM_DBG(EMM_DBGLV_INFO, "SetOutputType conn = %x, Type = %x \n",connection,u32Type);
551     if(u32Type == EMM_OUT_NORMAL)
552     {
553         u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_GENERAL_CTRL_L);
554         u16Data &= ~(__BIT2);
555         HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_GENERAL_CTRL_L, u16Data);
556     }
557     else if(u32Type == EMM_OUT_184BYTES)
558     {
559 
560     }
561     else if(u32Type == EMM_OUT_PACKETNUM)
562     {
563         u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_GENERAL_CTRL_L);
564         u16Data |= (__BIT2);
565         HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_GENERAL_CTRL_L, u16Data);
566     }
567     return TRUE;
568 }
569 
HAL_EMMFLT_Enable_Int(void)570 MS_U32 HAL_EMMFLT_Enable_Int(void)
571 {
572     MS_U32 i;
573 
574     HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_Enable_Int\n");
575     for( i=0 ; i<EMMENG_NUMBER ; i++ )
576     {
577         //HAL_EMMFLT_WriteReg_Word(REG_EMM_CA_INT,0);
578         //HAL_EMMFLT_WriteReg_Word( i, 0x0075, 0x3);
579         HAL_EMMFLT_WriteReg_Word( i, REG_EMM_CA_INT, (EMM_ONEPAKCET_INT | EMM_OVERFLOW_INT));
580     }
581     return TRUE;
582 }
583 
584 
HAL_EMMFLT_SetTidMode(MS_U32 connection,MS_U8 u8TidValue,EMM_TIDMODE_e eTIDMODE)585 MS_U32 HAL_EMMFLT_SetTidMode(MS_U32 connection, MS_U8 u8TidValue, EMM_TIDMODE_e eTIDMODE)
586 {
587 
588     MS_U32 u32Data;
589 
590     ConnectionCheck(connection);
591 
592     u32Data = HAL_EMMFLT_ReadReg_Dword(connection,REG_EMM_TID_MODE_L);
593 
594     u32Data &= ~((MS_U32)E_TIDMODE_RESERVED<<u8TidValue);
595     u32Data |= ((MS_U32)eTIDMODE<<u8TidValue);
596 
597 
598     HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_TID_MODE_L,u32Data);
599     HALEMM_DBG(EMM_DBGLV_INFO, "%s SetTidMode value : %x\n", __FUNCTION__, u32Data);
600     return TRUE;
601 }
602 
HAL_EMMFLT_SetIRDMode(MS_U32 connection,MS_U8 u8IRDNum,MS_U8 u8CompareMode)603 MS_U32 HAL_EMMFLT_SetIRDMode(MS_U32 connection,MS_U8 u8IRDNum, MS_U8 u8CompareMode)
604 {
605     MS_U16 u16Mask,u16Data;
606 
607     ConnectionCheck(connection);
608     if(u8CompareMode > REG_EMM_CTRL_MAX)
609     {
610         return HAL_EMMFLT_INVALID_REQUEST;
611     }
612 
613     if(u8IRDNum > REG_EMM_IRD_MAX)
614     {
615         return HAL_EMMFLT_INVALID_REQUEST;
616     }
617 
618     HALEMM_DBG(EMM_DBGLV_INFO, "%s u8IRDNum= %d, u8CompareMode = %d\n", __FUNCTION__, u8IRDNum, u8CompareMode );
619     u16Mask = (EMM_IRD_REG_MASK << (u8IRDNum*2));
620 
621     u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_CTRL_ID);
622 
623     HALEMM_DBG(EMM_DBGLV_INFO, "REG_EMM_CTRL_ID = %x\n",u16Data);
624     u16Data &= ~u16Mask;
625 
626 
627     u16Data |= (u8CompareMode << (u8IRDNum*2));
628     HALEMM_DBG(EMM_DBGLV_INFO, "%s u16Data= %x \n", __FUNCTION__, u16Data);
629     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CTRL_ID, u16Data);
630 
631     return TRUE;
632 }
633 
634 
HAL_EMMFLT_SetEmmDataIDx(MS_U32 connection,MS_U8 u8IRDNum,MS_U8 * pu8Data)635 MS_U32 HAL_EMMFLT_SetEmmDataIDx(MS_U32 connection, MS_U8 u8IRDNum, MS_U8 *pu8Data)
636 {
637     MS_U32 u32IRDAddr,u32EMMAddr;
638     MS_U32 u32Mapping[] = {REG_EMM_DATA_ID1_L, REG_EMM_DATA_ID2_L,
639                            REG_EMM_DATA_ID3_L, REG_EMM_DATA_ID4_L,
640                            REG_EMM_DATA_ID5_L, REG_EMM_DATA_ID6_L,
641                            REG_EMM_DATA_ID7_L, REG_EMM_DATA_ID8_L, };
642 
643 
644     ConnectionCheck(connection);
645 
646     u32EMMAddr = ((MS_U32)pu8Data[0]<<24) + ((MS_U32)pu8Data[1]<<16) +
647                  ((MS_U32)pu8Data[2]<<8) + ((MS_U32)pu8Data[3]) ;
648 
649 
650     HALEMM_DBG(EMM_DBGLV_INFO, "%s u8IRDNum= %x, u32EMMAddr = %x\n", __FUNCTION__, u8IRDNum, u32EMMAddr);
651 
652     if(u8IRDNum >= REG_EMM_IRD_MAX)
653     {
654         return HAL_EMMFLT_INVALID_REQUEST;
655     }
656 
657 
658     u32IRDAddr = u32Mapping[u8IRDNum];
659 
660     HAL_EMMFLT_WriteReg_Dword(connection,u32IRDAddr,u32EMMAddr);
661 
662     return TRUE;
663 }
664 
HAL_EMMFLT_SetEmmMaskIDx(MS_U32 connection,MS_U8 u8IRDNum,MS_U8 * pu8Data)665 MS_U32 HAL_EMMFLT_SetEmmMaskIDx(MS_U32 connection,MS_U8 u8IRDNum, MS_U8 *pu8Data)
666 {
667     MS_U32 u32IRDAddr,u32EMMMask;
668     MS_U32 u32Mapping[] = {REG_EMM_MASK_ID1_L, REG_EMM_MASK_ID2_L,
669                            REG_EMM_MASK_ID3_L, REG_EMM_MASK_ID4_L,
670                            REG_EMM_MASK_ID5_L, REG_EMM_MASK_ID6_L,
671                            REG_EMM_MASK_ID7_L, REG_EMM_MASK_ID8_L, };
672 
673 
674     ConnectionCheck(connection);
675 
676     u32EMMMask = ((MS_U32)pu8Data[0]<<24) + ((MS_U32)pu8Data[1]<<16) +
677                  ((MS_U32)pu8Data[2]<<8) + ((MS_U32)pu8Data[3]) ;
678     HALEMM_DBG(EMM_DBGLV_INFO, "%s u8IRDNum= %x, u32EMMMask = %x\n", __FUNCTION__, u8IRDNum, u32EMMMask);
679 
680     if(u8IRDNum >= REG_EMM_IRD_MAX)
681     {
682         return HAL_EMMFLT_INVALID_REQUEST;
683     }
684 
685 
686     u32IRDAddr = u32Mapping[u8IRDNum];
687 
688     HAL_EMMFLT_WriteReg_Dword(connection,u32IRDAddr,u32EMMMask);
689 
690     return TRUE;
691 }
692 
HAL_EMMFLT_DisableEMM(MS_U32 connection)693 MS_U32 HAL_EMMFLT_DisableEMM(MS_U32 connection)
694 {
695     ConnectionCheck(connection);
696 
697     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, 0);
698     return TRUE;
699 }
700 
HAL_EMMFLT_SetEmmPID(MS_U32 connection,MS_U16 u16EmmPID)701 MS_U32 HAL_EMMFLT_SetEmmPID(MS_U32 connection,MS_U16 u16EmmPID)
702 {
703     MS_U16 u16Data;
704 
705     HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_SetEmmPID conn = %x, u16EmmPID = %x \n",connection,u16EmmPID);
706     PrintSetting();
707 
708     ConnectionCheck(connection);
709 #if 1
710     u16Data = 0;
711     u16Data = u16EmmPID;
712 #else
713     u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_PID);
714 
715     u16Data = ( u16Data & ~(REG_EMM_ENABLE_TID | REG_EMM_ENABLE_PID) ) | u16EmmPID;
716 #endif
717     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, u16Data);
718     return TRUE;
719 }
720 
HAL_EMMFLT_SetEmmTID(MS_U32 connection,MS_U16 u16EmmTID)721 MS_U32 HAL_EMMFLT_SetEmmTID(MS_U32 connection,MS_U16 u16EmmTID)
722 {
723     HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_SetEmmTID conn = %x, u16EmmTID = %x \n",connection,u16EmmTID);
724     ConnectionCheck(connection);
725     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_TID, u16EmmTID);
726     return TRUE;
727 }
728 
HAL_EMMFLT_EnableEmmTID(MS_U32 connection,MS_BOOL bEnable)729 MS_U32 HAL_EMMFLT_EnableEmmTID(MS_U32 connection, MS_BOOL bEnable)
730 {
731     MS_U16 u16Data;
732 
733     HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_EnableEmmTID conn = %x, bEnable = %x \n",connection,bEnable);
734     ConnectionCheck(connection);
735     u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_PID);
736 
737     if(TRUE == bEnable)
738     {
739         u16Data |= REG_EMM_ENABLE_TID;
740     }
741     else
742     {
743         u16Data &= (~REG_EMM_ENABLE_TID);
744     }
745 
746     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, u16Data);
747 
748     return TRUE;
749 }
750 
751 
HAL_EMMFLT_ResetInt(MS_U32 connection)752 MS_U32 HAL_EMMFLT_ResetInt(MS_U32 connection)
753 {
754     MS_U16 u16Data;
755 
756     HALEMM_DBG(EMM_DBGLV_ERR, "EMMFLT_ResetInt conn = %x\n",connection);
757 
758     u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_CA_INT);
759 
760     u16Data |= EMM_RESET_INT;
761 
762 	HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CA_INT, u16Data);
763 
764     return TRUE;
765 }
766 
767 #if 0
768 MS_U32 HAL_EMMFLT_GetIntReg(MS_U16 *pu16Data)
769 {
770     MS_U16 u16Data = 0,u16I;
771     *pu16Data = 0;
772 
773     for( u16I=0 ; u16I<EMMENG_NUMBER ; u16I++)
774     {
775         u16Data = HAL_EMMFLT_ReadReg_Word( u16I, REG_EMM_CA_INT );
776         *pu16Data = u16Data & (EMM_ONEPAKCET_INT | EMM_OVERFLOW_INT);
777     }
778 
779     return TRUE;
780 }
781 #endif
782 
HAL_EMMFLT_GetIntStatus(MS_U16 * pu16EMMInt,MS_U16 * pu16IntStat,MS_U8 * pu8conflag)783 MS_U32 HAL_EMMFLT_GetIntStatus(MS_U16 *pu16EMMInt, MS_U16 *pu16IntStat, MS_U8 *pu8conflag)
784 {
785     MS_U16 u16Data,i;
786 
787     for( i=0; i<EMMENG_NUMBER ; i++)
788     {
789         pu8conflag[i] = FALSE;
790         u16Data = HAL_EMMFLT_ReadReg_Word(i,REG_EMM_CA_INT);
791         HALEMM_DBG(EMM_DBGLV_DEBUG, "%s i= %x, u16Data = %x\n", __FUNCTION__, i, u16Data);
792 
793         //that means the first emm has interrupt....
794         if( (u16Data & EMMFLT_EMM_OVERFLOW_INT) || (u16Data & EMMFLT_EMM_INT) )
795         {
796             pu8conflag[i]  =  TRUE;
797             pu16IntStat[i] = (u16Data & EMM_INT_MASK) ;
798             pu16EMMInt[i]  =  u16Data;
799         }
800     }
801     HALEMM_DBG(EMM_DBGLV_DEBUG, "Int status = %x\n",u16Data);
802 
803     return TRUE;
804 }
805 
HAL_EMMFLT_GetCurrentBufIndex(MS_U32 connection)806 MS_U32 HAL_EMMFLT_GetCurrentBufIndex(MS_U32 connection)
807 {
808     MS_U32 index = HAL_EMMFLT_ReadReg_Word(connection, REG_EMM_INT_STAT);
809 
810     //MS_U32 index = (HAL_EMMFLT_ReadReg_Word(connection, REG_EMM_CA_INT)>>8);
811     HALEMM_DBG(EMM_DBGLV_INFO, "current index = %x\n",index);
812     return index;
813 }
814 
HAL_EMMFLT_ReqDstBufSize(MS_U32 * p32DstBufSize,MS_U32 * p32AlignBytes,MS_U8 * p8BufBum)815 MS_U32 HAL_EMMFLT_ReqDstBufSize(MS_U32 *p32DstBufSize, MS_U32 *p32AlignBytes, MS_U8 *p8BufBum)
816 {
817     *p32DstBufSize = EMMFLT_HWBUF_SIZE;
818     *p32AlignBytes = EMMFLT_BUF_ALIGNMENT;
819     *p8BufBum = EMMENG_NUMBER;
820 
821     HALEMM_DBG(EMM_DBGLV_INFO, "ReqDstBufSize HWBUF_SIZE = %x, BUF_ALIGNMENT = %x, EMMENG_NUMBER = %x\n",EMMFLT_HWBUF_SIZE, EMMFLT_BUF_ALIGNMENT,EMMENG_NUMBER);
822     return TRUE;
823 }
824 
HAL_EMMFLT_SetDstBufInfo(MS_U32 connection,MS_U32 u32BufAddr,MS_U32 u32BufSize,MS_U32 * p32BufAddrs)825 MS_U32 HAL_EMMFLT_SetDstBufInfo(MS_U32 connection, MS_U32 u32BufAddr, MS_U32 u32BufSize, MS_U32 *p32BufAddrs)
826 {
827     MS_U32 u32I;
828     MS_U16 u16Reg;
829 
830     ConnectionCheck(connection);
831     HALEMM_DBG(EMM_DBGLV_INFO, "%s u32BufAddr= %x, u32BufSize= %x \n", __FUNCTION__, u32BufAddr,u32BufSize);
832 
833     HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_STR2MIU_HEAD1_L, (u32BufAddr>>4));
834     HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_STR2MIU_TAIL1_L, ((u32BufAddr+u32BufSize)>>4));
835     HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_STR2MIU_MID1_L,  ((u32BufAddr+u32BufSize)>>4));
836 
837 
838     u16Reg = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_STR2MIU_EN);
839     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_STR2MIU_EN, (u16Reg | 0x4) );
840 
841     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_STR2MIU_EN,u16Reg);
842 
843     for(u32I = 0; u32I<MAX_EMMFLT_NUM ; u32I++)
844     {
845         p32BufAddrs[u32I] = u32BufAddr + (u32I*U01_NDS_EMMFLT_BUF_SIZE);
846         HALEMM_DBG(EMM_DBGLV_INFO, "%s p32BufAddr[%x] = %x, \n", __FUNCTION__, u32I, p32BufAddrs[u32I]);
847     }
848 
849     return TRUE;
850 }
851 
852 
853 //does connection needs to be increased.
HAL_EMMFLT_PacketCount(MS_U32 connection,MS_U8 * pCount)854 MS_U32 HAL_EMMFLT_PacketCount(MS_U32 connection,MS_U8 *pCount)
855 {
856     MS_U16 PacketCnt;
857     PacketCnt = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_PACKET_CNT);
858     HALEMM_DBG(EMM_DBGLV_INFO, "REG_EMM_PACKET_CNT = %x\n",PacketCnt);
859     *pCount = (MS_U8)((PacketCnt>>8)&0xff);
860     return TRUE;
861 }
862 
863 
864 
865 //does connection needs to be increased.
HAL_EMMFLT_PacketAct(MS_U32 connection)866 MS_U32 HAL_EMMFLT_PacketAct(MS_U32 connection)
867 {
868 #if 0
869     MS_U16 u16Rg;
870     u16Rg = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_CA_INT);
871     u16Rg = (0x10<<8);
872     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CA_INT,u16Rg);
873 #else
874     HALEMM_DBG(EMM_DBGLV_INFO, "HAL_EMMFLT_PacketAct = %x\n",connection);
875     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_INT_STAT,EMM_RECIEVE_ACT);
876     //HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CA_INT,(EMM_RECIEVE_ACT<<8) + 0x6);
877 #endif
878 
879     //MS_U16 u16Data;
880     //MsOS_DelayTaskUs(10);
881 
882     //u16Data = HAL_EMMFLT_ReadReg_Word(REG_EMM_INT_STAT);
883 
884     //HALEMM_DBG(0, "HAL_EMMFLT_PacketAct = %x\n",u16Data);
885 
886     return TRUE;
887 }
888 
889 
HAL_EMMFLT_IntCtrl(MS_U8 u8En)890 MS_U32 HAL_EMMFLT_IntCtrl(MS_U8 u8En)
891 {
892     MS_U16 u16Data;
893 
894     HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_IntCtrl u8En = %x\n",u8En);
895 
896     u16Data = HAL_EMMFLT_ReadReg_Word(0,REG_EMM_CA_INT);
897 
898     if(1 == u8En ) //mask interrupt
899     {
900         u16Data &= (~EMM_RESET_INT);
901         u16Data &= ~(EMM_ONEPAKCET_INT | EMM_OVERFLOW_INT);
902     }
903     else //unmask interrupt....
904     {
905         u16Data &= (~EMM_RESET_INT);
906         u16Data |= (EMM_ONEPAKCET_INT | EMM_OVERFLOW_INT);
907     }
908 
909     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_CA_INT, u16Data);
910     return TRUE;
911 }
912 
913 
HAL_EMMFLT_SetDebugMode(MS_U16 u16Mode)914 MS_U32 HAL_EMMFLT_SetDebugMode(MS_U16 u16Mode)
915 {
916     MS_U16 u16Reg,u16I;
917 
918     for(u16I=0; u16I<EMMENG_NUMBER; u16I++)
919     {
920         u16Reg = HAL_EMMFLT_ReadReg_Word(u16I,REG_EMM_TS_IF2_CTRL);
921 
922         u16Reg &= ~(REG_EMM_DGB_SEL);
923         u16Reg |= (u16Mode<<8);
924 
925         u16Reg |= (0x1<<13);
926         HAL_EMMFLT_WriteReg_Word(u16I,REG_EMM_TS_IF2_CTRL, u16Reg);
927     }
928     return TRUE;
929 }
930 
HAL_EMMFLT_GetDebugStatus(MS_U32 * pRegValue)931 MS_U32 HAL_EMMFLT_GetDebugStatus(MS_U32 *pRegValue)
932 {
933     *pRegValue = HAL_EMMFLT_ReadReg_Dword(0,REG_EMM_TS_IF2_DEBUG_L);
934     return TRUE;
935 }
936 
937 
938 //#define PureFileInOut
939 
HAL_EMMFLT_GeneralCtrl(MS_U32 connection)940 MS_U32 HAL_EMMFLT_GeneralCtrl(MS_U32 connection)
941 {
942 
943 #if 0
944     u16Data = HAL_EMMFLT_ReadReg_Word(REG_EMM_STR2MIU_EN);
945     u16Data |= REG_STR2MIU_RST_WADR;
946 
947     HALEMM_DBG(0, "REG_EMM_STR2MIU_EN = %x\n",(u16Data | REG_STR2MIU_RST_WADR));
948 
949     HAL_EMMFLT_WriteReg_Word(REG_EMM_STR2MIU_EN, (u16Data | REG_STR2MIU_RST_WADR) );
950 
951     MsOS_DelayTaskUs(1);
952 
953     u16Data &= ~(REG_STR2MIU_RST_WADR);
954     HALEMM_DBG(0, "REG_EMM_STR2MIU_EN = %x\n",u16Data);
955     HAL_EMMFLT_WriteReg_Word(REG_EMM_STR2MIU_EN, u16Data);
956 #endif
957 
958 #ifdef PureFileInOut
959     MS_U16 u16Data;
960     u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_PID);
961     u16Data &= 0x3fff;
962     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, u16Data);
963 #endif
964 
965     //HAL_EMMFLT_WriteReg_Word(REG_EMM_GENERAL_CTRL_L, 0x0004);
966 
967 	/*	select parallel TS interface for TS interface 2 in emm_flt0
968 	select exteranl sync for ts_if2 in emm_flt0
969 	Set 1 to enable the patch of internal sync in ��tsif�� in emm_flt0
970 	set 1 to enable ts_if2 in emm_flt0		*/
971 	//HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_TS_IF2_CTRL, 0x80e1);
972 
973     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_GENERAL_CTRL_L, 0x0000);
974     HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_GENERAL_CTRL_H, 0x0010);	//Bit[23:20]: packet number enable bits for TS3-TS0
975 
976     HALEMM_DBG(EMM_DBGLV_ERR, "fire EMM filter\n");
977 
978     return TRUE;
979 }
980 
HAL_EMMFLT_ConnectCheck(MS_U32 connection)981 MS_U32 HAL_EMMFLT_ConnectCheck(MS_U32 connection)
982 {
983 
984     ConnectionCheck(connection);
985     return TRUE;
986 }
987 
HAL_EMMFLT_HWSimulation(void)988 MS_U32 HAL_EMMFLT_HWSimulation(void)
989 {
990     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_GENERAL_CTRL_L, 0x0004);
991     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_GENERAL_CTRL_H, 0x0010);
992 
993     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_CA_INT, 0x0006);
994     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_TS_IF2_CTRL, 0x80e1);
995 
996     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_PID, 0xC000);
997     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_TID, 0x0000);
998 
999     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_TID_MODE_L, 0xFFFF);
1000     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_TID_MODE_H, 0x0000);
1001 
1002     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_EN, 0x0002); //string 2 miu enable
1003 
1004     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_HEAD1_L, 0x0000);
1005     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_HEAD1_H, 0x0000);
1006 
1007     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_TAIL1_L, 0x006C);
1008     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_TAIL1_H, 0x0000);
1009 
1010     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_MID1_L, 0x0010);
1011     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_MID1_H, 0x0000);
1012 
1013 
1014     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_HEAD2_L, 0x1000);
1015     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_HEAD2_H, 0x0000);
1016 
1017     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_TAIL2_L, 0x106C);
1018     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_TAIL2_H, 0x0000);
1019 
1020     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_MID2_L, 0x1010);
1021     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_STR2MIU_MID2_H, 0x0000);
1022 
1023     return TRUE;
1024 }
1025 
HAL_EMMFLT_IntStatusTest(void)1026 void HAL_EMMFLT_IntStatusTest(void)
1027 {
1028     MS_U16 CA_INT, INT_STAT;
1029 
1030     CA_INT = HAL_EMMFLT_ReadReg_Word(0,REG_EMM_CA_INT);
1031     HALEMM_DBG(EMM_DBGLV_INFO, "REG_EMM_CA_INT = %x\n",CA_INT);
1032 
1033     INT_STAT = HAL_EMMFLT_ReadReg_Word(0,REG_EMM_INT_STAT);
1034     HALEMM_DBG(EMM_DBGLV_INFO, "REG_EMM_INT_STAT = %x\n",INT_STAT);
1035 
1036 
1037     if(CA_INT == 0x2)
1038     {
1039         HAL_EMMFLT_WriteReg_Word(0,REG_EMM_INT_STAT,EMM_RECIEVE_ACT);
1040         HAL_EMMFLT_WriteReg_Word(0,REG_EMM_CA_INT,(EMM_RECIEVE_ACT<<8) + 0x6);
1041     }
1042     else if(CA_INT == 0x6)
1043     {
1044         HALEMM_DBG(EMM_DBGLV_INFO, "Buffer overflow\n");
1045     }
1046 
1047 }
1048 
HAL_EMMFLT_SetExtendConfig(MS_U32 x_connection,MS_U16 type,MS_U16 extendbytes,MS_U16 syncbyte)1049 MS_U32 HAL_EMMFLT_SetExtendConfig(MS_U32 x_connection, MS_U16 type, MS_U16 extendbytes, MS_U16 syncbyte)
1050 {
1051     MS_U16 Reg;
1052 
1053     Reg = 0x204;
1054     Reg = (Reg&(~0x1f0)) | ((extendbytes&0x1f)<<4);
1055     printf("EMM HW Config 0 is %x\n",Reg);
1056     HAL_EMMFLT_WriteReg_Word(x_connection,REG_EMM_HW_CONFIG0, 0x02C4);
1057 
1058 
1059     Reg = HAL_EMMFLT_ReadReg_Word(x_connection,REG_EMM_SYNC_BYTES);
1060 
1061     Reg = ((extendbytes + 188)<<0x8) | (syncbyte&0xff);
1062     printf("sync byte reg is %x\n",Reg);
1063     HAL_EMMFLT_WriteReg_Word(x_connection,REG_EMM_SYNC_BYTES, Reg);
1064 
1065     return TRUE;
1066 }
1067 
HAL_EMMFLT_Bypass(void)1068 MS_U32 HAL_EMMFLT_Bypass(void)
1069 {
1070     MS_U16 Reg;
1071     Reg = HAL_EMMFLT_ReadReg_Word(0,REG_EMM_CTRL0_L);
1072     HAL_EMMFLT_WriteReg_Word(0,REG_EMM_CTRL0_L, (Reg | EMM_FLT_BYPASS) );
1073 
1074     return TRUE;
1075 }
1076 
HAL_EMMFLT_En192Output(MS_U32 x_connection)1077 MS_U32 HAL_EMMFLT_En192Output(MS_U32 x_connection)
1078 {
1079     MS_U16 Reg;
1080 
1081     Reg = HAL_EMMFLT_ReadReg_Word(x_connection,REG_EMM_CTRL0_L);
1082     HAL_EMMFLT_WriteReg_Word(x_connection,REG_EMM_CTRL0_L, (Reg & ~(EMM_PACKET256_EN | EMM_PVR_EN)) );
1083 
1084     Reg = HAL_EMMFLT_ReadReg_Word(x_connection,REG_EMM_STR2MIU_CTRL);
1085     HAL_EMMFLT_WriteReg_Word(x_connection,REG_EMM_STR2MIU_CTRL, (Reg | REG_PKT192_EN) );
1086 
1087     return TRUE;
1088 }
1089 
HAL_EMMFLT_InputMode(MS_U32 x_connection,MS_BOOL bSerial)1090 MS_U32 HAL_EMMFLT_InputMode(MS_U32 x_connection, MS_BOOL bSerial)
1091 {
1092     MS_U16 Reg_TS_IF2_CTRL = 0, Reg_STR2MIU_CTRL = 0;
1093 
1094     Reg_TS_IF2_CTRL = HAL_EMMFLT_ReadReg_Word(x_connection, REG_EMM_TS_IF2_CTRL );
1095     Reg_TS_IF2_CTRL &= ~(REG_SIM_C0_CONFIG | REG_SIM_C1_CONFIG | REG_P_SEL2 | REG_EXT_SYNC_SEL2 | REG_SERIAL_EXT_SYNC_1T); // bit 2,3,5,6,12
1096 
1097     Reg_STR2MIU_CTRL = HAL_EMMFLT_ReadReg_Word(x_connection, REG_EMM_STR2MIU_CTRL );
1098 
1099     if( bSerial == TRUE ) //input with serial mode....
1100     {
1101         Reg_TS_IF2_CTRL |= (REG_SIM_C0_CONFIG | REG_SIM_C1_CONFIG | REG_EXT_SYNC_SEL2 | REG_SERIAL_EXT_SYNC_1T);  // bit[3..2]=11, bit[6..5]=10,bit[12]=1
1102         Reg_STR2MIU_CTRL |= REG_RECORD_AT_SYNC_DIS;  // bit[10]=1
1103     }
1104     else  //input with parallel mode....
1105     {
1106         Reg_TS_IF2_CTRL |= (REG_P_SEL2 | REG_EXT_SYNC_SEL2);  // bit[3..2]=00, bit[6..5]=11,bit[12]=0
1107         Reg_STR2MIU_CTRL &= ~(REG_RECORD_AT_SYNC_DIS);  // bit[10]=0
1108     }
1109 
1110     HAL_EMMFLT_WriteReg_Word( x_connection, REG_EMM_TS_IF2_CTRL, Reg_TS_IF2_CTRL );
1111     HAL_EMMFLT_WriteReg_Word( x_connection, REG_EMM_STR2MIU_CTRL, Reg_STR2MIU_CTRL );
1112     return TRUE;
1113 }
1114 
1115