// //****************************************************************************** // MStar Software // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. // All software, firmware and related documentation herein ("MStar Software") are // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by // law, including, but not limited to, copyright law and international treaties. // Any use, modification, reproduction, retransmission, or republication of all // or part of MStar Software is expressly prohibited, unless prior written // permission has been granted by MStar. // // By accessing, browsing and/or using MStar Software, you acknowledge that you // have read, understood, and agree, to be bound by below terms ("Terms") and to // comply with all applicable laws and regulations: // // 1. MStar shall retain any and all right, ownership and interest to MStar // Software and any modification/derivatives thereof. // No right, ownership, or interest to MStar Software and any // modification/derivatives thereof is transferred to you under Terms. // // 2. You understand that MStar Software might include, incorporate or be // supplied together with third party`s software and the use of MStar // Software may require additional licenses from third parties. // Therefore, you hereby agree it is your sole responsibility to separately // obtain any and all third party right and license necessary for your use of // such third party`s software. // // 3. MStar Software and any modification/derivatives thereof shall be deemed as // MStar`s confidential information and you agree to keep MStar`s // confidential information in strictest confidence and not disclose to any // third party. // // 4. MStar Software is provided on an "AS IS" basis without warranties of any // kind. Any warranties are hereby expressly disclaimed by MStar, including // without limitation, any warranties of merchantability, non-infringement of // intellectual property rights, fitness for a particular purpose, error free // and in conformity with any international standard. You agree to waive any // claim against MStar for any loss, damage, cost or expense that you may // incur related to your use of MStar Software. // In no event shall MStar be liable for any direct, indirect, incidental or // consequential damages, including without limitation, lost of profit or // revenues, lost or damage of data, and unauthorized system use. // You agree that this Section 4 shall still apply without being affected // even if MStar Software has been modified by MStar in accordance with your // request or instruction for your use, except otherwise agreed by both // parties in writing. // // 5. If requested, MStar may from time to time provide technical supports or // services in relation with MStar Software to you for your use of // MStar Software in conjunction with your or your customer`s product // ("Services"). // You understand and agree that, except otherwise agreed by both parties in // writing, Services are provided on an "AS IS" basis and the warranty // disclaimer set forth in Section 4 above shall apply. // // 6. Nothing contained herein shall be construed as by implication, estoppels // or otherwise: // (a) conferring any license or right to use MStar name, trademark, service // mark, symbol or any other identification; // (b) obligating MStar or any of its affiliates to furnish any person, // including without limitation, you and your customers, any assistance // of any kind whatsoever, or any information; or // (c) conferring any license or right under any intellectual property right. // // 7. These terms shall be governed by and construed in accordance with the laws // of Taiwan, R.O.C., excluding its conflict of law rules. // Any and all dispute arising out hereof or related hereto shall be finally // settled by arbitration referred to the Chinese Arbitration Association, // Taipei in accordance with the ROC Arbitration Law and the Arbitration // Rules of the Association by three (3) arbitrators appointed in accordance // with the said Rules. // The place of arbitration shall be in Taipei, Taiwan and the language shall // be English. // The arbitration award shall be final and binding to both parties. // //****************************************************************************** // //////////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2008-2009 MStar Semiconductor, Inc. // All rights reserved. // // Unless otherwise stipulated in writing, any and all information contained // herein regardless in any format shall remain the sole proprietary of // MStar Semiconductor Inc. and be kept in strict confidence // ("MStar Confidential Information") by the recipient. // Any unauthorized act including without limitation unauthorized disclosure, // copying, use, reproduction, sale, distribution, modification, disassembling, // reverse engineering and compiling of the contents of MStar Confidential // Information is unlawful and strictly prohibited. MStar hereby reserves the // rights to any and all damages, losses, costs and expenses resulting therefrom. //////////////////////////////////////////////////////////////////////////////// #define _HAL_EMMFLT_C //////////////////////////////////////////////////////////////////////////////// /// @file halEMMflt.c /// @author MStar Semiconductor Inc. /// @brief //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Header Files //////////////////////////////////////////////////////////////////////////////// #include "MsCommon.h" #include "MsTypes.h" #include "drvEMMFlt.h" #include "halEMMflt.h" #include "regEMMflt.h" #include "../../include/drvNSK2Type.h" #include "MsIRQ.h" //////////////////////////////////////////////////////////////////////////////// // Define & data type /////////////////////////////////////////////////////////////////////////////// //0x113c for emm filter.. //0x100B #define CLKGEN0_REG(addr) (*((volatile MS_U16*)(_gCLKGEN0_Addr + ((addr)<<2)))) //0x100A #define CLKGEN2_REG(addr) (*((volatile MS_U16*)(_gCLKGEN2_Addr + ((addr)<<2)))) //bank 0x101E #define CHIP_REG(addr) (*((volatile MS_U16*)(_gCHIPTOP_Addr + ((addr)<<2)))) //bank 0x1137 #define PVR0_REG(addr) (*((volatile MS_U16*)(_gPVR0_Addr + ((addr)<<2)))) //bank 0x19xx #define OTP_REG(addr) (*((volatile MS_U32*)(_gOTP_Addr + addr ))) //bank 0x1713 #define OTP_CTRL_REG(addr) (*((volatile MS_U32*)(_gOTP_CTRL_Addr + (addr<<2) ))) #define EMM_IRQ_INT E_INT_FIQ_TSP_SPARE_CA2PM_8 static MS_U32 _g32EMMHalDbgLv = EMM_DBGLV_INFO; #define HALEMM_DBG(lv, x, args...) if (lv <= _g32EMMHalDbgLv ) \ {printf(x, ##args);} #define ConnectionCheck(x) { if(x>EMMENG_NUMBER) \ { printf("only one emm allow\n"); \ return FALSE;} } //////////////////////////////////////////////////////////////////////////////// // Local variable //////////////////////////////////////////////////////////////////////////////// //static MS_U32 _gEMMflt_BankAddr = 0; static MS_U32 _gEMMflt_Addr[EMMENG_NUMBER]; static MS_U32 _gBasicAddr = 0; static MS_U32 _gOTP_Addr = 0; static MS_U32 _gOTP_CTRL_Addr = 0; static MS_U32 _gPVR0_Addr = 0; static MS_U32 _gCLKGEN0_Addr = 0; static MS_U32 _gCLKGEN2_Addr = 0; static MS_U32 _gCHIPTOP_Addr = 0; //////////////////////////////////////////////////////////////////////////////// // Global variable //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Extern Function //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Function Declaration //////////////////////////////////////////////////////////////////////////////// void PrintSetting(void); //////////////////////////////////////////////////////////////////////////////// // Local Function //////////////////////////////////////////////////////////////////////////////// static void HAL_EMMFLT_WriteReg_Word(MS_U32 connection, MS_U32 u32RegAddr, MS_U16 u16Data) { MS_U32 u32reg; u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection]; (*(volatile MS_U16*)(u32reg)) = u16Data; } static MS_U16 HAL_EMMFLT_ReadReg_Word(MS_U32 connection, MS_U32 u32RegAddr) { MS_U32 u32reg; MS_U16 u16Data; u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection]; u16Data = (*(volatile MS_U16*)(u32reg)); return u16Data; } static void HAL_EMMFLT_WriteReg_Dword(MS_U32 connection, MS_U32 u32RegAddr, MS_U32 u32Data) { MS_U32 u32reg; u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection]; (*(volatile MS_U16*)(u32reg)) = (MS_U16)(u32Data&0xffff); u32reg += 4; (*(volatile MS_U16*)(u32reg)) = (MS_U16)((u32Data>>16)&0xffff); } static MS_U32 HAL_EMMFLT_ReadReg_Dword(MS_U32 connection, MS_U32 u32RegAddr) { MS_U32 u32reg,u32Data; MS_U16 u16Data1,u16Data2; u32reg = (u32RegAddr*4) + _gEMMflt_Addr[connection]; u16Data1 = (*(volatile MS_U16*)(u32reg)); u32reg += 4; u16Data2 = (*(volatile MS_U16*)(u32reg)); u32Data = (u16Data1) + ((MS_U32)u16Data2<<16); return u32Data; } //////////////////////////////////////////////////////////////////////////////// // Global Function //////////////////////////////////////////////////////////////////////////////// void HAL_EMMFLT_SetBank(MS_U32 u32Base) { MS_U16 u16I,u16J; MS_U16 u16Data; HALEMM_DBG(EMM_DBGLV_INFO, "%s: u32Base = 0x%x\n", __FUNCTION__, u32Base); _gBasicAddr = u32Base; _gEMMflt_Addr[0] = _gBasicAddr + REG_EMMFLT_BASE1; _gEMMflt_Addr[1] = _gBasicAddr + REG_EMMFLT_BASE2; _gOTP_Addr = _gBasicAddr + REG_OTP_BASE; _gOTP_CTRL_Addr = _gBasicAddr + REG_OTP_CTRL_BASE; _gPVR0_Addr = _gBasicAddr + REG_PVR0_BASE; _gCHIPTOP_Addr= _gBasicAddr + REG_CHIPTOP_BASE; _gCLKGEN0_Addr= _gBasicAddr + REG_CLKGEN0_BASE; _gCLKGEN2_Addr= _gBasicAddr + REG_CLKGEN2_BASE; HALEMM_DBG(EMM_DBGLV_INFO,"_gBasicAddr = %x, _gEMMflt_Addr[0] = %x, _gEMMflt_Addr[1] = %x\n",_gBasicAddr,_gEMMflt_Addr[0],_gEMMflt_Addr[1]); HALEMM_DBG(EMM_DBGLV_INFO,"_gCHIPTOP_Addr = %x, _gCLKGEN0_Addr = %x\n",_gCHIPTOP_Addr,_gCLKGEN0_Addr); HALEMM_DBG(EMM_DBGLV_INFO,"int ctrl addr = %x\n", (_gBasicAddr+ (0x101900<<1) )); for( u16J=0; u16J REG_EMM_CTRL_MAX) { return HAL_EMMFLT_INVALID_REQUEST; } if(u8IRDNum > REG_EMM_IRD_MAX) { return HAL_EMMFLT_INVALID_REQUEST; } HALEMM_DBG(EMM_DBGLV_INFO, "%s u8IRDNum= %d, u8CompareMode = %d\n", __FUNCTION__, u8IRDNum, u8CompareMode ); u16Mask = (EMM_IRD_REG_MASK << (u8IRDNum*2)); u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_CTRL_ID); HALEMM_DBG(EMM_DBGLV_INFO, "REG_EMM_CTRL_ID = %x\n",u16Data); u16Data &= ~u16Mask; u16Data |= (u8CompareMode << (u8IRDNum*2)); HALEMM_DBG(EMM_DBGLV_INFO, "%s u16Data= %x \n", __FUNCTION__, u16Data); HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CTRL_ID, u16Data); return TRUE; } MS_U32 HAL_EMMFLT_SetEmmDataIDx(MS_U32 connection, MS_U8 u8IRDNum, MS_U8 *pu8Data) { MS_U32 u32IRDAddr,u32EMMAddr; MS_U32 u32Mapping[] = {REG_EMM_DATA_ID1_L, REG_EMM_DATA_ID2_L, REG_EMM_DATA_ID3_L, REG_EMM_DATA_ID4_L, REG_EMM_DATA_ID5_L, REG_EMM_DATA_ID6_L, REG_EMM_DATA_ID7_L, REG_EMM_DATA_ID8_L, }; ConnectionCheck(connection); u32EMMAddr = ((MS_U32)pu8Data[0]<<24) + ((MS_U32)pu8Data[1]<<16) + ((MS_U32)pu8Data[2]<<8) + ((MS_U32)pu8Data[3]) ; HALEMM_DBG(EMM_DBGLV_INFO, "%s u8IRDNum= %x, u32EMMAddr = %x\n", __FUNCTION__, u8IRDNum, u32EMMAddr); if(u8IRDNum >= REG_EMM_IRD_MAX) { return HAL_EMMFLT_INVALID_REQUEST; } u32IRDAddr = u32Mapping[u8IRDNum]; HAL_EMMFLT_WriteReg_Dword(connection,u32IRDAddr,u32EMMAddr); return TRUE; } MS_U32 HAL_EMMFLT_SetEmmMaskIDx(MS_U32 connection,MS_U8 u8IRDNum, MS_U8 *pu8Data) { MS_U32 u32IRDAddr,u32EMMMask; MS_U32 u32Mapping[] = {REG_EMM_MASK_ID1_L, REG_EMM_MASK_ID2_L, REG_EMM_MASK_ID3_L, REG_EMM_MASK_ID4_L, REG_EMM_MASK_ID5_L, REG_EMM_MASK_ID6_L, REG_EMM_MASK_ID7_L, REG_EMM_MASK_ID8_L, }; ConnectionCheck(connection); u32EMMMask = ((MS_U32)pu8Data[0]<<24) + ((MS_U32)pu8Data[1]<<16) + ((MS_U32)pu8Data[2]<<8) + ((MS_U32)pu8Data[3]) ; HALEMM_DBG(EMM_DBGLV_INFO, "%s u8IRDNum= %x, u32EMMMask = %x\n", __FUNCTION__, u8IRDNum, u32EMMMask); if(u8IRDNum >= REG_EMM_IRD_MAX) { return HAL_EMMFLT_INVALID_REQUEST; } u32IRDAddr = u32Mapping[u8IRDNum]; HAL_EMMFLT_WriteReg_Dword(connection,u32IRDAddr,u32EMMMask); return TRUE; } MS_U32 HAL_EMMFLT_DisableEMM(MS_U32 connection) { ConnectionCheck(connection); HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, 0); return TRUE; } MS_U32 HAL_EMMFLT_SetEmmPID(MS_U32 connection,MS_U16 u16EmmPID) { MS_U16 u16Data; HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_SetEmmPID conn = %x, u16EmmPID = %x \n",connection,u16EmmPID); PrintSetting(); ConnectionCheck(connection); #if 1 u16Data = 0; u16Data = u16EmmPID; #else u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_PID); u16Data = ( u16Data & ~(REG_EMM_ENABLE_TID | REG_EMM_ENABLE_PID) ) | u16EmmPID; #endif HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, u16Data); return TRUE; } MS_U32 HAL_EMMFLT_SetEmmTID(MS_U32 connection,MS_U16 u16EmmTID) { HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_SetEmmTID conn = %x, u16EmmTID = %x \n",connection,u16EmmTID); ConnectionCheck(connection); HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_TID, u16EmmTID); return TRUE; } MS_U32 HAL_EMMFLT_EnableEmmTID(MS_U32 connection, MS_BOOL bEnable) { MS_U16 u16Data; HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_EnableEmmTID conn = %x, bEnable = %x \n",connection,bEnable); ConnectionCheck(connection); u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_PID); if(TRUE == bEnable) { u16Data |= REG_EMM_ENABLE_TID; } else { u16Data &= (~REG_EMM_ENABLE_TID); } HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_PID, u16Data); return TRUE; } MS_U32 HAL_EMMFLT_ResetInt(MS_U32 connection) { MS_U16 u16Data; HALEMM_DBG(EMM_DBGLV_ERR, "EMMFLT_ResetInt conn = %x\n",connection); u16Data = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_CA_INT); u16Data |= EMM_RESET_INT; HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CA_INT, u16Data); return TRUE; } #if 0 MS_U32 HAL_EMMFLT_GetIntReg(MS_U16 *pu16Data) { MS_U16 u16Data = 0,u16I; *pu16Data = 0; for( u16I=0 ; u16I>8); HALEMM_DBG(EMM_DBGLV_INFO, "current index = %x\n",index); return index; } MS_U32 HAL_EMMFLT_ReqDstBufSize(MS_U32 *p32DstBufSize, MS_U32 *p32AlignBytes, MS_U8 *p8BufBum) { *p32DstBufSize = EMMFLT_HWBUF_SIZE; *p32AlignBytes = EMMFLT_BUF_ALIGNMENT; *p8BufBum = EMMENG_NUMBER; HALEMM_DBG(EMM_DBGLV_INFO, "ReqDstBufSize HWBUF_SIZE = %x, BUF_ALIGNMENT = %x, EMMENG_NUMBER = %x\n",EMMFLT_HWBUF_SIZE, EMMFLT_BUF_ALIGNMENT,EMMENG_NUMBER); return TRUE; } MS_U32 HAL_EMMFLT_SetDstBufInfo(MS_U32 connection, MS_U32 u32BufAddr, MS_U32 u32BufSize, MS_U32 *p32BufAddrs) { MS_U32 u32I; MS_U16 u16Reg; ConnectionCheck(connection); HALEMM_DBG(EMM_DBGLV_INFO, "%s u32BufAddr= %x, u32BufSize= %x \n", __FUNCTION__, u32BufAddr,u32BufSize); HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_STR2MIU_HEAD1_L, (u32BufAddr>>4)); HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_STR2MIU_TAIL1_L, ((u32BufAddr+u32BufSize)>>4)); HAL_EMMFLT_WriteReg_Dword(connection,REG_EMM_STR2MIU_MID1_L, ((u32BufAddr+u32BufSize)>>4)); u16Reg = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_STR2MIU_EN); HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_STR2MIU_EN, (u16Reg | 0x4) ); HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_STR2MIU_EN,u16Reg); for(u32I = 0; u32I>8)&0xff); return TRUE; } //does connection needs to be increased. MS_U32 HAL_EMMFLT_PacketAct(MS_U32 connection) { #if 0 MS_U16 u16Rg; u16Rg = HAL_EMMFLT_ReadReg_Word(connection,REG_EMM_CA_INT); u16Rg = (0x10<<8); HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CA_INT,u16Rg); #else HALEMM_DBG(EMM_DBGLV_INFO, "HAL_EMMFLT_PacketAct = %x\n",connection); HAL_EMMFLT_WriteReg_Word(0,REG_EMM_INT_STAT,EMM_RECIEVE_ACT); //HAL_EMMFLT_WriteReg_Word(connection,REG_EMM_CA_INT,(EMM_RECIEVE_ACT<<8) + 0x6); #endif //MS_U16 u16Data; //MsOS_DelayTaskUs(10); //u16Data = HAL_EMMFLT_ReadReg_Word(REG_EMM_INT_STAT); //HALEMM_DBG(0, "HAL_EMMFLT_PacketAct = %x\n",u16Data); return TRUE; } MS_U32 HAL_EMMFLT_IntCtrl(MS_U8 u8En) { MS_U16 u16Data; HALEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_IntCtrl u8En = %x\n",u8En); u16Data = HAL_EMMFLT_ReadReg_Word(0,REG_EMM_CA_INT); if(1 == u8En ) //mask interrupt { u16Data &= (~EMM_RESET_INT); u16Data &= ~(EMM_ONEPAKCET_INT | EMM_OVERFLOW_INT); } else //unmask interrupt.... { u16Data &= (~EMM_RESET_INT); u16Data |= (EMM_ONEPAKCET_INT | EMM_OVERFLOW_INT); } HAL_EMMFLT_WriteReg_Word(0,REG_EMM_CA_INT, u16Data); return TRUE; } MS_U32 HAL_EMMFLT_SetDebugMode(MS_U16 u16Mode) { MS_U16 u16Reg,u16I; for(u16I=0; u16I