import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / arm / mach-clps711x / time.c
1 /*
2  *  linux/arch/arm/mach-clps711x/time.c
3  *
4  *  Copyright (C) 2001 Deep Blue Solutions Ltd.
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  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 #include <linux/sched.h>
20 #include <linux/init.h>
21
22 #include <asm/hardware.h>
23 #include <asm/io.h>
24 #include <asm/hardware/clps7111.h>
25
26 extern unsigned long (*gettimeoffset)(void);
27
28 /*
29  * gettimeoffset() returns time since last timer tick, in usecs.
30  *
31  * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
32  * 'tick' is usecs per jiffy.
33  */
34 static unsigned long clps711x_gettimeoffset(void)
35 {
36         unsigned long hwticks;
37         hwticks = LATCH - (clps_readl(TC2D) & 0xffff);  /* since last underflow */
38         return (hwticks * tick) / LATCH;
39 }
40
41 void __init clps711x_setup_timer(void)
42 {
43         unsigned int syscon;
44
45         gettimeoffset = clps711x_gettimeoffset;
46
47         syscon = clps_readl(SYSCON1);
48         syscon |= SYSCON1_TC2S | SYSCON1_TC2M;
49         clps_writel(syscon, SYSCON1);
50
51         clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */
52
53         xtime.tv_sec = clps_readl(RTCDR);
54 }