xref: /freebsd/sys/dev/ath/ath_hal/ar5416/ar5416_cal.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1*6e778a7eSPedro F. Giffuni /*-
2*6e778a7eSPedro F. Giffuni  * SPDX-License-Identifier: ISC
3*6e778a7eSPedro F. Giffuni  *
459efa8b5SSam Leffler  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
514779705SSam Leffler  * Copyright (c) 2002-2008 Atheros Communications, Inc.
614779705SSam Leffler  *
714779705SSam Leffler  * Permission to use, copy, modify, and/or distribute this software for any
814779705SSam Leffler  * purpose with or without fee is hereby granted, provided that the above
914779705SSam Leffler  * copyright notice and this permission notice appear in all copies.
1014779705SSam Leffler  *
1114779705SSam Leffler  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1214779705SSam Leffler  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1314779705SSam Leffler  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1414779705SSam Leffler  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1514779705SSam Leffler  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1614779705SSam Leffler  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1714779705SSam Leffler  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1814779705SSam Leffler  */
1914779705SSam Leffler #ifndef _ATH_AR5416_CAL_H_
2014779705SSam Leffler #define _ATH_AR5416_CAL_H_
2114779705SSam Leffler 
2214779705SSam Leffler typedef enum {
2314779705SSam Leffler 	ADC_DC_INIT_CAL	= 0x1,
2414779705SSam Leffler 	ADC_GAIN_CAL	= 0x2,
2514779705SSam Leffler 	ADC_DC_CAL	= 0x4,
2614779705SSam Leffler 	IQ_MISMATCH_CAL	= 0x8
2714779705SSam Leffler } HAL_CAL_TYPE;
2814779705SSam Leffler 
2914779705SSam Leffler /* Calibrate state */
3014779705SSam Leffler typedef enum {
3114779705SSam Leffler 	CAL_INACTIVE,
3214779705SSam Leffler 	CAL_WAITING,
3314779705SSam Leffler 	CAL_RUNNING,
3414779705SSam Leffler 	CAL_DONE
3514779705SSam Leffler } HAL_CAL_STATE;
3614779705SSam Leffler 
3714779705SSam Leffler typedef union {
3814779705SSam Leffler 	uint32_t	u;
3914779705SSam Leffler 	int32_t		s;
4014779705SSam Leffler } HAL_CAL_SAMPLE;
4114779705SSam Leffler 
4214779705SSam Leffler #define	MIN_CAL_SAMPLES     1
4314779705SSam Leffler #define	MAX_CAL_SAMPLES    64
4414779705SSam Leffler #define	INIT_LOG_COUNT      5
4514779705SSam Leffler #define	PER_MIN_LOG_COUNT   2
4614779705SSam Leffler #define	PER_MAX_LOG_COUNT  10
4714779705SSam Leffler 
4814779705SSam Leffler /* Per Calibration data structure */
4914779705SSam Leffler typedef struct per_cal_data {
5014779705SSam Leffler 	const char	*calName;		/* for diagnostics */
5114779705SSam Leffler 	HAL_CAL_TYPE	calType;		/* Type of calibration */
5214779705SSam Leffler 	uint32_t	calNumSamples;		/* # SW samples to collect */
5314779705SSam Leffler 	uint32_t	calCountMax;		/* # HW samples to collect */
5414779705SSam Leffler 	void (*calCollect)(struct ath_hal *);	/* Accumulator function */
5514779705SSam Leffler 						/* Post-processing function */
5614779705SSam Leffler 	void (*calPostProc)(struct ath_hal *, uint8_t);
5714779705SSam Leffler } HAL_PERCAL_DATA;
5814779705SSam Leffler 
5914779705SSam Leffler /* List structure for calibration data */
6014779705SSam Leffler typedef struct cal_list {
6114779705SSam Leffler 	struct cal_list		*calNext;
6214779705SSam Leffler 	HAL_CAL_STATE		calState;
6314779705SSam Leffler 	const HAL_PERCAL_DATA	*calData;
6414779705SSam Leffler } HAL_CAL_LIST;
6514779705SSam Leffler 
6614779705SSam Leffler struct ar5416PerCal {
6714779705SSam Leffler 	/*
6814779705SSam Leffler 	 * Periodic calibration state.
6914779705SSam Leffler 	 */
7014779705SSam Leffler 	HAL_CAL_TYPE	suppCals;
7114779705SSam Leffler 	HAL_CAL_LIST	iqCalData;
7214779705SSam Leffler 	HAL_CAL_LIST	adcGainCalData;
7314779705SSam Leffler 	HAL_CAL_LIST	adcDcCalInitData;
7414779705SSam Leffler 	HAL_CAL_LIST	adcDcCalData;
7514779705SSam Leffler 	HAL_CAL_LIST	*cal_list;
7614779705SSam Leffler 	HAL_CAL_LIST	*cal_last;
7714779705SSam Leffler 	HAL_CAL_LIST	*cal_curr;
7814779705SSam Leffler #define AR5416_MAX_CHAINS            	3	/* XXX dup's eeprom def */
7914779705SSam Leffler 	HAL_CAL_SAMPLE	caldata[4][AR5416_MAX_CHAINS];
8014779705SSam Leffler 	int		calSamples;
8114779705SSam Leffler 	/*
8214779705SSam Leffler 	 * Noise floor cal histogram support.
8314779705SSam Leffler 	 * XXX be nice to re-use space in ar5212
8414779705SSam Leffler 	 */
8514779705SSam Leffler #define	AR5416_NUM_NF_READINGS		6	/* (3 chains * (ctl + ext) */
8614779705SSam Leffler 	struct ar5212NfCalHist nfCalHist[AR5416_NUM_NF_READINGS];
8714779705SSam Leffler };
8814779705SSam Leffler 
8914779705SSam Leffler #define INIT_CAL(_perCal) do {						\
9014779705SSam Leffler 	(_perCal)->calState = CAL_WAITING;				\
9114779705SSam Leffler 	(_perCal)->calNext = AH_NULL;					\
9214779705SSam Leffler } while (0)
9314779705SSam Leffler 
9414779705SSam Leffler #define INSERT_CAL(_cal, _perCal) do {					\
9514779705SSam Leffler 	if ((_cal)->cal_last == AH_NULL) {				\
9614779705SSam Leffler 		(_cal)->cal_list = (_cal)->cal_last = (_perCal);	\
9714779705SSam Leffler 		((_cal)->cal_last)->calNext = (_perCal);		\
9814779705SSam Leffler 	} else {							\
9914779705SSam Leffler 		((_cal)->cal_last)->calNext = (_perCal);		\
10014779705SSam Leffler 		(_cal)->cal_last = (_perCal);				\
10114779705SSam Leffler 		(_perCal)->calNext = (_cal)->cal_list;			\
10214779705SSam Leffler 	}								\
10314779705SSam Leffler } while (0)
10414779705SSam Leffler 
105c0b9002dSAdrian Chadd HAL_BOOL	ar5416InitCalHardware(struct ath_hal *ah, const struct ieee80211_channel *chan);
10659efa8b5SSam Leffler HAL_BOOL ar5416InitCal(struct ath_hal *, const struct ieee80211_channel *);
10759efa8b5SSam Leffler HAL_BOOL ar5416PerCalibration(struct ath_hal *,  struct ieee80211_channel *,
10814779705SSam Leffler 	    HAL_BOOL *isIQdone);
10959efa8b5SSam Leffler HAL_BOOL ar5416PerCalibrationN(struct ath_hal *, struct ieee80211_channel *,
11014779705SSam Leffler 	    u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone);
11159efa8b5SSam Leffler HAL_BOOL ar5416ResetCalValid(struct ath_hal *,
11259efa8b5SSam Leffler 	    const struct ieee80211_channel *);
11314779705SSam Leffler 
11414779705SSam Leffler void	ar5416IQCalCollect(struct ath_hal *ah);
11514779705SSam Leffler void	ar5416IQCalibration(struct ath_hal *ah, uint8_t numChains);
11614779705SSam Leffler void	ar5416AdcGainCalCollect(struct ath_hal *ah);
11714779705SSam Leffler void	ar5416AdcGainCalibration(struct ath_hal *ah, uint8_t numChains);
11814779705SSam Leffler void	ar5416AdcDcCalCollect(struct ath_hal *ah);
11914779705SSam Leffler void	ar5416AdcDcCalibration(struct ath_hal *ah, uint8_t numChains);
12012fefae2SRui Paulo void	ar5416InitNfHistBuff(struct ar5212NfCalHist *h);
12114779705SSam Leffler #endif /* _ATH_AR5416_CAL_H_ */
122