blob: 973189cd97665c7aee22f2a51439e5745eb4a630 [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
2 * linux/arch/arm/mach-omap2/timer-gp.c
3 *
4 * OMAP2 GP timer support.
5 *
6 * Copyright (C) 2005 Nokia Corporation
7 * Author: Paul Mundt <paul.mundt@nokia.com>
8 * Juha Yrjölä <juha.yrjola@nokia.com>
Timo Teras77900a22006-06-26 16:16:12 -07009 * OMAP Dual-mode timer framework support by Timo Teras
Tony Lindgren1dbae812005-11-10 14:26:51 +000010 *
11 * Some parts based off of TI's 24xx code:
12 *
13 * Copyright (C) 2004 Texas Instruments, Inc.
14 *
15 * Roughly modelled after the OMAP1 MPU timer code.
16 *
17 * This file is subject to the terms and conditions of the GNU General Public
18 * License. See the file "COPYING" in the main directory of this archive
19 * for more details.
20 */
21#include <linux/init.h>
22#include <linux/time.h>
23#include <linux/interrupt.h>
24#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000025#include <linux/clk.h>
Timo Teras77900a22006-06-26 16:16:12 -070026#include <linux/delay.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000027
Tony Lindgren1dbae812005-11-10 14:26:51 +000028#include <asm/mach/time.h>
Timo Teras77900a22006-06-26 16:16:12 -070029#include <asm/arch/dmtimer.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000030
Timo Teras77900a22006-06-26 16:16:12 -070031static struct omap_dm_timer *gptimer;
Tony Lindgren1dbae812005-11-10 14:26:51 +000032
Timo Teras77900a22006-06-26 16:16:12 -070033static inline void omap2_gp_timer_start(unsigned long load_val)
Tony Lindgren1dbae812005-11-10 14:26:51 +000034{
Timo Teras77900a22006-06-26 16:16:12 -070035 omap_dm_timer_set_load(gptimer, 1, 0xffffffff - load_val);
36 omap_dm_timer_set_int_enable(gptimer, OMAP_TIMER_INT_OVERFLOW);
37 omap_dm_timer_start(gptimer);
Tony Lindgren1dbae812005-11-10 14:26:51 +000038}
39
Linus Torvalds0cd61b62006-10-06 10:53:39 -070040static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id)
Tony Lindgren1dbae812005-11-10 14:26:51 +000041{
42 write_seqlock(&xtime_lock);
43
Timo Teras77900a22006-06-26 16:16:12 -070044 omap_dm_timer_write_status(gptimer, OMAP_TIMER_INT_OVERFLOW);
Linus Torvalds0cd61b62006-10-06 10:53:39 -070045 timer_tick();
Tony Lindgren1dbae812005-11-10 14:26:51 +000046
47 write_sequnlock(&xtime_lock);
48
49 return IRQ_HANDLED;
50}
51
52static struct irqaction omap2_gp_timer_irq = {
53 .name = "gp timer",
Thomas Gleixner52e405e2006-07-03 02:20:05 +020054 .flags = IRQF_DISABLED | IRQF_TIMER,
Tony Lindgren1dbae812005-11-10 14:26:51 +000055 .handler = omap2_gp_timer_interrupt,
56};
57
58static void __init omap2_gp_timer_init(void)
59{
Timo Teras77900a22006-06-26 16:16:12 -070060 u32 tick_period;
Tony Lindgren1dbae812005-11-10 14:26:51 +000061
Timo Teras77900a22006-06-26 16:16:12 -070062 omap_dm_timer_init();
Timo Terase32f7ec2006-06-26 16:16:13 -070063 gptimer = omap_dm_timer_request_specific(1);
Timo Teras77900a22006-06-26 16:16:12 -070064 BUG_ON(gptimer == NULL);
Tony Lindgren1dbae812005-11-10 14:26:51 +000065
Timo Teras77900a22006-06-26 16:16:12 -070066 omap_dm_timer_set_source(gptimer, OMAP_TIMER_SRC_SYS_CLK);
67 tick_period = clk_get_rate(omap_dm_timer_get_fclk(gptimer)) / 100;
Tony Lindgren1dbae812005-11-10 14:26:51 +000068 tick_period -= 1;
69
Timo Teras77900a22006-06-26 16:16:12 -070070 setup_irq(omap_dm_timer_get_irq(gptimer), &omap2_gp_timer_irq);
71 omap2_gp_timer_start(tick_period);
Tony Lindgren1dbae812005-11-10 14:26:51 +000072}
73
74struct sys_timer omap_timer = {
75 .init = omap2_gp_timer_init,
76};