# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / arch / arm / common / time-acorn.c
1 /*
2  *  linux/arch/arm/common/time-acorn.c
3  *
4  *  Copyright (c) 1996-2000 Russell King.
5  *
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.
9  *
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
15  */
16 #include <linux/timex.h>
17 #include <linux/init.h>
18
19 #include <asm/hardware.h>
20 #include <asm/io.h>
21 #include <asm/hardware/ioc.h>
22
23 #include <asm/mach/time.h>
24
25 static unsigned long ioctime_gettimeoffset(void)
26 {
27         unsigned int count1, count2, status;
28         long offset;
29
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);
39
40         offset = count2;
41         if (count2 < count1) {
42                 /*
43                  * We have not had an interrupt between reading count1
44                  * and count2.
45                  */
46                 if (status & (1 << 5))
47                         offset -= LATCH;
48         } else if (count2 > count1) {
49                 /*
50                  * We have just had another interrupt between reading
51                  * count1 and count2.
52                  */
53                 offset -= LATCH;
54         }
55
56         offset = (LATCH - offset) * (tick_nsec / 1000);
57         return (offset + LATCH/2) / LATCH;
58 }
59
60 void __init ioctime_init(void)
61 {
62         ioc_writeb(LATCH & 255, IOC_T0LTCHL);
63         ioc_writeb(LATCH >> 8, IOC_T0LTCHH);
64         ioc_writeb(0, IOC_T0GO);
65
66         gettimeoffset = ioctime_gettimeoffset;
67 }