ar9003_mci.c 40 KB

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