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