Patchwork [U-Boot,2/9] Exynos: Add timer_get_us function

login
register
mail settings
Submitter Akshay Saraswat
Date Feb. 27, 2013, 10:02 a.m.
Message ID <1361959366-27634-3-git-send-email-akshay.s@samsung.com>
Download mbox | patch
Permalink /patch/223566/
State Changes Requested
Delegated to: Minkyu Kang
Headers show

Comments

Akshay Saraswat - Feb. 27, 2013, 10:02 a.m.
timer_get_us returns the time in microseconds since a certain reference
point of history.  However, it does not guarantee to return an accurate
time after a long period; instead, it wraps around (that is, the
reference point is reset to some other point of history) after some
periods. The frequency of wrapping around is about an hour (or 2^32
microseconds).

TEST=sf probe 1:0; time sf read 40008000 0 1000
Try with different numbers of bytes and see that sane values are obtained

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Akshay Saraswat <akshay.s@samsung.com>
---
 arch/arm/cpu/armv7/s5p-common/timer.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Simon Glass - Feb. 28, 2013, 1:27 a.m.
On Wed, Feb 27, 2013 at 2:02 AM, Akshay Saraswat <akshay.s@samsung.com> wrote:
> timer_get_us returns the time in microseconds since a certain reference
> point of history.  However, it does not guarantee to return an accurate
> time after a long period; instead, it wraps around (that is, the
> reference point is reset to some other point of history) after some
> periods. The frequency of wrapping around is about an hour (or 2^32
> microseconds).
>
> TEST=sf probe 1:0; time sf read 40008000 0 1000
> Try with different numbers of bytes and see that sane values are obtained
>
> Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
> Signed-off-by: Akshay Saraswat <akshay.s@samsung.com>

Acked-by: Simon Glass <sjg@chromium.org>

> ---
>  arch/arm/cpu/armv7/s5p-common/timer.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
> index c48a297..de61405 100644
> --- a/arch/arm/cpu/armv7/s5p-common/timer.c
> +++ b/arch/arm/cpu/armv7/s5p-common/timer.c
> @@ -90,6 +90,21 @@ unsigned long get_timer(unsigned long base)
>         return gd->arch.timer_reset_value / 1000 - base;
>  }
>
> +unsigned long timer_get_us(void)
> +{
> +       static unsigned long base_time_us;
> +
> +       struct s5p_timer *const timer =
> +               (struct s5p_timer *)samsung_get_base_timer();
> +       unsigned long now_downward_us = readl(&timer->tcnto4);
> +
> +       if (!base_time_us)
> +               base_time_us = now_downward_us;
> +
> +       /* Note that this timer counts downward. */
> +       return base_time_us - now_downward_us;
> +}
> +
>  /* delay x useconds */
>  void __udelay(unsigned long usec)
>  {
> --
> 1.8.0
>

Patch

diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
index c48a297..de61405 100644
--- a/arch/arm/cpu/armv7/s5p-common/timer.c
+++ b/arch/arm/cpu/armv7/s5p-common/timer.c
@@ -90,6 +90,21 @@  unsigned long get_timer(unsigned long base)
 	return gd->arch.timer_reset_value / 1000 - base;
 }
 
+unsigned long timer_get_us(void)
+{
+	static unsigned long base_time_us;
+
+	struct s5p_timer *const timer =
+		(struct s5p_timer *)samsung_get_base_timer();
+	unsigned long now_downward_us = readl(&timer->tcnto4);
+
+	if (!base_time_us)
+		base_time_us = now_downward_us;
+
+	/* Note that this timer counts downward. */
+	return base_time_us - now_downward_us;
+}
+
 /* delay x useconds */
 void __udelay(unsigned long usec)
 {