Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 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 | |
| 17 | #ifndef CALIB_H |
| 18 | #define CALIB_H |
| 19 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame^] | 20 | #include "hw.h" |
| 21 | |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 22 | extern const struct ath9k_percal_data iq_cal_multi_sample; |
| 23 | extern const struct ath9k_percal_data iq_cal_single_sample; |
| 24 | extern const struct ath9k_percal_data adc_gain_cal_multi_sample; |
| 25 | extern const struct ath9k_percal_data adc_gain_cal_single_sample; |
| 26 | extern const struct ath9k_percal_data adc_dc_cal_multi_sample; |
| 27 | extern const struct ath9k_percal_data adc_dc_cal_single_sample; |
| 28 | extern const struct ath9k_percal_data adc_init_dc_cal; |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 29 | |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 30 | #define AR_PHY_CCA_MAX_AR5416_GOOD_VALUE -85 |
| 31 | #define AR_PHY_CCA_MAX_AR9280_GOOD_VALUE -112 |
| 32 | #define AR_PHY_CCA_MAX_AR9285_GOOD_VALUE -118 |
Vivek Natarajan | 6170cd5 | 2009-09-17 09:24:24 +0530 | [diff] [blame] | 33 | #define AR_PHY_CCA_MAX_AR9287_GOOD_VALUE -118 |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 34 | #define AR_PHY_CCA_MAX_HIGH_VALUE -62 |
Sujith | b06e786 | 2009-02-12 10:06:54 +0530 | [diff] [blame] | 35 | #define AR_PHY_CCA_MIN_BAD_VALUE -140 |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 36 | #define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT 3 |
| 37 | #define AR_PHY_CCA_FILTERWINDOW_LENGTH 5 |
| 38 | |
| 39 | #define NUM_NF_READINGS 6 |
| 40 | #define ATH9K_NF_CAL_HIST_MAX 5 |
| 41 | |
| 42 | struct ar5416IniArray { |
| 43 | u32 *ia_array; |
| 44 | u32 ia_rows; |
| 45 | u32 ia_columns; |
| 46 | }; |
| 47 | |
| 48 | #define INIT_INI_ARRAY(iniarray, array, rows, columns) do { \ |
| 49 | (iniarray)->ia_array = (u32 *)(array); \ |
| 50 | (iniarray)->ia_rows = (rows); \ |
| 51 | (iniarray)->ia_columns = (columns); \ |
| 52 | } while (0) |
| 53 | |
| 54 | #define INI_RA(iniarray, row, column) \ |
| 55 | (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)]) |
| 56 | |
| 57 | #define INIT_CAL(_perCal) do { \ |
| 58 | (_perCal)->calState = CAL_WAITING; \ |
| 59 | (_perCal)->calNext = NULL; \ |
| 60 | } while (0) |
| 61 | |
| 62 | #define INSERT_CAL(_ahp, _perCal) \ |
| 63 | do { \ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 64 | if ((_ahp)->cal_list_last == NULL) { \ |
| 65 | (_ahp)->cal_list = \ |
| 66 | (_ahp)->cal_list_last = (_perCal); \ |
| 67 | ((_ahp)->cal_list_last)->calNext = (_perCal); \ |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 68 | } else { \ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 69 | ((_ahp)->cal_list_last)->calNext = (_perCal); \ |
| 70 | (_ahp)->cal_list_last = (_perCal); \ |
| 71 | (_perCal)->calNext = (_ahp)->cal_list; \ |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 72 | } \ |
| 73 | } while (0) |
| 74 | |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 75 | enum ath9k_cal_types { |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 76 | ADC_DC_INIT_CAL = 0x1, |
| 77 | ADC_GAIN_CAL = 0x2, |
| 78 | ADC_DC_CAL = 0x4, |
| 79 | IQ_MISMATCH_CAL = 0x8 |
| 80 | }; |
| 81 | |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 82 | enum ath9k_cal_state { |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 83 | CAL_INACTIVE, |
| 84 | CAL_WAITING, |
| 85 | CAL_RUNNING, |
| 86 | CAL_DONE |
| 87 | }; |
| 88 | |
| 89 | #define MIN_CAL_SAMPLES 1 |
| 90 | #define MAX_CAL_SAMPLES 64 |
| 91 | #define INIT_LOG_COUNT 5 |
| 92 | #define PER_MIN_LOG_COUNT 2 |
| 93 | #define PER_MAX_LOG_COUNT 10 |
| 94 | |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 95 | struct ath9k_percal_data { |
| 96 | enum ath9k_cal_types calType; |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 97 | u32 calNumSamples; |
| 98 | u32 calCountMax; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 99 | void (*calCollect) (struct ath_hw *); |
| 100 | void (*calPostProc) (struct ath_hw *, u8); |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 101 | }; |
| 102 | |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 103 | struct ath9k_cal_list { |
| 104 | const struct ath9k_percal_data *calData; |
| 105 | enum ath9k_cal_state calState; |
| 106 | struct ath9k_cal_list *calNext; |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | struct ath9k_nfcal_hist { |
| 110 | int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX]; |
| 111 | u8 currIndex; |
| 112 | int16_t privNF; |
| 113 | u8 invalidNFcount; |
| 114 | }; |
| 115 | |
Sujith | a13883b | 2009-08-26 08:39:40 +0530 | [diff] [blame] | 116 | #define MAX_PACAL_SKIPCOUNT 8 |
| 117 | struct ath9k_pacal_info{ |
| 118 | int32_t prev_offset; /* Previous value of PA offset value */ |
| 119 | int8_t max_skipcount; /* Max No. of times PACAL can be skipped */ |
| 120 | int8_t skipcount; /* No. of times the PACAL to be skipped */ |
| 121 | }; |
| 122 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 123 | bool ath9k_hw_reset_calvalid(struct ath_hw *ah); |
| 124 | void ath9k_hw_start_nfcal(struct ath_hw *ah); |
| 125 | void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan); |
| 126 | int16_t ath9k_hw_getnf(struct ath_hw *ah, |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 127 | struct ath9k_channel *chan); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 128 | void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah); |
| 129 | s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan); |
| 130 | bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 131 | u8 rxchainmask, bool longcal); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 132 | bool ath9k_hw_init_cal(struct ath_hw *ah, |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 133 | struct ath9k_channel *chan); |
| 134 | |
| 135 | #endif /* CALIB_H */ |