18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2008-2011 Atheros Communications Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef CALIB_H 188c2ecf20Sopenharmony_ci#define CALIB_H 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include "hw.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define AR_PHY_CCA_FILTERWINDOW_LENGTH 5 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Internal noise floor can vary by about 6db depending on the frequency */ 258c2ecf20Sopenharmony_ci#define ATH9K_NF_CAL_NOISE_THRESH 6 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define NUM_NF_READINGS 6 288c2ecf20Sopenharmony_ci#define ATH9K_NF_CAL_HIST_MAX 5 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct ar5416IniArray { 318c2ecf20Sopenharmony_ci u32 *ia_array; 328c2ecf20Sopenharmony_ci u32 ia_rows; 338c2ecf20Sopenharmony_ci u32 ia_columns; 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define STATIC_INI_ARRAY(array) { \ 378c2ecf20Sopenharmony_ci .ia_array = (u32 *)(array), \ 388c2ecf20Sopenharmony_ci .ia_rows = ARRAY_SIZE(array), \ 398c2ecf20Sopenharmony_ci .ia_columns = ARRAY_SIZE(array[0]), \ 408c2ecf20Sopenharmony_ci } 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define INIT_INI_ARRAY(iniarray, array) do { \ 438c2ecf20Sopenharmony_ci (iniarray)->ia_array = (u32 *)(array); \ 448c2ecf20Sopenharmony_ci (iniarray)->ia_rows = ARRAY_SIZE(array); \ 458c2ecf20Sopenharmony_ci (iniarray)->ia_columns = ARRAY_SIZE(array[0]); \ 468c2ecf20Sopenharmony_ci } while (0) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define INI_RA(iniarray, row, column) \ 498c2ecf20Sopenharmony_ci (((iniarray)->ia_array)[(row) * ((iniarray)->ia_columns) + (column)]) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define INIT_CAL(_perCal) do { \ 528c2ecf20Sopenharmony_ci (_perCal)->calState = CAL_WAITING; \ 538c2ecf20Sopenharmony_ci (_perCal)->calNext = NULL; \ 548c2ecf20Sopenharmony_ci } while (0) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define INSERT_CAL(_ahp, _perCal) \ 578c2ecf20Sopenharmony_ci do { \ 588c2ecf20Sopenharmony_ci if ((_ahp)->cal_list_last == NULL) { \ 598c2ecf20Sopenharmony_ci (_ahp)->cal_list = \ 608c2ecf20Sopenharmony_ci (_ahp)->cal_list_last = (_perCal); \ 618c2ecf20Sopenharmony_ci ((_ahp)->cal_list_last)->calNext = (_perCal); \ 628c2ecf20Sopenharmony_ci } else { \ 638c2ecf20Sopenharmony_ci ((_ahp)->cal_list_last)->calNext = (_perCal); \ 648c2ecf20Sopenharmony_ci (_ahp)->cal_list_last = (_perCal); \ 658c2ecf20Sopenharmony_ci (_perCal)->calNext = (_ahp)->cal_list; \ 668c2ecf20Sopenharmony_ci } \ 678c2ecf20Sopenharmony_ci } while (0) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cienum ath9k_cal_state { 708c2ecf20Sopenharmony_ci CAL_INACTIVE, 718c2ecf20Sopenharmony_ci CAL_WAITING, 728c2ecf20Sopenharmony_ci CAL_RUNNING, 738c2ecf20Sopenharmony_ci CAL_DONE 748c2ecf20Sopenharmony_ci}; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define MIN_CAL_SAMPLES 1 778c2ecf20Sopenharmony_ci#define MAX_CAL_SAMPLES 64 788c2ecf20Sopenharmony_ci#define INIT_LOG_COUNT 5 798c2ecf20Sopenharmony_ci#define PER_MIN_LOG_COUNT 2 808c2ecf20Sopenharmony_ci#define PER_MAX_LOG_COUNT 10 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistruct ath9k_percal_data { 838c2ecf20Sopenharmony_ci u32 calType; 848c2ecf20Sopenharmony_ci u32 calNumSamples; 858c2ecf20Sopenharmony_ci u32 calCountMax; 868c2ecf20Sopenharmony_ci void (*calCollect) (struct ath_hw *); 878c2ecf20Sopenharmony_ci void (*calPostProc) (struct ath_hw *, u8); 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistruct ath9k_cal_list { 918c2ecf20Sopenharmony_ci const struct ath9k_percal_data *calData; 928c2ecf20Sopenharmony_ci enum ath9k_cal_state calState; 938c2ecf20Sopenharmony_ci struct ath9k_cal_list *calNext; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistruct ath9k_nfcal_hist { 978c2ecf20Sopenharmony_ci int16_t nfCalBuffer[ATH9K_NF_CAL_HIST_MAX]; 988c2ecf20Sopenharmony_ci u8 currIndex; 998c2ecf20Sopenharmony_ci int16_t privNF; 1008c2ecf20Sopenharmony_ci u8 invalidNFcount; 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define MAX_PACAL_SKIPCOUNT 8 1048c2ecf20Sopenharmony_cistruct ath9k_pacal_info{ 1058c2ecf20Sopenharmony_ci int32_t prev_offset; /* Previous value of PA offset value */ 1068c2ecf20Sopenharmony_ci int8_t max_skipcount; /* Max No. of times PACAL can be skipped */ 1078c2ecf20Sopenharmony_ci int8_t skipcount; /* No. of times the PACAL to be skipped */ 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cibool ath9k_hw_reset_calvalid(struct ath_hw *ah); 1118c2ecf20Sopenharmony_civoid ath9k_hw_start_nfcal(struct ath_hw *ah, bool update); 1128c2ecf20Sopenharmony_ciint ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan); 1138c2ecf20Sopenharmony_cibool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan); 1148c2ecf20Sopenharmony_civoid ath9k_init_nfcal_hist_buffer(struct ath_hw *ah, 1158c2ecf20Sopenharmony_ci struct ath9k_channel *chan); 1168c2ecf20Sopenharmony_civoid ath9k_hw_bstuck_nfcal(struct ath_hw *ah); 1178c2ecf20Sopenharmony_civoid ath9k_hw_reset_calibration(struct ath_hw *ah, 1188c2ecf20Sopenharmony_ci struct ath9k_cal_list *currCal); 1198c2ecf20Sopenharmony_cis16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan, 1208c2ecf20Sopenharmony_ci s16 nf); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#endif /* CALIB_H */ 124