File: /usr/src/linux/arch/arm/kernel/time-acorn.c

1     /*
2      *  linux/arch/arm/kernel/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      */
15     #include <linux/sched.h>
16     #include <linux/interrupt.h>
17     #include <linux/init.h>
18     
19     #include <asm/hardware.h>
20     #include <asm/io.h>
21     #include <asm/irq.h>
22     #include <asm/hardware/ioc.h>
23     
24     extern unsigned long (*gettimeoffset)(void);
25     
26     static unsigned long ioctime_gettimeoffset(void)
27     {
28     	unsigned int count1, count2, status1, status2;
29     	unsigned long offset = 0;
30     
31     	status1 = ioc_readb(IOC_IRQREQA);
32     	barrier ();
33     	ioc_writeb (0, IOC_T0LATCH);
34     	barrier ();
35     	count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
36     	barrier ();
37     	status2 = ioc_readb(IOC_IRQREQA);
38     	barrier ();
39     	ioc_writeb (0, IOC_T0LATCH);
40     	barrier ();
41     	count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
42     
43     	if (count2 < count1) {
44     		/*
45     		 * This means that we haven't just had an interrupt
46     		 * while reading into status2.
47     		 */
48     		if (status2 & (1 << 5))
49     			offset = tick;
50     		count1 = count2;
51     	} else if (count2 > count1) {
52     		/*
53     		 * We have just had another interrupt while reading
54     		 * status2.
55     		 */
56     		offset += tick;
57     		count1 = count2;
58     	}
59     
60     	count1 = LATCH - count1;
61     	/*
62     	 * count1 = number of clock ticks since last interrupt
63     	 */
64     	offset += count1 * tick / LATCH;
65     	return offset;
66     }
67     
68     void __init ioctime_init(void)
69     {
70     	ioc_writeb(LATCH & 255, IOC_T0LTCHL);
71     	ioc_writeb(LATCH >> 8, IOC_T0LTCHH);
72     	ioc_writeb(0, IOC_T0GO);
73     
74     	gettimeoffset = ioctime_gettimeoffset;
75     }
76