[MIPS] Use common definitions from asm-generic/signal.h
[linux-2.6/linux-mips/linux-dm7025.git] / arch / arm / mach-iop3xx / iop331-time.c
blob0c09e74c574042240a5d1af81fc57502eaf0ec5d
1 /*
2 * arch/arm/mach-iop3xx/iop331-time.c
4 * Timer code for IOP331 based systems
6 * Author: Dave Jiang <dave.jiang@intel.com>
8 * Copyright 2003 Intel Corp.
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.
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>
22 #include <asm/hardware.h>
23 #include <asm/io.h>
24 #include <asm/irq.h>
25 #include <asm/uaccess.h>
26 #include <asm/mach/irq.h>
27 #include <asm/mach/time.h>
29 static inline unsigned long get_elapsed(void)
31 return LATCH - *IOP331_TU_TCR0;
34 static unsigned long iop331_gettimeoffset(void)
36 unsigned long elapsed, usec;
37 u32 tisr1, tisr2;
40 * If an interrupt was pending before we read the timer,
41 * we've already wrapped. Factor this into the time.
42 * If an interrupt was pending after we read the timer,
43 * it may have wrapped between checking the interrupt
44 * status and reading the timer. Re-read the timer to
45 * be sure its value is after the wrap.
48 asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr1));
49 elapsed = get_elapsed();
50 asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr2));
52 if(tisr1 & 1)
53 elapsed += LATCH;
54 else if (tisr2 & 1)
55 elapsed = LATCH + get_elapsed();
58 * Now convert them to usec.
60 usec = (unsigned long)(elapsed / (CLOCK_TICK_RATE/1000000));
62 return usec;
65 static irqreturn_t
66 iop331_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
68 u32 tisr;
70 write_seqlock(&xtime_lock);
72 asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr));
73 tisr |= 1;
74 asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (tisr));
76 timer_tick(regs);
78 write_sequnlock(&xtime_lock);
79 return IRQ_HANDLED;
82 static struct irqaction iop331_timer_irq = {
83 .name = "IOP331 Timer Tick",
84 .handler = iop331_timer_interrupt,
85 .flags = IRQF_DISABLED | IRQF_TIMER,
88 static void __init iop331_timer_init(void)
90 u32 timer_ctl;
92 setup_irq(IRQ_IOP331_TIMER0, &iop331_timer_irq);
94 timer_ctl = IOP331_TMR_EN | IOP331_TMR_PRIVILEGED | IOP331_TMR_RELOAD |
95 IOP331_TMR_RATIO_1_1;
97 asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (LATCH));
99 asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl));
103 struct sys_timer iop331_timer = {
104 .init = iop331_timer_init,
105 .offset = iop331_gettimeoffset,