calib.h 3.7 KB

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