blob: 8d322c20ccaedd0e65f8537d376e2bceae3f42c4 [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>
Jan Engelhardt96de0e22007-10-19 23:21:04 +02008 * 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>
Dirk Behmee6687292006-12-06 17:14:00 -080027#include <linux/irq.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000028
Tony Lindgren1dbae812005-11-10 14:26:51 +000029#include <asm/mach/time.h>
Timo Teras77900a22006-06-26 16:16:12 -070030#include <asm/arch/dmtimer.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000031
Timo Teras77900a22006-06-26 16:16:12 -070032static struct omap_dm_timer *gptimer;
Tony Lindgren1dbae812005-11-10 14:26:51 +000033
Timo Teras77900a22006-06-26 16:16:12 -070034static inline void omap2_gp_timer_start(unsigned long load_val)
Tony Lindgren1dbae812005-11-10 14:26:51 +000035{
Timo Teras77900a22006-06-26 16:16:12 -070036 omap_dm_timer_set_load(gptimer, 1, 0xffffffff - load_val);
37 omap_dm_timer_set_int_enable(gptimer, OMAP_TIMER_INT_OVERFLOW);
38 omap_dm_timer_start(gptimer);
Tony Lindgren1dbae812005-11-10 14:26:51 +000039}
40
Linus Torvalds0cd61b62006-10-06 10:53:39 -070041static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id)
Tony Lindgren1dbae812005-11-10 14:26:51 +000042{
43 write_seqlock(&xtime_lock);
44
Timo Teras77900a22006-06-26 16:16:12 -070045 omap_dm_timer_write_status(gptimer, OMAP_TIMER_INT_OVERFLOW);
Linus Torvalds0cd61b62006-10-06 10:53:39 -070046 timer_tick();
Tony Lindgren1dbae812005-11-10 14:26:51 +000047
48 write_sequnlock(&xtime_lock);
49
50 return IRQ_HANDLED;
51}
52
53static struct irqaction omap2_gp_timer_irq = {
54 .name = "gp timer",
Bernhard Walleb30faba2007-05-08 00:35:39 -070055 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Tony Lindgren1dbae812005-11-10 14:26:51 +000056 .handler = omap2_gp_timer_interrupt,
57};
58
59static void __init omap2_gp_timer_init(void)
60{
Timo Teras77900a22006-06-26 16:16:12 -070061 u32 tick_period;
Tony Lindgren1dbae812005-11-10 14:26:51 +000062
Timo Teras77900a22006-06-26 16:16:12 -070063 omap_dm_timer_init();
Timo Terase32f7ec2006-06-26 16:16:13 -070064 gptimer = omap_dm_timer_request_specific(1);
Timo Teras77900a22006-06-26 16:16:12 -070065 BUG_ON(gptimer == NULL);
Tony Lindgren1dbae812005-11-10 14:26:51 +000066
Timo Teras77900a22006-06-26 16:16:12 -070067 omap_dm_timer_set_source(gptimer, OMAP_TIMER_SRC_SYS_CLK);
David Brownellb097f492006-12-06 17:14:04 -080068 tick_period = clk_get_rate(omap_dm_timer_get_fclk(gptimer)) / HZ;
Tony Lindgren1dbae812005-11-10 14:26:51 +000069 tick_period -= 1;
70
Timo Teras77900a22006-06-26 16:16:12 -070071 setup_irq(omap_dm_timer_get_irq(gptimer), &omap2_gp_timer_irq);
72 omap2_gp_timer_start(tick_period);
Tony Lindgren1dbae812005-11-10 14:26:51 +000073}
74
75struct sys_timer omap_timer = {
76 .init = omap2_gp_timer_init,
77};