diff mbox

[U-Boot] rtc: Set valid date after reset

Message ID 1428621114-6758-1-git-send-email-marex@denx.de
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Marek Vasut April 9, 2015, 11:11 p.m. UTC
Some RTC chips tend to set garbage date after reset.
This patch sets the date to 2000-01-01 00:00 immediatelly
after the RTC chip reset is issued using the "date reset"
command.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Heiko Schocher <hs@denx.de>
Cc: Tom Rini <trini@konsulko.com>
---
 common/cmd_date.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Tom Rini April 23, 2015, 10:03 p.m. UTC | #1
On Fri, Apr 10, 2015 at 01:11:54AM +0200, Marek Vasut wrote:

> Some RTC chips tend to set garbage date after reset.
> This patch sets the date to 2000-01-01 00:00 immediatelly
> after the RTC chip reset is issued using the "date reset"
> command.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Heiko Schocher <hs@denx.de>
> Cc: Tom Rini <trini@konsulko.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/common/cmd_date.c b/common/cmd_date.c
index e349166..4a653e5 100644
--- a/common/cmd_date.c
+++ b/common/cmd_date.c
@@ -27,6 +27,8 @@  static const char * const weekdays[] = {
 
 int mk_date (const char *, struct rtc_time *);
 
+static struct rtc_time default_tm = { 0, 0, 0, 1, 1, 2000, 6, 0, 0 };
+
 static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	struct rtc_time tm;
@@ -47,6 +49,9 @@  static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (strcmp(argv[1],"reset") == 0) {
 			puts ("Reset RTC...\n");
 			rtc_reset ();
+			rcode = rtc_set(&default_tm);
+			if (rcode)
+				puts("## Failed to set date after RTC reset\n");
 		} else {
 			/* initialize tm with current time */
 			rcode = rtc_get (&tm);