2 * linux/include/asm-arm/arch-at91rm9200/time.h
4 * Copyright (C) 2003 SAN People
5 * Copyright (C) 2003 ATMEL
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef __ASM_ARCH_TIME_H
23 #define __ASM_ARCH_TIME_H
25 #include <asm/system.h>
27 extern unsigned long (*gettimeoffset)(void);
30 * Returns number of microseconds since last timer interrupt. Note that interrupts
31 * will have been disabled by do_gettimeofday()
32 * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
33 * 'tick' is usecs per jiffy (linux/timex.h).
35 static unsigned long at91rm9200_gettimeoffset(void)
37 unsigned long elapsed;
39 elapsed = (AT91_SYS->ST_CRTR - AT91_SYS->ST_RTAR) & AT91C_ST_ALMV;
41 return (unsigned long)(elapsed * tick) / LATCH;
45 * IRQ handler for the timer.
47 static void at91rm9200_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
49 if (AT91_SYS->ST_SR & AT91C_ST_PITS) { /* This is a shared interrupt */
53 AT91_SYS->ST_RTAR = (AT91_SYS->ST_RTAR + LATCH) & AT91C_ST_ALMV;
55 } while (((AT91_SYS->ST_CRTR - AT91_SYS->ST_RTAR) & AT91C_ST_ALMV) >= LATCH);
62 * Set up timer interrupt.
64 static inline void setup_timer(void)
66 /* Disable all timer interrupts */
67 AT91_SYS->ST_IDR = AT91C_ST_PITS | AT91C_ST_WDOVF | AT91C_ST_RTTINC | AT91C_ST_ALMS;
68 (void) AT91_SYS->ST_SR; /* Clear any pending interrupts */
71 * Make IRQs happen for the system timer.
73 timer_irq.handler = at91rm9200_timer_interrupt;
74 timer_irq.flags = SA_SHIRQ | SA_INTERRUPT;
75 setup_arm_irq(AT91C_ID_SYS, &timer_irq);
76 gettimeoffset = at91rm9200_gettimeoffset;
78 /* Set initial alarm to 0 */
79 AT91_SYS->ST_RTAR = 0;
81 /* Real time counter incremented every 30.51758 microseconds */
82 AT91_SYS->ST_RTMR = 1;
84 /* Set Period Interval timer */
85 AT91_SYS->ST_PIMR = LATCH;
87 /* Change the kernel's 'tick' value to 10009 usec. (the default is 10000) */
88 tick = (LATCH * 1000000) / CLOCK_TICK_RATE;
90 /* Enable Period Interval Timer interrupt */
91 AT91_SYS->ST_IER = AT91C_ST_PITS;