21 #include <linux/kernel.h>
23 #include <linux/device.h>
36 static u32 arch_timer_rate;
39 static int arch_timer_ppi;
50 evt->event_handler(evt);
57 static void arch_timer_stop(
void)
66 static void arch_timer_set_mode(
enum clock_event_mode
mode,
67 struct clock_event_device *
clk)
70 case CLOCK_EVT_MODE_UNUSED:
71 case CLOCK_EVT_MODE_SHUTDOWN:
79 static int arch_timer_set_next_event(
unsigned long evt,
80 struct clock_event_device *
unused)
94 static void __cpuinit arch_timer_setup(
struct clock_event_device *clk)
99 clk->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_C3STOP;
100 clk->name =
"arch_sys_timer";
102 clk->set_mode = arch_timer_set_mode;
103 clk->set_next_event = arch_timer_set_next_event;
104 clk->irq = arch_timer_ppi;
113 arch_counter_enable_user_access();
116 static void __init arch_timer_calibrate(
void)
118 if (arch_timer_rate == 0) {
123 if (arch_timer_rate == 0)
124 panic(
"Architected timer frequency is set to zero.\n"
125 "You must set this in your .dts file\n");
132 pr_info(
"Architected local timer running at %u.%02uMHz.\n",
133 arch_timer_rate / 1000000, (arch_timer_rate / 10000) % 100);
138 return arch_counter_get_cntpct();
142 .name =
"arch_sys_counter",
144 .read = arch_counter_read,
151 *timer_value = arch_counter_get_cntpct();
157 return arch_counter_get_cntvct() * sched_clock_mult;
161 unsigned long action,
void *hcpu)
164 struct clock_event_device *clk =
per_cpu_ptr(&arch_timer_evt, cpu);
169 arch_timer_setup(clk);
174 pr_debug(
"arch_timer_teardown disable IRQ%d cpu #%d\n",
177 arch_timer_set_mode(CLOCK_EVT_MODE_UNUSED, clk);
185 .notifier_call = arch_timer_cpu_notify,
189 { .compatible =
"arm,armv8-timer" },
201 pr_err(
"arch_timer: can't find DT node\n");
206 if (!of_property_read_u32(np,
"clock-frequency", &freq))
207 arch_timer_rate =
freq;
208 arch_timer_calibrate();
211 pr_info(
"arch_timer: found %s irq %d\n", np->
name, arch_timer_ppi);
214 np->
name, &arch_timer_evt);
216 pr_err(
"arch_timer: can't register interrupt %d (%d)\n",
217 arch_timer_ppi, err);
221 clocksource_register_hz(&clocksource_counter, arch_timer_rate);
229 register_cpu_notifier(&arch_timer_cpu_nb);