From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rob Herring Date: Sun, 8 Sep 2013 15:12:48 -0500 Subject: [U-Boot] [PATCH 3/9] time: create default __udelay In-Reply-To: <1378671174-18535-1-git-send-email-robherring2@gmail.com> References: <1378671174-18535-1-git-send-email-robherring2@gmail.com> Message-ID: <1378671174-18535-4-git-send-email-robherring2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Rob Herring Implement a default __udelay using get_tbclk and get_ticks. Signed-off-by: Rob Herring --- lib/time.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/time.c b/lib/time.c index 68b8ff4..55f05bb 100644 --- a/lib/time.c +++ b/lib/time.c @@ -7,11 +7,32 @@ #include #include +#include #ifndef CONFIG_WD_PERIOD # define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default*/ #endif +static unsigned long long usec_to_tick(unsigned long usec) +{ + unsigned long long tick = usec * get_tbclk(); + usec *= get_tbclk(); + do_div(tick, 1000000); + return tick; +} + +void __weak __udelay(unsigned long usec) +{ + unsigned long long tmp; + ulong tmo; + + tmo = usec_to_tick(usec); + tmp = get_ticks() + tmo; /* get current timestamp */ + + while (get_ticks() < tmp) /* loop till event */ + /*NOP*/; +} + /* ------------------------------------------------------------------------- */ void udelay(unsigned long usec) -- 1.8.1.2