1 /***************************************************************************/
4 * timers.c -- generic ColdFire hardware timer support.
6 * Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
9 /***************************************************************************/
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/param.h>
15 #include <linux/interrupt.h>
16 #include <linux/init.h>
19 #include <asm/traps.h>
20 #include <asm/machdep.h>
21 #include <asm/coldfire.h>
22 #include <asm/mcftimer.h>
23 #include <asm/mcfsim.h>
25 /***************************************************************************/
28 * By default use timer1 as the system clock timer.
30 #define TA(a) (MCF_MBAR + MCFTIMER_BASE1 + (a))
33 * Default the timer and vector to use for ColdFire. Some ColdFire
34 * CPU's and some boards may want different. Their sub-architecture
35 * startup code (in config.c) can change these if they want.
37 unsigned int mcf_timervector = 29;
38 unsigned int mcf_profilevector = 31;
39 unsigned int mcf_timerlevel = 5;
42 * These provide the underlying interrupt vector support.
43 * Unfortunately it is a little different on each ColdFire.
45 extern void mcf_settimericr(int timer, int level);
46 extern int mcf_timerirqpending(int timer);
48 /***************************************************************************/
50 void coldfire_tick(void)
52 /* Reset the ColdFire timer */
53 __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, TA(MCFTIMER_TER));
56 /***************************************************************************/
58 void coldfire_timer_init(irqreturn_t (*handler)(int, void *, struct pt_regs *))
60 __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR));
61 __raw_writew(((MCF_BUSCLK / 16) / HZ), TA(MCFTIMER_TRR));
62 __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
63 MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR));
65 request_irq(mcf_timervector, handler, SA_INTERRUPT, "timer", NULL);
66 mcf_settimericr(1, mcf_timerlevel);
68 #ifdef CONFIG_HIGHPROFILE
69 coldfire_profile_init();
73 /***************************************************************************/
75 unsigned long coldfire_timer_offset(void)
77 unsigned long trr, tcn, offset;
79 tcn = __raw_readw(TA(MCFTIMER_TCN));
80 trr = __raw_readw(TA(MCFTIMER_TRR));
81 offset = (tcn * (1000000 / HZ)) / trr;
83 /* Check if we just wrapped the counters and maybe missed a tick */
84 if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1))
85 offset += 1000000 / HZ;
89 /***************************************************************************/
90 #ifdef CONFIG_HIGHPROFILE
91 /***************************************************************************/
94 * By default use timer2 as the profiler clock timer.
96 #define PA(a) (MCF_MBAR + MCFTIMER_BASE2 + (a))
99 * Choose a reasonably fast profile timer. Make it an odd value to
100 * try and get good coverage of kernal operations.
102 #define PROFILEHZ 1013
105 * Use the other timer to provide high accuracy profiling info.
107 void coldfire_profile_tick(int irq, void *dummy, struct pt_regs *regs)
109 /* Reset ColdFire timer2 */
110 __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, PA(MCFTIMER_TER));
112 profile_tick(CPU_PROFILING, regs);
115 /***************************************************************************/
117 void coldfire_profile_init(void)
119 printk(KERN_INFO "PROFILE: lodging TIMER2 @ %dHz as profile timer\n", PROFILEHZ);
121 /* Set up TIMER 2 as high speed profile clock */
122 __raw_writew(MCFTIMER_TMR_DISABLE, PA(MCFTIMER_TMR));
124 __raw_writew(((MCF_CLK / 16) / PROFILEHZ), PA(MCFTIMER_TRR));
125 __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
126 MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, PA(MCFTIMER_TMR));
128 request_irq(mcf_profilevector, coldfire_profile_tick,
129 (SA_INTERRUPT | IRQ_FLG_FAST), "profile timer", NULL);
130 mcf_settimericr(2, 7);
133 /***************************************************************************/
134 #endif /* CONFIG_HIGHPROFILE */
135 /***************************************************************************/