19 #include <linux/export.h>
31 sort[i] = nfCalBuffer[i];
33 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
34 for (j = 1; j < ATH9K_NF_CAL_HIST_MAX -
i; j++) {
35 if (sort[j] > sort[j - 1]) {
37 sort[
j] = sort[j - 1];
42 nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
60 static s16 ath9k_hw_get_default_nf(
struct ath_hw *ah,
63 return ath9k_hw_get_nf_limits(ah, chan)->nominal;
72 ath9k_hw_get_default_nf(ah, chan);
80 static void ath9k_hw_update_nfcal_hist_buffer(
struct ath_hw *ah,
87 bool high_nf_mid =
false;
92 limit = ath9k_hw_get_nf_limits(ah, ah->
curchan);
95 if (!(chainmask & (1 << i)) ||
101 if (++h[i].
currIndex >= ATH9K_NF_CAL_HIST_MAX)
109 ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
115 if (h[i].privNF > limit->
max) {
119 "NFmid[%d] (%d) > MAX (%d), %s\n",
120 i, h[i].privNF, limit->
max,
122 "not corrected (due to interference)" :
123 "correcting to MAX"));
146 static bool ath9k_hw_get_nf_thresh(
struct ath_hw *ah,
170 ath9k_hw_setup_calibration(ah, currCal);
187 struct ath_common *common = ath9k_hw_common(ah);
201 ath_dbg(common, CALIBRATE,
"Calibration state incorrect, %d\n",
209 ath_dbg(common, CALIBRATE,
"Resetting Cal %d state for channel %u\n",
222 ah->
caldata->nfcal_pending =
true;
243 struct ath_common *common = ath9k_hw_common(ah);
245 s16 default_nf = ath9k_hw_get_default_nf(ah, chan);
251 if (chainmask & (1 << i)) {
264 val |= (((
u32) nfval << 1) & 0x1ff);
285 for (j = 0; j < 10000; j++) {
303 "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n",
315 if (chainmask & (1 << i)) {
321 val |= (((
u32) (-50) << 1) & 0x1ff);
329 static void ath9k_hw_nf_sanitize(
struct ath_hw *ah,
s16 *nf)
331 struct ath_common *common = ath9k_hw_common(ah);
345 "NF calibrated [%s] [chain %d] is %d\n",
346 (i >= 3 ?
"ext" :
"ctl"), i % 3, nf[i]);
348 if (nf[i] > limit->
max) {
350 "NF[%d] (%d) > MAX (%d), correcting to MAX\n",
351 i, nf[i], limit->
max);
353 }
else if (nf[i] < limit->
min) {
355 "NF[%d] (%d) < MIN (%d), correcting to NOM\n",
356 i, nf[i], limit->
min);
364 struct ath_common *common = ath9k_hw_common(ah);
374 "NF did not complete in calibration window\n");
378 ath9k_hw_do_getnf(ah, nfarray);
379 ath9k_hw_nf_sanitize(ah, nfarray);
381 if (ath9k_hw_get_nf_thresh(ah, c->
band, &nfThresh)
384 "noise floor failed detected; detected %d, threshold %d\n",
397 ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray);
414 default_nf = ath9k_hw_get_default_nf(ah, chan);