Commit b73a19e1 authored by Yuri Tikhonov's avatar Yuri Tikhonov Committed by Wolfgang Denk
Browse files

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: default avatarYuri Tikhonov <yur@emcraft.com>
parent 23e20aa6
......@@ -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
......
......@@ -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)
{
......
......@@ -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 )
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......@@ -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)
......
......@@ -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
......
......@@ -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;
}
/* ------------------------------------------------------------------------- */
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
/*
......
......@@ -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 )
......
......@@ -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 )
......
......@@ -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)
......
......@@ -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;
}
......
......@@ -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;
}
/*
......
......@@ -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, &cent, 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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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;
}
/*****************************************************************************
......
......@@ -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)
......
......@@ -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",