aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/linux/linux-2.6.24/ts72xx/ep93xx-timer-accuracy.diff
blob: 8254153b6949137a1956f9655479f120960ee898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
The ep93xx has a weird timer tick base (983.04 kHz.)  This experimental
patch tries to increase time of day accuracy by keeping the number of
ticks until the next jiffy in a fractional value representation.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>

Index: linux-2.6.22/arch/arm/mach-ep93xx/core.c
===================================================================
--- linux-2.6.22.orig/arch/arm/mach-ep93xx/core.c
+++ linux-2.6.22/arch/arm/mach-ep93xx/core.c
@@ -94,19 +94,32 @@ void __init ep93xx_map_io(void)
  * track of lost jiffies.
  */
 static unsigned int last_jiffy_time;
+static unsigned int next_jiffy_time;
+static unsigned int accumulator;
 
-#define TIMER4_TICKS_PER_JIFFY		((CLOCK_TICK_RATE + (HZ/2)) / HZ)
+#define TIMER4_TICKS_PER_JIFFY		(983040 / HZ)
+#define TIMER4_TICKS_MOD_JIFFY		(983040 % HZ)
+
+static int after_eq(unsigned long a, unsigned long b)
+{
+	return ((signed long)(a - b)) >= 0;
+}
 
 static int ep93xx_timer_interrupt(int irq, void *dev_id)
 {
 	write_seqlock(&xtime_lock);
 
 	__raw_writel(1, EP93XX_TIMER1_CLEAR);
-	while ((signed long)
-		(__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
-						>= TIMER4_TICKS_PER_JIFFY) {
-		last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
+	while (after_eq(__raw_readl(EP93XX_TIMER4_VALUE_LOW), next_jiffy_time)) {
 		timer_tick();
+
+		last_jiffy_time = next_jiffy_time;
+		next_jiffy_time += TIMER4_TICKS_PER_JIFFY;
+		accumulator += TIMER4_TICKS_MOD_JIFFY;
+		if (accumulator >= HZ) {
+			next_jiffy_time++;
+			accumulator -= HZ;
+		}
 	}
 
 	write_sequnlock(&xtime_lock);
Index: linux-2.6.22/include/asm-arm/arch-ep93xx/timex.h
===================================================================
--- linux-2.6.22.orig/include/asm-arm/arch-ep93xx/timex.h
+++ linux-2.6.22/include/asm-arm/arch-ep93xx/timex.h
@@ -2,4 +2,4 @@
  * linux/include/asm-arm/arch-ep93xx/timex.h
  */
 
-#define CLOCK_TICK_RATE		983040
+#define CLOCK_TICK_RATE		(1000 * HZ)