aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2013-08-21 08:59:23 -0400
committerThomas Gleixner <tglx@linutronix.de>2013-08-21 08:59:23 -0400
commitcfb6d656d569510ac9239583ce09e4c92ad54719 (patch)
treef80d4526a5a293d69a0262b04890ba296c8874ab /drivers
parentfac778a2b8d6ca953d440baeee72901c2dd5aad9 (diff)
parent220069945b298d3998c6598b081c466dca259929 (diff)
Merge branch 'timers/clockevents-next' of git://git.linaro.org/people/dlezcano/clockevents into timers/core
* Support for memory mapped arch_timers * Trivial fixes to the moxart timer code * Documentation updates Trivial conflicts in drivers/clocksource/arm_arch_timer.c. Fixed up the newly added __cpuinit annotations as well. Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/clocksource/arm_arch_timer.c447
-rw-r--r--drivers/clocksource/moxart_timer.c1
2 files changed, 379 insertions, 69 deletions
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index ffadd836e0b5..fbd9ccd5e114 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -16,13 +16,39 @@
16#include <linux/clockchips.h> 16#include <linux/clockchips.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/of_irq.h> 18#include <linux/of_irq.h>
19#include <linux/of_address.h>
19#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/slab.h>
20 22
21#include <asm/arch_timer.h> 23#include <asm/arch_timer.h>
22#include <asm/virt.h> 24#include <asm/virt.h>
23 25
24#include <clocksource/arm_arch_timer.h> 26#include <clocksource/arm_arch_timer.h>
25 27
28#define CNTTIDR 0x08
29#define CNTTIDR_VIRT(n) (BIT(1) << ((n) * 4))
30
31#define CNTVCT_LO 0x08
32#define CNTVCT_HI 0x0c
33#define CNTFRQ 0x10
34#define CNTP_TVAL 0x28
35#define CNTP_CTL 0x2c
36#define CNTV_TVAL 0x38
37#define CNTV_CTL 0x3c
38
39#define ARCH_CP15_TIMER BIT(0)
40#define ARCH_MEM_TIMER BIT(1)
41static unsigned arch_timers_present __initdata;
42
43static void __iomem *arch_counter_base;
44
45struct arch_timer {
46 void __iomem *base;
47 struct clock_event_device evt;
48};
49
50#define to_arch_timer(e) container_of(e, struct arch_timer, evt)
51
26static u32 arch_timer_rate; 52static u32 arch_timer_rate;
27 53
28enum ppi_nr { 54enum ppi_nr {
@@ -38,19 +64,83 @@ static int arch_timer_ppi[MAX_TIMER_PPI];
38static struct clock_event_device __percpu *arch_timer_evt; 64static struct clock_event_device __percpu *arch_timer_evt;
39 65
40static bool arch_timer_use_virtual = true; 66static bool arch_timer_use_virtual = true;
67static bool arch_timer_mem_use_virtual;
41 68
42/* 69/*
43 * Architected system timer support. 70 * Architected system timer support.
44 */ 71 */
45 72
46static inline irqreturn_t timer_handler(const int access, 73static __always_inline
74void arch_timer_reg_write(int access, enum arch_timer_reg reg, u32 val,
75 struct clock_event_device *clk)
76{
77 if (access == ARCH_TIMER_MEM_PHYS_ACCESS) {
78 struct arch_timer *timer = to_arch_timer(clk);
79 switch (reg) {
80 case ARCH_TIMER_REG_CTRL:
81 writel_relaxed(val, timer->base + CNTP_CTL);
82 break;
83 case ARCH_TIMER_REG_TVAL:
84 writel_relaxed(val, timer->base + CNTP_TVAL);
85 break;
86 }
87 } else if (access == ARCH_TIMER_MEM_VIRT_ACCESS) {
88 struct arch_timer *timer = to_arch_timer(clk);
89 switch (reg) {
90 case ARCH_TIMER_REG_CTRL:
91 writel_relaxed(val, timer->base + CNTV_CTL);
92 break;
93 case ARCH_TIMER_REG_TVAL:
94 writel_relaxed(val, timer->base + CNTV_TVAL);
95 break;
96 }
97 } else {
98 arch_timer_reg_write_cp15(access, reg, val);
99 }
100}
101
102static __always_inline
103u32 arch_timer_reg_read(int access, enum arch_timer_reg reg,
104 struct clock_event_device *clk)
105{
106 u32 val;
107
108 if (access == ARCH_TIMER_MEM_PHYS_ACCESS) {
109 struct arch_timer *timer = to_arch_timer(clk);
110 switch (reg) {
111 case ARCH_TIMER_REG_CTRL:
112 val = readl_relaxed(timer->base + CNTP_CTL);
113 break;
114 case ARCH_TIMER_REG_TVAL:
115 val = readl_relaxed(timer->base + CNTP_TVAL);
116 break;
117 }
118 } else if (access == ARCH_TIMER_MEM_VIRT_ACCESS) {
119 struct arch_timer *timer = to_arch_timer(clk);
120 switch (reg) {
121 case ARCH_TIMER_REG_CTRL:
122 val = readl_relaxed(timer->base + CNTV_CTL);
123 break;
124 case ARCH_TIMER_REG_TVAL:
125 val = readl_relaxed(timer->base + CNTV_TVAL);
126 break;
127 }
128 } else {
129 val = arch_timer_reg_read_cp15(access, reg);
130 }
131
132 return val;
133}
134
135static __always_inline irqreturn_t timer_handler(const int access,
47 struct clock_event_device *evt) 136 struct clock_event_device *evt)
48{ 137{
49 unsigned long ctrl; 138 unsigned long ctrl;
50 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL); 139
140 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, evt);
51 if (ctrl & ARCH_TIMER_CTRL_IT_STAT) { 141 if (ctrl & ARCH_TIMER_CTRL_IT_STAT) {
52 ctrl |= ARCH_TIMER_CTRL_IT_MASK; 142 ctrl |= ARCH_TIMER_CTRL_IT_MASK;
53 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl); 143 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, evt);
54 evt->event_handler(evt); 144 evt->event_handler(evt);
55 return IRQ_HANDLED; 145 return IRQ_HANDLED;
56 } 146 }
@@ -72,15 +162,30 @@ static irqreturn_t arch_timer_handler_phys(int irq, void *dev_id)
72 return timer_handler(ARCH_TIMER_PHYS_ACCESS, evt); 162 return timer_handler(ARCH_TIMER_PHYS_ACCESS, evt);
73} 163}
74 164
75static inline void timer_set_mode(const int access, int mode) 165static irqreturn_t arch_timer_handler_phys_mem(int irq, void *dev_id)
166{
167 struct clock_event_device *evt = dev_id;
168
169 return timer_handler(ARCH_TIMER_MEM_PHYS_ACCESS, evt);
170}
171
172static irqreturn_t arch_timer_handler_virt_mem(int irq, void *dev_id)
173{
174 struct clock_event_device *evt = dev_id;
175
176 return timer_handler(ARCH_TIMER_MEM_VIRT_ACCESS, evt);
177}
178
179static __always_inline void timer_set_mode(const int access, int mode,
180 struct clock_event_device *clk)
76{ 181{
77 unsigned long ctrl; 182 unsigned long ctrl;
78 switch (mode) { 183 switch (mode) {
79 case CLOCK_EVT_MODE_UNUSED: 184 case CLOCK_EVT_MODE_UNUSED:
80 case CLOCK_EVT_MODE_SHUTDOWN: 185 case CLOCK_EVT_MODE_SHUTDOWN:
81 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL); 186 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk);
82 ctrl &= ~ARCH_TIMER_CTRL_ENABLE; 187 ctrl &= ~ARCH_TIMER_CTRL_ENABLE;
83 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl); 188 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk);
84 break; 189 break;
85 default: 190 default:
86 break; 191 break;
@@ -90,60 +195,108 @@ static inline void timer_set_mode(const int access, int mode)
90static void arch_timer_set_mode_virt(enum clock_event_mode mode, 195static void arch_timer_set_mode_virt(enum clock_event_mode mode,
91 struct clock_event_device *clk) 196 struct clock_event_device *clk)
92{ 197{
93 timer_set_mode(ARCH_TIMER_VIRT_ACCESS, mode); 198 timer_set_mode(ARCH_TIMER_VIRT_ACCESS, mode, clk);
94} 199}
95 200
96static void arch_timer_set_mode_phys(enum clock_event_mode mode, 201static void arch_timer_set_mode_phys(enum clock_event_mode mode,
97 struct clock_event_device *clk) 202 struct clock_event_device *clk)
98{ 203{
99 timer_set_mode(ARCH_TIMER_PHYS_ACCESS, mode); 204 timer_set_mode(ARCH_TIMER_PHYS_ACCESS, mode, clk);
205}
206
207static void arch_timer_set_mode_virt_mem(enum clock_event_mode mode,
208 struct clock_event_device *clk)
209{
210 timer_set_mode(ARCH_TIMER_MEM_VIRT_ACCESS, mode, clk);
100} 211}
101 212
102static inline void set_next_event(const int access, unsigned long evt) 213static void arch_timer_set_mode_phys_mem(enum clock_event_mode mode,
214 struct clock_event_device *clk)
215{
216 timer_set_mode(ARCH_TIMER_MEM_PHYS_ACCESS, mode, clk);
217}
218
219static __always_inline void set_next_event(const int access, unsigned long evt,
220 struct clock_event_device *clk)
103{ 221{
104 unsigned long ctrl; 222 unsigned long ctrl;
105 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL); 223 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk);
106 ctrl |= ARCH_TIMER_CTRL_ENABLE; 224 ctrl |= ARCH_TIMER_CTRL_ENABLE;
107 ctrl &= ~ARCH_TIMER_CTRL_IT_MASK; 225 ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
108 arch_timer_reg_write(access, ARCH_TIMER_REG_TVAL, evt); 226 arch_timer_reg_write(access, ARCH_TIMER_REG_TVAL, evt, clk);
109 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl); 227 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk);
110} 228}
111 229
112static int arch_timer_set_next_event_virt(unsigned long evt, 230static int arch_timer_set_next_event_virt(unsigned long evt,
113 struct clock_event_device *unused) 231 struct clock_event_device *clk)
114{ 232{
115 set_next_event(ARCH_TIMER_VIRT_ACCESS, evt); 233 set_next_event(ARCH_TIMER_VIRT_ACCESS, evt, clk);
116 return 0; 234 return 0;
117} 235}
118 236
119static int arch_timer_set_next_event_phys(unsigned long evt, 237static int arch_timer_set_next_event_phys(unsigned long evt,
120 struct clock_event_device *unused) 238 struct clock_event_device *clk)
121{ 239{
122 set_next_event(ARCH_TIMER_PHYS_ACCESS, evt); 240 set_next_event(ARCH_TIMER_PHYS_ACCESS, evt, clk);
123 return 0; 241 return 0;
124} 242}
125 243
126static int arch_timer_setup(struct clock_event_device *clk) 244static int arch_timer_set_next_event_virt_mem(unsigned long evt,
245 struct clock_event_device *clk)
127{ 246{
128 clk->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_C3STOP; 247 set_next_event(ARCH_TIMER_MEM_VIRT_ACCESS, evt, clk);
129 clk->name = "arch_sys_timer"; 248 return 0;
130 clk->rating = 450; 249}
131 if (arch_timer_use_virtual) { 250
132 clk->irq = arch_timer_ppi[VIRT_PPI]; 251static int arch_timer_set_next_event_phys_mem(unsigned long evt,
133 clk->set_mode = arch_timer_set_mode_virt; 252 struct clock_event_device *clk)
134 clk->set_next_event = arch_timer_set_next_event_virt; 253{
254 set_next_event(ARCH_TIMER_MEM_PHYS_ACCESS, evt, clk);
255 return 0;
256}
257
258static void __arch_timer_setup(unsigned type,
259 struct clock_event_device *clk)
260{
261 clk->features = CLOCK_EVT_FEAT_ONESHOT;
262
263 if (type == ARCH_CP15_TIMER) {
264 clk->features |= CLOCK_EVT_FEAT_C3STOP;
265 clk->name = "arch_sys_timer";
266 clk->rating = 450;
267 clk->cpumask = cpumask_of(smp_processor_id());
268 if (arch_timer_use_virtual) {
269 clk->irq = arch_timer_ppi[VIRT_PPI];
270 clk->set_mode = arch_timer_set_mode_virt;
271 clk->set_next_event = arch_timer_set_next_event_virt;
272 } else {
273 clk->irq = arch_timer_ppi[PHYS_SECURE_PPI];
274 clk->set_mode = arch_timer_set_mode_phys;
275 clk->set_next_event = arch_timer_set_next_event_phys;
276 }
135 } else { 277 } else {
136 clk->irq = arch_timer_ppi[PHYS_SECURE_PPI]; 278 clk->name = "arch_mem_timer";
137 clk->set_mode = arch_timer_set_mode_phys; 279 clk->rating = 400;
138 clk->set_next_event = arch_timer_set_next_event_phys; 280 clk->cpumask = cpu_all_mask;
281 if (arch_timer_mem_use_virtual) {
282 clk->set_mode = arch_timer_set_mode_virt_mem;
283 clk->set_next_event =
284 arch_timer_set_next_event_virt_mem;
285 } else {
286 clk->set_mode = arch_timer_set_mode_phys_mem;
287 clk->set_next_event =
288 arch_timer_set_next_event_phys_mem;
289 }
139 } 290 }
140 291
141 clk->cpumask = cpumask_of(smp_processor_id()); 292 clk->set_mode(CLOCK_EVT_MODE_SHUTDOWN, clk);
142 293
143 clk->set_mode(CLOCK_EVT_MODE_SHUTDOWN, NULL); 294 clockevents_config_and_register(clk, arch_timer_rate, 0xf, 0x7fffffff);
295}
144 296
145 clockevents_config_and_register(clk, arch_timer_rate, 297static int arch_timer_setup(struct clock_event_device *clk)
146 0xf, 0x7fffffff); 298{
299 __arch_timer_setup(ARCH_CP15_TIMER, clk);
147 300
148 if (arch_timer_use_virtual) 301 if (arch_timer_use_virtual)
149 enable_percpu_irq(arch_timer_ppi[VIRT_PPI], 0); 302 enable_percpu_irq(arch_timer_ppi[VIRT_PPI], 0);
@@ -158,27 +311,41 @@ static int arch_timer_setup(struct clock_event_device *clk)
158 return 0; 311 return 0;
159} 312}
160 313
161static int arch_timer_available(void) 314static void
315arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
162{ 316{
163 u32 freq; 317 /* Who has more than one independent system counter? */
164 318 if (arch_timer_rate)
165 if (arch_timer_rate == 0) { 319 return;
166 freq = arch_timer_get_cntfrq();
167
168 /* Check the timer frequency. */
169 if (freq == 0) {
170 pr_warn("Architected timer frequency not available\n");
171 return -EINVAL;
172 }
173 320
174 arch_timer_rate = freq; 321 /* Try to determine the frequency from the device tree or CNTFRQ */
322 if (of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
323 if (cntbase)
324 arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
325 else
326 arch_timer_rate = arch_timer_get_cntfrq();
175 } 327 }
176 328
177 pr_info_once("Architected local timer running at %lu.%02luMHz (%s).\n", 329 /* Check the timer frequency. */
330 if (arch_timer_rate == 0)
331 pr_warn("Architected timer frequency not available\n");
332}
333
334static void arch_timer_banner(unsigned type)
335{
336 pr_info("Architected %s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
337 type & ARCH_CP15_TIMER ? "cp15" : "",
338 type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ? " and " : "",
339 type & ARCH_MEM_TIMER ? "mmio" : "",
178 (unsigned long)arch_timer_rate / 1000000, 340 (unsigned long)arch_timer_rate / 1000000,
179 (unsigned long)(arch_timer_rate / 10000) % 100, 341 (unsigned long)(arch_timer_rate / 10000) % 100,
180 arch_timer_use_virtual ? "virt" : "phys"); 342 type & ARCH_CP15_TIMER ?
181 return 0; 343 arch_timer_use_virtual ? "virt" : "phys" :
344 "",
345 type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ? "/" : "",
346 type & ARCH_MEM_TIMER ?
347 arch_timer_mem_use_virtual ? "virt" : "phys" :
348 "");
182} 349}
183 350
184u32 arch_timer_get_rate(void) 351u32 arch_timer_get_rate(void)
@@ -186,19 +353,35 @@ u32 arch_timer_get_rate(void)
186 return arch_timer_rate; 353 return arch_timer_rate;
187} 354}
188 355
189u64 arch_timer_read_counter(void) 356static u64 arch_counter_get_cntvct_mem(void)
190{ 357{
191 return arch_counter_get_cntvct(); 358 u32 vct_lo, vct_hi, tmp_hi;
359
360 do {
361 vct_hi = readl_relaxed(arch_counter_base + CNTVCT_HI);
362 vct_lo = readl_relaxed(arch_counter_base + CNTVCT_LO);
363 tmp_hi = readl_relaxed(arch_counter_base + CNTVCT_HI);
364 } while (vct_hi != tmp_hi);
365
366 return ((u64) vct_hi << 32) | vct_lo;
192} 367}
193 368
369/*
370 * Default to cp15 based access because arm64 uses this function for
371 * sched_clock() before DT is probed and the cp15 method is guaranteed
372 * to exist on arm64. arm doesn't use this before DT is probed so even
373 * if we don't have the cp15 accessors we won't have a problem.
374 */
375u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct;
376
194static cycle_t arch_counter_read(struct clocksource *cs) 377static cycle_t arch_counter_read(struct clocksource *cs)
195{ 378{
196 return arch_counter_get_cntvct(); 379 return arch_timer_read_counter();
197} 380}
198 381
199static cycle_t arch_counter_read_cc(const struct cyclecounter *cc) 382static cycle_t arch_counter_read_cc(const struct cyclecounter *cc)
200{ 383{
201 return arch_counter_get_cntvct(); 384 return arch_timer_read_counter();
202} 385}
203 386
204static struct clocksource clocksource_counter = { 387static struct clocksource clocksource_counter = {
@@ -221,6 +404,23 @@ struct timecounter *arch_timer_get_timecounter(void)
221 return &timecounter; 404 return &timecounter;
222} 405}
223 406
407static void __init arch_counter_register(unsigned type)
408{
409 u64 start_count;
410
411 /* Register the CP15 based counter if we have one */
412 if (type & ARCH_CP15_TIMER)
413 arch_timer_read_counter = arch_counter_get_cntvct;
414 else
415 arch_timer_read_counter = arch_counter_get_cntvct_mem;
416
417 start_count = arch_timer_read_counter();
418 clocksource_register_hz(&clocksource_counter, arch_timer_rate);
419 cyclecounter.mult = clocksource_counter.mult;
420 cyclecounter.shift = clocksource_counter.shift;
421 timecounter_init(&timecounter, &cyclecounter, start_count);
422}
423
224static void arch_timer_stop(struct clock_event_device *clk) 424static void arch_timer_stop(struct clock_event_device *clk)
225{ 425{
226 pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n", 426 pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n",
@@ -265,22 +465,12 @@ static int __init arch_timer_register(void)
265 int err; 465 int err;
266 int ppi; 466 int ppi;
267 467
268 err = arch_timer_available();
269 if (err)
270 goto out;
271
272 arch_timer_evt = alloc_percpu(struct clock_event_device); 468 arch_timer_evt = alloc_percpu(struct clock_event_device);
273 if (!arch_timer_evt) { 469 if (!arch_timer_evt) {
274 err = -ENOMEM; 470 err = -ENOMEM;
275 goto out; 471 goto out;
276 } 472 }
277 473
278 clocksource_register_hz(&clocksource_counter, arch_timer_rate);
279 cyclecounter.mult = clocksource_counter.mult;
280 cyclecounter.shift = clocksource_counter.shift;
281 timecounter_init(&timecounter, &cyclecounter,
282 arch_counter_get_cntvct());
283
284 if (arch_timer_use_virtual) { 474 if (arch_timer_use_virtual) {
285 ppi = arch_timer_ppi[VIRT_PPI]; 475 ppi = arch_timer_ppi[VIRT_PPI];
286 err = request_percpu_irq(ppi, arch_timer_handler_virt, 476 err = request_percpu_irq(ppi, arch_timer_handler_virt,
@@ -331,24 +521,77 @@ out:
331 return err; 521 return err;
332} 522}
333 523
524static int __init arch_timer_mem_register(void __iomem *base, unsigned int irq)
525{
526 int ret;
527 irq_handler_t func;
528 struct arch_timer *t;
529
530 t = kzalloc(sizeof(*t), GFP_KERNEL);
531 if (!t)
532 return -ENOMEM;
533
534 t->base = base;
535 t->evt.irq = irq;
536 __arch_timer_setup(ARCH_MEM_TIMER, &t->evt);
537
538 if (arch_timer_mem_use_virtual)
539 func = arch_timer_handler_virt_mem;
540 else
541 func = arch_timer_handler_phys_mem;
542
543 ret = request_irq(irq, func, IRQF_TIMER, "arch_mem_timer", &t->evt);
544 if (ret) {
545 pr_err("arch_timer: Failed to request mem timer irq\n");
546 kfree(t);
547 }
548
549 return ret;
550}
551
552static const struct of_device_id arch_timer_of_match[] __initconst = {
553 { .compatible = "arm,armv7-timer", },
554 { .compatible = "arm,armv8-timer", },
555 {},
556};
557
558static const struct of_device_id arch_timer_mem_of_match[] __initconst = {
559 { .compatible = "arm,armv7-timer-mem", },
560 {},
561};
562
563static void __init arch_timer_common_init(void)
564{
565 unsigned mask = ARCH_CP15_TIMER | ARCH_MEM_TIMER;
566
567 /* Wait until both nodes are probed if we have two timers */
568 if ((arch_timers_present & mask) != mask) {
569 if (of_find_matching_node(NULL, arch_timer_mem_of_match) &&
570 !(arch_timers_present & ARCH_MEM_TIMER))
571 return;
572 if (of_find_matching_node(NULL, arch_timer_of_match) &&
573 !(arch_timers_present & ARCH_CP15_TIMER))
574 return;
575 }
576
577 arch_timer_banner(arch_timers_present);
578 arch_counter_register(arch_timers_present);
579 arch_timer_arch_init();
580}
581
334static void __init arch_timer_init(struct device_node *np) 582static void __init arch_timer_init(struct device_node *np)
335{ 583{
336 u32 freq;
337 int i; 584 int i;
338 585
339 if (arch_timer_get_rate()) { 586 if (arch_timers_present & ARCH_CP15_TIMER) {
340 pr_warn("arch_timer: multiple nodes in dt, skipping\n"); 587 pr_warn("arch_timer: multiple nodes in dt, skipping\n");
341 return; 588 return;
342 } 589 }
343 590
344 /* Try to determine the frequency from the device tree or CNTFRQ */ 591 arch_timers_present |= ARCH_CP15_TIMER;
345 if (!of_property_read_u32(np, "clock-frequency", &freq))
346 arch_timer_rate = freq;
347
348 for (i = PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++) 592 for (i = PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++)
349 arch_timer_ppi[i] = irq_of_parse_and_map(np, i); 593 arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
350 594 arch_timer_detect_rate(NULL, np);
351 of_node_put(np);
352 595
353 /* 596 /*
354 * If HYP mode is available, we know that the physical timer 597 * If HYP mode is available, we know that the physical timer
@@ -369,7 +612,73 @@ static void __init arch_timer_init(struct device_node *np)
369 } 612 }
370 613
371 arch_timer_register(); 614 arch_timer_register();
372 arch_timer_arch_init(); 615 arch_timer_common_init();
373} 616}
374CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_init); 617CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_init);
375CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_init); 618CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_init);
619
620static void __init arch_timer_mem_init(struct device_node *np)
621{
622 struct device_node *frame, *best_frame = NULL;
623 void __iomem *cntctlbase, *base;
624 unsigned int irq;
625 u32 cnttidr;
626
627 arch_timers_present |= ARCH_MEM_TIMER;
628 cntctlbase = of_iomap(np, 0);
629 if (!cntctlbase) {
630 pr_err("arch_timer: Can't find CNTCTLBase\n");
631 return;
632 }
633
634 cnttidr = readl_relaxed(cntctlbase + CNTTIDR);
635 iounmap(cntctlbase);
636
637 /*
638 * Try to find a virtual capable frame. Otherwise fall back to a
639 * physical capable frame.
640 */
641 for_each_available_child_of_node(np, frame) {
642 int n;
643
644 if (of_property_read_u32(frame, "frame-number", &n)) {
645 pr_err("arch_timer: Missing frame-number\n");
646 of_node_put(best_frame);
647 of_node_put(frame);
648 return;
649 }
650
651 if (cnttidr & CNTTIDR_VIRT(n)) {
652 of_node_put(best_frame);
653 best_frame = frame;
654 arch_timer_mem_use_virtual = true;
655 break;
656 }
657 of_node_put(best_frame);
658 best_frame = of_node_get(frame);
659 }
660
661 base = arch_counter_base = of_iomap(best_frame, 0);
662 if (!base) {
663 pr_err("arch_timer: Can't map frame's registers\n");
664 of_node_put(best_frame);
665 return;
666 }
667
668 if (arch_timer_mem_use_virtual)
669 irq = irq_of_parse_and_map(best_frame, 1);
670 else
671 irq = irq_of_parse_and_map(best_frame, 0);
672 of_node_put(best_frame);
673 if (!irq) {
674 pr_err("arch_timer: Frame missing %s irq",
675 arch_timer_mem_use_virtual ? "virt" : "phys");
676 return;
677 }
678
679 arch_timer_detect_rate(base, np);
680 arch_timer_mem_register(base, irq);
681 arch_timer_common_init();
682}
683CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
684 arch_timer_mem_init);
diff --git a/drivers/clocksource/moxart_timer.c b/drivers/clocksource/moxart_timer.c
index 08a5943b3e42..5eb2c35932b1 100644
--- a/drivers/clocksource/moxart_timer.c
+++ b/drivers/clocksource/moxart_timer.c
@@ -20,6 +20,7 @@
20#include <linux/of_irq.h> 20#include <linux/of_irq.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/clocksource.h> 22#include <linux/clocksource.h>
23#include <linux/bitops.h>
23 24
24#define TIMER1_BASE 0x00 25#define TIMER1_BASE 0x00
25#define TIMER2_BASE 0x10 26#define TIMER2_BASE 0x10