Skip to contentSkip to conversation

CONFIG_SYS_HZ fix for ARM920T S3C24X0 Boards

U-Boot kevin.morfitt at fearnside-systems.co.uk 2 participants 2 messages Jun 21, 2009 – Jul 4, 2009

lore
Share & tools
lore
#0 lore raw

This sets CONFIG_SYS_HZ to 1000 for all boards that use the s3c2400 and s3c2410 cpu's.

Tested on an Embest SBC2440-II Board with local u-boot patches as I don't have any s3c2400 or s3c2410 boards but need this patch applying before I can submit patches for thge SBC2440-II Board.

Also, ran MAKEALL for all ARM9 targets and no new warnings or errors were found.

Note that the existing code modified by this patch does not meet the u-boot coding style but I'd like to handle this separately and submit patches to fix this later.

---
 cpu/arm920t/s3c24x0/timer.c |   42 ++++++++++++++++++++++++++----------------
 include/configs/sbc2410x.h  |    4 +---
 include/configs/smdk2400.h  |    4 +---
 include/configs/smdk2410.h  |    4 +---
 include/configs/trab.h      |   12 +-----------
 5 files changed, 30 insertions(+), 36 deletions(-)
 mode change 100644 => 100755 cpu/arm920t/s3c24x0/timer.c
 mode change 100644 => 100755 include/configs/sbc2410x.h
 mode change 100644 => 100755 include/configs/smdk2400.h
 mode change 100644 => 100755 include/configs/smdk2410.h
 mode change 100644 => 100755 include/configs/trab.h
cpu/arm920t/s3c24x0/timer.c +26 -16
old mode 100644
new mode 100755
index f0a09cd..8ea2e4b
@@ -38,7 +38,9 @@
 #include <s3c2410.h>
 #endif
 
+static unsigned long get_timer_raw(void);
 int timer_load_val = 0;
+static ulong timer_clk;
 
 /* macro to read the 16 bit timer */
 static inline ulong READ_TIMER(void)
@@ -66,6 +68,7 @@ int timer_init (void)
 		 * @33.25MHz and 15625 @ 50 MHz
 		 */
 		timer_load_val = get_PCLK()/(2 * 16 * 100);
+		timer_clk = get_PCLK() / (2 * 16);
 	}
 	/* load value for 10 ms timeout */
 	lastdec = timers->TCNTB4 = timer_load_val;
@@ -100,13 +103,13 @@ void set_timer (ulong t)
 void udelay (unsigned long usec)
 {
 	ulong tmo;
-	ulong start = get_timer(0);
+	ulong start = get_timer_raw();
 
 	tmo = usec / 1000;
 	tmo *= (timer_load_val * 100);
 	tmo /= 1000;
 
-	while ((ulong)(get_timer_masked () - start) < tmo)
+	while ((ulong) (get_timer_raw() - start) < tmo)
 		/*NOP*/;
 }
 
@@ -119,18 +122,9 @@ void reset_timer_masked (void)
 
 ulong get_timer_masked (void)
 {
-	ulong now = READ_TIMER();
+	ulong tmr = get_timer_raw();
 
-	if (lastdec >= now) {
-		/* normal mode */
-		timestamp += lastdec - now;
-	} else {
-		/* we have an overflow ... */
-		timestamp += lastdec + timer_load_val - now;
-	}
-	lastdec = now;
-
-	return timestamp;
+	return tmr / (timer_clk / CONFIG_SYS_HZ);
 }
 
 void udelay_masked (unsigned long usec)
@@ -148,21 +142,37 @@ void udelay_masked (unsigned long usec)
 		tmo /= (1000*1000);
 	}
 
-	endtime = get_timer_masked () + tmo;
+	endtime = get_timer_raw() + tmo;
 
 	do {
-		ulong now = get_timer_masked ();
+		ulong now = get_timer_raw();
 		diff = endtime - now;
 	} while (diff >= 0);
 }
 
+static unsigned long get_timer_raw(void)
+{
+	ulong now = READ_TIMER();
+
+	if (lastdec >= now) {
+		/* normal mode */
+		timestamp += lastdec - now;
+	} else {
+		/* we have an overflow ... */
+		timestamp += lastdec + timer_load_val - now;
+	}
+	lastdec = now;
+
+	return timestamp;
+}
+
 /*
  * This function is derived from PowerPC code (read timebase as long long).
  * On ARM it just returns the timer value.
  */
 unsigned long long get_ticks(void)
 {
-	return get_timer(0);
+	return get_timer_raw();
 }
 
 /*
include/configs/sbc2410x.h +1 -3
old mode 100644
new mode 100755
index eab9629..e8afa50
@@ -138,9 +138,7 @@
 
 #define	CONFIG_SYS_LOAD_ADDR		0x33000000	/* default load address	*/
 
