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