Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8da58553 authored by Wojciech Dubowik's avatar Wojciech Dubowik Committed by Kalle Valo
Browse files

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: default avatarWojciech Dubowik <Wojciech.Dubowik@neratec.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 34d4fcd8
Loading
Loading
Loading
Loading
+24 −14
Original line number Diff line number Diff line
@@ -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,
				   struct ath9k_channel *chan)
				   struct ath9k_channel *chan,
				   int chain)
{
	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 nf)
{
	s8 noise = ATH_DEFAULT_NOISE_FLOOR;
	s8 noise = ath9k_hw_get_default_nf(ah, chan, 0);

	if (nf) {
		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)
			noise += delta;
	}
@@ -240,7 +246,7 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
	unsigned i, j;
	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
	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);

	if (ah->caldata)
@@ -258,8 +264,13 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
				nfval = ah->nf_override;
			else if (h)
				nfval = h[i].privNF;
			else
			else {
				/* 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],
				(((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_nfcal_hist *h;
	s16 default_nf;
	int i, j;
	int i, j, k = 0;

	ah->caldata->channel = chan->channel;
	ah->caldata->channelFlags = chan->channelFlags;
	h = ah->caldata->nfCalHist;
	default_nf = ath9k_hw_get_default_nf(ah, chan);
	for (i = 0; i < NUM_NF_READINGS; i++) {
		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;
		for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
			h[i].nfCalBuffer[j] = default_nf;
		}
		for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++)
			h[i].nfCalBuffer[j] = h[i].privNF;
		if (++k >= AR5416_MAX_CHAINS)
			k = 0;
	}
}