btcoex.c 5.6 KB

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