2 * linux/arch/arm/mach-clps711x/time.c
4 * Copyright (C) 2001 Deep Blue Solutions Ltd.
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 * 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.
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
19 #include <linux/timex.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/sched.h>
25 #include <asm/hardware.h>
29 #include <asm/hardware/clps7111.h>
31 #include <asm/mach/time.h>
35 * gettimeoffset() returns time since last timer tick, in usecs.
37 * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
38 * 'tick' is usecs per jiffy.
40 static unsigned long clps711x_gettimeoffset(void)
42 unsigned long hwticks
;
43 hwticks
= LATCH
- (clps_readl(TC2D
) & 0xffff); /* since last underflow */
44 return (hwticks
* (tick_nsec
/ 1000)) / LATCH
;
48 * IRQ handler for the timer
51 p720t_timer_interrupt(int irq
, void *dev_id
)
53 write_seqlock(&xtime_lock
);
55 write_sequnlock(&xtime_lock
);
59 static struct irqaction clps711x_timer_irq
= {
60 .name
= "CLPS711x Timer Tick",
61 .flags
= IRQF_DISABLED
| IRQF_TIMER
| IRQF_IRQPOLL
,
62 .handler
= p720t_timer_interrupt
,
65 static void __init
clps711x_timer_init(void)
70 syscon
= clps_readl(SYSCON1
);
71 syscon
|= SYSCON1_TC2S
| SYSCON1_TC2M
;
72 clps_writel(syscon
, SYSCON1
);
74 clps_writel(LATCH
-1, TC2D
); /* 512kHz / 100Hz - 1 */
76 setup_irq(IRQ_TC2OI
, &clps711x_timer_irq
);
79 tv
.tv_sec
= clps_readl(RTCDR
);
83 struct sys_timer clps711x_timer
= {
84 .init
= clps711x_timer_init
,
85 .offset
= clps711x_gettimeoffset
,