2 * arch/arm/mach-iop3xx/iop321-time.c
4 * Timer code for IOP321 based systems
6 * Author: Deepak Saxena <dsaxena@mvista.com>
8 * Copyright 2002 MontaVista Software Inc.
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>
25 #include <asm/uaccess.h>
26 #include <asm/mach/irq.h>
28 static unsigned long iop321_gettimeoffset(void)
30 unsigned long elapsed, usec;
33 * FIXME: Implement what is described in this comment.
35 * If an interrupt was pending before we read the timer,
36 * we've already wrapped. Factor this into the time.
37 * If an interrupt was pending after we read the timer,
38 * it may have wrapped between checking the interrupt
39 * status and reading the timer. Re-read the timer to
40 * be sure its value is after the wrap.
43 elapsed = *IOP321_TU_TCR0;
46 * Now convert them to usec.
48 usec = (unsigned long)((LATCH - elapsed) * (tick_nsec / 1000)) / LATCH;
54 iop321_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
58 asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr));
62 asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (tisr));
69 extern unsigned long (*gettimeoffset)(void);
71 static struct irqaction timer_irq = {
73 .handler = iop321_timer_interrupt,
76 extern int setup_arm_irq(int, struct irqaction*);
78 void __init time_init(void)
83 gettimeoffset = iop321_gettimeoffset;
84 setup_irq(IRQ_IOP321_TIMER0, &timer_irq);
86 timer_ctl = IOP321_TMR_EN | IOP321_TMR_PRIVILEGED | IOP321_TMR_RELOAD |
89 asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (LATCH));
91 asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl));