[U-Boot-Users] [PATCH] LWMON5: POST RTC fix
Wolfgang Denk
wd at denx.de
Thu Mar 20 21:51:06 CET 2008
From: Yuri Tikhonov <yur at emcraft.com>
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 at emcraft.com>
---
board/bmw/m48t59y.c | 4 +++-
board/cray/L1/L1.c | 4 ++--
board/etin/debris/phantom.c | 4 +++-
board/mousse/m48t59y.c | 4 +++-
cpu/s3c44b0/cpu.c | 4 +++-
drivers/rtc/bfin_rtc.c | 6 ++++--
drivers/rtc/ds12887.c | 4 +++-
drivers/rtc/ds1302.c | 6 +++++-
drivers/rtc/ds1306.c | 8 ++++++--
drivers/rtc/ds1307.c | 6 +++++-
drivers/rtc/ds1337.c | 6 +++++-
drivers/rtc/ds1374.c | 11 ++++++++---
drivers/rtc/ds1556.c | 3 ++-
drivers/rtc/ds164x.c | 4 +++-
drivers/rtc/ds174x.c | 4 +++-
drivers/rtc/ds3231.c | 6 +++++-
drivers/rtc/isl1208.c | 6 +++++-
drivers/rtc/m41t11.c | 7 ++++++-
drivers/rtc/m41t60.c | 6 ++++--
drivers/rtc/m41t62.c | 4 +++-
drivers/rtc/m48t35ax.c | 4 +++-
drivers/rtc/max6900.c | 4 +++-
drivers/rtc/mc146818.c | 4 +++-
drivers/rtc/mcfrtc.c | 4 +++-
drivers/rtc/mk48t59.c | 4 +++-
drivers/rtc/mpc5xxx.c | 4 +++-
drivers/rtc/mpc8xx.c | 4 +++-
drivers/rtc/pcf8563.c | 6 +++++-
drivers/rtc/rs5c372.c | 8 ++++----
drivers/rtc/rx8025.c | 17 +++++++++++++----
drivers/rtc/s3c24x0_rtc.c | 4 +++-
drivers/rtc/x1205.c | 4 +++-
include/rtc.h | 2 +-
post/drivers/rtc.c | 15 +++++++++++++++
34 files changed, 146 insertions(+), 45 deletions(-)
diff --git a/board/bmw/m48t59y.c b/board/bmw/m48t59y.c
index d72c861..a1a85d0 100644
--- a/board/bmw/m48t59y.c
+++ b/board/bmw/m48t59y.c
@@ -278,7 +278,7 @@ void m48_watchdog_arm(int usec)
/*
* U-Boot RTC support.
*/
-void
+int
rtc_get( struct rtc_time *tmp )
{
m48_tod_get(&tmp->tm_year,
@@ -295,6 +295,8 @@ rtc_get( struct rtc_time *tmp )
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
#endif
+
+ return 0;
}
void
diff --git a/board/cray/L1/L1.c b/board/cray/L1/L1.c
index a0fac7f..5264baf 100644
--- a/board/cray/L1/L1.c
+++ b/board/cray/L1/L1.c
@@ -170,9 +170,9 @@ long int initdram (int board_type)
/* ------------------------------------------------------------------------- */
/* stubs so we can print dates w/o any nvram RTC.*/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
- return;
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
{
diff --git a/board/etin/debris/phantom.c b/board/etin/debris/phantom.c
index 18ab500..263da6b 100644
--- a/board/etin/debris/phantom.c
+++ b/board/etin/debris/phantom.c
@@ -182,7 +182,7 @@ static int get_century_flag(void)
return flag;
}
-void rtc_get( struct rtc_time *tmp)
+int rtc_get( struct rtc_time *tmp)
{
if (phantom_flag < 0)
phantom_flag = get_phantom_flag();
@@ -250,6 +250,8 @@ void rtc_get( struct rtc_time *tmp)
tmp->tm_yday = 0;
tmp->tm_isdst= 0;
}
+
+ return 0;
}
void rtc_set( struct rtc_time *tmp )
diff --git a/board/mousse/m48t59y.c b/board/mousse/m48t59y.c
index 37a6244..2c1e6cf 100644
--- a/board/mousse/m48t59y.c
+++ b/board/mousse/m48t59y.c
@@ -278,7 +278,7 @@ void m48_watchdog_arm(int usec)
/*
* U-Boot RTC support.
*/
-void
+int
rtc_get( struct rtc_time *tmp )
{
m48_tod_get(&tmp->tm_year,
@@ -295,6 +295,8 @@ rtc_get( struct rtc_time *tmp )
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
#endif
+
+ return 0;
}
void
diff --git a/cpu/s3c44b0/cpu.c b/cpu/s3c44b0/cpu.c
index 5d50b3c..eae6adb 100644
--- a/cpu/s3c44b0/cpu.c
+++ b/cpu/s3c44b0/cpu.c
@@ -155,7 +155,7 @@ int dcache_status (void)
#define HEX2BCD(x) ((((x) / 10) << 4) + (x) % 10)
#endif
-void rtc_get (struct rtc_time* tm)
+int rtc_get (struct rtc_time* tm)
{
RTCCON |= 1;
tm->tm_year = BCD2HEX(BCDYEAR);
@@ -184,6 +184,8 @@ void rtc_get (struct rtc_time* tm)
tm->tm_year += 1900;
else
tm->tm_year += 2000;
+
+ return 0;
}
void rtc_set (struct rtc_time* tm)
diff --git a/drivers/rtc/bfin_rtc.c b/drivers/rtc/bfin_rtc.c
index 5755a20..ce4f171 100644
--- a/drivers/rtc/bfin_rtc.c
+++ b/drivers/rtc/bfin_rtc.c
@@ -85,7 +85,7 @@ void rtc_set(struct rtc_time *tmp)
}
/* Read the time from the RTC_STAT. time_in_seconds is seconds since Jan 1970 */
-void rtc_get(struct rtc_time *tmp)
+int rtc_get(struct rtc_time *tmp)
{
uint32_t cur_rtc_stat;
int time_in_sec;
@@ -95,7 +95,7 @@ void rtc_get(struct rtc_time *tmp)
if (tmp == NULL) {
puts("Error getting the date/time\n");
- return;
+ return -1;
}
wait_for_complete();
@@ -112,6 +112,8 @@ void rtc_get(struct rtc_time *tmp)
/* Calculate the total number of seconds since epoch */
time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day);
to_tm(time_in_sec, tmp);
+
+ return 0;
}
#endif
diff --git a/drivers/rtc/ds12887.c b/drivers/rtc/ds12887.c
index 84fecf0..57a446d 100644
--- a/drivers/rtc/ds12887.c
+++ b/drivers/rtc/ds12887.c
@@ -88,7 +88,7 @@ static unsigned char bin2bcd (unsigned int n)
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
uchar sec, min, hour, mday, wday, mon, year;
@@ -150,6 +150,8 @@ else
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/ds1302.c b/drivers/rtc/ds1302.c
index 55af130..3a856c8 100644
--- a/drivers/rtc/ds1302.c
+++ b/drivers/rtc/ds1302.c
@@ -253,9 +253,10 @@ rtc_reset(void)
/* TODO */
}
-void
+int
rtc_get(struct rtc_time *tmp)
{
+ int rel = 0;
struct ds1302_st bbclk;
if(!ds1302_initted) rtc_init();
@@ -265,6 +266,7 @@ rtc_get(struct rtc_time *tmp)
if (bbclk.CH) {
printf("ds1302: rtc_get: Clock was halted, clock probably "
"corrupt\n");
+ rel = -1;
}
tmp->tm_sec=10*bbclk.sec10+bbclk.sec;
@@ -281,6 +283,8 @@ rtc_get(struct rtc_time *tmp)
DPRINTF("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
+
+ return rel;
}
void
diff --git a/drivers/rtc/ds1306.c b/drivers/rtc/ds1306.c
index 89e433d..1c8ac7f 100644
--- a/drivers/rtc/ds1306.c
+++ b/drivers/rtc/ds1306.c
@@ -91,7 +91,7 @@ static void init_spi (void);
/* ------------------------------------------------------------------------- */
/* read clock time from DS1306 and return it in *tmp */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
volatile immap_t *immap = (immap_t *) CFG_IMMR;
unsigned char spi_byte; /* Data Byte */
@@ -141,6 +141,8 @@ void rtc_get (struct rtc_time *tmp)
debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
/* ------------------------------------------------------------------------- */
@@ -304,7 +306,7 @@ static unsigned char rtc_read (unsigned char reg);
static void rtc_write (unsigned char reg, unsigned char val);
/* read clock time from DS1306 and return it in *tmp */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
unsigned char sec, min, hour, mday, wday, mon, year;
@@ -349,6 +351,8 @@ void rtc_get (struct rtc_time *tmp)
debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
/* ------------------------------------------------------------------------- */
diff --git a/drivers/rtc/ds1307.c b/drivers/rtc/ds1307.c
index c882d79..b20f193 100644
--- a/drivers/rtc/ds1307.c
+++ b/drivers/rtc/ds1307.c
@@ -83,8 +83,9 @@ static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
*/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar sec, min, hour, mday, wday, mon, year;
sec = rtc_read (RTC_SEC_REG_ADDR);
@@ -104,6 +105,7 @@ void rtc_get (struct rtc_time *tmp)
/* clear the CH flag */
rtc_write (RTC_SEC_REG_ADDR,
rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH);
+ rel = -1;
}
tmp->tm_sec = bcd2bin (sec & 0x7F);
@@ -119,6 +121,8 @@ void rtc_get (struct rtc_time *tmp)
DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
diff --git a/drivers/rtc/ds1337.c b/drivers/rtc/ds1337.c
index c636ac5..50ab446 100644
--- a/drivers/rtc/ds1337.c
+++ b/drivers/rtc/ds1337.c
@@ -84,8 +84,9 @@ static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
*/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar sec, min, hour, mday, wday, mon_cent, year, control, status;
control = rtc_read (RTC_CTL_REG_ADDR);
@@ -107,6 +108,7 @@ void rtc_get (struct rtc_time *tmp)
/* clear the OSF flag */
rtc_write (RTC_STAT_REG_ADDR,
rtc_read (RTC_STAT_REG_ADDR) & ~RTC_STAT_BIT_OSF);
+ rel = -1;
}
tmp->tm_sec = bcd2bin (sec & 0x7F);
@@ -122,6 +124,8 @@ void rtc_get (struct rtc_time *tmp)
DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
diff --git a/drivers/rtc/ds1374.c b/drivers/rtc/ds1374.c
index e773dd9..f6bb296 100644
--- a/drivers/rtc/ds1374.c
+++ b/drivers/rtc/ds1374.c
@@ -107,8 +107,8 @@ static void rtc_write_raw (uchar reg, uchar val);
/*
* Get the current time from the RTC
*/
-void rtc_get (struct rtc_time *tm){
-
+int rtc_get (struct rtc_time *tm){
+ int rel = 0;
unsigned long time1, time2;
unsigned int limit;
unsigned char tmp;
@@ -138,18 +138,23 @@ void rtc_get (struct rtc_time *tm){
if (time1 != time2) {
printf("can't get consistent time from rtc chip\n");
+ rel = -1;
}
DEBUGR ("Get RTC s since 1.1.1970: %d\n", time1);
to_tm(time1, tm); /* To Gregorian Date */
- if (rtc_read(RTC_SR_ADDR) & RTC_SR_BIT_OSF)
+ if (rtc_read(RTC_SR_ADDR) & RTC_SR_BIT_OSF) {
printf ("### Warning: RTC oscillator has stopped\n");
+ rel = -1;
+ }
DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ return rel;
}
/*
diff --git a/drivers/rtc/ds1556.c b/drivers/rtc/ds1556.c
index 4365cfb..2c496f5 100644
--- a/drivers/rtc/ds1556.c
+++ b/drivers/rtc/ds1556.c
@@ -69,7 +69,7 @@ static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
-void rtc_get( struct rtc_time *tmp )
+int rtc_get( struct rtc_time *tmp )
{
uchar sec, min, hour;
uchar mday, wday, mon, year;
@@ -118,6 +118,7 @@ void rtc_get( struct rtc_time *tmp )
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
#endif
+ return 0;
}
void rtc_set( struct rtc_time *tmp )
diff --git a/drivers/rtc/ds164x.c b/drivers/rtc/ds164x.c
index bff22b9..5943f87 100644
--- a/drivers/rtc/ds164x.c
+++ b/drivers/rtc/ds164x.c
@@ -70,7 +70,7 @@ static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
-void rtc_get( struct rtc_time *tmp )
+int rtc_get( struct rtc_time *tmp )
{
uchar sec, min, hour;
uchar mday, wday, mon, year;
@@ -115,6 +115,8 @@ void rtc_get( struct rtc_time *tmp )
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec );
#endif
+
+ return 0;
}
void rtc_set( struct rtc_time *tmp )
diff --git a/drivers/rtc/ds174x.c b/drivers/rtc/ds174x.c
index 5f85a68..81a9cb3 100644
--- a/drivers/rtc/ds174x.c
+++ b/drivers/rtc/ds174x.c
@@ -65,7 +65,7 @@ static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
-void rtc_get( struct rtc_time *tmp )
+int rtc_get( struct rtc_time *tmp )
{
uchar sec, min, hour;
uchar mday, wday, mon, year;
@@ -142,6 +142,8 @@ void rtc_set( struct rtc_time *tmp )
/* unlock clock registers after read */
rtc_write( RTC_CONTROLA, ( reg_a & ~RTC_CA_WRITE ));
+
+ return 0;
}
void rtc_reset (void)
diff --git a/drivers/rtc/ds3231.c b/drivers/rtc/ds3231.c
index fe11b86..95cb186 100644
--- a/drivers/rtc/ds3231.c
+++ b/drivers/rtc/ds3231.c
@@ -86,8 +86,9 @@ static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
*/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar sec, min, hour, mday, wday, mon_cent, year, control, status;
control = rtc_read (RTC_CTL_REG_ADDR);
@@ -109,6 +110,7 @@ void rtc_get (struct rtc_time *tmp)
/* clear the OSF flag */
rtc_write (RTC_STAT_REG_ADDR,
rtc_read (RTC_STAT_REG_ADDR) & ~RTC_STAT_BIT_OSF);
+ rel = -1;
}
tmp->tm_sec = bcd2bin (sec & 0x7F);
@@ -124,6 +126,8 @@ void rtc_get (struct rtc_time *tmp)
DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
diff --git a/drivers/rtc/isl1208.c b/drivers/rtc/isl1208.c
index d872802..3d46fd0 100644
--- a/drivers/rtc/isl1208.c
+++ b/drivers/rtc/isl1208.c
@@ -73,8 +73,9 @@ static unsigned bcd2bin (uchar c);
* Get the current time from the RTC
*/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar sec, min, hour, mday, wday, mon, year, status;
status = rtc_read (RTC_STAT_REG_ADDR);
@@ -94,6 +95,7 @@ void rtc_get (struct rtc_time *tmp)
printf ("### Warning: RTC oscillator has stopped\n");
rtc_write(RTC_STAT_REG_ADDR,
rtc_read(RTC_STAT_REG_ADDR) &~ (RTC_STAT_BIT_BAT|RTC_STAT_BIT_RTCF));
+ rel = -1;
}
tmp->tm_sec = bcd2bin (sec & 0x7F);
@@ -109,6 +111,8 @@ void rtc_get (struct rtc_time *tmp)
DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
/*
diff --git a/drivers/rtc/m41t11.c b/drivers/rtc/m41t11.c
index 81da33a..fce00d9 100644
--- a/drivers/rtc/m41t11.c
+++ b/drivers/rtc/m41t11.c
@@ -96,14 +96,16 @@ static unsigned char bin2bcd (unsigned int n)
#define M41T11_STORAGE_SZ (64-REG_CNT)
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar data[RTC_REG_CNT];
i2c_read(CFG_I2C_RTC_ADDR, RTC_SEC_ADDR, 1, data, RTC_REG_CNT);
if( data[RTC_SEC_ADDR] & 0x80 ){
printf( "m41t11 RTC Clock stopped!!!\n" );
+ rel = -1;
}
tmp->tm_sec = bcd2bin (data[RTC_SEC_ADDR] & 0x7F);
tmp->tm_min = bcd2bin (data[RTC_MIN_ADDR] & 0x7F);
@@ -120,6 +122,7 @@ void rtc_get (struct rtc_time *tmp)
i2c_read(CFG_I2C_RTC_ADDR, M41T11_YEAR_DATA, 1, ¢, M41T11_YEAR_SIZE);
if( !(data[RTC_HOUR_ADDR] & 0x80) ){
printf( "m41t11 RTC: cann't keep track of years without CEB set\n" );
+ rel = -1;
}
if( (cent & 0x1) != ((data[RTC_HOUR_ADDR]&0x40)>>7) ){
/*century flip store off new year*/
@@ -136,6 +139,8 @@ void rtc_get (struct rtc_time *tmp)
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/m41t60.c b/drivers/rtc/m41t60.c
index 7c80143..8a32ea0 100644
--- a/drivers/rtc/m41t60.c
+++ b/drivers/rtc/m41t60.c
@@ -170,12 +170,12 @@ static uchar *rtc_validate(void)
return data;
}
-void rtc_get(struct rtc_time *tmp)
+int rtc_get(struct rtc_time *tmp)
{
uchar const *const data = rtc_validate();
if (!data)
- return;
+ return -1;
tmp->tm_sec = bcd2bin(data[RTC_SEC] & 0x7F);
tmp->tm_min = bcd2bin(data[RTC_MIN] & 0x7F);
@@ -190,6 +190,8 @@ void rtc_get(struct rtc_time *tmp)
debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
void rtc_set(struct rtc_time *tmp)
diff --git a/drivers/rtc/m41t62.c b/drivers/rtc/m41t62.c
index 2bdca3b..cf2a957 100644
--- a/drivers/rtc/m41t62.c
+++ b/drivers/rtc/m41t62.c
@@ -64,7 +64,7 @@
#define M41T62_FEATURE_HT (1 << 0)
#define M41T62_FEATURE_BL (1 << 1)
-void rtc_get(struct rtc_time *tm)
+int rtc_get(struct rtc_time *tm)
{
u8 buf[M41T62_DATETIME_REG_SIZE];
@@ -92,6 +92,8 @@ void rtc_get(struct rtc_time *tm)
__FUNCTION__,
tm->tm_sec, tm->tm_min, tm->tm_hour,
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
+
+ return 0;
}
void rtc_set(struct rtc_time *tm)
diff --git a/drivers/rtc/m48t35ax.c b/drivers/rtc/m48t35ax.c
index 0a0ffa8..be29279 100644
--- a/drivers/rtc/m48t35ax.c
+++ b/drivers/rtc/m48t35ax.c
@@ -42,7 +42,7 @@ static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
uchar sec, min, hour, cent_day, date, month, year;
uchar ccr; /* Clock control register */
@@ -83,6 +83,8 @@ void rtc_get (struct rtc_time *tmp)
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/max6900.c b/drivers/rtc/max6900.c
index c75a8e0..e9979f2 100644
--- a/drivers/rtc/max6900.c
+++ b/drivers/rtc/max6900.c
@@ -63,7 +63,7 @@ static unsigned char bin2bcd (unsigned int n)
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
uchar sec, min, hour, mday, wday, mon, cent, year;
int retry = 1;
@@ -103,6 +103,8 @@ void rtc_get (struct rtc_time *tmp)
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/mc146818.c b/drivers/rtc/mc146818.c
index ab377ed..70f7017 100644
--- a/drivers/rtc/mc146818.c
+++ b/drivers/rtc/mc146818.c
@@ -57,7 +57,7 @@ static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
uchar sec, min, hour, mday, wday, mon, year;
/* here check if rtc can be accessed */
@@ -101,6 +101,8 @@ void rtc_get (struct rtc_time *tmp)
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/mcfrtc.c b/drivers/rtc/mcfrtc.c
index 27386e5..d235d10 100644
--- a/drivers/rtc/mcfrtc.c
+++ b/drivers/rtc/mcfrtc.c
@@ -39,7 +39,7 @@
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
#define STARTOFTIME 1970
-void rtc_get(struct rtc_time *tmp)
+int rtc_get(struct rtc_time *tmp)
{
volatile rtc_t *rtc = (rtc_t *) (CFG_MCFRTC_BASE);
@@ -64,6 +64,8 @@ void rtc_get(struct rtc_time *tmp)
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
+
+ return 0;
}
void rtc_set(struct rtc_time *tmp)
diff --git a/drivers/rtc/mk48t59.c b/drivers/rtc/mk48t59.c
index bacdb5b..5981399 100644
--- a/drivers/rtc/mk48t59.c
+++ b/drivers/rtc/mk48t59.c
@@ -135,7 +135,7 @@ void nvram_write(short dest, const void *src, size_t count)
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
uchar save_ctrl_a;
uchar sec, min, hour, mday, wday, mon, year;
@@ -183,6 +183,8 @@ void rtc_get (struct rtc_time *tmp)
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/mpc5xxx.c b/drivers/rtc/mpc5xxx.c
index 216386a..a6555f5 100644
--- a/drivers/rtc/mpc5xxx.c
+++ b/drivers/rtc/mpc5xxx.c
@@ -55,7 +55,7 @@ typedef struct rtc5200 {
/*****************************************************************************
* get time
*****************************************************************************/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
RTC5200 *rtc = (RTC5200 *) (CFG_MBAR+0x800);
ulong time, date, time2;
@@ -81,6 +81,8 @@ void rtc_get (struct rtc_time *tmp)
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
/*****************************************************************************
diff --git a/drivers/rtc/mpc8xx.c b/drivers/rtc/mpc8xx.c
index 8d10c0e..057547b 100644
--- a/drivers/rtc/mpc8xx.c
+++ b/drivers/rtc/mpc8xx.c
@@ -35,7 +35,7 @@
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
volatile immap_t *immr = (immap_t *)CFG_IMMR;
ulong tim;
@@ -47,6 +47,8 @@ void rtc_get (struct rtc_time *tmp)
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/pcf8563.c b/drivers/rtc/pcf8563.c
index 2d73d5d..c384975 100644
--- a/drivers/rtc/pcf8563.c
+++ b/drivers/rtc/pcf8563.c
@@ -41,8 +41,9 @@ static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar sec, min, hour, mday, wday, mon_cent, year;
sec = rtc_read (0x02);
@@ -65,6 +66,7 @@ void rtc_get (struct rtc_time *tmp)
if (sec & 0x80) {
puts ("### Warning: RTC Low Voltage - date/time not reliable\n");
+ rel = -1;
}
tmp->tm_sec = bcd2bin (sec & 0x7F);
@@ -80,6 +82,8 @@ void rtc_get (struct rtc_time *tmp)
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/rs5c372.c b/drivers/rtc/rs5c372.c
index 3d1346e..1c9b752 100644
--- a/drivers/rtc/rs5c372.c
+++ b/drivers/rtc/rs5c372.c
@@ -166,7 +166,7 @@ rs5c372_convert_to_time(struct rtc_time *dt, unsigned char *buf)
/*
* Get the current time from the RTC
*/
-void
+int
rtc_get (struct rtc_time *tmp)
{
unsigned char buf[RS5C372_RAM_SIZE];
@@ -176,7 +176,7 @@ rtc_get (struct rtc_time *tmp)
rs5c372_enable();
if (!setup_done)
- return;
+ return -1;
memset(buf, 0, sizeof(buf));
@@ -184,12 +184,12 @@ rtc_get (struct rtc_time *tmp)
ret = rs5c372_readram(buf, RS5C372_RAM_SIZE);
if (ret != 0) {
printf("%s: failed\n", __FUNCTION__);
- return;
+ return -1;
}
rs5c372_convert_to_time(tmp, buf);
- return;
+ return 0;
}
/*
diff --git a/drivers/rtc/rx8025.c b/drivers/rtc/rx8025.c
index 9122f12..64eafe5 100644
--- a/drivers/rtc/rx8025.c
+++ b/drivers/rtc/rx8025.c
@@ -96,8 +96,9 @@ static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
*/
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
+ int rel = 0;
uchar sec, min, hour, mday, wday, mon, year, ctl2;
uchar buf[16];
@@ -118,14 +119,20 @@ void rtc_get (struct rtc_time *tmp)
/* dump status */
ctl2 = rtc_read(RTC_CTL2_REG_ADDR);
- if (ctl2 & RTC_CTL2_BIT_PON)
+ if (ctl2 & RTC_CTL2_BIT_PON) {
printf("RTC: power-on detected\n");
+ rel = -1;
+ }
- if (ctl2 & RTC_CTL2_BIT_VDET)
+ if (ctl2 & RTC_CTL2_BIT_VDET) {
printf("RTC: voltage drop detected\n");
+ rel = -1;
+ }
- if (!(ctl2 & RTC_CTL2_BIT_XST))
+ if (!(ctl2 & RTC_CTL2_BIT_XST)) {
printf("RTC: oscillator stop detected\n");
+ rel = -1;
+ }
tmp->tm_sec = bcd2bin (sec & 0x7F);
tmp->tm_min = bcd2bin (min & 0x7F);
@@ -140,6 +147,8 @@ void rtc_get (struct rtc_time *tmp)
DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+ return rel;
}
/*
diff --git a/drivers/rtc/s3c24x0_rtc.c b/drivers/rtc/s3c24x0_rtc.c
index 7f8b4fa..358aef7 100644
--- a/drivers/rtc/s3c24x0_rtc.c
+++ b/drivers/rtc/s3c24x0_rtc.c
@@ -70,7 +70,7 @@ static unsigned char bin2bcd (unsigned int n)
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
S3C24X0_RTC * const rtc = S3C24X0_GetBase_RTC();
uchar sec, min, hour, mday, wday, mon, year;
@@ -131,6 +131,8 @@ void rtc_get (struct rtc_time *tmp)
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
+
+ return 0;
}
void rtc_set (struct rtc_time *tmp)
diff --git a/drivers/rtc/x1205.c b/drivers/rtc/x1205.c
index 319f051..0e18139 100644
--- a/drivers/rtc/x1205.c
+++ b/drivers/rtc/x1205.c
@@ -104,7 +104,7 @@ static void rtc_write(int reg, u8 val)
* rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
* Epoch is initialized as 2000. Time is set to UTC.
*/
-void rtc_get(struct rtc_time *tm)
+int rtc_get(struct rtc_time *tm)
{
u8 buf[8];
@@ -130,6 +130,8 @@ void rtc_get(struct rtc_time *tm)
__FUNCTION__,
tm->tm_sec, tm->tm_min, tm->tm_hour,
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
+
+ return 0;
}
void rtc_set(struct rtc_time *tm)
diff --git a/include/rtc.h b/include/rtc.h
index 15f3571..2995144 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -52,7 +52,7 @@ struct rtc_time {
int tm_isdst;
};
-void rtc_get (struct rtc_time *);
+int rtc_get (struct rtc_time *);
void rtc_set (struct rtc_time *);
void rtc_reset (void);
diff --git a/post/drivers/rtc.c b/post/drivers/rtc.c
index 7d4f9b8..e3da5e6 100644
--- a/post/drivers/rtc.c
+++ b/post/drivers/rtc.c
@@ -28,6 +28,8 @@
*
* The Real Time Clock (RTC) operation is verified by this test.
* The following features are verified:
+ * o) RTC Power Fault
+ * This is verified by analyzing the rtc_get() return status.
* o) Time uniformity
* This is verified by reading RTC in polling within
* a short period of time.
@@ -96,6 +98,10 @@ int rtc_post_test (int flags)
unsigned int ynl = 1999;
unsigned int yl = 2000;
unsigned int skipped = 0;
+ int reliable;
+
+ /* Time reliability */
+ reliable = rtc_get (&svtm);
/* Time uniformity */
if (rtc_post_skip (&diff) != 0) {
@@ -176,6 +182,15 @@ int rtc_post_test (int flags)
}
rtc_post_restore (&svtm, skipped);
+ /* If come here, then RTC operates correcty, check the correctness
+ * of the time it reports.
+ */
+ if (reliable < 0) {
+ post_log ("RTC Time is not reliable! Power fault? \n");
+
+ return -1;
+ }
+
return 0;
}
--
1.5.4.2
More information about the U-Boot
mailing list