]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_date.c
POST: replace the LOGBUFF_INITIALIZED flag in gd->post_log_word (1 << 31) with the...
[u-boot] / common / cmd_date.c
index 1472e3f1aa6a10c373eec6dd73b76f0b04f813a6..751159847a487da0fd3c034d355417eed03ca646 100644 (file)
 #include <common.h>
 #include <command.h>
 #include <rtc.h>
+#include <i2c.h>
 
-#if (CONFIG_COMMANDS & CFG_CMD_DATE)
+DECLARE_GLOBAL_DATA_PTR;
 
 const char *weekdays[] = {
        "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
 };
 
+#define RELOC(a)       ((typeof(a))((unsigned long)(a) + gd->reloc_off))
+
 int mk_date (char *, struct rtc_time *);
 
 int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        struct rtc_time tm;
        int rcode = 0;
+       int old_bus;
+
+       /* switch to correct I2C bus */
+       old_bus = I2C_GET_BUS();
+       I2C_SET_BUS(CFG_RTC_BUS_NUM);
 
        switch (argc) {
        case 2:                 /* set date & time */
                if (strcmp(argv[1],"reset") == 0) {
-                       printf ("Reset RTC...\n");
+                       puts ("Reset RTC...\n");
                        rtc_reset ();
                } else {
                        /* initialize tm with current time */
                        rtc_get (&tm);
                        /* insert new date & time */
                        if (mk_date (argv[1], &tm) != 0) {
-                               printf ("## Bad date format\n");
-                               return 1;
+                               puts ("## Bad date format\n");
+                               break;
                        }
                        /* and write to RTC */
                        rtc_set (&tm);
@@ -64,14 +72,18 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                printf ("Date: %4d-%02d-%02d (%sday)    Time: %2d:%02d:%02d\n",
                        tm.tm_year, tm.tm_mon, tm.tm_mday,
                        (tm.tm_wday<0 || tm.tm_wday>6) ?
-                               "unknown " : weekdays[tm.tm_wday],
+                               "unknown " : RELOC(weekdays[tm.tm_wday]),
                        tm.tm_hour, tm.tm_min, tm.tm_sec);
 
-               return 0;
+               break;
        default:
                printf ("Usage:\n%s\n", cmdtp->usage);
                rcode = 1;
        }
+
+       /* switch back to original I2C bus */
+       I2C_SET_BUS(old_bus);
+
        return rcode;
 }
 
@@ -186,4 +198,13 @@ int mk_date (char *datestr, struct rtc_time *tmp)
        return (-1);
 }
 
-#endif /* CFG_CMD_DATE */
+/***************************************************/
+
+U_BOOT_CMD(
+       date,   2,      1,      do_date,
+       "date    - get/set/reset date & time\n",
+       "[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n"
+       "  - without arguments: print date & time\n"
+       "  - with numeric argument: set the system date & time\n"
+       "  - with 'reset' argument: reset the RTC\n"
+);