Commit b73a19e1609d0f705cbab8014ca17aefe89e4c76

Authored by Yuri Tikhonov
Committed by Wolfgang Denk
1 parent 23e20aa648

LWMON5: POST RTC fix

Modify the RTC API to provide one a status for the time reported by
the rtc_get() function:
  0 - a reliable time is guaranteed,
< 0 - a reliable time isn't guaranteed (power fault, clock issues,
      and so on).

The RTC chip drivers are responsible for providing this info if the
corresponding chip supports such functionality. If not - always
report that the time is reliable.

The POST RTC test was modified to detect the RTC faults utilizing
this new rtc_get() feature.

Signed-off-by: Yuri Tikhonov <yur@emcraft.com>

Showing 34 changed files with 146 additions and 45 deletions Side-by-side Diff

... ... @@ -278,7 +278,7 @@
278 278 /*
279 279 * U-Boot RTC support.
280 280 */
281   -void
  281 +int
282 282 rtc_get( struct rtc_time *tmp )
283 283 {
284 284 m48_tod_get(&tmp->tm_year,
... ... @@ -295,6 +295,8 @@
295 295 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
296 296 tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
297 297 #endif
  298 +
  299 + return 0;
298 300 }
299 301  
300 302 void
... ... @@ -170,9 +170,9 @@
170 170  
171 171 /* ------------------------------------------------------------------------- */
172 172 /* stubs so we can print dates w/o any nvram RTC.*/
173   -void rtc_get (struct rtc_time *tmp)
  173 +int rtc_get (struct rtc_time *tmp)
174 174 {
175   - return;
  175 + return 0;
176 176 }
177 177 void rtc_set (struct rtc_time *tmp)
178 178 {
board/etin/debris/phantom.c
... ... @@ -182,7 +182,7 @@
182 182 return flag;
183 183 }
184 184  
185   -void rtc_get( struct rtc_time *tmp)
  185 +int rtc_get( struct rtc_time *tmp)
186 186 {
187 187 if (phantom_flag < 0)
188 188 phantom_flag = get_phantom_flag();
... ... @@ -250,6 +250,8 @@
250 250 tmp->tm_yday = 0;
251 251 tmp->tm_isdst= 0;
252 252 }
  253 +
  254 + return 0;
253 255 }
254 256  
255 257 void rtc_set( struct rtc_time *tmp )
board/mousse/m48t59y.c
... ... @@ -278,7 +278,7 @@
278 278 /*
279 279 * U-Boot RTC support.
280 280 */
281   -void
  281 +int
282 282 rtc_get( struct rtc_time *tmp )
283 283 {
284 284 m48_tod_get(&tmp->tm_year,
... ... @@ -295,6 +295,8 @@
295 295 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
296 296 tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
297 297 #endif
  298 +
  299 + return 0;
298 300 }
299 301  
300 302 void
... ... @@ -155,7 +155,7 @@
155 155 #define HEX2BCD(x) ((((x) / 10) << 4) + (x) % 10)
156 156 #endif
157 157  
158   -void rtc_get (struct rtc_time* tm)
  158 +int rtc_get (struct rtc_time* tm)
159 159 {
160 160 RTCCON |= 1;
161 161 tm->tm_year = BCD2HEX(BCDYEAR);
... ... @@ -184,6 +184,8 @@
184 184 tm->tm_year += 1900;
185 185 else
186 186 tm->tm_year += 2000;
  187 +
  188 + return 0;
187 189 }
188 190  
189 191 void rtc_set (struct rtc_time* tm)
drivers/rtc/bfin_rtc.c
... ... @@ -85,7 +85,7 @@
85 85 }
86 86  
87 87 /* Read the time from the RTC_STAT. time_in_seconds is seconds since Jan 1970 */
88   -void rtc_get(struct rtc_time *tmp)
  88 +int rtc_get(struct rtc_time *tmp)
89 89 {
90 90 uint32_t cur_rtc_stat;
91 91 int time_in_sec;
... ... @@ -95,7 +95,7 @@
95 95  
96 96 if (tmp == NULL) {
97 97 puts("Error getting the date/time\n");
98   - return;
  98 + return -1;
99 99 }
100 100  
101 101 wait_for_complete();
... ... @@ -112,6 +112,8 @@
112 112 /* Calculate the total number of seconds since epoch */
113 113 time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day);
114 114 to_tm(time_in_sec, tmp);
  115 +
  116 + return 0;
