blob: ffd1323ed7db4de9e1d28112315c14d4c0515c2a [file] [log] [blame]
Changhwan Youn30d8bea2011-03-11 10:39:57 +09001/* 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>
Kukjin Kim2edb36c2012-11-15 15:48:56 +090022#include <linux/of.h>
Changhwan Youn30d8bea2011-03-11 10:39:57 +090023
Kukjin Kim2edb36c2012-11-15 15:48:56 +090024#include <asm/arch_timer.h>
Marc Zyngiera8cb6042012-01-10 19:44:19 +000025#include <asm/localtimer.h>
Changhwan Youn3a062282011-10-04 17:02:58 +090026
27#include <plat/cpu.h>
28
Changhwan Youn30d8bea2011-03-11 10:39:57 +090029#include <mach/map.h>
Changhwan Youn3a062282011-10-04 17:02:58 +090030#include <mach/irqs.h>
Changhwan Youn30d8bea2011-03-11 10:39:57 +090031#include <asm/mach/time.h>
32
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090033#define EXYNOS4_MCTREG(x) (x)
34#define EXYNOS4_MCT_G_CNT_L EXYNOS4_MCTREG(0x100)
35#define EXYNOS4_MCT_G_CNT_U EXYNOS4_MCTREG(0x104)
36#define EXYNOS4_MCT_G_CNT_WSTAT EXYNOS4_MCTREG(0x110)
37#define EXYNOS4_MCT_G_COMP0_L EXYNOS4_MCTREG(0x200)
38#define EXYNOS4_MCT_G_COMP0_U EXYNOS4_MCTREG(0x204)
39#define EXYNOS4_MCT_G_COMP0_ADD_INCR EXYNOS4_MCTREG(0x208)
40#define EXYNOS4_MCT_G_TCON EXYNOS4_MCTREG(0x240)
41#define EXYNOS4_MCT_G_INT_CSTAT EXYNOS4_MCTREG(0x244)
42#define EXYNOS4_MCT_G_INT_ENB EXYNOS4_MCTREG(0x248)
43#define EXYNOS4_MCT_G_WSTAT EXYNOS4_MCTREG(0x24C)
44#define _EXYNOS4_MCT_L_BASE EXYNOS4_MCTREG(0x300)
45#define EXYNOS4_MCT_L_BASE(x) (_EXYNOS4_MCT_L_BASE + (0x100 * x))
46#define EXYNOS4_MCT_L_MASK (0xffffff00)
47
48#define MCT_L_TCNTB_OFFSET (0x00)
49#define MCT_L_ICNTB_OFFSET (0x08)
50#define MCT_L_TCON_OFFSET (0x20)
51#define MCT_L_INT_CSTAT_OFFSET (0x30)
52#define MCT_L_INT_ENB_OFFSET (0x34)
53#define MCT_L_WSTAT_OFFSET (0x40)
54#define MCT_G_TCON_START (1 << 8)
55#define MCT_G_TCON_COMP0_AUTO_INC (1 << 1)
56#define MCT_G_TCON_COMP0_ENABLE (1 << 0)
57#define MCT_L_TCON_INTERVAL_MODE (1 << 2)
58#define MCT_L_TCON_INT_START (1 << 1)
59#define MCT_L_TCON_TIMER_START (1 << 0)
60
Changhwan Youn4d2e4d72012-03-09 15:09:21 -080061#define TICK_BASE_CNT 1
62
Changhwan Youn3a062282011-10-04 17:02:58 +090063enum {
64 MCT_INT_SPI,
65 MCT_INT_PPI
66};
67
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090068static void __iomem *reg_base;
Changhwan Youn30d8bea2011-03-11 10:39:57 +090069static unsigned long clk_rate;
Changhwan Youn3a062282011-10-04 17:02:58 +090070static unsigned int mct_int_type;
Changhwan Youn30d8bea2011-03-11 10:39:57 +090071
72struct mct_clock_event_device {
73 struct clock_event_device *evt;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090074 unsigned long base;
Changhwan Younc8987472011-10-04 17:09:26 +090075 char name[10];
Changhwan Youn30d8bea2011-03-11 10:39:57 +090076};
77
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090078static void exynos4_mct_write(unsigned int value, unsigned long offset)
Changhwan Youn30d8bea2011-03-11 10:39:57 +090079{
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090080 unsigned long stat_addr;
Changhwan Youn30d8bea2011-03-11 10:39:57 +090081 u32 mask;
82 u32 i;
83
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090084 __raw_writel(value, reg_base + offset);
Changhwan Youn30d8bea2011-03-11 10:39:57 +090085
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090086 if (likely(offset >= EXYNOS4_MCT_L_BASE(0))) {
87 stat_addr = (offset & ~EXYNOS4_MCT_L_MASK) + MCT_L_WSTAT_OFFSET;
88 switch (offset & EXYNOS4_MCT_L_MASK) {
89 case MCT_L_TCON_OFFSET:
Changhwan Younc8987472011-10-04 17:09:26 +090090 mask = 1 << 3; /* L_TCON write status */
91 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090092 case MCT_L_ICNTB_OFFSET:
Changhwan Younc8987472011-10-04 17:09:26 +090093 mask = 1 << 1; /* L_ICNTB write status */
94 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +090095 case MCT_L_TCNTB_OFFSET:
Changhwan Younc8987472011-10-04 17:09:26 +090096 mask = 1 << 0; /* L_TCNTB write status */
97 break;
98 default:
99 return;
100 }
101 } else {
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900102 switch (offset) {
103 case EXYNOS4_MCT_G_TCON:
Changhwan Younc8987472011-10-04 17:09:26 +0900104 stat_addr = EXYNOS4_MCT_G_WSTAT;
105 mask = 1 << 16; /* G_TCON write status */
106 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900107 case EXYNOS4_MCT_G_COMP0_L:
Changhwan Younc8987472011-10-04 17:09:26 +0900108 stat_addr = EXYNOS4_MCT_G_WSTAT;
109 mask = 1 << 0; /* G_COMP0_L write status */
110 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900111 case EXYNOS4_MCT_G_COMP0_U:
Changhwan Younc8987472011-10-04 17:09:26 +0900112 stat_addr = EXYNOS4_MCT_G_WSTAT;
113 mask = 1 << 1; /* G_COMP0_U write status */
114 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900115 case EXYNOS4_MCT_G_COMP0_ADD_INCR:
Changhwan Younc8987472011-10-04 17:09:26 +0900116 stat_addr = EXYNOS4_MCT_G_WSTAT;
117 mask = 1 << 2; /* G_COMP0_ADD_INCR w status */
118 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900119 case EXYNOS4_MCT_G_CNT_L:
Changhwan Younc8987472011-10-04 17:09:26 +0900120 stat_addr = EXYNOS4_MCT_G_CNT_WSTAT;
121 mask = 1 << 0; /* G_CNT_L write status */
122 break;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900123 case EXYNOS4_MCT_G_CNT_U:
Changhwan Younc8987472011-10-04 17:09:26 +0900124 stat_addr = EXYNOS4_MCT_G_CNT_WSTAT;
125 mask = 1 << 1; /* G_CNT_U write status */
126 break;
127 default:
128 return;
129 }
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900130 }
131
132 /* Wait maximum 1 ms until written values are applied */
133 for (i = 0; i < loops_per_jiffy / 1000 * HZ; i++)
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900134 if (__raw_readl(reg_base + stat_addr) & mask) {
135 __raw_writel(mask, reg_base + stat_addr);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900136 return;
137 }
138
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900139 panic("MCT hangs after writing %d (offset:0x%lx)\n", value, offset);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900140}
141
142/* Clocksource handling */
143static void exynos4_mct_frc_start(u32 hi, u32 lo)
144{
145 u32 reg;
146
147 exynos4_mct_write(lo, EXYNOS4_MCT_G_CNT_L);
148 exynos4_mct_write(hi, EXYNOS4_MCT_G_CNT_U);
149
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900150 reg = __raw_readl(reg_base + EXYNOS4_MCT_G_TCON);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900151 reg |= MCT_G_TCON_START;
152 exynos4_mct_write(reg, EXYNOS4_MCT_G_TCON);
153}
154
155static cycle_t exynos4_frc_read(struct clocksource *cs)
156{
157 unsigned int lo, hi;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900158 u32 hi2 = __raw_readl(reg_base + EXYNOS4_MCT_G_CNT_U);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900159
160 do {
161 hi = hi2;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900162 lo = __raw_readl(reg_base + EXYNOS4_MCT_G_CNT_L);
163 hi2 = __raw_readl(reg_base + EXYNOS4_MCT_G_CNT_U);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900164 } while (hi != hi2);
165
166 return ((cycle_t)hi << 32) | lo;
167}
168
Changhwan Younaa421c12011-09-02 14:10:52 +0900169static void exynos4_frc_resume(struct clocksource *cs)
170{
171 exynos4_mct_frc_start(0, 0);
172}
173
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900174struct clocksource mct_frc = {
175 .name = "mct-frc",
176 .rating = 400,
177 .read = exynos4_frc_read,
178 .mask = CLOCKSOURCE_MASK(64),
179 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
Changhwan Younaa421c12011-09-02 14:10:52 +0900180 .resume = exynos4_frc_resume,
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900181};
182
183static void __init exynos4_clocksource_init(void)
184{
185 exynos4_mct_frc_start(0, 0);
186
187 if (clocksource_register_hz(&mct_frc, clk_rate))
188 panic("%s: can't register clocksource\n", mct_frc.name);
189}
190
191static void exynos4_mct_comp0_stop(void)
192{
193 unsigned int tcon;
194
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900195 tcon = __raw_readl(reg_base + EXYNOS4_MCT_G_TCON);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900196 tcon &= ~(MCT_G_TCON_COMP0_ENABLE | MCT_G_TCON_COMP0_AUTO_INC);
197
198 exynos4_mct_write(tcon, EXYNOS4_MCT_G_TCON);
199 exynos4_mct_write(0, EXYNOS4_MCT_G_INT_ENB);
200}
201
202static void exynos4_mct_comp0_start(enum clock_event_mode mode,
203 unsigned long cycles)
204{
205 unsigned int tcon;
206 cycle_t comp_cycle;
207
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900208 tcon = __raw_readl(reg_base + EXYNOS4_MCT_G_TCON);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900209
210 if (mode == CLOCK_EVT_MODE_PERIODIC) {
211 tcon |= MCT_G_TCON_COMP0_AUTO_INC;
212 exynos4_mct_write(cycles, EXYNOS4_MCT_G_COMP0_ADD_INCR);
213 }
214
215 comp_cycle = exynos4_frc_read(&mct_frc) + cycles;
216 exynos4_mct_write((u32)comp_cycle, EXYNOS4_MCT_G_COMP0_L);
217 exynos4_mct_write((u32)(comp_cycle >> 32), EXYNOS4_MCT_G_COMP0_U);
218
219 exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_ENB);
220
221 tcon |= MCT_G_TCON_COMP0_ENABLE;
222 exynos4_mct_write(tcon , EXYNOS4_MCT_G_TCON);
223}
224
225static int exynos4_comp_set_next_event(unsigned long cycles,
226 struct clock_event_device *evt)
227{
228 exynos4_mct_comp0_start(evt->mode, cycles);
229
230 return 0;
231}
232
233static void exynos4_comp_set_mode(enum clock_event_mode mode,
234 struct clock_event_device *evt)
235{
Changhwan Youn4d2e4d72012-03-09 15:09:21 -0800236 unsigned long cycles_per_jiffy;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900237 exynos4_mct_comp0_stop();
238
239 switch (mode) {
240 case CLOCK_EVT_MODE_PERIODIC:
Changhwan Youn4d2e4d72012-03-09 15:09:21 -0800241 cycles_per_jiffy =
242 (((unsigned long long) NSEC_PER_SEC / HZ * evt->mult) >> evt->shift);
243 exynos4_mct_comp0_start(mode, cycles_per_jiffy);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900244 break;
245
246 case CLOCK_EVT_MODE_ONESHOT:
247 case CLOCK_EVT_MODE_UNUSED:
248 case CLOCK_EVT_MODE_SHUTDOWN:
249 case CLOCK_EVT_MODE_RESUME:
250 break;
251 }
252}
253
254static struct clock_event_device mct_comp_device = {
255 .name = "mct-comp",
256 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
257 .rating = 250,
258 .set_next_event = exynos4_comp_set_next_event,
259 .set_mode = exynos4_comp_set_mode,
260};
261
262static irqreturn_t exynos4_mct_comp_isr(int irq, void *dev_id)
263{
264 struct clock_event_device *evt = dev_id;
265
266 exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_CSTAT);
267
268 evt->event_handler(evt);
269
270 return IRQ_HANDLED;
271}
272
273static struct irqaction mct_comp_event_irq = {
274 .name = "mct_comp_irq",
275 .flags = IRQF_TIMER | IRQF_IRQPOLL,
276 .handler = exynos4_mct_comp_isr,
277 .dev_id = &mct_comp_device,
278};
279
280static void exynos4_clockevent_init(void)
281{
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900282 mct_comp_device.cpumask = cpumask_of(0);
Shawn Guo838a2ae2013-01-12 11:50:05 +0000283 clockevents_config_and_register(&mct_comp_device, clk_rate,
284 0xf, 0xffffffff);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900285
Kukjin Kimbb19a752012-01-25 13:48:11 +0900286 if (soc_is_exynos5250())
287 setup_irq(EXYNOS5_IRQ_MCT_G0, &mct_comp_event_irq);
288 else
289 setup_irq(EXYNOS4_IRQ_MCT_G0, &mct_comp_event_irq);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900290}
291
292#ifdef CONFIG_LOCAL_TIMERS
Kukjin Kim991a6c72011-12-08 10:04:49 +0900293
294static DEFINE_PER_CPU(struct mct_clock_event_device, percpu_mct_tick);
295
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900296/* Clock event handling */
297static void exynos4_mct_tick_stop(struct mct_clock_event_device *mevt)
298{
299 unsigned long tmp;
300 unsigned long mask = MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900301 unsigned long offset = mevt->base + MCT_L_TCON_OFFSET;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900302
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900303 tmp = __raw_readl(reg_base + offset);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900304 if (tmp & mask) {
305 tmp &= ~mask;
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900306 exynos4_mct_write(tmp, offset);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900307 }
308}
309
310static void exynos4_mct_tick_start(unsigned long cycles,
311 struct mct_clock_event_device *mevt)
312{
313 unsigned long tmp;
314
315 exynos4_mct_tick_stop(mevt);
316
317 tmp = (1 << 31) | cycles; /* MCT_L_UPDATE_ICNTB */
318
319 /* update interrupt count buffer */
320 exynos4_mct_write(tmp, mevt->base + MCT_L_ICNTB_OFFSET);
321
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300322 /* enable MCT tick interrupt */
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900323 exynos4_mct_write(0x1, mevt->base + MCT_L_INT_ENB_OFFSET);
324
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900325 tmp = __raw_readl(reg_base + mevt->base + MCT_L_TCON_OFFSET);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900326 tmp |= MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START |
327 MCT_L_TCON_INTERVAL_MODE;
328 exynos4_mct_write(tmp, mevt->base + MCT_L_TCON_OFFSET);
329}
330
331static int exynos4_tick_set_next_event(unsigned long cycles,
332 struct clock_event_device *evt)
333{
Marc Zyngiere700e412011-11-03 11:13:12 +0900334 struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900335
336 exynos4_mct_tick_start(cycles, mevt);
337
338 return 0;
339}
340
341static inline void exynos4_tick_set_mode(enum clock_event_mode mode,
342 struct clock_event_device *evt)
343{
Marc Zyngiere700e412011-11-03 11:13:12 +0900344 struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick);
Changhwan Youn4d2e4d72012-03-09 15:09:21 -0800345 unsigned long cycles_per_jiffy;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900346
347 exynos4_mct_tick_stop(mevt);
348
349 switch (mode) {
350 case CLOCK_EVT_MODE_PERIODIC:
Changhwan Youn4d2e4d72012-03-09 15:09:21 -0800351 cycles_per_jiffy =
352 (((unsigned long long) NSEC_PER_SEC / HZ * evt->mult) >> evt->shift);
353 exynos4_mct_tick_start(cycles_per_jiffy, mevt);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900354 break;
355
356 case CLOCK_EVT_MODE_ONESHOT:
357 case CLOCK_EVT_MODE_UNUSED:
358 case CLOCK_EVT_MODE_SHUTDOWN:
359 case CLOCK_EVT_MODE_RESUME:
360 break;
361 }
362}
363
Changhwan Younc8987472011-10-04 17:09:26 +0900364static int exynos4_mct_tick_clear(struct mct_clock_event_device *mevt)
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900365{
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900366 struct clock_event_device *evt = mevt->evt;
367
368 /*
369 * This is for supporting oneshot mode.
370 * Mct would generate interrupt periodically
371 * without explicit stopping.
372 */
373 if (evt->mode != CLOCK_EVT_MODE_PERIODIC)
374 exynos4_mct_tick_stop(mevt);
375
376 /* Clear the MCT tick interrupt */
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900377 if (__raw_readl(reg_base + mevt->base + MCT_L_INT_CSTAT_OFFSET) & 1) {
Changhwan Youn3a062282011-10-04 17:02:58 +0900378 exynos4_mct_write(0x1, mevt->base + MCT_L_INT_CSTAT_OFFSET);
379 return 1;
380 } else {
381 return 0;
382 }
383}
384
385static irqreturn_t exynos4_mct_tick_isr(int irq, void *dev_id)
386{
387 struct mct_clock_event_device *mevt = dev_id;
388 struct clock_event_device *evt = mevt->evt;
389
390 exynos4_mct_tick_clear(mevt);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900391
392 evt->event_handler(evt);
393
394 return IRQ_HANDLED;
395}
396
397static struct irqaction mct_tick0_event_irq = {
398 .name = "mct_tick0_irq",
399 .flags = IRQF_TIMER | IRQF_NOBALANCING,
400 .handler = exynos4_mct_tick_isr,
401};
402
403static struct irqaction mct_tick1_event_irq = {
404 .name = "mct_tick1_irq",
405 .flags = IRQF_TIMER | IRQF_NOBALANCING,
406 .handler = exynos4_mct_tick_isr,
407};
408
Marc Zyngiera8cb6042012-01-10 19:44:19 +0000409static int __cpuinit exynos4_local_timer_setup(struct clock_event_device *evt)
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900410{
Marc Zyngiere700e412011-11-03 11:13:12 +0900411 struct mct_clock_event_device *mevt;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900412 unsigned int cpu = smp_processor_id();
Changhwan Youneeed66e2012-04-24 14:33:14 -0700413 int mct_lx_irq;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900414
Marc Zyngiere700e412011-11-03 11:13:12 +0900415 mevt = this_cpu_ptr(&percpu_mct_tick);
416 mevt->evt = evt;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900417
Marc Zyngiere700e412011-11-03 11:13:12 +0900418 mevt->base = EXYNOS4_MCT_L_BASE(cpu);
419 sprintf(mevt->name, "mct_tick%d", cpu);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900420
Marc Zyngiere700e412011-11-03 11:13:12 +0900421 evt->name = mevt->name;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900422 evt->cpumask = cpumask_of(cpu);
423 evt->set_next_event = exynos4_tick_set_next_event;
424 evt->set_mode = exynos4_tick_set_mode;
425 evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
426 evt->rating = 450;
Shawn Guo838a2ae2013-01-12 11:50:05 +0000427 clockevents_config_and_register(evt, clk_rate / (TICK_BASE_CNT + 1),
428 0xf, 0x7fffffff);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900429
Changhwan Youn4d2e4d72012-03-09 15:09:21 -0800430 exynos4_mct_write(TICK_BASE_CNT, mevt->base + MCT_L_TCNTB_OFFSET);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900431
Changhwan Youn3a062282011-10-04 17:02:58 +0900432 if (mct_int_type == MCT_INT_SPI) {
433 if (cpu == 0) {
Changhwan Youneeed66e2012-04-24 14:33:14 -0700434 mct_lx_irq = soc_is_exynos4210() ? EXYNOS4_IRQ_MCT_L0 :
435 EXYNOS5_IRQ_MCT_L0;
Marc Zyngiere700e412011-11-03 11:13:12 +0900436 mct_tick0_event_irq.dev_id = mevt;
Changhwan Youneeed66e2012-04-24 14:33:14 -0700437 evt->irq = mct_lx_irq;
438 setup_irq(mct_lx_irq, &mct_tick0_event_irq);
Changhwan Youn3a062282011-10-04 17:02:58 +0900439 } else {
Changhwan Youneeed66e2012-04-24 14:33:14 -0700440 mct_lx_irq = soc_is_exynos4210() ? EXYNOS4_IRQ_MCT_L1 :
441 EXYNOS5_IRQ_MCT_L1;
Marc Zyngiere700e412011-11-03 11:13:12 +0900442 mct_tick1_event_irq.dev_id = mevt;
Changhwan Youneeed66e2012-04-24 14:33:14 -0700443 evt->irq = mct_lx_irq;
444 setup_irq(mct_lx_irq, &mct_tick1_event_irq);
445 irq_set_affinity(mct_lx_irq, cpumask_of(1));
Changhwan Youn3a062282011-10-04 17:02:58 +0900446 }
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900447 } else {
Kukjin Kimbb19a752012-01-25 13:48:11 +0900448 enable_percpu_irq(EXYNOS_IRQ_MCT_LOCALTIMER, 0);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900449 }
Kukjin Kim4d487d72011-08-24 16:07:39 +0900450
451 return 0;
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900452}
453
Marc Zyngiera8cb6042012-01-10 19:44:19 +0000454static void exynos4_local_timer_stop(struct clock_event_device *evt)
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900455{
Amit Daniel Kachhape248cd52011-12-08 10:07:08 +0900456 unsigned int cpu = smp_processor_id();
Marc Zyngier28af6902011-07-22 12:52:37 +0100457 evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt);
Marc Zyngiere700e412011-11-03 11:13:12 +0900458 if (mct_int_type == MCT_INT_SPI)
Amit Daniel Kachhape248cd52011-12-08 10:07:08 +0900459 if (cpu == 0)
460 remove_irq(evt->irq, &mct_tick0_event_irq);
461 else
462 remove_irq(evt->irq, &mct_tick1_event_irq);
Marc Zyngiere700e412011-11-03 11:13:12 +0900463 else
Kukjin Kimbb19a752012-01-25 13:48:11 +0900464 disable_percpu_irq(EXYNOS_IRQ_MCT_LOCALTIMER);
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900465}
Marc Zyngiera8cb6042012-01-10 19:44:19 +0000466
467static struct local_timer_ops exynos4_mct_tick_ops __cpuinitdata = {
468 .setup = exynos4_local_timer_setup,
469 .stop = exynos4_local_timer_stop,
470};
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900471#endif /* CONFIG_LOCAL_TIMERS */
472
473static void __init exynos4_timer_resources(void)
474{
475 struct clk *mct_clk;
476 mct_clk = clk_get(NULL, "xtal");
477
478 clk_rate = clk_get_rate(mct_clk);
Marc Zyngiere700e412011-11-03 11:13:12 +0900479
Thomas Abrahama1ba7a72013-03-09 16:01:47 +0900480 reg_base = S5P_VA_SYSTIMER;
481
Kukjin Kim991a6c72011-12-08 10:04:49 +0900482#ifdef CONFIG_LOCAL_TIMERS
Marc Zyngiere700e412011-11-03 11:13:12 +0900483 if (mct_int_type == MCT_INT_PPI) {
484 int err;
485
Kukjin Kimbb19a752012-01-25 13:48:11 +0900486 err = request_percpu_irq(EXYNOS_IRQ_MCT_LOCALTIMER,
Marc Zyngiere700e412011-11-03 11:13:12 +0900487 exynos4_mct_tick_isr, "MCT",
488 &percpu_mct_tick);
489 WARN(err, "MCT: can't request IRQ %d (%d)\n",
Kukjin Kimbb19a752012-01-25 13:48:11 +0900490 EXYNOS_IRQ_MCT_LOCALTIMER, err);
Marc Zyngiere700e412011-11-03 11:13:12 +0900491 }
Marc Zyngiera8cb6042012-01-10 19:44:19 +0000492
493 local_timer_register(&exynos4_mct_tick_ops);
Kukjin Kim991a6c72011-12-08 10:04:49 +0900494#endif /* CONFIG_LOCAL_TIMERS */
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900495}
496
Stephen Warren6bb27d72012-11-08 12:40:59 -0700497void __init exynos4_timer_init(void)
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900498{
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900499 if (soc_is_exynos5440()) {
500 arch_timer_of_register();
501 return;
502 }
503
Changhwan Youneeed66e2012-04-24 14:33:14 -0700504 if ((soc_is_exynos4210()) || (soc_is_exynos5250()))
Changhwan Youn3a062282011-10-04 17:02:58 +0900505 mct_int_type = MCT_INT_SPI;
506 else
507 mct_int_type = MCT_INT_PPI;
508
Changhwan Youn30d8bea2011-03-11 10:39:57 +0900509 exynos4_timer_resources();
510 exynos4_clocksource_init();
511 exynos4_clockevent_init();
512}