diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2009-02-18 14:58:40 -0500 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2009-05-07 10:15:42 -0400 |
commit | ec996ba9b5cc2a085ca6938678317c4ff9c954d1 (patch) | |
tree | d13b9e1f1ef674e762b2ed24f55b6b514b8cc509 /arch/arm/plat-mxc | |
parent | cd4a05f9df859e7cd2efa96e035444a3decb427a (diff) |
mxc timer: make compile time independent
Currently we depend on hardcoded base addresses for the timer.
This prevents us from compiling in more than one i.MX architecture
at a time. This patch changes the base address to a runtime
calculated one.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/plat-mxc')
-rw-r--r-- | arch/arm/plat-mxc/include/mach/mxc_timer.h | 158 | ||||
-rw-r--r-- | arch/arm/plat-mxc/time.c | 155 |
2 files changed, 135 insertions, 178 deletions
diff --git a/arch/arm/plat-mxc/include/mach/mxc_timer.h b/arch/arm/plat-mxc/include/mach/mxc_timer.h deleted file mode 100644 index 6c19a134744b..000000000000 --- a/arch/arm/plat-mxc/include/mach/mxc_timer.h +++ /dev/null | |||
@@ -1,158 +0,0 @@ | |||
1 | /* | ||
2 | * mxc_timer.h | ||
3 | * | ||
4 | * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de) | ||
5 | * | ||
6 | * Platform independent (i.MX1, i.MX2, i.MX3) definition for timer handling. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * as published by the Free Software Foundation; either version 2 | ||
11 | * of the License, or (at your option) any later version. | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | * Boston, MA 02110-1301, USA. | ||
21 | */ | ||
22 | |||
23 | #ifndef __PLAT_MXC_TIMER_H | ||
24 | #define __PLAT_MXC_TIMER_H | ||
25 | |||
26 | #include <linux/clk.h> | ||
27 | #include <mach/hardware.h> | ||
28 | |||
29 | #ifdef CONFIG_ARCH_MX1 | ||
30 | #define TIMER_BASE IO_ADDRESS(TIM1_BASE_ADDR) | ||
31 | #define TIMER_INTERRUPT TIM1_INT | ||
32 | |||
33 | #define TCTL_VAL TCTL_CLK_PCLK1 | ||
34 | #define TCTL_IRQEN (1<<4) | ||
35 | #define TCTL_FRR (1<<8) | ||
36 | #define TCTL_CLK_PCLK1 (1<<1) | ||
37 | #define TCTL_CLK_PCLK1_4 (2<<1) | ||
38 | #define TCTL_CLK_TIN (3<<1) | ||
39 | #define TCTL_CLK_32 (4<<1) | ||
40 | |||
41 | #define MXC_TCTL 0x00 | ||
42 | #define MXC_TPRER 0x04 | ||
43 | #define MXC_TCMP 0x08 | ||
44 | #define MXC_TCR 0x0c | ||
45 | #define MXC_TCN 0x10 | ||
46 | #define MXC_TSTAT 0x14 | ||
47 | #define TSTAT_CAPT (1<<1) | ||
48 | #define TSTAT_COMP (1<<0) | ||
49 | |||
50 | static inline void gpt_irq_disable(void) | ||
51 | { | ||
52 | unsigned int tmp; | ||
53 | |||
54 | tmp = __raw_readl(TIMER_BASE + MXC_TCTL); | ||
55 | __raw_writel(tmp & ~TCTL_IRQEN, TIMER_BASE + MXC_TCTL); | ||
56 | } | ||
57 | |||
58 | static inline void gpt_irq_enable(void) | ||
59 | { | ||
60 | __raw_writel(__raw_readl(TIMER_BASE + MXC_TCTL) | TCTL_IRQEN, | ||
61 | TIMER_BASE + MXC_TCTL); | ||
62 | } | ||
63 | |||
64 | static void gpt_irq_acknowledge(void) | ||
65 | { | ||
66 | __raw_writel(0, TIMER_BASE + MXC_TSTAT); | ||
67 | } | ||
68 | #endif /* CONFIG_ARCH_MX1 */ | ||
69 | |||
70 | #ifdef CONFIG_ARCH_MX2 | ||
71 | #define TIMER_BASE IO_ADDRESS(GPT1_BASE_ADDR) | ||
72 | #define TIMER_INTERRUPT MXC_INT_GPT1 | ||
73 | |||
74 | #define MXC_TCTL 0x00 | ||
75 | #define TCTL_VAL TCTL_CLK_PCLK1 | ||
76 | #define TCTL_CLK_PCLK1 (1<<1) | ||
77 | #define TCTL_CLK_PCLK1_4 (2<<1) | ||
78 | #define TCTL_IRQEN (1<<4) | ||
79 | #define TCTL_FRR (1<<8) | ||
80 | #define MXC_TPRER 0x04 | ||
81 | #define MXC_TCMP 0x08 | ||
82 | #define MXC_TCR 0x0c | ||
83 | #define MXC_TCN 0x10 | ||
84 | #define MXC_TSTAT 0x14 | ||
85 | #define TSTAT_CAPT (1<<1) | ||
86 | #define TSTAT_COMP (1<<0) | ||
87 | |||
88 | static inline void gpt_irq_disable(void) | ||
89 | { | ||
90 | unsigned int tmp; | ||
91 | |||
92 | tmp = __raw_readl(TIMER_BASE + MXC_TCTL); | ||
93 | __raw_writel(tmp & ~TCTL_IRQEN, TIMER_BASE + MXC_TCTL); | ||
94 | } | ||
95 | |||
96 | static inline void gpt_irq_enable(void) | ||
97 | { | ||
98 | __raw_writel(__raw_readl(TIMER_BASE + MXC_TCTL) | TCTL_IRQEN, | ||
99 | TIMER_BASE + MXC_TCTL); | ||
100 | } | ||
101 | |||
102 | static void gpt_irq_acknowledge(void) | ||
103 | { | ||
104 | __raw_writel(TSTAT_CAPT | TSTAT_COMP, TIMER_BASE + MXC_TSTAT); | ||
105 | } | ||
106 | #endif /* CONFIG_ARCH_MX2 */ | ||
107 | |||
108 | #ifdef CONFIG_ARCH_MX3 | ||
109 | #define TIMER_BASE IO_ADDRESS(GPT1_BASE_ADDR) | ||
110 | #define TIMER_INTERRUPT MXC_INT_GPT | ||
111 | |||
112 | #define MXC_TCTL 0x00 | ||
113 | #define TCTL_VAL (TCTL_CLK_IPG | TCTL_WAITEN) | ||
114 | #define TCTL_CLK_IPG (1<<6) | ||
115 | #define TCTL_FRR (1<<9) | ||
116 | #define TCTL_WAITEN (1<<3) | ||
117 | |||
118 | #define MXC_TPRER 0x04 | ||
119 | #define MXC_TSTAT 0x08 | ||
120 | #define TSTAT_OF1 (1<<0) | ||
121 | #define TSTAT_OF2 (1<<1) | ||
122 | #define TSTAT_OF3 (1<<2) | ||
123 | #define TSTAT_IF1 (1<<3) | ||
124 | #define TSTAT_IF2 (1<<4) | ||
125 | #define TSTAT_ROV (1<<5) | ||
126 | #define MXC_IR 0x0c | ||
127 | #define MXC_TCMP 0x10 | ||
128 | #define MXC_TCMP2 0x14 | ||
129 | #define MXC_TCMP3 0x18 | ||
130 | #define MXC_TCR 0x1c | ||
131 | #define MXC_TCN 0x24 | ||
132 | |||
133 | static inline void gpt_irq_disable(void) | ||
134 | { | ||
135 | __raw_writel(0, TIMER_BASE + MXC_IR); | ||
136 | } | ||
137 | |||
138 | static inline void gpt_irq_enable(void) | ||
139 | { | ||
140 | __raw_writel(1<<0, TIMER_BASE + MXC_IR); | ||
141 | } | ||
142 | |||
143 | static inline void gpt_irq_acknowledge(void) | ||
144 | { | ||
145 | __raw_writel(TSTAT_OF1, TIMER_BASE + MXC_TSTAT); | ||
146 | } | ||
147 | #endif /* CONFIG_ARCH_MX3 */ | ||
148 | |||
149 | #define TCTL_SWR (1<<15) | ||
150 | #define TCTL_CC (1<<10) | ||
151 | #define TCTL_OM (1<<9) | ||
152 | #define TCTL_CAP_RIS (1<<6) | ||
153 | #define TCTL_CAP_FAL (2<<6) | ||
154 | #define TCTL_CAP_RIS_FAL (3<<6) | ||
155 | #define TCTL_CAP_ENA (1<<5) | ||
156 | #define TCTL_TEN (1<<0) | ||
157 | |||
158 | #endif | ||
diff --git a/arch/arm/plat-mxc/time.c b/arch/arm/plat-mxc/time.c index dab3357196fb..85f002e7f1e5 100644 --- a/arch/arm/plat-mxc/time.c +++ b/arch/arm/plat-mxc/time.c | |||
@@ -29,22 +29,85 @@ | |||
29 | #include <mach/hardware.h> | 29 | #include <mach/hardware.h> |
30 | #include <asm/mach/time.h> | 30 | #include <asm/mach/time.h> |
31 | #include <mach/common.h> | 31 | #include <mach/common.h> |
32 | #include <mach/mxc_timer.h> | 32 | |
33 | /* defines common for all i.MX */ | ||
34 | #define MXC_TCTL 0x00 | ||
35 | #define MXC_TCTL_TEN (1 << 0) | ||
36 | #define MXC_TPRER 0x04 | ||
37 | |||
38 | /* MX1, MX21, MX27 */ | ||
39 | #define MX1_2_TCTL_CLK_PCLK1 (1 << 1) | ||
40 | #define MX1_2_TCTL_IRQEN (1 << 4) | ||
41 | #define MX1_2_TCTL_FRR (1 << 8) | ||
42 | #define MX1_2_TCMP 0x08 | ||
43 | #define MX1_2_TCN 0x10 | ||
44 | #define MX1_2_TSTAT 0x14 | ||
45 | |||
46 | /* MX21, MX27 */ | ||
47 | #define MX2_TSTAT_CAPT (1 << 1) | ||
48 | #define MX2_TSTAT_COMP (1 << 0) | ||
49 | |||
50 | /* MX31, MX35 */ | ||
51 | #define MX3_TCTL_WAITEN (1 << 3) | ||
52 | #define MX3_TCTL_CLK_IPG (1 << 6) | ||
53 | #define MX3_TCTL_FRR (1 << 9) | ||
54 | #define MX3_IR 0x0c | ||
55 | #define MX3_TSTAT 0x08 | ||
56 | #define MX3_TSTAT_OF1 (1 << 0) | ||
57 | #define MX3_TCN 0x24 | ||
58 | #define MX3_TCMP 0x10 | ||
33 | 59 | ||
34 | static struct clock_event_device clockevent_mxc; | 60 | static struct clock_event_device clockevent_mxc; |
35 | static enum clock_event_mode clockevent_mode = CLOCK_EVT_MODE_UNUSED; | 61 | static enum clock_event_mode clockevent_mode = CLOCK_EVT_MODE_UNUSED; |
36 | 62 | ||
37 | /* clock source */ | 63 | static void __iomem *timer_base; |
38 | 64 | ||
39 | static cycle_t mxc_get_cycles(struct clocksource *cs) | 65 | static inline void gpt_irq_disable(void) |
40 | { | 66 | { |
41 | return __raw_readl(TIMER_BASE + MXC_TCN); | 67 | unsigned int tmp; |
68 | |||
69 | if (cpu_is_mx3()) | ||
70 | __raw_writel(0, timer_base + MX3_IR); | ||
71 | else { | ||
72 | tmp = __raw_readl(timer_base + MXC_TCTL); | ||
73 | __raw_writel(tmp & ~MX1_2_TCTL_IRQEN, timer_base + MXC_TCTL); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | static inline void gpt_irq_enable(void) | ||
78 | { | ||
79 | if (cpu_is_mx3()) | ||
80 | __raw_writel(1<<0, timer_base + MX3_IR); | ||
81 | else { | ||
82 | __raw_writel(__raw_readl(timer_base + MXC_TCTL) | MX1_2_TCTL_IRQEN, | ||
83 | timer_base + MXC_TCTL); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | static void gpt_irq_acknowledge(void) | ||
88 | { | ||
89 | if (cpu_is_mx1()) | ||
90 | __raw_writel(0, timer_base + MX1_2_TSTAT); | ||
91 | if (cpu_is_mx2()) | ||
92 | __raw_writel(MX2_TSTAT_CAPT | MX2_TSTAT_COMP, timer_base + MX1_2_TSTAT); | ||
93 | if (cpu_is_mx3()) | ||
94 | __raw_writel(MX3_TSTAT_OF1, timer_base + MX3_TSTAT); | ||
95 | } | ||
96 | |||
97 | static cycle_t mx1_2_get_cycles(struct clocksource *cs) | ||
98 | { | ||
99 | return __raw_readl(timer_base + MX1_2_TCN); | ||
100 | } | ||
101 | |||
102 | static cycle_t mx3_get_cycles(struct clocksource *cs) | ||
103 | { | ||
104 | return __raw_readl(timer_base + MX3_TCN); | ||
42 | } | 105 | } |
43 | 106 | ||
44 | static struct clocksource clocksource_mxc = { | 107 | static struct clocksource clocksource_mxc = { |
45 | .name = "mxc_timer1", | 108 | .name = "mxc_timer1", |
46 | .rating = 200, | 109 | .rating = 200, |
47 | .read = mxc_get_cycles, | 110 | .read = mx1_2_get_cycles, |
48 | .mask = CLOCKSOURCE_MASK(32), | 111 | .mask = CLOCKSOURCE_MASK(32), |
49 | .shift = 20, | 112 | .shift = 20, |
50 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 113 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
@@ -54,6 +117,9 @@ static int __init mxc_clocksource_init(struct clk *timer_clk) | |||
54 | { | 117 | { |
55 | unsigned int c = clk_get_rate(timer_clk); | 118 | unsigned int c = clk_get_rate(timer_clk); |
56 | 119 | ||
120 | if (cpu_is_mx3()) | ||
121 | clocksource_mxc.read = mx3_get_cycles; | ||
122 | |||
57 | clocksource_mxc.mult = clocksource_hz2mult(c, | 123 | clocksource_mxc.mult = clocksource_hz2mult(c, |
58 | clocksource_mxc.shift); | 124 | clocksource_mxc.shift); |
59 | clocksource_register(&clocksource_mxc); | 125 | clocksource_register(&clocksource_mxc); |
@@ -63,15 +129,29 @@ static int __init mxc_clocksource_init(struct clk *timer_clk) | |||
63 | 129 | ||
64 | /* clock event */ | 130 | /* clock event */ |
65 | 131 | ||
66 | static int mxc_set_next_event(unsigned long evt, | 132 | static int mx1_2_set_next_event(unsigned long evt, |
67 | struct clock_event_device *unused) | 133 | struct clock_event_device *unused) |
68 | { | 134 | { |
69 | unsigned long tcmp; | 135 | unsigned long tcmp; |
70 | 136 | ||
71 | tcmp = __raw_readl(TIMER_BASE + MXC_TCN) + evt; | 137 | tcmp = __raw_readl(timer_base + MX1_2_TCN) + evt; |
72 | __raw_writel(tcmp, TIMER_BASE + MXC_TCMP); | ||
73 | 138 | ||
74 | return (int)(tcmp - __raw_readl(TIMER_BASE + MXC_TCN)) < 0 ? | 139 | __raw_writel(tcmp, timer_base + MX1_2_TCMP); |
140 | |||
141 | return (int)(tcmp - __raw_readl(timer_base + MX1_2_TCN)) < 0 ? | ||
142 | -ETIME : 0; | ||
143 | } | ||
144 | |||
145 | static int mx3_set_next_event(unsigned long evt, | ||
146 | struct clock_event_device *unused) | ||
147 | { | ||
148 | unsigned long tcmp; | ||
149 | |||
150 | tcmp = __raw_readl(timer_base + MX3_TCN) + evt; | ||
151 | |||
152 | __raw_writel(tcmp, timer_base + MX3_TCMP); | ||
153 | |||
154 | return (int)(tcmp - __raw_readl(timer_base + MX3_TCN)) < 0 ? | ||
75 | -ETIME : 0; | 155 | -ETIME : 0; |
76 | } | 156 | } |
77 | 157 | ||
@@ -100,8 +180,13 @@ static void mxc_set_mode(enum clock_event_mode mode, | |||
100 | 180 | ||
101 | if (mode != clockevent_mode) { | 181 | if (mode != clockevent_mode) { |
102 | /* Set event time into far-far future */ | 182 | /* Set event time into far-far future */ |
103 | __raw_writel(__raw_readl(TIMER_BASE + MXC_TCN) - 3, | 183 | if (cpu_is_mx3()) |
104 | TIMER_BASE + MXC_TCMP); | 184 | __raw_writel(__raw_readl(timer_base + MX3_TCN) - 3, |
185 | timer_base + MX3_TCMP); | ||
186 | else | ||
187 | __raw_writel(__raw_readl(timer_base + MX1_2_TCN) - 3, | ||
188 | timer_base + MX1_2_TCMP); | ||
189 | |||
105 | /* Clear pending interrupt */ | 190 | /* Clear pending interrupt */ |
106 | gpt_irq_acknowledge(); | 191 | gpt_irq_acknowledge(); |
107 | } | 192 | } |
@@ -148,7 +233,10 @@ static irqreturn_t mxc_timer_interrupt(int irq, void *dev_id) | |||
148 | struct clock_event_device *evt = &clockevent_mxc; | 233 | struct clock_event_device *evt = &clockevent_mxc; |
149 | uint32_t tstat; | 234 | uint32_t tstat; |
150 | 235 | ||
151 | tstat = __raw_readl(TIMER_BASE + MXC_TSTAT); | 236 | if (cpu_is_mx3()) |
237 | tstat = __raw_readl(timer_base + MX1_2_TSTAT); | ||
238 | else | ||
239 | tstat = __raw_readl(timer_base + MX3_TSTAT); | ||
152 | 240 | ||
153 | gpt_irq_acknowledge(); | 241 | gpt_irq_acknowledge(); |
154 | 242 | ||
@@ -168,7 +256,7 @@ static struct clock_event_device clockevent_mxc = { | |||
168 | .features = CLOCK_EVT_FEAT_ONESHOT, | 256 | .features = CLOCK_EVT_FEAT_ONESHOT, |
169 | .shift = 32, | 257 | .shift = 32, |
170 | .set_mode = mxc_set_mode, | 258 | .set_mode = mxc_set_mode, |
171 | .set_next_event = mxc_set_next_event, | 259 | .set_next_event = mx1_2_set_next_event, |
172 | .rating = 200, | 260 | .rating = 200, |
173 | }; | 261 | }; |
174 | 262 | ||
@@ -176,6 +264,9 @@ static int __init mxc_clockevent_init(struct clk *timer_clk) | |||
176 | { | 264 | { |
177 | unsigned int c = clk_get_rate(timer_clk); | 265 | unsigned int c = clk_get_rate(timer_clk); |
178 | 266 | ||
267 | if (cpu_is_mx3()) | ||
268 | clockevent_mxc.set_next_event = mx3_set_next_event; | ||
269 | |||
179 | clockevent_mxc.mult = div_sc(c, NSEC_PER_SEC, | 270 | clockevent_mxc.mult = div_sc(c, NSEC_PER_SEC, |
180 | clockevent_mxc.shift); | 271 | clockevent_mxc.shift); |
181 | clockevent_mxc.max_delta_ns = | 272 | clockevent_mxc.max_delta_ns = |
@@ -192,23 +283,47 @@ static int __init mxc_clockevent_init(struct clk *timer_clk) | |||
192 | 283 | ||
193 | void __init mxc_timer_init(struct clk *timer_clk) | 284 | void __init mxc_timer_init(struct clk *timer_clk) |
194 | { | 285 | { |
286 | uint32_t tctl_val; | ||
287 | int irq; | ||
288 | |||
195 | clk_enable(timer_clk); | 289 | clk_enable(timer_clk); |
196 | 290 | ||
291 | if (cpu_is_mx1()) { | ||
292 | #ifdef CONFIG_ARCH_MX1 | ||
293 | timer_base = IO_ADDRESS(TIM1_BASE_ADDR); | ||
294 | irq = TIM1_INT; | ||
295 | #endif | ||
296 | } else if (cpu_is_mx2()) { | ||
297 | #ifdef CONFIG_ARCH_MX2 | ||
298 | timer_base = IO_ADDRESS(GPT1_BASE_ADDR); | ||
299 | irq = MXC_INT_GPT1; | ||
300 | #endif | ||
301 | } else if (cpu_is_mx3()) { | ||
302 | #ifdef CONFIG_ARCH_MX3 | ||
303 | timer_base = IO_ADDRESS(GPT1_BASE_ADDR); | ||
304 | irq = MXC_INT_GPT; | ||
305 | #endif | ||
306 | } else | ||
307 | BUG(); | ||
308 | |||
197 | /* | 309 | /* |
198 | * Initialise to a known state (all timers off, and timing reset) | 310 | * Initialise to a known state (all timers off, and timing reset) |
199 | */ | 311 | */ |
200 | __raw_writel(0, TIMER_BASE + MXC_TCTL); | ||
201 | __raw_writel(0, TIMER_BASE + MXC_TPRER); /* see datasheet note */ | ||
202 | 312 | ||
203 | __raw_writel(TCTL_FRR | /* free running */ | 313 | __raw_writel(0, timer_base + MXC_TCTL); |
204 | TCTL_VAL | /* set clocksource and arch specific bits */ | 314 | __raw_writel(0, timer_base + MXC_TPRER); /* see datasheet note */ |
205 | TCTL_TEN, /* start the timer */ | 315 | |
206 | TIMER_BASE + MXC_TCTL); | 316 | if (cpu_is_mx3()) |
317 | tctl_val = MX3_TCTL_CLK_IPG | MX3_TCTL_FRR | MX3_TCTL_WAITEN | MXC_TCTL_TEN; | ||
318 | else | ||
319 | tctl_val = MX1_2_TCTL_FRR | MX1_2_TCTL_CLK_PCLK1 | MXC_TCTL_TEN; | ||
320 | |||
321 | __raw_writel(tctl_val, timer_base + MXC_TCTL); | ||
207 | 322 | ||
208 | /* init and register the timer to the framework */ | 323 | /* init and register the timer to the framework */ |
209 | mxc_clocksource_init(timer_clk); | 324 | mxc_clocksource_init(timer_clk); |
210 | mxc_clockevent_init(timer_clk); | 325 | mxc_clockevent_init(timer_clk); |
211 | 326 | ||
212 | /* Make irqs happen */ | 327 | /* Make irqs happen */ |
213 | setup_irq(TIMER_INTERRUPT, &mxc_timer_irq); | 328 | setup_irq(irq, &mxc_timer_irq); |
214 | } | 329 | } |