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