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