btcoex.c 6.3 KB

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