MINI2440: Updated early nand loader
[u-boot-openmoko/mini2440.git] / cpu / sh3 / time.c
blob0c273dde37e1af710008a2d6a24f3fb76ce7dc5a
1 /*
2 * (C) Copyright 2007
3 * Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
5 * (C) Copyright 2007
6 * Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
8 * (C) Copyright 2003
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 * See file CREDITS for list of people who contributed to this
12 * project.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
30 #include <common.h>
31 #include <asm/processor.h>
32 #include <asm/io.h>
34 #define TMU_MAX_COUNTER (~0UL)
36 static void tmu_timer_start(unsigned int timer)
38 if (timer > 2)
39 return;
41 outb(inb(TSTR) | (1 << timer), TSTR);
44 static void tmu_timer_stop(unsigned int timer)
46 u8 val = inb(TSTR);
48 if (timer > 2)
49 return;
50 outb(val & ~(1 << timer), TSTR);
53 int timer_init(void)
55 /* Divide clock by 4 */
56 outw(0, TCR0);
58 tmu_timer_stop(0);
59 tmu_timer_start(0);
60 return 0;
64 In theory we should return a true 64bit value (ie something that doesn't
65 overflow). However, we don't. Therefore if TMU runs at fastest rate of
66 6.75 MHz this value will wrap after u-boot has been running for approx
67 10 minutes.
69 unsigned long long get_ticks(void)
71 return (0 - inl(TCNT0));
74 unsigned long get_timer(unsigned long base)
76 return ((0 - inl(TCNT0)) - base);
79 void set_timer(unsigned long t)
81 outl(0 - t, TCNT0);
84 void reset_timer(void)
86 tmu_timer_stop(0);
87 set_timer(0);
88 tmu_timer_start(0);
91 void udelay(unsigned long usec)
93 unsigned int start = get_timer(0);
94 unsigned int end = start + (usec * ((CFG_HZ + 500000) / 1000000));
96 while (get_timer(0) < end)
97 continue;
100 unsigned long get_tbclk(void)
102 return CFG_HZ;