Commit d1e23194 authored by Jean-Christophe PLAGNIOL-VILLARD's avatar Jean-Christophe PLAGNIOL-VILLARD Committed by Wolfgang Denk
Browse files

rtc: allow rtc_set to return an error and use it in cmd_date


Signed-off-by: default avatarJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
parent ee9536a2
......@@ -299,8 +299,7 @@ rtc_get( struct rtc_time *tmp )
return 0;
}
void
rtc_set( struct rtc_time *tmp )
int rtc_set( struct rtc_time *tmp )
{
m48_tod_set(tmp->tm_year, /* 1980-2079 */
tmp->tm_mon, /* 01-12 */
......@@ -315,6 +314,7 @@ rtc_set( struct rtc_time *tmp )
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
return 0;
}
void
......
......@@ -181,9 +181,9 @@ int rtc_get (struct rtc_time *tmp)
{
return 0;
}
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
return;
return 0;
}
void rtc_reset (void)
{
......
......@@ -254,7 +254,7 @@ int rtc_get( struct rtc_time *tmp)
return 0;
}
void rtc_set( struct rtc_time *tmp )
int rtc_set( struct rtc_time *tmp )
{
if (phantom_flag < 0)
phantom_flag = get_phantom_flag();
......@@ -307,6 +307,8 @@ void rtc_set( struct rtc_time *tmp )
/* unlock clock registers after read */
rtc_write( RTC_CONTROLA, ( reg_a & ~RTC_CA_WRITE ));
}
return 0;
}
#endif
......@@ -299,8 +299,7 @@ rtc_get( struct rtc_time *tmp )
return 0;
}
void
rtc_set( struct rtc_time *tmp )
int rtc_set( struct rtc_time *tmp )
{
m48_tod_set(tmp->tm_year, /* 1980-2079 */
tmp->tm_mon, /* 01-12 */
......@@ -315,6 +314,7 @@ rtc_set( struct rtc_time *tmp )
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
return 0;
}
void
......
......@@ -56,18 +56,30 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
rtc_reset ();
} else {
/* initialize tm with current time */
rtc_get (&tm);
/* insert new date & time */
if (mk_date (argv[1], &tm) != 0) {
puts ("## Bad date format\n");
break;
rcode = rtc_get (&tm);
if(!rcode) {
/* insert new date & time */
if (mk_date (argv[1], &tm) != 0) {
puts ("## Bad date format\n");
break;
}
/* and write to RTC */
rcode = rtc_set (&tm);
if(rcode)
puts("## Set date failled\n");
} else {
puts("## Get date failled\n");
}
/* and write to RTC */
rtc_set (&tm);
}
/* FALL TROUGH */
case 1: /* get date & time */
rtc_get (&tm);
rcode = rtc_get (&tm);
if (rcode) {
puts("## Get date failled\n");
break;
}
printf ("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n",
tm.tm_year, tm.tm_mon, tm.tm_mday,
......
......@@ -188,7 +188,7 @@ int rtc_get (struct rtc_time* tm)
return 0;
}
void rtc_set (struct rtc_time* tm)
int rtc_set (struct rtc_time* tm)
{
if(tm->tm_year < 2000)
tm->tm_year -= 1900;
......@@ -204,6 +204,8 @@ void rtc_set (struct rtc_time* tm)
BCDMIN = HEX2BCD(tm->tm_min);
BCDSEC = HEX2BCD(tm->tm_sec);
RTCCON &= 1;
return 0;
}
void rtc_reset (void)
......
......@@ -53,7 +53,7 @@ int rtc_init(void)
/* Set the time. Get the time_in_secs which is the number of seconds since Jan 1970 and set the RTC registers
* based on this value.
*/
void rtc_set(struct rtc_time *tmp)
int rtc_set(struct rtc_time *tmp)
{
unsigned long remain, days, hrs, mins, secs;
......@@ -61,7 +61,7 @@ void rtc_set(struct rtc_time *tmp)
if (tmp == NULL) {
puts("Error setting the date/time\n");
return;
return -1;
}
wait_for_complete();
......@@ -82,6 +82,8 @@ void rtc_set(struct rtc_time *tmp)
/* Encode these time values into our RTC_STAT register */
bfin_write_RTC_STAT(SET_ALARM(days, hrs, mins, secs));
return 0;
}
/* Read the time from the RTC_STAT. time_in_seconds is seconds since Jan 1970 */
......
......@@ -154,7 +154,7 @@ else
return 0;
}
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
uchar save_ctrl_b;
uchar sec, min, hour, mday, wday, mon, year;
......@@ -202,6 +202,8 @@ void rtc_set (struct rtc_time *tmp)
/* enables the RTC to update the regs */
save_ctrl_b &= ~RTC_CB_SET;
rtc_write(RTC_CONTROL_B, save_ctrl_b);
return 0;
}
void rtc_reset (void)
......
......@@ -287,8 +287,7 @@ rtc_get(struct rtc_time *tmp)
return rel;
}
void
rtc_set(struct rtc_time *tmp)
int rtc_set(struct rtc_time *tmp)
{
struct ds1302_st bbclk;
unsigned char b=0;
......@@ -326,6 +325,8 @@ rtc_set(struct rtc_time *tmp)
write_ser_drv(0x8e,&b,1); /* disable write protect */
write_ser_drv(0xbe,(unsigned char *)&bbclk, 8); /* write burst */
return 0;
}
#endif
......@@ -141,7 +141,7 @@ int rtc_get (struct rtc_time *tmp)
/* ------------------------------------------------------------------------- */
/* set clock time in DS1306 RTC and in MPC8xx RTC */
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
volatile immap_t *immap = (immap_t *) CFG_IMMR;
......@@ -209,6 +209,8 @@ void rtc_set (struct rtc_time *tmp)
debug ("Set 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;
}
/* ------------------------------------------------------------------------- */
......@@ -371,7 +373,7 @@ int rtc_get (struct rtc_time *tmp)
/* ------------------------------------------------------------------------- */
/* set clock time from *tmp in DS1306 RTC */
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
/* Assuming Vcc = 2.0V (lowest speed) */
if (!slave) {
......
......@@ -128,7 +128,7 @@ int rtc_get (struct rtc_time *tmp)
/*
* Set the RTC
*/
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
......@@ -144,6 +144,8 @@ void rtc_set (struct rtc_time *tmp)
rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour));
rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min));
rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec));
return 0;
}
......
......@@ -132,7 +132,7 @@ int rtc_get (struct rtc_time *tmp)
/*
* Set the RTC
*/
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
uchar century;
......@@ -150,6 +150,8 @@ void rtc_set (struct rtc_time *tmp)
rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour));
rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min));
rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec));
return 0;
}
......
......@@ -160,7 +160,7 @@ int rtc_get (struct rtc_time *tm){
/*
* Set the RTC
*/
void rtc_set (struct rtc_time *tmp){
int rtc_set (struct rtc_time *tmp){
unsigned long time;
unsigned i;
......@@ -186,6 +186,8 @@ void rtc_set (struct rtc_time *tmp){
/* Start clock */
rtc_write(RTC_CTL_ADDR, RTC_CTL_BIT_EN_OSC, FALSE);
return 0;
}
/*
......
......@@ -120,7 +120,7 @@ int rtc_get( struct rtc_time *tmp )
return 0;
}
void rtc_set( struct rtc_time *tmp )
int rtc_set( struct rtc_time *tmp )
{
uchar reg_a;
#ifdef RTC_DEBUG
......@@ -146,6 +146,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)
......
......@@ -119,7 +119,7 @@ int rtc_get( struct rtc_time *tmp )
return 0;
}
void rtc_set( struct rtc_time *tmp )
int rtc_set( struct rtc_time *tmp )
{
uchar reg_a;
......@@ -145,6 +145,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)
......
......@@ -117,7 +117,7 @@ int rtc_get( struct rtc_time *tmp )
return 0;
}
void rtc_set( struct rtc_time *tmp )
int rtc_set( struct rtc_time *tmp )
{
uchar reg_a;
#ifdef RTC_DEBUG
......@@ -143,6 +143,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)
......
......@@ -134,7 +134,7 @@ int rtc_get (struct rtc_time *tmp)
/*
* Set the RTC
*/
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
uchar century;
......@@ -152,6 +152,8 @@ void rtc_set (struct rtc_time *tmp)
rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour));
rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min));
rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec));
return 0;
}
......
......@@ -118,7 +118,7 @@ int rtc_get (struct rtc_time *tmp)
/*
* Set the RTC
*/
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
......@@ -139,6 +139,8 @@ void rtc_set (struct rtc_time *tmp)
/* disable write */
rtc_write(RTC_STAT_REG_ADDR,
rtc_read(RTC_STAT_REG_ADDR) & ~RTC_STAT_BIT_WRTC);
return 0;
}
void rtc_reset (void)
......
......@@ -143,7 +143,7 @@ int rtc_get (struct rtc_time *tmp)
return rel;
}
void rtc_set (struct rtc_time *tmp)
int rtc_set (struct rtc_time *tmp)
{
uchar data[RTC_REG_CNT];
......@@ -176,6 +176,8 @@ void rtc_set (struct rtc_time *tmp)
}
#endif
i2c_write(CFG_I2C_RTC_ADDR, RTC_SEC_ADDR, 1, data, RTC_REG_CNT);
return 0;
}
void rtc_reset (void)
......
......@@ -193,12 +193,12 @@ int rtc_get(struct rtc_time *tmp)
return 0;
}
void rtc_set(struct rtc_time *tmp)
int rtc_set(struct rtc_time *tmp)
{
uchar *const data = rtc_validate();
if (!data)
return;
return -1;
debug("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
......@@ -214,8 +214,10 @@ void rtc_set(struct rtc_time *tmp)
data[RTC_DAY] = bin2bcd(tmp->tm_wday + 1) & 0x07;
if (i2c_write(CFG_I2C_RTC_ADDR, 0, 1, data, RTC_REG_CNT)) {
printf("I2C write failed in rtc_set()\n");
return;
return -1;
}
return 0;
}
void rtc_reset(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment