summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/ath/ath9k/common-spectral.h
diff options
context:
space:
mode:
authorNick Kossifidis <mickflemm@gmail.com>2015-04-30 02:51:13 +0300
committerKalle Valo <kvalo@codeaurora.org>2015-05-09 16:46:10 +0300
commite33f855d436846f0e6034311bf9f52f32808d9a7 (patch)
treeec8eada5cefc408aeb484109cd5a3653f6c44b6a /drivers/net/wireless/ath/ath9k/common-spectral.h
parent04a81e183d506f8bcf919b9dbbb287d6723e989e (diff)
downloadlinux-e33f855d436846f0e6034311bf9f52f32808d9a7.tar.xz
ath9k: Fix hanlding of maximum magnitude index
Maximum magnitude index is a 5bit signed integer, convert to an 8bit signed integer and then "shift" it so that it can be used as an array index. Note that the current implementation adds +1 to the index value (so it can't be used as an array index) and it's only valid for HT20 channels. Note that the maximum magnitude index is not being used by the userspace tools that parse FFT samples (they just use maximum magnitude) so this doesn't break userspace compatibility. Signed-off-by: Nick Kossifidis <mickflemm@gmail.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/common-spectral.h')
-rw-r--r--drivers/net/wireless/ath/ath9k/common-spectral.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/drivers/net/wireless/ath/ath9k/common-spectral.h b/drivers/net/wireless/ath/ath9k/common-spectral.h
index 82d9dd29652c..072ff76c3581 100644
--- a/drivers/net/wireless/ath/ath9k/common-spectral.h
+++ b/drivers/net/wireless/ath/ath9k/common-spectral.h
@@ -111,17 +111,32 @@ static inline u16 spectral_max_magnitude(u8 *bins)
}
/* return the max magnitude from the all/upper/lower bins */
-static inline u8 spectral_max_index(u8 *bins)
+static inline u8 spectral_max_index(u8 *bins, int num_bins)
{
s8 m = (bins[2] & 0xfc) >> 2;
-
- /* TODO: this still doesn't always report the right values ... */
- if (m > 32)
+ u8 zero_idx = num_bins / 2;
+
+ /* It's a 5 bit signed int, remove its sign and use one's
+ * complement interpretation to add the sign back to the 8
+ * bit int
+ */
+ if (m & 0x20) {
+ m &= ~0x20;
m |= 0xe0;
- else
- m &= ~0xe0;
+ }
+
+ /* Bring the zero point to the beginning
+ * instead of the middle so that we can use
+ * it for array lookup and that we don't deal
+ * with negative values later
+ */
+ m += zero_idx;
+
+ /* Sanity check to make sure index is within bounds */
+ if (m < 0 || m > num_bins - 1)
+ m = 0;
- return m + 29;
+ return m;
}
/* return the bitmap weight from the all/upper/lower bins */