-/* the PWM TImer 4 uses a counter of 15625 for 10 ms, so we need */
-/* it to wrap 100 times (total 1562500) to get 1 sec. */
-#define	CONFIG_SYS_HZ			1562500
+#define	CONFIG_SYS_HZ			1000
 
 /* valid baudrates */
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200 }
include/configs/smdk2400.h +1 -3
old mode 100644
new mode 100755
index b712db4..22b88ae
@@ -140,9 +140,7 @@
 
 #define	CONFIG_SYS_LOAD_ADDR		0x0cf00000	/* default load address	*/
 
-/* the PWM TImer 4 uses a counter of 15625 for 10 ms, so we need */
-/* it to wrap 100 times (total 1562500) to get 1 sec. */
-#define	CONFIG_SYS_HZ			1562500
+#define	CONFIG_SYS_HZ			1000
 
 /* valid baudrates */
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200 }
include/configs/smdk2410.h +1 -3
old mode 100644
new mode 100755
index a473278..f45d94b
@@ -123,9 +123,7 @@
 
 #define	CONFIG_SYS_LOAD_ADDR		0x33000000	/* default load address	*/
 
-/* the PWM TImer 4 uses a counter of 15625 for 10 ms, so we need */
-/* it to wrap 100 times (total 1562500) to get 1 sec. */
-#define	CONFIG_SYS_HZ			1562500
+#define	CONFIG_SYS_HZ			1000
 
 /* valid baudrates */
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200 }
include/configs/trab.h +1 -11
old mode 100644
new mode 100755
index 7687ee6..b3f23ae
@@ -319,17 +319,7 @@
 
 #define	CONFIG_SYS_LOAD_ADDR		0x0CF00000	/* default load address	*/
 
-#ifdef CONFIG_TRAB_50MHZ
-/* the PWM TImer 4 uses a counter of 15625 for 10 ms, so we need */
-/* it to wrap 100 times (total 1562500) to get 1 sec. */
-/* this should _really_ be calculated !! */
-#define	CONFIG_SYS_HZ			1562500
-#else
-/* the PWM TImer 4 uses a counter of 10390 for 10 ms, so we need */
-/* it to wrap 100 times (total 1039000) to get 1 sec. */
-/* this should _really_ be calculated !! */
-#define	CONFIG_SYS_HZ			1039000
-#endif
+#define	CONFIG_SYS_HZ			1000
 
 /* valid baudrates */
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200 }

-- 1.6.0.6

#1 lore raw
Quoted 7 lines · kevin.morfitt at fearnside-systems.co.uk

This sets CONFIG_SYS_HZ to 1000 for all boards that use the s3c2400 and s3c2410 cpu's.

Tested on an Embest SBC2440-II Board with local u-boot patches as I don't have any s3c2400 or s3c2410 boards but need this patch applying before I can submit patches for thge SBC2440-II Board.

Quoted 5 lines

Also, ran MAKEALL for all ARM9 targets and no new warnings or errors were found.

Note that the existing code modified by this patch does not meet the u-boot coding style but I'd like to handle this separately and submit patches to fix this later.

It look fine but it will be good that someone test it on the other soc I'll try to ping someone

Quoted 22 lines
---
 cpu/arm920t/s3c24x0/timer.c |   42 ++++++++++++++++++++++++++----------------
 include/configs/sbc2410x.h  |    4 +---
 include/configs/smdk2400.h  |    4 +---
 include/configs/smdk2410.h  |    4 +---
 include/configs/trab.h      |   12 +-----------
 5 files changed, 30 insertions(+), 36 deletions(-)
 mode change 100644 => 100755 cpu/arm920t/s3c24x0/timer.c
 mode change 100644 => 100755 include/configs/sbc2410x.h
 mode change 100644 => 100755 include/configs/smdk2400.h
 mode change 100644 => 100755 include/configs/smdk2410.h
 mode change 100644 => 100755 include/configs/trab.h
cpu/arm920t/s3c24x0/timer.c +0 -0
old mode 100644
new mode 100755
index f0a09cd..8ea2e4b

cpu/arm920t/s3c24x0/timer.c line 46

Quoted 9 lines
cpu/arm920t/s3c24x0/timer.c +3 -0
@@ -38,7 +38,9 @@
 #include <s3c2410.h>
 #endif
 
+static unsigned long get_timer_raw(void);
 int timer_load_val = 0;
+static ulong timer_clk;
 
 
+static unsigned long get_timer_raw(void)

rename it get_ticks

Quoted 15 lines
cpu/arm920t/s3c24x0/timer.c +14 -0
+{
+	ulong now = READ_TIMER();
+
+	if (lastdec >= now) {
+		/* normal mode */
+		timestamp += lastdec - now;
+	} else {
+		/* we have an overflow ... */
+		timestamp += lastdec + timer_load_val - now;
+	}
+	lastdec = now;
+
+	return timestamp;
+}

cpu/arm920t/s3c24x0/timer.c void udelay_masked (unsigned long usec) · line 176

Quoted 10 lines
cpu/arm920t/s3c24x0/timer.c +2 -1
+
 /*
  * This function is derived from PowerPC code (read timebase as long long).
  * On ARM it just returns the timer value.
  */
 unsigned long long get_ticks(void)
 {
-	return get_timer(0);
+	return get_timer_raw();
 }

Best Regards,
J.