calib.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_HIGH_VALUE -62
  29. #define AR_PHY_CCA_MIN_BAD_VALUE -140
  30. #define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT 3
  31. #define AR_PHY_CCA_FILTERWINDOW_LENGTH 5
  32. #define NUM_NF_READINGS 6
  33. #define ATH9K_NF_CAL_HIST_MAX 5
  34. struct ar5416IniArray {
  35. u32 *ia_array;
  36. u32 ia_rows;
  37. u32 ia_columns;
  38. };
  39. #define INIT_INI_ARRAY(iniarray, array, rows, columns) do { \
  40. (iniarray)->ia_array = (u32 *)(array); \
  41. (iniarray)->ia_rows = (rows); \
  42. (iniarray)->ia_columns = (columns); \
  43. } while (0)
  44. #define INI_RA(iniarray, row, column) \
  45. (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)])
  46. #define INIT_CAL(_perCal) do { \
  47. (_perCal)->calState = CAL_WAITING; \
  48. (_perCal)->calNext = NULL; \
  49. } while (0)
  50. #define INSERT_CAL(_ahp, _perCal) \
  51. do { \
  52. if ((_ahp)->cal_list_last == NULL) { \
  53. (_ahp)->cal_list = \
  54. (_ahp)->cal_list_last = (_perCal); \
  55. ((_ahp)->cal_list_last)->calNext = (_perCal); \
  56. } else { \
  57. ((_ahp)->cal_list_last)->calNext = (_perCal); \
  58. (_ahp)->cal_list_last = (_perCal); \
  59. (_perCal)->calNext = (_ahp)->cal_list; \
  60. } \
  61. } while (0)
  62. enum ath9k_cal_types {
  63. ADC_DC_INIT_CAL = 0x1,
  64. ADC_GAIN_CAL = 0x2,
  65. ADC_DC_CAL = 0x4,
  66. IQ_MISMATCH_CAL = 0x8
  67. };
  68. enum ath9k_cal_state {
  69. CAL_INACTIVE,
  70. CAL_WAITING,
  71. CAL_RUNNING,
  72. CAL_DONE
  73. };
  74. #define MIN_CAL_SAMPLES 1
  75. #define MAX_CAL_SAMPLES 64
  76. #define INIT_LOG_COUNT 5
  77. #define PER_MIN_LOG_COUNT 2
  78. #define PER_MAX_LOG_COUNT 10
  79. struct ath9k_percal_data {
  80. enum ath9k_cal_types calType;
  81. u32 calNumSamples;
  82. u32 calCountMax;
  83. void (*calCollect) (struct ath_hw *);
  84. void (*calPostProc) (struct ath_hw *, u8);
  85. };
  86. struct ath9k_cal_list {
  87. const struct ath9k_percal_data *calData;
  88. enum ath9k_cal_state calState;
  89. struct ath9k_cal_list *calNext;
  90. };
  91. struct ath9k_nfcal_hist {
  92. int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
  93. u8 currIndex;
  94. int16_t privNF;
  95. u8 invalidNFcount;
  96. };
  97. bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
  98. void ath9k_hw_start_nfcal(struct ath_hw *ah);
  99. void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
  100. int16_t ath9k_hw_getnf(struct ath_hw *ah,
  101. struct ath9k_channel *chan);
  102. void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
  103. s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
  104. bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
  105. u8 rxchainmask, bool longcal);
  106. bool ath9k_hw_init_cal(struct ath_hw *ah,
  107. struct ath9k_channel *chan);
  108. #endif /* CALIB_H */