http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / arch / arm / mach-iop3xx / iop321-time.c
1 /*
2  * arch/arm/mach-iop3xx/iop321-time.c
3  *
4  * Timer code for IOP321 based systems
5  *
6  * Author: Deepak Saxena <dsaxena@mvista.com>
7  *
8  * Copyright 2002 MontaVista Software Inc.
9  *
10  *  This program is free software; you can redistribute  it and/or modify it
11  *  under  the terms of  the GNU General  Public License as published by the
12  *  Free Software Foundation;  either version 2 of the  License, or (at your
13  *  option) any later version.
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/interrupt.h>
18 #include <linux/time.h>
19 #include <linux/init.h>
20 #include <linux/timex.h>
21
22 #include <asm/hardware.h>
23 #include <asm/io.h>
24 #include <asm/irq.h>
25 #include <asm/uaccess.h>
26
27 #include <asm/mach/irq.h>
28 #include <asm/mach/time.h>
29
30 static unsigned long iop321_gettimeoffset(void)
31 {
32         unsigned long elapsed, usec;
33
34         /*
35          * FIXME: Implement what is described in this comment.
36          *
37          * If an interrupt was pending before we read the timer,
38          * we've already wrapped.  Factor this into the time.
39          * If an interrupt was pending after we read the timer,
40          * it may have wrapped between checking the interrupt
41          * status and reading the timer.  Re-read the timer to
42          * be sure its value is after the wrap.
43          */
44
45         elapsed = *IOP321_TU_TCR0;
46
47         /*
48          * Now convert them to usec.
49          */
50         usec = (unsigned long)((LATCH - elapsed) * (tick_nsec / 1000)) / LATCH;
51
52         return usec;
53 }
54
55 static irqreturn_t
56 iop321_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
57 {
58         u32 tisr;
59
60         asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr));
61
62         tisr |= 1;
63
64         asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (tisr));
65
66         timer_tick(regs);
67
68         return IRQ_HANDLED;
69 }
70
71 static struct irqaction iop321_timer_irq = {
72         .name           = "IOP321 Timer Tick",
73         .handler        = iop321_timer_interrupt,
74         .flags          = SA_INTERRUPT
75 };
76
77 extern int setup_arm_irq(int, struct irqaction*);
78
79 void __init iop321_init_time(void)
80 {
81         u32 timer_ctl;
82         u32 latch = LATCH;
83
84         gettimeoffset = iop321_gettimeoffset;
85         setup_irq(IRQ_IOP321_TIMER0, &iop321_timer_irq);
86
87         timer_ctl = IOP321_TMR_EN | IOP321_TMR_PRIVILEGED | IOP321_TMR_RELOAD |
88                         IOP321_TMR_RATIO_1_1;
89
90         asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (LATCH));
91
92         asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl));
93 }
94
95