2 * arch/arm/mach-iop13xx/time.c
4 * Timer code for IOP13xx (copied from IOP32x/IOP33x implementation)
6 * Author: Deepak Saxena <dsaxena@mvista.com>
8 * Copyright 2002-2003 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>
23 #include <asm/uaccess.h>
24 #include <asm/mach/irq.h>
25 #include <asm/mach/time.h>
27 static unsigned long ticks_per_jiffy;
28 static unsigned long ticks_per_usec;
29 static unsigned long next_jiffy_time;
31 static inline u32 read_tcr1(void)
34 asm volatile("mrc p6, 0, %0, c3, c9, 0" : "=r" (val));
38 unsigned long iop13xx_gettimeoffset(void)
43 cp_flags = iop13xx_cp6_save();
44 offset = next_jiffy_time - read_tcr1();
45 iop13xx_cp6_restore(cp_flags);
47 return offset / ticks_per_usec;
51 iop13xx_timer_interrupt(int irq, void *dev_id)
53 u32 cp_flags = iop13xx_cp6_save();
55 write_seqlock(&xtime_lock);
57 asm volatile("mcr p6, 0, %0, c6, c9, 0" : : "r" (1));
59 while ((signed long)(next_jiffy_time - read_tcr1())
62 next_jiffy_time -= ticks_per_jiffy;
65 write_sequnlock(&xtime_lock);
67 iop13xx_cp6_restore(cp_flags);
72 static struct irqaction iop13xx_timer_irq = {
73 .name = "IOP13XX Timer Tick",
74 .handler = iop13xx_timer_interrupt,
75 .flags = IRQF_DISABLED | IRQF_TIMER,
78 void __init iop13xx_init_time(unsigned long tick_rate)
83 ticks_per_jiffy = (tick_rate + HZ/2) / HZ;
84 ticks_per_usec = tick_rate / 1000000;
85 next_jiffy_time = 0xffffffff;
87 timer_ctl = IOP13XX_TMR_EN | IOP13XX_TMR_PRIVILEGED |
88 IOP13XX_TMR_RELOAD | IOP13XX_TMR_RATIO_1_1;
91 * We use timer 0 for our timer interrupt, and timer 1 as
92 * monotonic counter for tracking missed jiffies.
94 cp_flags = iop13xx_cp6_save();
95 asm volatile("mcr p6, 0, %0, c4, c9, 0" : : "r" (ticks_per_jiffy - 1));
96 asm volatile("mcr p6, 0, %0, c0, c9, 0" : : "r" (timer_ctl));
97 asm volatile("mcr p6, 0, %0, c5, c9, 0" : : "r" (0xffffffff));
98 asm volatile("mcr p6, 0, %0, c1, c9, 0" : : "r" (timer_ctl));
99 iop13xx_cp6_restore(cp_flags);
101 setup_irq(IRQ_IOP13XX_TIMER0, &iop13xx_timer_irq);