blob: 9c1dc509bb7cc757deda31db43925e02296acb6a [file] [log] [blame]
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09001/*
2 * Copyright (c) 2007
3 * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
Nobuhiro Iwamatsu9e23fe02008-07-08 12:03:24 +090025#include <asm/processor.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090026
27static void tmu_timer_start (unsigned int timer)
28{
29 if (timer > 2)
30 return;
31
32 *((volatile unsigned char *) TSTR0) |= (1 << timer);
33}
34
35int timer_init (void)
36{
37 *(volatile u16 *)TCR0 = 0;
38
39 tmu_timer_start (0);
40 return 0;
41}
42
43unsigned long long get_ticks (void)
44{
45 return (0 - *((volatile unsigned int *) TCNT0));
46}
47
48unsigned long get_timer (unsigned long base)
49{
50 return ((0 - *((volatile unsigned int *) TCNT0)) - base);
51}
52
53void set_timer (unsigned long t)
54{
55 *((volatile unsigned int *) TCNT0) = (0 - t);
56}
57
58void reset_timer (void)
59{
60 set_timer (0);
61}
62
63void udelay (unsigned long usec)
64{
65 unsigned int start = get_timer (0);
66 unsigned int end = start + (usec * ((CFG_HZ + 500000) / 1000000));
67
68 while (get_timer (0) < end)
69 continue;
70}
71
72unsigned long get_tbclk (void)
73{
74 return CFG_HZ;
75}