diff options
Diffstat (limited to 'arch/sh/kernel/timers')
-rw-r--r-- | arch/sh/kernel/timers/Makefile | 1 | ||||
-rw-r--r-- | arch/sh/kernel/timers/timer-broadcast.c | 57 | ||||
-rw-r--r-- | arch/sh/kernel/timers/timer-cmt.c | 2 | ||||
-rw-r--r-- | arch/sh/kernel/timers/timer-tmu.c | 177 |
4 files changed, 178 insertions, 59 deletions
diff --git a/arch/sh/kernel/timers/Makefile b/arch/sh/kernel/timers/Makefile index bcf244ff6a12..0b7f8577193f 100644 --- a/arch/sh/kernel/timers/Makefile +++ b/arch/sh/kernel/timers/Makefile | |||
@@ -8,3 +8,4 @@ obj-$(CONFIG_SH_TMU) += timer-tmu.o | |||
8 | obj-$(CONFIG_SH_MTU2) += timer-mtu2.o | 8 | obj-$(CONFIG_SH_MTU2) += timer-mtu2.o |
9 | obj-$(CONFIG_SH_CMT) += timer-cmt.o | 9 | obj-$(CONFIG_SH_CMT) += timer-cmt.o |
10 | 10 | ||
11 | obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += timer-broadcast.o | ||
diff --git a/arch/sh/kernel/timers/timer-broadcast.c b/arch/sh/kernel/timers/timer-broadcast.c new file mode 100644 index 000000000000..c2317635230f --- /dev/null +++ b/arch/sh/kernel/timers/timer-broadcast.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * Dummy local timer | ||
3 | * | ||
4 | * Copyright (C) 2008 Paul Mundt | ||
5 | * | ||
6 | * cloned from: | ||
7 | * | ||
8 | * linux/arch/arm/mach-realview/localtimer.c | ||
9 | * | ||
10 | * Copyright (C) 2002 ARM Ltd. | ||
11 | * All Rights Reserved | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License version 2 as | ||
15 | * published by the Free Software Foundation. | ||
16 | */ | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/delay.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/smp.h> | ||
22 | #include <linux/jiffies.h> | ||
23 | #include <linux/percpu.h> | ||
24 | #include <linux/clockchips.h> | ||
25 | #include <linux/irq.h> | ||
26 | |||
27 | static DEFINE_PER_CPU(struct clock_event_device, local_clockevent); | ||
28 | |||
29 | /* | ||
30 | * Used on SMP for either the local timer or SMP_MSG_TIMER | ||
31 | */ | ||
32 | void local_timer_interrupt(void) | ||
33 | { | ||
34 | struct clock_event_device *clk = &__get_cpu_var(local_clockevent); | ||
35 | |||
36 | clk->event_handler(clk); | ||
37 | } | ||
38 | |||
39 | static void dummy_timer_set_mode(enum clock_event_mode mode, | ||
40 | struct clock_event_device *clk) | ||
41 | { | ||
42 | } | ||
43 | |||
44 | void __cpuinit local_timer_setup(unsigned int cpu) | ||
45 | { | ||
46 | struct clock_event_device *clk = &per_cpu(local_clockevent, cpu); | ||
47 | |||
48 | clk->name = "dummy_timer"; | ||
49 | clk->features = CLOCK_EVT_FEAT_DUMMY; | ||
50 | clk->rating = 200; | ||
51 | clk->mult = 1; | ||
52 | clk->set_mode = dummy_timer_set_mode; | ||
53 | clk->broadcast = smp_timer_broadcast; | ||
54 | clk->cpumask = cpumask_of_cpu(cpu); | ||
55 | |||
56 | clockevents_register_device(clk); | ||
57 | } | ||
diff --git a/arch/sh/kernel/timers/timer-cmt.c b/arch/sh/kernel/timers/timer-cmt.c index d20c8c375881..c127293271e1 100644 --- a/arch/sh/kernel/timers/timer-cmt.c +++ b/arch/sh/kernel/timers/timer-cmt.c | |||
@@ -174,7 +174,7 @@ static int cmt_timer_init(void) | |||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | 176 | ||
177 | struct sys_timer_ops cmt_timer_ops = { | 177 | static struct sys_timer_ops cmt_timer_ops = { |
178 | .init = cmt_timer_init, | 178 | .init = cmt_timer_init, |
179 | .start = cmt_timer_start, | 179 | .start = cmt_timer_start, |
180 | .stop = cmt_timer_stop, | 180 | .stop = cmt_timer_stop, |
diff --git a/arch/sh/kernel/timers/timer-tmu.c b/arch/sh/kernel/timers/timer-tmu.c index 1ca9ad49b541..aaaf90d06b85 100644 --- a/arch/sh/kernel/timers/timer-tmu.c +++ b/arch/sh/kernel/timers/timer-tmu.c | |||
@@ -28,43 +28,90 @@ | |||
28 | #define TMU_TOCR_INIT 0x00 | 28 | #define TMU_TOCR_INIT 0x00 |
29 | #define TMU_TCR_INIT 0x0020 | 29 | #define TMU_TCR_INIT 0x0020 |
30 | 30 | ||
31 | static int tmu_timer_start(void) | 31 | #define TMU0 (0) |
32 | #define TMU1 (1) | ||
33 | |||
34 | static inline void _tmu_start(int tmu_num) | ||
32 | { | 35 | { |
33 | ctrl_outb(ctrl_inb(TMU_012_TSTR) | 0x3, TMU_012_TSTR); | 36 | ctrl_outb(ctrl_inb(TMU_012_TSTR) | (0x1<<tmu_num), TMU_012_TSTR); |
34 | return 0; | ||
35 | } | 37 | } |
36 | 38 | ||
37 | static void tmu0_timer_set_interval(unsigned long interval, unsigned int reload) | 39 | static inline void _tmu_set_irq(int tmu_num, int enabled) |
38 | { | 40 | { |
39 | ctrl_outl(interval, TMU0_TCNT); | 41 | register unsigned long tmu_tcr = TMU0_TCR + (0xc*tmu_num); |
42 | ctrl_outw( (enabled ? ctrl_inw(tmu_tcr) | (1<<5) : ctrl_inw(tmu_tcr) & ~(1<<5)), tmu_tcr); | ||
43 | } | ||
40 | 44 | ||
41 | /* | 45 | static inline void _tmu_stop(int tmu_num) |
42 | * TCNT reloads from TCOR on underflow, clear it if we don't | 46 | { |
43 | * intend to auto-reload | 47 | ctrl_outb(ctrl_inb(TMU_012_TSTR) & ~(0x1<<tmu_num), TMU_012_TSTR); |
44 | */ | 48 | } |
45 | if (reload) | 49 | |
46 | ctrl_outl(interval, TMU0_TCOR); | 50 | static inline void _tmu_clear_status(int tmu_num) |
47 | else | 51 | { |
48 | ctrl_outl(0, TMU0_TCOR); | 52 | register unsigned long tmu_tcr = TMU0_TCR + (0xc*tmu_num); |
53 | /* Clear UNF bit */ | ||
54 | ctrl_outw(ctrl_inw(tmu_tcr) & ~0x100, tmu_tcr); | ||
55 | } | ||
49 | 56 | ||
50 | tmu_timer_start(); | 57 | static inline unsigned long _tmu_read(int tmu_num) |
58 | { | ||
59 | return ctrl_inl(TMU0_TCNT+0xC*tmu_num); | ||
60 | } | ||
61 | |||
62 | static int tmu_timer_start(void) | ||
63 | { | ||
64 | _tmu_start(TMU0); | ||
65 | _tmu_start(TMU1); | ||
66 | _tmu_set_irq(TMU0,1); | ||
67 | return 0; | ||
51 | } | 68 | } |
52 | 69 | ||
53 | static int tmu_timer_stop(void) | 70 | static int tmu_timer_stop(void) |
54 | { | 71 | { |
55 | ctrl_outb(ctrl_inb(TMU_012_TSTR) & ~0x3, TMU_012_TSTR); | 72 | _tmu_stop(TMU0); |
73 | _tmu_stop(TMU1); | ||
74 | _tmu_clear_status(TMU0); | ||
56 | return 0; | 75 | return 0; |
57 | } | 76 | } |
58 | 77 | ||
78 | /* | ||
79 | * also when the module_clk is scaled the TMU1 | ||
80 | * will show the same frequency | ||
81 | */ | ||
82 | static int tmus_are_scaled; | ||
83 | |||
59 | static cycle_t tmu_timer_read(void) | 84 | static cycle_t tmu_timer_read(void) |
60 | { | 85 | { |
61 | return ~ctrl_inl(TMU1_TCNT); | 86 | return ((cycle_t)(~_tmu_read(TMU1)))<<tmus_are_scaled; |
87 | } | ||
88 | |||
89 | |||
90 | static unsigned long tmu_latest_interval[3]; | ||
91 | static void tmu_timer_set_interval(int tmu_num, unsigned long interval, unsigned int reload) | ||
92 | { | ||
93 | unsigned long tmu_tcnt = TMU0_TCNT + tmu_num*0xC; | ||
94 | unsigned long tmu_tcor = TMU0_TCOR + tmu_num*0xC; | ||
95 | |||
96 | _tmu_stop(tmu_num); | ||
97 | |||
98 | ctrl_outl(interval, tmu_tcnt); | ||
99 | tmu_latest_interval[tmu_num] = interval; | ||
100 | |||
101 | /* | ||
102 | * TCNT reloads from TCOR on underflow, clear it if we don't | ||
103 | * intend to auto-reload | ||
104 | */ | ||
105 | ctrl_outl( reload ? interval : 0 , tmu_tcor); | ||
106 | |||
107 | _tmu_start(tmu_num); | ||
62 | } | 108 | } |
63 | 109 | ||
64 | static int tmu_set_next_event(unsigned long cycles, | 110 | static int tmu_set_next_event(unsigned long cycles, |
65 | struct clock_event_device *evt) | 111 | struct clock_event_device *evt) |
66 | { | 112 | { |
67 | tmu0_timer_set_interval(cycles, 1); | 113 | tmu_timer_set_interval(TMU0,cycles, evt->mode == CLOCK_EVT_MODE_PERIODIC); |
114 | _tmu_set_irq(TMU0,1); | ||
68 | return 0; | 115 | return 0; |
69 | } | 116 | } |
70 | 117 | ||
@@ -96,12 +143,8 @@ static struct clock_event_device tmu0_clockevent = { | |||
96 | static irqreturn_t tmu_timer_interrupt(int irq, void *dummy) | 143 | static irqreturn_t tmu_timer_interrupt(int irq, void *dummy) |
97 | { | 144 | { |
98 | struct clock_event_device *evt = &tmu0_clockevent; | 145 | struct clock_event_device *evt = &tmu0_clockevent; |
99 | unsigned long timer_status; | 146 | _tmu_clear_status(TMU0); |
100 | 147 | _tmu_set_irq(TMU0,tmu0_clockevent.mode != CLOCK_EVT_MODE_ONESHOT); | |
101 | /* Clear UNF bit */ | ||
102 | timer_status = ctrl_inw(TMU0_TCR); | ||
103 | timer_status &= ~0x100; | ||
104 | ctrl_outw(timer_status, TMU0_TCR); | ||
105 | 148 | ||
106 | evt->event_handler(evt); | 149 | evt->event_handler(evt); |
107 | 150 | ||
@@ -109,56 +152,73 @@ static irqreturn_t tmu_timer_interrupt(int irq, void *dummy) | |||
109 | } | 152 | } |
110 | 153 | ||
111 | static struct irqaction tmu0_irq = { | 154 | static struct irqaction tmu0_irq = { |
112 | .name = "periodic timer", | 155 | .name = "periodic/oneshot timer", |
113 | .handler = tmu_timer_interrupt, | 156 | .handler = tmu_timer_interrupt, |
114 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, | 157 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
115 | .mask = CPU_MASK_NONE, | 158 | .mask = CPU_MASK_NONE, |
116 | }; | 159 | }; |
117 | 160 | ||
118 | static void tmu0_clk_init(struct clk *clk) | 161 | static void __init tmu_clk_init(struct clk *clk) |
119 | { | 162 | { |
120 | u8 divisor = TMU_TCR_INIT & 0x7; | 163 | u8 divisor = TMU_TCR_INIT & 0x7; |
121 | ctrl_outw(TMU_TCR_INIT, TMU0_TCR); | 164 | int tmu_num = clk->name[3]-'0'; |
122 | clk->rate = clk->parent->rate / (4 << (divisor << 1)); | 165 | ctrl_outw(TMU_TCR_INIT, TMU0_TCR+(tmu_num*0xC)); |
166 | clk->rate = clk_get_rate(clk->parent) / (4 << (divisor << 1)); | ||
123 | } | 167 | } |
124 | 168 | ||
125 | static void tmu0_clk_recalc(struct clk *clk) | 169 | static void tmu_clk_recalc(struct clk *clk) |
126 | { | 170 | { |
127 | u8 divisor = ctrl_inw(TMU0_TCR) & 0x7; | 171 | int tmu_num = clk->name[3]-'0'; |
128 | clk->rate = clk->parent->rate / (4 << (divisor << 1)); | 172 | unsigned long prev_rate = clk_get_rate(clk); |
129 | } | 173 | unsigned long flags; |
174 | u8 divisor = ctrl_inw(TMU0_TCR+tmu_num*0xC) & 0x7; | ||
175 | clk->rate = clk_get_rate(clk->parent) / (4 << (divisor << 1)); | ||
130 | 176 | ||
131 | static struct clk_ops tmu0_clk_ops = { | 177 | if(prev_rate==clk_get_rate(clk)) |
132 | .init = tmu0_clk_init, | 178 | return; |
133 | .recalc = tmu0_clk_recalc, | ||
134 | }; | ||
135 | 179 | ||
136 | static struct clk tmu0_clk = { | 180 | if(tmu_num) |
137 | .name = "tmu0_clk", | 181 | return; /* No more work on TMU1 */ |
138 | .ops = &tmu0_clk_ops, | ||
139 | }; | ||
140 | 182 | ||
141 | static void tmu1_clk_init(struct clk *clk) | 183 | local_irq_save(flags); |
142 | { | 184 | tmus_are_scaled = (prev_rate > clk->rate); |
143 | u8 divisor = TMU_TCR_INIT & 0x7; | ||
144 | ctrl_outw(divisor, TMU1_TCR); | ||
145 | clk->rate = clk->parent->rate / (4 << (divisor << 1)); | ||
146 | } | ||
147 | 185 | ||
148 | static void tmu1_clk_recalc(struct clk *clk) | 186 | _tmu_stop(TMU0); |
149 | { | 187 | |
150 | u8 divisor = ctrl_inw(TMU1_TCR) & 0x7; | 188 | tmu0_clockevent.mult = div_sc(clk->rate, NSEC_PER_SEC, |
151 | clk->rate = clk->parent->rate / (4 << (divisor << 1)); | 189 | tmu0_clockevent.shift); |
190 | tmu0_clockevent.max_delta_ns = | ||
191 | clockevent_delta2ns(-1, &tmu0_clockevent); | ||
192 | tmu0_clockevent.min_delta_ns = | ||
193 | clockevent_delta2ns(1, &tmu0_clockevent); | ||
194 | |||
195 | if (tmus_are_scaled) | ||
196 | tmu_latest_interval[TMU0] >>= 1; | ||
197 | else | ||
198 | tmu_latest_interval[TMU0] <<= 1; | ||
199 | |||
200 | tmu_timer_set_interval(TMU0, | ||
201 | tmu_latest_interval[TMU0], | ||
202 | tmu0_clockevent.mode == CLOCK_EVT_MODE_PERIODIC); | ||
203 | |||
204 | _tmu_start(TMU0); | ||
205 | |||
206 | local_irq_restore(flags); | ||
152 | } | 207 | } |
153 | 208 | ||
154 | static struct clk_ops tmu1_clk_ops = { | 209 | static struct clk_ops tmu_clk_ops = { |
155 | .init = tmu1_clk_init, | 210 | .init = tmu_clk_init, |
156 | .recalc = tmu1_clk_recalc, | 211 | .recalc = tmu_clk_recalc, |
212 | }; | ||
213 | |||
214 | static struct clk tmu0_clk = { | ||
215 | .name = "tmu0_clk", | ||
216 | .ops = &tmu_clk_ops, | ||
157 | }; | 217 | }; |
158 | 218 | ||
159 | static struct clk tmu1_clk = { | 219 | static struct clk tmu1_clk = { |
160 | .name = "tmu1_clk", | 220 | .name = "tmu1_clk", |
161 | .ops = &tmu1_clk_ops, | 221 | .ops = &tmu_clk_ops, |
162 | }; | 222 | }; |
163 | 223 | ||
164 | static int tmu_timer_init(void) | 224 | static int tmu_timer_init(void) |
@@ -189,11 +249,12 @@ static int tmu_timer_init(void) | |||
189 | frequency = clk_get_rate(&tmu0_clk); | 249 | frequency = clk_get_rate(&tmu0_clk); |
190 | interval = (frequency + HZ / 2) / HZ; | 250 | interval = (frequency + HZ / 2) / HZ; |
191 | 251 | ||
192 | sh_hpt_frequency = clk_get_rate(&tmu1_clk); | 252 | tmu_timer_set_interval(TMU0,interval, 1); |
193 | ctrl_outl(~0, TMU1_TCNT); | 253 | tmu_timer_set_interval(TMU1,~0,1); |
194 | ctrl_outl(~0, TMU1_TCOR); | ||
195 | 254 | ||
196 | tmu0_timer_set_interval(interval, 1); | 255 | _tmu_start(TMU1); |
256 | |||
257 | sh_hpt_frequency = clk_get_rate(&tmu1_clk); | ||
197 | 258 | ||
198 | tmu0_clockevent.mult = div_sc(frequency, NSEC_PER_SEC, | 259 | tmu0_clockevent.mult = div_sc(frequency, NSEC_PER_SEC, |
199 | tmu0_clockevent.shift); | 260 | tmu0_clockevent.shift); |