initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / h8300 / kernel / time.c
blob0b293d652bf461b14f4f1394878694f5c4ef6e46
1 /*
2 * linux/arch/h8300/kernel/time.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
6 * Copied/hacked from:
8 * linux/arch/m68k/kernel/time.c
10 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
12 * This file contains the m68k-specific time handling details.
13 * Most of the stuff is located in the machine specific files.
15 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
16 * "A Kernel Model for Precision Timekeeping" by Dave Mills
19 #include <linux/config.h> /* CONFIG_HEARTBEAT */
20 #include <linux/errno.h>
21 #include <linux/module.h>
22 #include <linux/sched.h>
23 #include <linux/kernel.h>
24 #include <linux/param.h>
25 #include <linux/string.h>
26 #include <linux/mm.h>
27 #include <linux/timex.h>
28 #include <linux/profile.h>
30 #include <asm/io.h>
31 #include <asm/target_time.h>
33 #define TICK_SIZE (tick_nsec / 1000)
35 u64 jiffies_64;
37 EXPORT_SYMBOL(jiffies_64);
40 * timer_interrupt() needs to keep up the real-time clock,
41 * as well as call the "do_timer()" routine every clocktick
43 static void timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
45 /* may need to kick the hardware timer */
46 platform_timer_eoi();
48 do_timer(regs);
49 profile_tick(CPU_PROFILING, regs);
52 void time_init(void)
54 unsigned int year, mon, day, hour, min, sec;
56 /* FIX by dqg : Set to zero for platforms that don't have tod */
57 /* without this time is undefined and can overflow time_t, causing */
58 /* very stange errors */
59 year = 1980;
60 mon = day = 1;
61 hour = min = sec = 0;
62 platform_gettod (&year, &mon, &day, &hour, &min, &sec);
64 if ((year += 1900) < 1970)
65 year += 100;
66 xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
67 xtime.tv_nsec = 0;
69 platform_timer_setup(timer_interrupt);
73 * This version of gettimeofday has near microsecond resolution.
75 void do_gettimeofday(struct timeval *tv)
77 unsigned long flags;
78 unsigned long usec, sec;
80 read_lock_irqsave(&xtime_lock, flags);
81 usec = 0;
82 sec = xtime.tv_sec;
83 usec += (xtime.tv_nsec / 1000);
84 read_unlock_irqrestore(&xtime_lock, flags);
86 while (usec >= 1000000) {
87 usec -= 1000000;
88 sec++;
91 tv->tv_sec = sec;
92 tv->tv_usec = usec;
95 EXPORT_SYMBOL(do_gettimeofday);
97 int do_settimeofday(struct timespec *tv)
99 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
100 return -EINVAL;
102 write_lock_irq(&xtime_lock);
103 /* This is revolting. We need to set the xtime.tv_usec
104 * correctly. However, the value in this location is
105 * is value at the last tick.
106 * Discover what correction gettimeofday
107 * would have done, and then undo it!
109 while (tv->tv_nsec < 0) {
110 tv->tv_nsec += NSEC_PER_SEC;
111 tv->tv_sec--;
114 xtime.tv_sec = tv->tv_sec;
115 xtime.tv_nsec = tv->tv_nsec;
116 time_adjust = 0; /* stop active adjtime() */
117 time_status |= STA_UNSYNC;
118 time_maxerror = NTP_PHASE_LIMIT;
119 time_esterror = NTP_PHASE_LIMIT;
120 write_sequnlock_irq(&xtime_lock);
121 clock_was_set();
122 return 0;
125 EXPORT_SYMBOL(do_settimeofday);
127 unsigned long long sched_clock(void)
129 return (unsigned long long)jiffies * (1000000000 / HZ);