diff mbox

ath9k_hw: Fix magnitude/phase average in TxIQ Calibration

Message ID 1315320602-2815-1-git-send-email-rmanohar@qca.qualcomm.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Manoharan, Rajkumar Sept. 6, 2011, 2:50 p.m. UTC
The commit "ath9k_hw: Fix Tx IQ Calibration hang issue in
AR9003 chips" did not consider more than one potential sample
while calculating magnitude/phase average if more than one
sample has the same value which could affect post-processing
of outlier detection that causes an undesirable Tx IQ
correction value will be assigned to tx gain settings where
outlier happens.

Cc: Kai Shi <kaishi@qca.qualcomm.com>
Reported-by: Paul Stewart <pstew@google.com>
Signed-off-by: Rajkumar Manoharan <rmanohar@qca.qualcomm.com>
---
 drivers/net/wireless/ath/ath9k/ar9003_calib.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

Comments

Paul Stewart Sept. 6, 2011, 3:43 p.m. UTC | #1
Hi Rajkumar,

On Tue, Sep 6, 2011 at 7:50 AM, Rajkumar Manoharan
<rmanohar@qca.qualcomm.com> wrote:
> The commit "ath9k_hw: Fix Tx IQ Calibration hang issue in
> AR9003 chips" did not consider more than one potential sample
> while calculating magnitude/phase average if more than one
> sample has the same value which could affect post-processing
> of outlier detection that causes an undesirable Tx IQ
> correction value will be assigned to tx gain settings where
> outlier happens.
>
[...]

> +       /*
> +        * finding mean magnitude/phase if possible, otherwise
> +        * just use the last value as the mean
> +        */
> +       if (mp_count)
> +               mp_avg /= mp_count;
> +       else
> +               mp_avg = mp_coeff[i - 1];

Why use "i - 1" here instead of "nmeasurement - 1"?  Seems more
error-prone for later changes and harder to understand.

--
Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index ee3a8a2..6ec3e6d 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -615,11 +615,10 @@  static void ar9003_hw_detect_outlier(int *mp_coeff, int nmeasurement,
 {
 	int mp_max = -64, max_idx = 0;
 	int mp_min = 63, min_idx = 0;
-	int mp_avg = 0, i, outlier_idx = 0;
+	int mp_avg = 0, i, outlier_idx = 0, mp_count = 0;
 
 	/* find min/max mismatch across all calibrated gains */
 	for (i = 0; i < nmeasurement; i++) {
-		mp_avg += mp_coeff[i];
 		if (mp_coeff[i] > mp_max) {
 			mp_max = mp_coeff[i];
 			max_idx = i;
@@ -632,10 +631,20 @@  static void ar9003_hw_detect_outlier(int *mp_coeff, int nmeasurement,
 	/* find average (exclude max abs value) */
 	for (i = 0; i < nmeasurement; i++) {
 		if ((abs(mp_coeff[i]) < abs(mp_max)) ||
-		    (abs(mp_coeff[i]) < abs(mp_min)))
+		    (abs(mp_coeff[i]) < abs(mp_min))) {
 			mp_avg += mp_coeff[i];
+			mp_count++;
+		}
 	}
-	mp_avg /= (nmeasurement - 1);
+
+	/*
+	 * finding mean magnitude/phase if possible, otherwise
+	 * just use the last value as the mean
+	 */
+	if (mp_count)
+		mp_avg /= mp_count;
+	else
+		mp_avg = mp_coeff[i - 1];
 
 	/* detect outlier */
 	if (abs(mp_max - mp_min) > max_delta) {