115 117 }
116 118  
117 119 #endif
drivers/rtc/ds12887.c
... ... @@ -88,7 +88,7 @@
88 88  
89 89 /* ------------------------------------------------------------------------- */
90 90  
91   -void rtc_get (struct rtc_time *tmp)
  91 +int rtc_get (struct rtc_time *tmp)
92 92 {
93 93 uchar sec, min, hour, mday, wday, mon, year;
94 94  
... ... @@ -150,6 +150,8 @@
150 150 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
151 151 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
152 152 #endif
  153 +
  154 + return 0;
153 155 }
154 156  
155 157 void rtc_set (struct rtc_time *tmp)
drivers/rtc/ds1302.c
... ... @@ -253,9 +253,10 @@
253 253 /* TODO */
254 254 }
255 255  
256   -void
  256 +int
257 257 rtc_get(struct rtc_time *tmp)
258 258 {
  259 + int rel = 0;
259 260 struct ds1302_st bbclk;
260 261  
261 262 if(!ds1302_initted) rtc_init();
... ... @@ -265,6 +266,7 @@
265 266 if (bbclk.CH) {
266 267 printf("ds1302: rtc_get: Clock was halted, clock probably "
267 268 "corrupt\n");
  269 + rel = -1;
268 270 }
269 271  
270 272 tmp->tm_sec=10*bbclk.sec10+bbclk.sec;
... ... @@ -281,6 +283,8 @@
281 283 DPRINTF("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
282 284 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
283 285 tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
  286 +
  287 + return rel;
284 288 }
285 289  
286 290 void
drivers/rtc/ds1306.c
... ... @@ -91,7 +91,7 @@
91 91 /* ------------------------------------------------------------------------- */
92 92  
93 93 /* read clock time from DS1306 and return it in *tmp */
94   -void rtc_get (struct rtc_time *tmp)
  94 +int rtc_get (struct rtc_time *tmp)
95 95 {
96 96 volatile immap_t *immap = (immap_t *) CFG_IMMR;
97 97 unsigned char spi_byte; /* Data Byte */
... ... @@ -141,6 +141,8 @@
141 141 debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
142 142 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
143 143 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  144 +
  145 + return 0;
144 146 }
145 147  
146 148 /* ------------------------------------------------------------------------- */
... ... @@ -304,7 +306,7 @@
304 306 static void rtc_write (unsigned char reg, unsigned char val);
305 307  
306 308 /* read clock time from DS1306 and return it in *tmp */
307   -void rtc_get (struct rtc_time *tmp)
  309 +int rtc_get (struct rtc_time *tmp)
308 310 {
309 311 unsigned char sec, min, hour, mday, wday, mon, year;
310 312  
... ... @@ -349,6 +351,8 @@
349 351 debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
350 352 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
351 353 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  354 +
  355 + return 0;
352 356 }
353 357  
354 358 /* ------------------------------------------------------------------------- */
drivers/rtc/ds1307.c
... ... @@ -83,8 +83,9 @@
83 83 /*
84 84 * Get the current time from the RTC
85 85 */
86   -void rtc_get (struct rtc_time *tmp)
  86 +int rtc_get (struct rtc_time *tmp)
87 87 {
  88 + int rel = 0;
88 89 uchar sec, min, hour, mday, wday, mon, year;
89 90  
90 91 sec = rtc_read (RTC_SEC_REG_ADDR);
... ... @@ -104,6 +105,7 @@
104 105 /* clear the CH flag */
105 106 rtc_write (RTC_SEC_REG_ADDR,
106 107 rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH);
  108 + rel = -1;
107 109 }
108 110  
109 111 tmp->tm_sec = bcd2bin (sec & 0x7F);
... ... @@ -119,6 +121,8 @@
119 121 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
120 122 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
121 123 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  124 +
  125 + return rel;
122 126 }
123 127  
124 128  
drivers/rtc/ds1337.c
... ... @@ -84,8 +84,9 @@
84 84 /*
85 85 * Get the current time from the RTC
86 86 */
87   -void rtc_get (struct rtc_time *tmp)
  87 +int rtc_get (struct rtc_time *tmp)
