2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #include <asm/m5272.h>
30 #include <asm/m5282.h>
32 #include <asm/mcftimer.h>
33 #include <asm/processor.h>
36 static ulong timestamp;
37 static unsigned short lastinc;
39 void coldfire_timer_init (void)
41 volatile unsigned short *timerp;
43 timerp = (volatile unsigned short *) (MCF_MBAR + MCFTIMER_BASE4);
47 /* Set up TIMER 4 as poll clock */
48 timerp[MCFTIMER_TMR] = MCFTIMER_TMR_DISABLE;
49 timerp[MCFTIMER_TRR] = lastinc = 0;
50 timerp[MCFTIMER_TMR] = (65 << 8) | MCFTIMER_TMR_CLK1 |
51 MCFTIMER_TMR_FREERUN | MCFTIMER_TMR_ENABLE;
55 /* Set up TIMER 4 as poll clock */
56 timerp[MCFTIMER_PCSR] = MCFTIMER_PCSR_OVW;
57 timerp[MCFTIMER_PMR] = lastinc = 0;
58 timerp[MCFTIMER_PCSR] =
59 (5 << 8) | MCFTIMER_PCSR_EN | MCFTIMER_PCSR_OVW;
64 void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
67 void irq_free_handler (int vec)
71 int interrupt_init (void)
73 coldfire_timer_init ();
77 void enable_interrupts ()
80 int disable_interrupts ()
85 void set_timer (ulong t)
87 volatile unsigned short *timerp;
89 timerp = (volatile unsigned short *) (MCF_MBAR + MCFTIMER_BASE4);
93 timerp[MCFTIMER_TRR] = lastinc = 0;
97 timerp[MCFTIMER_PMR] = lastinc = 0;
101 ulong get_timer (ulong base)
103 unsigned short now, diff;
104 volatile unsigned short *timerp;
106 timerp = (volatile unsigned short *) (MCF_MBAR + MCFTIMER_BASE4);
109 now = timerp[MCFTIMER_TCN];
110 diff = (now - lastinc);
114 now = timerp[MCFTIMER_PCNTR];
115 diff = -(now - lastinc);
120 return timestamp - base;
123 void wait_ticks (unsigned long ticks)
126 while (get_timer (0) < ticks);