Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 1 | /* linux/arch/arm/mach-exynos4/mct.c |
| 2 | * |
| 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 4 | * http://www.samsung.com |
| 5 | * |
| 6 | * EXYNOS4 MCT(Multi-Core Timer) support |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/irq.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/clockchips.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/percpu.h> |
| 22 | |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 23 | #include <asm/hardware/gic.h> |
Marc Zyngier | a8cb604 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 24 | #include <asm/localtimer.h> |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 25 | |
| 26 | #include <plat/cpu.h> |
| 27 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 28 | #include <mach/map.h> |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 29 | #include <mach/irqs.h> |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 30 | #include <mach/regs-mct.h> |
| 31 | #include <asm/mach/time.h> |
| 32 | |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 33 | enum { |
| 34 | MCT_INT_SPI, |
| 35 | MCT_INT_PPI |
| 36 | }; |
| 37 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 38 | static unsigned long clk_cnt_per_tick; |
| 39 | static unsigned long clk_rate; |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 40 | static unsigned int mct_int_type; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 41 | |
| 42 | struct mct_clock_event_device { |
| 43 | struct clock_event_device *evt; |
| 44 | void __iomem *base; |
Changhwan Youn | c898747 | 2011-10-04 17:09:26 +0900 | [diff] [blame] | 45 | char name[10]; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 46 | }; |
| 47 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 48 | static void exynos4_mct_write(unsigned int value, void *addr) |
| 49 | { |
| 50 | void __iomem *stat_addr; |
| 51 | u32 mask; |
| 52 | u32 i; |
| 53 | |
| 54 | __raw_writel(value, addr); |
| 55 | |
Changhwan Youn | c898747 | 2011-10-04 17:09:26 +0900 | [diff] [blame] | 56 | if (likely(addr >= EXYNOS4_MCT_L_BASE(0))) { |
| 57 | u32 base = (u32) addr & EXYNOS4_MCT_L_MASK; |
| 58 | switch ((u32) addr & ~EXYNOS4_MCT_L_MASK) { |
| 59 | case (u32) MCT_L_TCON_OFFSET: |
| 60 | stat_addr = (void __iomem *) base + MCT_L_WSTAT_OFFSET; |
| 61 | mask = 1 << 3; /* L_TCON write status */ |
| 62 | break; |
| 63 | case (u32) MCT_L_ICNTB_OFFSET: |
| 64 | stat_addr = (void __iomem *) base + MCT_L_WSTAT_OFFSET; |
| 65 | mask = 1 << 1; /* L_ICNTB write status */ |
| 66 | break; |
| 67 | case (u32) MCT_L_TCNTB_OFFSET: |
| 68 | stat_addr = (void __iomem *) base + MCT_L_WSTAT_OFFSET; |
| 69 | mask = 1 << 0; /* L_TCNTB write status */ |
| 70 | break; |
| 71 | default: |
| 72 | return; |
| 73 | } |
| 74 | } else { |
| 75 | switch ((u32) addr) { |
| 76 | case (u32) EXYNOS4_MCT_G_TCON: |
| 77 | stat_addr = EXYNOS4_MCT_G_WSTAT; |
| 78 | mask = 1 << 16; /* G_TCON write status */ |
| 79 | break; |
| 80 | case (u32) EXYNOS4_MCT_G_COMP0_L: |
| 81 | stat_addr = EXYNOS4_MCT_G_WSTAT; |
| 82 | mask = 1 << 0; /* G_COMP0_L write status */ |
| 83 | break; |
| 84 | case (u32) EXYNOS4_MCT_G_COMP0_U: |
| 85 | stat_addr = EXYNOS4_MCT_G_WSTAT; |
| 86 | mask = 1 << 1; /* G_COMP0_U write status */ |
| 87 | break; |
| 88 | case (u32) EXYNOS4_MCT_G_COMP0_ADD_INCR: |
| 89 | stat_addr = EXYNOS4_MCT_G_WSTAT; |
| 90 | mask = 1 << 2; /* G_COMP0_ADD_INCR w status */ |
| 91 | break; |
| 92 | case (u32) EXYNOS4_MCT_G_CNT_L: |
| 93 | stat_addr = EXYNOS4_MCT_G_CNT_WSTAT; |
| 94 | mask = 1 << 0; /* G_CNT_L write status */ |
| 95 | break; |
| 96 | case (u32) EXYNOS4_MCT_G_CNT_U: |
| 97 | stat_addr = EXYNOS4_MCT_G_CNT_WSTAT; |
| 98 | mask = 1 << 1; /* G_CNT_U write status */ |
| 99 | break; |
| 100 | default: |
| 101 | return; |
| 102 | } |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* Wait maximum 1 ms until written values are applied */ |
| 106 | for (i = 0; i < loops_per_jiffy / 1000 * HZ; i++) |
| 107 | if (__raw_readl(stat_addr) & mask) { |
| 108 | __raw_writel(mask, stat_addr); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | panic("MCT hangs after writing %d (addr:0x%08x)\n", value, (u32)addr); |
| 113 | } |
| 114 | |
| 115 | /* Clocksource handling */ |
| 116 | static void exynos4_mct_frc_start(u32 hi, u32 lo) |
| 117 | { |
| 118 | u32 reg; |
| 119 | |
| 120 | exynos4_mct_write(lo, EXYNOS4_MCT_G_CNT_L); |
| 121 | exynos4_mct_write(hi, EXYNOS4_MCT_G_CNT_U); |
| 122 | |
| 123 | reg = __raw_readl(EXYNOS4_MCT_G_TCON); |
| 124 | reg |= MCT_G_TCON_START; |
| 125 | exynos4_mct_write(reg, EXYNOS4_MCT_G_TCON); |
| 126 | } |
| 127 | |
| 128 | static cycle_t exynos4_frc_read(struct clocksource *cs) |
| 129 | { |
| 130 | unsigned int lo, hi; |
| 131 | u32 hi2 = __raw_readl(EXYNOS4_MCT_G_CNT_U); |
| 132 | |
| 133 | do { |
| 134 | hi = hi2; |
| 135 | lo = __raw_readl(EXYNOS4_MCT_G_CNT_L); |
| 136 | hi2 = __raw_readl(EXYNOS4_MCT_G_CNT_U); |
| 137 | } while (hi != hi2); |
| 138 | |
| 139 | return ((cycle_t)hi << 32) | lo; |
| 140 | } |
| 141 | |
Changhwan Youn | aa421c1 | 2011-09-02 14:10:52 +0900 | [diff] [blame] | 142 | static void exynos4_frc_resume(struct clocksource *cs) |
| 143 | { |
| 144 | exynos4_mct_frc_start(0, 0); |
| 145 | } |
| 146 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 147 | struct clocksource mct_frc = { |
| 148 | .name = "mct-frc", |
| 149 | .rating = 400, |
| 150 | .read = exynos4_frc_read, |
| 151 | .mask = CLOCKSOURCE_MASK(64), |
| 152 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
Changhwan Youn | aa421c1 | 2011-09-02 14:10:52 +0900 | [diff] [blame] | 153 | .resume = exynos4_frc_resume, |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | static void __init exynos4_clocksource_init(void) |
| 157 | { |
| 158 | exynos4_mct_frc_start(0, 0); |
| 159 | |
| 160 | if (clocksource_register_hz(&mct_frc, clk_rate)) |
| 161 | panic("%s: can't register clocksource\n", mct_frc.name); |
| 162 | } |
| 163 | |
| 164 | static void exynos4_mct_comp0_stop(void) |
| 165 | { |
| 166 | unsigned int tcon; |
| 167 | |
| 168 | tcon = __raw_readl(EXYNOS4_MCT_G_TCON); |
| 169 | tcon &= ~(MCT_G_TCON_COMP0_ENABLE | MCT_G_TCON_COMP0_AUTO_INC); |
| 170 | |
| 171 | exynos4_mct_write(tcon, EXYNOS4_MCT_G_TCON); |
| 172 | exynos4_mct_write(0, EXYNOS4_MCT_G_INT_ENB); |
| 173 | } |
| 174 | |
| 175 | static void exynos4_mct_comp0_start(enum clock_event_mode mode, |
| 176 | unsigned long cycles) |
| 177 | { |
| 178 | unsigned int tcon; |
| 179 | cycle_t comp_cycle; |
| 180 | |
| 181 | tcon = __raw_readl(EXYNOS4_MCT_G_TCON); |
| 182 | |
| 183 | if (mode == CLOCK_EVT_MODE_PERIODIC) { |
| 184 | tcon |= MCT_G_TCON_COMP0_AUTO_INC; |
| 185 | exynos4_mct_write(cycles, EXYNOS4_MCT_G_COMP0_ADD_INCR); |
| 186 | } |
| 187 | |
| 188 | comp_cycle = exynos4_frc_read(&mct_frc) + cycles; |
| 189 | exynos4_mct_write((u32)comp_cycle, EXYNOS4_MCT_G_COMP0_L); |
| 190 | exynos4_mct_write((u32)(comp_cycle >> 32), EXYNOS4_MCT_G_COMP0_U); |
| 191 | |
| 192 | exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_ENB); |
| 193 | |
| 194 | tcon |= MCT_G_TCON_COMP0_ENABLE; |
| 195 | exynos4_mct_write(tcon , EXYNOS4_MCT_G_TCON); |
| 196 | } |
| 197 | |
| 198 | static int exynos4_comp_set_next_event(unsigned long cycles, |
| 199 | struct clock_event_device *evt) |
| 200 | { |
| 201 | exynos4_mct_comp0_start(evt->mode, cycles); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | static void exynos4_comp_set_mode(enum clock_event_mode mode, |
| 207 | struct clock_event_device *evt) |
| 208 | { |
| 209 | exynos4_mct_comp0_stop(); |
| 210 | |
| 211 | switch (mode) { |
| 212 | case CLOCK_EVT_MODE_PERIODIC: |
| 213 | exynos4_mct_comp0_start(mode, clk_cnt_per_tick); |
| 214 | break; |
| 215 | |
| 216 | case CLOCK_EVT_MODE_ONESHOT: |
| 217 | case CLOCK_EVT_MODE_UNUSED: |
| 218 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 219 | case CLOCK_EVT_MODE_RESUME: |
| 220 | break; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | static struct clock_event_device mct_comp_device = { |
| 225 | .name = "mct-comp", |
| 226 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, |
| 227 | .rating = 250, |
| 228 | .set_next_event = exynos4_comp_set_next_event, |
| 229 | .set_mode = exynos4_comp_set_mode, |
| 230 | }; |
| 231 | |
| 232 | static irqreturn_t exynos4_mct_comp_isr(int irq, void *dev_id) |
| 233 | { |
| 234 | struct clock_event_device *evt = dev_id; |
| 235 | |
| 236 | exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_CSTAT); |
| 237 | |
| 238 | evt->event_handler(evt); |
| 239 | |
| 240 | return IRQ_HANDLED; |
| 241 | } |
| 242 | |
| 243 | static struct irqaction mct_comp_event_irq = { |
| 244 | .name = "mct_comp_irq", |
| 245 | .flags = IRQF_TIMER | IRQF_IRQPOLL, |
| 246 | .handler = exynos4_mct_comp_isr, |
| 247 | .dev_id = &mct_comp_device, |
| 248 | }; |
| 249 | |
| 250 | static void exynos4_clockevent_init(void) |
| 251 | { |
| 252 | clk_cnt_per_tick = clk_rate / 2 / HZ; |
| 253 | |
| 254 | clockevents_calc_mult_shift(&mct_comp_device, clk_rate / 2, 5); |
| 255 | mct_comp_device.max_delta_ns = |
| 256 | clockevent_delta2ns(0xffffffff, &mct_comp_device); |
| 257 | mct_comp_device.min_delta_ns = |
| 258 | clockevent_delta2ns(0xf, &mct_comp_device); |
| 259 | mct_comp_device.cpumask = cpumask_of(0); |
| 260 | clockevents_register_device(&mct_comp_device); |
| 261 | |
| 262 | setup_irq(IRQ_MCT_G0, &mct_comp_event_irq); |
| 263 | } |
| 264 | |
| 265 | #ifdef CONFIG_LOCAL_TIMERS |
Kukjin Kim | 991a6c7 | 2011-12-08 10:04:49 +0900 | [diff] [blame] | 266 | |
| 267 | static DEFINE_PER_CPU(struct mct_clock_event_device, percpu_mct_tick); |
| 268 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 269 | /* Clock event handling */ |
| 270 | static void exynos4_mct_tick_stop(struct mct_clock_event_device *mevt) |
| 271 | { |
| 272 | unsigned long tmp; |
| 273 | unsigned long mask = MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START; |
| 274 | void __iomem *addr = mevt->base + MCT_L_TCON_OFFSET; |
| 275 | |
| 276 | tmp = __raw_readl(addr); |
| 277 | if (tmp & mask) { |
| 278 | tmp &= ~mask; |
| 279 | exynos4_mct_write(tmp, addr); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static void exynos4_mct_tick_start(unsigned long cycles, |
| 284 | struct mct_clock_event_device *mevt) |
| 285 | { |
| 286 | unsigned long tmp; |
| 287 | |
| 288 | exynos4_mct_tick_stop(mevt); |
| 289 | |
| 290 | tmp = (1 << 31) | cycles; /* MCT_L_UPDATE_ICNTB */ |
| 291 | |
| 292 | /* update interrupt count buffer */ |
| 293 | exynos4_mct_write(tmp, mevt->base + MCT_L_ICNTB_OFFSET); |
| 294 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 295 | /* enable MCT tick interrupt */ |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 296 | exynos4_mct_write(0x1, mevt->base + MCT_L_INT_ENB_OFFSET); |
| 297 | |
| 298 | tmp = __raw_readl(mevt->base + MCT_L_TCON_OFFSET); |
| 299 | tmp |= MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START | |
| 300 | MCT_L_TCON_INTERVAL_MODE; |
| 301 | exynos4_mct_write(tmp, mevt->base + MCT_L_TCON_OFFSET); |
| 302 | } |
| 303 | |
| 304 | static int exynos4_tick_set_next_event(unsigned long cycles, |
| 305 | struct clock_event_device *evt) |
| 306 | { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 307 | struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 308 | |
| 309 | exynos4_mct_tick_start(cycles, mevt); |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static inline void exynos4_tick_set_mode(enum clock_event_mode mode, |
| 315 | struct clock_event_device *evt) |
| 316 | { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 317 | struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 318 | |
| 319 | exynos4_mct_tick_stop(mevt); |
| 320 | |
| 321 | switch (mode) { |
| 322 | case CLOCK_EVT_MODE_PERIODIC: |
| 323 | exynos4_mct_tick_start(clk_cnt_per_tick, mevt); |
| 324 | break; |
| 325 | |
| 326 | case CLOCK_EVT_MODE_ONESHOT: |
| 327 | case CLOCK_EVT_MODE_UNUSED: |
| 328 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 329 | case CLOCK_EVT_MODE_RESUME: |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
Changhwan Youn | c898747 | 2011-10-04 17:09:26 +0900 | [diff] [blame] | 334 | static int exynos4_mct_tick_clear(struct mct_clock_event_device *mevt) |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 335 | { |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 336 | struct clock_event_device *evt = mevt->evt; |
| 337 | |
| 338 | /* |
| 339 | * This is for supporting oneshot mode. |
| 340 | * Mct would generate interrupt periodically |
| 341 | * without explicit stopping. |
| 342 | */ |
| 343 | if (evt->mode != CLOCK_EVT_MODE_PERIODIC) |
| 344 | exynos4_mct_tick_stop(mevt); |
| 345 | |
| 346 | /* Clear the MCT tick interrupt */ |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 347 | if (__raw_readl(mevt->base + MCT_L_INT_CSTAT_OFFSET) & 1) { |
| 348 | exynos4_mct_write(0x1, mevt->base + MCT_L_INT_CSTAT_OFFSET); |
| 349 | return 1; |
| 350 | } else { |
| 351 | return 0; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | static irqreturn_t exynos4_mct_tick_isr(int irq, void *dev_id) |
| 356 | { |
| 357 | struct mct_clock_event_device *mevt = dev_id; |
| 358 | struct clock_event_device *evt = mevt->evt; |
| 359 | |
| 360 | exynos4_mct_tick_clear(mevt); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 361 | |
| 362 | evt->event_handler(evt); |
| 363 | |
| 364 | return IRQ_HANDLED; |
| 365 | } |
| 366 | |
| 367 | static struct irqaction mct_tick0_event_irq = { |
| 368 | .name = "mct_tick0_irq", |
| 369 | .flags = IRQF_TIMER | IRQF_NOBALANCING, |
| 370 | .handler = exynos4_mct_tick_isr, |
| 371 | }; |
| 372 | |
| 373 | static struct irqaction mct_tick1_event_irq = { |
| 374 | .name = "mct_tick1_irq", |
| 375 | .flags = IRQF_TIMER | IRQF_NOBALANCING, |
| 376 | .handler = exynos4_mct_tick_isr, |
| 377 | }; |
| 378 | |
Marc Zyngier | a8cb604 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 379 | static int __cpuinit exynos4_local_timer_setup(struct clock_event_device *evt) |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 380 | { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 381 | struct mct_clock_event_device *mevt; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 382 | unsigned int cpu = smp_processor_id(); |
| 383 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 384 | mevt = this_cpu_ptr(&percpu_mct_tick); |
| 385 | mevt->evt = evt; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 386 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 387 | mevt->base = EXYNOS4_MCT_L_BASE(cpu); |
| 388 | sprintf(mevt->name, "mct_tick%d", cpu); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 389 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 390 | evt->name = mevt->name; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 391 | evt->cpumask = cpumask_of(cpu); |
| 392 | evt->set_next_event = exynos4_tick_set_next_event; |
| 393 | evt->set_mode = exynos4_tick_set_mode; |
| 394 | evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; |
| 395 | evt->rating = 450; |
| 396 | |
| 397 | clockevents_calc_mult_shift(evt, clk_rate / 2, 5); |
| 398 | evt->max_delta_ns = |
| 399 | clockevent_delta2ns(0x7fffffff, evt); |
| 400 | evt->min_delta_ns = |
| 401 | clockevent_delta2ns(0xf, evt); |
| 402 | |
| 403 | clockevents_register_device(evt); |
| 404 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 405 | exynos4_mct_write(0x1, mevt->base + MCT_L_TCNTB_OFFSET); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 406 | |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 407 | if (mct_int_type == MCT_INT_SPI) { |
| 408 | if (cpu == 0) { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 409 | mct_tick0_event_irq.dev_id = mevt; |
Arnd Bergmann | a7fadac | 2011-10-31 23:58:06 +0100 | [diff] [blame] | 410 | evt->irq = IRQ_MCT_L0; |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 411 | setup_irq(IRQ_MCT_L0, &mct_tick0_event_irq); |
| 412 | } else { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 413 | mct_tick1_event_irq.dev_id = mevt; |
Arnd Bergmann | a7fadac | 2011-10-31 23:58:06 +0100 | [diff] [blame] | 414 | evt->irq = IRQ_MCT_L1; |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 415 | setup_irq(IRQ_MCT_L1, &mct_tick1_event_irq); |
| 416 | irq_set_affinity(IRQ_MCT_L1, cpumask_of(1)); |
| 417 | } |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 418 | } else { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 419 | enable_percpu_irq(IRQ_MCT_LOCALTIMER, 0); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 420 | } |
Kukjin Kim | 4d487d7 | 2011-08-24 16:07:39 +0900 | [diff] [blame] | 421 | |
| 422 | return 0; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 423 | } |
| 424 | |
Marc Zyngier | a8cb604 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 425 | static void exynos4_local_timer_stop(struct clock_event_device *evt) |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 426 | { |
Amit Daniel Kachhap | e248cd5 | 2011-12-08 10:07:08 +0900 | [diff] [blame] | 427 | unsigned int cpu = smp_processor_id(); |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame] | 428 | evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt); |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 429 | if (mct_int_type == MCT_INT_SPI) |
Amit Daniel Kachhap | e248cd5 | 2011-12-08 10:07:08 +0900 | [diff] [blame] | 430 | if (cpu == 0) |
| 431 | remove_irq(evt->irq, &mct_tick0_event_irq); |
| 432 | else |
| 433 | remove_irq(evt->irq, &mct_tick1_event_irq); |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 434 | else |
| 435 | disable_percpu_irq(IRQ_MCT_LOCALTIMER); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 436 | } |
Marc Zyngier | a8cb604 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 437 | |
| 438 | static struct local_timer_ops exynos4_mct_tick_ops __cpuinitdata = { |
| 439 | .setup = exynos4_local_timer_setup, |
| 440 | .stop = exynos4_local_timer_stop, |
| 441 | }; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 442 | #endif /* CONFIG_LOCAL_TIMERS */ |
| 443 | |
| 444 | static void __init exynos4_timer_resources(void) |
| 445 | { |
| 446 | struct clk *mct_clk; |
| 447 | mct_clk = clk_get(NULL, "xtal"); |
| 448 | |
| 449 | clk_rate = clk_get_rate(mct_clk); |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 450 | |
Kukjin Kim | 991a6c7 | 2011-12-08 10:04:49 +0900 | [diff] [blame] | 451 | #ifdef CONFIG_LOCAL_TIMERS |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 452 | if (mct_int_type == MCT_INT_PPI) { |
| 453 | int err; |
| 454 | |
| 455 | err = request_percpu_irq(IRQ_MCT_LOCALTIMER, |
| 456 | exynos4_mct_tick_isr, "MCT", |
| 457 | &percpu_mct_tick); |
| 458 | WARN(err, "MCT: can't request IRQ %d (%d)\n", |
| 459 | IRQ_MCT_LOCALTIMER, err); |
| 460 | } |
Marc Zyngier | a8cb604 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 461 | |
| 462 | local_timer_register(&exynos4_mct_tick_ops); |
Kukjin Kim | 991a6c7 | 2011-12-08 10:04:49 +0900 | [diff] [blame] | 463 | #endif /* CONFIG_LOCAL_TIMERS */ |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void __init exynos4_timer_init(void) |
| 467 | { |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 468 | if (soc_is_exynos4210()) |
| 469 | mct_int_type = MCT_INT_SPI; |
| 470 | else |
| 471 | mct_int_type = MCT_INT_PPI; |
| 472 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 473 | exynos4_timer_resources(); |
| 474 | exynos4_clocksource_init(); |
| 475 | exynos4_clockevent_init(); |
| 476 | } |
| 477 | |
| 478 | struct sys_timer exynos4_timer = { |
| 479 | .init = exynos4_timer_init, |
| 480 | }; |