12 #include <linux/kernel.h>
15 #include <linux/device.h>
32 static struct clk *twd_clk;
33 static unsigned long twd_timer_rate;
35 static struct clock_event_device
__percpu **twd_evt;
38 static void twd_set_mode(
enum clock_event_mode
mode,
39 struct clock_event_device *
clk)
44 case CLOCK_EVT_MODE_PERIODIC:
50 case CLOCK_EVT_MODE_ONESHOT:
54 case CLOCK_EVT_MODE_UNUSED:
55 case CLOCK_EVT_MODE_SHUTDOWN:
63 static int twd_set_next_event(
unsigned long evt,
64 struct clock_event_device *
unused)
82 static int twd_timer_ack(
void)
92 static void twd_timer_stop(
struct clock_event_device *clk)
94 twd_set_mode(CLOCK_EVT_MODE_UNUSED, clk);
98 #ifdef CONFIG_COMMON_CLK
104 static void twd_update_frequency(
void *new_rate)
106 twd_timer_rate = *((
unsigned long *) new_rate);
114 struct clk_notifier_data *cnd =
data;
121 if (flags == POST_RATE_CHANGE)
123 (
void *)&cnd->new_rate, 1);
132 static int twd_clk_init(
void)
141 #elif defined (CONFIG_CPU_FREQ)
149 static void twd_update_frequency(
void *data)
157 unsigned long state,
void *data)
177 static int twd_cpufreq_init(
void)
189 static void __cpuinit twd_calibrate_rate(
void)
198 if (twd_timer_rate == 0) {
221 twd_timer_rate = (0xFFFFFFFF
U -
count) * (
HZ / 5);
223 printk(
"%lu.%02luMHz.\n", twd_timer_rate / 1000000,
224 (twd_timer_rate / 10000) % 100);
230 struct clock_event_device *
evt = *(
struct clock_event_device **)dev_id;
232 if (twd_timer_ack()) {
233 evt->event_handler(evt);
240 static struct clk *twd_get_clock(
void)
247 pr_err(
"smp_twd: clock not found: %d\n", (
int)PTR_ERR(clk));
253 pr_err(
"smp_twd: clock failed to prepare: %d\n", err);
260 pr_err(
"smp_twd: clock failed to enable: %d\n", err);
272 static int __cpuinit twd_timer_setup(
struct clock_event_device *clk)
274 struct clock_event_device **this_cpu_clk;
277 twd_clk = twd_get_clock();
279 if (!IS_ERR_OR_NULL(twd_clk))
282 twd_calibrate_rate();
286 clk->name =
"local_timer";
287 clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
288 CLOCK_EVT_FEAT_C3STOP;
290 clk->set_mode = twd_set_mode;
291 clk->set_next_event = twd_set_next_event;
305 .setup = twd_timer_setup,
306 .stop = twd_timer_stop,
309 static int __init twd_local_timer_common_register(
void)
321 pr_err(
"twd: can't register interrupt %d (%d)\n", twd_ppi, err);
325 err = local_timer_register(&twd_lt_ops);
343 if (twd_base || twd_evt)
346 twd_ppi = tlt->
res[1].start;
348 twd_base =
ioremap(tlt->
res[0].start, resource_size(&tlt->
res[0]));
352 return twd_local_timer_common_register();
357 { .compatible =
"arm,cortex-a9-twd-timer", },
358 { .compatible =
"arm,cortex-a5-twd-timer", },
359 { .compatible =
"arm,arm11mp-twd-timer", },
363 void __init twd_local_timer_of_register(
void)
386 err = twd_local_timer_common_register();
389 WARN(err,
"twd_local_timer_of_register failed (%d)\n", err);