#include <common.h>
#include <command.h>
#include <rtc.h>
+#include <i2c.h>
+
+DECLARE_GLOBAL_DATA_PTR;
#if (CONFIG_COMMANDS & CFG_CMD_DATE)
int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
- DECLARE_GLOBAL_DATA_PTR;
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);
"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;
}
return (-1);
}
+/***************************************************/
+
+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"
+);
+
#endif /* CFG_CMD_DATE */