[U-Boot] [PATCH] cfi_flash: reset timer in flash status check

Thomas Chou thomas at wytron.com.tw
Thu Apr 1 05:11:37 CEST 2010


This patch adds reset_timer() before the flash status check
waiting loop.

Since the timer is basically running asynchronous to the cfi
code, it is possible to call get_timer(0), then only a few
_SYSCLK_ cycles later an interrupt is generated. This causes
timeout even though much less time has elapsed. So the timer
period registers should be reset before get_timer(0) is
called.

There is similar usage in nand_base.c.

Signed-off-by: Thomas Chou <thomas at wytron.com.tw>
---
 drivers/mtd/cfi_flash.c   |    2 ++
 include/configs/EP3C120.h |   10 +++++-----
 include/configs/NEEK.h    |   10 +++++-----
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index aae93bd..99300ba 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -544,6 +544,7 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector,
 #endif
 
 	/* Wait for command completion */
+	reset_timer();
 	start = get_timer (0);
 	while (flash_is_busy (info, sector)) {
 		if (get_timer (start) > tout) {
@@ -630,6 +631,7 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst,
 #endif
 
 	/* Wait for command completion */
+	reset_timer();
 	start = get_timer(0);
 	while (1) {
 		switch (info->portwidth) {
diff --git a/include/configs/EP3C120.h b/include/configs/EP3C120.h
index cfd5569..6734a65 100644
--- a/include/configs/EP3C120.h
+++ b/include/configs/EP3C120.h
@@ -152,10 +152,10 @@
  */
 #define CONFIG_SYS_NIOS_TMRBASE	(LINUX_TIMER_1MS_BASE | IO_REGION_BASE)
 #define CONFIG_SYS_NIOS_TMRIRQ		LINUX_TIMER_1MS_IRQ
-#define CONFIG_SYS_NIOS_TMRCNT		((LINUX_TIMER_1MS_FREQ / \
-					  CONFIG_SYS_HZ) - 1)
-#define CONFIG_SYS_NIOS_TMRMS		1	/* Must be one */
-#define CONFIG_SYS_HZ			1000
+#define CONFIG_SYS_HZ			1000	/* Always 1000 */
+#define CONFIG_SYS_NIOS_TMRMS		10	/* Desired period (msec)*/
+#define CONFIG_SYS_NIOS_TMRCNT \
+	(CONFIG_SYS_NIOS_TMRMS * (LINUX_TIMER_1MS_FREQ / 1000) - 1)
 
 /*
  * STATUS LED
@@ -167,7 +167,7 @@
 
 #define STATUS_LED_BIT			1	/* Bit-0 on PIO */
 #define STATUS_LED_STATE		1	/* Blinking */
-#define STATUS_LED_PERIOD		(CONFIG_SYS_HZ / 2) /* 500 mS */
+#define STATUS_LED_PERIOD	(500 / CONFIG_SYS_NIOS_TMRMS) /* 500 msec */
 
 /*
  * IDE support
diff --git a/include/configs/NEEK.h b/include/configs/NEEK.h
index f42701e..432a582 100644
--- a/include/configs/NEEK.h
+++ b/include/configs/NEEK.h
@@ -149,10 +149,10 @@
  */
 #define CONFIG_SYS_NIOS_TMRBASE	(SYS_CLK_TIMER_BASE | IO_REGION_BASE)
 #define CONFIG_SYS_NIOS_TMRIRQ		SYS_CLK_TIMER_IRQ
-#define CONFIG_SYS_NIOS_TMRCNT		((SYS_CLK_TIMER_FREQ / \
-					  CONFIG_SYS_HZ) - 1)
-#define CONFIG_SYS_NIOS_TMRMS		1	/* Must be one */
-#define CONFIG_SYS_HZ			1000
+#define CONFIG_SYS_HZ			1000	/* Always 1000 */
+#define CONFIG_SYS_NIOS_TMRMS		10	/* Desired period (msec)*/
+#define CONFIG_SYS_NIOS_TMRCNT \
+	(CONFIG_SYS_NIOS_TMRMS * (SYS_CLK_TIMER_FREQ / 1000) - 1)
 
 /*
  * STATUS LED
@@ -162,7 +162,7 @@
 
 #define STATUS_LED_BIT		CONFIG_SYS_GPIO_HBT
 #define STATUS_LED_STATE	1		/* Blinking		*/
-#define STATUS_LED_PERIOD	(CONFIG_SYS_HZ / 2)	/* 500 mS */
+#define STATUS_LED_PERIOD	(500 / CONFIG_SYS_NIOS_TMRMS) /* 500 msec */
 
 /*
  * IDE support
-- 
1.6.6.1



More information about the U-Boot mailing list