88 88 {
  89 + int rel = 0;
89 90 uchar sec, min, hour, mday, wday, mon_cent, year, control, status;
90 91  
91 92 control = rtc_read (RTC_CTL_REG_ADDR);
... ... @@ -107,6 +108,7 @@
107 108 /* clear the OSF flag */
108 109 rtc_write (RTC_STAT_REG_ADDR,
109 110 rtc_read (RTC_STAT_REG_ADDR) & ~RTC_STAT_BIT_OSF);
  111 + rel = -1;
110 112 }
111 113  
112 114 tmp->tm_sec = bcd2bin (sec & 0x7F);
... ... @@ -122,6 +124,8 @@
122 124 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
123 125 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
124 126 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  127 +
  128 + return rel;
125 129 }
126 130  
127 131  
drivers/rtc/ds1374.c
... ... @@ -107,8 +107,8 @@
107 107 /*
108 108 * Get the current time from the RTC
109 109 */
110   -void rtc_get (struct rtc_time *tm){
111   -
  110 +int rtc_get (struct rtc_time *tm){
  111 + int rel = 0;
112 112 unsigned long time1, time2;
113 113 unsigned int limit;
114 114 unsigned char tmp;
115 115  
116 116  
117 117  
... ... @@ -138,18 +138,23 @@
138 138  
139 139 if (time1 != time2) {
140 140 printf("can't get consistent time from rtc chip\n");
  141 + rel = -1;
141 142 }
142 143  
143 144 DEBUGR ("Get RTC s since 1.1.1970: %d\n", time1);
144 145  
145 146 to_tm(time1, tm); /* To Gregorian Date */
146 147  
147   - if (rtc_read(RTC_SR_ADDR) & RTC_SR_BIT_OSF)
  148 + if (rtc_read(RTC_SR_ADDR) & RTC_SR_BIT_OSF) {
148 149 printf ("### Warning: RTC oscillator has stopped\n");
  150 + rel = -1;
  151 + }
149 152  
150 153 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
151 154 tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
152 155 tm->tm_hour, tm->tm_min, tm->tm_sec);
  156 +
  157 + return rel;
153 158 }
154 159  
155 160 /*
drivers/rtc/ds1556.c
... ... @@ -69,7 +69,7 @@
69 69  
70 70 /* ------------------------------------------------------------------------- */
71 71  
72   -void rtc_get( struct rtc_time *tmp )
  72 +int rtc_get( struct rtc_time *tmp )
73 73 {
74 74 uchar sec, min, hour;
75 75 uchar mday, wday, mon, year;
... ... @@ -118,6 +118,7 @@
118 118 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
119 119 tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
120 120 #endif
  121 + return 0;
121 122 }
122 123  
123 124 void rtc_set( struct rtc_time *tmp )
drivers/rtc/ds164x.c
... ... @@ -70,7 +70,7 @@
70 70  
71 71 /* ------------------------------------------------------------------------- */
72 72  
73   -void rtc_get( struct rtc_time *tmp )
  73 +int rtc_get( struct rtc_time *tmp )
74 74 {
75 75 uchar sec, min, hour;
76 76 uchar mday, wday, mon, year;
... ... @@ -115,6 +115,8 @@
115 115 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
116 116 tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
117 117 #endif
  118 +
  119 + return 0;
118 120 }
119 121  
120 122 void rtc_set( struct rtc_time *tmp )
drivers/rtc/ds174x.c
... ... @@ -65,7 +65,7 @@
65 65  
66 66 /* ------------------------------------------------------------------------- */
67 67  
68   -void rtc_get( struct rtc_time *tmp )
  68 +int rtc_get( struct rtc_time *tmp )
69 69 {
70 70 uchar sec, min, hour;
71 71 uchar mday, wday, mon, year;
... ... @@ -142,6 +142,8 @@
142 142  
143 143 /* unlock clock registers after read */
144 144 rtc_write( RTC_CONTROLA, ( reg_a & ~RTC_CA_WRITE ));
  145 +
  146 + return 0;
145 147 }
146 148  
147 149 void rtc_reset (void)
drivers/rtc/ds3231.c
... ... @@ -86,8 +86,9 @@
86 86 /*
87 87 * Get the current time from the RTC
88 88 */
89   -void rtc_get (struct rtc_time *tmp)
  89 +int rtc_get (struct rtc_time *tmp)
