1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <asm/rtc.h>
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>
34
35int have_rtc; ;
36
37#define TICK_SIZE tick
38
39extern unsigned long loops_per_jiffy;
40unsigned long loops_per_usec;
41
42
43#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
44extern unsigned long do_slow_gettimeoffset(void);
45static unsigned long (*do_gettimeoffset)(void) = do_slow_gettimeoffset;
46
47u32 arch_gettimeoffset(void)
48{
49 return do_gettimeoffset() * 1000;
50}
51#endif
52
53
54
55
56
57
58int set_rtc_mmss(unsigned long nowtime)
59{
60 int retval = 0;
61 int real_seconds, real_minutes, cmos_minutes;
62
63 printk(KERN_DEBUG "set_rtc_mmss(%lu)\n", nowtime);
64
65 if(!have_rtc)
66 return 0;
67
68 cmos_minutes = CMOS_READ(RTC_MINUTES);
69 cmos_minutes = bcd2bin(cmos_minutes);
70
71
72
73
74
75
76
77 real_seconds = nowtime % 60;
78 real_minutes = nowtime / 60;
79 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
80 real_minutes += 30;
81 real_minutes %= 60;
82
83 if (abs(real_minutes - cmos_minutes) < 30) {
84 real_seconds = bin2bcd(real_seconds);
85 real_minutes = bin2bcd(real_minutes);
86 CMOS_WRITE(real_seconds,RTC_SECONDS);
87 CMOS_WRITE(real_minutes,RTC_MINUTES);
88 } else {
89 printk_once(KERN_NOTICE
90 "set_rtc_mmss: can't update from %d to %d\n",
91 cmos_minutes, real_minutes);
92 retval = -1;
93 }
94
95 return retval;
96}
97
98
99
100unsigned long
101get_cmos_time(void)
102{
103 unsigned int year, mon, day, hour, min, sec;
104 if(!have_rtc)
105 return 0;
106
107 sec = CMOS_READ(RTC_SECONDS);
108 min = CMOS_READ(RTC_MINUTES);
109 hour = CMOS_READ(RTC_HOURS);
110 day = CMOS_READ(RTC_DAY_OF_MONTH);
111 mon = CMOS_READ(RTC_MONTH);
112 year = CMOS_READ(RTC_YEAR);
113
114 sec = bcd2bin(sec);
115 min = bcd2bin(min);
116 hour = bcd2bin(hour);
117 day = bcd2bin(day);
118 mon = bcd2bin(mon);
119 year = bcd2bin(year);
120
121 if ((year += 1900) < 1970)
122 year += 100;
123
124 return mktime(year, mon, day, hour, min, sec);
125}
126
127
128int update_persistent_clock(struct timespec now)
129{
130 return set_rtc_mmss(now.tv_sec);
131}
132
133void read_persistent_clock(struct timespec *ts)
134{
135 ts->tv_sec = get_cmos_time();
136 ts->tv_nsec = 0;
137}
138
139
140extern void cris_profile_sample(struct pt_regs* regs);
141
142void
143cris_do_profile(struct pt_regs* regs)
144{
145
146#ifdef CONFIG_SYSTEM_PROFILER
147 cris_profile_sample(regs);
148#endif
149
150#ifdef CONFIG_PROFILING
151 profile_tick(CPU_PROFILING);
152#endif
153}
154
155unsigned long long sched_clock(void)
156{
157 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ) +
158 get_ns_in_jiffie();
159}
160
161static int
162__init init_udelay(void)
163{
164 loops_per_usec = (loops_per_jiffy * HZ) / 1000000;
165 return 0;
166}
167
168__initcall(init_udelay);
169