calib.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2008-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. #ifndef CALIB_H
  17. #define CALIB_H
  18. extern const struct ath9k_percal_data iq_cal_multi_sample;
  19. extern const struct ath9k_percal_data iq_cal_single_sample;
  20. extern const struct ath9k_percal_data adc_gain_cal_multi_sample;
  21. extern const struct ath9k_percal_data adc_gain_cal_single_sample;
  22. extern const struct ath9k_percal_data adc_dc_cal_multi_sample;
  23. extern const struct ath9k_percal_data adc_dc_cal_single_sample;
  24. extern const struct ath9k_percal_data adc_init_dc_cal;
  25. #define AR_PHY_CCA_MAX_AR5416_GOOD_VALUE -85
  26. #define AR_PHY_CCA_MAX_AR9280_GOOD_VALUE -112
  27. #define AR_PHY_CCA_MAX_AR9285_GOOD_VALUE -118
  28. #define AR_PHY_CCA_MAX_AR9287_GOOD_VALUE -118
  29. #define AR_PHY_CCA_MAX_HIGH_VALUE -62
  30. #define AR_PHY_CCA_MIN_BAD_VALUE -140
  31. #define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT 3
  32. #define AR_PHY_CCA_FILTERWINDOW_LENGTH 5
  33. #define NUM_NF_READINGS 6
  34. #define ATH9K_NF_CAL_HIST_MAX 5
  35. struct ar5416IniArray {
  36. u32 *ia_array;
  37. u32 ia_rows;
  38. u32 ia_columns;
  39. };
  40. #define INIT_INI_ARRAY(iniarray, array, rows, columns) do { \
  41. (iniarray)->ia_array = (u32 *)(array); \
  42. (iniarray)->ia_rows = (rows); \
  43. (iniarray)->ia_columns = (columns); \
  44. } while (0)
  45. #define INI_RA(iniarray, row, column) \
  46. (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)])
  47. #define INIT_CAL(_perCal) do { \
  48. (_perCal)->calState = CAL_WAITING; \
  49. (_perCal)->calNext = NULL; \
  50. } while (0)
  51. #define INSERT_CAL(_ahp, _perCal) \
  52. do { \
  53. if ((_ahp)->cal_list_last == NULL) { \
  54. (_ahp)->cal_list = \
  55. (_ahp)->cal_list_last = (_perCal); \
  56. ((_ahp)->cal_list_last)->calNext = (_perCal); \
  57. } else { \
  58. ((_ahp)->cal_list_last)->calNext = (_perCal); \
  59. (_ahp)->cal_list_last = (_perCal); \
  60. (_perCal)->calNext = (_ahp)->cal_list; \
  61. } \
  62. } while (0)
  63. enum ath9k_cal_types {
  64. ADC_DC_INIT_CAL = 0x1,
  65. ADC_GAIN_CAL = 0x2,
  66. ADC_DC_CAL = 0x4,
  67. IQ_MISMATCH_CAL = 0x8
  68. };
  69. enum ath9k_cal_state {
  70. CAL_INACTIVE,
  71. CAL_WAITING,
  72. CAL_RUNNING,
  73. CAL_DONE
  74. };
  75. #define MIN_CAL_SAMPLES 1
  76. #define MAX_CAL_SAMPLES 64
  77. #define INIT_LOG_COUNT 5
  78. #define PER_MIN_LOG_COUNT 2
  79. #define PER_MAX_LOG_COUNT 10
  80. struct ath9k_percal_data {
  81. enum ath9k_cal_types calType;
  82. u32 calNumSamples;
  83. u32 calCountMax;
  84. void (*calCollect) (struct ath_hw *);
  85. void (*calPostProc) (struct ath_hw *, u8);
  86. };
  87. struct ath9k_cal_list {
  88. const struct ath9k_percal_data *calData;
  89. enum ath9k_cal_state calState;
  90. struct ath9k_cal_list *calNext;
  91. };
  92. struct ath9k_nfcal_hist {
  93. int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
  94. u8 currIndex;
  95. int16_t privNF;
  96. u8 invalidNFcount;
  97. };
  98. #define MAX_PACAL_SKIPCOUNT 8
  99. struct ath9k_pacal_info{
  100. int32_t prev_offset; /* Previous value of PA offset value */
  101. int8_t max_skipcount; /* Max No. of times PACAL can be skipped */
  102. int8_t skipcount; /* No. of times the PACAL to be skipped */
  103. };
  104. bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
  105. void ath9k_hw_start_nfcal(struct ath_hw *ah);
  106. void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
  107. int16_t ath9k_hw_getnf(struct ath_hw *ah,
  108. struct ath9k_channel *chan);
  109. void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
  110. s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
  111. bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
  112. u8 rxchainmask, bool longcal);
  113. bool ath9k_hw_init_cal(struct ath_hw *ah,
  114. struct ath9k_channel *chan);
  115. #endif /* CALIB_H */