Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 1 | /* |
| 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 Hauer | 1a815ae | 2006-12-12 09:23:45 +0100 | [diff] [blame] | 22 | #include <linux/irq.h> |
| 23 | #include <linux/clocksource.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame^] | 24 | #include <linux/io.h> |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 25 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 27 | #include <asm/mach/time.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/netx-regs.h> |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 29 | |
| 30 | /* |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 31 | * IRQ handler for the timer |
| 32 | */ |
| 33 | static irqreturn_t |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 34 | netx_timer_interrupt(int irq, void *dev_id) |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 35 | { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 36 | timer_tick(); |
Sascha Hauer | 1a815ae | 2006-12-12 09:23:45 +0100 | [diff] [blame] | 37 | |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 38 | /* acknowledge interrupt */ |
| 39 | writel(COUNTER_BIT(0), NETX_GPIO_IRQ); |
| 40 | |
| 41 | return IRQ_HANDLED; |
| 42 | } |
| 43 | |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 44 | static struct irqaction netx_timer_irq = { |
| 45 | .name = "NetX Timer Tick", |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 46 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 47 | .handler = netx_timer_interrupt, |
| 48 | }; |
| 49 | |
Sascha Hauer | 1a815ae | 2006-12-12 09:23:45 +0100 | [diff] [blame] | 50 | cycle_t netx_get_cycles(void) |
| 51 | { |
| 52 | return readl(NETX_GPIO_COUNTER_CURRENT(1)); |
| 53 | } |
| 54 | |
| 55 | static struct clocksource clocksource_netx = { |
| 56 | .name = "netx_timer", |
| 57 | .rating = 200, |
| 58 | .read = netx_get_cycles, |
| 59 | .mask = CLOCKSOURCE_MASK(32), |
| 60 | .shift = 20, |
Thomas Gleixner | c66699a | 2007-02-16 01:27:37 -0800 | [diff] [blame] | 61 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
Sascha Hauer | 1a815ae | 2006-12-12 09:23:45 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 64 | /* |
| 65 | * Set up timer interrupt |
| 66 | */ |
| 67 | static void __init netx_timer_init(void) |
| 68 | { |
| 69 | /* disable timer initially */ |
| 70 | writel(0, NETX_GPIO_COUNTER_CTRL(0)); |
| 71 | |
| 72 | /* Reset the timer value to zero */ |
| 73 | writel(0, NETX_GPIO_COUNTER_CURRENT(0)); |
| 74 | |
| 75 | writel(LATCH, NETX_GPIO_COUNTER_MAX(0)); |
| 76 | |
| 77 | /* acknowledge interrupt */ |
| 78 | writel(COUNTER_BIT(0), NETX_GPIO_IRQ); |
| 79 | |
| 80 | /* Enable the interrupt in the specific timer register and start timer */ |
| 81 | writel(COUNTER_BIT(0), NETX_GPIO_IRQ_ENABLE); |
| 82 | writel(NETX_GPIO_COUNTER_CTRL_IRQ_EN | NETX_GPIO_COUNTER_CTRL_RUN, |
| 83 | NETX_GPIO_COUNTER_CTRL(0)); |
| 84 | |
| 85 | setup_irq(NETX_IRQ_TIMER0, &netx_timer_irq); |
Sascha Hauer | 1a815ae | 2006-12-12 09:23:45 +0100 | [diff] [blame] | 86 | |
| 87 | /* Setup timer one for clocksource */ |
| 88 | writel(0, NETX_GPIO_COUNTER_CTRL(1)); |
| 89 | writel(0, NETX_GPIO_COUNTER_CURRENT(1)); |
| 90 | writel(0xFFFFFFFF, NETX_GPIO_COUNTER_MAX(1)); |
| 91 | |
| 92 | writel(NETX_GPIO_COUNTER_CTRL_RUN, |
| 93 | NETX_GPIO_COUNTER_CTRL(1)); |
| 94 | |
| 95 | clocksource_netx.mult = |
| 96 | clocksource_hz2mult(CLOCK_TICK_RATE, clocksource_netx.shift); |
| 97 | clocksource_register(&clocksource_netx); |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | struct sys_timer netx_timer = { |
Sascha Hauer | 1a815ae | 2006-12-12 09:23:45 +0100 | [diff] [blame] | 101 | .init = netx_timer_init, |
Sascha Hauer | bb6d8c8 | 2006-06-19 15:27:53 +0100 | [diff] [blame] | 102 | }; |