90 90 {
  91 + int rel = 0;
91 92 uchar sec, min, hour, mday, wday, mon_cent, year, control, status;
92 93  
93 94 control = rtc_read (RTC_CTL_REG_ADDR);
... ... @@ -109,6 +110,7 @@
109 110 /* clear the OSF flag */
110 111 rtc_write (RTC_STAT_REG_ADDR,
111 112 rtc_read (RTC_STAT_REG_ADDR) & ~RTC_STAT_BIT_OSF);
  113 + rel = -1;
112 114 }
113 115  
114 116 tmp->tm_sec = bcd2bin (sec & 0x7F);
... ... @@ -124,6 +126,8 @@
124 126 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
125 127 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
126 128 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  129 +
  130 + return rel;
127 131 }
128 132  
129 133  
drivers/rtc/isl1208.c
... ... @@ -73,8 +73,9 @@
73 73 * Get the current time from the RTC
74 74 */
75 75  
76   -void rtc_get (struct rtc_time *tmp)
  76 +int rtc_get (struct rtc_time *tmp)
77 77 {
  78 + int rel = 0;
78 79 uchar sec, min, hour, mday, wday, mon, year, status;
79 80  
80 81 status = rtc_read (RTC_STAT_REG_ADDR);
... ... @@ -94,6 +95,7 @@
94 95 printf ("### Warning: RTC oscillator has stopped\n");
95 96 rtc_write(RTC_STAT_REG_ADDR,
96 97 rtc_read(RTC_STAT_REG_ADDR) &~ (RTC_STAT_BIT_BAT|RTC_STAT_BIT_RTCF));
  98 + rel = -1;
97 99 }
98 100  
99 101 tmp->tm_sec = bcd2bin (sec & 0x7F);
... ... @@ -109,6 +111,8 @@
109 111 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
110 112 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
111 113 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  114 +
  115 + return rel;
112 116 }
113 117  
114 118 /*
drivers/rtc/m41t11.c
... ... @@ -96,14 +96,16 @@
96 96  
97 97 #define M41T11_STORAGE_SZ (64-REG_CNT)
98 98  
99   -void rtc_get (struct rtc_time *tmp)
  99 +int rtc_get (struct rtc_time *tmp)
100 100 {
  101 + int rel = 0;
101 102 uchar data[RTC_REG_CNT];
102 103  
103 104 i2c_read(CFG_I2C_RTC_ADDR, RTC_SEC_ADDR, 1, data, RTC_REG_CNT);
104 105  
105 106 if( data[RTC_SEC_ADDR] & 0x80 ){
106 107 printf( "m41t11 RTC Clock stopped!!!\n" );
  108 + rel = -1;
107 109 }
108 110 tmp->tm_sec = bcd2bin (data[RTC_SEC_ADDR] & 0x7F);
109 111 tmp->tm_min = bcd2bin (data[RTC_MIN_ADDR] & 0x7F);
... ... @@ -120,6 +122,7 @@
120 122 i2c_read(CFG_I2C_RTC_ADDR, M41T11_YEAR_DATA, 1, &cent, M41T11_YEAR_SIZE);
121 123 if( !(data[RTC_HOUR_ADDR] & 0x80) ){
122 124 printf( "m41t11 RTC: cann't keep track of years without CEB set\n" );
  125 + rel = -1;
123 126 }
124 127 if( (cent & 0x1) != ((data[RTC_HOUR_ADDR]&0x40)>>7) ){
125 128 /*century flip store off new year*/
... ... @@ -136,6 +139,8 @@
136 139 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
137 140 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
138 141 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  142 +
  143 + return rel;
139 144 }
140 145  
141 146 void rtc_set (struct rtc_time *tmp)
drivers/rtc/m41t60.c
... ... @@ -170,12 +170,12 @@
170 170 return data;
171 171 }
172 172  
173   -void rtc_get(struct rtc_time *tmp)
  173 +int rtc_get(struct rtc_time *tmp)
