htc_drv_gpio.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "htc.h"
  2. /******************/
  3. /* BTCOEX */
  4. /******************/
  5. /*
  6. * Detects if there is any priority bt traffic
  7. */
  8. static void ath_detect_bt_priority(struct ath9k_htc_priv *priv)
  9. {
  10. struct ath_btcoex *btcoex = &priv->btcoex;
  11. struct ath_hw *ah = priv->ah;
  12. if (ath9k_hw_gpio_get(ah, ah->btcoex_hw.btpriority_gpio))
  13. btcoex->bt_priority_cnt++;
  14. if (time_after(jiffies, btcoex->bt_priority_time +
  15. msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
  16. priv->op_flags &= ~(OP_BT_PRIORITY_DETECTED | OP_BT_SCAN);
  17. /* Detect if colocated bt started scanning */
  18. if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
  19. ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
  20. "BT scan detected");
  21. priv->op_flags |= (OP_BT_SCAN |
  22. OP_BT_PRIORITY_DETECTED);
  23. } else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
  24. ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
  25. "BT priority traffic detected");
  26. priv->op_flags |= OP_BT_PRIORITY_DETECTED;
  27. }
  28. btcoex->bt_priority_cnt = 0;
  29. btcoex->bt_priority_time = jiffies;
  30. }
  31. }
  32. /*
  33. * This is the master bt coex work which runs for every
  34. * 45ms, bt traffic will be given priority during 55% of this
  35. * period while wlan gets remaining 45%
  36. */
  37. static void ath_btcoex_period_work(struct work_struct *work)
  38. {
  39. struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
  40. coex_period_work.work);
  41. struct ath_btcoex *btcoex = &priv->btcoex;
  42. struct ath_common *common = ath9k_hw_common(priv->ah);
  43. u32 timer_period;
  44. bool is_btscan;
  45. int ret;
  46. u8 cmd_rsp, aggr;
  47. ath_detect_bt_priority(priv);
  48. is_btscan = !!(priv->op_flags & OP_BT_SCAN);
  49. aggr = priv->op_flags & OP_BT_PRIORITY_DETECTED;
  50. WMI_CMD_BUF(WMI_AGGR_LIMIT_CMD, &aggr);
  51. ath9k_cmn_btcoex_bt_stomp(common, is_btscan ? ATH_BTCOEX_STOMP_ALL :
  52. btcoex->bt_stomp_type);
  53. timer_period = is_btscan ? btcoex->btscan_no_stomp :
  54. btcoex->btcoex_no_stomp;
  55. ieee80211_queue_delayed_work(priv->hw, &priv->duty_cycle_work,
  56. msecs_to_jiffies(timer_period));
  57. ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work,
  58. msecs_to_jiffies(btcoex->btcoex_period));
  59. }
  60. /*
  61. * Work to time slice between wlan and bt traffic and
  62. * configure weight registers
  63. */
  64. static void ath_btcoex_duty_cycle_work(struct work_struct *work)
  65. {
  66. struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
  67. duty_cycle_work.work);
  68. struct ath_hw *ah = priv->ah;
  69. struct ath_btcoex *btcoex = &priv->btcoex;
  70. struct ath_common *common = ath9k_hw_common(ah);
  71. bool is_btscan = priv->op_flags & OP_BT_SCAN;
  72. ath_print(common, ATH_DBG_BTCOEX,
  73. "time slice work for bt and wlan\n");
  74. if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan)
  75. ath9k_cmn_btcoex_bt_stomp(common, ATH_BTCOEX_STOMP_NONE);
  76. else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
  77. ath9k_cmn_btcoex_bt_stomp(common, ATH_BTCOEX_STOMP_LOW);
  78. }
  79. void ath_htc_init_btcoex_work(struct ath9k_htc_priv *priv)
  80. {
  81. struct ath_btcoex *btcoex = &priv->btcoex;
  82. btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD;
  83. btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
  84. btcoex->btcoex_period / 100;
  85. btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
  86. btcoex->btcoex_period / 100;
  87. INIT_DELAYED_WORK(&priv->coex_period_work, ath_btcoex_period_work);
  88. INIT_DELAYED_WORK(&priv->duty_cycle_work, ath_btcoex_duty_cycle_work);
  89. }
  90. /*
  91. * (Re)start btcoex work
  92. */
  93. void ath_htc_resume_btcoex_work(struct ath9k_htc_priv *priv)
  94. {
  95. struct ath_btcoex *btcoex = &priv->btcoex;
  96. struct ath_hw *ah = priv->ah;
  97. ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
  98. "Starting btcoex work");
  99. btcoex->bt_priority_cnt = 0;
  100. btcoex->bt_priority_time = jiffies;
  101. priv->op_flags &= ~(OP_BT_PRIORITY_DETECTED | OP_BT_SCAN);
  102. ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 0);
  103. }
  104. /*
  105. * Cancel btcoex and bt duty cycle work.
  106. */
  107. void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv)
  108. {
  109. cancel_delayed_work_sync(&priv->coex_period_work);
  110. cancel_delayed_work_sync(&priv->duty_cycle_work);
  111. }