btcoex.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Copyright (c) 2009 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 "ath9k.h"
  17. enum ath_bt_mode {
  18. ATH_BT_COEX_MODE_LEGACY, /* legacy rx_clear mode */
  19. ATH_BT_COEX_MODE_UNSLOTTED, /* untimed/unslotted mode */
  20. ATH_BT_COEX_MODE_SLOTTED, /* slotted mode */
  21. ATH_BT_COEX_MODE_DISALBED, /* coexistence disabled */
  22. };
  23. struct ath_btcoex_config {
  24. u8 bt_time_extend;
  25. bool bt_txstate_extend;
  26. bool bt_txframe_extend;
  27. enum ath_bt_mode bt_mode; /* coexistence mode */
  28. bool bt_quiet_collision;
  29. bool bt_rxclear_polarity; /* invert rx_clear as WLAN_ACTIVE*/
  30. u8 bt_priority_time;
  31. u8 bt_first_slot_time;
  32. bool bt_hold_rx_clear;
  33. };
  34. static const u16 ath_subsysid_tbl[] = {
  35. AR9280_COEX2WIRE_SUBSYSID,
  36. AT9285_COEX3WIRE_SA_SUBSYSID,
  37. AT9285_COEX3WIRE_DA_SUBSYSID
  38. };
  39. /*
  40. * Checks the subsystem id of the device to see if it
  41. * supports btcoex
  42. */
  43. bool ath9k_hw_btcoex_supported(struct ath_hw *ah)
  44. {
  45. int i;
  46. if (!ah->hw_version.subsysid)
  47. return false;
  48. for (i = 0; i < ARRAY_SIZE(ath_subsysid_tbl); i++)
  49. if (ah->hw_version.subsysid == ath_subsysid_tbl[i])
  50. return true;
  51. return false;
  52. }
  53. void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum)
  54. {
  55. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  56. const struct ath_btcoex_config ath_bt_config = {
  57. .bt_time_extend = 0,
  58. .bt_txstate_extend = true,
  59. .bt_txframe_extend = true,
  60. .bt_mode = ATH_BT_COEX_MODE_SLOTTED,
  61. .bt_quiet_collision = true,
  62. .bt_rxclear_polarity = true,
  63. .bt_priority_time = 2,
  64. .bt_first_slot_time = 5,
  65. .bt_hold_rx_clear = true,
  66. };
  67. u32 i;
  68. btcoex_hw->bt_coex_mode =
  69. (btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) |
  70. SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) |
  71. SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) |
  72. SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) |
  73. SM(ath_bt_config.bt_mode, AR_BT_MODE) |
  74. SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) |
  75. SM(ath_bt_config.bt_rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) |
  76. SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) |
  77. SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) |
  78. SM(qnum, AR_BT_QCU_THRESH);
  79. btcoex_hw->bt_coex_mode2 =
  80. SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) |
  81. SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) |
  82. AR_BT_DISABLE_BT_ANT;
  83. for (i = 0; i < 32; i++)
  84. ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i;
  85. }
  86. void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah)
  87. {
  88. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  89. /* connect bt_active to baseband */
  90. REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  91. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
  92. AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
  93. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  94. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
  95. /* Set input mux for bt_active to gpio pin */
  96. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  97. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  98. btcoex_hw->btactive_gpio);
  99. /* Configure the desired gpio port for input */
  100. ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
  101. }
  102. void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
  103. {
  104. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  105. /* btcoex 3-wire */
  106. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  107. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
  108. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
  109. /* Set input mux for bt_prority_async and
  110. * bt_active_async to GPIO pins */
  111. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  112. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  113. btcoex_hw->btactive_gpio);
  114. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  115. AR_GPIO_INPUT_MUX1_BT_PRIORITY,
  116. btcoex_hw->btpriority_gpio);
  117. /* Configure the desired GPIO ports for input */
  118. ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
  119. ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio);
  120. }
  121. static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
  122. {
  123. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  124. /* Configure the desired GPIO port for TX_FRAME output */
  125. ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
  126. AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
  127. }
  128. void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
  129. u32 bt_weight,
  130. u32 wlan_weight)
  131. {
  132. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  133. btcoex_hw->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) |
  134. SM(wlan_weight, AR_BTCOEX_WL_WGHT);
  135. }
  136. static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
  137. {
  138. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  139. /*
  140. * Program coex mode and weight registers to
  141. * enable coex 3-wire
  142. */
  143. REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_hw->bt_coex_mode);
  144. REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_hw->bt_coex_weights);
  145. REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_hw->bt_coex_mode2);
  146. REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
  147. REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
  148. ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
  149. AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
  150. }
  151. void ath9k_hw_btcoex_enable(struct ath_hw *ah)
  152. {
  153. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  154. switch (btcoex_hw->scheme) {
  155. case ATH_BTCOEX_CFG_NONE:
  156. break;
  157. case ATH_BTCOEX_CFG_2WIRE:
  158. ath9k_hw_btcoex_enable_2wire(ah);
  159. break;
  160. case ATH_BTCOEX_CFG_3WIRE:
  161. ath9k_hw_btcoex_enable_3wire(ah);
  162. break;
  163. }
  164. REG_RMW(ah, AR_GPIO_PDPU,
  165. (0x2 << (btcoex_hw->btactive_gpio * 2)),
  166. (0x3 << (btcoex_hw->btactive_gpio * 2)));
  167. ah->btcoex_hw.enabled = true;
  168. }
  169. void ath9k_hw_btcoex_disable(struct ath_hw *ah)
  170. {
  171. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  172. ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0);
  173. ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
  174. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  175. if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) {
  176. REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
  177. REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
  178. REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
  179. }
  180. ah->btcoex_hw.enabled = false;
  181. }