blob: 33610d39333f3555091ef6edebd7abf4f83a41f7 [file] [log] [blame]
/******************************************************************************
*
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
******************************************************************************/
#include "Mp_Precomp.h"
/* Global variables, these are static variables */
static COEX_DM_8723B_2ANT GLCoexDm8723b2Ant;
static PCOEX_DM_8723B_2ANT pCoexDm = &GLCoexDm8723b2Ant;
static COEX_STA_8723B_2ANT GLCoexSta8723b2Ant;
static PCOEX_STA_8723B_2ANT pCoexSta = &GLCoexSta8723b2Ant;
static const char *const GLBtInfoSrc8723b2Ant[] = {
"BT Info[wifi fw]",
"BT Info[bt rsp]",
"BT Info[bt auto report]",
};
static u32 GLCoexVerDate8723b2Ant = 20131211;
static u32 GLCoexVer8723b2Ant = 0x40;
/* local function start with halbtc8723b2ant_ */
static u8 halbtc8723b2ant_BtRssiState(
u8 levelNum, u8 rssiThresh, u8 rssiThresh1
)
{
s32 btRssi = 0;
u8 btRssiState = pCoexSta->preBtRssiState;
btRssi = pCoexSta->btRssi;
if (levelNum == 2) {
if (
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
) {
if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
btRssiState = BTC_RSSI_STATE_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
} else {
btRssiState = BTC_RSSI_STATE_STAY_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
}
} else {
if (btRssi < rssiThresh) {
btRssiState = BTC_RSSI_STATE_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
} else {
btRssiState = BTC_RSSI_STATE_STAY_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
}
}
} else if (levelNum == 3) {
if (rssiThresh > rssiThresh1) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));
return pCoexSta->preBtRssiState;
}
if (
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
) {
if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
btRssiState = BTC_RSSI_STATE_MEDIUM;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
} else {
btRssiState = BTC_RSSI_STATE_STAY_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
}
} else if (
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM)
) {
if (btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
btRssiState = BTC_RSSI_STATE_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
} else if (btRssi < rssiThresh) {
btRssiState = BTC_RSSI_STATE_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
} else {
btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));
}
} else {
if (btRssi < rssiThresh1) {
btRssiState = BTC_RSSI_STATE_MEDIUM;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
} else {
btRssiState = BTC_RSSI_STATE_STAY_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
}
}
}
pCoexSta->preBtRssiState = btRssiState;
return btRssiState;
}
static u8 halbtc8723b2ant_WifiRssiState(
PBTC_COEXIST pBtCoexist,
u8 index,
u8 levelNum,
u8 rssiThresh,
u8 rssiThresh1
)
{
s32 wifiRssi = 0;
u8 wifiRssiState = pCoexSta->preWifiRssiState[index];
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
if (levelNum == 2) {
if (
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW)
) {
if (wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
wifiRssiState = BTC_RSSI_STATE_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));
} else {
wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));
}
} else {
if (wifiRssi < rssiThresh) {
wifiRssiState = BTC_RSSI_STATE_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));
} else {
wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));
}
}
} else if (levelNum == 3) {
if (rssiThresh > rssiThresh1) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));
return pCoexSta->preWifiRssiState[index];
}
if (
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW)
) {
if (wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
wifiRssiState = BTC_RSSI_STATE_MEDIUM;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));
} else {
wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));
}
} else if (
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM)
) {
if (wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
wifiRssiState = BTC_RSSI_STATE_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));
} else if (wifiRssi < rssiThresh) {
wifiRssiState = BTC_RSSI_STATE_LOW;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));
} else {
wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));
}
} else {
if (wifiRssi < rssiThresh1) {
wifiRssiState = BTC_RSSI_STATE_MEDIUM;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));
} else {
wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));
}
}
}
pCoexSta->preWifiRssiState[index] = wifiRssiState;
return wifiRssiState;
}
static void halbtc8723b2ant_LimitedRx(
PBTC_COEXIST pBtCoexist,
bool bForceExec,
bool bRejApAggPkt,
bool bBtCtrlAggBufSize,
u8 aggBufSize
)
{
bool bRejectRxAgg = bRejApAggPkt;
bool bBtCtrlRxAggSize = bBtCtrlAggBufSize;
u8 rxAggSize = aggBufSize;
/* */
/* Rx Aggregation related setting */
/* */
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
/* decide BT control aggregation buf size or not */
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
/* aggregation buf size, only work when BT control Rx aggregation size. */
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
/* real update aggregation setting */
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
}
static void halbtc8723b2ant_MonitorBtCtr(PBTC_COEXIST pBtCoexist)
{
u32 regHPTxRx, regLPTxRx, u4Tmp;
u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
regHPTxRx = 0x770;
regLPTxRx = 0x774;
u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
regHPTx = u4Tmp & bMaskLWord;
regHPRx = (u4Tmp & bMaskHWord)>>16;
u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
regLPTx = u4Tmp & bMaskLWord;
regLPRx = (u4Tmp & bMaskHWord)>>16;
pCoexSta->highPriorityTx = regHPTx;
pCoexSta->highPriorityRx = regHPRx;
pCoexSta->lowPriorityTx = regLPTx;
pCoexSta->lowPriorityRx = regLPRx;
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_BT_MONITOR,
(
"[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
regHPTxRx,
regHPTx,
regHPTx,
regHPRx,
regHPRx
)
);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_BT_MONITOR,
(
"[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
regLPTxRx,
regLPTx,
regLPTx,
regLPRx,
regLPRx
)
);
/* reset counter */
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
}
static void halbtc8723b2ant_QueryBtInfo(PBTC_COEXIST pBtCoexist)
{
u8 H2C_Parameter[1] = {0};
pCoexSta->bC2hBtInfoReqSent = true;
H2C_Parameter[0] |= BIT0; /* trigger */
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
("[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n", H2C_Parameter[0])
);
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
}
static bool halbtc8723b2ant_IsWifiStatusChanged(PBTC_COEXIST pBtCoexist)
{
static bool bPreWifiBusy, bPreUnder4way, bPreBtHsOn;
bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false;
bool bWifiConnected = false;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
if (bWifiConnected) {
if (bWifiBusy != bPreWifiBusy) {
bPreWifiBusy = bWifiBusy;
return true;
}
if (bUnder4way != bPreUnder4way) {
bPreUnder4way = bUnder4way;
return true;
}
if (bBtHsOn != bPreBtHsOn) {
bPreBtHsOn = bBtHsOn;
return true;
}
}
return false;
}
static void halbtc8723b2ant_UpdateBtLinkInfo(PBTC_COEXIST pBtCoexist)
{
PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
bool bBtHsOn = false;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
/* work around for HS mode. */
if (bBtHsOn) {
pBtLinkInfo->bPanExist = true;
pBtLinkInfo->bBtLinkExist = true;
}
/* check if Sco only */
if (
pBtLinkInfo->bScoExist &&
!pBtLinkInfo->bA2dpExist &&
!pBtLinkInfo->bPanExist &&
!pBtLinkInfo->bHidExist
)
pBtLinkInfo->bScoOnly = true;
else
pBtLinkInfo->bScoOnly = false;
/* check if A2dp only */
if (
!pBtLinkInfo->bScoExist &&
pBtLinkInfo->bA2dpExist &&
!pBtLinkInfo->bPanExist &&
!pBtLinkInfo->bHidExist
)
pBtLinkInfo->bA2dpOnly = true;
else
pBtLinkInfo->bA2dpOnly = false;
/* check if Pan only */
if (
!pBtLinkInfo->bScoExist &&
!pBtLinkInfo->bA2dpExist &&
pBtLinkInfo->bPanExist &&
!pBtLinkInfo->bHidExist
)
pBtLinkInfo->bPanOnly = true;
else
pBtLinkInfo->bPanOnly = false;
/* check if Hid only */
if (
!pBtLinkInfo->bScoExist &&
!pBtLinkInfo->bA2dpExist &&
!pBtLinkInfo->bPanExist &&
pBtLinkInfo->bHidExist
)
pBtLinkInfo->bHidOnly = true;
else
pBtLinkInfo->bHidOnly = false;
}
static u8 halbtc8723b2ant_ActionAlgorithm(PBTC_COEXIST pBtCoexist)
{
PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
bool bBtHsOn = false;
u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED;
u8 numOfDiffProfile = 0;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
if (!pBtLinkInfo->bBtLinkExist) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));
return algorithm;
}
if (pBtLinkInfo->bScoExist)
numOfDiffProfile++;
if (pBtLinkInfo->bHidExist)
numOfDiffProfile++;
if (pBtLinkInfo->bPanExist)
numOfDiffProfile++;
if (pBtLinkInfo->bA2dpExist)
numOfDiffProfile++;
if (numOfDiffProfile == 1) {
if (pBtLinkInfo->bScoExist) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
} else {
if (pBtLinkInfo->bHidExist) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
} else if (pBtLinkInfo->bA2dpExist) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP;
} else if (pBtLinkInfo->bPanExist) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANHS;
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR;
}
}
}
} else if (numOfDiffProfile == 2) {
if (pBtLinkInfo->bScoExist) {
if (pBtLinkInfo->bHidExist) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
} else if (pBtLinkInfo->bA2dpExist) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
} else if (pBtLinkInfo->bPanExist) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
}
}
} else {
if (
pBtLinkInfo->bHidExist &&
pBtLinkInfo->bA2dpExist
) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
} else if (
pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist
) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
}
} else if (
pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist
) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS;
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP;
}
}
}
} else if (numOfDiffProfile == 3) {
if (pBtLinkInfo->bScoExist) {
if (
pBtLinkInfo->bHidExist &&
pBtLinkInfo->bA2dpExist
) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE,
("[BTCoex], SCO + HID + A2DP ==> HID\n")
);
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
} else if (
pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist
) {
if (bBtHsOn) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE,
("[BTCoex], SCO + HID + PAN(HS)\n")
);
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
} else {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE,
("[BTCoex], SCO + HID + PAN(EDR)\n")
);
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
}
} else if (
pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist
) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
}
}
} else {
if (
pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist
) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
}
}
}
} else if (numOfDiffProfile >= 3) {
if (pBtLinkInfo->bScoExist) {
if (
pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist
) {
if (bBtHsOn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR) ==>PAN(EDR)+HID\n"));
algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
}
}
}
}
return algorithm;
}
static void halbtc8723b2ant_SetFwDacSwingLevel(
PBTC_COEXIST pBtCoexist, u8 dacSwingLvl
)
{
u8 H2C_Parameter[1] = {0};
/* There are several type of dacswing */
/* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
H2C_Parameter[0] = dacSwingLvl;
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl)
);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
("[BTCoex], FW write 0x64 = 0x%x\n", H2C_Parameter[0])
);
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);
}
static void halbtc8723b2ant_SetFwDecBtPwr(
PBTC_COEXIST pBtCoexist, u8 decBtPwrLvl
)
{
u8 H2C_Parameter[1] = {0};
H2C_Parameter[0] = decBtPwrLvl;
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
(
"[BTCoex], decrease Bt Power level = %d, FW write 0x62 = 0x%x\n",
decBtPwrLvl,
H2C_Parameter[0]
)
);
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);
}
static void halbtc8723b2ant_DecBtPwr(
PBTC_COEXIST pBtCoexist, bool bForceExec, u8 decBtPwrLvl
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW,
(
"[BTCoex], %s Dec BT power level = %d\n",
(bForceExec ? "force to" : ""),
decBtPwrLvl
)
);
pCoexDm->curBtDecPwrLvl = decBtPwrLvl;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_DETAIL,
(
"[BTCoex], preBtDecPwrLvl =%d, curBtDecPwrLvl =%d\n",
pCoexDm->preBtDecPwrLvl,
pCoexDm->curBtDecPwrLvl
)
);
if (pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl)
return;
}
halbtc8723b2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);
pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;
}
static void halbtc8723b2ant_FwDacSwingLvl(
PBTC_COEXIST pBtCoexist, bool bForceExec, u8 fwDacSwingLvl
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW,
(
"[BTCoex], %s set FW Dac Swing level = %d\n",
(bForceExec ? "force to" : ""),
fwDacSwingLvl
)
);
pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_DETAIL,
(
"[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n",
pCoexDm->preFwDacSwingLvl,
pCoexDm->curFwDacSwingLvl
)
);
if (pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl)
return;
}
halbtc8723b2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);
pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;
}
static void halbtc8723b2ant_SetSwRfRxLpfCorner(
PBTC_COEXIST pBtCoexist,
bool bRxRfShrinkOn
)
{
if (bRxRfShrinkOn) {
/* Shrink RF Rx LPF corner */
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_EXEC,
("[BTCoex], Shrink RF Rx LPF corner!!\n")
);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);
} else {
/* Resume RF Rx LPF corner */
/* After initialized, we can use pCoexDm->btRf0x1eBackup */
if (pBtCoexist->bInitilized) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);
}
}
}
static void halbtc8723b2ant_RfShrink(
PBTC_COEXIST pBtCoexist, bool bForceExec, bool bRxRfShrinkOn
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW,
(
"[BTCoex], %s turn Rx RF Shrink = %s\n",
(bForceExec ? "force to" : ""),
(bRxRfShrinkOn ? "ON" : "OFF")
)
);
pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_DETAIL,
(
"[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n",
pCoexDm->bPreRfRxLpfShrink,
pCoexDm->bCurRfRxLpfShrink
)
);
if (pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
return;
}
halbtc8723b2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
}
static void halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(
PBTC_COEXIST pBtCoexist, bool bLowPenaltyRa
)
{
u8 H2C_Parameter[6] = {0};
H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
if (bLowPenaltyRa) {
H2C_Parameter[1] |= BIT0;
H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */
H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */
H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */
}
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
(
"[BTCoex], set WiFi Low-Penalty Retry: %s",
(bLowPenaltyRa ? "ON!!" : "OFF!!")
)
);
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
}
static void halbtc8723b2ant_LowPenaltyRa(
PBTC_COEXIST pBtCoexist, bool bForceExec, bool bLowPenaltyRa
)
{
/* return; */
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW,
(
"[BTCoex], %s turn LowPenaltyRA = %s\n",
(bForceExec ? "force to" : ""),
(bLowPenaltyRa ? "ON" : "OFF")
)
);
pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_DETAIL,
(
"[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n",
pCoexDm->bPreLowPenaltyRa,
pCoexDm->bCurLowPenaltyRa
)
);
if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
return;
}
halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
}
static void halbtc8723b2ant_SetDacSwingReg(PBTC_COEXIST pBtCoexist, u32 level)
{
u8 val = (u8)level;
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_EXEC,
("[BTCoex], Write SwDacSwing = 0x%x\n", level)
);
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val);
}
static void halbtc8723b2ant_SetSwFullTimeDacSwing(
PBTC_COEXIST pBtCoexist, bool bSwDacSwingOn, u32 swDacSwingLvl
)
{
if (bSwDacSwingOn)
halbtc8723b2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);
else
halbtc8723b2ant_SetDacSwingReg(pBtCoexist, 0x18);
}
static void halbtc8723b2ant_DacSwing(
PBTC_COEXIST pBtCoexist,
bool bForceExec,
bool bDacSwingOn,
u32 dacSwingLvl
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW,
(
"[BTCoex], %s turn DacSwing =%s, dacSwingLvl = 0x%x\n",
(bForceExec ? "force to" : ""),
(bDacSwingOn ? "ON" : "OFF"),
dacSwingLvl
)
);
pCoexDm->bCurDacSwingOn = bDacSwingOn;
pCoexDm->curDacSwingLvl = dacSwingLvl;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_DETAIL,
(
"[BTCoex], bPreDacSwingOn =%d, preDacSwingLvl = 0x%x, bCurDacSwingOn =%d, curDacSwingLvl = 0x%x\n",
pCoexDm->bPreDacSwingOn,
pCoexDm->preDacSwingLvl,
pCoexDm->bCurDacSwingOn,
pCoexDm->curDacSwingLvl
)
);
if ((pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&
(pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl))
return;
}
mdelay(30);
halbtc8723b2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);
pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;
pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;
}
static void halbtc8723b2ant_SetAgcTable(
PBTC_COEXIST pBtCoexist, bool bAgcTableEn
)
{
u8 rssiAdjustVal = 0;
/* BB AGC Gain Table */
if (bAgcTableEn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table On!\n"));
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6e1A0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6d1B0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6c1C0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6b1D0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6a1E0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x691F0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x68200001);
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table Off!\n"));
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa4200001);
}
/* RF Gain */
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
if (bAgcTableEn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);
}
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
if (bAgcTableEn) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);
}
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
/* set rssiAdjustVal for wifi module. */
if (bAgcTableEn)
rssiAdjustVal = 8;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);
}
static void halbtc8723b2ant_AgcTable(
PBTC_COEXIST pBtCoexist, bool bForceExec, bool bAgcTableEn
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW,
(
"[BTCoex], %s %s Agc Table\n",
(bForceExec ? "force to" : ""),
(bAgcTableEn ? "Enable" : "Disable")
)
);
pCoexDm->bCurAgcTableEn = bAgcTableEn;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_DETAIL,
(
"[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n",
pCoexDm->bPreAgcTableEn,
pCoexDm->bCurAgcTableEn
)
);
if (pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn)
return;
}
halbtc8723b2ant_SetAgcTable(pBtCoexist, bAgcTableEn);
pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;
}
static void halbtc8723b2ant_SetCoexTable(
PBTC_COEXIST pBtCoexist,
u32 val0x6c0,
u32 val0x6c4,
u32 val0x6c8,
u8 val0x6cc
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_EXEC,
("[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0)
);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_EXEC,
("[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4)
);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_EXEC,
("[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8)
);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_EXEC,
("[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc)
);
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
}
static void halbtc8723b2ant_CoexTable(
PBTC_COEXIST pBtCoexist,
bool bForceExec,
u32 val0x6c0,
u32 val0x6c4,
u32 val0x6c8,
u8 val0x6cc
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW,
(
"[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
(bForceExec ? "force to" : ""),
val0x6c0,
val0x6c4,
val0x6c8,
val0x6cc
)
);
pCoexDm->curVal0x6c0 = val0x6c0;
pCoexDm->curVal0x6c4 = val0x6c4;
pCoexDm->curVal0x6c8 = val0x6c8;
pCoexDm->curVal0x6cc = val0x6cc;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_DETAIL,
(
"[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c4 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n",
pCoexDm->preVal0x6c0,
pCoexDm->preVal0x6c4,
pCoexDm->preVal0x6c8,
pCoexDm->preVal0x6cc
)
);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_SW_DETAIL,
(
"[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c4 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n",
pCoexDm->curVal0x6c0,
pCoexDm->curVal0x6c4,
pCoexDm->curVal0x6c8,
pCoexDm->curVal0x6cc
)
);
if (
(pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
(pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc)
)
return;
}
halbtc8723b2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
}
static void halbtc8723b2ant_CoexTableWithType(
PBTC_COEXIST pBtCoexist, bool bForceExec, u8 type
)
{
switch (type) {
case 0:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffff, 0x3);
break;
case 1:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffff, 0x3);
break;
case 2:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);
break;
case 3:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffff, 0x3);
break;
case 4:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffff, 0x3);
break;
case 5:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffff, 0x3);
break;
case 6:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffff, 0x3);
break;
case 7:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0xfafafafa, 0xffff, 0x3);
break;
case 8:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3);
break;
case 9:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aea5aea, 0xffff, 0x3);
break;
case 10:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aff5aff, 0xffff, 0x3);
break;
case 11:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5f5a5f, 0xffff, 0x3);
break;
case 12:
halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5f5f5f5f, 0xffff, 0x3);
break;
default:
break;
}
}
static void halbtc8723b2ant_SetFwIgnoreWlanAct(
PBTC_COEXIST pBtCoexist, bool bEnable
)
{
u8 H2C_Parameter[1] = {0};
if (bEnable)
H2C_Parameter[0] |= BIT0; /* function enable */
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
(
"[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
H2C_Parameter[0]
)
);
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
}
static void halbtc8723b2ant_IgnoreWlanAct(
PBTC_COEXIST pBtCoexist, bool bForceExec, bool bEnable
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW,
(
"[BTCoex], %s turn Ignore WlanAct %s\n",
(bForceExec ? "force to" : ""),
(bEnable ? "ON" : "OFF")
)
);
pCoexDm->bCurIgnoreWlanAct = bEnable;
if (!bForceExec) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));
if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
return;
}
halbtc8723b2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
}
static void halbtc8723b2ant_SetFwPstdma(
PBTC_COEXIST pBtCoexist,
u8 byte1,
u8 byte2,
u8 byte3,
u8 byte4,
u8 byte5
)
{
u8 H2C_Parameter[5] = {0};
H2C_Parameter[0] = byte1;
H2C_Parameter[1] = byte2;
H2C_Parameter[2] = byte3;
H2C_Parameter[3] = byte4;
H2C_Parameter[4] = byte5;
pCoexDm->psTdmaPara[0] = byte1;
pCoexDm->psTdmaPara[1] = byte2;
pCoexDm->psTdmaPara[2] = byte3;
pCoexDm->psTdmaPara[3] = byte4;
pCoexDm->psTdmaPara[4] = byte5;
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_EXEC,
(
"[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
H2C_Parameter[0],
H2C_Parameter[1]<<24|
H2C_Parameter[2]<<16|
H2C_Parameter[3]<<8|
H2C_Parameter[4]
)
);
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
}
static void halbtc8723b2ant_SwMechanism1(
PBTC_COEXIST pBtCoexist,
bool bShrinkRxLPF,
bool bLowPenaltyRA,
bool bLimitedDIG,
bool bBTLNAConstrain
)
{
halbtc8723b2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);
halbtc8723b2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
}
static void halbtc8723b2ant_SwMechanism2(
PBTC_COEXIST pBtCoexist,
bool bAGCTableShift,
bool bADCBackOff,
bool bSWDACSwing,
u32 dacSwingLvl
)
{
halbtc8723b2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);
halbtc8723b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);
}
static void halbtc8723b2ant_SetAntPath(
PBTC_COEXIST pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff
)
{
PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
u32 fwVer = 0, u4Tmp = 0;
bool bPgExtSwitch = false;
bool bUseExtSwitch = false;
u8 H2C_Parameter[2] = {0};
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */
if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch)
bUseExtSwitch = true;
if (bInitHwCfg) {
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1);
if (fwVer >= 0x180000) {
/* Use H2C to set GNT_BT to LOW */
H2C_Parameter[0] = 0;
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
} else {
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
}
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); /* WiFi TRx Mask off */
pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01); /* BT TRx Mask off */
if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
/* tell firmware "no antenna inverse" */
H2C_Parameter[0] = 0;
} else {
/* tell firmware "antenna inverse" */
H2C_Parameter[0] = 1;
}
if (bUseExtSwitch) {
/* ext switch type */
H2C_Parameter[1] = 1;
} else {
/* int switch type */
H2C_Parameter[1] = 0;
}
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
}
/* ext switch setting */
if (bUseExtSwitch) {
if (bInitHwCfg) {
/* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
u4Tmp &= ~BIT23;
u4Tmp |= BIT24;
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
}
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
switch (antPosType) {
case BTC_ANT_WIFI_AT_MAIN:
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); /* ext switch main at wifi */
break;
case BTC_ANT_WIFI_AT_AUX:
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); /* ext switch aux at wifi */
break;
}
} else { /* internal switch */
if (bInitHwCfg) {
/* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
u4Tmp |= BIT23;
u4Tmp &= ~BIT24;
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
}
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); /* fixed external switch S1->Main, S0->Aux */
switch (antPosType) {
case BTC_ANT_WIFI_AT_MAIN:
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
break;
case BTC_ANT_WIFI_AT_AUX:
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); /* fixed internal switch S0->WiFi, S1->BT */
break;
}
}
}
static void halbtc8723b2ant_PsTdma(
PBTC_COEXIST pBtCoexist, bool bForceExec, bool bTurnOn, u8 type
)
{
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW,
(
"[BTCoex], %s turn %s PS TDMA, type =%d\n",
(bForceExec ? "force to" : ""),
(bTurnOn ? "ON" : "OFF"),
type
)
);
pCoexDm->bCurPsTdmaOn = bTurnOn;
pCoexDm->curPsTdma = type;
if (!bForceExec) {
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_DETAIL,
(
"[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
pCoexDm->bPrePsTdmaOn,
pCoexDm->bCurPsTdmaOn
)
);
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_DETAIL,
(
"[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
pCoexDm->prePsTdma, pCoexDm->curPsTdma
)
);
if (
(pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
(pCoexDm->prePsTdma == pCoexDm->curPsTdma)
)
return;
}
if (bTurnOn) {
switch (type) {
case 1:
default:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
break;
case 2:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
break;
case 3:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);
break;
case 4:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90);
break;
case 5:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
break;
case 6:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
break;
case 7:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);
break;
case 8:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);
break;
case 9:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
break;
case 10:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
break;
case 11:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90);
break;
case 12:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
break;
case 13:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
break;
case 14:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
break;
case 15:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90);
break;
case 16:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90);
break;
case 17:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90);
break;
case 18:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
break;
case 19:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);
break;
case 20:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);
break;
case 21:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);
break;
case 71:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
break;
}
} else {
/* disable PS tdma */
switch (type) {
case 0:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
break;
case 1:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
break;
default:
halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
break;
}
}
/* update pre state */
pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
pCoexDm->prePsTdma = pCoexDm->curPsTdma;
}
static void halbtc8723b2ant_CoexAllOff(PBTC_COEXIST pBtCoexist)
{
/* fw all off */
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
/* sw all off */
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
/* hw all off */
/* pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
}
static void halbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)
{
/* force to reset coex mechanism */
halbtc8723b2ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 1);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
halbtc8723b2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
static void halbtc8723b2ant_ActionBtInquiry(PBTC_COEXIST pBtCoexist)
{
bool bWifiConnected = false;
bool bLowPwrDisable = true;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
if (bWifiConnected) {
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
} else {
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
}
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
pCoexDm->bNeedRecover0x948 = true;
pCoexDm->backup0x948 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_AUX, false, false);
}
static bool halbtc8723b2ant_IsCommonAction(PBTC_COEXIST pBtCoexist)
{
u8 btRssiState = BTC_RSSI_STATE_HIGH;
bool bCommon = false, bWifiConnected = false, bWifiBusy = false;
bool bBtHsOn = false, bLowPwrDisable = false;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
if (!bWifiConnected) {
bLowPwrDisable = false;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-connected idle!!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
bCommon = true;
} else {
if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) {
bLowPwrDisable = false;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
bCommon = true;
} else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) {
bLowPwrDisable = true;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
if (bBtHsOn)
return false;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
bCommon = true;
} else {
bLowPwrDisable = true;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
if (bWifiBusy) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
bCommon = false;
} else {
if (bBtHsOn)
return false;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 21);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
if (BTC_RSSI_HIGH(btRssiState))
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
bCommon = true;
}
}
}
return bCommon;
}
static void halbtc8723b2ant_TdmaDurationAdjust(
PBTC_COEXIST pBtCoexist, bool bScoHid, bool bTxPause, u8 maxInterval
)
{
static s32 up, dn, m, n, WaitCount;
s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
u8 retryCount = 0;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjust()\n"));
if (!pCoexDm->bAutoTdmaAdjust) {
pCoexDm->bAutoTdmaAdjust = true;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
{
if (bScoHid) {
if (bTxPause) {
if (maxInterval == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
pCoexDm->psTdmaDuAdjType = 13;
} else if (maxInterval == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (maxInterval == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
}
} else {
if (maxInterval == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
pCoexDm->psTdmaDuAdjType = 9;
} else if (maxInterval == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (maxInterval == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
}
}
} else {
if (bTxPause) {
if (maxInterval == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
pCoexDm->psTdmaDuAdjType = 5;
} else if (maxInterval == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (maxInterval == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
}
} else {
if (maxInterval == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
pCoexDm->psTdmaDuAdjType = 1;
} else if (maxInterval == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (maxInterval == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
}
}
}
}
/* */
up = 0;
dn = 0;
m = 1;
n = 3;
result = 0;
WaitCount = 0;
} else {
/* accquire the BT TRx retry count from BT_Info byte2 */
retryCount = pCoexSta->btRetryCnt;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_DETAIL,
(
"[BTCoex], up =%d, dn =%d, m =%d, n =%d, WaitCount =%d\n",
up, dn, m, n, WaitCount
)
);
result = 0;
WaitCount++;
if (retryCount == 0) { /* no retry in the last 2-second duration */
up++;
dn--;
if (dn <= 0)
dn = 0;
if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
WaitCount = 0;
n = 3;
up = 0;
dn = 0;
result = 1;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));
}
} else if (retryCount <= 3) { /* <=3 retry in the last 2-second duration */
up--;
dn++;
if (up <= 0)
up = 0;
if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
if (WaitCount <= 2)
m++; /* 避免一直在兩個level中來回 */
else
m = 1;
if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
m = 20;
n = 3*m;
up = 0;
dn = 0;
WaitCount = 0;
result = -1;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
}
} else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
if (WaitCount == 1)
m++; /* 避免一直在兩個level中來回 */
else
m = 1;
if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
m = 20;
n = 3*m;
up = 0;
dn = 0;
WaitCount = 0;
result = -1;
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
}
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], max Interval = %d\n", maxInterval));
if (maxInterval == 1) {
if (bTxPause) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
if (pCoexDm->curPsTdma == 71) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
pCoexDm->psTdmaDuAdjType = 5;
} else if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
pCoexDm->psTdmaDuAdjType = 5;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 4) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
pCoexDm->psTdmaDuAdjType = 8;
}
if (pCoexDm->curPsTdma == 9) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
pCoexDm->psTdmaDuAdjType = 13;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 12) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
pCoexDm->psTdmaDuAdjType = 16;
}
if (result == -1) {
if (pCoexDm->curPsTdma == 5) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
pCoexDm->psTdmaDuAdjType = 8;
} else if (pCoexDm->curPsTdma == 13) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
pCoexDm->psTdmaDuAdjType = 16;
}
} else if (result == 1) {
if (pCoexDm->curPsTdma == 8) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
pCoexDm->psTdmaDuAdjType = 5;
} else if (pCoexDm->curPsTdma == 16) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
pCoexDm->psTdmaDuAdjType = 13;
}
}
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
if (pCoexDm->curPsTdma == 5) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 71);
pCoexDm->psTdmaDuAdjType = 71;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 8) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
pCoexDm->psTdmaDuAdjType = 4;
}
if (pCoexDm->curPsTdma == 13) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
pCoexDm->psTdmaDuAdjType = 9;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 16) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
pCoexDm->psTdmaDuAdjType = 12;
}
if (result == -1) {
if (pCoexDm->curPsTdma == 71) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
pCoexDm->psTdmaDuAdjType = 1;
} else if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
pCoexDm->psTdmaDuAdjType = 4;
} else if (pCoexDm->curPsTdma == 9) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
pCoexDm->psTdmaDuAdjType = 12;
}
} else if (result == 1) {
if (pCoexDm->curPsTdma == 4) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
pCoexDm->psTdmaDuAdjType = 1;
} else if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 71);
pCoexDm->psTdmaDuAdjType = 71;
} else if (pCoexDm->curPsTdma == 12) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
pCoexDm->psTdmaDuAdjType = 9;
}
}
}
} else if (maxInterval == 2) {
if (bTxPause) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 4) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
pCoexDm->psTdmaDuAdjType = 8;
}
if (pCoexDm->curPsTdma == 9) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 12) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
pCoexDm->psTdmaDuAdjType = 16;
}
if (result == -1) {
if (pCoexDm->curPsTdma == 5) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
pCoexDm->psTdmaDuAdjType = 8;
} else if (pCoexDm->curPsTdma == 13) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
pCoexDm->psTdmaDuAdjType = 16;
}
} else if (result == 1) {
if (pCoexDm->curPsTdma == 8) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
pCoexDm->psTdmaDuAdjType = 6;
} else if (pCoexDm->curPsTdma == 16) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
pCoexDm->psTdmaDuAdjType = 14;
}
}
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
if (pCoexDm->curPsTdma == 5) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 8) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
pCoexDm->psTdmaDuAdjType = 4;
}
if (pCoexDm->curPsTdma == 13) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 16) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
pCoexDm->psTdmaDuAdjType = 12;
}
if (result == -1) {
if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
pCoexDm->psTdmaDuAdjType = 4;
} else if (pCoexDm->curPsTdma == 9) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
pCoexDm->psTdmaDuAdjType = 12;
}
} else if (result == 1) {
if (pCoexDm->curPsTdma == 4) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
pCoexDm->psTdmaDuAdjType = 2;
} else if (pCoexDm->curPsTdma == 12) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
pCoexDm->psTdmaDuAdjType = 10;
}
}
}
} else if (maxInterval == 3) {
if (bTxPause) {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 4) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
pCoexDm->psTdmaDuAdjType = 8;
}
if (pCoexDm->curPsTdma == 9) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 12) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
pCoexDm->psTdmaDuAdjType = 16;
}
if (result == -1) {
if (pCoexDm->curPsTdma == 5) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
pCoexDm->psTdmaDuAdjType = 8;
} else if (pCoexDm->curPsTdma == 13) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
pCoexDm->psTdmaDuAdjType = 16;
}
} else if (result == 1) {
if (pCoexDm->curPsTdma == 8) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
pCoexDm->psTdmaDuAdjType = 7;
} else if (pCoexDm->curPsTdma == 16) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
pCoexDm->psTdmaDuAdjType = 15;
}
}
} else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
if (pCoexDm->curPsTdma == 5) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 6) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 7) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 8) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
pCoexDm->psTdmaDuAdjType = 4;
}
if (pCoexDm->curPsTdma == 13) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 14) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 15) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 16) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
pCoexDm->psTdmaDuAdjType = 12;
}
if (result == -1) {
if (pCoexDm->curPsTdma == 1) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
pCoexDm->psTdmaDuAdjType = 4;
} else if (pCoexDm->curPsTdma == 9) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
pCoexDm->psTdmaDuAdjType = 12;
}
} else if (result == 1) {
if (pCoexDm->curPsTdma == 4) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 3) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 2) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
pCoexDm->psTdmaDuAdjType = 3;
} else if (pCoexDm->curPsTdma == 12) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 11) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
} else if (pCoexDm->curPsTdma == 10) {
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
pCoexDm->psTdmaDuAdjType = 11;
}
}
}
}
}
/* if current PsTdma not match with the recorded one (when scan, dhcp...), */
/* then we have to adjust it back to the previous record one. */
if (pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType) {
bool bScan = false, bLink = false, bRoam = false;
BTC_PRINT(
BTC_MSG_ALGORITHM,
ALGO_TRACE_FW_DETAIL,
(
"[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
pCoexDm->curPsTdma,
pCoexDm->psTdmaDuAdjType
)
);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
if (!bScan && !bLink && !bRoam)
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType);
else {
BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
}
}
}
/* SCO only or SCO+PAN(HS) */
static void halbtc8723b2ant_ActionSco(PBTC_COEXIST pBtCoexist)
{
u8 wifiRssiState, btRssiState;
u32 wifiBw;
wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4);
if (BTC_RSSI_HIGH(btRssiState))
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if (BTC_WIFI_BW_LEGACY == wifiBw) /* for SCO quality at 11b/g mode */
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
else /* for SCO quality & wifi performance balance at 11n mode */
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); /* for voice quality */
/* sw mechanism */
if (BTC_WIFI_BW_HT40 == wifiBw) {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4);
}
} else {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4);
}
}
}
static void halbtc8723b2ant_ActionHid(PBTC_COEXIST pBtCoexist)
{
u8 wifiRssiState, btRssiState;
u32 wifiBw;
wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
if (BTC_RSSI_HIGH(btRssiState))
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if (BTC_WIFI_BW_LEGACY == wifiBw) /* for HID at 11b/g mode */
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
else /* for HID quality & wifi performance balance at 11n mode */
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 9);
if (
(btRssiState == BTC_RSSI_STATE_HIGH) ||
(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
)
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
else
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
/* sw mechanism */
if (BTC_WIFI_BW_HT40 == wifiBw) {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
} else {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
}
}
/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
static void halbtc8723b2ant_ActionA2dp(PBTC_COEXIST pBtCoexist)
{
u8 wifiRssiState, wifiRssiState1, btRssiState;
u32 wifiBw;
u8 apNum = 0;
wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
wifiRssiState1 = halbtc8723b2ant_WifiRssiState(pBtCoexist, 1, 2, 40, 0);
btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
/* define the office environment */
if (apNum >= 10 && BTC_RSSI_HIGH(wifiRssiState1)) {
/* DbgPrint(" AP#>10(%d)\n", apNum); */
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
/* sw mechanism */
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if (BTC_WIFI_BW_HT40 == wifiBw) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18);
}
return;
}
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
if (BTC_RSSI_HIGH(btRssiState))
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
if (
(btRssiState == BTC_RSSI_STATE_HIGH) ||
(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
)
halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 1);
else
halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 1);
/* sw mechanism */
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if (BTC_WIFI_BW_HT40 == wifiBw) {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
} else {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
}
}
static void halbtc8723b2ant_ActionA2dpPanHs(PBTC_COEXIST pBtCoexist)
{
u8 wifiRssiState, btRssiState;
u32 wifiBw;
wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
if (BTC_RSSI_HIGH(btRssiState))
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 2);
/* sw mechanism */
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if (BTC_WIFI_BW_HT40 == wifiBw) {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
} else {
if (
(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
) {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
} else {
halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
}
}
}
static void halbtc8723b2ant_ActionPanEdr(PBTC_COEXIST pBtCoexist)
{
u8 wifiRssiState, btRssiState;
u32 wifiBw;
wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
if (BTC_RSSI_HIGH(btRssiState))
halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8723b2ant_