diff mbox

ath5k: Fix 64 bits TSF reading.

Message ID 1267394932-11038-1-git-send-email-benoit.papillault@free.fr (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Benoit PAPILLAULT Feb. 28, 2010, 10:08 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/net/wireless/ath/ath5k/pcu.c b/drivers/net/wireless/ath/ath5k/pcu.c
index aefe84f..4b24c15 100644
--- a/drivers/net/wireless/ath/ath5k/pcu.c
+++ b/drivers/net/wireless/ath/ath5k/pcu.c
@@ -593,10 +593,27 @@  u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
  */
 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
 {
-	u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
+	u32 tsf_lower, tsf_upper;
+
+	/*
+	 * While reading TSF upper and then lower part, the clock is still
+	 * counting so the lower part can rollover just after reading the
+	 * upper part. In this case, we expect the lower part to be quite
+	 * small (let's say less than 100us) and we would just need to read
+	 * the upper part again to get the correct value.
+	 *
+	 * Tested on AR2425 (AR5001)
+	 */
+
+	tsf_upper = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
+	tsf_lower = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
+
+	if (tsf_lower < 100)
+		tsf_upper = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
+
 	ATH5K_TRACE(ah->ah_sc);
 
-	return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
+	return (((u64)tsf_upper << 32) | tsf_lower);
 }
 
 /**