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