MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / arch / arm / common / time-acorn.c
blobeb06282962eb9d26cbce5c6c99b7a123480ba7c8
1 /*
2 * linux/arch/arm/common/time-acorn.c
4 * Copyright (c) 1996-2000 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 * Changelog:
11 * 24-Sep-1996 RMK Created
12 * 10-Oct-1996 RMK Brought up to date with arch-sa110eval
13 * 04-Dec-1997 RMK Updated for new arch/arm/time.c
14 * 13=Jun-2004 DS Moved to arch/arm/common b/c shared w/CLPS7500
16 #include <linux/timex.h>
17 #include <linux/init.h>
19 #include <asm/hardware.h>
20 #include <asm/io.h>
21 #include <asm/hardware/ioc.h>
23 #include <asm/mach/time.h>
25 static unsigned long ioctime_gettimeoffset(void)
27 unsigned int count1, count2, status;
28 long offset;
30 ioc_writeb (0, IOC_T0LATCH);
31 barrier ();
32 count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
33 barrier ();
34 status = ioc_readb(IOC_IRQREQA);
35 barrier ();
36 ioc_writeb (0, IOC_T0LATCH);
37 barrier ();
38 count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
40 offset = count2;
41 if (count2 < count1) {
43 * We have not had an interrupt between reading count1
44 * and count2.
46 if (status & (1 << 5))
47 offset -= LATCH;
48 } else if (count2 > count1) {
50 * We have just had another interrupt between reading
51 * count1 and count2.
53 offset -= LATCH;
56 offset = (LATCH - offset) * (tick_nsec / 1000);
57 return (offset + LATCH/2) / LATCH;
60 void __init ioctime_init(void)
62 ioc_writeb(LATCH & 255, IOC_T0LTCHL);
63 ioc_writeb(LATCH >> 8, IOC_T0LTCHH);
64 ioc_writeb(0, IOC_T0GO);
66 gettimeoffset = ioctime_gettimeoffset;