xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8189es/hal/btc/HalBtc8821a2Ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 //============================================================
3 // Description:
4 //
5 // This file is for RTL8821A Co-exist mechanism
6 //
7 // History
8 // 2012/11/15 Cosa first check in.
9 //
10 //============================================================
11 
12 //============================================================
13 // include files
14 //============================================================
15 #include "Mp_Precomp.h"
16 
17 #if WPP_SOFTWARE_TRACE
18 #include "HalBtc8821a2Ant.tmh"
19 #endif
20 
21 #if(BT_30_SUPPORT == 1)
22 //============================================================
23 // Global variables, these are static variables
24 //============================================================
25 static COEX_DM_8821A_2ANT		GLCoexDm8821a2Ant;
26 static PCOEX_DM_8821A_2ANT 	pCoexDm=&GLCoexDm8821a2Ant;
27 static COEX_STA_8821A_2ANT		GLCoexSta8821a2Ant;
28 static PCOEX_STA_8821A_2ANT	pCoexSta=&GLCoexSta8821a2Ant;
29 
30 const char *const GLBtInfoSrc8821a2Ant[]={
31 	"BT Info[wifi fw]",
32 	"BT Info[bt rsp]",
33 	"BT Info[bt auto report]",
34 };
35 
36 u4Byte	GLCoexVerDate8821a2Ant=20150128;
37 u4Byte	GLCoexVer8821a2Ant=0x51;
38 
39 //============================================================
40 // local function proto type if needed
41 //============================================================
42 //============================================================
43 // local function start with halbtc8821a2ant_
44 //============================================================
45 u1Byte
halbtc8821a2ant_BtRssiState(u1Byte levelNum,u1Byte rssiThresh,u1Byte rssiThresh1)46 halbtc8821a2ant_BtRssiState(
47 	u1Byte			levelNum,
48 	u1Byte			rssiThresh,
49 	u1Byte			rssiThresh1
50 	)
51 {
52 	s4Byte			btRssi=0;
53 	u1Byte			btRssiState=pCoexSta->preBtRssiState;
54 
55 	btRssi = pCoexSta->btRssi;
56 
57 	if(levelNum == 2)
58 	{
59 		if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
60 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
61 		{
62 			if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
63 			{
64 				btRssiState = BTC_RSSI_STATE_HIGH;
65 			}
66 			else
67 			{
68 				btRssiState = BTC_RSSI_STATE_STAY_LOW;
69 			}
70 		}
71 		else
72 		{
73 			if(btRssi < rssiThresh)
74 			{
75 				btRssiState = BTC_RSSI_STATE_LOW;
76 			}
77 			else
78 			{
79 				btRssiState = BTC_RSSI_STATE_STAY_HIGH;
80 			}
81 		}
82 	}
83 	else if(levelNum == 3)
84 	{
85 		if(rssiThresh > rssiThresh1)
86 		{
87 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));
88 			return pCoexSta->preBtRssiState;
89 		}
90 
91 		if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
92 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
93 		{
94 			if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
95 			{
96 				btRssiState = BTC_RSSI_STATE_MEDIUM;
97 			}
98 			else
99 			{
100 				btRssiState = BTC_RSSI_STATE_STAY_LOW;
101 			}
102 		}
103 		else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
104 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))
105 		{
106 			if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
107 			{
108 				btRssiState = BTC_RSSI_STATE_HIGH;
109 			}
110 			else if(btRssi < rssiThresh)
111 			{
112 				btRssiState = BTC_RSSI_STATE_LOW;
113 			}
114 			else
115 			{
116 				btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
117 			}
118 		}
119 		else
120 		{
121 			if(btRssi < rssiThresh1)
122 			{
123 				btRssiState = BTC_RSSI_STATE_MEDIUM;
124 			}
125 			else
126 			{
127 				btRssiState = BTC_RSSI_STATE_STAY_HIGH;
128 			}
129 		}
130 	}
131 
132 	pCoexSta->preBtRssiState = btRssiState;
133 
134 	return btRssiState;
135 }
136 
137 u1Byte
halbtc8821a2ant_WifiRssiState(IN PBTC_COEXIST pBtCoexist,IN u1Byte index,IN u1Byte levelNum,IN u1Byte rssiThresh,IN u1Byte rssiThresh1)138 halbtc8821a2ant_WifiRssiState(
139 	IN	PBTC_COEXIST		pBtCoexist,
140 	IN	u1Byte			index,
141 	IN	u1Byte			levelNum,
142 	IN	u1Byte			rssiThresh,
143 	IN	u1Byte			rssiThresh1
144 	)
145 {
146 	s4Byte			wifiRssi=0;
147 	u1Byte			wifiRssiState=pCoexSta->preWifiRssiState[index];
148 
149 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
150 
151 	if(levelNum == 2)
152 	{
153 		if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
154 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
155 		{
156 			if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
157 			{
158 				wifiRssiState = BTC_RSSI_STATE_HIGH;
159 			}
160 			else
161 			{
162 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
163 			}
164 		}
165 		else
166 		{
167 			if(wifiRssi < rssiThresh)
168 			{
169 				wifiRssiState = BTC_RSSI_STATE_LOW;
170 			}
171 			else
172 			{
173 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
174 			}
175 		}
176 	}
177 	else if(levelNum == 3)
178 	{
179 		if(rssiThresh > rssiThresh1)
180 		{
181 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));
182 			return pCoexSta->preWifiRssiState[index];
183 		}
184 
185 		if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
186 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
187 		{
188 			if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
189 			{
190 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
191 			}
192 			else
193 			{
194 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
195 			}
196 		}
197 		else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
198 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))
199 		{
200 			if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
201 			{
202 				wifiRssiState = BTC_RSSI_STATE_HIGH;
203 			}
204 			else if(wifiRssi < rssiThresh)
205 			{
206 				wifiRssiState = BTC_RSSI_STATE_LOW;
207 			}
208 			else
209 			{
210 				wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
211 			}
212 		}
213 		else
214 		{
215 			if(wifiRssi < rssiThresh1)
216 			{
217 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
218 			}
219 			else
220 			{
221 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
222 			}
223 		}
224 	}
225 
226 	pCoexSta->preWifiRssiState[index] = wifiRssiState;
227 
228 	return wifiRssiState;
229 }
230 
231 VOID
halbtc8821a2ant_MonitorBtEnableDisable(IN PBTC_COEXIST pBtCoexist)232 halbtc8821a2ant_MonitorBtEnableDisable(
233 	IN 	PBTC_COEXIST		pBtCoexist
234 	)
235 {
236 	static BOOLEAN	bPreBtDisabled=FALSE;
237 	static u4Byte	btDisableCnt=0;
238 	BOOLEAN			bBtActive=TRUE, bBtDisabled=FALSE;
239 
240 	// This function check if bt is disabled
241 
242 	if(	pCoexSta->highPriorityTx == 0 &&
243 		pCoexSta->highPriorityRx == 0 &&
244 		pCoexSta->lowPriorityTx == 0 &&
245 		pCoexSta->lowPriorityRx == 0)
246 	{
247 		bBtActive = FALSE;
248 	}
249 	if(	pCoexSta->highPriorityTx == 0xffff &&
250 		pCoexSta->highPriorityRx == 0xffff &&
251 		pCoexSta->lowPriorityTx == 0xffff &&
252 		pCoexSta->lowPriorityRx == 0xffff)
253 	{
254 		bBtActive = FALSE;
255 	}
256 	if(bBtActive)
257 	{
258 		btDisableCnt = 0;
259 		bBtDisabled = FALSE;
260 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
261 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));
262 	}
263 	else
264 	{
265 		btDisableCnt++;
266 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n",
267 				btDisableCnt));
268 		if(btDisableCnt >= 2)
269 		{
270 			bBtDisabled = TRUE;
271 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
272 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));
273 		}
274 	}
275 	if(bPreBtDisabled != bBtDisabled)
276 	{
277 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n",
278 			(bPreBtDisabled ? "disabled":"enabled"),
279 			(bBtDisabled ? "disabled":"enabled")));
280 		bPreBtDisabled = bBtDisabled;
281 		if(!bBtDisabled)
282 		{
283 		}
284 		else
285 		{
286 		}
287 	}
288 }
289 
290 VOID
halbtc8821a2ant_LimitedRx(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRejApAggPkt,IN BOOLEAN bBtCtrlAggBufSize,IN u1Byte aggBufSize)291 halbtc8821a2ant_LimitedRx(
292 	IN	PBTC_COEXIST		pBtCoexist,
293 	IN	BOOLEAN				bForceExec,
294 	IN	BOOLEAN				bRejApAggPkt,
295 	IN	BOOLEAN				bBtCtrlAggBufSize,
296 	IN	u1Byte				aggBufSize
297 	)
298 {
299 	BOOLEAN	bRejectRxAgg=bRejApAggPkt;
300 	BOOLEAN	bBtCtrlRxAggSize=bBtCtrlAggBufSize;
301 	u1Byte	rxAggSize=aggBufSize;
302 
303 	//============================================
304 	//	Rx Aggregation related setting
305 	//============================================
306 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
307 	// decide BT control aggregation buf size or not
308 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
309 	// aggregation buf size, only work when BT control Rx aggregation size.
310 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
311 	// real update aggregation setting
312 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
313 }
314 
315 VOID
halbtc8821a2ant_MonitorBtCtr(IN PBTC_COEXIST pBtCoexist)316 halbtc8821a2ant_MonitorBtCtr(
317 	IN	PBTC_COEXIST		pBtCoexist
318 	)
319 {
320 	u4Byte 			regHPTxRx, regLPTxRx, u4Tmp;
321 	u4Byte			regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;
322 	u1Byte			u1Tmp;
323 
324 	PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
325 
326 	regHPTxRx = 0x770;
327 	regLPTxRx = 0x774;
328 
329 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
330 	regHPTx = u4Tmp & bMaskLWord;
331 	regHPRx = (u4Tmp & bMaskHWord)>>16;
332 
333 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
334 	regLPTx = u4Tmp & bMaskLWord;
335 	regLPRx = (u4Tmp & bMaskHWord)>>16;
336 
337 	pCoexSta->highPriorityTx = regHPTx;
338 	pCoexSta->highPriorityRx = regHPRx;
339 	pCoexSta->lowPriorityTx = regLPTx;
340 	pCoexSta->lowPriorityRx = regLPRx;
341 
342 	if ( (pCoexSta->lowPriorityRx >= 950)  &&  (pCoexSta->lowPriorityRx >= pCoexSta->lowPriorityTx) && (!pCoexSta->bUnderIps) )
343 	{
344 		pBtLinkInfo->bSlaveRole = TRUE;
345 	}
346 	else
347 	{
348 		pBtLinkInfo->bSlaveRole = FALSE;
349 	}
350 
351 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
352 		regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));
353 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
354 		regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));
355 
356 	// reset counter
357 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
358 }
359 
360 VOID
halbtc8821a2ant_MonitorWiFiCtr(IN PBTC_COEXIST pBtCoexist)361 halbtc8821a2ant_MonitorWiFiCtr(
362 	IN	PBTC_COEXIST		pBtCoexist
363 	)
364 {
365 	u4Byte 	u4Tmp;
366 	u2Byte 	u2Tmp[3];
367 	s4Byte	wifiRssi=0;
368 	BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;
369 	static u1Byte nCCKLockCounter = 0;
370 
371 
372 	if (pCoexSta->bUnderIps)
373 	{
374 		pCoexSta->nCRCOK_CCK = 0;
375 		pCoexSta->nCRCOK_11g = 0;
376 		pCoexSta->nCRCOK_11n = 0;
377 		pCoexSta->nCRCOK_11nAgg = 0;
378 
379 		pCoexSta->nCRCErr_CCK = 0;
380 		pCoexSta->nCRCErr_11g = 0;
381 		pCoexSta->nCRCErr_11n = 0;
382 		pCoexSta->nCRCErr_11nAgg = 0;
383 	}
384 	else
385 	{
386 		pCoexSta->nCRCOK_CCK	= pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
387 		pCoexSta->nCRCOK_11g 	= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
388 		pCoexSta->nCRCOK_11n	= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
389 		pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
390 
391 		pCoexSta->nCRCErr_CCK 	 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
392 		pCoexSta->nCRCErr_11g 	 = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
393 		pCoexSta->nCRCErr_11n 	 = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
394 		pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
395 	}
396 
397 	//reset counter
398 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
399 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
400 }
401 
402 VOID
halbtc8821a2ant_QueryBtInfo(IN PBTC_COEXIST pBtCoexist)403 halbtc8821a2ant_QueryBtInfo(
404 	IN	PBTC_COEXIST		pBtCoexist
405 	)
406 {
407 	u1Byte			H2C_Parameter[1] ={0};
408 
409 	pCoexSta->bC2hBtInfoReqSent = TRUE;
410 
411 	H2C_Parameter[0] |= BIT0;	// trigger
412 
413 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n",
414 		H2C_Parameter[0]));
415 
416 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
417 }
418 
419 BOOLEAN
halbtc8821a2ant_IsWifiStatusChanged(IN PBTC_COEXIST pBtCoexist)420 halbtc8821a2ant_IsWifiStatusChanged(
421 	IN	PBTC_COEXIST		pBtCoexist
422 	)
423 {
424 	static BOOLEAN	bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;
425 	BOOLEAN			bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;
426 	BOOLEAN			bWifiConnected=FALSE;
427 	u1Byte			wifiRssiState=BTC_RSSI_STATE_HIGH;
428 
429 
430 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
431 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
432 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
433 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
434 
435 	if(bWifiConnected)
436 	{
437 		if(bWifiBusy != bPreWifiBusy)
438 		{
439 			bPreWifiBusy = bWifiBusy;
440 			return TRUE;
441 		}
442 		if(bUnder4way != bPreUnder4way)
443 		{
444 			bPreUnder4way = bUnder4way;
445 			return TRUE;
446 		}
447 		if(bBtHsOn != bPreBtHsOn)
448 		{
449 			bPreBtHsOn = bBtHsOn;
450 			return TRUE;
451 		}
452 
453 
454 		wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist,3, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
455 
456 		if ( (BTC_RSSI_STATE_HIGH ==wifiRssiState ) ||  (BTC_RSSI_STATE_LOW ==wifiRssiState ))
457 		{
458 			return TRUE;
459 		}
460 
461 	}
462 
463 	return FALSE;
464 }
465 
466 VOID
halbtc8821a2ant_UpdateBtLinkInfo(IN PBTC_COEXIST pBtCoexist)467 halbtc8821a2ant_UpdateBtLinkInfo(
468 	IN	PBTC_COEXIST		pBtCoexist
469 	)
470 {
471 	PBTC_STACK_INFO 	pStackInfo=&pBtCoexist->stackInfo;
472 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
473 	BOOLEAN				bBtHsOn=FALSE;
474 
475 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 1)	// profile from bt patch
476 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
477 
478 	pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
479 	pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
480 	pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
481 	pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
482 	pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
483 
484 	// work around for HS mode.
485 	if(bBtHsOn)
486 	{
487 		pBtLinkInfo->bPanExist = TRUE;
488 		pBtLinkInfo->bBtLinkExist = TRUE;
489 	}
490 #else	// profile from bt stack
491 	pBtLinkInfo->bBtLinkExist = pStackInfo->bBtLinkExist;
492 	pBtLinkInfo->bScoExist = pStackInfo->bScoExist;
493 	pBtLinkInfo->bA2dpExist = pStackInfo->bA2dpExist;
494 	pBtLinkInfo->bPanExist = pStackInfo->bPanExist;
495 	pBtLinkInfo->bHidExist = pStackInfo->bHidExist;
496 
497 	//for win-8 stack HID report error
498 	if(!pStackInfo->bHidExist)
499 		pStackInfo->bHidExist = pCoexSta->bHidExist;  //sync  BTInfo with BT firmware and stack
500 	// when stack HID report error, here we use the info from bt fw.
501 	if(!pStackInfo->bBtLinkExist)
502 		pStackInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
503 #endif
504 	// check if Sco only
505 	if( pBtLinkInfo->bScoExist &&
506 		!pBtLinkInfo->bA2dpExist &&
507 		!pBtLinkInfo->bPanExist &&
508 		!pBtLinkInfo->bHidExist )
509 		pBtLinkInfo->bScoOnly = TRUE;
510 	else
511 		pBtLinkInfo->bScoOnly = FALSE;
512 
513 	// check if A2dp only
514 	if( !pBtLinkInfo->bScoExist &&
515 		pBtLinkInfo->bA2dpExist &&
516 		!pBtLinkInfo->bPanExist &&
517 		!pBtLinkInfo->bHidExist )
518 		pBtLinkInfo->bA2dpOnly = TRUE;
519 	else
520 		pBtLinkInfo->bA2dpOnly = FALSE;
521 
522 	// check if Pan only
523 	if( !pBtLinkInfo->bScoExist &&
524 		!pBtLinkInfo->bA2dpExist &&
525 		pBtLinkInfo->bPanExist &&
526 		!pBtLinkInfo->bHidExist )
527 		pBtLinkInfo->bPanOnly = TRUE;
528 	else
529 		pBtLinkInfo->bPanOnly = FALSE;
530 
531 	// check if Hid only
532 	if( !pBtLinkInfo->bScoExist &&
533 		!pBtLinkInfo->bA2dpExist &&
534 		!pBtLinkInfo->bPanExist &&
535 		pBtLinkInfo->bHidExist )
536 		pBtLinkInfo->bHidOnly = TRUE;
537 	else
538 		pBtLinkInfo->bHidOnly = FALSE;
539 }
540 
541 u1Byte
halbtc8821a2ant_ActionAlgorithm(IN PBTC_COEXIST pBtCoexist)542 halbtc8821a2ant_ActionAlgorithm(
543 	IN	PBTC_COEXIST		pBtCoexist
544 	)
545 {
546 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
547 	BOOLEAN				bBtHsOn=FALSE;
548 	u1Byte				algorithm=BT_8821A_2ANT_COEX_ALGO_UNDEFINED;
549 	u1Byte				numOfDiffProfile=0;
550 
551 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
552 
553 	if(!pBtLinkInfo->bBtLinkExist)
554 	{
555 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));
556 		return algorithm;
557 	}
558 
559 	if(pBtLinkInfo->bScoExist)
560 		numOfDiffProfile++;
561 	if(pBtLinkInfo->bHidExist)
562 		numOfDiffProfile++;
563 	if(pBtLinkInfo->bPanExist)
564 		numOfDiffProfile++;
565 	if(pBtLinkInfo->bA2dpExist)
566 		numOfDiffProfile++;
567 
568 	if(numOfDiffProfile == 1)
569 	{
570 		if(pBtLinkInfo->bScoExist)
571 		{
572 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO only\n"));
573 			algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
574 		}
575 		else
576 		{
577 			if(pBtLinkInfo->bHidExist)
578 			{
579 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID only\n"));
580 				algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
581 			}
582 			else if(pBtLinkInfo->bA2dpExist)
583 			{
584 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP only\n"));
585 				algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;
586 			}
587 			else if(pBtLinkInfo->bPanExist)
588 			{
589 				if(bBtHsOn)
590 				{
591 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(HS) only\n"));
592 					algorithm = BT_8821A_2ANT_COEX_ALGO_PANHS;
593 				}
594 				else
595 				{
596 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(EDR) only\n"));
597 					algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR;
598 				}
599 			}
600 		}
601 	}
602 	else if(numOfDiffProfile == 2)
603 	{
604 		if(pBtLinkInfo->bScoExist)
605 		{
606 			if(pBtLinkInfo->bHidExist)
607 			{
608 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID\n"));
609 				algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
610 			}
611 			else if(pBtLinkInfo->bA2dpExist)
612 			{
613 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP ==> SCO\n"));
614 				algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
615 			}
616 			else if(pBtLinkInfo->bPanExist)
617 			{
618 				if(bBtHsOn)
619 				{
620 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(HS)\n"));
621 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
622 				}
623 				else
624 				{
625 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(EDR)\n"));
626 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
627 				}
628 			}
629 		}
630 		else
631 		{
632 			if( pBtLinkInfo->bHidExist &&
633 				pBtLinkInfo->bA2dpExist )
634 			{
635 #if 0
636 				if(pStackInfo->numOfHid >= 2)
637 				{
638 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID*2 + A2DP\n"));
639 					algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
640 				}
641 				else
642 #endif
643 				{
644 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP\n"));
645 					algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
646 				}
647 			}
648 			else if( pBtLinkInfo->bHidExist &&
649 				pBtLinkInfo->bPanExist )
650 			{
651 				if(bBtHsOn)
652 				{
653 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(HS)\n"));
654 					algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
655 				}
656 				else
657 				{
658 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(EDR)\n"));
659 					algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
660 				}
661 			}
662 			else if( pBtLinkInfo->bPanExist &&
663 				pBtLinkInfo->bA2dpExist )
664 			{
665 				if(bBtHsOn)
666 				{
667 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(HS)\n"));
668 					algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;
669 				}
670 				else
671 				{
672 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(EDR)\n"));
673 					algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;
674 				}
675 			}
676 		}
677 	}
678 	else if(numOfDiffProfile == 3)
679 	{
680 		if(pBtLinkInfo->bScoExist)
681 		{
682 			if( pBtLinkInfo->bHidExist &&
683 				pBtLinkInfo->bA2dpExist )
684 			{
685 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP ==> SCO\n"));
686 				algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
687 			}
688 			else if( pBtLinkInfo->bHidExist &&
689 				pBtLinkInfo->bPanExist )
690 			{
691 				if(bBtHsOn)
692 				{
693 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(HS) ==> SCO\n"));
694 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
695 				}
696 				else
697 				{
698 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(EDR) ==> SCO\n"));
699 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
700 				}
701 			}
702 			else if( pBtLinkInfo->bPanExist &&
703 				pBtLinkInfo->bA2dpExist )
704 			{
705 				if(bBtHsOn)
706 				{
707 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));
708 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
709 				}
710 				else
711 				{
712 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));
713 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
714 				}
715 			}
716 		}
717 		else
718 		{
719 			if( pBtLinkInfo->bHidExist &&
720 				pBtLinkInfo->bPanExist &&
721 				pBtLinkInfo->bA2dpExist )
722 			{
723 				if(bBtHsOn)
724 				{
725 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
726 					algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
727 				}
728 				else
729 				{
730 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
731 					algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
732 				}
733 			}
734 		}
735 	}
736 	else if(numOfDiffProfile >= 3)
737 	{
738 		if(pBtLinkInfo->bScoExist)
739 		{
740 			if( pBtLinkInfo->bHidExist &&
741 				pBtLinkInfo->bPanExist &&
742 				pBtLinkInfo->bA2dpExist )
743 			{
744 				if(bBtHsOn)
745 				{
746 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
747 
748 				}
749 				else
750 				{
751 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));
752 					algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
753 				}
754 			}
755 		}
756 	}
757 
758 	return algorithm;
759 }
760 
761 VOID
halbtc8821a2ant_SetFwDacSwingLevel(IN PBTC_COEXIST pBtCoexist,IN u1Byte dacSwingLvl)762 halbtc8821a2ant_SetFwDacSwingLevel(
763 	IN	PBTC_COEXIST		pBtCoexist,
764 	IN	u1Byte			dacSwingLvl
765 	)
766 {
767 	u1Byte			H2C_Parameter[1] ={0};
768 
769 	// There are several type of dacswing
770 	// 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
771 	H2C_Parameter[0] = dacSwingLvl;
772 
773 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));
774 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x64=0x%x\n", H2C_Parameter[0]));
775 
776 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);
777 }
778 
779 VOID
halbtc8821a2ant_SetFwDecBtPwr(IN PBTC_COEXIST pBtCoexist,IN u1Byte decBtPwrLvl)780 halbtc8821a2ant_SetFwDecBtPwr(
781 	IN	PBTC_COEXIST		pBtCoexist,
782 	IN	u1Byte				decBtPwrLvl
783 	)
784 {
785 	u1Byte			H2C_Parameter[1] ={0};
786 
787 	H2C_Parameter[0] = decBtPwrLvl;
788 
789 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], decrease Bt Power level = %d, FW write 0x62=0x%x\n",
790 		decBtPwrLvl, H2C_Parameter[0]));
791 
792 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);
793 }
794 
795 VOID
halbtc8821a2ant_DecBtPwr(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte decBtPwrLvl)796 halbtc8821a2ant_DecBtPwr(
797 	IN	PBTC_COEXIST		pBtCoexist,
798 	IN	BOOLEAN				bForceExec,
799 	IN	u1Byte				decBtPwrLvl
800 	)
801 {
802 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s Dec BT power level = %d\n",
803 		(bForceExec? "force to":""), decBtPwrLvl));
804 	pCoexDm->curBtDecPwrLvl = decBtPwrLvl;
805 
806 	if(!bForceExec)
807 	{
808 		if(pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl)
809 			return;
810 	}
811 	halbtc8821a2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);
812 
813 	pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;
814 }
815 
816 VOID
halbtc8821a2ant_SetBtAutoReport(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnableAutoReport)817 halbtc8821a2ant_SetBtAutoReport(
818 	IN	PBTC_COEXIST		pBtCoexist,
819 	IN	BOOLEAN			bEnableAutoReport
820 	)
821 {
822 	u1Byte			H2C_Parameter[1] ={0};
823 
824 	H2C_Parameter[0] = 0;
825 
826 	if(bEnableAutoReport)
827 	{
828 		H2C_Parameter[0] |= BIT0;
829 	}
830 
831 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n",
832 		(bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));
833 
834 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);
835 }
836 
837 VOID
halbtc8821a2ant_BtAutoReport(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnableAutoReport)838 halbtc8821a2ant_BtAutoReport(
839 	IN	PBTC_COEXIST		pBtCoexist,
840 	IN	BOOLEAN			bForceExec,
841 	IN	BOOLEAN			bEnableAutoReport
842 	)
843 {
844 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",
845 		(bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));
846 	pCoexDm->bCurBtAutoReport = bEnableAutoReport;
847 
848 	if(!bForceExec)
849 	{
850 		if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport)
851 			return;
852 	}
853 	halbtc8821a2ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);
854 
855 	pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;
856 }
857 
858 VOID
halbtc8821a2ant_FwDacSwingLvl(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte fwDacSwingLvl)859 halbtc8821a2ant_FwDacSwingLvl(
860 	IN	PBTC_COEXIST		pBtCoexist,
861 	IN	BOOLEAN			bForceExec,
862 	IN	u1Byte			fwDacSwingLvl
863 	)
864 {
865 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set FW Dac Swing level = %d\n",
866 		(bForceExec? "force to":""), fwDacSwingLvl));
867 	pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;
868 
869 	if(!bForceExec)
870 	{
871 		if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl)
872 			return;
873 	}
874 
875 	halbtc8821a2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);
876 
877 	pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;
878 }
879 
880 VOID
halbtc8821a2ant_SetSwRfRxLpfCorner(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bRxRfShrinkOn)881 halbtc8821a2ant_SetSwRfRxLpfCorner(
882 	IN	PBTC_COEXIST		pBtCoexist,
883 	IN	BOOLEAN			bRxRfShrinkOn
884 	)
885 {
886 	if(bRxRfShrinkOn)
887 	{
888 		//Shrink RF Rx LPF corner
889 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));
890 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);
891 	}
892 	else
893 	{
894 		//Resume RF Rx LPF corner
895 		// After initialized, we can use pCoexDm->btRf0x1eBackup
896 		if(pBtCoexist->bInitilized)
897 		{
898 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
899 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);
900 		}
901 	}
902 }
903 
904 VOID
halbtc8821a2ant_RfShrink(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRxRfShrinkOn)905 halbtc8821a2ant_RfShrink(
906 	IN	PBTC_COEXIST		pBtCoexist,
907 	IN	BOOLEAN			bForceExec,
908 	IN	BOOLEAN			bRxRfShrinkOn
909 	)
910 {
911 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",
912 		(bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));
913 	pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
914 
915 	if(!bForceExec)
916 	{
917 		if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
918 			return;
919 	}
920 	halbtc8821a2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
921 
922 	pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
923 }
924 
925 VOID
halbtc8821a2ant_SetSwPenaltyTxRateAdaptive(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bLowPenaltyRa)926 halbtc8821a2ant_SetSwPenaltyTxRateAdaptive(
927 	IN	PBTC_COEXIST		pBtCoexist,
928 	IN	BOOLEAN			bLowPenaltyRa
929 	)
930 {
931 	u1Byte			H2C_Parameter[6] ={0};
932 
933 	H2C_Parameter[0] = 0x6;	// opCode, 0x6= Retry_Penalty
934 
935 	if(bLowPenaltyRa)
936 	{
937 		H2C_Parameter[1] |= BIT0;
938 		H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36
939 		H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54
940 		H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48
941 		H2C_Parameter[5] = 0xf9;	//MCS5 or OFDM36
942 	}
943 
944 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s",
945 		(bLowPenaltyRa? "ON!!":"OFF!!")) );
946 
947 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
948 }
949 
950 VOID
halbtc8821a2ant_LowPenaltyRa(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bLowPenaltyRa)951 halbtc8821a2ant_LowPenaltyRa(
952 	IN	PBTC_COEXIST		pBtCoexist,
953 	IN	BOOLEAN			bForceExec,
954 	IN	BOOLEAN			bLowPenaltyRa
955 	)
956 {
957 	//return;
958 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",
959 		(bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));
960 	pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
961 
962 	if(!bForceExec)
963 	{
964 		if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
965 			return;
966 	}
967 	halbtc8821a2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
968 
969 	pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
970 }
971 
972 VOID
halbtc8821a2ant_SetDacSwingReg(IN PBTC_COEXIST pBtCoexist,IN u4Byte level)973 halbtc8821a2ant_SetDacSwingReg(
974 	IN	PBTC_COEXIST		pBtCoexist,
975 	IN	u4Byte			level
976 	)
977 {
978 	u1Byte	val=(u1Byte)level;
979 
980 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Write SwDacSwing = 0x%x\n", level));
981 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc5b, 0x3e, val);
982 }
983 
984 VOID
halbtc8821a2ant_SetSwFullTimeDacSwing(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bSwDacSwingOn,IN u4Byte swDacSwingLvl)985 halbtc8821a2ant_SetSwFullTimeDacSwing(
986 	IN	PBTC_COEXIST		pBtCoexist,
987 	IN	BOOLEAN			bSwDacSwingOn,
988 	IN	u4Byte			swDacSwingLvl
989 	)
990 {
991 	if(bSwDacSwingOn)
992 	{
993 		halbtc8821a2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);
994 	}
995 	else
996 	{
997 		halbtc8821a2ant_SetDacSwingReg(pBtCoexist, 0x18);
998 	}
999 }
1000 
1001 
1002 VOID
halbtc8821a2ant_DacSwing(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bDacSwingOn,IN u4Byte dacSwingLvl)1003 halbtc8821a2ant_DacSwing(
1004 	IN	PBTC_COEXIST		pBtCoexist,
1005 	IN	BOOLEAN			bForceExec,
1006 	IN	BOOLEAN			bDacSwingOn,
1007 	IN	u4Byte			dacSwingLvl
1008 	)
1009 {
1010 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",
1011 		(bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));
1012 	pCoexDm->bCurDacSwingOn = bDacSwingOn;
1013 	pCoexDm->curDacSwingLvl = dacSwingLvl;
1014 
1015 	if(!bForceExec)
1016 	{
1017 		if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&
1018 			(pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )
1019 			return;
1020 	}
1021 	delay_ms(30);
1022 	halbtc8821a2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);
1023 
1024 	pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;
1025 	pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;
1026 }
1027 
1028 VOID
halbtc8821a2ant_SetAdcBackOff(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAdcBackOff)1029 halbtc8821a2ant_SetAdcBackOff(
1030 	IN	PBTC_COEXIST		pBtCoexist,
1031 	IN	BOOLEAN			bAdcBackOff
1032 	)
1033 {
1034 	if(bAdcBackOff)
1035 	{
1036 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level On!\n"));
1037 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x8db, 0x60, 0x3);
1038 	}
1039 	else
1040 	{
1041 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level Off!\n"));
1042 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x8db, 0x60, 0x1);
1043 	}
1044 }
1045 
1046 VOID
halbtc8821a2ant_AdcBackOff(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bAdcBackOff)1047 halbtc8821a2ant_AdcBackOff(
1048 	IN	PBTC_COEXIST		pBtCoexist,
1049 	IN	BOOLEAN			bForceExec,
1050 	IN	BOOLEAN			bAdcBackOff
1051 	)
1052 {
1053 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn AdcBackOff = %s\n",
1054 		(bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));
1055 	pCoexDm->bCurAdcBackOff = bAdcBackOff;
1056 
1057 	if(!bForceExec)
1058 	{
1059 		if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff)
1060 			return;
1061 	}
1062 	halbtc8821a2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);
1063 
1064 	pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;
1065 }
1066 
1067 VOID
halbtc8821a2ant_SetAgcTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAgcTableEn)1068 halbtc8821a2ant_SetAgcTable(
1069 	IN	PBTC_COEXIST		pBtCoexist,
1070 	IN	BOOLEAN			bAgcTableEn
1071 	)
1072 {
1073 	u1Byte		rssiAdjustVal=0;
1074 
1075 	//=================BB AGC Gain Table
1076 	if(bAgcTableEn)
1077 	{
1078 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB Agc Table On!\n"));
1079 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6e1A0001);
1080 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6d1B0001);
1081 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6c1C0001);
1082 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6b1D0001);
1083 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6a1E0001);
1084 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x691F0001);
1085 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x68200001);
1086 	}
1087 	else
1088 	{
1089 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB Agc Table Off!\n"));
1090 	 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);
1091 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);
1092 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);
1093 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);
1094 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);
1095 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);
1096 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa4200001);
1097 	}
1098 
1099 
1100 	//=================RF Gain
1101 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
1102 	if(bAgcTableEn)
1103 	{
1104 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));
1105 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);
1106 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);
1107 	}
1108 	else
1109 	{
1110 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));
1111 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);
1112 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);
1113 	}
1114 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
1115 
1116 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
1117 	if(bAgcTableEn)
1118 	{
1119 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));
1120 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);
1121 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);
1122 	}
1123 	else
1124 	{
1125 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));
1126 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);
1127 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);
1128 	}
1129 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
1130 
1131 	// set rssiAdjustVal for wifi module.
1132 	if(bAgcTableEn)
1133 	{
1134 		rssiAdjustVal = 8;
1135 	}
1136 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);
1137 }
1138 
1139 VOID
halbtc8821a2ant_AgcTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bAgcTableEn)1140 halbtc8821a2ant_AgcTable(
1141 	IN	PBTC_COEXIST		pBtCoexist,
1142 	IN	BOOLEAN			bForceExec,
1143 	IN	BOOLEAN			bAgcTableEn
1144 	)
1145 {
1146 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s %s Agc Table\n",
1147 		(bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));
1148 	pCoexDm->bCurAgcTableEn = bAgcTableEn;
1149 
1150 	if(!bForceExec)
1151 	{
1152 		if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn)
1153 			return;
1154 	}
1155 	halbtc8821a2ant_SetAgcTable(pBtCoexist, bAgcTableEn);
1156 
1157 	pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;
1158 }
1159 
1160 VOID
halbtc8821a2ant_SetCoexTable(IN PBTC_COEXIST pBtCoexist,IN u4Byte val0x6c0,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u1Byte val0x6cc)1161 halbtc8821a2ant_SetCoexTable(
1162 	IN	PBTC_COEXIST	pBtCoexist,
1163 	IN	u4Byte		val0x6c0,
1164 	IN	u4Byte		val0x6c4,
1165 	IN	u4Byte		val0x6c8,
1166 	IN	u1Byte		val0x6cc
1167 	)
1168 {
1169 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
1170 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
1171 
1172 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
1173 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
1174 
1175 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
1176 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
1177 
1178 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
1179 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
1180 }
1181 
1182 VOID
halbtc8821a2ant_CoexTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte val0x6c0,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u1Byte val0x6cc)1183 halbtc8821a2ant_CoexTable(
1184 	IN	PBTC_COEXIST		pBtCoexist,
1185 	IN	BOOLEAN			bForceExec,
1186 	IN	u4Byte			val0x6c0,
1187 	IN	u4Byte			val0x6c4,
1188 	IN	u4Byte			val0x6c8,
1189 	IN	u1Byte			val0x6cc
1190 	)
1191 {
1192 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
1193 		(bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));
1194 	pCoexDm->curVal0x6c0 = val0x6c0;
1195 	pCoexDm->curVal0x6c4 = val0x6c4;
1196 	pCoexDm->curVal0x6c8 = val0x6c8;
1197 	pCoexDm->curVal0x6cc = val0x6cc;
1198 
1199 	if(!bForceExec)
1200 	{
1201 		if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1202 			(pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1203 			(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1204 			(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
1205 			return;
1206 	}
1207 	halbtc8821a2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1208 
1209 	pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1210 	pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1211 	pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1212 	pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1213 }
1214 
1215 VOID
halbtc8821a2ant_CoexTableWithType(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)1216 halbtc8821a2ant_CoexTableWithType(
1217 	IN	PBTC_COEXIST		pBtCoexist,
1218 	IN	BOOLEAN				bForceExec,
1219 	IN	u1Byte				type
1220 	)
1221 {
1222 	pCoexSta->nCoexTableType = type;
1223 
1224 	switch(type)
1225 	{
1226 		case 0:
1227 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);
1228 			break;
1229 		case 1:
1230 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffffff, 0x3);
1231 			break;
1232 		case 2:
1233 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3);
1234 			break;
1235 		case 3:
1236 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
1237 			break;
1238 		case 4:
1239 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffffff, 0x3);
1240 			break;
1241 		case 5:
1242 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3);
1243 			break;
1244 		case 6:
1245 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3);
1246 			break;
1247 		case 7:
1248 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1249 			break;
1250 		case 8:
1251 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1252 			break;
1253 		case 9:
1254 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1255 			break;
1256 		case 10:
1257 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1258 			break;
1259 		case 11:
1260 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1261 			break;
1262 		case 12:
1263 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1264 			break;
1265 		case 13:
1266 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3);
1267 			break;
1268 		case 14:
1269 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3);
1270 			break;
1271 		case 15:
1272 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3);
1273 			break;
1274 		case 16:
1275 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
1276 			break;
1277 		case 17:
1278 			halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0xfafafafa, 0xfafafafa, 0xffffff, 0x3);
1279 			break;
1280 		default:
1281 			break;
1282 	}
1283 }
1284 
1285 VOID
halbtc8821a2ant_SetFwIgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnable)1286 halbtc8821a2ant_SetFwIgnoreWlanAct(
1287 	IN	PBTC_COEXIST		pBtCoexist,
1288 	IN	BOOLEAN			bEnable
1289 	)
1290 {
1291 	u1Byte			H2C_Parameter[1] ={0};
1292 
1293 	if(bEnable)
1294 	{
1295 		H2C_Parameter[0] |= BIT0;		// function enable
1296 	}
1297 
1298 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n",
1299 		H2C_Parameter[0]));
1300 
1301 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
1302 }
1303 
1304 VOID
halbtc8821a2ant_SetLpsRpwm(IN PBTC_COEXIST pBtCoexist,IN u1Byte lpsVal,IN u1Byte rpwmVal)1305 halbtc8821a2ant_SetLpsRpwm(
1306 	IN	PBTC_COEXIST		pBtCoexist,
1307 	IN	u1Byte			lpsVal,
1308 	IN	u1Byte			rpwmVal
1309 	)
1310 {
1311 	u1Byte	lps=lpsVal;
1312 	u1Byte	rpwm=rpwmVal;
1313 
1314 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
1315 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1316 }
1317 
1318 VOID
halbtc8821a2ant_LpsRpwm(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte lpsVal,IN u1Byte rpwmVal)1319 halbtc8821a2ant_LpsRpwm(
1320 	IN	PBTC_COEXIST		pBtCoexist,
1321 	IN	BOOLEAN			bForceExec,
1322 	IN	u1Byte			lpsVal,
1323 	IN	u1Byte			rpwmVal
1324 	)
1325 {
1326 	BOOLEAN	bForceExecPwrCmd=FALSE;
1327 
1328 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n",
1329 		(bForceExec? "force to":""), lpsVal, rpwmVal));
1330 	pCoexDm->curLps = lpsVal;
1331 	pCoexDm->curRpwm = rpwmVal;
1332 
1333 	if(!bForceExec)
1334 	{
1335 		if( (pCoexDm->preLps == pCoexDm->curLps) &&
1336 			(pCoexDm->preRpwm == pCoexDm->curRpwm) )
1337 		{
1338 			return;
1339 		}
1340 	}
1341 	halbtc8821a2ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
1342 
1343 	pCoexDm->preLps = pCoexDm->curLps;
1344 	pCoexDm->preRpwm = pCoexDm->curRpwm;
1345 }
1346 
1347 VOID
halbtc8821a2ant_IgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnable)1348 halbtc8821a2ant_IgnoreWlanAct(
1349 	IN	PBTC_COEXIST		pBtCoexist,
1350 	IN	BOOLEAN			bForceExec,
1351 	IN	BOOLEAN			bEnable
1352 	)
1353 {
1354 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n",
1355 		(bForceExec? "force to":""), (bEnable? "ON":"OFF")));
1356 	pCoexDm->bCurIgnoreWlanAct = bEnable;
1357 
1358 	if(!bForceExec)
1359 	{
1360 		if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1361 			return;
1362 	}
1363 	halbtc8821a2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1364 
1365 	pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1366 }
1367 
1368 VOID
halbtc8821a2ant_SetFwPstdma(IN PBTC_COEXIST pBtCoexist,IN u1Byte byte1,IN u1Byte byte2,IN u1Byte byte3,IN u1Byte byte4,IN u1Byte byte5)1369 halbtc8821a2ant_SetFwPstdma(
1370 	IN	PBTC_COEXIST		pBtCoexist,
1371 	IN	u1Byte			byte1,
1372 	IN	u1Byte			byte2,
1373 	IN	u1Byte			byte3,
1374 	IN	u1Byte			byte4,
1375 	IN	u1Byte			byte5
1376 	)
1377 {
1378 	u1Byte			H2C_Parameter[5] ={0};
1379 
1380 	H2C_Parameter[0] = byte1;
1381 	H2C_Parameter[1] = byte2;
1382 	H2C_Parameter[2] = byte3;
1383 	H2C_Parameter[3] = byte4;
1384 	H2C_Parameter[4] = byte5;
1385 
1386 	pCoexDm->psTdmaPara[0] = byte1;
1387 	pCoexDm->psTdmaPara[1] = byte2;
1388 	pCoexDm->psTdmaPara[2] = byte3;
1389 	pCoexDm->psTdmaPara[3] = byte4;
1390 	pCoexDm->psTdmaPara[4] = byte5;
1391 
1392 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n",
1393 		H2C_Parameter[0],
1394 		H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
1395 
1396 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1397 }
1398 
1399 VOID
halbtc8821a2ant_SwMechanism1(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bShrinkRxLPF,IN BOOLEAN bLowPenaltyRA,IN BOOLEAN bLimitedDIG,IN BOOLEAN bBTLNAConstrain)1400 halbtc8821a2ant_SwMechanism1(
1401 	IN	PBTC_COEXIST	pBtCoexist,
1402 	IN	BOOLEAN		bShrinkRxLPF,
1403 	IN	BOOLEAN 	bLowPenaltyRA,
1404 	IN	BOOLEAN		bLimitedDIG,
1405 	IN	BOOLEAN		bBTLNAConstrain
1406 	)
1407 {
1408 	/*
1409 	u4Byte	wifiBw;
1410 
1411 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1412 
1413 	if(BTC_WIFI_BW_HT40 != wifiBw)  //only shrink RF Rx LPF for HT40
1414 	{
1415 		if (bShrinkRxLPF)
1416 			bShrinkRxLPF = FALSE;
1417 	}
1418 	*/
1419 
1420 	//halbtc8821a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);
1421 	halbtc8821a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1422 }
1423 
1424 VOID
halbtc8821a2ant_SwMechanism2(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAGCTableShift,IN BOOLEAN bADCBackOff,IN BOOLEAN bSWDACSwing,IN u4Byte dacSwingLvl)1425 halbtc8821a2ant_SwMechanism2(
1426 	IN	PBTC_COEXIST	pBtCoexist,
1427 	IN	BOOLEAN		bAGCTableShift,
1428 	IN	BOOLEAN 	bADCBackOff,
1429 	IN	BOOLEAN		bSWDACSwing,
1430 	IN	u4Byte		dacSwingLvl
1431 	)
1432 {
1433 	//halbtc8821a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);
1434 	//halbtc8821a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, bADCBackOff);
1435 	halbtc8821a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);
1436 }
1437 
1438 VOID
halbtc8821a2ant_SetAntPath(IN PBTC_COEXIST pBtCoexist,IN u1Byte antPosType,IN BOOLEAN bInitHwCfg,IN BOOLEAN bWifiOff)1439 halbtc8821a2ant_SetAntPath(
1440 	IN	PBTC_COEXIST		pBtCoexist,
1441 	IN	u1Byte				antPosType,
1442 	IN	BOOLEAN				bInitHwCfg,
1443 	IN	BOOLEAN				bWifiOff
1444 	)
1445 {
1446 	PBTC_BOARD_INFO 	pBoardInfo=&pBtCoexist->boardInfo;
1447 	u4Byte				u4Tmp=0;
1448 	u1Byte				H2C_Parameter[2] ={0};
1449 
1450 	if(bInitHwCfg)
1451 	{
1452 		// 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT
1453 		u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1454 		u4Tmp &=~BIT23;
1455 		u4Tmp |= BIT24;
1456 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1457 
1458 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x974, 0x3ff);
1459 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x77);
1460 
1461 		if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1462 		{
1463 			//tell firmware "antenna inverse"  ==> WRONG firmware antenna control code.==>need fw to fix
1464 			H2C_Parameter[0] = 1;
1465 			H2C_Parameter[1] = 1;
1466 			pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1467 		}
1468 		else
1469 		{
1470 			//tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix
1471 			H2C_Parameter[0] = 0;
1472 			H2C_Parameter[1] = 1;
1473 			pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1474 		}
1475 	}
1476 
1477 	// ext switch setting
1478 	switch(antPosType)
1479 	{
1480 		case BTC_ANT_WIFI_AT_MAIN:
1481 			pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);
1482 			break;
1483 		case BTC_ANT_WIFI_AT_AUX:
1484 			pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);
1485 			break;
1486 	}
1487 }
1488 
1489 VOID
halbtc8821a2ant_PsTdma(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bTurnOn,IN u1Byte type)1490 halbtc8821a2ant_PsTdma(
1491 	IN	PBTC_COEXIST		pBtCoexist,
1492 	IN	BOOLEAN			bForceExec,
1493 	IN	BOOLEAN			bTurnOn,
1494 	IN	u1Byte			type
1495 	)
1496 {
1497 	BOOLEAN			bTurnOnByCnt=FALSE;
1498 	u1Byte			psTdmaTypeByCnt=0;
1499 	u1Byte			wifiRssiState1, btRssiState;
1500 
1501 
1502 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1503 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1504 
1505 	if (!(BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState)) && bTurnOn)
1506 	{
1507 		type = type +100;  //for WiFi RSSI low or BT RSSI low
1508 	}
1509 
1510 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn %s PS TDMA, type=%d\n",
1511 		(bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));
1512 	pCoexDm->bCurPsTdmaOn = bTurnOn;
1513 	pCoexDm->curPsTdma = type;
1514 
1515 	if(!bForceExec)
1516 	{
1517 		if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1518 			(pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
1519 			return;
1520 	}
1521 	if(bTurnOn)
1522 	{
1523 		switch(type)
1524 		{
1525 			case 1:
1526 			default:
1527 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1528 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);
1529 				break;
1530 			case 2:
1531 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
1532 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x03, 0xf1, 0x90);
1533 				break;
1534 			case 3:
1535 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);
1536 				break;
1537 			case 4:
1538 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90);
1539 				break;
1540 			case 5:
1541 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
1542 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x3, 0x70, 0x90);
1543 				break;
1544 			case 6:
1545 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
1546 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x3, 0x70, 0x90);
1547 				break;
1548 			case 7:
1549 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);
1550 				break;
1551 			case 8:
1552 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);
1553 				break;
1554 			case 9:
1555 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1556 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);
1557 				break;
1558 			case 10:
1559 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
1560 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x03, 0xf1, 0x90);
1561 				break;
1562 			case 11:
1563 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90);
1564 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);
1565 				break;
1566 			case 12:
1567 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1568 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x90);
1569 				break;
1570 			case 13:
1571 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
1572 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x3, 0x70, 0x90);
1573 				break;
1574 			case 14:
1575 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
1576 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x3, 0x70, 0x90);
1577 				break;
1578 			case 15:
1579 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90);
1580 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);
1581 				break;
1582 			case 16:
1583 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90);
1584 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0x70, 0x90);
1585 				break;
1586 			case 17:
1587 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90);
1588 				break;
1589 			case 18:
1590 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1591 				break;
1592 			case 19:
1593 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);
1594 				break;
1595 			case 20:
1596 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);
1597 				break;
1598 			case 21:
1599 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);
1600 				break;
1601 			case 23:
1602 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x03, 0xf1, 0x10);
1603 				break;
1604 			case 24:
1605 			case 124:
1606 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x3c, 0x03, 0x70, 0x50);
1607 				break;
1608 			case 71:
1609 				//halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1610 
1611 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);
1612 				break;
1613 			case 101:
1614 			case 105:
1615 			case 171:
1616 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x3a, 0x03, 0x70, 0x50);
1617 				break;
1618 			case 102:
1619 			case 106:
1620 			case 110:
1621 			case 114:
1622 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x2d, 0x03, 0x70, 0x50);
1623 				break;
1624 			case 103:
1625 			case 107:
1626 			case 111:
1627 			case 115:
1628 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1c, 0x03, 0x70, 0x50);
1629 				break;
1630 			case 104:
1631 			case 108:
1632 			case 112:
1633 			case 116:
1634 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x10, 0x03, 0x70, 0x50);
1635 				break;
1636 			case 109:
1637 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);
1638 				break;
1639 			case 113:
1640 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0x70, 0x90);
1641 				break;
1642 			case 121:
1643 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);
1644 				break;
1645 			case 22:
1646 			case 122:
1647 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x35, 0x03, 0x71, 0x11);
1648 				break;
1649 			case 123:
1650 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1c, 0x03, 0x70, 0x50);
1651 				break;
1652 		}
1653 	}
1654 	else
1655 	{
1656 		// disable PS tdma
1657 		switch(type)
1658 		{
1659 			case 0:
1660 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
1661 				break;
1662 			case 1:
1663 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
1664 				break;
1665 			default:
1666 				halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
1667 				break;
1668 		}
1669 	}
1670 
1671 	// update pre state
1672 	pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1673 	pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1674 }
1675 
1676 VOID
halbtc8821a2ant_PsTdmaCheckForPowerSaveState(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bNewPsState)1677 halbtc8821a2ant_PsTdmaCheckForPowerSaveState(
1678 	IN	PBTC_COEXIST		pBtCoexist,
1679 	IN	BOOLEAN			bNewPsState
1680 	)
1681 {
1682 	u1Byte	lpsMode=0x0;
1683 
1684 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
1685 
1686 	if(lpsMode)	// already under LPS state
1687 	{
1688 		if(bNewPsState)
1689 		{
1690 			// keep state under LPS, do nothing.
1691 		}
1692 		else
1693 		{
1694 			// will leave LPS state, turn off psTdma first
1695 			halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1696 		}
1697 	}
1698 	else						// NO PS state
1699 	{
1700 		if(bNewPsState)
1701 		{
1702 			// will enter LPS state, turn off psTdma first
1703 			halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1704 		}
1705 		else
1706 		{
1707 			// keep state under NO PS state, do nothing.
1708 		}
1709 	}
1710 }
1711 
1712 VOID
halbtc8821a2ant_PowerSaveState(IN PBTC_COEXIST pBtCoexist,IN u1Byte psType,IN u1Byte lpsVal,IN u1Byte rpwmVal)1713 halbtc8821a2ant_PowerSaveState(
1714 	IN	PBTC_COEXIST		pBtCoexist,
1715 	IN	u1Byte				psType,
1716 	IN	u1Byte				lpsVal,
1717 	IN	u1Byte				rpwmVal
1718 	)
1719 {
1720 	BOOLEAN		bLowPwrDisable=FALSE;
1721 
1722 	switch(psType)
1723 	{
1724 		case BTC_PS_WIFI_NATIVE:
1725 			// recover to original 32k low power setting
1726 			bLowPwrDisable = FALSE;
1727 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1728 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1729 			pCoexSta->bForceLpsOn = FALSE;
1730 			break;
1731 		case BTC_PS_LPS_ON:
1732 			halbtc8821a2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);
1733 			halbtc8821a2ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
1734 			// when coex force to enter LPS, do not enter 32k low power.
1735 			bLowPwrDisable = TRUE;
1736 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1737 			// power save must executed before psTdma.
1738 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1739 			pCoexSta->bForceLpsOn = TRUE;
1740 			break;
1741 		case BTC_PS_LPS_OFF:
1742 			halbtc8821a2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);
1743 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1744 			pCoexSta->bForceLpsOn = FALSE;
1745 			break;
1746 		default:
1747 			break;
1748 	}
1749 }
1750 
1751 
1752 VOID
halbtc8821a2ant_CoexAllOff(IN PBTC_COEXIST pBtCoexist)1753 halbtc8821a2ant_CoexAllOff(
1754 	IN	PBTC_COEXIST		pBtCoexist
1755 	)
1756 {
1757 	// fw all off
1758 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1759 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1760 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1761 	halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1762 
1763 	// sw all off
1764 	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1765 	halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1766 
1767 	// hw all off
1768 	//pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1769 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1770 }
1771 
1772 VOID
halbtc8821a2ant_CoexUnder5G(IN PBTC_COEXIST pBtCoexist)1773 halbtc8821a2ant_CoexUnder5G(
1774 	IN	PBTC_COEXIST		pBtCoexist
1775 	)
1776 {
1777 	halbtc8821a2ant_CoexAllOff(pBtCoexist);
1778 
1779 	halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, TRUE);
1780 }
1781 
1782 VOID
halbtc8821a2ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)1783 halbtc8821a2ant_InitCoexDm(
1784 	IN	PBTC_COEXIST		pBtCoexist
1785 	)
1786 {
1787 	// force to reset coex mechanism
1788 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1789 
1790 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1791 	halbtc8821a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
1792 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1793 	halbtc8821a2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);
1794 
1795 	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1796 	halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1797 }
1798 
1799 VOID
halbtc8821a2ant_ActionBtInquiry(IN PBTC_COEXIST pBtCoexist)1800 halbtc8821a2ant_ActionBtInquiry(
1801 	IN	PBTC_COEXIST		pBtCoexist
1802 	)
1803 {
1804 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
1805 	BOOLEAN	bWifiConnected=FALSE;
1806 	BOOLEAN	bLowPwrDisable=TRUE;
1807 	BOOLEAN		bScan=FALSE, bLink=FALSE, bRoam=FALSE;
1808 
1809 
1810 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
1811 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1812 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1813 
1814 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1815 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1816 
1817 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1818 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1819 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1820 
1821 
1822 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1823 
1824 	if(bScan || bLink || bRoam)
1825 	{
1826 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi link process + BT Inq/Page!!\n"));
1827 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);
1828 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
1829 	}
1830 	else if(bWifiConnected)
1831 	{
1832 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT Inq/Page!!\n"));
1833 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);
1834 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
1835 	}
1836 	else
1837 	{
1838 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi no-link + BT Inq/Page!!\n"));
1839 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1840 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1841 	}
1842 
1843 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1844 	halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1845 
1846 	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1847 	halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1848 
1849 }
1850 
1851 
1852 VOID
halbtc8821a2ant_ActionWiFiLinkProcess(IN PBTC_COEXIST pBtCoexist)1853 halbtc8821a2ant_ActionWiFiLinkProcess(
1854 	IN	PBTC_COEXIST		pBtCoexist
1855 	)
1856 {
1857 	u1Byte 	u1Tmpa, u1Tmpb;
1858 
1859 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);
1860 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
1861 
1862 	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1863 	halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1864 
1865 
1866 
1867 	u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
1868 	u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
1869 
1870 	RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u1Tmpa, u1Tmpb));
1871 }
1872 
1873 BOOLEAN
halbtc8821a2ant_ActionWifiIdleProcess(IN PBTC_COEXIST pBtCoexist)1874 halbtc8821a2ant_ActionWifiIdleProcess(
1875 	IN	PBTC_COEXIST		pBtCoexist
1876 	)
1877 {
1878 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
1879 	u4Byte		wifiBw;
1880 	u1Byte		apNum=0;
1881 
1882 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
1883 	//wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1884 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES-20, 0);
1885 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1886 
1887 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
1888 
1889 	// define the office environment
1890 	if(BTC_RSSI_HIGH(wifiRssiState1) &&
1891 			(pCoexSta->bHidExist == TRUE) && (pCoexSta->bA2dpExist == TRUE))
1892 	{
1893 
1894 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi  idle process for BT HID+A2DP exist!!\n"));
1895 
1896 		halbtc8821a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x6);
1897 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1898 
1899 		// sw all off
1900 		halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1901 		halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1902 
1903 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1904 
1905 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1906 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1907 
1908 	  	return TRUE;
1909 	}
1910 	else
1911 	{
1912 		halbtc8821a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1913 		return FALSE;
1914 	}
1915 
1916 
1917 }
1918 
1919 
1920 
1921 BOOLEAN
halbtc8821a2ant_IsCommonAction(IN PBTC_COEXIST pBtCoexist)1922 halbtc8821a2ant_IsCommonAction(
1923 	IN	PBTC_COEXIST		pBtCoexist
1924 	)
1925 {
1926 	u1Byte			btRssiState=BTC_RSSI_STATE_HIGH;
1927 	BOOLEAN			bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;
1928 	BOOLEAN			bBtHsOn=FALSE, bLowPwrDisable=FALSE;
1929 
1930 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1931 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1932 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1933 
1934 	if(!bWifiConnected)
1935 	{
1936 		bLowPwrDisable = FALSE;
1937 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1938 		halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1939 
1940 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-connected idle!!\n"));
1941 
1942 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1943 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1944 
1945 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1946 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1947 		halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1948 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1949 
1950  		halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1951 		halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1952 
1953 		bCommon = TRUE;
1954 	}
1955 	else
1956 	{
1957 		if(BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
1958 		{
1959 			bLowPwrDisable = FALSE;
1960 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1961 			halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1962 
1963 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
1964 
1965 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1966 			halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1967 
1968 			halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1969 			halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1970 			halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1971 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1972 
1973 	      	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1974 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1975 
1976 			bCommon = TRUE;
1977 		}
1978 		else if(BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)
1979 		{
1980 			bLowPwrDisable = TRUE;
1981 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1982 
1983 			if(bBtHsOn)
1984 				return FALSE;
1985 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
1986 			halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1987 
1988 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1989 			halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1990 
1991 			halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1992 			halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1993 			halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1994 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1995 
1996 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
1997 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1998 
1999 			bCommon = TRUE;
2000 		}
2001 		else
2002 		{
2003 			bLowPwrDisable = TRUE;
2004 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2005 
2006 			if(bWifiBusy)
2007 			{
2008 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
2009 				bCommon = FALSE;
2010 				//bCommon = halbtc8821a2ant_ActionWifiIdleProcess(pBtCoexist);
2011 			}
2012 			else
2013 			{
2014 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
2015 				//bCommon = FALSE;
2016 				bCommon = halbtc8821a2ant_ActionWifiIdleProcess(pBtCoexist);
2017 			}
2018 		}
2019 	}
2020 
2021 	return bCommon;
2022 }
2023 VOID
halbtc8821a2ant_TdmaDurationAdjust(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bScoHid,IN BOOLEAN bTxPause,IN u1Byte maxInterval)2024 halbtc8821a2ant_TdmaDurationAdjust(
2025 	IN	PBTC_COEXIST		pBtCoexist,
2026 	IN	BOOLEAN			bScoHid,
2027 	IN	BOOLEAN			bTxPause,
2028 	IN	u1Byte			maxInterval
2029 	)
2030 {
2031 	static s4Byte		up,dn,m,n,WaitCount;
2032 	s4Byte			result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
2033 	u1Byte			retryCount=0;
2034 
2035 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
2036 
2037 	if(!pCoexDm->bAutoTdmaAdjust)
2038 	{
2039 		pCoexDm->bAutoTdmaAdjust = TRUE;
2040 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
2041 		{
2042 			if(bScoHid)
2043 			{
2044 				if(bTxPause)
2045 				{
2046 					if(maxInterval == 1)
2047 					{
2048 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2049 						pCoexDm->psTdmaDuAdjType = 13;
2050 					}
2051 					else if(maxInterval == 2)
2052 					{
2053 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2054 						pCoexDm->psTdmaDuAdjType = 14;
2055 					}
2056 					else if(maxInterval == 3)
2057 					{
2058 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2059 						pCoexDm->psTdmaDuAdjType = 15;
2060 					}
2061 					else
2062 					{
2063 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2064 						pCoexDm->psTdmaDuAdjType = 15;
2065 					}
2066 				}
2067 				else
2068 				{
2069 					if(maxInterval == 1)
2070 					{
2071 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2072 						pCoexDm->psTdmaDuAdjType = 9;
2073 					}
2074 					else if(maxInterval == 2)
2075 					{
2076 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2077 						pCoexDm->psTdmaDuAdjType = 10;
2078 					}
2079 					else if(maxInterval == 3)
2080 					{
2081 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2082 						pCoexDm->psTdmaDuAdjType = 11;
2083 					}
2084 					else
2085 					{
2086 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2087 						pCoexDm->psTdmaDuAdjType = 11;
2088 					}
2089 				}
2090 			}
2091 			else
2092 			{
2093 				if(bTxPause)
2094 				{
2095 					if(maxInterval == 1)
2096 					{
2097 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2098 						pCoexDm->psTdmaDuAdjType = 5;
2099 					}
2100 					else if(maxInterval == 2)
2101 					{
2102 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2103 						pCoexDm->psTdmaDuAdjType = 6;
2104 					}
2105 					else if(maxInterval == 3)
2106 					{
2107 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2108 						pCoexDm->psTdmaDuAdjType = 7;
2109 					}
2110 					else
2111 					{
2112 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2113 						pCoexDm->psTdmaDuAdjType = 7;
2114 					}
2115 				}
2116 				else
2117 				{
2118 					if(maxInterval == 1)
2119 					{
2120 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2121 						pCoexDm->psTdmaDuAdjType = 1;
2122 					}
2123 					else if(maxInterval == 2)
2124 					{
2125 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2126 						pCoexDm->psTdmaDuAdjType = 2;
2127 					}
2128 					else if(maxInterval == 3)
2129 					{
2130 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2131 						pCoexDm->psTdmaDuAdjType = 3;
2132 					}
2133 					else
2134 					{
2135 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2136 						pCoexDm->psTdmaDuAdjType = 3;
2137 					}
2138 				}
2139 			}
2140 		}
2141 		//============
2142 		up = 0;
2143 		dn = 0;
2144 		m = 1;
2145 		n= 3;
2146 		result = 0;
2147 		WaitCount = 0;
2148 	}
2149 	else
2150 	{
2151 		//accquire the BT TRx retry count from BT_Info byte2
2152 		retryCount = pCoexSta->btRetryCnt;
2153 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
2154 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n",
2155 			up, dn, m, n, WaitCount));
2156 		result = 0;
2157 		WaitCount++;
2158 
2159 		if(retryCount == 0)  // no retry in the last 2-second duration
2160 		{
2161 			up++;
2162 			dn--;
2163 
2164 			if (dn <= 0)
2165 				dn = 0;
2166 
2167 			if(up >= n)	// if �s�� n ��2�� retry count��0, �h�ռeWiFi duration
2168 			{
2169 				WaitCount = 0;
2170 				n = 3;
2171 				up = 0;
2172 				dn = 0;
2173 				result = 1;
2174 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
2175 			}
2176 		}
2177 		else if (retryCount <= 3)	// <=3 retry in the last 2-second duration
2178 		{
2179 			up--;
2180 			dn++;
2181 
2182 			if (up <= 0)
2183 				up = 0;
2184 
2185 			if (dn == 2)	// if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration
2186 			{
2187 				if (WaitCount <= 2)
2188 					m++; // �קK�@���b���level���Ӧ^
2189 				else
2190 					m = 1;
2191 
2192 				if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
2193 					m = 20;
2194 
2195 				n = 3*m;
2196 				up = 0;
2197 				dn = 0;
2198 				WaitCount = 0;
2199 				result = -1;
2200 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
2201 			}
2202 		}
2203 		else  //retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration
2204 		{
2205 			if (WaitCount == 1)
2206 				m++; // �קK�@���b���level���Ӧ^
2207 			else
2208 				m = 1;
2209 
2210 			if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
2211 				m = 20;
2212 
2213 			n = 3*m;
2214 			up = 0;
2215 			dn = 0;
2216 			WaitCount = 0;
2217 			result = -1;
2218 			RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
2219 		}
2220 
2221 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
2222 		if(maxInterval == 1)
2223 		{
2224 			if(bTxPause)
2225 			{
2226 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));
2227 
2228 				if(pCoexDm->curPsTdma == 71)
2229 				{
2230 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2231 					pCoexDm->psTdmaDuAdjType = 5;
2232 				}
2233 				else if(pCoexDm->curPsTdma == 1)
2234 				{
2235 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2236 					pCoexDm->psTdmaDuAdjType = 5;
2237 				}
2238 				else if(pCoexDm->curPsTdma == 2)
2239 				{
2240 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2241 					pCoexDm->psTdmaDuAdjType = 6;
2242 				}
2243 				else if(pCoexDm->curPsTdma == 3)
2244 				{
2245 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2246 					pCoexDm->psTdmaDuAdjType = 7;
2247 				}
2248 				else if(pCoexDm->curPsTdma == 4)
2249 				{
2250 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2251 					pCoexDm->psTdmaDuAdjType = 8;
2252 				}
2253 				if(pCoexDm->curPsTdma == 9)
2254 				{
2255 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2256 					pCoexDm->psTdmaDuAdjType = 13;
2257 				}
2258 				else if(pCoexDm->curPsTdma == 10)
2259 				{
2260 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2261 					pCoexDm->psTdmaDuAdjType = 14;
2262 				}
2263 				else if(pCoexDm->curPsTdma == 11)
2264 				{
2265 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2266 					pCoexDm->psTdmaDuAdjType = 15;
2267 				}
2268 				else if(pCoexDm->curPsTdma == 12)
2269 				{
2270 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2271 					pCoexDm->psTdmaDuAdjType = 16;
2272 				}
2273 
2274 				if(result == -1)
2275 				{
2276 					if(pCoexDm->curPsTdma == 5)
2277 					{
2278 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2279 						pCoexDm->psTdmaDuAdjType = 6;
2280 					}
2281 					else if(pCoexDm->curPsTdma == 6)
2282 					{
2283 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2284 						pCoexDm->psTdmaDuAdjType = 7;
2285 					}
2286 					else if(pCoexDm->curPsTdma == 7)
2287 					{
2288 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2289 						pCoexDm->psTdmaDuAdjType = 8;
2290 					}
2291 					else if(pCoexDm->curPsTdma == 13)
2292 					{
2293 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2294 						pCoexDm->psTdmaDuAdjType = 14;
2295 					}
2296 					else if(pCoexDm->curPsTdma == 14)
2297 					{
2298 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2299 						pCoexDm->psTdmaDuAdjType = 15;
2300 					}
2301 					else if(pCoexDm->curPsTdma == 15)
2302 					{
2303 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2304 						pCoexDm->psTdmaDuAdjType = 16;
2305 					}
2306 				}
2307 				else if (result == 1)
2308 				{
2309 					if(pCoexDm->curPsTdma == 8)
2310 					{
2311 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2312 						pCoexDm->psTdmaDuAdjType = 7;
2313 					}
2314 					else if(pCoexDm->curPsTdma == 7)
2315 					{
2316 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2317 						pCoexDm->psTdmaDuAdjType = 6;
2318 					}
2319 					else if(pCoexDm->curPsTdma == 6)
2320 					{
2321 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2322 						pCoexDm->psTdmaDuAdjType = 5;
2323 					}
2324 					else if(pCoexDm->curPsTdma == 16)
2325 					{
2326 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2327 						pCoexDm->psTdmaDuAdjType = 15;
2328 					}
2329 					else if(pCoexDm->curPsTdma == 15)
2330 					{
2331 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2332 						pCoexDm->psTdmaDuAdjType = 14;
2333 					}
2334 					else if(pCoexDm->curPsTdma == 14)
2335 					{
2336 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2337 						pCoexDm->psTdmaDuAdjType = 13;
2338 					}
2339 				}
2340 			}
2341 			else
2342 			{
2343 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));
2344 				if(pCoexDm->curPsTdma == 5)
2345 				{
2346 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);
2347 					pCoexDm->psTdmaDuAdjType = 71;
2348 				}
2349 				else if(pCoexDm->curPsTdma == 6)
2350 				{
2351 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2352 					pCoexDm->psTdmaDuAdjType = 2;
2353 				}
2354 				else if(pCoexDm->curPsTdma == 7)
2355 				{
2356 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2357 					pCoexDm->psTdmaDuAdjType = 3;
2358 				}
2359 				else if(pCoexDm->curPsTdma == 8)
2360 				{
2361 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2362 					pCoexDm->psTdmaDuAdjType = 4;
2363 				}
2364 				if(pCoexDm->curPsTdma == 13)
2365 				{
2366 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2367 					pCoexDm->psTdmaDuAdjType = 9;
2368 				}
2369 				else if(pCoexDm->curPsTdma == 14)
2370 				{
2371 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2372 					pCoexDm->psTdmaDuAdjType = 10;
2373 				}
2374 				else if(pCoexDm->curPsTdma == 15)
2375 				{
2376 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2377 					pCoexDm->psTdmaDuAdjType = 11;
2378 				}
2379 				else if(pCoexDm->curPsTdma == 16)
2380 				{
2381 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2382 					pCoexDm->psTdmaDuAdjType = 12;
2383 				}
2384 
2385 				if(result == -1)
2386 				{
2387 					if(pCoexDm->curPsTdma == 71)
2388 					{
2389 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2390 						pCoexDm->psTdmaDuAdjType = 1;
2391 					}
2392 					else if(pCoexDm->curPsTdma == 1)
2393 					{
2394 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2395 						pCoexDm->psTdmaDuAdjType = 2;
2396 					}
2397 					else if(pCoexDm->curPsTdma == 2)
2398 					{
2399 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2400 						pCoexDm->psTdmaDuAdjType = 3;
2401 					}
2402 					else if(pCoexDm->curPsTdma == 3)
2403 					{
2404 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2405 						pCoexDm->psTdmaDuAdjType = 4;
2406 					}
2407 					else if(pCoexDm->curPsTdma == 9)
2408 					{
2409 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2410 						pCoexDm->psTdmaDuAdjType = 10;
2411 					}
2412 					else if(pCoexDm->curPsTdma == 10)
2413 					{
2414 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2415 						pCoexDm->psTdmaDuAdjType = 11;
2416 					}
2417 					else if(pCoexDm->curPsTdma == 11)
2418 					{
2419 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2420 						pCoexDm->psTdmaDuAdjType = 12;
2421 					}
2422 				}
2423 				else if (result == 1)
2424 				{
2425 					if(pCoexDm->curPsTdma == 4)
2426 					{
2427 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2428 						pCoexDm->psTdmaDuAdjType = 3;
2429 					}
2430 					else if(pCoexDm->curPsTdma == 3)
2431 					{
2432 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2433 						pCoexDm->psTdmaDuAdjType = 2;
2434 					}
2435 					else if(pCoexDm->curPsTdma == 2)
2436 					{
2437 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2438 						pCoexDm->psTdmaDuAdjType = 1;
2439 					}
2440 					else if(pCoexDm->curPsTdma == 1)
2441 					{
2442 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);
2443 						pCoexDm->psTdmaDuAdjType = 71;
2444 					}
2445 					else if(pCoexDm->curPsTdma == 12)
2446 					{
2447 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2448 						pCoexDm->psTdmaDuAdjType = 11;
2449 					}
2450 					else if(pCoexDm->curPsTdma == 11)
2451 					{
2452 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2453 						pCoexDm->psTdmaDuAdjType = 10;
2454 					}
2455 					else if(pCoexDm->curPsTdma == 10)
2456 					{
2457 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2458 						pCoexDm->psTdmaDuAdjType = 9;
2459 					}
2460 				}
2461 			}
2462 		}
2463 		else if(maxInterval == 2)
2464 		{
2465 			if(bTxPause)
2466 			{
2467 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));
2468 				if(pCoexDm->curPsTdma == 1)
2469 				{
2470 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2471 					pCoexDm->psTdmaDuAdjType = 6;
2472 				}
2473 				else if(pCoexDm->curPsTdma == 2)
2474 				{
2475 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2476 					pCoexDm->psTdmaDuAdjType = 6;
2477 				}
2478 				else if(pCoexDm->curPsTdma == 3)
2479 				{
2480 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2481 					pCoexDm->psTdmaDuAdjType = 7;
2482 				}
2483 				else if(pCoexDm->curPsTdma == 4)
2484 				{
2485 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2486 					pCoexDm->psTdmaDuAdjType = 8;
2487 				}
2488 				if(pCoexDm->curPsTdma == 9)
2489 				{
2490 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2491 					pCoexDm->psTdmaDuAdjType = 14;
2492 				}
2493 				else if(pCoexDm->curPsTdma == 10)
2494 				{
2495 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2496 					pCoexDm->psTdmaDuAdjType = 14;
2497 				}
2498 				else if(pCoexDm->curPsTdma == 11)
2499 				{
2500 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2501 					pCoexDm->psTdmaDuAdjType = 15;
2502 				}
2503 				else if(pCoexDm->curPsTdma == 12)
2504 				{
2505 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2506 					pCoexDm->psTdmaDuAdjType = 16;
2507 				}
2508 				if(result == -1)
2509 				{
2510 					if(pCoexDm->curPsTdma == 5)
2511 					{
2512 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2513 						pCoexDm->psTdmaDuAdjType = 6;
2514 					}
2515 					else if(pCoexDm->curPsTdma == 6)
2516 					{
2517 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2518 						pCoexDm->psTdmaDuAdjType = 7;
2519 					}
2520 					else if(pCoexDm->curPsTdma == 7)
2521 					{
2522 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2523 						pCoexDm->psTdmaDuAdjType = 8;
2524 					}
2525 					else if(pCoexDm->curPsTdma == 13)
2526 					{
2527 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2528 						pCoexDm->psTdmaDuAdjType = 14;
2529 					}
2530 					else if(pCoexDm->curPsTdma == 14)
2531 					{
2532 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2533 						pCoexDm->psTdmaDuAdjType = 15;
2534 					}
2535 					else if(pCoexDm->curPsTdma == 15)
2536 					{
2537 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2538 						pCoexDm->psTdmaDuAdjType = 16;
2539 					}
2540 				}
2541 				else if (result == 1)
2542 				{
2543 					if(pCoexDm->curPsTdma == 8)
2544 					{
2545 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2546 						pCoexDm->psTdmaDuAdjType = 7;
2547 					}
2548 					else if(pCoexDm->curPsTdma == 7)
2549 					{
2550 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2551 						pCoexDm->psTdmaDuAdjType = 6;
2552 					}
2553 					else if(pCoexDm->curPsTdma == 6)
2554 					{
2555 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2556 						pCoexDm->psTdmaDuAdjType = 6;
2557 					}
2558 					else if(pCoexDm->curPsTdma == 16)
2559 					{
2560 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2561 						pCoexDm->psTdmaDuAdjType = 15;
2562 					}
2563 					else if(pCoexDm->curPsTdma == 15)
2564 					{
2565 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2566 						pCoexDm->psTdmaDuAdjType = 14;
2567 					}
2568 					else if(pCoexDm->curPsTdma == 14)
2569 					{
2570 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2571 						pCoexDm->psTdmaDuAdjType = 14;
2572 					}
2573 				}
2574 			}
2575 			else
2576 			{
2577 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));
2578 				if(pCoexDm->curPsTdma == 5)
2579 				{
2580 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2581 					pCoexDm->psTdmaDuAdjType = 2;
2582 				}
2583 				else if(pCoexDm->curPsTdma == 6)
2584 				{
2585 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2586 					pCoexDm->psTdmaDuAdjType = 2;
2587 				}
2588 				else if(pCoexDm->curPsTdma == 7)
2589 				{
2590 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2591 					pCoexDm->psTdmaDuAdjType = 3;
2592 				}
2593 				else if(pCoexDm->curPsTdma == 8)
2594 				{
2595 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2596 					pCoexDm->psTdmaDuAdjType = 4;
2597 				}
2598 				if(pCoexDm->curPsTdma == 13)
2599 				{
2600 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2601 					pCoexDm->psTdmaDuAdjType = 10;
2602 				}
2603 				else if(pCoexDm->curPsTdma == 14)
2604 				{
2605 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2606 					pCoexDm->psTdmaDuAdjType = 10;
2607 				}
2608 				else if(pCoexDm->curPsTdma == 15)
2609 				{
2610 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2611 					pCoexDm->psTdmaDuAdjType = 11;
2612 				}
2613 				else if(pCoexDm->curPsTdma == 16)
2614 				{
2615 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2616 					pCoexDm->psTdmaDuAdjType = 12;
2617 				}
2618 				if(result == -1)
2619 				{
2620 					if(pCoexDm->curPsTdma == 1)
2621 					{
2622 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2623 						pCoexDm->psTdmaDuAdjType = 2;
2624 					}
2625 					else if(pCoexDm->curPsTdma == 2)
2626 					{
2627 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2628 						pCoexDm->psTdmaDuAdjType = 3;
2629 					}
2630 					else if(pCoexDm->curPsTdma == 3)
2631 					{
2632 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2633 						pCoexDm->psTdmaDuAdjType = 4;
2634 					}
2635 					else if(pCoexDm->curPsTdma == 9)
2636 					{
2637 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2638 						pCoexDm->psTdmaDuAdjType = 10;
2639 					}
2640 					else if(pCoexDm->curPsTdma == 10)
2641 					{
2642 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2643 						pCoexDm->psTdmaDuAdjType = 11;
2644 					}
2645 					else if(pCoexDm->curPsTdma == 11)
2646 					{
2647 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2648 						pCoexDm->psTdmaDuAdjType = 12;
2649 					}
2650 				}
2651 				else if (result == 1)
2652 				{
2653 					if(pCoexDm->curPsTdma == 4)
2654 					{
2655 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2656 						pCoexDm->psTdmaDuAdjType = 3;
2657 					}
2658 					else if(pCoexDm->curPsTdma == 3)
2659 					{
2660 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2661 						pCoexDm->psTdmaDuAdjType = 2;
2662 					}
2663 					else if(pCoexDm->curPsTdma == 2)
2664 					{
2665 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2666 						pCoexDm->psTdmaDuAdjType = 2;
2667 					}
2668 					else if(pCoexDm->curPsTdma == 12)
2669 					{
2670 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2671 						pCoexDm->psTdmaDuAdjType = 11;
2672 					}
2673 					else if(pCoexDm->curPsTdma == 11)
2674 					{
2675 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2676 						pCoexDm->psTdmaDuAdjType = 10;
2677 					}
2678 					else if(pCoexDm->curPsTdma == 10)
2679 					{
2680 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2681 						pCoexDm->psTdmaDuAdjType = 10;
2682 					}
2683 				}
2684 			}
2685 		}
2686 		else if(maxInterval == 3)
2687 		{
2688 			if(bTxPause)
2689 			{
2690 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));
2691 				if(pCoexDm->curPsTdma == 1)
2692 				{
2693 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2694 					pCoexDm->psTdmaDuAdjType = 7;
2695 				}
2696 				else if(pCoexDm->curPsTdma == 2)
2697 				{
2698 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2699 					pCoexDm->psTdmaDuAdjType = 7;
2700 				}
2701 				else if(pCoexDm->curPsTdma == 3)
2702 				{
2703 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2704 					pCoexDm->psTdmaDuAdjType = 7;
2705 				}
2706 				else if(pCoexDm->curPsTdma == 4)
2707 				{
2708 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2709 					pCoexDm->psTdmaDuAdjType = 8;
2710 				}
2711 				if(pCoexDm->curPsTdma == 9)
2712 				{
2713 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2714 					pCoexDm->psTdmaDuAdjType = 15;
2715 				}
2716 				else if(pCoexDm->curPsTdma == 10)
2717 				{
2718 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2719 					pCoexDm->psTdmaDuAdjType = 15;
2720 				}
2721 				else if(pCoexDm->curPsTdma == 11)
2722 				{
2723 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2724 					pCoexDm->psTdmaDuAdjType = 15;
2725 				}
2726 				else if(pCoexDm->curPsTdma == 12)
2727 				{
2728 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2729 					pCoexDm->psTdmaDuAdjType = 16;
2730 				}
2731 				if(result == -1)
2732 				{
2733 					if(pCoexDm->curPsTdma == 5)
2734 					{
2735 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2736 						pCoexDm->psTdmaDuAdjType = 7;
2737 					}
2738 					else if(pCoexDm->curPsTdma == 6)
2739 					{
2740 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2741 						pCoexDm->psTdmaDuAdjType = 7;
2742 					}
2743 					else if(pCoexDm->curPsTdma == 7)
2744 					{
2745 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2746 						pCoexDm->psTdmaDuAdjType = 8;
2747 					}
2748 					else if(pCoexDm->curPsTdma == 13)
2749 					{
2750 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2751 						pCoexDm->psTdmaDuAdjType = 15;
2752 					}
2753 					else if(pCoexDm->curPsTdma == 14)
2754 					{
2755 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2756 						pCoexDm->psTdmaDuAdjType = 15;
2757 					}
2758 					else if(pCoexDm->curPsTdma == 15)
2759 					{
2760 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2761 						pCoexDm->psTdmaDuAdjType = 16;
2762 					}
2763 				}
2764 				else if (result == 1)
2765 				{
2766 					if(pCoexDm->curPsTdma == 8)
2767 					{
2768 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2769 						pCoexDm->psTdmaDuAdjType = 7;
2770 					}
2771 					else if(pCoexDm->curPsTdma == 7)
2772 					{
2773 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2774 						pCoexDm->psTdmaDuAdjType = 7;
2775 					}
2776 					else if(pCoexDm->curPsTdma == 6)
2777 					{
2778 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2779 						pCoexDm->psTdmaDuAdjType = 7;
2780 					}
2781 					else if(pCoexDm->curPsTdma == 16)
2782 					{
2783 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2784 						pCoexDm->psTdmaDuAdjType = 15;
2785 					}
2786 					else if(pCoexDm->curPsTdma == 15)
2787 					{
2788 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2789 						pCoexDm->psTdmaDuAdjType = 15;
2790 					}
2791 					else if(pCoexDm->curPsTdma == 14)
2792 					{
2793 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2794 						pCoexDm->psTdmaDuAdjType = 15;
2795 					}
2796 				}
2797 			}
2798 			else
2799 			{
2800 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));
2801 				if(pCoexDm->curPsTdma == 5)
2802 				{
2803 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2804 					pCoexDm->psTdmaDuAdjType = 3;
2805 				}
2806 				else if(pCoexDm->curPsTdma == 6)
2807 				{
2808 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2809 					pCoexDm->psTdmaDuAdjType = 3;
2810 				}
2811 				else if(pCoexDm->curPsTdma == 7)
2812 				{
2813 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2814 					pCoexDm->psTdmaDuAdjType = 3;
2815 				}
2816 				else if(pCoexDm->curPsTdma == 8)
2817 				{
2818 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2819 					pCoexDm->psTdmaDuAdjType = 4;
2820 				}
2821 				if(pCoexDm->curPsTdma == 13)
2822 				{
2823 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2824 					pCoexDm->psTdmaDuAdjType = 11;
2825 				}
2826 				else if(pCoexDm->curPsTdma == 14)
2827 				{
2828 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2829 					pCoexDm->psTdmaDuAdjType = 11;
2830 				}
2831 				else if(pCoexDm->curPsTdma == 15)
2832 				{
2833 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2834 					pCoexDm->psTdmaDuAdjType = 11;
2835 				}
2836 				else if(pCoexDm->curPsTdma == 16)
2837 				{
2838 					halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2839 					pCoexDm->psTdmaDuAdjType = 12;
2840 				}
2841 				if(result == -1)
2842 				{
2843 					if(pCoexDm->curPsTdma == 1)
2844 					{
2845 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2846 						pCoexDm->psTdmaDuAdjType = 3;
2847 					}
2848 					else if(pCoexDm->curPsTdma == 2)
2849 					{
2850 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2851 						pCoexDm->psTdmaDuAdjType = 3;
2852 					}
2853 					else if(pCoexDm->curPsTdma == 3)
2854 					{
2855 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2856 						pCoexDm->psTdmaDuAdjType = 4;
2857 					}
2858 					else if(pCoexDm->curPsTdma == 9)
2859 					{
2860 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2861 						pCoexDm->psTdmaDuAdjType = 11;
2862 					}
2863 					else if(pCoexDm->curPsTdma == 10)
2864 					{
2865 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2866 						pCoexDm->psTdmaDuAdjType = 11;
2867 					}
2868 					else if(pCoexDm->curPsTdma == 11)
2869 					{
2870 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2871 						pCoexDm->psTdmaDuAdjType = 12;
2872 					}
2873 				}
2874 				else if (result == 1)
2875 				{
2876 					if(pCoexDm->curPsTdma == 4)
2877 					{
2878 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2879 						pCoexDm->psTdmaDuAdjType = 3;
2880 					}
2881 					else if(pCoexDm->curPsTdma == 3)
2882 					{
2883 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2884 						pCoexDm->psTdmaDuAdjType = 3;
2885 					}
2886 					else if(pCoexDm->curPsTdma == 2)
2887 					{
2888 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2889 						pCoexDm->psTdmaDuAdjType = 3;
2890 					}
2891 					else if(pCoexDm->curPsTdma == 12)
2892 					{
2893 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2894 						pCoexDm->psTdmaDuAdjType = 11;
2895 					}
2896 					else if(pCoexDm->curPsTdma == 11)
2897 					{
2898 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2899 						pCoexDm->psTdmaDuAdjType = 11;
2900 					}
2901 					else if(pCoexDm->curPsTdma == 10)
2902 					{
2903 						halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2904 						pCoexDm->psTdmaDuAdjType = 11;
2905 					}
2906 				}
2907 			}
2908 		}
2909 	}
2910 
2911 	// if current PsTdma not match with the recorded one (when scan, dhcp...),
2912 	// then we have to adjust it back to the previous record one.
2913 	if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)
2914 	{
2915 		BOOLEAN	bScan=FALSE, bLink=FALSE, bRoam=FALSE;
2916 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n",
2917 			pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));
2918 
2919 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2920 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2921 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2922 
2923 		if( !bScan && !bLink && !bRoam)
2924 		{
2925 			halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
2926 		}
2927 		else
2928 		{
2929 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
2930 		}
2931 	}
2932 }
2933 
2934 // SCO only or SCO+PAN(HS)
2935 VOID
halbtc8821a2ant_ActionSco(IN PBTC_COEXIST pBtCoexist)2936 halbtc8821a2ant_ActionSco(
2937 	IN	PBTC_COEXIST		pBtCoexist
2938 	)
2939 {
2940 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
2941 	u1Byte	wifiRssiState, btRssiState;
2942 	u4Byte	wifiBw;
2943 
2944 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2945 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2946 
2947 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2948 
2949 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
2950 
2951 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4);
2952 
2953 	if(BTC_RSSI_HIGH(btRssiState))
2954 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2955 	else
2956 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2957 
2958 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2959 
2960 	if (BTC_WIFI_BW_LEGACY == wifiBw) //for SCO quality at 11b/g mode
2961 	{
2962 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2963 	}
2964 	else  //for SCO quality & wifi performance balance at 11n mode
2965 	{
2966 		if(BTC_WIFI_BW_HT40 == wifiBw)
2967 			halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
2968 		else
2969 		{
2970 			if(pBtLinkInfo->bScoOnly)
2971 				halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 17);
2972 			else
2973 				halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);
2974 		}
2975 	}
2976 
2977 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2978 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); //for voice quality
2979 
2980 	// sw mechanism
2981 	if(BTC_WIFI_BW_HT40 == wifiBw)
2982 	{
2983 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2984 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
2985 		{
2986 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
2987 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x18);
2988 		}
2989 		else
2990 		{
2991 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
2992 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x18);
2993 		}
2994 	}
2995 	else
2996 	{
2997 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2998 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
2999 		{
3000 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3001 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x18);
3002 		}
3003 		else
3004 		{
3005 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3006 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x18);
3007 		}
3008 	}
3009 }
3010 
3011 
3012 VOID
halbtc8821a2ant_ActionHid(IN PBTC_COEXIST pBtCoexist)3013 halbtc8821a2ant_ActionHid(
3014 	IN	PBTC_COEXIST		pBtCoexist
3015 	)
3016 {
3017 	u1Byte	wifiRssiState, btRssiState;
3018 	u4Byte	wifiBw;
3019 
3020 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3021 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3022 
3023 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3024 
3025 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3026 
3027 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3028 
3029 	if(BTC_RSSI_HIGH(btRssiState))
3030 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3031 	else
3032 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3033 
3034 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3035 
3036 	if (BTC_WIFI_BW_LEGACY == wifiBw) //for HID at 11b/g mode
3037 	{
3038 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3039 	}
3040 	else  //for HID quality & wifi performance balance at 11n mode
3041 	{
3042 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3043 	}
3044 
3045 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3046 
3047 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);
3048 
3049 	// sw mechanism
3050 	if(BTC_WIFI_BW_HT40 == wifiBw)
3051 	{
3052 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3053 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3054 		{
3055 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3056 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3057 		}
3058 		else
3059 		{
3060  			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3061 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3062 		}
3063 	}
3064 	else
3065 	{
3066 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3067 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3068 		{
3069 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3070 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3071 		}
3072 		else
3073 		{
3074  			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3075 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3076 		}
3077 	}
3078 }
3079 
3080 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)
3081 VOID
halbtc8821a2ant_ActionA2dp(IN PBTC_COEXIST pBtCoexist)3082 halbtc8821a2ant_ActionA2dp(
3083 	IN	PBTC_COEXIST		pBtCoexist
3084 	)
3085 {
3086 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
3087 	u4Byte		wifiBw;
3088 	u1Byte		apNum=0;
3089 
3090 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3091 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3092 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3093 
3094 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
3095 
3096 	// define the office environment
3097 	if( (apNum >= 10) && BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3098 	{
3099 		//DbgPrint(" AP#>10(%d)\n", apNum);
3100 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3101 
3102 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3103 		halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3104 		halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3105 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3106 
3107 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3108 
3109 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3110 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
3111 
3112 		// sw mechanism
3113 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3114 		if(BTC_WIFI_BW_HT40 == wifiBw)
3115 		{
3116 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3117 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);
3118 		}
3119 		else
3120 		{
3121 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3122 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);
3123 		}
3124 		return;
3125 
3126 	}
3127 
3128 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3129 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3130 
3131 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3132 
3133 	if(BTC_RSSI_HIGH(btRssiState))
3134 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3135 	else
3136 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3137 
3138 
3139 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3140 	{
3141 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3142 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3143 	}
3144 	else
3145 	{
3146 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);
3147 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3148 	}
3149 
3150 
3151 	if( (btRssiState == BTC_RSSI_STATE_HIGH) ||
3152 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3153 	{
3154 		halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);
3155 	}
3156 	else
3157 	{
3158 		halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);
3159 	}
3160 
3161 	// sw mechanism
3162 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3163 	if(BTC_WIFI_BW_HT40 == wifiBw)
3164 	{
3165 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3166 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3167 		{
3168  			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3169 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3170 		}
3171 		else
3172 		{
3173 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3174 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3175 		}
3176 	}
3177 	else
3178 	{
3179 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3180 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3181 		{
3182 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3183 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3184 		}
3185 		else
3186 		{
3187 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3188 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3189 		}
3190 	}
3191 }
3192 
3193 VOID
halbtc8821a2ant_ActionA2dpPanHs(IN PBTC_COEXIST pBtCoexist)3194 halbtc8821a2ant_ActionA2dpPanHs(
3195 	IN	PBTC_COEXIST		pBtCoexist
3196 	)
3197 {
3198 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
3199 	u4Byte		wifiBw;
3200 
3201 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3202 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3203 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3204 
3205 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3206 
3207 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3208 
3209 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3210 
3211 	if(BTC_RSSI_HIGH(btRssiState))
3212 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3213 	else
3214 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3215 
3216 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3217 	{
3218 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3219 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3220 	}
3221 	else
3222 	{
3223 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);
3224 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3225 	}
3226 
3227 	halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 2);
3228 
3229 	// sw mechanism
3230 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3231 	if(BTC_WIFI_BW_HT40 == wifiBw)
3232 	{
3233 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3234 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3235 		{
3236  			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3237 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3238 		}
3239 		else
3240 		{
3241 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3242 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3243 		}
3244 	}
3245 	else
3246 	{
3247 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3248 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3249 		{
3250 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3251 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3252 		}
3253 		else
3254 		{
3255 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3256 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3257 		}
3258 	}
3259 }
3260 
3261 VOID
halbtc8821a2ant_ActionPanEdr(IN PBTC_COEXIST pBtCoexist)3262 halbtc8821a2ant_ActionPanEdr(
3263 	IN	PBTC_COEXIST		pBtCoexist
3264 	)
3265 {
3266 	u1Byte		wifiRssiState,wifiRssiState1, btRssiState;
3267 	u4Byte		wifiBw;
3268 
3269 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3270 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3271 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3272 
3273 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3274 
3275 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3276 
3277 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3278 
3279 	if(BTC_RSSI_HIGH(btRssiState))
3280 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3281 	else
3282 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3283 
3284 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3285 	{
3286 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 10);
3287 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3288 	}
3289 	else
3290 	{
3291 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);
3292 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3293 	}
3294 
3295 	if( (btRssiState == BTC_RSSI_STATE_HIGH) ||
3296 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3297 	{
3298 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);	//1->3 for TENCENT spp profile delay time
3299 	}
3300 	else
3301 	{
3302 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
3303 	}
3304 
3305 	// sw mechanism
3306 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3307 	if(BTC_WIFI_BW_HT40 == wifiBw)
3308 	{
3309 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3310 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3311 		{
3312 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3313 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3314 		}
3315 		else
3316 		{
3317 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3318 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3319 		}
3320 	}
3321 	else
3322 	{
3323 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3324 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3325 		{
3326 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3327 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3328 		}
3329 		else
3330 		{
3331 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3332 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3333 		}
3334 	}
3335 }
3336 
3337 
3338 //PAN(HS) only
3339 VOID
halbtc8821a2ant_ActionPanHs(IN PBTC_COEXIST pBtCoexist)3340 halbtc8821a2ant_ActionPanHs(
3341 	IN	PBTC_COEXIST		pBtCoexist
3342 	)
3343 {
3344 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
3345 	u4Byte		wifiBw;
3346 
3347 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3348 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3349 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3350 
3351 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3352 
3353 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3354 
3355 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3356 
3357 	if(BTC_RSSI_HIGH(btRssiState))
3358 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3359 	else
3360 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3361 
3362 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3363 
3364 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3365 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
3366 
3367 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3368 	if(BTC_WIFI_BW_HT40 == wifiBw)
3369 	{
3370 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3371 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3372 		{
3373 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3374 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3375 		}
3376 		else
3377 		{
3378 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3379 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3380 		}
3381 	}
3382 	else
3383 	{
3384 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3385 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3386 		{
3387 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3388 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3389 		}
3390 		else
3391 		{
3392 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3393 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3394 		}
3395 	}
3396 }
3397 
3398 //PAN(EDR)+A2DP
3399 VOID
halbtc8821a2ant_ActionPanEdrA2dp(IN PBTC_COEXIST pBtCoexist)3400 halbtc8821a2ant_ActionPanEdrA2dp(
3401 	IN	PBTC_COEXIST		pBtCoexist
3402 	)
3403 {
3404 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
3405 	u4Byte		wifiBw;
3406 
3407 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3408 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3409 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3410 
3411 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3412 
3413 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3414 
3415 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3416 
3417 	if(BTC_RSSI_HIGH(btRssiState))
3418 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3419 	else
3420 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3421 
3422 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3423 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3424 	else
3425 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3426 
3427 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3428 
3429 	if( (btRssiState == BTC_RSSI_STATE_HIGH) ||
3430 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3431 	{
3432 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);
3433 
3434 		if(BTC_WIFI_BW_HT40 == wifiBw)
3435 			halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);
3436 		else
3437 			halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);
3438 	}
3439 	else
3440 	{
3441 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);
3442 		halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);
3443 	}
3444 
3445 	// sw mechanism
3446 	if(BTC_WIFI_BW_HT40 == wifiBw)
3447 	{
3448 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3449 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3450 		{
3451 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3452 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3453 		}
3454 		else
3455 		{
3456 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3457 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3458 		}
3459 	}
3460 	else
3461 	{
3462 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3463 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3464 		{
3465 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3466 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3467 		}
3468 		else
3469 		{
3470 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3471 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3472 		}
3473 	}
3474 }
3475 
3476 VOID
halbtc8821a2ant_ActionPanEdrHid(IN PBTC_COEXIST pBtCoexist)3477 halbtc8821a2ant_ActionPanEdrHid(
3478 	IN	PBTC_COEXIST		pBtCoexist
3479 	)
3480 {
3481 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
3482 	u4Byte		wifiBw;
3483 
3484 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3485 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3486 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3487 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3488 
3489 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3490 
3491 	if(BTC_RSSI_HIGH(btRssiState))
3492 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3493 	else
3494 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3495 
3496 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3497 	{
3498 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3499 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3500 	}
3501 	else
3502 	{
3503 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);
3504 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3505 	}
3506 
3507 	if( (btRssiState == BTC_RSSI_STATE_HIGH) ||
3508 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3509 	{
3510 		if(BTC_WIFI_BW_HT40 == wifiBw)
3511 		{
3512 			halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 3);
3513 			//halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);
3514 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3515 		}
3516 		else
3517 		{
3518 			halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3519 			//halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3520 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3521 		}
3522 		halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);
3523 	}
3524 	else
3525 	{
3526 		halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3527 		//halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);
3528 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3529 		halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);
3530 	}
3531 
3532 	// sw mechanism
3533 	if(BTC_WIFI_BW_HT40 == wifiBw)
3534 	{
3535 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3536 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3537 		{
3538 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3539 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3540 		}
3541 		else
3542 		{
3543 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3544 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3545 		}
3546 	}
3547 	else
3548 	{
3549 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3550 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3551 		{
3552 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3553 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3554 		}
3555 		else
3556 		{
3557 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3558 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3559 		}
3560 	}
3561 }
3562 
3563 // HID+A2DP+PAN(EDR)
3564 VOID
halbtc8821a2ant_ActionHidA2dpPanEdr(IN PBTC_COEXIST pBtCoexist)3565 halbtc8821a2ant_ActionHidA2dpPanEdr(
3566 	IN	PBTC_COEXIST		pBtCoexist
3567 	)
3568 {
3569 	u1Byte		wifiRssiState,wifiRssiState1,  btRssiState;
3570 	u4Byte		wifiBw;
3571 
3572 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3573 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3574 	btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3575 
3576 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3577 
3578 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3579 
3580 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3581 
3582 	if(BTC_RSSI_HIGH(btRssiState))
3583 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3584 	else
3585 		halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3586 
3587 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3588 	{
3589 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3590 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3591 	}
3592 	else
3593 	{
3594 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);
3595 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3596 	}
3597 
3598 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3599 
3600 	if( (btRssiState == BTC_RSSI_STATE_HIGH) ||
3601 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3602 	{
3603 		if(BTC_WIFI_BW_HT40 == wifiBw)
3604 			halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);
3605 		else
3606 			halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);
3607 	}
3608 	else
3609 	{
3610 		halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);
3611 	}
3612 
3613 	// sw mechanism
3614 	if(BTC_WIFI_BW_HT40 == wifiBw)
3615 	{
3616 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3617 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3618 		{
3619 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3620 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3621 		}
3622 		else
3623 		{
3624 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3625 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3626 		}
3627 	}
3628 	else
3629 	{
3630 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3631 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3632 		{
3633 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3634 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3635 		}
3636 		else
3637 		{
3638 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3639 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3640 		}
3641 	}
3642 }
3643 
3644 VOID
halbtc8821a2ant_ActionHidA2dp(IN PBTC_COEXIST pBtCoexist)3645 halbtc8821a2ant_ActionHidA2dp(
3646 	IN	PBTC_COEXIST		pBtCoexist
3647 	)
3648 {
3649 	u1Byte		wifiRssiState, wifiRssiState1, btRssiState;
3650 	u4Byte		wifiBw;
3651 	u1Byte		apNum=0;
3652 
3653 	wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
3654 	//btRssiState = halbtc8821a2ant_BtRssiState(2, 29, 0);
3655 	wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3656 	btRssiState = halbtc8821a2ant_BtRssiState(3, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);
3657 
3658 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3659 
3660 	halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x5);
3661 
3662 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3663 
3664 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3665 	if(BTC_WIFI_BW_LEGACY == wifiBw)
3666 	{
3667 		if(BTC_RSSI_HIGH(btRssiState))
3668 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3669 		else if(BTC_RSSI_MEDIUM(btRssiState))
3670 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3671 		else
3672 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3673 	}
3674 	else
3675 	{	// only 802.11N mode we have to dec bt power to 4 degree
3676 		if(BTC_RSSI_HIGH(btRssiState))
3677 		{
3678 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
3679 			// need to check ap Number of Not
3680 			if(apNum < 10)
3681 				halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3682 			else
3683 				halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3684 		}
3685 		else if(BTC_RSSI_MEDIUM(btRssiState))
3686 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3687 		else
3688 			halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3689 	}
3690 
3691 	if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))
3692 	{
3693 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3694 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3695 	}
3696 	else
3697 	{
3698 		halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);
3699 		halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3700 	}
3701 
3702 	if( (btRssiState == BTC_RSSI_STATE_HIGH) ||
3703 		(btRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3704 	{
3705 		//halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);
3706 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);
3707 	}
3708 	else
3709 	{
3710 		//halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);
3711 		halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);
3712 	}
3713 
3714 	// sw mechanism
3715 	if(BTC_WIFI_BW_HT40 == wifiBw)
3716 	{
3717 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3718 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3719 		{
3720 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3721 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3722 		}
3723 		else
3724 		{
3725 			halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3726 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3727 		}
3728 	}
3729 	else
3730 	{
3731 		if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
3732 			(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
3733 		{
3734 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3735 			halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3736 		}
3737 		else
3738 		{
3739 			halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3740 			halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3741 		}
3742 	}
3743 }
3744 
3745 VOID
halbtc8821a2ant_ActionBtWhckTest(IN PBTC_COEXIST pBtCoexist)3746 halbtc8821a2ant_ActionBtWhckTest(
3747 	IN	PBTC_COEXIST		pBtCoexist
3748 	)
3749 {
3750 	halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3751 
3752 	// sw all off
3753 	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3754 	halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3755 
3756 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3757 
3758 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
3759 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3760 }
3761 
3762 VOID
halbtc8821a2ant_ActionWifiMultiPort(IN PBTC_COEXIST pBtCoexist)3763 halbtc8821a2ant_ActionWifiMultiPort(
3764 	IN	PBTC_COEXIST		pBtCoexist
3765 	)
3766 {
3767 	halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3768 	halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3769 
3770 	// sw all off
3771 	halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3772 	halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3773 
3774 	// hw all off
3775 	//pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3776 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3777 
3778 	halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3779 	halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
3780 }
3781 
3782 VOID
halbtc8821a2ant_RunCoexistMechanism(IN PBTC_COEXIST pBtCoexist)3783 halbtc8821a2ant_RunCoexistMechanism(
3784 	IN	PBTC_COEXIST		pBtCoexist
3785 	)
3786 {
3787 	BOOLEAN				bWifiUnder5G=FALSE, bBtHsOn=FALSE;
3788 	u1Byte				btInfoOriginal=0, btRetryCnt=0;
3789 	u1Byte				algorithm=0;
3790 	u4Byte				numOfWifiLink=0;
3791 	u4Byte				wifiLinkStatus=0;
3792 	PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
3793 	BOOLEAN				bMiracastPlusBt=FALSE;
3794 	BOOLEAN				bScan=FALSE, bLink=FALSE, bRoam=FALSE;
3795 
3796 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));
3797 
3798 	if(pBtCoexist->bManualControl)
3799 	{
3800 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
3801 		return;
3802 	}
3803 
3804 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
3805 	if(bWifiUnder5G)
3806 	{
3807 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n"));
3808 		halbtc8821a2ant_CoexUnder5G(pBtCoexist);
3809 		return;
3810 	}
3811 
3812 	if(pCoexSta->bUnderIps)
3813 	{
3814 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));
3815 		return;
3816 	}
3817 
3818 	if(pCoexSta->bBtWhckTest)
3819 	{
3820 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));
3821 		halbtc8821a2ant_ActionBtWhckTest(pBtCoexist);
3822 		return;
3823 	}
3824 
3825 	algorithm = halbtc8821a2ant_ActionAlgorithm(pBtCoexist);
3826 	if(pCoexSta->bC2hBtInquiryPage && (BT_8821A_2ANT_COEX_ALGO_PANHS!=algorithm))
3827 	{
3828 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under inquiry/page scan !!\n"));
3829 		halbtc8821a2ant_ActionBtInquiry(pBtCoexist);
3830 		return;
3831 	}
3832 	else
3833 	{
3834 
3835 	}
3836 
3837 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
3838 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
3839 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
3840 
3841 	if(bScan || bLink || bRoam)
3842 	{
3843 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], WiFi is under Link Process !!\n"));
3844 		halbtc8821a2ant_ActionWiFiLinkProcess(pBtCoexist);
3845 		return;
3846 	}
3847 
3848 	//for P2P
3849 
3850 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
3851 	numOfWifiLink = wifiLinkStatus>>16;
3852 
3853 	if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))
3854 	{
3855 		RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex],  Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );
3856 
3857 		if(pBtLinkInfo->bBtLinkExist)
3858 		{
3859 			bMiracastPlusBt = TRUE;
3860 		}
3861 		else
3862 		{
3863 			bMiracastPlusBt = FALSE;
3864 		}
3865 
3866 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3867 		halbtc8821a2ant_ActionWifiMultiPort(pBtCoexist);
3868 
3869 		return;
3870 	}
3871 	else
3872 	{
3873 		bMiracastPlusBt = FALSE;
3874 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3875 	}
3876 
3877 	pCoexDm->curAlgorithm = algorithm;
3878 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));
3879 
3880 	if(halbtc8821a2ant_IsCommonAction(pBtCoexist))
3881 	{
3882 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant common.\n"));
3883 		pCoexDm->bAutoTdmaAdjust = FALSE;
3884 	}
3885 	else
3886 	{
3887 		if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)
3888 		{
3889 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n",
3890 				pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));
3891 			pCoexDm->bAutoTdmaAdjust = FALSE;
3892 		}
3893 		switch(pCoexDm->curAlgorithm)
3894 		{
3895 			case BT_8821A_2ANT_COEX_ALGO_SCO:
3896 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));
3897 				halbtc8821a2ant_ActionSco(pBtCoexist);
3898 				break;
3899 			case BT_8821A_2ANT_COEX_ALGO_HID:
3900 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));
3901 				halbtc8821a2ant_ActionHid(pBtCoexist);
3902 				break;
3903 			case BT_8821A_2ANT_COEX_ALGO_A2DP:
3904 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));
3905 				halbtc8821a2ant_ActionA2dp(pBtCoexist);
3906 				break;
3907 			case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
3908 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));
3909 				halbtc8821a2ant_ActionA2dpPanHs(pBtCoexist);
3910 				break;
3911 			case BT_8821A_2ANT_COEX_ALGO_PANEDR:
3912 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));
3913 				halbtc8821a2ant_ActionPanEdr(pBtCoexist);
3914 				break;
3915 			case BT_8821A_2ANT_COEX_ALGO_PANHS:
3916 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));
3917 				halbtc8821a2ant_ActionPanHs(pBtCoexist);
3918 				break;
3919 			case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
3920 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));
3921 				halbtc8821a2ant_ActionPanEdrA2dp(pBtCoexist);
3922 				break;
3923 			case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
3924 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
3925 				halbtc8821a2ant_ActionPanEdrHid(pBtCoexist);
3926 				break;
3927 			case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3928 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
3929 				halbtc8821a2ant_ActionHidA2dpPanEdr(pBtCoexist);
3930 				break;
3931 			case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
3932 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));
3933 				halbtc8821a2ant_ActionHidA2dp(pBtCoexist);
3934 				break;
3935 			default:
3936 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));
3937 				halbtc8821a2ant_CoexAllOff(pBtCoexist);
3938 				break;
3939 		}
3940 		pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
3941 	}
3942 }
3943 
3944 VOID
halbtc8821a2ant_WifiOffHwCfg(IN PBTC_COEXIST pBtCoexist)3945 halbtc8821a2ant_WifiOffHwCfg(
3946 	IN	PBTC_COEXIST		pBtCoexist
3947 	)
3948 {
3949 	BOOLEAN	bIsInMpMode = FALSE;
3950 	u1Byte H2C_Parameter[2] ={0};
3951 	u4Byte fwVer=0;
3952 
3953 	// set wlan_act to low
3954 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
3955 
3956 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); //WiFi goto standby while GNT_BT 0-->1
3957 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
3958 	if(fwVer >= 0x180000)
3959 	{
3960 		/* Use H2C to set GNT_BT to HIGH */
3961 		H2C_Parameter[0] = 1;
3962 		pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
3963 	}
3964 	else
3965 	{
3966 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
3967 	}
3968 }
3969 
3970 VOID
halbtc8821a2ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bBackUp)3971 halbtc8821a2ant_InitHwConfig(
3972 	IN	PBTC_COEXIST		pBtCoexist,
3973 	IN	BOOLEAN				bBackUp
3974 	)
3975 {
3976 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
3977 	u4Byte	u4Tmp=0, fwVer;
3978 	u2Byte				u2Tmp=0;
3979 	u1Byte	u1Tmp=0;
3980 	u1Byte				H2C_Parameter[2] ={0};
3981 
3982 
3983 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));
3984 
3985 	// backup rf 0x1e value
3986 	pCoexDm->btRf0x1eBackup =
3987 		pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);
3988 
3989 	// 0x790[5:0]=0x5
3990 	u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);
3991 	u1Tmp &= 0xc0;
3992 	u1Tmp |= 0x5;
3993 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);
3994 
3995 	//Antenna config
3996 	halbtc8821a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, TRUE, FALSE);
3997 	pCoexSta->disVerInfoCnt = 0;
3998 
3999 	// PTA parameter
4000 	halbtc8821a2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
4001 
4002 	// Enable counter statistics
4003 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); //0x76e[3] =1, WLAN_Act control by PTA
4004 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);
4005 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
4006 }
4007 
4008 //============================================================
4009 // work around function start with wa_halbtc8821a2ant_
4010 //============================================================
4011 //============================================================
4012 // extern function start with EXhalbtc8821a2ant_
4013 //============================================================
4014 VOID
EXhalbtc8821a2ant_PowerOnSetting(IN PBTC_COEXIST pBtCoexist)4015 EXhalbtc8821a2ant_PowerOnSetting(
4016 	IN	PBTC_COEXIST		pBtCoexist
4017 	)
4018 {
4019 
4020 }
4021 
4022 VOID
EXhalbtc8821a2ant_PreLoadFirmware(IN PBTC_COEXIST pBtCoexist)4023 EXhalbtc8821a2ant_PreLoadFirmware(
4024 	IN	PBTC_COEXIST		pBtCoexist
4025 	)
4026 {
4027 	PBTC_BOARD_INFO 	pBoardInfo=&pBtCoexist->boardInfo;
4028 	u1Byte u1Tmp=0x4; /* Set BIT2 by default since it's 2ant case */
4029 
4030 	//
4031 	// S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)
4032 	// Local setting bit define
4033 	//	BIT0: "0" for no antenna inverse; "1" for antenna inverse
4034 	//	BIT1: "0" for internal switch; "1" for external switch
4035 	//	BIT2: "0" for one antenna; "1" for two antenna
4036 	// NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0
4037 	if(pBtCoexist->chipInterface == BTC_INTF_USB)
4038 	{
4039 		// fixed at S0 for USB interface
4040 	 	u1Tmp |= 0x1;	// antenna inverse
4041 		pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
4042 	}
4043 	else
4044 	{
4045 		// for PCIE and SDIO interface, we check efuse 0xc3[6]
4046 		if(pBoardInfo->singleAntPath == 0)
4047 		{
4048 		}
4049 		else if(pBoardInfo->singleAntPath == 1)
4050 		{
4051 			// set to S0
4052 			u1Tmp |= 0x1;	// antenna inverse
4053 		}
4054 
4055 		if(pBtCoexist->chipInterface == BTC_INTF_PCI)
4056 		{
4057 			pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
4058 		}
4059 		else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
4060 		{
4061 			pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
4062 		}
4063 	}
4064 }
4065 
4066 VOID
EXhalbtc8821a2ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bWifiOnly)4067 EXhalbtc8821a2ant_InitHwConfig(
4068 	IN	PBTC_COEXIST		pBtCoexist,
4069 	IN	BOOLEAN				bWifiOnly
4070 	)
4071 {
4072 	halbtc8821a2ant_InitHwConfig(pBtCoexist, TRUE);
4073 }
4074 
4075 VOID
EXhalbtc8821a2ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)4076 EXhalbtc8821a2ant_InitCoexDm(
4077 	IN	PBTC_COEXIST		pBtCoexist
4078 	)
4079 {
4080 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
4081 
4082 	halbtc8821a2ant_InitCoexDm(pBtCoexist);
4083 }
4084 
4085 VOID
EXhalbtc8821a2ant_DisplayCoexInfo(IN PBTC_COEXIST pBtCoexist)4086 EXhalbtc8821a2ant_DisplayCoexInfo(
4087 	IN	PBTC_COEXIST		pBtCoexist
4088 	)
4089 {
4090 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
4091 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
4092 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
4093 	pu1Byte				cliBuf=pBtCoexist->cliBuf;
4094 	u1Byte				u1Tmp[4], i, btInfoExt, psTdmaCase=0;
4095 	u4Byte				u4Tmp[4];
4096 	u4Byte				faOfdm, faCck;
4097 	u4Byte				fwVer=0, btPatchVer=0;
4098 
4099 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
4100 	CL_PRINTF(cliBuf);
4101 
4102 	if(pBtCoexist->bManualControl)
4103 	{
4104 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
4105 		CL_PRINTF(cliBuf);
4106 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4107 		CL_PRINTF(cliBuf);
4108 	}
4109 
4110 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
4111 		pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);
4112 	CL_PRINTF(cliBuf);
4113 
4114 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
4115 		((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
4116 	CL_PRINTF(cliBuf);
4117 
4118 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
4119 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
4120 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
4121 		GLCoexVerDate8821a2Ant, GLCoexVer8821a2Ant, fwVer, btPatchVer, btPatchVer);
4122 	CL_PRINTF(cliBuf);
4123 
4124 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
4125 		pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
4126 		pCoexDm->wifiChnlInfo[2]);
4127 	CL_PRINTF(cliBuf);
4128 
4129 	// wifi status
4130 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
4131 	CL_PRINTF(cliBuf);
4132 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
4133 
4134 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
4135 	CL_PRINTF(cliBuf);
4136 
4137 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %ddBm/ %d] ", "BT [status/ rssi/ retryCnt]", \
4138 		((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):	((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
4139 		(  (BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
4140 		pCoexSta->btRssi-100, pCoexSta->btRetryCnt);
4141 	CL_PRINTF(cliBuf);
4142 
4143 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
4144 		pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);
4145 	CL_PRINTF(cliBuf);
4146 
4147 	if (pStackInfo->bProfileNotified)
4148 	{
4149 		pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
4150 	}
4151 	else
4152 	{
4153 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role", \
4154 		(pBtLinkInfo->bSlaveRole )? "Slave":"Master");
4155 		CL_PRINTF(cliBuf);
4156 	}
4157 
4158 	btInfoExt = pCoexSta->btInfoExt;
4159 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \
4160 		(btInfoExt&BIT0)? "Basic rate":"EDR rate");
4161 	CL_PRINTF(cliBuf);
4162 
4163 	for(i=0; i<BT_INFO_SRC_8821A_2ANT_MAX; i++)
4164 	{
4165 		if(pCoexSta->btInfoC2hCnt[i])
4166 		{
4167 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8821a2Ant[i], \
4168 				pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
4169 				pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
4170 				pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
4171 				pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
4172 			CL_PRINTF(cliBuf);
4173 		}
4174 	}
4175 
4176 	// Sw mechanism
4177 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
4178 	CL_PRINTF(cliBuf);
4179 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \
4180 		pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);
4181 	CL_PRINTF(cliBuf);
4182 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \
4183 		pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);
4184 	CL_PRINTF(cliBuf);
4185 
4186 	// Fw mechanism
4187 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
4188 	CL_PRINTF(cliBuf);
4189 
4190 	psTdmaCase = pCoexDm->curPsTdma;
4191 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \
4192 		pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
4193 		pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
4194 		pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);
4195 	CL_PRINTF(cliBuf);
4196 
4197 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type", \
4198 			pCoexSta->nCoexTableType);
4199 		CL_PRINTF(cliBuf);
4200 
4201 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \
4202 		pCoexDm->curBtDecPwrLvl, pCoexDm->bCurIgnoreWlanAct);
4203 	CL_PRINTF(cliBuf);
4204 
4205 	// Hw setting
4206 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
4207 	CL_PRINTF(cliBuf);
4208 
4209 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
4210 		pCoexDm->btRf0x1eBackup);
4211 	CL_PRINTF(cliBuf);
4212 
4213 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
4214 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xc5b);
4215 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
4216 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x880[29:25]/0xc58[29:25]", \
4217 		u1Tmp[0], (u4Tmp[0]&0x3e000000) >> 25, ((u1Tmp[1]&0x3e)>>1));
4218 	CL_PRINTF(cliBuf);
4219 
4220 	u4Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x764);
4221 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
4222 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x764/ 0x765/ 0x76e", \
4223 		(u4Tmp[0]&0xff), (u4Tmp[0]&0xff00)>>8, u1Tmp[0]);
4224 	CL_PRINTF(cliBuf);
4225 
4226 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcb4);
4227 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)", \
4228 		u4Tmp[0]&0xff, ((u4Tmp[0]&0x30000000)>>28));
4229 	CL_PRINTF(cliBuf);
4230 
4231 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
4232 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
4233 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x974);
4234 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x40/ 0x4c[24:23]/ 0x974", \
4235 		u1Tmp[0], ((u4Tmp[0]&0x01800000)>>23), u4Tmp[1]);
4236 	CL_PRINTF(cliBuf);
4237 
4238 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
4239 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
4240 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
4241 		u4Tmp[0], u1Tmp[0]);
4242 	CL_PRINTF(cliBuf);
4243 
4244 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
4245 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);
4246 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \
4247 		u4Tmp[0]&0xff, u1Tmp[0]);
4248 	CL_PRINTF(cliBuf);
4249 
4250 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
4251 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
4252 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
4253 	u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
4254 
4255 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
4256 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
4257 
4258 	faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) +  ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \
4259 		             ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;
4260 	faCck = (u1Tmp[0] << 8) + u1Tmp[1];
4261 
4262 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \
4263 		u4Tmp[0]&0xffff, faOfdm, faCck);
4264 	CL_PRINTF(cliBuf);
4265 
4266 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \
4267 		pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);
4268 	CL_PRINTF(cliBuf);
4269 
4270 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \
4271 		pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);
4272 	CL_PRINTF(cliBuf);
4273 
4274 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
4275 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
4276 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
4277 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);
4278 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
4279 		u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);
4280 	CL_PRINTF(cliBuf);
4281 
4282 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
4283 		pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
4284 	CL_PRINTF(cliBuf);
4285 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
4286 		pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
4287 	CL_PRINTF(cliBuf);
4288 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 1)
4289 	//halbtc8821a2ant_MonitorBtCtr(pBtCoexist);
4290 #endif
4291 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
4292 }
4293 
4294 
4295 VOID
EXhalbtc8821a2ant_IpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4296 EXhalbtc8821a2ant_IpsNotify(
4297 	IN	PBTC_COEXIST		pBtCoexist,
4298 	IN	u1Byte			type
4299 	)
4300 {
4301 	if(BTC_IPS_ENTER == type)
4302 	{
4303 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
4304 		pCoexSta->bUnderIps = TRUE;
4305 		halbtc8821a2ant_WifiOffHwCfg(pBtCoexist);
4306 		halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4307 		halbtc8821a2ant_CoexAllOff(pBtCoexist);
4308 	}
4309 	else if(BTC_IPS_LEAVE == type)
4310 	{
4311 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
4312 		pCoexSta->bUnderIps = FALSE;
4313 		halbtc8821a2ant_InitHwConfig(pBtCoexist, FALSE);
4314 		halbtc8821a2ant_InitCoexDm(pBtCoexist);
4315 		halbtc8821a2ant_QueryBtInfo(pBtCoexist);
4316 	}
4317 }
4318 
4319 VOID
EXhalbtc8821a2ant_LpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4320 EXhalbtc8821a2ant_LpsNotify(
4321 	IN	PBTC_COEXIST		pBtCoexist,
4322 	IN	u1Byte			type
4323 	)
4324 {
4325 	if(BTC_LPS_ENABLE == type)
4326 	{
4327 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
4328 		pCoexSta->bUnderLps = TRUE;
4329 	}
4330 	else if(BTC_LPS_DISABLE == type)
4331 	{
4332 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
4333 		pCoexSta->bUnderLps = FALSE;
4334 	}
4335 }
4336 
4337 VOID
EXhalbtc8821a2ant_ScanNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4338 EXhalbtc8821a2ant_ScanNotify(
4339 	IN	PBTC_COEXIST		pBtCoexist,
4340 	IN	u1Byte			type
4341 	)
4342 {
4343 	u1Byte 	u1Tmpa, u1Tmpb;
4344 
4345 	u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
4346 	u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
4347 
4348 	if(BTC_SCAN_START == type)
4349 	{
4350 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4351 	}
4352 	else if(BTC_SCAN_FINISH == type)
4353 	{
4354 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4355 	}
4356 
4357 	RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u1Tmpa, u1Tmpb));
4358 }
4359 
4360 VOID
EXhalbtc8821a2ant_ConnectNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4361 EXhalbtc8821a2ant_ConnectNotify(
4362 	IN	PBTC_COEXIST		pBtCoexist,
4363 	IN	u1Byte			type
4364 	)
4365 {
4366 	if(BTC_ASSOCIATE_START == type)
4367 	{
4368 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
4369 	}
4370 	else if(BTC_ASSOCIATE_FINISH == type)
4371 	{
4372 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
4373 	}
4374 }
4375 
4376 VOID
EXhalbtc8821a2ant_MediaStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4377 EXhalbtc8821a2ant_MediaStatusNotify(
4378 	IN	PBTC_COEXIST		pBtCoexist,
4379 	IN	u1Byte				type
4380 	)
4381 {
4382 	u1Byte			H2C_Parameter[3] ={0};
4383 	u4Byte			wifiBw;
4384 	u1Byte			wifiCentralChnl;
4385 	u1Byte			apNum=0;
4386 
4387 	if(BTC_MEDIA_CONNECT == type)
4388 	{
4389 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
4390 	}
4391 	else
4392 	{
4393 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
4394 	}
4395 
4396 	// only 2.4G we need to inform bt the chnl mask
4397 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
4398 	if( (BTC_MEDIA_CONNECT == type) &&
4399 		(wifiCentralChnl <= 14) )
4400 	{
4401 		H2C_Parameter[0] = 0x1;
4402 		H2C_Parameter[1] = wifiCentralChnl;
4403 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4404 		if(BTC_WIFI_BW_HT40 == wifiBw)
4405 			H2C_Parameter[2] = 0x30;
4406 		else
4407 		{
4408 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
4409 			if(apNum < 10)
4410 				H2C_Parameter[2] = 0x30;
4411 			else
4412 				H2C_Parameter[2] = 0x20;
4413 		}
4414 	}
4415 
4416 	pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
4417 	pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
4418 	pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
4419 
4420 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n",
4421 		H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
4422 
4423 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
4424 }
4425 
4426 VOID
EXhalbtc8821a2ant_SpecialPacketNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4427 EXhalbtc8821a2ant_SpecialPacketNotify(
4428 	IN	PBTC_COEXIST			pBtCoexist,
4429 	IN	u1Byte				type
4430 	)
4431 {
4432 	if(type == BTC_PACKET_DHCP)
4433 	{
4434 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));
4435 	}
4436 }
4437 
4438 VOID
EXhalbtc8821a2ant_BtInfoNotify(IN PBTC_COEXIST pBtCoexist,IN pu1Byte tmpBuf,IN u1Byte length)4439 EXhalbtc8821a2ant_BtInfoNotify(
4440 	IN	PBTC_COEXIST		pBtCoexist,
4441 	IN	pu1Byte			tmpBuf,
4442 	IN	u1Byte			length
4443 	)
4444 {
4445 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
4446 	u1Byte			btInfo=0;
4447 	u1Byte			i, rspSource=0;
4448 	BOOLEAN			bBtBusy=FALSE, bLimitedDig=FALSE;
4449 	BOOLEAN			bWifiConnected=FALSE, bWifiUnder5G=FALSE;
4450 	static BOOLEAN		bPreScoExist=FALSE;
4451 	u4Byte				raMask=0x0;
4452 
4453 	pCoexSta->bC2hBtInfoReqSent = FALSE;
4454 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
4455 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4456 
4457 	rspSource = tmpBuf[0]&0xf;
4458 	if(rspSource >= BT_INFO_SRC_8821A_2ANT_MAX)
4459 		rspSource = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
4460 	pCoexSta->btInfoC2hCnt[rspSource]++;
4461 
4462 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
4463 	for(i=0; i<length; i++)
4464 	{
4465 		pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
4466 		if(i == 1)
4467 			btInfo = tmpBuf[i];
4468 		if(i == length-1)
4469 		{
4470 			RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
4471 		}
4472 		else
4473 		{
4474 			RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
4475 		}
4476 	}
4477 
4478 	if(pBtCoexist->bManualControl)
4479 	{
4480 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));
4481 		return;
4482 	}
4483 
4484 	// if 0xff, it means BT is under WHCK test
4485 	if (btInfo == 0xff)
4486 		pCoexSta->bBtWhckTest = TRUE;
4487 	else
4488 		pCoexSta->bBtWhckTest = FALSE;
4489 
4490 	if(BT_INFO_SRC_8821A_2ANT_WIFI_FW != rspSource)
4491 	{
4492 		pCoexSta->btRetryCnt =	// [3:0]
4493 			pCoexSta->btInfoC2h[rspSource][2]&0xf;
4494 
4495 		pCoexSta->btRssi =
4496 			pCoexSta->btInfoC2h[rspSource][3]*2+10;
4497 
4498 		pCoexSta->btInfoExt =
4499 			pCoexSta->btInfoC2h[rspSource][4];
4500 
4501 		pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
4502 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
4503 		if(pCoexSta->bBtTxRxMask)
4504 		{
4505 			/* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */
4506 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"));
4507 			pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01);
4508 		}
4509 
4510 		// Here we need to resend some wifi info to BT
4511 		// because bt is reset and loss of the info.
4512 		if( (pCoexSta->btInfoExt & BIT1) )
4513 		{
4514 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
4515 			if(bWifiConnected)
4516 			{
4517 				EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
4518 			}
4519 			else
4520 			{
4521 				EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
4522 			}
4523 		}
4524 
4525 
4526 		if(!pBtCoexist->bManualControl && !bWifiUnder5G)
4527 		{
4528 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info = 0x%x!!\n", pCoexSta->btInfoExt));
4529 			if( (pCoexSta->btInfoExt&BIT3) )
4530 			{
4531 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3=1, bWifiConnected=%d\n", bWifiConnected));
4532 				if(bWifiConnected)
4533 				{
4534 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
4535 					halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
4536 				}
4537 			}
4538 			else
4539 			{
4540 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3=0, bWifiConnected=%d\n", bWifiConnected));
4541 				// BT already NOT ignore Wlan active, do nothing here.
4542 				if(!bWifiConnected)
4543 				{
4544 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n"));
4545 					halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4546 				}
4547 			}
4548 		}
4549 
4550 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)
4551 		if( (pCoexSta->btInfoExt & BIT4) )
4552 		{
4553 			// BT auto report already enabled, do nothing
4554 		}
4555 		else
4556 		{
4557 			halbtc8821a2ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);
4558 		}
4559 #endif
4560 	}
4561 
4562 	// check BIT2 first ==> check if bt is under inquiry or page scan
4563 	if(btInfo & BT_INFO_8821A_2ANT_B_INQ_PAGE)
4564 		pCoexSta->bC2hBtInquiryPage = TRUE;
4565 	else
4566 		pCoexSta->bC2hBtInquiryPage = FALSE;
4567 
4568 	// set link exist status
4569 	if(!(btInfo&BT_INFO_8821A_2ANT_B_CONNECTION))
4570 	{
4571 		pCoexSta->bBtLinkExist = FALSE;
4572 		pCoexSta->bPanExist = FALSE;
4573 		pCoexSta->bA2dpExist = FALSE;
4574 		pCoexSta->bHidExist = FALSE;
4575 		pCoexSta->bScoExist = FALSE;
4576 	}
4577 	else	// connection exists
4578 	{
4579 		pCoexSta->bBtLinkExist = TRUE;
4580 		if(btInfo & BT_INFO_8821A_2ANT_B_FTP)
4581 			pCoexSta->bPanExist = TRUE;
4582 		else
4583 			pCoexSta->bPanExist = FALSE;
4584 		if(btInfo & BT_INFO_8821A_2ANT_B_A2DP)
4585 			pCoexSta->bA2dpExist = TRUE;
4586 		else
4587 			pCoexSta->bA2dpExist = FALSE;
4588 		if(btInfo & BT_INFO_8821A_2ANT_B_HID)
4589 			pCoexSta->bHidExist = TRUE;
4590 		else
4591 			pCoexSta->bHidExist = FALSE;
4592 		if(btInfo & BT_INFO_8821A_2ANT_B_SCO_ESCO)
4593 			pCoexSta->bScoExist = TRUE;
4594 		else
4595 			pCoexSta->bScoExist = FALSE;
4596 
4597 		if ( (pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) && (pCoexSta->bScoExist == FALSE))
4598 		{
4599 			if (pCoexSta->highPriorityTx  + pCoexSta->highPriorityRx >= 160)
4600 				pCoexSta->bHidExist = TRUE;
4601 		}
4602 	}
4603 
4604 	halbtc8821a2ant_UpdateBtLinkInfo(pBtCoexist);
4605 
4606 	if(!(btInfo&BT_INFO_8821A_2ANT_B_CONNECTION))
4607 	{
4608 		pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
4609 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
4610 	}
4611 	else if(btInfo == BT_INFO_8821A_2ANT_B_CONNECTION)	// connection exists but no busy
4612 	{
4613 		pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE;
4614 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
4615 	}
4616 	else if((btInfo&BT_INFO_8821A_2ANT_B_SCO_ESCO) ||
4617 		(btInfo&BT_INFO_8821A_2ANT_B_SCO_BUSY))
4618 	{
4619 		pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_SCO_BUSY;
4620 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
4621 	}
4622 	else if(btInfo&BT_INFO_8821A_2ANT_B_ACL_BUSY)
4623 	{
4624 		pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_ACL_BUSY;
4625 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
4626 	}
4627 	else
4628 	{
4629 		pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_MAX;
4630 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
4631 	}
4632 
4633 	if( (BT_8821A_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
4634 		(BT_8821A_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
4635 		(BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
4636 	{
4637 		bBtBusy = TRUE;
4638 		bLimitedDig = TRUE;
4639 	}
4640 	else
4641 	{
4642 		bBtBusy = FALSE;
4643 		bLimitedDig = FALSE;
4644 	}
4645 
4646 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
4647 
4648 	pCoexDm->bLimitedDig = bLimitedDig;
4649 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);
4650 
4651 	halbtc8821a2ant_RunCoexistMechanism(pBtCoexist);
4652 }
4653 
4654 VOID
EXhalbtc8821a2ant_HaltNotify(IN PBTC_COEXIST pBtCoexist)4655 EXhalbtc8821a2ant_HaltNotify(
4656 	IN	PBTC_COEXIST			pBtCoexist
4657 	)
4658 {
4659 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
4660 
4661 	halbtc8821a2ant_WifiOffHwCfg(pBtCoexist);
4662 	//remove due to interrupt is disabled that polling c2h will fail and delay 100ms.
4663 	//pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0
4664 	halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4665 
4666 	EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
4667 }
4668 
4669 VOID
EXhalbtc8821a2ant_PnpNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte pnpState)4670 EXhalbtc8821a2ant_PnpNotify(
4671 	IN	PBTC_COEXIST			pBtCoexist,
4672 	IN	u1Byte				pnpState
4673 	)
4674 {
4675 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));
4676 
4677 	if(BTC_WIFI_PNP_SLEEP == pnpState)
4678 	{
4679 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));
4680 	}
4681 	else if(BTC_WIFI_PNP_WAKE_UP == pnpState)
4682 	{
4683 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));
4684 		halbtc8821a2ant_InitHwConfig(pBtCoexist, FALSE);
4685 		halbtc8821a2ant_InitCoexDm(pBtCoexist);
4686 		halbtc8821a2ant_QueryBtInfo(pBtCoexist);
4687 	}
4688 }
4689 
4690 VOID
EXhalbtc8821a2ant_Periodical(IN PBTC_COEXIST pBtCoexist)4691 EXhalbtc8821a2ant_Periodical(
4692 	IN	PBTC_COEXIST			pBtCoexist
4693 	)
4694 {
4695 	//static u1Byte		disVerInfoCnt=0;
4696 	u4Byte				fwVer=0, btPatchVer=0;
4697 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
4698 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
4699 
4700 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));
4701 
4702 	if(pCoexSta->disVerInfoCnt <= 5)
4703 	{
4704 		pCoexSta->disVerInfoCnt += 1;
4705 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
4706 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
4707 			pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));
4708 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",
4709 			((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));
4710 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
4711 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
4712 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
4713 			GLCoexVerDate8821a2Ant, GLCoexVer8821a2Ant, fwVer, btPatchVer, btPatchVer));
4714 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
4715 
4716 		if (pCoexSta->disVerInfoCnt == 3)
4717 		{
4718 			//Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial
4719 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set GNT_BT control by PTA\n"));
4720 			halbtc8821a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, FALSE, FALSE);
4721 		}
4722 	}
4723 
4724 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)
4725 	halbtc8821a2ant_QueryBtInfo(pBtCoexist);
4726 	halbtc8821a2ant_MonitorBtEnableDisable(pBtCoexist);
4727 #else
4728 	halbtc8821a2ant_MonitorBtCtr(pBtCoexist);
4729 	halbtc8821a2ant_MonitorWiFiCtr(pBtCoexist);
4730 
4731 	if( halbtc8821a2ant_IsWifiStatusChanged(pBtCoexist) ||
4732 		pCoexDm->bAutoTdmaAdjust)
4733 	{
4734 		halbtc8821a2ant_RunCoexistMechanism(pBtCoexist);
4735 	}
4736 #endif
4737 }
4738 
4739 
4740 #endif
4741 
4742