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> |
| 24 | |
| 25 | #include <plat/cpu.h> |
| 26 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 27 | #include <mach/map.h> |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 28 | #include <mach/irqs.h> |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 29 | #include <mach/regs-mct.h> |
| 30 | #include <asm/mach/time.h> |
| 31 | |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 32 | #define TICK_BASE_CNT 1 |
| 33 | |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 34 | enum { |
| 35 | MCT_INT_SPI, |
| 36 | MCT_INT_PPI |
| 37 | }; |
| 38 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 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 | { |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 209 | unsigned long cycles_per_jiffy; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 210 | exynos4_mct_comp0_stop(); |
| 211 | |
| 212 | switch (mode) { |
| 213 | case CLOCK_EVT_MODE_PERIODIC: |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 214 | cycles_per_jiffy = |
| 215 | (((unsigned long long) NSEC_PER_SEC / HZ * evt->mult) >> evt->shift); |
| 216 | exynos4_mct_comp0_start(mode, cycles_per_jiffy); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 217 | break; |
| 218 | |
| 219 | case CLOCK_EVT_MODE_ONESHOT: |
| 220 | case CLOCK_EVT_MODE_UNUSED: |
| 221 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 222 | case CLOCK_EVT_MODE_RESUME: |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | static struct clock_event_device mct_comp_device = { |
| 228 | .name = "mct-comp", |
| 229 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, |
| 230 | .rating = 250, |
| 231 | .set_next_event = exynos4_comp_set_next_event, |
| 232 | .set_mode = exynos4_comp_set_mode, |
| 233 | }; |
| 234 | |
| 235 | static irqreturn_t exynos4_mct_comp_isr(int irq, void *dev_id) |
| 236 | { |
| 237 | struct clock_event_device *evt = dev_id; |
| 238 | |
| 239 | exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_CSTAT); |
| 240 | |
| 241 | evt->event_handler(evt); |
| 242 | |
| 243 | return IRQ_HANDLED; |
| 244 | } |
| 245 | |
| 246 | static struct irqaction mct_comp_event_irq = { |
| 247 | .name = "mct_comp_irq", |
| 248 | .flags = IRQF_TIMER | IRQF_IRQPOLL, |
| 249 | .handler = exynos4_mct_comp_isr, |
| 250 | .dev_id = &mct_comp_device, |
| 251 | }; |
| 252 | |
| 253 | static void exynos4_clockevent_init(void) |
| 254 | { |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 255 | clockevents_calc_mult_shift(&mct_comp_device, clk_rate, 5); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 256 | mct_comp_device.max_delta_ns = |
| 257 | clockevent_delta2ns(0xffffffff, &mct_comp_device); |
| 258 | mct_comp_device.min_delta_ns = |
| 259 | clockevent_delta2ns(0xf, &mct_comp_device); |
| 260 | mct_comp_device.cpumask = cpumask_of(0); |
| 261 | clockevents_register_device(&mct_comp_device); |
| 262 | |
| 263 | setup_irq(IRQ_MCT_G0, &mct_comp_event_irq); |
| 264 | } |
| 265 | |
| 266 | #ifdef CONFIG_LOCAL_TIMERS |
Kukjin Kim | 991a6c7 | 2011-12-08 10:04:49 +0900 | [diff] [blame] | 267 | |
| 268 | static DEFINE_PER_CPU(struct mct_clock_event_device, percpu_mct_tick); |
| 269 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 270 | /* Clock event handling */ |
| 271 | static void exynos4_mct_tick_stop(struct mct_clock_event_device *mevt) |
| 272 | { |
| 273 | unsigned long tmp; |
| 274 | unsigned long mask = MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START; |
| 275 | void __iomem *addr = mevt->base + MCT_L_TCON_OFFSET; |
| 276 | |
| 277 | tmp = __raw_readl(addr); |
| 278 | if (tmp & mask) { |
| 279 | tmp &= ~mask; |
| 280 | exynos4_mct_write(tmp, addr); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | static void exynos4_mct_tick_start(unsigned long cycles, |
| 285 | struct mct_clock_event_device *mevt) |
| 286 | { |
| 287 | unsigned long tmp; |
| 288 | |
| 289 | exynos4_mct_tick_stop(mevt); |
| 290 | |
| 291 | tmp = (1 << 31) | cycles; /* MCT_L_UPDATE_ICNTB */ |
| 292 | |
| 293 | /* update interrupt count buffer */ |
| 294 | exynos4_mct_write(tmp, mevt->base + MCT_L_ICNTB_OFFSET); |
| 295 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 296 | /* enable MCT tick interrupt */ |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 297 | exynos4_mct_write(0x1, mevt->base + MCT_L_INT_ENB_OFFSET); |
| 298 | |
| 299 | tmp = __raw_readl(mevt->base + MCT_L_TCON_OFFSET); |
| 300 | tmp |= MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START | |
| 301 | MCT_L_TCON_INTERVAL_MODE; |
| 302 | exynos4_mct_write(tmp, mevt->base + MCT_L_TCON_OFFSET); |
| 303 | } |
| 304 | |
| 305 | static int exynos4_tick_set_next_event(unsigned long cycles, |
| 306 | struct clock_event_device *evt) |
| 307 | { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 308 | struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 309 | |
| 310 | exynos4_mct_tick_start(cycles, mevt); |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static inline void exynos4_tick_set_mode(enum clock_event_mode mode, |
| 316 | struct clock_event_device *evt) |
| 317 | { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 318 | struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick); |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 319 | unsigned long cycles_per_jiffy; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 320 | |
| 321 | exynos4_mct_tick_stop(mevt); |
| 322 | |
| 323 | switch (mode) { |
| 324 | case CLOCK_EVT_MODE_PERIODIC: |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 325 | cycles_per_jiffy = |
| 326 | (((unsigned long long) NSEC_PER_SEC / HZ * evt->mult) >> evt->shift); |
| 327 | exynos4_mct_tick_start(cycles_per_jiffy, mevt); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 328 | break; |
| 329 | |
| 330 | case CLOCK_EVT_MODE_ONESHOT: |
| 331 | case CLOCK_EVT_MODE_UNUSED: |
| 332 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 333 | case CLOCK_EVT_MODE_RESUME: |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
Changhwan Youn | c898747 | 2011-10-04 17:09:26 +0900 | [diff] [blame] | 338 | static int exynos4_mct_tick_clear(struct mct_clock_event_device *mevt) |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 339 | { |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 340 | struct clock_event_device *evt = mevt->evt; |
| 341 | |
| 342 | /* |
| 343 | * This is for supporting oneshot mode. |
| 344 | * Mct would generate interrupt periodically |
| 345 | * without explicit stopping. |
| 346 | */ |
| 347 | if (evt->mode != CLOCK_EVT_MODE_PERIODIC) |
| 348 | exynos4_mct_tick_stop(mevt); |
| 349 | |
| 350 | /* Clear the MCT tick interrupt */ |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 351 | if (__raw_readl(mevt->base + MCT_L_INT_CSTAT_OFFSET) & 1) { |
| 352 | exynos4_mct_write(0x1, mevt->base + MCT_L_INT_CSTAT_OFFSET); |
| 353 | return 1; |
| 354 | } else { |
| 355 | return 0; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | static irqreturn_t exynos4_mct_tick_isr(int irq, void *dev_id) |
| 360 | { |
| 361 | struct mct_clock_event_device *mevt = dev_id; |
| 362 | struct clock_event_device *evt = mevt->evt; |
| 363 | |
| 364 | exynos4_mct_tick_clear(mevt); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 365 | |
| 366 | evt->event_handler(evt); |
| 367 | |
| 368 | return IRQ_HANDLED; |
| 369 | } |
| 370 | |
| 371 | static struct irqaction mct_tick0_event_irq = { |
| 372 | .name = "mct_tick0_irq", |
| 373 | .flags = IRQF_TIMER | IRQF_NOBALANCING, |
| 374 | .handler = exynos4_mct_tick_isr, |
| 375 | }; |
| 376 | |
| 377 | static struct irqaction mct_tick1_event_irq = { |
| 378 | .name = "mct_tick1_irq", |
| 379 | .flags = IRQF_TIMER | IRQF_NOBALANCING, |
| 380 | .handler = exynos4_mct_tick_isr, |
| 381 | }; |
| 382 | |
| 383 | static void exynos4_mct_tick_init(struct clock_event_device *evt) |
| 384 | { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 385 | struct mct_clock_event_device *mevt; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 386 | unsigned int cpu = smp_processor_id(); |
| 387 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 388 | mevt = this_cpu_ptr(&percpu_mct_tick); |
| 389 | mevt->evt = evt; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 390 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 391 | mevt->base = EXYNOS4_MCT_L_BASE(cpu); |
| 392 | sprintf(mevt->name, "mct_tick%d", cpu); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 393 | |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 394 | evt->name = mevt->name; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 395 | evt->cpumask = cpumask_of(cpu); |
| 396 | evt->set_next_event = exynos4_tick_set_next_event; |
| 397 | evt->set_mode = exynos4_tick_set_mode; |
| 398 | evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; |
| 399 | evt->rating = 450; |
| 400 | |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 401 | clockevents_calc_mult_shift(evt, clk_rate / (TICK_BASE_CNT + 1), 5); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 402 | evt->max_delta_ns = |
| 403 | clockevent_delta2ns(0x7fffffff, evt); |
| 404 | evt->min_delta_ns = |
| 405 | clockevent_delta2ns(0xf, evt); |
| 406 | |
| 407 | clockevents_register_device(evt); |
| 408 | |
Changhwan Youn | 4d2e4d7 | 2012-03-09 15:09:21 -0800 | [diff] [blame^] | 409 | exynos4_mct_write(TICK_BASE_CNT, mevt->base + MCT_L_TCNTB_OFFSET); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 410 | |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 411 | if (mct_int_type == MCT_INT_SPI) { |
| 412 | if (cpu == 0) { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 413 | mct_tick0_event_irq.dev_id = mevt; |
Arnd Bergmann | a7fadac | 2011-10-31 23:58:06 +0100 | [diff] [blame] | 414 | evt->irq = IRQ_MCT_L0; |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 415 | setup_irq(IRQ_MCT_L0, &mct_tick0_event_irq); |
| 416 | } else { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 417 | mct_tick1_event_irq.dev_id = mevt; |
Arnd Bergmann | a7fadac | 2011-10-31 23:58:06 +0100 | [diff] [blame] | 418 | evt->irq = IRQ_MCT_L1; |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 419 | setup_irq(IRQ_MCT_L1, &mct_tick1_event_irq); |
| 420 | irq_set_affinity(IRQ_MCT_L1, cpumask_of(1)); |
| 421 | } |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 422 | } else { |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 423 | enable_percpu_irq(IRQ_MCT_LOCALTIMER, 0); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | /* Setup the local clock events for a CPU */ |
Kukjin Kim | 4d487d7 | 2011-08-24 16:07:39 +0900 | [diff] [blame] | 428 | int __cpuinit local_timer_setup(struct clock_event_device *evt) |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 429 | { |
| 430 | exynos4_mct_tick_init(evt); |
Kukjin Kim | 4d487d7 | 2011-08-24 16:07:39 +0900 | [diff] [blame] | 431 | |
| 432 | return 0; |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 433 | } |
| 434 | |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame] | 435 | void local_timer_stop(struct clock_event_device *evt) |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 436 | { |
Amit Daniel Kachhap | e248cd5 | 2011-12-08 10:07:08 +0900 | [diff] [blame] | 437 | unsigned int cpu = smp_processor_id(); |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame] | 438 | evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt); |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 439 | if (mct_int_type == MCT_INT_SPI) |
Amit Daniel Kachhap | e248cd5 | 2011-12-08 10:07:08 +0900 | [diff] [blame] | 440 | if (cpu == 0) |
| 441 | remove_irq(evt->irq, &mct_tick0_event_irq); |
| 442 | else |
| 443 | remove_irq(evt->irq, &mct_tick1_event_irq); |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 444 | else |
| 445 | disable_percpu_irq(IRQ_MCT_LOCALTIMER); |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 446 | } |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 447 | #endif /* CONFIG_LOCAL_TIMERS */ |
| 448 | |
| 449 | static void __init exynos4_timer_resources(void) |
| 450 | { |
| 451 | struct clk *mct_clk; |
| 452 | mct_clk = clk_get(NULL, "xtal"); |
| 453 | |
| 454 | clk_rate = clk_get_rate(mct_clk); |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 455 | |
Kukjin Kim | 991a6c7 | 2011-12-08 10:04:49 +0900 | [diff] [blame] | 456 | #ifdef CONFIG_LOCAL_TIMERS |
Marc Zyngier | e700e41 | 2011-11-03 11:13:12 +0900 | [diff] [blame] | 457 | if (mct_int_type == MCT_INT_PPI) { |
| 458 | int err; |
| 459 | |
| 460 | err = request_percpu_irq(IRQ_MCT_LOCALTIMER, |
| 461 | exynos4_mct_tick_isr, "MCT", |
| 462 | &percpu_mct_tick); |
| 463 | WARN(err, "MCT: can't request IRQ %d (%d)\n", |
| 464 | IRQ_MCT_LOCALTIMER, err); |
| 465 | } |
Kukjin Kim | 991a6c7 | 2011-12-08 10:04:49 +0900 | [diff] [blame] | 466 | #endif /* CONFIG_LOCAL_TIMERS */ |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static void __init exynos4_timer_init(void) |
| 470 | { |
Changhwan Youn | 3a06228 | 2011-10-04 17:02:58 +0900 | [diff] [blame] | 471 | if (soc_is_exynos4210()) |
| 472 | mct_int_type = MCT_INT_SPI; |
| 473 | else |
| 474 | mct_int_type = MCT_INT_PPI; |
| 475 | |
Changhwan Youn | 30d8bea | 2011-03-11 10:39:57 +0900 | [diff] [blame] | 476 | exynos4_timer_resources(); |
| 477 | exynos4_clocksource_init(); |
| 478 | exynos4_clockevent_init(); |
| 479 | } |
| 480 | |
| 481 | struct sys_timer exynos4_timer = { |
| 482 | .init = exynos4_timer_init, |
| 483 | }; |