public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: seedshope <bocui107@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] S3C64XX: timer: replace bss variable by gd
Date: Tue, 04 Jan 2011 22:46:23 +0800	[thread overview]
Message-ID: <4D2332BF.4080607@gmail.com> (raw)
In-Reply-To: <4D22D6F7.3050609@samsung.com>

On 01/04/2011 04:14 PM, Minkyu Kang wrote:
> Use the global data instead of bss variable, replace as follow.
> timer_load_val ->  timer_rate_hz
> timestamp ->  timer_reset_value
> lastdec ->  lastinc
I have already test the patch on s3c6410 . It is work perfect.

Thanks,
seedshope
> Signed-off-by: Minkyu Kang<mk7.kang@samsung.com>
> Signed-off-by: Darius Augulis<augulis.darius@gmail.com>
> cc: Heiko Schocher<hs@denx.de>
> ---
>   arch/arm/cpu/arm1176/s3c64xx/timer.c |   40 +++++++++++++--------------------
>   1 files changed, 16 insertions(+), 24 deletions(-)
>
> diff --git a/arch/arm/cpu/arm1176/s3c64xx/timer.c b/arch/arm/cpu/arm1176/s3c64xx/timer.c
> index 9768319..c1280f2 100644
> --- a/arch/arm/cpu/arm1176/s3c64xx/timer.c
> +++ b/arch/arm/cpu/arm1176/s3c64xx/timer.c
> @@ -43,7 +43,7 @@
>   #include<asm/arch/s3c6400.h>
>   #include<div64.h>
>
> -static ulong timer_load_val;
> +DECLARE_GLOBAL_DATA_PTR;
>
>   #define PRESCALER	167
>
> @@ -60,12 +60,6 @@ static inline ulong read_timer(void)
>   	return timers->TCNTO4;
>   }
>
> -/* Internal tick units */
> -/* Last decremneter snapshot */
> -static unsigned long lastdec;
> -/* Monotonic incrementing timer */
> -static unsigned long long timestamp;
> -
>   int timer_init(void)
>   {
>   	s3c64xx_timers *const timers = s3c64xx_get_base_timers();
> @@ -83,20 +77,18 @@ int timer_init(void)
>   	 * the prescaler automatically for other PCLK frequencies.
>   	 */
>   	timers->TCFG0 = PRESCALER<<  8;
> -	if (timer_load_val == 0) {
> -		timer_load_val = get_PCLK() / PRESCALER * (100 / 4); /* 100s */
> -		timers->TCFG1 = (timers->TCFG1&  ~0xf0000) | 0x20000;
> -	}
> +	gd->timer_rate_hz = get_PCLK() / PRESCALER * (100 / 4); /* 100s */
> +	timers->TCFG1 = (timers->TCFG1&  ~0xf0000) | 0x20000;
>
>   	/* load value for 10 ms timeout */
> -	lastdec = timers->TCNTB4 = timer_load_val;
> +	gd->lastinc = timers->TCNTB4 = gd->timer_rate_hz;
>   	/* auto load, manual update of Timer 4 */
>   	timers->TCON = (timers->TCON&  ~0x00700000) | TCON_4_AUTO |
>   		TCON_4_UPDATE;
>
>   	/* auto load, start Timer 4 */
>   	timers->TCON = (timers->TCON&  ~0x00700000) | TCON_4_AUTO | COUNT_4_ON;
> -	timestamp = 0;
> +	gd->timer_reset_value = 0;
>
>   	return 0;
>   }
> @@ -113,16 +105,16 @@ unsigned long long get_ticks(void)
>   {
>   	ulong now = read_timer();
>
> -	if (lastdec>= now) {
> +	if (gd->lastinc>= now) {
>   		/* normal mode */
> -		timestamp += lastdec - now;
> +		gd->timer_reset_value += gd->lastinc - now;
>   	} else {
>   		/* we have an overflow ... */
> -		timestamp += lastdec + timer_load_val - now;
> +		gd->timer_reset_value += gd->lastinc + gd->timer_rate_hz - now;
>   	}
> -	lastdec = now;
> +	gd->lastinc = now;
>
> -	return timestamp;
> +	return gd->timer_reset_value;
>   }
>
>   /*
> @@ -132,14 +124,14 @@ unsigned long long get_ticks(void)
>   ulong get_tbclk(void)
>   {
>   	/* We overrun in 100s */
> -	return (ulong)(timer_load_val / 100);
> +	return (ulong)(gd->timer_rate_hz / 100);
>   }
>
>   void reset_timer_masked(void)
>   {
>   	/* reset time */
> -	lastdec = read_timer();
> -	timestamp = 0;
> +	gd->lastinc = read_timer();
> +	gd->timer_reset_value = 0;
>   }
>
>   void reset_timer(void)
> @@ -150,7 +142,7 @@ void reset_timer(void)
>   ulong get_timer_masked(void)
>   {
>   	unsigned long long res = get_ticks();
> -	do_div (res, (timer_load_val / (100 * CONFIG_SYS_HZ)));
> +	do_div(res, (gd->timer_rate_hz / (100 * CONFIG_SYS_HZ)));
>   	return res;
>   }
>
> @@ -161,7 +153,7 @@ ulong get_timer(ulong base)
>
>   void set_timer(ulong t)
>   {
> -	timestamp = t * (timer_load_val / (100 * CONFIG_SYS_HZ));
> +	gd->timer_reset_value = t * (gd->timer_rate_hz / (100 * CONFIG_SYS_HZ));
>   }
>
>   void __udelay(unsigned long usec)
> @@ -170,7 +162,7 @@ void __udelay(unsigned long usec)
>   	ulong tmo;
>
>   	tmo = (usec + 9) / 10;
> -	tmp = get_ticks() + tmo;	/* get current timestamp */
> +	tmp = get_ticks() + tmo;	/* get current timer_reset_value */
>
>   	while (get_ticks()<  tmp)/* loop till event */
>   		 /*NOP*/;

  reply	other threads:[~2011-01-04 14:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-04  8:14 [U-Boot] [PATCH] S3C64XX: timer: replace bss variable by gd Minkyu Kang
2011-01-04 14:46 ` seedshope [this message]
2011-01-04 14:56   ` seedshope
2011-01-05  7:04     ` Minkyu Kang
2011-01-05 15:57       ` seedshope
2011-01-06  8:34         ` Minkyu Kang
2011-01-06  8:53           ` Reinhard Meyer
2011-01-09 16:20             ` Wolfgang Denk
2011-01-09 16:14 ` Wolfgang Denk

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=4D2332BF.4080607@gmail.com \
    --to=bocui107@gmail.com \
    --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