public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RESEND PATCH v2 2/5] Tegra2: Add microsecond timer functions
Date: Sat, 09 Jul 2011 15:58:46 +0200	[thread overview]
Message-ID: <4E185E96.8000505@aribaud.net> (raw)
In-Reply-To: <1309884558-7700-3-git-send-email-sjg@chromium.org>

Hi Simon,

Le 05/07/2011 18:49, Simon Glass a ?crit :
> These functions provide access to the high resolution microsecond timer
> and tidy up a global variable in the code.
>
> Signed-off-by: Simon Glass<sjg@chromium.org>
> ---
>   arch/arm/cpu/armv7/tegra2/timer.c        |   27 +++++++++++++++++------
>   arch/arm/include/asm/arch-tegra2/timer.h |   34 ++++++++++++++++++++++++++++++
>   2 files changed, 54 insertions(+), 7 deletions(-)
>   create mode 100644 arch/arm/include/asm/arch-tegra2/timer.h
>
> diff --git a/arch/arm/cpu/armv7/tegra2/timer.c b/arch/arm/cpu/armv7/tegra2/timer.c
> index fb061d0..b69c172 100644
> --- a/arch/arm/cpu/armv7/tegra2/timer.c
> +++ b/arch/arm/cpu/armv7/tegra2/timer.c
> @@ -38,13 +38,12 @@
>   #include<common.h>
>   #include<asm/io.h>
>   #include<asm/arch/tegra2.h>
> +#include<asm/arch/timer.h>
>
>   DECLARE_GLOBAL_DATA_PTR;
>
> -struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
> -
>   /* counter runs at 1MHz */
> -#define TIMER_CLK	(1000000)
> +#define TIMER_CLK	1000000
>   #define TIMER_LOAD_VAL	0xffffffff
>
>   /* timer without interrupts */
> @@ -67,10 +66,10 @@ void set_timer(ulong t)
>   void __udelay(unsigned long usec)
>   {
>   	long tmo = usec * (TIMER_CLK / 1000) / 1000;
> -	unsigned long now, last = readl(&timer_base->cntr_1us);
> +	unsigned long now, last = timer_get_us();
>
>   	while (tmo>  0) {
> -		now = readl(&timer_base->cntr_1us);
> +		now = timer_get_us();
>   		if (last>  now) /* count up timer overflow */
>   			tmo -= TIMER_LOAD_VAL - last + now;
>   		else
> @@ -82,7 +81,7 @@ void __udelay(unsigned long usec)
>   void reset_timer_masked(void)
>   {
>   	/* reset time, capture current incrementer value time */
> -	gd->lastinc = readl(&timer_base->cntr_1us) / (TIMER_CLK/CONFIG_SYS_HZ);
> +	gd->lastinc = timer_get_us() / (TIMER_CLK/CONFIG_SYS_HZ);
>   	gd->tbl = 0;		/* start "advancing" time stamp from 0 */
>   }
>
> @@ -91,7 +90,7 @@ ulong get_timer_masked(void)
>   	ulong now;
>
>   	/* current tick value */
> -	now = readl(&timer_base->cntr_1us) / (TIMER_CLK / CONFIG_SYS_HZ);
> +	now = timer_get_us() / (TIMER_CLK / CONFIG_SYS_HZ);
>
>   	if (now>= gd->lastinc)	/* normal mode (non roll) */
>   		/* move stamp forward with absolute diff ticks */
> @@ -120,3 +119,17 @@ ulong get_tbclk(void)
>   {
>   	return CONFIG_SYS_HZ;
>   }
> +
> +
> +unsigned long timer_get_us(void)
> +{
> +	struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
> +
> +	return readl(&timer_base->cntr_1us);
> +}
> +
> +unsigned long timer_get_future_us(u32 delay)
> +{
> +	return timer_get_us() + delay;
> +}

What is the added value in a function that just adds its argument to the 
return value of another function? Might as well do the addition directly 
instead of calling this 'future' function.

> +
> diff --git a/arch/arm/include/asm/arch-tegra2/timer.h b/arch/arm/include/asm/arch-tegra2/timer.h
> new file mode 100644
> index 0000000..5d5445e
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-tegra2/timer.h
> @@ -0,0 +1,34 @@
> +/*
> + * Copyright (c) 2011 The Chromium OS Authors.
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +/* Tegra2 timer functions */
> +
> +#ifndef _TEGRA2_TIMER_H
> +#define _TEGRA2_TIMER_H
> +
> +/* returns the current monotonic timer value in microseconds */
> +unsigned long timer_get_us(void);
> +
> +/* returns what the time will likely be some microseconds into the future */
> +unsigned long timer_get_future_us(u32 delay);
> +
> +#endif
> +


Amicalement,
-- 
Albert.

  reply	other threads:[~2011-07-09 13:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05 16:49 [U-Boot] [RESEND PATCH v2 0/5] Add basic clock and pinmux functions to the Tegra2 Simon Glass
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 1/5] Tegra2: Add macros to calculate bitfield shifts and masks Simon Glass
2011-07-09 13:56   ` Albert ARIBAUD
2011-07-11  4:34     ` Simon Glass
2011-07-11  6:16       ` Wolfgang Denk
2011-07-11 16:19         ` Anton Staaf
2011-07-12 15:29           ` Albert ARIBAUD
2011-07-12 16:48             ` Anton Staaf
2011-07-12 19:30           ` Wolfgang Denk
2011-07-12 20:59             ` Anton Staaf
2011-07-12 21:18               ` Wolfgang Denk
2011-07-12 23:11                 ` Anton Staaf
2011-07-13 11:28                   ` Detlev Zundel
2011-07-13 16:47                     ` Anton Staaf
2011-07-14 16:00                       ` Albert ARIBAUD
2011-07-14 17:29                         ` Anton Staaf
2011-07-14 18:26                           ` Albert ARIBAUD
2011-07-14 18:30                           ` Wolfgang Denk
2011-07-14 18:42                             ` Anton Staaf
2011-07-14 18:44                   ` Wolfgang Denk
2011-07-14 20:06                     ` Anton Staaf
2011-07-11  6:13   ` Wolfgang Denk
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 2/5] Tegra2: Add microsecond timer functions Simon Glass
2011-07-09 13:58   ` Albert ARIBAUD [this message]
2011-07-10  5:24   ` Graeme Russ
2011-07-10  6:14     ` Simon Glass
2011-07-10  6:54       ` Graeme Russ
2011-07-11  6:17     ` Wolfgang Denk
2011-07-11  6:20     ` Wolfgang Denk
2011-07-11  6:43       ` Graeme Russ
2011-07-11 19:58         ` Wolfgang Denk
2011-07-11 22:52           ` Graeme Russ
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 3/5] Tegra2: Add more clock support Simon Glass
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 4/5] Tegra2: add additional pin multiplexing features Simon Glass
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 5/5] Tegra2: Use clock and pinmux functions to simplify code Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E185E96.8000505@aribaud.net \
    --to=albert.u.boot@aribaud.net \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox