From 989ae8601b28b053d4882ad70ce62420f19f9e91 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Sun, 10 Aug 2014 12:21:59 +0100 Subject: [PATCH] staging: vt6655: CARDqGetNextTBTT calculate qwTSF using do_div Use do_div to compute equation as shown replacing existing code. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman --- drivers/staging/vt6655/card.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c index 5295463cb2bd..a5da3d26c36f 100644 --- a/drivers/staging/vt6655/card.c +++ b/drivers/staging/vt6655/card.c @@ -1995,27 +1995,18 @@ bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF) */ u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval) { - unsigned int uLowNextTBTT; - unsigned int uHighRemain, uLowRemain; - unsigned int uBeaconInterval; + u32 beacon_int; - uBeaconInterval = wBeaconInterval * 1024; - // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval - uLowNextTBTT = ((qwTSF & 0xffffffffULL) >> 10) << 10; - // low dword (mod) bcn - uLowRemain = (uLowNextTBTT) % uBeaconInterval; - // high dword (mod) bcn - uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * (u32)(qwTSF >> 32)) - % uBeaconInterval; - uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; - uLowRemain = uBeaconInterval - uLowRemain; + beacon_int = wBeaconInterval * 1024; - // check if carry when add one beacon interval - if ((~uLowNextTBTT) < uLowRemain) - qwTSF = ((qwTSF >> 32) + 1) << 32; - - qwTSF = (qwTSF & 0xffffffff00000000ULL) | - (u64)(uLowNextTBTT + uLowRemain); + /* Next TBTT = + * ((local_current_TSF / beacon_interval) + 1) * beacon_interval + */ + if (beacon_int) { + do_div(qwTSF, beacon_int); + qwTSF += 1; + qwTSF *= beacon_int; + } return qwTSF; } -- 2.30.2