]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /***************************************************************************/ |
2 | ||
3 | /* | |
4 | * timers.c -- generic ColdFire hardware timer support. | |
5 | * | |
a7f61fa4 | 6 | * Copyright (C) 1999-2008, Greg Ungerer <gerg@snapgear.com> |
1da177e4 LT |
7 | */ |
8 | ||
9 | /***************************************************************************/ | |
10 | ||
1da177e4 | 11 | #include <linux/kernel.h> |
2f2c2679 | 12 | #include <linux/init.h> |
1da177e4 | 13 | #include <linux/sched.h> |
1da177e4 | 14 | #include <linux/interrupt.h> |
c52a2cda | 15 | #include <linux/irq.h> |
a7f61fa4 GU |
16 | #include <linux/profile.h> |
17 | #include <linux/clocksource.h> | |
0b7ac8e4 | 18 | #include <asm/io.h> |
1da177e4 LT |
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> | |
24 | ||
25 | /***************************************************************************/ | |
26 | ||
0b7ac8e4 GU |
27 | /* |
28 | * By default use timer1 as the system clock timer. | |
29 | */ | |
a7f61fa4 | 30 | #define FREQ (MCF_BUSCLK / 16) |
0b7ac8e4 GU |
31 | #define TA(a) (MCF_MBAR + MCFTIMER_BASE1 + (a)) |
32 | ||
1da177e4 LT |
33 | /* |
34 | * Default the timer and vector to use for ColdFire. Some ColdFire | |
35 | * CPU's and some boards may want different. Their sub-architecture | |
36 | * startup code (in config.c) can change these if they want. | |
37 | */ | |
38 | unsigned int mcf_timervector = 29; | |
39 | unsigned int mcf_profilevector = 31; | |
40 | unsigned int mcf_timerlevel = 5; | |
41 | ||
1da177e4 LT |
42 | /* |
43 | * These provide the underlying interrupt vector support. | |
44 | * Unfortunately it is a little different on each ColdFire. | |
45 | */ | |
46 | extern void mcf_settimericr(int timer, int level); | |
a7f61fa4 | 47 | void coldfire_profile_init(void); |
1da177e4 | 48 | |
deb77c85 GU |
49 | #if defined(CONFIG_M532x) |
50 | #define __raw_readtrr __raw_readl | |
51 | #define __raw_writetrr __raw_writel | |
52 | #else | |
53 | #define __raw_readtrr __raw_readw | |
54 | #define __raw_writetrr __raw_writew | |
55 | #endif | |
56 | ||
a7f61fa4 GU |
57 | static u32 mcftmr_cycles_per_jiffy; |
58 | static u32 mcftmr_cnt; | |
59 | ||
1da177e4 LT |
60 | /***************************************************************************/ |
61 | ||
a7f61fa4 | 62 | static irqreturn_t mcftmr_tick(int irq, void *dummy) |
1da177e4 LT |
63 | { |
64 | /* Reset the ColdFire timer */ | |
0b7ac8e4 | 65 | __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, TA(MCFTIMER_TER)); |
2f2c2679 | 66 | |
a7f61fa4 | 67 | mcftmr_cnt += mcftmr_cycles_per_jiffy; |
2f2c2679 | 68 | return arch_timer_interrupt(irq, dummy); |
1da177e4 LT |
69 | } |
70 | ||
71 | /***************************************************************************/ | |
72 | ||
a7f61fa4 | 73 | static struct irqaction mcftmr_timer_irq = { |
2f2c2679 GU |
74 | .name = "timer", |
75 | .flags = IRQF_DISABLED | IRQF_TIMER, | |
a7f61fa4 | 76 | .handler = mcftmr_tick, |
c52a2cda GU |
77 | }; |
78 | ||
2f2c2679 GU |
79 | /***************************************************************************/ |
80 | ||
a7f61fa4 GU |
81 | static cycle_t mcftmr_read_clk(void) |
82 | { | |
83 | unsigned long flags; | |
84 | u32 cycles; | |
85 | u16 tcn; | |
86 | ||
87 | local_irq_save(flags); | |
88 | tcn = __raw_readw(TA(MCFTIMER_TCN)); | |
89 | cycles = mcftmr_cnt; | |
90 | local_irq_restore(flags); | |
91 | ||
92 | return cycles + tcn; | |
93 | } | |
94 | ||
95 | /***************************************************************************/ | |
96 | ||
97 | static struct clocksource mcftmr_clk = { | |
98 | .name = "tmr", | |
99 | .rating = 250, | |
100 | .read = mcftmr_read_clk, | |
101 | .shift = 20, | |
102 | .mask = CLOCKSOURCE_MASK(32), | |
103 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | |
104 | }; | |
105 | ||
106 | /***************************************************************************/ | |
4342f4ac | 107 | |
2f2c2679 | 108 | void hw_timer_init(void) |
1da177e4 | 109 | { |
a7f61fa4 | 110 | setup_irq(mcf_timervector, &mcftmr_timer_irq); |
c52a2cda | 111 | |
0b7ac8e4 | 112 | __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR)); |
a7f61fa4 GU |
113 | mcftmr_cycles_per_jiffy = FREQ / HZ; |
114 | __raw_writetrr(mcftmr_cycles_per_jiffy, TA(MCFTIMER_TRR)); | |
0b7ac8e4 GU |
115 | __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | |
116 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR)); | |
1da177e4 | 117 | |
a7f61fa4 GU |
118 | mcftmr_clk.mult = clocksource_hz2mult(FREQ, mcftmr_clk.shift); |
119 | clocksource_register(&mcftmr_clk); | |
120 | ||
1da177e4 LT |
121 | mcf_settimericr(1, mcf_timerlevel); |
122 | ||
123 | #ifdef CONFIG_HIGHPROFILE | |
124 | coldfire_profile_init(); | |
125 | #endif | |
126 | } | |
127 | ||
1da177e4 LT |
128 | /***************************************************************************/ |
129 | #ifdef CONFIG_HIGHPROFILE | |
130 | /***************************************************************************/ | |
131 | ||
0b7ac8e4 GU |
132 | /* |
133 | * By default use timer2 as the profiler clock timer. | |
134 | */ | |
135 | #define PA(a) (MCF_MBAR + MCFTIMER_BASE2 + (a)) | |
136 | ||
1da177e4 LT |
137 | /* |
138 | * Choose a reasonably fast profile timer. Make it an odd value to | |
d08df601 | 139 | * try and get good coverage of kernel operations. |
1da177e4 LT |
140 | */ |
141 | #define PROFILEHZ 1013 | |
142 | ||
1da177e4 LT |
143 | /* |
144 | * Use the other timer to provide high accuracy profiling info. | |
145 | */ | |
c051b011 | 146 | irqreturn_t coldfire_profile_tick(int irq, void *dummy) |
1da177e4 LT |
147 | { |
148 | /* Reset ColdFire timer2 */ | |
0b7ac8e4 | 149 | __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, PA(MCFTIMER_TER)); |
1da177e4 | 150 | if (current->pid) |
6ef1e567 | 151 | profile_tick(CPU_PROFILING); |
c051b011 | 152 | return IRQ_HANDLED; |
1da177e4 LT |
153 | } |
154 | ||
155 | /***************************************************************************/ | |
156 | ||
6ef1e567 MW |
157 | static struct irqaction coldfire_profile_irq = { |
158 | .name = "profile timer", | |
159 | .flags = IRQF_DISABLED | IRQF_TIMER, | |
160 | .handler = coldfire_profile_tick, | |
161 | }; | |
162 | ||
1da177e4 LT |
163 | void coldfire_profile_init(void) |
164 | { | |
6ef1e567 MW |
165 | printk(KERN_INFO "PROFILE: lodging TIMER2 @ %dHz as profile timer\n", |
166 | PROFILEHZ); | |
167 | ||
168 | setup_irq(mcf_profilevector, &coldfire_profile_irq); | |
1da177e4 LT |
169 | |
170 | /* Set up TIMER 2 as high speed profile clock */ | |
0b7ac8e4 | 171 | __raw_writew(MCFTIMER_TMR_DISABLE, PA(MCFTIMER_TMR)); |
1da177e4 | 172 | |
6ef1e567 | 173 | __raw_writetrr(((MCF_BUSCLK / 16) / PROFILEHZ), PA(MCFTIMER_TRR)); |
0b7ac8e4 GU |
174 | __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | |
175 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, PA(MCFTIMER_TMR)); | |
1da177e4 | 176 | |
1da177e4 LT |
177 | mcf_settimericr(2, 7); |
178 | } | |
179 | ||
180 | /***************************************************************************/ | |
181 | #endif /* CONFIG_HIGHPROFILE */ | |
182 | /***************************************************************************/ |