xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8189es/hal/btc/HalBtc8812a2Ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 //============================================================
3 // Description:
4 //
5 // This file is for RTL8812A Co-exist mechanism
6 //
7 // History
8 // 2012/08/22 Cosa first check in.
9 // 2012/11/14 Cosa Revise for 8812A 2Ant out sourcing.
10 //
11 //============================================================
12 
13 //============================================================
14 // include files
15 //============================================================
16 #include "Mp_Precomp.h"
17 
18 #if WPP_SOFTWARE_TRACE
19 #include "HalBtc8812a2Ant.tmh"
20 #endif
21 
22 #if(BT_30_SUPPORT == 1)
23 //============================================================
24 // Global variables, these are static variables
25 //============================================================
26 static COEX_DM_8812A_2ANT	GLCoexDm8812a2Ant;
27 static PCOEX_DM_8812A_2ANT 	pCoexDm=&GLCoexDm8812a2Ant;
28 static COEX_STA_8812A_2ANT	GLCoexSta8812a2Ant;
29 static PCOEX_STA_8812A_2ANT	pCoexSta=&GLCoexSta8812a2Ant;
30 
31 const char *const GLBtInfoSrc8812a2Ant[]={
32 	"BT Info[wifi fw]",
33 	"BT Info[bt rsp]",
34 	"BT Info[bt auto report]",
35 };
36 
37 u4Byte	GLCoexVerDate8812a2Ant=20150408;
38 u4Byte	GLCoexVer8812a2Ant=0x39;
39 //improve 8761ATV D-cut BT off/on fail issue
40 //============================================================
41 // local function proto type if needed
42 //============================================================
43 //============================================================
44 // local function start with halbtc8812a2ant_
45 //============================================================
46 u1Byte
halbtc8812a2ant_BtRssiState(u1Byte levelNum,u1Byte rssiThresh,u1Byte rssiThresh1)47 halbtc8812a2ant_BtRssiState(
48 	u1Byte			levelNum,
49 	u1Byte			rssiThresh,
50 	u1Byte			rssiThresh1
51 	)
52 {
53 	s4Byte			btRssi=0;
54 	u1Byte			btRssiState=pCoexSta->preBtRssiState;
55 
56 	btRssi = pCoexSta->btRssi;
57 
58 	if(levelNum == 2)
59 	{
60 		if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
61 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
62 		{
63 			if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
64 			{
65 				btRssiState = BTC_RSSI_STATE_HIGH;
66 			}
67 			else
68 			{
69 				btRssiState = BTC_RSSI_STATE_STAY_LOW;
70 			}
71 		}
72 		else
73 		{
74 			if(btRssi < rssiThresh)
75 			{
76 				btRssiState = BTC_RSSI_STATE_LOW;
77 			}
78 			else
79 			{
80 				btRssiState = BTC_RSSI_STATE_STAY_HIGH;
81 			}
82 		}
83 	}
84 	else if(levelNum == 3)
85 	{
86 		if(rssiThresh > rssiThresh1)
87 		{
88 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));
89 			return pCoexSta->preBtRssiState;
90 		}
91 
92 		if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
93 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
94 		{
95 			if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
96 			{
97 				btRssiState = BTC_RSSI_STATE_MEDIUM;
98 			}
99 			else
100 			{
101 				btRssiState = BTC_RSSI_STATE_STAY_LOW;
102 			}
103 		}
104 		else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
105 			(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))
106 		{
107 			if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
108 			{
109 				btRssiState = BTC_RSSI_STATE_HIGH;
110 			}
111 			else if(btRssi < rssiThresh)
112 			{
113 				btRssiState = BTC_RSSI_STATE_LOW;
114 			}
115 			else
116 			{
117 				btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
118 			}
119 		}
120 		else
121 		{
122 			if(btRssi < rssiThresh1)
123 			{
124 				btRssiState = BTC_RSSI_STATE_MEDIUM;
125 			}
126 			else
127 			{
128 				btRssiState = BTC_RSSI_STATE_STAY_HIGH;
129 			}
130 		}
131 	}
132 
133 	pCoexSta->preBtRssiState = btRssiState;
134 
135 	return btRssiState;
136 }
137 
138 u1Byte
halbtc8812a2ant_WifiRssiState(IN PBTC_COEXIST pBtCoexist,IN u1Byte index,IN u1Byte levelNum,IN u1Byte rssiThresh,IN u1Byte rssiThresh1)139 halbtc8812a2ant_WifiRssiState(
140 	IN	PBTC_COEXIST		pBtCoexist,
141 	IN	u1Byte			index,
142 	IN	u1Byte			levelNum,
143 	IN	u1Byte			rssiThresh,
144 	IN	u1Byte			rssiThresh1
145 	)
146 {
147 	s4Byte			wifiRssi=0;
148 	u1Byte			wifiRssiState=pCoexSta->preWifiRssiState[index];
149 
150 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
151 
152 	if(levelNum == 2)
153 	{
154 		if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
155 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
156 		{
157 			if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
158 			{
159 				wifiRssiState = BTC_RSSI_STATE_HIGH;
160 			}
161 			else
162 			{
163 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
164 			}
165 		}
166 		else
167 		{
168 			if(wifiRssi < rssiThresh)
169 			{
170 				wifiRssiState = BTC_RSSI_STATE_LOW;
171 			}
172 			else
173 			{
174 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
175 			}
176 		}
177 	}
178 	else if(levelNum == 3)
179 	{
180 		if(rssiThresh > rssiThresh1)
181 		{
182 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));
183 			return pCoexSta->preWifiRssiState[index];
184 		}
185 
186 		if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
187 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
188 		{
189 			if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
190 			{
191 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
192 			}
193 			else
194 			{
195 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
196 			}
197 		}
198 		else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
199 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))
200 		{
201 			if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
202 			{
203 				wifiRssiState = BTC_RSSI_STATE_HIGH;
204 			}
205 			else if(wifiRssi < rssiThresh)
206 			{
207 				wifiRssiState = BTC_RSSI_STATE_LOW;
208 			}
209 			else
210 			{
211 				wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
212 			}
213 		}
214 		else
215 		{
216 			if(wifiRssi < rssiThresh1)
217 			{
218 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
219 			}
220 			else
221 			{
222 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
223 			}
224 		}
225 	}
226 
227 	pCoexSta->preWifiRssiState[index] = wifiRssiState;
228 
229 	return wifiRssiState;
230 }
231 
232 VOID
halbtc8812a2ant_SetEnablePTA(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnablePTA)233 halbtc8812a2ant_SetEnablePTA(
234 	IN	PBTC_COEXIST		pBtCoexist,
235 	IN	BOOLEAN 		bEnablePTA
236 	)
237 {
238 	if(bEnablePTA)
239 	{
240 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PTA is enable!\n"));
241 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);
242 
243 	}
244 	else
245 	{
246 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PTA is disable!\n"));
247 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x00);
248 
249 	}
250 }
251 
252 VOID
halbtc8812a2ant_EnablePTA(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnable)253 halbtc8812a2ant_EnablePTA(
254 	IN	PBTC_COEXIST		pBtCoexist,
255 	IN	BOOLEAN			bForceExec,
256 	IN	BOOLEAN			bEnable
257 	)
258 {
259 	RT_TRACE (COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Enable PTA %s\n",
260 		(bForceExec? "force to":""), (bEnable? "ON":"OFF")));
261 	pCoexDm->bCurEnablePTA = bEnable;
262 
263 	if(!bForceExec)
264 	{
265 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bPreEnablePTA = %d, bCurEnablePTA = %d!!\n",
266 			pCoexDm->bPreEnablePTA, pCoexDm->bCurEnablePTA));
267 
268 		if(pCoexDm->bPreEnablePTA == pCoexDm->bCurEnablePTA)
269 			return;
270 	}
271 	halbtc8812a2ant_SetEnablePTA(pBtCoexist, bEnable);
272 
273 
274 	pCoexDm->bPreEnablePTA = pCoexDm->bCurEnablePTA;
275 }
276 
277 VOID
halbtc8812a2ant_MonitorBtEnableDisable(IN PBTC_COEXIST pBtCoexist)278 halbtc8812a2ant_MonitorBtEnableDisable(
279 	IN 	PBTC_COEXIST		pBtCoexist
280 	)
281 {
282 	PBTC_STACK_INFO	pStackInfo=&pBtCoexist->stackInfo;
283 	static u4Byte	btDisableCnt=0;
284 	BOOLEAN			bBtActive=TRUE, bBtDisabled=FALSE;
285 
286 	// This function check if bt is disabled
287 
288 	// only 8812a need to consider if core stack is installed.
289 	if(!pStackInfo->hciVersion)
290 	{
291 		bBtActive = FALSE;
292 	}
293 /*
294 	if(	pCoexSta->highPriorityTx == 0 &&
295 		pCoexSta->highPriorityRx == 0 &&
296 		pCoexSta->lowPriorityTx == 0 &&
297 		pCoexSta->lowPriorityRx == 0)
298 	{
299 		bBtActive = FALSE;
300 	}
301 	if(	pCoexSta->highPriorityTx == 0xffff &&
302 		pCoexSta->highPriorityRx == 0xffff &&
303 		pCoexSta->lowPriorityTx == 0xffff &&
304 		pCoexSta->lowPriorityRx == 0xffff)
305 	{
306 		bBtActive = FALSE;
307 	}
308 */
309 
310 	if((pCoexSta->prebtInfoC2hCnt_BT_RSP == pCoexSta->btInfoC2hCnt[1]) &&
311 		(pCoexSta->prebtInfoC2hCnt_BT_SEND == pCoexSta->btInfoC2hCnt[2]))
312 	{
313 		bBtActive = FALSE;
314 	}
315 
316 	pCoexSta->prebtInfoC2hCnt_BT_RSP = pCoexSta->btInfoC2hCnt[1];
317 	pCoexSta->prebtInfoC2hCnt_BT_SEND = pCoexSta->btInfoC2hCnt[2];
318 
319 	if(bBtActive)
320 	{
321 		btDisableCnt = 0;
322 		bBtDisabled = FALSE;
323 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
324 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));
325 	}
326 	else
327 	{
328 		btDisableCnt++;
329 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt is detected as disabled %d times!!\n",
330 				btDisableCnt));
331 		if(btDisableCnt >= 2)
332 		{
333 			bBtDisabled = TRUE;
334 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
335 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));
336 		}
337 	}
338 	if(pCoexSta->preBtDisabled != bBtDisabled)
339 	{
340 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n",
341 			(pCoexSta->preBtDisabled ? "disabled":"enabled"),
342 			(bBtDisabled ? "disabled":"enabled")));
343 		pCoexSta->preBtDisabled = bBtDisabled;
344 
345 		if(!bBtDisabled)
346 		{
347 			// enable PTA
348 //			halbtc8812a2ant_EnablePTA(pBtCoexist,FORCE_EXEC, TRUE);
349 		}
350 		else
351 		{
352 			// disable PTA
353 //			halbtc8812a2ant_EnablePTA(pBtCoexist,FORCE_EXEC, FALSE);
354 		}
355 	}
356 }
357 
358 u4Byte
halbtc8812a2ant_DecideRaMask(IN PBTC_COEXIST pBtCoexist,IN u4Byte raMaskType)359 halbtc8812a2ant_DecideRaMask(
360 	IN	PBTC_COEXIST		pBtCoexist,
361 	IN	u4Byte				raMaskType
362 	)
363 {
364 	u4Byte	disRaMask=0x0;
365 
366 	switch(raMaskType)
367 	{
368 		case 0: // normal mode
369 			disRaMask = 0x0;
370 			break;
371 		case 1: // disable cck 1/2
372 			disRaMask = 0x00000003;
373 			break;
374 		case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4
375 			disRaMask = 0x0001f1f7;
376 			break;
377 		default:
378 			break;
379 	}
380 
381 	return disRaMask;
382 }
383 
384 VOID
halbtc8812a2ant_UpdateRaMask(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte disRateMask)385 halbtc8812a2ant_UpdateRaMask(
386 	IN	PBTC_COEXIST		pBtCoexist,
387 	IN	BOOLEAN				bForceExec,
388 	IN	u4Byte				disRateMask
389 	)
390 {
391 	pCoexDm->curRaMask = disRateMask;
392 
393 	if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
394 	{
395 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);
396 	}
397 	pCoexDm->preRaMask = pCoexDm->curRaMask;
398 }
399 
400 VOID
halbtc8812a2ant_AutoRateFallbackRetry(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)401 halbtc8812a2ant_AutoRateFallbackRetry(
402 	IN	PBTC_COEXIST		pBtCoexist,
403 	IN	BOOLEAN				bForceExec,
404 	IN	u1Byte				type
405 	)
406 {
407 	BOOLEAN	bWifiUnderBMode=FALSE;
408 
409 	pCoexDm->curArfrType = type;
410 
411 	if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))
412 	{
413 		switch(pCoexDm->curArfrType)
414 		{
415 			case 0:	// normal mode
416 				pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);
417 				pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);
418 				break;
419 			case 1:
420 				pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
421 				if(bWifiUnderBMode)
422 				{
423 					pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
424 					pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
425 				}
426 				else
427 				{
428 					pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
429 					pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
430 				}
431 				break;
432 			default:
433 				break;
434 		}
435 	}
436 
437 	pCoexDm->preArfrType = pCoexDm->curArfrType;
438 }
439 
440 VOID
halbtc8812a2ant_RetryLimit(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)441 halbtc8812a2ant_RetryLimit(
442 	IN	PBTC_COEXIST		pBtCoexist,
443 	IN	BOOLEAN				bForceExec,
444 	IN	u1Byte				type
445 	)
446 {
447 	pCoexDm->curRetryLimitType = type;
448 
449 	if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))
450 	{
451 		switch(pCoexDm->curRetryLimitType)
452 		{
453 			case 0:	// normal mode
454 				pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);
455 				break;
456 			case 1:	// retry limit=8
457 				pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
458 				break;
459 			default:
460 				break;
461 		}
462 	}
463 
464 	pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
465 }
466 
467 VOID
halbtc8812a2ant_AmpduMaxTime(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)468 halbtc8812a2ant_AmpduMaxTime(
469 	IN	PBTC_COEXIST		pBtCoexist,
470 	IN	BOOLEAN				bForceExec,
471 	IN	u1Byte				type
472 	)
473 {
474 	pCoexDm->curAmpduTimeType = type;
475 
476 	if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))
477 	{
478 		switch(pCoexDm->curAmpduTimeType)
479 		{
480 			case 0:	// normal mode
481 				pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);
482 				break;
483 			case 1:	// AMPDU timw = 0x38 * 32us
484 				pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
485 				break;
486 			default:
487 				break;
488 		}
489 	}
490 
491 	pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
492 }
493 
494 VOID
halbtc8812a2ant_LimitedTx(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte raMaskType,IN u1Byte arfrType,IN u1Byte retryLimitType,IN u1Byte ampduTimeType)495 halbtc8812a2ant_LimitedTx(
496 	IN	PBTC_COEXIST		pBtCoexist,
497 	IN	BOOLEAN				bForceExec,
498 	IN	u1Byte				raMaskType,
499 	IN	u1Byte				arfrType,
500 	IN	u1Byte				retryLimitType,
501 	IN	u1Byte				ampduTimeType
502 	)
503 {
504 	u4Byte	disRaMask=0x0;
505 
506 	pCoexDm->curRaMaskType = raMaskType;
507 	disRaMask = halbtc8812a2ant_DecideRaMask(pBtCoexist, raMaskType);
508 	halbtc8812a2ant_UpdateRaMask(pBtCoexist, bForceExec, disRaMask);
509 
510 	halbtc8812a2ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
511 	halbtc8812a2ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
512 	halbtc8812a2ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
513 }
514 
515 VOID
halbtc8812a2ant_LimitedRx(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRejApAggPkt,IN BOOLEAN bBtCtrlAggBufSize,IN u1Byte aggBufSize)516 halbtc8812a2ant_LimitedRx(
517 	IN	PBTC_COEXIST		pBtCoexist,
518 	IN	BOOLEAN				bForceExec,
519 	IN	BOOLEAN				bRejApAggPkt,
520 	IN	BOOLEAN				bBtCtrlAggBufSize,
521 	IN	u1Byte				aggBufSize
522 	)
523 {
524 	BOOLEAN	bRejectRxAgg=bRejApAggPkt;
525 	BOOLEAN	bBtCtrlRxAggSize=bBtCtrlAggBufSize;
526 	u1Byte	rxAggSize=aggBufSize;
527 
528 	//============================================
529 	//	Rx Aggregation related setting
530 	//============================================
531 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
532 	// decide BT control aggregation buf size or not
533 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
534 	// aggregation buf size, only work when BT control Rx aggregation size.
535 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
536 	// real update aggregation setting
537 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
538 
539 
540 }
541 
542 VOID
halbtc8812a2ant_MonitorBtCtr(IN PBTC_COEXIST pBtCoexist)543 halbtc8812a2ant_MonitorBtCtr(
544 	IN	PBTC_COEXIST		pBtCoexist
545 	)
546 {
547 	u4Byte 			regHPTxRx, regLPTxRx, u4Tmp;
548 	u4Byte			regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;
549 	u1Byte			u1Tmp;
550 
551 	regHPTxRx = 0x770;
552 	regLPTxRx = 0x774;
553 
554 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
555 	regHPTx = u4Tmp & bMaskLWord;
556 	regHPRx = (u4Tmp & bMaskHWord)>>16;
557 
558 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
559 	regLPTx = u4Tmp & bMaskLWord;
560 	regLPRx = (u4Tmp & bMaskHWord)>>16;
561 
562 	pCoexSta->highPriorityTx = regHPTx;
563 	pCoexSta->highPriorityRx = regHPRx;
564 	pCoexSta->lowPriorityTx = regLPTx;
565 	pCoexSta->lowPriorityRx = regLPRx;
566 
567 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
568 		regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));
569 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
570 		regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));
571 
572 	// reset counter
573 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
574 }
575 
576 VOID
halbtc8812a2ant_QueryBtInfo(IN PBTC_COEXIST pBtCoexist)577 halbtc8812a2ant_QueryBtInfo(
578 	IN	PBTC_COEXIST		pBtCoexist
579 	)
580 {
581 	u1Byte	dataLen=3;
582 	u1Byte	buf[5] = {0};
583 //8812a watch btifo to check BT enable/disable
584 //	if(!pBtCoexist->btInfo.bBtDisabled)
585 	{
586 		if(!pCoexSta->btInfoQueryCnt ||
587 			(pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8812A_2ANT_BT_RSP]-pCoexSta->btInfoQueryCnt)>2)
588 		{
589 			buf[0] = dataLen;
590 			buf[1] = 0x1;	// polling enable, 1=enable, 0=disable
591 			buf[2] = 0x2;	// polling time in seconds
592 			buf[3] = 0x1;	// auto report enable, 1=enable, 0=disable
593 
594 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_INFO, (PVOID)&buf[0]);
595 		}
596 	}
597 	pCoexSta->btInfoQueryCnt++;
598 }
599 
600 BOOLEAN
halbtc8812a2ant_IsWifiStatusChanged(IN PBTC_COEXIST pBtCoexist)601 halbtc8812a2ant_IsWifiStatusChanged(
602 	IN	PBTC_COEXIST		pBtCoexist
603 	)
604 {
605 	static BOOLEAN	bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;
606 	BOOLEAN	bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;
607 	BOOLEAN	bWifiConnected=FALSE;
608 
609 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
610 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
611 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
612 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
613 
614 	if(bWifiConnected)
615 	{
616 		if(bWifiBusy != bPreWifiBusy)
617 		{
618 			bPreWifiBusy = bWifiBusy;
619 			return TRUE;
620 		}
621 		if(bUnder4way != bPreUnder4way)
622 		{
623 			bPreUnder4way = bUnder4way;
624 			return TRUE;
625 		}
626 		if(bBtHsOn != bPreBtHsOn)
627 		{
628 			bPreBtHsOn = bBtHsOn;
629 			return TRUE;
630 		}
631 	}
632 
633 	return FALSE;
634 }
635 
636 VOID
halbtc8812a2ant_UpdateBtLinkInfo(IN PBTC_COEXIST pBtCoexist)637 halbtc8812a2ant_UpdateBtLinkInfo(
638 	IN	PBTC_COEXIST		pBtCoexist
639 	)
640 {
641 	PBTC_STACK_INFO 	pStackInfo=&pBtCoexist->stackInfo;
642 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
643 	BOOLEAN				bBtHsOn=FALSE;
644 
645 #if 1//(BT_AUTO_REPORT_ONLY_8812A_2ANT == 1)	// profile from bt patch
646 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
647 
648 	pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
649 	pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
650 	pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
651 	pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
652 	pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
653 	pBtLinkInfo->bAclBusy = pCoexSta->bAclBusy;
654 
655 	// work around for HS mode.
656 	if(bBtHsOn)
657 	{
658 		pBtLinkInfo->bPanExist = TRUE;
659 		pBtLinkInfo->bBtLinkExist = TRUE;
660 	}
661 #else	// profile from bt stack
662 	pBtLinkInfo->bBtLinkExist = pStackInfo->bBtLinkExist;
663 	pBtLinkInfo->bScoExist = pStackInfo->bScoExist;
664 	pBtLinkInfo->bA2dpExist = pStackInfo->bA2dpExist;
665 	pBtLinkInfo->bPanExist = pStackInfo->bPanExist;
666 	pBtLinkInfo->bHidExist = pStackInfo->bHidExist;
667 
668 	//for win-8 stack HID report error
669 	if(!pStackInfo->bHidExist)
670 		pStackInfo->bHidExist = pCoexSta->bHidExist;  //sync  BTInfo with BT firmware and stack
671 	// when stack HID report error, here we use the info from bt fw.
672 	if(!pStackInfo->bBtLinkExist)
673 		pStackInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
674 #endif
675 	// check if Sco only
676 	if( pBtLinkInfo->bScoExist &&
677 		!pBtLinkInfo->bA2dpExist &&
678 		!pBtLinkInfo->bPanExist &&
679 		!pBtLinkInfo->bHidExist )
680 		pBtLinkInfo->bScoOnly = TRUE;
681 	else
682 		pBtLinkInfo->bScoOnly = FALSE;
683 
684 	// check if A2dp only
685 	if( !pBtLinkInfo->bScoExist &&
686 		pBtLinkInfo->bA2dpExist &&
687 		!pBtLinkInfo->bPanExist &&
688 		!pBtLinkInfo->bHidExist )
689 		pBtLinkInfo->bA2dpOnly = TRUE;
690 	else
691 		pBtLinkInfo->bA2dpOnly = FALSE;
692 
693 	// check if Pan only
694 	if( !pBtLinkInfo->bScoExist &&
695 		!pBtLinkInfo->bA2dpExist &&
696 		pBtLinkInfo->bPanExist &&
697 		!pBtLinkInfo->bHidExist )
698 		pBtLinkInfo->bPanOnly = TRUE;
699 	else
700 		pBtLinkInfo->bPanOnly = FALSE;
701 
702 	// check if Hid only
703 	if( !pBtLinkInfo->bScoExist &&
704 		!pBtLinkInfo->bA2dpExist &&
705 		!pBtLinkInfo->bPanExist &&
706 		pBtLinkInfo->bHidExist )
707 		pBtLinkInfo->bHidOnly = TRUE;
708 	else
709 		pBtLinkInfo->bHidOnly = FALSE;
710 }
711 
712 u1Byte
halbtc8812a2ant_ActionAlgorithm(IN PBTC_COEXIST pBtCoexist)713 halbtc8812a2ant_ActionAlgorithm(
714 	IN	PBTC_COEXIST		pBtCoexist
715 	)
716 {
717 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
718 	PBTC_STACK_INFO 	pStackInfo=&pBtCoexist->stackInfo;
719 	BOOLEAN				bBtHsOn=FALSE;
720 	u1Byte				algorithm=BT_8812A_2ANT_COEX_ALGO_UNDEFINED;
721 	u1Byte				numOfDiffProfile=0;
722 
723 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
724 
725 	if(!pBtLinkInfo->bBtLinkExist)
726 	{
727 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));
728 		return algorithm;
729 	}
730 
731 	if(pBtLinkInfo->bScoExist)
732 		numOfDiffProfile++;
733 	if(pBtLinkInfo->bHidExist)
734 		numOfDiffProfile++;
735 	if(pBtLinkInfo->bPanExist)
736 		numOfDiffProfile++;
737 	if(pBtLinkInfo->bA2dpExist)
738 		numOfDiffProfile++;
739 
740 	if(numOfDiffProfile == 0)
741 	{
742 		if(pBtLinkInfo->bAclBusy)
743 		{
744 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ACL Busy only\n"));
745 			algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR;
746 		}
747 	}
748 	else if(numOfDiffProfile == 1)
749 	{
750 		if(pBtLinkInfo->bScoExist)
751 		{
752 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO only\n"));
753 			algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
754 		}
755 		else
756 		{
757 			if(pBtLinkInfo->bHidExist)
758 			{
759 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID only\n"));
760 				algorithm = BT_8812A_2ANT_COEX_ALGO_HID;
761 			}
762 			else if(pBtLinkInfo->bA2dpExist)
763 			{
764 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP only\n"));
765 				algorithm = BT_8812A_2ANT_COEX_ALGO_A2DP;
766 			}
767 			else if(pBtLinkInfo->bPanExist)
768 			{
769 				if(bBtHsOn)
770 				{
771 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(HS) only\n"));
772 					algorithm = BT_8812A_2ANT_COEX_ALGO_PANHS;
773 				}
774 				else
775 				{
776 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(EDR) only\n"));
777 					algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR;
778 				}
779 			}
780 		}
781 	}
782 	else if(numOfDiffProfile == 2)
783 	{
784 		if(pBtLinkInfo->bScoExist)
785 		{
786 			if(pBtLinkInfo->bHidExist)
787 			{
788 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID\n"));
789 				algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID;
790 			}
791 			else if(pBtLinkInfo->bA2dpExist)
792 			{
793 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP ==> SCO\n"));
794 				algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
795 			}
796 			else if(pBtLinkInfo->bPanExist)
797 			{
798 				if(bBtHsOn)
799 				{
800 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(HS)\n"));
801 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
802 				}
803 				else
804 				{
805 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(EDR)\n"));
806 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
807 				}
808 			}
809 		}
810 		else
811 		{
812 			if( pBtLinkInfo->bHidExist &&
813 				pBtLinkInfo->bA2dpExist )
814 			{
815 				if(pStackInfo->numOfHid >= 2)
816 				{
817 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID*2 + A2DP\n"));
818 					algorithm = BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
819 				}
820 				else
821 				{
822 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP\n"));
823 					algorithm = BT_8812A_2ANT_COEX_ALGO_HID_A2DP;
824 				}
825 			}
826 			else if( pBtLinkInfo->bHidExist &&
827 				pBtLinkInfo->bPanExist )
828 			{
829 				if(bBtHsOn)
830 				{
831 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(HS)\n"));
832 					algorithm =  BT_8812A_2ANT_COEX_ALGO_HID;
833 				}
834 				else
835 				{
836 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(EDR)\n"));
837 					algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
838 				}
839 			}
840 			else if( pBtLinkInfo->bPanExist &&
841 				pBtLinkInfo->bA2dpExist )
842 			{
843 				if(bBtHsOn)
844 				{
845 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(HS)\n"));
846 					algorithm = BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS;
847 				}
848 				else
849 				{
850 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(EDR)\n"));
851 					algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP;
852 				}
853 			}
854 		}
855 	}
856 	else if(numOfDiffProfile == 3)
857 	{
858 		if(pBtLinkInfo->bScoExist)
859 		{
860 			if( pBtLinkInfo->bHidExist &&
861 				pBtLinkInfo->bA2dpExist )
862 			{
863 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));
864 				algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
865 			}
866 			else if( pBtLinkInfo->bHidExist &&
867 				pBtLinkInfo->bPanExist )
868 			{
869 				if(bBtHsOn)
870 				{
871 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(HS)\n"));
872 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID;
873 				}
874 				else
875 				{
876 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
877 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID;
878 				}
879 			}
880 			else if( pBtLinkInfo->bPanExist &&
881 				pBtLinkInfo->bA2dpExist )
882 			{
883 				if(bBtHsOn)
884 				{
885 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));
886 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
887 				}
888 				else
889 				{
890 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));
891 					algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
892 				}
893 			}
894 		}
895 		else
896 		{
897 			if( pBtLinkInfo->bHidExist &&
898 				pBtLinkInfo->bPanExist &&
899 				pBtLinkInfo->bA2dpExist )
900 			{
901 				if(bBtHsOn)
902 				{
903 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
904 					algorithm = BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS;
905 				}
906 				else
907 				{
908 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
909 					algorithm = BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
910 				}
911 			}
912 		}
913 	}
914 	else if(numOfDiffProfile >= 3)
915 	{
916 		if(pBtLinkInfo->bScoExist)
917 		{
918 			if( pBtLinkInfo->bHidExist &&
919 				pBtLinkInfo->bPanExist &&
920 				pBtLinkInfo->bA2dpExist )
921 			{
922 				if(bBtHsOn)
923 				{
924 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
925 
926 				}
927 				else
928 				{
929 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));
930 					algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
931 				}
932 			}
933 		}
934 	}
935 
936 	return algorithm;
937 }
938 
939 VOID
halbtc8812a2ant_SetFwDacSwingLevel(IN PBTC_COEXIST pBtCoexist,IN u1Byte dacSwingLvl)940 halbtc8812a2ant_SetFwDacSwingLevel(
941 	IN	PBTC_COEXIST		pBtCoexist,
942 	IN	u1Byte			dacSwingLvl
943 	)
944 {
945 	u1Byte			H2C_Parameter[1] ={0};
946 
947 	// There are several type of dacswing
948 	// 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
949 	H2C_Parameter[0] = dacSwingLvl;
950 
951 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));
952 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x64=0x%x\n", H2C_Parameter[0]));
953 
954 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);
955 }
956 
957 VOID
halbtc8812a2ant_SetFwDecBtPwr(IN PBTC_COEXIST pBtCoexist,IN u1Byte decBtPwrLvl)958 halbtc8812a2ant_SetFwDecBtPwr(
959 	IN	PBTC_COEXIST		pBtCoexist,
960 	IN	u1Byte				decBtPwrLvl
961 	)
962 {
963 	u1Byte	dataLen=4;
964 	u1Byte	buf[6] = {0};
965 
966 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], decrease Bt Power level = %d\n",
967 		decBtPwrLvl));
968 
969 	buf[0] = dataLen;
970 	buf[1] = 0x3;		// OP_Code
971 	buf[2] = 0x2;		// OP_Code_Length
972 	if(decBtPwrLvl)
973 		buf[3] = 0x1;	// OP_Code_Content
974 	else
975 		buf[3] = 0x0;
976 	buf[4] = decBtPwrLvl;// pwrLevel
977 
978 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);
979 }
980 
981 VOID
halbtc8812a2ant_DecBtPwr(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte decBtPwrLvl)982 halbtc8812a2ant_DecBtPwr(
983 	IN	PBTC_COEXIST		pBtCoexist,
984 	IN	BOOLEAN			bForceExec,
985 	IN	u1Byte			decBtPwrLvl
986 	)
987 {
988 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s Dec BT power level = %d\n",
989 		(bForceExec? "force to":""), decBtPwrLvl));
990 	pCoexDm->curBtDecPwrLvl = decBtPwrLvl;
991 
992 	if(!bForceExec)
993 	{
994 		if(pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl)
995 			return;
996 	}
997 	halbtc8812a2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);
998 
999 	pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;
1000 }
1001 
1002 VOID
halbtc8812a2ant_FwDacSwingLvl(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte fwDacSwingLvl)1003 halbtc8812a2ant_FwDacSwingLvl(
1004 	IN	PBTC_COEXIST		pBtCoexist,
1005 	IN	BOOLEAN			bForceExec,
1006 	IN	u1Byte			fwDacSwingLvl
1007 	)
1008 {
1009 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set FW Dac Swing level = %d\n",
1010 		(bForceExec? "force to":""), fwDacSwingLvl));
1011 	pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;
1012 
1013 	if(!bForceExec)
1014 	{
1015 		if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl)
1016 			return;
1017 	}
1018 
1019 	halbtc8812a2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);
1020 
1021 	pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;
1022 }
1023 
1024 VOID
halbtc8812a2ant_SetSwRfRxLpfCorner(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bRxRfShrinkOn)1025 halbtc8812a2ant_SetSwRfRxLpfCorner(
1026 	IN	PBTC_COEXIST		pBtCoexist,
1027 	IN	BOOLEAN			bRxRfShrinkOn
1028 	)
1029 {
1030 	if(bRxRfShrinkOn)
1031 	{
1032 		//Shrink RF Rx LPF corner
1033 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));
1034 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);
1035 	}
1036 	else
1037 	{
1038 		//Resume RF Rx LPF corner
1039 		// After initialized, we can use pCoexDm->btRf0x1eBackup
1040 		if(pBtCoexist->bInitilized)
1041 		{
1042 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
1043 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);
1044 		}
1045 	}
1046 }
1047 
1048 VOID
halbtc8812a2ant_RfShrink(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRxRfShrinkOn)1049 halbtc8812a2ant_RfShrink(
1050 	IN	PBTC_COEXIST		pBtCoexist,
1051 	IN	BOOLEAN			bForceExec,
1052 	IN	BOOLEAN			bRxRfShrinkOn
1053 	)
1054 {
1055 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",
1056 		(bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));
1057 	pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
1058 
1059 	if(!bForceExec)
1060 	{
1061 		if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
1062 			return;
1063 	}
1064 	halbtc8812a2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
1065 
1066 	pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
1067 }
1068 
1069 VOID
halbtc8812a2ant_SetSwPenaltyTxRateAdaptive(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bLowPenaltyRa)1070 halbtc8812a2ant_SetSwPenaltyTxRateAdaptive(
1071 	IN	PBTC_COEXIST		pBtCoexist,
1072 	IN	BOOLEAN			bLowPenaltyRa
1073 	)
1074 {
1075 	u1Byte	tmpU1;
1076 
1077 	tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);
1078 	tmpU1 |= BIT0;
1079 	if(bLowPenaltyRa)
1080 	{
1081 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));
1082 		tmpU1 &= ~BIT2;
1083 	}
1084 	else
1085 	{
1086 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set normal!!\n"));
1087 		tmpU1 |= BIT2;
1088 	}
1089 
1090 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);
1091 }
1092 
1093 VOID
halbtc8812a2ant_LowPenaltyRa(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bLowPenaltyRa)1094 halbtc8812a2ant_LowPenaltyRa(
1095 	IN	PBTC_COEXIST		pBtCoexist,
1096 	IN	BOOLEAN			bForceExec,
1097 	IN	BOOLEAN			bLowPenaltyRa
1098 	)
1099 {
1100 	return;
1101 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",
1102 		(bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));
1103 	pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
1104 
1105 	if(!bForceExec)
1106 	{
1107 		if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
1108 			return;
1109 	}
1110 	halbtc8812a2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
1111 
1112 	pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
1113 }
1114 
1115 VOID
halbtc8812a2ant_SetDacSwingReg(IN PBTC_COEXIST pBtCoexist,IN u4Byte level)1116 halbtc8812a2ant_SetDacSwingReg(
1117 	IN	PBTC_COEXIST		pBtCoexist,
1118 	IN	u4Byte			level
1119 	)
1120 {
1121 	u1Byte	val=(u1Byte)level;
1122 
1123 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Write SwDacSwing = 0x%x\n", level));
1124 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc5b, 0x3e, val);
1125 }
1126 
1127 VOID
halbtc8812a2ant_SetSwFullTimeDacSwing(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bSwDacSwingOn,IN u4Byte swDacSwingLvl)1128 halbtc8812a2ant_SetSwFullTimeDacSwing(
1129 	IN	PBTC_COEXIST		pBtCoexist,
1130 	IN	BOOLEAN			bSwDacSwingOn,
1131 	IN	u4Byte			swDacSwingLvl
1132 	)
1133 {
1134 	if(bSwDacSwingOn)
1135 	{
1136 		halbtc8812a2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);
1137 	}
1138 	else
1139 	{
1140 		halbtc8812a2ant_SetDacSwingReg(pBtCoexist, 0x18);
1141 	}
1142 }
1143 
1144 
1145 VOID
halbtc8812a2ant_DacSwing(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bDacSwingOn,IN u4Byte dacSwingLvl)1146 halbtc8812a2ant_DacSwing(
1147 	IN	PBTC_COEXIST		pBtCoexist,
1148 	IN	BOOLEAN			bForceExec,
1149 	IN	BOOLEAN			bDacSwingOn,
1150 	IN	u4Byte			dacSwingLvl
1151 	)
1152 {
1153 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",
1154 		(bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));
1155 	pCoexDm->bCurDacSwingOn = bDacSwingOn;
1156 	pCoexDm->curDacSwingLvl = dacSwingLvl;
1157 
1158 	if(!bForceExec)
1159 	{
1160 		if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&
1161 			(pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )
1162 			return;
1163 	}
1164 	delay_ms(30);
1165 	halbtc8812a2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);
1166 
1167 	pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;
1168 	pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;
1169 }
1170 
1171 VOID
halbtc8812a2ant_SetAdcBackOff(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAdcBackOff)1172 halbtc8812a2ant_SetAdcBackOff(
1173 	IN	PBTC_COEXIST		pBtCoexist,
1174 	IN	BOOLEAN			bAdcBackOff
1175 	)
1176 {
1177 	if(bAdcBackOff)
1178 	{
1179 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level On!\n"));
1180 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x8db, 0x60, 0x3);
1181 	}
1182 	else
1183 	{
1184 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level Off!\n"));
1185 		pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x8db, 0x60, 0x1);
1186 	}
1187 }
1188 
1189 VOID
halbtc8812a2ant_AdcBackOff(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bAdcBackOff)1190 halbtc8812a2ant_AdcBackOff(
1191 	IN	PBTC_COEXIST		pBtCoexist,
1192 	IN	BOOLEAN			bForceExec,
1193 	IN	BOOLEAN			bAdcBackOff
1194 	)
1195 {
1196 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn AdcBackOff = %s\n",
1197 		(bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));
1198 	pCoexDm->bCurAdcBackOff = bAdcBackOff;
1199 
1200 	if(!bForceExec)
1201 	{
1202 		if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff)
1203 			return;
1204 	}
1205 	halbtc8812a2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);
1206 
1207 	pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;
1208 }
1209 
1210 VOID
halbtc8812a2ant_SetAgcTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAgcTableEn)1211 halbtc8812a2ant_SetAgcTable(
1212 	IN	PBTC_COEXIST		pBtCoexist,
1213 	IN	BOOLEAN			bAgcTableEn
1214 	)
1215 {
1216 	u1Byte		rssiAdjustVal=0;
1217 
1218 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
1219 	if(bAgcTableEn)
1220 	{
1221 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));
1222 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff,  0x28F4B);
1223 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff,  0x10AB2);
1224 		rssiAdjustVal = 8;
1225 	}
1226 	else
1227 	{
1228 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));
1229 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x2884B);
1230 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x104B2);
1231 	}
1232 	pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
1233 
1234 	// set rssiAdjustVal for wifi module.
1235 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);
1236 }
1237 
1238 VOID
halbtc8812a2ant_AgcTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bAgcTableEn)1239 halbtc8812a2ant_AgcTable(
1240 	IN	PBTC_COEXIST		pBtCoexist,
1241 	IN	BOOLEAN			bForceExec,
1242 	IN	BOOLEAN			bAgcTableEn
1243 	)
1244 {
1245 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s %s Agc Table\n",
1246 		(bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));
1247 	pCoexDm->bCurAgcTableEn = bAgcTableEn;
1248 
1249 	if(!bForceExec)
1250 	{
1251 		if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn)
1252 			return;
1253 	}
1254 	halbtc8812a2ant_SetAgcTable(pBtCoexist, bAgcTableEn);
1255 
1256 	pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;
1257 }
1258 
1259 VOID
halbtc8812a2ant_SetCoexTable(IN PBTC_COEXIST pBtCoexist,IN u4Byte val0x6c0,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u1Byte val0x6cc)1260 halbtc8812a2ant_SetCoexTable(
1261 	IN	PBTC_COEXIST	pBtCoexist,
1262 	IN	u4Byte		val0x6c0,
1263 	IN	u4Byte		val0x6c4,
1264 	IN	u4Byte		val0x6c8,
1265 	IN	u1Byte		val0x6cc
1266 	)
1267 {
1268 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
1269 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
1270 
1271 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
1272 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
1273 
1274 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
1275 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
1276 
1277 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
1278 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
1279 }
1280 
1281 VOID
halbtc8812a2ant_CoexTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte val0x6c0,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u1Byte val0x6cc)1282 halbtc8812a2ant_CoexTable(
1283 	IN	PBTC_COEXIST		pBtCoexist,
1284 	IN	BOOLEAN			bForceExec,
1285 	IN	u4Byte			val0x6c0,
1286 	IN	u4Byte			val0x6c4,
1287 	IN	u4Byte			val0x6c8,
1288 	IN	u1Byte			val0x6cc
1289 	)
1290 {
1291 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
1292 		(bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));
1293 	pCoexDm->curVal0x6c0 = val0x6c0;
1294 	pCoexDm->curVal0x6c4 = val0x6c4;
1295 	pCoexDm->curVal0x6c8 = val0x6c8;
1296 	pCoexDm->curVal0x6cc = val0x6cc;
1297 
1298 	if(!bForceExec)
1299 	{
1300 		if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1301 			(pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1302 			(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1303 			(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
1304 			return;
1305 	}
1306 	halbtc8812a2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1307 
1308 	pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1309 	pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1310 	pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1311 	pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1312 }
1313 
1314 VOID
halbtc8812a2ant_CoexTableWithType(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)1315 halbtc8812a2ant_CoexTableWithType(
1316 	IN	PBTC_COEXIST		pBtCoexist,
1317 	IN	BOOLEAN				bForceExec,
1318 	IN	u1Byte				type
1319 	)
1320 {
1321 	switch(type)
1322 	{
1323 		case 0:
1324 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
1325 			break;
1326 		case 1:
1327 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
1328 			break;
1329 		case 2:
1330 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5ffb5ffb, 0xffffff, 0x3);
1331 			break;
1332 		case 3:
1333 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
1334 			break;
1335 		case 4:
1336 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0xdfffdfff, 0x5fdb5fdb, 0xffffff, 0x3);
1337 			break;
1338 		case 5:
1339 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x5ddd5ddd, 0x5fdb5fdb, 0xffffff, 0x3);
1340 			break;
1341 		case 6:
1342 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5a5a5a5a, 0xffffff, 0x3);
1343 			break;
1344 		case 7:
1345 			if(pCoexSta->nScanAPNum <= 5)
1346 				halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xfafafafa, 0xffffff, 0x3);
1347 			else
1348 				halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0x5a5a5a5a, 0xffffff, 0x3);
1349 			break;
1350 		case 8:
1351 			halbtc8812a2ant_CoexTable(pBtCoexist, bForceExec, 0x5f5f5f5f, 0x5a5a5a5a, 0xffffff, 0x3);
1352 			break;
1353 
1354 		default:
1355 			break;
1356 	}
1357 }
1358 
1359 VOID
halbtc8812a2ant_SetFwIgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnable)1360 halbtc8812a2ant_SetFwIgnoreWlanAct(
1361 	IN	PBTC_COEXIST		pBtCoexist,
1362 	IN	BOOLEAN			bEnable
1363 	)
1364 {
1365 	u1Byte	dataLen=3;
1366 	u1Byte	buf[5] = {0};
1367 
1368 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Ignore Wlan_Act\n",
1369 		(bEnable? "Enable":"Disable")));
1370 
1371 	buf[0] = dataLen;
1372 	buf[1] = 0x1;			// OP_Code
1373 	buf[2] = 0x1;			// OP_Code_Length
1374 	if(bEnable)
1375 		buf[3] = 0x1; 		// OP_Code_Content
1376 	else
1377 		buf[3] = 0x0;
1378 
1379 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);
1380 }
1381 
1382 VOID
halbtc8812a2ant_IgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnable)1383 halbtc8812a2ant_IgnoreWlanAct(
1384 	IN	PBTC_COEXIST		pBtCoexist,
1385 	IN	BOOLEAN			bForceExec,
1386 	IN	BOOLEAN			bEnable
1387 	)
1388 {
1389 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n",
1390 		(bForceExec? "force to":""), (bEnable? "ON":"OFF")));
1391 	pCoexDm->bCurIgnoreWlanAct = bEnable;
1392 
1393 	if(!bForceExec)
1394 	{
1395 		if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1396 			return;
1397 	}
1398 	halbtc8812a2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1399 
1400 	pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1401 }
1402 
1403 VOID
halbtc8812a2ant_SetFwPstdma(IN PBTC_COEXIST pBtCoexist,IN u1Byte byte1,IN u1Byte byte2,IN u1Byte byte3,IN u1Byte byte4,IN u1Byte byte5)1404 halbtc8812a2ant_SetFwPstdma(
1405 	IN	PBTC_COEXIST		pBtCoexist,
1406 	IN	u1Byte			byte1,
1407 	IN	u1Byte			byte2,
1408 	IN	u1Byte			byte3,
1409 	IN	u1Byte			byte4,
1410 	IN	u1Byte			byte5
1411 	)
1412 {
1413 	u1Byte			H2C_Parameter[5] ={0};
1414 	u1Byte			realByte1=byte1, realByte5=byte5;
1415 	BOOLEAN			bApEnable=FALSE;
1416 
1417 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1418 
1419 	if(bApEnable)
1420 	{
1421 		if(byte1&BIT4 && !(byte1&BIT5))
1422 		{
1423 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));
1424 			realByte1 &= ~BIT4;
1425 			realByte1 |= BIT5;
1426 
1427 			realByte5 |= BIT5;
1428 			realByte5 &= ~BIT6;
1429 		}
1430 	}
1431 
1432 	H2C_Parameter[0] = realByte1;
1433 	H2C_Parameter[1] = byte2;
1434 	H2C_Parameter[2] = byte3;
1435 	H2C_Parameter[3] = byte4;
1436 	H2C_Parameter[4] = realByte5;
1437 
1438 
1439 	pCoexDm->psTdmaPara[0] = realByte1;
1440 	pCoexDm->psTdmaPara[1] = byte2;
1441 	pCoexDm->psTdmaPara[2] = byte3;
1442 	pCoexDm->psTdmaPara[3] = byte4;
1443 	pCoexDm->psTdmaPara[4] = realByte5;
1444 
1445 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
1446 		H2C_Parameter[0],
1447 		H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
1448 
1449 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1450 }
1451 
1452 VOID
halbtc8812a2ant_SetLpsRpwm(IN PBTC_COEXIST pBtCoexist,IN u1Byte lpsVal,IN u1Byte rpwmVal)1453 halbtc8812a2ant_SetLpsRpwm(
1454 	IN	PBTC_COEXIST		pBtCoexist,
1455 	IN	u1Byte			lpsVal,
1456 	IN	u1Byte			rpwmVal
1457 	)
1458 {
1459 	u1Byte	lps=lpsVal;
1460 	u1Byte	rpwm=rpwmVal;
1461 
1462 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
1463 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1464 }
1465 
1466 VOID
halbtc8812a2ant_LpsRpwm(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte lpsVal,IN u1Byte rpwmVal)1467 halbtc8812a2ant_LpsRpwm(
1468 	IN	PBTC_COEXIST		pBtCoexist,
1469 	IN	BOOLEAN			bForceExec,
1470 	IN	u1Byte			lpsVal,
1471 	IN	u1Byte			rpwmVal
1472 	)
1473 {
1474 	BOOLEAN	bForceExecPwrCmd=FALSE;
1475 
1476 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n",
1477 		(bForceExec? "force to":""), lpsVal, rpwmVal));
1478 	pCoexDm->curLps = lpsVal;
1479 	pCoexDm->curRpwm = rpwmVal;
1480 
1481 	if(!bForceExec)
1482 	{
1483 		if( (pCoexDm->preLps == pCoexDm->curLps) &&
1484 			(pCoexDm->preRpwm == pCoexDm->curRpwm) )
1485 		{
1486 			return;
1487 		}
1488 	}
1489 	halbtc8812a2ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
1490 
1491 	pCoexDm->preLps = pCoexDm->curLps;
1492 	pCoexDm->preRpwm = pCoexDm->curRpwm;
1493 }
1494 
1495 VOID
halbtc8812a2ant_SwMechanism1(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bShrinkRxLPF,IN BOOLEAN bLowPenaltyRA,IN BOOLEAN bLimitedDIG,IN BOOLEAN bBTLNAConstrain)1496 halbtc8812a2ant_SwMechanism1(
1497 	IN	PBTC_COEXIST	pBtCoexist,
1498 	IN	BOOLEAN		bShrinkRxLPF,
1499 	IN	BOOLEAN 	bLowPenaltyRA,
1500 	IN	BOOLEAN		bLimitedDIG,
1501 	IN	BOOLEAN		bBTLNAConstrain
1502 	)
1503 {
1504 	/*
1505 	u4Byte	wifiBw;
1506 
1507 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1508 
1509 	if(BTC_WIFI_BW_HT40 != wifiBw)  //only shrink RF Rx LPF for HT40
1510 	{
1511 		if (bShrinkRxLPF)
1512 			bShrinkRxLPF = FALSE;
1513 	}
1514 	*/
1515 
1516 	 halbtc8812a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);
1517 	//halbtc8812a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1518 }
1519 
1520 VOID
halbtc8812a2ant_SwMechanism2(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAGCTableShift,IN BOOLEAN bADCBackOff,IN BOOLEAN bSWDACSwing,IN u4Byte dacSwingLvl)1521 halbtc8812a2ant_SwMechanism2(
1522 	IN	PBTC_COEXIST	pBtCoexist,
1523 	IN	BOOLEAN		bAGCTableShift,
1524 	IN	BOOLEAN 	bADCBackOff,
1525 	IN	BOOLEAN		bSWDACSwing,
1526 	IN	u4Byte		dacSwingLvl
1527 	)
1528 {
1529 	//halbtc8812a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);
1530 	halbtc8812a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, bADCBackOff);
1531 	halbtc8812a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);
1532 }
1533 
1534 VOID
halbtc8812a2ant_SetAntPath(IN PBTC_COEXIST pBtCoexist,IN u1Byte antPosType,IN BOOLEAN bInitHwCfg,IN BOOLEAN bWifiOff)1535 halbtc8812a2ant_SetAntPath(
1536 	IN	PBTC_COEXIST		pBtCoexist,
1537 	IN	u1Byte				antPosType,
1538 	IN	BOOLEAN				bInitHwCfg,
1539 	IN	BOOLEAN				bWifiOff
1540 	)
1541 {
1542 	u1Byte			u1Tmp=0;
1543 
1544 	if(bInitHwCfg)
1545 	{
1546 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x900, 0x00000400);
1547 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76d, 0x1);
1548 	}
1549 	else if(bWifiOff)
1550 	{
1551 
1552 	}
1553 
1554 	// ext switch setting
1555 	switch(antPosType)
1556 	{
1557 		case BTC_ANT_WIFI_AT_CPL_MAIN:
1558 			break;
1559 		case BTC_ANT_WIFI_AT_CPL_AUX:
1560 			u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb7);
1561 			u1Tmp &= ~BIT3;
1562 			u1Tmp |= BIT2;
1563 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb7, u1Tmp);
1564 			break;
1565 		default:
1566 			break;
1567 	}
1568 }
1569 
1570 VOID
halbtc8812a2ant_PsTdma(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bTurnOn,IN u1Byte type)1571 halbtc8812a2ant_PsTdma(
1572 	IN	PBTC_COEXIST		pBtCoexist,
1573 	IN	BOOLEAN			bForceExec,
1574 	IN	BOOLEAN			bTurnOn,
1575 	IN	u1Byte			type
1576 	)
1577 {
1578 	BOOLEAN			bTurnOnByCnt=FALSE;
1579 	u1Byte			psTdmaTypeByCnt=0;
1580 	s1Byte			nWiFiDurationAdjust = 0x0;
1581 
1582 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn %s PS TDMA, type=%d\n",
1583 		(bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));
1584 	pCoexDm->bCurPsTdmaOn = bTurnOn;
1585 	pCoexDm->curPsTdma = type;
1586 
1587 	if(!bForceExec)
1588 	{
1589 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1590 			pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));
1591 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1592 			pCoexDm->prePsTdma, pCoexDm->curPsTdma));
1593 
1594 		if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1595 			(pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
1596 			return;
1597 	}
1598 
1599 	if  (pCoexSta->nScanAPNum >= 40)
1600 	 	nWiFiDurationAdjust = -15;
1601 	else if  (pCoexSta->nScanAPNum >= 20)
1602 	 	nWiFiDurationAdjust = -10;
1603 
1604 /*
1605 	if (!pCoexSta->bForceLpsOn)  //only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30
1606 	{
1607 		psTdmaByte0Val = 0x61;  //no null-pkt
1608 		psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1609 		psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle
1610 	}
1611 
1612 
1613 	if (  (type == 3) || (type == 13) || (type == 14) )
1614 	{
1615 		psTdmaByte4Val = psTdmaByte4Val & 0xbf;  //no dynamic slot for multi-profile
1616 
1617 		if (!bWifiBusy)
1618 		 psTdmaByte4Val = psTdmaByte4Val | 0x1;  //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
1619 	}
1620 
1621 	if (pBtLinkInfo->bSlaveRole == TRUE)
1622 		psTdmaByte4Val = psTdmaByte4Val | 0x1;  //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
1623 
1624 */
1625 	if(bTurnOn)
1626 	{
1627 		switch(type)
1628 		{
1629 			case 1:
1630 			default:	//d1,wb
1631 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0x11, 0x10);
1632 				break;
1633 			case 2:
1634 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x32, 0x03, 0x11, 0x10);
1635 				break;
1636 			case 3:
1637 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x28, 0x03, 0x11, 0x10);
1638 				break;
1639 			case 4:
1640 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1e, 0x03, 0x11, 0x10);
1641 				break;
1642 			case 5:		//d1,pb,TXpause
1643 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x63, 0x3c, 0x03, 0x90, 0x10);
1644 				break;
1645 			case 6:
1646 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x63, 0x32, 0x03, 0x90, 0x10);
1647 				break;
1648 			case 7:
1649 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x63, 0x28, 0x03, 0x90, 0x10);
1650 				break;
1651 			case 8:
1652 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x63, 0x1e, 0x03, 0x90, 0x10);
1653 				break;
1654 			case 9:		//d1,bb
1655 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0x31, 0x10);
1656 				break;
1657 			case 10:
1658 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x32, 0x03, 0x31, 0x10);
1659 				break;
1660 			case 11:
1661 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x28, 0x03, 0x31, 0x10);
1662 				break;
1663 			case 12:
1664 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1e, 0x03, 0x31, 0x10);
1665 				break;
1666 			case 13:	//d1,bb,TXpause
1667 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0x30, 0x10);
1668 				break;
1669 			case 14:
1670 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x32, 0x03, 0x30, 0x10);
1671 				break;
1672 			case 15:
1673 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x28, 0x03, 0x30, 0x10);
1674 				break;
1675 			case 16:
1676 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1e, 0x03, 0x30, 0x10);
1677 				break;
1678 			case 17:
1679 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11);
1680 				break;
1681 			case 18:
1682 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1683 				break;
1684 			case 19:
1685 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);
1686 				break;
1687 			case 20:
1688 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);
1689 				break;
1690 			case 21:
1691 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x70, 0x90);
1692 				break;
1693 			case 22:
1694 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x61, 0x1a, 0x1a, 0x21, 0x10);
1695 				break;
1696 			case 23:
1697 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x03, 0x31, 0x10);
1698 				break;
1699 
1700 			case 71:
1701 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1702 				break;
1703 
1704 			// following cases is for wifi rssi low, started from 81
1705 			case 80:
1706 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x3c, 0x3, 0x90, 0x50);
1707 				break;
1708 			case 81:
1709 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x3a+nWiFiDurationAdjust, 0x3, 0x90, 0x50);
1710 				break;
1711 			case 82:
1712 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x30+nWiFiDurationAdjust, 0x03, 0x90, 0x50);
1713 				break;
1714 			case 83:
1715 	   			halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x21, 0x03, 0x90, 0x50);
1716 				break;
1717 			case 84:
1718 	   			halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x15, 0x3, 0x90, 0x50);
1719 				break;
1720 			case 85:
1721 	   			halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x1d, 0x1d, 0x80, 0x50);
1722 				break;
1723 			case 86:
1724 	   			halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x53, 0x15, 0x15, 0x80, 0x50);
1725 				break;
1726 		}
1727 	}
1728 	else
1729 	{
1730 		// disable PS tdma
1731 		switch(type)
1732 		{
1733 			case 0: //ANT2PTA, 0x778=0x1
1734 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
1735 				break;
1736 			case 1: //ANT2BT, 0x778=3
1737 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);
1738 				delay_ms(5);
1739 				halbtc8812a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_CPL_AUX, FALSE, FALSE);
1740 				break;
1741 			default:
1742 				halbtc8812a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1743 				break;
1744 		}
1745 	}
1746 
1747 	// update pre state
1748 	pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1749 	pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1750 }
1751 
1752 VOID
halbtc8812a2ant_CoexAllOff(IN PBTC_COEXIST pBtCoexist)1753 halbtc8812a2ant_CoexAllOff(
1754 	IN	PBTC_COEXIST		pBtCoexist
1755 	)
1756 {
1757 	// fw all off
1758 	halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1759 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1760 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1761 
1762 	// sw all off
1763 	halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1764 	halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1765 
1766 	// hw all off
1767 	halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1768 }
1769 
1770 VOID
halbtc8812a2ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)1771 halbtc8812a2ant_InitCoexDm(
1772 	IN	PBTC_COEXIST		pBtCoexist
1773 	)
1774 {
1775 	// force to reset coex mechanism
1776 
1777 	halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
1778 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1779 	halbtc8812a2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);
1780 
1781 	halbtc8812a2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
1782 
1783 	halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1784 	halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1785 }
1786 
1787 VOID
halbtc8812a2ant_PsTdmaCheckForPowerSaveState(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bNewPsState)1788 halbtc8812a2ant_PsTdmaCheckForPowerSaveState(
1789 	IN	PBTC_COEXIST		pBtCoexist,
1790 	IN	BOOLEAN			bNewPsState
1791 	)
1792 {
1793 	u1Byte	lpsMode=0x0;
1794 
1795 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
1796 
1797 	if(lpsMode)	// already under LPS state
1798 	{
1799 		if(bNewPsState)
1800 		{
1801 			// keep state under LPS, do nothing.
1802 		}
1803 		else
1804 		{
1805 			// will leave LPS state, turn off psTdma first
1806 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1807 		}
1808 	}
1809 	else						// NO PS state
1810 	{
1811 		if(bNewPsState)
1812 		{
1813 			// will enter LPS state, turn off psTdma first
1814 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1815 		}
1816 		else
1817 		{
1818 			// keep state under NO PS state, do nothing.
1819 		}
1820 	}
1821 }
1822 
1823 VOID
halbtc8812a2ant_PowerSaveState(IN PBTC_COEXIST pBtCoexist,IN u1Byte psType,IN u1Byte lpsVal,IN u1Byte rpwmVal)1824 halbtc8812a2ant_PowerSaveState(
1825 	IN	PBTC_COEXIST		pBtCoexist,
1826 	IN	u1Byte				psType,
1827 	IN	u1Byte				lpsVal,
1828 	IN	u1Byte				rpwmVal
1829 	)
1830 {
1831 	BOOLEAN		bLowPwrDisable=FALSE;
1832 
1833 	switch(psType)
1834 	{
1835 		case BTC_PS_WIFI_NATIVE:
1836 			// recover to original 32k low power setting
1837 			bLowPwrDisable = TRUE;
1838 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1839 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1840 			pCoexSta->bForceLpsOn = FALSE;
1841 			break;
1842 		case BTC_PS_LPS_ON:
1843 			halbtc8812a2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);
1844 			halbtc8812a2ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
1845 			// when coex force to enter LPS, do not enter 32k low power.
1846 			bLowPwrDisable = TRUE;
1847 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1848 			// power save must executed before psTdma.
1849 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1850 			pCoexSta->bForceLpsOn = TRUE;
1851 			break;
1852 		case BTC_PS_LPS_OFF:
1853 			halbtc8812a2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);
1854 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1855 			pCoexSta->bForceLpsOn = FALSE;
1856 			break;
1857 		default:
1858 			break;
1859 	}
1860 }
1861 
1862 VOID
halbtc8812a2ant_ActionBtInquiry(IN PBTC_COEXIST pBtCoexist)1863 halbtc8812a2ant_ActionBtInquiry(
1864 	IN	PBTC_COEXIST		pBtCoexist
1865 	)
1866 {
1867 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1868 
1869 	halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1870 	halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
1871 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1872 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1873 
1874 	halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1875 	halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1876 }
1877 
1878 BOOLEAN
halbtc8812a2ant_IsCommonAction(IN PBTC_COEXIST pBtCoexist)1879 halbtc8812a2ant_IsCommonAction(
1880 	IN	PBTC_COEXIST		pBtCoexist
1881 	)
1882 {
1883 	u1Byte				wifiRssiState=BTC_RSSI_STATE_HIGH;
1884 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
1885 	BOOLEAN				bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;
1886 	BOOLEAN				bBtHsOn=FALSE;
1887 
1888 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1889 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1890 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1891 
1892 
1893 	if(pCoexSta->bC2hBtInquiryPage)
1894 	{
1895 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under inquiry/page scan !!\n"));
1896 		halbtc8812a2ant_ActionBtInquiry(pBtCoexist);
1897 		return TRUE;
1898 	}
1899 
1900 	if(pBtLinkInfo->bScoExist || pBtLinkInfo->bHidExist)
1901 	{
1902 		halbtc8812a2ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 0, 0, 0);
1903 	}
1904 	else
1905 	{
1906 		halbtc8812a2ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
1907 	}
1908 
1909 	if(!bWifiConnected)
1910 	{
1911 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1912 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1913 
1914 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-connected idle!!\n"));
1915 
1916 		if( (BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) ||
1917 			(BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
1918 		{
1919 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);
1920 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1921 		}
1922 		else
1923 		{
1924 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1925 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
1926 		}
1927 
1928 		halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1929 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1930 
1931  		halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1932 		halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1933 
1934 		bCommon = TRUE;
1935 	}
1936 	else
1937 	{
1938 		if(BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
1939 		{
1940 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
1941 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1942 			halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1943 
1944 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1945 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1946 			halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1947 			halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1948 
1949 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1950 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1951 
1952 			bCommon = TRUE;
1953 		}
1954 		else if(BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)
1955 		{
1956 			if(bBtHsOn)
1957 				return FALSE;
1958 
1959 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
1960 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1961 			halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1962 
1963 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1964 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1965 			halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1966 			halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1967 
1968 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
1969 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1970 
1971 			bCommon = TRUE;
1972 		}
1973 		else
1974 		{
1975 			if(bWifiBusy)
1976 			{
1977 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
1978 				bCommon = FALSE;
1979 			}
1980 			else
1981 			{
1982 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
1983 
1984 				halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1985 
1986 				halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
1987 
1988 				halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1989 
1990 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 17);
1991 
1992 				halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1993 				halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1994 				halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
1995 				halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
1996 				bCommon = TRUE;
1997 			}
1998 		}
1999 	}
2000 
2001 	return bCommon;
2002 }
2003 
2004 VOID
halbtc8812a2ant_TdmaDurationAdjust(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bScoHid,IN BOOLEAN bTxPause,IN u1Byte maxInterval)2005 halbtc8812a2ant_TdmaDurationAdjust(
2006 	IN	PBTC_COEXIST		pBtCoexist,
2007 	IN	BOOLEAN			bScoHid,
2008 	IN	BOOLEAN			bTxPause,
2009 	IN	u1Byte			maxInterval
2010 	)
2011 {
2012 	static s4Byte		up,dn,m,n,WaitCount;
2013 	s4Byte			result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
2014 	u1Byte			retryCount=0;
2015 
2016 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
2017 
2018 	pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
2019 
2020 	if(!pCoexDm->bAutoTdmaAdjust)
2021 	{
2022 		pCoexDm->bAutoTdmaAdjust = TRUE;
2023 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
2024 		{
2025 			if(bScoHid)
2026 			{
2027 				if(bTxPause)
2028 				{
2029 					if(maxInterval == 1)
2030 					{
2031 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2032 						pCoexDm->psTdmaDuAdjType = 13;
2033 					}
2034 					else if(maxInterval == 2)
2035 					{
2036 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2037 						pCoexDm->psTdmaDuAdjType = 14;
2038 					}
2039 					else if(maxInterval == 3)
2040 					{
2041 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2042 						pCoexDm->psTdmaDuAdjType = 15;
2043 					}
2044 					else
2045 					{
2046 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2047 						pCoexDm->psTdmaDuAdjType = 15;
2048 					}
2049 				}
2050 				else
2051 				{
2052 					if(maxInterval == 1)
2053 					{
2054 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2055 						pCoexDm->psTdmaDuAdjType = 9;
2056 					}
2057 					else if(maxInterval == 2)
2058 					{
2059 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2060 						pCoexDm->psTdmaDuAdjType = 10;
2061 					}
2062 					else if(maxInterval == 3)
2063 					{
2064 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2065 						pCoexDm->psTdmaDuAdjType = 11;
2066 					}
2067 					else
2068 					{
2069 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2070 						pCoexDm->psTdmaDuAdjType = 11;
2071 					}
2072 				}
2073 			}
2074 			else
2075 			{
2076 				if(bTxPause)
2077 				{
2078 					if(maxInterval == 1)
2079 					{
2080 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2081 						pCoexDm->psTdmaDuAdjType = 5;
2082 					}
2083 					else if(maxInterval == 2)
2084 					{
2085 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2086 						pCoexDm->psTdmaDuAdjType = 6;
2087 					}
2088 					else if(maxInterval == 3)
2089 					{
2090 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2091 						pCoexDm->psTdmaDuAdjType = 7;
2092 					}
2093 					else
2094 					{
2095 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2096 						pCoexDm->psTdmaDuAdjType = 7;
2097 					}
2098 				}
2099 				else
2100 				{
2101 					if(maxInterval == 1)
2102 					{
2103 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2104 						pCoexDm->psTdmaDuAdjType = 1;
2105 					}
2106 					else if(maxInterval == 2)
2107 					{
2108 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2109 						pCoexDm->psTdmaDuAdjType = 2;
2110 					}
2111 					else if(maxInterval == 3)
2112 					{
2113 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2114 						pCoexDm->psTdmaDuAdjType = 3;
2115 					}
2116 					else
2117 					{
2118 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2119 						pCoexDm->psTdmaDuAdjType = 3;
2120 					}
2121 				}
2122 			}
2123 		}
2124 		//============
2125 		up = 0;
2126 		dn = 0;
2127 		m = 1;
2128 		n= 3;
2129 		result = 0;
2130 		WaitCount = 0;
2131 	}
2132 	else
2133 	{
2134 		//accquire the BT TRx retry count from BT_Info byte2
2135 		retryCount = pCoexSta->btRetryCnt;
2136 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
2137 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n",
2138 			up, dn, m, n, WaitCount));
2139 		result = 0;
2140 		WaitCount++;
2141 
2142 		if(retryCount == 0)  // no retry in the last 2-second duration
2143 		{
2144 			up++;
2145 			dn--;
2146 
2147 			if (dn <= 0)
2148 				dn = 0;
2149 
2150 			if(up >= n)	// if �s�� n ��2�� retry count��0, �h�ռeWiFi duration
2151 			{
2152 				WaitCount = 0;
2153 				n = 3;
2154 				up = 0;
2155 				dn = 0;
2156 				result = 1;
2157 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
2158 			}
2159 		}
2160 		else if (retryCount <= 3)	// <=3 retry in the last 2-second duration
2161 		{
2162 			up--;
2163 			dn++;
2164 
2165 			if (up <= 0)
2166 				up = 0;
2167 
2168 			if (dn == 2)	// if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration
2169 			{
2170 				if (WaitCount <= 2)
2171 					m++; // �קK�@���b���level���Ӧ^
2172 				else
2173 					m = 1;
2174 
2175 				if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
2176 					m = 20;
2177 
2178 				n = 3*m;
2179 				up = 0;
2180 				dn = 0;
2181 				WaitCount = 0;
2182 				result = -1;
2183 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
2184 			}
2185 		}
2186 		else  //retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration
2187 		{
2188 			if (WaitCount == 1)
2189 				m++; // �קK�@���b���level���Ӧ^
2190 			else
2191 				m = 1;
2192 
2193 			if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
2194 				m = 20;
2195 
2196 			n = 3*m;
2197 			up = 0;
2198 			dn = 0;
2199 			WaitCount = 0;
2200 			result = -1;
2201 			RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
2202 		}
2203 
2204 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
2205 		if(maxInterval == 1)
2206 		{
2207 			if(bTxPause)
2208 			{
2209 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));
2210 
2211                                 if(pCoexDm->curPsTdma == 1)
2212 				{
2213 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2214 					pCoexDm->psTdmaDuAdjType = 5;
2215 				}
2216 				else if(pCoexDm->curPsTdma == 2)
2217 				{
2218 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2219 					pCoexDm->psTdmaDuAdjType = 6;
2220 				}
2221 				else if(pCoexDm->curPsTdma == 3)
2222 				{
2223 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2224 					pCoexDm->psTdmaDuAdjType = 7;
2225 				}
2226 				else if(pCoexDm->curPsTdma == 4)
2227 				{
2228 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2229 					pCoexDm->psTdmaDuAdjType = 8;
2230 				}
2231 				if(pCoexDm->curPsTdma == 9)
2232 				{
2233 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2234 					pCoexDm->psTdmaDuAdjType = 13;
2235 				}
2236 				else if(pCoexDm->curPsTdma == 10)
2237 				{
2238 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2239 					pCoexDm->psTdmaDuAdjType = 14;
2240 				}
2241 				else if(pCoexDm->curPsTdma == 11)
2242 				{
2243 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2244 					pCoexDm->psTdmaDuAdjType = 15;
2245 				}
2246 				else if(pCoexDm->curPsTdma == 12)
2247 				{
2248 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2249 					pCoexDm->psTdmaDuAdjType = 16;
2250 				}
2251 
2252 				if(result == -1)
2253 				{
2254 					if(pCoexDm->curPsTdma == 5)
2255 					{
2256 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2257 						pCoexDm->psTdmaDuAdjType = 6;
2258 					}
2259 					else if(pCoexDm->curPsTdma == 6)
2260 					{
2261 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2262 						pCoexDm->psTdmaDuAdjType = 7;
2263 					}
2264 					else if(pCoexDm->curPsTdma == 7)
2265 					{
2266 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2267 						pCoexDm->psTdmaDuAdjType = 8;
2268 					}
2269 					else if(pCoexDm->curPsTdma == 13)
2270 					{
2271 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2272 						pCoexDm->psTdmaDuAdjType = 14;
2273 					}
2274 					else if(pCoexDm->curPsTdma == 14)
2275 					{
2276 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2277 						pCoexDm->psTdmaDuAdjType = 15;
2278 					}
2279 					else if(pCoexDm->curPsTdma == 15)
2280 					{
2281 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2282 						pCoexDm->psTdmaDuAdjType = 16;
2283 					}
2284 				}
2285 				else if (result == 1)
2286 				{
2287 					if(pCoexDm->curPsTdma == 8)
2288 					{
2289 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2290 						pCoexDm->psTdmaDuAdjType = 7;
2291 					}
2292 					else if(pCoexDm->curPsTdma == 7)
2293 					{
2294 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2295 						pCoexDm->psTdmaDuAdjType = 6;
2296 					}
2297 					else if(pCoexDm->curPsTdma == 6)
2298 					{
2299 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2300 						pCoexDm->psTdmaDuAdjType = 5;
2301 					}
2302 					else if(pCoexDm->curPsTdma == 16)
2303 					{
2304 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2305 						pCoexDm->psTdmaDuAdjType = 15;
2306 					}
2307 					else if(pCoexDm->curPsTdma == 15)
2308 					{
2309 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2310 						pCoexDm->psTdmaDuAdjType = 14;
2311 					}
2312 					else if(pCoexDm->curPsTdma == 14)
2313 					{
2314 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2315 						pCoexDm->psTdmaDuAdjType = 13;
2316 					}
2317 				}
2318 			}
2319 			else
2320 			{
2321 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));
2322 				if(pCoexDm->curPsTdma == 5)
2323 				{
2324 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2325 					pCoexDm->psTdmaDuAdjType = 1;
2326 				}
2327 				else if(pCoexDm->curPsTdma == 6)
2328 				{
2329 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2330 					pCoexDm->psTdmaDuAdjType = 2;
2331 				}
2332 				else if(pCoexDm->curPsTdma == 7)
2333 				{
2334 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2335 					pCoexDm->psTdmaDuAdjType = 3;
2336 				}
2337 				else if(pCoexDm->curPsTdma == 8)
2338 				{
2339 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2340 					pCoexDm->psTdmaDuAdjType = 4;
2341 				}
2342 				if(pCoexDm->curPsTdma == 13)
2343 				{
2344 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2345 					pCoexDm->psTdmaDuAdjType = 9;
2346 				}
2347 				else if(pCoexDm->curPsTdma == 14)
2348 				{
2349 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2350 					pCoexDm->psTdmaDuAdjType = 10;
2351 				}
2352 				else if(pCoexDm->curPsTdma == 15)
2353 				{
2354 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2355 					pCoexDm->psTdmaDuAdjType = 11;
2356 				}
2357 				else if(pCoexDm->curPsTdma == 16)
2358 				{
2359 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2360 					pCoexDm->psTdmaDuAdjType = 12;
2361 				}
2362 
2363 				if(result == -1)
2364 				{
2365 					if(pCoexDm->curPsTdma == 1)
2366 					{
2367 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2368 						pCoexDm->psTdmaDuAdjType = 2;
2369 					}
2370 					else if(pCoexDm->curPsTdma == 2)
2371 					{
2372 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2373 						pCoexDm->psTdmaDuAdjType = 3;
2374 					}
2375 					else if(pCoexDm->curPsTdma == 3)
2376 					{
2377 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2378 						pCoexDm->psTdmaDuAdjType = 4;
2379 					}
2380 					else if(pCoexDm->curPsTdma == 9)
2381 					{
2382 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2383 						pCoexDm->psTdmaDuAdjType = 10;
2384 					}
2385 					else if(pCoexDm->curPsTdma == 10)
2386 					{
2387 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2388 						pCoexDm->psTdmaDuAdjType = 11;
2389 					}
2390 					else if(pCoexDm->curPsTdma == 11)
2391 					{
2392 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2393 						pCoexDm->psTdmaDuAdjType = 12;
2394 					}
2395 				}
2396 				else if (result == 1)
2397 				{
2398 					if(pCoexDm->curPsTdma == 4)
2399 					{
2400 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2401 						pCoexDm->psTdmaDuAdjType = 3;
2402 					}
2403 					else if(pCoexDm->curPsTdma == 3)
2404 					{
2405 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2406 						pCoexDm->psTdmaDuAdjType = 2;
2407 					}
2408 					else if(pCoexDm->curPsTdma == 2)
2409 					{
2410 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2411 						pCoexDm->psTdmaDuAdjType = 1;
2412 					}
2413 					else if(pCoexDm->curPsTdma == 12)
2414 					{
2415 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2416 						pCoexDm->psTdmaDuAdjType = 11;
2417 					}
2418 					else if(pCoexDm->curPsTdma == 11)
2419 					{
2420 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2421 						pCoexDm->psTdmaDuAdjType = 10;
2422 					}
2423 					else if(pCoexDm->curPsTdma == 10)
2424 					{
2425 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2426 						pCoexDm->psTdmaDuAdjType = 9;
2427 					}
2428 				}
2429 			}
2430 		}
2431 		else if(maxInterval == 2)
2432 		{
2433 			if(bTxPause)
2434 			{
2435 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));
2436 				if(pCoexDm->curPsTdma == 1)
2437 				{
2438 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2439 					pCoexDm->psTdmaDuAdjType = 6;
2440 				}
2441 				else if(pCoexDm->curPsTdma == 2)
2442 				{
2443 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2444 					pCoexDm->psTdmaDuAdjType = 6;
2445 				}
2446 				else if(pCoexDm->curPsTdma == 3)
2447 				{
2448 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2449 					pCoexDm->psTdmaDuAdjType = 7;
2450 				}
2451 				else if(pCoexDm->curPsTdma == 4)
2452 				{
2453 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2454 					pCoexDm->psTdmaDuAdjType = 8;
2455 				}
2456 				if(pCoexDm->curPsTdma == 9)
2457 				{
2458 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2459 					pCoexDm->psTdmaDuAdjType = 14;
2460 				}
2461 				else if(pCoexDm->curPsTdma == 10)
2462 				{
2463 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2464 					pCoexDm->psTdmaDuAdjType = 14;
2465 				}
2466 				else if(pCoexDm->curPsTdma == 11)
2467 				{
2468 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2469 					pCoexDm->psTdmaDuAdjType = 15;
2470 				}
2471 				else if(pCoexDm->curPsTdma == 12)
2472 				{
2473 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2474 					pCoexDm->psTdmaDuAdjType = 16;
2475 				}
2476 				if(result == -1)
2477 				{
2478 					if(pCoexDm->curPsTdma == 5)
2479 					{
2480 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2481 						pCoexDm->psTdmaDuAdjType = 6;
2482 					}
2483 					else if(pCoexDm->curPsTdma == 6)
2484 					{
2485 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2486 						pCoexDm->psTdmaDuAdjType = 7;
2487 					}
2488 					else if(pCoexDm->curPsTdma == 7)
2489 					{
2490 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2491 						pCoexDm->psTdmaDuAdjType = 8;
2492 					}
2493 					else if(pCoexDm->curPsTdma == 13)
2494 					{
2495 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2496 						pCoexDm->psTdmaDuAdjType = 14;
2497 					}
2498 					else if(pCoexDm->curPsTdma == 14)
2499 					{
2500 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2501 						pCoexDm->psTdmaDuAdjType = 15;
2502 					}
2503 					else if(pCoexDm->curPsTdma == 15)
2504 					{
2505 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2506 						pCoexDm->psTdmaDuAdjType = 16;
2507 					}
2508 				}
2509 				else if (result == 1)
2510 				{
2511 					if(pCoexDm->curPsTdma == 8)
2512 					{
2513 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2514 						pCoexDm->psTdmaDuAdjType = 7;
2515 					}
2516 					else if(pCoexDm->curPsTdma == 7)
2517 					{
2518 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2519 						pCoexDm->psTdmaDuAdjType = 6;
2520 					}
2521 					else if(pCoexDm->curPsTdma == 6)
2522 					{
2523 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2524 						pCoexDm->psTdmaDuAdjType = 6;
2525 					}
2526 					else if(pCoexDm->curPsTdma == 16)
2527 					{
2528 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2529 						pCoexDm->psTdmaDuAdjType = 15;
2530 					}
2531 					else if(pCoexDm->curPsTdma == 15)
2532 					{
2533 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2534 						pCoexDm->psTdmaDuAdjType = 14;
2535 					}
2536 					else if(pCoexDm->curPsTdma == 14)
2537 					{
2538 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2539 						pCoexDm->psTdmaDuAdjType = 14;
2540 					}
2541 				}
2542 			}
2543 			else
2544 			{
2545 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));
2546 				if(pCoexDm->curPsTdma == 5)
2547 				{
2548 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2549 					pCoexDm->psTdmaDuAdjType = 2;
2550 				}
2551 				else if(pCoexDm->curPsTdma == 6)
2552 				{
2553 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2554 					pCoexDm->psTdmaDuAdjType = 2;
2555 				}
2556 				else if(pCoexDm->curPsTdma == 7)
2557 				{
2558 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2559 					pCoexDm->psTdmaDuAdjType = 3;
2560 				}
2561 				else if(pCoexDm->curPsTdma == 8)
2562 				{
2563 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2564 					pCoexDm->psTdmaDuAdjType = 4;
2565 				}
2566 				if(pCoexDm->curPsTdma == 13)
2567 				{
2568 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2569 					pCoexDm->psTdmaDuAdjType = 10;
2570 				}
2571 				else if(pCoexDm->curPsTdma == 14)
2572 				{
2573 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2574 					pCoexDm->psTdmaDuAdjType = 10;
2575 				}
2576 				else if(pCoexDm->curPsTdma == 15)
2577 				{
2578 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2579 					pCoexDm->psTdmaDuAdjType = 11;
2580 				}
2581 				else if(pCoexDm->curPsTdma == 16)
2582 				{
2583 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2584 					pCoexDm->psTdmaDuAdjType = 12;
2585 				}
2586 				if(result == -1)
2587 				{
2588 					if(pCoexDm->curPsTdma == 1)
2589 					{
2590 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2591 						pCoexDm->psTdmaDuAdjType = 2;
2592 					}
2593 					else if(pCoexDm->curPsTdma == 2)
2594 					{
2595 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2596 						pCoexDm->psTdmaDuAdjType = 3;
2597 					}
2598 					else if(pCoexDm->curPsTdma == 3)
2599 					{
2600 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2601 						pCoexDm->psTdmaDuAdjType = 4;
2602 					}
2603 					else if(pCoexDm->curPsTdma == 9)
2604 					{
2605 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2606 						pCoexDm->psTdmaDuAdjType = 10;
2607 					}
2608 					else if(pCoexDm->curPsTdma == 10)
2609 					{
2610 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2611 						pCoexDm->psTdmaDuAdjType = 11;
2612 					}
2613 					else if(pCoexDm->curPsTdma == 11)
2614 					{
2615 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2616 						pCoexDm->psTdmaDuAdjType = 12;
2617 					}
2618 				}
2619 				else if (result == 1)
2620 				{
2621 					if(pCoexDm->curPsTdma == 4)
2622 					{
2623 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2624 						pCoexDm->psTdmaDuAdjType = 3;
2625 					}
2626 					else if(pCoexDm->curPsTdma == 3)
2627 					{
2628 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2629 						pCoexDm->psTdmaDuAdjType = 2;
2630 					}
2631 					else if(pCoexDm->curPsTdma == 2)
2632 					{
2633 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2634 						pCoexDm->psTdmaDuAdjType = 2;
2635 					}
2636 					else if(pCoexDm->curPsTdma == 12)
2637 					{
2638 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2639 						pCoexDm->psTdmaDuAdjType = 11;
2640 					}
2641 					else if(pCoexDm->curPsTdma == 11)
2642 					{
2643 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2644 						pCoexDm->psTdmaDuAdjType = 10;
2645 					}
2646 					else if(pCoexDm->curPsTdma == 10)
2647 					{
2648 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
2649 						pCoexDm->psTdmaDuAdjType = 10;
2650 					}
2651 				}
2652 			}
2653 		}
2654 		else if(maxInterval == 3)
2655 		{
2656 			if(bTxPause)
2657 			{
2658 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));
2659 				if(pCoexDm->curPsTdma == 1)
2660 				{
2661 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2662 					pCoexDm->psTdmaDuAdjType = 7;
2663 				}
2664 				else if(pCoexDm->curPsTdma == 2)
2665 				{
2666 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2667 					pCoexDm->psTdmaDuAdjType = 7;
2668 				}
2669 				else if(pCoexDm->curPsTdma == 3)
2670 				{
2671 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2672 					pCoexDm->psTdmaDuAdjType = 7;
2673 				}
2674 				else if(pCoexDm->curPsTdma == 4)
2675 				{
2676 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2677 					pCoexDm->psTdmaDuAdjType = 8;
2678 				}
2679 				if(pCoexDm->curPsTdma == 9)
2680 				{
2681 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2682 					pCoexDm->psTdmaDuAdjType = 15;
2683 				}
2684 				else if(pCoexDm->curPsTdma == 10)
2685 				{
2686 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2687 					pCoexDm->psTdmaDuAdjType = 15;
2688 				}
2689 				else if(pCoexDm->curPsTdma == 11)
2690 				{
2691 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2692 					pCoexDm->psTdmaDuAdjType = 15;
2693 				}
2694 				else if(pCoexDm->curPsTdma == 12)
2695 				{
2696 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2697 					pCoexDm->psTdmaDuAdjType = 16;
2698 				}
2699 				if(result == -1)
2700 				{
2701 					if(pCoexDm->curPsTdma == 5)
2702 					{
2703 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2704 						pCoexDm->psTdmaDuAdjType = 7;
2705 					}
2706 					else if(pCoexDm->curPsTdma == 6)
2707 					{
2708 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2709 						pCoexDm->psTdmaDuAdjType = 7;
2710 					}
2711 					else if(pCoexDm->curPsTdma == 7)
2712 					{
2713 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2714 						pCoexDm->psTdmaDuAdjType = 8;
2715 					}
2716 					else if(pCoexDm->curPsTdma == 13)
2717 					{
2718 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2719 						pCoexDm->psTdmaDuAdjType = 15;
2720 					}
2721 					else if(pCoexDm->curPsTdma == 14)
2722 					{
2723 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2724 						pCoexDm->psTdmaDuAdjType = 15;
2725 					}
2726 					else if(pCoexDm->curPsTdma == 15)
2727 					{
2728 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);
2729 						pCoexDm->psTdmaDuAdjType = 16;
2730 					}
2731 				}
2732 				else if (result == 1)
2733 				{
2734 					if(pCoexDm->curPsTdma == 8)
2735 					{
2736 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2737 						pCoexDm->psTdmaDuAdjType = 7;
2738 					}
2739 					else if(pCoexDm->curPsTdma == 7)
2740 					{
2741 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2742 						pCoexDm->psTdmaDuAdjType = 7;
2743 					}
2744 					else if(pCoexDm->curPsTdma == 6)
2745 					{
2746 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2747 						pCoexDm->psTdmaDuAdjType = 7;
2748 					}
2749 					else if(pCoexDm->curPsTdma == 16)
2750 					{
2751 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2752 						pCoexDm->psTdmaDuAdjType = 15;
2753 					}
2754 					else if(pCoexDm->curPsTdma == 15)
2755 					{
2756 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2757 						pCoexDm->psTdmaDuAdjType = 15;
2758 					}
2759 					else if(pCoexDm->curPsTdma == 14)
2760 					{
2761 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);
2762 						pCoexDm->psTdmaDuAdjType = 15;
2763 					}
2764 				}
2765 			}
2766 			else
2767 			{
2768 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));
2769 				if(pCoexDm->curPsTdma == 5)
2770 				{
2771 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2772 					pCoexDm->psTdmaDuAdjType = 3;
2773 				}
2774 				else if(pCoexDm->curPsTdma == 6)
2775 				{
2776 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2777 					pCoexDm->psTdmaDuAdjType = 3;
2778 				}
2779 				else if(pCoexDm->curPsTdma == 7)
2780 				{
2781 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2782 					pCoexDm->psTdmaDuAdjType = 3;
2783 				}
2784 				else if(pCoexDm->curPsTdma == 8)
2785 				{
2786 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2787 					pCoexDm->psTdmaDuAdjType = 4;
2788 				}
2789 				if(pCoexDm->curPsTdma == 13)
2790 				{
2791 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2792 					pCoexDm->psTdmaDuAdjType = 11;
2793 				}
2794 				else if(pCoexDm->curPsTdma == 14)
2795 				{
2796 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2797 					pCoexDm->psTdmaDuAdjType = 11;
2798 				}
2799 				else if(pCoexDm->curPsTdma == 15)
2800 				{
2801 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2802 					pCoexDm->psTdmaDuAdjType = 11;
2803 				}
2804 				else if(pCoexDm->curPsTdma == 16)
2805 				{
2806 					halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2807 					pCoexDm->psTdmaDuAdjType = 12;
2808 				}
2809 				if(result == -1)
2810 				{
2811 					if(pCoexDm->curPsTdma == 1)
2812 					{
2813 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2814 						pCoexDm->psTdmaDuAdjType = 3;
2815 					}
2816 					else if(pCoexDm->curPsTdma == 2)
2817 					{
2818 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2819 						pCoexDm->psTdmaDuAdjType = 3;
2820 					}
2821 					else if(pCoexDm->curPsTdma == 3)
2822 					{
2823 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2824 						pCoexDm->psTdmaDuAdjType = 4;
2825 					}
2826 					else if(pCoexDm->curPsTdma == 9)
2827 					{
2828 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2829 						pCoexDm->psTdmaDuAdjType = 11;
2830 					}
2831 					else if(pCoexDm->curPsTdma == 10)
2832 					{
2833 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2834 						pCoexDm->psTdmaDuAdjType = 11;
2835 					}
2836 					else if(pCoexDm->curPsTdma == 11)
2837 					{
2838 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
2839 						pCoexDm->psTdmaDuAdjType = 12;
2840 					}
2841 				}
2842 				else if (result == 1)
2843 				{
2844 					if(pCoexDm->curPsTdma == 4)
2845 					{
2846 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2847 						pCoexDm->psTdmaDuAdjType = 3;
2848 					}
2849 					else if(pCoexDm->curPsTdma == 3)
2850 					{
2851 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2852 						pCoexDm->psTdmaDuAdjType = 3;
2853 					}
2854 					else if(pCoexDm->curPsTdma == 2)
2855 					{
2856 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2857 						pCoexDm->psTdmaDuAdjType = 3;
2858 					}
2859 					else if(pCoexDm->curPsTdma == 12)
2860 					{
2861 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2862 						pCoexDm->psTdmaDuAdjType = 11;
2863 					}
2864 					else if(pCoexDm->curPsTdma == 11)
2865 					{
2866 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2867 						pCoexDm->psTdmaDuAdjType = 11;
2868 					}
2869 					else if(pCoexDm->curPsTdma == 10)
2870 					{
2871 						halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2872 						pCoexDm->psTdmaDuAdjType = 11;
2873 					}
2874 				}
2875 			}
2876 		}
2877 	}
2878 
2879 	// if current PsTdma not match with the recorded one (when scan, dhcp...),
2880 	// then we have to adjust it back to the previous record one.
2881 	if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)
2882 	{
2883 		BOOLEAN	bScan=FALSE, bLink=FALSE, bRoam=FALSE;
2884 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n",
2885 			pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));
2886 
2887 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2888 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2889 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2890 
2891 		if( !bScan && !bLink && !bRoam)
2892 		{
2893 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
2894 		}
2895 		else
2896 		{
2897 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
2898 		}
2899 	}
2900 }
2901 
2902 //==================
2903 // pstdma for wifi rssi low
2904 //==================
2905 VOID
halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(IN PBTC_COEXIST pBtCoexist)2906 halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(
2907 	IN	PBTC_COEXIST		pBtCoexist//,
2908 	//IN	u1Byte				wifiStatus
2909 	)
2910 {
2911 	static s4Byte		up,dn,m,n,WaitCount;
2912 	s4Byte			result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
2913 	u1Byte			retryCount=0, btInfoExt;
2914 
2915 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow()\n"));
2916 #if 0
2917 	if( (BT_8812A_2ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
2918 		(BT_8812A_2ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
2919 		(BT_8812A_2ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )
2920 	{
2921 		if( pCoexDm->curPsTdma != 81 &&
2922 			pCoexDm->curPsTdma != 82 &&
2923 			pCoexDm->curPsTdma != 83 &&
2924 			pCoexDm->curPsTdma != 84 )
2925 		{
2926 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 82);
2927 			pCoexDm->psTdmaDuAdjType = 82;
2928 
2929 			up = 0;
2930 			dn = 0;
2931 			m = 1;
2932 			n= 3;
2933 			result = 0;
2934 			WaitCount = 0;
2935 		}
2936 		return;
2937 	}
2938 #endif
2939 	pCoexDm->bAutoTdmaAdjust = FALSE;
2940 
2941 	retryCount = pCoexSta->btRetryCnt;
2942 	btInfoExt = pCoexSta->btInfoExt;
2943 
2944 	if(!pCoexDm->bAutoTdmaAdjustLowRssi)
2945 	{
2946 		pCoexDm->bAutoTdmaAdjustLowRssi = TRUE;
2947 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjustForWifiRssiLow()!!\n"));
2948 
2949 		if(BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(btInfoExt))
2950 		{
2951 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 83);
2952 			pCoexDm->psTdmaDuAdjType = 83;
2953 		}
2954 		else
2955 		{
2956 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 82);
2957 		pCoexDm->psTdmaDuAdjType = 82;
2958 		}
2959 		//============
2960 		up = 0;
2961 		dn = 0;
2962 		m = 1;
2963 		n= 3;
2964 		result = 0;
2965 		WaitCount = 0;
2966 	}
2967 	else
2968 	{
2969 		//accquire the BT TRx retry count from BT_Info byte2
2970 //		retryCount = pCoexSta->btRetryCnt;
2971 //		btInfoExt = pCoexSta->btInfoExt;
2972 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
2973 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n",
2974 			up, dn, m, n, WaitCount));
2975 		result = 0;
2976 		WaitCount++;
2977 
2978 		if ( (pCoexSta->lowPriorityTx) > 1050 ||  (pCoexSta->lowPriorityRx) > 1250 )
2979 			retryCount++;
2980 
2981 		if(retryCount == 0)  // no retry in the last 2-second duration
2982 		{
2983 			up++;
2984 			dn--;
2985 
2986 			if (dn <= 0)
2987 				dn = 0;
2988 
2989 			if(up >= n)	// if �s�� n ��2�� retry count��0, �h�ռeWiFi duration
2990 			{
2991 				WaitCount = 0;
2992 				n = 3;
2993 				up = 0;
2994 				dn = 0;
2995 				result = 1;
2996 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
2997 			}
2998 		}
2999 		else if (retryCount <= 3)	// <=3 retry in the last 2-second duration
3000 		{
3001 			up--;
3002 			dn++;
3003 
3004 			if (up <= 0)
3005 				up = 0;
3006 
3007 			if (dn == 2)	// if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration
3008 			{
3009 				if (WaitCount <= 2)
3010 					m++; // �קK�@���b���level���Ӧ^
3011 				else
3012 					m = 1;
3013 
3014 				if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
3015 					m = 20;
3016 
3017 				n = 3*m;
3018 				up = 0;
3019 				dn = 0;
3020 				WaitCount = 0;
3021 				result = -1;
3022 				RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
3023 			}
3024 		}
3025 		else  //retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration
3026 		{
3027 			if (WaitCount == 1)
3028 				m++; // �קK�@���b���level���Ӧ^
3029 			else
3030 				m = 1;
3031 
3032 			if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
3033 				m = 20;
3034 
3035 			n = 3*m;
3036 			up = 0;
3037 			dn = 0;
3038 			WaitCount = 0;
3039 			result = -1;
3040 			RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
3041 		}
3042 
3043 		if(result == -1)
3044 		{
3045 /*
3046 			if( (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(btInfoExt)) &&
3047 				((pCoexDm->curPsTdma == 81) ||(pCoexDm->curPsTdma == 82)) )
3048 			{
3049 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 84);
3050 				pCoexDm->psTdmaDuAdjType = 84;
3051 			}
3052 */
3053 			if(pCoexDm->curPsTdma == 80)
3054 			{
3055 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 82);
3056 				pCoexDm->psTdmaDuAdjType = 82;
3057 			}
3058 			else if(pCoexDm->curPsTdma == 81)
3059 			{
3060 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 82);
3061 				pCoexDm->psTdmaDuAdjType = 82;
3062 			}
3063 			else if(pCoexDm->curPsTdma == 82)
3064 			{
3065 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 83);
3066 				pCoexDm->psTdmaDuAdjType = 83;
3067 			}
3068 			else if(pCoexDm->curPsTdma == 83)
3069 			{
3070 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 84);
3071 				pCoexDm->psTdmaDuAdjType = 84;
3072 			}
3073 		}
3074 		else if(result == 1)
3075 		{
3076 /*
3077 			if( (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(btInfoExt)) &&
3078 				((pCoexDm->curPsTdma == 81) ||(pCoexDm->curPsTdma == 82)) )
3079 			{
3080 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 83);
3081 				pCoexDm->psTdmaDuAdjType = 83;
3082 			}
3083 */
3084 			if(pCoexDm->curPsTdma == 84)
3085 			{
3086 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 83);
3087 				pCoexDm->psTdmaDuAdjType = 83;
3088 			}
3089 			else if(pCoexDm->curPsTdma == 83)
3090 			{
3091 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 82);
3092 				pCoexDm->psTdmaDuAdjType = 82;
3093 			}
3094 			else if(pCoexDm->curPsTdma == 82)
3095 			{
3096 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 81);
3097 				pCoexDm->psTdmaDuAdjType = 81;
3098 			}
3099 			else if((pCoexDm->curPsTdma == 81)&&((pCoexSta->nScanAPNum <= 5)))
3100 			{
3101 				halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 81);
3102 				pCoexDm->psTdmaDuAdjType = 81;
3103 		        }
3104                 }
3105 
3106 		if( pCoexDm->curPsTdma != 80 &&
3107                         pCoexDm->curPsTdma != 81 &&
3108 			pCoexDm->curPsTdma != 82 &&
3109 			pCoexDm->curPsTdma != 83 &&
3110 			pCoexDm->curPsTdma != 84 )
3111 		{
3112 			// recover to previous adjust type
3113 			halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
3114 		}
3115 	}
3116 }
3117 
3118 VOID
halbtc8812a2ant_GetBtRssiThreshold(IN PBTC_COEXIST pBtCoexist,IN pu1Byte pThres0,IN pu1Byte pThres1)3119 halbtc8812a2ant_GetBtRssiThreshold(
3120 	IN	PBTC_COEXIST		pBtCoexist,
3121 	IN	pu1Byte				pThres0,
3122 	IN	pu1Byte				pThres1
3123 	)
3124 {
3125 	u1Byte antType, btThreshold=0;
3126 
3127 //	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_ANT_TYPE, &antType);
3128 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
3129         antType = pBoardInfo->antType;
3130 
3131 
3132 	switch(antType)
3133 	{
3134 		case BTC_ANT_TYPE_0:
3135 			*pThres0 = 100;
3136 			*pThres1 = 100;
3137 			break;
3138 		case BTC_ANT_TYPE_1:
3139 			*pThres0 = 34;
3140 			*pThres1 = 42;
3141 			break;
3142 		case BTC_ANT_TYPE_2:
3143 			*pThres0 = 34;
3144 			*pThres1 = 42;
3145 			break;
3146 		case BTC_ANT_TYPE_3:
3147 			*pThres0 = 34;
3148 			*pThres1 = 42;
3149 			break;
3150 		case BTC_ANT_TYPE_4:
3151 			*pThres0 = 34;
3152 			*pThres1 = 42;
3153 			break;
3154 		default:
3155 			break;
3156 	}
3157 }
3158 
3159 
3160 
3161 VOID
halbtc8812a2ant_ActionSco(IN PBTC_COEXIST pBtCoexist)3162 halbtc8812a2ant_ActionSco(
3163 	IN	PBTC_COEXIST		pBtCoexist
3164 	)
3165 {
3166 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3167 	u4Byte		wifiBw;
3168 	u1Byte		btThresh0=0, btThresh1=0;
3169 
3170 
3171 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3172 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3173 
3174 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3175 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3176 
3177 	// power save state
3178 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3179 
3180 	// coex table
3181 	if(BTC_RSSI_LOW(btRssiState))
3182 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
3183 	else
3184 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
3185 
3186 	// pstdma
3187 	if(BTC_RSSI_LOW(btRssiState))
3188 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
3189 	else
3190 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
3191 
3192 	// decrease BT power
3193 	if(BTC_RSSI_LOW(btRssiState))
3194 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3195 	else if(BTC_RSSI_MEDIUM(btRssiState))
3196 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3197 	else
3198 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3199 
3200 	// limited Rx
3201 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3202 
3203 	// fw dac swing level
3204 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3205 
3206 
3207 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3208 	// sw mechanism
3209 	if(BTC_WIFI_BW_HT40 == wifiBw)
3210 	{
3211 		if(BTC_RSSI_HIGH(wifiRssiState))
3212 		{
3213 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3214 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);
3215 		}
3216 		else
3217 		{
3218 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3219 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);
3220 		}
3221 	}
3222 	else
3223 	{
3224 		if(BTC_RSSI_HIGH(wifiRssiState))
3225 		{
3226 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3227 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);
3228 		}
3229 		else
3230 		{
3231 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3232 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);
3233 		}
3234 	}
3235 }
3236 
3237 VOID
halbtc8812a2ant_ActionScoHid(IN PBTC_COEXIST pBtCoexist)3238 halbtc8812a2ant_ActionScoHid(
3239 	IN	PBTC_COEXIST		pBtCoexist
3240 	)
3241 {
3242 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3243 	u4Byte		wifiBw;
3244 	u1Byte		btThresh0=0, btThresh1=0;
3245 
3246 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3247 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3248 
3249 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3250 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3251 
3252 	// power save state
3253 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3254 
3255 	// coex table
3256 	halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
3257 
3258 	// pstdma
3259 	if(BTC_RSSI_LOW(btRssiState))
3260 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
3261 	else
3262 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
3263 
3264 	// decrease BT power
3265 	if(BTC_RSSI_LOW(btRssiState))
3266 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3267 	else if(BTC_RSSI_MEDIUM(btRssiState))
3268 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3269 	else
3270 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3271 
3272 	// limited Rx
3273 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
3274 
3275 	// fw dac swing level
3276 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3277 
3278 
3279 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3280 	// sw mechanism
3281 	if(BTC_WIFI_BW_HT40 == wifiBw)
3282 	{
3283 		if(BTC_RSSI_HIGH(wifiRssiState))
3284 		{
3285 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3286 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);
3287 		}
3288 		else
3289 		{
3290 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3291 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6);
3292 		}
3293 	}
3294 	else
3295 	{
3296 		if(BTC_RSSI_HIGH(wifiRssiState))
3297 		{
3298 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3299 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);
3300 		}
3301 		else
3302 		{
3303 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3304 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6);
3305 		}
3306 	}
3307 }
3308 
3309 VOID
halbtc8812a2ant_ActionHid(IN PBTC_COEXIST pBtCoexist)3310 halbtc8812a2ant_ActionHid(
3311 	IN	PBTC_COEXIST		pBtCoexist
3312 	)
3313 {
3314 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3315 	u4Byte		wifiBw;
3316 	u1Byte		anttype=0;
3317 	BOOLEAN 	bApEnable=FALSE;
3318 
3319 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
3320 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
3321 
3322     anttype = pBoardInfo->antType;
3323 
3324 
3325 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3326 //	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3327 
3328 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3329 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3330 
3331 
3332 	if(anttype == 0)//ANTTYPE = 0   92E 2ant with SPDT
3333 	{
3334 		// power save state & pstdma & coex table
3335        	pCoexDm->bAutoTdmaAdjust = FALSE;
3336 		pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3337 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3338 		halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
3339 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3340 	}
3341 	else if(anttype == 1) //92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation
3342 	{
3343 		// power save state & pstdma & coex table
3344        	pCoexDm->bAutoTdmaAdjust = FALSE;
3345 		pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3346 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3347 		halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
3348 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3349 	}
3350 	else if(anttype == 2)//ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation
3351 	{
3352 		// power save state & pstdma & coex table
3353 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3354 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3355 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3356 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 9);
3357 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
3358 		}
3359 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3360         {	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3361 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3362 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 9);
3363 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
3364         }
3365 		else	//WIFI RSSI || BT RSSI == low
3366 		{
3367 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3368 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 9);
3369 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
3370 		}
3371 	}
3372 	else if(anttype == 3)	//ANTTYPE = 3,  92E 3ant with good ant. isolation
3373 	{
3374 		// power save state & pstdma & coex table
3375 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3376 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3377         	pCoexDm->bAutoTdmaAdjust = FALSE;
3378 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3379 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3380 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3381 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3382 
3383 		}
3384 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3385 		{	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3386         	pCoexDm->bAutoTdmaAdjust = FALSE;
3387 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3388 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3389 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3390 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3391 
3392 		}
3393 		else	//WIFI RSSI || BT RSSI == low
3394 		{
3395         	pCoexDm->bAutoTdmaAdjust = FALSE;
3396 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3397 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3398 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3399 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3400 		}
3401 	}
3402 	else	//ANTTYPE = 4 for test
3403 	{
3404 		// power save state & pstdma & coex table
3405 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3406 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3407 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3408 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3409 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3410 		}
3411 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3412 		{	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3413 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3414 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3415 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3416 		}
3417 		else	//WIFI RSSI || BT RSSI == low
3418 		{
3419 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3420 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3421 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3422 		}
3423 	}
3424 
3425 
3426 	// power save state
3427 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3428 
3429 	// coex table
3430 	halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3431 
3432 	// pstdma
3433 	halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
3434 
3435 	// decrease BT power
3436 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3437 
3438 	// limited Rx
3439 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3440 
3441 	// fw dac swing level
3442 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3443 
3444 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3445 	// sw mechanism
3446 	if(BTC_WIFI_BW_HT40 == wifiBw)
3447 	{
3448 		if(BTC_RSSI_HIGH(wifiRssiState))
3449 		{
3450 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3451 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3452 		}
3453 		else
3454 		{
3455  			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
3456 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3457 		}
3458 	}
3459 	else
3460 	{
3461 		if(BTC_RSSI_HIGH(wifiRssiState))
3462 		{
3463 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3464 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3465 		}
3466 		else
3467 		{
3468  			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
3469 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3470 		}
3471 	}
3472 }
3473 
3474 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)
3475 VOID
halbtc8812a2ant_ActionA2dp(IN PBTC_COEXIST pBtCoexist)3476 halbtc8812a2ant_ActionA2dp(
3477 	IN	PBTC_COEXIST		pBtCoexist
3478 	)
3479 {
3480 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3481 	u4Byte		wifiBw;
3482 	u1Byte		anttype=0;
3483 	BOOLEAN			bApEnable=FALSE;
3484 
3485 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
3486 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
3487 
3488     anttype = pBoardInfo->antType;
3489 
3490 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3491 //	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3492 
3493 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3494 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3495 
3496 //	anttype = 4;
3497 
3498 	if(anttype == 0)//ANTTYPE = 0   92E 2ant with SPDT
3499 	{
3500 
3501 		if((pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3502 		{
3503 			pCoexDm->bAutoTdmaAdjust = FALSE;
3504 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3505 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3506 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
3507 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3508 		}
3509 		else
3510 		{
3511 			if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)))
3512 			{	//WIFI RSSI = high & BT RSSI = high & shielding room
3513 				halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3514 				halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3515 				halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3516 			}
3517 			else	//WIFI RSSI || BT RSSI == low
3518 			{
3519 				halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3520 				halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3521 				halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3522 			}
3523 		}
3524 
3525 		// power save state & pstdma & coex table
3526 /*
3527 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3528 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3529 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3530 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3531 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3532 		}
3533 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3534         {	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3535         	pCoexDm->bAutoTdmaAdjust = FALSE;
3536 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3537 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3538 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
3539 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3540         }
3541 		else	//WIFI RSSI || BT RSSI == low
3542 		{
3543 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3544 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3545 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3546 		}
3547 */
3548 	}
3549 	else if(anttype == 1) //92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation
3550 	{
3551 		// power save state & pstdma & coex table
3552 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3553 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3554 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3555 			halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);	//shielding room
3556 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3557 		}
3558 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3559         {	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3560         	pCoexDm->bAutoTdmaAdjust = FALSE;
3561 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3562 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3563 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3564 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3565         }
3566 		else	//WIFI RSSI || BT RSSI == low
3567 		{
3568 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3569 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3570 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3571 		}
3572 
3573 	}
3574 	else if(anttype == 2)//ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation
3575 	{
3576 		// power save state & pstdma & coex table
3577 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3578 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3579 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3580 			halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);
3581 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
3582 		}
3583 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3584         {	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3585         	pCoexDm->bAutoTdmaAdjust = FALSE;
3586 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3587 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3588 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3589 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3590         }
3591 		else	//WIFI RSSI || BT RSSI == low
3592 		{
3593 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3594 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3595 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3596 		}
3597 	}
3598 	else if(anttype == 3)	//ANTTYPE = 3,  92E 3ant with good ant. isolation
3599 	{
3600 		// power save state & pstdma & coex table
3601 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3602 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3603         	pCoexDm->bAutoTdmaAdjust = FALSE;
3604 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3605 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3606 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3607 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3608 
3609 		}
3610 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3611 		{	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3612         	pCoexDm->bAutoTdmaAdjust = FALSE;
3613 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3614 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3615 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3616 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3617 
3618 		}
3619 		else	//WIFI RSSI || BT RSSI == low
3620 		{
3621         	pCoexDm->bAutoTdmaAdjust = FALSE;
3622 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
3623 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3624 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
3625 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3626 		}
3627 	}
3628 	else	//ANTTYPE = 4 for test
3629 	{
3630 		// power save state & pstdma & coex table
3631 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
3632 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
3633 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3634 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3635 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3636 		}
3637 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
3638 		{	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
3639 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3640 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3641 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3642 		}
3643 		else	//WIFI RSSI || BT RSSI == low
3644 		{
3645 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3646 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
3647 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
3648 		}
3649 	}
3650 
3651 	// decrease BT power
3652 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3653 
3654 	// decrease BT power
3655 /*
3656 	if(BTC_RSSI_LOW(btRssiState))
3657 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3658 	else if(BTC_RSSI_MEDIUM(btRssiState))
3659 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3660 	else if (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A)  // BT HIGH RSSI & shielding room
3661 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3662 */
3663 	// limited Rx
3664 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3665 
3666 	// fw dac swing level
3667 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3668 
3669 
3670 	// sw mechanism
3671 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3672 	if(BTC_WIFI_BW_HT40 == wifiBw)
3673 	{
3674 		if(BTC_RSSI_HIGH(wifiRssiState))
3675 		{
3676  			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3677 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3678 		}
3679 		else
3680 		{
3681 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3682 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3683 		}
3684 	}
3685 	else
3686 	{
3687 		if(BTC_RSSI_HIGH(wifiRssiState))
3688 		{
3689 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3690 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3691 		}
3692 		else
3693 		{
3694 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3695 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3696 		}
3697 	}
3698 }
3699 
3700 VOID
halbtc8812a2ant_ActionA2dpPanHs(IN PBTC_COEXIST pBtCoexist)3701 halbtc8812a2ant_ActionA2dpPanHs(
3702 	IN	PBTC_COEXIST		pBtCoexist
3703 	)
3704 {
3705 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3706 	u4Byte		wifiBw;
3707 	u1Byte		btThresh0=0, btThresh1=0;
3708 
3709 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3710 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3711 
3712 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3713 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3714 
3715 	// power save state
3716 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3717 
3718 	// coex table
3719 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3720 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3721 	else
3722 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
3723 
3724 	// pstdma
3725 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3726 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 2);
3727 	else
3728 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 2);
3729 
3730 	// decrease BT power
3731 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3732 /*
3733 	// decrease BT power
3734 	if(BTC_RSSI_LOW(btRssiState))
3735 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3736 	else if(BTC_RSSI_MEDIUM(btRssiState))
3737 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3738 	else
3739 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3740 */
3741 	// limited Rx
3742 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3743 
3744 	// fw dac swing level
3745 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3746 
3747 
3748 	// sw mechanism
3749 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3750 	if(BTC_WIFI_BW_HT40 == wifiBw)
3751 	{
3752 		if(BTC_RSSI_HIGH(wifiRssiState))
3753 		{
3754  			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3755 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);
3756 		}
3757 		else
3758 		{
3759 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3760 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);
3761 		}
3762 	}
3763 	else
3764 	{
3765 		if(BTC_RSSI_HIGH(wifiRssiState))
3766 		{
3767 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3768 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);
3769 		}
3770 		else
3771 		{
3772 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3773 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);
3774 		}
3775 	}
3776 }
3777 
3778 VOID
halbtc8812a2ant_ActionPanEdr(IN PBTC_COEXIST pBtCoexist)3779 halbtc8812a2ant_ActionPanEdr(
3780 	IN	PBTC_COEXIST		pBtCoexist
3781 	)
3782 {
3783 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3784 	u4Byte		wifiBw;
3785 	u1Byte		btThresh0=0, btThresh1=0;
3786 	BOOLEAN		bApEnable=FALSE;
3787 
3788 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
3789 
3790 
3791 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3792 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3793 
3794 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3795 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3796 
3797 	// power save state
3798 	if((bApEnable == TRUE) || (BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState))))
3799 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3800 	else
3801 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3802 
3803 	// coex table
3804 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3805 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3806 	else
3807 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3808 
3809 	// pstdma
3810 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3811 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
3812 	else
3813 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 85);
3814 
3815 	// decrease BT power
3816 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3817 /*
3818 	// decrease BT power
3819 	if(BTC_RSSI_LOW(btRssiState))
3820 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3821 	else if(BTC_RSSI_MEDIUM(btRssiState))
3822 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3823 	else
3824 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3825 */
3826 	// limited Rx
3827 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3828 
3829 	// fw dac swing level
3830 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3831 
3832 
3833 	// sw mechanism
3834 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3835 	if(BTC_WIFI_BW_HT40 == wifiBw)
3836 	{
3837 		if(BTC_RSSI_HIGH(wifiRssiState))
3838 		{
3839 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3840 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3841 		}
3842 		else
3843 		{
3844 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3845 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3846 		}
3847 	}
3848 	else
3849 	{
3850 		if(BTC_RSSI_HIGH(wifiRssiState))
3851 		{
3852 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3853 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3854 		}
3855 		else
3856 		{
3857 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3858 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3859 		}
3860 	}
3861 }
3862 
3863 //PAN(HS) only
3864 VOID
halbtc8812a2ant_ActionPanHs(IN PBTC_COEXIST pBtCoexist)3865 halbtc8812a2ant_ActionPanHs(
3866 	IN	PBTC_COEXIST		pBtCoexist
3867 	)
3868 {
3869 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3870 	u4Byte		wifiBw;
3871 
3872 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3873 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3874 
3875 	// power save state
3876 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3877 
3878 	// coex table
3879 	halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3880 
3881 	// pstdma
3882 	halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);
3883 
3884 	// decrease BT power
3885 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3886 
3887 /*
3888 	// decrease BT power
3889 	if(BTC_RSSI_LOW(btRssiState))
3890 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3891 	else if(BTC_RSSI_MEDIUM(btRssiState))
3892 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3893 	else
3894 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3895 */
3896 	// limited Rx
3897 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3898 
3899 	// fw dac swing level
3900 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3901 
3902 
3903 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3904 	if(BTC_WIFI_BW_HT40 == wifiBw)
3905 	{
3906 		if(BTC_RSSI_HIGH(wifiRssiState))
3907 		{
3908 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3909 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3910 		}
3911 		else
3912 		{
3913 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
3914 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3915 		}
3916 	}
3917 	else
3918 	{
3919 		if(BTC_RSSI_HIGH(wifiRssiState))
3920 		{
3921 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3922 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
3923 		}
3924 		else
3925 		{
3926 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
3927 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
3928 		}
3929 	}
3930 }
3931 
3932 //PAN(EDR)+A2DP
3933 VOID
halbtc8812a2ant_ActionPanEdrA2dp(IN PBTC_COEXIST pBtCoexist)3934 halbtc8812a2ant_ActionPanEdrA2dp(
3935 	IN	PBTC_COEXIST		pBtCoexist
3936 	)
3937 {
3938 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
3939 	u4Byte		wifiBw;
3940 	u1Byte		btThresh0=0, btThresh1=0;
3941 	BOOLEAN			bApEnable=FALSE;
3942 
3943 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
3944 
3945 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
3946 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
3947 
3948 
3949 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
3950 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
3951 
3952 	// power save state
3953 	if((bApEnable == TRUE) || (BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState))))
3954 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3955 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3956 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3957 	else
3958 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
3959 
3960 	// coex table
3961 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3962 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3963 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3964 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
3965 	else
3966 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
3967 
3968 	// pstdma
3969 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3970 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);
3971 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
3972 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);
3973 	else
3974 	{
3975 		pCoexDm->bAutoTdmaAdjust = FALSE;
3976 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 86);
3977 	}
3978 
3979 	// decrease BT power
3980 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3981 
3982 
3983 /*
3984 	// decrease BT power
3985 	if(BTC_RSSI_LOW(btRssiState))
3986 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
3987 	else if(BTC_RSSI_MEDIUM(btRssiState))
3988 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
3989 	else
3990 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
3991 */
3992 	// limited Rx
3993 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
3994 
3995 	// fw dac swing level
3996 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
3997 
3998 
3999 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4000 	// sw mechanism
4001 	if(BTC_WIFI_BW_HT40 == wifiBw)
4002 	{
4003 		if(BTC_RSSI_HIGH(wifiRssiState))
4004 		{
4005 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
4006 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4007 		}
4008 		else
4009 		{
4010 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);
4011 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4012 		}
4013 	}
4014 	else
4015 	{
4016 		if(BTC_RSSI_HIGH(wifiRssiState))
4017 		{
4018 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
4019 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4020 		}
4021 		else
4022 		{
4023 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);
4024 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4025 		}
4026 	}
4027 }
4028 
4029 VOID
halbtc8812a2ant_ActionPanEdrHid(IN PBTC_COEXIST pBtCoexist)4030 halbtc8812a2ant_ActionPanEdrHid(
4031 	IN	PBTC_COEXIST		pBtCoexist
4032 	)
4033 {
4034 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
4035 	u4Byte		wifiBw;
4036 	u1Byte		btThresh0=0, btThresh1=0;
4037 	BOOLEAN			bApEnable=FALSE;
4038 
4039 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
4040 
4041 	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
4042 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
4043 
4044 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
4045 //	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
4046 
4047 	// power save state
4048 	if((bApEnable == TRUE) || (BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState))))
4049 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4050 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4051 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4052 	else
4053 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4054 
4055 	// coex table
4056 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4057 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
4058 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4059 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
4060 	else
4061 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4062 
4063 	// pstdma
4064 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4065 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
4066 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4067 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
4068 	else
4069 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 85);
4070 
4071 	// decrease BT power
4072 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4073 
4074 /*
4075 	// decrease BT power
4076 	if(BTC_RSSI_LOW(btRssiState))
4077 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4078 	else if(BTC_RSSI_MEDIUM(btRssiState))
4079 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
4080 	else
4081 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
4082 */
4083 	// limited Rx
4084 	if(BTC_RSSI_HIGH(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4085 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4086 	else if(BTC_RSSI_LOW(wifiRssiState) &&  (!BTC_RSSI_LOW(btRssiState)))
4087 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4088 	else
4089 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
4090 
4091 	// fw dac swing level
4092 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
4093 
4094 
4095 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4096 	// sw mechanism
4097 	if(BTC_WIFI_BW_HT40 == wifiBw)
4098 	{
4099 		if(BTC_RSSI_HIGH(wifiRssiState))
4100 		{
4101 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4102 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4103 		}
4104 		else
4105 		{
4106 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4107 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4108 		}
4109 	}
4110 	else
4111 	{
4112 		if(BTC_RSSI_HIGH(wifiRssiState))
4113 		{
4114 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4115 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4116 		}
4117 		else
4118 		{
4119 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4120 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4121 		}
4122 	}
4123 }
4124 
4125 // HID+A2DP+PAN(EDR)
4126 VOID
halbtc8812a2ant_ActionHidA2dpPanEdr(IN PBTC_COEXIST pBtCoexist)4127 halbtc8812a2ant_ActionHidA2dpPanEdr(
4128 	IN	PBTC_COEXIST		pBtCoexist
4129 	)
4130 {
4131 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
4132 	u4Byte		wifiBw;
4133 	u1Byte		btThresh0=0, btThresh1=0;
4134 	BOOLEAN			bApEnable=FALSE;
4135 
4136 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
4137 
4138 	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
4139 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
4140 
4141 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
4142 //	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
4143 
4144 	// power save state
4145 	if((bApEnable == TRUE) || (BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState))))
4146 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4147 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4148 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4149 	else
4150 		halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4151 
4152 	// coex table
4153 	if(BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4154 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
4155 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4156 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
4157 	else
4158 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4159 
4160 	// pstdma
4161 	if(BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4162 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);
4163 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4164 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);
4165 	else
4166 	{
4167 		pCoexDm->bAutoTdmaAdjust = FALSE;
4168 		halbtc8812a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 86);
4169 	}
4170 
4171 	// decrease BT power
4172 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4173 /*
4174 	// decrease BT power
4175 	if(BTC_RSSI_LOW(btRssiState))
4176 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4177 	else if(BTC_RSSI_MEDIUM(btRssiState))
4178 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
4179 	else
4180 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
4181 */
4182 	// limited Rx
4183 	if(BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4184 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4185 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4186 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4187 	else
4188 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
4189 
4190 
4191 	// fw dac swing level
4192 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
4193 
4194 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4195 	// sw mechanism
4196 	if(BTC_WIFI_BW_HT40 == wifiBw)
4197 	{
4198 		if(BTC_RSSI_HIGH(wifiRssiState))
4199 		{
4200 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4201 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4202 		}
4203 		else
4204 		{
4205 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4206 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4207 		}
4208 	}
4209 	else
4210 	{
4211 		if(BTC_RSSI_HIGH(wifiRssiState))
4212 		{
4213 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4214 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4215 		}
4216 		else
4217 		{
4218 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4219 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4220 		}
4221 	}
4222 }
4223 
4224 VOID
halbtc8812a2ant_ActionHidA2dpPanHs(IN PBTC_COEXIST pBtCoexist)4225 halbtc8812a2ant_ActionHidA2dpPanHs(
4226 	IN	PBTC_COEXIST		pBtCoexist
4227 	)
4228 {
4229 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
4230 	u4Byte		wifiBw;
4231 	u1Byte		btThresh0=0, btThresh1=0;
4232 
4233 	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
4234 	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
4235 
4236 
4237 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
4238 //	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
4239 
4240 	// power save state
4241 	halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4242 
4243 	// coex table
4244 	if(BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4245 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
4246 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4247 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
4248 	else
4249 		halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4250 
4251 	// pstdma
4252 	if(BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4253 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);
4254 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4255 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);
4256 	else
4257 		halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);
4258 
4259 	// decrease BT power
4260 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4261 
4262 /*
4263 	// decrease BT power
4264 	if(BTC_RSSI_LOW(btRssiState))
4265 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4266 	else if(BTC_RSSI_MEDIUM(btRssiState))
4267 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
4268 	else
4269 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
4270 */
4271 	// limited Rx
4272 	if(BTC_RSSI_HIGH(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4273 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4274 	else if(BTC_RSSI_LOW(wifiRssiState) && (!BTC_RSSI_LOW(btRssiState)))
4275 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4276 	else
4277 		halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
4278 
4279 	// fw dac swing level
4280 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
4281 
4282 
4283 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4284 	// sw mechanism
4285 	if(BTC_WIFI_BW_HT40 == wifiBw)
4286 	{
4287 		if(BTC_RSSI_HIGH(wifiRssiState))
4288 		{
4289 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4290 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4291 		}
4292 		else
4293 		{
4294 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4295 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4296 		}
4297 	}
4298 	else
4299 	{
4300 		if(BTC_RSSI_HIGH(wifiRssiState))
4301 		{
4302 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4303 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4304 		}
4305 		else
4306 		{
4307 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4308 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4309 		}
4310 	}
4311 }
4312 
4313 VOID
halbtc8812a2ant_ActionHidA2dp(IN PBTC_COEXIST pBtCoexist)4314 halbtc8812a2ant_ActionHidA2dp(
4315 	IN	PBTC_COEXIST		pBtCoexist
4316 	)
4317 {
4318 	u1Byte		wifiRssiState=BTC_RSSI_STATE_HIGH, btRssiState=BTC_RSSI_STATE_HIGH;
4319 	u4Byte		wifiBw;
4320 	u1Byte		btThresh0=0, btThresh1=0, anttype=0;
4321 	BOOLEAN			bApEnable=FALSE;
4322 
4323 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
4324 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
4325 
4326     anttype = pBoardInfo->antType;
4327 
4328 
4329 //	halbtc8812a2ant_GetBtRssiThreshold(pBtCoexist, &btThresh0, &btThresh1);
4330 //	btRssiState = halbtc8812a2ant_BtRssiState(3, btThresh0, btThresh1);
4331 
4332 	wifiRssiState = halbtc8812a2ant_WifiRssiState(pBtCoexist, 0, 2, 34, 0);
4333 	btRssiState = halbtc8812a2ant_BtRssiState(3, 34, 42);
4334 
4335 	if(anttype == 0)//ANTTYPE = 0	92E 2ant with SPDT
4336 	{
4337 		// power save state & pstdma & coex table
4338 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
4339 		{
4340 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4341 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 83);
4342 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4343 
4344 		}
4345 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
4346 		{
4347 			pCoexDm->bAutoTdmaAdjust = FALSE;
4348 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4349 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4350 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4351 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4352 		}
4353 		else
4354 		{
4355 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4356 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 83);
4357 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4358 		}
4359 	}
4360 	else if(anttype == 1) //92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation
4361 	{
4362 		// power save state & pstdma & coex table
4363 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
4364 		{
4365 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4366 			halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);
4367 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4368 		}
4369 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
4370 		{
4371 			pCoexDm->bAutoTdmaAdjust = FALSE;
4372 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4373 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4374 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4375 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4376 		}
4377 		else
4378 		{
4379 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4380 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 83);
4381 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4382 		}
4383 	}
4384 	else if(anttype == 2)//ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation
4385 	{
4386 		// power save state & pstdma & coex table
4387 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
4388 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
4389 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4390 			halbtc8812a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);
4391 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4392 		}
4393 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
4394         {	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
4395         	pCoexDm->bAutoTdmaAdjust = FALSE;
4396 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4397 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4398 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4399 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4400         }
4401 		else	//WIFI RSSI || BT RSSI == low
4402 		{
4403 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4404 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, 83);
4405 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
4406 		}
4407 	}
4408 	else if(anttype == 3)	//ANTTYPE = 3,  92E 3ant with good ant. isolation
4409 	{
4410 		// power save state & pstdma & coex table
4411 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
4412 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
4413         	pCoexDm->bAutoTdmaAdjust = FALSE;
4414 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4415 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4416 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
4417 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4418 
4419 		}
4420 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
4421 		{	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
4422         	pCoexDm->bAutoTdmaAdjust = FALSE;
4423 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4424 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4425 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
4426 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4427 
4428 		}
4429 		else	//WIFI RSSI || BT RSSI == low
4430 		{
4431         	pCoexDm->bAutoTdmaAdjust = FALSE;
4432 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4433 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4434 			halbtc8812a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);
4435 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4436 		}
4437 	}
4438 	else	//ANTTYPE = 4 for test
4439 	{
4440 		// power save state & pstdma & coex table
4441 		if(BTC_RSSI_HIGH(wifiRssiState) &&	(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A))
4442 		{	//WIFI RSSI = high & BT RSSI = high & shielding room
4443 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4444 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
4445 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
4446 		}
4447 		else if (BTC_RSSI_HIGH(wifiRssiState)&&(!BTC_RSSI_LOW(btRssiState)) && (pCoexSta->nScanAPNum > NOISY_AP_NUM_THRESH_8812A))
4448 		{	//WIFI RSSI = high & BT RSSI = high & noisy enviroment
4449 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4450 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
4451 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
4452 		}
4453 		else	//WIFI RSSI || BT RSSI == low
4454 		{
4455 			halbtc8812a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
4456 			halbtc8812a2ant_TdmaDurationAdjustForWifiRssiLow(pBtCoexist);
4457 			halbtc8812a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
4458 		}
4459 	}
4460 
4461 	// decrease BT power
4462 	halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4463 
4464 /*
4465 	// decrease BT power
4466 	if(BTC_RSSI_LOW(btRssiState))
4467 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
4468 	else if(BTC_RSSI_MEDIUM(btRssiState))
4469 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
4470         else if (pCoexSta->nScanAPNum < NOISY_AP_NUM_THRESH_8812A)  // BT HIGH RSSI & shielding room
4471 		halbtc8812a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
4472 */
4473 	// limited Rx
4474 	halbtc8812a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);
4475 
4476 	// fw dac swing level
4477 	halbtc8812a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
4478 
4479 
4480 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4481 	// sw mechanism
4482 	if(BTC_WIFI_BW_HT40 == wifiBw)
4483 	{
4484 		if(BTC_RSSI_HIGH(wifiRssiState))
4485 		{
4486 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4487 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4488 		}
4489 		else
4490 		{
4491 			halbtc8812a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);
4492 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4493 		}
4494 	}
4495 	else
4496 	{
4497 		if(BTC_RSSI_HIGH(wifiRssiState))
4498 		{
4499 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4500 			halbtc8812a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);
4501 		}
4502 		else
4503 		{
4504 			halbtc8812a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);
4505 			halbtc8812a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);
4506 		}
4507 	}
4508 }
4509 
4510 VOID
halbtc8812a2ant_CoexUnder5G(IN PBTC_COEXIST pBtCoexist)4511 halbtc8812a2ant_CoexUnder5G(
4512 	IN	PBTC_COEXIST		pBtCoexist
4513 	)
4514 {
4515 	halbtc8812a2ant_CoexAllOff(pBtCoexist);
4516 
4517 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Under 5G, force set BT to ignore Wlan active!!\n"));
4518 	halbtc8812a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, TRUE);
4519 }
4520 //====================================================
4521 VOID
halbtc8812a2ant_RunCoexistMechanism(IN PBTC_COEXIST pBtCoexist)4522 halbtc8812a2ant_RunCoexistMechanism(
4523 	IN	PBTC_COEXIST		pBtCoexist
4524 	)
4525 {
4526 	BOOLEAN				bWifiUnder5G=FALSE, bBtHsOn=FALSE;
4527 	u1Byte				btInfoOriginal=0, btRetryCnt=0;
4528 	u1Byte				algorithm=0;
4529 
4530 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));
4531 
4532 	if(pBtCoexist->bManualControl)
4533 	{
4534 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
4535 		return;
4536 	}
4537 
4538 	if(pCoexSta->bUnderIps)
4539 	{
4540 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));
4541 		return;
4542 	}
4543 
4544 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
4545 	if(bWifiUnder5G)
4546 	{
4547 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n"));
4548 		halbtc8812a2ant_CoexUnder5G(pBtCoexist);
4549 		return;
4550 	}
4551 
4552 
4553 	algorithm = halbtc8812a2ant_ActionAlgorithm(pBtCoexist);
4554 	if(pCoexSta->bC2hBtInquiryPage && (BT_8812A_2ANT_COEX_ALGO_PANHS!=algorithm))
4555 	{
4556 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under inquiry/page scan !!\n"));
4557 		halbtc8812a2ant_ActionBtInquiry(pBtCoexist);
4558 		return;
4559 	}
4560 
4561 	pCoexDm->curAlgorithm = algorithm;
4562 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));
4563 
4564 	if(halbtc8812a2ant_IsCommonAction(pBtCoexist))
4565 	{
4566 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant common.\n"));
4567 		pCoexDm->bAutoTdmaAdjust = FALSE;
4568 		pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4569 	}
4570 	else
4571 	{
4572 		if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)
4573 		{
4574 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n",
4575 				pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));
4576 			pCoexDm->bAutoTdmaAdjust = FALSE;
4577 			pCoexDm->bAutoTdmaAdjustLowRssi = FALSE;
4578 		}
4579 		switch(pCoexDm->curAlgorithm)
4580 		{
4581 			case BT_8812A_2ANT_COEX_ALGO_SCO:
4582 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));
4583 				halbtc8812a2ant_ActionSco(pBtCoexist);
4584 				break;
4585 			case BT_8812A_2ANT_COEX_ALGO_SCO_HID:
4586 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO+HID.\n"));
4587 				halbtc8812a2ant_ActionScoHid(pBtCoexist);
4588 				break;
4589 			case BT_8812A_2ANT_COEX_ALGO_HID:
4590 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));
4591 				halbtc8812a2ant_ActionHid(pBtCoexist);
4592 				break;
4593 			case BT_8812A_2ANT_COEX_ALGO_A2DP:
4594 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));
4595 				halbtc8812a2ant_ActionA2dp(pBtCoexist);
4596 				break;
4597 			case BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS:
4598 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));
4599 				halbtc8812a2ant_ActionA2dpPanHs(pBtCoexist);
4600 				break;
4601 			case BT_8812A_2ANT_COEX_ALGO_PANEDR:
4602 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));
4603 				halbtc8812a2ant_ActionPanEdr(pBtCoexist);
4604 				break;
4605 			case BT_8812A_2ANT_COEX_ALGO_PANHS:
4606 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));
4607 				halbtc8812a2ant_ActionPanHs(pBtCoexist);
4608 				break;
4609 			case BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP:
4610 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));
4611 				halbtc8812a2ant_ActionPanEdrA2dp(pBtCoexist);
4612 				break;
4613 			case BT_8812A_2ANT_COEX_ALGO_PANEDR_HID:
4614 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
4615 				halbtc8812a2ant_ActionPanEdrHid(pBtCoexist);
4616 				break;
4617 			case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
4618 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
4619 				halbtc8812a2ant_ActionHidA2dpPanEdr(pBtCoexist);
4620 				break;
4621 			case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS:
4622 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN(HS).\n"));
4623 				halbtc8812a2ant_ActionHidA2dpPanHs(pBtCoexist);
4624 				break;
4625 			case BT_8812A_2ANT_COEX_ALGO_HID_A2DP:
4626 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));
4627 				halbtc8812a2ant_ActionHidA2dp(pBtCoexist);
4628 				break;
4629 			default:
4630 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));
4631 				halbtc8812a2ant_CoexAllOff(pBtCoexist);
4632 				break;
4633 		}
4634 		pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
4635 	}
4636 
4637 }
4638 
4639 VOID
halbtc8812a2ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bBackUp)4640 halbtc8812a2ant_InitHwConfig(
4641 	IN	PBTC_COEXIST		pBtCoexist,
4642 	IN	BOOLEAN				bBackUp
4643 	)
4644 {
4645 	u4Byte	u4Tmp=0;
4646 	u2Byte	u2Tmp=0;
4647 	u1Byte	u1Tmp=0;
4648 
4649 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));
4650 
4651 	if(bBackUp)
4652 	{
4653 		// backup rf 0x1e value
4654 		pCoexDm->btRf0x1eBackup =
4655 			pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);
4656 
4657 		pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4658 		pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4659 		pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4660 		pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4661 	}
4662 
4663 	//ant sw control to BT
4664 	halbtc8812a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_CPL_AUX, TRUE, FALSE);
4665 
4666 	// 0x790[5:0]=0x5
4667 	u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);
4668 	u1Tmp &= 0xc0;
4669 	u1Tmp |= 0x5;
4670 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);
4671 
4672 	// PTA parameter
4673 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, 0x0);
4674 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, 0xffff);
4675 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, 0x55555555);
4676 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, 0x55555555);
4677 
4678 	// coex parameters
4679 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
4680 
4681 	// enable counter statistics
4682 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
4683 
4684 	// disable PTA to avoid BT insn't on
4685 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x00);
4686 
4687 	// bt clock related
4688 	u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4);
4689 	u1Tmp |= BIT7;
4690 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4, u1Tmp);
4691 
4692 	// bt clock related
4693 	u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7);
4694 	u1Tmp |= BIT1;
4695 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x7, u1Tmp);
4696 }
4697 
4698 //============================================================
4699 // work around function start with wa_halbtc8812a2ant_
4700 //============================================================
4701 //============================================================
4702 // extern function start with EXhalbtc8812a2ant_
4703 //============================================================
4704 VOID
EXhalbtc8812a2ant_PowerOnSetting(IN PBTC_COEXIST pBtCoexist)4705 EXhalbtc8812a2ant_PowerOnSetting(
4706 	IN	PBTC_COEXIST		pBtCoexist
4707 	)
4708 {
4709 }
4710 
4711 VOID
EXhalbtc8812a2ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bWifiOnly)4712 EXhalbtc8812a2ant_InitHwConfig(
4713 	IN	PBTC_COEXIST		pBtCoexist,
4714 	IN	BOOLEAN				bWifiOnly
4715 	)
4716 {
4717 	halbtc8812a2ant_InitHwConfig(pBtCoexist, TRUE);
4718 }
4719 
4720 VOID
EXhalbtc8812a2ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)4721 EXhalbtc8812a2ant_InitCoexDm(
4722 	IN	PBTC_COEXIST		pBtCoexist
4723 	)
4724 {
4725 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
4726 
4727 	halbtc8812a2ant_InitCoexDm(pBtCoexist);
4728 }
4729 
4730 VOID
EXhalbtc8812a2ant_BTOffOnNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte BTstatus)4731 EXhalbtc8812a2ant_BTOffOnNotify(
4732 	IN	PBTC_COEXIST			pBtCoexist,
4733 	IN	u1Byte			BTstatus
4734 	)
4735 {
4736 	u1Byte u1Tmp=0;
4737 
4738 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BToff/on notify\n"));
4739 	DBG_871X("%s, BTstatus:%d", __func__, BTstatus);
4740 
4741 	if(BTC_BT_OFF == BTstatus)
4742 	{
4743     		//PTA off
4744 		pBtCoexist->btInfo.bBtDisabled = TRUE;
4745 		halbtc8812a2ant_EnablePTA(pBtCoexist,FORCE_EXEC, FALSE);
4746 
4747 	}
4748 	else
4749 	{
4750 		//PTA on
4751 		pBtCoexist->btInfo.bBtDisabled = FALSE;
4752 		halbtc8812a2ant_EnablePTA(pBtCoexist,FORCE_EXEC, TRUE);
4753 	}
4754 
4755 }
4756 
4757 
4758 
4759 VOID
EXhalbtc8812a2ant_DisplayCoexInfo(IN PBTC_COEXIST pBtCoexist)4760 EXhalbtc8812a2ant_DisplayCoexInfo(
4761 	IN	PBTC_COEXIST		pBtCoexist
4762 	)
4763 {
4764 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
4765 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
4766 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
4767 	pu1Byte				cliBuf=pBtCoexist->cliBuf;
4768 	u1Byte				u1Tmp[4], i, btInfoExt, psTdmaCase=0;
4769 	u2Byte				u2Tmp[4];
4770 	u4Byte				u4Tmp[4];
4771 	u4Byte				fwVer=0, btPatchVer=0;
4772 
4773 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
4774 	CL_PRINTF(cliBuf);
4775 
4776 	if(pBtCoexist->bManualControl)
4777 	{
4778 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
4779 		CL_PRINTF(cliBuf);
4780 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4781 		CL_PRINTF(cliBuf);
4782 	}
4783 
4784 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
4785 		pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);
4786 	CL_PRINTF(cliBuf);
4787 
4788 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Antenna type:", \
4789 		pBoardInfo->antType);
4790 	CL_PRINTF(cliBuf);
4791 
4792 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
4793 		((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
4794 	CL_PRINTF(cliBuf);
4795 
4796 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
4797 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
4798 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
4799 		GLCoexVerDate8812a2Ant, GLCoexVer8812a2Ant, fwVer, btPatchVer, btPatchVer);
4800 	CL_PRINTF(cliBuf);
4801 
4802 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
4803 		pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
4804 		pCoexDm->wifiChnlInfo[2]);
4805 	CL_PRINTF(cliBuf);
4806 
4807 	// wifi status
4808 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
4809 	CL_PRINTF(cliBuf);
4810 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
4811 
4812 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
4813 	CL_PRINTF(cliBuf);
4814 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \
4815 		((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):	((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
4816 		(  (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
4817 		pCoexSta->btRssi, pCoexSta->btRetryCnt);
4818 	CL_PRINTF(cliBuf);
4819 
4820 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
4821 		pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);
4822 	CL_PRINTF(cliBuf);
4823 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
4824 
4825 	btInfoExt = pCoexSta->btInfoExt;
4826 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \
4827 		(btInfoExt&BIT0)? "Basic rate":"EDR rate");
4828 	CL_PRINTF(cliBuf);
4829 
4830 	for(i=0; i<BT_INFO_SRC_8812A_2ANT_MAX; i++)
4831 	{
4832 		if(pCoexSta->btInfoC2hCnt[i])
4833 		{
4834 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8812a2Ant[i], \
4835 				pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
4836 				pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
4837 				pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
4838 				pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
4839 			CL_PRINTF(cliBuf);
4840 		}
4841 	}
4842 
4843 	// Sw mechanism
4844 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
4845 	CL_PRINTF(cliBuf);
4846 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \
4847 		pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);
4848 	CL_PRINTF(cliBuf);
4849 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \
4850 		pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);
4851 	CL_PRINTF(cliBuf);
4852 
4853 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \
4854 			pBtCoexist->btInfo.raMask);
4855 	CL_PRINTF(cliBuf);
4856 
4857 	// Fw mechanism
4858 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
4859 	CL_PRINTF(cliBuf);
4860 
4861 	psTdmaCase = pCoexDm->curPsTdma;
4862 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d/%d)", "PS TDMA", \
4863 		pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
4864 		pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
4865 		pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust, pCoexDm->bAutoTdmaAdjustLowRssi);
4866 	CL_PRINTF(cliBuf);
4867 
4868 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \
4869 		pCoexDm->curBtDecPwrLvl, pCoexDm->bCurIgnoreWlanAct);
4870 	CL_PRINTF(cliBuf);
4871 
4872 	// Hw setting
4873 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
4874 	CL_PRINTF(cliBuf);
4875 
4876 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
4877 		pCoexDm->btRf0x1eBackup);
4878 	CL_PRINTF(cliBuf);
4879 
4880 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \
4881 		pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);
4882 	CL_PRINTF(cliBuf);
4883 
4884 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4885 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4886 	u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4887 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4888 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \
4889 		u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
4890 	CL_PRINTF(cliBuf);
4891 
4892 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
4893 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);
4894 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x ", "0x778 (W_Act)/ 0x6cc (CoTab Sel)", \
4895 		u1Tmp[0], u1Tmp[1]);
4896 	CL_PRINTF(cliBuf);
4897 
4898 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x8db);
4899 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xc5b);
4900 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x8db(ADC)/0xc5b[29:25](DAC)", \
4901 		((u1Tmp[0]&0x60)>>5), ((u1Tmp[1]&0x3e)>>1));
4902 	CL_PRINTF(cliBuf);
4903 
4904 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb3);
4905 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb7);
4906 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xcb3/ 0xcb7", \
4907 		u1Tmp[0], u1Tmp[1]);
4908 	CL_PRINTF(cliBuf);
4909 
4910 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
4911 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
4912 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x974);
4913 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x40/ 0x4c[24:23]/ 0x974", \
4914 		u1Tmp[0], ((u4Tmp[0]&0x01800000)>>23), u4Tmp[1]);
4915 	CL_PRINTF(cliBuf);
4916 
4917 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
4918 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
4919 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
4920 		u4Tmp[0], u1Tmp[0]);
4921 	CL_PRINTF(cliBuf);
4922 
4923 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
4924 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa0a);
4925 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(DIG)/0xa0a(CCK-TH)", \
4926 		u4Tmp[0], u1Tmp[0]);
4927 	CL_PRINTF(cliBuf);
4928 
4929 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf48);
4930 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
4931 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
4932 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xf48/ 0xa5b (FA cnt-- OFDM : CCK)", \
4933 		u4Tmp[0], (u1Tmp[0]<<8) + u1Tmp[1]  );
4934 	CL_PRINTF(cliBuf);
4935 
4936 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
4937 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
4938 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
4939 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);
4940 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
4941 		u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);
4942 	CL_PRINTF(cliBuf);
4943 
4944 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
4945 		pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
4946 	CL_PRINTF(cliBuf);
4947 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
4948 		pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
4949 	CL_PRINTF(cliBuf);
4950 #if(BT_AUTO_REPORT_ONLY_8812A_2ANT == 1)
4951 	halbtc8812a2ant_MonitorBtCtr(pBtCoexist);
4952 #endif
4953 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
4954 }
4955 
4956 
4957 VOID
EXhalbtc8812a2ant_IpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4958 EXhalbtc8812a2ant_IpsNotify(
4959 	IN	PBTC_COEXIST		pBtCoexist,
4960 	IN	u1Byte			type
4961 	)
4962 {
4963 	BOOLEAN	bWifiUnder5G=FALSE;
4964 
4965 	if(BTC_IPS_ENTER == type)
4966 	{
4967 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
4968 		pCoexSta->bUnderIps = TRUE;
4969 		halbtc8812a2ant_CoexAllOff(pBtCoexist);
4970 		halbtc8812a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_CPL_AUX, FALSE, TRUE);
4971 
4972 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS notify, force set BT to ignore Wlan active!!\n"));
4973 		halbtc8812a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4974 		EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
4975 	}
4976 	else if(BTC_IPS_LEAVE == type)
4977 	{
4978 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
4979 		pCoexSta->bUnderIps = FALSE;
4980 
4981 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
4982 		if(!bWifiUnder5G)
4983 		{
4984 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS notify, force set BT NOT to ignore Wlan active!!\n"));
4985 			halbtc8812a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
4986 		}
4987 	}
4988 }
4989 
4990 VOID
EXhalbtc8812a2ant_LpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4991 EXhalbtc8812a2ant_LpsNotify(
4992 	IN	PBTC_COEXIST		pBtCoexist,
4993 	IN	u1Byte			type
4994 	)
4995 {
4996 	if(BTC_LPS_ENABLE == type)
4997 	{
4998 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
4999 		pCoexSta->bUnderLps = TRUE;
5000 	}
5001 	else if(BTC_LPS_DISABLE == type)
5002 	{
5003 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
5004 		pCoexSta->bUnderLps = FALSE;
5005 	}
5006 }
5007 
5008 VOID
EXhalbtc8812a2ant_ScanNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)5009 EXhalbtc8812a2ant_ScanNotify(
5010 	IN	PBTC_COEXIST		pBtCoexist,
5011 	IN	u1Byte			type
5012 	)
5013 {
5014 	if(BTC_SCAN_START == type)
5015 	{
5016 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
5017 	}
5018 	else if(BTC_SCAN_FINISH == type)
5019 	{
5020 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
5021 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);
5022 	}
5023 }
5024 
5025 VOID
EXhalbtc8812a2ant_ConnectNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)5026 EXhalbtc8812a2ant_ConnectNotify(
5027 	IN	PBTC_COEXIST		pBtCoexist,
5028 	IN	u1Byte			type
5029 	)
5030 {
5031 	if(BTC_ASSOCIATE_START == type)
5032 	{
5033 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
5034 	}
5035 	else if(BTC_ASSOCIATE_FINISH == type)
5036 	{
5037 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
5038 	}
5039 }
5040 
5041 VOID
EXhalbtc8812a2ant_MediaStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)5042 EXhalbtc8812a2ant_MediaStatusNotify(
5043 	IN	PBTC_COEXIST			pBtCoexist,
5044 	IN	u1Byte				type
5045 	)
5046 {
5047 	u1Byte			dataLen=5;
5048 	u1Byte			buf[6] = {0};
5049 	u1Byte			H2C_Parameter[3] ={0};
5050 	u4Byte			wifiBw;
5051 	u1Byte			wifiCentralChnl;
5052 
5053 	if(pBtCoexist->bManualControl ||
5054 		pBtCoexist->bStopCoexDm ||
5055 		pBtCoexist->btInfo.bBtDisabled )
5056 		return;
5057 
5058 	if(BTC_MEDIA_CONNECT == type)
5059 	{
5060 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
5061 	}
5062 	else
5063 	{
5064 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
5065 	}
5066 
5067 	// only 2.4G we need to inform bt the chnl mask
5068 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
5069 	if( (BTC_MEDIA_CONNECT == type) &&
5070 		(wifiCentralChnl <= 14) )
5071 	{
5072 		H2C_Parameter[0] = 0x1;
5073 		H2C_Parameter[1] = wifiCentralChnl;
5074 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
5075 		if(BTC_WIFI_BW_HT40 == wifiBw)
5076 			H2C_Parameter[2] = 0x30;
5077 		else
5078 			H2C_Parameter[2] = 0x20;
5079 	}
5080 
5081 	pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
5082 	pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
5083 	pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
5084 
5085 	buf[0] = dataLen;
5086 	buf[1] = 0x5;				// OP_Code
5087 	buf[2] = 0x3;				// OP_Code_Length
5088 	buf[3] = H2C_Parameter[0]; 	// OP_Code_Content
5089 	buf[4] = H2C_Parameter[1];
5090 	buf[5] = H2C_Parameter[2];
5091 
5092 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);
5093 }
5094 
5095 VOID
EXhalbtc8812a2ant_SpecialPacketNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)5096 EXhalbtc8812a2ant_SpecialPacketNotify(
5097 	IN	PBTC_COEXIST			pBtCoexist,
5098 	IN	u1Byte				type
5099 	)
5100 {
5101 	if(type == BTC_PACKET_DHCP)
5102 	{
5103 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));
5104 	}
5105 
5106 }
5107 
5108 VOID
EXhalbtc8812a2ant_BtInfoNotify(IN PBTC_COEXIST pBtCoexist,IN pu1Byte tmpBuf,IN u1Byte length)5109 EXhalbtc8812a2ant_BtInfoNotify(
5110 	IN	PBTC_COEXIST		pBtCoexist,
5111 	IN	pu1Byte			tmpBuf,
5112 	IN	u1Byte			length
5113 	)
5114 {
5115 	PBTC_BT_LINK_INFO	pBtLinkInfo=&pBtCoexist->btLinkInfo;
5116 	u1Byte			btInfo=0;
5117 	u1Byte			i, rspSource=0;
5118 	BOOLEAN			bBtBusy=FALSE, bLimitedDig=FALSE;
5119 	BOOLEAN			bWifiConnected=FALSE, bBtHsOn=FALSE, bWifiUnder5G=FALSE;
5120 
5121 	pCoexSta->bC2hBtInfoReqSent = FALSE;
5122 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
5123 
5124 	rspSource = tmpBuf[0]&0xf;
5125 	if(rspSource >= BT_INFO_SRC_8812A_2ANT_MAX)
5126 		rspSource = BT_INFO_SRC_8812A_2ANT_WIFI_FW;
5127 	pCoexSta->btInfoC2hCnt[rspSource]++;
5128 
5129 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
5130 	for(i=0; i<length; i++)
5131 	{
5132 		pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
5133 		if(i == 1)
5134 			btInfo = tmpBuf[i];
5135 		if(i == length-1)
5136 		{
5137 			RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
5138 		}
5139 		else
5140 		{
5141 			RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
5142 		}
5143 	}
5144 
5145 	if(BT_INFO_SRC_8812A_2ANT_WIFI_FW != rspSource)
5146 	{
5147 		pCoexSta->btRetryCnt =	// [3:0]
5148 			pCoexSta->btInfoC2h[rspSource][2]&0xf;
5149 
5150 		pCoexSta->btRssi =
5151 			pCoexSta->btInfoC2h[rspSource][3]*2+10;
5152 
5153 		pCoexSta->btInfoExt =
5154 			pCoexSta->btInfoC2h[rspSource][4];
5155 
5156 		// Here we need to resend some wifi info to BT
5157 		// because bt is reset and loss of the info.
5158 		if( (pCoexSta->btInfoExt & BIT1) )
5159 		{
5160 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
5161 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
5162 			if(bWifiConnected)
5163 			{
5164 				EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
5165 			}
5166 			else
5167 			{
5168 				EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
5169 			}
5170 		}
5171 
5172 		if( (pCoexSta->btInfoExt&BIT3) && !bWifiUnder5G)
5173 		{
5174 			// BT already ignored WlanAct
5175 			if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
5176 			{
5177 				if(!pCoexSta->bUnderIps)
5178 				{
5179 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
5180 					halbtc8812a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
5181 				}
5182 			}
5183 		}
5184 		else
5185 		{
5186 			// BT already NOT ignore Wlan active, do nothing here.
5187 
5188 			if(pCoexSta->bUnderIps)
5189 			{
5190 				// work around for 8812a combo hw bug => when IPS, wlanAct is always high.
5191 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS, set BT to ignore Wlan active!!\n"));
5192 				halbtc8812a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
5193 			}
5194 		}
5195 	}
5196 
5197 	// check BIT2 first ==> check if bt is under inquiry or page scan
5198 	if(btInfo & BT_INFO_8812A_2ANT_B_INQ_PAGE)
5199 		pCoexSta->bC2hBtInquiryPage = TRUE;
5200 	else
5201 		pCoexSta->bC2hBtInquiryPage = FALSE;
5202 
5203 	// set link exist status
5204 	if(!(btInfo&BT_INFO_8812A_2ANT_B_CONNECTION))
5205 	{
5206 		pCoexSta->bBtLinkExist = FALSE;
5207 		pCoexSta->bPanExist = FALSE;
5208 		pCoexSta->bA2dpExist = FALSE;
5209 		pCoexSta->bHidExist = FALSE;
5210 		pCoexSta->bScoExist = FALSE;
5211 		pCoexSta->bAclBusy = FALSE;
5212 	}
5213 	else	// connection exists
5214 	{
5215 		pCoexSta->bBtLinkExist = TRUE;
5216 		if(btInfo & BT_INFO_8812A_2ANT_B_FTP)
5217 			pCoexSta->bPanExist = TRUE;
5218 		else
5219 			pCoexSta->bPanExist = FALSE;
5220 		if(btInfo & BT_INFO_8812A_2ANT_B_A2DP)
5221 			pCoexSta->bA2dpExist = TRUE;
5222 		else
5223 			pCoexSta->bA2dpExist = FALSE;
5224 		if(btInfo & BT_INFO_8812A_2ANT_B_HID)
5225 			pCoexSta->bHidExist = TRUE;
5226 		else
5227 			pCoexSta->bHidExist = FALSE;
5228 		if(btInfo & BT_INFO_8812A_2ANT_B_SCO_ESCO)
5229 			pCoexSta->bScoExist = TRUE;
5230 		else
5231 			pCoexSta->bScoExist = FALSE;
5232 		if(btInfo & BT_INFO_8812A_2ANT_B_ACL_BUSY)
5233 			pCoexSta->bAclBusy = TRUE;
5234 		else
5235 			pCoexSta->bAclBusy = FALSE;
5236 
5237 	}
5238 
5239 	halbtc8812a2ant_UpdateBtLinkInfo(pBtCoexist);
5240 
5241 	if(!(btInfo&BT_INFO_8812A_2ANT_B_CONNECTION))
5242 	{
5243 		pCoexDm->btStatus = BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
5244 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
5245 	}
5246 	else if(btInfo == BT_INFO_8812A_2ANT_B_CONNECTION)	// connection exists but no busy
5247 	{
5248 		pCoexDm->btStatus = BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE;
5249 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
5250 	}
5251 	else if((btInfo&BT_INFO_8812A_2ANT_B_SCO_ESCO) ||
5252 		(btInfo&BT_INFO_8812A_2ANT_B_SCO_BUSY))
5253 	{
5254 		pCoexDm->btStatus = BT_8812A_2ANT_BT_STATUS_SCO_BUSY;
5255 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
5256 	}
5257 	else if(btInfo&BT_INFO_8812A_2ANT_B_ACL_BUSY)
5258 	{
5259 		pCoexDm->btStatus = BT_8812A_2ANT_BT_STATUS_ACL_BUSY;
5260 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
5261 	}
5262 	else
5263 	{
5264 		pCoexDm->btStatus = BT_8812A_2ANT_BT_STATUS_MAX;
5265 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
5266 	}
5267 
5268 	if( (BT_8812A_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
5269 		(BT_8812A_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
5270 		(BT_8812A_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
5271 	{
5272 		bBtBusy = TRUE;
5273 		if(!bWifiUnder5G)
5274 			bLimitedDig = TRUE;
5275 	}
5276 	else
5277 	{
5278 		bBtBusy = FALSE;
5279 		bLimitedDig = FALSE;
5280 	}
5281 
5282 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
5283 
5284 	pCoexDm->bLimitedDig = bLimitedDig;
5285 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);
5286 
5287 	halbtc8812a2ant_RunCoexistMechanism(pBtCoexist);
5288 }
5289 
5290 VOID
EXhalbtc8812a2ant_HaltNotify(IN PBTC_COEXIST pBtCoexist)5291 EXhalbtc8812a2ant_HaltNotify(
5292 	IN	PBTC_COEXIST			pBtCoexist
5293 	)
5294 {
5295 	u1Byte u1Tmp=0;
5296 
5297 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
5298 
5299 	halbtc8812a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_CPL_AUX, FALSE, TRUE);
5300 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify, force set BT to ignore Wlan active!!\n"));
5301 	halbtc8812a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
5302 	EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
5303 
5304 	// 0x522=0xff, pause tx
5305 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x522, 0xff);
5306 	// 0x40[7:6]=2'b01, modify BT mode.
5307 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0xc0, 0x2);
5308 	//PTA off.
5309 	pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x0);
5310 
5311 }
5312 
5313 VOID
EXhalbtc8812a2ant_Periodical(IN PBTC_COEXIST pBtCoexist)5314 EXhalbtc8812a2ant_Periodical(
5315 	IN	PBTC_COEXIST			pBtCoexist
5316 	)
5317 {
5318 	static u1Byte		disVerInfoCnt=0;
5319 	u4Byte				fwVer=0, btPatchVer=0;
5320 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
5321 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
5322 
5323 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));
5324 
5325 	if(disVerInfoCnt <= 5)
5326 	{
5327 		disVerInfoCnt += 1;
5328 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5329 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
5330 			pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));
5331 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",
5332 			((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));
5333 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
5334 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
5335 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
5336 			GLCoexVerDate8812a2Ant, GLCoexVer8812a2Ant, fwVer, btPatchVer, btPatchVer));
5337 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5338 	}
5339 
5340 #if(BT_AUTO_REPORT_ONLY_8812A_2ANT == 0)
5341 	halbtc8812a2ant_QueryBtInfo(pBtCoexist);
5342 	halbtc8812a2ant_MonitorBtCtr(pBtCoexist);
5343 //	halbtc8812a2ant_MonitorBtEnableDisable(pBtCoexist);
5344 #else
5345 	if( halbtc8812a2ant_IsWifiStatusChanged(pBtCoexist) ||
5346 		pCoexDm->bAutoTdmaAdjust ||
5347 		pCoexDm->bAutoTdmaAdjustLowRssi)
5348 	{
5349 		halbtc8812a2ant_RunCoexistMechanism(pBtCoexist);
5350 	}
5351 #endif
5352 }
5353 
5354 VOID
EXhalbtc8812a2ant_DbgControl(IN PBTC_COEXIST pBtCoexist,IN u1Byte opCode,IN u1Byte opLen,IN pu1Byte pData)5355 EXhalbtc8812a2ant_DbgControl(
5356 	IN	PBTC_COEXIST			pBtCoexist,
5357 	IN	u1Byte				opCode,
5358 	IN	u1Byte				opLen,
5359 	IN	pu1Byte				pData
5360 	)
5361 {
5362 	switch(opCode)
5363 	{
5364 		case BTC_DBG_SET_COEX_DEC_BT_PWR:
5365 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set Dec BT power\n"));
5366 			{
5367 				u1Byte	dataLen=4;
5368 				u1Byte	buf[6] = {0};
5369 				u1Byte	decBtPwr=0, pwrLevel=0;
5370 				if(opLen == 2)
5371 				{
5372 					decBtPwr = pData[0];
5373 					pwrLevel = pData[1];
5374 
5375 					buf[0] = dataLen;
5376 					buf[1] = 0x3;		// OP_Code
5377 					buf[2] = 0x2;		// OP_Code_Length
5378 
5379 					buf[3] = decBtPwr;	// OP_Code_Content
5380 					buf[4] = pwrLevel;
5381 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set Dec BT power=%d, pwrLevel=%d\n", decBtPwr, pwrLevel));
5382 					pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);
5383 				}
5384 			}
5385 			break;
5386 
5387 		case BTC_DBG_SET_COEX_BT_AFH_MAP:
5388 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set BT AFH Map\n"));
5389 			{
5390 				u1Byte	dataLen=5;
5391 				u1Byte	buf[6] = {0};
5392 				if(opLen == 3)
5393 				{
5394 					buf[0] = dataLen;
5395 					buf[1] = 0x5;				// OP_Code
5396 					buf[2] = 0x3;				// OP_Code_Length
5397 
5398 					buf[3] = pData[0];			// OP_Code_Content
5399 					buf[4] = pData[1];
5400 					buf[5] = pData[2];
5401 
5402 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set BT AFH Map = %02x %02x %02x\n",
5403 						pData[0], pData[1], pData[2]));
5404 					pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);
5405 				}
5406 			}
5407 			break;
5408 
5409 		case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:
5410 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set BT Ignore Wlan Active\n"));
5411 			{
5412 				u1Byte	dataLen=3;
5413 				u1Byte	buf[6] = {0};
5414 				if(opLen == 1)
5415 				{
5416 					buf[0] = dataLen;
5417 					buf[1] = 0x1;			// OP_Code
5418 					buf[2] = 0x1;			// OP_Code_Length
5419 
5420 					buf[3] = pData[0];		// OP_Code_Content
5421 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set BT Ignore Wlan Active = 0x%x\n",
5422 						pData[0]));
5423 
5424 					pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);
5425 				}
5426 			}
5427 			break;
5428 
5429 		default:
5430 			break;
5431 	}
5432 }
5433 
5434 #endif
5435 
5436