aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-mips
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-mips')
-rw-r--r--include/asm-mips/mc146818-time.h24
-rw-r--r--include/asm-mips/time.h3
2 files changed, 25 insertions, 2 deletions
diff --git a/include/asm-mips/mc146818-time.h b/include/asm-mips/mc146818-time.h
index a2c2d2c24303..47214861093b 100644
--- a/include/asm-mips/mc146818-time.h
+++ b/include/asm-mips/mc146818-time.h
@@ -33,7 +33,9 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime)
33 int real_seconds, real_minutes, cmos_minutes; 33 int real_seconds, real_minutes, cmos_minutes;
34 unsigned char save_control, save_freq_select; 34 unsigned char save_control, save_freq_select;
35 int retval = 0; 35 int retval = 0;
36 unsigned long flags;
36 37
38 spin_lock_irqsave(&rtc_lock, flags);
37 save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */ 39 save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */
38 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); 40 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
39 41
@@ -79,14 +81,30 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime)
79 */ 81 */
80 CMOS_WRITE(save_control, RTC_CONTROL); 82 CMOS_WRITE(save_control, RTC_CONTROL);
81 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); 83 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
84 spin_unlock_irqrestore(&rtc_lock, flags);
82 85
83 return retval; 86 return retval;
84} 87}
85 88
89/*
90 * Returns true if a clock update is in progress
91 */
92static inline unsigned char rtc_is_updating(void)
93{
94 unsigned char uip;
95 unsigned long flags;
96
97 spin_lock_irqsave(&rtc_lock, flags);
98 uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
99 spin_unlock_irqrestore(&rtc_lock, flags);
100 return uip;
101}
102
86static inline unsigned long mc146818_get_cmos_time(void) 103static inline unsigned long mc146818_get_cmos_time(void)
87{ 104{
88 unsigned int year, mon, day, hour, min, sec; 105 unsigned int year, mon, day, hour, min, sec;
89 int i; 106 int i;
107 unsigned long flags;
90 108
91 /* 109 /*
92 * The Linux interpretation of the CMOS clock register contents: 110 * The Linux interpretation of the CMOS clock register contents:
@@ -97,12 +115,13 @@ static inline unsigned long mc146818_get_cmos_time(void)
97 115
98 /* read RTC exactly on falling edge of update flag */ 116 /* read RTC exactly on falling edge of update flag */
99 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ 117 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */
100 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) 118 if (rtc_is_updating())
101 break; 119 break;
102 for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */ 120 for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */
103 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)) 121 if (!rtc_is_updating())
104 break; 122 break;
105 123
124 spin_lock_irqsave(&rtc_lock, flags);
106 do { /* Isn't this overkill ? UIP above should guarantee consistency */ 125 do { /* Isn't this overkill ? UIP above should guarantee consistency */
107 sec = CMOS_READ(RTC_SECONDS); 126 sec = CMOS_READ(RTC_SECONDS);
108 min = CMOS_READ(RTC_MINUTES); 127 min = CMOS_READ(RTC_MINUTES);
@@ -120,6 +139,7 @@ static inline unsigned long mc146818_get_cmos_time(void)
120 BCD_TO_BIN(mon); 139 BCD_TO_BIN(mon);
121 BCD_TO_BIN(year); 140 BCD_TO_BIN(year);
122 } 141 }
142 spin_unlock_irqrestore(&rtc_lock, flags);
123 year = mc146818_decode_year(year); 143 year = mc146818_decode_year(year);
124 144
125 return mktime(year, mon, day, hour, min, sec); 145 return mktime(year, mon, day, hour, min, sec);
diff --git a/include/asm-mips/time.h b/include/asm-mips/time.h
index e22a20665871..9cc3564cc2c9 100644
--- a/include/asm-mips/time.h
+++ b/include/asm-mips/time.h
@@ -20,6 +20,9 @@
20#include <linux/linkage.h> 20#include <linux/linkage.h>
21#include <linux/ptrace.h> 21#include <linux/ptrace.h>
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/spinlock.h>
24
25extern spinlock_t rtc_lock;
23 26
24/* 27/*
25 * RTC ops. By default, they point to no-RTC functions. 28 * RTC ops. By default, they point to no-RTC functions.