/*
* U-Boot RTC support.
*/
-void
+int
rtc_get( struct rtc_time *tmp )
{
m48_tod_get(&tmp->tm_year,
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
/* ------------------------------------------------------------------------- */
/* 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)
{
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();
tmp->tm_yday = 0;
tmp->tm_isdst= 0;
}
+
+ return 0;
}
void rtc_set( struct rtc_time *tmp )
/*
* U-Boot RTC support.
*/
-void
+int
rtc_get( struct rtc_time *tmp )
{
m48_tod_get(&tmp->tm_year,
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
#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);
tm->tm_year += 1900;
else
tm->tm_year += 2000;
+
+ return 0;
}
void rtc_set (struct rtc_time* tm)
}
/* 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;
if (tmp == NULL) {
puts("Error getting the date/time\n");
- return;
+ return -1;
}
wait_for_complete();
/* 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
/* ------------------------------------------------------------------------- */
-void rtc_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
uchar sec, min, hour, mday, wday, mon, year;
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)
/* TODO */
}
-void
+int
rtc_get(struct rtc_time *tmp)
{
+ int rel = 0;
struct ds1302_st bbclk;
if(!ds1302_initted) rtc_init();
if (bbclk.CH) {
printf("ds1302: rtc_get: Clock was halted, clock probably "
"corrupt\n");
+ rel = -1;
}
tmp->tm_sec=10*bbclk.sec10+bbclk.sec;
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
/* ------------------------------------------------------------------------- */
/* 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 */
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;
}
/* ------------------------------------------------------------------------- */
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;
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;
}
/* ------------------------------------------------------------------------- */
/*
* 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);
/* 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);
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;
}
/*
* 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);
/* 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);
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;
}
/*
* 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;
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;
}
/*
/* ------------------------------------------------------------------------- */
-void rtc_get( struct rtc_time *tmp )
+int rtc_get( struct rtc_time *tmp )
{
uchar sec, min, hour;
uchar mday, wday, mon, year;
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 )
/* ------------------------------------------------------------------------- */
-void rtc_get( struct rtc_time *tmp )
+int rtc_get( struct rtc_time *tmp )
{
uchar sec, min, hour;
uchar mday, wday, mon, year;
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 )
/* ------------------------------------------------------------------------- */
-void rtc_get( struct rtc_time *tmp )
+int rtc_get( struct rtc_time *tmp )
{
uchar sec, min, hour;
uchar mday, wday, mon, year;
/* unlock clock registers after read */
rtc_write( RTC_CONTROLA, ( reg_a & ~RTC_CA_WRITE ));
+
+ return 0;
}
void rtc_reset (void)
/*
* 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);
/* 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);
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;
}
* 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);
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);
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;
}
/*
#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);
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*/
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)
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);
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)
#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];
__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)
/* ------------------------------------------------------------------------- */
-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 */
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)
/* ------------------------------------------------------------------------- */
-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;
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)
/* ------------------------------------------------------------------------- */
-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 */
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)
#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);
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)
/* ------------------------------------------------------------------------- */
-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;
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)
/*****************************************************************************
* 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;
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_get (struct rtc_time *tmp)
+int rtc_get (struct rtc_time *tmp)
{
volatile immap_t *immr = (immap_t *)CFG_IMMR;
ulong tim;
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)
/* ------------------------------------------------------------------------- */
-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);
if (sec & 0x80) {
puts ("### Warning: RTC Low Voltage - date/time not reliable\n");
+ rel = -1;
}
tmp->tm_sec = bcd2bin (sec & 0x7F);
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)
/*
* Get the current time from the RTC
*/
-void
+int
rtc_get (struct rtc_time *tmp)
{
unsigned char buf[RS5C372_RAM_SIZE];
rs5c372_enable();
if (!setup_done)
- return;
+ return -1;
memset(buf, 0, sizeof(buf));
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;
}
/*
/*
* 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];
/* 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);
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;
}
/*
/* ------------------------------------------------------------------------- */
-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;
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)
* 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];
__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)
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);
*
* 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.
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) {
}
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;
}