#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",
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(CONFIG_SYS_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;
+ rcode = rtc_get (&tm);
+
+ if(!rcode) {
+ /* insert new date & time */
+ if (mk_date (argv[1], &tm) != 0) {
+ puts ("## Bad date format\n");
+ break;
+ }
+ /* and write to RTC */
+ rcode = rtc_set (&tm);
+ if(rcode)
+ puts("## Set date failled\n");
+ } else {
+ puts("## Get date failled\n");
}
- /* and write to RTC */
- rtc_set (&tm);
}
/* FALL TROUGH */
case 1: /* get date & time */
- rtc_get (&tm);
+ rcode = rtc_get (&tm);
+
+ if (rcode) {
+ puts("## Get date failled\n");
+ break;
+ }
printf ("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n",
tm.tm_year, tm.tm_mon, tm.tm_mday,
"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);
+ cmd_usage(cmdtp);
rcode = 1;
}
+
+ /* switch back to original I2C bus */
+ I2C_SET_BUS(old_bus);
+
return rcode;
}
/***************************************************/
-cmd_tbl_t U_BOOT_CMD(DATE) = MK_CMD_ENTRY(
- "date", 2, 1, do_date,
- "date - get/set/reset date & time\n",
+U_BOOT_CMD(
+ date, 2, 1, do_date,
+ "get/set/reset date & time",
"[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 */