174 174 {
175 175 uchar const *const data = rtc_validate();
176 176  
177 177 if (!data)
178   - return;
  178 + return -1;
179 179  
180 180 tmp->tm_sec = bcd2bin(data[RTC_SEC] & 0x7F);
181 181 tmp->tm_min = bcd2bin(data[RTC_MIN] & 0x7F);
... ... @@ -190,6 +190,8 @@
190 190 debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
191 191 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
192 192 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  193 +
  194 + return 0;
193 195 }
194 196  
195 197 void rtc_set(struct rtc_time *tmp)
drivers/rtc/m41t62.c
... ... @@ -64,7 +64,7 @@
64 64 #define M41T62_FEATURE_HT (1 << 0)
65 65 #define M41T62_FEATURE_BL (1 << 1)
66 66  
67   -void rtc_get(struct rtc_time *tm)
  67 +int rtc_get(struct rtc_time *tm)
68 68 {
69 69 u8 buf[M41T62_DATETIME_REG_SIZE];
70 70  
... ... @@ -92,6 +92,8 @@
92 92 __FUNCTION__,
93 93 tm->tm_sec, tm->tm_min, tm->tm_hour,
94 94 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
  95 +
  96 + return 0;
95 97 }
96 98  
97 99 void rtc_set(struct rtc_time *tm)
drivers/rtc/m48t35ax.c
... ... @@ -42,7 +42,7 @@
42 42  
43 43 /* ------------------------------------------------------------------------- */
44 44  
45   -void rtc_get (struct rtc_time *tmp)
  45 +int rtc_get (struct rtc_time *tmp)
46 46 {
47 47 uchar sec, min, hour, cent_day, date, month, year;
48 48 uchar ccr; /* Clock control register */
... ... @@ -83,6 +83,8 @@
83 83 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
84 84 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
85 85 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  86 +
  87 + return 0;
86 88 }
87 89  
88 90 void rtc_set (struct rtc_time *tmp)
drivers/rtc/max6900.c
... ... @@ -63,7 +63,7 @@
63 63  
64 64 /* ------------------------------------------------------------------------- */
65 65  
66   -void rtc_get (struct rtc_time *tmp)
  66 +int rtc_get (struct rtc_time *tmp)
67 67 {
68 68 uchar sec, min, hour, mday, wday, mon, cent, year;
69 69 int retry = 1;
... ... @@ -103,6 +103,8 @@
103 103 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
104 104 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
105 105 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  106 +
  107 + return 0;
106 108 }
107 109  
108 110 void rtc_set (struct rtc_time *tmp)
drivers/rtc/mc146818.c
... ... @@ -57,7 +57,7 @@
57 57  
58 58 /* ------------------------------------------------------------------------- */
59 59  
60   -void rtc_get (struct rtc_time *tmp)
  60 +int rtc_get (struct rtc_time *tmp)
61 61 {
62 62 uchar sec, min, hour, mday, wday, mon, year;
63 63 /* here check if rtc can be accessed */
... ... @@ -101,6 +101,8 @@
101 101 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
102 102 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
103 103 #endif
  104 +
  105 + return 0;
104 106 }
105 107  
106 108 void rtc_set (struct rtc_time *tmp)
drivers/rtc/mcfrtc.c
... ... @@ -39,7 +39,7 @@
39 39 #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
40 40 #define STARTOFTIME 1970
41 41  
42   -void rtc_get(struct rtc_time *tmp)
  42 +int rtc_get(struct rtc_time *tmp)
43 43 {
44 44 volatile rtc_t *rtc = (rtc_t *) (CFG_MCFRTC_BASE);
45 45  
... ... @@ -64,6 +64,8 @@
64 64 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
65 65 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
66 66 #endif
  67 +
  68 + return 0;
67 69 }
68 70  
69 71 void rtc_set(struct rtc_time *tmp)
drivers/rtc/mk48t59.c
... ... @@ -135,7 +135,7 @@
135 135  
136 136 /* ------------------------------------------------------------------------- */
137 137  
138   -void rtc_get (struct rtc_time *tmp)
  138 +int rtc_get (struct rtc_time *tmp)
