blob: 5773b55ef4a69f203dc83831d6452128094924b8 [file] [log] [blame]
Sascha Hauerbb6d8c82006-06-19 15:27:53 +01001/*
2 * arch/arm/mach-netx/time.c
3 *
4 * Copyright (c) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/interrupt.h>
Sascha Hauer1a815ae2006-12-12 09:23:45 +010022#include <linux/irq.h>
23#include <linux/clocksource.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010024
25#include <asm/hardware.h>
26#include <asm/io.h>
27#include <asm/mach/time.h>
28#include <asm/arch/netx-regs.h>
29
30/*
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010031 * IRQ handler for the timer
32 */
33static irqreturn_t
Linus Torvalds0cd61b62006-10-06 10:53:39 -070034netx_timer_interrupt(int irq, void *dev_id)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010035{
36 write_seqlock(&xtime_lock);
37
Linus Torvalds0cd61b62006-10-06 10:53:39 -070038 timer_tick();
Sascha Hauer1a815ae2006-12-12 09:23:45 +010039
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010040 write_sequnlock(&xtime_lock);
41
42 /* acknowledge interrupt */
43 writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
44
45 return IRQ_HANDLED;
46}
47
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010048static struct irqaction netx_timer_irq = {
49 .name = "NetX Timer Tick",
Thomas Gleixner52e405e2006-07-03 02:20:05 +020050 .flags = IRQF_DISABLED | IRQF_TIMER,
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010051 .handler = netx_timer_interrupt,
52};
53
Sascha Hauer1a815ae2006-12-12 09:23:45 +010054cycle_t netx_get_cycles(void)
55{
56 return readl(NETX_GPIO_COUNTER_CURRENT(1));
57}
58
59static struct clocksource clocksource_netx = {
60 .name = "netx_timer",
61 .rating = 200,
62 .read = netx_get_cycles,
63 .mask = CLOCKSOURCE_MASK(32),
64 .shift = 20,
65 .is_continuous = 1,
66};
67
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010068/*
69 * Set up timer interrupt
70 */
71static void __init netx_timer_init(void)
72{
73 /* disable timer initially */
74 writel(0, NETX_GPIO_COUNTER_CTRL(0));
75
76 /* Reset the timer value to zero */
77 writel(0, NETX_GPIO_COUNTER_CURRENT(0));
78
79 writel(LATCH, NETX_GPIO_COUNTER_MAX(0));
80
81 /* acknowledge interrupt */
82 writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
83
84 /* Enable the interrupt in the specific timer register and start timer */
85 writel(COUNTER_BIT(0), NETX_GPIO_IRQ_ENABLE);
86 writel(NETX_GPIO_COUNTER_CTRL_IRQ_EN | NETX_GPIO_COUNTER_CTRL_RUN,
87 NETX_GPIO_COUNTER_CTRL(0));
88
89 setup_irq(NETX_IRQ_TIMER0, &netx_timer_irq);
Sascha Hauer1a815ae2006-12-12 09:23:45 +010090
91 /* Setup timer one for clocksource */
92 writel(0, NETX_GPIO_COUNTER_CTRL(1));
93 writel(0, NETX_GPIO_COUNTER_CURRENT(1));
94 writel(0xFFFFFFFF, NETX_GPIO_COUNTER_MAX(1));
95
96 writel(NETX_GPIO_COUNTER_CTRL_RUN,
97 NETX_GPIO_COUNTER_CTRL(1));
98
99 clocksource_netx.mult =
100 clocksource_hz2mult(CLOCK_TICK_RATE, clocksource_netx.shift);
101 clocksource_register(&clocksource_netx);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100102}
103
104struct sys_timer netx_timer = {
Sascha Hauer1a815ae2006-12-12 09:23:45 +0100105 .init = netx_timer_init,
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100106};