blob: 9028ab193e4203e8a133efc396b0bd9fb07c62c9 [file] [log] [blame]
Sujith394cf0a2009-02-09 13:26:54 +05301/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Sujith394cf0a2009-02-09 13:26:54 +05303 *
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
Sujithcbfe9462009-04-13 21:56:56 +053020extern const struct ath9k_percal_data iq_cal_multi_sample;
21extern const struct ath9k_percal_data iq_cal_single_sample;
22extern const struct ath9k_percal_data adc_gain_cal_multi_sample;
23extern const struct ath9k_percal_data adc_gain_cal_single_sample;
24extern const struct ath9k_percal_data adc_dc_cal_multi_sample;
25extern const struct ath9k_percal_data adc_dc_cal_single_sample;
26extern const struct ath9k_percal_data adc_init_dc_cal;
Sujith394cf0a2009-02-09 13:26:54 +053027
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -040028#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
Vivek Natarajan6170cd52009-09-17 09:24:24 +053031#define AR_PHY_CCA_MAX_AR9287_GOOD_VALUE -118
Sujith394cf0a2009-02-09 13:26:54 +053032#define AR_PHY_CCA_MAX_HIGH_VALUE -62
Sujithb06e7862009-02-12 10:06:54 +053033#define AR_PHY_CCA_MIN_BAD_VALUE -140
Sujith394cf0a2009-02-09 13:26:54 +053034#define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT 3
35#define AR_PHY_CCA_FILTERWINDOW_LENGTH 5
36
37#define NUM_NF_READINGS 6
38#define ATH9K_NF_CAL_HIST_MAX 5
39
40struct ar5416IniArray {
41 u32 *ia_array;
42 u32 ia_rows;
43 u32 ia_columns;
44};
45
46#define INIT_INI_ARRAY(iniarray, array, rows, columns) do { \
47 (iniarray)->ia_array = (u32 *)(array); \
48 (iniarray)->ia_rows = (rows); \
49 (iniarray)->ia_columns = (columns); \
50 } while (0)
51
52#define INI_RA(iniarray, row, column) \
53 (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)])
54
55#define INIT_CAL(_perCal) do { \
56 (_perCal)->calState = CAL_WAITING; \
57 (_perCal)->calNext = NULL; \
58 } while (0)
59
60#define INSERT_CAL(_ahp, _perCal) \
61 do { \
Sujith2660b812009-02-09 13:27:26 +053062 if ((_ahp)->cal_list_last == NULL) { \
63 (_ahp)->cal_list = \
64 (_ahp)->cal_list_last = (_perCal); \
65 ((_ahp)->cal_list_last)->calNext = (_perCal); \
Sujith394cf0a2009-02-09 13:26:54 +053066 } else { \
Sujith2660b812009-02-09 13:27:26 +053067 ((_ahp)->cal_list_last)->calNext = (_perCal); \
68 (_ahp)->cal_list_last = (_perCal); \
69 (_perCal)->calNext = (_ahp)->cal_list; \
Sujith394cf0a2009-02-09 13:26:54 +053070 } \
71 } while (0)
72
Sujithcbfe9462009-04-13 21:56:56 +053073enum ath9k_cal_types {
Sujith394cf0a2009-02-09 13:26:54 +053074 ADC_DC_INIT_CAL = 0x1,
75 ADC_GAIN_CAL = 0x2,
76 ADC_DC_CAL = 0x4,
77 IQ_MISMATCH_CAL = 0x8
78};
79
Sujithcbfe9462009-04-13 21:56:56 +053080enum ath9k_cal_state {
Sujith394cf0a2009-02-09 13:26:54 +053081 CAL_INACTIVE,
82 CAL_WAITING,
83 CAL_RUNNING,
84 CAL_DONE
85};
86
87#define MIN_CAL_SAMPLES 1
88#define MAX_CAL_SAMPLES 64
89#define INIT_LOG_COUNT 5
90#define PER_MIN_LOG_COUNT 2
91#define PER_MAX_LOG_COUNT 10
92
Sujithcbfe9462009-04-13 21:56:56 +053093struct ath9k_percal_data {
94 enum ath9k_cal_types calType;
Sujith394cf0a2009-02-09 13:26:54 +053095 u32 calNumSamples;
96 u32 calCountMax;
Sujithcbe61d82009-02-09 13:27:12 +053097 void (*calCollect) (struct ath_hw *);
98 void (*calPostProc) (struct ath_hw *, u8);
Sujith394cf0a2009-02-09 13:26:54 +053099};
100
Sujithcbfe9462009-04-13 21:56:56 +0530101struct ath9k_cal_list {
102 const struct ath9k_percal_data *calData;
103 enum ath9k_cal_state calState;
104 struct ath9k_cal_list *calNext;
Sujith394cf0a2009-02-09 13:26:54 +0530105};
106
107struct ath9k_nfcal_hist {
108 int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
109 u8 currIndex;
110 int16_t privNF;
111 u8 invalidNFcount;
112};
113
Sujitha13883b2009-08-26 08:39:40 +0530114#define MAX_PACAL_SKIPCOUNT 8
115struct ath9k_pacal_info{
116 int32_t prev_offset; /* Previous value of PA offset value */
117 int8_t max_skipcount; /* Max No. of times PACAL can be skipped */
118 int8_t skipcount; /* No. of times the PACAL to be skipped */
119};
120
Sujithcbe61d82009-02-09 13:27:12 +0530121bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
122void ath9k_hw_start_nfcal(struct ath_hw *ah);
123void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
124int16_t ath9k_hw_getnf(struct ath_hw *ah,
Sujith394cf0a2009-02-09 13:26:54 +0530125 struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +0530126void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
127s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
128bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
Sujith379f0442009-04-13 21:56:48 +0530129 u8 rxchainmask, bool longcal);
Sujithcbe61d82009-02-09 13:27:12 +0530130bool ath9k_hw_init_cal(struct ath_hw *ah,
Sujith394cf0a2009-02-09 13:26:54 +0530131 struct ath9k_channel *chan);
132
133#endif /* CALIB_H */