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