blob: 34a6a157f3559b69576fbfe9425aacbf20e83b0f [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>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010025
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010027#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/netx-regs.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010029
Uwe Kleine-König24e78572008-12-09 21:57:22 +010030#define TIMER_CLOCKSOURCE 1
31
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010032/*
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010033 * IRQ handler for the timer
34 */
35static irqreturn_t
Linus Torvalds0cd61b62006-10-06 10:53:39 -070036netx_timer_interrupt(int irq, void *dev_id)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010037{
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 /* acknowledge interrupt */
41 writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
42
43 return IRQ_HANDLED;
44}
45
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010046static struct irqaction netx_timer_irq = {
Uwe Kleine-König98538482008-12-09 21:57:21 +010047 .name = "NetX Timer Tick",
48 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
49 .handler = netx_timer_interrupt,
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010050};
51
Sascha Hauer1a815ae2006-12-12 09:23:45 +010052cycle_t netx_get_cycles(void)
53{
Uwe Kleine-König24e78572008-12-09 21:57:22 +010054 return readl(NETX_GPIO_COUNTER_CURRENT(TIMER_CLOCKSOURCE));
Sascha Hauer1a815ae2006-12-12 09:23:45 +010055}
56
57static struct clocksource clocksource_netx = {
Uwe Kleine-König98538482008-12-09 21:57:21 +010058 .name = "netx_timer",
Sascha Hauer1a815ae2006-12-12 09:23:45 +010059 .rating = 200,
60 .read = netx_get_cycles,
61 .mask = CLOCKSOURCE_MASK(32),
Uwe Kleine-König98538482008-12-09 21:57:21 +010062 .shift = 20,
Thomas Gleixnerc66699a2007-02-16 01:27:37 -080063 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
Sascha Hauer1a815ae2006-12-12 09:23:45 +010064};
65
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010066/*
67 * Set up timer interrupt
68 */
69static void __init netx_timer_init(void)
70{
71 /* disable timer initially */
72 writel(0, NETX_GPIO_COUNTER_CTRL(0));
73
74 /* Reset the timer value to zero */
75 writel(0, NETX_GPIO_COUNTER_CURRENT(0));
76
77 writel(LATCH, NETX_GPIO_COUNTER_MAX(0));
78
79 /* acknowledge interrupt */
80 writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
81
Uwe Kleine-König98538482008-12-09 21:57:21 +010082 /* Enable the interrupt in the specific timer
83 * register and start timer
84 */
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010085 writel(COUNTER_BIT(0), NETX_GPIO_IRQ_ENABLE);
86 writel(NETX_GPIO_COUNTER_CTRL_IRQ_EN | NETX_GPIO_COUNTER_CTRL_RUN,
Uwe Kleine-König98538482008-12-09 21:57:21 +010087 NETX_GPIO_COUNTER_CTRL(0));
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010088
89 setup_irq(NETX_IRQ_TIMER0, &netx_timer_irq);
Sascha Hauer1a815ae2006-12-12 09:23:45 +010090
91 /* Setup timer one for clocksource */
Uwe Kleine-König24e78572008-12-09 21:57:22 +010092 writel(0, NETX_GPIO_COUNTER_CTRL(TIMER_CLOCKSOURCE));
93 writel(0, NETX_GPIO_COUNTER_CURRENT(TIMER_CLOCKSOURCE));
94 writel(0xffffffff, NETX_GPIO_COUNTER_MAX(TIMER_CLOCKSOURCE));
Sascha Hauer1a815ae2006-12-12 09:23:45 +010095
Uwe Kleine-König98538482008-12-09 21:57:21 +010096 writel(NETX_GPIO_COUNTER_CTRL_RUN,
Uwe Kleine-König24e78572008-12-09 21:57:22 +010097 NETX_GPIO_COUNTER_CTRL(TIMER_CLOCKSOURCE));
Sascha Hauer1a815ae2006-12-12 09:23:45 +010098
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};