2 * linux/arch/ia64/sn/kernel/sn2/timer.c
4 * Copyright (C) 2003 Silicon Graphics, Inc.
5 * Copyright (C) 2003 Hewlett-Packard Co
6 * David Mosberger <davidm@hpl.hp.com>: updated for new timer-interpolation infrastructure
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/time.h>
13 #include <linux/interrupt.h>
15 #include <asm/hw_irq.h>
16 #include <asm/system.h>
18 #include <asm/sn/leds.h>
19 #include <asm/sn/clksupport.h>
22 extern unsigned long sn_rtc_cycles_per_second;
23 static volatile unsigned long last_wall_rtc;
25 static unsigned long rtc_offset; /* updated only when xtime write-lock is held! */
26 static long rtc_nsecs_per_cycle;
27 static long rtc_per_timer_tick;
32 return rtc_offset + (GET_RTC_COUNTER() - last_wall_rtc)*rtc_nsecs_per_cycle;
37 update(long delta_nsec)
39 unsigned long rtc_counter = GET_RTC_COUNTER();
40 unsigned long offset = rtc_offset + (rtc_counter - last_wall_rtc)*rtc_nsecs_per_cycle;
42 /* Be careful about signed/unsigned comparisons here: */
43 if (delta_nsec < 0 || (unsigned long) delta_nsec < offset)
44 rtc_offset = offset - delta_nsec;
47 last_wall_rtc = rtc_counter;
55 last_wall_rtc = GET_RTC_COUNTER();
59 static struct time_interpolator sn2_interpolator = {
60 .get_offset = getoffset,
68 sn2_interpolator.frequency = sn_rtc_cycles_per_second;
69 sn2_interpolator.drift = -1; /* unknown */
70 register_time_interpolator(&sn2_interpolator);
72 rtc_per_timer_tick = sn_rtc_cycles_per_second / HZ;
73 rtc_nsecs_per_cycle = 1000000000 / sn_rtc_cycles_per_second;
75 last_wall_rtc = GET_RTC_COUNTER();