ar9003_mci.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  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_gpio_request_out(ah, 3, NULL,
  353. AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_DATA);
  354. ath9k_hw_gpio_request_out(ah, 2, NULL,
  355. AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_CLK);
  356. ath9k_hw_gpio_request_out(ah, 1, NULL,
  357. AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
  358. ath9k_hw_gpio_request_out(ah, 0, NULL,
  359. AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
  360. } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_TXRX) {
  361. ath9k_hw_gpio_request_out(ah, 3, NULL,
  362. AR_GPIO_OUTPUT_MUX_AS_WL_IN_TX);
  363. ath9k_hw_gpio_request_out(ah, 2, NULL,
  364. AR_GPIO_OUTPUT_MUX_AS_WL_IN_RX);
  365. ath9k_hw_gpio_request_out(ah, 1, NULL,
  366. AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
  367. ath9k_hw_gpio_request_out(ah, 0, NULL,
  368. AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
  369. ath9k_hw_gpio_request_out(ah, 5, NULL,
  370. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  371. } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_BT) {
  372. ath9k_hw_gpio_request_out(ah, 3, NULL,
  373. AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
  374. ath9k_hw_gpio_request_out(ah, 2, NULL,
  375. AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
  376. ath9k_hw_gpio_request_out(ah, 1, NULL,
  377. AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
  378. ath9k_hw_gpio_request_out(ah, 0, NULL,
  379. AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
  380. } else
  381. return;
  382. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  383. REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_DS_JTAG_DISABLE, 1);
  384. REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_WLAN_UART_INTF_EN, 0);
  385. REG_SET_BIT(ah, AR_GLB_GPIO_CONTROL, ATH_MCI_CONFIG_MCI_OBS_GPIO);
  386. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_GPIO_OBS_SEL, 0);
  387. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_MAC_BB_OBS_SEL, 1);
  388. REG_WRITE(ah, AR_OBS, 0x4b);
  389. REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL1, 0x03);
  390. REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL2, 0x01);
  391. REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_LSB, 0x02);
  392. REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_MSB, 0x03);
  393. REG_RMW_FIELD(ah, AR_PHY_TEST_CTL_STATUS,
  394. AR_PHY_TEST_CTL_DEBUGPORT_SEL, 0x07);
  395. }
  396. static bool ar9003_mci_send_coex_bt_flags(struct ath_hw *ah, bool wait_done,
  397. u8 opcode, u32 bt_flags)
  398. {
  399. u32 pld[4] = {0, 0, 0, 0};
  400. MCI_GPM_SET_TYPE_OPCODE(pld, MCI_GPM_COEX_AGENT,
  401. MCI_GPM_COEX_BT_UPDATE_FLAGS);
  402. *(((u8 *)pld) + MCI_GPM_COEX_B_BT_FLAGS_OP) = opcode;
  403. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 0) = bt_flags & 0xFF;
  404. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 1) = (bt_flags >> 8) & 0xFF;
  405. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 2) = (bt_flags >> 16) & 0xFF;
  406. *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 3) = (bt_flags >> 24) & 0xFF;
  407. return ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16,
  408. wait_done, true);
  409. }
  410. static void ar9003_mci_sync_bt_state(struct ath_hw *ah)
  411. {
  412. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  413. u32 cur_bt_state;
  414. cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP);
  415. if (mci->bt_state != cur_bt_state)
  416. mci->bt_state = cur_bt_state;
  417. if (mci->bt_state != MCI_BT_SLEEP) {
  418. ar9003_mci_send_coex_version_query(ah, true);
  419. ar9003_mci_send_coex_wlan_channels(ah, true);
  420. if (mci->unhalt_bt_gpm == true)
  421. ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
  422. }
  423. }
  424. void ar9003_mci_check_bt(struct ath_hw *ah)
  425. {
  426. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  427. if (!mci_hw->ready)
  428. return;
  429. /*
  430. * check BT state again to make
  431. * sure it's not changed.
  432. */
  433. ar9003_mci_sync_bt_state(ah);
  434. ar9003_mci_2g5g_switch(ah, true);
  435. if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
  436. (mci_hw->query_bt == true)) {
  437. mci_hw->need_flush_btinfo = true;
  438. }
  439. }
  440. static void ar9003_mci_process_gpm_extra(struct ath_hw *ah, u8 gpm_type,
  441. u8 gpm_opcode, u32 *p_gpm)
  442. {
  443. struct ath_common *common = ath9k_hw_common(ah);
  444. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  445. u8 *p_data = (u8 *) p_gpm;
  446. if (gpm_type != MCI_GPM_COEX_AGENT)
  447. return;
  448. switch (gpm_opcode) {
  449. case MCI_GPM_COEX_VERSION_QUERY:
  450. ath_dbg(common, MCI, "MCI Recv GPM COEX Version Query\n");
  451. ar9003_mci_send_coex_version_response(ah, true);
  452. break;
  453. case MCI_GPM_COEX_VERSION_RESPONSE:
  454. ath_dbg(common, MCI, "MCI Recv GPM COEX Version Response\n");
  455. mci->bt_ver_major =
  456. *(p_data + MCI_GPM_COEX_B_MAJOR_VERSION);
  457. mci->bt_ver_minor =
  458. *(p_data + MCI_GPM_COEX_B_MINOR_VERSION);
  459. mci->bt_version_known = true;
  460. ath_dbg(common, MCI, "MCI BT Coex version: %d.%d\n",
  461. mci->bt_ver_major, mci->bt_ver_minor);
  462. break;
  463. case MCI_GPM_COEX_STATUS_QUERY:
  464. ath_dbg(common, MCI,
  465. "MCI Recv GPM COEX Status Query = 0x%02X\n",
  466. *(p_data + MCI_GPM_COEX_B_WLAN_BITMAP));
  467. mci->wlan_channels_update = true;
  468. ar9003_mci_send_coex_wlan_channels(ah, true);
  469. break;
  470. case MCI_GPM_COEX_BT_PROFILE_INFO:
  471. mci->query_bt = true;
  472. ath_dbg(common, MCI, "MCI Recv GPM COEX BT_Profile_Info\n");
  473. break;
  474. case MCI_GPM_COEX_BT_STATUS_UPDATE:
  475. mci->query_bt = true;
  476. ath_dbg(common, MCI,
  477. "MCI Recv GPM COEX BT_Status_Update SEQ=%d (drop&query)\n",
  478. *(p_gpm + 3));
  479. break;
  480. default:
  481. break;
  482. }
  483. }
  484. static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
  485. u8 gpm_opcode, int time_out)
  486. {
  487. struct ath_common *common = ath9k_hw_common(ah);
  488. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  489. u32 *p_gpm = NULL, mismatch = 0, more_data;
  490. u32 offset;
  491. u8 recv_type = 0, recv_opcode = 0;
  492. bool b_is_bt_cal_done = (gpm_type == MCI_GPM_BT_CAL_DONE);
  493. more_data = time_out ? MCI_GPM_NOMORE : MCI_GPM_MORE;
  494. while (time_out > 0) {
  495. if (p_gpm) {
  496. MCI_GPM_RECYCLE(p_gpm);
  497. p_gpm = NULL;
  498. }
  499. if (more_data != MCI_GPM_MORE)
  500. time_out = ar9003_mci_wait_for_interrupt(ah,
  501. AR_MCI_INTERRUPT_RX_MSG_RAW,
  502. AR_MCI_INTERRUPT_RX_MSG_GPM,
  503. time_out);
  504. if (!time_out)
  505. break;
  506. offset = ar9003_mci_get_next_gpm_offset(ah, &more_data);
  507. if (offset == MCI_GPM_INVALID)
  508. continue;
  509. p_gpm = (u32 *) (mci->gpm_buf + offset);
  510. recv_type = MCI_GPM_TYPE(p_gpm);
  511. recv_opcode = MCI_GPM_OPCODE(p_gpm);
  512. if (MCI_GPM_IS_CAL_TYPE(recv_type)) {
  513. if (recv_type == gpm_type) {
  514. if ((gpm_type == MCI_GPM_BT_CAL_DONE) &&
  515. !b_is_bt_cal_done) {
  516. gpm_type = MCI_GPM_BT_CAL_GRANT;
  517. continue;
  518. }
  519. break;
  520. }
  521. } else if ((recv_type == gpm_type) &&
  522. (recv_opcode == gpm_opcode))
  523. break;
  524. /*
  525. * check if it's cal_grant
  526. *
  527. * When we're waiting for cal_grant in reset routine,
  528. * it's possible that BT sends out cal_request at the
  529. * same time. Since BT's calibration doesn't happen
  530. * that often, we'll let BT completes calibration then
  531. * we continue to wait for cal_grant from BT.
  532. * Orginal: Wait BT_CAL_GRANT.
  533. * New: Receive BT_CAL_REQ -> send WLAN_CAL_GRANT->wait
  534. * BT_CAL_DONE -> Wait BT_CAL_GRANT.
  535. */
  536. if ((gpm_type == MCI_GPM_BT_CAL_GRANT) &&
  537. (recv_type == MCI_GPM_BT_CAL_REQ)) {
  538. u32 payload[4] = {0, 0, 0, 0};
  539. gpm_type = MCI_GPM_BT_CAL_DONE;
  540. MCI_GPM_SET_CAL_TYPE(payload,
  541. MCI_GPM_WLAN_CAL_GRANT);
  542. ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
  543. false, false);
  544. continue;
  545. } else {
  546. ath_dbg(common, MCI, "MCI GPM subtype not match 0x%x\n",
  547. *(p_gpm + 1));
  548. mismatch++;
  549. ar9003_mci_process_gpm_extra(ah, recv_type,
  550. recv_opcode, p_gpm);
  551. }
  552. }
  553. if (p_gpm) {
  554. MCI_GPM_RECYCLE(p_gpm);
  555. p_gpm = NULL;
  556. }
  557. if (time_out <= 0)
  558. time_out = 0;
  559. while (more_data == MCI_GPM_MORE) {
  560. offset = ar9003_mci_get_next_gpm_offset(ah, &more_data);
  561. if (offset == MCI_GPM_INVALID)
  562. break;
  563. p_gpm = (u32 *) (mci->gpm_buf + offset);
  564. recv_type = MCI_GPM_TYPE(p_gpm);
  565. recv_opcode = MCI_GPM_OPCODE(p_gpm);
  566. if (!MCI_GPM_IS_CAL_TYPE(recv_type))
  567. ar9003_mci_process_gpm_extra(ah, recv_type,
  568. recv_opcode, p_gpm);
  569. MCI_GPM_RECYCLE(p_gpm);
  570. }
  571. return time_out;
  572. }
  573. bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan)
  574. {
  575. struct ath_common *common = ath9k_hw_common(ah);
  576. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  577. u32 payload[4] = {0, 0, 0, 0};
  578. ar9003_mci_2g5g_changed(ah, IS_CHAN_2GHZ(chan));
  579. if (mci_hw->bt_state != MCI_BT_CAL_START)
  580. return false;
  581. mci_hw->bt_state = MCI_BT_CAL;
  582. /*
  583. * MCI FIX: disable mci interrupt here. This is to avoid
  584. * SW_MSG_DONE or RX_MSG bits to trigger MCI_INT and
  585. * lead to mci_intr reentry.
  586. */
  587. ar9003_mci_disable_interrupt(ah);
  588. MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_GRANT);
  589. ar9003_mci_send_message(ah, MCI_GPM, 0, payload,
  590. 16, true, false);
  591. /* Wait BT calibration to be completed for 25ms */
  592. if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_DONE,
  593. 0, 25000))
  594. ath_dbg(common, MCI, "MCI BT_CAL_DONE received\n");
  595. else
  596. ath_dbg(common, MCI,
  597. "MCI BT_CAL_DONE not received\n");
  598. mci_hw->bt_state = MCI_BT_AWAKE;
  599. /* MCI FIX: enable mci interrupt here */
  600. ar9003_mci_enable_interrupt(ah);
  601. return true;
  602. }
  603. int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  604. struct ath9k_hw_cal_data *caldata)
  605. {
  606. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  607. if (!mci_hw->ready)
  608. return 0;
  609. if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP))
  610. goto exit;
  611. if (!ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) &&
  612. !ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE))
  613. goto exit;
  614. /*
  615. * BT is sleeping. Check if BT wakes up during
  616. * WLAN calibration. If BT wakes up during
  617. * WLAN calibration, need to go through all
  618. * message exchanges again and recal.
  619. */
  620. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  621. (AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
  622. AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE));
  623. ar9003_mci_remote_reset(ah, true);
  624. ar9003_mci_send_sys_waking(ah, true);
  625. udelay(1);
  626. if (IS_CHAN_2GHZ(chan))
  627. ar9003_mci_send_lna_transfer(ah, true);
  628. mci_hw->bt_state = MCI_BT_AWAKE;
  629. REG_CLR_BIT(ah, AR_PHY_TIMING4,
  630. 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
  631. if (caldata) {
  632. clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
  633. clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
  634. clear_bit(RTT_DONE, &caldata->cal_flags);
  635. }
  636. if (!ath9k_hw_init_cal(ah, chan))
  637. return -EIO;
  638. REG_SET_BIT(ah, AR_PHY_TIMING4,
  639. 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
  640. exit:
  641. ar9003_mci_enable_interrupt(ah);
  642. return 0;
  643. }
  644. static void ar9003_mci_mute_bt(struct ath_hw *ah)
  645. {
  646. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  647. /* disable all MCI messages */
  648. REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE, 0xffff0000);
  649. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS0, 0xffffffff);
  650. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS1, 0xffffffff);
  651. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS2, 0xffffffff);
  652. REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS3, 0xffffffff);
  653. REG_SET_BIT(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  654. /* wait pending HW messages to flush out */
  655. udelay(10);
  656. /*
  657. * Send LNA_TAKE and SYS_SLEEPING when
  658. * 1. reset not after resuming from full sleep
  659. * 2. before reset MCI RX, to quiet BT and avoid MCI RX misalignment
  660. */
  661. if (MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
  662. ar9003_mci_send_lna_take(ah, true);
  663. udelay(5);
  664. }
  665. ar9003_mci_send_sys_sleeping(ah, true);
  666. }
  667. static void ar9003_mci_osla_setup(struct ath_hw *ah, bool enable)
  668. {
  669. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  670. u32 thresh;
  671. if (!enable) {
  672. REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
  673. AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  674. return;
  675. }
  676. REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2, AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
  677. REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
  678. AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
  679. if (AR_SREV_9565(ah))
  680. REG_RMW_FIELD(ah, AR_MCI_MISC, AR_MCI_MISC_HW_FIX_EN, 1);
  681. if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
  682. thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
  683. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  684. AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
  685. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  686. AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
  687. } else
  688. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  689. AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
  690. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  691. AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
  692. }
  693. static void ar9003_mci_stat_setup(struct ath_hw *ah)
  694. {
  695. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  696. if (!AR_SREV_9565(ah))
  697. return;
  698. if (mci->config & ATH_MCI_CONFIG_MCI_STAT_DBG) {
  699. REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
  700. AR_MCI_DBG_CNT_CTRL_ENABLE, 1);
  701. REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
  702. AR_MCI_DBG_CNT_CTRL_BT_LINKID,
  703. MCI_STAT_ALL_BT_LINKID);
  704. } else {
  705. REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
  706. AR_MCI_DBG_CNT_CTRL_ENABLE, 0);
  707. }
  708. }
  709. static void ar9003_mci_set_btcoex_ctrl_9565_1ANT(struct ath_hw *ah)
  710. {
  711. u32 regval;
  712. regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
  713. SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
  714. SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
  715. SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
  716. SM(1, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
  717. SM(1, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
  718. SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
  719. SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
  720. SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  721. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  722. AR_BTCOEX_CTRL2_TX_CHAIN_MASK, 0x1);
  723. REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
  724. }
  725. static void ar9003_mci_set_btcoex_ctrl_9565_2ANT(struct ath_hw *ah)
  726. {
  727. u32 regval;
  728. regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
  729. SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
  730. SM(0, AR_BTCOEX_CTRL_PA_SHARED) |
  731. SM(0, AR_BTCOEX_CTRL_LNA_SHARED) |
  732. SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
  733. SM(1, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
  734. SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
  735. SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
  736. SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  737. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  738. AR_BTCOEX_CTRL2_TX_CHAIN_MASK, 0x0);
  739. REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
  740. }
  741. static void ar9003_mci_set_btcoex_ctrl_9462(struct ath_hw *ah)
  742. {
  743. u32 regval;
  744. regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
  745. SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
  746. SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
  747. SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
  748. SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
  749. SM(3, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
  750. SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
  751. SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
  752. SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
  753. REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
  754. }
  755. int ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
  756. bool is_full_sleep)
  757. {
  758. struct ath_common *common = ath9k_hw_common(ah);
  759. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  760. u32 regval, i;
  761. ath_dbg(common, MCI, "MCI Reset (full_sleep = %d, is_2g = %d)\n",
  762. is_full_sleep, is_2g);
  763. if (REG_READ(ah, AR_BTCOEX_CTRL) == 0xdeadbeef) {
  764. ath_err(common, "BTCOEX control register is dead\n");
  765. return -EINVAL;
  766. }
  767. /* Program MCI DMA related registers */
  768. REG_WRITE(ah, AR_MCI_GPM_0, mci->gpm_addr);
  769. REG_WRITE(ah, AR_MCI_GPM_1, mci->gpm_len);
  770. REG_WRITE(ah, AR_MCI_SCHD_TABLE_0, mci->sched_addr);
  771. /*
  772. * To avoid MCI state machine be affected by incoming remote MCI msgs,
  773. * MCI mode will be enabled later, right before reset the MCI TX and RX.
  774. */
  775. if (AR_SREV_9565(ah)) {
  776. u8 ant = MS(mci->config, ATH_MCI_CONFIG_ANT_ARCH);
  777. if (ant == ATH_MCI_ANT_ARCH_1_ANT_PA_LNA_SHARED)
  778. ar9003_mci_set_btcoex_ctrl_9565_1ANT(ah);
  779. else
  780. ar9003_mci_set_btcoex_ctrl_9565_2ANT(ah);
  781. } else {
  782. ar9003_mci_set_btcoex_ctrl_9462(ah);
  783. }
  784. if (is_2g && !(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
  785. ar9003_mci_osla_setup(ah, true);
  786. else
  787. ar9003_mci_osla_setup(ah, false);
  788. REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
  789. AR_BTCOEX_CTRL_SPDT_ENABLE);
  790. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL3,
  791. AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT, 20);
  792. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_RX_DEWEIGHT, 0);
  793. REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
  794. /* Set the time out to 3.125ms (5 BT slots) */
  795. REG_RMW_FIELD(ah, AR_BTCOEX_WL_LNA, AR_BTCOEX_WL_LNA_TIMEOUT, 0x3D090);
  796. /* concurrent tx priority */
  797. if (mci->config & ATH_MCI_CONFIG_CONCUR_TX) {
  798. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  799. AR_BTCOEX_CTRL2_DESC_BASED_TXPWR_ENABLE, 0);
  800. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
  801. AR_BTCOEX_CTRL2_TXPWR_THRESH, 0x7f);
  802. REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
  803. AR_BTCOEX_CTRL_REDUCE_TXPWR, 0);
  804. for (i = 0; i < 8; i++)
  805. REG_WRITE(ah, AR_BTCOEX_MAX_TXPWR(i), 0x7f7f7f7f);
  806. }
  807. regval = MS(mci->config, ATH_MCI_CONFIG_CLK_DIV);
  808. REG_RMW_FIELD(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_CLK_DIV, regval);
  809. REG_SET_BIT(ah, AR_BTCOEX_CTRL, AR_BTCOEX_CTRL_MCI_MODE_EN);
  810. /* Resetting the Rx and Tx paths of MCI */
  811. regval = REG_READ(ah, AR_MCI_COMMAND2);
  812. regval |= SM(1, AR_MCI_COMMAND2_RESET_TX);
  813. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  814. udelay(1);
  815. regval &= ~SM(1, AR_MCI_COMMAND2_RESET_TX);
  816. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  817. if (is_full_sleep) {
  818. ar9003_mci_mute_bt(ah);
  819. udelay(100);
  820. }
  821. /* Check pending GPM msg before MCI Reset Rx */
  822. ar9003_mci_check_gpm_offset(ah);
  823. regval |= SM(1, AR_MCI_COMMAND2_RESET_RX);
  824. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  825. udelay(1);
  826. regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX);
  827. REG_WRITE(ah, AR_MCI_COMMAND2, regval);
  828. /* Init GPM offset after MCI Reset Rx */
  829. ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET);
  830. REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE,
  831. (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) |
  832. SM(0x0000, AR_MCI_MSG_ATTRIBUTES_TABLE_CHECKSUM)));
  833. if (MCI_ANT_ARCH_PA_LNA_SHARED(mci))
  834. REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
  835. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  836. else
  837. REG_SET_BIT(ah, AR_MCI_TX_CTRL,
  838. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  839. ar9003_mci_observation_set_up(ah);
  840. mci->ready = true;
  841. ar9003_mci_prep_interface(ah);
  842. ar9003_mci_stat_setup(ah);
  843. if (en_int)
  844. ar9003_mci_enable_interrupt(ah);
  845. if (ath9k_hw_is_aic_enabled(ah))
  846. ar9003_aic_start_normal(ah);
  847. return 0;
  848. }
  849. void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep)
  850. {
  851. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  852. ar9003_mci_disable_interrupt(ah);
  853. if (mci_hw->ready && !save_fullsleep) {
  854. ar9003_mci_mute_bt(ah);
  855. udelay(20);
  856. REG_WRITE(ah, AR_BTCOEX_CTRL, 0);
  857. }
  858. mci_hw->bt_state = MCI_BT_SLEEP;
  859. mci_hw->ready = false;
  860. }
  861. static void ar9003_mci_send_2g5g_status(struct ath_hw *ah, bool wait_done)
  862. {
  863. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  864. u32 new_flags, to_set, to_clear;
  865. if (!mci->update_2g5g || (mci->bt_state == MCI_BT_SLEEP))
  866. return;
  867. if (mci->is_2g) {
  868. new_flags = MCI_2G_FLAGS;
  869. to_clear = MCI_2G_FLAGS_CLEAR_MASK;
  870. to_set = MCI_2G_FLAGS_SET_MASK;
  871. } else {
  872. new_flags = MCI_5G_FLAGS;
  873. to_clear = MCI_5G_FLAGS_CLEAR_MASK;
  874. to_set = MCI_5G_FLAGS_SET_MASK;
  875. }
  876. if (to_clear)
  877. ar9003_mci_send_coex_bt_flags(ah, wait_done,
  878. MCI_GPM_COEX_BT_FLAGS_CLEAR,
  879. to_clear);
  880. if (to_set)
  881. ar9003_mci_send_coex_bt_flags(ah, wait_done,
  882. MCI_GPM_COEX_BT_FLAGS_SET,
  883. to_set);
  884. }
  885. static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
  886. u32 *payload, bool queue)
  887. {
  888. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  889. u8 type, opcode;
  890. /* check if the message is to be queued */
  891. if (header != MCI_GPM)
  892. return;
  893. type = MCI_GPM_TYPE(payload);
  894. opcode = MCI_GPM_OPCODE(payload);
  895. if (type != MCI_GPM_COEX_AGENT)
  896. return;
  897. switch (opcode) {
  898. case MCI_GPM_COEX_BT_UPDATE_FLAGS:
  899. if (*(((u8 *)payload) + MCI_GPM_COEX_B_BT_FLAGS_OP) ==
  900. MCI_GPM_COEX_BT_FLAGS_READ)
  901. break;
  902. mci->update_2g5g = queue;
  903. break;
  904. case MCI_GPM_COEX_WLAN_CHANNELS:
  905. mci->wlan_channels_update = queue;
  906. break;
  907. case MCI_GPM_COEX_HALT_BT_GPM:
  908. if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
  909. MCI_GPM_COEX_BT_GPM_UNHALT) {
  910. mci->unhalt_bt_gpm = queue;
  911. if (!queue)
  912. mci->halted_bt_gpm = false;
  913. }
  914. if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
  915. MCI_GPM_COEX_BT_GPM_HALT) {
  916. mci->halted_bt_gpm = !queue;
  917. }
  918. break;
  919. default:
  920. break;
  921. }
  922. }
  923. void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool force)
  924. {
  925. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  926. if (!mci->update_2g5g && !force)
  927. return;
  928. if (mci->is_2g) {
  929. ar9003_mci_send_2g5g_status(ah, true);
  930. ar9003_mci_send_lna_transfer(ah, true);
  931. udelay(5);
  932. REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
  933. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  934. REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
  935. AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
  936. if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
  937. ar9003_mci_osla_setup(ah, true);
  938. if (AR_SREV_9462(ah))
  939. REG_WRITE(ah, AR_SELFGEN_MASK, 0x02);
  940. } else {
  941. ar9003_mci_send_lna_take(ah, true);
  942. udelay(5);
  943. REG_SET_BIT(ah, AR_MCI_TX_CTRL,
  944. AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
  945. REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
  946. AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
  947. ar9003_mci_osla_setup(ah, false);
  948. ar9003_mci_send_2g5g_status(ah, true);
  949. }
  950. }
  951. bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag,
  952. u32 *payload, u8 len, bool wait_done,
  953. bool check_bt)
  954. {
  955. struct ath_common *common = ath9k_hw_common(ah);
  956. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  957. bool msg_sent = false;
  958. u32 regval;
  959. u32 saved_mci_int_en;
  960. int i;
  961. saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
  962. regval = REG_READ(ah, AR_BTCOEX_CTRL);
  963. if ((regval == 0xdeadbeef) || !(regval & AR_BTCOEX_CTRL_MCI_MODE_EN)) {
  964. ath_dbg(common, MCI,
  965. "MCI Not sending 0x%x. MCI is not enabled. full_sleep = %d\n",
  966. header, (ah->power_mode == ATH9K_PM_FULL_SLEEP) ? 1 : 0);
  967. ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
  968. return false;
  969. } else if (check_bt && (mci->bt_state == MCI_BT_SLEEP)) {
  970. ath_dbg(common, MCI,
  971. "MCI Don't send message 0x%x. BT is in sleep state\n",
  972. header);
  973. ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
  974. return false;
  975. }
  976. if (wait_done)
  977. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
  978. /* Need to clear SW_MSG_DONE raw bit before wait */
  979. REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
  980. (AR_MCI_INTERRUPT_SW_MSG_DONE |
  981. AR_MCI_INTERRUPT_MSG_FAIL_MASK));
  982. if (payload) {
  983. for (i = 0; (i * 4) < len; i++)
  984. REG_WRITE(ah, (AR_MCI_TX_PAYLOAD0 + i * 4),
  985. *(payload + i));
  986. }
  987. REG_WRITE(ah, AR_MCI_COMMAND0,
  988. (SM((flag & MCI_FLAG_DISABLE_TIMESTAMP),
  989. AR_MCI_COMMAND0_DISABLE_TIMESTAMP) |
  990. SM(len, AR_MCI_COMMAND0_LEN) |
  991. SM(header, AR_MCI_COMMAND0_HEADER)));
  992. if (wait_done &&
  993. !(ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RAW,
  994. AR_MCI_INTERRUPT_SW_MSG_DONE, 500)))
  995. ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
  996. else {
  997. ar9003_mci_queue_unsent_gpm(ah, header, payload, false);
  998. msg_sent = true;
  999. }
  1000. if (wait_done)
  1001. REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
  1002. return msg_sent;
  1003. }
  1004. EXPORT_SYMBOL(ar9003_mci_send_message);
  1005. void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable)
  1006. {
  1007. struct ath_common *common = ath9k_hw_common(ah);
  1008. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  1009. u32 pld[4] = {0, 0, 0, 0};
  1010. if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
  1011. (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
  1012. return;
  1013. MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_REQ);
  1014. pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_seq++;
  1015. ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
  1016. if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) {
  1017. ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n");
  1018. } else {
  1019. *is_reusable = false;
  1020. ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n");
  1021. }
  1022. }
  1023. void ar9003_mci_init_cal_done(struct ath_hw *ah)
  1024. {
  1025. struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
  1026. u32 pld[4] = {0, 0, 0, 0};
  1027. if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
  1028. (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
  1029. return;
  1030. MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_DONE);
  1031. pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_done++;
  1032. ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
  1033. }
  1034. int ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf,
  1035. u16 len, u32 sched_addr)
  1036. {
  1037. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1038. mci->gpm_addr = gpm_addr;
  1039. mci->gpm_buf = gpm_buf;
  1040. mci->gpm_len = len;
  1041. mci->sched_addr = sched_addr;
  1042. return ar9003_mci_reset(ah, true, true, true);
  1043. }
  1044. EXPORT_SYMBOL(ar9003_mci_setup);
  1045. void ar9003_mci_cleanup(struct ath_hw *ah)
  1046. {
  1047. /* Turn off MCI and Jupiter mode. */
  1048. REG_WRITE(ah, AR_BTCOEX_CTRL, 0x00);
  1049. ar9003_mci_disable_interrupt(ah);
  1050. }
  1051. EXPORT_SYMBOL(ar9003_mci_cleanup);
  1052. u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type)
  1053. {
  1054. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1055. u32 value = 0, tsf;
  1056. u8 query_type;
  1057. switch (state_type) {
  1058. case MCI_STATE_ENABLE:
  1059. if (mci->ready) {
  1060. value = REG_READ(ah, AR_BTCOEX_CTRL);
  1061. if ((value == 0xdeadbeef) || (value == 0xffffffff))
  1062. value = 0;
  1063. }
  1064. value &= AR_BTCOEX_CTRL_MCI_MODE_EN;
  1065. break;
  1066. case MCI_STATE_INIT_GPM_OFFSET:
  1067. value = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
  1068. if (value < mci->gpm_len)
  1069. mci->gpm_idx = value;
  1070. else
  1071. mci->gpm_idx = 0;
  1072. break;
  1073. case MCI_STATE_LAST_SCHD_MSG_OFFSET:
  1074. value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
  1075. AR_MCI_RX_LAST_SCHD_MSG_INDEX);
  1076. /* Make it in bytes */
  1077. value <<= 4;
  1078. break;
  1079. case MCI_STATE_REMOTE_SLEEP:
  1080. value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
  1081. AR_MCI_RX_REMOTE_SLEEP) ?
  1082. MCI_BT_SLEEP : MCI_BT_AWAKE;
  1083. break;
  1084. case MCI_STATE_SET_BT_AWAKE:
  1085. mci->bt_state = MCI_BT_AWAKE;
  1086. ar9003_mci_send_coex_version_query(ah, true);
  1087. ar9003_mci_send_coex_wlan_channels(ah, true);
  1088. if (mci->unhalt_bt_gpm)
  1089. ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
  1090. ar9003_mci_2g5g_switch(ah, false);
  1091. break;
  1092. case MCI_STATE_RESET_REQ_WAKE:
  1093. ar9003_mci_reset_req_wakeup(ah);
  1094. mci->update_2g5g = true;
  1095. if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MASK) {
  1096. /* Check if we still have control of the GPIOs */
  1097. if ((REG_READ(ah, AR_GLB_GPIO_CONTROL) &
  1098. ATH_MCI_CONFIG_MCI_OBS_GPIO) !=
  1099. ATH_MCI_CONFIG_MCI_OBS_GPIO) {
  1100. ar9003_mci_observation_set_up(ah);
  1101. }
  1102. }
  1103. break;
  1104. case MCI_STATE_SEND_WLAN_COEX_VERSION:
  1105. ar9003_mci_send_coex_version_response(ah, true);
  1106. break;
  1107. case MCI_STATE_SEND_VERSION_QUERY:
  1108. ar9003_mci_send_coex_version_query(ah, true);
  1109. break;
  1110. case MCI_STATE_SEND_STATUS_QUERY:
  1111. query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY;
  1112. ar9003_mci_send_coex_bt_status_query(ah, true, query_type);
  1113. break;
  1114. case MCI_STATE_RECOVER_RX:
  1115. tsf = ath9k_hw_gettsf32(ah);
  1116. if ((tsf - mci->last_recovery) <= MCI_RECOVERY_DUR_TSF) {
  1117. ath_dbg(ath9k_hw_common(ah), MCI,
  1118. "(MCI) ignore Rx recovery\n");
  1119. break;
  1120. }
  1121. ath_dbg(ath9k_hw_common(ah), MCI, "(MCI) RECOVER RX\n");
  1122. mci->last_recovery = tsf;
  1123. ar9003_mci_prep_interface(ah);
  1124. mci->query_bt = true;
  1125. mci->need_flush_btinfo = true;
  1126. ar9003_mci_send_coex_wlan_channels(ah, true);
  1127. ar9003_mci_2g5g_switch(ah, false);
  1128. break;
  1129. case MCI_STATE_NEED_FTP_STOMP:
  1130. value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP);
  1131. break;
  1132. case MCI_STATE_NEED_FLUSH_BT_INFO:
  1133. value = (!mci->unhalt_bt_gpm && mci->need_flush_btinfo) ? 1 : 0;
  1134. mci->need_flush_btinfo = false;
  1135. break;
  1136. case MCI_STATE_AIC_CAL:
  1137. if (ath9k_hw_is_aic_enabled(ah))
  1138. value = ar9003_aic_calibration(ah);
  1139. break;
  1140. case MCI_STATE_AIC_START:
  1141. if (ath9k_hw_is_aic_enabled(ah))
  1142. ar9003_aic_start_normal(ah);
  1143. break;
  1144. case MCI_STATE_AIC_CAL_RESET:
  1145. if (ath9k_hw_is_aic_enabled(ah))
  1146. value = ar9003_aic_cal_reset(ah);
  1147. break;
  1148. case MCI_STATE_AIC_CAL_SINGLE:
  1149. if (ath9k_hw_is_aic_enabled(ah))
  1150. value = ar9003_aic_calibration_single(ah);
  1151. break;
  1152. default:
  1153. break;
  1154. }
  1155. return value;
  1156. }
  1157. EXPORT_SYMBOL(ar9003_mci_state);
  1158. void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah)
  1159. {
  1160. struct ath_common *common = ath9k_hw_common(ah);
  1161. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1162. ath_dbg(common, MCI, "Give LNA and SPDT control to BT\n");
  1163. ar9003_mci_send_lna_take(ah, true);
  1164. udelay(50);
  1165. REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
  1166. mci->is_2g = false;
  1167. mci->update_2g5g = true;
  1168. ar9003_mci_send_2g5g_status(ah, true);
  1169. /* Force another 2g5g update at next scanning */
  1170. mci->update_2g5g = true;
  1171. }
  1172. void ar9003_mci_set_power_awake(struct ath_hw *ah)
  1173. {
  1174. u32 btcoex_ctrl2, diag_sw;
  1175. int i;
  1176. u8 lna_ctrl, bt_sleep;
  1177. for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
  1178. btcoex_ctrl2 = REG_READ(ah, AR_BTCOEX_CTRL2);
  1179. if (btcoex_ctrl2 != 0xdeadbeef)
  1180. break;
  1181. udelay(AH_TIME_QUANTUM);
  1182. }
  1183. REG_WRITE(ah, AR_BTCOEX_CTRL2, (btcoex_ctrl2 | BIT(23)));
  1184. for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
  1185. diag_sw = REG_READ(ah, AR_DIAG_SW);
  1186. if (diag_sw != 0xdeadbeef)
  1187. break;
  1188. udelay(AH_TIME_QUANTUM);
  1189. }
  1190. REG_WRITE(ah, AR_DIAG_SW, (diag_sw | BIT(27) | BIT(19) | BIT(18)));
  1191. lna_ctrl = REG_READ(ah, AR_OBS_BUS_CTRL) & 0x3;
  1192. bt_sleep = MS(REG_READ(ah, AR_MCI_RX_STATUS), AR_MCI_RX_REMOTE_SLEEP);
  1193. REG_WRITE(ah, AR_BTCOEX_CTRL2, btcoex_ctrl2);
  1194. REG_WRITE(ah, AR_DIAG_SW, diag_sw);
  1195. if (bt_sleep && (lna_ctrl == 2)) {
  1196. REG_SET_BIT(ah, AR_BTCOEX_RC, 0x1);
  1197. REG_CLR_BIT(ah, AR_BTCOEX_RC, 0x1);
  1198. udelay(50);
  1199. }
  1200. }
  1201. void ar9003_mci_check_gpm_offset(struct ath_hw *ah)
  1202. {
  1203. struct ath_common *common = ath9k_hw_common(ah);
  1204. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1205. u32 offset;
  1206. /*
  1207. * This should only be called before "MAC Warm Reset" or "MCI Reset Rx".
  1208. */
  1209. offset = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
  1210. if (mci->gpm_idx == offset)
  1211. return;
  1212. ath_dbg(common, MCI, "GPM cached write pointer mismatch %d %d\n",
  1213. mci->gpm_idx, offset);
  1214. mci->query_bt = true;
  1215. mci->need_flush_btinfo = true;
  1216. mci->gpm_idx = 0;
  1217. }
  1218. u32 ar9003_mci_get_next_gpm_offset(struct ath_hw *ah, u32 *more)
  1219. {
  1220. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1221. u32 offset, more_gpm = 0, gpm_ptr;
  1222. /*
  1223. * This could be useful to avoid new GPM message interrupt which
  1224. * may lead to spurious interrupt after power sleep, or multiple
  1225. * entry of ath_mci_intr().
  1226. * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
  1227. * alleviate this effect, but clearing GPM RX interrupt bit is
  1228. * safe, because whether this is called from hw or driver code
  1229. * there must be an interrupt bit set/triggered initially
  1230. */
  1231. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
  1232. AR_MCI_INTERRUPT_RX_MSG_GPM);
  1233. gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
  1234. offset = gpm_ptr;
  1235. if (!offset)
  1236. offset = mci->gpm_len - 1;
  1237. else if (offset >= mci->gpm_len) {
  1238. if (offset != 0xFFFF)
  1239. offset = 0;
  1240. } else {
  1241. offset--;
  1242. }
  1243. if ((offset == 0xFFFF) || (gpm_ptr == mci->gpm_idx)) {
  1244. offset = MCI_GPM_INVALID;
  1245. more_gpm = MCI_GPM_NOMORE;
  1246. goto out;
  1247. }
  1248. for (;;) {
  1249. u32 temp_index;
  1250. /* skip reserved GPM if any */
  1251. if (offset != mci->gpm_idx)
  1252. more_gpm = MCI_GPM_MORE;
  1253. else
  1254. more_gpm = MCI_GPM_NOMORE;
  1255. temp_index = mci->gpm_idx;
  1256. if (temp_index >= mci->gpm_len)
  1257. temp_index = 0;
  1258. mci->gpm_idx++;
  1259. if (mci->gpm_idx >= mci->gpm_len)
  1260. mci->gpm_idx = 0;
  1261. if (ar9003_mci_is_gpm_valid(ah, temp_index)) {
  1262. offset = temp_index;
  1263. break;
  1264. }
  1265. if (more_gpm == MCI_GPM_NOMORE) {
  1266. offset = MCI_GPM_INVALID;
  1267. break;
  1268. }
  1269. }
  1270. if (offset != MCI_GPM_INVALID)
  1271. offset <<= 4;
  1272. out:
  1273. if (more)
  1274. *more = more_gpm;
  1275. return offset;
  1276. }
  1277. EXPORT_SYMBOL(ar9003_mci_get_next_gpm_offset);
  1278. void ar9003_mci_set_bt_version(struct ath_hw *ah, u8 major, u8 minor)
  1279. {
  1280. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1281. mci->bt_ver_major = major;
  1282. mci->bt_ver_minor = minor;
  1283. mci->bt_version_known = true;
  1284. ath_dbg(ath9k_hw_common(ah), MCI, "MCI BT version set: %d.%d\n",
  1285. mci->bt_ver_major, mci->bt_ver_minor);
  1286. }
  1287. EXPORT_SYMBOL(ar9003_mci_set_bt_version);
  1288. void ar9003_mci_send_wlan_channels(struct ath_hw *ah)
  1289. {
  1290. struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
  1291. mci->wlan_channels_update = true;
  1292. ar9003_mci_send_coex_wlan_channels(ah, true);
  1293. }
  1294. EXPORT_SYMBOL(ar9003_mci_send_wlan_channels);
  1295. u16 ar9003_mci_get_max_txpower(struct ath_hw *ah, u8 ctlmode)
  1296. {
  1297. if (!ah->btcoex_hw.mci.concur_tx)
  1298. goto out;
  1299. if (ctlmode == CTL_2GHT20)
  1300. return ATH_BTCOEX_HT20_MAX_TXPOWER;
  1301. else if (ctlmode == CTL_2GHT40)
  1302. return ATH_BTCOEX_HT40_MAX_TXPOWER;
  1303. out:
  1304. return -1;
  1305. }