xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8189es/hal/btc/HalBtc8188c2Ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 //============================================================
3 // Description:
4 //
5 // This file is for 92CE/92CU BT 1 Antenna Co-exist mechanism
6 //
7 // By cosa 02/11/2011
8 //
9 //============================================================
10 
11 //============================================================
12 // include files
13 //============================================================
14 #include "Mp_Precomp.h"
15 
16 #if WPP_SOFTWARE_TRACE
17 #include "HalBtc8188c2Ant.tmh"
18 #endif
19 
20 #if(BT_30_SUPPORT == 1)
21 //============================================================
22 // Global variables, these are static variables
23 //============================================================
24 static COEX_DM_8188C_2ANT	GLCoexDm8188c2Ant;
25 static PCOEX_DM_8188C_2ANT 	pCoexDm=&GLCoexDm8188c2Ant;
26 static COEX_STA_8188C_2ANT	GLCoexSta8188c2Ant;
27 static PCOEX_STA_8188C_2ANT	pCoexSta=&GLCoexSta8188c2Ant;
28 
29 //============================================================
30 // local function start with btdm_
31 //============================================================
32 u1Byte
halbtc8188c2ant_WifiRssiState(IN PBTC_COEXIST pBtCoexist,IN u1Byte index,IN u1Byte levelNum,IN u1Byte rssiThresh,IN u1Byte rssiThresh1)33 halbtc8188c2ant_WifiRssiState(
34 	IN	PBTC_COEXIST		pBtCoexist,
35 	IN	u1Byte			index,
36 	IN	u1Byte			levelNum,
37 	IN	u1Byte			rssiThresh,
38 	IN	u1Byte			rssiThresh1
39 	)
40 {
41 	s4Byte			wifiRssi=0;
42 	u1Byte			wifiRssiState=pCoexSta->preWifiRssiState[index];
43 
44 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
45 
46 	if(levelNum == 2)
47 	{
48 		if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
49 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
50 		{
51 			if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8188C_2ANT))
52 			{
53 				wifiRssiState = BTC_RSSI_STATE_HIGH;
54 			}
55 			else
56 			{
57 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
58 			}
59 		}
60 		else
61 		{
62 			if(wifiRssi < rssiThresh)
63 			{
64 				wifiRssiState = BTC_RSSI_STATE_LOW;
65 			}
66 			else
67 			{
68 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
69 			}
70 		}
71 	}
72 	else if(levelNum == 3)
73 	{
74 		if(rssiThresh > rssiThresh1)
75 		{
76 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));
77 			return pCoexSta->preWifiRssiState[index];
78 		}
79 
80 		if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
81 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
82 		{
83 			if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8188C_2ANT))
84 			{
85 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
86 			}
87 			else
88 			{
89 				wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
90 			}
91 		}
92 		else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
93 			(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))
94 		{
95 			if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8188C_2ANT))
96 			{
97 				wifiRssiState = BTC_RSSI_STATE_HIGH;
98 			}
99 			else if(wifiRssi < rssiThresh)
100 			{
101 				wifiRssiState = BTC_RSSI_STATE_LOW;
102 			}
103 			else
104 			{
105 				wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
106 			}
107 		}
108 		else
109 		{
110 			if(wifiRssi < rssiThresh1)
111 			{
112 				wifiRssiState = BTC_RSSI_STATE_MEDIUM;
113 			}
114 			else
115 			{
116 				wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
117 			}
118 		}
119 	}
120 
121 	pCoexSta->preWifiRssiState[index] = wifiRssiState;
122 
123 	return wifiRssiState;
124 }
125 
126 u1Byte
halbtc8188c2ant_ActionAlgorithm(IN PBTC_COEXIST pBtCoexist)127 halbtc8188c2ant_ActionAlgorithm(
128 	IN	PBTC_COEXIST		pBtCoexist
129 	)
130 {
131 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
132 	u1Byte				algorithm=BT_8188C_2ANT_COEX_ALGO_UNDEFINED;
133 	u1Byte				numOfDiffProfile=0;
134 
135 	if(!pStackInfo->bBtLinkExist)
136 	{
137 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No profile exists!!!\n"));
138 		return algorithm;
139 	}
140 
141 	if(pStackInfo->bScoExist)
142 		numOfDiffProfile++;
143 	if(pStackInfo->bHidExist)
144 		numOfDiffProfile++;
145 	if(pStackInfo->bPanExist)
146 		numOfDiffProfile++;
147 	if(pStackInfo->bA2dpExist)
148 		numOfDiffProfile++;
149 
150 	if(pStackInfo->bScoExist)
151 	{
152 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO algorithm\n"));
153 		algorithm = BT_8188C_2ANT_COEX_ALGO_SCO;
154 	}
155 	else
156 	{
157 		if(numOfDiffProfile == 1)
158 		{
159 			if(pStackInfo->bHidExist)
160 			{
161 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID only\n"));
162 				algorithm = BT_8188C_2ANT_COEX_ALGO_HID;
163 			}
164 			else if(pStackInfo->bA2dpExist)
165 			{
166 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP only\n"));
167 				algorithm = BT_8188C_2ANT_COEX_ALGO_A2DP;
168 			}
169 			else if(pStackInfo->bPanExist)
170 			{
171 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN only\n"));
172 				algorithm = BT_8188C_2ANT_COEX_ALGO_PAN;
173 			}
174 		}
175 		else
176 		{
177 			if( pStackInfo->bHidExist &&
178 				pStackInfo->bA2dpExist )
179 			{
180 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP\n"));
181 				algorithm = BT_8188C_2ANT_COEX_ALGO_HID_A2DP;
182 			}
183 			else if( pStackInfo->bHidExist &&
184 				pStackInfo->bPanExist )
185 			{
186 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN\n"));
187 				algorithm = BT_8188C_2ANT_COEX_ALGO_HID_PAN;
188 			}
189 			else if( pStackInfo->bPanExist &&
190 				pStackInfo->bA2dpExist )
191 			{
192 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN + A2DP\n"));
193 				algorithm = BT_8188C_2ANT_COEX_ALGO_PAN_A2DP;
194 			}
195 		}
196 	}
197 	return algorithm;
198 }
199 
200 VOID
halbtc8188c2ant_SetFwBalance(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bBalanceOn,IN u1Byte ms0,IN u1Byte ms1)201 halbtc8188c2ant_SetFwBalance(
202 	IN	PBTC_COEXIST		pBtCoexist,
203 	IN	BOOLEAN			bBalanceOn,
204 	IN	u1Byte			ms0,
205 	IN	u1Byte			ms1
206 	)
207 {
208 	u1Byte	H2C_Parameter[3] ={0};
209 
210 	if(bBalanceOn)
211 	{
212 		H2C_Parameter[2] = 1;
213 		H2C_Parameter[1] = ms1;
214 		H2C_Parameter[0] = ms0;
215 	}
216 	else
217 	{
218 		H2C_Parameter[2] = 0;
219 		H2C_Parameter[1] = 0;
220 		H2C_Parameter[0] = 0;
221 	}
222 
223 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Balance=[%s:%dms:%dms], write 0xc=0x%x\n",
224 		bBalanceOn?"ON":"OFF", ms0, ms1,
225 		H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
226 
227 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0xc, 3, H2C_Parameter);
228 }
229 
230 VOID
halbtc8188c2ant_Balance(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bBalanceOn,IN u1Byte ms0,IN u1Byte ms1)231 halbtc8188c2ant_Balance(
232 	IN	PBTC_COEXIST		pBtCoexist,
233 	IN	BOOLEAN			bForceExec,
234 	IN	BOOLEAN			bBalanceOn,
235 	IN	u1Byte			ms0,
236 	IN	u1Byte			ms1
237 	)
238 {
239 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Balance %s\n",
240 		(bForceExec? "force to":""), (bBalanceOn? "ON":"OFF")));
241 	pCoexDm->bCurBalanceOn = bBalanceOn;
242 
243 	if(!bForceExec)
244 	{
245 		if(pCoexDm->bPreBalanceOn == pCoexDm->bCurBalanceOn)
246 			return;
247 	}
248 	halbtc8188c2ant_SetFwBalance(pBtCoexist, bBalanceOn, ms0, ms1);
249 
250 	pCoexDm->bPreBalanceOn = pCoexDm->bCurBalanceOn;
251 }
252 
253 VOID
halbtc8188c2ant_SetFwDiminishWifi(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bDacOn,IN BOOLEAN bInterruptOn,IN u1Byte fwDacSwingLvl,IN BOOLEAN bNavOn)254 halbtc8188c2ant_SetFwDiminishWifi(
255 	IN	PBTC_COEXIST		pBtCoexist,
256 	IN	BOOLEAN 		bDacOn,
257 	IN	BOOLEAN 		bInterruptOn,
258 	IN	u1Byte			fwDacSwingLvl,
259 	IN	BOOLEAN 		bNavOn
260 	)
261 {
262 	u1Byte			H2C_Parameter[3] ={0};
263 
264 	if((pBtCoexist->stackInfo.minBtRssi <= -5) && (fwDacSwingLvl == 0x20))
265 	{
266 		RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
267 		fwDacSwingLvl = 0x18;
268 	}
269 
270 	H2C_Parameter[2] = 0;
271 	H2C_Parameter[1] = fwDacSwingLvl;
272 	H2C_Parameter[0] = 0;
273 	if(bDacOn)
274 	{
275 		H2C_Parameter[2] |= 0x01;	//BIT0
276 		if(bInterruptOn)
277 		{
278 			H2C_Parameter[2] |= 0x02;	//BIT1
279 		}
280 	}
281 	if(bNavOn)
282 	{
283 		H2C_Parameter[2] |= 0x08;	//BIT3
284 	}
285 
286 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], bDacOn=%s, bInterruptOn=%s, bNavOn=%s, write 0xe=0x%x\n",
287 		(bDacOn?"ON":"OFF"), (bInterruptOn?"ON":"OFF"), (bNavOn?"ON":"OFF"),
288 		(H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2])));
289 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0xe, 3, H2C_Parameter);
290 }
291 
292 VOID
halbtc8188c2ant_DiminishWifi(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bDacOn,IN BOOLEAN bInterruptOn,IN u1Byte fwDacSwingLvl,IN BOOLEAN bNavOn)293 halbtc8188c2ant_DiminishWifi(
294 	IN	PBTC_COEXIST		pBtCoexist,
295 	IN	BOOLEAN			bForceExec,
296 	IN	BOOLEAN			bDacOn,
297 	IN	BOOLEAN			bInterruptOn,
298 	IN	u1Byte			fwDacSwingLvl,
299 	IN	BOOLEAN			bNavOn
300 	)
301 {
302 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set Diminish Wifi, bDacOn=%s, bInterruptOn=%s, fwDacSwingLvl=%d, bNavOn=%s\n",
303 		(bForceExec? "force to":""), (bDacOn? "ON":"OFF"), (bInterruptOn? "ON":"OFF"), fwDacSwingLvl, (bNavOn? "ON":"OFF")));
304 
305 	pCoexDm->bCurDacOn = bDacOn;
306 	pCoexDm->bCurInterruptOn = bInterruptOn;
307 	pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;
308 	pCoexDm->bCurNavOn = bNavOn;
309 
310 	if(!bForceExec)
311 	{
312 		if( (pCoexDm->bPreDacOn==pCoexDm->bCurDacOn) &&
313 			(pCoexDm->bPreInterruptOn==pCoexDm->bCurInterruptOn) &&
314 			(pCoexDm->preFwDacSwingLvl==pCoexDm->curFwDacSwingLvl) &&
315 			(pCoexDm->bPreNavOn==pCoexDm->bCurNavOn) )
316 			return;
317 	}
318 	halbtc8188c2ant_SetFwDiminishWifi(pBtCoexist, bDacOn, bInterruptOn, fwDacSwingLvl, bNavOn);
319 
320 	pCoexDm->bPreDacOn = pCoexDm->bCurDacOn;
321 	pCoexDm->bPreInterruptOn = pCoexDm->bCurInterruptOn;
322 	pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;
323 	pCoexDm->bPreNavOn = pCoexDm->bCurNavOn;
324 }
325 
326 VOID
halbtc8188c2ant_SetSwRfRxLpfCorner(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bRxRfShrinkOn)327 halbtc8188c2ant_SetSwRfRxLpfCorner(
328 	IN	PBTC_COEXIST		pBtCoexist,
329 	IN	BOOLEAN			bRxRfShrinkOn
330 	)
331 {
332 	if(bRxRfShrinkOn)
333 	{
334 		//Shrink RF Rx LPF corner
335 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));
336 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xf0, 0xf);
337 	}
338 	else
339 	{
340 		//Resume RF Rx LPF corner
341 		// After initialized, we can use pCoexDm->btRf0x1eBackup
342 		if(pBtCoexist->bInitilized)
343 		{
344 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
345 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xf0, pCoexDm->btRf0x1eBackup);
346 		}
347 	}
348 }
349 
350 VOID
halbtc8188c2ant_RfShrink(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRxRfShrinkOn)351 halbtc8188c2ant_RfShrink(
352 	IN	PBTC_COEXIST		pBtCoexist,
353 	IN	BOOLEAN			bForceExec,
354 	IN	BOOLEAN			bRxRfShrinkOn
355 	)
356 {
357 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",
358 		(bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));
359 	pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
360 
361 	if(!bForceExec)
362 	{
363 		if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
364 			return;
365 	}
366 	halbtc8188c2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
367 
368 	pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
369 }
370 
371 VOID
halbtc8188c2ant_SetSwPenaltyTxRateAdaptive(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bLowPenaltyRa)372 halbtc8188c2ant_SetSwPenaltyTxRateAdaptive(
373 	IN	PBTC_COEXIST		pBtCoexist,
374 	IN	BOOLEAN			bLowPenaltyRa
375 	)
376 {
377 	u1Byte	tmpU1;
378 
379 	tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);
380 	if(bLowPenaltyRa)
381 	{
382 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));
383 		tmpU1 &= ~BIT2;
384 	}
385 	else
386 	{
387 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set normal!!\n"));
388 		tmpU1 |= BIT2;
389 	}
390 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);
391 }
392 
393 VOID
halbtc8188c2ant_LowPenaltyRa(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bLowPenaltyRa)394 halbtc8188c2ant_LowPenaltyRa(
395 	IN	PBTC_COEXIST		pBtCoexist,
396 	IN	BOOLEAN			bForceExec,
397 	IN	BOOLEAN			bLowPenaltyRa
398 	)
399 {
400 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",
401 		(bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));
402 	pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
403 
404 	if(!bForceExec)
405 	{
406 		if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
407 			return;
408 	}
409 	halbtc8188c2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
410 
411 	pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
412 }
413 
414 VOID
halbtc8188c2ant_SetSwFullTimeDacSwing(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bSwDacSwingOn,IN u4Byte swDacSwingLvl)415 halbtc8188c2ant_SetSwFullTimeDacSwing(
416 	IN	PBTC_COEXIST		pBtCoexist,
417 	IN	BOOLEAN			bSwDacSwingOn,
418 	IN	u4Byte			swDacSwingLvl
419 	)
420 {
421 	u4Byte	dacSwingLvl;
422 
423 	if(bSwDacSwingOn)
424 	{
425 		if((pBtCoexist->stackInfo.minBtRssi <= -5) && (swDacSwingLvl == 0x20))
426 		{
427 			dacSwingLvl = 0x18;
428 		}
429 		else
430 		{
431 			dacSwingLvl = swDacSwingLvl;
432 		}
433 		pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xfc000000, dacSwingLvl);
434 	}
435 	else
436 	{
437 		pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xfc000000, 0x30);
438 	}
439 }
440 
441 VOID
halbtc8188c2ant_DacSwing(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bDacSwingOn,IN u4Byte dacSwingLvl)442 halbtc8188c2ant_DacSwing(
443 	IN	PBTC_COEXIST		pBtCoexist,
444 	IN	BOOLEAN			bForceExec,
445 	IN	BOOLEAN			bDacSwingOn,
446 	IN	u4Byte			dacSwingLvl
447 	)
448 {
449 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",
450 		(bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));
451 	pCoexDm->bCurDacSwingOn = bDacSwingOn;
452 	pCoexDm->curDacSwingLvl = dacSwingLvl;
453 
454 	if(!bForceExec)
455 	{
456 		if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&
457 			(pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )
458 			return;
459 	}
460 	delay_ms(30);
461 	halbtc8188c2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);
462 
463 	pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;
464 	pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;
465 }
466 
467 VOID
halbtc8188c2ant_SetAdcBackOff(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAdcBackOff)468 halbtc8188c2ant_SetAdcBackOff(
469 	IN	PBTC_COEXIST		pBtCoexist,
470 	IN	BOOLEAN			bAdcBackOff
471 	)
472 {
473 	if(bAdcBackOff)
474 	{
475 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level On!\n"));
476 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a07611);
477 	}
478 	else
479 	{
480 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level Off!\n"));
481 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a05611);
482 	}
483 }
484 
485 VOID
halbtc8188c2ant_AdcBackOff(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bAdcBackOff)486 halbtc8188c2ant_AdcBackOff(
487 	IN	PBTC_COEXIST		pBtCoexist,
488 	IN	BOOLEAN			bForceExec,
489 	IN	BOOLEAN			bAdcBackOff
490 	)
491 {
492 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn AdcBackOff = %s\n",
493 		(bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));
494 	pCoexDm->bCurAdcBackOff = bAdcBackOff;
495 
496 	if(!bForceExec)
497 	{
498 		if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff)
499 			return;
500 	}
501 	halbtc8188c2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);
502 
503 	pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;
504 }
505 
506 VOID
halbtc8188c2ant_SetAgcTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAgcTableEn)507 halbtc8188c2ant_SetAgcTable(
508 	IN	PBTC_COEXIST		pBtCoexist,
509 	IN	BOOLEAN			bAgcTableEn
510 	)
511 {
512 	u1Byte		rssiAdjustVal=0;
513 
514 	if(bAgcTableEn)
515 	{
516 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));
517 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4e1c0001);
518 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4d1d0001);
519 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4c1e0001);
520 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4b1f0001);
521 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4a200001);
522 
523 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xdc000);
524 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x90000);
525 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x51000);
526 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x12000);
527 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x00255);
528 	}
529 	else
530 	{
531 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));
532 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x641c0001);
533 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x631d0001);
534 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x621e0001);
535 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x611f0001);
536 		pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x60200001);
537 
538 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x32000);
539 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x71000);
540 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xb0000);
541 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xfc000);
542 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x10255);
543 	}
544 
545 	// set rssiAdjustVal for wifi module.
546 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);
547 }
548 
549 
550 VOID
halbtc8188c2ant_AgcTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bAgcTableEn)551 halbtc8188c2ant_AgcTable(
552 	IN	PBTC_COEXIST		pBtCoexist,
553 	IN	BOOLEAN			bForceExec,
554 	IN	BOOLEAN			bAgcTableEn
555 	)
556 {
557 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s %s Agc Table\n",
558 		(bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));
559 	pCoexDm->bCurAgcTableEn = bAgcTableEn;
560 
561 	if(!bForceExec)
562 	{
563 		if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn)
564 			return;
565 	}
566 	halbtc8188c2ant_SetAgcTable(pBtCoexist, bAgcTableEn);
567 
568 	pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;
569 }
570 
571 VOID
halbtc8188c2ant_SetCoexTable(IN PBTC_COEXIST pBtCoexist,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u4Byte val0x6cc)572 halbtc8188c2ant_SetCoexTable(
573 	IN	PBTC_COEXIST	pBtCoexist,
574 	IN	u4Byte		val0x6c4,
575 	IN	u4Byte		val0x6c8,
576 	IN	u4Byte		val0x6cc
577 	)
578 {
579 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
580 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
581 
582 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
583 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
584 
585 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
586 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6cc, val0x6cc);
587 }
588 
589 VOID
halbtc8188c2ant_CoexTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u4Byte val0x6cc)590 halbtc8188c2ant_CoexTable(
591 	IN	PBTC_COEXIST		pBtCoexist,
592 	IN	BOOLEAN			bForceExec,
593 	IN	u4Byte			val0x6c4,
594 	IN	u4Byte			val0x6c8,
595 	IN	u4Byte			val0x6cc
596 	)
597 {
598 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
599 		(bForceExec? "force to":""), val0x6c4, val0x6c8, val0x6cc));
600 	pCoexDm->curVal0x6c4 = val0x6c4;
601 	pCoexDm->curVal0x6c8 = val0x6c8;
602 	pCoexDm->curVal0x6cc = val0x6cc;
603 
604 	if(!bForceExec)
605 	{
606 		if( (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
607 			(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
608 			(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
609 			return;
610 	}
611 	halbtc8188c2ant_SetCoexTable(pBtCoexist, val0x6c4, val0x6c8, val0x6cc);
612 
613 	pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
614 	pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
615 	pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
616 }
617 
618 VOID
halbtc8188c2ant_CoexAllOff(IN PBTC_COEXIST pBtCoexist)619 halbtc8188c2ant_CoexAllOff(
620 	IN	PBTC_COEXIST		pBtCoexist
621 	)
622 {
623 	// fw mechanism
624 	halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
625 	halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
626 
627 	// sw mechanism
628 	halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
629 	halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
630 	halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
631 }
632 VOID
halbtc8188c2ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)633 halbtc8188c2ant_InitCoexDm(
634 	IN	PBTC_COEXIST		pBtCoexist
635 	)
636 {
637 }
638 
639 
640 VOID
halbtc8188c2ant_MonitorBtState(IN PBTC_COEXIST pBtCoexist)641 halbtc8188c2ant_MonitorBtState(
642 	IN	PBTC_COEXIST			pBtCoexist
643 	)
644 {
645 	BOOLEAN			stateChange=FALSE;
646 	u4Byte 			BT_Polling, Ratio_Act, Ratio_STA;
647 	u4Byte 			BT_Active, BT_State;
648 	u4Byte			regBTActive=0, regBTState=0, regBTPolling=0;
649 	u4Byte			btBusyThresh=0;
650 	u4Byte			fwVer=0;
651 	static BOOLEAN	bBtBusyTraffic=FALSE;
652 	BOOLEAN			bRejApAggPkt=FALSE;
653 
654 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
655 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FirmwareVersion = 0x%x(%d)\n", fwVer, fwVer));
656 	if(fwVer < 62)
657 	{
658 		regBTActive = 0x488;
659 		regBTState = 0x48c;
660 		regBTPolling = 0x490;
661 	}
662 	else
663 	{
664 		regBTActive = 0x444;
665 		regBTState = 0x448;
666 		if(fwVer >= 74)
667 			regBTPolling = 0x44c;
668 		else
669 			regBTPolling = 0x700;
670 	}
671 	btBusyThresh = 60;
672 
673 	BT_Active = pBtCoexist->fBtcRead4Byte(pBtCoexist, regBTActive);
674 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT_Active(0x%x)=0x%x\n", regBTActive, BT_Active));
675 	BT_Active = BT_Active & 0x00ffffff;
676 
677 	BT_State = pBtCoexist->fBtcRead4Byte(pBtCoexist, regBTState);
678 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT_State(0x%x)=0x%x\n", regBTState, BT_State));
679 	BT_State = BT_State & 0x00ffffff;
680 
681 	BT_Polling = pBtCoexist->fBtcRead4Byte(pBtCoexist, regBTPolling);
682 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT_Polling(0x%x)=0x%x\n", regBTPolling, BT_Polling));
683 
684 	if(BT_Active==0xffffffff && BT_State==0xffffffff && BT_Polling==0xffffffff )
685 		return;
686 
687 	// 2011/05/04 MH For Slim combo test meet a problem. Surprise remove and WLAN is running
688 	// DHCP process. At the same time, the register read value might be zero. And cause BSOD 0x7f
689 	// EXCEPTION_DIVIDED_BY_ZERO. In This case, the stack content may always be wrong due to
690 	// HW divide trap.
691 	if (BT_Polling==0)
692 		return;
693 
694 	Ratio_Act = BT_Active*1000/BT_Polling;
695 	Ratio_STA = BT_State*1000/BT_Polling;
696 
697 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ratio_Act=%d\n", Ratio_Act));
698 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ratio_STA=%d\n", Ratio_STA));
699 
700 	if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
701 	{
702 		if(Ratio_STA < 60)	// BT PAN idle
703 		{
704 		}
705 		else
706 		{
707 			// Check if BT PAN (under BT 2.1) is uplink or downlink
708 			if((Ratio_Act/Ratio_STA) < 2)
709 			{	// BT PAN Uplink
710 				pCoexSta->bBtUplink = TRUE;
711 			}
712 			else
713 			{	// BT PAN downlink
714 				pCoexSta->bBtUplink = FALSE;
715 			}
716 		}
717 	}
718 
719 	// Check BT is idle or not
720 	if(!pBtCoexist->stackInfo.bBtLinkExist)
721 	{
722 		pCoexSta->bBtBusy = FALSE;
723 	}
724 	else
725 	{
726 		if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
727 		{
728 			if(Ratio_Act<20)
729 			{
730 				pCoexSta->bBtBusy = FALSE;
731 			}
732 			else
733 			{
734 				pCoexSta->bBtBusy = TRUE;
735 			}
736 		}
737 		else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
738 		{
739 			if(Ratio_STA < btBusyThresh)
740 			{
741 				pCoexSta->bBtBusy = FALSE;
742 			}
743 			else
744 			{
745 				pCoexSta->bBtBusy = TRUE;
746 			}
747 
748 			if( (Ratio_STA < btBusyThresh) ||
749 				(Ratio_Act<180 && Ratio_STA<130) )
750 			{
751 				pCoexSta->bA2dpBusy = FALSE;
752 			}
753 			else
754 			{
755 				pCoexSta->bA2dpBusy = TRUE;
756 			}
757 		}
758 	}
759 
760 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &pCoexSta->bBtBusy);
761 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &pCoexSta->bBtBusy);
762 
763 	if(bBtBusyTraffic != pCoexSta->bBtBusy)
764 	{	// BT idle or BT non-idle
765 		bBtBusyTraffic = pCoexSta->bBtBusy;
766 		stateChange = TRUE;
767 	}
768 
769 	if(stateChange)
770 	{
771 		if(!pCoexSta->bBtBusy)
772 		{
773 			halbtc8188c2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);
774 			halbtc8188c2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);
775 			halbtc8188c2ant_CoexAllOff(pBtCoexist);
776 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
777 		}
778 		else
779 		{
780 			halbtc8188c2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);
781 			halbtc8188c2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);
782 		}
783 	}
784 
785 	if(stateChange)
786 	{
787 		bRejApAggPkt = pCoexSta->bBtBusy;
788 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejApAggPkt);
789 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
790 	}
791 }
792 
793 VOID
halbtc8188c2ant_ActionA2dpBc4(IN PBTC_COEXIST pBtCoexist)794 halbtc8188c2ant_ActionA2dpBc4(
795 	IN	PBTC_COEXIST		pBtCoexist
796 	)
797 {
798 	u1Byte			wifiRssiState;
799 	u4Byte			wifiBw, wifiTrafficDir;
800 
801 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
802 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
803 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
804 
805 	if(pCoexSta->bBtBusy)
806 	{
807 		if(BTC_WIFI_BW_HT40 == wifiBw)
808 		{
809 			// fw mechanism first
810 			if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
811 			{
812 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0xc, 0x18);
813 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);
814 			}
815 			else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
816 			{
817 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
818 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
819 			}
820 
821 			// sw mechanism
822 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
823 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
824 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
825 		}
826 		else
827 		{
828 			wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);
829 
830 			if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
831 			{
832 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0xc, 0x18);
833 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);
834 			}
835 			else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
836 			{
837 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
838 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
839 			}
840 
841 			// sw mechanism
842 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
843 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
844 			{
845 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
846 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
847 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
848 			}
849 			else
850 			{
851 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
852 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
853 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
854 			}
855 		}
856 	}
857 	else
858 	{
859 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
860 	}
861 }
862 
863 VOID
halbtc8188c2ant_ActionA2dpBc8(IN PBTC_COEXIST pBtCoexist)864 halbtc8188c2ant_ActionA2dpBc8(
865 	IN	PBTC_COEXIST		pBtCoexist
866 	)
867 {
868 	u1Byte			wifiRssiState;
869 	u4Byte			wifiBw, wifiTrafficDir;
870 	BOOLEAN			bWifiBusy=FALSE;
871 
872 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
873 	if(pCoexSta->bA2dpBusy && bWifiBusy)
874 	{
875 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
876 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
877 		wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);
878 
879 		// fw mechanism first
880 		if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
881 		{
882 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0xc, 0x18);
883 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
884 		}
885 		else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
886 		{
887 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x10, 0x18);
888 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
889 		}
890 
891 		// sw mechanism
892 		if(BTC_WIFI_BW_HT40 == wifiBw)
893 		{
894 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
895 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
896 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
897 		}
898 		else
899 		{
900 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
901 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
902 			{
903 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
904 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
905 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
906 			}
907 			else
908 			{
909 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
910 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
911 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
912 			}
913 		}
914 	}
915 	else if(pCoexSta->bA2dpBusy)
916 	{
917 		// fw mechanism first
918 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
919 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, TRUE, 0x18, FALSE);
920 
921 		// sw mechanism
922 		halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
923 		halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
924 		halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
925 	}
926 	else
927 	{
928 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
929 	}
930 }
931 
932 VOID
halbtc8188c2ant_ActionA2dp(IN PBTC_COEXIST pBtCoexist)933 halbtc8188c2ant_ActionA2dp(
934 	IN	PBTC_COEXIST		pBtCoexist
935 	)
936 {
937 	if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
938 	{
939 		halbtc8188c2ant_ActionA2dpBc4(pBtCoexist);
940 	}
941 	else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
942 	{
943 		halbtc8188c2ant_ActionA2dpBc8(pBtCoexist);
944 	}
945 }
946 
947 VOID
halbtc8188c2ant_ActionPanBc4(IN PBTC_COEXIST pBtCoexist)948 halbtc8188c2ant_ActionPanBc4(
949 	IN	PBTC_COEXIST		pBtCoexist
950 	)
951 {
952 	BOOLEAN		bBtHsOn=FALSE, bWifiBusy=FALSE;
953 
954 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
955 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
956 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
957 	if(bBtHsOn)
958 	{
959 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
960 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
961 	}
962 	else
963 	{
964 		if(pCoexSta->bBtBusy && bWifiBusy)
965 		{
966 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x10);
967 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
968 		}
969 		else
970 		{
971 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
972 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
973 		}
974 	}
975 	// sw mechanism
976 	halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
977 	halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
978 	halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
979 }
980 
981 VOID
halbtc8188c2ant_ActionPanBc8(IN PBTC_COEXIST pBtCoexist)982 halbtc8188c2ant_ActionPanBc8(
983 	IN	PBTC_COEXIST		pBtCoexist
984 	)
985 {
986 	BOOLEAN		bBtHsOn=FALSE, bWifiBusy=FALSE;
987 	u1Byte		wifiRssiState;
988 	u4Byte		wifiBw, wifiTrafficDir;
989 	s4Byte		wifiRssi;
990 
991 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
992 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
993 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
994 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
995 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
996 
997 	if(bBtHsOn)
998 	{
999 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
1000 	}
1001 	else
1002 	{
1003 		wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 3, 25, 50);
1004 
1005 		if(pCoexSta->bBtBusy && bWifiBusy)
1006 		{
1007 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
1008 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
1009 			{
1010 				// fw mechanism first
1011 				if(pCoexSta->bBtUplink)
1012 				{
1013 					halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x20);
1014 					halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1015 				}
1016 				else
1017 				{
1018 					halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1019 					halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1020 				}
1021 				// sw mechanism
1022 				if(BTC_WIFI_BW_HT40 == wifiBw)
1023 				{
1024 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1025 				}
1026 				else
1027 				{
1028 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1029 				}
1030 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1031 				if(pCoexSta->bBtUplink)
1032 				{
1033 					halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1034 				}
1035 				else
1036 				{
1037 					halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
1038 				}
1039 			}
1040 			else if( (wifiRssiState == BTC_RSSI_STATE_MEDIUM) ||
1041 				(wifiRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )
1042 			{
1043 				// fw mechanism first
1044 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x20);
1045 
1046 				if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1047 				{
1048 					halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1049 				}
1050 				else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1051 				{
1052 					if(BTC_WIFI_BW_HT40 == wifiBw)
1053 						halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);//BT_FW_NAV_ON);
1054 					else
1055 						halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1056 				}
1057 				// sw mechanism
1058 				if(BTC_WIFI_BW_HT40 == wifiBw)
1059 				{
1060 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1061 				}
1062 				else
1063 				{
1064 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1065 				}
1066 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1067 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1068 			}
1069 			else
1070 			{
1071 				// fw mechanism first
1072 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x20);
1073 
1074 				if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1075 				{
1076 					halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1077 				}
1078 				else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1079 				{
1080 					if(pCoexSta->bBtUplink)
1081 					{
1082 						if(BTC_WIFI_BW_HT40 == wifiBw)
1083 						{
1084 							halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);//BT_FW_NAV_ON);
1085 						}
1086 						else
1087 						{
1088 							halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1089 						}
1090 					}
1091 					else
1092 					{
1093 						halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1094 					}
1095 				}
1096 				// sw mechanism
1097 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1098 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1099 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1100 			}
1101 		}
1102 		else if(pCoexSta->bBtBusy && !bWifiBusy && (wifiRssi < 30))
1103 		{
1104 			// fw mechanism first
1105 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x0a, 0x20);
1106 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1107 			// sw mechanism
1108 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1109 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1110 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1111 		}
1112 		else
1113 		{
1114 			halbtc8188c2ant_CoexAllOff(pBtCoexist);
1115 		}
1116 	}
1117 }
1118 
1119 VOID
halbtc8188c2ant_ActionPan(IN PBTC_COEXIST pBtCoexist)1120 halbtc8188c2ant_ActionPan(
1121 	IN	PBTC_COEXIST		pBtCoexist
1122 	)
1123 {
1124 	if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
1125 	{
1126 		halbtc8188c2ant_ActionPanBc4(pBtCoexist);
1127 	}
1128 	else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
1129 	{
1130 		halbtc8188c2ant_ActionPanBc8(pBtCoexist);
1131 	}
1132 }
1133 
1134 VOID
halbtc8188c2ant_ActionHid(IN PBTC_COEXIST pBtCoexist)1135 halbtc8188c2ant_ActionHid(
1136 	IN	PBTC_COEXIST		pBtCoexist
1137 	)
1138 {
1139 	u4Byte		wifiBw, wifiTrafficDir;
1140 	BOOLEAN 	bWifiBusy=FALSE;
1141 
1142 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1143 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1144 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1145 	if(BTC_WIFI_BW_LEGACY == wifiBw)
1146 	{
1147 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1148 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1149 
1150 		halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);
1151 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);
1152 	}
1153 	else if(!bWifiBusy)
1154 	{
1155 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
1156 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1157 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1158 	}
1159 	else if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1160 	{
1161 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1162 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1163 
1164 		halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);
1165 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);
1166 	}
1167 	else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1168 	{
1169 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
1170 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1171 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1172 	}
1173 	// sw mechanism
1174 	halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1175 	halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1176 	halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1177 }
1178 
1179 
1180 VOID
halbtc8188c2ant_ActionSco(IN PBTC_COEXIST pBtCoexist)1181 halbtc8188c2ant_ActionSco(
1182 	IN	PBTC_COEXIST		pBtCoexist
1183 	)
1184 {
1185 	u1Byte	wifiRssiState;
1186 	u4Byte	wifiBw;
1187 
1188 	if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
1189 	{
1190 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
1191 
1192 		// fw mechanism
1193 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1194 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1195 
1196 		// sw mechanism
1197 		halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1198 		halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1199 		halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1200 	}
1201 	else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
1202 	{
1203 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1204 		if(BTC_WIFI_BW_HT40 == wifiBw)
1205 		{
1206 			// fw mechanism first
1207 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1208 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1209 
1210 			// sw mechanism
1211 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1212 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1213 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1214 		}
1215 		else
1216 		{
1217 			wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);
1218 			// fw mechanism first
1219 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1220 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1221 
1222 			// sw mechanism
1223 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
1224 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
1225 			{
1226 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1227 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1228 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1229 			}
1230 			else
1231 			{
1232 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1233 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1234 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1235 			}
1236 		}
1237 	}
1238 }
1239 
1240 VOID
halbtc8188c2ant_ActionHidA2dpBc4(IN PBTC_COEXIST pBtCoexist)1241 halbtc8188c2ant_ActionHidA2dpBc4(
1242 	IN	PBTC_COEXIST		pBtCoexist
1243 	)
1244 {
1245 	u1Byte		wifiRssiState;
1246 	u4Byte		wifiBw, wifiTrafficDir;
1247 
1248 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1249 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1250 
1251 	if(pCoexSta->bBtBusy)
1252 	{
1253 		if(BTC_WIFI_BW_HT40 == wifiBw)
1254 		{
1255 			// fw mechanism first
1256 			if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1257 			{
1258 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x7, 0x20);
1259 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);
1260 			}
1261 			else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1262 			{
1263 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1264 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1265 			}
1266 
1267 			// sw mechanism
1268 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1269 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1270 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1271 		}
1272 		else
1273 		{
1274 			wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);
1275 			// fw mechanism first
1276 			if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1277 			{
1278 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x7, 0x20);
1279 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);
1280 			}
1281 			else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1282 			{
1283 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1284 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1285 			}
1286 
1287 			// sw mechanism
1288 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
1289 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
1290 			{
1291 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1292 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1293 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1294 			}
1295 			else
1296 			{
1297 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1298 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1299 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1300 			}
1301 		}
1302 	}
1303 	else
1304 	{
1305 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
1306 	}
1307 }
1308 VOID
halbtc8188c2ant_ActionHidA2dpBc8(IN PBTC_COEXIST pBtCoexist)1309 halbtc8188c2ant_ActionHidA2dpBc8(
1310 	IN	PBTC_COEXIST		pBtCoexist
1311 	)
1312 {
1313 	u1Byte		wifiRssiState;
1314 	u4Byte		wifiBw;
1315 
1316 	if(pCoexSta->bBtBusy)
1317 	{
1318 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1319 		if(BTC_WIFI_BW_HT40 == wifiBw)
1320 		{
1321 			// fw mechanism first
1322 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1323 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1324 
1325 			// sw mechanism
1326 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1327 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1328 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1329 		}
1330 		else
1331 		{
1332 			wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);
1333 			// fw mechanism
1334 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1335 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1336 
1337 			// sw mechanism
1338 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
1339 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
1340 			{
1341 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1342 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1343 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1344 			}
1345 			else
1346 			{
1347 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1348 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1349 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1350 			}
1351 		}
1352 	}
1353 	else
1354 	{
1355 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
1356 	}
1357 }
1358 
1359 VOID
halbtc8188c2ant_ActionHidA2dp(IN PBTC_COEXIST pBtCoexist)1360 halbtc8188c2ant_ActionHidA2dp(
1361 	IN	PBTC_COEXIST		pBtCoexist
1362 	)
1363 {
1364 	if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
1365 	{
1366 		halbtc8188c2ant_ActionHidA2dpBc4(pBtCoexist);
1367 	}
1368 	else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
1369 	{
1370 		halbtc8188c2ant_ActionHidA2dpBc8(pBtCoexist);
1371 	}
1372 }
1373 
1374 VOID
halbtc8188c2ant_ActionHidPanBc4(IN PBTC_COEXIST pBtCoexist)1375 halbtc8188c2ant_ActionHidPanBc4(
1376 	IN	PBTC_COEXIST		pBtCoexist
1377 	)
1378 {
1379 	BOOLEAN		bBtHsOn=FALSE, bWifiBusy=FALSE;
1380 	u4Byte		wifiBw, wifiTrafficDir;
1381 
1382 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1383 
1384 	if(bBtHsOn)
1385 	{
1386 		halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1387 		halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1388 
1389 		halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);
1390 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);
1391 	}
1392 	else
1393 	{
1394 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1395 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1396 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1397 		if(BTC_WIFI_BW_LEGACY == wifiBw)
1398 		{
1399 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1400 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1401 
1402 			halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);
1403 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);
1404 		}
1405 		else if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1406 		{
1407 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1408 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1409 
1410 			halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);
1411 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);
1412 		}
1413 		else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1414 		{
1415 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
1416 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x10);
1417 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1418 		}
1419 		else if(!bWifiBusy)
1420 		{
1421 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
1422 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1423 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1424 		}
1425 	}
1426 	halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1427 	halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1428 	halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1429 }
1430 VOID
halbtc8188c2ant_ActionHidPanBc8(IN PBTC_COEXIST pBtCoexist)1431 halbtc8188c2ant_ActionHidPanBc8(
1432 	IN	PBTC_COEXIST		pBtCoexist
1433 	)
1434 {
1435 	BOOLEAN		bBtHsOn=FALSE, bWifiBusy=FALSE;
1436 	u1Byte		wifiRssiState;
1437 	u4Byte		wifiBw, wifiTrafficDir;
1438 
1439 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1440 
1441 	if(!bBtHsOn)
1442 	{
1443 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1444 		wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 25, 0);
1445 		if((pCoexSta->bBtBusy && bWifiBusy))
1446 		{
1447 			// fw mechanism first
1448 			if(pCoexSta->bBtUplink)
1449 			{
1450 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x15, 0x20);
1451 			}
1452 			else
1453 			{
1454 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x10, 0x20);
1455 			}
1456 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1457 
1458 			// sw mechanism
1459 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
1460 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
1461 			{
1462 				pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1463 				if(BTC_WIFI_BW_HT40 == wifiBw)
1464 				{
1465 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1466 					halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1467 					halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1468 				}
1469 				else
1470 				{
1471 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1472 					halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1473 					halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1474 				}
1475 			}
1476 			else
1477 			{
1478 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1479 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1480 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1481 			}
1482 		}
1483 		else
1484 		{
1485 			halbtc8188c2ant_CoexAllOff(pBtCoexist);
1486 		}
1487 	}
1488 	else
1489 	{
1490 		if(BTC_INTF_USB == pBtCoexist->chipInterface)
1491 		{
1492 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1493 			if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)
1494 			{
1495 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1496 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1497 
1498 				halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);
1499 				pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);
1500 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1501 			}
1502 			else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)
1503 			{
1504 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);
1505 			}
1506 		}
1507 		else
1508 		{
1509 			if(pCoexSta->bBtBusy)
1510 			{
1511 				// fw mechanism
1512 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1513 				halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1514 
1515 				// sw mechanism
1516 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1517 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1518 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
1519 			}
1520 			else
1521 			{
1522 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1523 			}
1524 		}
1525 	}
1526 }
1527 
1528 VOID
halbtc8188c2ant_ActionHidPan(IN PBTC_COEXIST pBtCoexist)1529 halbtc8188c2ant_ActionHidPan(
1530 	IN	PBTC_COEXIST		pBtCoexist
1531 	)
1532 {
1533 	if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
1534 	{
1535 		halbtc8188c2ant_ActionHidPanBc4(pBtCoexist);
1536 	}
1537 	else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
1538 	{
1539 		halbtc8188c2ant_ActionHidPanBc8(pBtCoexist);
1540 	}
1541 }
1542 
1543 VOID
halbtc8188c2ant_ActionPanA2dpBc4(IN PBTC_COEXIST pBtCoexist)1544 halbtc8188c2ant_ActionPanA2dpBc4(
1545 	IN	PBTC_COEXIST		pBtCoexist
1546 	)
1547 {
1548 	BOOLEAN		bBtHsOn=FALSE, bWifiBusy=FALSE;
1549 	u1Byte		wifiRssiState;
1550 
1551 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1552 
1553 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);
1554 	if(bBtHsOn)
1555 	{
1556 		if(pCoexSta->bBtBusy)
1557 		{
1558 			// fw mechanism
1559 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1560 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1561 
1562 			// sw mechanism
1563 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1564 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1565 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
1566 		}
1567 		else
1568 		{
1569 			halbtc8188c2ant_CoexAllOff(pBtCoexist);
1570 		}
1571 	}
1572 	else
1573 	{
1574 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1575 		if(pCoexSta->bBtBusy && bWifiBusy)
1576 		{
1577 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x10);
1578 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1579 		}
1580 		else
1581 		{
1582 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1583 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);
1584 		}
1585 		// sw mechanism
1586 		halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1587 		halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1588 		halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1589 	}
1590 }
1591 VOID
halbtc8188c2ant_ActionPanA2dpBc8(IN PBTC_COEXIST pBtCoexist)1592 halbtc8188c2ant_ActionPanA2dpBc8(
1593 	IN	PBTC_COEXIST		pBtCoexist
1594 	)
1595 {
1596 	BOOLEAN		bBtHsOn=FALSE, bWifiBusy=FALSE;
1597 	u1Byte		wifiRssiState;
1598 	u4Byte		wifiBw;
1599 
1600 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1601 
1602 	if(!bBtHsOn)
1603 	{
1604 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1605 		wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 25, 0);
1606 		if((pCoexSta->bBtBusy && bWifiBusy))
1607 		{
1608 			// fw mechanism first
1609 			if(pCoexSta->bBtUplink)
1610 			{
1611 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x15, 0x20);
1612 			}
1613 			else
1614 			{
1615 				halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x10, 0x20);
1616 			}
1617 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);
1618 
1619 			// sw mechanism
1620 			if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
1621 				(wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )
1622 			{
1623 				pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1624 				if(BTC_WIFI_BW_HT40 == wifiBw)
1625 				{
1626 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1627 					halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1628 					halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1629 				}
1630 				else
1631 				{
1632 					halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);
1633 					halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);
1634 					halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1635 				}
1636 			}
1637 			else
1638 			{
1639 				halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1640 				halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1641 				halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1642 			}
1643 		}
1644 		else
1645 		{
1646 			halbtc8188c2ant_CoexAllOff(pBtCoexist);
1647 		}
1648 	}
1649 	else
1650 	{
1651 		if(pCoexSta->bBtBusy)
1652 		{
1653 			// fw mechanism
1654 			halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);
1655 			halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);
1656 
1657 			// sw mechanism
1658 			halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);
1659 			halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);
1660 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);
1661 		}
1662 		else
1663 		{
1664 			halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);
1665 		}
1666 	}
1667 }
1668 
1669 VOID
halbtc8188c2ant_ActionPanA2dp(IN PBTC_COEXIST pBtCoexist)1670 halbtc8188c2ant_ActionPanA2dp(
1671 	IN	PBTC_COEXIST		pBtCoexist
1672 	)
1673 {
1674 	if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)
1675 	{
1676 		halbtc8188c2ant_ActionPanA2dpBc4(pBtCoexist);
1677 	}
1678 	else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)
1679 	{
1680 		halbtc8188c2ant_ActionPanA2dpBc8(pBtCoexist);
1681 	}
1682 }
1683 
1684 //============================================================
1685 // extern function start with EXhalbtc8188c2ant_
1686 //============================================================
1687 VOID
EXhalbtc8188c2ant_PowerOnSetting(IN PBTC_COEXIST pBtCoexist)1688 EXhalbtc8188c2ant_PowerOnSetting(
1689 	IN	PBTC_COEXIST		pBtCoexist
1690 	)
1691 {
1692 }
1693 
1694 VOID
EXhalbtc8188c2ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bWifiOnly)1695 EXhalbtc8188c2ant_InitHwConfig(
1696 	IN	PBTC_COEXIST		pBtCoexist,
1697 	IN	BOOLEAN				bWifiOnly
1698 	)
1699 {
1700 	u1Byte	u1Tmp=0;
1701 
1702 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));
1703 
1704 	// backup rf 0x1e value
1705 	pCoexDm->btRf0x1eBackup =
1706 		pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xf0);
1707 
1708 	if( (BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType) ||
1709 		(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType) )
1710 	{
1711 		u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd) & BIT0;
1712 		pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, u1Tmp);
1713 
1714 		halbtc8188c2ant_CoexTable(pBtCoexist, FORCE_EXEC, 0xaaaa9aaa, 0xffbd0040, 0x40000010);
1715 	}
1716 }
1717 
1718 VOID
EXhalbtc8188c2ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)1719 EXhalbtc8188c2ant_InitCoexDm(
1720 	IN	PBTC_COEXIST		pBtCoexist
1721 	)
1722 {
1723 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
1724 
1725 	halbtc8188c2ant_InitCoexDm(pBtCoexist);
1726 }
1727 
1728 VOID
EXhalbtc8188c2ant_DisplayCoexInfo(IN PBTC_COEXIST pBtCoexist)1729 EXhalbtc8188c2ant_DisplayCoexInfo(
1730 	IN	PBTC_COEXIST		pBtCoexist
1731 	)
1732 {
1733 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
1734 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
1735 	pu1Byte				cliBuf=pBtCoexist->cliBuf;
1736 	u1Byte				u1Tmp[4], i, btInfoExt, psTdmaCase=0;
1737 	u4Byte				u4Tmp[4];
1738 
1739 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
1740 	CL_PRINTF(cliBuf);
1741 
1742 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
1743 		pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);
1744 	CL_PRINTF(cliBuf);
1745 
1746 	if(pBtCoexist->bManualControl)
1747 	{
1748 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
1749 		CL_PRINTF(cliBuf);
1750 	}
1751 
1752 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
1753 		((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
1754 	CL_PRINTF(cliBuf);
1755 
1756 	// wifi status
1757 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
1758 	CL_PRINTF(cliBuf);
1759 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
1760 
1761 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
1762 	CL_PRINTF(cliBuf);
1763 
1764 	if(pStackInfo->bProfileNotified)
1765 	{
1766 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
1767 			pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);
1768 		CL_PRINTF(cliBuf);
1769 
1770 		pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
1771 	}
1772 
1773 	// Sw mechanism
1774 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
1775 	CL_PRINTF(cliBuf);
1776 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \
1777 		pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);
1778 	CL_PRINTF(cliBuf);
1779 
1780 	// Fw mechanism
1781 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
1782 	CL_PRINTF(cliBuf);
1783 
1784 	// Hw setting
1785 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
1786 	CL_PRINTF(cliBuf);
1787 
1788 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
1789 		pCoexDm->btRf0x1eBackup);
1790 	CL_PRINTF(cliBuf);
1791 
1792 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
1793 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
1794 		u1Tmp[0]);
1795 	CL_PRINTF(cliBuf);
1796 
1797 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
1798 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
1799 		u4Tmp[0]);
1800 	CL_PRINTF(cliBuf);
1801 
1802 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
1803 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
1804 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
1805 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c4/0x6c8/0x6cc(coexTable)", \
1806 		u4Tmp[0], u4Tmp[1], u4Tmp[2]);
1807 	CL_PRINTF(cliBuf);
1808 
1809 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
1810 }
1811 
1812 
1813 VOID
EXhalbtc8188c2ant_IpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1814 EXhalbtc8188c2ant_IpsNotify(
1815 	IN	PBTC_COEXIST		pBtCoexist,
1816 	IN	u1Byte			type
1817 	)
1818 {
1819 	if(BTC_IPS_ENTER == type)
1820 	{
1821 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
1822 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
1823 	}
1824 	else if(BTC_IPS_LEAVE == type)
1825 	{
1826 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
1827 		//halbtc8188c2ant_InitCoexDm(pBtCoexist);
1828 	}
1829 }
1830 
1831 VOID
EXhalbtc8188c2ant_LpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1832 EXhalbtc8188c2ant_LpsNotify(
1833 	IN	PBTC_COEXIST		pBtCoexist,
1834 	IN	u1Byte			type
1835 	)
1836 {
1837 	if(BTC_LPS_ENABLE == type)
1838 	{
1839 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
1840 		halbtc8188c2ant_CoexAllOff(pBtCoexist);
1841 	}
1842 	else if(BTC_LPS_DISABLE == type)
1843 	{
1844 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
1845 		halbtc8188c2ant_InitCoexDm(pBtCoexist);
1846 	}
1847 }
1848 
1849 VOID
EXhalbtc8188c2ant_ScanNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1850 EXhalbtc8188c2ant_ScanNotify(
1851 	IN	PBTC_COEXIST		pBtCoexist,
1852 	IN	u1Byte			type
1853 	)
1854 {
1855 	if(BTC_SCAN_START == type)
1856 	{
1857 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
1858 	}
1859 	else if(BTC_SCAN_FINISH == type)
1860 	{
1861 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
1862 	}
1863 }
1864 
1865 VOID
EXhalbtc8188c2ant_ConnectNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1866 EXhalbtc8188c2ant_ConnectNotify(
1867 	IN	PBTC_COEXIST		pBtCoexist,
1868 	IN	u1Byte			type
1869 	)
1870 {
1871 	if(BTC_ASSOCIATE_START == type)
1872 	{
1873 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
1874 	}
1875 	else if(BTC_ASSOCIATE_FINISH == type)
1876 	{
1877 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
1878 	}
1879 }
1880 
1881 VOID
EXhalbtc8188c2ant_MediaStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1882 EXhalbtc8188c2ant_MediaStatusNotify(
1883 	IN	PBTC_COEXIST			pBtCoexist,
1884 	IN	u1Byte				type
1885 	)
1886 {
1887 	if(BTC_MEDIA_CONNECT == type)
1888 	{
1889 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
1890 	}
1891 	else
1892 	{
1893 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
1894 	}
1895 
1896 }
1897 
1898 VOID
EXhalbtc8188c2ant_SpecialPacketNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1899 EXhalbtc8188c2ant_SpecialPacketNotify(
1900 	IN	PBTC_COEXIST			pBtCoexist,
1901 	IN	u1Byte				type
1902 	)
1903 {
1904 	if(type == BTC_PACKET_DHCP)
1905 	{
1906 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));
1907 	}
1908 }
1909 
1910 VOID
EXhalbtc8188c2ant_BtInfoNotify(IN PBTC_COEXIST pBtCoexist,IN pu1Byte tmpBuf,IN u1Byte length)1911 EXhalbtc8188c2ant_BtInfoNotify(
1912 	IN	PBTC_COEXIST		pBtCoexist,
1913 	IN	pu1Byte			tmpBuf,
1914 	IN	u1Byte			length
1915 	)
1916 {
1917 }
1918 
1919 VOID
EXhalbtc8188c2ant_HaltNotify(IN PBTC_COEXIST pBtCoexist)1920 EXhalbtc8188c2ant_HaltNotify(
1921 	IN	PBTC_COEXIST			pBtCoexist
1922 	)
1923 {
1924 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
1925 
1926 	EXhalbtc8188c2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
1927 }
1928 
1929 VOID
EXhalbtc8188c2ant_Periodical(IN PBTC_COEXIST pBtCoexist)1930 EXhalbtc8188c2ant_Periodical(
1931 	IN	PBTC_COEXIST			pBtCoexist
1932 	)
1933 {
1934 	u1Byte	algorithm;
1935 
1936 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Periodical!!\n"));
1937 
1938 	// NOTE:
1939 	// sw mechanism must be done after fw mechanism
1940 	//
1941 
1942 	if((BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType) ||
1943 		(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType) )
1944 	{
1945 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_GET_BT_RSSI, NULL);
1946 
1947 		halbtc8188c2ant_MonitorBtState(pBtCoexist);
1948 		algorithm = halbtc8188c2ant_ActionAlgorithm(pBtCoexist);
1949 		pCoexDm->curAlgorithm = algorithm;
1950 		switch(pCoexDm->curAlgorithm)
1951 		{
1952 			case BT_8188C_2ANT_COEX_ALGO_SCO:
1953 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO\n"));
1954 				halbtc8188c2ant_ActionSco(pBtCoexist);
1955 				break;
1956 			case BT_8188C_2ANT_COEX_ALGO_HID:
1957 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID\n"));
1958 				halbtc8188c2ant_ActionHid(pBtCoexist);
1959 				break;
1960 			case BT_8188C_2ANT_COEX_ALGO_A2DP:
1961 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP\n"));
1962 				halbtc8188c2ant_ActionA2dp(pBtCoexist);
1963 				break;
1964 			case BT_8188C_2ANT_COEX_ALGO_PAN:
1965 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN\n"));
1966 				halbtc8188c2ant_ActionPan(pBtCoexist);
1967 				break;
1968 			case BT_8188C_2ANT_COEX_ALGO_HID_A2DP:
1969 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n"));
1970 				halbtc8188c2ant_ActionHidA2dp(pBtCoexist);
1971 				break;
1972 			case BT_8188C_2ANT_COEX_ALGO_HID_PAN:
1973 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+HID\n"));
1974 				halbtc8188c2ant_ActionHidPan(pBtCoexist);
1975 				break;
1976 			case BT_8188C_2ANT_COEX_ALGO_PAN_A2DP:
1977 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n"));
1978 				halbtc8188c2ant_ActionPanA2dp(pBtCoexist);
1979 				break;
1980 			default:
1981 				break;
1982 		}
1983 	}
1984 }
1985 
1986 
1987 #endif
1988 
1989