ar9003_mci.c 44 KB

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