2 * linux/arch/arm/mach-imx/time.c
4 * Copyright (C) 2000-2001 Deep Blue Solutions
5 * Copyright (C) 2002 Shane Nay (shane@minirl.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/irq.h>
16 #include <linux/time.h>
17 #include <linux/clocksource.h>
19 #include <asm/hardware.h>
23 #include <asm/mach/time.h>
25 /* Use timer 1 as system timer */
26 #define TIMER_BASE IMX_TIM1_BASE
28 static unsigned long evt_diff;
31 * IRQ handler for the timer
34 imx_timer_interrupt(int irq, void *dev_id)
38 /* clear the interrupt */
39 tstat = IMX_TSTAT(TIMER_BASE);
40 IMX_TSTAT(TIMER_BASE) = 0;
42 if (tstat & TSTAT_COMP) {
45 write_seqlock(&xtime_lock);
47 write_sequnlock(&xtime_lock);
48 IMX_TCMP(TIMER_BASE) += evt_diff;
50 } while (unlikely((int32_t)(IMX_TCMP(TIMER_BASE)
51 - IMX_TCN(TIMER_BASE)) < 0));
57 static struct irqaction imx_timer_irq = {
58 .name = "i.MX Timer Tick",
59 .flags = IRQF_DISABLED | IRQF_TIMER,
60 .handler = imx_timer_interrupt,
64 * Set up timer hardware into expected mode and state.
66 static void __init imx_timer_hardware_init(void)
69 * Initialise to a known state (all timers off, and timing reset)
71 IMX_TCTL(TIMER_BASE) = 0;
72 IMX_TPRER(TIMER_BASE) = 0;
73 IMX_TCMP(TIMER_BASE) = LATCH - 1;
75 IMX_TCTL(TIMER_BASE) = TCTL_FRR | TCTL_CLK_PCLK1 | TCTL_IRQEN | TCTL_TEN;
79 cycle_t imx_get_cycles(void)
81 return IMX_TCN(TIMER_BASE);
84 static struct clocksource clocksource_imx = {
87 .read = imx_get_cycles,
93 static int __init imx_clocksource_init(void)
95 clocksource_imx.mult =
96 clocksource_hz2mult(imx_get_perclk1(), clocksource_imx.shift);
97 clocksource_register(&clocksource_imx);
102 static void __init imx_timer_init(void)
104 imx_timer_hardware_init();
105 imx_clocksource_init();
108 * Make irqs happen for the system timer
110 setup_irq(TIM1_INT, &imx_timer_irq);
113 struct sys_timer imx_timer = {
114 .init = imx_timer_init,