Merge branch 'linus' into tracing/core
[linux-block.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 extern const struct ath9k_percal_data iq_cal_multi_sample;
21 extern const struct ath9k_percal_data iq_cal_single_sample;
22 extern const struct ath9k_percal_data adc_gain_cal_multi_sample;
23 extern const struct ath9k_percal_data adc_gain_cal_single_sample;
24 extern const struct ath9k_percal_data adc_dc_cal_multi_sample;
25 extern const struct ath9k_percal_data adc_dc_cal_single_sample;
26 extern const struct ath9k_percal_data adc_init_dc_cal;
27
28 #define AR_PHY_CCA_MAX_AR5416_GOOD_VALUE        -85
29 #define AR_PHY_CCA_MAX_AR9280_GOOD_VALUE        -112
30 #define AR_PHY_CCA_MAX_AR9285_GOOD_VALUE        -118
31 #define AR_PHY_CCA_MAX_HIGH_VALUE               -62
32 #define AR_PHY_CCA_MIN_BAD_VALUE                -140
33 #define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT     3
34 #define AR_PHY_CCA_FILTERWINDOW_LENGTH          5
35
36 #define NUM_NF_READINGS       6
37 #define ATH9K_NF_CAL_HIST_MAX 5
38
39 struct ar5416IniArray {
40         u32 *ia_array;
41         u32 ia_rows;
42         u32 ia_columns;
43 };
44
45 #define INIT_INI_ARRAY(iniarray, array, rows, columns) do {     \
46                 (iniarray)->ia_array = (u32 *)(array);          \
47                 (iniarray)->ia_rows = (rows);                   \
48                 (iniarray)->ia_columns = (columns);             \
49         } while (0)
50
51 #define INI_RA(iniarray, row, column) \
52         (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)])
53
54 #define INIT_CAL(_perCal) do {                          \
55                 (_perCal)->calState = CAL_WAITING;      \
56                 (_perCal)->calNext = NULL;              \
57         } while (0)
58
59 #define INSERT_CAL(_ahp, _perCal)                                       \
60         do {                                                            \
61                 if ((_ahp)->cal_list_last == NULL) {                    \
62                         (_ahp)->cal_list =                              \
63                                 (_ahp)->cal_list_last = (_perCal);      \
64                         ((_ahp)->cal_list_last)->calNext = (_perCal); \
65                 } else {                                                \
66                         ((_ahp)->cal_list_last)->calNext = (_perCal); \
67                         (_ahp)->cal_list_last = (_perCal);              \
68                         (_perCal)->calNext = (_ahp)->cal_list;  \
69                 }                                                       \
70         } while (0)
71
72 enum ath9k_cal_types {
73         ADC_DC_INIT_CAL = 0x1,
74         ADC_GAIN_CAL = 0x2,
75         ADC_DC_CAL = 0x4,
76         IQ_MISMATCH_CAL = 0x8
77 };
78
79 enum ath9k_cal_state {
80         CAL_INACTIVE,
81         CAL_WAITING,
82         CAL_RUNNING,
83         CAL_DONE
84 };
85
86 #define MIN_CAL_SAMPLES     1
87 #define MAX_CAL_SAMPLES    64
88 #define INIT_LOG_COUNT      5
89 #define PER_MIN_LOG_COUNT   2
90 #define PER_MAX_LOG_COUNT  10
91
92 struct ath9k_percal_data {
93         enum ath9k_cal_types calType;
94         u32 calNumSamples;
95         u32 calCountMax;
96         void (*calCollect) (struct ath_hw *);
97         void (*calPostProc) (struct ath_hw *, u8);
98 };
99
100 struct ath9k_cal_list {
101         const struct ath9k_percal_data *calData;
102         enum ath9k_cal_state calState;
103         struct ath9k_cal_list *calNext;
104 };
105
106 struct ath9k_nfcal_hist {
107         int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
108         u8 currIndex;
109         int16_t privNF;
110         u8 invalidNFcount;
111 };
112
113 #define MAX_PACAL_SKIPCOUNT 8
114 struct ath9k_pacal_info{
115         int32_t prev_offset;    /* Previous value of PA offset value */
116         int8_t max_skipcount;   /* Max No. of times PACAL can be skipped */
117         int8_t skipcount;       /* No. of times the PACAL to be skipped */
118 };
119
120 bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
121 void ath9k_hw_start_nfcal(struct ath_hw *ah);
122 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
123 int16_t ath9k_hw_getnf(struct ath_hw *ah,
124                        struct ath9k_channel *chan);
125 void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
126 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
127 bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
128                         u8 rxchainmask, bool longcal);
129 bool ath9k_hw_init_cal(struct ath_hw *ah,
130                        struct ath9k_channel *chan);
131
132 #endif /* CALIB_H */