1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #include "Mp_Precomp.h"
9 
10 /*  Global variables, these are static variables */
11 static COEX_DM_8723B_2ANT GLCoexDm8723b2Ant;
12 static PCOEX_DM_8723B_2ANT pCoexDm = &GLCoexDm8723b2Ant;
13 static COEX_STA_8723B_2ANT GLCoexSta8723b2Ant;
14 static PCOEX_STA_8723B_2ANT pCoexSta = &GLCoexSta8723b2Ant;
15 
16 static const char *const GLBtInfoSrc8723b2Ant[] = {
17 	"BT Info[wifi fw]",
18 	"BT Info[bt rsp]",
19 	"BT Info[bt auto report]",
20 };
21 
22 static u32 GLCoexVerDate8723b2Ant = 20131211;
23 static u32 GLCoexVer8723b2Ant = 0x40;
24 
25 /*  local function start with halbtc8723b2ant_ */
halbtc8723b2ant_BtRssiState(u8 levelNum,u8 rssiThresh,u8 rssiThresh1)26 static u8 halbtc8723b2ant_BtRssiState(
27 	u8 levelNum, u8 rssiThresh, u8 rssiThresh1
28 )
29 {
30 	s32 btRssi = 0;
31 	u8 btRssiState = pCoexSta->preBtRssiState;
32 
33 	btRssi = pCoexSta->btRssi;
34 
35 	if (levelNum == 2) {
36 		if (
37 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
38 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
39 		) {
40 			if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
41 				btRssiState = BTC_RSSI_STATE_HIGH;
42 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
43 			} else {
44 				btRssiState = BTC_RSSI_STATE_STAY_LOW;
45 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
46 			}
47 		} else {
48 			if (btRssi < rssiThresh) {
49 				btRssiState = BTC_RSSI_STATE_LOW;
50 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
51 			} else {
52 				btRssiState = BTC_RSSI_STATE_STAY_HIGH;
53 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
54 			}
55 		}
56 	} else if (levelNum == 3) {
57 		if (rssiThresh > rssiThresh1) {
58 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));
59 			return pCoexSta->preBtRssiState;
60 		}
61 
62 		if (
63 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
64 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
65 		) {
66 			if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
67 				btRssiState = BTC_RSSI_STATE_MEDIUM;
68 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
69 			} else {
70 				btRssiState = BTC_RSSI_STATE_STAY_LOW;
71 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
72 			}
73 		} else if (
74 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
75 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM)
76 		) {
77 			if (btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
78 				btRssiState = BTC_RSSI_STATE_HIGH;
79 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
80 			} else if (btRssi < rssiThresh) {
81 				btRssiState = BTC_RSSI_STATE_LOW;
82 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
83 			} else {
84 				btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
85 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));
86 			}
87 		} else {
88 			if (btRssi < rssiThresh1) {
89 				btRssiState = BTC_RSSI_STATE_MEDIUM;
90 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
91 			} else {
92 				btRssiState = BTC_RSSI_STATE_STAY_HIGH;
93 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
94 			}
95 		}
96 	}
97 
98 	pCoexSta->preBtRssiState = btRssiState;
99 
100 	return btRssiState;
101 }
102 
halbtc8723b2ant_WifiRssiState(PBTC_COEXIST pBtCoexist,u8 index,u8 levelNum,u8 rssiThresh,u8 rssiThresh1)103 static u8 halbtc8723b2ant_WifiRssiState(
104 	PBTC_COEXIST pBtCoexist,
105 	u8 index,
106 	u8 levelNum,
107 	u8 rssiThresh,
108 	u8 rssiThresh1
109 )
110 {
111 	s32 wifiRssi = 0;
112 	u8 wifiRssiState = pCoexSta->preWifiRssiState[index];
113 
114 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
115 
116 	if (levelNum == 2) {
117 		if (
118 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
119 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW)
120 		) {
121 			if (wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
122 				wifiRssiState = BTC_RSSI_STATE_HIGH;
123 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));
124 			} else {
125 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
126 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));
127 			}
128 		} else {
129 			if (wifiRssi < rssiThresh) {
130 				wifiRssiState = BTC_RSSI_STATE_LOW;
131 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));
132 			} else {
133 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
134 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));
135 			}
136 		}
137 	} else if (levelNum == 3) {
138 		if (rssiThresh > rssiThresh1) {
139 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));
140 			return pCoexSta->preWifiRssiState[index];
141 		}
142 
143 		if (
144 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
145 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW)
146 		) {
147 			if (wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
148 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
149 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));
150 			} else {
151 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
152 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));
153 			}
154 		} else if (
155 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
156 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM)
157 		) {
158 			if (wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
159 				wifiRssiState = BTC_RSSI_STATE_HIGH;
160 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));
161 			} else if (wifiRssi < rssiThresh) {
162 				wifiRssiState = BTC_RSSI_STATE_LOW;
163 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));
164 			} else {
165 				wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
166 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));
167 			}
168 		} else {
169 			if (wifiRssi < rssiThresh1) {
170 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
171 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));
172 			} else {
173 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
174 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));
175 			}
176 		}
177 	}
178 
179 	pCoexSta->preWifiRssiState[index] = wifiRssiState;
180 
181 	return wifiRssiState;
182 }
183 
halbtc8723b2ant_LimitedRx(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bRejApAggPkt,bool bBtCtrlAggBufSize,u8 aggBufSize)184 static void halbtc8723b2ant_LimitedRx(
185 	PBTC_COEXIST pBtCoexist,
186 	bool bForceExec,
187 	bool bRejApAggPkt,
188 	bool bBtCtrlAggBufSize,
189 	u8 aggBufSize
190 )
191 {
192 	bool bRejectRxAgg = bRejApAggPkt;
193 	bool bBtCtrlRxAggSize = bBtCtrlAggBufSize;
194 	u8 rxAggSize = aggBufSize;
195 
196 	/*  */
197 	/* 	Rx Aggregation related setting */
198 	/*  */
199 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
200 	/*  decide BT control aggregation buf size or not */
201 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
202 	/*  aggregation buf size, only work when BT control Rx aggregation size. */
203 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
204 	/*  real update aggregation setting */
205 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
206 }
207 
halbtc8723b2ant_MonitorBtCtr(PBTC_COEXIST pBtCoexist)208 static void halbtc8723b2ant_MonitorBtCtr(PBTC_COEXIST pBtCoexist)
209 {
210 	u32 regHPTxRx, regLPTxRx, u4Tmp;
211 	u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
212 
213 	regHPTxRx = 0x770;
214 	regLPTxRx = 0x774;
215 
216 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
217 	regHPTx = u4Tmp & bMaskLWord;
218 	regHPRx = (u4Tmp & bMaskHWord)>>16;
219 
220 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
221 	regLPTx = u4Tmp & bMaskLWord;
222 	regLPRx = (u4Tmp & bMaskHWord)>>16;
223 
224 	pCoexSta->highPriorityTx = regHPTx;
225 	pCoexSta->highPriorityRx = regHPRx;
226 	pCoexSta->lowPriorityTx = regLPTx;
227 	pCoexSta->lowPriorityRx = regLPRx;
228 
229 	BTC_PRINT(
230 		BTC_MSG_ALGORITHM,
231 		ALGO_BT_MONITOR,
232 		(
233 			"[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
234 			regHPTxRx,
235 			regHPTx,
236 			regHPTx,
237 			regHPRx,
238 			regHPRx
239 		)
240 	);
241 	BTC_PRINT(
242 		BTC_MSG_ALGORITHM,
243 		ALGO_BT_MONITOR,
244 		(
245 			"[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
246 			regLPTxRx,
247 			regLPTx,
248 			regLPTx,
249 			regLPRx,
250 			regLPRx
251 		)
252 	);
253 
254 	/*  reset counter */
255 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
256 }
257 
halbtc8723b2ant_QueryBtInfo(PBTC_COEXIST pBtCoexist)258 static void halbtc8723b2ant_QueryBtInfo(PBTC_COEXIST pBtCoexist)
259 {
260 	u8 	H2C_Parameter[1] = {0};
261 
262 	pCoexSta->bC2hBtInfoReqSent = true;
263 
264 	H2C_Parameter[0] |= BIT0;	/*  trigger */
265 
266 	BTC_PRINT(
267 		BTC_MSG_ALGORITHM,
268 		ALGO_TRACE_FW_EXEC,
269 		("[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n", H2C_Parameter[0])
270 	);
271 
272 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
273 }
274 
halbtc8723b2ant_IsWifiStatusChanged(PBTC_COEXIST pBtCoexist)275 static bool halbtc8723b2ant_IsWifiStatusChanged(PBTC_COEXIST pBtCoexist)
276 {
277 	static bool	bPreWifiBusy, bPreUnder4way, bPreBtHsOn;
278 	bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false;
279 	bool bWifiConnected = false;
280 
281 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
282 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
283 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
284 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
285 
286 	if (bWifiConnected) {
287 		if (bWifiBusy != bPreWifiBusy) {
288 			bPreWifiBusy = bWifiBusy;
289 			return true;
290 		}
291 
292 		if (bUnder4way != bPreUnder4way) {
293 			bPreUnder4way = bUnder4way;
294 			return true;
295 		}
296 
297 		if (bBtHsOn != bPreBtHsOn) {
298 			bPreBtHsOn = bBtHsOn;
299 			return true;
300 		}
301 	}
302 
303 	return false;
304 }
305 
halbtc8723b2ant_UpdateBtLinkInfo(PBTC_COEXIST pBtCoexist)306 static void halbtc8723b2ant_UpdateBtLinkInfo(PBTC_COEXIST pBtCoexist)
307 {
308 	PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
309 	bool bBtHsOn = false;
310 
311 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
312 
313 	pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
314 	pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
315 	pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
316 	pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
317 	pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
318 
319 	/*  work around for HS mode. */
320 	if (bBtHsOn) {
321 		pBtLinkInfo->bPanExist = true;
322 		pBtLinkInfo->bBtLinkExist = true;
323 	}
324 
325 	/*  check if Sco only */
326 	if (
327 		pBtLinkInfo->bScoExist &&
328 		!pBtLinkInfo->bA2dpExist &&
329 		!pBtLinkInfo->bPanExist &&
330 		!pBtLinkInfo->bHidExist
331 	)
332 		pBtLinkInfo->bScoOnly = true;
333 	else
334 		pBtLinkInfo->bScoOnly = false;
335 
336 	/*  check if A2dp only */
337 	if (
338 		!pBtLinkInfo->bScoExist &&
339 		pBtLinkInfo->bA2dpExist &&
340 		!pBtLinkInfo->bPanExist &&
341 		!pBtLinkInfo->bHidExist
342 	)
343 		pBtLinkInfo->bA2dpOnly = true;
344 	else
345 		pBtLinkInfo->bA2dpOnly = false;
346 
347 	/*  check if Pan only */
348 	if (
349 		!pBtLinkInfo->bScoExist &&
350 		!pBtLinkInfo->bA2dpExist &&
351 		pBtLinkInfo->bPanExist &&
352 		!pBtLinkInfo->bHidExist
353 	)
354 		pBtLinkInfo->bPanOnly = true;
355 	else
356 		pBtLinkInfo->bPanOnly = false;
357 
358 	/*  check if Hid only */
359 	if (
360 		!pBtLinkInfo->bScoExist &&
361 		!pBtLinkInfo->bA2dpExist &&
362 		!pBtLinkInfo->bPanExist &&
363 		pBtLinkInfo->bHidExist
364 	)
365 		pBtLinkInfo->bHidOnly = true;
366 	else
367 		pBtLinkInfo->bHidOnly = false;
368 }
369 
halbtc8723b2ant_ActionAlgorithm(PBTC_COEXIST pBtCoexist)370 static u8 halbtc8723b2ant_ActionAlgorithm(PBTC_COEXIST pBtCoexist)
371 {
372 	PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
373 	bool bBtHsOn = false;
374 	u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED;
375 	u8 numOfDiffProfile = 0;
376 
377 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
378 
379 	if (!pBtLinkInfo->bBtLinkExist) {
380 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));
381 		return algorithm;
382 	}
383 
384 	if (pBtLinkInfo->bScoExist)
385 		numOfDiffProfile++;
386 
387 	if (pBtLinkInfo->bHidExist)
388 		numOfDiffProfile++;
389 
390 	if (pBtLinkInfo->bPanExist)
391 		numOfDiffProfile++;
392 
393 	if (pBtLinkInfo->bA2dpExist)
394 		numOfDiffProfile++;
395 
396 	if (numOfDiffProfile == 1) {
397 		if (pBtLinkInfo->bScoExist) {
398 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));
399 			algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
400 		} else {
401 			if (pBtLinkInfo->bHidExist) {
402 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));
403 				algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
404 			} else if (pBtLinkInfo->bA2dpExist) {
405 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));
406 				algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP;
407 			} else if (pBtLinkInfo->bPanExist) {
408 				if (bBtHsOn) {
409 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));
410 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANHS;
411 				} else {
412 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));
413 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR;
414 				}
415 			}
416 		}
417 	} else if (numOfDiffProfile == 2) {
418 		if (pBtLinkInfo->bScoExist) {
419 			if (pBtLinkInfo->bHidExist) {
420 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));
421 				algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
422 			} else if (pBtLinkInfo->bA2dpExist) {
423 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));
424 				algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
425 			} else if (pBtLinkInfo->bPanExist) {
426 				if (bBtHsOn) {
427 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
428 					algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
429 				} else {
430 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
431 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
432 				}
433 			}
434 		} else {
435 			if (
436 				pBtLinkInfo->bHidExist &&
437 				pBtLinkInfo->bA2dpExist
438 			) {
439 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));
440 				algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
441 			} else if (
442 				pBtLinkInfo->bHidExist &&
443 				pBtLinkInfo->bPanExist
444 			) {
445 				if (bBtHsOn) {
446 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
447 					algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
448 				} else {
449 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
450 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
451 				}
452 			} else if (
453 				pBtLinkInfo->bPanExist &&
454 				pBtLinkInfo->bA2dpExist
455 			) {
456 				if (bBtHsOn) {
457 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
458 					algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS;
459 				} else {
460 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
461 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP;
462 				}
463 			}
464 		}
465 	} else if (numOfDiffProfile == 3) {
466 		if (pBtLinkInfo->bScoExist) {
467 			if (
468 				pBtLinkInfo->bHidExist &&
469 				pBtLinkInfo->bA2dpExist
470 			) {
471 				BTC_PRINT(
472 					BTC_MSG_ALGORITHM,
473 					ALGO_TRACE,
474 					("[BTCoex], SCO + HID + A2DP ==> HID\n")
475 				);
476 				algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
477 			} else if (
478 				pBtLinkInfo->bHidExist &&
479 				pBtLinkInfo->bPanExist
480 			) {
481 				if (bBtHsOn) {
482 					BTC_PRINT(
483 						BTC_MSG_ALGORITHM,
484 						ALGO_TRACE,
485 						("[BTCoex], SCO + HID + PAN(HS)\n")
486 					);
487 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
488 				} else {
489 					BTC_PRINT(
490 						BTC_MSG_ALGORITHM,
491 						ALGO_TRACE,
492 						("[BTCoex], SCO + HID + PAN(EDR)\n")
493 					);
494 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
495 				}
496 			} else if (
497 				pBtLinkInfo->bPanExist &&
498 				pBtLinkInfo->bA2dpExist
499 			) {
500 				if (bBtHsOn) {
501 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));
502 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
503 				} else {
504 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));
505 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
506 				}
507 			}
508 		} else {
509 			if (
510 				pBtLinkInfo->bHidExist &&
511 				pBtLinkInfo->bPanExist &&
512 				pBtLinkInfo->bA2dpExist
513 			) {
514 				if (bBtHsOn) {
515 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
516 					algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
517 				} else {
518 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
519 					algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
520 				}
521 			}
522 		}
523 	} else if (numOfDiffProfile >= 3) {
524 		if (pBtLinkInfo->bScoExist) {
525 			if (
526 				pBtLinkInfo->bHidExist &&
527 				pBtLinkInfo->bPanExist &&
528 				pBtLinkInfo->bA2dpExist
529 			) {
530 				if (bBtHsOn) {
531 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
532 
533 				} else {
534 					BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR) ==>PAN(EDR)+HID\n"));
535 					algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
536 				}
537 			}
538 		}
539 	}
540 
541 	return algorithm;
542 }
543 
halbtc8723b2ant_SetFwDacSwingLevel(PBTC_COEXIST pBtCoexist,u8 dacSwingLvl)544 static void halbtc8723b2ant_SetFwDacSwingLevel(
545 	PBTC_COEXIST pBtCoexist, u8 dacSwingLvl
546 )
547 {
548 	u8 	H2C_Parameter[1] = {0};
549 
550 	/*  There are several type of dacswing */
551 	/*  0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
552 	H2C_Parameter[0] = dacSwingLvl;
553 
554 	BTC_PRINT(
555 		BTC_MSG_ALGORITHM,
556 		ALGO_TRACE_FW_EXEC,
557 		("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl)
558 	);
559 	BTC_PRINT(
560 		BTC_MSG_ALGORITHM,
561 		ALGO_TRACE_FW_EXEC,
562 		("[BTCoex], FW write 0x64 = 0x%x\n", H2C_Parameter[0])
563 	);
564 
565 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);
566 }
567 
halbtc8723b2ant_SetFwDecBtPwr(PBTC_COEXIST pBtCoexist,u8 decBtPwrLvl)568 static void halbtc8723b2ant_SetFwDecBtPwr(
569 	PBTC_COEXIST pBtCoexist, u8 decBtPwrLvl
570 )
571 {
572 	u8 	H2C_Parameter[1] = {0};
573 
574 	H2C_Parameter[0] = decBtPwrLvl;
575 
576 	BTC_PRINT(
577 		BTC_MSG_ALGORITHM,
578 		ALGO_TRACE_FW_EXEC,
579 		(
580 			"[BTCoex], decrease Bt Power level = %d, FW write 0x62 = 0x%x\n",
581 			decBtPwrLvl,
582 			H2C_Parameter[0]
583 		)
584 	);
585 
586 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);
587 }
588 
halbtc8723b2ant_DecBtPwr(PBTC_COEXIST pBtCoexist,bool bForceExec,u8 decBtPwrLvl)589 static void halbtc8723b2ant_DecBtPwr(
590 	PBTC_COEXIST pBtCoexist, bool bForceExec, u8 decBtPwrLvl
591 )
592 {
593 	BTC_PRINT(
594 		BTC_MSG_ALGORITHM,
595 		ALGO_TRACE_FW,
596 		(
597 			"[BTCoex], %s Dec BT power level = %d\n",
598 			(bForceExec ? "force to" : ""),
599 			decBtPwrLvl
600 		)
601 	);
602 	pCoexDm->curBtDecPwrLvl = decBtPwrLvl;
603 
604 	if (!bForceExec) {
605 		BTC_PRINT(
606 			BTC_MSG_ALGORITHM,
607 			ALGO_TRACE_FW_DETAIL,
608 			(
609 				"[BTCoex], preBtDecPwrLvl =%d, curBtDecPwrLvl =%d\n",
610 				pCoexDm->preBtDecPwrLvl,
611 				pCoexDm->curBtDecPwrLvl
612 			)
613 		);
614 
615 		if (pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl)
616 			return;
617 	}
618 	halbtc8723b2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);
619 
620 	pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;
621 }
622 
halbtc8723b2ant_FwDacSwingLvl(PBTC_COEXIST pBtCoexist,bool bForceExec,u8 fwDacSwingLvl)623 static void halbtc8723b2ant_FwDacSwingLvl(
624 	PBTC_COEXIST pBtCoexist, bool bForceExec, u8 fwDacSwingLvl
625 )
626 {
627 	BTC_PRINT(
628 		BTC_MSG_ALGORITHM,
629 		ALGO_TRACE_FW,
630 		(
631 			"[BTCoex], %s set FW Dac Swing level = %d\n",
632 			(bForceExec ? "force to" : ""),
633 			fwDacSwingLvl
634 		)
635 	);
636 	pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;
637 
638 	if (!bForceExec) {
639 		BTC_PRINT(
640 			BTC_MSG_ALGORITHM,
641 			ALGO_TRACE_FW_DETAIL,
642 			(
643 				"[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n",
644 				pCoexDm->preFwDacSwingLvl,
645 				pCoexDm->curFwDacSwingLvl
646 			)
647 		);
648 
649 		if (pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl)
650 			return;
651 	}
652 
653 	halbtc8723b2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);
654 
655 	pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;
656 }
657 
halbtc8723b2ant_SetSwRfRxLpfCorner(PBTC_COEXIST pBtCoexist,bool bRxRfShrinkOn)658 static void halbtc8723b2ant_SetSwRfRxLpfCorner(
659 	PBTC_COEXIST pBtCoexist,
660 	bool bRxRfShrinkOn
661 )
662 {
663 	if (bRxRfShrinkOn) {
664 		/* Shrink RF Rx LPF corner */
665 		BTC_PRINT(
666 			BTC_MSG_ALGORITHM,
667 			ALGO_TRACE_SW_EXEC,
668 			("[BTCoex], Shrink RF Rx LPF corner!!\n")
669 		);
670 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);
671 	} else {
672 		/* Resume RF Rx LPF corner */
673 		/*  After initialized, we can use pCoexDm->btRf0x1eBackup */
674 		if (pBtCoexist->bInitilized) {
675 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
676 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);
677 		}
678 	}
679 }
680 
halbtc8723b2ant_RfShrink(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bRxRfShrinkOn)681 static void halbtc8723b2ant_RfShrink(
682 	PBTC_COEXIST pBtCoexist, bool bForceExec, bool bRxRfShrinkOn
683 )
684 {
685 	BTC_PRINT(
686 		BTC_MSG_ALGORITHM,
687 		ALGO_TRACE_SW,
688 		(
689 			"[BTCoex], %s turn Rx RF Shrink = %s\n",
690 			(bForceExec ? "force to" : ""),
691 			(bRxRfShrinkOn ? "ON" : "OFF")
692 		)
693 	);
694 	pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
695 
696 	if (!bForceExec) {
697 		BTC_PRINT(
698 			BTC_MSG_ALGORITHM,
699 			ALGO_TRACE_SW_DETAIL,
700 			(
701 				"[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n",
702 				pCoexDm->bPreRfRxLpfShrink,
703 				pCoexDm->bCurRfRxLpfShrink
704 			)
705 		);
706 
707 		if (pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
708 			return;
709 	}
710 	halbtc8723b2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
711 
712 	pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
713 }
714 
halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(PBTC_COEXIST pBtCoexist,bool bLowPenaltyRa)715 static void halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(
716 	PBTC_COEXIST pBtCoexist, bool bLowPenaltyRa
717 )
718 {
719 	u8 	H2C_Parameter[6] = {0};
720 
721 	H2C_Parameter[0] = 0x6;	/*  opCode, 0x6 = Retry_Penalty */
722 
723 	if (bLowPenaltyRa) {
724 		H2C_Parameter[1] |= BIT0;
725 		H2C_Parameter[2] = 0x00;  /* normal rate except MCS7/6/5, OFDM54/48/36 */
726 		H2C_Parameter[3] = 0xf7;  /* MCS7 or OFDM54 */
727 		H2C_Parameter[4] = 0xf8;  /* MCS6 or OFDM48 */
728 		H2C_Parameter[5] = 0xf9;	/* MCS5 or OFDM36 */
729 	}
730 
731 	BTC_PRINT(
732 		BTC_MSG_ALGORITHM,
733 		ALGO_TRACE_FW_EXEC,
734 		(
735 			"[BTCoex], set WiFi Low-Penalty Retry: %s",
736 			(bLowPenaltyRa ? "ON!!" : "OFF!!")
737 		)
738 	);
739 
740 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
741 }
742 
halbtc8723b2ant_LowPenaltyRa(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bLowPenaltyRa)743 static void halbtc8723b2ant_LowPenaltyRa(
744 	PBTC_COEXIST pBtCoexist, bool bForceExec, bool bLowPenaltyRa
745 )
746 {
747 	/* return; */
748 	BTC_PRINT(
749 		BTC_MSG_ALGORITHM,
750 		ALGO_TRACE_SW,
751 		(
752 			"[BTCoex], %s turn LowPenaltyRA = %s\n",
753 			(bForceExec ? "force to" : ""),
754 			(bLowPenaltyRa ? "ON" : "OFF")
755 		)
756 	);
757 	pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
758 
759 	if (!bForceExec) {
760 		BTC_PRINT(
761 			BTC_MSG_ALGORITHM,
762 			ALGO_TRACE_SW_DETAIL,
763 			(
764 				"[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n",
765 				pCoexDm->bPreLowPenaltyRa,
766 				pCoexDm->bCurLowPenaltyRa
767 			)
768 		);
769 
770 		if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
771 			return;
772 	}
773 	halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
774 
775 	pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
776 }
777 
halbtc8723b2ant_SetDacSwingReg(PBTC_COEXIST pBtCoexist,u32 level)778 static void halbtc8723b2ant_SetDacSwingReg(PBTC_COEXIST pBtCoexist, u32 level)
779 {
780 	u8 val = (u8)level;
781 
782 	BTC_PRINT(
783 		BTC_MSG_ALGORITHM,
784 		ALGO_TRACE_SW_EXEC,
785 		("[BTCoex], Write SwDacSwing = 0x%x\n", level)
786 	);
787 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val);
788 }
789 
halbtc8723b2ant_SetSwFullTimeDacSwing(PBTC_COEXIST pBtCoexist,bool bSwDacSwingOn,u32 swDacSwingLvl)790 static void halbtc8723b2ant_SetSwFullTimeDacSwing(
791 	PBTC_COEXIST pBtCoexist, bool bSwDacSwingOn, u32 swDacSwingLvl
792 )
793 {
794 	if (bSwDacSwingOn)
795 		halbtc8723b2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);
796 	else
797 		halbtc8723b2ant_SetDacSwingReg(pBtCoexist, 0x18);
798 }
799 
800 
halbtc8723b2ant_DacSwing(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bDacSwingOn,u32 dacSwingLvl)801 static void halbtc8723b2ant_DacSwing(
802 	PBTC_COEXIST pBtCoexist,
803 	bool bForceExec,
804 	bool bDacSwingOn,
805 	u32 dacSwingLvl
806 )
807 {
808 	BTC_PRINT(
809 		BTC_MSG_ALGORITHM,
810 		ALGO_TRACE_SW,
811 		(
812 			"[BTCoex], %s turn DacSwing =%s, dacSwingLvl = 0x%x\n",
813 			(bForceExec ? "force to" : ""),
814 			(bDacSwingOn ? "ON" : "OFF"),
815 			dacSwingLvl
816 		)
817 	);
818 	pCoexDm->bCurDacSwingOn = bDacSwingOn;
819 	pCoexDm->curDacSwingLvl = dacSwingLvl;
820 
821 	if (!bForceExec) {
822 		BTC_PRINT(
823 			BTC_MSG_ALGORITHM,
824 			ALGO_TRACE_SW_DETAIL,
825 			(
826 				"[BTCoex], bPreDacSwingOn =%d, preDacSwingLvl = 0x%x, bCurDacSwingOn =%d, curDacSwingLvl = 0x%x\n",
827 				pCoexDm->bPreDacSwingOn,
828 				pCoexDm->preDacSwingLvl,
829 				pCoexDm->bCurDacSwingOn,
830 				pCoexDm->curDacSwingLvl
831 			)
832 		);
833 
834 		if ((pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&
835 			(pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl))
836 			return;
837 	}
838 	mdelay(30);
839 	halbtc8723b2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);
840 
841 	pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;
842 	pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;
843 }
844 
halbtc8723b2ant_SetAgcTable(PBTC_COEXIST pBtCoexist,bool bAgcTableEn)845 static void halbtc8723b2ant_SetAgcTable(
846 	PBTC_COEXIST pBtCoexist, bool bAgcTableEn
847 )
848 {
849 	u8 rssiAdjustVal = 0;
850 
851 	/* BB AGC Gain Table */
852 	if (bAgcTableEn) {
853 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table On!\n"));
854 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6e1A0001);
855 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6d1B0001);
856 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6c1C0001);
857 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6b1D0001);
858 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6a1E0001);
859 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x691F0001);
860 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x68200001);
861 	} else {
862 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table Off!\n"));
863 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);
864 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);
865 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);
866 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);
867 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);
868 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);
869 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa4200001);
870 	}
871 
872 
873 	/* RF Gain */
874 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
875 	if (bAgcTableEn) {
876 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));
877 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);
878 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);
879 	} else {
880 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));
881 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);
882 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);
883 	}
884 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
885 
886 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
887 	if (bAgcTableEn) {
888 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));
889 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);
890 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);
891 	} else {
892 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));
893 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);
894 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);
895 	}
896 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
897 
898 	/*  set rssiAdjustVal for wifi module. */
899 	if (bAgcTableEn)
900 		rssiAdjustVal = 8;
901 
902 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);
903 }
904 
halbtc8723b2ant_AgcTable(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bAgcTableEn)905 static void halbtc8723b2ant_AgcTable(
906 	PBTC_COEXIST pBtCoexist, bool bForceExec, bool bAgcTableEn
907 )
908 {
909 	BTC_PRINT(
910 		BTC_MSG_ALGORITHM,
911 		ALGO_TRACE_SW,
912 		(
913 			"[BTCoex], %s %s Agc Table\n",
914 			(bForceExec ? "force to" : ""),
915 			(bAgcTableEn ? "Enable" : "Disable")
916 		)
917 	);
918 	pCoexDm->bCurAgcTableEn = bAgcTableEn;
919 
920 	if (!bForceExec) {
921 		BTC_PRINT(
922 			BTC_MSG_ALGORITHM,
923 			ALGO_TRACE_SW_DETAIL,
924 			(
925 				"[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n",
926 				pCoexDm->bPreAgcTableEn,
927 				pCoexDm->bCurAgcTableEn
928 			)
929 		);
930 
931 		if (pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn)
932 			return;
933 	}
934 	halbtc8723b2ant_SetAgcTable(pBtCoexist, bAgcTableEn);
935 
936 	pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;
937 }
938 
halbtc8723b2ant_SetCoexTable(PBTC_COEXIST pBtCoexist,u32 val0x6c0,u32 val0x6c4,u32 val0x6c8,u8 val0x6cc)939 static void halbtc8723b2ant_SetCoexTable(
940 	PBTC_COEXIST pBtCoexist,
941 	u32 val0x6c0,
942 	u32 val0x6c4,
943 	u32 val0x6c8,
944 	u8 val0x6cc
945 )
946 {
947 	BTC_PRINT(
948 		BTC_MSG_ALGORITHM,
949 		ALGO_TRACE_SW_EXEC,
950 		("[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0)
951 	);
952 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
953 
954 	BTC_PRINT(
955 		BTC_MSG_ALGORITHM,
956 		ALGO_TRACE_SW_EXEC,
957 		("[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4)
958 	);
959 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
960 
961 	BTC_PRINT(
962 		BTC_MSG_ALGORITHM,
963 		ALGO_TRACE_SW_EXEC,
964 		("[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8)
965 	);
966 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
967 
968 	BTC_PRINT(
969 		BTC_MSG_ALGORITHM,
970 		ALGO_TRACE_SW_EXEC,
971 		("[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc)
972 	);
973 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
974 }
975 
halbtc8723b2ant_CoexTable(PBTC_COEXIST pBtCoexist,bool bForceExec,u32 val0x6c0,u32 val0x6c4,u32 val0x6c8,u8 val0x6cc)976 static void halbtc8723b2ant_CoexTable(
977 	PBTC_COEXIST pBtCoexist,
978 	bool bForceExec,
979 	u32 val0x6c0,
980 	u32 val0x6c4,
981 	u32 val0x6c8,
982 	u8 val0x6cc
983 )
984 {
985 	BTC_PRINT(
986 		BTC_MSG_ALGORITHM,
987 		ALGO_TRACE_SW,
988 		(
989 			"[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
990 			(bForceExec ? "force to" : ""),
991 			val0x6c0,
992 			val0x6c4,
993 			val0x6c8,
994 			val0x6cc
995 		)
996 	);
997 	pCoexDm->curVal0x6c0 = val0x6c0;
998 	pCoexDm->curVal0x6c4 = val0x6c4;
999 	pCoexDm->curVal0x6c8 = val0x6c8;
1000 	pCoexDm->curVal0x6cc = val0x6cc;
1001 
1002 	if (!bForceExec) {
1003 		BTC_PRINT(
1004 			BTC_MSG_ALGORITHM,
1005 			ALGO_TRACE_SW_DETAIL,
1006 			(
1007 				"[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c4 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n",
1008 				pCoexDm->preVal0x6c0,
1009 				pCoexDm->preVal0x6c4,
1010 				pCoexDm->preVal0x6c8,
1011 				pCoexDm->preVal0x6cc
1012 			)
1013 		);
1014 		BTC_PRINT(
1015 			BTC_MSG_ALGORITHM,
1016 			ALGO_TRACE_SW_DETAIL,
1017 			(
1018 				"[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c4 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n",
1019 				pCoexDm->curVal0x6c0,
1020 				pCoexDm->curVal0x6c4,
1021 				pCoexDm->curVal0x6c8,
1022 				pCoexDm->curVal0x6cc
1023 			)
1024 		);
1025 
1026 		if (
1027 			(pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1028 			(pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1029 			(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1030 			(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc)
1031 		)
1032 			return;
1033 	}
1034 	halbtc8723b2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1035 
1036 	pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1037 	pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1038 	pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1039 	pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1040 }
1041 
halbtc8723b2ant_CoexTableWithType(PBTC_COEXIST pBtCoexist,bool bForceExec,u8 type)1042 static void halbtc8723b2ant_CoexTableWithType(
1043 	PBTC_COEXIST pBtCoexist, bool bForceExec, u8 type
1044 )
1045 {
1046 	switch (type) {
1047 	case 0:
1048 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffff, 0x3);
1049 		break;
1050 	case 1:
1051 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffff, 0x3);
1052 		break;
1053 	case 2:
1054 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);
1055 		break;
1056 	case 3:
1057 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffff, 0x3);
1058 		break;
1059 	case 4:
1060 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffff, 0x3);
1061 		break;
1062 	case 5:
1063 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffff, 0x3);
1064 		break;
1065 	case 6:
1066 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffff, 0x3);
1067 		break;
1068 	case 7:
1069 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0xfafafafa, 0xffff, 0x3);
1070 		break;
1071 	case 8:
1072 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3);
1073 		break;
1074 	case 9:
1075 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aea5aea, 0xffff, 0x3);
1076 		break;
1077 	case 10:
1078 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aff5aff, 0xffff, 0x3);
1079 		break;
1080 	case 11:
1081 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5f5a5f, 0xffff, 0x3);
1082 		break;
1083 	case 12:
1084 		halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5f5f5f5f, 0xffff, 0x3);
1085 		break;
1086 	default:
1087 		break;
1088 	}
1089 }
1090 
halbtc8723b2ant_SetFwIgnoreWlanAct(PBTC_COEXIST pBtCoexist,bool bEnable)1091 static void halbtc8723b2ant_SetFwIgnoreWlanAct(
1092 	PBTC_COEXIST pBtCoexist, bool bEnable
1093 )
1094 {
1095 	u8 	H2C_Parameter[1] = {0};
1096 
1097 	if (bEnable)
1098 		H2C_Parameter[0] |= BIT0;		/*  function enable */
1099 
1100 	BTC_PRINT(
1101 		BTC_MSG_ALGORITHM,
1102 		ALGO_TRACE_FW_EXEC,
1103 		(
1104 			"[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
1105 			H2C_Parameter[0]
1106 		)
1107 	);
1108 
1109 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
1110 }
1111 
halbtc8723b2ant_IgnoreWlanAct(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bEnable)1112 static void halbtc8723b2ant_IgnoreWlanAct(
1113 	PBTC_COEXIST pBtCoexist, bool bForceExec, bool bEnable
1114 )
1115 {
1116 	BTC_PRINT(
1117 		BTC_MSG_ALGORITHM,
1118 		ALGO_TRACE_FW,
1119 		(
1120 			"[BTCoex], %s turn Ignore WlanAct %s\n",
1121 			(bForceExec ? "force to" : ""),
1122 			(bEnable ? "ON" : "OFF")
1123 		)
1124 	);
1125 
1126 	pCoexDm->bCurIgnoreWlanAct = bEnable;
1127 
1128 	if (!bForceExec) {
1129 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
1130 			pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));
1131 
1132 		if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1133 			return;
1134 	}
1135 	halbtc8723b2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1136 
1137 	pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1138 }
1139 
halbtc8723b2ant_SetFwPstdma(PBTC_COEXIST pBtCoexist,u8 byte1,u8 byte2,u8 byte3,u8 byte4,u8 byte5)1140 static void halbtc8723b2ant_SetFwPstdma(
1141 	PBTC_COEXIST pBtCoexist,
1142 	u8 byte1,
1143 	u8 byte2,
1144 	u8 byte3,
1145 	u8 byte4,
1146 	u8 byte5
1147 )
1148 {
1149 	u8 	H2C_Parameter[5] = {0};
1150 
1151 	H2C_Parameter[0] = byte1;
1152 	H2C_Parameter[1] = byte2;
1153 	H2C_Parameter[2] = byte3;
1154 	H2C_Parameter[3] = byte4;
1155 	H2C_Parameter[4] = byte5;
1156 
1157 	pCoexDm->psTdmaPara[0] = byte1;
1158 	pCoexDm->psTdmaPara[1] = byte2;
1159 	pCoexDm->psTdmaPara[2] = byte3;
1160 	pCoexDm->psTdmaPara[3] = byte4;
1161 	pCoexDm->psTdmaPara[4] = byte5;
1162 
1163 	BTC_PRINT(
1164 		BTC_MSG_ALGORITHM,
1165 		ALGO_TRACE_FW_EXEC,
1166 		(
1167 			"[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1168 			H2C_Parameter[0],
1169 			H2C_Parameter[1]<<24|
1170 			H2C_Parameter[2]<<16|
1171 			H2C_Parameter[3]<<8|
1172 			H2C_Parameter[4]
1173 		)
1174 	);
1175 
1176 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1177 }
1178 
halbtc8723b2ant_SwMechanism1(PBTC_COEXIST pBtCoexist,bool bShrinkRxLPF,bool bLowPenaltyRA,bool bLimitedDIG,bool bBTLNAConstrain)1179 static void halbtc8723b2ant_SwMechanism1(
1180 	PBTC_COEXIST pBtCoexist,
1181 	bool bShrinkRxLPF,
1182 	bool bLowPenaltyRA,
1183 	bool bLimitedDIG,
1184 	bool bBTLNAConstrain
1185 )
1186 {
1187 	halbtc8723b2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);
1188 	halbtc8723b2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1189 }
1190 
halbtc8723b2ant_SwMechanism2(PBTC_COEXIST pBtCoexist,bool bAGCTableShift,bool bADCBackOff,bool bSWDACSwing,u32 dacSwingLvl)1191 static void halbtc8723b2ant_SwMechanism2(
1192 	PBTC_COEXIST pBtCoexist,
1193 	bool bAGCTableShift,
1194 	bool bADCBackOff,
1195 	bool bSWDACSwing,
1196 	u32 dacSwingLvl
1197 )
1198 {
1199 	halbtc8723b2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);
1200 	halbtc8723b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);
1201 }
1202 
halbtc8723b2ant_SetAntPath(PBTC_COEXIST pBtCoexist,u8 antPosType,bool bInitHwCfg,bool bWifiOff)1203 static void halbtc8723b2ant_SetAntPath(
1204 	PBTC_COEXIST pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff
1205 )
1206 {
1207 	PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
1208 	u32 fwVer = 0, u4Tmp = 0;
1209 	bool bPgExtSwitch = false;
1210 	bool bUseExtSwitch = false;
1211 	u8 	H2C_Parameter[2] = {0};
1212 
1213 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
1214 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);	/*  [31:16]=fw ver, [15:0]=fw sub ver */
1215 
1216 	if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch)
1217 		bUseExtSwitch = true;
1218 
1219 	if (bInitHwCfg) {
1220 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
1221 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
1222 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
1223 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
1224 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1);
1225 
1226 		if (fwVer >= 0x180000) {
1227 			/* Use H2C to set GNT_BT to LOW */
1228 			H2C_Parameter[0] = 0;
1229 			pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1230 		} else {
1231 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
1232 		}
1233 
1234 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
1235 
1236 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); /* WiFi TRx Mask off */
1237 		pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01); /* BT TRx Mask off */
1238 
1239 		if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
1240 			/* tell firmware "no antenna inverse" */
1241 			H2C_Parameter[0] = 0;
1242 		} else {
1243 			/* tell firmware "antenna inverse" */
1244 			H2C_Parameter[0] = 1;
1245 		}
1246 
1247 		if (bUseExtSwitch) {
1248 			/* ext switch type */
1249 			H2C_Parameter[1] = 1;
1250 		} else {
1251 			/* int switch type */
1252 			H2C_Parameter[1] = 0;
1253 		}
1254 		pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1255 	}
1256 
1257 	/*  ext switch setting */
1258 	if (bUseExtSwitch) {
1259 		if (bInitHwCfg) {
1260 			/*  0x4c[23]= 0, 0x4c[24]= 1  Antenna control by WL/BT */
1261 			u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1262 			u4Tmp &= ~BIT23;
1263 			u4Tmp |= BIT24;
1264 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1265 		}
1266 
1267 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /*  fixed internal switch S1->WiFi, S0->BT */
1268 		switch (antPosType) {
1269 		case BTC_ANT_WIFI_AT_MAIN:
1270 			pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);	/*  ext switch main at wifi */
1271 			break;
1272 		case BTC_ANT_WIFI_AT_AUX:
1273 			pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);	/*  ext switch aux at wifi */
1274 			break;
1275 		}
1276 	} else { /*  internal switch */
1277 		if (bInitHwCfg) {
1278 			/*  0x4c[23]= 0, 0x4c[24]= 1  Antenna control by WL/BT */
1279 			u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1280 			u4Tmp |= BIT23;
1281 			u4Tmp &= ~BIT24;
1282 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1283 		}
1284 
1285 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); /* fixed external switch S1->Main, S0->Aux */
1286 		switch (antPosType) {
1287 		case BTC_ANT_WIFI_AT_MAIN:
1288 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /*  fixed internal switch S1->WiFi, S0->BT */
1289 			break;
1290 		case BTC_ANT_WIFI_AT_AUX:
1291 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); /*  fixed internal switch S0->WiFi, S1->BT */
1292 			break;
1293 		}
1294 	}
1295 }
1296 
halbtc8723b2ant_PsTdma(PBTC_COEXIST pBtCoexist,bool bForceExec,bool bTurnOn,u8 type)1297 static void halbtc8723b2ant_PsTdma(
1298 	PBTC_COEXIST pBtCoexist, bool bForceExec, bool bTurnOn, u8 type
1299 )
1300 {
1301 	BTC_PRINT(
1302 		BTC_MSG_ALGORITHM,
1303 		ALGO_TRACE_FW,
1304 		(
1305 			"[BTCoex], %s turn %s PS TDMA, type =%d\n",
1306 			(bForceExec ? "force to" : ""),
1307 			(bTurnOn ? "ON" : "OFF"),
1308 			type
1309 		)
1310 	);
1311 	pCoexDm->bCurPsTdmaOn = bTurnOn;
1312 	pCoexDm->curPsTdma = type;
1313 
1314 	if (!bForceExec) {
1315 		BTC_PRINT(
1316 			BTC_MSG_ALGORITHM,
1317 			ALGO_TRACE_FW_DETAIL,
1318 			(
1319 				"[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1320 				pCoexDm->bPrePsTdmaOn,
1321 				pCoexDm->bCurPsTdmaOn
1322 			)
1323 		);
1324 		BTC_PRINT(
1325 			BTC_MSG_ALGORITHM,
1326 			ALGO_TRACE_FW_DETAIL,
1327 			(
1328 				"[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1329 				pCoexDm->prePsTdma, pCoexDm->curPsTdma
1330 			)
1331 		);
1332 
1333 		if (
1334 			(pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1335 			(pCoexDm->prePsTdma == pCoexDm->curPsTdma)
1336 		)
1337 			return;
1338 	}
1339 
1340 	if (bTurnOn) {
1341 		switch (type) {
1342 		case 1:
1343 		default:
1344 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1345 			break;
1346 		case 2:
1347 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
1348 			break;
1349 		case 3:
1350 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);
1351 			break;
1352 		case 4:
1353 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90);
1354 			break;
1355 		case 5:
1356 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
1357 			break;
1358 		case 6:
1359 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
1360 			break;
1361 		case 7:
1362 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);
1363 			break;
1364 		case 8:
1365 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);
1366 			break;
1367 		case 9:
1368 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1369 			break;
1370 		case 10:
1371 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
1372 			break;
1373 		case 11:
1374 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90);
1375 			break;
1376 		case 12:
1377 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1378 			break;
1379 		case 13:
1380 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
1381 			break;
1382 		case 14:
1383 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
1384 			break;
1385 		case 15:
1386 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90);
1387 			break;
1388 		case 16:
1389 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90);
1390 			break;
1391 		case 17:
1392 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90);
1393 			break;
1394 		case 18:
1395 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1396 			break;
1397 		case 19:
1398 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);
1399 			break;
1400 		case 20:
1401 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);
1402 			break;
1403 		case 21:
1404 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);
1405 			break;
1406 		case 71:
1407 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1408 			break;
1409 		}
1410 	} else {
1411 		/*  disable PS tdma */
1412 		switch (type) {
1413 		case 0:
1414 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
1415 			break;
1416 		case 1:
1417 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
1418 			break;
1419 		default:
1420 			halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
1421 			break;
1422 		}
1423 	}
1424 
1425 	/*  update pre state */
1426 	pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1427 	pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1428 }
1429 
halbtc8723b2ant_CoexAllOff(PBTC_COEXIST pBtCoexist)1430 static void halbtc8723b2ant_CoexAllOff(PBTC_COEXIST pBtCoexist)
1431 {
1432 	/*  fw all off */
1433 	halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1434 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1435 	halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1436 
1437 	/*  sw all off */
1438 	halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1439 	halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1440 
1441 	/*  hw all off */
1442 	/* pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
1443 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1444 }
1445 
halbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)1446 static void halbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)
1447 {
1448 	/*  force to reset coex mechanism */
1449 
1450 	halbtc8723b2ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 1);
1451 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1452 	halbtc8723b2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);
1453 
1454 	halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1455 	halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1456 }
1457 
halbtc8723b2ant_ActionBtInquiry(PBTC_COEXIST pBtCoexist)1458 static void halbtc8723b2ant_ActionBtInquiry(PBTC_COEXIST pBtCoexist)
1459 {
1460 	bool bWifiConnected = false;
1461 	bool bLowPwrDisable = true;
1462 
1463 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1464 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1465 
1466 	if (bWifiConnected) {
1467 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1468 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1469 	} else {
1470 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1471 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1472 	}
1473 
1474 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1475 	halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1476 
1477 	halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1478 	halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1479 
1480 	pCoexDm->bNeedRecover0x948 = true;
1481 	pCoexDm->backup0x948 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
1482 
1483 	halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_AUX, false, false);
1484 }
1485 
halbtc8723b2ant_IsCommonAction(PBTC_COEXIST pBtCoexist)1486 static bool halbtc8723b2ant_IsCommonAction(PBTC_COEXIST pBtCoexist)
1487 {
1488 	u8 btRssiState = BTC_RSSI_STATE_HIGH;
1489 	bool bCommon = false, bWifiConnected = false, bWifiBusy = false;
1490 	bool bBtHsOn = false, bLowPwrDisable = false;
1491 
1492 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1493 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1494 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1495 
1496 	if (!bWifiConnected) {
1497 		bLowPwrDisable = false;
1498 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1499 		halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1500 
1501 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-connected idle!!\n"));
1502 
1503 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1504 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1505 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1506 		halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1507 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1508 
1509 		halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1510 		halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1511 
1512 		bCommon = true;
1513 	} else {
1514 		if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) {
1515 			bLowPwrDisable = false;
1516 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1517 			halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1518 
1519 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
1520 
1521 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1522 			halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1523 			halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1524 			halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1525 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1526 
1527 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1528 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1529 
1530 			bCommon = true;
1531 		} else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) {
1532 			bLowPwrDisable = true;
1533 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1534 
1535 			if (bBtHsOn)
1536 				return false;
1537 
1538 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
1539 			halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1540 
1541 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1542 			halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1543 			halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1544 			halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1545 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1546 
1547 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
1548 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1549 
1550 			bCommon = true;
1551 		} else {
1552 			bLowPwrDisable = true;
1553 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1554 
1555 			if (bWifiBusy) {
1556 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
1557 				bCommon = false;
1558 			} else {
1559 				if (bBtHsOn)
1560 					return false;
1561 
1562 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
1563 				btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
1564 				halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1565 
1566 				pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1567 				halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1568 				halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 21);
1569 				halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1570 
1571 				if (BTC_RSSI_HIGH(btRssiState))
1572 					halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
1573 				else
1574 					halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1575 
1576 				halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1577 				halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1578 				bCommon = true;
1579 			}
1580 		}
1581 	}
1582 
1583 	return bCommon;
1584 }
1585 
halbtc8723b2ant_TdmaDurationAdjust(PBTC_COEXIST pBtCoexist,bool bScoHid,bool bTxPause,u8 maxInterval)1586 static void halbtc8723b2ant_TdmaDurationAdjust(
1587 	PBTC_COEXIST pBtCoexist, bool bScoHid, bool bTxPause, u8 maxInterval
1588 )
1589 {
1590 	static s32 up, dn, m, n, WaitCount;
1591 	s32 result;   /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1592 	u8 retryCount = 0;
1593 
1594 	BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjust()\n"));
1595 
1596 	if (!pCoexDm->bAutoTdmaAdjust) {
1597 		pCoexDm->bAutoTdmaAdjust = true;
1598 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
1599 		{
1600 			if (bScoHid) {
1601 				if (bTxPause) {
1602 					if (maxInterval == 1) {
1603 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
1604 						pCoexDm->psTdmaDuAdjType = 13;
1605 					} else if (maxInterval == 2) {
1606 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1607 						pCoexDm->psTdmaDuAdjType = 14;
1608 					} else if (maxInterval == 3) {
1609 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1610 						pCoexDm->psTdmaDuAdjType = 15;
1611 					} else {
1612 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1613 						pCoexDm->psTdmaDuAdjType = 15;
1614 					}
1615 				} else {
1616 					if (maxInterval == 1) {
1617 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1618 						pCoexDm->psTdmaDuAdjType = 9;
1619 					} else if (maxInterval == 2) {
1620 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
1621 						pCoexDm->psTdmaDuAdjType = 10;
1622 					} else if (maxInterval == 3) {
1623 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1624 						pCoexDm->psTdmaDuAdjType = 11;
1625 					} else {
1626 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1627 						pCoexDm->psTdmaDuAdjType = 11;
1628 					}
1629 				}
1630 			} else {
1631 				if (bTxPause) {
1632 					if (maxInterval == 1) {
1633 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1634 						pCoexDm->psTdmaDuAdjType = 5;
1635 					} else if (maxInterval == 2) {
1636 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1637 						pCoexDm->psTdmaDuAdjType = 6;
1638 					} else if (maxInterval == 3) {
1639 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1640 						pCoexDm->psTdmaDuAdjType = 7;
1641 					} else {
1642 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1643 						pCoexDm->psTdmaDuAdjType = 7;
1644 					}
1645 				} else {
1646 					if (maxInterval == 1) {
1647 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
1648 						pCoexDm->psTdmaDuAdjType = 1;
1649 					} else if (maxInterval == 2) {
1650 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1651 						pCoexDm->psTdmaDuAdjType = 2;
1652 					} else if (maxInterval == 3) {
1653 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1654 						pCoexDm->psTdmaDuAdjType = 3;
1655 					} else {
1656 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1657 						pCoexDm->psTdmaDuAdjType = 3;
1658 					}
1659 				}
1660 			}
1661 		}
1662 		/*  */
1663 		up = 0;
1664 		dn = 0;
1665 		m = 1;
1666 		n = 3;
1667 		result = 0;
1668 		WaitCount = 0;
1669 	} else {
1670 		/* accquire the BT TRx retry count from BT_Info byte2 */
1671 		retryCount = pCoexSta->btRetryCnt;
1672 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));
1673 		BTC_PRINT(
1674 			BTC_MSG_ALGORITHM,
1675 			ALGO_TRACE_FW_DETAIL,
1676 			(
1677 				"[BTCoex], up =%d, dn =%d, m =%d, n =%d, WaitCount =%d\n",
1678 				up, dn, m, n, WaitCount
1679 			)
1680 		);
1681 		result = 0;
1682 		WaitCount++;
1683 
1684 		if (retryCount == 0) { /*  no retry in the last 2-second duration */
1685 			up++;
1686 			dn--;
1687 
1688 			if (dn <= 0)
1689 				dn = 0;
1690 
1691 			if (up >= n) { /*  if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
1692 				WaitCount = 0;
1693 				n = 3;
1694 				up = 0;
1695 				dn = 0;
1696 				result = 1;
1697 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));
1698 			}
1699 		} else if (retryCount <= 3) { /*  <=3 retry in the last 2-second duration */
1700 			up--;
1701 			dn++;
1702 
1703 			if (up <= 0)
1704 				up = 0;
1705 
1706 			if (dn == 2) { /*  if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
1707 				if (WaitCount <= 2)
1708 					m++; /*  避免一直在兩個level中來回 */
1709 				else
1710 					m = 1;
1711 
1712 				if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1713 					m = 20;
1714 
1715 				n = 3*m;
1716 				up = 0;
1717 				dn = 0;
1718 				WaitCount = 0;
1719 				result = -1;
1720 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
1721 			}
1722 		} else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
1723 			if (WaitCount == 1)
1724 				m++; /*  避免一直在兩個level中來回 */
1725 			else
1726 				m = 1;
1727 
1728 			if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1729 				m = 20;
1730 
1731 			n = 3*m;
1732 			up = 0;
1733 			dn = 0;
1734 			WaitCount = 0;
1735 			result = -1;
1736 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
1737 		}
1738 
1739 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], max Interval = %d\n", maxInterval));
1740 		if (maxInterval == 1) {
1741 			if (bTxPause) {
1742 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
1743 
1744 				if (pCoexDm->curPsTdma == 71) {
1745 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1746 					pCoexDm->psTdmaDuAdjType = 5;
1747 				} else if (pCoexDm->curPsTdma == 1) {
1748 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1749 					pCoexDm->psTdmaDuAdjType = 5;
1750 				} else if (pCoexDm->curPsTdma == 2) {
1751 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1752 					pCoexDm->psTdmaDuAdjType = 6;
1753 				} else if (pCoexDm->curPsTdma == 3) {
1754 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1755 					pCoexDm->psTdmaDuAdjType = 7;
1756 				} else if (pCoexDm->curPsTdma == 4) {
1757 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
1758 					pCoexDm->psTdmaDuAdjType = 8;
1759 				}
1760 
1761 				if (pCoexDm->curPsTdma == 9) {
1762 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
1763 					pCoexDm->psTdmaDuAdjType = 13;
1764 				} else if (pCoexDm->curPsTdma == 10) {
1765 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1766 					pCoexDm->psTdmaDuAdjType = 14;
1767 				} else if (pCoexDm->curPsTdma == 11) {
1768 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1769 					pCoexDm->psTdmaDuAdjType = 15;
1770 				} else if (pCoexDm->curPsTdma == 12) {
1771 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
1772 					pCoexDm->psTdmaDuAdjType = 16;
1773 				}
1774 
1775 				if (result == -1) {
1776 					if (pCoexDm->curPsTdma == 5) {
1777 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1778 						pCoexDm->psTdmaDuAdjType = 6;
1779 					} else if (pCoexDm->curPsTdma == 6) {
1780 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1781 						pCoexDm->psTdmaDuAdjType = 7;
1782 					} else if (pCoexDm->curPsTdma == 7) {
1783 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
1784 						pCoexDm->psTdmaDuAdjType = 8;
1785 					} else if (pCoexDm->curPsTdma == 13) {
1786 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1787 						pCoexDm->psTdmaDuAdjType = 14;
1788 					} else if (pCoexDm->curPsTdma == 14) {
1789 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1790 						pCoexDm->psTdmaDuAdjType = 15;
1791 					} else if (pCoexDm->curPsTdma == 15) {
1792 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
1793 						pCoexDm->psTdmaDuAdjType = 16;
1794 					}
1795 				} else if (result == 1) {
1796 					if (pCoexDm->curPsTdma == 8) {
1797 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1798 						pCoexDm->psTdmaDuAdjType = 7;
1799 					} else if (pCoexDm->curPsTdma == 7) {
1800 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1801 						pCoexDm->psTdmaDuAdjType = 6;
1802 					} else if (pCoexDm->curPsTdma == 6) {
1803 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1804 						pCoexDm->psTdmaDuAdjType = 5;
1805 					} else if (pCoexDm->curPsTdma == 16) {
1806 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1807 						pCoexDm->psTdmaDuAdjType = 15;
1808 					} else if (pCoexDm->curPsTdma == 15) {
1809 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1810 						pCoexDm->psTdmaDuAdjType = 14;
1811 					} else if (pCoexDm->curPsTdma == 14) {
1812 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
1813 						pCoexDm->psTdmaDuAdjType = 13;
1814 					}
1815 				}
1816 			} else {
1817 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
1818 				if (pCoexDm->curPsTdma == 5) {
1819 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 71);
1820 					pCoexDm->psTdmaDuAdjType = 71;
1821 				} else if (pCoexDm->curPsTdma == 6) {
1822 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1823 					pCoexDm->psTdmaDuAdjType = 2;
1824 				} else if (pCoexDm->curPsTdma == 7) {
1825 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1826 					pCoexDm->psTdmaDuAdjType = 3;
1827 				} else if (pCoexDm->curPsTdma == 8) {
1828 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
1829 					pCoexDm->psTdmaDuAdjType = 4;
1830 				}
1831 
1832 				if (pCoexDm->curPsTdma == 13) {
1833 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1834 					pCoexDm->psTdmaDuAdjType = 9;
1835 				} else if (pCoexDm->curPsTdma == 14) {
1836 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
1837 					pCoexDm->psTdmaDuAdjType = 10;
1838 				} else if (pCoexDm->curPsTdma == 15) {
1839 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1840 					pCoexDm->psTdmaDuAdjType = 11;
1841 				} else if (pCoexDm->curPsTdma == 16) {
1842 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
1843 					pCoexDm->psTdmaDuAdjType = 12;
1844 				}
1845 
1846 				if (result == -1) {
1847 					if (pCoexDm->curPsTdma == 71) {
1848 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
1849 						pCoexDm->psTdmaDuAdjType = 1;
1850 					} else if (pCoexDm->curPsTdma == 1) {
1851 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1852 						pCoexDm->psTdmaDuAdjType = 2;
1853 					} else if (pCoexDm->curPsTdma == 2) {
1854 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1855 						pCoexDm->psTdmaDuAdjType = 3;
1856 					} else if (pCoexDm->curPsTdma == 3) {
1857 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
1858 						pCoexDm->psTdmaDuAdjType = 4;
1859 					} else if (pCoexDm->curPsTdma == 9) {
1860 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
1861 						pCoexDm->psTdmaDuAdjType = 10;
1862 					} else if (pCoexDm->curPsTdma == 10) {
1863 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1864 						pCoexDm->psTdmaDuAdjType = 11;
1865 					} else if (pCoexDm->curPsTdma == 11) {
1866 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
1867 						pCoexDm->psTdmaDuAdjType = 12;
1868 					}
1869 				} else if (result == 1) {
1870 					if (pCoexDm->curPsTdma == 4) {
1871 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1872 						pCoexDm->psTdmaDuAdjType = 3;
1873 					} else if (pCoexDm->curPsTdma == 3) {
1874 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1875 						pCoexDm->psTdmaDuAdjType = 2;
1876 					} else if (pCoexDm->curPsTdma == 2) {
1877 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
1878 						pCoexDm->psTdmaDuAdjType = 1;
1879 					} else if (pCoexDm->curPsTdma == 1) {
1880 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 71);
1881 						pCoexDm->psTdmaDuAdjType = 71;
1882 					} else if (pCoexDm->curPsTdma == 12) {
1883 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1884 						pCoexDm->psTdmaDuAdjType = 11;
1885 					} else if (pCoexDm->curPsTdma == 11) {
1886 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
1887 						pCoexDm->psTdmaDuAdjType = 10;
1888 					} else if (pCoexDm->curPsTdma == 10) {
1889 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1890 						pCoexDm->psTdmaDuAdjType = 9;
1891 					}
1892 				}
1893 			}
1894 		} else if (maxInterval == 2) {
1895 			if (bTxPause) {
1896 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
1897 				if (pCoexDm->curPsTdma == 1) {
1898 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1899 					pCoexDm->psTdmaDuAdjType = 6;
1900 				} else if (pCoexDm->curPsTdma == 2) {
1901 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1902 					pCoexDm->psTdmaDuAdjType = 6;
1903 				} else if (pCoexDm->curPsTdma == 3) {
1904 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1905 					pCoexDm->psTdmaDuAdjType = 7;
1906 				} else if (pCoexDm->curPsTdma == 4) {
1907 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
1908 					pCoexDm->psTdmaDuAdjType = 8;
1909 				}
1910 
1911 				if (pCoexDm->curPsTdma == 9) {
1912 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1913 					pCoexDm->psTdmaDuAdjType = 14;
1914 				} else if (pCoexDm->curPsTdma == 10) {
1915 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1916 					pCoexDm->psTdmaDuAdjType = 14;
1917 				} else if (pCoexDm->curPsTdma == 11) {
1918 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1919 					pCoexDm->psTdmaDuAdjType = 15;
1920 				} else if (pCoexDm->curPsTdma == 12) {
1921 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
1922 					pCoexDm->psTdmaDuAdjType = 16;
1923 				}
1924 
1925 				if (result == -1) {
1926 					if (pCoexDm->curPsTdma == 5) {
1927 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1928 						pCoexDm->psTdmaDuAdjType = 6;
1929 					} else if (pCoexDm->curPsTdma == 6) {
1930 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1931 						pCoexDm->psTdmaDuAdjType = 7;
1932 					} else if (pCoexDm->curPsTdma == 7) {
1933 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
1934 						pCoexDm->psTdmaDuAdjType = 8;
1935 					} else if (pCoexDm->curPsTdma == 13) {
1936 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1937 						pCoexDm->psTdmaDuAdjType = 14;
1938 					} else if (pCoexDm->curPsTdma == 14) {
1939 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1940 						pCoexDm->psTdmaDuAdjType = 15;
1941 					} else if (pCoexDm->curPsTdma == 15) {
1942 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
1943 						pCoexDm->psTdmaDuAdjType = 16;
1944 					}
1945 				} else if (result == 1) {
1946 					if (pCoexDm->curPsTdma == 8) {
1947 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
1948 						pCoexDm->psTdmaDuAdjType = 7;
1949 					} else if (pCoexDm->curPsTdma == 7) {
1950 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1951 						pCoexDm->psTdmaDuAdjType = 6;
1952 					} else if (pCoexDm->curPsTdma == 6) {
1953 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1954 						pCoexDm->psTdmaDuAdjType = 6;
1955 					} else if (pCoexDm->curPsTdma == 16) {
1956 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
1957 						pCoexDm->psTdmaDuAdjType = 15;
1958 					} else if (pCoexDm->curPsTdma == 15) {
1959 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1960 						pCoexDm->psTdmaDuAdjType = 14;
1961 					} else if (pCoexDm->curPsTdma == 14) {
1962 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1963 						pCoexDm->psTdmaDuAdjType = 14;
1964 					}
1965 				}
1966 			} else {
1967 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
1968 				if (pCoexDm->curPsTdma == 5) {
1969 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1970 					pCoexDm->psTdmaDuAdjType = 2;
1971 				} else if (pCoexDm->curPsTdma == 6) {
1972 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1973 					pCoexDm->psTdmaDuAdjType = 2;
1974 				} else if (pCoexDm->curPsTdma == 7) {
1975 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1976 					pCoexDm->psTdmaDuAdjType = 3;
1977 				} else if (pCoexDm->curPsTdma == 8) {
1978 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
1979 					pCoexDm->psTdmaDuAdjType = 4;
1980 				}
1981 
1982 				if (pCoexDm->curPsTdma == 13) {
1983 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
1984 					pCoexDm->psTdmaDuAdjType = 10;
1985 				} else if (pCoexDm->curPsTdma == 14) {
1986 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
1987 					pCoexDm->psTdmaDuAdjType = 10;
1988 				} else if (pCoexDm->curPsTdma == 15) {
1989 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1990 					pCoexDm->psTdmaDuAdjType = 11;
1991 				} else if (pCoexDm->curPsTdma == 16) {
1992 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
1993 					pCoexDm->psTdmaDuAdjType = 12;
1994 				}
1995 
1996 				if (result == -1) {
1997 					if (pCoexDm->curPsTdma == 1) {
1998 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1999 						pCoexDm->psTdmaDuAdjType = 2;
2000 					} else if (pCoexDm->curPsTdma == 2) {
2001 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2002 						pCoexDm->psTdmaDuAdjType = 3;
2003 					} else if (pCoexDm->curPsTdma == 3) {
2004 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
2005 						pCoexDm->psTdmaDuAdjType = 4;
2006 					} else if (pCoexDm->curPsTdma == 9) {
2007 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
2008 						pCoexDm->psTdmaDuAdjType = 10;
2009 					} else if (pCoexDm->curPsTdma == 10) {
2010 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2011 						pCoexDm->psTdmaDuAdjType = 11;
2012 					} else if (pCoexDm->curPsTdma == 11) {
2013 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
2014 						pCoexDm->psTdmaDuAdjType = 12;
2015 					}
2016 				} else if (result == 1) {
2017 					if (pCoexDm->curPsTdma == 4) {
2018 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2019 						pCoexDm->psTdmaDuAdjType = 3;
2020 					} else if (pCoexDm->curPsTdma == 3) {
2021 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
2022 						pCoexDm->psTdmaDuAdjType = 2;
2023 					} else if (pCoexDm->curPsTdma == 2) {
2024 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
2025 						pCoexDm->psTdmaDuAdjType = 2;
2026 					} else if (pCoexDm->curPsTdma == 12) {
2027 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2028 						pCoexDm->psTdmaDuAdjType = 11;
2029 					} else if (pCoexDm->curPsTdma == 11) {
2030 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
2031 						pCoexDm->psTdmaDuAdjType = 10;
2032 					} else if (pCoexDm->curPsTdma == 10) {
2033 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
2034 						pCoexDm->psTdmaDuAdjType = 10;
2035 					}
2036 				}
2037 			}
2038 		} else if (maxInterval == 3) {
2039 			if (bTxPause) {
2040 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
2041 				if (pCoexDm->curPsTdma == 1) {
2042 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2043 					pCoexDm->psTdmaDuAdjType = 7;
2044 				} else if (pCoexDm->curPsTdma == 2) {
2045 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2046 					pCoexDm->psTdmaDuAdjType = 7;
2047 				} else if (pCoexDm->curPsTdma == 3) {
2048 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2049 					pCoexDm->psTdmaDuAdjType = 7;
2050 				} else if (pCoexDm->curPsTdma == 4) {
2051 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
2052 					pCoexDm->psTdmaDuAdjType = 8;
2053 				}
2054 
2055 				if (pCoexDm->curPsTdma == 9) {
2056 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2057 					pCoexDm->psTdmaDuAdjType = 15;
2058 				} else if (pCoexDm->curPsTdma == 10) {
2059 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2060 					pCoexDm->psTdmaDuAdjType = 15;
2061 				} else if (pCoexDm->curPsTdma == 11) {
2062 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2063 					pCoexDm->psTdmaDuAdjType = 15;
2064 				} else if (pCoexDm->curPsTdma == 12) {
2065 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
2066 					pCoexDm->psTdmaDuAdjType = 16;
2067 				}
2068 
2069 				if (result == -1) {
2070 					if (pCoexDm->curPsTdma == 5) {
2071 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2072 						pCoexDm->psTdmaDuAdjType = 7;
2073 					} else if (pCoexDm->curPsTdma == 6) {
2074 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2075 						pCoexDm->psTdmaDuAdjType = 7;
2076 					} else if (pCoexDm->curPsTdma == 7) {
2077 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
2078 						pCoexDm->psTdmaDuAdjType = 8;
2079 					} else if (pCoexDm->curPsTdma == 13) {
2080 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2081 						pCoexDm->psTdmaDuAdjType = 15;
2082 					} else if (pCoexDm->curPsTdma == 14) {
2083 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2084 						pCoexDm->psTdmaDuAdjType = 15;
2085 					} else if (pCoexDm->curPsTdma == 15) {
2086 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
2087 						pCoexDm->psTdmaDuAdjType = 16;
2088 					}
2089 				} else if (result == 1) {
2090 					if (pCoexDm->curPsTdma == 8) {
2091 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2092 						pCoexDm->psTdmaDuAdjType = 7;
2093 					} else if (pCoexDm->curPsTdma == 7) {
2094 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2095 						pCoexDm->psTdmaDuAdjType = 7;
2096 					} else if (pCoexDm->curPsTdma == 6) {
2097 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
2098 						pCoexDm->psTdmaDuAdjType = 7;
2099 					} else if (pCoexDm->curPsTdma == 16) {
2100 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2101 						pCoexDm->psTdmaDuAdjType = 15;
2102 					} else if (pCoexDm->curPsTdma == 15) {
2103 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2104 						pCoexDm->psTdmaDuAdjType = 15;
2105 					} else if (pCoexDm->curPsTdma == 14) {
2106 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
2107 						pCoexDm->psTdmaDuAdjType = 15;
2108 					}
2109 				}
2110 			} else {
2111 				BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
2112 				if (pCoexDm->curPsTdma == 5) {
2113 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2114 					pCoexDm->psTdmaDuAdjType = 3;
2115 				} else if (pCoexDm->curPsTdma == 6) {
2116 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2117 					pCoexDm->psTdmaDuAdjType = 3;
2118 				} else if (pCoexDm->curPsTdma == 7) {
2119 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2120 					pCoexDm->psTdmaDuAdjType = 3;
2121 				} else if (pCoexDm->curPsTdma == 8) {
2122 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
2123 					pCoexDm->psTdmaDuAdjType = 4;
2124 				}
2125 
2126 				if (pCoexDm->curPsTdma == 13) {
2127 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2128 					pCoexDm->psTdmaDuAdjType = 11;
2129 				} else if (pCoexDm->curPsTdma == 14) {
2130 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2131 					pCoexDm->psTdmaDuAdjType = 11;
2132 				} else if (pCoexDm->curPsTdma == 15) {
2133 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2134 					pCoexDm->psTdmaDuAdjType = 11;
2135 				} else if (pCoexDm->curPsTdma == 16) {
2136 					halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
2137 					pCoexDm->psTdmaDuAdjType = 12;
2138 				}
2139 
2140 				if (result == -1) {
2141 					if (pCoexDm->curPsTdma == 1) {
2142 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2143 						pCoexDm->psTdmaDuAdjType = 3;
2144 					} else if (pCoexDm->curPsTdma == 2) {
2145 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2146 						pCoexDm->psTdmaDuAdjType = 3;
2147 					} else if (pCoexDm->curPsTdma == 3) {
2148 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
2149 						pCoexDm->psTdmaDuAdjType = 4;
2150 					} else if (pCoexDm->curPsTdma == 9) {
2151 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2152 						pCoexDm->psTdmaDuAdjType = 11;
2153 					} else if (pCoexDm->curPsTdma == 10) {
2154 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2155 						pCoexDm->psTdmaDuAdjType = 11;
2156 					} else if (pCoexDm->curPsTdma == 11) {
2157 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
2158 						pCoexDm->psTdmaDuAdjType = 12;
2159 					}
2160 				} else if (result == 1) {
2161 					if (pCoexDm->curPsTdma == 4) {
2162 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2163 						pCoexDm->psTdmaDuAdjType = 3;
2164 					} else if (pCoexDm->curPsTdma == 3) {
2165 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2166 						pCoexDm->psTdmaDuAdjType = 3;
2167 					} else if (pCoexDm->curPsTdma == 2) {
2168 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2169 						pCoexDm->psTdmaDuAdjType = 3;
2170 					} else if (pCoexDm->curPsTdma == 12) {
2171 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2172 						pCoexDm->psTdmaDuAdjType = 11;
2173 					} else if (pCoexDm->curPsTdma == 11) {
2174 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2175 						pCoexDm->psTdmaDuAdjType = 11;
2176 					} else if (pCoexDm->curPsTdma == 10) {
2177 						halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
2178 						pCoexDm->psTdmaDuAdjType = 11;
2179 					}
2180 				}
2181 			}
2182 		}
2183 	}
2184 
2185 	/*  if current PsTdma not match with the recorded one (when scan, dhcp...), */
2186 	/*  then we have to adjust it back to the previous record one. */
2187 	if (pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType) {
2188 		bool bScan = false, bLink = false, bRoam = false;
2189 		BTC_PRINT(
2190 			BTC_MSG_ALGORITHM,
2191 			ALGO_TRACE_FW_DETAIL,
2192 			(
2193 				"[BTCoex], PsTdma type mismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
2194 				pCoexDm->curPsTdma,
2195 				pCoexDm->psTdmaDuAdjType
2196 			)
2197 		);
2198 
2199 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2200 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2201 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2202 
2203 		if (!bScan && !bLink && !bRoam)
2204 			halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType);
2205 		else {
2206 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
2207 		}
2208 	}
2209 }
2210 
2211 /*  SCO only or SCO+PAN(HS) */
halbtc8723b2ant_ActionSco(PBTC_COEXIST pBtCoexist)2212 static void halbtc8723b2ant_ActionSco(PBTC_COEXIST pBtCoexist)
2213 {
2214 	u8 wifiRssiState, btRssiState;
2215 	u32 wifiBw;
2216 
2217 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2218 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2219 
2220 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2221 
2222 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2223 
2224 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4);
2225 
2226 	if (BTC_RSSI_HIGH(btRssiState))
2227 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2228 	else
2229 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2230 
2231 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2232 
2233 	if (BTC_WIFI_BW_LEGACY == wifiBw) /* for SCO quality at 11b/g mode */
2234 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2235 	else  /* for SCO quality & wifi performance balance at 11n mode */
2236 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
2237 
2238 	halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); /* for voice quality */
2239 
2240 	/*  sw mechanism */
2241 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2242 		if (
2243 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2244 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2245 		) {
2246 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2247 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4);
2248 		} else {
2249 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2250 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4);
2251 		}
2252 	} else {
2253 		if (
2254 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2255 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2256 		) {
2257 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2258 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4);
2259 		} else {
2260 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2261 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4);
2262 		}
2263 	}
2264 }
2265 
2266 
halbtc8723b2ant_ActionHid(PBTC_COEXIST pBtCoexist)2267 static void halbtc8723b2ant_ActionHid(PBTC_COEXIST pBtCoexist)
2268 {
2269 	u8 wifiRssiState, btRssiState;
2270 	u32 wifiBw;
2271 
2272 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2273 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2274 
2275 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2276 
2277 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2278 
2279 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2280 
2281 	if (BTC_RSSI_HIGH(btRssiState))
2282 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2283 	else
2284 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2285 
2286 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2287 
2288 	if (BTC_WIFI_BW_LEGACY == wifiBw) /* for HID at 11b/g mode */
2289 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2290 	else  /* for HID quality & wifi performance balance at 11n mode */
2291 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 9);
2292 
2293 	if (
2294 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2295 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2296 	)
2297 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
2298 	else
2299 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
2300 
2301 	/*  sw mechanism */
2302 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2303 		if (
2304 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2305 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2306 		) {
2307 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2308 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2309 		} else {
2310 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2311 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2312 		}
2313 	} else {
2314 		if (
2315 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2316 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2317 		) {
2318 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2319 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2320 		} else {
2321 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2322 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2323 		}
2324 	}
2325 }
2326 
2327 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
halbtc8723b2ant_ActionA2dp(PBTC_COEXIST pBtCoexist)2328 static void halbtc8723b2ant_ActionA2dp(PBTC_COEXIST pBtCoexist)
2329 {
2330 	u8 wifiRssiState, wifiRssiState1, btRssiState;
2331 	u32 wifiBw;
2332 	u8 apNum = 0;
2333 
2334 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2335 	wifiRssiState1 = halbtc8723b2ant_WifiRssiState(pBtCoexist, 1, 2, 40, 0);
2336 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2337 
2338 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
2339 
2340 	/*  define the office environment */
2341 	if (apNum >= 10 && BTC_RSSI_HIGH(wifiRssiState1)) {
2342 		/* DbgPrint(" AP#>10(%d)\n", apNum); */
2343 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2344 		halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2345 		halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2346 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2347 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2348 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
2349 
2350 		/*  sw mechanism */
2351 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2352 		if (BTC_WIFI_BW_HT40 == wifiBw) {
2353 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2354 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18);
2355 		} else {
2356 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2357 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18);
2358 		}
2359 		return;
2360 	}
2361 
2362 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2363 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2364 
2365 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2366 
2367 	if (BTC_RSSI_HIGH(btRssiState))
2368 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2369 	else
2370 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2371 
2372 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2373 
2374 	if (
2375 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2376 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2377 	)
2378 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 1);
2379 	else
2380 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 1);
2381 
2382 	/*  sw mechanism */
2383 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2384 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2385 		if (
2386 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2387 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2388 		) {
2389 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2390 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2391 		} else {
2392 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2393 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2394 		}
2395 	} else {
2396 		if (
2397 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2398 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2399 		) {
2400 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2401 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2402 		} else {
2403 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2404 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2405 		}
2406 	}
2407 }
2408 
halbtc8723b2ant_ActionA2dpPanHs(PBTC_COEXIST pBtCoexist)2409 static void halbtc8723b2ant_ActionA2dpPanHs(PBTC_COEXIST pBtCoexist)
2410 {
2411 	u8 wifiRssiState, btRssiState;
2412 	u32 wifiBw;
2413 
2414 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2415 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2416 
2417 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2418 
2419 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2420 
2421 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2422 
2423 	if (BTC_RSSI_HIGH(btRssiState))
2424 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2425 	else
2426 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2427 
2428 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2429 
2430 	halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 2);
2431 
2432 	/*  sw mechanism */
2433 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2434 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2435 		if (
2436 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2437 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2438 		) {
2439 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2440 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2441 		} else {
2442 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2443 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2444 		}
2445 	} else {
2446 		if (
2447 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2448 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2449 		) {
2450 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2451 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2452 		} else {
2453 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2454 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2455 		}
2456 	}
2457 }
2458 
halbtc8723b2ant_ActionPanEdr(PBTC_COEXIST pBtCoexist)2459 static void halbtc8723b2ant_ActionPanEdr(PBTC_COEXIST pBtCoexist)
2460 {
2461 	u8 wifiRssiState, btRssiState;
2462 	u32 wifiBw;
2463 
2464 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2465 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2466 
2467 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2468 
2469 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2470 
2471 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2472 
2473 	if (BTC_RSSI_HIGH(btRssiState))
2474 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2475 	else
2476 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2477 
2478 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 10);
2479 
2480 	if (
2481 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2482 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2483 	)
2484 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
2485 	else
2486 		halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
2487 
2488 	/*  sw mechanism */
2489 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2490 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2491 		if (
2492 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2493 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2494 		) {
2495 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2496 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2497 		} else {
2498 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2499 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2500 		}
2501 	} else {
2502 		if (
2503 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2504 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2505 		) {
2506 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2507 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2508 		} else {
2509 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2510 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2511 		}
2512 	}
2513 }
2514 
2515 
2516 /* PAN(HS) only */
halbtc8723b2ant_ActionPanHs(PBTC_COEXIST pBtCoexist)2517 static void halbtc8723b2ant_ActionPanHs(PBTC_COEXIST pBtCoexist)
2518 {
2519 	u8 wifiRssiState, btRssiState;
2520 	u32 wifiBw;
2521 
2522 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2523 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2524 
2525 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2526 
2527 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2528 
2529 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2530 
2531 	if (BTC_RSSI_HIGH(btRssiState))
2532 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2533 	else
2534 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2535 
2536 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2537 
2538 	halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
2539 
2540 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2541 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2542 		if (
2543 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2544 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2545 		) {
2546 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2547 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2548 		} else {
2549 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2550 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2551 		}
2552 	} else {
2553 		if (
2554 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2555 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2556 		) {
2557 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2558 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2559 		} else {
2560 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2561 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2562 		}
2563 	}
2564 }
2565 
2566 /* PAN(EDR)+A2DP */
halbtc8723b2ant_ActionPanEdrA2dp(PBTC_COEXIST pBtCoexist)2567 static void halbtc8723b2ant_ActionPanEdrA2dp(PBTC_COEXIST pBtCoexist)
2568 {
2569 	u8 wifiRssiState, btRssiState;
2570 	u32 wifiBw;
2571 
2572 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2573 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2574 
2575 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2576 
2577 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2578 
2579 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2580 
2581 	if (BTC_RSSI_HIGH(btRssiState))
2582 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2583 	else
2584 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2585 
2586 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2587 
2588 	if (
2589 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2590 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2591 	) {
2592 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);
2593 		if (BTC_WIFI_BW_HT40 == wifiBw)
2594 			halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 3);
2595 		else
2596 			halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 3);
2597 	} else {
2598 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2599 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 3);
2600 	}
2601 
2602 	/*  sw mechanism */
2603 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2604 		if (
2605 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2606 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2607 		) {
2608 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2609 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2610 		} else {
2611 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2612 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2613 		}
2614 	} else {
2615 		if (
2616 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2617 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2618 		) {
2619 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2620 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2621 		} else {
2622 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2623 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2624 		}
2625 	}
2626 }
2627 
halbtc8723b2ant_ActionPanEdrHid(PBTC_COEXIST pBtCoexist)2628 static void halbtc8723b2ant_ActionPanEdrHid(PBTC_COEXIST pBtCoexist)
2629 {
2630 	u8 wifiRssiState, btRssiState;
2631 	u32 wifiBw;
2632 
2633 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2634 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2635 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2636 
2637 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2638 
2639 	if (BTC_RSSI_HIGH(btRssiState))
2640 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2641 	else
2642 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2643 
2644 	if (
2645 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2646 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2647 	) {
2648 		if (BTC_WIFI_BW_HT40 == wifiBw) {
2649 			halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 3);
2650 			halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);
2651 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
2652 		} else {
2653 			halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2654 			halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2655 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2656 		}
2657 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 2);
2658 	} else {
2659 		halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2660 		halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);
2661 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2662 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2);
2663 	}
2664 
2665 	/*  sw mechanism */
2666 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2667 		if (
2668 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2669 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2670 		) {
2671 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2672 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2673 		} else {
2674 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2675 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2676 		}
2677 	} else {
2678 		if (
2679 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2680 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2681 		) {
2682 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2683 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2684 		} else {
2685 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2686 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2687 		}
2688 	}
2689 }
2690 
2691 /*  HID+A2DP+PAN(EDR) */
halbtc8723b2ant_ActionHidA2dpPanEdr(PBTC_COEXIST pBtCoexist)2692 static void halbtc8723b2ant_ActionHidA2dpPanEdr(PBTC_COEXIST pBtCoexist)
2693 {
2694 	u8 wifiRssiState, btRssiState;
2695 	u32 wifiBw;
2696 
2697 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2698 	btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2699 
2700 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2701 
2702 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2703 
2704 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2705 
2706 	if (BTC_RSSI_HIGH(btRssiState))
2707 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2708 	else
2709 		halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2710 
2711 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2712 
2713 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2714 
2715 	if (
2716 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2717 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2718 	) {
2719 		if (BTC_WIFI_BW_HT40 == wifiBw)
2720 			halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2);
2721 		else
2722 			halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 3);
2723 	} else
2724 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 3);
2725 
2726 	/*  sw mechanism */
2727 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2728 		if (
2729 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2730 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2731 		) {
2732 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2733 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2734 		} else {
2735 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2736 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2737 		}
2738 	} else {
2739 		if (
2740 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2741 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2742 		) {
2743 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2744 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2745 		} else {
2746 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2747 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2748 		}
2749 	}
2750 }
2751 
halbtc8723b2ant_ActionHidA2dp(PBTC_COEXIST pBtCoexist)2752 static void halbtc8723b2ant_ActionHidA2dp(PBTC_COEXIST pBtCoexist)
2753 {
2754 	u8 wifiRssiState, btRssiState;
2755 	u32 wifiBw;
2756 	u8 apNum = 0;
2757 
2758 	wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2759 	/* btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); */
2760 	btRssiState = halbtc8723b2ant_BtRssiState(3, 29, 37);
2761 
2762 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2763 
2764 	halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5);
2765 
2766 	halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2767 
2768 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2769 	if (BTC_WIFI_BW_LEGACY == wifiBw) {
2770 		if (BTC_RSSI_HIGH(btRssiState))
2771 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2772 		else if (BTC_RSSI_MEDIUM(btRssiState))
2773 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2774 		else
2775 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2776 	} else {
2777 		/*  only 802.11N mode we have to dec bt power to 4 degree */
2778 		if (BTC_RSSI_HIGH(btRssiState)) {
2779 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
2780 			/*  need to check ap Number of Not */
2781 			if (apNum < 10)
2782 				halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
2783 			else
2784 				halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2785 		} else if (BTC_RSSI_MEDIUM(btRssiState))
2786 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2787 		else
2788 			halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2789 	}
2790 
2791 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2792 
2793 	if (
2794 		(btRssiState == BTC_RSSI_STATE_HIGH) ||
2795 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2796 	)
2797 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 2);
2798 	else
2799 		halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2);
2800 
2801 	/*  sw mechanism */
2802 	if (BTC_WIFI_BW_HT40 == wifiBw) {
2803 		if (
2804 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2805 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2806 		) {
2807 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2808 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2809 		} else {
2810 			halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2811 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2812 		}
2813 	} else {
2814 		if (
2815 			(wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2816 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2817 		) {
2818 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2819 			halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2820 		} else {
2821 			halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2822 			halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2823 		}
2824 	}
2825 }
2826 
halbtc8723b2ant_RunCoexistMechanism(PBTC_COEXIST pBtCoexist)2827 static void halbtc8723b2ant_RunCoexistMechanism(PBTC_COEXIST pBtCoexist)
2828 {
2829 	u8 algorithm = 0;
2830 
2831 	BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism() ===>\n"));
2832 
2833 	if (pBtCoexist->bManualControl) {
2834 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
2835 		return;
2836 	}
2837 
2838 	if (pCoexSta->bUnderIps) {
2839 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));
2840 		return;
2841 	}
2842 
2843 	algorithm = halbtc8723b2ant_ActionAlgorithm(pBtCoexist);
2844 	if (pCoexSta->bC2hBtInquiryPage && (BT_8723B_2ANT_COEX_ALGO_PANHS != algorithm)) {
2845 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT is under inquiry/page scan !!\n"));
2846 		halbtc8723b2ant_ActionBtInquiry(pBtCoexist);
2847 		return;
2848 	} else {
2849 		if (pCoexDm->bNeedRecover0x948) {
2850 			pCoexDm->bNeedRecover0x948 = false;
2851 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, pCoexDm->backup0x948);
2852 		}
2853 	}
2854 
2855 	pCoexDm->curAlgorithm = algorithm;
2856 	BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Algorithm = %d\n", pCoexDm->curAlgorithm));
2857 
2858 	if (halbtc8723b2ant_IsCommonAction(pBtCoexist)) {
2859 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant common.\n"));
2860 		pCoexDm->bAutoTdmaAdjust = false;
2861 	} else {
2862 		if (pCoexDm->curAlgorithm != pCoexDm->preAlgorithm) {
2863 			BTC_PRINT(
2864 				BTC_MSG_ALGORITHM,
2865 				ALGO_TRACE,
2866 				(
2867 					"[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
2868 					pCoexDm->preAlgorithm,
2869 					pCoexDm->curAlgorithm
2870 				)
2871 			);
2872 			pCoexDm->bAutoTdmaAdjust = false;
2873 		}
2874 
2875 
2876 		switch (pCoexDm->curAlgorithm) {
2877 		case BT_8723B_2ANT_COEX_ALGO_SCO:
2878 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));
2879 			halbtc8723b2ant_ActionSco(pBtCoexist);
2880 			break;
2881 		case BT_8723B_2ANT_COEX_ALGO_HID:
2882 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));
2883 			halbtc8723b2ant_ActionHid(pBtCoexist);
2884 			break;
2885 		case BT_8723B_2ANT_COEX_ALGO_A2DP:
2886 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));
2887 			halbtc8723b2ant_ActionA2dp(pBtCoexist);
2888 			break;
2889 		case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS:
2890 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));
2891 			halbtc8723b2ant_ActionA2dpPanHs(pBtCoexist);
2892 			break;
2893 		case BT_8723B_2ANT_COEX_ALGO_PANEDR:
2894 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));
2895 			halbtc8723b2ant_ActionPanEdr(pBtCoexist);
2896 			break;
2897 		case BT_8723B_2ANT_COEX_ALGO_PANHS:
2898 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));
2899 			halbtc8723b2ant_ActionPanHs(pBtCoexist);
2900 			break;
2901 		case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP:
2902 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));
2903 			halbtc8723b2ant_ActionPanEdrA2dp(pBtCoexist);
2904 			break;
2905 		case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID:
2906 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
2907 			halbtc8723b2ant_ActionPanEdrHid(pBtCoexist);
2908 			break;
2909 		case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
2910 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
2911 			halbtc8723b2ant_ActionHidA2dpPanEdr(pBtCoexist);
2912 			break;
2913 		case BT_8723B_2ANT_COEX_ALGO_HID_A2DP:
2914 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));
2915 			halbtc8723b2ant_ActionHidA2dp(pBtCoexist);
2916 			break;
2917 		default:
2918 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));
2919 			halbtc8723b2ant_CoexAllOff(pBtCoexist);
2920 			break;
2921 		}
2922 		pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
2923 	}
2924 }
2925 
halbtc8723b2ant_WifiOffHwCfg(PBTC_COEXIST pBtCoexist)2926 static void halbtc8723b2ant_WifiOffHwCfg(PBTC_COEXIST pBtCoexist)
2927 {
2928 	bool bIsInMpMode = false;
2929 	u8 H2C_Parameter[2] = {0};
2930 	u32 fwVer = 0;
2931 
2932 	/*  set wlan_act to low */
2933 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
2934 
2935 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi goto standby while GNT_BT 0-->1 */
2936 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
2937 	if (fwVer >= 0x180000) {
2938 		/* Use H2C to set GNT_BT to HIGH */
2939 		H2C_Parameter[0] = 1;
2940 		pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
2941 	} else
2942 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2943 
2944 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
2945 	if (!bIsInMpMode)
2946 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */
2947 	else
2948 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
2949 }
2950 
halbtc8723b2ant_InitHwConfig(PBTC_COEXIST pBtCoexist,bool bBackUp)2951 static void halbtc8723b2ant_InitHwConfig(PBTC_COEXIST pBtCoexist, bool bBackUp)
2952 {
2953 	u8 u1Tmp = 0;
2954 
2955 	BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 2Ant Init HW Config!!\n"));
2956 
2957 	/*  backup rf 0x1e value */
2958 	pCoexDm->btRf0x1eBackup =
2959 		pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);
2960 
2961 	/*  0x790[5:0]= 0x5 */
2962 	u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);
2963 	u1Tmp &= 0xc0;
2964 	u1Tmp |= 0x5;
2965 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);
2966 
2967 	/* Antenna config */
2968 	halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, true, false);
2969 
2970 	/*  PTA parameter */
2971 	halbtc8723b2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2972 
2973 	/*  Enable counter statistics */
2974 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); /* 0x76e[3] = 1, WLAN_Act control by PTA */
2975 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);
2976 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
2977 }
2978 
2979 /*  */
2980 /*  work around function start with wa_halbtc8723b2ant_ */
2981 /*  */
2982 /*  */
2983 /*  extern function start with EXhalbtc8723b2ant_ */
2984 /*  */
EXhalbtc8723b2ant_PowerOnSetting(PBTC_COEXIST pBtCoexist)2985 void EXhalbtc8723b2ant_PowerOnSetting(PBTC_COEXIST pBtCoexist)
2986 {
2987 	PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
2988 	u8 u1Tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
2989 	u16 u2Tmp = 0x0;
2990 
2991 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);
2992 
2993 	/*  enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2994 	u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
2995 	pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
2996 
2997 	/*  set GRAN_BT = 1 */
2998 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2999 	/*  set WLAN_ACT = 0 */
3000 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
3001 
3002 	/*  */
3003 	/*  S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
3004 	/*  Local setting bit define */
3005 	/* 	BIT0: "0" for no antenna inverse; "1" for antenna inverse */
3006 	/* 	BIT1: "0" for internal switch; "1" for external switch */
3007 	/* 	BIT2: "0" for one antenna; "1" for two antenna */
3008 	/*  NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */
3009 	if (pBtCoexist->chipInterface == BTC_INTF_USB) {
3010 		/*  fixed at S0 for USB interface */
3011 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
3012 
3013 		u1Tmp |= 0x1;	/*  antenna inverse */
3014 		pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
3015 
3016 		pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
3017 	} else {
3018 		/*  for PCIE and SDIO interface, we check efuse 0xc3[6] */
3019 		if (pBoardInfo->singleAntPath == 0) {
3020 			/*  set to S1 */
3021 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
3022 			pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
3023 		} else if (pBoardInfo->singleAntPath == 1) {
3024 			/*  set to S0 */
3025 			pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
3026 			u1Tmp |= 0x1;	/*  antenna inverse */
3027 			pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
3028 		}
3029 
3030 		if (pBtCoexist->chipInterface == BTC_INTF_PCI)
3031 			pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
3032 		else if (pBtCoexist->chipInterface == BTC_INTF_SDIO)
3033 			pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
3034 	}
3035 }
3036 
EXhalbtc8723b2ant_InitHwConfig(PBTC_COEXIST pBtCoexist,bool bWifiOnly)3037 void EXhalbtc8723b2ant_InitHwConfig(PBTC_COEXIST pBtCoexist, bool bWifiOnly)
3038 {
3039 	halbtc8723b2ant_InitHwConfig(pBtCoexist, true);
3040 }
3041 
EXhalbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)3042 void EXhalbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)
3043 {
3044 	BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));
3045 
3046 	halbtc8723b2ant_InitCoexDm(pBtCoexist);
3047 }
3048 
EXhalbtc8723b2ant_DisplayCoexInfo(PBTC_COEXIST pBtCoexist)3049 void EXhalbtc8723b2ant_DisplayCoexInfo(PBTC_COEXIST pBtCoexist)
3050 {
3051 	PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
3052 	PBTC_STACK_INFO pStackInfo = &pBtCoexist->stackInfo;
3053 	PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
3054 	u8 *cliBuf = pBtCoexist->cliBuf;
3055 	u8 u1Tmp[4], i, btInfoExt, psTdmaCase = 0;
3056 	u32 u4Tmp[4];
3057 	bool bRoam = false, bScan = false, bLink = false, bWifiUnder5G = false;
3058 	bool bBtHsOn = false, bWifiBusy = false;
3059 	s32 wifiRssi = 0, btHsRssi = 0;
3060 	u32 wifiBw, wifiTrafficDir, faOfdm, faCck;
3061 	u8 wifiDot11Chnl, wifiHsChnl;
3062 	u32 fwVer = 0, btPatchVer = 0;
3063 	u8 apNum = 0;
3064 
3065 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
3066 	CL_PRINTF(cliBuf);
3067 
3068 	if (pBtCoexist->bManualControl) {
3069 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
3070 		CL_PRINTF(cliBuf);
3071 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
3072 		CL_PRINTF(cliBuf);
3073 	}
3074 
3075 	CL_SPRINTF(
3076 		cliBuf,
3077 		BT_TMP_BUF_SIZE,
3078 		"\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
3079 		pBoardInfo->pgAntNum,
3080 		pBoardInfo->btdmAntNum
3081 	);
3082 	CL_PRINTF(cliBuf);
3083 
3084 	CL_SPRINTF(
3085 		cliBuf,
3086 		BT_TMP_BUF_SIZE,
3087 		"\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
3088 		(pStackInfo->bProfileNotified ? "Yes" : "No"),
3089 		pStackInfo->hciVersion
3090 	);
3091 	CL_PRINTF(cliBuf);
3092 
3093 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
3094 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
3095 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
3096 		GLCoexVerDate8723b2Ant, GLCoexVer8723b2Ant, fwVer, btPatchVer, btPatchVer);
3097 	CL_PRINTF(cliBuf);
3098 
3099 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3100 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);
3101 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);
3102 	CL_SPRINTF(
3103 		cliBuf,
3104 		BT_TMP_BUF_SIZE,
3105 		"\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \
3106 		wifiDot11Chnl,
3107 		wifiHsChnl,
3108 		bBtHsOn
3109 	);
3110 	CL_PRINTF(cliBuf);
3111 
3112 	CL_SPRINTF(
3113 		cliBuf,
3114 		BT_TMP_BUF_SIZE,
3115 		"\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \
3116 		pCoexDm->wifiChnlInfo[0],
3117 		pCoexDm->wifiChnlInfo[1],
3118 		pCoexDm->wifiChnlInfo[2]
3119 	);
3120 	CL_PRINTF(cliBuf);
3121 
3122 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
3123 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
3124 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
3125 	CL_SPRINTF(
3126 		cliBuf,
3127 		BT_TMP_BUF_SIZE,
3128 		"\r\n %-35s = %d/ %d/ %d", "Wifi rssi/ HS rssi/ AP#", \
3129 		wifiRssi,
3130 		btHsRssi,
3131 		apNum
3132 	);
3133 	CL_PRINTF(cliBuf);
3134 
3135 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
3136 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
3137 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
3138 	CL_SPRINTF(
3139 		cliBuf,
3140 		BT_TMP_BUF_SIZE,
3141 		"\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
3142 		bLink,
3143 		bRoam,
3144 		bScan
3145 	);
3146 	CL_PRINTF(cliBuf);
3147 
3148 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
3149 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3150 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
3151 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
3152 	CL_SPRINTF(
3153 		cliBuf,
3154 		BT_TMP_BUF_SIZE,
3155 		"\r\n %-35s = %s / %s/ %s ", "Wifi status", \
3156 		(bWifiUnder5G ? "5G" : "2.4G"),
3157 		((BTC_WIFI_BW_LEGACY == wifiBw) ? "Legacy" : (((BTC_WIFI_BW_HT40 == wifiBw) ? "HT40" : "HT20"))),
3158 		((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink"))
3159 	);
3160 	CL_PRINTF(cliBuf);
3161 
3162 	CL_SPRINTF(
3163 		cliBuf,
3164 		BT_TMP_BUF_SIZE,
3165 		"\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \
3166 		((pBtCoexist->btInfo.bBtDisabled) ? ("disabled") : ((pCoexSta->bC2hBtInquiryPage) ? ("inquiry/page scan") : ((BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) ? "non-connected idle" :
3167 		((BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) ? "connected-idle" : "busy")))),
3168 		pCoexSta->btRssi,
3169 		pCoexSta->btRetryCnt
3170 	);
3171 	CL_PRINTF(cliBuf);
3172 
3173 	CL_SPRINTF(
3174 		cliBuf,
3175 		BT_TMP_BUF_SIZE,
3176 		"\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
3177 		pBtLinkInfo->bScoExist,
3178 		pBtLinkInfo->bHidExist,
3179 		pBtLinkInfo->bPanExist,
3180 		pBtLinkInfo->bA2dpExist
3181 	);
3182 	CL_PRINTF(cliBuf);
3183 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
3184 
3185 	btInfoExt = pCoexSta->btInfoExt;
3186 	CL_SPRINTF(
3187 		cliBuf,
3188 		BT_TMP_BUF_SIZE,
3189 		"\r\n %-35s = %s", "BT Info A2DP rate", \
3190 		(btInfoExt&BIT0) ? "Basic rate" : "EDR rate"
3191 	);
3192 	CL_PRINTF(cliBuf);
3193 
3194 	for (i = 0; i < BT_INFO_SRC_8723B_2ANT_MAX; i++) {
3195 		if (pCoexSta->btInfoC2hCnt[i]) {
3196 			CL_SPRINTF(
3197 				cliBuf,
3198 				BT_TMP_BUF_SIZE,
3199 				"\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b2Ant[i], \
3200 				pCoexSta->btInfoC2h[i][0],
3201 				pCoexSta->btInfoC2h[i][1],
3202 				pCoexSta->btInfoC2h[i][2],
3203 				pCoexSta->btInfoC2h[i][3],
3204 				pCoexSta->btInfoC2h[i][4],
3205 				pCoexSta->btInfoC2h[i][5],
3206 				pCoexSta->btInfoC2h[i][6],
3207 				pCoexSta->btInfoC2hCnt[i]
3208 			);
3209 			CL_PRINTF(cliBuf);
3210 		}
3211 	}
3212 
3213 	CL_SPRINTF(
3214 		cliBuf,
3215 		BT_TMP_BUF_SIZE,
3216 		"\r\n %-35s = %s/%s", "PS state, IPS/LPS", \
3217 		((pCoexSta->bUnderIps ? "IPS ON" : "IPS OFF")),
3218 		((pCoexSta->bUnderLps ? "LPS ON" : "LPS OFF"))
3219 	);
3220 	CL_PRINTF(cliBuf);
3221 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3222 
3223 	/*  Sw mechanism */
3224 	CL_SPRINTF(
3225 		cliBuf,
3226 		BT_TMP_BUF_SIZE,
3227 		"\r\n %-35s", "============[Sw mechanism]============"
3228 	);
3229 	CL_PRINTF(cliBuf);
3230 	CL_SPRINTF(
3231 		cliBuf,
3232 		BT_TMP_BUF_SIZE,
3233 		"\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \
3234 		pCoexDm->bCurRfRxLpfShrink,
3235 		pCoexDm->bCurLowPenaltyRa,
3236 		pCoexDm->bLimitedDig
3237 	);
3238 	CL_PRINTF(cliBuf);
3239 	CL_SPRINTF(
3240 		cliBuf,
3241 		BT_TMP_BUF_SIZE,
3242 		"\r\n %-35s = %d/ %d/ %d(0x%x) ",
3243 		"SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \
3244 		pCoexDm->bCurAgcTableEn,
3245 		pCoexDm->bCurAdcBackOff,
3246 		pCoexDm->bCurDacSwingOn,
3247 		pCoexDm->curDacSwingLvl
3248 	);
3249 	CL_PRINTF(cliBuf);
3250 
3251 	/*  Fw mechanism */
3252 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
3253 	CL_PRINTF(cliBuf);
3254 
3255 	psTdmaCase = pCoexDm->curPsTdma;
3256 	CL_SPRINTF(
3257 		cliBuf,
3258 		BT_TMP_BUF_SIZE,
3259 		"\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \
3260 		pCoexDm->psTdmaPara[0],
3261 		pCoexDm->psTdmaPara[1],
3262 		pCoexDm->psTdmaPara[2],
3263 		pCoexDm->psTdmaPara[3],
3264 		pCoexDm->psTdmaPara[4],
3265 		psTdmaCase, pCoexDm->bAutoTdmaAdjust
3266 	);
3267 	CL_PRINTF(cliBuf);
3268 
3269 	CL_SPRINTF(
3270 		cliBuf,
3271 		BT_TMP_BUF_SIZE,
3272 		"\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \
3273 		pCoexDm->curBtDecPwrLvl,
3274 		pCoexDm->bCurIgnoreWlanAct
3275 	);
3276 	CL_PRINTF(cliBuf);
3277 
3278 	/*  Hw setting */
3279 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
3280 	CL_PRINTF(cliBuf);
3281 
3282 	CL_SPRINTF(
3283 		cliBuf,
3284 		BT_TMP_BUF_SIZE,
3285 		"\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
3286 		pCoexDm->btRf0x1eBackup
3287 	);
3288 	CL_PRINTF(cliBuf);
3289 
3290 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
3291 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
3292 	CL_SPRINTF(
3293 		cliBuf,
3294 		BT_TMP_BUF_SIZE,
3295 		"\r\n %-35s = 0x%x/ 0x%x", "0x778/0x880[29:25]", \
3296 		u1Tmp[0],
3297 		(u4Tmp[0]&0x3e000000) >> 25
3298 	);
3299 	CL_PRINTF(cliBuf);
3300 
3301 
3302 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
3303 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
3304 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
3305 	CL_SPRINTF(
3306 		cliBuf,
3307 		BT_TMP_BUF_SIZE,
3308 		"\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x765", \
3309 		u4Tmp[0],
3310 		((u1Tmp[0]&0x20)>>5),
3311 		u1Tmp[1]
3312 	);
3313 	CL_PRINTF(cliBuf);
3314 
3315 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);
3316 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);
3317 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);
3318 	CL_SPRINTF(
3319 		cliBuf,
3320 		BT_TMP_BUF_SIZE,
3321 		"\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", \
3322 		u4Tmp[0]&0x3,
3323 		u4Tmp[1]&0xff,
3324 		u4Tmp[2]&0x3
3325 	);
3326 	CL_PRINTF(cliBuf);
3327 
3328 
3329 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);
3330 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
3331 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
3332 	u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);
3333 	CL_SPRINTF(
3334 		cliBuf,
3335 		BT_TMP_BUF_SIZE,
3336 		"\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]", \
3337 		((u1Tmp[0] & 0x8)>>3),
3338 		u1Tmp[1],
3339 		((u4Tmp[0]&0x01800000)>>23),
3340 		u1Tmp[2]&0x1
3341 	);
3342 	CL_PRINTF(cliBuf);
3343 
3344 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
3345 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
3346 	CL_SPRINTF(
3347 		cliBuf,
3348 		BT_TMP_BUF_SIZE,
3349 		"\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
3350 		u4Tmp[0],
3351 		u1Tmp[0]
3352 	);
3353 	CL_PRINTF(cliBuf);
3354 
3355 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
3356 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);
3357 	CL_SPRINTF(
3358 		cliBuf,
3359 		BT_TMP_BUF_SIZE,
3360 		"\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \
3361 		u4Tmp[0]&0xff,
3362 		u1Tmp[0]
3363 	);
3364 	CL_PRINTF(cliBuf);
3365 
3366 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
3367 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
3368 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
3369 	u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
3370 
3371 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
3372 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
3373 
3374 	faOfdm =
3375 		((u4Tmp[0]&0xffff0000) >> 16) +
3376 		((u4Tmp[1]&0xffff0000) >> 16) +
3377 		(u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \
3378 		((u4Tmp[3]&0xffff0000) >> 16) +
3379 		(u4Tmp[3] & 0xffff);
3380 
3381 	faCck = (u1Tmp[0] << 8) + u1Tmp[1];
3382 
3383 	CL_SPRINTF(
3384 		cliBuf,
3385 		BT_TMP_BUF_SIZE,
3386 		"\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \
3387 		u4Tmp[0]&0xffff,
3388 		faOfdm,
3389 		faCck
3390 	);
3391 	CL_PRINTF(cliBuf);
3392 
3393 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
3394 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
3395 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
3396 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);
3397 	CL_SPRINTF(
3398 		cliBuf,
3399 		BT_TMP_BUF_SIZE,
3400 		"\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
3401 		u4Tmp[0],
3402 		u4Tmp[1],
3403 		u4Tmp[2],
3404 		u1Tmp[0]
3405 	);
3406 	CL_PRINTF(cliBuf);
3407 
3408 	CL_SPRINTF(
3409 		cliBuf,
3410 		BT_TMP_BUF_SIZE,
3411 		"\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
3412 		pCoexSta->highPriorityRx,
3413 		pCoexSta->highPriorityTx
3414 	);
3415 	CL_PRINTF(cliBuf);
3416 	CL_SPRINTF(
3417 		cliBuf,
3418 		BT_TMP_BUF_SIZE,
3419 		"\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
3420 		pCoexSta->lowPriorityRx,
3421 		pCoexSta->lowPriorityTx
3422 	);
3423 	CL_PRINTF(cliBuf);
3424 
3425 	halbtc8723b2ant_MonitorBtCtr(pBtCoexist);
3426 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
3427 }
3428 
3429 
EXhalbtc8723b2ant_IpsNotify(PBTC_COEXIST pBtCoexist,u8 type)3430 void EXhalbtc8723b2ant_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
3431 {
3432 	if (BTC_IPS_ENTER == type) {
3433 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));
3434 		pCoexSta->bUnderIps = true;
3435 		halbtc8723b2ant_WifiOffHwCfg(pBtCoexist);
3436 		halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
3437 		halbtc8723b2ant_CoexAllOff(pBtCoexist);
3438 	} else if (BTC_IPS_LEAVE == type) {
3439 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));
3440 		pCoexSta->bUnderIps = false;
3441 		halbtc8723b2ant_InitHwConfig(pBtCoexist, false);
3442 		halbtc8723b2ant_InitCoexDm(pBtCoexist);
3443 		halbtc8723b2ant_QueryBtInfo(pBtCoexist);
3444 	}
3445 }
3446 
EXhalbtc8723b2ant_LpsNotify(PBTC_COEXIST pBtCoexist,u8 type)3447 void EXhalbtc8723b2ant_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
3448 {
3449 	if (BTC_LPS_ENABLE == type) {
3450 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));
3451 		pCoexSta->bUnderLps = true;
3452 	} else if (BTC_LPS_DISABLE == type) {
3453 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));
3454 		pCoexSta->bUnderLps = false;
3455 	}
3456 }
3457 
EXhalbtc8723b2ant_ScanNotify(PBTC_COEXIST pBtCoexist,u8 type)3458 void EXhalbtc8723b2ant_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
3459 {
3460 	if (BTC_SCAN_START == type) {
3461 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));
3462 	} else if (BTC_SCAN_FINISH == type) {
3463 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));
3464 	}
3465 }
3466 
EXhalbtc8723b2ant_ConnectNotify(PBTC_COEXIST pBtCoexist,u8 type)3467 void EXhalbtc8723b2ant_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 type)
3468 {
3469 	if (BTC_ASSOCIATE_START == type) {
3470 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));
3471 	} else if (BTC_ASSOCIATE_FINISH == type) {
3472 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));
3473 	}
3474 }
3475 
EXhalbtc8723b2ant_MediaStatusNotify(PBTC_COEXIST pBtCoexist,u8 type)3476 void EXhalbtc8723b2ant_MediaStatusNotify(PBTC_COEXIST pBtCoexist, u8 type)
3477 {
3478 	u8 H2C_Parameter[3] = {0};
3479 	u32 wifiBw;
3480 	u8 wifiCentralChnl;
3481 	u8 apNum = 0;
3482 
3483 	if (BTC_MEDIA_CONNECT == type) {
3484 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));
3485 	} else {
3486 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));
3487 	}
3488 
3489 	/*  only 2.4G we need to inform bt the chnl mask */
3490 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
3491 	if ((BTC_MEDIA_CONNECT == type) && (wifiCentralChnl <= 14)) {
3492 		H2C_Parameter[0] = 0x1;
3493 		H2C_Parameter[1] = wifiCentralChnl;
3494 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3495 		if (BTC_WIFI_BW_HT40 == wifiBw)
3496 			H2C_Parameter[2] = 0x30;
3497 		else {
3498 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
3499 			if (apNum < 10)
3500 				H2C_Parameter[2] = 0x30;
3501 			else
3502 				H2C_Parameter[2] = 0x20;
3503 		}
3504 	}
3505 
3506 	pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
3507 	pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
3508 	pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
3509 
3510 	BTC_PRINT(
3511 		BTC_MSG_ALGORITHM,
3512 		ALGO_TRACE_FW_EXEC,
3513 		(
3514 			"[BTCoex], FW write 0x66 = 0x%x\n",
3515 			H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]
3516 		)
3517 	);
3518 
3519 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
3520 }
3521 
EXhalbtc8723b2ant_SpecialPacketNotify(PBTC_COEXIST pBtCoexist,u8 type)3522 void EXhalbtc8723b2ant_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 type)
3523 {
3524 	if (type == BTC_PACKET_DHCP) {
3525 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n"));
3526 	}
3527 }
3528 
EXhalbtc8723b2ant_BtInfoNotify(PBTC_COEXIST pBtCoexist,u8 * tmpBuf,u8 length)3529 void EXhalbtc8723b2ant_BtInfoNotify(
3530 	PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length
3531 )
3532 {
3533 	u8 	btInfo = 0;
3534 	u8 	i, rspSource = 0;
3535 	bool bBtBusy = false, bLimitedDig = false;
3536 	bool bWifiConnected = false;
3537 
3538 	pCoexSta->bC2hBtInfoReqSent = false;
3539 
3540 	rspSource = tmpBuf[0]&0xf;
3541 	if (rspSource >= BT_INFO_SRC_8723B_2ANT_MAX)
3542 		rspSource = BT_INFO_SRC_8723B_2ANT_WIFI_FW;
3543 
3544 	pCoexSta->btInfoC2hCnt[rspSource]++;
3545 
3546 	BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length =%d, hex data =[", rspSource, length));
3547 	for (i = 0; i < length; i++) {
3548 		pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
3549 		if (i == 1)
3550 			btInfo = tmpBuf[i];
3551 
3552 		if (i == length-1) {
3553 			BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));
3554 		} else {
3555 			BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));
3556 		}
3557 	}
3558 
3559 	if (pBtCoexist->bManualControl) {
3560 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));
3561 		return;
3562 	}
3563 
3564 	if (BT_INFO_SRC_8723B_2ANT_WIFI_FW != rspSource) {
3565 		pCoexSta->btRetryCnt = pCoexSta->btInfoC2h[rspSource][2]&0xf; /* [3:0] */
3566 
3567 		pCoexSta->btRssi = pCoexSta->btInfoC2h[rspSource][3]*2+10;
3568 
3569 		pCoexSta->btInfoExt = pCoexSta->btInfoC2h[rspSource][4];
3570 
3571 		pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
3572 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
3573 		if (pCoexSta->bBtTxRxMask) {
3574 			/* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */
3575 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"));
3576 			pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01);
3577 		}
3578 
3579 		/*  Here we need to resend some wifi info to BT */
3580 		/*  because bt is reset and loss of the info. */
3581 		if ((pCoexSta->btInfoExt & BIT1)) {
3582 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
3583 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3584 
3585 			if (bWifiConnected)
3586 				EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
3587 			else
3588 				EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3589 		}
3590 
3591 		if ((pCoexSta->btInfoExt & BIT3)) {
3592 			BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
3593 			halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false);
3594 		} else {
3595 			/*  BT already NOT ignore Wlan active, do nothing here. */
3596 		}
3597 	}
3598 
3599 	/*  check BIT2 first ==> check if bt is under inquiry or page scan */
3600 	if (btInfo & BT_INFO_8723B_2ANT_B_INQ_PAGE)
3601 		pCoexSta->bC2hBtInquiryPage = true;
3602 	else
3603 		pCoexSta->bC2hBtInquiryPage = false;
3604 
3605 	/*  set link exist status */
3606 	if (!(btInfo&BT_INFO_8723B_2ANT_B_CONNECTION)) {
3607 		pCoexSta->bBtLinkExist = false;
3608 		pCoexSta->bPanExist = false;
3609 		pCoexSta->bA2dpExist = false;
3610 		pCoexSta->bHidExist = false;
3611 		pCoexSta->bScoExist = false;
3612 	} else { /*  connection exists */
3613 		pCoexSta->bBtLinkExist = true;
3614 		if (btInfo & BT_INFO_8723B_2ANT_B_FTP)
3615 			pCoexSta->bPanExist = true;
3616 		else
3617 			pCoexSta->bPanExist = false;
3618 		if (btInfo & BT_INFO_8723B_2ANT_B_A2DP)
3619 			pCoexSta->bA2dpExist = true;
3620 		else
3621 			pCoexSta->bA2dpExist = false;
3622 		if (btInfo & BT_INFO_8723B_2ANT_B_HID)
3623 			pCoexSta->bHidExist = true;
3624 		else
3625 			pCoexSta->bHidExist = false;
3626 		if (btInfo & BT_INFO_8723B_2ANT_B_SCO_ESCO)
3627 			pCoexSta->bScoExist = true;
3628 		else
3629 			pCoexSta->bScoExist = false;
3630 	}
3631 
3632 	halbtc8723b2ant_UpdateBtLinkInfo(pBtCoexist);
3633 
3634 	if (!(btInfo&BT_INFO_8723B_2ANT_B_CONNECTION)) {
3635 		pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
3636 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
3637 	} else if (btInfo == BT_INFO_8723B_2ANT_B_CONNECTION)	{ /*  connection exists but no busy */
3638 		pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE;
3639 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
3640 	} else if (
3641 		(btInfo&BT_INFO_8723B_2ANT_B_SCO_ESCO) ||
3642 		(btInfo&BT_INFO_8723B_2ANT_B_SCO_BUSY)
3643 	) {
3644 		pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_SCO_BUSY;
3645 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
3646 	} else if (btInfo&BT_INFO_8723B_2ANT_B_ACL_BUSY) {
3647 		pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_ACL_BUSY;
3648 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
3649 	} else {
3650 		pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_MAX;
3651 		BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
3652 	}
3653 
3654 	if (
3655 		(BT_8723B_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
3656 		(BT_8723B_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3657 		(BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus)
3658 	) {
3659 		bBtBusy = true;
3660 		bLimitedDig = true;
3661 	} else {
3662 		bBtBusy = false;
3663 		bLimitedDig = false;
3664 	}
3665 
3666 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
3667 
3668 	pCoexDm->bLimitedDig = bLimitedDig;
3669 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);
3670 
3671 	halbtc8723b2ant_RunCoexistMechanism(pBtCoexist);
3672 }
3673 
EXhalbtc8723b2ant_HaltNotify(PBTC_COEXIST pBtCoexist)3674 void EXhalbtc8723b2ant_HaltNotify(PBTC_COEXIST pBtCoexist)
3675 {
3676 	BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));
3677 
3678 	halbtc8723b2ant_WifiOffHwCfg(pBtCoexist);
3679 	pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */
3680 	halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
3681 
3682 	EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3683 }
3684 
EXhalbtc8723b2ant_PnpNotify(PBTC_COEXIST pBtCoexist,u8 pnpState)3685 void EXhalbtc8723b2ant_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
3686 {
3687 	BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));
3688 
3689 	if (BTC_WIFI_PNP_SLEEP == pnpState) {
3690 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to SLEEP\n"));
3691 	} else if (BTC_WIFI_PNP_WAKE_UP == pnpState) {
3692 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to WAKE UP\n"));
3693 		halbtc8723b2ant_InitHwConfig(pBtCoexist, false);
3694 		halbtc8723b2ant_InitCoexDm(pBtCoexist);
3695 		halbtc8723b2ant_QueryBtInfo(pBtCoexist);
3696 	}
3697 }
3698 
EXhalbtc8723b2ant_Periodical(PBTC_COEXIST pBtCoexist)3699 void EXhalbtc8723b2ant_Periodical(PBTC_COEXIST pBtCoexist)
3700 {
3701 	static u8 disVerInfoCnt;
3702 	u32 fwVer = 0, btPatchVer = 0;
3703 
3704 	BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical ===========================\n"));
3705 
3706 	if (disVerInfoCnt <= 5) {
3707 		disVerInfoCnt += 1;
3708 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));
3709 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
3710 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
3711 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \
3712 			GLCoexVerDate8723b2Ant, GLCoexVer8723b2Ant, fwVer, btPatchVer, btPatchVer));
3713 		BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));
3714 	}
3715 
3716 	if (
3717 		halbtc8723b2ant_IsWifiStatusChanged(pBtCoexist) ||
3718 		pCoexDm->bAutoTdmaAdjust
3719 	)
3720 		halbtc8723b2ant_RunCoexistMechanism(pBtCoexist);
3721 }
3722