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