timer-gp.c 1.9 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * linux/arch/arm/mach-omap2/timer-gp.c
 *
 * OMAP2 GP timer support.
 *
 * Copyright (C) 2005 Nokia Corporation
 * Author: Paul Mundt <paul.mundt@nokia.com>
 *         Juha Yrjl <juha.yrjola@nokia.com>
9
 * OMAP Dual-mode timer framework support by Timo Teras
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Some parts based off of TI's 24xx code:
 *
 *   Copyright (C) 2004 Texas Instruments, Inc.
 *
 * Roughly modelled after the OMAP1 MPU timer code.
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License. See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/init.h>
#include <linux/time.h>
#include <linux/interrupt.h>
#include <linux/err.h>
25
#include <linux/clk.h>
26
#include <linux/delay.h>
27
#include <linux/irq.h>
28

29
#include <asm/mach/time.h>
30
#include <asm/arch/dmtimer.h>
31

32
static struct omap_dm_timer *gptimer;
33

34
static inline void omap2_gp_timer_start(unsigned long load_val)
35
{
36 37 38
	omap_dm_timer_set_load(gptimer, 1, 0xffffffff - load_val);
	omap_dm_timer_set_int_enable(gptimer, OMAP_TIMER_INT_OVERFLOW);
	omap_dm_timer_start(gptimer);
39 40
}

41
static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id)
42 43 44
{
	write_seqlock(&xtime_lock);

45
	omap_dm_timer_write_status(gptimer, OMAP_TIMER_INT_OVERFLOW);
46
	timer_tick();
47 48 49 50 51 52 53 54

	write_sequnlock(&xtime_lock);

	return IRQ_HANDLED;
}

static struct irqaction omap2_gp_timer_irq = {
	.name		= "gp timer",
55
	.flags		= IRQF_DISABLED | IRQF_TIMER,
56 57 58 59 60
	.handler	= omap2_gp_timer_interrupt,
};

static void __init omap2_gp_timer_init(void)
{
61
	u32 tick_period;
62

63
	omap_dm_timer_init();
64
	gptimer = omap_dm_timer_request_specific(1);
65
	BUG_ON(gptimer == NULL);
66

67
	omap_dm_timer_set_source(gptimer, OMAP_TIMER_SRC_SYS_CLK);
68
	tick_period = clk_get_rate(omap_dm_timer_get_fclk(gptimer)) / HZ;
69 70
	tick_period -= 1;

71 72
	setup_irq(omap_dm_timer_get_irq(gptimer), &omap2_gp_timer_irq);
	omap2_gp_timer_start(tick_period);
73 74 75 76 77
}

struct sys_timer omap_timer = {
	.init	= omap2_gp_timer_init,
};