X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Frtc%2Fds1374.c;h=d61a2289f998015c45be8a1b75590512534749ab;hb=4ebbba442587cb03590c0747fd1fea16a158f15c;hp=e773dd92615fbc32fd6fcbdca1e7faccd5df96c8;hpb=521dcd30b9cc5b72cd27ae04104f19369251aa20;p=u-boot diff --git a/drivers/rtc/ds1374.c b/drivers/rtc/ds1374.c index e773dd9261..d61a2289f9 100644 --- a/drivers/rtc/ds1374.c +++ b/drivers/rtc/ds1374.c @@ -35,7 +35,7 @@ #include #include -#if (defined(CONFIG_RTC_DS1374)) && defined(CONFIG_CMD_DATE) +#if defined(CONFIG_CMD_DATE) /*---------------------------------------------------------------------*/ #undef DEBUG_RTC @@ -48,11 +48,11 @@ #endif /*---------------------------------------------------------------------*/ -#ifndef CFG_I2C_RTC_ADDR -# define CFG_I2C_RTC_ADDR 0x68 +#ifndef CONFIG_SYS_I2C_RTC_ADDR +# define CONFIG_SYS_I2C_RTC_ADDR 0x68 #endif -#if defined(CONFIG_RTC_DS1374) && (CFG_I2C_SPEED > 400000) +#if defined(CONFIG_RTC_DS1374) && (CONFIG_SYS_I2C_SPEED > 400000) # error The DS1374 is specified up to 400kHz in fast mode! #endif @@ -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,24 +138,29 @@ 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); + DEBUGR ("Get RTC s since 1.1.1970: %ld\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; } /* * Set the RTC */ -void rtc_set (struct rtc_time *tmp){ +int rtc_set (struct rtc_time *tmp){ unsigned long time; unsigned i; @@ -171,7 +176,7 @@ void rtc_set (struct rtc_time *tmp){ tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - DEBUGR ("Set RTC s since 1.1.1970: %d (0x%02x)\n", time, time); + DEBUGR ("Set RTC s since 1.1.1970: %ld (0x%02lx)\n", time, time); /* write to RTC_TOD_CNT_BYTEn_ADDR */ for (i = 0; i <= 3; i++) { @@ -181,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; } /* @@ -232,22 +239,22 @@ void rtc_reset (void){ */ static uchar rtc_read (uchar reg) { - return (i2c_reg_read (CFG_I2C_RTC_ADDR, reg)); + return (i2c_reg_read (CONFIG_SYS_I2C_RTC_ADDR, reg)); } static void rtc_write (uchar reg, uchar val, boolean_t set) { if (set == TRUE) { - val |= i2c_reg_read (CFG_I2C_RTC_ADDR, reg); - i2c_reg_write (CFG_I2C_RTC_ADDR, reg, val); + val |= i2c_reg_read (CONFIG_SYS_I2C_RTC_ADDR, reg); + i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val); } else { - val = i2c_reg_read (CFG_I2C_RTC_ADDR, reg) & ~val; - i2c_reg_write (CFG_I2C_RTC_ADDR, reg, val); + val = i2c_reg_read (CONFIG_SYS_I2C_RTC_ADDR, reg) & ~val; + i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val); } } static void rtc_write_raw (uchar reg, uchar val) { - i2c_reg_write (CFG_I2C_RTC_ADDR, reg, val); + i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val); } #endif