halbtc8723b1ant.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. /***************************************************************
  26. * Description:
  27. *
  28. * This file is for RTL8723B Co-exist mechanism
  29. *
  30. * History
  31. * 2012/11/15 Cosa first check in.
  32. *
  33. ***************************************************************/
  34. /***************************************************************
  35. * include files
  36. ***************************************************************/
  37. #include "halbt_precomp.h"
  38. /***************************************************************
  39. * Global variables, these are static variables
  40. ***************************************************************/
  41. static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant;
  42. static struct coex_dm_8723b_1ant *coex_dm = &glcoex_dm_8723b_1ant;
  43. static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant;
  44. static struct coex_sta_8723b_1ant *coex_sta = &glcoex_sta_8723b_1ant;
  45. static const char *const glbt_info_src_8723b_1ant[] = {
  46. "BT Info[wifi fw]",
  47. "BT Info[bt rsp]",
  48. "BT Info[bt auto report]",
  49. };
  50. static u32 glcoex_ver_date_8723b_1ant = 20130918;
  51. static u32 glcoex_ver_8723b_1ant = 0x47;
  52. /***************************************************************
  53. * local function proto type if needed
  54. ***************************************************************/
  55. /***************************************************************
  56. * local function start with halbtc8723b1ant_
  57. ***************************************************************/
  58. static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
  59. bool force_exec, u32 dis_rate_mask)
  60. {
  61. coex_dm->curra_mask = dis_rate_mask;
  62. if (force_exec || (coex_dm->prera_mask != coex_dm->curra_mask))
  63. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
  64. &coex_dm->curra_mask);
  65. coex_dm->prera_mask = coex_dm->curra_mask;
  66. }
  67. static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist,
  68. bool force_exec, u8 type)
  69. {
  70. bool wifi_under_bmode = false;
  71. coex_dm->cur_arfr_type = type;
  72. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  73. switch (coex_dm->cur_arfr_type) {
  74. case 0: /* normal mode */
  75. btcoexist->btc_write_4byte(btcoexist, 0x430,
  76. coex_dm->backup_arfr_cnt1);
  77. btcoexist->btc_write_4byte(btcoexist, 0x434,
  78. coex_dm->backup_arfr_cnt2);
  79. break;
  80. case 1:
  81. btcoexist->btc_get(btcoexist,
  82. BTC_GET_BL_WIFI_UNDER_B_MODE,
  83. &wifi_under_bmode);
  84. if (wifi_under_bmode) {
  85. btcoexist->btc_write_4byte(btcoexist,
  86. 0x430, 0x0);
  87. btcoexist->btc_write_4byte(btcoexist,
  88. 0x434, 0x01010101);
  89. } else {
  90. btcoexist->btc_write_4byte(btcoexist,
  91. 0x430, 0x0);
  92. btcoexist->btc_write_4byte(btcoexist,
  93. 0x434, 0x04030201);
  94. }
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  101. }
  102. static void halbtc8723b1ant_retry_limit(struct btc_coexist *btcoexist,
  103. bool force_exec, u8 type)
  104. {
  105. coex_dm->cur_retry_limit_type = type;
  106. if (force_exec || (coex_dm->pre_retry_limit_type !=
  107. coex_dm->cur_retry_limit_type)) {
  108. switch (coex_dm->cur_retry_limit_type) {
  109. case 0: /* normal mode */
  110. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  111. coex_dm->backup_retry_limit);
  112. break;
  113. case 1: /* retry limit = 8 */
  114. btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  121. }
  122. static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist *btcoexist,
  123. bool force_exec, u8 type)
  124. {
  125. coex_dm->cur_ampdu_time_type = type;
  126. if (force_exec || (coex_dm->pre_ampdu_time_type !=
  127. coex_dm->cur_ampdu_time_type)) {
  128. switch (coex_dm->cur_ampdu_time_type) {
  129. case 0: /* normal mode */
  130. btcoexist->btc_write_1byte(btcoexist, 0x456,
  131. coex_dm->backup_ampdu_max_time);
  132. break;
  133. case 1: /* AMPDU timw = 0x38 * 32us */
  134. btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
  135. break;
  136. default:
  137. break;
  138. }
  139. }
  140. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  141. }
  142. static void halbtc8723b1ant_limited_tx(struct btc_coexist *btcoexist,
  143. bool force_exec, u8 ra_masktype,
  144. u8 arfr_type, u8 retry_limit_type,
  145. u8 ampdu_time_type)
  146. {
  147. switch (ra_masktype) {
  148. case 0: /* normal mode */
  149. halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 0x0);
  150. break;
  151. case 1: /* disable cck 1/2 */
  152. halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
  153. 0x00000003);
  154. break;
  155. /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
  156. case 2:
  157. halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
  158. 0x0001f1f7);
  159. break;
  160. default:
  161. break;
  162. }
  163. btc8723b1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type);
  164. halbtc8723b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  165. halbtc8723b1ant_ampdu_maxtime(btcoexist, force_exec, ampdu_time_type);
  166. }
  167. static void halbtc8723b1ant_limited_rx(struct btc_coexist *btcoexist,
  168. bool force_exec, bool rej_ap_agg_pkt,
  169. bool bt_ctrl_agg_buf_size,
  170. u8 agg_buf_size)
  171. {
  172. bool reject_rx_agg = rej_ap_agg_pkt;
  173. bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  174. u8 rxaggsize = agg_buf_size;
  175. /**********************************************
  176. * Rx Aggregation related setting
  177. **********************************************/
  178. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  179. &reject_rx_agg);
  180. /* decide BT control aggregation buf size or not */
  181. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  182. &bt_ctrl_rx_agg_size);
  183. /* aggregation buf size, only work
  184. * when BT control Rx aggregation size.
  185. */
  186. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxaggsize);
  187. /* real update aggregation setting */
  188. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  189. }
  190. static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
  191. {
  192. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  193. u32 reg_hp_tx = 0, reg_hp_rx = 0;
  194. u32 reg_lp_tx = 0, reg_lp_rx = 0;
  195. reg_hp_txrx = 0x770;
  196. reg_lp_txrx = 0x774;
  197. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  198. reg_hp_tx = u32tmp & MASKLWORD;
  199. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  200. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  201. reg_lp_tx = u32tmp & MASKLWORD;
  202. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  203. coex_sta->high_priority_tx = reg_hp_tx;
  204. coex_sta->high_priority_rx = reg_hp_rx;
  205. coex_sta->low_priority_tx = reg_lp_tx;
  206. coex_sta->low_priority_rx = reg_lp_rx;
  207. /* reset counter */
  208. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  209. }
  210. static void halbtc8723b1ant_query_bt_info(struct btc_coexist *btcoexist)
  211. {
  212. struct rtl_priv *rtlpriv = btcoexist->adapter;
  213. u8 h2c_parameter[1] = {0};
  214. coex_sta->c2h_bt_info_req_sent = true;
  215. /* trigger */
  216. h2c_parameter[0] |= BIT0;
  217. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  218. "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
  219. h2c_parameter[0]);
  220. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  221. }
  222. static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
  223. {
  224. static bool pre_wifi_busy;
  225. static bool pre_under_4way, pre_bt_hs_on;
  226. bool wifi_busy = false, under_4way = false, bt_hs_on = false;
  227. bool wifi_connected = false;
  228. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  229. &wifi_connected);
  230. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  231. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  232. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  233. &under_4way);
  234. if (wifi_connected) {
  235. if (wifi_busy != pre_wifi_busy) {
  236. pre_wifi_busy = wifi_busy;
  237. return true;
  238. }
  239. if (under_4way != pre_under_4way) {
  240. pre_under_4way = under_4way;
  241. return true;
  242. }
  243. if (bt_hs_on != pre_bt_hs_on) {
  244. pre_bt_hs_on = bt_hs_on;
  245. return true;
  246. }
  247. }
  248. return false;
  249. }
  250. static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist *btcoexist)
  251. {
  252. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  253. bool bt_hs_on = false;
  254. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  255. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  256. bt_link_info->sco_exist = coex_sta->sco_exist;
  257. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  258. bt_link_info->pan_exist = coex_sta->pan_exist;
  259. bt_link_info->hid_exist = coex_sta->hid_exist;
  260. /* work around for HS mode. */
  261. if (bt_hs_on) {
  262. bt_link_info->pan_exist = true;
  263. bt_link_info->bt_link_exist = true;
  264. }
  265. /* check if Sco only */
  266. if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
  267. !bt_link_info->pan_exist && !bt_link_info->hid_exist)
  268. bt_link_info->sco_only = true;
  269. else
  270. bt_link_info->sco_only = false;
  271. /* check if A2dp only */
  272. if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
  273. !bt_link_info->pan_exist && !bt_link_info->hid_exist)
  274. bt_link_info->a2dp_only = true;
  275. else
  276. bt_link_info->a2dp_only = false;
  277. /* check if Pan only */
  278. if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
  279. bt_link_info->pan_exist && !bt_link_info->hid_exist)
  280. bt_link_info->pan_only = true;
  281. else
  282. bt_link_info->pan_only = false;
  283. /* check if Hid only */
  284. if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
  285. !bt_link_info->pan_exist && bt_link_info->hid_exist)
  286. bt_link_info->hid_only = true;
  287. else
  288. bt_link_info->hid_only = false;
  289. }
  290. static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist *btcoexist,
  291. bool low_penalty_ra)
  292. {
  293. struct rtl_priv *rtlpriv = btcoexist->adapter;
  294. u8 h2c_parameter[6] = {0};
  295. h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty */
  296. if (low_penalty_ra) {
  297. h2c_parameter[1] |= BIT0;
  298. /* normal rate except MCS7/6/5, OFDM54/48/36 */
  299. h2c_parameter[2] = 0x00;
  300. h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
  301. h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
  302. h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
  303. }
  304. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  305. "[BTCoex], set WiFi Low-Penalty Retry: %s",
  306. (low_penalty_ra ? "ON!!" : "OFF!!"));
  307. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  308. }
  309. static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist *btcoexist,
  310. bool force_exec, bool low_penalty_ra)
  311. {
  312. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  313. if (!force_exec) {
  314. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  315. return;
  316. }
  317. btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist,
  318. coex_dm->cur_low_penalty_ra);
  319. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  320. }
  321. static void halbtc8723b1ant_set_coex_table(struct btc_coexist *btcoexist,
  322. u32 val0x6c0, u32 val0x6c4,
  323. u32 val0x6c8, u8 val0x6cc)
  324. {
  325. struct rtl_priv *rtlpriv = btcoexist->adapter;
  326. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  327. "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
  328. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  329. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  330. "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
  331. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  332. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  333. "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
  334. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  335. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  336. "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
  337. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  338. }
  339. static void halbtc8723b1ant_coex_table(struct btc_coexist *btcoexist,
  340. bool force_exec, u32 val0x6c0,
  341. u32 val0x6c4, u32 val0x6c8,
  342. u8 val0x6cc)
  343. {
  344. struct rtl_priv *rtlpriv = btcoexist->adapter;
  345. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  346. "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
  347. (force_exec ? "force to" : ""),
  348. val0x6c0, val0x6c4, val0x6cc);
  349. coex_dm->cur_val0x6c0 = val0x6c0;
  350. coex_dm->cur_val0x6c4 = val0x6c4;
  351. coex_dm->cur_val0x6c8 = val0x6c8;
  352. coex_dm->cur_val0x6cc = val0x6cc;
  353. if (!force_exec) {
  354. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  355. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  356. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  357. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  358. return;
  359. }
  360. halbtc8723b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
  361. val0x6c8, val0x6cc);
  362. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  363. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  364. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  365. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  366. }
  367. static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist *btcoexist,
  368. bool force_exec, u8 type)
  369. {
  370. switch (type) {
  371. case 0:
  372. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  373. 0x55555555, 0xffffff, 0x3);
  374. break;
  375. case 1:
  376. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  377. 0x5a5a5a5a, 0xffffff, 0x3);
  378. break;
  379. case 2:
  380. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
  381. 0x5a5a5a5a, 0xffffff, 0x3);
  382. break;
  383. case 3:
  384. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  385. 0xaaaaaaaa, 0xffffff, 0x3);
  386. break;
  387. case 4:
  388. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  389. 0x5aaa5aaa, 0xffffff, 0x3);
  390. break;
  391. case 5:
  392. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
  393. 0xaaaa5a5a, 0xffffff, 0x3);
  394. break;
  395. case 6:
  396. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  397. 0xaaaa5a5a, 0xffffff, 0x3);
  398. break;
  399. case 7:
  400. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
  401. 0xaaaaaaaa, 0xffffff, 0x3);
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407. static void
  408. halbtc8723b1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
  409. bool enable)
  410. {
  411. struct rtl_priv *rtlpriv = btcoexist->adapter;
  412. u8 h2c_parameter[1] = {0};
  413. if (enable)
  414. h2c_parameter[0] |= BIT0; /* function enable */
  415. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  416. "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
  417. h2c_parameter[0]);
  418. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  419. }
  420. static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
  421. bool force_exec, bool enable)
  422. {
  423. struct rtl_priv *rtlpriv = btcoexist->adapter;
  424. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  425. "[BTCoex], %s turn Ignore WlanAct %s\n",
  426. (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
  427. coex_dm->cur_ignore_wlan_act = enable;
  428. if (!force_exec) {
  429. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  430. "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
  431. coex_dm->pre_ignore_wlan_act,
  432. coex_dm->cur_ignore_wlan_act);
  433. if (coex_dm->pre_ignore_wlan_act ==
  434. coex_dm->cur_ignore_wlan_act)
  435. return;
  436. }
  437. halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist, enable);
  438. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  439. }
  440. static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist,
  441. u8 byte1, u8 byte2, u8 byte3,
  442. u8 byte4, u8 byte5)
  443. {
  444. struct rtl_priv *rtlpriv = btcoexist->adapter;
  445. u8 h2c_parameter[5] = {0};
  446. u8 real_byte1 = byte1, real_byte5 = byte5;
  447. bool ap_enable = false;
  448. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  449. &ap_enable);
  450. if (ap_enable) {
  451. if ((byte1 & BIT4) && !(byte1 & BIT5)) {
  452. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  453. "[BTCoex], FW for 1Ant AP mode\n");
  454. real_byte1 &= ~BIT4;
  455. real_byte1 |= BIT5;
  456. real_byte5 |= BIT5;
  457. real_byte5 &= ~BIT6;
  458. }
  459. }
  460. h2c_parameter[0] = real_byte1;
  461. h2c_parameter[1] = byte2;
  462. h2c_parameter[2] = byte3;
  463. h2c_parameter[3] = byte4;
  464. h2c_parameter[4] = real_byte5;
  465. coex_dm->ps_tdma_para[0] = real_byte1;
  466. coex_dm->ps_tdma_para[1] = byte2;
  467. coex_dm->ps_tdma_para[2] = byte3;
  468. coex_dm->ps_tdma_para[3] = byte4;
  469. coex_dm->ps_tdma_para[4] = real_byte5;
  470. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  471. "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
  472. h2c_parameter[0],
  473. h2c_parameter[1] << 24 |
  474. h2c_parameter[2] << 16 |
  475. h2c_parameter[3] << 8 |
  476. h2c_parameter[4]);
  477. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  478. }
  479. static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
  480. u8 lps_val, u8 rpwm_val)
  481. {
  482. u8 lps = lps_val;
  483. u8 rpwm = rpwm_val;
  484. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  485. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  486. }
  487. static void halbtc8723b1ant_lps_rpwm(struct btc_coexist *btcoexist,
  488. bool force_exec,
  489. u8 lps_val, u8 rpwm_val)
  490. {
  491. struct rtl_priv *rtlpriv = btcoexist->adapter;
  492. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  493. "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
  494. (force_exec ? "force to" : ""), lps_val, rpwm_val);
  495. coex_dm->cur_lps = lps_val;
  496. coex_dm->cur_rpwm = rpwm_val;
  497. if (!force_exec) {
  498. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  499. "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
  500. coex_dm->cur_lps, coex_dm->cur_rpwm);
  501. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  502. (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) {
  503. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  504. "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
  505. coex_dm->pre_rpwm, coex_dm->cur_rpwm);
  506. return;
  507. }
  508. }
  509. halbtc8723b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  510. coex_dm->pre_lps = coex_dm->cur_lps;
  511. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  512. }
  513. static void halbtc8723b1ant_sw_mechanism(struct btc_coexist *btcoexist,
  514. bool low_penalty_ra)
  515. {
  516. struct rtl_priv *rtlpriv = btcoexist->adapter;
  517. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  518. "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra);
  519. halbtc8723b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  520. }
  521. static void halbtc8723b1ant_set_ant_path(struct btc_coexist *btcoexist,
  522. u8 ant_pos_type, bool init_hw_cfg,
  523. bool wifi_off)
  524. {
  525. struct btc_board_info *board_info = &btcoexist->board_info;
  526. u32 fw_ver = 0, u32tmp = 0;
  527. bool pg_ext_switch = false;
  528. bool use_ext_switch = false;
  529. u8 h2c_parameter[2] = {0};
  530. btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch);
  531. /* [31:16] = fw ver, [15:0] = fw sub ver */
  532. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  533. if ((fw_ver < 0xc0000) || pg_ext_switch)
  534. use_ext_switch = true;
  535. if (init_hw_cfg) {
  536. /*BT select s0/s1 is controlled by WiFi */
  537. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1);
  538. /*Force GNT_BT to Normal */
  539. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
  540. } else if (wifi_off) {
  541. /*Force GNT_BT to High */
  542. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
  543. /*BT select s0/s1 is controlled by BT */
  544. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0);
  545. /* 0x4c[24:23] = 00, Set Antenna control by BT_RFE_CTRL
  546. * BT Vendor 0xac = 0xf002
  547. */
  548. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  549. u32tmp &= ~BIT23;
  550. u32tmp &= ~BIT24;
  551. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  552. }
  553. if (use_ext_switch) {
  554. if (init_hw_cfg) {
  555. /* 0x4c[23] = 0, 0x4c[24] = 1
  556. * Antenna control by WL/BT
  557. */
  558. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  559. u32tmp &= ~BIT23;
  560. u32tmp |= BIT24;
  561. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  562. if (board_info->btdm_ant_pos ==
  563. BTC_ANTENNA_AT_MAIN_PORT) {
  564. /* Main Ant to BT for IPS case 0x4c[23] = 1 */
  565. btcoexist->btc_write_1byte_bitmask(btcoexist,
  566. 0x64, 0x1,
  567. 0x1);
  568. /* tell firmware "no antenna inverse" */
  569. h2c_parameter[0] = 0;
  570. h2c_parameter[1] = 1; /*ext switch type*/
  571. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  572. h2c_parameter);
  573. } else {
  574. /* Aux Ant to BT for IPS case 0x4c[23] = 1 */
  575. btcoexist->btc_write_1byte_bitmask(btcoexist,
  576. 0x64, 0x1,
  577. 0x0);
  578. /* tell firmware "antenna inverse" */
  579. h2c_parameter[0] = 1;
  580. h2c_parameter[1] = 1; /* ext switch type */
  581. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  582. h2c_parameter);
  583. }
  584. }
  585. /* fixed internal switch first
  586. * fixed internal switch S1->WiFi, S0->BT
  587. */
  588. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
  589. btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0);
  590. else /* fixed internal switch S0->WiFi, S1->BT */
  591. btcoexist->btc_write_2byte(btcoexist, 0x948, 0x280);
  592. /* ext switch setting */
  593. switch (ant_pos_type) {
  594. case BTC_ANT_PATH_WIFI:
  595. if (board_info->btdm_ant_pos ==
  596. BTC_ANTENNA_AT_MAIN_PORT)
  597. btcoexist->btc_write_1byte_bitmask(btcoexist,
  598. 0x92c, 0x3,
  599. 0x1);
  600. else
  601. btcoexist->btc_write_1byte_bitmask(btcoexist,
  602. 0x92c, 0x3,
  603. 0x2);
  604. break;
  605. case BTC_ANT_PATH_BT:
  606. if (board_info->btdm_ant_pos ==
  607. BTC_ANTENNA_AT_MAIN_PORT)
  608. btcoexist->btc_write_1byte_bitmask(btcoexist,
  609. 0x92c, 0x3,
  610. 0x2);
  611. else
  612. btcoexist->btc_write_1byte_bitmask(btcoexist,
  613. 0x92c, 0x3,
  614. 0x1);
  615. break;
  616. default:
  617. case BTC_ANT_PATH_PTA:
  618. if (board_info->btdm_ant_pos ==
  619. BTC_ANTENNA_AT_MAIN_PORT)
  620. btcoexist->btc_write_1byte_bitmask(btcoexist,
  621. 0x92c, 0x3,
  622. 0x1);
  623. else
  624. btcoexist->btc_write_1byte_bitmask(btcoexist,
  625. 0x92c, 0x3,
  626. 0x2);
  627. break;
  628. }
  629. } else {
  630. if (init_hw_cfg) {
  631. /* 0x4c[23] = 1, 0x4c[24] = 0 Antenna control by 0x64 */
  632. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  633. u32tmp |= BIT23;
  634. u32tmp &= ~BIT24;
  635. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  636. if (board_info->btdm_ant_pos ==
  637. BTC_ANTENNA_AT_MAIN_PORT) {
  638. /* Main Ant to WiFi for IPS case 0x4c[23] = 1 */
  639. btcoexist->btc_write_1byte_bitmask(btcoexist,
  640. 0x64, 0x1,
  641. 0x0);
  642. /* tell firmware "no antenna inverse" */
  643. h2c_parameter[0] = 0;
  644. h2c_parameter[1] = 0; /* internal switch type */
  645. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  646. h2c_parameter);
  647. } else {
  648. /* Aux Ant to BT for IPS case 0x4c[23] = 1 */
  649. btcoexist->btc_write_1byte_bitmask(btcoexist,
  650. 0x64, 0x1,
  651. 0x1);
  652. /* tell firmware "antenna inverse" */
  653. h2c_parameter[0] = 1;
  654. h2c_parameter[1] = 0; /* internal switch type */
  655. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  656. h2c_parameter);
  657. }
  658. }
  659. /* fixed external switch first
  660. * Main->WiFi, Aux->BT
  661. */
  662. if (board_info->btdm_ant_pos ==
  663. BTC_ANTENNA_AT_MAIN_PORT)
  664. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
  665. 0x3, 0x1);
  666. else /* Main->BT, Aux->WiFi */
  667. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
  668. 0x3, 0x2);
  669. /* internal switch setting */
  670. switch (ant_pos_type) {
  671. case BTC_ANT_PATH_WIFI:
  672. if (board_info->btdm_ant_pos ==
  673. BTC_ANTENNA_AT_MAIN_PORT)
  674. btcoexist->btc_write_2byte(btcoexist, 0x948,
  675. 0x0);
  676. else
  677. btcoexist->btc_write_2byte(btcoexist, 0x948,
  678. 0x280);
  679. break;
  680. case BTC_ANT_PATH_BT:
  681. if (board_info->btdm_ant_pos ==
  682. BTC_ANTENNA_AT_MAIN_PORT)
  683. btcoexist->btc_write_2byte(btcoexist, 0x948,
  684. 0x280);
  685. else
  686. btcoexist->btc_write_2byte(btcoexist, 0x948,
  687. 0x0);
  688. break;
  689. default:
  690. case BTC_ANT_PATH_PTA:
  691. if (board_info->btdm_ant_pos ==
  692. BTC_ANTENNA_AT_MAIN_PORT)
  693. btcoexist->btc_write_2byte(btcoexist, 0x948,
  694. 0x200);
  695. else
  696. btcoexist->btc_write_2byte(btcoexist, 0x948,
  697. 0x80);
  698. break;
  699. }
  700. }
  701. }
  702. static void halbtc8723b1ant_ps_tdma(struct btc_coexist *btcoexist,
  703. bool force_exec, bool turn_on, u8 type)
  704. {
  705. struct rtl_priv *rtlpriv = btcoexist->adapter;
  706. bool wifi_busy = false;
  707. u8 rssi_adjust_val = 0;
  708. coex_dm->cur_ps_tdma_on = turn_on;
  709. coex_dm->cur_ps_tdma = type;
  710. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  711. if (!force_exec) {
  712. if (coex_dm->cur_ps_tdma_on)
  713. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  714. "[BTCoex], ******** TDMA(on, %d) *********\n",
  715. coex_dm->cur_ps_tdma);
  716. else
  717. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  718. "[BTCoex], ******** TDMA(off, %d) ********\n",
  719. coex_dm->cur_ps_tdma);
  720. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  721. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  722. return;
  723. }
  724. if (turn_on) {
  725. switch (type) {
  726. default:
  727. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a,
  728. 0x1a, 0x0, 0x50);
  729. break;
  730. case 1:
  731. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x3a,
  732. 0x03, 0x10, 0x50);
  733. rssi_adjust_val = 11;
  734. break;
  735. case 2:
  736. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x2b,
  737. 0x03, 0x10, 0x50);
  738. rssi_adjust_val = 14;
  739. break;
  740. case 3:
  741. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1d,
  742. 0x1d, 0x0, 0x52);
  743. break;
  744. case 4:
  745. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
  746. 0x3, 0x14, 0x0);
  747. rssi_adjust_val = 17;
  748. break;
  749. case 5:
  750. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15,
  751. 0x3, 0x11, 0x10);
  752. break;
  753. case 6:
  754. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x20,
  755. 0x3, 0x11, 0x13);
  756. break;
  757. case 7:
  758. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc,
  759. 0x5, 0x0, 0x0);
  760. break;
  761. case 8:
  762. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
  763. 0x3, 0x10, 0x0);
  764. break;
  765. case 9:
  766. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
  767. 0x3, 0x10, 0x50);
  768. rssi_adjust_val = 18;
  769. break;
  770. case 10:
  771. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
  772. 0xa, 0x0, 0x40);
  773. break;
  774. case 11:
  775. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x15,
  776. 0x03, 0x10, 0x50);
  777. rssi_adjust_val = 20;
  778. break;
  779. case 12:
  780. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a,
  781. 0x0a, 0x0, 0x50);
  782. break;
  783. case 13:
  784. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x15,
  785. 0x15, 0x0, 0x50);
  786. break;
  787. case 14:
  788. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
  789. 0x3, 0x10, 0x52);
  790. break;
  791. case 15:
  792. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
  793. 0x3, 0x8, 0x0);
  794. break;
  795. case 16:
  796. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
  797. 0x3, 0x10, 0x0);
  798. rssi_adjust_val = 18;
  799. break;
  800. case 18:
  801. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
  802. 0x3, 0x10, 0x0);
  803. rssi_adjust_val = 14;
  804. break;
  805. case 20:
  806. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x35,
  807. 0x03, 0x11, 0x10);
  808. break;
  809. case 21:
  810. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
  811. 0x03, 0x11, 0x11);
  812. break;
  813. case 22:
  814. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
  815. 0x03, 0x11, 0x10);
  816. break;
  817. case 23:
  818. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
  819. 0x3, 0x31, 0x18);
  820. rssi_adjust_val = 22;
  821. break;
  822. case 24:
  823. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
  824. 0x3, 0x31, 0x18);
  825. rssi_adjust_val = 22;
  826. break;
  827. case 25:
  828. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
  829. 0x3, 0x31, 0x18);
  830. rssi_adjust_val = 22;
  831. break;
  832. case 26:
  833. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
  834. 0x3, 0x31, 0x18);
  835. rssi_adjust_val = 22;
  836. break;
  837. case 27:
  838. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
  839. 0x3, 0x31, 0x98);
  840. rssi_adjust_val = 22;
  841. break;
  842. case 28:
  843. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25,
  844. 0x3, 0x31, 0x0);
  845. break;
  846. case 29:
  847. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a,
  848. 0x1a, 0x1, 0x10);
  849. break;
  850. case 30:
  851. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14,
  852. 0x3, 0x10, 0x50);
  853. break;
  854. case 31:
  855. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a,
  856. 0x1a, 0, 0x58);
  857. break;
  858. case 32:
  859. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0xa,
  860. 0x3, 0x10, 0x0);
  861. break;
  862. case 33:
  863. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x25,
  864. 0x3, 0x30, 0x90);
  865. break;
  866. case 34:
  867. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a,
  868. 0x1a, 0x0, 0x10);
  869. break;
  870. case 35:
  871. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a,
  872. 0x1a, 0x0, 0x10);
  873. break;
  874. case 36:
  875. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12,
  876. 0x3, 0x14, 0x50);
  877. break;
  878. /* SoftAP only with no sta associated, BT disable,
  879. * TDMA mode for power saving
  880. * here softap mode screen off will cost 70-80mA for phone
  881. */
  882. case 40:
  883. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x23, 0x18,
  884. 0x00, 0x10, 0x24);
  885. break;
  886. }
  887. } else {
  888. switch (type) {
  889. case 8: /* PTA Control */
  890. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0,
  891. 0x0, 0x0, 0x0);
  892. halbtc8723b1ant_set_ant_path(btcoexist,
  893. BTC_ANT_PATH_PTA,
  894. false, false);
  895. break;
  896. case 0:
  897. default:
  898. /* Software control, Antenna at BT side */
  899. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
  900. 0x0, 0x0, 0x0);
  901. halbtc8723b1ant_set_ant_path(btcoexist,
  902. BTC_ANT_PATH_BT,
  903. false, false);
  904. break;
  905. case 9:
  906. /* Software control, Antenna at WiFi side */
  907. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
  908. 0x0, 0x0, 0x0);
  909. halbtc8723b1ant_set_ant_path(btcoexist,
  910. BTC_ANT_PATH_WIFI,
  911. false, false);
  912. break;
  913. }
  914. }
  915. rssi_adjust_val = 0;
  916. btcoexist->btc_set(btcoexist,
  917. BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE,
  918. &rssi_adjust_val);
  919. /* update pre state */
  920. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  921. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  922. }
  923. static void halbtc8723b1ant_ps_tdma_chk_pwr_save(struct btc_coexist *btcoexist,
  924. bool new_ps_state)
  925. {
  926. u8 lps_mode = 0x0;
  927. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  928. if (lps_mode) {
  929. /* already under LPS state */
  930. if (new_ps_state) {
  931. /* keep state under LPS, do nothing. */
  932. } else {
  933. /* will leave LPS state, turn off psTdma first */
  934. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  935. false, 0);
  936. }
  937. } else {
  938. /* NO PS state */
  939. if (new_ps_state) {
  940. /* will enter LPS state, turn off psTdma first */
  941. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  942. false, 0);
  943. } else {
  944. /* keep state under NO PS state, do nothing. */
  945. }
  946. }
  947. }
  948. static void halbtc8723b1ant_power_save_state(struct btc_coexist *btcoexist,
  949. u8 ps_type, u8 lps_val,
  950. u8 rpwm_val)
  951. {
  952. bool low_pwr_disable = false;
  953. switch (ps_type) {
  954. case BTC_PS_WIFI_NATIVE:
  955. /* recover to original 32k low power setting */
  956. low_pwr_disable = false;
  957. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  958. &low_pwr_disable);
  959. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
  960. break;
  961. case BTC_PS_LPS_ON:
  962. halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, true);
  963. halbtc8723b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
  964. rpwm_val);
  965. /* when coex force to enter LPS, do not enter 32k low power */
  966. low_pwr_disable = true;
  967. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  968. &low_pwr_disable);
  969. /* power save must executed before psTdma */
  970. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
  971. break;
  972. case BTC_PS_LPS_OFF:
  973. halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, false);
  974. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
  975. break;
  976. default:
  977. break;
  978. }
  979. }
  980. /*****************************************************
  981. *
  982. * Non-Software Coex Mechanism start
  983. *
  984. *****************************************************/
  985. static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist *btcoexist)
  986. {
  987. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  988. 0x0, 0x0);
  989. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  990. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  991. }
  992. static void halbtc8723b1ant_action_hs(struct btc_coexist *btcoexist)
  993. {
  994. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  995. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  996. }
  997. static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
  998. {
  999. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1000. bool wifi_connected = false, ap_enable = false;
  1001. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1002. &ap_enable);
  1003. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1004. &wifi_connected);
  1005. if (!wifi_connected) {
  1006. halbtc8723b1ant_power_save_state(btcoexist,
  1007. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1008. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1009. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1010. } else if (bt_link_info->sco_exist || bt_link_info->hid_only) {
  1011. /* SCO/HID-only busy */
  1012. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1013. 0x0, 0x0);
  1014. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1015. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1016. } else {
  1017. if (ap_enable)
  1018. halbtc8723b1ant_power_save_state(btcoexist,
  1019. BTC_PS_WIFI_NATIVE,
  1020. 0x0, 0x0);
  1021. else
  1022. halbtc8723b1ant_power_save_state(btcoexist,
  1023. BTC_PS_LPS_ON,
  1024. 0x50, 0x4);
  1025. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 30);
  1026. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1027. }
  1028. }
  1029. static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist,
  1030. u8 wifi_status)
  1031. {
  1032. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1033. bool wifi_connected = false;
  1034. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1035. &wifi_connected);
  1036. /* tdma and coex table */
  1037. if (bt_link_info->sco_exist) {
  1038. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1039. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1040. } else {
  1041. /* HID */
  1042. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
  1043. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  1044. }
  1045. }
  1046. static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
  1047. struct btc_coexist *btcoexist,
  1048. u8 wifi_status)
  1049. {
  1050. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1051. if (bt_link_info->hid_only) { /* HID */
  1052. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, wifi_status);
  1053. coex_dm->auto_tdma_adjust = false;
  1054. return;
  1055. } else if (bt_link_info->a2dp_only) { /* A2DP */
  1056. if (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) {
  1057. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1058. false, 8);
  1059. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1060. NORMAL_EXEC, 2);
  1061. coex_dm->auto_tdma_adjust = false;
  1062. } else { /* for low BT RSSI */
  1063. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1064. true, 11);
  1065. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1066. NORMAL_EXEC, 1);
  1067. coex_dm->auto_tdma_adjust = false;
  1068. }
  1069. } else if (bt_link_info->hid_exist &&
  1070. bt_link_info->a2dp_exist) { /* HID + A2DP */
  1071. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  1072. coex_dm->auto_tdma_adjust = false;
  1073. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  1074. /* PAN(OPP,FTP), HID + PAN(OPP,FTP) */
  1075. } else if (bt_link_info->pan_only ||
  1076. (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
  1077. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1078. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  1079. coex_dm->auto_tdma_adjust = false;
  1080. /* A2DP + PAN(OPP,FTP), HID + A2DP + PAN(OPP,FTP) */
  1081. } else if ((bt_link_info->a2dp_exist && bt_link_info->pan_exist) ||
  1082. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  1083. bt_link_info->pan_exist)) {
  1084. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  1085. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1086. coex_dm->auto_tdma_adjust = false;
  1087. } else {
  1088. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1089. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1090. coex_dm->auto_tdma_adjust = false;
  1091. }
  1092. }
  1093. static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist *btcoexist)
  1094. {
  1095. /* power save state */
  1096. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1097. 0x0, 0x0);
  1098. /* tdma and coex table */
  1099. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1100. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1101. }
  1102. static void
  1103. btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist *btcoexist)
  1104. {
  1105. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1106. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1107. 0x0, 0x0);
  1108. /* tdma and coex table */
  1109. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1110. if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
  1111. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1112. true, 22);
  1113. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1114. NORMAL_EXEC, 1);
  1115. } else if (bt_link_info->pan_only) {
  1116. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1117. true, 20);
  1118. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1119. NORMAL_EXEC, 2);
  1120. } else {
  1121. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1122. true, 20);
  1123. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1124. NORMAL_EXEC, 1);
  1125. }
  1126. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1127. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1128. coex_dm->bt_status)){
  1129. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1130. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1131. } else {
  1132. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1133. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1134. }
  1135. }
  1136. static void
  1137. btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist *btcoexist)
  1138. {
  1139. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1140. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1141. 0x0, 0x0);
  1142. if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
  1143. (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
  1144. (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
  1145. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1146. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1147. } else {
  1148. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1149. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1150. }
  1151. }
  1152. static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist *btcoexist)
  1153. {
  1154. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1155. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1156. 0x0, 0x0);
  1157. /* tdma and coex table */
  1158. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1159. if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
  1160. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1161. true, 22);
  1162. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1163. NORMAL_EXEC, 1);
  1164. } else if (bt_link_info->pan_only) {
  1165. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1166. true, 20);
  1167. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1168. NORMAL_EXEC, 2);
  1169. } else {
  1170. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1171. true, 20);
  1172. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1173. NORMAL_EXEC, 1);
  1174. }
  1175. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1176. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1177. coex_dm->bt_status)) {
  1178. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1179. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1180. } else {
  1181. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1182. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1183. }
  1184. }
  1185. static void halbtc8723b1ant_action_wifi_connected_special_packet(
  1186. struct btc_coexist *btcoexist)
  1187. {
  1188. bool hs_connecting = false;
  1189. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1190. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting);
  1191. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1192. 0x0, 0x0);
  1193. /* tdma and coex table */
  1194. if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
  1195. (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
  1196. (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
  1197. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1198. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1199. } else {
  1200. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1201. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1202. }
  1203. }
  1204. static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist *btcoexist)
  1205. {
  1206. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1207. bool wifi_busy = false;
  1208. bool scan = false, link = false, roam = false;
  1209. bool under_4way = false, ap_enable = false;
  1210. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1211. "[BTCoex], CoexForWifiConnect()===>\n");
  1212. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  1213. &under_4way);
  1214. if (under_4way) {
  1215. halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
  1216. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1217. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  1218. return;
  1219. }
  1220. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1221. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1222. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1223. if (scan || link || roam) {
  1224. if (scan)
  1225. btc8723b1ant_action_wifi_conn_scan(btcoexist);
  1226. else
  1227. halbtc8723b1ant_action_wifi_connected_special_packet(
  1228. btcoexist);
  1229. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1230. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  1231. return;
  1232. }
  1233. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1234. &ap_enable);
  1235. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1236. /* power save state */
  1237. if (!ap_enable &&
  1238. BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
  1239. !btcoexist->bt_link_info.hid_only) {
  1240. if (!wifi_busy && btcoexist->bt_link_info.a2dp_only)
  1241. halbtc8723b1ant_power_save_state(btcoexist,
  1242. BTC_PS_WIFI_NATIVE,
  1243. 0x0, 0x0);
  1244. else
  1245. halbtc8723b1ant_power_save_state(btcoexist,
  1246. BTC_PS_LPS_ON,
  1247. 0x50, 0x4);
  1248. } else {
  1249. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1250. 0x0, 0x0);
  1251. }
  1252. /* tdma and coex table */
  1253. if (!wifi_busy) {
  1254. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1255. halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist,
  1256. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1257. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY ==
  1258. coex_dm->bt_status) ||
  1259. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1260. coex_dm->bt_status)) {
  1261. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1262. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1263. } else {
  1264. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1265. false, 8);
  1266. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1267. NORMAL_EXEC, 2);
  1268. }
  1269. } else {
  1270. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1271. halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist,
  1272. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1273. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY ==
  1274. coex_dm->bt_status) ||
  1275. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1276. coex_dm->bt_status)) {
  1277. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1278. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1279. } else {
  1280. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1281. false, 8);
  1282. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1283. NORMAL_EXEC, 2);
  1284. }
  1285. }
  1286. }
  1287. static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
  1288. {
  1289. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1290. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1291. bool wifi_connected = false, bt_hs_on = false;
  1292. bool increase_scan_dev_num = false;
  1293. bool bt_ctrl_agg_buf_size = false;
  1294. u8 agg_buf_size = 5;
  1295. u32 wifi_link_status = 0;
  1296. u32 num_of_wifi_link = 0;
  1297. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1298. "[BTCoex], RunCoexistMechanism()===>\n");
  1299. if (btcoexist->manual_control) {
  1300. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1301. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  1302. return;
  1303. }
  1304. if (btcoexist->stop_coex_dm) {
  1305. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1306. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  1307. return;
  1308. }
  1309. if (coex_sta->under_ips) {
  1310. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1311. "[BTCoex], wifi is under IPS !!!\n");
  1312. return;
  1313. }
  1314. if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  1315. (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1316. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
  1317. increase_scan_dev_num = true;
  1318. }
  1319. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  1320. &increase_scan_dev_num);
  1321. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1322. &wifi_connected);
  1323. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1324. &wifi_link_status);
  1325. num_of_wifi_link = wifi_link_status >> 16;
  1326. if (num_of_wifi_link >= 2) {
  1327. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1328. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1329. bt_ctrl_agg_buf_size,
  1330. agg_buf_size);
  1331. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  1332. return;
  1333. }
  1334. if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) {
  1335. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1336. } else {
  1337. if (wifi_connected)
  1338. halbtc8723b1ant_limited_tx(btcoexist,
  1339. NORMAL_EXEC, 1, 1, 1, 1);
  1340. else
  1341. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC,
  1342. 0, 0, 0, 0);
  1343. }
  1344. if (bt_link_info->sco_exist) {
  1345. bt_ctrl_agg_buf_size = true;
  1346. agg_buf_size = 0x3;
  1347. } else if (bt_link_info->hid_exist) {
  1348. bt_ctrl_agg_buf_size = true;
  1349. agg_buf_size = 0x5;
  1350. } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
  1351. bt_ctrl_agg_buf_size = true;
  1352. agg_buf_size = 0x8;
  1353. }
  1354. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1355. bt_ctrl_agg_buf_size, agg_buf_size);
  1356. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1357. if (coex_sta->c2h_bt_inquiry_page) {
  1358. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  1359. return;
  1360. } else if (bt_hs_on) {
  1361. halbtc8723b1ant_action_hs(btcoexist);
  1362. return;
  1363. }
  1364. if (!wifi_connected) {
  1365. bool scan = false, link = false, roam = false;
  1366. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1367. "[BTCoex], wifi is non connected-idle !!!\n");
  1368. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1369. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1370. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1371. if (scan || link || roam) {
  1372. if (scan)
  1373. btc8723b1ant_action_wifi_not_conn_scan(
  1374. btcoexist);
  1375. else
  1376. btc8723b1ant_act_wifi_not_conn_asso_auth(
  1377. btcoexist);
  1378. } else {
  1379. btc8723b1ant_action_wifi_not_conn(btcoexist);
  1380. }
  1381. } else { /* wifi LPS/Busy */
  1382. halbtc8723b1ant_action_wifi_connected(btcoexist);
  1383. }
  1384. }
  1385. static void halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
  1386. {
  1387. /* sw all off */
  1388. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1389. halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  1390. halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1391. }
  1392. static void halbtc8723b1ant_init_hw_config(struct btc_coexist *btcoexist,
  1393. bool backup)
  1394. {
  1395. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1396. u32 u32tmp = 0;
  1397. u8 u8tmp = 0;
  1398. u32 cnt_bt_cal_chk = 0;
  1399. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1400. "[BTCoex], 1Ant Init HW Config!!\n");
  1401. if (backup) {/* backup rf 0x1e value */
  1402. coex_dm->backup_arfr_cnt1 =
  1403. btcoexist->btc_read_4byte(btcoexist, 0x430);
  1404. coex_dm->backup_arfr_cnt2 =
  1405. btcoexist->btc_read_4byte(btcoexist, 0x434);
  1406. coex_dm->backup_retry_limit =
  1407. btcoexist->btc_read_2byte(btcoexist, 0x42a);
  1408. coex_dm->backup_ampdu_max_time =
  1409. btcoexist->btc_read_1byte(btcoexist, 0x456);
  1410. }
  1411. /* WiFi goto standby while GNT_BT 0-->1 */
  1412. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
  1413. /* BT goto standby while GNT_BT 1-->0 */
  1414. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x500);
  1415. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1416. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3);
  1417. btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77);
  1418. /* BT calibration check */
  1419. while (cnt_bt_cal_chk <= 20) {
  1420. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x49d);
  1421. cnt_bt_cal_chk++;
  1422. if (u32tmp & BIT0) {
  1423. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1424. "[BTCoex], ########### BT calibration(cnt=%d) ###########\n",
  1425. cnt_bt_cal_chk);
  1426. mdelay(50);
  1427. } else {
  1428. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1429. "[BTCoex], ********** BT NOT calibration (cnt=%d)**********\n",
  1430. cnt_bt_cal_chk);
  1431. break;
  1432. }
  1433. }
  1434. /* 0x790[5:0] = 0x5 */
  1435. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  1436. u8tmp &= 0xc0;
  1437. u8tmp |= 0x5;
  1438. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  1439. /* Enable counter statistics */
  1440. /*0x76e[3] = 1, WLAN_Act control by PTA */
  1441. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  1442. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  1443. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  1444. /* Antenna config */
  1445. halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true, false);
  1446. /* PTA parameter */
  1447. halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1448. }
  1449. /**************************************************************
  1450. * extern function start with ex_halbtc8723b1ant_
  1451. **************************************************************/
  1452. void ex_halbtc8723b1ant_init_hwconfig(struct btc_coexist *btcoexist)
  1453. {
  1454. halbtc8723b1ant_init_hw_config(btcoexist, true);
  1455. }
  1456. void ex_halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
  1457. {
  1458. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1459. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1460. "[BTCoex], Coex Mechanism Init!!\n");
  1461. btcoexist->stop_coex_dm = false;
  1462. halbtc8723b1ant_init_coex_dm(btcoexist);
  1463. halbtc8723b1ant_query_bt_info(btcoexist);
  1464. }
  1465. void ex_halbtc8723b1ant_display_coex_info(struct btc_coexist *btcoexist)
  1466. {
  1467. struct btc_board_info *board_info = &btcoexist->board_info;
  1468. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  1469. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1470. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1471. u8 u8tmp[4], i, bt_info_ext, pstdmacase = 0;
  1472. u16 u16tmp[4];
  1473. u32 u32tmp[4];
  1474. bool roam = false, scan = false;
  1475. bool link = false, wifi_under_5g = false;
  1476. bool bt_hs_on = false, wifi_busy = false;
  1477. s32 wifi_rssi = 0, bt_hs_rssi = 0;
  1478. u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck, wifi_link_status;
  1479. u8 wifi_dot11_chnl, wifi_hs_chnl;
  1480. u32 fw_ver = 0, bt_patch_ver = 0;
  1481. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1482. "\r\n ============[BT Coexist info]============");
  1483. if (btcoexist->manual_control) {
  1484. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1485. "\r\n ============[Under Manual Control]==========");
  1486. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1487. "\r\n ==========================================");
  1488. }
  1489. if (btcoexist->stop_coex_dm) {
  1490. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1491. "\r\n ============[Coex is STOPPED]============");
  1492. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1493. "\r\n ==========================================");
  1494. }
  1495. if (!board_info->bt_exist) {
  1496. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
  1497. return;
  1498. }
  1499. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d",
  1500. "Ant PG Num/ Ant Mech/ Ant Pos:",
  1501. board_info->pg_ant_num, board_info->btdm_ant_num,
  1502. board_info->btdm_ant_pos);
  1503. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d",
  1504. "BT stack/ hci ext ver",
  1505. ((stack_info->profile_notified) ? "Yes" : "No"),
  1506. stack_info->hci_version);
  1507. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  1508. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  1509. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1510. "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
  1511. "CoexVer/ FwVer/ PatchVer",
  1512. glcoex_ver_date_8723b_1ant, glcoex_ver_8723b_1ant,
  1513. fw_ver, bt_patch_ver, bt_patch_ver);
  1514. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1515. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
  1516. &wifi_dot11_chnl);
  1517. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
  1518. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)",
  1519. "Dot11 channel / HsChnl(HsMode)",
  1520. wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
  1521. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %3ph ",
  1522. "H2C Wifi inform bt chnl Info",
  1523. coex_dm->wifi_chnl_info);
  1524. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  1525. btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
  1526. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  1527. "Wifi rssi/ HS rssi", wifi_rssi, bt_hs_rssi);
  1528. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1529. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1530. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1531. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
  1532. "Wifi link/ roam/ scan", link, roam, scan);
  1533. btcoexist->btc_get(btcoexist , BTC_GET_BL_WIFI_UNDER_5G,
  1534. &wifi_under_5g);
  1535. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  1536. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1537. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
  1538. &wifi_traffic_dir);
  1539. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ",
  1540. "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
  1541. ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" :
  1542. ((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20")),
  1543. ((!wifi_busy) ? "idle" :
  1544. ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ?
  1545. "uplink" : "downlink")));
  1546. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1547. &wifi_link_status);
  1548. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
  1549. "sta/vwifi/hs/p2pGo/p2pGc",
  1550. ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
  1551. ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
  1552. ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
  1553. ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
  1554. ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
  1555. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = [%s/ %d/ %d] ",
  1556. "BT [status/ rssi/ retryCnt]",
  1557. ((btcoexist->bt_info.bt_disabled) ? ("disabled") :
  1558. ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
  1559. ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1560. coex_dm->bt_status) ?
  1561. "non-connected idle" :
  1562. ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1563. coex_dm->bt_status) ?
  1564. "connected-idle" : "busy")))),
  1565. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  1566. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1567. "\r\n %-35s = %d / %d / %d / %d",
  1568. "SCO/HID/PAN/A2DP", bt_link_info->sco_exist,
  1569. bt_link_info->hid_exist, bt_link_info->pan_exist,
  1570. bt_link_info->a2dp_exist);
  1571. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  1572. bt_info_ext = coex_sta->bt_info_ext;
  1573. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
  1574. "BT Info A2DP rate",
  1575. (bt_info_ext & BIT0) ? "Basic rate" : "EDR rate");
  1576. for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) {
  1577. if (coex_sta->bt_info_c2h_cnt[i]) {
  1578. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1579. "\r\n %-35s = %7ph(%d)",
  1580. glbt_info_src_8723b_1ant[i],
  1581. coex_sta->bt_info_c2h[i],
  1582. coex_sta->bt_info_c2h_cnt[i]);
  1583. }
  1584. }
  1585. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1586. "\r\n %-35s = %s/%s, (0x%x/0x%x)",
  1587. "PS state, IPS/LPS, (lps/rpwm)",
  1588. ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
  1589. ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")),
  1590. btcoexist->bt_info.lps_val,
  1591. btcoexist->bt_info.rpwm_val);
  1592. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
  1593. if (!btcoexist->manual_control) {
  1594. /* Sw mechanism */
  1595. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  1596. "============[Sw mechanism]============");
  1597. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/",
  1598. "SM[LowPenaltyRA]", coex_dm->cur_low_penalty_ra);
  1599. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/ %s/ %d ",
  1600. "DelBA/ BtCtrlAgg/ AggSize",
  1601. (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"),
  1602. (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"),
  1603. btcoexist->bt_info.agg_buf_size);
  1604. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
  1605. "Rate Mask", btcoexist->bt_info.ra_mask);
  1606. /* Fw mechanism */
  1607. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  1608. "============[Fw mechanism]============");
  1609. pstdmacase = coex_dm->cur_ps_tdma;
  1610. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1611. "\r\n %-35s = %5ph case-%d (auto:%d)",
  1612. "PS TDMA", coex_dm->ps_tdma_para,
  1613. pstdmacase, coex_dm->auto_tdma_adjust);
  1614. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d ",
  1615. "IgnWlanAct", coex_dm->cur_ignore_wlan_act);
  1616. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
  1617. "Latest error condition(should be 0)",
  1618. coex_dm->error_condition);
  1619. }
  1620. /* Hw setting */
  1621. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  1622. "============[Hw setting]============");
  1623. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  1624. "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm->backup_arfr_cnt1,
  1625. coex_dm->backup_arfr_cnt2, coex_dm->backup_retry_limit,
  1626. coex_dm->backup_ampdu_max_time);
  1627. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  1628. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  1629. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  1630. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  1631. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  1632. "0x430/0x434/0x42a/0x456",
  1633. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  1634. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  1635. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
  1636. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x880);
  1637. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  1638. "0x778/0x6cc/0x880[29:25]", u8tmp[0], u32tmp[0],
  1639. (u32tmp[1] & 0x3e000000) >> 25);
  1640. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948);
  1641. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67);
  1642. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765);
  1643. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  1644. "0x948/ 0x67[5] / 0x765",
  1645. u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]);
  1646. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c);
  1647. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930);
  1648. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944);
  1649. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  1650. "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
  1651. u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3);
  1652. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39);
  1653. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  1654. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  1655. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  1656. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1657. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  1658. "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
  1659. ((u8tmp[0] & 0x8) >> 3), u8tmp[1],
  1660. ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1);
  1661. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  1662. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  1663. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  1664. "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
  1665. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  1666. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
  1667. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  1668. "0xc50(dig)/0x49c(null-drop)", u32tmp[0] & 0xff, u8tmp[0]);
  1669. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
  1670. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
  1671. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
  1672. u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
  1673. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
  1674. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
  1675. fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) +
  1676. ((u32tmp[1] & 0xffff0000) >> 16) +
  1677. (u32tmp[1] & 0xffff) +
  1678. (u32tmp[2] & 0xffff) +
  1679. ((u32tmp[3] & 0xffff0000) >> 16) +
  1680. (u32tmp[3] & 0xffff);
  1681. fa_cck = (u8tmp[0] << 8) + u8tmp[1];
  1682. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  1683. "OFDM-CCA/OFDM-FA/CCK-FA",
  1684. u32tmp[0] & 0xffff, fa_ofdm, fa_cck);
  1685. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  1686. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  1687. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  1688. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  1689. "0x6c0/0x6c4/0x6c8(coexTable)",
  1690. u32tmp[0], u32tmp[1], u32tmp[2]);
  1691. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  1692. "0x770(high-pri rx/tx)", coex_sta->high_priority_rx,
  1693. coex_sta->high_priority_tx);
  1694. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  1695. "0x774(low-pri rx/tx)", coex_sta->low_priority_rx,
  1696. coex_sta->low_priority_tx);
  1697. #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)
  1698. halbtc8723b1ant_monitor_bt_ctr(btcoexist);
  1699. #endif
  1700. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  1701. }
  1702. void ex_halbtc8723b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
  1703. {
  1704. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1705. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  1706. return;
  1707. if (BTC_IPS_ENTER == type) {
  1708. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1709. "[BTCoex], IPS ENTER notify\n");
  1710. coex_sta->under_ips = true;
  1711. halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  1712. false, true);
  1713. /* set PTA control */
  1714. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  1715. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1716. NORMAL_EXEC, 0);
  1717. } else if (BTC_IPS_LEAVE == type) {
  1718. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1719. "[BTCoex], IPS LEAVE notify\n");
  1720. coex_sta->under_ips = false;
  1721. halbtc8723b1ant_init_hw_config(btcoexist, false);
  1722. halbtc8723b1ant_init_coex_dm(btcoexist);
  1723. halbtc8723b1ant_query_bt_info(btcoexist);
  1724. }
  1725. }
  1726. void ex_halbtc8723b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
  1727. {
  1728. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1729. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  1730. return;
  1731. if (BTC_LPS_ENABLE == type) {
  1732. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1733. "[BTCoex], LPS ENABLE notify\n");
  1734. coex_sta->under_lps = true;
  1735. } else if (BTC_LPS_DISABLE == type) {
  1736. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1737. "[BTCoex], LPS DISABLE notify\n");
  1738. coex_sta->under_lps = false;
  1739. }
  1740. }
  1741. void ex_halbtc8723b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
  1742. {
  1743. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1744. bool wifi_connected = false, bt_hs_on = false;
  1745. u32 wifi_link_status = 0;
  1746. u32 num_of_wifi_link = 0;
  1747. bool bt_ctrl_agg_buf_size = false;
  1748. u8 agg_buf_size = 5;
  1749. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  1750. btcoexist->bt_info.bt_disabled)
  1751. return;
  1752. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1753. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1754. &wifi_connected);
  1755. halbtc8723b1ant_query_bt_info(btcoexist);
  1756. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1757. &wifi_link_status);
  1758. num_of_wifi_link = wifi_link_status >> 16;
  1759. if (num_of_wifi_link >= 2) {
  1760. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1761. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1762. bt_ctrl_agg_buf_size, agg_buf_size);
  1763. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  1764. return;
  1765. }
  1766. if (coex_sta->c2h_bt_inquiry_page) {
  1767. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  1768. return;
  1769. } else if (bt_hs_on) {
  1770. halbtc8723b1ant_action_hs(btcoexist);
  1771. return;
  1772. }
  1773. if (BTC_SCAN_START == type) {
  1774. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1775. "[BTCoex], SCAN START notify\n");
  1776. if (!wifi_connected)
  1777. /* non-connected scan */
  1778. btc8723b1ant_action_wifi_not_conn_scan(btcoexist);
  1779. else
  1780. /* wifi is connected */
  1781. btc8723b1ant_action_wifi_conn_scan(btcoexist);
  1782. } else if (BTC_SCAN_FINISH == type) {
  1783. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1784. "[BTCoex], SCAN FINISH notify\n");
  1785. if (!wifi_connected)
  1786. /* non-connected scan */
  1787. btc8723b1ant_action_wifi_not_conn(btcoexist);
  1788. else
  1789. halbtc8723b1ant_action_wifi_connected(btcoexist);
  1790. }
  1791. }
  1792. void ex_halbtc8723b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
  1793. {
  1794. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1795. bool wifi_connected = false, bt_hs_on = false;
  1796. u32 wifi_link_status = 0;
  1797. u32 num_of_wifi_link = 0;
  1798. bool bt_ctrl_agg_buf_size = false;
  1799. u8 agg_buf_size = 5;
  1800. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  1801. btcoexist->bt_info.bt_disabled)
  1802. return;
  1803. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1804. &wifi_link_status);
  1805. num_of_wifi_link = wifi_link_status>>16;
  1806. if (num_of_wifi_link >= 2) {
  1807. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1808. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1809. bt_ctrl_agg_buf_size, agg_buf_size);
  1810. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  1811. return;
  1812. }
  1813. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1814. if (coex_sta->c2h_bt_inquiry_page) {
  1815. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  1816. return;
  1817. } else if (bt_hs_on) {
  1818. halbtc8723b1ant_action_hs(btcoexist);
  1819. return;
  1820. }
  1821. if (BTC_ASSOCIATE_START == type) {
  1822. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1823. "[BTCoex], CONNECT START notify\n");
  1824. btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist);
  1825. } else if (BTC_ASSOCIATE_FINISH == type) {
  1826. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1827. "[BTCoex], CONNECT FINISH notify\n");
  1828. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1829. &wifi_connected);
  1830. if (!wifi_connected)
  1831. /* non-connected scan */
  1832. btc8723b1ant_action_wifi_not_conn(btcoexist);
  1833. else
  1834. halbtc8723b1ant_action_wifi_connected(btcoexist);
  1835. }
  1836. }
  1837. void ex_halbtc8723b1ant_media_status_notify(struct btc_coexist *btcoexist,
  1838. u8 type)
  1839. {
  1840. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1841. u8 h2c_parameter[3] = {0};
  1842. u32 wifi_bw;
  1843. u8 wifiCentralChnl;
  1844. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  1845. btcoexist->bt_info.bt_disabled)
  1846. return;
  1847. if (BTC_MEDIA_CONNECT == type)
  1848. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1849. "[BTCoex], MEDIA connect notify\n");
  1850. else
  1851. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1852. "[BTCoex], MEDIA disconnect notify\n");
  1853. /* only 2.4G we need to inform bt the chnl mask */
  1854. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  1855. &wifiCentralChnl);
  1856. if ((BTC_MEDIA_CONNECT == type) &&
  1857. (wifiCentralChnl <= 14)) {
  1858. h2c_parameter[0] = 0x0;
  1859. h2c_parameter[1] = wifiCentralChnl;
  1860. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  1861. if (BTC_WIFI_BW_HT40 == wifi_bw)
  1862. h2c_parameter[2] = 0x30;
  1863. else
  1864. h2c_parameter[2] = 0x20;
  1865. }
  1866. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  1867. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  1868. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  1869. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1870. "[BTCoex], FW write 0x66 = 0x%x\n",
  1871. h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
  1872. h2c_parameter[2]);
  1873. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  1874. }
  1875. void ex_halbtc8723b1ant_special_packet_notify(struct btc_coexist *btcoexist,
  1876. u8 type)
  1877. {
  1878. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1879. bool bt_hs_on = false;
  1880. u32 wifi_link_status = 0;
  1881. u32 num_of_wifi_link = 0;
  1882. bool bt_ctrl_agg_buf_size = false;
  1883. u8 agg_buf_size = 5;
  1884. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  1885. btcoexist->bt_info.bt_disabled)
  1886. return;
  1887. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1888. &wifi_link_status);
  1889. num_of_wifi_link = wifi_link_status >> 16;
  1890. if (num_of_wifi_link >= 2) {
  1891. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1892. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1893. bt_ctrl_agg_buf_size, agg_buf_size);
  1894. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  1895. return;
  1896. }
  1897. coex_sta->special_pkt_period_cnt = 0;
  1898. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1899. if (coex_sta->c2h_bt_inquiry_page) {
  1900. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  1901. return;
  1902. } else if (bt_hs_on) {
  1903. halbtc8723b1ant_action_hs(btcoexist);
  1904. return;
  1905. }
  1906. if (BTC_PACKET_DHCP == type ||
  1907. BTC_PACKET_EAPOL == type) {
  1908. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1909. "[BTCoex], special Packet(%d) notify\n", type);
  1910. halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
  1911. }
  1912. }
  1913. void ex_halbtc8723b1ant_bt_info_notify(struct btc_coexist *btcoexist,
  1914. u8 *tmp_buf, u8 length)
  1915. {
  1916. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1917. u8 bt_info = 0;
  1918. u8 i, rsp_source = 0;
  1919. bool wifi_connected = false;
  1920. bool bt_busy = false;
  1921. coex_sta->c2h_bt_info_req_sent = false;
  1922. rsp_source = tmp_buf[0] & 0xf;
  1923. if (rsp_source >= BT_INFO_SRC_8723B_1ANT_MAX)
  1924. rsp_source = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
  1925. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  1926. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1927. "[BTCoex], Bt info[%d], length=%d, hex data = [",
  1928. rsp_source, length);
  1929. for (i = 0; i < length; i++) {
  1930. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  1931. if (i == 1)
  1932. bt_info = tmp_buf[i];
  1933. if (i == length - 1)
  1934. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1935. "0x%02x]\n", tmp_buf[i]);
  1936. else
  1937. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1938. "0x%02x, ", tmp_buf[i]);
  1939. }
  1940. if (BT_INFO_SRC_8723B_1ANT_WIFI_FW != rsp_source) {
  1941. coex_sta->bt_retry_cnt = /* [3:0] */
  1942. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  1943. coex_sta->bt_rssi =
  1944. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  1945. coex_sta->bt_info_ext =
  1946. coex_sta->bt_info_c2h[rsp_source][4];
  1947. /* Here we need to resend some wifi info to BT
  1948. * because bt is reset and loss of the info.
  1949. */
  1950. if (coex_sta->bt_info_ext & BIT1) {
  1951. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1952. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  1953. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1954. &wifi_connected);
  1955. if (wifi_connected)
  1956. ex_halbtc8723b1ant_media_status_notify(btcoexist,
  1957. BTC_MEDIA_CONNECT);
  1958. else
  1959. ex_halbtc8723b1ant_media_status_notify(btcoexist,
  1960. BTC_MEDIA_DISCONNECT);
  1961. }
  1962. if (coex_sta->bt_info_ext & BIT3) {
  1963. if (!btcoexist->manual_control &&
  1964. !btcoexist->stop_coex_dm) {
  1965. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1966. "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
  1967. halbtc8723b1ant_ignore_wlan_act(btcoexist,
  1968. FORCE_EXEC,
  1969. false);
  1970. }
  1971. } else {
  1972. /* BT already NOT ignore Wlan active, do nothing here.*/
  1973. }
  1974. #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
  1975. if (coex_sta->bt_info_ext & BIT4) {
  1976. /* BT auto report already enabled, do nothing */
  1977. } else {
  1978. halbtc8723b1ant_bt_auto_report(btcoexist, FORCE_EXEC,
  1979. true);
  1980. }
  1981. #endif
  1982. }
  1983. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  1984. if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE)
  1985. coex_sta->c2h_bt_inquiry_page = true;
  1986. else
  1987. coex_sta->c2h_bt_inquiry_page = false;
  1988. /* set link exist status */
  1989. if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) {
  1990. coex_sta->bt_link_exist = false;
  1991. coex_sta->pan_exist = false;
  1992. coex_sta->a2dp_exist = false;
  1993. coex_sta->hid_exist = false;
  1994. coex_sta->sco_exist = false;
  1995. } else {
  1996. /* connection exists */
  1997. coex_sta->bt_link_exist = true;
  1998. if (bt_info & BT_INFO_8723B_1ANT_B_FTP)
  1999. coex_sta->pan_exist = true;
  2000. else
  2001. coex_sta->pan_exist = false;
  2002. if (bt_info & BT_INFO_8723B_1ANT_B_A2DP)
  2003. coex_sta->a2dp_exist = true;
  2004. else
  2005. coex_sta->a2dp_exist = false;
  2006. if (bt_info & BT_INFO_8723B_1ANT_B_HID)
  2007. coex_sta->hid_exist = true;
  2008. else
  2009. coex_sta->hid_exist = false;
  2010. if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO)
  2011. coex_sta->sco_exist = true;
  2012. else
  2013. coex_sta->sco_exist = false;
  2014. }
  2015. halbtc8723b1ant_update_bt_link_info(btcoexist);
  2016. if (!(bt_info&BT_INFO_8723B_1ANT_B_CONNECTION)) {
  2017. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  2018. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2019. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
  2020. /* connection exists but no busy */
  2021. } else if (bt_info == BT_INFO_8723B_1ANT_B_CONNECTION) {
  2022. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
  2023. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2024. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  2025. } else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
  2026. (bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY)) {
  2027. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
  2028. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2029. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  2030. } else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) {
  2031. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  2032. coex_dm->auto_tdma_adjust = false;
  2033. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
  2034. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2035. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  2036. } else {
  2037. coex_dm->bt_status =
  2038. BT_8723B_1ANT_BT_STATUS_MAX;
  2039. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2040. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
  2041. }
  2042. if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2043. (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2044. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2045. bt_busy = true;
  2046. else
  2047. bt_busy = false;
  2048. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2049. halbtc8723b1ant_run_coexist_mechanism(btcoexist);
  2050. }
  2051. void ex_halbtc8723b1ant_halt_notify(struct btc_coexist *btcoexist)
  2052. {
  2053. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2054. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n");
  2055. btcoexist->stop_coex_dm = true;
  2056. halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
  2057. halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2058. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2059. 0x0, 0x0);
  2060. halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2061. ex_halbtc8723b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  2062. }
  2063. void ex_halbtc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
  2064. {
  2065. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2066. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
  2067. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  2068. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2069. "[BTCoex], Pnp notify to SLEEP\n");
  2070. btcoexist->stop_coex_dm = true;
  2071. halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
  2072. true);
  2073. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2074. 0x0, 0x0);
  2075. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2076. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2077. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  2078. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2079. "[BTCoex], Pnp notify to WAKE UP\n");
  2080. btcoexist->stop_coex_dm = false;
  2081. halbtc8723b1ant_init_hw_config(btcoexist, false);
  2082. halbtc8723b1ant_init_coex_dm(btcoexist);
  2083. halbtc8723b1ant_query_bt_info(btcoexist);
  2084. }
  2085. }
  2086. void ex_halbtc8723b1ant_coex_dm_reset(struct btc_coexist *btcoexist)
  2087. {
  2088. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2089. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2090. "[BTCoex], *****************Coex DM Reset****************\n");
  2091. halbtc8723b1ant_init_hw_config(btcoexist, false);
  2092. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2093. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
  2094. halbtc8723b1ant_init_coex_dm(btcoexist);
  2095. }
  2096. void ex_halbtc8723b1ant_periodical(struct btc_coexist *btcoexist)
  2097. {
  2098. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2099. struct btc_board_info *board_info = &btcoexist->board_info;
  2100. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  2101. static u8 dis_ver_info_cnt;
  2102. u32 fw_ver = 0, bt_patch_ver = 0;
  2103. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2104. "[BTCoex], ==========================Periodical===========================\n");
  2105. if (dis_ver_info_cnt <= 5) {
  2106. dis_ver_info_cnt += 1;
  2107. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2108. "[BTCoex], ****************************************************************\n");
  2109. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2110. "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
  2111. board_info->pg_ant_num, board_info->btdm_ant_num,
  2112. board_info->btdm_ant_pos);
  2113. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2114. "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
  2115. stack_info->profile_notified ? "Yes" : "No",
  2116. stack_info->hci_version);
  2117. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
  2118. &bt_patch_ver);
  2119. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2120. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2121. "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
  2122. glcoex_ver_date_8723b_1ant,
  2123. glcoex_ver_8723b_1ant, fw_ver,
  2124. bt_patch_ver, bt_patch_ver);
  2125. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2126. "[BTCoex], ****************************************************************\n");
  2127. }
  2128. #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
  2129. halbtc8723b1ant_query_bt_info(btcoexist);
  2130. halbtc8723b1ant_monitor_bt_ctr(btcoexist);
  2131. halbtc8723b1ant_monitor_bt_enable_disable(btcoexist);
  2132. #else
  2133. if (btc8723b1ant_is_wifi_status_changed(btcoexist) ||
  2134. coex_dm->auto_tdma_adjust) {
  2135. halbtc8723b1ant_run_coexist_mechanism(btcoexist);
  2136. }
  2137. coex_sta->special_pkt_period_cnt++;
  2138. #endif
  2139. }