@@ -22,6 +22,7 @@
#include <common.h>
#include <asm/io.h>
+#include <div64.h>
struct mtu {
uint imsc;
@@ -42,14 +43,6 @@ struct mtu {
#define MTU_CRn_PRESCALE_256 0x08
#define MTU_CRn_32BITS 0x02
-/*
- * The timer is a decrementer, we'll left it free running at 2.4MHz.
- * We have 2.4 ticks per microsecond and an overflow in almost 30min
- */
-#define TIMER_CLOCK (24 * 100 * 1000)
-#define COUNT_TO_USEC(x) ((x) * 5 / 12) /* overflows at 6min */
-#define USEC_TO_COUNT(x) ((x) * 12 / 5) /* overflows at 6min */
-
static const struct mtu_timer *timer
= &((struct mtu *) CONFIG_SYS_TIMERBASE)->timer[0];
@@ -59,10 +52,18 @@ static ulong read_timer(void)
return 0 - readl(&timer->val);
}
+static unsigned long usec_to_count(unsigned long long usec)
+{
+ unsigned long long count = usec * CONFIG_NOMADIK_MTU_CLOCK;
+ do_div(count, 1000000);
+ return count;
+}
+
/* Configure a free-running, auto-wrap counter with no prescaler */
int timer_init(void)
{
- writel(MTU_CRn_ENA | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS, &timer->cr);
+ writel(MTU_CRn_ENA | CONFIG_NOMADIK_MTU_PRESCALE | MTU_CRn_32BITS,
+ &timer->cr);
reset_timer();
return 0;
}
@@ -85,7 +86,7 @@ void reset_timer(void)
/* Return how many HZ passed since "base" */
ulong get_timer(ulong base)
{
- ulong hz = read_timer() / (TIMER_CLOCK / CONFIG_SYS_HZ);
+ ulong hz = read_timer() / (CONFIG_NOMADIK_MTU_CLOCK / CONFIG_SYS_HZ);
return hz - base;
}
@@ -95,7 +96,7 @@ void __udelay(unsigned long usec)
ulong ini, end;
ini = read_timer();
- end = ini + USEC_TO_COUNT(usec);
+ end = ini + usec_to_count(usec);
while ((signed)(end - read_timer()) > 0)
;
}
@@ -98,6 +98,9 @@
#define CONFIG_SYS_HZ 1000 /* Mandatory... */
#define CONFIG_SYS_TIMERBASE 0x101E2000
#define CONFIG_NOMADIK_MTU
+/* We have 2.4 ticks per microsecond and an overflow in almost 30min */
+#define CONFIG_NOMADIK_MTU_CLOCK (24 * 100 * 1000)
+#define CONFIG_NOMADIK_MTU_PRESCALE MTU_CRn_PRESCALE_1
/* GPIO */
#define CONFIG_NOMADIK_GPIO