Linux 2.6.19-rc1
[linux-2.6/next.git] / arch / arm / mach-netx / time.c
blob6d72c81b7d9f3c67ea9a696559fa683b0a5e78f9
1 /*
2 * arch/arm/mach-netx/time.c
4 * Copyright (c) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
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.
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.
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
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
23 #include <asm/hardware.h>
24 #include <asm/io.h>
25 #include <asm/mach/time.h>
26 #include <asm/arch/netx-regs.h>
29 * Returns number of us since last clock interrupt. Note that interrupts
30 * will have been disabled by do_gettimeoffset()
32 static unsigned long netx_gettimeoffset(void)
34 return readl(NETX_GPIO_COUNTER_CURRENT(0)) / 100;
38 * IRQ handler for the timer
40 static irqreturn_t
41 netx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
43 write_seqlock(&xtime_lock);
45 timer_tick(regs);
46 write_sequnlock(&xtime_lock);
48 /* acknowledge interrupt */
49 writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
51 return IRQ_HANDLED;
55 static struct irqaction netx_timer_irq = {
56 .name = "NetX Timer Tick",
57 .flags = IRQF_DISABLED | IRQF_TIMER,
58 .handler = netx_timer_interrupt,
62 * Set up timer interrupt
64 static void __init netx_timer_init(void)
66 /* disable timer initially */
67 writel(0, NETX_GPIO_COUNTER_CTRL(0));
69 /* Reset the timer value to zero */
70 writel(0, NETX_GPIO_COUNTER_CURRENT(0));
72 writel(LATCH, NETX_GPIO_COUNTER_MAX(0));
74 /* acknowledge interrupt */
75 writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
77 /* Enable the interrupt in the specific timer register and start timer */
78 writel(COUNTER_BIT(0), NETX_GPIO_IRQ_ENABLE);
79 writel(NETX_GPIO_COUNTER_CTRL_IRQ_EN | NETX_GPIO_COUNTER_CTRL_RUN,
80 NETX_GPIO_COUNTER_CTRL(0));
82 setup_irq(NETX_IRQ_TIMER0, &netx_timer_irq);
85 struct sys_timer netx_timer = {
86 .init = netx_timer_init,
87 .offset = netx_gettimeoffset,