ar9003_mci.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/export.h>
  17. #include "hw.h"
  18. #include "hw-ops.h"
  19. #include "ar9003_phy.h"
  20. #include "ar9003_mci.h"
  21. #include "ar9003_aic.h"
  22. static void ar9003_mci_reset_req_wakeup(struct ath_hw *ah)
  23. {
  24. REG_RMW_FIELD(ah, AR_MCI_COMMAND2,
  25. AR_MCI_COMMAND2_RESET_REQ_WAKEUP, 1);
  26. udelay(1);
  27. REG_RMW_FIELD(ah, AR_MCI_COMMAND2,
  28. AR_MCI_COMMAND2_RESET_REQ_WAKEUP, 0);
  29. }
  30. static int ar9003_mci_wait_for_interrupt(struct ath_hw *ah, u32 address,
  31. u32 bit_position, int time_out)
  32. {
  33. struct ath_common *common = ath9k_hw_common(ah);
  34. while (time_out) {
  35. if (!(REG_READ(ah, address) & bit_position)) {
  36. udelay(10);
  37. time_out -= 10;
  38. if (time_out < 0)
  39. break;
  40. else
  41. continue;
  42. }
  43. REG_WRITE(ah, address, bit_position);
  44. if (address != AR_MCI_INTERRUPT_RX_MSG_RAW)
  45. break;
  46. if (bit_position & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)
  47. ar9003_mci_reset_req_wakeup(ah);
  48. if (bit_position & (AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING |
  49. AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING))
  50. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
  51. AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
  52. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_RX_MSG);
  53. break;
  54. }
  55. if (time_out <= 0) {
  56. ath_dbg(common, MCI,
  57. "MCI Wait for Reg 0x%08x = 0x%08x timeout\n",
  58. address, bit_position);
  59. ath_dbg(common, MCI,
  60. "MCI INT_RAW = 0x%08x, RX_MSG_RAW = 0x%08x\n",
  61. REG_READ(ah, AR_MCI_INTERRUPT_RAW),
  62. REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
  63. time_out = 0;
  64. }
  65. return time_out;
  66. }
  67. static void ar9003_mci_remote_reset(struct ath_hw *ah, bool wait_done)
  68. {
  69. u32 payload[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00};
  70. ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0, payload, 16,
  71. wait_done, false);
  72. udelay(5);
  73. }
  74. static void ar9003_mci_send_lna_transfer(struct ath_hw *ah, bool wait_done)
  75. {
  76. u32 payload = 0x00000000;
  77. ar9003_mci_send_message(ah, MCI_LNA_TRANS, 0, &payload, 1,
  78. wait_done, false);
  79. }
  80. static void ar9003_mci_send_req_wake(struct ath_hw *ah, bool wait_done)
  81. {
  82. ar9003_mci_send_message(ah, MCI_REQ_WAKE, MCI_FLAG_DISABLE_TIMESTAMP,
  83. NULL, 0, wait_done, false);
  84. udelay(5);
  85. }
  86. static void ar9003_mci_send_sys_waking(struct ath_hw *ah, bool wait_done)
  87. {
  88. ar9003_mci_send_message(ah, MCI_SYS_WAKING, MCI_FLAG_DISABLE_TIMESTAMP,
  89. NULL, 0, wait_done, false);
  90. }
  91. static void ar9003_mci_send_lna_take(struct ath_hw *ah, bool wait_done)
  92. {
  93. u32 payload = 0x70000000;
  94. ar9003_mci_send_message(ah, MCI_LNA_TAKE, 0, &payload, 1,
  95. wait_done, false);
  96. }
  97. static void ar9003_mci_send_sys_sleeping(struct ath_hw *ah, bool wait_done)
  98. {
  99. ar9003_mci_send_message(ah, MCI_SYS_SLEEPING,
  100. MCI_FLAG_DISABLE_TIMESTAMP,
  101. NULL, 0, wait_done, false);
  102. }
  103. static void ar9003_mci_send_coex_version_query(struct ath_hw *ah,
  104. bool wait_done)
  105. {
  106. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  107. u32 payload[4] = {0, 0, 0, 0};
  108. if (mci->bt_version_known ||
  109. (mci->bt_state == MCI_BT_SLEEP))
  110. return;
  111. MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
  112. MCI_GPM_COEX_VERSION_QUERY);
  113. ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
  114. }
  115. static void ar9003_mci_send_coex_version_response(struct ath_hw *ah,
  116. bool wait_done)
  117. {
  118. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  119. u32 payload[4] = {0, 0, 0, 0};
  120. MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
  121. MCI_GPM_COEX_VERSION_RESPONSE);
  122. *(((u8 *)payload) + MCI_GPM_COEX_B_MAJOR_VERSION) =
  123. mci->wlan_ver_major;
  124. *(((u8 *)payload) + MCI_GPM_COEX_B_MINOR_VERSION) =
  125. mci->wlan_ver_minor;
  126. ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
  127. }
  128. static void ar9003_mci_send_coex_wlan_channels(struct ath_hw *ah,
  129. bool wait_done)
  130. {
  131. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  132. u32 *payload = &mci->wlan_channels[0];
  133. if (!mci->wlan_channels_update ||
  134. (mci->bt_state == MCI_BT_SLEEP))
  135. return;
  136. MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
  137. MCI_GPM_COEX_WLAN_CHANNELS);
  138. ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
  139. MCI_GPM_SET_TYPE_OPCODE(payload, 0xff, 0xff);
  140. }
  141. static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah,
  142. bool wait_done, u8 query_type)
  143. {
  144. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  145. u32 payload[4] = {0, 0, 0, 0};
  146. bool query_btinfo;
  147. if (mci->bt_state == MCI_BT_SLEEP)
  148. return;
  149. query_btinfo = !!(query_type & (MCI_GPM_COEX_QUERY_BT_ALL_INFO |
  150. MCI_GPM_COEX_QUERY_BT_TOPOLOGY));
  151. MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
  152. MCI_GPM_COEX_STATUS_QUERY);
  153. *(((u8 *)payload) + MCI_GPM_COEX_B_BT_BITMAP) = query_type;
  154. /*
  155. * If bt_status_query message is not sent successfully,
  156. * then need_flush_btinfo should be set again.
  157. */
  158. if (!ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
  159. wait_done, true)) {
  160. if (query_btinfo)
  161. mci->need_flush_btinfo = true;
  162. }
  163. if (query_btinfo)
  164. mci->query_bt = false;
  165. }
  166. static void ar9003_mci_send_coex_halt_bt_gpm(struct ath_hw *ah, bool halt,
  167. bool wait_done)
  168. {
  169. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  170. u32 payload[4] = {0, 0, 0, 0};
  171. MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
  172. MCI_GPM_COEX_HALT_BT_GPM);
  173. if (halt) {
  174. mci->query_bt = true;
  175. /* Send next unhalt no matter halt sent or not */
  176. mci->unhalt_bt_gpm = true;
  177. mci->need_flush_btinfo = true;
  178. *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
  179. MCI_GPM_COEX_BT_GPM_HALT;
  180. } else
  181. *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
  182. MCI_GPM_COEX_BT_GPM_UNHALT;
  183. ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
  184. }
  185. static void ar9003_mci_prep_interface(struct ath_hw *ah)
  186. {
  187. struct ath_common *common = ath9k_hw_common(ah);
  188. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  189. u32 saved_mci_int_en;
  190. u32 mci_timeout = 150;
  191. mci->bt_state = MCI_BT_SLEEP;
  192. saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
  193. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
  194. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  195. REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
  196. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
  197. REG_READ(ah, AR_MCI_INTERRUPT_RAW));
  198. ar9003_mci_remote_reset(ah, true);
  199. ar9003_mci_send_req_wake(ah, true);
  200. if (!ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  201. AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING, 500))
  202. goto clear_redunt;
  203. mci->bt_state = MCI_BT_AWAKE;
  204. /*
  205. * we don't need to send more remote_reset at this moment.
  206. * If BT receive first remote_reset, then BT HW will
  207. * be cleaned up and will be able to receive req_wake
  208. * and BT HW will respond sys_waking.
  209. * In this case, WLAN will receive BT's HW sys_waking.
  210. * Otherwise, if BT SW missed initial remote_reset,
  211. * that remote_reset will still clean up BT MCI RX,
  212. * and the req_wake will wake BT up,
  213. * and BT SW will respond this req_wake with a remote_reset and
  214. * sys_waking. In this case, WLAN will receive BT's SW
  215. * sys_waking. In either case, BT's RX is cleaned up. So we
  216. * don't need to reply BT's remote_reset now, if any.
  217. * Similarly, if in any case, WLAN can receive BT's sys_waking,
  218. * that means WLAN's RX is also fine.
  219. */
  220. ar9003_mci_send_sys_waking(ah, true);
  221. udelay(10);
  222. /*
  223. * Set BT priority interrupt value to be 0xff to
  224. * avoid having too many BT PRIORITY interrupts.
  225. */
  226. REG_WRITE(ah, AR_MCI_BT_PRI0, 0xFFFFFFFF);
  227. REG_WRITE(ah, AR_MCI_BT_PRI1, 0xFFFFFFFF);
  228. REG_WRITE(ah, AR_MCI_BT_PRI2, 0xFFFFFFFF);
  229. REG_WRITE(ah, AR_MCI_BT_PRI3, 0xFFFFFFFF);
  230. REG_WRITE(ah, AR_MCI_BT_PRI, 0X000000FF);
  231. /*
  232. * A contention reset will be received after send out
  233. * sys_waking. Also BT priority interrupt bits will be set.
  234. * Clear those bits before the next step.
  235. */
  236. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  237. AR_MCI_INTERRUPT_RX_MSG_CONT_RST);
  238. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_BT_PRI);
  239. if (mci->is_2g && MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
  240. ar9003_mci_send_lna_transfer(ah, true);
  241. udelay(5);
  242. }
  243. if (mci->is_2g && !mci->update_2g5g && MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
  244. if (ar9003_mci_wait_for_interrupt(ah,
  245. AR_MCI_INTERRUPT_RX_MSG_RAW,
  246. AR_MCI_INTERRUPT_RX_MSG_LNA_INFO,
  247. mci_timeout))
  248. ath_dbg(common, MCI,
  249. "MCI WLAN has control over the LNA & BT obeys it\n");
  250. else
  251. ath_dbg(common, MCI,
  252. "MCI BT didn't respond to LNA_TRANS\n");
  253. }
  254. clear_redunt:
  255. /* Clear the extra redundant SYS_WAKING from BT */
  256. if ((mci->bt_state == MCI_BT_AWAKE) &&
  257. (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  258. AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING)) &&
  259. (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  260. AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) == 0)) {
  261. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  262. AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING);
  263. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
  264. AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
  265. }
  266. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
  267. }
  268. void ar9003_mci_set_full_sleep(struct ath_hw *ah)
  269. {
  270. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  271. if (ar9003_mci_state(ah, MCI_STATE_ENABLE) &&
  272. (mci->bt_state != MCI_BT_SLEEP) &&
  273. !mci->halted_bt_gpm) {
  274. ar9003_mci_send_coex_halt_bt_gpm(ah, true, true);
  275. }
  276. mci->ready = false;
  277. }
  278. static void ar9003_mci_disable_interrupt(struct ath_hw *ah)
  279. {
  280. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
  281. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
  282. }
  283. static void ar9003_mci_enable_interrupt(struct ath_hw *ah)
  284. {
  285. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, AR_MCI_INTERRUPT_DEFAULT);
  286. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
  287. AR_MCI_INTERRUPT_RX_MSG_DEFAULT);
  288. }
  289. static bool ar9003_mci_check_int(struct ath_hw *ah, u32 ints)
  290. {
  291. u32 intr;
  292. intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
  293. return ((intr & ints) == ints);
  294. }
  295. void ar9003_mci_get_interrupt(struct ath_hw *ah, u32 *raw_intr,
  296. u32 *rx_msg_intr)
  297. {
  298. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  299. *raw_intr = mci->raw_intr;
  300. *rx_msg_intr = mci->rx_msg_intr;
  301. /* Clean int bits after the values are read. */
  302. mci->raw_intr = 0;
  303. mci->rx_msg_intr = 0;
  304. }
  305. EXPORT_SYMBOL(ar9003_mci_get_interrupt);
  306. void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
  307. {
  308. struct ath_common *common = ath9k_hw_common(ah);
  309. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  310. u32 raw_intr, rx_msg_intr;
  311. rx_msg_intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
  312. raw_intr = REG_READ(ah, AR_MCI_INTERRUPT_RAW);
  313. if ((raw_intr == 0xdeadbeef) || (rx_msg_intr == 0xdeadbeef)) {
  314. ath_dbg(common, MCI,
  315. "MCI gets 0xdeadbeef during int processing\n");
  316. } else {
  317. mci->rx_msg_intr |= rx_msg_intr;
  318. mci->raw_intr |= raw_intr;
  319. *masked |= ATH9K_INT_MCI;
  320. if (rx_msg_intr & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO)
  321. mci->cont_status = REG_READ(ah, AR_MCI_CONT_STATUS);
  322. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, rx_msg_intr);
  323. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, raw_intr);
  324. }
  325. }
  326. static void ar9003_mci_2g5g_changed(struct ath_hw *ah, bool is_2g)
  327. {
  328. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  329. if (!mci->update_2g5g &&
  330. (mci->is_2g != is_2g))
  331. mci->update_2g5g = true;
  332. mci->is_2g = is_2g;
  333. }
  334. static bool ar9003_mci_is_gpm_valid(struct ath_hw *ah, u32 msg_index)
  335. {
  336. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  337. u32 *payload;
  338. u32 recv_type, offset;
  339. if (msg_index == MCI_GPM_INVALID)
  340. return false;
  341. offset = msg_index << 4;
  342. payload = (u32 *)(mci->gpm_buf + offset);
  343. recv_type = MCI_GPM_TYPE(payload);
  344. if (recv_type == MCI_GPM_RSVD_PATTERN)
  345. return false;
  346. return true;
  347. }
  348. static void ar9003_mci_observation_set_up(struct ath_hw *ah)
  349. {
  350. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  351. if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MCI) {
  352. ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_DATA);
  353. ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_CLK);
  354. ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
  355. ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
  356. } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_TXRX) {
  357. ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_WL_IN_TX);
  358. ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_WL_IN_RX);
  359. ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
  360. ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
  361. ath9k_hw_cfg_output(ah, 5, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  362. } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_BT) {
  363. ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
  364. ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
  365. ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
  366. ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
  367. } else
  368. return;
  369. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  370. REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_DS_JTAG_DISABLE, 1);
  371. REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_WLAN_UART_INTF_EN, 0);
  372. REG_SET_BIT(ah, AR_GLB_GPIO_CONTROL, ATH_MCI_CONFIG_MCI_OBS_GPIO);
  373. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_GPIO_OBS_SEL, 0);
  374. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_MAC_BB_OBS_SEL, 1);
  375. REG_WRITE(ah, AR_OBS, 0x4b);
  376. REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL1, 0x03);
  377. REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL2, 0x01);
  378. REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_LSB, 0x02);
  379. REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_MSB, 0x03);
  380. REG_RMW_FIELD(ah, AR_PHY_TEST_CTL_STATUS,
  381. AR_PHY_TEST_CTL_DEBUGPORT_SEL, 0x07);
  382. }
  383. static bool ar9003_mci_send_coex_bt_flags(struct ath_hw *ah, bool wait_done,
  384. u8 opcode, u32 bt_flags)
  385. {
  386. u32 pld[4] = {0, 0, 0, 0};
  387. MCI_GPM_SET_TYPE_OPCODE(pld, MCI_GPM_COEX_AGENT,
  388. MCI_GPM_COEX_BT_UPDATE_FLAGS);
  389. *(((u8 *)pld) + MCI_GPM_COEX_B_BT_FLAGS_OP) = opcode;
  390. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 0) = bt_flags & 0xFF;
  391. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 1) = (bt_flags >> 8) & 0xFF;
  392. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 2) = (bt_flags >> 16) & 0xFF;
  393. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 3) = (bt_flags >> 24) & 0xFF;
  394. return ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16,
  395. wait_done, true);
  396. }
  397. static void ar9003_mci_sync_bt_state(struct ath_hw *ah)
  398. {
  399. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  400. u32 cur_bt_state;
  401. cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP);
  402. if (mci->bt_state != cur_bt_state)
  403. mci->bt_state = cur_bt_state;
  404. if (mci->bt_state != MCI_BT_SLEEP) {
  405. ar9003_mci_send_coex_version_query(ah, true);
  406. ar9003_mci_send_coex_wlan_channels(ah, true);
  407. if (mci->unhalt_bt_gpm == true)
  408. ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
  409. }
  410. }
  411. void ar9003_mci_check_bt(struct ath_hw *ah)
  412. {
  413. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  414. if (!mci_hw->ready)
  415. return;
  416. /*
  417. * check BT state again to make
  418. * sure it's not changed.
  419. */
  420. ar9003_mci_sync_bt_state(ah);
  421. ar9003_mci_2g5g_switch(ah, true);
  422. if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
  423. (mci_hw->query_bt == true)) {
  424. mci_hw->need_flush_btinfo = true;
  425. }
  426. }
  427. static void ar9003_mci_process_gpm_extra(struct ath_hw *ah, u8 gpm_type,
  428. u8 gpm_opcode, u32 *p_gpm)
  429. {
  430. struct ath_common *common = ath9k_hw_common(ah);
  431. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  432. u8 *p_data = (u8 *) p_gpm;
  433. if (gpm_type != MCI_GPM_COEX_AGENT)
  434. return;
  435. switch (gpm_opcode) {
  436. case MCI_GPM_COEX_VERSION_QUERY:
  437. ath_dbg(common, MCI, "MCI Recv GPM COEX Version Query\n");
  438. ar9003_mci_send_coex_version_response(ah, true);
  439. break;
  440. case MCI_GPM_COEX_VERSION_RESPONSE:
  441. ath_dbg(common, MCI, "MCI Recv GPM COEX Version Response\n");
  442. mci->bt_ver_major =
  443. *(p_data + MCI_GPM_COEX_B_MAJOR_VERSION);
  444. mci->bt_ver_minor =
  445. *(p_data + MCI_GPM_COEX_B_MINOR_VERSION);
  446. mci->bt_version_known = true;
  447. ath_dbg(common, MCI, "MCI BT Coex version: %d.%d\n",
  448. mci->bt_ver_major, mci->bt_ver_minor);
  449. break;
  450. case MCI_GPM_COEX_STATUS_QUERY:
  451. ath_dbg(common, MCI,
  452. "MCI Recv GPM COEX Status Query = 0x%02X\n",
  453. *(p_data + MCI_GPM_COEX_B_WLAN_BITMAP));
  454. mci->wlan_channels_update = true;
  455. ar9003_mci_send_coex_wlan_channels(ah, true);
  456. break;
  457. case MCI_GPM_COEX_BT_PROFILE_INFO:
  458. mci->query_bt = true;
  459. ath_dbg(common, MCI, "MCI Recv GPM COEX BT_Profile_Info\n");
  460. break;
  461. case MCI_GPM_COEX_BT_STATUS_UPDATE:
  462. mci->query_bt = true;
  463. ath_dbg(common, MCI,
  464. "MCI Recv GPM COEX BT_Status_Update SEQ=%d (drop&query)\n",
  465. *(p_gpm + 3));
  466. break;
  467. default:
  468. break;
  469. }
  470. }
  471. static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
  472. u8 gpm_opcode, int time_out)
  473. {
  474. struct ath_common *common = ath9k_hw_common(ah);
  475. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  476. u32 *p_gpm = NULL, mismatch = 0, more_data;
  477. u32 offset;
  478. u8 recv_type = 0, recv_opcode = 0;
  479. bool b_is_bt_cal_done = (gpm_type == MCI_GPM_BT_CAL_DONE);
  480. more_data = time_out ? MCI_GPM_NOMORE : MCI_GPM_MORE;
  481. while (time_out > 0) {
  482. if (p_gpm) {
  483. MCI_GPM_RECYCLE(p_gpm);
  484. p_gpm = NULL;
  485. }
  486. if (more_data != MCI_GPM_MORE)
  487. time_out = ar9003_mci_wait_for_interrupt(ah,
  488. AR_MCI_INTERRUPT_RX_MSG_RAW,
  489. AR_MCI_INTERRUPT_RX_MSG_GPM,
  490. time_out);
  491. if (!time_out)
  492. break;
  493. offset = ar9003_mci_get_next_gpm_offset(ah, &more_data);
  494. if (offset == MCI_GPM_INVALID)
  495. continue;
  496. p_gpm = (u32 *) (mci->gpm_buf + offset);
  497. recv_type = MCI_GPM_TYPE(p_gpm);
  498. recv_opcode = MCI_GPM_OPCODE(p_gpm);
  499. if (MCI_GPM_IS_CAL_TYPE(recv_type)) {
  500. if (recv_type == gpm_type) {
  501. if ((gpm_type == MCI_GPM_BT_CAL_DONE) &&
  502. !b_is_bt_cal_done) {
  503. gpm_type = MCI_GPM_BT_CAL_GRANT;
  504. continue;
  505. }
  506. break;
  507. }
  508. } else if ((recv_type == gpm_type) &&
  509. (recv_opcode == gpm_opcode))
  510. break;
  511. /*
  512. * check if it's cal_grant
  513. *
  514. * When we're waiting for cal_grant in reset routine,
  515. * it's possible that BT sends out cal_request at the
  516. * same time. Since BT's calibration doesn't happen
  517. * that often, we'll let BT completes calibration then
  518. * we continue to wait for cal_grant from BT.
  519. * Orginal: Wait BT_CAL_GRANT.
  520. * New: Receive BT_CAL_REQ -> send WLAN_CAL_GRANT->wait
  521. * BT_CAL_DONE -> Wait BT_CAL_GRANT.
  522. */
  523. if ((gpm_type == MCI_GPM_BT_CAL_GRANT) &&
  524. (recv_type == MCI_GPM_BT_CAL_REQ)) {
  525. u32 payload[4] = {0, 0, 0, 0};
  526. gpm_type = MCI_GPM_BT_CAL_DONE;
  527. MCI_GPM_SET_CAL_TYPE(payload,
  528. MCI_GPM_WLAN_CAL_GRANT);
  529. ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
  530. false, false);
  531. continue;
  532. } else {
  533. ath_dbg(common, MCI, "MCI GPM subtype not match 0x%x\n",
  534. *(p_gpm + 1));
  535. mismatch++;
  536. ar9003_mci_process_gpm_extra(ah, recv_type,
  537. recv_opcode, p_gpm);
  538. }
  539. }
  540. if (p_gpm) {
  541. MCI_GPM_RECYCLE(p_gpm);
  542. p_gpm = NULL;
  543. }
  544. if (time_out <= 0)
  545. time_out = 0;
  546. while (more_data == MCI_GPM_MORE) {
  547. offset = ar9003_mci_get_next_gpm_offset(ah, &more_data);
  548. if (offset == MCI_GPM_INVALID)
  549. break;
  550. p_gpm = (u32 *) (mci->gpm_buf + offset);
  551. recv_type = MCI_GPM_TYPE(p_gpm);
  552. recv_opcode = MCI_GPM_OPCODE(p_gpm);
  553. if (!MCI_GPM_IS_CAL_TYPE(recv_type))
  554. ar9003_mci_process_gpm_extra(ah, recv_type,
  555. recv_opcode, p_gpm);
  556. MCI_GPM_RECYCLE(p_gpm);
  557. }
  558. return time_out;
  559. }
  560. bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan)
  561. {
  562. struct ath_common *common = ath9k_hw_common(ah);
  563. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  564. u32 payload[4] = {0, 0, 0, 0};
  565. ar9003_mci_2g5g_changed(ah, IS_CHAN_2GHZ(chan));
  566. if (mci_hw->bt_state != MCI_BT_CAL_START)
  567. return false;
  568. mci_hw->bt_state = MCI_BT_CAL;
  569. /*
  570. * MCI FIX: disable mci interrupt here. This is to avoid
  571. * SW_MSG_DONE or RX_MSG bits to trigger MCI_INT and
  572. * lead to mci_intr reentry.
  573. */
  574. ar9003_mci_disable_interrupt(ah);
  575. MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_GRANT);
  576. ar9003_mci_send_message(ah, MCI_GPM, 0, payload,
  577. 16, true, false);
  578. /* Wait BT calibration to be completed for 25ms */
  579. if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_DONE,
  580. 0, 25000))
  581. ath_dbg(common, MCI, "MCI BT_CAL_DONE received\n");
  582. else
  583. ath_dbg(common, MCI,
  584. "MCI BT_CAL_DONE not received\n");
  585. mci_hw->bt_state = MCI_BT_AWAKE;
  586. /* MCI FIX: enable mci interrupt here */
  587. ar9003_mci_enable_interrupt(ah);
  588. return true;
  589. }
  590. int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  591. struct ath9k_hw_cal_data *caldata)
  592. {
  593. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  594. if (!mci_hw->ready)
  595. return 0;
  596. if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP))
  597. goto exit;
  598. if (!ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) &&
  599. !ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE))
  600. goto exit;
  601. /*
  602. * BT is sleeping. Check if BT wakes up during
  603. * WLAN calibration. If BT wakes up during
  604. * WLAN calibration, need to go through all
  605. * message exchanges again and recal.
  606. */
  607. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  608. (AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
  609. AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE));
  610. ar9003_mci_remote_reset(ah, true);
  611. ar9003_mci_send_sys_waking(ah, true);
  612. udelay(1);
  613. if (IS_CHAN_2GHZ(chan))
  614. ar9003_mci_send_lna_transfer(ah, true);
  615. mci_hw->bt_state = MCI_BT_AWAKE;
  616. REG_CLR_BIT(ah, AR_PHY_TIMING4,
  617. 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
  618. if (caldata) {
  619. clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
  620. clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
  621. clear_bit(RTT_DONE, &caldata->cal_flags);
  622. }
  623. if (!ath9k_hw_init_cal(ah, chan))
  624. return -EIO;
  625. REG_SET_BIT(ah, AR_PHY_TIMING4,
  626. 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
  627. exit:
  628. ar9003_mci_enable_interrupt(ah);
  629. return 0;
  630. }
  631. static void ar9003_mci_mute_bt(struct ath_hw *ah)
  632. {
  633. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  634. /* disable all MCI messages */
  635. REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE, 0xffff0000);
  636. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS0, 0xffffffff);
  637. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS1, 0xffffffff);
  638. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS2, 0xffffffff);
  639. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS3, 0xffffffff);
  640. REG_SET_BIT(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  641. /* wait pending HW messages to flush out */
  642. udelay(10);
  643. /*
  644. * Send LNA_TAKE and SYS_SLEEPING when
  645. * 1. reset not after resuming from full sleep
  646. * 2. before reset MCI RX, to quiet BT and avoid MCI RX misalignment
  647. */
  648. if (MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
  649. ar9003_mci_send_lna_take(ah, true);
  650. udelay(5);
  651. }
  652. ar9003_mci_send_sys_sleeping(ah, true);
  653. }
  654. static void ar9003_mci_osla_setup(struct ath_hw *ah, bool enable)
  655. {
  656. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  657. u32 thresh;
  658. if (!enable) {
  659. REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
  660. AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  661. return;
  662. }
  663. REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2, AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
  664. REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
  665. AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
  666. if (AR_SREV_9565(ah))
  667. REG_RMW_FIELD(ah, AR_MCI_MISC, AR_MCI_MISC_HW_FIX_EN, 1);
  668. if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
  669. thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
  670. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  671. AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
  672. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  673. AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
  674. } else
  675. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  676. AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
  677. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  678. AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
  679. }
  680. static void ar9003_mci_stat_setup(struct ath_hw *ah)
  681. {
  682. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  683. if (!AR_SREV_9565(ah))
  684. return;
  685. if (mci->config & ATH_MCI_CONFIG_MCI_STAT_DBG) {
  686. REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
  687. AR_MCI_DBG_CNT_CTRL_ENABLE, 1);
  688. REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
  689. AR_MCI_DBG_CNT_CTRL_BT_LINKID,
  690. MCI_STAT_ALL_BT_LINKID);
  691. } else {
  692. REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
  693. AR_MCI_DBG_CNT_CTRL_ENABLE, 0);
  694. }
  695. }
  696. static void ar9003_mci_set_btcoex_ctrl_9565_1ANT(struct ath_hw *ah)
  697. {
  698. u32 regval;
  699. regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
  700. SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
  701. SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
  702. SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
  703. SM(1, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
  704. SM(1, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
  705. SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
  706. SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
  707. SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  708. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  709. AR_BTCOEX_CTRL2_TX_CHAIN_MASK, 0x1);
  710. REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
  711. }
  712. static void ar9003_mci_set_btcoex_ctrl_9565_2ANT(struct ath_hw *ah)
  713. {
  714. u32 regval;
  715. regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
  716. SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
  717. SM(0, AR_BTCOEX_CTRL_PA_SHARED) |
  718. SM(0, AR_BTCOEX_CTRL_LNA_SHARED) |
  719. SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
  720. SM(1, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
  721. SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
  722. SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
  723. SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  724. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  725. AR_BTCOEX_CTRL2_TX_CHAIN_MASK, 0x0);
  726. REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
  727. }
  728. static void ar9003_mci_set_btcoex_ctrl_9462(struct ath_hw *ah)
  729. {
  730. u32 regval;
  731. regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
  732. SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
  733. SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
  734. SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
  735. SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
  736. SM(3, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
  737. SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
  738. SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
  739. SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  740. REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
  741. }
  742. int ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
  743. bool is_full_sleep)
  744. {
  745. struct ath_common *common = ath9k_hw_common(ah);
  746. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  747. u32 regval, i;
  748. ath_dbg(common, MCI, "MCI Reset (full_sleep = %d, is_2g = %d)\n",
  749. is_full_sleep, is_2g);
  750. if (REG_READ(ah, AR_BTCOEX_CTRL) == 0xdeadbeef) {
  751. ath_err(common, "BTCOEX control register is dead\n");
  752. return -EINVAL;
  753. }
  754. /* Program MCI DMA related registers */
  755. REG_WRITE(ah, AR_MCI_GPM_0, mci->gpm_addr);
  756. REG_WRITE(ah, AR_MCI_GPM_1, mci->gpm_len);
  757. REG_WRITE(ah, AR_MCI_SCHD_TABLE_0, mci->sched_addr);
  758. /*
  759. * To avoid MCI state machine be affected by incoming remote MCI msgs,
  760. * MCI mode will be enabled later, right before reset the MCI TX and RX.
  761. */
  762. if (AR_SREV_9565(ah)) {
  763. u8 ant = MS(mci->config, ATH_MCI_CONFIG_ANT_ARCH);
  764. if (ant == ATH_MCI_ANT_ARCH_1_ANT_PA_LNA_SHARED)
  765. ar9003_mci_set_btcoex_ctrl_9565_1ANT(ah);
  766. else
  767. ar9003_mci_set_btcoex_ctrl_9565_2ANT(ah);
  768. } else {
  769. ar9003_mci_set_btcoex_ctrl_9462(ah);
  770. }
  771. if (is_2g && !(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
  772. ar9003_mci_osla_setup(ah, true);
  773. else
  774. ar9003_mci_osla_setup(ah, false);
  775. REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
  776. AR_BTCOEX_CTRL_SPDT_ENABLE);
  777. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL3,
  778. AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT, 20);
  779. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_RX_DEWEIGHT, 0);
  780. REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
  781. /* Set the time out to 3.125ms (5 BT slots) */
  782. REG_RMW_FIELD(ah, AR_BTCOEX_WL_LNA, AR_BTCOEX_WL_LNA_TIMEOUT, 0x3D090);
  783. /* concurrent tx priority */
  784. if (mci->config & ATH_MCI_CONFIG_CONCUR_TX) {
  785. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  786. AR_BTCOEX_CTRL2_DESC_BASED_TXPWR_ENABLE, 0);
  787. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  788. AR_BTCOEX_CTRL2_TXPWR_THRESH, 0x7f);
  789. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  790. AR_BTCOEX_CTRL_REDUCE_TXPWR, 0);
  791. for (i = 0; i < 8; i++)
  792. REG_WRITE(ah, AR_BTCOEX_MAX_TXPWR(i), 0x7f7f7f7f);
  793. }
  794. regval = MS(mci->config, ATH_MCI_CONFIG_CLK_DIV);
  795. REG_RMW_FIELD(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_CLK_DIV, regval);
  796. REG_SET_BIT(ah, AR_BTCOEX_CTRL, AR_BTCOEX_CTRL_MCI_MODE_EN);
  797. /* Resetting the Rx and Tx paths of MCI */
  798. regval = REG_READ(ah, AR_MCI_COMMAND2);
  799. regval |= SM(1, AR_MCI_COMMAND2_RESET_TX);
  800. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  801. udelay(1);
  802. regval &= ~SM(1, AR_MCI_COMMAND2_RESET_TX);
  803. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  804. if (is_full_sleep) {
  805. ar9003_mci_mute_bt(ah);
  806. udelay(100);
  807. }
  808. /* Check pending GPM msg before MCI Reset Rx */
  809. ar9003_mci_check_gpm_offset(ah);
  810. regval |= SM(1, AR_MCI_COMMAND2_RESET_RX);
  811. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  812. udelay(1);
  813. regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX);
  814. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  815. /* Init GPM offset after MCI Reset Rx */
  816. ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET);
  817. REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE,
  818. (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) |
  819. SM(0x0000, AR_MCI_MSG_ATTRIBUTES_TABLE_CHECKSUM)));
  820. if (MCI_ANT_ARCH_PA_LNA_SHARED(mci))
  821. REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
  822. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  823. else
  824. REG_SET_BIT(ah, AR_MCI_TX_CTRL,
  825. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  826. ar9003_mci_observation_set_up(ah);
  827. mci->ready = true;
  828. ar9003_mci_prep_interface(ah);
  829. ar9003_mci_stat_setup(ah);
  830. if (en_int)
  831. ar9003_mci_enable_interrupt(ah);
  832. if (ath9k_hw_is_aic_enabled(ah))
  833. ar9003_aic_start_normal(ah);
  834. return 0;
  835. }
  836. void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep)
  837. {
  838. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  839. ar9003_mci_disable_interrupt(ah);
  840. if (mci_hw->ready && !save_fullsleep) {
  841. ar9003_mci_mute_bt(ah);
  842. udelay(20);
  843. REG_WRITE(ah, AR_BTCOEX_CTRL, 0);
  844. }
  845. mci_hw->bt_state = MCI_BT_SLEEP;
  846. mci_hw->ready = false;
  847. }
  848. static void ar9003_mci_send_2g5g_status(struct ath_hw *ah, bool wait_done)
  849. {
  850. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  851. u32 new_flags, to_set, to_clear;
  852. if (!mci->update_2g5g || (mci->bt_state == MCI_BT_SLEEP))
  853. return;
  854. if (mci->is_2g) {
  855. new_flags = MCI_2G_FLAGS;
  856. to_clear = MCI_2G_FLAGS_CLEAR_MASK;
  857. to_set = MCI_2G_FLAGS_SET_MASK;
  858. } else {
  859. new_flags = MCI_5G_FLAGS;
  860. to_clear = MCI_5G_FLAGS_CLEAR_MASK;
  861. to_set = MCI_5G_FLAGS_SET_MASK;
  862. }
  863. if (to_clear)
  864. ar9003_mci_send_coex_bt_flags(ah, wait_done,
  865. MCI_GPM_COEX_BT_FLAGS_CLEAR,
  866. to_clear);
  867. if (to_set)
  868. ar9003_mci_send_coex_bt_flags(ah, wait_done,
  869. MCI_GPM_COEX_BT_FLAGS_SET,
  870. to_set);
  871. }
  872. static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
  873. u32 *payload, bool queue)
  874. {
  875. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  876. u8 type, opcode;
  877. /* check if the message is to be queued */
  878. if (header != MCI_GPM)
  879. return;
  880. type = MCI_GPM_TYPE(payload);
  881. opcode = MCI_GPM_OPCODE(payload);
  882. if (type != MCI_GPM_COEX_AGENT)
  883. return;
  884. switch (opcode) {
  885. case MCI_GPM_COEX_BT_UPDATE_FLAGS:
  886. if (*(((u8 *)payload) + MCI_GPM_COEX_B_BT_FLAGS_OP) ==
  887. MCI_GPM_COEX_BT_FLAGS_READ)
  888. break;
  889. mci->update_2g5g = queue;
  890. break;
  891. case MCI_GPM_COEX_WLAN_CHANNELS:
  892. mci->wlan_channels_update = queue;
  893. break;
  894. case MCI_GPM_COEX_HALT_BT_GPM:
  895. if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
  896. MCI_GPM_COEX_BT_GPM_UNHALT) {
  897. mci->unhalt_bt_gpm = queue;
  898. if (!queue)
  899. mci->halted_bt_gpm = false;
  900. }
  901. if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
  902. MCI_GPM_COEX_BT_GPM_HALT) {
  903. mci->halted_bt_gpm = !queue;
  904. }
  905. break;
  906. default:
  907. break;
  908. }
  909. }
  910. void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool force)
  911. {
  912. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  913. if (!mci->update_2g5g && !force)
  914. return;
  915. if (mci->is_2g) {
  916. ar9003_mci_send_2g5g_status(ah, true);
  917. ar9003_mci_send_lna_transfer(ah, true);
  918. udelay(5);
  919. REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
  920. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  921. REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
  922. AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
  923. if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
  924. ar9003_mci_osla_setup(ah, true);
  925. if (AR_SREV_9462(ah))
  926. REG_WRITE(ah, AR_SELFGEN_MASK, 0x02);
  927. } else {
  928. ar9003_mci_send_lna_take(ah, true);
  929. udelay(5);
  930. REG_SET_BIT(ah, AR_MCI_TX_CTRL,
  931. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  932. REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
  933. AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
  934. ar9003_mci_osla_setup(ah, false);
  935. ar9003_mci_send_2g5g_status(ah, true);
  936. }
  937. }
  938. bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag,
  939. u32 *payload, u8 len, bool wait_done,
  940. bool check_bt)
  941. {
  942. struct ath_common *common = ath9k_hw_common(ah);
  943. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  944. bool msg_sent = false;
  945. u32 regval;
  946. u32 saved_mci_int_en;
  947. int i;
  948. saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
  949. regval = REG_READ(ah, AR_BTCOEX_CTRL);
  950. if ((regval == 0xdeadbeef) || !(regval & AR_BTCOEX_CTRL_MCI_MODE_EN)) {
  951. ath_dbg(common, MCI,
  952. "MCI Not sending 0x%x. MCI is not enabled. full_sleep = %d\n",
  953. header, (ah->power_mode == ATH9K_PM_FULL_SLEEP) ? 1 : 0);
  954. ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
  955. return false;
  956. } else if (check_bt && (mci->bt_state == MCI_BT_SLEEP)) {
  957. ath_dbg(common, MCI,
  958. "MCI Don't send message 0x%x. BT is in sleep state\n",
  959. header);
  960. ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
  961. return false;
  962. }
  963. if (wait_done)
  964. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
  965. /* Need to clear SW_MSG_DONE raw bit before wait */
  966. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
  967. (AR_MCI_INTERRUPT_SW_MSG_DONE |
  968. AR_MCI_INTERRUPT_MSG_FAIL_MASK));
  969. if (payload) {
  970. for (i = 0; (i * 4) < len; i++)
  971. REG_WRITE(ah, (AR_MCI_TX_PAYLOAD0 + i * 4),
  972. *(payload + i));
  973. }
  974. REG_WRITE(ah, AR_MCI_COMMAND0,
  975. (SM((flag & MCI_FLAG_DISABLE_TIMESTAMP),
  976. AR_MCI_COMMAND0_DISABLE_TIMESTAMP) |
  977. SM(len, AR_MCI_COMMAND0_LEN) |
  978. SM(header, AR_MCI_COMMAND0_HEADER)));
  979. if (wait_done &&
  980. !(ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RAW,
  981. AR_MCI_INTERRUPT_SW_MSG_DONE, 500)))
  982. ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
  983. else {
  984. ar9003_mci_queue_unsent_gpm(ah, header, payload, false);
  985. msg_sent = true;
  986. }
  987. if (wait_done)
  988. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
  989. return msg_sent;
  990. }
  991. EXPORT_SYMBOL(ar9003_mci_send_message);
  992. void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable)
  993. {
  994. struct ath_common *common = ath9k_hw_common(ah);
  995. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  996. u32 pld[4] = {0, 0, 0, 0};
  997. if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
  998. (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
  999. return;
  1000. MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_REQ);
  1001. pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_seq++;
  1002. ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
  1003. if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) {
  1004. ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n");
  1005. } else {
  1006. *is_reusable = false;
  1007. ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n");
  1008. }
  1009. }
  1010. void ar9003_mci_init_cal_done(struct ath_hw *ah)
  1011. {
  1012. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  1013. u32 pld[4] = {0, 0, 0, 0};
  1014. if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
  1015. (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
  1016. return;
  1017. MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_DONE);
  1018. pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_done++;
  1019. ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
  1020. }
  1021. int ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf,
  1022. u16 len, u32 sched_addr)
  1023. {
  1024. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1025. mci->gpm_addr = gpm_addr;
  1026. mci->gpm_buf = gpm_buf;
  1027. mci->gpm_len = len;
  1028. mci->sched_addr = sched_addr;
  1029. return ar9003_mci_reset(ah, true, true, true);
  1030. }
  1031. EXPORT_SYMBOL(ar9003_mci_setup);
  1032. void ar9003_mci_cleanup(struct ath_hw *ah)
  1033. {
  1034. /* Turn off MCI and Jupiter mode. */
  1035. REG_WRITE(ah, AR_BTCOEX_CTRL, 0x00);
  1036. ar9003_mci_disable_interrupt(ah);
  1037. }
  1038. EXPORT_SYMBOL(ar9003_mci_cleanup);
  1039. u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type)
  1040. {
  1041. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1042. u32 value = 0, tsf;
  1043. u8 query_type;
  1044. switch (state_type) {
  1045. case MCI_STATE_ENABLE:
  1046. if (mci->ready) {
  1047. value = REG_READ(ah, AR_BTCOEX_CTRL);
  1048. if ((value == 0xdeadbeef) || (value == 0xffffffff))
  1049. value = 0;
  1050. }
  1051. value &= AR_BTCOEX_CTRL_MCI_MODE_EN;
  1052. break;
  1053. case MCI_STATE_INIT_GPM_OFFSET:
  1054. value = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
  1055. if (value < mci->gpm_len)
  1056. mci->gpm_idx = value;
  1057. else
  1058. mci->gpm_idx = 0;
  1059. break;
  1060. case MCI_STATE_LAST_SCHD_MSG_OFFSET:
  1061. value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
  1062. AR_MCI_RX_LAST_SCHD_MSG_INDEX);
  1063. /* Make it in bytes */
  1064. value <<= 4;
  1065. break;
  1066. case MCI_STATE_REMOTE_SLEEP:
  1067. value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
  1068. AR_MCI_RX_REMOTE_SLEEP) ?
  1069. MCI_BT_SLEEP : MCI_BT_AWAKE;
  1070. break;
  1071. case MCI_STATE_SET_BT_AWAKE:
  1072. mci->bt_state = MCI_BT_AWAKE;
  1073. ar9003_mci_send_coex_version_query(ah, true);
  1074. ar9003_mci_send_coex_wlan_channels(ah, true);
  1075. if (mci->unhalt_bt_gpm)
  1076. ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
  1077. ar9003_mci_2g5g_switch(ah, false);
  1078. break;
  1079. case MCI_STATE_RESET_REQ_WAKE:
  1080. ar9003_mci_reset_req_wakeup(ah);
  1081. mci->update_2g5g = true;
  1082. if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MASK) {
  1083. /* Check if we still have control of the GPIOs */
  1084. if ((REG_READ(ah, AR_GLB_GPIO_CONTROL) &
  1085. ATH_MCI_CONFIG_MCI_OBS_GPIO) !=
  1086. ATH_MCI_CONFIG_MCI_OBS_GPIO) {
  1087. ar9003_mci_observation_set_up(ah);
  1088. }
  1089. }
  1090. break;
  1091. case MCI_STATE_SEND_WLAN_COEX_VERSION:
  1092. ar9003_mci_send_coex_version_response(ah, true);
  1093. break;
  1094. case MCI_STATE_SEND_VERSION_QUERY:
  1095. ar9003_mci_send_coex_version_query(ah, true);
  1096. break;
  1097. case MCI_STATE_SEND_STATUS_QUERY:
  1098. query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY;
  1099. ar9003_mci_send_coex_bt_status_query(ah, true, query_type);
  1100. break;
  1101. case MCI_STATE_RECOVER_RX:
  1102. tsf = ath9k_hw_gettsf32(ah);
  1103. if ((tsf - mci->last_recovery) <= MCI_RECOVERY_DUR_TSF) {
  1104. ath_dbg(ath9k_hw_common(ah), MCI,
  1105. "(MCI) ignore Rx recovery\n");
  1106. break;
  1107. }
  1108. ath_dbg(ath9k_hw_common(ah), MCI, "(MCI) RECOVER RX\n");
  1109. mci->last_recovery = tsf;
  1110. ar9003_mci_prep_interface(ah);
  1111. mci->query_bt = true;
  1112. mci->need_flush_btinfo = true;
  1113. ar9003_mci_send_coex_wlan_channels(ah, true);
  1114. ar9003_mci_2g5g_switch(ah, false);
  1115. break;
  1116. case MCI_STATE_NEED_FTP_STOMP:
  1117. value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP);
  1118. break;
  1119. case MCI_STATE_NEED_FLUSH_BT_INFO:
  1120. value = (!mci->unhalt_bt_gpm && mci->need_flush_btinfo) ? 1 : 0;
  1121. mci->need_flush_btinfo = false;
  1122. break;
  1123. case MCI_STATE_AIC_CAL:
  1124. if (ath9k_hw_is_aic_enabled(ah))
  1125. value = ar9003_aic_calibration(ah);
  1126. break;
  1127. case MCI_STATE_AIC_START:
  1128. if (ath9k_hw_is_aic_enabled(ah))
  1129. ar9003_aic_start_normal(ah);
  1130. break;
  1131. case MCI_STATE_AIC_CAL_RESET:
  1132. if (ath9k_hw_is_aic_enabled(ah))
  1133. value = ar9003_aic_cal_reset(ah);
  1134. break;
  1135. case MCI_STATE_AIC_CAL_SINGLE:
  1136. if (ath9k_hw_is_aic_enabled(ah))
  1137. value = ar9003_aic_calibration_single(ah);
  1138. break;
  1139. default:
  1140. break;
  1141. }
  1142. return value;
  1143. }
  1144. EXPORT_SYMBOL(ar9003_mci_state);
  1145. void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah)
  1146. {
  1147. struct ath_common *common = ath9k_hw_common(ah);
  1148. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1149. ath_dbg(common, MCI, "Give LNA and SPDT control to BT\n");
  1150. ar9003_mci_send_lna_take(ah, true);
  1151. udelay(50);
  1152. REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
  1153. mci->is_2g = false;
  1154. mci->update_2g5g = true;
  1155. ar9003_mci_send_2g5g_status(ah, true);
  1156. /* Force another 2g5g update at next scanning */
  1157. mci->update_2g5g = true;
  1158. }
  1159. void ar9003_mci_set_power_awake(struct ath_hw *ah)
  1160. {
  1161. u32 btcoex_ctrl2, diag_sw;
  1162. int i;
  1163. u8 lna_ctrl, bt_sleep;
  1164. for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
  1165. btcoex_ctrl2 = REG_READ(ah, AR_BTCOEX_CTRL2);
  1166. if (btcoex_ctrl2 != 0xdeadbeef)
  1167. break;
  1168. udelay(AH_TIME_QUANTUM);
  1169. }
  1170. REG_WRITE(ah, AR_BTCOEX_CTRL2, (btcoex_ctrl2 | BIT(23)));
  1171. for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
  1172. diag_sw = REG_READ(ah, AR_DIAG_SW);
  1173. if (diag_sw != 0xdeadbeef)
  1174. break;
  1175. udelay(AH_TIME_QUANTUM);
  1176. }
  1177. REG_WRITE(ah, AR_DIAG_SW, (diag_sw | BIT(27) | BIT(19) | BIT(18)));
  1178. lna_ctrl = REG_READ(ah, AR_OBS_BUS_CTRL) & 0x3;
  1179. bt_sleep = MS(REG_READ(ah, AR_MCI_RX_STATUS), AR_MCI_RX_REMOTE_SLEEP);
  1180. REG_WRITE(ah, AR_BTCOEX_CTRL2, btcoex_ctrl2);
  1181. REG_WRITE(ah, AR_DIAG_SW, diag_sw);
  1182. if (bt_sleep && (lna_ctrl == 2)) {
  1183. REG_SET_BIT(ah, AR_BTCOEX_RC, 0x1);
  1184. REG_CLR_BIT(ah, AR_BTCOEX_RC, 0x1);
  1185. udelay(50);
  1186. }
  1187. }
  1188. void ar9003_mci_check_gpm_offset(struct ath_hw *ah)
  1189. {
  1190. struct ath_common *common = ath9k_hw_common(ah);
  1191. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1192. u32 offset;
  1193. /*
  1194. * This should only be called before "MAC Warm Reset" or "MCI Reset Rx".
  1195. */
  1196. offset = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
  1197. if (mci->gpm_idx == offset)
  1198. return;
  1199. ath_dbg(common, MCI, "GPM cached write pointer mismatch %d %d\n",
  1200. mci->gpm_idx, offset);
  1201. mci->query_bt = true;
  1202. mci->need_flush_btinfo = true;
  1203. mci->gpm_idx = 0;
  1204. }
  1205. u32 ar9003_mci_get_next_gpm_offset(struct ath_hw *ah, u32 *more)
  1206. {
  1207. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1208. u32 offset, more_gpm = 0, gpm_ptr;
  1209. /*
  1210. * This could be useful to avoid new GPM message interrupt which
  1211. * may lead to spurious interrupt after power sleep, or multiple
  1212. * entry of ath_mci_intr().
  1213. * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
  1214. * alleviate this effect, but clearing GPM RX interrupt bit is
  1215. * safe, because whether this is called from hw or driver code
  1216. * there must be an interrupt bit set/triggered initially
  1217. */
  1218. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  1219. AR_MCI_INTERRUPT_RX_MSG_GPM);
  1220. gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
  1221. offset = gpm_ptr;
  1222. if (!offset)
  1223. offset = mci->gpm_len - 1;
  1224. else if (offset >= mci->gpm_len) {
  1225. if (offset != 0xFFFF)
  1226. offset = 0;
  1227. } else {
  1228. offset--;
  1229. }
  1230. if ((offset == 0xFFFF) || (gpm_ptr == mci->gpm_idx)) {
  1231. offset = MCI_GPM_INVALID;
  1232. more_gpm = MCI_GPM_NOMORE;
  1233. goto out;
  1234. }
  1235. for (;;) {
  1236. u32 temp_index;
  1237. /* skip reserved GPM if any */
  1238. if (offset != mci->gpm_idx)
  1239. more_gpm = MCI_GPM_MORE;
  1240. else
  1241. more_gpm = MCI_GPM_NOMORE;
  1242. temp_index = mci->gpm_idx;
  1243. if (temp_index >= mci->gpm_len)
  1244. temp_index = 0;
  1245. mci->gpm_idx++;
  1246. if (mci->gpm_idx >= mci->gpm_len)
  1247. mci->gpm_idx = 0;
  1248. if (ar9003_mci_is_gpm_valid(ah, temp_index)) {
  1249. offset = temp_index;
  1250. break;
  1251. }
  1252. if (more_gpm == MCI_GPM_NOMORE) {
  1253. offset = MCI_GPM_INVALID;
  1254. break;
  1255. }
  1256. }
  1257. if (offset != MCI_GPM_INVALID)
  1258. offset <<= 4;
  1259. out:
  1260. if (more)
  1261. *more = more_gpm;
  1262. return offset;
  1263. }
  1264. EXPORT_SYMBOL(ar9003_mci_get_next_gpm_offset);
  1265. void ar9003_mci_set_bt_version(struct ath_hw *ah, u8 major, u8 minor)
  1266. {
  1267. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1268. mci->bt_ver_major = major;
  1269. mci->bt_ver_minor = minor;
  1270. mci->bt_version_known = true;
  1271. ath_dbg(ath9k_hw_common(ah), MCI, "MCI BT version set: %d.%d\n",
  1272. mci->bt_ver_major, mci->bt_ver_minor);
  1273. }
  1274. EXPORT_SYMBOL(ar9003_mci_set_bt_version);
  1275. void ar9003_mci_send_wlan_channels(struct ath_hw *ah)
  1276. {
  1277. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1278. mci->wlan_channels_update = true;
  1279. ar9003_mci_send_coex_wlan_channels(ah, true);
  1280. }
  1281. EXPORT_SYMBOL(ar9003_mci_send_wlan_channels);
  1282. u16 ar9003_mci_get_max_txpower(struct ath_hw *ah, u8 ctlmode)
  1283. {
  1284. if (!ah->btcoex_hw.mci.concur_tx)
  1285. goto out;
  1286. if (ctlmode == CTL_2GHT20)
  1287. return ATH_BTCOEX_HT20_MAX_TXPOWER;
  1288. else if (ctlmode == CTL_2GHT40)
  1289. return ATH_BTCOEX_HT40_MAX_TXPOWER;
  1290. out:
  1291. return -1;
  1292. }