162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2008-2011 Atheros Communications Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
562306a36Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
662306a36Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
962306a36Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1062306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1162306a36Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1262306a36Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1362306a36Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1462306a36Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#ifndef CALIB_H
1862306a36Sopenharmony_ci#define CALIB_H
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#include "hw.h"
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define AR_PHY_CCA_FILTERWINDOW_LENGTH          5
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/* Internal noise floor can vary by about 6db depending on the frequency */
2562306a36Sopenharmony_ci#define ATH9K_NF_CAL_NOISE_THRESH		6
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#define NUM_NF_READINGS       6
2862306a36Sopenharmony_ci#define ATH9K_NF_CAL_HIST_MAX 5
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistruct ar5416IniArray {
3162306a36Sopenharmony_ci	u32 *ia_array;
3262306a36Sopenharmony_ci	u32 ia_rows;
3362306a36Sopenharmony_ci	u32 ia_columns;
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define STATIC_INI_ARRAY(array) {			\
3762306a36Sopenharmony_ci		.ia_array = (u32 *)(array),		\
3862306a36Sopenharmony_ci		.ia_rows = ARRAY_SIZE(array),		\
3962306a36Sopenharmony_ci		.ia_columns = ARRAY_SIZE(array[0]),	\
4062306a36Sopenharmony_ci	}
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define INIT_INI_ARRAY(iniarray, array) do {	\
4362306a36Sopenharmony_ci		(iniarray)->ia_array = (u32 *)(array);		\
4462306a36Sopenharmony_ci		(iniarray)->ia_rows = ARRAY_SIZE(array);	\
4562306a36Sopenharmony_ci		(iniarray)->ia_columns = ARRAY_SIZE(array[0]);	\
4662306a36Sopenharmony_ci	} while (0)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define INI_RA(iniarray, row, column) \
4962306a36Sopenharmony_ci	(((iniarray)->ia_array)[(row) *	((iniarray)->ia_columns) + (column)])
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define INIT_CAL(_perCal) do {				\
5262306a36Sopenharmony_ci		(_perCal)->calState = CAL_WAITING;	\
5362306a36Sopenharmony_ci		(_perCal)->calNext = NULL;		\
5462306a36Sopenharmony_ci	} while (0)
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define INSERT_CAL(_ahp, _perCal)					\
5762306a36Sopenharmony_ci	do {								\
5862306a36Sopenharmony_ci		if ((_ahp)->cal_list_last == NULL) {			\
5962306a36Sopenharmony_ci			(_ahp)->cal_list =				\
6062306a36Sopenharmony_ci				(_ahp)->cal_list_last = (_perCal);	\
6162306a36Sopenharmony_ci			((_ahp)->cal_list_last)->calNext = (_perCal); \
6262306a36Sopenharmony_ci		} else {						\
6362306a36Sopenharmony_ci			((_ahp)->cal_list_last)->calNext = (_perCal); \
6462306a36Sopenharmony_ci			(_ahp)->cal_list_last = (_perCal);		\
6562306a36Sopenharmony_ci			(_perCal)->calNext = (_ahp)->cal_list;	\
6662306a36Sopenharmony_ci		}							\
6762306a36Sopenharmony_ci	} while (0)
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cienum ath9k_cal_state {
7062306a36Sopenharmony_ci	CAL_INACTIVE,
7162306a36Sopenharmony_ci	CAL_WAITING,
7262306a36Sopenharmony_ci	CAL_RUNNING,
7362306a36Sopenharmony_ci	CAL_DONE
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define MIN_CAL_SAMPLES     1
7762306a36Sopenharmony_ci#define MAX_CAL_SAMPLES    64
7862306a36Sopenharmony_ci#define INIT_LOG_COUNT      5
7962306a36Sopenharmony_ci#define PER_MIN_LOG_COUNT   2
8062306a36Sopenharmony_ci#define PER_MAX_LOG_COUNT  10
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistruct ath9k_percal_data {
8362306a36Sopenharmony_ci	u32 calType;
8462306a36Sopenharmony_ci	u32 calNumSamples;
8562306a36Sopenharmony_ci	u32 calCountMax;
8662306a36Sopenharmony_ci	void (*calCollect) (struct ath_hw *);
8762306a36Sopenharmony_ci	void (*calPostProc) (struct ath_hw *, u8);
8862306a36Sopenharmony_ci};
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_cistruct ath9k_cal_list {
9162306a36Sopenharmony_ci	const struct ath9k_percal_data *calData;
9262306a36Sopenharmony_ci	enum ath9k_cal_state calState;
9362306a36Sopenharmony_ci	struct ath9k_cal_list *calNext;
9462306a36Sopenharmony_ci};
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistruct ath9k_nfcal_hist {
9762306a36Sopenharmony_ci	int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX];
9862306a36Sopenharmony_ci	u8 currIndex;
9962306a36Sopenharmony_ci	int16_t privNF;
10062306a36Sopenharmony_ci	u8 invalidNFcount;
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define MAX_PACAL_SKIPCOUNT 8
10462306a36Sopenharmony_cistruct ath9k_pacal_info{
10562306a36Sopenharmony_ci	int32_t prev_offset;	/* Previous value of PA offset value */
10662306a36Sopenharmony_ci	int8_t max_skipcount;	/* Max No. of times PACAL can be skipped */
10762306a36Sopenharmony_ci	int8_t skipcount;	/* No. of times the PACAL to be skipped */
10862306a36Sopenharmony_ci};
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_cibool ath9k_hw_reset_calvalid(struct ath_hw *ah);
11162306a36Sopenharmony_civoid ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
11262306a36Sopenharmony_ciint ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
11362306a36Sopenharmony_cibool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
11462306a36Sopenharmony_civoid ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
11562306a36Sopenharmony_ci				  struct ath9k_channel *chan);
11662306a36Sopenharmony_civoid ath9k_hw_bstuck_nfcal(struct ath_hw *ah);
11762306a36Sopenharmony_civoid ath9k_hw_reset_calibration(struct ath_hw *ah,
11862306a36Sopenharmony_ci				struct ath9k_cal_list *currCal);
11962306a36Sopenharmony_cis16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan,
12062306a36Sopenharmony_ci			   s16 nf);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#endif /* CALIB_H */
124