diff options
Diffstat (limited to 'arch/mn10300/kernel/time.c')
-rw-r--r-- | arch/mn10300/kernel/time.c | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/arch/mn10300/kernel/time.c b/arch/mn10300/kernel/time.c index 0cb9bdb3b6bd..f860a340acc9 100644 --- a/arch/mn10300/kernel/time.c +++ b/arch/mn10300/kernel/time.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include <linux/smp.h> | 17 | #include <linux/smp.h> |
18 | #include <linux/profile.h> | 18 | #include <linux/profile.h> |
19 | #include <linux/cnt32_to_63.h> | 19 | #include <linux/cnt32_to_63.h> |
20 | #include <linux/clocksource.h> | ||
21 | #include <linux/clockchips.h> | ||
20 | #include <asm/irq.h> | 22 | #include <asm/irq.h> |
21 | #include <asm/div64.h> | 23 | #include <asm/div64.h> |
22 | #include <asm/processor.h> | 24 | #include <asm/processor.h> |
@@ -27,14 +29,6 @@ | |||
27 | static unsigned long mn10300_last_tsc; /* time-stamp counter at last time | 29 | static unsigned long mn10300_last_tsc; /* time-stamp counter at last time |
28 | * interrupt occurred */ | 30 | * interrupt occurred */ |
29 | 31 | ||
30 | static irqreturn_t timer_interrupt(int irq, void *dev_id); | ||
31 | |||
32 | static struct irqaction timer_irq = { | ||
33 | .handler = timer_interrupt, | ||
34 | .flags = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER, | ||
35 | .name = "timer", | ||
36 | }; | ||
37 | |||
38 | static unsigned long sched_clock_multiplier; | 32 | static unsigned long sched_clock_multiplier; |
39 | 33 | ||
40 | /* | 34 | /* |
@@ -54,7 +48,7 @@ unsigned long long sched_clock(void) | |||
54 | 48 | ||
55 | /* read the TSC value | 49 | /* read the TSC value |
56 | */ | 50 | */ |
57 | tsc = 0 - get_cycles(); /* get_cycles() counts down */ | 51 | tsc = get_cycles(); |
58 | 52 | ||
59 | /* expand to 64-bits. | 53 | /* expand to 64-bits. |
60 | * - sched_clock() must be called once a minute or better or the | 54 | * - sched_clock() must be called once a minute or better or the |
@@ -103,6 +97,7 @@ irqreturn_t local_timer_interrupt(void) | |||
103 | return IRQ_HANDLED; | 97 | return IRQ_HANDLED; |
104 | } | 98 | } |
105 | 99 | ||
100 | #ifndef CONFIG_GENERIC_TIME | ||
106 | /* | 101 | /* |
107 | * advance the kernel's time keeping clocks (xtime and jiffies) | 102 | * advance the kernel's time keeping clocks (xtime and jiffies) |
108 | * - we use Timer 0 & 1 cascaded as a clock to nudge us the next time | 103 | * - we use Timer 0 & 1 cascaded as a clock to nudge us the next time |
@@ -116,11 +111,11 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id) | |||
116 | write_seqlock(&xtime_lock); | 111 | write_seqlock(&xtime_lock); |
117 | 112 | ||
118 | while (tsc = get_cycles(), | 113 | while (tsc = get_cycles(), |
119 | elapse = mn10300_last_tsc - tsc, /* time elapsed since last | 114 | elapse = tsc - mn10300_last_tsc, /* time elapsed since last |
120 | * tick */ | 115 | * tick */ |
121 | elapse > MN10300_TSC_PER_HZ | 116 | elapse > MN10300_TSC_PER_HZ |
122 | ) { | 117 | ) { |
123 | mn10300_last_tsc -= MN10300_TSC_PER_HZ; | 118 | mn10300_last_tsc += MN10300_TSC_PER_HZ; |
124 | 119 | ||
125 | /* advance the kernel's time tracking system */ | 120 | /* advance the kernel's time tracking system */ |
126 | do_timer(1); | 121 | do_timer(1); |
@@ -135,6 +130,50 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id) | |||
135 | return ret; | 130 | return ret; |
136 | } | 131 | } |
137 | 132 | ||
133 | static struct irqaction timer_irq = { | ||
134 | .handler = timer_interrupt, | ||
135 | .flags = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER, | ||
136 | .name = "timer", | ||
137 | }; | ||
138 | #endif /* CONFIG_GENERIC_TIME */ | ||
139 | |||
140 | #ifdef CONFIG_CSRC_MN10300 | ||
141 | void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock) | ||
142 | { | ||
143 | u64 temp; | ||
144 | u32 shift; | ||
145 | |||
146 | /* Find a shift value */ | ||
147 | for (shift = 32; shift > 0; shift--) { | ||
148 | temp = (u64) NSEC_PER_SEC << shift; | ||
149 | do_div(temp, clock); | ||
150 | if ((temp >> 32) == 0) | ||
151 | break; | ||
152 | } | ||
153 | cs->shift = shift; | ||
154 | cs->mult = (u32) temp; | ||
155 | } | ||
156 | #endif | ||
157 | |||
158 | #if CONFIG_CEVT_MN10300 | ||
159 | void __cpuinit clockevent_set_clock(struct clock_event_device *cd, | ||
160 | unsigned int clock) | ||
161 | { | ||
162 | u64 temp; | ||
163 | u32 shift; | ||
164 | |||
165 | /* Find a shift value */ | ||
166 | for (shift = 32; shift > 0; shift--) { | ||
167 | temp = (u64) clock << shift; | ||
168 | do_div(temp, NSEC_PER_SEC); | ||
169 | if ((temp >> 32) == 0) | ||
170 | break; | ||
171 | } | ||
172 | cd->shift = shift; | ||
173 | cd->mult = (u32) temp; | ||
174 | } | ||
175 | #endif | ||
176 | |||
138 | /* | 177 | /* |
139 | * initialise the various timers used by the main part of the kernel | 178 | * initialise the various timers used by the main part of the kernel |
140 | */ | 179 | */ |
@@ -146,21 +185,25 @@ void __init time_init(void) | |||
146 | */ | 185 | */ |
147 | TMPSCNT |= TMPSCNT_ENABLE; | 186 | TMPSCNT |= TMPSCNT_ENABLE; |
148 | 187 | ||
188 | #ifdef CONFIG_GENERIC_TIME | ||
189 | init_clocksource(); | ||
190 | #else | ||
149 | startup_timestamp_counter(); | 191 | startup_timestamp_counter(); |
192 | #endif | ||
150 | 193 | ||
151 | printk(KERN_INFO | 194 | printk(KERN_INFO |
152 | "timestamp counter I/O clock running at %lu.%02lu" | 195 | "timestamp counter I/O clock running at %lu.%02lu" |
153 | " (calibrated against RTC)\n", | 196 | " (calibrated against RTC)\n", |
154 | MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100); | 197 | MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100); |
155 | 198 | ||
156 | mn10300_last_tsc = TMTSCBC; | 199 | mn10300_last_tsc = read_timestamp_counter(); |
157 | 200 | ||
158 | /* use timer 0 & 1 cascaded to tick at as close to HZ as possible */ | 201 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
159 | setup_irq(TMJCIRQ, &timer_irq); | 202 | init_clockevents(); |
160 | 203 | #else | |
161 | set_intr_level(TMJCIRQ, NUM2GxICR_LEVEL(CONFIG_TIMER_IRQ_LEVEL)); | 204 | reload_jiffies_counter(MN10300_JC_PER_HZ - 1); |
162 | 205 | setup_jiffies_interrupt(TMJCIRQ, &timer_irq, CONFIG_TIMER_IRQ_LEVEL); | |
163 | startup_jiffies_counter(); | 206 | #endif |
164 | 207 | ||
165 | #ifdef CONFIG_MN10300_WD_TIMER | 208 | #ifdef CONFIG_MN10300_WD_TIMER |
166 | /* start the watchdog timer */ | 209 | /* start the watchdog timer */ |