aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-gemini
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-10-01 06:57:20 -0400
committerOlof Johansson <olof@lixom.net>2013-10-28 18:06:15 -0400
commitf3372c01816ec9e974e449cf7233408a31647dd3 (patch)
treee231213b1acbcace7aa9438b8e46b864bb52727c /arch/arm/mach-gemini
parent43d93947a54cf9323198a3a37eaf3ec14adb23e1 (diff)
ARM: gemini: convert to GENERIC_CLOCKEVENTS
This converts the gemini machine to use generic clockevents by rewriting the timer driver. Cc: arm@kernel.org Cc: Hans Ulli Kroll <ulli.kroll@googlemail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'arch/arm/mach-gemini')
-rw-r--r--arch/arm/mach-gemini/time.c97
1 files changed, 89 insertions, 8 deletions
diff --git a/arch/arm/mach-gemini/time.c b/arch/arm/mach-gemini/time.c
index 21dc5a89d1c4..0a63c4d25b64 100644
--- a/arch/arm/mach-gemini/time.c
+++ b/arch/arm/mach-gemini/time.c
@@ -13,6 +13,8 @@
13#include <mach/hardware.h> 13#include <mach/hardware.h>
14#include <mach/global_reg.h> 14#include <mach/global_reg.h>
15#include <asm/mach/time.h> 15#include <asm/mach/time.h>
16#include <linux/clockchips.h>
17#include <linux/clocksource.h>
16 18
17/* 19/*
18 * Register definitions for the timers 20 * Register definitions for the timers
@@ -33,19 +35,89 @@
33#define TIMER_3_CR_CLOCK (1 << 7) 35#define TIMER_3_CR_CLOCK (1 << 7)
34#define TIMER_3_CR_INT (1 << 8) 36#define TIMER_3_CR_INT (1 << 8)
35 37
38static unsigned int tick_rate;
39
40static int gemini_timer_set_next_event(unsigned long cycles,
41 struct clock_event_device *evt)
42{
43 u32 cr;
44
45 cr = readl(TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
46
47 /* This may be overdoing it, feel free to test without this */
48 cr &= ~TIMER_2_CR_ENABLE;
49 cr &= ~TIMER_2_CR_INT;
50 writel(cr, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
51
52 /* Set next event */
53 writel(cycles, TIMER_COUNT(IO_ADDRESS(GEMINI_TIMER2_BASE)));
54 writel(cycles, TIMER_LOAD(IO_ADDRESS(GEMINI_TIMER2_BASE)));
55 cr |= TIMER_2_CR_ENABLE;
56 cr |= TIMER_2_CR_INT;
57 writel(cr, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
58
59 return 0;
60}
61
62static void gemini_timer_set_mode(enum clock_event_mode mode,
63 struct clock_event_device *evt)
64{
65 u32 period = DIV_ROUND_CLOSEST(tick_rate, HZ);
66 u32 cr;
67
68 switch (mode) {
69 case CLOCK_EVT_MODE_PERIODIC:
70 /* Start the timer */
71 writel(period,
72 TIMER_COUNT(IO_ADDRESS(GEMINI_TIMER2_BASE)));
73 writel(period,
74 TIMER_LOAD(IO_ADDRESS(GEMINI_TIMER2_BASE)));
75 cr = readl(TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
76 cr |= TIMER_2_CR_ENABLE;
77 cr |= TIMER_2_CR_INT;
78 writel(cr, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
79 break;
80 case CLOCK_EVT_MODE_ONESHOT:
81 case CLOCK_EVT_MODE_UNUSED:
82 case CLOCK_EVT_MODE_SHUTDOWN:
83 case CLOCK_EVT_MODE_RESUME:
84 /*
85 * Disable also for oneshot: the set_next() call will
86 * arm the timer instead.
87 */
88 cr = readl(TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
89 cr &= ~TIMER_2_CR_ENABLE;
90 cr &= ~TIMER_2_CR_INT;
91 writel(cr, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
92 break;
93 default:
94 break;
95 }
96}
97
98/* Use TIMER2 as clock event */
99static struct clock_event_device gemini_clockevent = {
100 .name = "TIMER2",
101 .rating = 300, /* Reasonably fast and accurate clock event */
102 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
103 .set_next_event = gemini_timer_set_next_event,
104 .set_mode = gemini_timer_set_mode,
105};
106
36/* 107/*
37 * IRQ handler for the timer 108 * IRQ handler for the timer
38 */ 109 */
39static irqreturn_t gemini_timer_interrupt(int irq, void *dev_id) 110static irqreturn_t gemini_timer_interrupt(int irq, void *dev_id)
40{ 111{
41 timer_tick(); 112 struct clock_event_device *evt = &gemini_clockevent;
42 113
114 evt->event_handler(evt);
43 return IRQ_HANDLED; 115 return IRQ_HANDLED;
44} 116}
45 117
46static struct irqaction gemini_timer_irq = { 118static struct irqaction gemini_timer_irq = {
47 .name = "Gemini Timer Tick", 119 .name = "Gemini Timer Tick",
48 .flags = IRQF_DISABLED | IRQF_TIMER, 120 .flags = IRQF_TIMER,
49 .handler = gemini_timer_interrupt, 121 .handler = gemini_timer_interrupt,
50}; 122};
51 123
@@ -54,9 +126,9 @@ static struct irqaction gemini_timer_irq = {
54 */ 126 */
55void __init gemini_timer_init(void) 127void __init gemini_timer_init(void)
56{ 128{
57 unsigned int tick_rate, reg_v; 129 u32 reg_v;
58 130
59 reg_v = __raw_readl(IO_ADDRESS(GEMINI_GLOBAL_BASE + GLOBAL_STATUS)); 131 reg_v = readl(IO_ADDRESS(GEMINI_GLOBAL_BASE + GLOBAL_STATUS));
60 tick_rate = REG_TO_AHB_SPEED(reg_v) * 1000000; 132 tick_rate = REG_TO_AHB_SPEED(reg_v) * 1000000;
61 133
62 printk(KERN_INFO "Bus: %dMHz", tick_rate / 1000000); 134 printk(KERN_INFO "Bus: %dMHz", tick_rate / 1000000);
@@ -82,8 +154,17 @@ void __init gemini_timer_init(void)
82 * Make irqs happen for the system timer 154 * Make irqs happen for the system timer
83 */ 155 */
84 setup_irq(IRQ_TIMER2, &gemini_timer_irq); 156 setup_irq(IRQ_TIMER2, &gemini_timer_irq);
85 /* Start the timer */ 157
86 __raw_writel(tick_rate / HZ, TIMER_COUNT(IO_ADDRESS(GEMINI_TIMER2_BASE))); 158 /* Enable and use TIMER1 as clock source */
87 __raw_writel(tick_rate / HZ, TIMER_LOAD(IO_ADDRESS(GEMINI_TIMER2_BASE))); 159 writel(0xffffffff, TIMER_COUNT(IO_ADDRESS(GEMINI_TIMER1_BASE)));
88 __raw_writel(TIMER_2_CR_ENABLE | TIMER_2_CR_INT, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE))); 160 writel(0xffffffff, TIMER_LOAD(IO_ADDRESS(GEMINI_TIMER1_BASE)));
161 writel(TIMER_1_CR_ENABLE, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
162 if (clocksource_mmio_init(TIMER_COUNT(IO_ADDRESS(GEMINI_TIMER1_BASE)),
163 "TIMER1", tick_rate, 300, 32,
164 clocksource_mmio_readl_up))
165 pr_err("timer: failed to initialize gemini clock source\n");
166
167 /* Configure and register the clockevent */
168 clockevents_config_and_register(&gemini_clockevent, tick_rate,
169 1, 0xffffffff);
89} 170}