ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-arm / arch-nexuspci / time.h
1 /*
2  * linux/include/asm-arm/arch-nexuspci/time.h
3  *
4  * Copyright (c) 1997, 1998, 1999, 2000 FutureTV Labs Ltd.
5  *
6  * The FTV PCI card has no real-time clock.  We get timer ticks from the
7  * SCC chip.
8  */
9
10 /*
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version
14  * 2 of the License, or (at your option) any later version.
15  */
16
17 static irqreturn_t
18 timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
19 {
20         static int count = 25;
21         unsigned char stat = __raw_readb(DUART_BASE + 0x14);
22         if (!(stat & 0x10))
23                 return;         /* Not for us */
24
25         /* Reset counter */
26         __raw_writeb(0x90, DUART_BASE + 8);
27
28         if (--count == 0) {
29                 static int state = 1;
30                 state ^= 1;
31                 __raw_writeb(0x1a + state, INTCONT_BASE);
32                 __raw_writeb(0x18 + state, INTCONT_BASE);
33                 count = 50;
34         }
35
36         /* Wait for slow rise time */
37         __raw_readb(DUART_BASE + 0x14);
38         __raw_readb(DUART_BASE + 0x14);
39         __raw_readb(DUART_BASE + 0x14);
40         __raw_readb(DUART_BASE + 0x14);
41         __raw_readb(DUART_BASE + 0x14);
42         __raw_readb(DUART_BASE + 0x14);
43
44         do_timer(regs);
45
46         return IRQ_HANDLED;
47 }
48
49 void __init time_init(void)
50 {
51         int tick = 3686400 / 16 / 2 / 100;
52
53         __raw_writeb(tick & 0xff, DUART_BASE + 0x1c);
54         __raw_writeb(tick >> 8, DUART_BASE + 0x18);
55         __raw_writeb(0x80, DUART_BASE + 8);
56         __raw_writeb(0x10, DUART_BASE + 0x14);
57
58         timer_irq.handler = timer_interrupt;
59         timer_irq.flags = SA_SHIRQ;
60
61         setup_irq(IRQ_TIMER, &timer_irq);
62 }