public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Shinya Kuribayashi <shinya.kuribayashi@necel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH] [resend] mips: Support to set CFG_HZ to 1000, consistent with other architectures
Date: Wed, 21 May 2008 12:53:01 +0900	[thread overview]
Message-ID: <48339C9D.5040800@necel.com> (raw)
In-Reply-To: <20080520185822.8B9C86545F@mcmullan-linux.hq.netapp.com>

Hi Jason,

I don't look closely yet, but find some comments below:

Jason McMullan wrote:
> ---
>  include/configs/dbau1x00.h  |    3 ++-
>  include/configs/gth2.h      |    3 ++-
>  include/configs/incaip.h    |    3 ++-
>  include/configs/pb1x00.h    |    3 ++-
>  include/configs/purple.h    |    3 ++-
>  include/configs/qemu-mips.h |    3 ++-
>  include/configs/tb0229.h    |    3 ++-

Ok.

> diff --git a/lib_mips/time.c b/lib_mips/time.c
> index cd8dc72..4807f1a 100644
> --- a/lib_mips/time.c
> +++ b/lib_mips/time.c
> @@ -23,23 +23,57 @@
>  
>  #include <common.h>
>  
> +/* CFG_MIPS_CLOCK is the number of ticks per second of the MIPS C0 Clock timer.
> + *
> + * For most implementations, this is the same as the CPU speed in HZ
> + * divided by 2. Some embedded MIPS implementations may use a /4
> + * or /1 divider, so see your CPU reference manual for specific details.
> + */
> +#ifndef CFG_MIPS_CLOCK
> +#error CFG_MIPS_CLOCK must be set in the board configuration file
> +#endif
>  
> +static struct {
> +	uint32_t lo;
> +	uint32_t hi;
> +} mips_ticks;	/* Last number of ticks seen */

See below.

> +/* Input is in CFG_HZ ticks */
>  static inline void mips_compare_set(u32 v)
>  {
> +	v *= (CFG_MIPS_CLOCK / CFG_HZ);
>  	asm volatile ("mtc0 %0, $11" : : "r" (v));
>  }

I tend to remove these mips_{count,compare}_{get,set} functions because
they can be (and should be) replaced {read,write}_32bit_ cp0_register,
IMO.

And I want to handle (CFG_MIPS_CLOCK/CFG_HZ) stuffs or something like
that at udelay() side.

> +/* Returns CFG_HZ ticks 
> + *
> + * NOTE: This must be called at least once every
> + *       few seconds to be reliable.
> + */
>  static inline u32 mips_count_get(void)
>  {
>  	u32 count;
>  
>  	asm volatile ("mfc0 %0, $9" : "=r" (count) :);
> +
> +	/* Handle 32-bit timer overflow */
> +	if (count < mips_ticks.lo) {
> +		mips_ticks.hi++;
> +	}
> +	mips_ticks.lo = count;
> +	count =(mips_ticks.lo / (CFG_MIPS_CLOCK / CFG_HZ)) +
> +	       (mips_ticks.hi * (0x100000000ULL / (CFG_MIPS_CLOCK / CFG_HZ)));
> +
>  	return count;
>  }

I disagree with having this structure. Basic strategy for MIPS COUNT/
COMPARE handling is, let them overflow (os should I say wrap-around) as
they are. All we need is the Delta, not the numbers of overflows.

> @@ -75,7 +109,7 @@ void udelay (unsigned long usec)
>  	ulong tmo;
>  	ulong start = get_timer(0);
>  
> -	tmo = usec * (CFG_HZ / 1000000);
> +	tmo = usec * CFG_HZ / 1000;
>  	while ((ulong)((mips_count_get() - start)) < tmo)
>  		/*NOP*/;
>  }

Again, what is needed is `the Delta' between CP0.COUNT(Previous) and
CP0.COUNT(Current). This can be always achieved by

    delta = COUNT(Curr) - COUNT(Prev)

regardless of COUNT value. Even if `(u32)0x00010000 - (u32)0xFFFFFFFF',
it works.

I'll look around until this weekend. Sorry for inconvinience, and thank
you for working on this.

  Shinya

  reply	other threads:[~2008-05-21  3:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-20 16:24 [U-Boot-Users] [PATCH] [resend] mips: Support to set CFG_HZ to 1000, consistent with other architectures Jason McMullan
2008-05-21  3:53 ` Shinya Kuribayashi [this message]
2008-05-21 15:32   ` Scott Wood
2008-05-24 12:58     ` [U-Boot-Users] [PATCH 1/3][MIPS] lib_mips/time.c: Replace CP0 access functions with existing macros Shinya Kuribayashi
2008-05-24 12:59       ` [U-Boot-Users] [PATCH 2/3][MIPS] lib_mips/time.c: Fix udelay Shinya Kuribayashi
2008-05-24 13:02         ` [U-Boot-Users] [PATCH 3/3][MIPS] lib_mips/time.c: Fix improper use of CFG_HZ and timer routines Shinya Kuribayashi
2008-05-24 19:59           ` Wolfgang Denk
2008-05-25  2:04             ` Shinya Kuribayashi
2008-05-25  8:15               ` Wolfgang Denk
2008-05-25 13:45                 ` Shinya Kuribayashi
2008-05-25 15:18                   ` Wolfgang Denk
2008-05-31  6:12                     ` Shinya Kuribayashi
2008-05-31  6:17                       ` Shinya Kuribayashi
2008-05-31 14:40           ` [U-Boot-Users] [PATCH 3/3 v2][MIPS] lib_mips/time.c: Fix CP0 count register usage " Shinya Kuribayashi

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=48339C9D.5040800@necel.com \
    --to=shinya.kuribayashi@necel.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