xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723bu/hal/btc/HalBtc8723a1Ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 //============================================================
3 // Description:
4 //
5 // This file is for RTL8723A Co-exist mechanism
6 //
7 // History
8 // 2012/08/22 Cosa first check in.
9 // 2012/11/14 Cosa Revise for 8723A 1Ant out sourcing.
10 //
11 //============================================================
12 
13 //============================================================
14 // include files
15 //============================================================
16 #include "Mp_Precomp.h"
17 
18 #if WPP_SOFTWARE_TRACE
19 #include "HalBtc8723a1Ant.tmh"
20 #endif
21 
22 #if(BT_30_SUPPORT == 1)
23 //============================================================
24 // Global variables, these are static variables
25 //============================================================
26 static COEX_DM_8723A_1ANT	GLCoexDm8723a1Ant;
27 static PCOEX_DM_8723A_1ANT 	pCoexDm=&GLCoexDm8723a1Ant;
28 static COEX_STA_8723A_1ANT	GLCoexSta8723a1Ant;
29 static PCOEX_STA_8723A_1ANT	pCoexSta=&GLCoexSta8723a1Ant;
30 
31 const char *const GLBtInfoSrc8723a1Ant[]={
32 	"BT Info[wifi fw]",
33 	"BT Info[bt rsp]",
34 	"BT Info[bt auto report]",
35 };
36 
37 //============================================================
38 // local function proto type if needed
39 //============================================================
40 //============================================================
41 // local function start with halbtc8723a1ant_
42 //============================================================
43 VOID
halbtc8723a1ant_Reg0x550Bit3(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bSet)44 halbtc8723a1ant_Reg0x550Bit3(
45 	IN	PBTC_COEXIST		pBtCoexist,
46 	IN	BOOLEAN			bSet
47 	)
48 {
49 	u1Byte	u1tmp=0;
50 
51 	u1tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x550);
52 	if(bSet)
53 	{
54 		u1tmp |= BIT3;
55 	}
56 	else
57 	{
58 		u1tmp &= ~BIT3;
59 	}
60 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x550, u1tmp);
61 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set 0x550[3]=%d\n", (bSet? 1:0)));
62 }
63 
64 VOID
halbtc8723a1ant_NotifyFwScan(IN PBTC_COEXIST pBtCoexist,IN u1Byte scanType)65 halbtc8723a1ant_NotifyFwScan(
66 	IN	PBTC_COEXIST		pBtCoexist,
67 	IN	u1Byte			scanType
68 	)
69 {
70 	u1Byte			H2C_Parameter[1] ={0};
71 
72 	if(BTC_SCAN_START == scanType)
73 		H2C_Parameter[0] = 0x1;
74 
75 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b=0x%x\n",
76 		H2C_Parameter[0]));
77 
78 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3b, 1, H2C_Parameter);
79 }
80 
81 VOID
halbtc8723a1ant_QueryBtInfo(IN PBTC_COEXIST pBtCoexist)82 halbtc8723a1ant_QueryBtInfo(
83 	IN	PBTC_COEXIST		pBtCoexist
84 	)
85 {
86 	u1Byte			H2C_Parameter[1] ={0};
87 
88 	pCoexSta->bC2hBtInfoReqSent = TRUE;
89 
90 	H2C_Parameter[0] |= BIT0;	// trigger
91 
92 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x38=0x%x\n",
93 		H2C_Parameter[0]));
94 
95 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x38, 1, H2C_Parameter);
96 }
97 
98 VOID
halbtc8723a1ant_SetSwRfRxLpfCorner(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bRxRfShrinkOn)99 halbtc8723a1ant_SetSwRfRxLpfCorner(
100 	IN	PBTC_COEXIST		pBtCoexist,
101 	IN	BOOLEAN			bRxRfShrinkOn
102 	)
103 {
104 	if(bRxRfShrinkOn)
105 	{
106 		//Shrink RF Rx LPF corner
107 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));
108 		pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xf0ff7);
109 	}
110 	else
111 	{
112 		//Resume RF Rx LPF corner
113 		// After initialized, we can use pCoexDm->btRf0x1eBackup
114 		if(pBtCoexist->bInitilized)
115 		{
116 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
117 			pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);
118 		}
119 	}
120 }
121 
122 VOID
halbtc8723a1ant_RfShrink(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRxRfShrinkOn)123 halbtc8723a1ant_RfShrink(
124 	IN	PBTC_COEXIST		pBtCoexist,
125 	IN	BOOLEAN			bForceExec,
126 	IN	BOOLEAN			bRxRfShrinkOn
127 	)
128 {
129 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",
130 		(bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));
131 	pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
132 
133 	if(!bForceExec)
134 	{
135 		if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
136 			return;
137 	}
138 	halbtc8723a1ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
139 
140 	pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
141 }
142 
143 VOID
halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bLowPenaltyRa)144 halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(
145 	IN	PBTC_COEXIST		pBtCoexist,
146 	IN	BOOLEAN			bLowPenaltyRa
147 	)
148 {
149 	u1Byte	tmpU1;
150 
151 	tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);
152 	tmpU1 |= BIT0;
153 	if(bLowPenaltyRa)
154 	{
155 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));
156 		tmpU1 &= ~BIT2;
157 	}
158 	else
159 	{
160 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set normal!!\n"));
161 		tmpU1 |= BIT2;
162 	}
163 
164 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);
165 }
166 
167 VOID
halbtc8723a1ant_LowPenaltyRa(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bLowPenaltyRa)168 halbtc8723a1ant_LowPenaltyRa(
169 	IN	PBTC_COEXIST		pBtCoexist,
170 	IN	BOOLEAN			bForceExec,
171 	IN	BOOLEAN			bLowPenaltyRa
172 	)
173 {
174 	return;
175 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",
176 		(bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));
177 	pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
178 
179 	if(!bForceExec)
180 	{
181 		if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
182 			return;
183 	}
184 	halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
185 
186 	pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
187 }
188 
189 VOID
halbtc8723a1ant_SetCoexTable(IN PBTC_COEXIST pBtCoexist,IN u4Byte val0x6c0,IN u4Byte val0x6c8,IN u1Byte val0x6cc)190 halbtc8723a1ant_SetCoexTable(
191 	IN	PBTC_COEXIST	pBtCoexist,
192 	IN	u4Byte		val0x6c0,
193 	IN	u4Byte		val0x6c8,
194 	IN	u1Byte		val0x6cc
195 	)
196 {
197 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
198 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
199 
200 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
201 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
202 
203 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
204 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
205 }
206 
207 VOID
halbtc8723a1ant_CoexTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte val0x6c0,IN u4Byte val0x6c8,IN u1Byte val0x6cc)208 halbtc8723a1ant_CoexTable(
209 	IN	PBTC_COEXIST		pBtCoexist,
210 	IN	BOOLEAN			bForceExec,
211 	IN	u4Byte			val0x6c0,
212 	IN	u4Byte			val0x6c8,
213 	IN	u1Byte			val0x6cc
214 	)
215 {
216 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
217 		(bForceExec? "force to":""), val0x6c0, val0x6c8, val0x6cc));
218 	pCoexDm->curVal0x6c0 = val0x6c0;
219 	pCoexDm->curVal0x6c8 = val0x6c8;
220 	pCoexDm->curVal0x6cc = val0x6cc;
221 
222 	if(!bForceExec)
223 	{
224 		if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
225 			(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
226 			(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
227 			return;
228 	}
229 	halbtc8723a1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c8, val0x6cc);
230 
231 	pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
232 	pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
233 	pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
234 }
235 
236 VOID
halbtc8723a1ant_SetFwIgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnable)237 halbtc8723a1ant_SetFwIgnoreWlanAct(
238 	IN	PBTC_COEXIST		pBtCoexist,
239 	IN	BOOLEAN			bEnable
240 	)
241 {
242 	u1Byte			H2C_Parameter[1] ={0};
243 
244 	if(bEnable)
245 	{
246 		H2C_Parameter[0] |= BIT0;		// function enable
247 	}
248 
249 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x25=0x%x\n",
250 		H2C_Parameter[0]));
251 
252 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x25, 1, H2C_Parameter);
253 }
254 
255 VOID
halbtc8723a1ant_IgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnable)256 halbtc8723a1ant_IgnoreWlanAct(
257 	IN	PBTC_COEXIST		pBtCoexist,
258 	IN	BOOLEAN			bForceExec,
259 	IN	BOOLEAN			bEnable
260 	)
261 {
262 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n",
263 		(bForceExec? "force to":""), (bEnable? "ON":"OFF")));
264 	pCoexDm->bCurIgnoreWlanAct = bEnable;
265 
266 	if(!bForceExec)
267 	{
268 		if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
269 			return;
270 	}
271 	halbtc8723a1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
272 
273 	pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
274 }
275 
276 VOID
halbtc8723a1ant_SetFwPstdma(IN PBTC_COEXIST pBtCoexist,IN u1Byte type,IN u1Byte byte1,IN u1Byte byte2,IN u1Byte byte3,IN u1Byte byte4,IN u1Byte byte5)277 halbtc8723a1ant_SetFwPstdma(
278 	IN	PBTC_COEXIST		pBtCoexist,
279 	IN	u1Byte			type,
280 	IN	u1Byte			byte1,
281 	IN	u1Byte			byte2,
282 	IN	u1Byte			byte3,
283 	IN	u1Byte			byte4,
284 	IN	u1Byte			byte5
285 	)
286 {
287 	u1Byte			H2C_Parameter[5] ={0};
288 	u1Byte			realByte1=byte1, realByte5=byte5;
289 	BOOLEAN			bApEnable=FALSE;
290 
291 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
292 
293 	// byte1[1:0] != 0 means enable pstdma
294 	// for 2Ant bt coexist, if byte1 != 0 means enable pstdma
295 	if(byte1)
296 	{
297 		if(bApEnable)
298 		{
299 			if(type != 5 && type != 12)
300 			{
301 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));
302 				realByte1 &= ~BIT4;
303 				realByte1 |= BIT5;
304 
305 				realByte5 |= BIT5;
306 				realByte5 &= ~BIT6;
307 			}
308 		}
309 	}
310 	H2C_Parameter[0] = realByte1;
311 	H2C_Parameter[1] = byte2;
312 	H2C_Parameter[2] = byte3;
313 	H2C_Parameter[3] = byte4;
314 	H2C_Parameter[4] = realByte5;
315 
316 	pCoexDm->psTdmaPara[0] = realByte1;
317 	pCoexDm->psTdmaPara[1] = byte2;
318 	pCoexDm->psTdmaPara[2] = byte3;
319 	pCoexDm->psTdmaPara[3] = byte4;
320 	pCoexDm->psTdmaPara[4] = realByte5;
321 
322 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x3a(5bytes)=0x%x%08x\n",
323 		H2C_Parameter[0],
324 		H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
325 
326 	pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3a, 5, H2C_Parameter);
327 }
328 
329 VOID
halbtc8723a1ant_PsTdma(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bTurnOn,IN u1Byte type)330 halbtc8723a1ant_PsTdma(
331 	IN	PBTC_COEXIST		pBtCoexist,
332 	IN	BOOLEAN			bForceExec,
333 	IN	BOOLEAN			bTurnOn,
334 	IN	u1Byte			type
335 	)
336 {
337 	RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn %s PS TDMA, type=%d\n",
338 		(bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));
339 	pCoexDm->bCurPsTdmaOn = bTurnOn;
340 	pCoexDm->curPsTdma = type;
341 
342 	if(!bForceExec)
343 	{
344 		if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
345 			(pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
346 			return;
347 	}
348 	if(pCoexDm->bCurPsTdmaOn)
349 	{
350 		switch(pCoexDm->curPsTdma)
351 		{
352 			case 1:
353 			default:
354 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x1a, 0x1a, 0x0, 0x40);
355 				break;
356 			case 2:
357 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x12, 0x12, 0x0, 0x40);
358 				break;
359 			case 3:
360 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x3f, 0x3, 0x10, 0x40);
361 				break;
362 			case 4:
363 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x15, 0x3, 0x10, 0x0);
364 				break;
365 			case 5:
366 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0xa9, 0x15, 0x3, 0x35, 0xc0);
367 				break;
368 
369 			case 8:
370 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);
371 				break;
372 			case 9:
373 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x0, 0x40);
374 				break;
375 			case 10:
376 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x0, 0x40);
377 				break;
378 			case 11:
379 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x0, 0x40);
380 				break;
381 			case 12:
382 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0xa9, 0xa, 0x3, 0x15, 0xc0);
383 				break;
384 
385 			case 18:
386 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);
387 				break;
388 
389 			case 20:
390 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x2a, 0x2a, 0x0, 0x0);
391 				break;
392 			case 21:
393 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x20, 0x3, 0x10, 0x40);
394 				break;
395 			case 22:
396 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x1a, 0x1a, 0x2, 0x40);
397 				break;
398 			case 23:
399 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x12, 0x12, 0x2, 0x40);
400 				break;
401 			case 24:
402 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x2, 0x40);
403 				break;
404 			case 25:
405 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x2, 0x40);
406 				break;
407 			case 26:
408 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);
409 				break;
410 			case 27:
411 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x2, 0x40);
412 				break;
413 			case 28:
414 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x3, 0x2f, 0x2f, 0x0, 0x0);
415 				break;
416 
417 		}
418 	}
419 	else
420 	{
421 		// disable PS tdma
422 		switch(pCoexDm->curPsTdma)
423 		{
424 			case 8:
425 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x8, 0x0, 0x0, 0x0, 0x0);
426 				break;
427 			case 0:
428 			default:
429 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x0, 0x0, 0x0, 0x0, 0x0);
430 				pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x210);
431 				break;
432 			case 9:
433 				halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x0, 0x0, 0x0, 0x0, 0x0);
434 				pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x110);
435 				break;
436 
437 		}
438 	}
439 
440 	// update pre state
441 	pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
442 	pCoexDm->prePsTdma = pCoexDm->curPsTdma;
443 }
444 
445 
446 VOID
halbtc8723a1ant_CoexAllOff(IN PBTC_COEXIST pBtCoexist)447 halbtc8723a1ant_CoexAllOff(
448 	IN	PBTC_COEXIST		pBtCoexist
449 	)
450 {
451 	// fw all off
452 	halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);
453 	halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
454 
455 	// sw all off
456 	halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);
457 	halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);
458 
459 	// hw all off
460 	halbtc8723a1ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);
461 }
462 
463 VOID
halbtc8723a1ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)464 halbtc8723a1ant_InitCoexDm(
465 	IN	PBTC_COEXIST		pBtCoexist
466 	)
467 {
468 	// force to reset coex mechanism
469 	halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
470 }
471 
472 VOID
halbtc8723a1ant_BtEnableAction(IN PBTC_COEXIST pBtCoexist)473 halbtc8723a1ant_BtEnableAction(
474 	IN 	PBTC_COEXIST		pBtCoexist
475 	)
476 {
477 	halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
478 }
479 
480 VOID
halbtc8723a1ant_MonitorBtCtr(IN PBTC_COEXIST pBtCoexist)481 halbtc8723a1ant_MonitorBtCtr(
482 	IN	PBTC_COEXIST		pBtCoexist
483 	)
484 {
485 	u4Byte 			regHPTxRx, regLPTxRx, u4Tmp;
486 	u4Byte			regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;
487 	u1Byte			u1Tmp;
488 
489 	regHPTxRx = 0x770;
490 	regLPTxRx = 0x774;
491 
492 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
493 	regHPTx = u4Tmp & bMaskLWord;
494 	regHPRx = (u4Tmp & bMaskHWord)>>16;
495 
496 	u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
497 	regLPTx = u4Tmp & bMaskLWord;
498 	regLPRx = (u4Tmp & bMaskHWord)>>16;
499 
500 	pCoexSta->highPriorityTx = regHPTx;
501 	pCoexSta->highPriorityRx = regHPRx;
502 	pCoexSta->lowPriorityTx = regLPTx;
503 	pCoexSta->lowPriorityRx = regLPRx;
504 
505 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
506 		regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));
507 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
508 		regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));
509 
510 	// reset counter
511 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
512 }
513 
514 VOID
halbtc8723a1ant_MonitorBtEnableDisable(IN PBTC_COEXIST pBtCoexist)515 halbtc8723a1ant_MonitorBtEnableDisable(
516 	IN 	PBTC_COEXIST		pBtCoexist
517 	)
518 {
519 	static BOOLEAN	bPreBtDisabled=FALSE;
520 	static u4Byte	btDisableCnt=0;
521 	BOOLEAN			bBtActive=TRUE, bBtDisabled=FALSE;
522 
523 	// This function check if bt is disabled
524 
525 	if(	pCoexSta->highPriorityTx == 0 &&
526 		pCoexSta->highPriorityRx == 0 &&
527 		pCoexSta->lowPriorityTx == 0 &&
528 		pCoexSta->lowPriorityRx == 0)
529 	{
530 		bBtActive = FALSE;
531 	}
532 	if(	pCoexSta->highPriorityTx == 0xffff &&
533 		pCoexSta->highPriorityRx == 0xffff &&
534 		pCoexSta->lowPriorityTx == 0xffff &&
535 		pCoexSta->lowPriorityRx == 0xffff)
536 	{
537 		bBtActive = FALSE;
538 	}
539 	if(bBtActive)
540 	{
541 		btDisableCnt = 0;
542 		bBtDisabled = FALSE;
543 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
544 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));
545 	}
546 	else
547 	{
548 		btDisableCnt++;
549 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n",
550 				btDisableCnt));
551 		if(btDisableCnt >= 2)
552 		{
553 			bBtDisabled = TRUE;
554 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
555 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));
556 		}
557 	}
558 	if(bPreBtDisabled != bBtDisabled)
559 	{
560 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n",
561 			(bPreBtDisabled ? "disabled":"enabled"),
562 			(bBtDisabled ? "disabled":"enabled")));
563 		bPreBtDisabled = bBtDisabled;
564 		if(!bBtDisabled)
565 		{
566 			halbtc8723a1ant_BtEnableAction(pBtCoexist);
567 		}
568 		else
569 		{
570 			pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
571 		}
572 	}
573 }
574 
575 VOID
halbtc8723a1ant_TdmaDurationAdjust(IN PBTC_COEXIST pBtCoexist)576 halbtc8723a1ant_TdmaDurationAdjust(
577 	IN	PBTC_COEXIST		pBtCoexist
578 	)
579 {
580 	static s4Byte		up,dn,m,n,WaitCount;
581 	s4Byte			result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
582 	u1Byte			retryCount=0;
583 	u1Byte			btState;
584 	BOOLEAN			bScan=FALSE, bLink=FALSE, bRoam=FALSE;
585 	u4Byte			wifiBw;
586 
587 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
588 	btState = pCoexDm->btStatus;
589 
590 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], TdmaDurationAdjust()\n"));
591 	if(pCoexDm->psTdmaGlobalCnt != pCoexDm->psTdmaMonitorCnt)
592 	{
593 		pCoexDm->psTdmaMonitorCnt = 0;
594 		pCoexDm->psTdmaGlobalCnt = 0;
595 	}
596 	if(pCoexDm->psTdmaMonitorCnt == 0)
597 	{
598 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], first run BT A2DP + WiFi busy state!!\n"));
599 		if(btState == BT_STATE_8723A_1ANT_ACL_ONLY_BUSY)
600 		{
601 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
602 			pCoexDm->psTdmaDuAdjType = 1;
603 		}
604 		else
605 		{
606 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
607 			pCoexDm->psTdmaDuAdjType = 22;
608 		}
609 		//============
610 		up = 0;
611 		dn = 0;
612 		m = 1;
613 		n= 3;
614 		result = 0;
615 		WaitCount = 0;
616 	}
617 	else
618 	{
619 		//accquire the BT TRx retry count from BT_Info byte2
620 		retryCount = pCoexSta->btRetryCnt;
621 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], retryCount = %d\n", retryCount));
622 		result = 0;
623 		WaitCount++;
624 
625 		if(retryCount == 0)  // no retry in the last 2-second duration
626 		{
627 			up++;
628 			dn--;
629 
630 			if (dn <= 0)
631 				dn = 0;
632 
633 			if(up >= n) // if �s�� n ��2�� retry count��0, �h�ռeWiFi duration
634 			{
635 				WaitCount = 0;
636 				n = 3;
637 				up = 0;
638 				dn = 0;
639 				result = 1;
640 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Increase wifi duration!!\n"));
641 			}
642 		}
643 		else if (retryCount <= 3)	// <=3 retry in the last 2-second duration
644 		{
645 			up--;
646 			dn++;
647 
648 			if (up <= 0)
649 				up = 0;
650 
651 			if (dn == 2)	// if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration
652 			{
653 				if (WaitCount <= 2)
654 					m++; // �קK�@���b���level���Ӧ^
655 				else
656 					m = 1;
657 
658 				if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
659 					m = 20;
660 
661 				n = 3*m;
662 				up = 0;
663 				dn = 0;
664 				WaitCount = 0;
665 				result = -1;
666 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
667 			}
668 		}
669 		else  //retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration
670 		{
671 			if (WaitCount == 1)
672 				m++; // �קK�@���b���level���Ӧ^
673 			else
674 				m = 1;
675 
676 			if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
677 				m = 20;
678 
679 			n = 3*m;
680 			up = 0;
681 			dn = 0;
682 			WaitCount = 0;
683 			result = -1;
684 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
685 		}
686 
687 		{
688 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT TxRx counter H+L <= 1200\n"));
689 			if(btState != BT_STATE_8723A_1ANT_ACL_ONLY_BUSY)
690 			{
691 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], NOT ACL only busy!\n"));
692 				if(BTC_WIFI_BW_HT40 != wifiBw)
693 				{
694 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 20MHz\n"));
695 					if(result == -1)
696 					{
697 						if(pCoexDm->curPsTdma == 22)
698 						{
699 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);
700 							pCoexDm->psTdmaDuAdjType = 23;
701 						}
702 						else if(pCoexDm->curPsTdma == 23)
703 						{
704 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);
705 							pCoexDm->psTdmaDuAdjType = 24;
706 						}
707 						else if(pCoexDm->curPsTdma == 24)
708 						{
709 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);
710 							pCoexDm->psTdmaDuAdjType = 25;
711 						}
712 					}
713 					else if (result == 1)
714 					{
715 						if(pCoexDm->curPsTdma == 25)
716 						{
717 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);
718 							pCoexDm->psTdmaDuAdjType = 24;
719 						}
720 						else if(pCoexDm->curPsTdma == 24)
721 						{
722 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);
723 							pCoexDm->psTdmaDuAdjType = 23;
724 						}
725 						else if(pCoexDm->curPsTdma == 23)
726 						{
727 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
728 							pCoexDm->psTdmaDuAdjType = 22;
729 						}
730 					}
731 					// error handle, if not in the following state,
732 					// set psTdma again.
733 					if( (pCoexDm->psTdmaDuAdjType != 22) &&
734 						(pCoexDm->psTdmaDuAdjType != 23) &&
735 						(pCoexDm->psTdmaDuAdjType != 24) &&
736 						(pCoexDm->psTdmaDuAdjType != 25) )
737 					{
738 						RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], duration case out of handle!!\n"));
739 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);
740 						pCoexDm->psTdmaDuAdjType = 23;
741 					}
742 				}
743 				else
744 				{
745 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 40MHz\n"));
746 					if(result == -1)
747 					{
748 						if(pCoexDm->curPsTdma == 23)
749 						{
750 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);
751 							pCoexDm->psTdmaDuAdjType = 24;
752 						}
753 						else if(pCoexDm->curPsTdma == 24)
754 						{
755 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);
756 							pCoexDm->psTdmaDuAdjType = 25;
757 						}
758 						else if(pCoexDm->curPsTdma == 25)
759 						{
760 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 27);
761 							pCoexDm->psTdmaDuAdjType = 27;
762 						}
763 					}
764 					else if (result == 1)
765 					{
766 						if(pCoexDm->curPsTdma == 27)
767 						{
768 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);
769 							pCoexDm->psTdmaDuAdjType = 25;
770 						}
771 						else if(pCoexDm->curPsTdma == 25)
772 						{
773 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);
774 							pCoexDm->psTdmaDuAdjType = 24;
775 						}
776 						else if(pCoexDm->curPsTdma == 24)
777 						{
778 							halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);
779 							pCoexDm->psTdmaDuAdjType = 23;
780 						}
781 					}
782 					// error handle, if not in the following state,
783 					// set psTdma again.
784 					if( (pCoexDm->psTdmaDuAdjType != 23) &&
785 						(pCoexDm->psTdmaDuAdjType != 24) &&
786 						(pCoexDm->psTdmaDuAdjType != 25) &&
787 						(pCoexDm->psTdmaDuAdjType != 27) )
788 					{
789 						RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], duration case out of handle!!\n"));
790 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);
791 						pCoexDm->psTdmaDuAdjType = 24;
792 					}
793 				}
794 			}
795 			else
796 			{
797 				RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ACL only busy\n"));
798 				if (result == -1)
799 				{
800 					if(pCoexDm->curPsTdma == 1)
801 					{
802 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
803 						pCoexDm->psTdmaDuAdjType = 2;
804 					}
805 					else if(pCoexDm->curPsTdma == 2)
806 					{
807 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
808 						pCoexDm->psTdmaDuAdjType = 9;
809 					}
810 					else if(pCoexDm->curPsTdma == 9)
811 					{
812 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
813 						pCoexDm->psTdmaDuAdjType = 11;
814 					}
815 				}
816 				else if (result == 1)
817 				{
818 					if(pCoexDm->curPsTdma == 11)
819 					{
820 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
821 						pCoexDm->psTdmaDuAdjType = 9;
822 					}
823 					else if(pCoexDm->curPsTdma == 9)
824 					{
825 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
826 						pCoexDm->psTdmaDuAdjType = 2;
827 					}
828 					else if(pCoexDm->curPsTdma == 2)
829 					{
830 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
831 						pCoexDm->psTdmaDuAdjType = 1;
832 					}
833 				}
834 
835 				// error handle, if not in the following state,
836 				// set psTdma again.
837 				if( (pCoexDm->psTdmaDuAdjType != 1) &&
838 					(pCoexDm->psTdmaDuAdjType != 2) &&
839 					(pCoexDm->psTdmaDuAdjType != 9) &&
840 					(pCoexDm->psTdmaDuAdjType != 11) )
841 				{
842 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], duration case out of handle!!\n"));
843 					halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
844 					pCoexDm->psTdmaDuAdjType = 2;
845 				}
846 			}
847 		}
848 	}
849 
850 	// if current PsTdma not match with the recorded one (when scan, dhcp...),
851 	// then we have to adjust it back to the previous record one.
852 	if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)
853 	{
854 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n",
855 			pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));
856 
857 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
858 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
859 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
860 
861 		if( !bScan && !bLink &&	!bRoam)
862 		{
863 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
864 		}
865 		else
866 		{
867 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
868 		}
869 	}
870 	pCoexDm->psTdmaMonitorCnt++;
871 }
872 
873 
874 VOID
halbtc8723a1ant_CoexForWifiConnect(IN PBTC_COEXIST pBtCoexist)875 halbtc8723a1ant_CoexForWifiConnect(
876 	IN	PBTC_COEXIST		pBtCoexist
877 	)
878 {
879 	BOOLEAN		bWifiConnected=FALSE, bWifiBusy=FALSE;
880 	u1Byte		btState, btInfoOriginal=0;
881 
882 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
883 
884 	btState = pCoexDm->btStatus;
885 	btInfoOriginal = pCoexSta->btInfoC2h[BT_INFO_SRC_8723A_1ANT_BT_RSP][0];
886 
887 	if(bWifiConnected)
888 	{
889 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi connected!!\n"));
890 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
891 
892 		if( !bWifiBusy &&
893 			((BT_STATE_8723A_1ANT_NO_CONNECTION == btState) ||
894 			(BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)) )
895 		{
896 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], [Wifi is idle] or [Bt is non connected idle or Bt is connected idle]!!\n"));
897 
898 			if(BT_STATE_8723A_1ANT_NO_CONNECTION == btState)
899 				halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);
900 			else if(BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)
901 				halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
902 
903 			pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);
904 		}
905 		else
906 		{
907 			if( (BT_STATE_8723A_1ANT_SCO_ONLY_BUSY == btState) ||
908 				(BT_STATE_8723A_1ANT_ACL_SCO_BUSY == btState) ||
909 				(BT_STATE_8723A_1ANT_HID_BUSY == btState) ||
910 				(BT_STATE_8723A_1ANT_HID_SCO_BUSY == btState) )
911 			{
912 				pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0x60);
913 			}
914 			else
915 			{
916 				pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);
917 			}
918 			switch(btState)
919 			{
920 				case BT_STATE_8723A_1ANT_NO_CONNECTION:
921 					halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
922 					break;
923 				case BT_STATE_8723A_1ANT_CONNECT_IDLE:
924 					halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);
925 					break;
926 				case BT_STATE_8723A_1ANT_INQ_OR_PAG:
927 					halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);
928 					break;
929 				case BT_STATE_8723A_1ANT_SCO_ONLY_BUSY:
930 				case BT_STATE_8723A_1ANT_ACL_SCO_BUSY:
931 				case BT_STATE_8723A_1ANT_HID_BUSY:
932 				case BT_STATE_8723A_1ANT_HID_SCO_BUSY:
933 					halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist);
934 					break;
935 				case BT_STATE_8723A_1ANT_ACL_ONLY_BUSY:
936 					if (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP)
937 					{
938 						halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist);
939 					}
940 					else if(btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP)
941 					{
942 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
943 					}
944 					else if( (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP) &&
945 							(btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP) )
946 					{
947 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
948 					}
949 					else
950 					{
951 						halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
952 					}
953 					break;
954 				default:
955 					RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], error!!!, undefined case in halbtc8723a1ant_CoexForWifiConnect()!!\n"));
956 					break;
957 			}
958 		}
959 	}
960 	else
961 	{
962 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is disconnected!!\n"));
963 	}
964 
965 	pCoexDm->psTdmaGlobalCnt++;
966 }
967 
968 //============================================================
969 // work around function start with wa_halbtc8723a1ant_
970 //============================================================
971 VOID
wa_halbtc8723a1ant_MonitorC2h(IN PBTC_COEXIST pBtCoexist)972 wa_halbtc8723a1ant_MonitorC2h(
973 	IN	PBTC_COEXIST			pBtCoexist
974 	)
975 {
976 	u1Byte	tmp1b=0x0;
977 	u4Byte	curC2hTotalCnt=0x0;
978 	static u4Byte	preC2hTotalCnt=0x0, sameCntPollingTime=0x0;
979 
980 	curC2hTotalCnt+=pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8723A_1ANT_BT_RSP];
981 
982 	if(curC2hTotalCnt == preC2hTotalCnt)
983 	{
984 		sameCntPollingTime++;
985 	}
986 	else
987 	{
988 		preC2hTotalCnt = curC2hTotalCnt;
989 		sameCntPollingTime = 0;
990 	}
991 
992 	if(sameCntPollingTime >= 2)
993 	{
994 		tmp1b = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x1af);
995 		if(tmp1b != 0x0)
996 		{
997 			pCoexSta->c2hHangDetectCnt++;
998 			pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x1af, 0x0);
999 		}
1000 	}
1001 }
1002 
1003 //============================================================
1004 // extern function start with EXhalbtc8723a1ant_
1005 //============================================================
1006 VOID
EXhalbtc8723a1ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist)1007 EXhalbtc8723a1ant_InitHwConfig(
1008 	IN	PBTC_COEXIST		pBtCoexist
1009 	)
1010 {
1011 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));
1012 
1013 	// backup rf 0x1e value
1014 	pCoexDm->btRf0x1eBackup =
1015 		pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);
1016 
1017 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);
1018 
1019 	// enable counter statistics
1020 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
1021 
1022 	// coex table
1023 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, 0x0);			// 1-Ant coex
1024 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, 0xffff);		// wifi break table
1025 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, 0x55555555);	//coex table
1026 
1027 	// antenna switch control parameter
1028 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x858, 0xaaaaaaaa);
1029 
1030 	pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x210);	//set antenna at wifi side if ANTSW is software control
1031 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x870, 0x300);	//SPDT(connected with TRSW) control by hardware PTA
1032 	pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x874, 0x22804000);	//ANTSW keep by GNT_BT
1033 
1034 	// coexistence parameters
1035 	pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);	// enable RTK mode PTA
1036 }
1037 
1038 VOID
EXhalbtc8723a1ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)1039 EXhalbtc8723a1ant_InitCoexDm(
1040 	IN	PBTC_COEXIST		pBtCoexist
1041 	)
1042 {
1043 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
1044 
1045 	halbtc8723a1ant_InitCoexDm(pBtCoexist);
1046 }
1047 
1048 VOID
EXhalbtc8723a1ant_DisplayCoexInfo(IN PBTC_COEXIST pBtCoexist)1049 EXhalbtc8723a1ant_DisplayCoexInfo(
1050 	IN	PBTC_COEXIST		pBtCoexist
1051 	)
1052 {
1053 	PBTC_BOARD_INFO		pBoardInfo=&pBtCoexist->boardInfo;
1054 	PBTC_STACK_INFO		pStackInfo=&pBtCoexist->stackInfo;
1055 	pu1Byte				cliBuf=pBtCoexist->cliBuf;
1056 	u1Byte				u1Tmp[4], i, btInfoExt, psTdmaCase=0;
1057 	u4Byte				u4Tmp[4];
1058 
1059 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
1060 	CL_PRINTF(cliBuf);
1061 
1062 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
1063 		pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);
1064 	CL_PRINTF(cliBuf);
1065 
1066 	if(pBtCoexist->bManualControl)
1067 	{
1068 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
1069 		CL_PRINTF(cliBuf);
1070 	}
1071 
1072 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
1073 		((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
1074 	CL_PRINTF(cliBuf);
1075 
1076 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
1077 		pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
1078 		pCoexDm->wifiChnlInfo[2]);
1079 	CL_PRINTF(cliBuf);
1080 
1081 	// wifi status
1082 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
1083 	CL_PRINTF(cliBuf);
1084 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
1085 
1086 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
1087 	CL_PRINTF(cliBuf);
1088 
1089 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \
1090 		((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723A_1ANT_BT_STATUS_IDLE == pCoexDm->btStatus)? "idle":(  (BT_8723A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy"))),
1091 		pCoexSta->btRssi, pCoexSta->btRetryCnt);
1092 	CL_PRINTF(cliBuf);
1093 
1094 	if(pStackInfo->bProfileNotified)
1095 	{
1096 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
1097 			pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);
1098 		CL_PRINTF(cliBuf);
1099 
1100 		pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
1101 	}
1102 
1103 	btInfoExt = pCoexSta->btInfoExt;
1104 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \
1105 		(btInfoExt&BIT0)? "Basic rate":"EDR rate");
1106 	CL_PRINTF(cliBuf);
1107 
1108 	for(i=0; i<BT_INFO_SRC_8723A_1ANT_MAX; i++)
1109 	{
1110 		if(pCoexSta->btInfoC2hCnt[i])
1111 		{
1112 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723a1Ant[i], \
1113 				pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
1114 				pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
1115 				pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
1116 				pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
1117 			CL_PRINTF(cliBuf);
1118 		}
1119 	}
1120 
1121 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "write 0x1af=0x0 num", \
1122 		pCoexSta->c2hHangDetectCnt);
1123 	CL_PRINTF(cliBuf);
1124 
1125 	// Sw mechanism
1126 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
1127 	CL_PRINTF(cliBuf);
1128 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "SM1[ShRf/ LpRA/ LimDig]", \
1129 		pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);
1130 	CL_PRINTF(cliBuf);
1131 
1132 	// Fw mechanism
1133 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
1134 	CL_PRINTF(cliBuf);
1135 
1136 	if(!pBtCoexist->bManualControl)
1137 	{
1138 		psTdmaCase = pCoexDm->curPsTdma;
1139 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \
1140 			pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
1141 			pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
1142 			pCoexDm->psTdmaPara[4], psTdmaCase);
1143 		CL_PRINTF(cliBuf);
1144 
1145 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \
1146 			pCoexDm->bCurIgnoreWlanAct);
1147 		CL_PRINTF(cliBuf);
1148 	}
1149 
1150 	// Hw setting
1151 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
1152 	CL_PRINTF(cliBuf);
1153 
1154 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
1155 		pCoexDm->btRf0x1eBackup);
1156 	CL_PRINTF(cliBuf);
1157 
1158 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
1159 	u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x783);
1160 	u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x796);
1161 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
1162 		u1Tmp[0], u1Tmp[1], u1Tmp[2]);
1163 	CL_PRINTF(cliBuf);
1164 
1165 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
1166 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
1167 		u4Tmp[0]);
1168 	CL_PRINTF(cliBuf);
1169 
1170 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
1171 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
1172 		u1Tmp[0]);
1173 	CL_PRINTF(cliBuf);
1174 
1175 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
1176 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
1177 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
1178 		u4Tmp[0], u1Tmp[0]);
1179 	CL_PRINTF(cliBuf);
1180 
1181 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x484);
1182 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
1183 		u4Tmp[0]);
1184 	CL_PRINTF(cliBuf);
1185 
1186 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
1187 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
1188 		u4Tmp[0]);
1189 	CL_PRINTF(cliBuf);
1190 
1191 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
1192 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
1193 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
1194 	u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xdac);
1195 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
1196 		u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
1197 	CL_PRINTF(cliBuf);
1198 
1199 	u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
1200 	u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
1201 	u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
1202 	u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);
1203 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
1204 		u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);
1205 	CL_PRINTF(cliBuf);
1206 
1207 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770 (hp rx[31:16]/tx[15:0])", \
1208 		pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
1209 	CL_PRINTF(cliBuf);
1210 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \
1211 		pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
1212 	CL_PRINTF(cliBuf);
1213 
1214 	pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
1215 }
1216 
1217 
1218 VOID
EXhalbtc8723a1ant_IpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1219 EXhalbtc8723a1ant_IpsNotify(
1220 	IN	PBTC_COEXIST		pBtCoexist,
1221 	IN	u1Byte			type
1222 	)
1223 {
1224 	if(BTC_IPS_ENTER == type)
1225 	{
1226 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
1227 		halbtc8723a1ant_CoexAllOff(pBtCoexist);
1228 	}
1229 	else if(BTC_IPS_LEAVE == type)
1230 	{
1231 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
1232 		//halbtc8723a1ant_InitCoexDm(pBtCoexist);
1233 	}
1234 }
1235 
1236 VOID
EXhalbtc8723a1ant_LpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1237 EXhalbtc8723a1ant_LpsNotify(
1238 	IN	PBTC_COEXIST		pBtCoexist,
1239 	IN	u1Byte			type
1240 	)
1241 {
1242 	if(BTC_LPS_ENABLE == type)
1243 	{
1244 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
1245 	}
1246 	else if(BTC_LPS_DISABLE == type)
1247 	{
1248 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
1249 		halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
1250 	}
1251 }
1252 
1253 VOID
EXhalbtc8723a1ant_ScanNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1254 EXhalbtc8723a1ant_ScanNotify(
1255 	IN	PBTC_COEXIST		pBtCoexist,
1256 	IN	u1Byte			type
1257 	)
1258 {
1259 	BOOLEAN		bWifiConnected=FALSE;
1260 
1261 	halbtc8723a1ant_NotifyFwScan(pBtCoexist, type);
1262 
1263 	if(pBtCoexist->btInfo.bBtDisabled)
1264 	{
1265 		halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);
1266 	}
1267 	else
1268 	{
1269 		pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1270 		if(BTC_SCAN_START == type)
1271 		{
1272 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
1273 			if(!bWifiConnected)	// non-connected scan
1274 			{
1275 				//set 0x550[3]=1 before PsTdma
1276 				halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE);
1277 			}
1278 
1279 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
1280 		}
1281 		else if(BTC_SCAN_FINISH == type)
1282 		{
1283 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
1284 			if(!bWifiConnected)	// non-connected scan
1285 			{
1286 				halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1287 			}
1288 			else
1289 			{
1290 				halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);
1291 			}
1292 		}
1293 	}
1294 }
1295 
1296 VOID
EXhalbtc8723a1ant_ConnectNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1297 EXhalbtc8723a1ant_ConnectNotify(
1298 	IN	PBTC_COEXIST		pBtCoexist,
1299 	IN	u1Byte			type
1300 	)
1301 {
1302 	BOOLEAN		bWifiConnected=FALSE;
1303 
1304 	if(pBtCoexist->btInfo.bBtDisabled)
1305 	{
1306 		halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);
1307 	}
1308 	else
1309 	{
1310 		if(BTC_ASSOCIATE_START == type)
1311 		{
1312 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
1313 			//set 0x550[3]=1 before PsTdma
1314 			halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE);
1315 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);	// extend wifi slot
1316 		}
1317 		else if(BTC_ASSOCIATE_FINISH == type)
1318 		{
1319 			RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
1320 			pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1321 			if(!bWifiConnected)	// non-connected scan
1322 			{
1323 				halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1324 			}
1325 			else
1326 			{
1327 				halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);
1328 			}
1329 		}
1330 	}
1331 }
1332 
1333 VOID
EXhalbtc8723a1ant_MediaStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1334 EXhalbtc8723a1ant_MediaStatusNotify(
1335 	IN	PBTC_COEXIST			pBtCoexist,
1336 	IN	u1Byte				type
1337 	)
1338 {
1339 	if(BTC_MEDIA_CONNECT == type)
1340 	{
1341 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
1342 	}
1343 	else
1344 	{
1345 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
1346 	}
1347 }
1348 
1349 VOID
EXhalbtc8723a1ant_SpecialPacketNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)1350 EXhalbtc8723a1ant_SpecialPacketNotify(
1351 	IN	PBTC_COEXIST			pBtCoexist,
1352 	IN	u1Byte				type
1353 	)
1354 {
1355 	if(type == BTC_PACKET_DHCP)
1356 	{
1357 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));
1358 		if(pBtCoexist->btInfo.bBtDisabled)
1359 		{
1360 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);
1361 		}
1362 		else
1363 		{
1364 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 18);
1365 		}
1366 	}
1367 }
1368 
1369 VOID
EXhalbtc8723a1ant_BtInfoNotify(IN PBTC_COEXIST pBtCoexist,IN pu1Byte tmpBuf,IN u1Byte length)1370 EXhalbtc8723a1ant_BtInfoNotify(
1371 	IN	PBTC_COEXIST		pBtCoexist,
1372 	IN	pu1Byte			tmpBuf,
1373 	IN	u1Byte			length
1374 	)
1375 {
1376 	u1Byte			btInfo=0;
1377 	u1Byte			i, rspSource=0;
1378 	BOOLEAN			bBtHsOn=FALSE, bBtBusy=FALSE, bForceLps=FALSE;
1379 
1380 	pCoexSta->bC2hBtInfoReqSent = FALSE;
1381 
1382 	rspSource = BT_INFO_SRC_8723A_1ANT_BT_RSP;
1383 	pCoexSta->btInfoC2hCnt[rspSource]++;
1384 
1385 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
1386 	for(i=0; i<length; i++)
1387 	{
1388 		pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
1389 		if(i == 0)
1390 			btInfo = tmpBuf[i];
1391 		if(i == length-1)
1392 		{
1393 			RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
1394 		}
1395 		else
1396 		{
1397 			RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
1398 		}
1399 	}
1400 
1401 	if(BT_INFO_SRC_8723A_1ANT_WIFI_FW != rspSource)
1402 	{
1403 		pCoexSta->btRetryCnt =
1404 			pCoexSta->btInfoC2h[rspSource][1];
1405 
1406 		pCoexSta->btRssi =
1407 			pCoexSta->btInfoC2h[rspSource][2]*2+10;
1408 
1409 		pCoexSta->btInfoExt =
1410 			pCoexSta->btInfoC2h[rspSource][3];
1411 	}
1412 
1413 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1414 	// check BIT2 first ==> check if bt is under inquiry or page scan
1415 	if(btInfo & BT_INFO_8723A_1ANT_B_INQ_PAGE)
1416 	{
1417 		pCoexSta->bC2hBtInquiryPage = TRUE;
1418 	}
1419 	else
1420 	{
1421 		pCoexSta->bC2hBtInquiryPage = FALSE;
1422 	}
1423 	btInfo &= ~BIT2;
1424 	if(!(btInfo & BIT0))
1425 	{
1426 		pCoexDm->btStatus = BT_STATE_8723A_1ANT_NO_CONNECTION;
1427 		bForceLps = FALSE;
1428 	}
1429 	else
1430 	{
1431 		bForceLps = TRUE;
1432 		if(btInfo == 0x1)
1433 		{
1434 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_CONNECT_IDLE;
1435 		}
1436 		else if(btInfo == 0x9)
1437 		{
1438 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_ACL_ONLY_BUSY;
1439 			bBtBusy = TRUE;
1440 		}
1441 		else if(btInfo == 0x13)
1442 		{
1443 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_SCO_ONLY_BUSY;
1444 			bBtBusy = TRUE;
1445 		}
1446 		else if(btInfo == 0x1b)
1447 		{
1448 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_ACL_SCO_BUSY;
1449 			bBtBusy = TRUE;
1450 		}
1451 		else if(btInfo == 0x29)
1452 		{
1453 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_HID_BUSY;
1454 			bBtBusy = TRUE;
1455 		}
1456 		else if(btInfo == 0x3b)
1457 		{
1458 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_HID_SCO_BUSY;
1459 			bBtBusy = TRUE;
1460 		}
1461 	}
1462 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
1463 	pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bBtBusy);
1464 	if(bForceLps)
1465 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1466 	else
1467 		pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1468 
1469 	if( (BT_STATE_8723A_1ANT_NO_CONNECTION == pCoexDm->btStatus) ||
1470 		(BT_STATE_8723A_1ANT_CONNECT_IDLE == pCoexDm->btStatus) )
1471 	{
1472 		if(pCoexSta->bC2hBtInquiryPage)
1473 			pCoexDm->btStatus = BT_STATE_8723A_1ANT_INQ_OR_PAG;
1474 	}
1475 }
1476 
1477 VOID
EXhalbtc8723a1ant_HaltNotify(IN PBTC_COEXIST pBtCoexist)1478 EXhalbtc8723a1ant_HaltNotify(
1479 	IN	PBTC_COEXIST			pBtCoexist
1480 	)
1481 {
1482 	halbtc8723a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
1483 
1484 	halbtc8723a1ant_LowPenaltyRa(pBtCoexist, FORCE_EXEC, FALSE);
1485 	halbtc8723a1ant_RfShrink(pBtCoexist, FORCE_EXEC, FALSE);
1486 
1487 	halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
1488 	EXhalbtc8723a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
1489 }
1490 
1491 VOID
EXhalbtc8723a1ant_Periodical(IN PBTC_COEXIST pBtCoexist)1492 EXhalbtc8723a1ant_Periodical(
1493 	IN	PBTC_COEXIST			pBtCoexist
1494 	)
1495 {
1496 	BOOLEAN		bScan=FALSE, bLink=FALSE, bRoam=FALSE, bWifiConnected=FALSE;
1497 
1498 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Periodical!!\n"));
1499 
1500 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1501 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1502 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1503 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1504 
1505 	// work around for c2h hang
1506 	wa_halbtc8723a1ant_MonitorC2h(pBtCoexist);
1507 
1508 	halbtc8723a1ant_QueryBtInfo(pBtCoexist);
1509 	halbtc8723a1ant_MonitorBtCtr(pBtCoexist);
1510 	halbtc8723a1ant_MonitorBtEnableDisable(pBtCoexist);
1511 
1512 
1513 	if(bScan)
1514 		return;
1515 	if(bLink)
1516 		return;
1517 
1518 	if(bWifiConnected)
1519 	{
1520 		if(pBtCoexist->btInfo.bBtDisabled)
1521 		{
1522 			halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);
1523 
1524 			halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);
1525 			halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);
1526 		}
1527 		else
1528 		{
1529 			halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);
1530 			halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);
1531 			halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);
1532 		}
1533 	}
1534 	else
1535 	{
1536 		halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
1537 
1538 		halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);
1539 		halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);
1540 	}
1541 }
1542 
1543 
1544 #endif
1545 
1546