139 139 {
140 140 uchar save_ctrl_a;
141 141 uchar sec, min, hour, mday, wday, mon, year;
... ... @@ -183,6 +183,8 @@
183 183 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
184 184 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
185 185 #endif
  186 +
  187 + return 0;
186 188 }
187 189  
188 190 void rtc_set (struct rtc_time *tmp)
drivers/rtc/mpc5xxx.c
... ... @@ -55,7 +55,7 @@
55 55 /*****************************************************************************
56 56 * get time
57 57 *****************************************************************************/
58   -void rtc_get (struct rtc_time *tmp)
  58 +int rtc_get (struct rtc_time *tmp)
59 59 {
60 60 RTC5200 *rtc = (RTC5200 *) (CFG_MBAR+0x800);
61 61 ulong time, date, time2;
... ... @@ -81,6 +81,8 @@
81 81 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
82 82 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
83 83 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  84 +
  85 + return 0;
84 86 }
85 87  
86 88 /*****************************************************************************
drivers/rtc/mpc8xx.c
... ... @@ -35,7 +35,7 @@
35 35  
36 36 /* ------------------------------------------------------------------------- */
37 37  
38   -void rtc_get (struct rtc_time *tmp)
  38 +int rtc_get (struct rtc_time *tmp)
39 39 {
40 40 volatile immap_t *immr = (immap_t *)CFG_IMMR;
41 41 ulong tim;
... ... @@ -47,6 +47,8 @@
47 47 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
48 48 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
49 49 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  50 +
  51 + return 0;
50 52 }
51 53  
52 54 void rtc_set (struct rtc_time *tmp)
drivers/rtc/pcf8563.c
... ... @@ -41,8 +41,9 @@
41 41  
42 42 /* ------------------------------------------------------------------------- */
43 43  
44   -void rtc_get (struct rtc_time *tmp)
  44 +int rtc_get (struct rtc_time *tmp)
45 45 {
  46 + int rel = 0;
46 47 uchar sec, min, hour, mday, wday, mon_cent, year;
47 48  
48 49 sec = rtc_read (0x02);
... ... @@ -65,6 +66,7 @@
65 66  
66 67 if (sec & 0x80) {
67 68 puts ("### Warning: RTC Low Voltage - date/time not reliable\n");
  69 + rel = -1;
68 70 }
69 71  
70 72 tmp->tm_sec = bcd2bin (sec & 0x7F);
... ... @@ -80,6 +82,8 @@
80 82 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
81 83 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
82 84 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  85 +
  86 + return rel;
83 87 }
84 88  
85 89 void rtc_set (struct rtc_time *tmp)
drivers/rtc/rs5c372.c
... ... @@ -166,7 +166,7 @@
166 166 /*
167 167 * Get the current time from the RTC
168 168 */
169   -void
  169 +int
170 170 rtc_get (struct rtc_time *tmp)
171 171 {
172 172 unsigned char buf[RS5C372_RAM_SIZE];
... ... @@ -176,7 +176,7 @@
176 176 rs5c372_enable();
177 177  
178 178 if (!setup_done)
179   - return;
  179 + return -1;
180 180  
181 181 memset(buf, 0, sizeof(buf));
182 182  
183 183  
... ... @@ -184,12 +184,12 @@
184 184 ret = rs5c372_readram(buf, RS5C372_RAM_SIZE);
185 185 if (ret != 0) {
186 186 printf("%s: failed\n", __FUNCTION__);
187   - return;
  187 + return -1;
188 188 }
189 189  
190 190 rs5c372_convert_to_time(tmp, buf);
191 191  
192   - return;
  192 + return 0;
193 193 }
194 194  
195 195 /*
drivers/rtc/rx8025.c
... ... @@ -96,8 +96,9 @@
96 96 /*
97 97 * Get the current time from the RTC
98 98 */
99   -void rtc_get (struct rtc_time *tmp)
  99 +int rtc_get (struct rtc_time *tmp)
