]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/timer-gp.c
ARM: OMAP: Cleanup omap2 path in comments.
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / timer-gp.c
1 /*
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>
9  *
10  * Some parts based off of TI's 24xx code:
11  *
12  *   Copyright (C) 2004 Texas Instruments, Inc.
13  *
14  * Roughly modelled after the OMAP1 MPU timer code.
15  *
16  * This file is subject to the terms and conditions of the GNU General Public
17  * License. See the file "COPYING" in the main directory of this archive
18  * for more details.
19  */
20 #include <linux/init.h>
21 #include <linux/time.h>
22 #include <linux/interrupt.h>
23 #include <asm/mach/time.h>
24 #include <asm/delay.h>
25 #include <asm/io.h>
26
27 #define OMAP2_GP_TIMER1_BASE    0x48028000
28 #define OMAP2_GP_TIMER2_BASE    0x4802a000
29 #define OMAP2_GP_TIMER3_BASE    0x48078000
30 #define OMAP2_GP_TIMER4_BASE    0x4807a000
31
32 #define GP_TIMER_TIDR           0x00
33 #define GP_TIMER_TISR           0x18
34 #define GP_TIMER_TIER           0x1c
35 #define GP_TIMER_TCLR           0x24
36 #define GP_TIMER_TCRR           0x28
37 #define GP_TIMER_TLDR           0x2c
38 #define GP_TIMER_TSICR          0x40
39
40 #define OS_TIMER_NR             1  /* GP timer 2 */
41
42 static unsigned long timer_base[] = {
43         IO_ADDRESS(OMAP2_GP_TIMER1_BASE),
44         IO_ADDRESS(OMAP2_GP_TIMER2_BASE),
45         IO_ADDRESS(OMAP2_GP_TIMER3_BASE),
46         IO_ADDRESS(OMAP2_GP_TIMER4_BASE),
47 };
48
49 static inline unsigned int timer_read_reg(int nr, unsigned int reg)
50 {
51         return __raw_readl(timer_base[nr] + reg);
52 }
53
54 static inline void timer_write_reg(int nr, unsigned int reg, unsigned int val)
55 {
56         __raw_writel(val, timer_base[nr] + reg);
57 }
58
59 static inline void omap2_gp_timer_start(int nr, unsigned long load_val)
60 {
61         unsigned int tmp;
62
63         tmp = 0xffffffff - load_val;
64
65         timer_write_reg(nr, GP_TIMER_TLDR, tmp);
66         timer_write_reg(nr, GP_TIMER_TCRR, tmp);
67         timer_write_reg(nr, GP_TIMER_TIER, 1 << 1);
68         timer_write_reg(nr, GP_TIMER_TCLR, (1 << 5) | (1 << 1) | 1);
69 }
70
71 static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id,
72                                             struct pt_regs *regs)
73 {
74         write_seqlock(&xtime_lock);
75
76         timer_write_reg(OS_TIMER_NR, GP_TIMER_TISR, 1 << 1);
77         timer_tick(regs);
78
79         write_sequnlock(&xtime_lock);
80
81         return IRQ_HANDLED;
82 }
83
84 static struct irqaction omap2_gp_timer_irq = {
85         .name           = "gp timer",
86         .flags          = SA_INTERRUPT,
87         .handler        = omap2_gp_timer_interrupt,
88 };
89
90 #define MPU_TIMER_TICK_PERIOD   (192000 - 1)
91
92 static void __init omap2_gp_timer_init(void)
93 {
94         u32 l;
95
96         l = timer_read_reg(OS_TIMER_NR, GP_TIMER_TIDR);
97         printk(KERN_INFO "OMAP2 GP timer (HW version %d.%d)\n",
98                (l >> 4) & 0x0f, l & 0x0f);
99
100         setup_irq(38, &omap2_gp_timer_irq);
101
102         omap2_gp_timer_start(OS_TIMER_NR, MPU_TIMER_TICK_PERIOD);
103 }
104
105 struct sys_timer omap_timer = {
106         .init   = omap2_gp_timer_init,
107 };
108