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