aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless
diff options
context:
space:
mode:
authorGábor Stefanik <netrolller.3d@gmail.com>2009-08-26 14:51:24 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-08-28 14:40:52 -0400
commitd8fa338ee01e7de029d2441a8c2b9c5fbfeac82f (patch)
treef744f9136f9f58136f03cd6e792d46a510474956 /drivers/net/wireless
parentca9152e37f57259ca92486ca5753af16fd9155c6 (diff)
b43: LP-PHY: Fix and simplify Qdiv roundup
The Qdiv roundup routine is essentially a fixed-point division algorithm, using only integer math. However, the version in the specs had a major error that has been recently fixed (a missing quotient++). Replace Qdiv roundup with a rewritten, simplified version. Signed-off-by: Gábor Stefanik <netrolller.3d@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless')
-rw-r--r--drivers/net/wireless/b43/phy_lp.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
index 7e70c078475b..5306f2c66b34 100644
--- a/drivers/net/wireless/b43/phy_lp.c
+++ b/drivers/net/wireless/b43/phy_lp.c
@@ -1032,9 +1032,10 @@ static int lpphy_loopback(struct b43_wldev *dev)
1032 return index; 1032 return index;
1033} 1033}
1034 1034
1035/* Fixed-point division algorithm using only integer math. */
1035static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision) 1036static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
1036{ 1037{
1037 u32 quotient, remainder, rbit, roundup, tmp; 1038 u32 quotient, remainder;
1038 1039
1039 if (divisor == 0) 1040 if (divisor == 0)
1040 return 0; 1041 return 0;
@@ -1042,20 +1043,16 @@ static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
1042 quotient = dividend / divisor; 1043 quotient = dividend / divisor;
1043 remainder = dividend % divisor; 1044 remainder = dividend % divisor;
1044 1045
1045 rbit = divisor & 0x1; 1046 while (precision > 0) {
1046 roundup = (divisor >> 1) + rbit;
1047
1048 while (precision != 0) {
1049 tmp = remainder - roundup;
1050 quotient <<= 1; 1047 quotient <<= 1;
1051 if (remainder >= roundup) 1048 if (remainder << 1 >= divisor) {
1052 remainder = (tmp << 1) + rbit; 1049 quotient++;
1053 else 1050 remainder = (remainder << 1) - divisor;
1054 remainder <<= 1; 1051 }
1055 precision--; 1052 precision--;
1056 } 1053 }
1057 1054
1058 if (remainder >= roundup) 1055 if (remainder << 1 >= divisor)
1059 quotient++; 1056 quotient++;
1060 1057
1061 return quotient; 1058 return quotient;