ar9003_rtt.c 4.3 KB

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