diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2009-12-04 03:34:51 -0500 |
---|---|---|
committer | Amit Kucheria <amit.kucheria@canonical.com> | 2010-02-09 09:15:26 -0500 |
commit | 0f3332c4fabb2227b1bc15dc7542017d08f10a09 (patch) | |
tree | 5957bc11e9bc2ba66d828068c93f1949840562e6 /arch/arm/plat-mxc | |
parent | a003708ad4ee9384226251431c7953a24079ff80 (diff) |
mxc: refactor timer code to use timer versions
Refactor the timer code into version 1 and version 2.
Essentially there are 2 versions of the timer hardware on Freescale MXC
hardware. Version 1 is found on MX1/MXL, MX21 and MX27. Version 2 is found on
MX25, MX31, MX35, MX37, MX51, and future parts.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Amit Kucheria <amit.kucheria@canonical.com>
Diffstat (limited to 'arch/arm/plat-mxc')
-rw-r--r-- | arch/arm/plat-mxc/time.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/arch/arm/plat-mxc/time.c b/arch/arm/plat-mxc/time.c index 844567ee35fe..c1ce51abdba6 100644 --- a/arch/arm/plat-mxc/time.c +++ b/arch/arm/plat-mxc/time.c | |||
@@ -30,9 +30,15 @@ | |||
30 | #include <asm/mach/time.h> | 30 | #include <asm/mach/time.h> |
31 | #include <mach/common.h> | 31 | #include <mach/common.h> |
32 | 32 | ||
33 | /* | ||
34 | * There are 2 versions of the timer hardware on Freescale MXC hardware. | ||
35 | * Version 1: MX1/MXL, MX21, MX27. | ||
36 | * Version 2: MX25, MX31, MX35, MX37, MX51 | ||
37 | */ | ||
38 | |||
33 | /* defines common for all i.MX */ | 39 | /* defines common for all i.MX */ |
34 | #define MXC_TCTL 0x00 | 40 | #define MXC_TCTL 0x00 |
35 | #define MXC_TCTL_TEN (1 << 0) | 41 | #define MXC_TCTL_TEN (1 << 0) /* Enable module */ |
36 | #define MXC_TPRER 0x04 | 42 | #define MXC_TPRER 0x04 |
37 | 43 | ||
38 | /* MX1, MX21, MX27 */ | 44 | /* MX1, MX21, MX27 */ |
@@ -47,8 +53,8 @@ | |||
47 | #define MX2_TSTAT_CAPT (1 << 1) | 53 | #define MX2_TSTAT_CAPT (1 << 1) |
48 | #define MX2_TSTAT_COMP (1 << 0) | 54 | #define MX2_TSTAT_COMP (1 << 0) |
49 | 55 | ||
50 | /* MX31, MX35, MX25, MXC91231 */ | 56 | /* MX31, MX35, MX25, MXC91231, MX5 */ |
51 | #define MX3_TCTL_WAITEN (1 << 3) | 57 | #define MX3_TCTL_WAITEN (1 << 3) /* Wait enable mode */ |
52 | #define MX3_TCTL_CLK_IPG (1 << 6) | 58 | #define MX3_TCTL_CLK_IPG (1 << 6) |
53 | #define MX3_TCTL_FRR (1 << 9) | 59 | #define MX3_TCTL_FRR (1 << 9) |
54 | #define MX3_IR 0x0c | 60 | #define MX3_IR 0x0c |
@@ -57,6 +63,9 @@ | |||
57 | #define MX3_TCN 0x24 | 63 | #define MX3_TCN 0x24 |
58 | #define MX3_TCMP 0x10 | 64 | #define MX3_TCMP 0x10 |
59 | 65 | ||
66 | #define timer_is_v1() (cpu_is_mx1() || cpu_is_mx21() || cpu_is_mx27()) | ||
67 | #define timer_is_v2() (!timer_is_v1()) | ||
68 | |||
60 | static struct clock_event_device clockevent_mxc; | 69 | static struct clock_event_device clockevent_mxc; |
61 | static enum clock_event_mode clockevent_mode = CLOCK_EVT_MODE_UNUSED; | 70 | static enum clock_event_mode clockevent_mode = CLOCK_EVT_MODE_UNUSED; |
62 | 71 | ||
@@ -66,7 +75,7 @@ static inline void gpt_irq_disable(void) | |||
66 | { | 75 | { |
67 | unsigned int tmp; | 76 | unsigned int tmp; |
68 | 77 | ||
69 | if (cpu_is_mx3() || cpu_is_mx25()) | 78 | if (timer_is_v2()) |
70 | __raw_writel(0, timer_base + MX3_IR); | 79 | __raw_writel(0, timer_base + MX3_IR); |
71 | else { | 80 | else { |
72 | tmp = __raw_readl(timer_base + MXC_TCTL); | 81 | tmp = __raw_readl(timer_base + MXC_TCTL); |
@@ -76,7 +85,7 @@ static inline void gpt_irq_disable(void) | |||
76 | 85 | ||
77 | static inline void gpt_irq_enable(void) | 86 | static inline void gpt_irq_enable(void) |
78 | { | 87 | { |
79 | if (cpu_is_mx3() || cpu_is_mx25()) | 88 | if (timer_is_v2()) |
80 | __raw_writel(1<<0, timer_base + MX3_IR); | 89 | __raw_writel(1<<0, timer_base + MX3_IR); |
81 | else { | 90 | else { |
82 | __raw_writel(__raw_readl(timer_base + MXC_TCTL) | MX1_2_TCTL_IRQEN, | 91 | __raw_writel(__raw_readl(timer_base + MXC_TCTL) | MX1_2_TCTL_IRQEN, |
@@ -86,11 +95,13 @@ static inline void gpt_irq_enable(void) | |||
86 | 95 | ||
87 | static void gpt_irq_acknowledge(void) | 96 | static void gpt_irq_acknowledge(void) |
88 | { | 97 | { |
89 | if (cpu_is_mx1()) | 98 | if (timer_is_v1()) { |
90 | __raw_writel(0, timer_base + MX1_2_TSTAT); | 99 | if (cpu_is_mx1()) |
91 | if (cpu_is_mx2()) | 100 | __raw_writel(0, timer_base + MX1_2_TSTAT); |
92 | __raw_writel(MX2_TSTAT_CAPT | MX2_TSTAT_COMP, timer_base + MX1_2_TSTAT); | 101 | else |
93 | if (cpu_is_mx3() || cpu_is_mx25()) | 102 | __raw_writel(MX2_TSTAT_CAPT | MX2_TSTAT_COMP, |
103 | timer_base + MX1_2_TSTAT); | ||
104 | } else if (timer_is_v2()) | ||
94 | __raw_writel(MX3_TSTAT_OF1, timer_base + MX3_TSTAT); | 105 | __raw_writel(MX3_TSTAT_OF1, timer_base + MX3_TSTAT); |
95 | } | 106 | } |
96 | 107 | ||
@@ -117,7 +128,7 @@ static int __init mxc_clocksource_init(struct clk *timer_clk) | |||
117 | { | 128 | { |
118 | unsigned int c = clk_get_rate(timer_clk); | 129 | unsigned int c = clk_get_rate(timer_clk); |
119 | 130 | ||
120 | if (cpu_is_mx3() || cpu_is_mx25()) | 131 | if (timer_is_v2()) |
121 | clocksource_mxc.read = mx3_get_cycles; | 132 | clocksource_mxc.read = mx3_get_cycles; |
122 | 133 | ||
123 | clocksource_mxc.mult = clocksource_hz2mult(c, | 134 | clocksource_mxc.mult = clocksource_hz2mult(c, |
@@ -180,7 +191,7 @@ static void mxc_set_mode(enum clock_event_mode mode, | |||
180 | 191 | ||
181 | if (mode != clockevent_mode) { | 192 | if (mode != clockevent_mode) { |
182 | /* Set event time into far-far future */ | 193 | /* Set event time into far-far future */ |
183 | if (cpu_is_mx3() || cpu_is_mx25()) | 194 | if (timer_is_v2()) |
184 | __raw_writel(__raw_readl(timer_base + MX3_TCN) - 3, | 195 | __raw_writel(__raw_readl(timer_base + MX3_TCN) - 3, |
185 | timer_base + MX3_TCMP); | 196 | timer_base + MX3_TCMP); |
186 | else | 197 | else |
@@ -233,7 +244,7 @@ static irqreturn_t mxc_timer_interrupt(int irq, void *dev_id) | |||
233 | struct clock_event_device *evt = &clockevent_mxc; | 244 | struct clock_event_device *evt = &clockevent_mxc; |
234 | uint32_t tstat; | 245 | uint32_t tstat; |
235 | 246 | ||
236 | if (cpu_is_mx3() || cpu_is_mx25()) | 247 | if (timer_is_v2()) |
237 | tstat = __raw_readl(timer_base + MX3_TSTAT); | 248 | tstat = __raw_readl(timer_base + MX3_TSTAT); |
238 | else | 249 | else |
239 | tstat = __raw_readl(timer_base + MX1_2_TSTAT); | 250 | tstat = __raw_readl(timer_base + MX1_2_TSTAT); |
@@ -264,7 +275,7 @@ static int __init mxc_clockevent_init(struct clk *timer_clk) | |||
264 | { | 275 | { |
265 | unsigned int c = clk_get_rate(timer_clk); | 276 | unsigned int c = clk_get_rate(timer_clk); |
266 | 277 | ||
267 | if (cpu_is_mx3() || cpu_is_mx25()) | 278 | if (timer_is_v2()) |
268 | clockevent_mxc.set_next_event = mx3_set_next_event; | 279 | clockevent_mxc.set_next_event = mx3_set_next_event; |
269 | 280 | ||
270 | clockevent_mxc.mult = div_sc(c, NSEC_PER_SEC, | 281 | clockevent_mxc.mult = div_sc(c, NSEC_PER_SEC, |
@@ -296,7 +307,7 @@ void __init mxc_timer_init(struct clk *timer_clk, void __iomem *base, int irq) | |||
296 | __raw_writel(0, timer_base + MXC_TCTL); | 307 | __raw_writel(0, timer_base + MXC_TCTL); |
297 | __raw_writel(0, timer_base + MXC_TPRER); /* see datasheet note */ | 308 | __raw_writel(0, timer_base + MXC_TPRER); /* see datasheet note */ |
298 | 309 | ||
299 | if (cpu_is_mx3() || cpu_is_mx25()) | 310 | if (timer_is_v2()) |
300 | tctl_val = MX3_TCTL_CLK_IPG | MX3_TCTL_FRR | MX3_TCTL_WAITEN | MXC_TCTL_TEN; | 311 | tctl_val = MX3_TCTL_CLK_IPG | MX3_TCTL_FRR | MX3_TCTL_WAITEN | MXC_TCTL_TEN; |
301 | else | 312 | else |
302 | tctl_val = MX1_2_TCTL_FRR | MX1_2_TCTL_CLK_PCLK1 | MXC_TCTL_TEN; | 313 | tctl_val = MX1_2_TCTL_FRR | MX1_2_TCTL_CLK_PCLK1 | MXC_TCTL_TEN; |