diff options
Diffstat (limited to 'arch/arm/plat-mxc/time.c')
| -rw-r--r-- | arch/arm/plat-mxc/time.c | 155 |
1 files changed, 135 insertions, 20 deletions
diff --git a/arch/arm/plat-mxc/time.c b/arch/arm/plat-mxc/time.c index dab3357196fb..88fb3a57e029 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 + MX3_TSTAT); | ||
| 238 | else | ||
| 239 | tstat = __raw_readl(timer_base + MX1_2_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 | } |
