blob: d293455017622aa6783a19ef0f3edd38d3cdb1f6 [file] [log] [blame]
Uwe Kleine-König9918cda2007-02-16 15:36:55 +01001/*
2 * arch/arm/mach-ns9xxx/time.c
3 *
4 * Copyright (C) 2006 by Digi International Inc.
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11#include <linux/jiffies.h>
12#include <linux/interrupt.h>
13#include <linux/irq.h>
Uwe Kleine-Königcef59752007-09-30 20:35:48 +010014#include <linux/stringify.h>
15#include <linux/clocksource.h>
16
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010017#include <asm/arch-ns9xxx/regs-sys.h>
18#include <asm/arch-ns9xxx/clock.h>
19#include <asm/arch-ns9xxx/irqs.h>
20#include <asm/arch/system.h>
21#include "generic.h"
22
23#define TIMERCLOCKSELECT 64
Uwe Kleine-Königcef59752007-09-30 20:35:48 +010024#define TIMER_CLOCKSOURCE 1
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010025
26static irqreturn_t
27ns9xxx_timer_interrupt(int irq, void *dev_id)
28{
Uwe Kleine-Königbf62e862007-08-07 21:08:21 +010029 int timerno = irq - IRQ_TIMER0;
30 u32 tc;
31
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010032 write_seqlock(&xtime_lock);
33 timer_tick();
34 write_sequnlock(&xtime_lock);
35
Uwe Kleine-Königbf62e862007-08-07 21:08:21 +010036 /* clear irq */
37 tc = SYS_TC(timerno);
38 if (REGGET(tc, SYS_TCx, REN) == SYS_TCx_REN_DIS) {
39 REGSET(tc, SYS_TCx, TEN, DIS);
40 SYS_TC(timerno) = tc;
41 }
42 REGSET(tc, SYS_TCx, INTC, SET);
43 SYS_TC(timerno) = tc;
44 REGSET(tc, SYS_TCx, INTC, UNSET);
45 SYS_TC(timerno) = tc;
46
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010047 return IRQ_HANDLED;
48}
49
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010050static struct irqaction ns9xxx_timer_irq = {
51 .name = "NS9xxx Timer Tick",
Bernhard Walleb30faba2007-05-08 00:35:39 -070052 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010053 .handler = ns9xxx_timer_interrupt,
54};
55
Uwe Kleine-Königcef59752007-09-30 20:35:48 +010056static cycle_t ns9xxx_clocksource_read(void)
57{
58 return SYS_TR(TIMER_CLOCKSOURCE);
59}
60
61static struct clocksource ns9xxx_clocksource = {
62 .name = "ns9xxx-timer" __stringify(TIMER_CLOCKSOURCE),
63 .rating = 300,
64 .read = ns9xxx_clocksource_read,
65 .mask = CLOCKSOURCE_MASK(32),
66 .shift = 20,
67 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
68};
69
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010070static void __init ns9xxx_timer_init(void)
71{
72 int tc;
73
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010074 /* disable timer */
75 if ((tc = SYS_TC(0)) & SYS_TCx_TEN)
76 SYS_TC(0) = tc & ~SYS_TCx_TEN;
77
78 SYS_TRC(0) = SH_DIV(ns9xxx_cpuclock(), (TIMERCLOCKSELECT * HZ), 0);
79
80 REGSET(tc, SYS_TCx, TEN, EN);
81 REGSET(tc, SYS_TCx, TLCS, DIV64); /* This must match TIMERCLOCKSELECT */
82 REGSET(tc, SYS_TCx, INTS, EN);
83 REGSET(tc, SYS_TCx, UDS, DOWN);
84 REGSET(tc, SYS_TCx, TDBG, STOP);
85 REGSET(tc, SYS_TCx, TSZ, 32);
86 REGSET(tc, SYS_TCx, REN, EN);
87 SYS_TC(0) = tc;
88
89 setup_irq(IRQ_TIMER0, &ns9xxx_timer_irq);
Uwe Kleine-Königcef59752007-09-30 20:35:48 +010090
91 tc = SYS_TC(TIMER_CLOCKSOURCE);
92 if (REGGET(tc, SYS_TCx, TEN)) {
93 REGSET(tc, SYS_TCx, TEN, DIS);
94 SYS_TC(TIMER_CLOCKSOURCE) = tc;
95 }
96
97 SYS_TRC(TIMER_CLOCKSOURCE) = 0;
98
99 REGSET(tc, SYS_TCx, TEN, EN);
100 REGSET(tc, SYS_TCx, TDBG, STOP);
101 REGSET(tc, SYS_TCx, TLCS, CPU);
102 REGSET(tc, SYS_TCx, TM, IEE);
103 REGSET(tc, SYS_TCx, INTS, DIS);
104 REGSET(tc, SYS_TCx, UDS, UP);
105 REGSET(tc, SYS_TCx, TSZ, 32);
106 REGSET(tc, SYS_TCx, REN, EN);
107
108 SYS_TC(TIMER_CLOCKSOURCE) = tc;
109
110 ns9xxx_clocksource.mult = clocksource_hz2mult(ns9xxx_cpuclock(),
111 ns9xxx_clocksource.shift);
112
113 clocksource_register(&ns9xxx_clocksource);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100114}
115
116struct sys_timer ns9xxx_timer = {
117 .init = ns9xxx_timer_init,
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100118};