100 100 {
  101 + int rel = 0;
101 102 uchar sec, min, hour, mday, wday, mon, year, ctl2;
102 103 uchar buf[16];
103 104  
104 105  
105 106  
106 107  
107 108  
108 109  
... ... @@ -118,14 +119,20 @@
118 119  
119 120 /* dump status */
120 121 ctl2 = rtc_read(RTC_CTL2_REG_ADDR);
121   - if (ctl2 & RTC_CTL2_BIT_PON)
  122 + if (ctl2 & RTC_CTL2_BIT_PON) {
122 123 printf("RTC: power-on detected\n");
  124 + rel = -1;
  125 + }
123 126  
124   - if (ctl2 & RTC_CTL2_BIT_VDET)
  127 + if (ctl2 & RTC_CTL2_BIT_VDET) {
125 128 printf("RTC: voltage drop detected\n");
  129 + rel = -1;
  130 + }
126 131  
127   - if (!(ctl2 & RTC_CTL2_BIT_XST))
  132 + if (!(ctl2 & RTC_CTL2_BIT_XST)) {
128 133 printf("RTC: oscillator stop detected\n");
  134 + rel = -1;
  135 + }
129 136  
130 137 tmp->tm_sec = bcd2bin (sec & 0x7F);
131 138 tmp->tm_min = bcd2bin (min & 0x7F);
... ... @@ -140,6 +147,8 @@
140 147 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
141 148 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
142 149 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  150 +
  151 + return rel;
143 152 }
144 153  
145 154 /*
drivers/rtc/s3c24x0_rtc.c
... ... @@ -70,7 +70,7 @@
70 70  
71 71 /* ------------------------------------------------------------------------- */
72 72  
73   -void rtc_get (struct rtc_time *tmp)
  73 +int rtc_get (struct rtc_time *tmp)
74 74 {
75 75 S3C24X0_RTC * const rtc = S3C24X0_GetBase_RTC();
76 76 uchar sec, min, hour, mday, wday, mon, year;
... ... @@ -131,6 +131,8 @@
131 131 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
132 132 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
133 133 #endif
  134 +
  135 + return 0;
134 136 }
135 137  
136 138 void rtc_set (struct rtc_time *tmp)
... ... @@ -104,7 +104,7 @@
104 104 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
105 105 * Epoch is initialized as 2000. Time is set to UTC.
106 106 */
107   -void rtc_get(struct rtc_time *tm)
  107 +int rtc_get(struct rtc_time *tm)
108 108 {
109 109 u8 buf[8];
110 110  
... ... @@ -130,6 +130,8 @@
130 130 __FUNCTION__,
131 131 tm->tm_sec, tm->tm_min, tm->tm_hour,
132 132 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
  133 +
  134 + return 0;
133 135 }
134 136  
135 137 void rtc_set(struct rtc_time *tm)
... ... @@ -52,7 +52,7 @@
52 52 int tm_isdst;
53 53 };
54 54  
55   -void rtc_get (struct rtc_time *);
  55 +int rtc_get (struct rtc_time *);
56 56 void rtc_set (struct rtc_time *);
57 57 void rtc_reset (void);
58 58  
... ... @@ -28,6 +28,8 @@
28 28 *
29 29 * The Real Time Clock (RTC) operation is verified by this test.
30 30 * The following features are verified:
  31 + * o) RTC Power Fault
  32 + * This is verified by analyzing the rtc_get() return status.
31 33 * o) Time uniformity
32 34 * This is verified by reading RTC in polling within
33 35 * a short period of time.
34 36  
... ... @@ -96,7 +98,11 @@
96 98 unsigned int ynl = 1999;
97 99 unsigned int yl = 2000;
98 100 unsigned int skipped = 0;
  101 + int reliable;
99 102  
  103 + /* Time reliability */
  104 + reliable = rtc_get (&svtm);
  105 +
100 106 /* Time uniformity */
101 107 if (rtc_post_skip (&diff) != 0) {
102 108 post_log ("Timeout while waiting for a new second !\n");
... ... @@ -175,6 +181,15 @@
175 181 }
176 182 }
177 183 rtc_post_restore (&svtm, skipped);
  184 +
  185 + /* If come here, then RTC operates correcty, check the correctness
  186 + * of the time it reports.
  187 + */
  188 + if (reliable < 0) {
  189 + post_log ("RTC Time is not reliable! Power fault? \n");
  190 +
  191 + return -1;
  192 + }
178 193  
179 194 return 0;
180 195 }