calib.h 3.6 KB

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