This source file includes following definitions.
- read_persistent_clock64
- update_persistent_clock64
- plat_time_init
1
2
3
4
5
6
7
8
9
10 #include <linux/bcd.h>
11 #include <linux/init.h>
12 #include <linux/mc146818rtc.h>
13 #include <linux/param.h>
14
15 #include <asm/cpu-features.h>
16 #include <asm/ds1287.h>
17 #include <asm/time.h>
18 #include <asm/dec/interrupts.h>
19 #include <asm/dec/ioasic.h>
20 #include <asm/dec/machtype.h>
21
22 void read_persistent_clock64(struct timespec64 *ts)
23 {
24 unsigned int year, mon, day, hour, min, sec, real_year;
25 unsigned long flags;
26
27 spin_lock_irqsave(&rtc_lock, flags);
28
29 do {
30 sec = CMOS_READ(RTC_SECONDS);
31 min = CMOS_READ(RTC_MINUTES);
32 hour = CMOS_READ(RTC_HOURS);
33 day = CMOS_READ(RTC_DAY_OF_MONTH);
34 mon = CMOS_READ(RTC_MONTH);
35 year = CMOS_READ(RTC_YEAR);
36
37
38
39
40
41 real_year = CMOS_READ(RTC_DEC_YEAR);
42 } while (sec != CMOS_READ(RTC_SECONDS));
43
44 spin_unlock_irqrestore(&rtc_lock, flags);
45
46 if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
47 sec = bcd2bin(sec);
48 min = bcd2bin(min);
49 hour = bcd2bin(hour);
50 day = bcd2bin(day);
51 mon = bcd2bin(mon);
52 year = bcd2bin(year);
53 }
54
55 year += real_year - 72 + 2000;
56
57 ts->tv_sec = mktime64(year, mon, day, hour, min, sec);
58 ts->tv_nsec = 0;
59 }
60
61
62
63
64
65
66
67
68 int update_persistent_clock64(struct timespec64 now)
69 {
70 time64_t nowtime = now.tv_sec;
71 int retval = 0;
72 int real_seconds, real_minutes, cmos_minutes;
73 unsigned char save_control, save_freq_select;
74
75
76 spin_lock(&rtc_lock);
77
78 save_control = CMOS_READ(RTC_CONTROL);
79 CMOS_WRITE((save_control | RTC_SET), RTC_CONTROL);
80
81
82 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
83 CMOS_WRITE((save_freq_select | RTC_DIV_RESET2), RTC_FREQ_SELECT);
84
85 cmos_minutes = CMOS_READ(RTC_MINUTES);
86 if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
87 cmos_minutes = bcd2bin(cmos_minutes);
88
89
90
91
92
93
94
95 real_minutes = div_s64_rem(nowtime, 60, &real_seconds);
96 if (((abs(real_minutes - cmos_minutes) + 15) / 30) & 1)
97 real_minutes += 30;
98 real_minutes %= 60;
99
100 if (abs(real_minutes - cmos_minutes) < 30) {
101 if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
102 real_seconds = bin2bcd(real_seconds);
103 real_minutes = bin2bcd(real_minutes);
104 }
105 CMOS_WRITE(real_seconds, RTC_SECONDS);
106 CMOS_WRITE(real_minutes, RTC_MINUTES);
107 } else {
108 printk_once(KERN_NOTICE
109 "set_rtc_mmss: can't update from %d to %d\n",
110 cmos_minutes, real_minutes);
111 retval = -1;
112 }
113
114
115
116
117
118
119
120 CMOS_WRITE(save_control, RTC_CONTROL);
121 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
122 spin_unlock(&rtc_lock);
123
124 return retval;
125 }
126
127 void __init plat_time_init(void)
128 {
129 int ioasic_clock = 0;
130 u32 start, end;
131 int i = HZ / 8;
132
133
134 ds1287_set_base_clock(HZ);
135
136
137 if (IOASIC)
138 ioasic_clock = dec_ioasic_clocksource_init() == 0;
139 if (cpu_has_counter) {
140 ds1287_timer_state();
141 while (!ds1287_timer_state())
142 ;
143
144 start = read_c0_count();
145
146 while (i--)
147 while (!ds1287_timer_state())
148 ;
149
150 end = read_c0_count();
151
152 mips_hpt_frequency = (end - start) * 8;
153 printk(KERN_INFO "MIPS counter frequency %dHz\n",
154 mips_hpt_frequency);
155
156
157
158
159
160
161
162
163
164
165 if (!ioasic_clock) {
166 init_r4k_clocksource();
167 mips_hpt_frequency = 0;
168 }
169 }
170
171 ds1287_clockevent_init(dec_interrupt[DEC_IRQ_RTC]);
172 }