ath9k: Use calibrated noise floor value when available

AR9003 series allows to calibrate noise floor for different frequency
bins. Once it's done it's possible to get more accurate rssi/signal
values over whole frequency band at a given temperature.
The RSSI/signal accuracy reported by calibrated RF cards improves
from 6 to up to 2dB.

This could be interesting for application which require good signal
accuracy like roaming or mesh protocols.

Signed-off-by: Wojciech Dubowik <Wojciech.Dubowik@neratec.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
This commit is contained in:
Wojciech Dubowik 2018-01-24 09:02:18 +01:00 коммит произвёл Kalle Valo
Родитель 34d4fcd881
Коммит 8da58553cc
1 изменённых файлов: 24 добавлений и 14 удалений

Просмотреть файл

@ -58,19 +58,25 @@ static struct ath_nf_limits *ath9k_hw_get_nf_limits(struct ath_hw *ah,
} }
static s16 ath9k_hw_get_default_nf(struct ath_hw *ah, static s16 ath9k_hw_get_default_nf(struct ath_hw *ah,
struct ath9k_channel *chan) struct ath9k_channel *chan,
int chain)
{ {
return ath9k_hw_get_nf_limits(ah, chan)->nominal; s16 calib_nf = ath9k_hw_get_nf_limits(ah, chan)->cal[chain];
if (calib_nf)
return calib_nf;
else
return ath9k_hw_get_nf_limits(ah, chan)->nominal;
} }
s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan, s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan,
s16 nf) s16 nf)
{ {
s8 noise = ATH_DEFAULT_NOISE_FLOOR; s8 noise = ath9k_hw_get_default_nf(ah, chan, 0);
if (nf) { if (nf) {
s8 delta = nf - ATH9K_NF_CAL_NOISE_THRESH - s8 delta = nf - ATH9K_NF_CAL_NOISE_THRESH -
ath9k_hw_get_default_nf(ah, chan); ath9k_hw_get_default_nf(ah, chan, 0);
if (delta > 0) if (delta > 0)
noise += delta; noise += delta;
} }
@ -240,7 +246,7 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
unsigned i, j; unsigned i, j;
u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask; u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
struct ath_common *common = ath9k_hw_common(ah); struct ath_common *common = ath9k_hw_common(ah);
s16 default_nf = ath9k_hw_get_default_nf(ah, chan); s16 default_nf = ath9k_hw_get_nf_limits(ah, chan)->nominal;
u32 bb_agc_ctl = REG_READ(ah, AR_PHY_AGC_CONTROL); u32 bb_agc_ctl = REG_READ(ah, AR_PHY_AGC_CONTROL);
if (ah->caldata) if (ah->caldata)
@ -258,8 +264,13 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
nfval = ah->nf_override; nfval = ah->nf_override;
else if (h) else if (h)
nfval = h[i].privNF; nfval = h[i].privNF;
else else {
nfval = default_nf; /* Try to get calibrated noise floor value */
nfval =
ath9k_hw_get_nf_limits(ah, chan)->cal[i];
if (nfval > -60 || nfval < -127)
nfval = default_nf;
}
REG_RMW(ah, ah->nf_regs[i], REG_RMW(ah, ah->nf_regs[i],
(((u32) nfval << 1) & 0x1ff), 0x1ff); (((u32) nfval << 1) & 0x1ff), 0x1ff);
@ -429,20 +440,19 @@ void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
struct ath9k_channel *chan) struct ath9k_channel *chan)
{ {
struct ath9k_nfcal_hist *h; struct ath9k_nfcal_hist *h;
s16 default_nf; int i, j, k = 0;
int i, j;
ah->caldata->channel = chan->channel; ah->caldata->channel = chan->channel;
ah->caldata->channelFlags = chan->channelFlags; ah->caldata->channelFlags = chan->channelFlags;
h = ah->caldata->nfCalHist; h = ah->caldata->nfCalHist;
default_nf = ath9k_hw_get_default_nf(ah, chan);
for (i = 0; i < NUM_NF_READINGS; i++) { for (i = 0; i < NUM_NF_READINGS; i++) {
h[i].currIndex = 0; h[i].currIndex = 0;
h[i].privNF = default_nf; h[i].privNF = ath9k_hw_get_default_nf(ah, chan, k);
h[i].invalidNFcount = AR_PHY_CCA_FILTERWINDOW_LENGTH; h[i].invalidNFcount = AR_PHY_CCA_FILTERWINDOW_LENGTH;
for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) { for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++)
h[i].nfCalBuffer[j] = default_nf; h[i].nfCalBuffer[j] = h[i].privNF;
} if (++k >= AR5416_MAX_CHAINS)
k = 0;
} }
} }