Merge branch 'master' into hpc2
[oweals/u-boot.git] / rtc / ds1307.c
index 247494c34d15c15ff0e416ec6a823768300456f2..3b26a0a327ad7f18169969fc0895debfe5b79408 100644 (file)
@@ -25,7 +25,7 @@
 
 /*
  * Date & Time support (no alarms) for Dallas Semiconductor (now Maxim)
- * DS1307 Real Time Clock (RTC).
+ * DS1307 and DS1338 Real Time Clock (RTC).
  *
  * based on ds1337.c
  */
@@ -35,7 +35,8 @@
 #include <rtc.h>
 #include <i2c.h>
 
-#if defined(CONFIG_RTC_DS1307) && (CONFIG_COMMANDS & CFG_CMD_DATE)
+#if (defined(CONFIG_RTC_DS1307) || defined(CONFIG_RTC_DS1338) ) && \
+    (CONFIG_COMMANDS & CFG_CMD_DATE)
 
 /*---------------------------------------------------------------------*/
 #undef DEBUG_RTC
@@ -51,7 +52,7 @@
 # define CFG_I2C_RTC_ADDR      0x68
 #endif
 
-#if CFG_I2C_SPEED > 100000
+#if defined(CONFIG_RTC_DS1307) && (CFG_I2C_SPEED > 100000)
 # error The DS1307 is specified only up to 100kHz!
 #endif
 
@@ -104,7 +105,7 @@ void rtc_get (struct rtc_time *tmp)
                rtc_write (RTC_SEC_REG_ADDR,
                           rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH);
        }
-       
+
        tmp->tm_sec  = bcd2bin (sec & 0x7F);
        tmp->tm_min  = bcd2bin (min & 0x7F);
        tmp->tm_hour = bcd2bin (hour & 0x3F);
@@ -132,7 +133,7 @@ void rtc_set (struct rtc_time *tmp)
 
        if (tmp->tm_year < 1970 || tmp->tm_year > 2069)
                printf("WARNING: year should be between 1970 and 2069!\n");
-               
+
        rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100));
        rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon));
        rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1));
@@ -144,8 +145,8 @@ void rtc_set (struct rtc_time *tmp)
 
 
 /*
- * Reset the RTC. We setting the date back to 1970-01-01. 
- * We also enable the oscillator output on the SQW/OUT pin and program 
+ * Reset the RTC. We setting the date back to 1970-01-01.
+ * We also enable the oscillator output on the SQW/OUT pin and program
  * it for 32,768 Hz output. Note that according to the datasheet, turning
  * on the square wave output increases the current drain on the backup
  * battery to something between 480nA and 800nA.
@@ -200,4 +201,4 @@ static unsigned char bin2bcd (unsigned int n)
        return (((n / 10) << 4) | (n % 10));
 }
 
-#endif /* CONFIG_RTC_DS1307 && (CFG_COMMANDS & CFG_CMD_DATE) */
+#endif /* (CONFIG_RTC_DS1307 || CONFIG_RTC_DS1338) && (CFG_COMMANDS & CFG_CMD_DATE) */