Merge branch 'u-boot-stm32_20190827' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / drivers / rtc / date.c
index bfa2e1378e22467cbe9c9049a868f7567ef46eee..c57317d2c267824b4c4a7f39a62e6918da98bd90 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2001
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -10,7 +9,8 @@
 #include <errno.h>
 #include <rtc.h>
 
-#if defined(CONFIG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
+#if defined(CONFIG_CMD_DATE) || defined(CONFIG_DM_RTC) || \
+                               defined(CONFIG_TIMESTAMP)
 
 #define FEBRUARY               2
 #define        STARTOFTIME             1970
 #define        days_in_year(a)         (leapyear(a) ? 366 : 365)
 #define        days_in_month(a)        (month_days[(a) - 1])
 
-static int month_days[12] = {
-       31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
 static int month_offset[] = {
        0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
 };
@@ -66,45 +62,6 @@ int rtc_calc_weekday(struct rtc_time *tm)
        return 0;
 }
 
-int rtc_to_tm(int tim, struct rtc_time *tm)
-{
-       register int i;
-       register long hms, day;
-
-       day = tim / SECDAY;
-       hms = tim % SECDAY;
-
-       /* Hours, minutes, seconds are easy */
-       tm->tm_hour = hms / 3600;
-       tm->tm_min = (hms % 3600) / 60;
-       tm->tm_sec = (hms % 3600) % 60;
-
-       /* Number of years in days */
-       for (i = STARTOFTIME; day >= days_in_year(i); i++)
-               day -= days_in_year(i);
-       tm->tm_year = i;
-
-       /* Number of months in days left */
-       if (leapyear(tm->tm_year))
-               days_in_month(FEBRUARY) = 29;
-       for (i = 1; day >= days_in_month(i); i++)
-               day -= days_in_month(i);
-       days_in_month(FEBRUARY) = 28;
-       tm->tm_mon = i;
-
-       /* Days are what is left over (+1) from all that */
-       tm->tm_mday = day + 1;
-
-       /* Zero unused fields */
-       tm->tm_yday = 0;
-       tm->tm_isdst = 0;
-
-       /*
-        * Determine the day of week
-        */
-       return rtc_calc_weekday(tm);
-}
-
 /*
  * Converts Gregorian date to seconds since 1970-01-01 00:00:00.
  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59