ar5416_cal.h revision 203882
1181155Sdas/* 2181155Sdas * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3181155Sdas * Copyright (c) 2002-2008 Atheros Communications, Inc. 4181155Sdas * 5181155Sdas * Permission to use, copy, modify, and/or distribute this software for any 6181155Sdas * purpose with or without fee is hereby granted, provided that the above 7181155Sdas * copyright notice and this permission notice appear in all copies. 8181155Sdas * 9181155Sdas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10181155Sdas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11181155Sdas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12181155Sdas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13181155Sdas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14181155Sdas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15181155Sdas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16181155Sdas * 17181155Sdas * $FreeBSD: head/sys/dev/ath/ath_hal/ar5416/ar5416_cal.h 203882 2010-02-14 16:26:32Z rpaulo $ 18181155Sdas */ 19181155Sdas#ifndef _ATH_AR5416_CAL_H_ 20181155Sdas#define _ATH_AR5416_CAL_H_ 21181155Sdas 22181155Sdastypedef enum { 23181155Sdas ADC_DC_INIT_CAL = 0x1, 24181155Sdas ADC_GAIN_CAL = 0x2, 25181155Sdas ADC_DC_CAL = 0x4, 26181155Sdas IQ_MISMATCH_CAL = 0x8 27181155Sdas} HAL_CAL_TYPE; 28181155Sdas 29181155Sdas/* Calibrate state */ 30181155Sdastypedef enum { 31181155Sdas CAL_INACTIVE, 32181155Sdas CAL_WAITING, 33181155Sdas CAL_RUNNING, 34181155Sdas CAL_DONE 35181155Sdas} HAL_CAL_STATE; 36181155Sdas 37181155Sdastypedef union { 38181155Sdas uint32_t u; 39181155Sdas int32_t s; 40181155Sdas} HAL_CAL_SAMPLE; 41181155Sdas 42181155Sdas#define MIN_CAL_SAMPLES 1 43181155Sdas#define MAX_CAL_SAMPLES 64 44181155Sdas#define INIT_LOG_COUNT 5 45181155Sdas#define PER_MIN_LOG_COUNT 2 46181155Sdas#define PER_MAX_LOG_COUNT 10 47181155Sdas 48181155Sdas/* Per Calibration data structure */ 49181155Sdastypedef struct per_cal_data { 50181155Sdas const char *calName; /* for diagnostics */ 51181155Sdas HAL_CAL_TYPE calType; /* Type of calibration */ 52181155Sdas uint32_t calNumSamples; /* # SW samples to collect */ 53181155Sdas uint32_t calCountMax; /* # HW samples to collect */ 54181155Sdas void (*calCollect)(struct ath_hal *); /* Accumulator function */ 55181155Sdas /* Post-processing function */ 56181155Sdas void (*calPostProc)(struct ath_hal *, uint8_t); 57181155Sdas} HAL_PERCAL_DATA; 58181155Sdas 59181155Sdas/* List structure for calibration data */ 60181155Sdastypedef struct cal_list { 61181155Sdas struct cal_list *calNext; 62181155Sdas HAL_CAL_STATE calState; 63181155Sdas const HAL_PERCAL_DATA *calData; 64181155Sdas} HAL_CAL_LIST; 65181155Sdas 66181155Sdasstruct ar5416PerCal { 67181155Sdas /* 68181155Sdas * Periodic calibration state. 69181155Sdas */ 70181155Sdas HAL_CAL_TYPE suppCals; 71181155Sdas HAL_CAL_LIST iqCalData; 72181155Sdas HAL_CAL_LIST adcGainCalData; 73181155Sdas HAL_CAL_LIST adcDcCalInitData; 74181155Sdas HAL_CAL_LIST adcDcCalData; 75181155Sdas HAL_CAL_LIST *cal_list; 76181155Sdas HAL_CAL_LIST *cal_last; 77181155Sdas HAL_CAL_LIST *cal_curr; 78181155Sdas#define AR5416_MAX_CHAINS 3 /* XXX dup's eeprom def */ 79181155Sdas HAL_CAL_SAMPLE caldata[4][AR5416_MAX_CHAINS]; 80181155Sdas int calSamples; 81181155Sdas /* 82181155Sdas * Noise floor cal histogram support. 83181155Sdas * XXX be nice to re-use space in ar5212 84181155Sdas */ 85181155Sdas#define AR5416_NUM_NF_READINGS 6 /* (3 chains * (ctl + ext) */ 86181155Sdas struct ar5212NfCalHist nfCalHist[AR5416_NUM_NF_READINGS]; 87181155Sdas}; 88181155Sdas 89181155Sdas#define INIT_CAL(_perCal) do { \ 90181155Sdas (_perCal)->calState = CAL_WAITING; \ 91181155Sdas (_perCal)->calNext = AH_NULL; \ 92181155Sdas} while (0) 93181155Sdas 94181155Sdas#define INSERT_CAL(_cal, _perCal) do { \ 95181155Sdas if ((_cal)->cal_last == AH_NULL) { \ 96181155Sdas (_cal)->cal_list = (_cal)->cal_last = (_perCal); \ 97181155Sdas ((_cal)->cal_last)->calNext = (_perCal); \ 98181155Sdas } else { \ 99181155Sdas ((_cal)->cal_last)->calNext = (_perCal); \ 100181155Sdas (_cal)->cal_last = (_perCal); \ 101181155Sdas (_perCal)->calNext = (_cal)->cal_list; \ 102181155Sdas } \ 103} while (0) 104 105HAL_BOOL ar5416InitCal(struct ath_hal *, const struct ieee80211_channel *); 106HAL_BOOL ar5416PerCalibration(struct ath_hal *, struct ieee80211_channel *, 107 HAL_BOOL *isIQdone); 108HAL_BOOL ar5416PerCalibrationN(struct ath_hal *, struct ieee80211_channel *, 109 u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone); 110HAL_BOOL ar5416ResetCalValid(struct ath_hal *, 111 const struct ieee80211_channel *); 112 113void ar5416IQCalCollect(struct ath_hal *ah); 114void ar5416IQCalibration(struct ath_hal *ah, uint8_t numChains); 115void ar5416AdcGainCalCollect(struct ath_hal *ah); 116void ar5416AdcGainCalibration(struct ath_hal *ah, uint8_t numChains); 117void ar5416AdcDcCalCollect(struct ath_hal *ah); 118void ar5416AdcDcCalibration(struct ath_hal *ah, uint8_t numChains); 119void ar5416InitNfHistBuff(struct ar5212NfCalHist *h); 120#endif /* _ATH_AR5416_CAL_H_ */ 121