pxa: fixing get_timer to return time in miliseconds.
[platform/kernel/u-boot.git] / cpu / pxa / interrupts.c
1 /*
2  * (C) Copyright 2002
3  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4  * Marius Groeger <mgroeger@sysgo.de>
5  *
6  * (C) Copyright 2002
7  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8  * Alex Zuepke <azu@sysgo.de>
9  *
10  * See file CREDITS for list of people who contributed to this
11  * project.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of
16  * the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26  * MA 02111-1307 USA
27  */
28
29 #include <common.h>
30 #include <asm/arch/pxa-regs.h>
31
32 #ifdef CONFIG_USE_IRQ
33 #error: interrupts not implemented yet
34 #endif
35
36 #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
37 #define TIMER_FREQ_HZ 3250000
38 #elif defined(CONFIG_PXA250)
39 #define TIMER_FREQ_HZ 3686400
40 #else
41 #error "Timer frequency unknown - please config PXA CPU type"
42 #endif
43
44 int interrupt_init (void)
45 {
46         /* nothing happens here - we don't setup any IRQs */
47         return (0);
48 }
49
50 void reset_timer (void)
51 {
52         reset_timer_masked ();
53 }
54
55 ulong get_timer (ulong base)
56 {
57         return get_timer_masked () - base;
58 }
59
60 void set_timer (ulong t)
61 {
62         /* nop */
63 }
64
65 void udelay (unsigned long usec)
66 {
67         udelay_masked (usec);
68 }
69
70
71 void reset_timer_masked (void)
72 {
73         OSCR = 0;
74 }
75
76 ulong get_timer_masked (void)
77 {
78         unsigned long long ticks = get_ticks();
79
80         return (((ticks / TIMER_FREQ_HZ) * 1000) +
81                 ((ticks % TIMER_FREQ_HZ) * 1000) / TIMER_FREQ_HZ);
82 }
83
84 void udelay_masked (unsigned long usec)
85 {
86         ulong tmo;
87         ulong endtime;
88         signed long diff;
89
90         if (usec >= 1000) {
91                 tmo = usec / 1000;
92                 tmo *= TIMER_FREQ_HZ;
93                 tmo /= 1000;
94         } else {
95                 tmo = usec * TIMER_FREQ_HZ;
96                 tmo /= (1000*1000);
97         }
98
99         endtime = get_ticks() + tmo;
100
101         do {
102                 ulong now = get_ticks();
103                 diff = endtime - now;
104         } while (diff >= 0);
105 }
106
107 /*
108  * This function is derived from PowerPC code (read timebase as long long).
109  * On ARM it just returns the timer value.
110  */
111 unsigned long long get_ticks(void)
112 {
113         return OSCR;
114 }
115
116 /*
117  * This function is derived from PowerPC code (timebase clock frequency).
118  * On ARM it returns the number of timer ticks per second.
119  */
120 ulong get_tbclk (void)
121 {
122         ulong tbclk;
123         tbclk = TIMER_FREQ_HZ;
124         return tbclk;
125 }