btcoex.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 "hw.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. EXPORT_SYMBOL(ath9k_hw_init_btcoex_hw);
  87. void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah)
  88. {
  89. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  90. /* connect bt_active to baseband */
  91. REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  92. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
  93. AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
  94. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  95. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
  96. /* Set input mux for bt_active to gpio pin */
  97. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  98. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  99. btcoex_hw->btactive_gpio);
  100. /* Configure the desired gpio port for input */
  101. ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
  102. }
  103. EXPORT_SYMBOL(ath9k_hw_btcoex_init_2wire);
  104. void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
  105. {
  106. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  107. /* btcoex 3-wire */
  108. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  109. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
  110. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
  111. /* Set input mux for bt_prority_async and
  112. * bt_active_async to GPIO pins */
  113. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  114. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  115. btcoex_hw->btactive_gpio);
  116. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  117. AR_GPIO_INPUT_MUX1_BT_PRIORITY,
  118. btcoex_hw->btpriority_gpio);
  119. /* Configure the desired GPIO ports for input */
  120. ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
  121. ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio);
  122. }
  123. EXPORT_SYMBOL(ath9k_hw_btcoex_init_3wire);
  124. static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
  125. {
  126. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  127. /* Configure the desired GPIO port for TX_FRAME output */
  128. ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
  129. AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
  130. }
  131. void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
  132. u32 bt_weight,
  133. u32 wlan_weight)
  134. {
  135. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  136. btcoex_hw->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) |
  137. SM(wlan_weight, AR_BTCOEX_WL_WGHT);
  138. }
  139. EXPORT_SYMBOL(ath9k_hw_btcoex_set_weight);
  140. static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
  141. {
  142. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  143. /*
  144. * Program coex mode and weight registers to
  145. * enable coex 3-wire
  146. */
  147. REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_hw->bt_coex_mode);
  148. REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_hw->bt_coex_weights);
  149. REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_hw->bt_coex_mode2);
  150. REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
  151. REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
  152. ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
  153. AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
  154. }
  155. void ath9k_hw_btcoex_enable(struct ath_hw *ah)
  156. {
  157. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  158. switch (btcoex_hw->scheme) {
  159. case ATH_BTCOEX_CFG_NONE:
  160. break;
  161. case ATH_BTCOEX_CFG_2WIRE:
  162. ath9k_hw_btcoex_enable_2wire(ah);
  163. break;
  164. case ATH_BTCOEX_CFG_3WIRE:
  165. ath9k_hw_btcoex_enable_3wire(ah);
  166. break;
  167. }
  168. REG_RMW(ah, AR_GPIO_PDPU,
  169. (0x2 << (btcoex_hw->btactive_gpio * 2)),
  170. (0x3 << (btcoex_hw->btactive_gpio * 2)));
  171. ah->btcoex_hw.enabled = true;
  172. }
  173. EXPORT_SYMBOL(ath9k_hw_btcoex_enable);
  174. void ath9k_hw_btcoex_disable(struct ath_hw *ah)
  175. {
  176. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  177. ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0);
  178. ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
  179. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  180. if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) {
  181. REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
  182. REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
  183. REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
  184. }
  185. ah->btcoex_hw.enabled = false;
  186. }
  187. EXPORT_SYMBOL(ath9k_hw_btcoex_disable);