net: wireless: rockchip: add rtl8822be pcie wifi driver
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8822be / hal / btc / halbtc8723a1ant.c
diff --git a/drivers/net/wireless/rockchip_wlan/rtl8822be/hal/btc/halbtc8723a1ant.c b/drivers/net/wireless/rockchip_wlan/rtl8822be/hal/btc/halbtc8723a1ant.c
new file mode 100644 (file)
index 0000000..db5b42e
--- /dev/null
@@ -0,0 +1,1544 @@
+//============================================================\r
+// Description:\r
+//\r
+// This file is for RTL8723A Co-exist mechanism\r
+//\r
+// History\r
+// 2012/08/22 Cosa first check in.\r
+// 2012/11/14 Cosa Revise for 8723A 1Ant out sourcing.\r
+//\r
+//============================================================\r
+\r
+//============================================================\r
+// include files\r
+//============================================================\r
+#include "Mp_Precomp.h"\r
+\r
+#if WPP_SOFTWARE_TRACE\r
+#include "HalBtc8723a1Ant.tmh"\r
+#endif\r
+\r
+#if(BT_30_SUPPORT == 1)\r
+//============================================================\r
+// Global variables, these are static variables\r
+//============================================================\r
+static COEX_DM_8723A_1ANT      GLCoexDm8723a1Ant;\r
+static PCOEX_DM_8723A_1ANT     pCoexDm=&GLCoexDm8723a1Ant;\r
+static COEX_STA_8723A_1ANT     GLCoexSta8723a1Ant;\r
+static PCOEX_STA_8723A_1ANT    pCoexSta=&GLCoexSta8723a1Ant;\r
+\r
+const char *const GLBtInfoSrc8723a1Ant[]={\r
+       "BT Info[wifi fw]",\r
+       "BT Info[bt rsp]",\r
+       "BT Info[bt auto report]",\r
+};\r
+\r
+//============================================================\r
+// local function proto type if needed\r
+//============================================================\r
+//============================================================\r
+// local function start with halbtc8723a1ant_\r
+//============================================================\r
+VOID\r
+halbtc8723a1ant_Reg0x550Bit3(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bSet\r
+       )\r
+{\r
+       u1Byte  u1tmp=0;\r
+       \r
+       u1tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x550);\r
+       if(bSet)\r
+       {\r
+               u1tmp |= BIT3;\r
+       }\r
+       else\r
+       {\r
+               u1tmp &= ~BIT3;\r
+       }\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x550, u1tmp);\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set 0x550[3]=%d\n", (bSet? 1:0)));\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_NotifyFwScan(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  scanType\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[1] ={0};\r
+       \r
+       if(BTC_SCAN_START == scanType)\r
+               H2C_Parameter[0] = 0x1;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b=0x%x\n", \r
+               H2C_Parameter[0]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3b, 1, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_QueryBtInfo(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[1] ={0};\r
+\r
+       pCoexSta->bC2hBtInfoReqSent = TRUE;\r
+\r
+       H2C_Parameter[0] |= BIT0;       // trigger\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x38=0x%x\n", \r
+               H2C_Parameter[0]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x38, 1, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_SetSwRfRxLpfCorner(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bRxRfShrinkOn\r
+       )\r
+{\r
+       if(bRxRfShrinkOn)\r
+       {\r
+               //Shrink RF Rx LPF corner\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
+               pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xf0ff7);\r
+       }\r
+       else\r
+       {\r
+               //Resume RF Rx LPF corner\r
+               // After initialized, we can use pCoexDm->btRf0x1eBackup\r
+               if(pBtCoexist->bInitilized)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
+                       pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_RfShrink(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bRxRfShrinkOn\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
+               (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
+       pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
+                       return;\r
+       }\r
+       halbtc8723a1ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
+\r
+       pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bLowPenaltyRa\r
+       )\r
+{\r
+       u1Byte  tmpU1;\r
+\r
+       tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
+       tmpU1 |= BIT0;\r
+       if(bLowPenaltyRa)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
+               tmpU1 &= ~BIT2;\r
+       }\r
+       else\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
+               tmpU1 |= BIT2;\r
+       }\r
+\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_LowPenaltyRa(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bLowPenaltyRa\r
+       )\r
+{\r
+       return;\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
+               (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
+       pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
+                       return;\r
+       }\r
+       halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
+\r
+       pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_SetCoexTable(\r
+       IN      PBTC_COEXIST    pBtCoexist,\r
+       IN      u4Byte          val0x6c0,\r
+       IN      u4Byte          val0x6c8,\r
+       IN      u1Byte          val0x6cc\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_CoexTable(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      u4Byte                  val0x6c0,\r
+       IN      u4Byte                  val0x6c8,\r
+       IN      u1Byte                  val0x6cc\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
+               (bForceExec? "force to":""), val0x6c0, val0x6c8, val0x6cc));\r
+       pCoexDm->curVal0x6c0 = val0x6c0;\r
+       pCoexDm->curVal0x6c8 = val0x6c8;\r
+       pCoexDm->curVal0x6cc = val0x6cc;\r
+\r
+       if(!bForceExec)\r
+       {       \r
+               if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
+                       (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
+                       (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
+                       return;\r
+       }\r
+       halbtc8723a1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c8, val0x6cc);\r
+\r
+       pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
+       pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
+       pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_SetFwIgnoreWlanAct(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bEnable\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[1] ={0};\r
+               \r
+       if(bEnable)\r
+       {\r
+               H2C_Parameter[0] |= BIT0;               // function enable\r
+       }\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x25=0x%x\n", \r
+               H2C_Parameter[0]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x25, 1, H2C_Parameter);    \r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_IgnoreWlanAct(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bEnable\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
+               (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
+       pCoexDm->bCurIgnoreWlanAct = bEnable;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
+                       return;\r
+       }\r
+       halbtc8723a1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
+\r
+       pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_SetFwPstdma(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type,\r
+       IN      u1Byte                  byte1,\r
+       IN      u1Byte                  byte2,\r
+       IN      u1Byte                  byte3,\r
+       IN      u1Byte                  byte4,\r
+       IN      u1Byte                  byte5\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[5] ={0};\r
+       u1Byte                  realByte1=byte1, realByte5=byte5;\r
+       BOOLEAN                 bApEnable=FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
+\r
+       // byte1[1:0] != 0 means enable pstdma\r
+       // for 2Ant bt coexist, if byte1 != 0 means enable pstdma\r
+       if(byte1)\r
+       {\r
+               if(bApEnable)\r
+               {\r
+                       if(type != 5 && type != 12)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));\r
+                               realByte1 &= ~BIT4;\r
+                               realByte1 |= BIT5;\r
+\r
+                               realByte5 |= BIT5;\r
+                               realByte5 &= ~BIT6;\r
+                       }\r
+               }\r
+       }\r
+       H2C_Parameter[0] = realByte1;   \r
+       H2C_Parameter[1] = byte2;       \r
+       H2C_Parameter[2] = byte3;\r
+       H2C_Parameter[3] = byte4;\r
+       H2C_Parameter[4] = realByte5;\r
+\r
+       pCoexDm->psTdmaPara[0] = realByte1;\r
+       pCoexDm->psTdmaPara[1] = byte2;\r
+       pCoexDm->psTdmaPara[2] = byte3;\r
+       pCoexDm->psTdmaPara[3] = byte4;\r
+       pCoexDm->psTdmaPara[4] = realByte5;\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x3a(5bytes)=0x%x%08x\n", \r
+               H2C_Parameter[0], \r
+               H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3a, 5, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_PsTdma(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bTurnOn,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
+               (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));             \r
+       pCoexDm->bCurPsTdmaOn = bTurnOn;\r
+       pCoexDm->curPsTdma = type;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
+                       (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
+                       return;\r
+       }       \r
+       if(pCoexDm->bCurPsTdmaOn)\r
+       {\r
+               switch(pCoexDm->curPsTdma)\r
+               {\r
+                       case 1:\r
+                       default:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x1a, 0x1a, 0x0, 0x40);\r
+                               break;\r
+                       case 2:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x12, 0x12, 0x0, 0x40);\r
+                               break;\r
+                       case 3:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x3f, 0x3, 0x10, 0x40);\r
+                               break;\r
+                       case 4:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x15, 0x3, 0x10, 0x0);\r
+                               break;\r
+                       case 5:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0xa9, 0x15, 0x3, 0x35, 0xc0);\r
+                               break;\r
+                       \r
+                       case 8: \r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);\r
+                               break;\r
+                       case 9: \r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x0, 0x40);\r
+                               break;\r
+                       case 10:        \r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x0, 0x40);\r
+                               break;\r
+                       case 11:        \r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x0, 0x40);\r
+                               break;\r
+                       case 12:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0xa9, 0xa, 0x3, 0x15, 0xc0);\r
+                               break;\r
+       \r
+                       case 18:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);\r
+                               break;                  \r
+\r
+                       case 20:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x2a, 0x2a, 0x0, 0x0);\r
+                               break;\r
+                       case 21:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x20, 0x3, 0x10, 0x40);\r
+                               break;\r
+                       case 22:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x1a, 0x1a, 0x2, 0x40);\r
+                               break;\r
+                       case 23:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x12, 0x12, 0x2, 0x40);\r
+                               break;\r
+                       case 24:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x2, 0x40);\r
+                               break;\r
+                       case 25:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x2, 0x40);\r
+                               break;\r
+                       case 26:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);\r
+                               break;\r
+                       case 27:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x2, 0x40);\r
+                               break;\r
+                       case 28:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x3, 0x2f, 0x2f, 0x0, 0x0);\r
+                               break;\r
+\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // disable PS tdma\r
+               switch(pCoexDm->curPsTdma)\r
+               {\r
+                       case 8:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x8, 0x0, 0x0, 0x0, 0x0);         \r
+                               break;\r
+                       case 0:\r
+                       default:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x0, 0x0, 0x0, 0x0, 0x0);\r
+                               pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x210);\r
+                               break;\r
+                       case 9:\r
+                               halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x0, 0x0, 0x0, 0x0, 0x0);\r
+                               pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x110);\r
+                               break;\r
+\r
+               }\r
+       }\r
+\r
+       // update pre state\r
+       pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
+       pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
+}\r
+\r
+\r
+VOID\r
+halbtc8723a1ant_CoexAllOff(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       // fw all off\r
+       halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
+       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+\r
+       // sw all off\r
+       halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
+       halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
+\r
+       // hw all off\r
+       halbtc8723a1ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_InitCoexDm(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       // force to reset coex mechanism\r
+       halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_BtEnableAction(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_MonitorBtCtr(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
+       u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
+       u1Byte                  u1Tmp;\r
+       \r
+       regHPTxRx = 0x770;\r
+       regLPTxRx = 0x774;\r
+\r
+       u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
+       regHPTx = u4Tmp & bMaskLWord;\r
+       regHPRx = (u4Tmp & bMaskHWord)>>16;\r
+\r
+       u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
+       regLPTx = u4Tmp & bMaskLWord;\r
+       regLPRx = (u4Tmp & bMaskHWord)>>16;\r
+               \r
+       pCoexSta->highPriorityTx = regHPTx;\r
+       pCoexSta->highPriorityRx = regHPRx;\r
+       pCoexSta->lowPriorityTx = regLPTx;\r
+       pCoexSta->lowPriorityRx = regLPRx;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
+               regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
+               regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
+\r
+       // reset counter\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_MonitorBtEnableDisable(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       static BOOLEAN  bPreBtDisabled=FALSE;\r
+       static u4Byte   btDisableCnt=0;\r
+       BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
+\r
+       // This function check if bt is disabled\r
+       \r
+       if(     pCoexSta->highPriorityTx == 0 &&\r
+               pCoexSta->highPriorityRx == 0 &&\r
+               pCoexSta->lowPriorityTx == 0 &&\r
+               pCoexSta->lowPriorityRx == 0)\r
+       {\r
+               bBtActive = FALSE;\r
+       }\r
+       if(     pCoexSta->highPriorityTx == 0xffff &&\r
+               pCoexSta->highPriorityRx == 0xffff &&\r
+               pCoexSta->lowPriorityTx == 0xffff &&\r
+               pCoexSta->lowPriorityRx == 0xffff)\r
+       {\r
+               bBtActive = FALSE;\r
+       }\r
+       if(bBtActive)\r
+       {\r
+               btDisableCnt = 0;\r
+               bBtDisabled = FALSE;\r
+               pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));\r
+       }\r
+       else\r
+       {\r
+               btDisableCnt++;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n", \r
+                               btDisableCnt));\r
+               if(btDisableCnt >= 2)\r
+               {\r
+                       bBtDisabled = TRUE;\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));\r
+               }\r
+       }\r
+       if(bPreBtDisabled != bBtDisabled)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n", \r
+                       (bPreBtDisabled ? "disabled":"enabled"), \r
+                       (bBtDisabled ? "disabled":"enabled")));\r
+               bPreBtDisabled = bBtDisabled;\r
+               if(!bBtDisabled)\r
+               {\r
+                       halbtc8723a1ant_BtEnableAction(pBtCoexist);\r
+               }\r
+               else\r
+               {\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8723a1ant_TdmaDurationAdjust(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       static s4Byte           up,dn,m,n,WaitCount;\r
+       s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
+       u1Byte                  retryCount=0;\r
+       u1Byte                  btState;\r
+       BOOLEAN                 bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
+       u4Byte                  wifiBw;\r
+       \r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
+       btState = pCoexDm->btStatus;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], TdmaDurationAdjust()\n"));\r
+       if(pCoexDm->psTdmaGlobalCnt != pCoexDm->psTdmaMonitorCnt)\r
+       {\r
+               pCoexDm->psTdmaMonitorCnt = 0;\r
+               pCoexDm->psTdmaGlobalCnt = 0;\r
+       }\r
+       if(pCoexDm->psTdmaMonitorCnt == 0)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], first run BT A2DP + WiFi busy state!!\n"));\r
+               if(btState == BT_STATE_8723A_1ANT_ACL_ONLY_BUSY)\r
+               {\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
+                       pCoexDm->psTdmaDuAdjType = 1;\r
+               }\r
+               else\r
+               {\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
+                       pCoexDm->psTdmaDuAdjType = 22;\r
+               }\r
+               //============\r
+               up = 0;\r
+               dn = 0;\r
+               m = 1;\r
+               n= 3;\r
+               result = 0;\r
+               WaitCount = 0;\r
+       }\r
+       else\r
+       {\r
+               //accquire the BT TRx retry count from BT_Info byte2\r
+               retryCount = pCoexSta->btRetryCnt;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], retryCount = %d\n", retryCount));\r
+               result = 0;\r
+               WaitCount++; \r
+                 \r
+               if(retryCount == 0)  // no retry in the last 2-second duration\r
+               {\r
+                       up++;\r
+                       dn--;\r
+\r
+                       if (dn <= 0)\r
+                               dn = 0;                          \r
+\r
+                       if(up >= n) // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
+                       {\r
+                               WaitCount = 0; \r
+                               n = 3;\r
+                               up = 0;\r
+                               dn = 0;\r
+                               result = 1; \r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Increase wifi duration!!\n"));\r
+                       }\r
+               }\r
+               else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
+               {\r
+                       up--; \r
+                       dn++;\r
+\r
+                       if (up <= 0)\r
+                               up = 0;\r
+\r
+                       if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
+                       {\r
+                               if (WaitCount <= 2)\r
+                                       m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
+                               else\r
+                                       m = 1;\r
+\r
+                               if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
+                                       m = 20;\r
+\r
+                               n = 3*m;\r
+                               up = 0;\r
+                               dn = 0;\r
+                               WaitCount = 0;  \r
+                               result = -1; \r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
+                       }\r
+               }\r
+               else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
+               {\r
+                       if (WaitCount == 1)\r
+                               m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
+                       else\r
+                               m = 1;\r
+\r
+                       if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
+                               m = 20;\r
+\r
+                       n = 3*m;\r
+                       up = 0;\r
+                       dn = 0;\r
+                       WaitCount = 0; \r
+                       result = -1;\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
+               }\r
+               \r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT TxRx counter H+L <= 1200\n"));\r
+                       if(btState != BT_STATE_8723A_1ANT_ACL_ONLY_BUSY)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], NOT ACL only busy!\n"));\r
+                               if(BTC_WIFI_BW_HT40 != wifiBw)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 20MHz\n"));\r
+                                       if(result == -1)\r
+                                       {\r
+                                               if(pCoexDm->curPsTdma == 22)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
+                                                       pCoexDm->psTdmaDuAdjType = 23;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 23)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
+                                                       pCoexDm->psTdmaDuAdjType = 24;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 24)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);\r
+                                                       pCoexDm->psTdmaDuAdjType = 25;\r
+                                               }\r
+                                       } \r
+                                       else if (result == 1)\r
+                                       {\r
+                                               if(pCoexDm->curPsTdma == 25)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
+                                                       pCoexDm->psTdmaDuAdjType = 24;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 24)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
+                                                       pCoexDm->psTdmaDuAdjType = 23;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 23)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
+                                                       pCoexDm->psTdmaDuAdjType = 22;\r
+                                               }\r
+                                       }\r
+                                       // error handle, if not in the following state,\r
+                                       // set psTdma again.\r
+                                       if( (pCoexDm->psTdmaDuAdjType != 22) &&\r
+                                               (pCoexDm->psTdmaDuAdjType != 23) &&\r
+                                               (pCoexDm->psTdmaDuAdjType != 24) &&\r
+                                               (pCoexDm->psTdmaDuAdjType != 25) )\r
+                                       {\r
+                                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], duration case out of handle!!\n"));\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
+                                               pCoexDm->psTdmaDuAdjType = 23;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 40MHz\n"));\r
+                                       if(result == -1)\r
+                                       {\r
+                                               if(pCoexDm->curPsTdma == 23)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
+                                                       pCoexDm->psTdmaDuAdjType = 24;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 24)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);\r
+                                                       pCoexDm->psTdmaDuAdjType = 25;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 25)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 27);\r
+                                                       pCoexDm->psTdmaDuAdjType = 27;\r
+                                               }\r
+                                       } \r
+                                       else if (result == 1)\r
+                                       {\r
+                                               if(pCoexDm->curPsTdma == 27)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);\r
+                                                       pCoexDm->psTdmaDuAdjType = 25;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 25)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
+                                                       pCoexDm->psTdmaDuAdjType = 24;\r
+                                               }\r
+                                               else if(pCoexDm->curPsTdma == 24)\r
+                                               {\r
+                                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
+                                                       pCoexDm->psTdmaDuAdjType = 23;\r
+                                               }\r
+                                       }\r
+                                       // error handle, if not in the following state,\r
+                                       // set psTdma again.\r
+                                       if( (pCoexDm->psTdmaDuAdjType != 23) &&\r
+                                               (pCoexDm->psTdmaDuAdjType != 24) &&\r
+                                               (pCoexDm->psTdmaDuAdjType != 25) &&\r
+                                               (pCoexDm->psTdmaDuAdjType != 27) )\r
+                                       {\r
+                                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], duration case out of handle!!\n"));\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
+                                               pCoexDm->psTdmaDuAdjType = 24;\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ACL only busy\n"));\r
+                               if (result == -1)\r
+                               {\r
+                                       if(pCoexDm->curPsTdma == 1)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
+                                               pCoexDm->psTdmaDuAdjType = 2;\r
+                                       }\r
+                                       else if(pCoexDm->curPsTdma == 2)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                                               pCoexDm->psTdmaDuAdjType = 9;\r
+                                       }\r
+                                       else if(pCoexDm->curPsTdma == 9)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
+                                               pCoexDm->psTdmaDuAdjType = 11;\r
+                                       }\r
+                               }\r
+                               else if (result == 1)\r
+                               {\r
+                                       if(pCoexDm->curPsTdma == 11)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                                               pCoexDm->psTdmaDuAdjType = 9;\r
+                                       }\r
+                                       else if(pCoexDm->curPsTdma == 9)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
+                                               pCoexDm->psTdmaDuAdjType = 2;\r
+                                       }\r
+                                       else if(pCoexDm->curPsTdma == 2)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
+                                               pCoexDm->psTdmaDuAdjType = 1;\r
+                                       }\r
+                               }\r
+\r
+                               // error handle, if not in the following state,\r
+                               // set psTdma again.\r
+                               if( (pCoexDm->psTdmaDuAdjType != 1) &&\r
+                                       (pCoexDm->psTdmaDuAdjType != 2) &&\r
+                                       (pCoexDm->psTdmaDuAdjType != 9) &&\r
+                                       (pCoexDm->psTdmaDuAdjType != 11) )\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], duration case out of handle!!\n"));\r
+                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
+                                       pCoexDm->psTdmaDuAdjType = 2;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
+       // then we have to adjust it back to the previous record one.\r
+       if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
+                       pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
+\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
+\r
+               if( !bScan && !bLink && !bRoam)\r
+               {\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
+               }\r
+               else\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
+               }\r
+       }\r
+       pCoexDm->psTdmaMonitorCnt++;\r
+}\r
+\r
+\r
+VOID\r
+halbtc8723a1ant_CoexForWifiConnect(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       BOOLEAN         bWifiConnected=FALSE, bWifiBusy=FALSE;\r
+       u1Byte          btState, btInfoOriginal=0;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+\r
+       btState = pCoexDm->btStatus;\r
+       btInfoOriginal = pCoexSta->btInfoC2h[BT_INFO_SRC_8723A_1ANT_BT_RSP][0];\r
+\r
+       if(bWifiConnected)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi connected!!\n"));\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
+               \r
+               if( !bWifiBusy &&\r
+                       ((BT_STATE_8723A_1ANT_NO_CONNECTION == btState) ||\r
+                       (BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)) )\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], [Wifi is idle] or [Bt is non connected idle or Bt is connected idle]!!\n"));\r
+\r
+                       if(BT_STATE_8723A_1ANT_NO_CONNECTION == btState)\r
+                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);\r
+                       else if(BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)\r
+                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+\r
+                       pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);\r
+               }\r
+               else\r
+               {\r
+                       if( (BT_STATE_8723A_1ANT_SCO_ONLY_BUSY == btState) ||\r
+                               (BT_STATE_8723A_1ANT_ACL_SCO_BUSY == btState) ||\r
+                               (BT_STATE_8723A_1ANT_HID_BUSY == btState) ||\r
+                               (BT_STATE_8723A_1ANT_HID_SCO_BUSY == btState) )\r
+                       {\r
+                               pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0x60);\r
+                       }\r
+                       else\r
+                       {\r
+                               pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);\r
+                       }\r
+                       switch(btState)\r
+                       {\r
+                               case BT_STATE_8723A_1ANT_NO_CONNECTION:\r
+                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
+                                       break;\r
+                               case BT_STATE_8723A_1ANT_CONNECT_IDLE:\r
+                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
+                                       break;\r
+                               case BT_STATE_8723A_1ANT_INQ_OR_PAG:\r
+                                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
+                                       break;\r
+                               case BT_STATE_8723A_1ANT_SCO_ONLY_BUSY:\r
+                               case BT_STATE_8723A_1ANT_ACL_SCO_BUSY:\r
+                               case BT_STATE_8723A_1ANT_HID_BUSY:\r
+                               case BT_STATE_8723A_1ANT_HID_SCO_BUSY:\r
+                                       halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist);\r
+                                       break;\r
+                               case BT_STATE_8723A_1ANT_ACL_ONLY_BUSY:\r
+                                       if (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP)\r
+                                       {\r
+                                               halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist);\r
+                                       }\r
+                                       else if(btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP)\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
+                                       }\r
+                                       else if( (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP) &&\r
+                                                       (btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP) )\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
+                                       }\r
+                                       break;\r
+                               default:\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], error!!!, undefined case in halbtc8723a1ant_CoexForWifiConnect()!!\n"));\r
+                                       break;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is disconnected!!\n"));\r
+       }\r
+\r
+       pCoexDm->psTdmaGlobalCnt++;\r
+}\r
+\r
+//============================================================\r
+// work around function start with wa_halbtc8723a1ant_\r
+//============================================================\r
+VOID\r
+wa_halbtc8723a1ant_MonitorC2h(\r
+       IN      PBTC_COEXIST                    pBtCoexist\r
+       )\r
+{\r
+       u1Byte  tmp1b=0x0;\r
+       u4Byte  curC2hTotalCnt=0x0;\r
+       static u4Byte   preC2hTotalCnt=0x0, sameCntPollingTime=0x0;\r
+\r
+       curC2hTotalCnt+=pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8723A_1ANT_BT_RSP];\r
+\r
+       if(curC2hTotalCnt == preC2hTotalCnt)\r
+       {\r
+               sameCntPollingTime++;\r
+       }\r
+       else\r
+       {\r
+               preC2hTotalCnt = curC2hTotalCnt;\r
+               sameCntPollingTime = 0;\r
+       }\r
+\r
+       if(sameCntPollingTime >= 2)\r
+       {\r
+               tmp1b = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x1af);\r
+               if(tmp1b != 0x0)\r
+               {\r
+                       pCoexSta->c2hHangDetectCnt++;\r
+                       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x1af, 0x0);\r
+               }\r
+       }\r
+}\r
+\r
+//============================================================\r
+// extern function start with EXhalbtc8723a1ant_\r
+//============================================================\r
+VOID\r
+EXhalbtc8723a1ant_InitHwConfig(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
+\r
+       // backup rf 0x1e value\r
+       pCoexDm->btRf0x1eBackup = \r
+               pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);\r
+\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
+\r
+       // enable counter statistics\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
+       \r
+       // coex table\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, 0x0);                     // 1-Ant coex\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, 0xffff);          // wifi break table\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, 0x55555555);      //coex table\r
+\r
+       // antenna switch control parameter\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x858, 0xaaaaaaaa);\r
+       \r
+       pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x210);   //set antenna at wifi side if ANTSW is software control\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x870, 0x300);   //SPDT(connected with TRSW) control by hardware PTA\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x874, 0x22804000);      //ANTSW keep by GNT_BT\r
+\r
+       // coexistence parameters\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);     // enable RTK mode PTA\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_InitCoexDm(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));\r
+       \r
+       halbtc8723a1ant_InitCoexDm(pBtCoexist);\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_DisplayCoexInfo(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
+       PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
+       pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
+       u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
+       u4Byte                          u4Tmp[4];\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
+               pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
+       CL_PRINTF(cliBuf);      \r
+       \r
+       if(pBtCoexist->bManualControl)\r
+       {\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");\r
+               CL_PRINTF(cliBuf);\r
+       }\r
+       \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
+               ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
+               pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
+               pCoexDm->wifiChnlInfo[2]);\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       // wifi status\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
+       CL_PRINTF(cliBuf);\r
+       pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
+               ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723A_1ANT_BT_STATUS_IDLE == pCoexDm->btStatus)? "idle":(  (BT_8723A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy"))),\r
+               pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       if(pStackInfo->bProfileNotified)\r
+       {                       \r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
+                       pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
+               CL_PRINTF(cliBuf);      \r
+\r
+               pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
+       }\r
+\r
+       btInfoExt = pCoexSta->btInfoExt;\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
+               (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
+       CL_PRINTF(cliBuf);      \r
+\r
+       for(i=0; i<BT_INFO_SRC_8723A_1ANT_MAX; i++)\r
+       {\r
+               if(pCoexSta->btInfoC2hCnt[i])\r
+               {                               \r
+                       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723a1Ant[i], \\r
+                               pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
+                               pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
+                               pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
+                               pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
+                       CL_PRINTF(cliBuf);\r
+               }\r
+       }\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "write 0x1af=0x0 num", \\r
+               pCoexSta->c2hHangDetectCnt);\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       // Sw mechanism \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
+       CL_PRINTF(cliBuf);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "SM1[ShRf/ LpRA/ LimDig]", \\r
+               pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       // Fw mechanism         \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
+       CL_PRINTF(cliBuf);      \r
+       \r
+       if(!pBtCoexist->bManualControl)\r
+       {\r
+               psTdmaCase = pCoexDm->curPsTdma;\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \\r
+                       pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
+                       pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
+                       pCoexDm->psTdmaPara[4], psTdmaCase);\r
+               CL_PRINTF(cliBuf);\r
+       \r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \\r
+                       pCoexDm->bCurIgnoreWlanAct);\r
+               CL_PRINTF(cliBuf);\r
+       }\r
+\r
+       // Hw setting           \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
+       CL_PRINTF(cliBuf);      \r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
+               pCoexDm->btRf0x1eBackup);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
+       u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x783);\r
+       u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x796);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \\r
+               u1Tmp[0], u1Tmp[1], u1Tmp[2]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \\r
+               u4Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \\r
+               u1Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
+               u4Tmp[0], u1Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x484);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \\r
+               u4Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
+               u4Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
+       u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
+       u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
+       u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xdac);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \\r
+               u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
+       u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
+       u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
+               u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770 (hp rx[31:16]/tx[15:0])", \\r
+               pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
+       CL_PRINTF(cliBuf);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
+               pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
+}\r
+\r
+\r
+VOID\r
+EXhalbtc8723a1ant_IpsNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       if(BTC_IPS_ENTER == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));\r
+               halbtc8723a1ant_CoexAllOff(pBtCoexist);\r
+       }\r
+       else if(BTC_IPS_LEAVE == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));\r
+               //halbtc8723a1ant_InitCoexDm(pBtCoexist);\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_LpsNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       if(BTC_LPS_ENABLE == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));\r
+       }\r
+       else if(BTC_LPS_DISABLE == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));\r
+               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_ScanNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       BOOLEAN         bWifiConnected=FALSE;\r
+       \r
+       halbtc8723a1ant_NotifyFwScan(pBtCoexist, type);\r
+\r
+       if(pBtCoexist->btInfo.bBtDisabled)\r
+       {\r
+               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); \r
+       }\r
+       else\r
+       {\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+               if(BTC_SCAN_START == type)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
+                       if(!bWifiConnected)     // non-connected scan\r
+                       {\r
+                               //set 0x550[3]=1 before PsTdma\r
+                               halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE);\r
+                       }\r
+\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
+               }\r
+               else if(BTC_SCAN_FINISH == type)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
+                       if(!bWifiConnected)     // non-connected scan\r
+                       {\r
+                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); \r
+                       }\r
+                       else\r
+                       {\r
+                               halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_ConnectNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       BOOLEAN         bWifiConnected=FALSE;\r
+               \r
+       if(pBtCoexist->btInfo.bBtDisabled)\r
+       {\r
+               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); \r
+       }\r
+       else\r
+       {\r
+               if(BTC_ASSOCIATE_START == type)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));\r
+                       //set 0x550[3]=1 before PsTdma\r
+                       halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE);\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);       // extend wifi slot     \r
+               }\r
+               else if(BTC_ASSOCIATE_FINISH == type)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));\r
+                       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+                       if(!bWifiConnected)     // non-connected scan\r
+                       {\r
+                               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+                       }\r
+                       else\r
+                       {\r
+                               halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_MediaStatusNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       if(BTC_MEDIA_CONNECT == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));\r
+       }\r
+       else\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_SpecialPacketNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       if(type == BTC_PACKET_DHCP)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));\r
+               if(pBtCoexist->btInfo.bBtDisabled)\r
+               {\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
+               }\r
+               else\r
+               {\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 18);\r
+               }               \r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_BtInfoNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      pu1Byte                 tmpBuf,\r
+       IN      u1Byte                  length\r
+       )\r
+{\r
+       u1Byte                  btInfo=0;\r
+       u1Byte                  i, rspSource=0;\r
+       BOOLEAN                 bBtHsOn=FALSE, bBtBusy=FALSE, bForceLps=FALSE;\r
+\r
+       pCoexSta->bC2hBtInfoReqSent = FALSE;\r
+       \r
+       rspSource = BT_INFO_SRC_8723A_1ANT_BT_RSP;\r
+       pCoexSta->btInfoC2hCnt[rspSource]++;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
+       for(i=0; i<length; i++)\r
+       {\r
+               pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
+               if(i == 0)\r
+                       btInfo = tmpBuf[i];\r
+               if(i == length-1)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));\r
+               }\r
+               else\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));\r
+               }\r
+       }\r
+\r
+       if(BT_INFO_SRC_8723A_1ANT_WIFI_FW != rspSource)\r
+       {\r
+               pCoexSta->btRetryCnt =\r
+                       pCoexSta->btInfoC2h[rspSource][1];\r
+\r
+               pCoexSta->btRssi =\r
+                       pCoexSta->btInfoC2h[rspSource][2]*2+10;\r
+\r
+               pCoexSta->btInfoExt = \r
+                       pCoexSta->btInfoC2h[rspSource][3];\r
+       }\r
+               \r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+       // check BIT2 first ==> check if bt is under inquiry or page scan\r
+       if(btInfo & BT_INFO_8723A_1ANT_B_INQ_PAGE)\r
+       {\r
+               pCoexSta->bC2hBtInquiryPage = TRUE;\r
+       }\r
+       else\r
+       {\r
+               pCoexSta->bC2hBtInquiryPage = FALSE;\r
+       }\r
+       btInfo &= ~BIT2;\r
+       if(!(btInfo & BIT0))\r
+       {\r
+               pCoexDm->btStatus = BT_STATE_8723A_1ANT_NO_CONNECTION;\r
+               bForceLps = FALSE;\r
+       }\r
+       else\r
+       {\r
+               bForceLps = TRUE;\r
+               if(btInfo == 0x1)\r
+               {\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_CONNECT_IDLE;\r
+               }\r
+               else if(btInfo == 0x9)\r
+               {\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_ACL_ONLY_BUSY;\r
+                       bBtBusy = TRUE;\r
+               }\r
+               else if(btInfo == 0x13)\r
+               {\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_SCO_ONLY_BUSY;\r
+                       bBtBusy = TRUE;\r
+               }\r
+               else if(btInfo == 0x1b)\r
+               {\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_ACL_SCO_BUSY;\r
+                       bBtBusy = TRUE;\r
+               }\r
+               else if(btInfo == 0x29)\r
+               {\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_HID_BUSY;\r
+                       bBtBusy = TRUE;\r
+               }\r
+               else if(btInfo == 0x3b)\r
+               {\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_HID_SCO_BUSY;\r
+                       bBtBusy = TRUE;\r
+               }\r
+       }\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bBtBusy);\r
+       if(bForceLps)\r
+               pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
+       else\r
+               pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
+\r
+       if( (BT_STATE_8723A_1ANT_NO_CONNECTION == pCoexDm->btStatus) ||\r
+               (BT_STATE_8723A_1ANT_CONNECT_IDLE == pCoexDm->btStatus) )\r
+       {\r
+               if(pCoexSta->bC2hBtInquiryPage)\r
+                       pCoexDm->btStatus = BT_STATE_8723A_1ANT_INQ_OR_PAG;\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_HaltNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist\r
+       )\r
+{\r
+       halbtc8723a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
+       \r
+       halbtc8723a1ant_LowPenaltyRa(pBtCoexist, FORCE_EXEC, FALSE);\r
+       halbtc8723a1ant_RfShrink(pBtCoexist, FORCE_EXEC, FALSE);\r
+\r
+       halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
+       EXhalbtc8723a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
+}\r
+\r
+VOID\r
+EXhalbtc8723a1ant_Periodical(\r
+       IN      PBTC_COEXIST                    pBtCoexist\r
+       )\r
+{\r
+       BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE, bWifiConnected=FALSE;\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Periodical!!\n"));\r
+       \r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+\r
+       // work around for c2h hang\r
+       wa_halbtc8723a1ant_MonitorC2h(pBtCoexist);      \r
+\r
+       halbtc8723a1ant_QueryBtInfo(pBtCoexist);\r
+       halbtc8723a1ant_MonitorBtCtr(pBtCoexist);\r
+       halbtc8723a1ant_MonitorBtEnableDisable(pBtCoexist);\r
+\r
+       \r
+       if(bScan)\r
+               return;\r
+       if(bLink)\r
+               return;\r
+\r
+       if(bWifiConnected)\r
+       {\r
+               if(pBtCoexist->btInfo.bBtDisabled)\r
+               {\r
+                       halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);\r
+                       \r
+                       halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
+                       halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
+               }\r
+               else\r
+               {\r
+                       halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
+                       halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
+                       halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+\r
+               halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
+               halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
+       }\r
+}\r
+\r
+\r
+#endif\r
+\r