From 6d2e7fc8a6faf78ec37f9cb4a77f7f571599ff38 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Patra S Date: Fri, 4 Nov 2016 21:10:37 +0530 Subject: [PATCH] qca: ipq806x: Fixed timer driver The logic used to calculate tick count in _udelay() was always giving Zero. Updated the logic to make it work across QCA boards. Change-Id: Iebc5905003ad99e66b299de3beabb80ce40ce710 Signed-off-by: Aditya Kumar Patra S --- arch/arm/cpu/armv7/qca/common/timer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm/cpu/armv7/qca/common/timer.c b/arch/arm/cpu/armv7/qca/common/timer.c index 2301a81e2e..3aa1d5812f 100644 --- a/arch/arm/cpu/armv7/qca/common/timer.c +++ b/arch/arm/cpu/armv7/qca/common/timer.c @@ -137,12 +137,18 @@ void __udelay(unsigned long usec) unsigned long long last; unsigned long long runcount; - val = (usec * GPT_FREQ); + if (usec == 0) + return; + + val = (usec * GPT_FREQ_KHZ) / 1000; + if (val == 0 ) + val = 1; /* Wait for atleast 1 tick */ + last = read_counter(); do { now = read_counter(); if (last > now) - runcount = (GPT_FREQ - last) + now; + runcount = (TIMER_LOAD_VAL - last) + now; else runcount = now - last; } while (runcount < val); @@ -177,7 +183,7 @@ ulong get_timer_masked(void) /* move stamp forward with absolute diff ticks */ } else { /* we have overflow of the count down timer */ - timestamp += now + (TIMER_LOAD_VAL - lastinc); + timestamp += now + (gpt_to_sys_freq(TIMER_LOAD_VAL) - lastinc); } lastinc = now;