Path: blob/main/sys/dev/ath/ath_hal/ar5416/ar5416_cal.h
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2008 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#ifndef _ATH_AR5416_CAL_H_19#define _ATH_AR5416_CAL_H_2021typedef enum {22ADC_DC_INIT_CAL = 0x1,23ADC_GAIN_CAL = 0x2,24ADC_DC_CAL = 0x4,25IQ_MISMATCH_CAL = 0x826} HAL_CAL_TYPE;2728/* Calibrate state */29typedef enum {30CAL_INACTIVE,31CAL_WAITING,32CAL_RUNNING,33CAL_DONE34} HAL_CAL_STATE;3536typedef union {37uint32_t u;38int32_t s;39} HAL_CAL_SAMPLE;4041#define MIN_CAL_SAMPLES 142#define MAX_CAL_SAMPLES 6443#define INIT_LOG_COUNT 544#define PER_MIN_LOG_COUNT 245#define PER_MAX_LOG_COUNT 104647/* Per Calibration data structure */48typedef struct per_cal_data {49const char *calName; /* for diagnostics */50HAL_CAL_TYPE calType; /* Type of calibration */51uint32_t calNumSamples; /* # SW samples to collect */52uint32_t calCountMax; /* # HW samples to collect */53void (*calCollect)(struct ath_hal *); /* Accumulator function */54/* Post-processing function */55void (*calPostProc)(struct ath_hal *, uint8_t);56} HAL_PERCAL_DATA;5758/* List structure for calibration data */59typedef struct cal_list {60struct cal_list *calNext;61HAL_CAL_STATE calState;62const HAL_PERCAL_DATA *calData;63} HAL_CAL_LIST;6465struct ar5416PerCal {66/*67* Periodic calibration state.68*/69HAL_CAL_TYPE suppCals;70HAL_CAL_LIST iqCalData;71HAL_CAL_LIST adcGainCalData;72HAL_CAL_LIST adcDcCalInitData;73HAL_CAL_LIST adcDcCalData;74HAL_CAL_LIST *cal_list;75HAL_CAL_LIST *cal_last;76HAL_CAL_LIST *cal_curr;77#define AR5416_MAX_CHAINS 3 /* XXX dup's eeprom def */78HAL_CAL_SAMPLE caldata[4][AR5416_MAX_CHAINS];79int calSamples;80/*81* Noise floor cal histogram support.82* XXX be nice to re-use space in ar521283*/84#define AR5416_NUM_NF_READINGS 6 /* (3 chains * (ctl + ext) */85struct ar5212NfCalHist nfCalHist[AR5416_NUM_NF_READINGS];86};8788#define INIT_CAL(_perCal) do { \89(_perCal)->calState = CAL_WAITING; \90(_perCal)->calNext = AH_NULL; \91} while (0)9293#define INSERT_CAL(_cal, _perCal) do { \94if ((_cal)->cal_last == AH_NULL) { \95(_cal)->cal_list = (_cal)->cal_last = (_perCal); \96((_cal)->cal_last)->calNext = (_perCal); \97} else { \98((_cal)->cal_last)->calNext = (_perCal); \99(_cal)->cal_last = (_perCal); \100(_perCal)->calNext = (_cal)->cal_list; \101} \102} while (0)103104HAL_BOOL ar5416InitCalHardware(struct ath_hal *ah, const struct ieee80211_channel *chan);105HAL_BOOL ar5416InitCal(struct ath_hal *, const struct ieee80211_channel *);106HAL_BOOL ar5416PerCalibration(struct ath_hal *, struct ieee80211_channel *,107HAL_BOOL *isIQdone);108HAL_BOOL ar5416PerCalibrationN(struct ath_hal *, struct ieee80211_channel *,109u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone);110HAL_BOOL ar5416ResetCalValid(struct ath_hal *,111const struct ieee80211_channel *);112113void 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_ */121122123