ath9k_hw: Fix signal strength / channel noise reporting
[pandora-kernel.git] / drivers / net / wireless / ath / ath9k / calib.h
1 /*
2  * Copyright (c) 2008-2011 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_FILTERWINDOW_LENGTH_INIT     3
23 #define AR_PHY_CCA_FILTERWINDOW_LENGTH          5
24
25 /* Internal noise floor can vary by about 6db depending on the frequency */
26 #define ATH9K_NF_CAL_NOISE_THRESH               6
27
28 #define NUM_NF_READINGS       6
29 #define ATH9K_NF_CAL_HIST_MAX 5
30
31 struct ar5416IniArray {
32         u32 *ia_array;
33         u32 ia_rows;
34         u32 ia_columns;
35 };
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
43 #define INI_RA(iniarray, row, column) \
44         (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)])
45
46 #define INIT_CAL(_perCal) do {                          \
47                 (_perCal)->calState = CAL_WAITING;      \
48                 (_perCal)->calNext = NULL;              \
49         } while (0)
50
51 #define INSERT_CAL(_ahp, _perCal)                                       \
52         do {                                                            \
53                 if ((_ahp)->cal_list_last == NULL) {                    \
54                         (_ahp)->cal_list =                              \
55                                 (_ahp)->cal_list_last = (_perCal);      \
56                         ((_ahp)->cal_list_last)->calNext = (_perCal); \
57                 } else {                                                \
58                         ((_ahp)->cal_list_last)->calNext = (_perCal); \
59                         (_ahp)->cal_list_last = (_perCal);              \
60                         (_perCal)->calNext = (_ahp)->cal_list;  \
61                 }                                                       \
62         } while (0)
63
64 enum ath9k_cal_state {
65         CAL_INACTIVE,
66         CAL_WAITING,
67         CAL_RUNNING,
68         CAL_DONE
69 };
70
71 #define MIN_CAL_SAMPLES     1
72 #define MAX_CAL_SAMPLES    64
73 #define INIT_LOG_COUNT      5
74 #define PER_MIN_LOG_COUNT   2
75 #define PER_MAX_LOG_COUNT  10
76
77 struct ath9k_percal_data {
78         u32 calType;
79         u32 calNumSamples;
80         u32 calCountMax;
81         void (*calCollect) (struct ath_hw *);
82         void (*calPostProc) (struct ath_hw *, u8);
83 };
84
85 struct ath9k_cal_list {
86         const struct ath9k_percal_data *calData;
87         enum ath9k_cal_state calState;
88         struct ath9k_cal_list *calNext;
89 };
90
91 struct ath9k_nfcal_hist {
92         int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
93         u8 currIndex;
94         int16_t privNF;
95         u8 invalidNFcount;
96 };
97
98 #define MAX_PACAL_SKIPCOUNT 8
99 struct ath9k_pacal_info{
100         int32_t prev_offset;    /* Previous value of PA offset value */
101         int8_t max_skipcount;   /* Max No. of times PACAL can be skipped */
102         int8_t skipcount;       /* No. of times the PACAL to be skipped */
103 };
104
105 bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
106 void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
107 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
108 bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
109 void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
110                                   struct ath9k_channel *chan);
111 void ath9k_hw_bstuck_nfcal(struct ath_hw *ah);
112 void ath9k_hw_reset_calibration(struct ath_hw *ah,
113                                 struct ath9k_cal_list *currCal);
114 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
115
116
117 #endif /* CALIB_H */