summaryrefslogtreecommitdiff
path: root/packages/linux/linux-2.6.22+2.6.23-rc5/ts72xx/ep93xx-timer-accuracy.diff
blob: 8a6de2e7da9904f92f8bf1392fc9e2dbba50f350 (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.23-rc5/arch/arm/mach-ep93xx/core.c
===================================================================
--- linux-2.6.23-rc5.orig/arch/arm/mach-ep93xx/core.c	2007-09-04 02:26:38.000000000 +0200
+++ linux-2.6.23-rc5/arch/arm/mach-ep93xx/core.c	2007-09-04 02:26:48.000000000 +0200
@@ -94,19 +94,32 @@
  * 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.23-rc5/include/asm-arm/arch-ep93xx/timex.h
===================================================================
--- linux-2.6.23-rc5.orig/include/asm-arm/arch-ep93xx/timex.h	2007-09-04 02:25:36.000000000 +0200
+++ linux-2.6.23-rc5/include/asm-arm/arch-ep93xx/timex.h	2007-09-04 02:26:48.000000000 +0200
@@ -2,4 +2,4 @@
  * linux/include/asm-arm/arch-ep93xx/timex.h
  */
 
-#define CLOCK_TICK_RATE		983040
+#define CLOCK_TICK_RATE		(1000 * HZ)