2 * linux/arch/cris/kernel/time.c
4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
5 * Copyright (C) 1999, 2000, 2001 Axis Communications AB
7 * 1994-07-02 Alan Modra
8 * fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime
9 * 1995-03-26 Markus Kuhn
10 * fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887
11 * precision CMOS clock update
12 * 1996-05-03 Ingo Molnar
13 * fixed time warps in do_[slow|fast]_gettimeoffset()
14 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
15 * "A Kernel Model for Precision Timekeeping" by Dave Mills
17 * Linux/CRIS specific code:
19 * Authors: Bjorn Wesen
25 #include <linux/errno.h>
26 #include <linux/module.h>
27 #include <linux/param.h>
28 #include <linux/jiffies.h>
29 #include <linux/bcd.h>
30 #include <linux/timex.h>
31 #include <linux/init.h>
32 #include <linux/profile.h>
33 #include <linux/sched.h> /* just for sched_clock() - funny that */
35 int have_rtc; /* used to remember if we have an RTC or not */;
37 #define TICK_SIZE tick
39 extern unsigned long loops_per_jiffy; /* init/main.c */
40 unsigned long loops_per_usec;
42 extern unsigned long do_slow_gettimeoffset(void);
43 static unsigned long (*do_gettimeoffset)(void) = do_slow_gettimeoffset;
45 u32 arch_gettimeoffset(void)
47 return do_gettimeoffset() * 1000;
51 * BUG: This routine does not handle hour overflow properly; it just
52 * sets the minutes. Usually you'll only notice that after reboot!
55 int set_rtc_mmss(unsigned long nowtime)
58 int real_seconds, real_minutes, cmos_minutes;
60 printk(KERN_DEBUG "set_rtc_mmss(%lu)\n", nowtime);
65 cmos_minutes = CMOS_READ(RTC_MINUTES);
66 cmos_minutes = bcd2bin(cmos_minutes);
69 * since we're only adjusting minutes and seconds,
70 * don't interfere with hour overflow. This avoids
71 * messing with unknown time zones but requires your
72 * RTC not to be off by more than 15 minutes
74 real_seconds = nowtime % 60;
75 real_minutes = nowtime / 60;
76 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
77 real_minutes += 30; /* correct for half hour time zone */
80 if (abs(real_minutes - cmos_minutes) < 30) {
81 real_seconds = bin2bcd(real_seconds);
82 real_minutes = bin2bcd(real_minutes);
83 CMOS_WRITE(real_seconds,RTC_SECONDS);
84 CMOS_WRITE(real_minutes,RTC_MINUTES);
87 "set_rtc_mmss: can't update from %d to %d\n",
88 cmos_minutes, real_minutes);
95 /* grab the time from the RTC chip */
100 unsigned int year, mon, day, hour, min, sec;
102 sec = CMOS_READ(RTC_SECONDS);
103 min = CMOS_READ(RTC_MINUTES);
104 hour = CMOS_READ(RTC_HOURS);
105 day = CMOS_READ(RTC_DAY_OF_MONTH);
106 mon = CMOS_READ(RTC_MONTH);
107 year = CMOS_READ(RTC_YEAR);
111 hour = bcd2bin(hour);
114 year = bcd2bin(year);
116 if ((year += 1900) < 1970)
119 return mktime(year, mon, day, hour, min, sec);
122 /* update xtime from the CMOS settings. used when /dev/rtc gets a SET_TIME.
123 * TODO: this doesn't reset the fancy NTP phase stuff as do_settimeofday does.
127 update_xtime_from_cmos(void)
130 xtime.tv_sec = get_cmos_time();
135 extern void cris_profile_sample(struct pt_regs* regs);
138 cris_do_profile(struct pt_regs* regs)
141 #ifdef CONFIG_SYSTEM_PROFILER
142 cris_profile_sample(regs);
145 #ifdef CONFIG_PROFILING
146 profile_tick(CPU_PROFILING);
150 unsigned long long sched_clock(void)
152 return (unsigned long long)jiffies * (1000000000 / HZ) +
157 __init init_udelay(void)
159 loops_per_usec = (loops_per_jiffy * HZ) / 1000000;
163 __initcall(init_udelay);