btcoex.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_info(struct ath_hw *ah, int qnum)
  39. {
  40. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  41. u32 i;
  42. btcoex_info->bt_coex_mode =
  43. (btcoex_info->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_info->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. btcoex_info->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
  58. for (i = 0; i < 32; i++)
  59. ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i;
  60. }
  61. void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah)
  62. {
  63. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  64. /* connect bt_active to baseband */
  65. REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  66. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
  67. AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
  68. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  69. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
  70. /* Set input mux for bt_active to gpio pin */
  71. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  72. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  73. btcoex_info->btactive_gpio);
  74. /* Configure the desired gpio port for input */
  75. ath9k_hw_cfg_gpio_input(ah, btcoex_info->btactive_gpio);
  76. }
  77. void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
  78. {
  79. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  80. /* btcoex 3-wire */
  81. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  82. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
  83. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
  84. /* Set input mux for bt_prority_async and
  85. * bt_active_async to GPIO pins */
  86. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  87. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  88. btcoex_info->btactive_gpio);
  89. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  90. AR_GPIO_INPUT_MUX1_BT_PRIORITY,
  91. btcoex_info->btpriority_gpio);
  92. /* Configure the desired GPIO ports for input */
  93. ath9k_hw_cfg_gpio_input(ah, btcoex_info->btactive_gpio);
  94. ath9k_hw_cfg_gpio_input(ah, btcoex_info->btpriority_gpio);
  95. }
  96. static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
  97. {
  98. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  99. /* Configure the desired GPIO port for TX_FRAME output */
  100. ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio,
  101. AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
  102. }
  103. static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
  104. {
  105. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  106. /*
  107. * Program coex mode and weight registers to
  108. * enable coex 3-wire
  109. */
  110. REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_info->bt_coex_mode);
  111. REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_info->bt_coex_weights);
  112. REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_info->bt_coex_mode2);
  113. REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
  114. REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
  115. ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio,
  116. AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
  117. }
  118. void ath9k_hw_btcoex_enable(struct ath_hw *ah)
  119. {
  120. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  121. switch (btcoex_info->btcoex_scheme) {
  122. case ATH_BTCOEX_CFG_NONE:
  123. break;
  124. case ATH_BTCOEX_CFG_2WIRE:
  125. ath9k_hw_btcoex_enable_2wire(ah);
  126. break;
  127. case ATH_BTCOEX_CFG_3WIRE:
  128. ath9k_hw_btcoex_enable_3wire(ah);
  129. break;
  130. }
  131. REG_RMW(ah, AR_GPIO_PDPU,
  132. (0x2 << (btcoex_info->btactive_gpio * 2)),
  133. (0x3 << (btcoex_info->btactive_gpio * 2)));
  134. ah->ah_sc->sc_flags |= SC_OP_BTCOEX_ENABLED;
  135. }
  136. void ath9k_hw_btcoex_disable(struct ath_hw *ah)
  137. {
  138. struct ath_btcoex_info *btcoex_info = &ah->btcoex_info;
  139. ath9k_hw_set_gpio(ah, btcoex_info->wlanactive_gpio, 0);
  140. ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio,
  141. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  142. if (btcoex_info->btcoex_scheme == ATH_BTCOEX_CFG_3WIRE) {
  143. REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
  144. REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
  145. REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
  146. }
  147. ah->ah_sc->sc_flags &= ~SC_OP_BTCOEX_ENABLED;
  148. }