From: Patrick Delaunay Date: Mon, 5 Mar 2018 15:24:31 +0100 Subject: [U-Boot] [PATCH 04/16] arm: armv7: solve issue for timer_rate_hz in arch timer In-Reply-To: <1520259883-4929-1-git-send-email-patrick.delaunay@st.com> References: <1520259883-4929-1-git-send-email-patrick.delaunay@st.com> Message-ID: <1520259883-4929-5-git-send-email-patrick.delaunay@st.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de The current value timer_rate_hz causes a problem with function timer_get_us() from lib time and then an issue with readx_poll_timeout() function. With corrected value for tbclk() = timer_rate_hz = CONFIG_SYS_HZ_CLOCK the weak functions in lib timer can be used: - get_timer() - __udelay() So the specific function in this file are removed. Signed-off-by: Patrick Delaunay --- this patch avoid issue in driver with readl_poll_timeout() Following source code has been used to demonstrate the issue (with CONFIG_SYS_HZ_CLOCK = 64 MHz) printf("Tick= %llx us=%lx boot us=%lx\n", get_ticks(), timer_get_us(), timer_get_boot_us()); mdelay(1000); printf("Tick= %llx us=%lx boot us=%lx\n", get_ticks(), timer_get_us(), timer_get_boot_us()); Result: Tick= 36fad40 us=35b0f45f boot us=dbeb8 Tick= 743b21e us=7181c02e boot us=1d0ecb => 1000ms : 0x1d0ecb-0xdbeb8 = 0xF5013 for timer_get_boot_us = 1000000 us => timer_get_boot_us is OK => 1000ms : 0x7181c02e-0x35b0f45f = 0x3BD0CBCF = 1.000.000.000 us for timer_get_us() which gives a invalid value (based on CONFIG_SYS_HZ and get_tbclk()) This patch resolves the issue. arch/arm/cpu/armv7/arch_timer.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/arch/arm/cpu/armv7/arch_timer.c b/arch/arm/cpu/armv7/arch_timer.c index 30915d2..545c518 100644 --- a/arch/arm/cpu/armv7/arch_timer.c +++ b/arch/arm/cpu/armv7/arch_timer.c @@ -17,7 +17,7 @@ int timer_init(void) gd->arch.tbl = 0; gd->arch.tbu = 0; - gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ; + gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK; return 0; } @@ -34,27 +34,9 @@ unsigned long long get_ticks(void) } -ulong get_timer(ulong base) -{ - return lldiv(get_ticks(), gd->arch.timer_rate_hz) - base; -} - ulong timer_get_boot_us(void) { - return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / (CONFIG_SYS_HZ * 1000)); -} - -void __udelay(unsigned long usec) -{ - unsigned long long endtime; - - endtime = lldiv((unsigned long long)usec * gd->arch.timer_rate_hz, - 1000UL); - - endtime += get_ticks(); - - while (get_ticks() < endtime) - ; + return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / 1000000); } ulong get_tbclk(void) -- 2.7.4