2 * (C) Copyright 2007-2008
3 * Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/processor.h>
31 #define TMU_MAX_COUNTER (~0UL)
32 static int clk_adj = 1;
34 static void tmu_timer_start (unsigned int timer)
38 writeb(readb(TSTR) | (1 << timer), TSTR);
41 static void tmu_timer_stop (unsigned int timer)
45 writeb(readb(TSTR) & ~(1 << timer), TSTR);
50 /* Divide clock by TMU_CLK_DIVIDER */
53 switch (TMU_CLK_DIVIDER) {
71 writew(readw(TCR0) | bit, TCR0);
73 /* Clock adjustment calc */
74 clk_adj = (int)(1.0 / ((1.0 / CONFIG_SYS_HZ) * 1000000));
84 unsigned long long get_ticks (void)
86 return 0 - readl(TCNT0);
89 static unsigned long get_usec (void)
91 return (0 - readl(TCNT0));
94 void udelay (unsigned long usec)
96 unsigned int start = get_usec();
97 unsigned int end = start + (usec * clk_adj);
99 while (get_usec() < end)
103 unsigned long get_timer (unsigned long base)
106 return ((get_usec() / clk_adj) / 1000) - base;
109 void set_timer (unsigned long t)
111 writel((0 - t), TCNT0);
114 void reset_timer (void)
121 unsigned long get_tbclk (void)
123 return CONFIG_SYS_HZ;