ar9003_rtt.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c) 2010-2011 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. #include "ar9003_phy.h"
  18. #define RTT_RESTORE_TIMEOUT 1000
  19. #define RTT_ACCESS_TIMEOUT 100
  20. #define RTT_BAD_VALUE 0x0bad0bad
  21. /*
  22. * RTT (Radio Retention Table) hardware implementation information
  23. *
  24. * There is an internal table (i.e. the rtt) for each chain (or bank).
  25. * Each table contains 6 entries and each entry is corresponding to
  26. * a specific calibration parameter as depicted below.
  27. * 0~2 - DC offset DAC calibration: loop, low, high (offsetI/Q_...)
  28. * 3 - Filter cal (filterfc)
  29. * 4 - RX gain settings
  30. * 5 - Peak detector offset calibration (agc_caldac)
  31. */
  32. void ar9003_hw_rtt_enable(struct ath_hw *ah)
  33. {
  34. REG_WRITE(ah, AR_PHY_RTT_CTRL, 1);
  35. }
  36. void ar9003_hw_rtt_disable(struct ath_hw *ah)
  37. {
  38. REG_WRITE(ah, AR_PHY_RTT_CTRL, 0);
  39. }
  40. void ar9003_hw_rtt_set_mask(struct ath_hw *ah, u32 rtt_mask)
  41. {
  42. REG_RMW_FIELD(ah, AR_PHY_RTT_CTRL,
  43. AR_PHY_RTT_CTRL_RESTORE_MASK, rtt_mask);
  44. }
  45. bool ar9003_hw_rtt_force_restore(struct ath_hw *ah)
  46. {
  47. if (!ath9k_hw_wait(ah, AR_PHY_RTT_CTRL,
  48. AR_PHY_RTT_CTRL_FORCE_RADIO_RESTORE,
  49. 0, RTT_RESTORE_TIMEOUT))
  50. return false;
  51. REG_RMW_FIELD(ah, AR_PHY_RTT_CTRL,
  52. AR_PHY_RTT_CTRL_FORCE_RADIO_RESTORE, 1);
  53. if (!ath9k_hw_wait(ah, AR_PHY_RTT_CTRL,
  54. AR_PHY_RTT_CTRL_FORCE_RADIO_RESTORE,
  55. 0, RTT_RESTORE_TIMEOUT))
  56. return false;
  57. return true;
  58. }
  59. static void ar9003_hw_rtt_load_hist_entry(struct ath_hw *ah, u8 chain,
  60. u32 index, u32 data28)
  61. {
  62. u32 val;
  63. val = SM(data28, AR_PHY_RTT_SW_RTT_TABLE_DATA);
  64. REG_WRITE(ah, AR_PHY_RTT_TABLE_SW_INTF_1_B(chain), val);
  65. val = SM(0, AR_PHY_RTT_SW_RTT_TABLE_ACCESS) |
  66. SM(1, AR_PHY_RTT_SW_RTT_TABLE_WRITE) |
  67. SM(index, AR_PHY_RTT_SW_RTT_TABLE_ADDR);
  68. REG_WRITE(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain), val);
  69. udelay(1);
  70. val |= SM(1, AR_PHY_RTT_SW_RTT_TABLE_ACCESS);
  71. REG_WRITE(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain), val);
  72. udelay(1);
  73. if (!ath9k_hw_wait(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain),
  74. AR_PHY_RTT_SW_RTT_TABLE_ACCESS, 0,
  75. RTT_ACCESS_TIMEOUT))
  76. return;
  77. val &= ~SM(1, AR_PHY_RTT_SW_RTT_TABLE_WRITE);
  78. REG_WRITE(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain), val);
  79. udelay(1);
  80. ath9k_hw_wait(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain),
  81. AR_PHY_RTT_SW_RTT_TABLE_ACCESS, 0,
  82. RTT_ACCESS_TIMEOUT);
  83. }
  84. void ar9003_hw_rtt_load_hist(struct ath_hw *ah, u8 chain, u32 *table)
  85. {
  86. int i;
  87. for (i = 0; i < MAX_RTT_TABLE_ENTRY; i++)
  88. ar9003_hw_rtt_load_hist_entry(ah, chain, i, table[i]);
  89. }
  90. static int ar9003_hw_rtt_fill_hist_entry(struct ath_hw *ah, u8 chain, u32 index)
  91. {
  92. u32 val;
  93. val = SM(0, AR_PHY_RTT_SW_RTT_TABLE_ACCESS) |
  94. SM(0, AR_PHY_RTT_SW_RTT_TABLE_WRITE) |
  95. SM(index, AR_PHY_RTT_SW_RTT_TABLE_ADDR);
  96. REG_WRITE(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain), val);
  97. udelay(1);
  98. val |= SM(1, AR_PHY_RTT_SW_RTT_TABLE_ACCESS);
  99. REG_WRITE(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain), val);
  100. udelay(1);
  101. if (!ath9k_hw_wait(ah, AR_PHY_RTT_TABLE_SW_INTF_B(chain),
  102. AR_PHY_RTT_SW_RTT_TABLE_ACCESS, 0,
  103. RTT_ACCESS_TIMEOUT))
  104. return RTT_BAD_VALUE;
  105. val = REG_READ(ah, AR_PHY_RTT_TABLE_SW_INTF_1_B(chain));
  106. return val;
  107. }
  108. void ar9003_hw_rtt_fill_hist(struct ath_hw *ah, u8 chain, u32 *table)
  109. {
  110. int i;
  111. for (i = 0; i < MAX_RTT_TABLE_ENTRY; i++)
  112. table[i] = ar9003_hw_rtt_fill_hist_entry(ah, chain, i);
  113. }
  114. void ar9003_hw_rtt_clear_hist(struct ath_hw *ah)
  115. {
  116. int i, j;
  117. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  118. if (!(ah->rxchainmask & (1 << i)))
  119. continue;
  120. for (j = 0; j < MAX_RTT_TABLE_ENTRY; j++)
  121. ar9003_hw_rtt_load_hist_entry(ah, i, j, 0);
  122. }
  123. }