linux/drivers/net/wireless/rtlwifi/rtl8723ae/hal_bt_coexist.c
<<
>>
Prefs
   1/******************************************************************************
   2 *
   3 * Copyright(c) 2009-2012  Realtek Corporation.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms of version 2 of the GNU General Public License as
   7 * published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  12 * more details.
  13 *
  14 * You should have received a copy of the GNU General Public License along with
  15 * this program; if not, write to the Free Software Foundation, Inc.,
  16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17 *
  18 * The full GNU General Public License is included in this distribution in the
  19 * file called LICENSE.
  20 *
  21 * Contact Information:
  22 * wlanfae <wlanfae@realtek.com>
  23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24 * Hsinchu 300, Taiwan.
  25 *
  26 * Larry Finger <Larry.Finger@lwfinger.net>
  27 *
  28 *****************************************************************************/
  29
  30#include "hal_bt_coexist.h"
  31#include "../pci.h"
  32#include "dm.h"
  33#include "fw.h"
  34#include "../rtl8723com/fw_common.h"
  35#include "phy.h"
  36#include "reg.h"
  37#include "hal_btc.h"
  38
  39void rtl8723ae_dm_bt_reject_ap_aggregated_packet(struct ieee80211_hw *hw,
  40                                                 bool reject)
  41{
  42}
  43
  44void _rtl8723_dm_bt_check_wifi_state(struct ieee80211_hw *hw)
  45{
  46        struct rtl_priv *rtlpriv = rtl_priv(hw);
  47        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  48        struct rtl_phy *rtlphy = &(rtlpriv->phy);
  49
  50        if (rtlpriv->link_info.busytraffic) {
  51                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_WIFI_IDLE;
  52
  53                if (rtlpriv->link_info.tx_busy_traffic)
  54                        rtlpcipriv->bt_coexist.cstate |=
  55                                        BT_COEX_STATE_WIFI_UPLINK;
  56                else
  57                        rtlpcipriv->bt_coexist.cstate &=
  58                                        ~BT_COEX_STATE_WIFI_UPLINK;
  59
  60                if (rtlpriv->link_info.rx_busy_traffic)
  61                        rtlpcipriv->bt_coexist.cstate |=
  62                                        BT_COEX_STATE_WIFI_DOWNLINK;
  63                else
  64                        rtlpcipriv->bt_coexist.cstate &=
  65                                        ~BT_COEX_STATE_WIFI_DOWNLINK;
  66        } else {
  67                rtlpcipriv->bt_coexist.cstate |= BT_COEX_STATE_WIFI_IDLE;
  68                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_WIFI_UPLINK;
  69                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_WIFI_DOWNLINK;
  70        }
  71
  72        if (rtlpriv->mac80211.mode == WIRELESS_MODE_G ||
  73            rtlpriv->mac80211.mode == WIRELESS_MODE_B) {
  74                rtlpcipriv->bt_coexist.cstate |= BT_COEX_STATE_WIFI_LEGACY;
  75                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_WIFI_HT20;
  76                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_WIFI_HT40;
  77        } else {
  78                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_WIFI_LEGACY;
  79                if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
  80                        rtlpcipriv->bt_coexist.cstate |=
  81                                        BT_COEX_STATE_WIFI_HT40;
  82                        rtlpcipriv->bt_coexist.cstate &=
  83                                        ~BT_COEX_STATE_WIFI_HT20;
  84                } else {
  85                        rtlpcipriv->bt_coexist.cstate |=
  86                                        BT_COEX_STATE_WIFI_HT20;
  87                        rtlpcipriv->bt_coexist.cstate &=
  88                                        ~BT_COEX_STATE_WIFI_HT40;
  89                }
  90        }
  91
  92        if (rtlpriv->bt_operation_on)
  93                rtlpcipriv->bt_coexist.cstate |= BT_COEX_STATE_BT30;
  94        else
  95                rtlpcipriv->bt_coexist.cstate &= ~BT_COEX_STATE_BT30;
  96}
  97
  98u8 rtl8723ae_dm_bt_check_coex_rssi_state1(struct ieee80211_hw *hw,
  99                                          u8 level_num, u8 rssi_thresh,
 100                                          u8 rssi_thresh1)
 101
 102{
 103        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 104        struct rtl_priv *rtlpriv = rtl_priv(hw);
 105        long smooth;
 106        u8 bt_rssi_state = 0;
 107
 108        smooth =  rtl8723ae_dm_bt_get_rx_ss(hw);
 109
 110        if (level_num == 2) {
 111                rtlpcipriv->bt_coexist.cstate &=
 112                                ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
 113
 114                if ((rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 115                    BT_RSSI_STATE_LOW) ||
 116                    (rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 117                    BT_RSSI_STATE_STAY_LOW)) {
 118                        if (smooth >= (rssi_thresh +
 119                            BT_FW_COEX_THRESH_TOL)) {
 120                                bt_rssi_state = BT_RSSI_STATE_HIGH;
 121                                rtlpcipriv->bt_coexist.cstate |=
 122                                        BT_COEX_STATE_WIFI_RSSI_1_HIGH;
 123                                rtlpcipriv->bt_coexist.cstate &=
 124                                        ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
 125                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 126                                         "[DM][BT], RSSI_1 state switch to High\n");
 127                        } else {
 128                                bt_rssi_state = BT_RSSI_STATE_STAY_LOW;
 129                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 130                                         "[DM][BT], RSSI_1 state stay at Low\n");
 131                        }
 132                } else {
 133                        if (smooth < rssi_thresh) {
 134                                bt_rssi_state = BT_RSSI_STATE_LOW;
 135                                rtlpcipriv->bt_coexist.cstate |=
 136                                         BT_COEX_STATE_WIFI_RSSI_1_LOW;
 137                                rtlpcipriv->bt_coexist.cstate &=
 138                                         ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
 139                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 140                                         "[DM][BT], RSSI_1 state switch to Low\n");
 141                        } else {
 142                                bt_rssi_state = BT_RSSI_STATE_STAY_HIGH;
 143                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 144                                         "[DM][BT], RSSI_1 state stay at High\n");
 145                        }
 146                }
 147        } else if (level_num == 3) {
 148                if (rssi_thresh > rssi_thresh1) {
 149                        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 150                                 "[DM][BT], RSSI_1 thresh error!!\n");
 151                        return rtlpcipriv->bt_coexist.bt_pre_rssi_state;
 152                }
 153
 154                if ((rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 155                    BT_RSSI_STATE_LOW) ||
 156                    (rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 157                    BT_RSSI_STATE_STAY_LOW)) {
 158                        if (smooth >=
 159                            (rssi_thresh+BT_FW_COEX_THRESH_TOL)) {
 160                                bt_rssi_state = BT_RSSI_STATE_MEDIUM;
 161                                rtlpcipriv->bt_coexist.cstate |=
 162                                         BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
 163                                rtlpcipriv->bt_coexist.cstate &=
 164                                         ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
 165                                rtlpcipriv->bt_coexist.cstate &=
 166                                         ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
 167                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 168                                         "[DM][BT], RSSI_1 state switch to Medium\n");
 169                        } else {
 170                                bt_rssi_state = BT_RSSI_STATE_STAY_LOW;
 171                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 172                                         "[DM][BT], RSSI_1 state stay at Low\n");
 173                        }
 174                } else if ((rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 175                           BT_RSSI_STATE_MEDIUM) ||
 176                           (rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 177                           BT_RSSI_STATE_STAY_MEDIUM)) {
 178                        if (smooth >= (rssi_thresh1 +
 179                            BT_FW_COEX_THRESH_TOL)) {
 180                                bt_rssi_state = BT_RSSI_STATE_HIGH;
 181                                rtlpcipriv->bt_coexist.cstate |=
 182                                         BT_COEX_STATE_WIFI_RSSI_1_HIGH;
 183                                rtlpcipriv->bt_coexist.cstate &=
 184                                         ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
 185                                rtlpcipriv->bt_coexist.cstate &=
 186                                         ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
 187                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 188                                         "[DM][BT], RSSI_1 state switch to High\n");
 189                        } else if (smooth < rssi_thresh) {
 190                                bt_rssi_state = BT_RSSI_STATE_LOW;
 191                                rtlpcipriv->bt_coexist.cstate |=
 192                                        BT_COEX_STATE_WIFI_RSSI_1_LOW;
 193                                rtlpcipriv->bt_coexist.cstate &=
 194                                        ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
 195                                rtlpcipriv->bt_coexist.cstate &=
 196                                        ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
 197                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 198                                         "[DM][BT], RSSI_1 state switch to Low\n");
 199                        } else {
 200                                bt_rssi_state = BT_RSSI_STATE_STAY_MEDIUM;
 201                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 202                                         "[DM][BT], RSSI_1 state stay at Medium\n");
 203                        }
 204                } else {
 205                        if (smooth < rssi_thresh1) {
 206                                bt_rssi_state = BT_RSSI_STATE_MEDIUM;
 207                                rtlpcipriv->bt_coexist.cstate |=
 208                                        BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
 209                                rtlpcipriv->bt_coexist.cstate &=
 210                                        ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
 211                                rtlpcipriv->bt_coexist.cstate &=
 212                                        ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
 213                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 214                                         "[DM][BT], RSSI_1 state switch to Medium\n");
 215                        } else {
 216                                bt_rssi_state = BT_RSSI_STATE_STAY_HIGH;
 217                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 218                                         "[DM][BT], RSSI_1 state stay at High\n");
 219                        }
 220                }
 221        }
 222
 223        rtlpcipriv->bt_coexist.bt_pre_rssi_state1 = bt_rssi_state;
 224
 225        return bt_rssi_state;
 226}
 227
 228u8 rtl8723ae_dm_bt_check_coex_rssi_state(struct ieee80211_hw *hw,
 229                                         u8 level_num, u8 rssi_thresh,
 230                                         u8 rssi_thresh1)
 231{
 232        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 233        struct rtl_priv *rtlpriv = rtl_priv(hw);
 234        long smooth;
 235        u8 bt_rssi_state = 0;
 236
 237        smooth = rtl8723ae_dm_bt_get_rx_ss(hw);
 238
 239        if (level_num == 2) {
 240                rtlpcipriv->bt_coexist.cstate &=
 241                                         ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
 242
 243                if ((rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 244                    BT_RSSI_STATE_LOW) ||
 245                    (rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 246                    BT_RSSI_STATE_STAY_LOW)){
 247                        if (smooth >=
 248                            (rssi_thresh + BT_FW_COEX_THRESH_TOL)) {
 249                                bt_rssi_state = BT_RSSI_STATE_HIGH;
 250                                rtlpcipriv->bt_coexist.cstate |=
 251                                        BT_COEX_STATE_WIFI_RSSI_HIGH;
 252                                rtlpcipriv->bt_coexist.cstate &=
 253                                        ~BT_COEX_STATE_WIFI_RSSI_LOW;
 254                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 255                                         "[DM][BT], RSSI state switch to High\n");
 256                        } else {
 257                                bt_rssi_state = BT_RSSI_STATE_STAY_LOW;
 258                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 259                                         "[DM][BT], RSSI state stay at Low\n");
 260                        }
 261                } else {
 262                        if (smooth < rssi_thresh) {
 263                                bt_rssi_state = BT_RSSI_STATE_LOW;
 264                                rtlpcipriv->bt_coexist.cstate |=
 265                                        BT_COEX_STATE_WIFI_RSSI_LOW;
 266                                rtlpcipriv->bt_coexist.cstate &=
 267                                        ~BT_COEX_STATE_WIFI_RSSI_HIGH;
 268                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 269                                         "[DM][BT], RSSI state switch to Low\n");
 270                        } else {
 271                                bt_rssi_state = BT_RSSI_STATE_STAY_HIGH;
 272                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 273                                         "[DM][BT], RSSI state stay at High\n");
 274                        }
 275                }
 276        } else if (level_num == 3) {
 277                if (rssi_thresh > rssi_thresh1) {
 278                        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 279                                 "[DM][BT], RSSI thresh error!!\n");
 280                        return rtlpcipriv->bt_coexist.bt_pre_rssi_state;
 281                }
 282                if ((rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 283                    BT_RSSI_STATE_LOW) ||
 284                    (rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 285                    BT_RSSI_STATE_STAY_LOW)) {
 286                        if (smooth >=
 287                            (rssi_thresh + BT_FW_COEX_THRESH_TOL)) {
 288                                bt_rssi_state = BT_RSSI_STATE_MEDIUM;
 289                                rtlpcipriv->bt_coexist.cstate
 290                                        |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
 291                                rtlpcipriv->bt_coexist.cstate
 292                                        &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
 293                                rtlpcipriv->bt_coexist.cstate
 294                                        &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
 295                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 296                                         "[DM][BT], RSSI state switch to Medium\n");
 297                        } else {
 298                                bt_rssi_state = BT_RSSI_STATE_STAY_LOW;
 299                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 300                                         "[DM][BT], RSSI state stay at Low\n");
 301                        }
 302                } else if ((rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 303                           BT_RSSI_STATE_MEDIUM) ||
 304                           (rtlpcipriv->bt_coexist.bt_pre_rssi_state ==
 305                           BT_RSSI_STATE_STAY_MEDIUM)) {
 306                        if (smooth >=
 307                            (rssi_thresh1 + BT_FW_COEX_THRESH_TOL)) {
 308                                bt_rssi_state = BT_RSSI_STATE_HIGH;
 309                                rtlpcipriv->bt_coexist.cstate
 310                                        |= BT_COEX_STATE_WIFI_RSSI_HIGH;
 311                                rtlpcipriv->bt_coexist.cstate
 312                                        &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
 313                                rtlpcipriv->bt_coexist.cstate
 314                                        &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
 315                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 316                                         "[DM][BT], RSSI state switch to High\n");
 317                        } else if (smooth < rssi_thresh) {
 318                                bt_rssi_state = BT_RSSI_STATE_LOW;
 319                                rtlpcipriv->bt_coexist.cstate
 320                                        |= BT_COEX_STATE_WIFI_RSSI_LOW;
 321                                rtlpcipriv->bt_coexist.cstate
 322                                        &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
 323                                rtlpcipriv->bt_coexist.cstate
 324                                        &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
 325                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 326                                         "[DM][BT], RSSI state switch to Low\n");
 327                        } else {
 328                                bt_rssi_state = BT_RSSI_STATE_STAY_MEDIUM;
 329                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 330                                         "[DM][BT], RSSI state stay at Medium\n");
 331                        }
 332                } else {
 333                        if (smooth < rssi_thresh1) {
 334                                bt_rssi_state = BT_RSSI_STATE_MEDIUM;
 335                                rtlpcipriv->bt_coexist.cstate
 336                                        |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
 337                                rtlpcipriv->bt_coexist.cstate
 338                                        &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
 339                                rtlpcipriv->bt_coexist.cstate
 340                                        &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
 341                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 342                                         "[DM][BT], RSSI state switch to Medium\n");
 343                        } else {
 344                                bt_rssi_state = BT_RSSI_STATE_STAY_HIGH;
 345                                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 346                                         "[DM][BT], RSSI state stay at High\n");
 347                        }
 348                }
 349        }
 350
 351        rtlpcipriv->bt_coexist.bt_pre_rssi_state = bt_rssi_state;
 352        return bt_rssi_state;
 353}
 354
 355long rtl8723ae_dm_bt_get_rx_ss(struct ieee80211_hw *hw)
 356{
 357        struct rtl_priv *rtlpriv = rtl_priv(hw);
 358        long smooth = 0;
 359
 360        if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
 361                smooth = GET_UNDECORATED_AVERAGE_RSSI(rtlpriv);
 362        else
 363                smooth = rtlpriv->dm.entry_min_undec_sm_pwdb;
 364
 365        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 366                 "rtl8723ae_dm_bt_get_rx_ss() = %ld\n", smooth);
 367
 368        return smooth;
 369}
 370
 371void rtl8723ae_dm_bt_balance(struct ieee80211_hw *hw,
 372                             bool balance_on, u8 ms0, u8 ms1)
 373{
 374        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 375        struct rtl_priv *rtlpriv = rtl_priv(hw);
 376        u8 h2c_parameter[3] = {0};
 377
 378        if (balance_on) {
 379                h2c_parameter[2] = 1;
 380                h2c_parameter[1] = ms1;
 381                h2c_parameter[0] = ms0;
 382                rtlpcipriv->bt_coexist.fw_coexist_all_off = false;
 383        } else {
 384                h2c_parameter[2] = 0;
 385                h2c_parameter[1] = 0;
 386                h2c_parameter[0] = 0;
 387        }
 388        rtlpcipriv->bt_coexist.balance_on = balance_on;
 389
 390        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 391                 "[DM][BT], Balance=[%s:%dms:%dms], write 0xc=0x%x\n",
 392                 balance_on ? "ON" : "OFF", ms0, ms1,
 393                 h2c_parameter[0]<<16 | h2c_parameter[1]<<8 | h2c_parameter[2]);
 394
 395        rtl8723ae_fill_h2c_cmd(hw, 0xc, 3, h2c_parameter);
 396}
 397
 398
 399void rtl8723ae_dm_bt_agc_table(struct ieee80211_hw *hw, u8 type)
 400{
 401        struct rtl_priv *rtlpriv = rtl_priv(hw);
 402        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 403
 404        if (type == BT_AGCTABLE_OFF) {
 405                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 406                         "[BT]AGCTable Off!\n");
 407                rtl_write_dword(rtlpriv, 0xc78, 0x641c0001);
 408                rtl_write_dword(rtlpriv, 0xc78, 0x631d0001);
 409                rtl_write_dword(rtlpriv, 0xc78, 0x621e0001);
 410                rtl_write_dword(rtlpriv, 0xc78, 0x611f0001);
 411                rtl_write_dword(rtlpriv, 0xc78, 0x60200001);
 412
 413                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 414                                        RF_RX_AGC_HP, 0xfffff, 0x32000);
 415                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 416                                        RF_RX_AGC_HP, 0xfffff, 0x71000);
 417                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 418                                        RF_RX_AGC_HP, 0xfffff, 0xb0000);
 419                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 420                                        RF_RX_AGC_HP, 0xfffff, 0xfc000);
 421                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 422                                        RF_RX_G1, 0xfffff, 0x30355);
 423        } else if (type == BT_AGCTABLE_ON) {
 424                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 425                         "[BT]AGCTable On!\n");
 426                rtl_write_dword(rtlpriv, 0xc78, 0x4e1c0001);
 427                rtl_write_dword(rtlpriv, 0xc78, 0x4d1d0001);
 428                rtl_write_dword(rtlpriv, 0xc78, 0x4c1e0001);
 429                rtl_write_dword(rtlpriv, 0xc78, 0x4b1f0001);
 430                rtl_write_dword(rtlpriv, 0xc78, 0x4a200001);
 431
 432                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 433                                        RF_RX_AGC_HP, 0xfffff, 0xdc000);
 434                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 435                                        RF_RX_AGC_HP, 0xfffff, 0x90000);
 436                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 437                                        RF_RX_AGC_HP, 0xfffff, 0x51000);
 438                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 439                                        RF_RX_AGC_HP, 0xfffff, 0x12000);
 440                rtl8723ae_phy_set_rf_reg(hw, RF90_PATH_A,
 441                                        RF_RX_G1, 0xfffff, 0x00355);
 442
 443                rtlpcipriv->bt_coexist.sw_coexist_all_off = false;
 444        }
 445}
 446
 447void rtl8723ae_dm_bt_bback_off_level(struct ieee80211_hw *hw, u8 type)
 448{
 449        struct rtl_priv *rtlpriv = rtl_priv(hw);
 450        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 451
 452        if (type == BT_BB_BACKOFF_OFF) {
 453                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 454                         "[BT]BBBackOffLevel Off!\n");
 455                rtl_write_dword(rtlpriv, 0xc04, 0x3a05611);
 456        } else if (type == BT_BB_BACKOFF_ON) {
 457                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 458                         "[BT]BBBackOffLevel On!\n");
 459                rtl_write_dword(rtlpriv, 0xc04, 0x3a07611);
 460                rtlpcipriv->bt_coexist.sw_coexist_all_off = false;
 461        }
 462}
 463
 464void rtl8723ae_dm_bt_fw_coex_all_off(struct ieee80211_hw *hw)
 465{
 466        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 467        struct rtl_priv *rtlpriv = rtl_priv(hw);
 468        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 469                 "rtl8723ae_dm_bt_fw_coex_all_off()\n");
 470
 471        if (rtlpcipriv->bt_coexist.fw_coexist_all_off)
 472                return;
 473
 474        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 475                 "rtl8723ae_dm_bt_fw_coex_all_off(), real Do\n");
 476        rtl8723ae_dm_bt_fw_coex_all_off_8723a(hw);
 477        rtlpcipriv->bt_coexist.fw_coexist_all_off = true;
 478}
 479
 480void rtl8723ae_dm_bt_sw_coex_all_off(struct ieee80211_hw *hw)
 481{
 482        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 483        struct rtl_priv *rtlpriv = rtl_priv(hw);
 484
 485        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 486                 "rtl8723ae_dm_bt_sw_coex_all_off()\n");
 487
 488        if (rtlpcipriv->bt_coexist.sw_coexist_all_off)
 489                return;
 490
 491        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 492                 "rtl8723ae_dm_bt_sw_coex_all_off(), real Do\n");
 493        rtl8723ae_dm_bt_sw_coex_all_off_8723a(hw);
 494        rtlpcipriv->bt_coexist.sw_coexist_all_off = true;
 495}
 496
 497void rtl8723ae_dm_bt_hw_coex_all_off(struct ieee80211_hw *hw)
 498{
 499        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 500        struct rtl_priv *rtlpriv = rtl_priv(hw);
 501
 502        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 503                 "rtl8723ae_dm_bt_hw_coex_all_off()\n");
 504
 505        if (rtlpcipriv->bt_coexist.hw_coexist_all_off)
 506                return;
 507        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
 508                 "rtl8723ae_dm_bt_hw_coex_all_off(), real Do\n");
 509
 510        rtl8723ae_dm_bt_hw_coex_all_off_8723a(hw);
 511
 512        rtlpcipriv->bt_coexist.hw_coexist_all_off = true;
 513}
 514
 515void rtl8723ae_btdm_coex_all_off(struct ieee80211_hw *hw)
 516{
 517        rtl8723ae_dm_bt_fw_coex_all_off(hw);
 518        rtl8723ae_dm_bt_sw_coex_all_off(hw);
 519        rtl8723ae_dm_bt_hw_coex_all_off(hw);
 520}
 521
 522bool rtl8723ae_dm_bt_is_coexist_state_changed(struct ieee80211_hw *hw)
 523{
 524        struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
 525
 526        if ((rtlpcipriv->bt_coexist.previous_state ==
 527            rtlpcipriv->bt_coexist.cstate) &&
 528            (rtlpcipriv->bt_coexist.previous_state_h ==
 529            rtlpcipriv->bt_coexist.cstate_h))
 530                return false;
 531        else
 532                return true;
 533}
 534
 535bool rtl8723ae_dm_bt_is_wifi_up_link(struct ieee80211_hw *hw)
 536{
 537        struct rtl_priv *rtlpriv = rtl_priv(hw);
 538
 539        if (rtlpriv->link_info.tx_busy_traffic)
 540                return true;
 541        else
 542                return false;
 543}
 544