Skip to contentSkip to conversation

m68knommu: fix ColdFire slice timer to handle clock counter wrapping

PATCH New [email protected] 1 participant 1 message Nov 18, 2011 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 m68knommu: fix ColdFire slice timer to handle clock counter wrapping

From: Greg Ungerer <[email protected]>

The read function for the ColdFire slice timer doesn't deal with the hardware timer count register wrapping while we are reading it to get an accurate snapshot of the time.

Re-read the timer a second time and see if it has wrapped, adjust the total count as required.

---
 arch/m68k/platform/coldfire/sltimers.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/m68k/platform/coldfire/sltimers.c +4 -3
index b7f822b..1249367 100644
@@ -98,16 +98,17 @@ static struct irqaction mcfslt_timer_irq = {
 static cycle_t mcfslt_read_clk(struct clocksource *cs)
 {
 	unsigned long flags;
-	u32 cycles;
-	u16 scnt;
+	u32 cycles, scnt;
 
 	local_irq_save(flags);
 	scnt = __raw_readl(TA(MCFSLT_SCNT));
 	cycles = mcfslt_cnt;
+	if (scnt < __raw_readl(TA(MCFSLT_SCNT)))
+		cycles += mcfslt_cycles_per_jiffy;
 	local_irq_restore(flags);
 
 	/* subtract because slice timers count down */
-	return cycles - scnt;
+	return cycles + ((mcfslt_cycles_per_jiffy - 1) - scnt);
 }
 
 static struct clocksource mcfslt_clk = {
Signature · 1 line
1.7.0.4