aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mn10300/kernel/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mn10300/kernel/time.c')
-rw-r--r--arch/mn10300/kernel/time.c112
1 files changed, 85 insertions, 27 deletions
diff --git a/arch/mn10300/kernel/time.c b/arch/mn10300/kernel/time.c
index 8f7f6d22783d..f860a340acc9 100644
--- a/arch/mn10300/kernel/time.c
+++ b/arch/mn10300/kernel/time.c
@@ -17,29 +17,18 @@
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>
23#include <asm/intctl-regs.h> 25#include <asm/intctl-regs.h>
24#include <asm/rtc.h> 26#include <asm/rtc.h>
25 27#include "internal.h"
26#ifdef CONFIG_MN10300_RTC
27unsigned long mn10300_ioclk; /* system I/O clock frequency */
28unsigned long mn10300_iobclk; /* system I/O clock frequency */
29unsigned long mn10300_tsc_per_HZ; /* number of ioclks per jiffy */
30#endif /* CONFIG_MN10300_RTC */
31 28
32static unsigned long mn10300_last_tsc; /* time-stamp counter at last time 29static unsigned long mn10300_last_tsc; /* time-stamp counter at last time
33 * interrupt occurred */ 30 * interrupt occurred */
34 31
35static irqreturn_t timer_interrupt(int irq, void *dev_id);
36
37static struct irqaction timer_irq = {
38 .handler = timer_interrupt,
39 .flags = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER,
40 .name = "timer",
41};
42
43static unsigned long sched_clock_multiplier; 32static unsigned long sched_clock_multiplier;
44 33
45/* 34/*
@@ -54,9 +43,12 @@ unsigned long long sched_clock(void)
54 unsigned long tsc, tmp; 43 unsigned long tsc, tmp;
55 unsigned product[3]; /* 96-bit intermediate value */ 44 unsigned product[3]; /* 96-bit intermediate value */
56 45
46 /* cnt32_to_63() is not safe with preemption */
47 preempt_disable();
48
57 /* read the TSC value 49 /* read the TSC value
58 */ 50 */
59 tsc = 0 - get_cycles(); /* get_cycles() counts down */ 51 tsc = get_cycles();
60 52
61 /* expand to 64-bits. 53 /* expand to 64-bits.
62 * - 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
@@ -64,6 +56,8 @@ unsigned long long sched_clock(void)
64 */ 56 */
65 tsc64.ll = cnt32_to_63(tsc) & 0x7fffffffffffffffULL; 57 tsc64.ll = cnt32_to_63(tsc) & 0x7fffffffffffffffULL;
66 58
59 preempt_enable();
60
67 /* scale the 64-bit TSC value to a nanosecond value via a 96-bit 61 /* scale the 64-bit TSC value to a nanosecond value via a 96-bit
68 * intermediate 62 * intermediate
69 */ 63 */
@@ -90,6 +84,20 @@ static void __init mn10300_sched_clock_init(void)
90 __muldiv64u(NSEC_PER_SEC, 1 << 16, MN10300_TSCCLK); 84 __muldiv64u(NSEC_PER_SEC, 1 << 16, MN10300_TSCCLK);
91} 85}
92 86
87/**
88 * local_timer_interrupt - Local timer interrupt handler
89 *
90 * Handle local timer interrupts for this CPU. They may have been propagated
91 * to this CPU from the CPU that actually gets them by way of an IPI.
92 */
93irqreturn_t local_timer_interrupt(void)
94{
95 profile_tick(CPU_PROFILING);
96 update_process_times(user_mode(get_irq_regs()));
97 return IRQ_HANDLED;
98}
99
100#ifndef CONFIG_GENERIC_TIME
93/* 101/*
94 * advance the kernel's time keeping clocks (xtime and jiffies) 102 * advance the kernel's time keeping clocks (xtime and jiffies)
95 * - 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
@@ -98,27 +106,73 @@ static void __init mn10300_sched_clock_init(void)
98static irqreturn_t timer_interrupt(int irq, void *dev_id) 106static irqreturn_t timer_interrupt(int irq, void *dev_id)
99{ 107{
100 unsigned tsc, elapse; 108 unsigned tsc, elapse;
109 irqreturn_t ret;
101 110
102 write_seqlock(&xtime_lock); 111 write_seqlock(&xtime_lock);
103 112
104 while (tsc = get_cycles(), 113 while (tsc = get_cycles(),
105 elapse = mn10300_last_tsc - tsc, /* time elapsed since last 114 elapse = tsc - mn10300_last_tsc, /* time elapsed since last
106 * tick */ 115 * tick */
107 elapse > MN10300_TSC_PER_HZ 116 elapse > MN10300_TSC_PER_HZ
108 ) { 117 ) {
109 mn10300_last_tsc -= MN10300_TSC_PER_HZ; 118 mn10300_last_tsc += MN10300_TSC_PER_HZ;
110 119
111 /* advance the kernel's time tracking system */ 120 /* advance the kernel's time tracking system */
112 profile_tick(CPU_PROFILING);
113 do_timer(1); 121 do_timer(1);
114 } 122 }
115 123
116 write_sequnlock(&xtime_lock); 124 write_sequnlock(&xtime_lock);
117 125
118 update_process_times(user_mode(get_irq_regs())); 126 ret = local_timer_interrupt();
127#ifdef CONFIG_SMP
128 send_IPI_allbutself(LOCAL_TIMER_IPI);
129#endif
130 return ret;
131}
119 132
120 return IRQ_HANDLED; 133static 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
141void __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;
121} 155}
156#endif
157
158#if CONFIG_CEVT_MN10300
159void __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
122 176
123/* 177/*
124 * 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
@@ -131,21 +185,25 @@ void __init time_init(void)
131 */ 185 */
132 TMPSCNT |= TMPSCNT_ENABLE; 186 TMPSCNT |= TMPSCNT_ENABLE;
133 187
188#ifdef CONFIG_GENERIC_TIME
189 init_clocksource();
190#else
134 startup_timestamp_counter(); 191 startup_timestamp_counter();
192#endif
135 193
136 printk(KERN_INFO 194 printk(KERN_INFO
137 "timestamp counter I/O clock running at %lu.%02lu" 195 "timestamp counter I/O clock running at %lu.%02lu"
138 " (calibrated against RTC)\n", 196 " (calibrated against RTC)\n",
139 MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100); 197 MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100);
140 198
141 mn10300_last_tsc = TMTSCBC; 199 mn10300_last_tsc = read_timestamp_counter();
142
143 /* use timer 0 & 1 cascaded to tick at as close to HZ as possible */
144 setup_irq(TMJCIRQ, &timer_irq);
145 200
146 set_intr_level(TMJCIRQ, TMJCICR_LEVEL); 201#ifdef CONFIG_GENERIC_CLOCKEVENTS
147 202 init_clockevents();
148 startup_jiffies_counter(); 203#else
204 reload_jiffies_counter(MN10300_JC_PER_HZ - 1);
205 setup_jiffies_interrupt(TMJCIRQ, &timer_irq, CONFIG_TIMER_IRQ_LEVEL);
206#endif
149 207
150#ifdef CONFIG_MN10300_WD_TIMER 208#ifdef CONFIG_MN10300_WD_TIMER
151 /* start the watchdog timer */ 209 /* start the watchdog timer */