1185380Ssam/* 2187831Ssam * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3185380Ssam * Copyright (c) 2002-2008 Atheros Communications, Inc. 4185380Ssam * 5185380Ssam * Permission to use, copy, modify, and/or distribute this software for any 6185380Ssam * purpose with or without fee is hereby granted, provided that the above 7185380Ssam * copyright notice and this permission notice appear in all copies. 8185380Ssam * 9185380Ssam * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10185380Ssam * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11185380Ssam * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12185380Ssam * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13185380Ssam * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14185380Ssam * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15185380Ssam * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16185380Ssam * 17187831Ssam * $FreeBSD: releng/10.2/sys/dev/ath/ath_hal/ar5416/ar5416_cal.h 219480 2011-03-11 11:35:36Z adrian $ 18185380Ssam */ 19185380Ssam#ifndef _ATH_AR5416_CAL_H_ 20185380Ssam#define _ATH_AR5416_CAL_H_ 21185380Ssam 22185380Ssamtypedef enum { 23185380Ssam ADC_DC_INIT_CAL = 0x1, 24185380Ssam ADC_GAIN_CAL = 0x2, 25185380Ssam ADC_DC_CAL = 0x4, 26185380Ssam IQ_MISMATCH_CAL = 0x8 27185380Ssam} HAL_CAL_TYPE; 28185380Ssam 29185380Ssam/* Calibrate state */ 30185380Ssamtypedef enum { 31185380Ssam CAL_INACTIVE, 32185380Ssam CAL_WAITING, 33185380Ssam CAL_RUNNING, 34185380Ssam CAL_DONE 35185380Ssam} HAL_CAL_STATE; 36185380Ssam 37185380Ssamtypedef union { 38185380Ssam uint32_t u; 39185380Ssam int32_t s; 40185380Ssam} HAL_CAL_SAMPLE; 41185380Ssam 42185380Ssam#define MIN_CAL_SAMPLES 1 43185380Ssam#define MAX_CAL_SAMPLES 64 44185380Ssam#define INIT_LOG_COUNT 5 45185380Ssam#define PER_MIN_LOG_COUNT 2 46185380Ssam#define PER_MAX_LOG_COUNT 10 47185380Ssam 48185380Ssam/* Per Calibration data structure */ 49185380Ssamtypedef struct per_cal_data { 50185380Ssam const char *calName; /* for diagnostics */ 51185380Ssam HAL_CAL_TYPE calType; /* Type of calibration */ 52185380Ssam uint32_t calNumSamples; /* # SW samples to collect */ 53185380Ssam uint32_t calCountMax; /* # HW samples to collect */ 54185380Ssam void (*calCollect)(struct ath_hal *); /* Accumulator function */ 55185380Ssam /* Post-processing function */ 56185380Ssam void (*calPostProc)(struct ath_hal *, uint8_t); 57185380Ssam} HAL_PERCAL_DATA; 58185380Ssam 59185380Ssam/* List structure for calibration data */ 60185380Ssamtypedef struct cal_list { 61185380Ssam struct cal_list *calNext; 62185380Ssam HAL_CAL_STATE calState; 63185380Ssam const HAL_PERCAL_DATA *calData; 64185380Ssam} HAL_CAL_LIST; 65185380Ssam 66185380Ssamstruct ar5416PerCal { 67185380Ssam /* 68185380Ssam * Periodic calibration state. 69185380Ssam */ 70185380Ssam HAL_CAL_TYPE suppCals; 71185380Ssam HAL_CAL_LIST iqCalData; 72185380Ssam HAL_CAL_LIST adcGainCalData; 73185380Ssam HAL_CAL_LIST adcDcCalInitData; 74185380Ssam HAL_CAL_LIST adcDcCalData; 75185380Ssam HAL_CAL_LIST *cal_list; 76185380Ssam HAL_CAL_LIST *cal_last; 77185380Ssam HAL_CAL_LIST *cal_curr; 78185380Ssam#define AR5416_MAX_CHAINS 3 /* XXX dup's eeprom def */ 79185380Ssam HAL_CAL_SAMPLE caldata[4][AR5416_MAX_CHAINS]; 80185380Ssam int calSamples; 81185380Ssam /* 82185380Ssam * Noise floor cal histogram support. 83185380Ssam * XXX be nice to re-use space in ar5212 84185380Ssam */ 85185380Ssam#define AR5416_NUM_NF_READINGS 6 /* (3 chains * (ctl + ext) */ 86185380Ssam struct ar5212NfCalHist nfCalHist[AR5416_NUM_NF_READINGS]; 87185380Ssam}; 88185380Ssam 89185380Ssam#define INIT_CAL(_perCal) do { \ 90185380Ssam (_perCal)->calState = CAL_WAITING; \ 91185380Ssam (_perCal)->calNext = AH_NULL; \ 92185380Ssam} while (0) 93185380Ssam 94185380Ssam#define INSERT_CAL(_cal, _perCal) do { \ 95185380Ssam if ((_cal)->cal_last == AH_NULL) { \ 96185380Ssam (_cal)->cal_list = (_cal)->cal_last = (_perCal); \ 97185380Ssam ((_cal)->cal_last)->calNext = (_perCal); \ 98185380Ssam } else { \ 99185380Ssam ((_cal)->cal_last)->calNext = (_perCal); \ 100185380Ssam (_cal)->cal_last = (_perCal); \ 101185380Ssam (_perCal)->calNext = (_cal)->cal_list; \ 102185380Ssam } \ 103185380Ssam} while (0) 104185380Ssam 105219480SadrianHAL_BOOL ar5416InitCalHardware(struct ath_hal *ah, const struct ieee80211_channel *chan); 106187831SsamHAL_BOOL ar5416InitCal(struct ath_hal *, const struct ieee80211_channel *); 107187831SsamHAL_BOOL ar5416PerCalibration(struct ath_hal *, struct ieee80211_channel *, 108185380Ssam HAL_BOOL *isIQdone); 109187831SsamHAL_BOOL ar5416PerCalibrationN(struct ath_hal *, struct ieee80211_channel *, 110185380Ssam u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone); 111187831SsamHAL_BOOL ar5416ResetCalValid(struct ath_hal *, 112187831Ssam const struct ieee80211_channel *); 113185380Ssam 114185380Ssamvoid ar5416IQCalCollect(struct ath_hal *ah); 115185380Ssamvoid ar5416IQCalibration(struct ath_hal *ah, uint8_t numChains); 116185380Ssamvoid ar5416AdcGainCalCollect(struct ath_hal *ah); 117185380Ssamvoid ar5416AdcGainCalibration(struct ath_hal *ah, uint8_t numChains); 118185380Ssamvoid ar5416AdcDcCalCollect(struct ath_hal *ah); 119185380Ssamvoid ar5416AdcDcCalibration(struct ath_hal *ah, uint8_t numChains); 120203882Srpaulovoid ar5416InitNfHistBuff(struct ar5212NfCalHist *h); 121185380Ssam#endif /* _ATH_AR5416_CAL_H_ */ 122