calib.h 4.1 KB
Newer Older
S
Sujith 已提交
1
/*
2
 * Copyright (c) 2008-2009 Atheros Communications Inc.
S
Sujith 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef CALIB_H
#define CALIB_H

20 21 22 23 24 25 26
extern const struct ath9k_percal_data iq_cal_multi_sample;
extern const struct ath9k_percal_data iq_cal_single_sample;
extern const struct ath9k_percal_data adc_gain_cal_multi_sample;
extern const struct ath9k_percal_data adc_gain_cal_single_sample;
extern const struct ath9k_percal_data adc_dc_cal_multi_sample;
extern const struct ath9k_percal_data adc_dc_cal_single_sample;
extern const struct ath9k_percal_data adc_init_dc_cal;
S
Sujith 已提交
27

28 29 30
#define AR_PHY_CCA_MAX_AR5416_GOOD_VALUE	-85
#define AR_PHY_CCA_MAX_AR9280_GOOD_VALUE	-112
#define AR_PHY_CCA_MAX_AR9285_GOOD_VALUE	-118
31
#define AR_PHY_CCA_MAX_AR9287_GOOD_VALUE	-118
S
Sujith 已提交
32
#define AR_PHY_CCA_MAX_HIGH_VALUE      		-62
S
Sujith 已提交
33
#define AR_PHY_CCA_MIN_BAD_VALUE       		-140
S
Sujith 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT     3
#define AR_PHY_CCA_FILTERWINDOW_LENGTH          5

#define NUM_NF_READINGS       6
#define ATH9K_NF_CAL_HIST_MAX 5

struct ar5416IniArray {
	u32 *ia_array;
	u32 ia_rows;
	u32 ia_columns;
};

#define INIT_INI_ARRAY(iniarray, array, rows, columns) do {	\
		(iniarray)->ia_array = (u32 *)(array);		\
		(iniarray)->ia_rows = (rows);			\
		(iniarray)->ia_columns = (columns);		\
	} while (0)

#define INI_RA(iniarray, row, column) \
	(((iniarray)->ia_array)[(row) *	((iniarray)->ia_columns) + (column)])

#define INIT_CAL(_perCal) do {				\
		(_perCal)->calState = CAL_WAITING;	\
		(_perCal)->calNext = NULL;		\
	} while (0)

#define INSERT_CAL(_ahp, _perCal)					\
	do {								\
62 63 64 65
		if ((_ahp)->cal_list_last == NULL) {			\
			(_ahp)->cal_list =				\
				(_ahp)->cal_list_last = (_perCal);	\
			((_ahp)->cal_list_last)->calNext = (_perCal); \
S
Sujith 已提交
66
		} else {						\
67 68 69
			((_ahp)->cal_list_last)->calNext = (_perCal); \
			(_ahp)->cal_list_last = (_perCal);		\
			(_perCal)->calNext = (_ahp)->cal_list;	\
S
Sujith 已提交
70 71 72
		}							\
	} while (0)

73
enum ath9k_cal_types {
S
Sujith 已提交
74 75 76 77 78 79
	ADC_DC_INIT_CAL = 0x1,
	ADC_GAIN_CAL = 0x2,
	ADC_DC_CAL = 0x4,
	IQ_MISMATCH_CAL = 0x8
};

80
enum ath9k_cal_state {
S
Sujith 已提交
81 82 83 84 85 86 87 88 89 90 91 92
	CAL_INACTIVE,
	CAL_WAITING,
	CAL_RUNNING,
	CAL_DONE
};

#define MIN_CAL_SAMPLES     1
#define MAX_CAL_SAMPLES    64
#define INIT_LOG_COUNT      5
#define PER_MIN_LOG_COUNT   2
#define PER_MAX_LOG_COUNT  10

93 94
struct ath9k_percal_data {
	enum ath9k_cal_types calType;
S
Sujith 已提交
95 96
	u32 calNumSamples;
	u32 calCountMax;
97 98
	void (*calCollect) (struct ath_hw *);
	void (*calPostProc) (struct ath_hw *, u8);
S
Sujith 已提交
99 100
};

101 102 103 104
struct ath9k_cal_list {
	const struct ath9k_percal_data *calData;
	enum ath9k_cal_state calState;
	struct ath9k_cal_list *calNext;
S
Sujith 已提交
105 106 107 108 109 110 111 112 113
};

struct ath9k_nfcal_hist {
	int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
	u8 currIndex;
	int16_t privNF;
	u8 invalidNFcount;
};

114 115 116 117 118 119 120
#define MAX_PACAL_SKIPCOUNT 8
struct ath9k_pacal_info{
	int32_t prev_offset;	/* Previous value of PA offset value */
	int8_t max_skipcount;	/* Max No. of times PACAL can be skipped */
	int8_t skipcount;	/* No. of times the PACAL to be skipped */
};

121 122 123 124
bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
void ath9k_hw_start_nfcal(struct ath_hw *ah);
void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
int16_t ath9k_hw_getnf(struct ath_hw *ah,
S
Sujith 已提交
125
		       struct ath9k_channel *chan);
126 127 128
void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
S
Sujith 已提交
129
			u8 rxchainmask, bool longcal);
130
bool ath9k_hw_init_cal(struct ath_hw *ah,
S
Sujith 已提交
131 132 133
		       struct ath9k_channel *chan);

#endif /* CALIB_H */