[U-Boot] [PATCH 4/8] nomadik_mtu: support configurable clock rates

Rabin Vincent rabin.vincent at stericsson.com
Thu Mar 18 06:08:10 CET 2010


Change the Nomadik MTU driver to get the clock rate and prescaler from
the config file.  Also remove the hardcoded divisors and do the
calculations based on the configured rate.

Acked-by: Alessandro Rubini <rubini at unipv.it>
Acked-by: Michael Brandt <michael.brandt at stericsson.com>
Signed-off-by: Rabin Vincent <rabin.vincent at stericsson.com>
---
 drivers/misc/nomadik_mtu.c |   22 +++++++++++++---------
 include/configs/nhk8815.h  |    3 +++
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/nomadik_mtu.c b/drivers/misc/nomadik_mtu.c
index b9c0fb1..4ec75ad 100644
--- a/drivers/misc/nomadik_mtu.c
+++ b/drivers/misc/nomadik_mtu.c
@@ -22,25 +22,29 @@
 
 #include <common.h>
 #include <asm/io.h>
+#include <div64.h>
 #include <nomadik_mtu.h>
 
-/*
- * 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 */
+#define TIMER_CLOCK		CONFIG_NOMADIK_MTU_CLOCK
 #define TICKS_PER_HZ		(TIMER_CLOCK / CONFIG_SYS_HZ)
 #define TICKS_TO_HZ(x)		((x) / TICKS_PER_HZ)
 
 /* macro to read the decrementing 32 bit timer as an increasing count */
 #define READ_TIMER() (0 - readl(CONFIG_SYS_TIMERBASE + MTU_VAL(0)))
 
+static unsigned long usec_to_count(unsigned long long usec)
+{
+	unsigned long long count = usec * TIMER_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,
+	writel(MTU_CRn_ENA | CONFIG_NOMADIK_MTU_PRESCALE | MTU_CRn_32BITS,
 	       CONFIG_SYS_TIMERBASE + MTU_CR(0));
 	reset_timer();
 	return 0;
@@ -73,7 +77,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)
 		;
 }
diff --git a/include/configs/nhk8815.h b/include/configs/nhk8815.h
index 8ba1e5e..d52f50c 100644
--- a/include/configs/nhk8815.h
+++ b/include/configs/nhk8815.h
@@ -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
-- 
1.7.0



More information about the U-Boot mailing list