2 * linux/include/asm-arm/arch-ebsa110/time.h
4 * Copyright (C) 1996,1997,1998 Russell King.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * No real time clock on the evalulation board!
13 * 10-Oct-1996 RMK Created
14 * 04-Dec-1997 RMK Updated for new arch/arm/kernel/time.c
15 * 07-Aug-1998 RMK Updated for arch/arm/kernel/leds.c
16 * 28-Dec-1998 APH Made leds code optional
22 extern unsigned long (*gettimeoffset)(void);
24 #define PIT_CTRL (PIT_BASE + 0x0d)
25 #define PIT_T2 (PIT_BASE + 0x09)
26 #define PIT_T1 (PIT_BASE + 0x05)
27 #define PIT_T0 (PIT_BASE + 0x01)
30 * This is the rate at which your MCLK signal toggles (in Hz)
31 * This was measured on a 10 digit frequency counter sampling
37 * This is the rate at which the PIT timers get clocked
39 #define CLKBY7 (MCLK / 7)
42 * This is the counter value. We tick at 200Hz on this platform.
44 #define COUNT ((CLKBY7 + (HZ / 2)) / HZ)
47 * Get the time offset from the system PIT. Note that if we have missed an
48 * interrupt, then the PIT counter will roll over (ie, be negative).
49 * This actually works out to be convenient.
51 static unsigned long ebsa110_gettimeoffset(void)
53 unsigned long offset, count;
55 __raw_writeb(0x40, PIT_CTRL);
56 count = __raw_readb(PIT_T1);
57 count |= __raw_readb(PIT_T1) << 8;
60 * If count > COUNT, make the number negative.
69 * `offset' is in units of timer counts. Convert
70 * offset to units of microseconds.
72 offset = offset * (1000000 / HZ) / COUNT;
78 timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
82 /* latch and read timer 1 */
83 __raw_writeb(0x40, PIT_CTRL);
84 count = __raw_readb(PIT_T1);
85 count |= __raw_readb(PIT_T1) << 8;
89 __raw_writeb(count & 0xff, PIT_T1);
90 __raw_writeb(count >> 8, PIT_T1);
100 * Set up timer interrupt.
102 void __init time_init(void)
105 * Timer 1, mode 2, LSB/MSB
107 __raw_writeb(0x70, PIT_CTRL);
108 __raw_writeb(COUNT & 0xff, PIT_T1);
109 __raw_writeb(COUNT >> 8, PIT_T1);
111 gettimeoffset = ebsa110_gettimeoffset;
113 timer_irq.handler = timer_interrupt;
115 setup_irq(IRQ_EBSA110_TIMER0, &timer_irq);