diff options
Diffstat (limited to 'arch/arm/mach-iop3xx/iop331-time.c')
-rw-r--r-- | arch/arm/mach-iop3xx/iop331-time.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/arch/arm/mach-iop3xx/iop331-time.c b/arch/arm/mach-iop3xx/iop331-time.c new file mode 100644 index 000000000000..e01696769263 --- /dev/null +++ b/arch/arm/mach-iop3xx/iop331-time.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-iop3xx/iop331-time.c | ||
3 | * | ||
4 | * Timer code for IOP331 based systems | ||
5 | * | ||
6 | * Author: Dave Jiang <dave.jiang@intel.com> | ||
7 | * | ||
8 | * Copyright 2003 Intel Corp. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/time.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/timex.h> | ||
21 | |||
22 | #include <asm/hardware.h> | ||
23 | #include <asm/io.h> | ||
24 | #include <asm/irq.h> | ||
25 | #include <asm/uaccess.h> | ||
26 | #include <asm/mach-types.h> | ||
27 | #include <asm/mach/irq.h> | ||
28 | #include <asm/mach/time.h> | ||
29 | |||
30 | static inline unsigned long get_elapsed(void) | ||
31 | { | ||
32 | return LATCH - *IOP331_TU_TCR0; | ||
33 | } | ||
34 | |||
35 | static unsigned long iop331_gettimeoffset(void) | ||
36 | { | ||
37 | unsigned long elapsed, usec; | ||
38 | u32 tisr1, tisr2; | ||
39 | |||
40 | /* | ||
41 | * If an interrupt was pending before we read the timer, | ||
42 | * we've already wrapped. Factor this into the time. | ||
43 | * If an interrupt was pending after we read the timer, | ||
44 | * it may have wrapped between checking the interrupt | ||
45 | * status and reading the timer. Re-read the timer to | ||
46 | * be sure its value is after the wrap. | ||
47 | */ | ||
48 | |||
49 | asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr1)); | ||
50 | elapsed = get_elapsed(); | ||
51 | asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr2)); | ||
52 | |||
53 | if(tisr1 & 1) | ||
54 | elapsed += LATCH; | ||
55 | else if (tisr2 & 1) | ||
56 | elapsed = LATCH + get_elapsed(); | ||
57 | |||
58 | /* | ||
59 | * Now convert them to usec. | ||
60 | */ | ||
61 | usec = (unsigned long)(elapsed * (tick_nsec / 1000)) / LATCH; | ||
62 | |||
63 | return usec; | ||
64 | } | ||
65 | |||
66 | static irqreturn_t | ||
67 | iop331_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
68 | { | ||
69 | u32 tisr; | ||
70 | |||
71 | write_seqlock(&xtime_lock); | ||
72 | |||
73 | asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr)); | ||
74 | tisr |= 1; | ||
75 | asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (tisr)); | ||
76 | |||
77 | timer_tick(regs); | ||
78 | |||
79 | write_sequnlock(&xtime_lock); | ||
80 | return IRQ_HANDLED; | ||
81 | } | ||
82 | |||
83 | static struct irqaction iop331_timer_irq = { | ||
84 | .name = "IOP331 Timer Tick", | ||
85 | .handler = iop331_timer_interrupt, | ||
86 | .flags = SA_INTERRUPT | ||
87 | }; | ||
88 | |||
89 | static void __init iop331_timer_init(void) | ||
90 | { | ||
91 | u32 timer_ctl; | ||
92 | |||
93 | setup_irq(IRQ_IOP331_TIMER0, &iop331_timer_irq); | ||
94 | |||
95 | timer_ctl = IOP331_TMR_EN | IOP331_TMR_PRIVILEGED | IOP331_TMR_RELOAD | | ||
96 | IOP331_TMR_RATIO_1_1; | ||
97 | |||
98 | asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (LATCH)); | ||
99 | |||
100 | asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl)); | ||
101 | |||
102 | } | ||
103 | |||
104 | struct sys_timer iop331_timer = { | ||
105 | .init = iop331_timer_init, | ||
106 | .offset = iop331_gettimeoffset, | ||
107 | }; | ||